X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchSolver%2FSketchSolver_Solver.cpp;h=975588bbb18084947a2bbcdeb457c1f68864f614;hb=cdd9efd8fbc75f120188ae16eed7471dc6492ac3;hp=f9ed8c37204c788a6de8c685faac995fe3b30af9;hpb=a398103d11950df8cb50eeea49942237eb16edcf;p=modules%2Fshaper.git diff --git a/src/SketchSolver/SketchSolver_Solver.cpp b/src/SketchSolver/SketchSolver_Solver.cpp index f9ed8c372..975588bbb 100644 --- a/src/SketchSolver/SketchSolver_Solver.cpp +++ b/src/SketchSolver/SketchSolver_Solver.cpp @@ -3,6 +3,7 @@ // Author: Artem ZHIDKOV #include "SketchSolver_Solver.h" +#include SketchSolver_Solver::SketchSolver_Solver() { @@ -16,6 +17,11 @@ SketchSolver_Solver::SketchSolver_Solver() myEquationsSystem.failed = 0; myEquationsSystem.faileds = 0; + myEquationsSystem.dragged[0] = 0; + myEquationsSystem.dragged[1] = 0; + myEquationsSystem.dragged[2] = 0; + myEquationsSystem.dragged[3] = 0; + // If the set of constraints is inconsistent, // the failed field will contain wrong constraints myEquationsSystem.calculateFaileds = 1; @@ -24,21 +30,21 @@ SketchSolver_Solver::SketchSolver_Solver() SketchSolver_Solver::~SketchSolver_Solver() { if (myEquationsSystem.param) - delete [] myEquationsSystem.param; + delete[] myEquationsSystem.param; if (myEquationsSystem.entity) - delete [] myEquationsSystem.entity; + delete[] myEquationsSystem.entity; if (myEquationsSystem.constraint) - delete [] myEquationsSystem.constraint; + delete[] myEquationsSystem.constraint; if (myEquationsSystem.failed) - delete [] myEquationsSystem.failed; + delete[] myEquationsSystem.failed; } void SketchSolver_Solver::setParameters(const std::vector& theParameters) { - if (theParameters.size() != myEquationsSystem.params) // number of parameters was changed => reallocate the memory - { + if (theParameters.size() != myEquationsSystem.params) // number of parameters was changed => reallocate the memory + { if (myEquationsSystem.param) - delete [] myEquationsSystem.param; + delete[] myEquationsSystem.param; myEquationsSystem.params = theParameters.size(); myEquationsSystem.param = new Slvs_Param[theParameters.size()]; } @@ -49,12 +55,25 @@ void SketchSolver_Solver::setParameters(const std::vector& theParame myEquationsSystem.param[i] = *aParamIter; } +void SketchSolver_Solver::setDraggedParameters(const std::vector& theDragged) +{ + if (theDragged.size() == 0) { + myEquationsSystem.dragged[0] = 0; + myEquationsSystem.dragged[1] = 0; + myEquationsSystem.dragged[2] = 0; + myEquationsSystem.dragged[3] = 0; + return; + } + for (unsigned int i = 0; i < theDragged.size(); i++) + myEquationsSystem.dragged[i] = theDragged[i]; +} + void SketchSolver_Solver::setEntities(const std::vector& theEntities) { - if (theEntities.size() != myEquationsSystem.entities) // number of entities was changed => reallocate the memory - { + if (theEntities.size() != myEquationsSystem.entities) // number of entities was changed => reallocate the memory + { if (myEquationsSystem.entity) - delete [] myEquationsSystem.entity; + delete[] myEquationsSystem.entity; myEquationsSystem.entities = theEntities.size(); myEquationsSystem.entity = new Slvs_Entity[theEntities.size()]; } @@ -67,12 +86,18 @@ void SketchSolver_Solver::setEntities(const std::vector& theEntitie void SketchSolver_Solver::setConstraints(const std::vector& theConstraints) { - if (theConstraints.size() != myEquationsSystem.constraints) // number of constraints was changed => reallocate the memory - { + if (theConstraints.size() != myEquationsSystem.constraints) // number of constraints was changed => reallocate the memory + { if (myEquationsSystem.constraint) - delete [] myEquationsSystem.constraint; + delete[] myEquationsSystem.constraint; myEquationsSystem.constraints = theConstraints.size(); myEquationsSystem.constraint = new Slvs_Constraint[theConstraints.size()]; + + // Assign the memory for the failed constraints + if (myEquationsSystem.failed) + delete[] myEquationsSystem.failed; + myEquationsSystem.failed = new Slvs_hConstraint[theConstraints.size()]; + myEquationsSystem.faileds = theConstraints.size(); } // Copy data @@ -86,7 +111,9 @@ int SketchSolver_Solver::solve() if (myEquationsSystem.constraints <= 0) return SLVS_RESULT_EMPTY_SET; + Events_LongOp::start(this); Slvs_Solve(&myEquationsSystem, myGroupID); + Events_LongOp::end(this); return myEquationsSystem.result; } @@ -97,13 +124,12 @@ bool SketchSolver_Solver::getResult(std::vector& theParameters) return false; if (theParameters.size() != myEquationsSystem.params) - return false; // number of parameters is not the same + return false; // number of parameters is not the same std::vector::iterator aParamIter = theParameters.begin(); - for (int i = 0; i < myEquationsSystem.params; i++, aParamIter++) - { + for (int i = 0; i < myEquationsSystem.params; i++, aParamIter++) { if (myEquationsSystem.param[i].h != aParamIter->h) - return false; // sequence of parameters was changed + return false; // sequence of parameters was changed aParamIter->val = myEquationsSystem.param[i].val; }