X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchSolver%2FSketchSolver_Solver.cpp;h=4e7a4f0e9269f7e2d76ad8219a130fce099864f3;hb=20d233731eaae06b9a75280a2ca675bc9a11cc72;hp=975588bbb18084947a2bbcdeb457c1f68864f614;hpb=8dc74f82810d5f597b78633b457efb0ef4f89f9f;p=modules%2Fshaper.git diff --git a/src/SketchSolver/SketchSolver_Solver.cpp b/src/SketchSolver/SketchSolver_Solver.cpp index 975588bbb..4e7a4f0e9 100644 --- a/src/SketchSolver/SketchSolver_Solver.cpp +++ b/src/SketchSolver/SketchSolver_Solver.cpp @@ -1,3 +1,5 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + // File: SketchSolver_Solver.cpp // Created: 07 May 2014 // Author: Artem ZHIDKOV @@ -29,83 +31,48 @@ SketchSolver_Solver::SketchSolver_Solver() SketchSolver_Solver::~SketchSolver_Solver() { - if (myEquationsSystem.param) - delete[] myEquationsSystem.param; - if (myEquationsSystem.entity) - delete[] myEquationsSystem.entity; if (myEquationsSystem.constraint) delete[] myEquationsSystem.constraint; if (myEquationsSystem.failed) delete[] myEquationsSystem.failed; } -void SketchSolver_Solver::setParameters(const std::vector& theParameters) +void SketchSolver_Solver::setParameters(Slvs_Param* theParameters, int theSize) { - if (theParameters.size() != myEquationsSystem.params) // number of parameters was changed => reallocate the memory - { - if (myEquationsSystem.param) - delete[] myEquationsSystem.param; - myEquationsSystem.params = theParameters.size(); - myEquationsSystem.param = new Slvs_Param[theParameters.size()]; - } - - // Copy data - std::vector::const_iterator aParamIter = theParameters.begin(); - for (int i = 0; i < myEquationsSystem.params; i++, aParamIter++) - myEquationsSystem.param[i] = *aParamIter; + myEquationsSystem.param = theParameters; + myEquationsSystem.params = theSize; } -void SketchSolver_Solver::setDraggedParameters(const std::vector& theDragged) + +void SketchSolver_Solver::setDraggedParameters(const Slvs_hParam* 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++) + for (unsigned int i = 0; i < 4; i++) myEquationsSystem.dragged[i] = theDragged[i]; } -void SketchSolver_Solver::setEntities(const std::vector& theEntities) +void SketchSolver_Solver::setEntities(Slvs_Entity* theEntities, int theSize) { - if (theEntities.size() != myEquationsSystem.entities) // number of entities was changed => reallocate the memory - { - if (myEquationsSystem.entity) - delete[] myEquationsSystem.entity; - myEquationsSystem.entities = theEntities.size(); - myEquationsSystem.entity = new Slvs_Entity[theEntities.size()]; - } - - // Copy data - std::vector::const_iterator aEntIter = theEntities.begin(); - for (int i = 0; i < myEquationsSystem.entities; i++, aEntIter++) - myEquationsSystem.entity[i] = *aEntIter; + myEquationsSystem.entity = theEntities; + myEquationsSystem.entities = theSize; } -void SketchSolver_Solver::setConstraints(const std::vector& theConstraints) +void SketchSolver_Solver::setConstraints(Slvs_Constraint* theConstraints, int theSize) { - if (theConstraints.size() != myEquationsSystem.constraints) // number of constraints was changed => reallocate the memory - { - if (myEquationsSystem.constraint) + if (!myEquationsSystem.constraint) { + myEquationsSystem.constraint = new Slvs_Constraint[theSize]; + myEquationsSystem.constraints = theSize; + } + else if (myEquationsSystem.constraints != theSize) { + if (theSize > myEquationsSystem.constraints) { 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(); + myEquationsSystem.constraint = new Slvs_Constraint[theSize]; + } + myEquationsSystem.constraints = theSize; } - - // Copy data - std::vector::const_iterator aConstrIter = theConstraints.begin(); - for (int i = 0; i < myEquationsSystem.constraints; i++, aConstrIter++) - myEquationsSystem.constraint[i] = *aConstrIter; + memcpy(myEquationsSystem.constraint, theConstraints, theSize * sizeof(Slvs_Constraint)); } + int SketchSolver_Solver::solve() { if (myEquationsSystem.constraints <= 0)