extend Python interface of sketcher and make non-parametic version working

This commit is contained in:
wmayer 2016-08-14 11:52:37 +02:00
parent d4bb01835c
commit bfb80b058c
5 changed files with 70 additions and 34 deletions

View File

@ -110,7 +110,6 @@ int Sketch::setUpSketch(const std::vector<Part::Geometry *> &GeoList,
const std::vector<Constraint *> &ConstraintList,
int extGeoCount)
{
Base::TimeInfo start_time;
clear();
@ -147,6 +146,17 @@ int Sketch::setUpSketch(const std::vector<Part::Geometry *> &GeoList,
return GCSsys.dofsNumber();
}
int Sketch::resetSolver()
{
GCSsys.clearByTag(-1);
GCSsys.declareUnknowns(Parameters);
GCSsys.initSolution(defaultSolverRedundant);
GCSsys.getConflicting(Conflicting);
GCSsys.getRedundant(Redundant);
return GCSsys.dofsNumber();
}
const char* nameByType(Sketch::GeoType type)
{
switch (type) {
@ -567,9 +577,10 @@ std::vector<Part::Geometry *> Sketch::extractGeometry(bool withConstructionEleme
{
std::vector<Part::Geometry *> temp;
temp.reserve(Geoms.size());
for (std::vector<GeoDef>::const_iterator it=Geoms.begin(); it != Geoms.end(); ++it)
for (std::vector<GeoDef>::const_iterator it=Geoms.begin(); it != Geoms.end(); ++it) {
if ((!it->external || withExternalElements) && (!it->geo->Construction || withConstructionElements))
temp.push_back(it->geo->clone());
}
return temp;
}
@ -2090,7 +2101,6 @@ bool Sketch::updateNonDrivingConstraints()
int Sketch::solve(void)
{
Base::TimeInfo start_time;
if (!isInitMove) { // make sure we are in single subsystem mode
GCSsys.clearByTag(-1);
@ -2134,11 +2144,12 @@ int Sketch::solve(void)
GCSsys.undoSolution();
updateGeometry();
Base::Console().Warning("Invalid solution from %s solver.\n", solvername.c_str());
}else
{
}
else {
updateNonDrivingConstraints();
}
} else {
}
else {
valid_solution = false;
if(debugMode==GCS::Minimal || debugMode==GCS::IterationLevel){
@ -2350,6 +2361,7 @@ int Sketch::initMove(int geoId, PointPos pos, bool fine)
*p0.y = *p.y;
GCSsys.addConstraintP2PCoincident(p0,p,-1);
}
p1.x = &MoveParameters[2];
p1.y = &MoveParameters[3];
*p1.x = *center.x;
@ -2493,8 +2505,6 @@ Base::Vector3d Sketch::getPoint(int geoId, PointPos pos)
return Base::Vector3d();
}
TopoShape Sketch::toShape(void) const
{
TopoShape result;
@ -2563,6 +2573,7 @@ TopoShape Sketch::toShape(void) const
aFix.FixClosed();
wires.push_back(aFix.Wire());
}
if (wires.size() == 1)
result = *wires.begin();
else if (wires.size() > 1) {

View File

@ -51,6 +51,8 @@ public:
/// solve the actual set up sketch
int solve(void);
/// resets the solver
int resetSolver();
/// get standard (aka fine) solver precision
double getSolverPrecision(){ return GCSsys.getFinePrecision(); }
/// delete all geometry and constraints, leave an empty sketch

View File

@ -56,11 +56,17 @@
</Documentation>
<Parameter Name="Constraint" Type="Int"/>
</Attribute>
<Attribute Name="Constraints" ReadOnly="true">
<Attribute Name="Conflicts" ReadOnly="true">
<Documentation>
<UserDocu>Tuple of all constrains in this sketch</UserDocu>
<UserDocu>Tuple of conflicting constraints</UserDocu>
</Documentation>
<Parameter Name="Constraints" Type="Tuple"/>
<Parameter Name="Conflicts" Type="Tuple"/>
</Attribute>
<Attribute Name="Redundancies" ReadOnly="true">
<Documentation>
<UserDocu>Tuple of redundant constraints</UserDocu>
</Documentation>
<Parameter Name="Redundancies" Type="Tuple"/>
</Attribute>
<Attribute Name="Geometries" ReadOnly="true">
<Documentation>

View File

@ -63,6 +63,7 @@ int SketchPy::PyInit(PyObject* /*args*/, PyObject* /*kwd*/)
PyObject* SketchPy::solve(PyObject *args)
{
getSketchPtr()->resetSolver();
return Py::new_reference_to(Py::Int(getSketchPtr()->solve()));
}
@ -169,10 +170,26 @@ Py::Int SketchPy::getConstraint(void) const
throw Py::AttributeError("Not yet implemented");
}
Py::Tuple SketchPy::getConstraints(void) const
Py::Tuple SketchPy::getConflicts(void) const
{
//return Py::Tuple();
throw Py::AttributeError("Not yet implemented");
std::vector<int> c = getSketchPtr()->getConflicting();
Py::Tuple t(c.size());
for (std::size_t i=0; i<c.size(); i++) {
t.setItem(i, Py::Long(c[i]));
}
return t;
}
Py::Tuple SketchPy::getRedundancies(void) const
{
std::vector<int> c = getSketchPtr()->getRedundant();
Py::Tuple t(c.size());
for (std::size_t i=0; i<c.size(); i++) {
t.setItem(i, Py::Long(c[i]));
}
return t;
}
Py::Tuple SketchPy::getGeometries(void) const

View File

@ -252,7 +252,7 @@ namespace GCS
double getFinePrecision(){ return convergence;}
int diagnose(Algorithm alg=DogLeg);
int dofsNumber() { return hasDiagnosis ? dofs : -1; }
int dofsNumber() const { return hasDiagnosis ? dofs : -1; }
void getConflicting(VEC_I &conflictingOut) const
{ conflictingOut = hasDiagnosis ? conflictingTags : VEC_I(0); }
void getRedundant(VEC_I &redundantOut) const