1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: SketchSolver_Storage.cpp
4 // Created: 18 Mar 2015
5 // Author: Artem ZHIDKOV
7 #include <SketchSolver_Storage.h>
9 #include <GeomAPI_Pnt2d.h>
10 #include <GeomAPI_XY.h>
13 /** \brief Search the entity/parameter with specified ID in the list of elements
14 * \param[in] theEntityID unique ID of the element
15 * \param[in] theEntities list of elements
16 * \return position of the found element or -1 if the element is not found
19 static int Search(const uint32_t& theEntityID, const std::vector<T>& theEntities);
21 /// \brief Compare two parameters to be different
22 static bool IsNotEqual(const Slvs_Param& theParam1, const Slvs_Param& theParam2);
23 /// \brief Compare two entities to be different
24 static bool IsNotEqual(const Slvs_Entity& theEntity1, const Slvs_Entity& theEntity2);
25 /// \brief Compare two constriants to be different
26 static bool IsNotEqual(const Slvs_Constraint& theConstraint1, const Slvs_Constraint& theConstraint2);
29 SketchSolver_Storage::SketchSolver_Storage()
30 : myParamMaxID(SLVS_E_UNKNOWN),
31 myEntityMaxID(SLVS_E_UNKNOWN),
32 myConstrMaxID(SLVS_C_UNKNOWN),
33 myFixed(SLVS_E_UNKNOWN),
34 myNeedToResolve(false),
35 myDuplicatedConstraint(false)
39 Slvs_hParam SketchSolver_Storage::addParameter(const Slvs_Param& theParam)
41 if (theParam.h > 0 && theParam.h <= myParamMaxID) {
42 // parameter is already used, rewrite it
43 return updateParameter(theParam);
46 Slvs_Param aParam = theParam;
47 if (aParam.h > myParamMaxID)
48 myParamMaxID = aParam.h;
50 aParam.h = ++myParamMaxID;
51 myParameters.push_back(aParam);
52 myNeedToResolve = true;
56 Slvs_hParam SketchSolver_Storage::updateParameter(const Slvs_Param& theParam)
58 if (theParam.h > 0 && theParam.h <= myParamMaxID) {
59 // parameter already used, rewrite it
60 int aPos = Search(theParam.h, myParameters);
61 if (aPos >= 0 && aPos < (int)myParameters.size()) {
62 if (IsNotEqual(myParameters[aPos], theParam))
63 myUpdatedParameters.insert(theParam.h);
64 myParameters[aPos] = theParam;
69 // Parameter is not found, add new one
70 Slvs_Param aParam = theParam;
72 return addParameter(aParam);
75 bool SketchSolver_Storage::removeParameter(const Slvs_hParam& theParamID)
77 int aPos = Search(theParamID, myParameters);
78 if (aPos >= 0 && aPos < (int)myParameters.size()) {
79 // Firstly, search the parametes is not used elsewhere
80 std::vector<Slvs_Entity>::const_iterator anEntIter = myEntities.begin();
81 for (; anEntIter != myEntities.end(); anEntIter++) {
82 for (int i = 0; i < 4; i++)
83 if (anEntIter->param[i] == theParamID)
87 myParameters.erase(myParameters.begin() + aPos);
88 myParamMaxID = myParameters.empty() ? SLVS_E_UNKNOWN : myParameters.back().h;
89 myNeedToResolve = true;
90 myRemovedParameters.insert(theParamID);
96 const Slvs_Param& SketchSolver_Storage::getParameter(const Slvs_hParam& theParamID) const
98 int aPos = Search(theParamID, myParameters);
99 if (aPos >= 0 && aPos < (int)myParameters.size())
100 return myParameters[aPos];
102 // Parameter is not found, return empty object
103 static Slvs_Param aDummy;
109 Slvs_hEntity SketchSolver_Storage::addEntity(const Slvs_Entity& theEntity)
111 if (theEntity.h > 0 && theEntity.h <= myEntityMaxID) {
112 // Entity is already used, rewrite it
113 return updateEntity(theEntity);
116 Slvs_Entity aEntity = theEntity;
117 if (aEntity.h > myEntityMaxID)
118 myEntityMaxID = aEntity.h;
120 aEntity.h = ++myEntityMaxID;
121 myEntities.push_back(aEntity);
122 myNeedToResolve = true;
126 Slvs_hEntity SketchSolver_Storage::updateEntity(const Slvs_Entity& theEntity)
128 if (theEntity.h > 0 && theEntity.h <= myEntityMaxID) {
129 // Entity already used, rewrite it
130 int aPos = Search(theEntity.h, myEntities);
131 if (aPos >= 0 && aPos < (int)myEntities.size()) {
132 myNeedToResolve = myNeedToResolve || IsNotEqual(myEntities[aPos], theEntity);
133 myEntities[aPos] = theEntity;
138 // Entity is not found, add new one
139 Slvs_Entity aEntity = theEntity;
141 return addEntity(aEntity);
144 bool SketchSolver_Storage::removeEntity(const Slvs_hEntity& theEntityID)
147 int aPos = Search(theEntityID, myEntities);
148 if (aPos >= 0 && aPos < (int)myEntities.size()) {
149 // Firstly, check the entity and its attributes is not used elsewhere
150 std::set<Slvs_hEntity> anEntAndSubs;
151 anEntAndSubs.insert(theEntityID);
152 for (int i = 0; i < 4; i++)
153 if (myEntities[aPos].point[i] != SLVS_E_UNKNOWN)
154 anEntAndSubs.insert(myEntities[aPos].point[i]);
156 std::vector<Slvs_Entity>::const_iterator anEntIter = myEntities.begin();
157 for (; anEntIter != myEntities.end(); anEntIter++) {
158 for (int i = 0; i < 4; i++)
159 if (anEntAndSubs.find(anEntIter->point[i]) != anEntAndSubs.end())
161 if (anEntAndSubs.find(anEntIter->distance) != anEntAndSubs.end())
164 std::vector<Slvs_Constraint>::const_iterator aConstrIter = myConstraints.begin();
165 for (; aConstrIter != myConstraints.end(); aConstrIter++) {
166 Slvs_hEntity anEntIDs[6] = {aConstrIter->ptA, aConstrIter->ptB,
167 aConstrIter->entityA, aConstrIter->entityB,
168 aConstrIter->entityC, aConstrIter->entityD};
169 for (int i = 0; i < 6; i++)
170 if (anEntAndSubs.find(anEntIDs[i]) != anEntAndSubs.end())
173 // The entity is not used, remove it and its parameters
174 Slvs_Entity anEntity = myEntities[aPos];
175 myEntities.erase(myEntities.begin() + aPos);
176 myEntityMaxID = myEntities.empty() ? SLVS_E_UNKNOWN : myEntities.back().h;
177 if (anEntity.distance != SLVS_E_UNKNOWN)
178 aResult = aResult && removeParameter(anEntity.distance);
179 for (int i = 0; i < 4; i++)
180 if (anEntity.param[i] != SLVS_E_UNKNOWN)
181 aResult = removeParameter(anEntity.param[i]) && aResult;
182 for (int i = 0; i < 4; i++)
183 if (anEntity.point[i] != SLVS_E_UNKNOWN)
184 aResult = removeEntity(anEntity.point[i]) && aResult;
185 myNeedToResolve = true;
186 myRemovedEntities.insert(theEntityID);
187 if (anEntity.type == SLVS_E_POINT_IN_2D || anEntity.type == SLVS_E_POINT_IN_3D)
188 removeCoincidentPoint(theEntityID);
193 void SketchSolver_Storage::removeUnusedEntities()
195 std::set<Slvs_hEntity> anUnusedEntities;
196 std::vector<Slvs_Entity>::const_iterator aEIt = myEntities.begin();
197 for (; aEIt != myEntities.end(); ++aEIt) {
198 if (aEIt->h == aEIt->wrkpl) {
199 // don't remove workplane
200 anUnusedEntities.erase(aEIt->point[0]);
201 anUnusedEntities.erase(aEIt->normal);
204 anUnusedEntities.insert(aEIt->h);
207 std::vector<Slvs_Constraint>::const_iterator aCIt = myConstraints.begin();
208 for (; aCIt != myConstraints.end(); ++aCIt) {
209 Slvs_hEntity aSubs[6] = {
210 aCIt->entityA, aCIt->entityB,
211 aCIt->entityC, aCIt->entityD,
212 aCIt->ptA, aCIt->ptB};
213 for (int i = 0; i < 6; i++) {
214 if (aSubs[i] != SLVS_E_UNKNOWN) {
215 anUnusedEntities.erase(aSubs[i]);
216 int aPos = Search(aSubs[i], myEntities);
217 if (aPos >= 0 && aPos < (int)myEntities.size()) {
218 for (int j = 0; j < 4; j++)
219 if (myEntities[aPos].point[j] != SLVS_E_UNKNOWN)
220 anUnusedEntities.erase(myEntities[aPos].point[j]);
221 if (myEntities[aPos].distance != SLVS_E_UNKNOWN)
222 anUnusedEntities.erase(myEntities[aPos].distance);
228 std::set<Slvs_hEntity>::const_iterator anEntIt = anUnusedEntities.begin();
229 while (anEntIt != anUnusedEntities.end()) {
230 int aPos = Search(*anEntIt, myEntities);
231 if (aPos < 0 && aPos >= (int)myEntities.size())
233 Slvs_Entity anEntity = myEntities[aPos];
234 // Remove entity if and only if all its parameters unused
236 if (anEntity.distance != SLVS_E_UNKNOWN &&
237 anUnusedEntities.find(anEntity.distance) == anUnusedEntities.end())
239 for (int i = 0; i < 4 && !isUsed; i++)
240 if (anEntity.point[i] != SLVS_E_UNKNOWN &&
241 anUnusedEntities.find(anEntity.point[i]) == anUnusedEntities.end())
244 anUnusedEntities.erase(anEntity.distance);
245 for (int i = 0; i < 4; i++)
246 if (anEntity.point[i] != SLVS_E_UNKNOWN)
247 anUnusedEntities.erase(anEntity.point[i]);
248 std::set<Slvs_hEntity>::iterator aRemoveIt = anEntIt++;
249 anUnusedEntities.erase(aRemoveIt);
255 for (anEntIt = anUnusedEntities.begin(); anEntIt != anUnusedEntities.end(); ++anEntIt) {
256 int aPos = Search(*anEntIt, myEntities);
257 if (aPos >= 0 && aPos < (int)myEntities.size()) {
258 // Remove entity and its parameters
259 Slvs_Entity anEntity = myEntities[aPos];
260 myEntities.erase(myEntities.begin() + aPos);
261 myEntityMaxID = myEntities.empty() ? SLVS_E_UNKNOWN : myEntities.back().h;
262 if (anEntity.distance != SLVS_E_UNKNOWN)
263 removeParameter(anEntity.distance);
264 for (int i = 0; i < 4; i++)
265 if (anEntity.param[i] != SLVS_E_UNKNOWN)
266 removeParameter(anEntity.param[i]);
267 for (int i = 0; i < 4; i++)
268 if (anEntity.point[i] != SLVS_E_UNKNOWN)
269 removeEntity(anEntity.point[i]);
270 myRemovedEntities.insert(*anEntIt);
271 if (anEntity.type == SLVS_E_POINT_IN_2D || anEntity.type == SLVS_E_POINT_IN_3D)
272 removeCoincidentPoint(*anEntIt);
276 if (!anUnusedEntities.empty())
277 myNeedToResolve = true;
280 bool SketchSolver_Storage::isUsedByConstraints(const Slvs_hEntity& theEntityID) const
282 std::vector<Slvs_Constraint>::const_iterator aCIt = myConstraints.begin();
283 for (; aCIt != myConstraints.end(); ++aCIt) {
284 Slvs_hEntity aSubs[6] = {
285 aCIt->entityA, aCIt->entityB,
286 aCIt->entityC, aCIt->entityD,
287 aCIt->ptA, aCIt->ptB};
288 for (int i = 0; i < 6; i++)
289 if (aSubs[i] != SLVS_E_UNKNOWN && aSubs[i] == theEntityID)
295 const Slvs_Entity& SketchSolver_Storage::getEntity(const Slvs_hEntity& theEntityID) const
297 int aPos = Search(theEntityID, myEntities);
298 if (aPos >= 0 && aPos < (int)myEntities.size())
299 return myEntities[aPos];
301 // Entity is not found, return empty object
302 static Slvs_Entity aDummy;
303 aDummy.h = SLVS_E_UNKNOWN;
307 Slvs_hEntity SketchSolver_Storage::copyEntity(const Slvs_hEntity& theCopied)
309 int aPos = Search(theCopied, myEntities);
310 if (aPos < 0 || aPos >= (int)myEntities.size())
311 return SLVS_E_UNKNOWN;
313 Slvs_Entity aCopy = myEntities[aPos];
314 aCopy.h = SLVS_E_UNKNOWN;
316 while (aCopy.point[i] != SLVS_E_UNKNOWN) {
317 aCopy.point[i] = copyEntity(aCopy.point[i]);
320 if (aCopy.param[0] != SLVS_E_UNKNOWN) {
321 aPos = Search(aCopy.param[0], myParameters);
323 while (aCopy.param[i] != SLVS_E_UNKNOWN) {
324 Slvs_Param aNewParam = myParameters[aPos];
325 aNewParam.h = SLVS_E_UNKNOWN;
326 aCopy.param[i] = addParameter(aNewParam);
331 return addEntity(aCopy);
334 void SketchSolver_Storage::copyEntity(const Slvs_hEntity& theFrom, const Slvs_hEntity& theTo)
336 int aPosFrom = Search(theFrom, myEntities);
337 int aPosTo = Search(theTo, myEntities);
338 if (aPosFrom < 0 || aPosFrom >= (int)myEntities.size() ||
339 aPosTo < 0 || aPosTo >= (int)myEntities.size())
342 Slvs_Entity aEntFrom = myEntities[aPosFrom];
343 Slvs_Entity aEntTo = myEntities[aPosTo];
345 while (aEntFrom.point[i] != SLVS_E_UNKNOWN) {
346 copyEntity(aEntFrom.point[i], aEntTo.point[i]);
349 if (aEntFrom.param[0] != SLVS_E_UNKNOWN) {
350 aPosFrom = Search(aEntFrom.param[0], myParameters);
351 aPosTo = Search(aEntTo.param[0], myParameters);
353 while (aEntFrom.param[i] != SLVS_E_UNKNOWN) {
354 myParameters[aPosTo++].val = myParameters[aPosFrom++].val;
361 bool SketchSolver_Storage::isPointFixed(
362 const Slvs_hEntity& thePointID, Slvs_hConstraint& theFixed, bool theAccurate) const
364 // Search the set of coincident points
365 std::set<Slvs_hEntity> aCoincident;
366 aCoincident.insert(thePointID);
367 std::vector< std::set<Slvs_hEntity> >::const_iterator aCPIter = myCoincidentPoints.begin();
368 for (; aCPIter != myCoincidentPoints.end(); aCPIter++)
369 if (aCPIter->find(thePointID) != aCPIter->end()) {
370 aCoincident = *aCPIter;
374 // Search the Rigid constraint
375 std::vector<Slvs_Constraint>::const_iterator aConstrIter = myConstraints.begin();
376 for (; aConstrIter != myConstraints.end(); aConstrIter++)
377 if (aConstrIter->type == SLVS_C_WHERE_DRAGGED &&
378 aCoincident.find(aConstrIter->ptA) != aCoincident.end()) {
379 theFixed = aConstrIter->h;
384 // Try to find the fixed entity which uses such point or its coincidence
385 std::vector<Slvs_Entity>::const_iterator anEntIter = myEntities.begin();
386 for (; anEntIter != myEntities.end(); anEntIter++) {
387 for (int i = 0; i < 4; i++) {
388 Slvs_hEntity aPt = anEntIter->point[i];
389 if (aPt != SLVS_E_UNKNOWN &&
390 (aPt == thePointID || aCoincident.find(aPt) != aCoincident.end())) {
391 if (isEntityFixed(anEntIter->h, true))
397 return SLVS_E_UNKNOWN;
400 bool SketchSolver_Storage::isEntityFixed(const Slvs_hEntity& theEntityID, bool theAccurate) const
402 int aPos = Search(theEntityID, myEntities);
403 if (aPos < 0 || aPos >= (int)myEntities.size())
406 // Firstly, find how many points are under Rigid constraint
408 for (int i = 0; i < 4; i++) {
409 Slvs_hEntity aPoint = myEntities[aPos].point[i];
410 if (aPoint == SLVS_E_UNKNOWN)
413 std::set<Slvs_hEntity> aCoincident;
414 aCoincident.insert(aPoint);
415 std::vector< std::set<Slvs_hEntity> >::const_iterator aCPIter = myCoincidentPoints.begin();
416 for (; aCPIter != myCoincidentPoints.end(); aCPIter++)
417 if (aCPIter->find(aPoint) != aCPIter->end()) {
418 aCoincident = *aCPIter;
422 // Search the Rigid constraint
423 std::vector<Slvs_Constraint>::const_iterator aConstrIter = myConstraints.begin();
424 for (; aConstrIter != myConstraints.end(); aConstrIter++)
425 if (aConstrIter->type == SLVS_C_WHERE_DRAGGED &&
426 aCoincident.find(aConstrIter->ptA) != aCoincident.end())
430 std::list<Slvs_Constraint> aList;
431 std::list<Slvs_Constraint>::iterator anIt;
432 Slvs_hConstraint aTempID; // used in isPointFixed() method
434 if (myEntities[aPos].type == SLVS_E_LINE_SEGMENT) {
437 else if (aNbFixed == 0 || !theAccurate)
439 // Additional check (the line may be fixed if it is used by different constraints):
440 // 1. The line is used in Equal constraint, another entity is fixed and there is a fixed point on line
441 aList = getConstraintsByType(SLVS_C_PT_ON_LINE);
442 for (anIt = aList.begin(); anIt != aList.end(); anIt++)
443 if (anIt->entityA == theEntityID && isPointFixed(anIt->ptA, aTempID))
445 if (anIt != aList.end()) {
446 aList = getConstraintsByType(SLVS_C_EQUAL_LENGTH_LINES);
447 aList.splice(aList.end(), getConstraintsByType(SLVS_C_EQUAL_LINE_ARC_LEN));
448 for (anIt = aList.begin(); anIt != aList.end(); anIt++)
449 if (anIt->entityA == theEntityID || anIt->entityB == theEntityID) {
450 Slvs_hEntity anOther = anIt->entityA == theEntityID ? anIt->entityB : anIt->entityA;
451 if (isEntityFixed(anOther, false))
455 // 2. The line is used in Parallel/Perpendicular/Vertical/Horizontal and Length constraints
456 aList = getConstraintsByType(SLVS_C_PARALLEL);
457 aList.splice(aList.end(), getConstraintsByType(SLVS_C_PERPENDICULAR));
458 aList.splice(aList.end(), getConstraintsByType(SLVS_C_VERTICAL));
459 aList.splice(aList.end(), getConstraintsByType(SLVS_C_HORIZONTAL));
460 for (anIt = aList.begin(); anIt != aList.end(); anIt++)
461 if (anIt->entityA == theEntityID || anIt->entityB == theEntityID) {
462 Slvs_hEntity anOther = anIt->entityA == theEntityID ? anIt->entityB : anIt->entityA;
463 if (isEntityFixed(anOther, false))
466 if (anIt != aList.end()) {
467 aList = getConstraintsByType(SLVS_C_PT_PT_DISTANCE);
468 for (anIt = aList.begin(); anIt != aList.end(); anIt++)
469 if ((anIt->ptA == myEntities[aPos].point[0] && anIt->ptB == myEntities[aPos].point[1]) ||
470 (anIt->ptA == myEntities[aPos].point[1] && anIt->ptB == myEntities[aPos].point[0]))
473 // 3. Another verifiers ...
474 } else if (myEntities[aPos].type == SLVS_E_CIRCLE) {
477 // Search for Diameter constraint
478 aList = getConstraintsByType(SLVS_C_DIAMETER);
479 for (anIt = aList.begin(); anIt != aList.end(); anIt++)
480 if (anIt->entityA == theEntityID)
484 // Additional check (the circle may be fixed if it is used by different constraints):
485 // 1. The circle is used in Equal constraint and another entity is fixed
486 aList = getConstraintsByType(SLVS_C_EQUAL_RADIUS);
487 for (anIt = aList.begin(); anIt != aList.end(); anIt++)
488 if (anIt->entityA == theEntityID || anIt->entityB == theEntityID) {
489 Slvs_hEntity anOther = anIt->entityA == theEntityID ? anIt->entityB : anIt->entityA;
490 if (isEntityFixed(anOther, false))
493 // 2. Another verifiers ...
494 } else if (myEntities[aPos].type == SLVS_E_ARC_OF_CIRCLE) {
497 else if (aNbFixed <= 1)
499 // Search for Diameter constraint
500 aList = getConstraintsByType(SLVS_C_DIAMETER);
501 for (anIt = aList.begin(); anIt != aList.end(); anIt++)
502 if (anIt->entityA == theEntityID)
506 // Additional check (the arc may be fixed if it is used by different constraints):
507 // 1. The arc is used in Equal constraint and another entity is fixed
508 aList = getConstraintsByType(SLVS_C_EQUAL_RADIUS);
509 aList.splice(aList.end(), getConstraintsByType(SLVS_C_EQUAL_LINE_ARC_LEN));
510 for (anIt = aList.begin(); anIt != aList.end(); anIt++)
511 if (anIt->entityA == theEntityID || anIt->entityB == theEntityID) {
512 Slvs_hEntity anOther = anIt->entityA == theEntityID ? anIt->entityB : anIt->entityA;
513 if (isEntityFixed(anOther, false))
516 // 2. Another verifiers ...
522 Slvs_hConstraint SketchSolver_Storage::addConstraint(const Slvs_Constraint& theConstraint)
524 if (theConstraint.h > 0 && theConstraint.h <= myConstrMaxID) {
525 // Constraint is already used, rewrite it
526 return updateConstraint(theConstraint);
529 Slvs_Constraint aConstraint = theConstraint;
531 // Find a constraint with same type uses same arguments to show user overconstraint situation
532 std::vector<Slvs_Constraint>::iterator aCIt = myConstraints.begin();
533 for (; aCIt != myConstraints.end(); aCIt++) {
534 if (aConstraint.type != aCIt->type)
536 if (aConstraint.ptA == aCIt->ptA && aConstraint.ptB == aCIt->ptB &&
537 aConstraint.entityA == aCIt->entityA && aConstraint.entityB == aCIt->entityB &&
538 aConstraint.entityC == aCIt->entityC && aConstraint.entityD == aCIt->entityD)
539 myDuplicatedConstraint = true;
542 if (aConstraint.h > myConstrMaxID)
543 myConstrMaxID = aConstraint.h;
545 aConstraint.h = ++myConstrMaxID;
546 myConstraints.push_back(aConstraint);
547 myNeedToResolve = true;
548 if (aConstraint.type == SLVS_C_POINTS_COINCIDENT)
549 addCoincidentPoints(aConstraint.ptA, aConstraint.ptB);
550 return aConstraint.h;
553 Slvs_hConstraint SketchSolver_Storage::updateConstraint(const Slvs_Constraint& theConstraint)
555 if (theConstraint.h > 0 && theConstraint.h <= myConstrMaxID) {
556 // Constraint already used, rewrite it
557 int aPos = Search(theConstraint.h, myConstraints);
558 if (aPos >= 0 && aPos < (int)myConstraints.size()) {
559 myNeedToResolve = myNeedToResolve || IsNotEqual(myConstraints[aPos], theConstraint);
560 myConstraints[aPos] = theConstraint;
561 if (theConstraint.type == SLVS_C_POINTS_COINCIDENT)
562 addCoincidentPoints(theConstraint.ptA, theConstraint.ptB);
563 return theConstraint.h;
567 // Constraint is not found, add new one
568 Slvs_Constraint aConstraint = theConstraint;
570 return addConstraint(aConstraint);
573 bool SketchSolver_Storage::removeConstraint(const Slvs_hConstraint& theConstraintID)
576 int aPos = Search(theConstraintID, myConstraints);
577 if (aPos >= 0 && aPos < (int)myConstraints.size()) {
578 Slvs_Constraint aConstraint = myConstraints[aPos];
579 myConstraints.erase(myConstraints.begin() + aPos);
580 myConstrMaxID = myConstraints.empty() ? SLVS_E_UNKNOWN : myConstraints.back().h;
581 myNeedToResolve = true;
582 myRemovedConstraints.insert(theConstraintID);
583 // Remove all entities
584 Slvs_hEntity anEntities[6] = {aConstraint.ptA, aConstraint.ptB,
585 aConstraint.entityA, aConstraint.entityB,
586 aConstraint.entityC, aConstraint.entityD};
587 for (int i = 0; i < 6; i++)
588 if (anEntities[i] != SLVS_E_UNKNOWN)
589 aResult = removeEntity(anEntities[i]) && aResult;
590 // remove temporary fixed point, if available
591 if (myFixed == theConstraintID)
592 myFixed = SLVS_E_UNKNOWN;
593 if (myDuplicatedConstraint) {
594 // Check the duplicated constraints are still available
595 myDuplicatedConstraint = false;
596 std::vector<Slvs_Constraint>::const_iterator anIt1 = myConstraints.begin();
597 std::vector<Slvs_Constraint>::const_iterator anIt2 = myConstraints.begin();
598 for (; anIt1 != myConstraints.end() && !myDuplicatedConstraint; anIt1++)
599 for (anIt2 = anIt1+1; anIt2 != myConstraints.end() && !myDuplicatedConstraint; anIt2++) {
600 if (anIt1->type != anIt2->type)
602 if (anIt1->ptA == anIt2->ptA && anIt1->ptB == anIt2->ptB &&
603 anIt1->entityA == anIt2->entityA && anIt1->entityB == anIt2->entityB &&
604 anIt1->entityC == anIt2->entityC && anIt1->entityD == anIt2->entityD)
605 myDuplicatedConstraint = true;
612 const Slvs_Constraint& SketchSolver_Storage::getConstraint(const Slvs_hConstraint& theConstraintID) const
614 int aPos = Search(theConstraintID, myConstraints);
615 if (aPos >= 0 && aPos < (int)myConstraints.size())
616 return myConstraints[aPos];
618 // Constraint is not found, return empty object
619 static Slvs_Constraint aDummy;
624 std::list<Slvs_Constraint> SketchSolver_Storage::getConstraintsByType(int theConstraintType) const
626 std::list<Slvs_Constraint> aResult;
627 std::vector<Slvs_Constraint>::const_iterator aCIter = myConstraints.begin();
628 for (; aCIter != myConstraints.end(); aCIter++)
629 if (aCIter->type == theConstraintType)
630 aResult.push_back(*aCIter);
635 void SketchSolver_Storage::addConstraintWhereDragged(const Slvs_hConstraint& theConstraintID)
637 if (myFixed != SLVS_E_UNKNOWN)
638 return; // the point is already fixed
639 int aPos = Search(theConstraintID, myConstraints);
640 if (aPos >= 0 && aPos < (int)myConstraints.size())
641 myFixed = theConstraintID;
644 void SketchSolver_Storage::addTemporaryConstraint(const Slvs_hConstraint& theConstraintID)
646 myTemporaryConstraints.insert(theConstraintID);
649 void SketchSolver_Storage::removeTemporaryConstraints()
651 myTemporaryConstraints.clear();
654 int SketchSolver_Storage::deleteTemporaryConstraint()
656 if (myTemporaryConstraints.empty())
658 // Search the point-on-line or a non-rigid constraint
659 std::set<Slvs_hConstraint>::iterator aCIt = myTemporaryConstraints.begin();
660 for (; aCIt != myTemporaryConstraints.end(); aCIt++) {
661 int aPos = Search(*aCIt, myConstraints);
662 if (aPos >= (int)myConstraints.size() || myConstraints[aPos].type != SLVS_C_WHERE_DRAGGED)
664 std::vector<Slvs_Constraint>::iterator anIt = myConstraints.begin();
665 for (; anIt != myConstraints.end(); anIt++)
666 if (anIt->type == SLVS_C_PT_ON_LINE && anIt->ptA == myConstraints[aPos].ptA)
668 if (anIt != myConstraints.end())
671 if (aCIt == myTemporaryConstraints.end())
672 aCIt = myTemporaryConstraints.begin();
673 bool aNewFixed = (*aCIt == myFixed);
674 removeConstraint(*aCIt);
675 myTemporaryConstraints.erase(aCIt);
677 for (aCIt = myTemporaryConstraints.begin(); aCIt != myTemporaryConstraints.end(); aCIt++) {
678 int aPos = Search(*aCIt, myConstraints);
679 if (myConstraints[aPos].type == SLVS_C_WHERE_DRAGGED) {
685 return (int)myTemporaryConstraints.size();
688 bool SketchSolver_Storage::isTemporary(const Slvs_hConstraint& theConstraintID) const
690 return myTemporaryConstraints.find(theConstraintID) != myTemporaryConstraints.end();
694 void SketchSolver_Storage::getRemoved(
695 std::set<Slvs_hParam>& theParameters,
696 std::set<Slvs_hEntity>& theEntities,
697 std::set<Slvs_hConstraint>& theConstraints)
699 theParameters = myRemovedParameters;
700 theEntities = myRemovedEntities;
701 theConstraints = myRemovedConstraints;
703 myRemovedParameters.clear();
704 myRemovedEntities.clear();
705 myRemovedConstraints.clear();
708 void SketchSolver_Storage::initializeSolver(SketchSolver_Solver& theSolver)
710 theSolver.setParameters(myParameters.data(), (int)myParameters.size());
711 theSolver.setEntities(myEntities.data(), (int)myEntities.size());
713 // Copy constraints excluding the fixed one
714 std::vector<Slvs_Constraint> aConstraints = myConstraints;
715 if (myFixed != SLVS_E_UNKNOWN) {
716 Slvs_hEntity aFixedPoint = SLVS_E_UNKNOWN;
717 std::vector<Slvs_Constraint>::iterator anIt = aConstraints.begin();
718 for (; anIt != aConstraints.end(); anIt++)
719 if (anIt->h == myFixed) {
720 aFixedPoint = anIt->ptA;
721 // aConstraints.erase(anIt);
724 // set dragged parameters
725 int aPos = Search(aFixedPoint, myEntities);
726 theSolver.setDraggedParameters(myEntities[aPos].param);
728 theSolver.setConstraints(aConstraints.data(), (int)aConstraints.size());
731 void SketchSolver_Storage::addCoincidentPoints(
732 const Slvs_hEntity& thePoint1, const Slvs_hEntity& thePoint2)
734 std::vector< std::set<Slvs_hEntity> >::iterator aCIter = myCoincidentPoints.begin();
735 std::vector< std::set<Slvs_hEntity> >::iterator aFoundIter = myCoincidentPoints.end(); // already found coincidence
736 bool isFound = false;
737 for (; aCIter != myCoincidentPoints.end(); aCIter++) {
738 bool isFirstFound = aCIter->find(thePoint1) != aCIter->end();
739 bool isSecondFound = aCIter->find(thePoint2) != aCIter->end();
740 isFound = isFound || isFirstFound || isSecondFound;
741 if (isFirstFound && isSecondFound)
742 break; // already coincident
743 else if (isFirstFound || isSecondFound) {
744 if (aFoundIter != myCoincidentPoints.end()) {
746 aFoundIter->insert(aCIter->begin(), aCIter->end());
747 myCoincidentPoints.erase(aCIter);
751 aCIter->insert(thePoint1);
752 aCIter->insert(thePoint2);
755 // coincident points not found
757 std::set<Slvs_hEntity> aNewSet;
758 aNewSet.insert(thePoint1);
759 aNewSet.insert(thePoint2);
760 myCoincidentPoints.push_back(aNewSet);
764 void SketchSolver_Storage::removeCoincidentPoint(const Slvs_hEntity& thePoint)
766 std::vector< std::set<Slvs_hEntity> >::iterator aCIter = myCoincidentPoints.begin();
767 for (; aCIter != myCoincidentPoints.end(); aCIter++)
768 if (aCIter->find(thePoint) != aCIter->end()) {
769 aCIter->erase(thePoint);
770 if (aCIter->size() <= 1)
771 myCoincidentPoints.erase(aCIter);
776 bool SketchSolver_Storage::isCoincident(
777 const Slvs_hEntity& thePoint1, const Slvs_hEntity& thePoint2) const
779 std::vector< std::set<Slvs_hEntity> >::const_iterator aCIter = myCoincidentPoints.begin();
780 for (; aCIter != myCoincidentPoints.end(); aCIter++)
781 if (aCIter->find(thePoint1) != aCIter->end() && aCIter->find(thePoint2) != aCIter->end())
786 bool SketchSolver_Storage::isEqual(
787 const Slvs_hEntity& thePoint1, const Slvs_hEntity& thePoint2) const
789 if (isCoincident(thePoint1, thePoint2))
792 // Precise checking of coincidence: verify that points have equal coordinates
793 int aEnt1Pos = Search(thePoint1, myEntities);
794 int aEnt2Pos = Search(thePoint2, myEntities);
795 if (aEnt1Pos >= 0 && aEnt1Pos < (int)myEntities.size() &&
796 aEnt2Pos >= 0 && aEnt2Pos < (int)myEntities.size()) {
799 for (int i = 0; i < 2; i++) {
800 aParamPos = Search(myEntities[aEnt1Pos].param[i], myParameters);
801 aDist[i] = myParameters[aParamPos].val;
802 aParamPos = Search(myEntities[aEnt2Pos].param[i], myParameters);
803 aDist[i] -= myParameters[aParamPos].val;
805 if (aDist[0] * aDist[0] + aDist[1] * aDist[1] < tolerance * tolerance)
812 std::vector<Slvs_hConstraint> SketchSolver_Storage::fixEntity(const Slvs_hEntity& theEntity)
814 std::vector<Slvs_hConstraint> aNewConstraints;
816 int aPos = Search(theEntity, myEntities);
817 if (aPos >= 0 && aPos < (int)myEntities.size()) {
818 switch (myEntities[aPos].type) {
819 case SLVS_E_POINT_IN_2D:
820 case SLVS_E_POINT_IN_3D:
821 fixPoint(myEntities[aPos], aNewConstraints);
823 case SLVS_E_LINE_SEGMENT:
824 fixLine(myEntities[aPos], aNewConstraints);
827 fixCircle(myEntities[aPos], aNewConstraints);
829 case SLVS_E_ARC_OF_CIRCLE:
830 fixArc(myEntities[aPos], aNewConstraints);
837 return aNewConstraints;
840 void SketchSolver_Storage::fixPoint(const Slvs_Entity& thePoint,
841 std::vector<Slvs_hConstraint>& theCreated)
843 Slvs_Constraint aConstraint;
844 Slvs_hConstraint aConstrID = SLVS_E_UNKNOWN;
845 bool isFixed = isPointFixed(thePoint.h, aConstrID, true);
846 bool isForceUpdate = (isFixed && isTemporary(aConstrID));
847 if (!isForceUpdate) { // create new constraint
849 aConstraint = Slvs_MakeConstraint(SLVS_E_UNKNOWN, thePoint.group, SLVS_C_WHERE_DRAGGED, thePoint.wrkpl,
850 0.0, thePoint.h, SLVS_E_UNKNOWN, SLVS_E_UNKNOWN, SLVS_E_UNKNOWN);
851 aConstraint.h = addConstraint(aConstraint);
852 theCreated.push_back(aConstraint.h);
853 } else { // update already existent constraint
854 if (!isFixed || aConstrID == SLVS_E_UNKNOWN)
856 int aPos = Search(aConstrID, myConstraints);
857 if (aPos >= 0 && aPos < (int)myConstraints.size())
858 myConstraints[aPos].ptA = thePoint.h;
862 void SketchSolver_Storage::fixLine(const Slvs_Entity& theLine,
863 std::vector<Slvs_hConstraint>& theCreated)
865 Slvs_Entity aPoint[2] = {
866 getEntity(theLine.point[0]),
867 getEntity(theLine.point[1])
870 Slvs_Constraint anEqual;
871 if (isAxisParallel(theLine.h)) {
872 // Fix one point and a line length
873 Slvs_hConstraint aFixed;
874 if (!isPointFixed(theLine.point[0], aFixed, true) &&
875 !isPointFixed(theLine.point[1], aFixed, true))
876 fixPoint(aPoint[0], theCreated);
877 if (!isUsedInEqual(theLine.h, anEqual)) {
878 // Check the distance is not set yet
879 std::vector<Slvs_Constraint>::const_iterator aDistIt = myConstraints.begin();
880 for (; aDistIt != myConstraints.end(); ++aDistIt)
881 if ((aDistIt->type == SLVS_C_PT_PT_DISTANCE) &&
882 ((aDistIt->ptA == theLine.point[0] && aDistIt->ptB == theLine.point[1]) ||
883 (aDistIt->ptA == theLine.point[1] && aDistIt->ptB == theLine.point[0])))
885 // Calculate distance between points on the line
887 for (int i = 0; i < 2; i++)
888 for (int j = 0; j < 2; j++) {
889 Slvs_Param aParam = getParameter(aPoint[i].param[j]);
890 aCoords[2*i+j] = aParam.val;
893 double aLength = sqrt((aCoords[2] - aCoords[0]) * (aCoords[2] - aCoords[0]) +
894 (aCoords[3] - aCoords[1]) * (aCoords[3] - aCoords[1]));
896 Slvs_Constraint aDistance = Slvs_MakeConstraint(SLVS_E_UNKNOWN, theLine.group,
897 SLVS_C_PT_PT_DISTANCE, theLine.wrkpl, aLength,
898 theLine.point[0], theLine.point[1], SLVS_E_UNKNOWN, SLVS_E_UNKNOWN);
899 aDistance.h = addConstraint(aDistance);
900 theCreated.push_back(aDistance.h);
904 else if (isUsedInEqual(theLine.h, anEqual)) {
905 // Check another entity of Equal is already fixed
906 Slvs_hEntity anOtherEntID = anEqual.entityA == theLine.h ? anEqual.entityB : anEqual.entityA;
907 if (isEntityFixed(anOtherEntID, true)) {
908 // Fix start point of the line (if end point is not fixed yet) ...
909 Slvs_hConstraint anEndFixedID = SLVS_E_UNKNOWN;
910 bool isFixed = isPointFixed(theLine.point[1], anEndFixedID, true);
911 if (isFixed == SLVS_E_UNKNOWN)
912 fixPoint(aPoint[0], theCreated);
913 // ... and create fixed point lying on this line
914 Slvs_hEntity aPointToCopy = anEndFixedID == SLVS_E_UNKNOWN ? theLine.point[1] : theLine.point[0];
915 // Firstly, search already fixed point on line
916 bool isPonLineFixed = false;
917 Slvs_hEntity aFixedPoint;
918 std::vector<Slvs_Constraint>::const_iterator aPLIter = myConstraints.begin();
919 for (; aPLIter != myConstraints.end() && !isPonLineFixed; ++aPLIter)
920 if (aPLIter->type == SLVS_C_PT_ON_LINE && aPLIter->entityA == theLine.h) {
921 isPonLineFixed = isPointFixed(aPLIter->ptA, anEndFixedID);
922 aFixedPoint = aPLIter->ptA;
925 if (isPonLineFixed) { // update existent constraint
926 copyEntity(aPointToCopy, aFixedPoint);
927 } else { // create new constraint
928 Slvs_hEntity aCopied = copyEntity(aPointToCopy);
929 Slvs_Constraint aPonLine = Slvs_MakeConstraint(SLVS_E_UNKNOWN, theLine.group, SLVS_C_PT_ON_LINE,
930 theLine.wrkpl, 0.0, aCopied, SLVS_E_UNKNOWN, theLine.h, SLVS_E_UNKNOWN);
931 aPonLine.h = addConstraint(aPonLine);
932 theCreated.push_back(aPonLine.h);
933 fixPoint(getEntity(aCopied), theCreated);
940 for (int i = 0; i < 2; i++)
941 fixPoint(aPoint[i], theCreated);
944 void SketchSolver_Storage::fixCircle(const Slvs_Entity& theCircle,
945 std::vector<Slvs_hConstraint>& theCreated)
947 bool isFixRadius = true;
948 // Verify the arc is under Equal constraint
949 Slvs_Constraint anEqual;
950 if (isUsedInEqual(theCircle.h, anEqual)) {
951 // Check another entity of Equal is already fixed
952 Slvs_hEntity anOtherEntID = anEqual.entityA == theCircle.h ? anEqual.entityB : anEqual.entityA;
953 if (isEntityFixed(anOtherEntID, true))
957 fixPoint(getEntity(theCircle.point[0]), theCreated);
960 // Search the radius is already fixed
961 std::vector<Slvs_Constraint>::const_iterator aDiamIter = myConstraints.begin();
962 for (; aDiamIter != myConstraints.end(); ++aDiamIter)
963 if (aDiamIter->type == SLVS_C_DIAMETER && aDiamIter->entityA == theCircle.h)
966 // Fix radius of a circle
967 const Slvs_Entity& aRadEnt = getEntity(theCircle.distance);
968 double aRadius = getParameter(aRadEnt.param[0]).val;
969 Slvs_Constraint aFixedR = Slvs_MakeConstraint(SLVS_E_UNKNOWN, theCircle.group, SLVS_C_DIAMETER,
970 theCircle.wrkpl, aRadius * 2.0, SLVS_E_UNKNOWN, SLVS_E_UNKNOWN, theCircle.h, SLVS_E_UNKNOWN);
971 aFixedR.h = addConstraint(aFixedR);
972 theCreated.push_back(aFixedR.h);
976 void SketchSolver_Storage::fixArc(const Slvs_Entity& theArc,
977 std::vector<Slvs_hConstraint>& theCreated)
979 Slvs_Entity aPoint[3] = {
980 getEntity(theArc.point[0]),
981 getEntity(theArc.point[1]),
982 getEntity(theArc.point[2])
985 bool isFixRadius = true;
986 std::list<Slvs_Entity> aPointsToFix;
987 aPointsToFix.push_back(aPoint[1]);
988 aPointsToFix.push_back(aPoint[2]);
990 // Verify the arc is under Equal constraint
991 Slvs_Constraint anEqual;
992 if (isUsedInEqual(theArc.h, anEqual)) {
993 // Check another entity of Equal is already fixed
994 Slvs_hEntity anOtherEntID = anEqual.entityA == theArc.h ? anEqual.entityB : anEqual.entityA;
995 if (isEntityFixed(anOtherEntID, true)) {
997 Slvs_Entity anOtherEntity = getEntity(anOtherEntID);
998 if (anOtherEntity.type == SLVS_E_LINE_SEGMENT) {
999 aPointsToFix.pop_back();
1000 aPointsToFix.push_back(aPoint[0]);
1005 Slvs_hConstraint aConstrID;
1006 int aNbPointsToFix = 2; // number of fixed points for the arc
1007 if (isPointFixed(theArc.point[0], aConstrID, true))
1010 double anArcPoints[3][2];
1011 for (int i = 0; i < 3; i++) {
1012 const Slvs_Entity& aPointOnArc = getEntity(theArc.point[i]);
1013 for (int j = 0; j < 2; j++)
1014 anArcPoints[i][j] = getParameter(aPointOnArc.param[j]).val;
1017 // Radius of the arc
1018 std::shared_ptr<GeomAPI_Pnt2d> aCenter(new GeomAPI_Pnt2d(anArcPoints[0][0], anArcPoints[0][1]));
1019 std::shared_ptr<GeomAPI_Pnt2d> aStart(new GeomAPI_Pnt2d(anArcPoints[1][0], anArcPoints[1][1]));
1020 double aRadius = aCenter->distance(aStart);
1022 // Update end point of the arc to be on a curve
1023 std::shared_ptr<GeomAPI_Pnt2d> anEnd(new GeomAPI_Pnt2d(anArcPoints[2][0], anArcPoints[2][1]));
1024 double aDistance = anEnd->distance(aCenter);
1025 std::shared_ptr<GeomAPI_XY> aDir = anEnd->xy()->decreased(aCenter->xy());
1026 if (aDistance < tolerance)
1027 aDir = aStart->xy()->decreased(aCenter->xy())->multiplied(-1.0);
1029 aDir = aDir->multiplied(aRadius / aDistance);
1030 double xy[2] = {aCenter->x() + aDir->x(), aCenter->y() + aDir->y()};
1031 const Slvs_Entity& aEndPoint = getEntity(theArc.point[2]);
1032 for (int i = 0; i < 2; i++) {
1033 Slvs_Param aParam = getParameter(aEndPoint.param[i]);
1035 updateParameter(aParam);
1038 std::list<Slvs_Entity>::iterator aPtIt = aPointsToFix.begin();
1039 for (; aNbPointsToFix > 0; aPtIt++, aNbPointsToFix--)
1040 fixPoint(*aPtIt, theCreated);
1043 // Fix radius of the arc
1044 bool isExists = false;
1045 std::vector<Slvs_Constraint>::iterator anIt = myConstraints.begin();
1046 for (; anIt != myConstraints.end() && !isExists; ++anIt)
1047 if (anIt->type == SLVS_C_DIAMETER && anIt->entityA == theArc.h)
1050 Slvs_Constraint aFixedR = Slvs_MakeConstraint(SLVS_E_UNKNOWN, theArc.group, SLVS_C_DIAMETER,
1051 theArc.wrkpl, aRadius * 2.0, SLVS_E_UNKNOWN, SLVS_E_UNKNOWN, theArc.h, SLVS_E_UNKNOWN);
1052 aFixedR.h = addConstraint(aFixedR);
1053 theCreated.push_back(aFixedR.h);
1059 bool SketchSolver_Storage::isAxisParallel(const Slvs_hEntity& theEntity) const
1061 std::vector<Slvs_Constraint>::const_iterator anIter = myConstraints.begin();
1062 for (; anIter != myConstraints.end(); anIter++)
1063 if ((anIter->type == SLVS_C_HORIZONTAL || anIter->type == SLVS_C_VERTICAL) &&
1064 anIter->entityA == theEntity)
1069 bool SketchSolver_Storage::isUsedInEqual(
1070 const Slvs_hEntity& theEntity, Slvs_Constraint& theEqual) const
1072 // Check the entity is used in Equal constraint
1073 std::vector<Slvs_Constraint>::const_iterator anEqIter = myConstraints.begin();
1074 for (; anEqIter != myConstraints.end(); anEqIter++)
1075 if ((anEqIter->type == SLVS_C_EQUAL_LENGTH_LINES ||
1076 anEqIter->type == SLVS_C_EQUAL_LINE_ARC_LEN ||
1077 anEqIter->type == SLVS_C_EQUAL_RADIUS) &&
1078 (anEqIter->entityA == theEntity || anEqIter->entityB == theEntity)) {
1079 theEqual = *anEqIter;
1085 bool SketchSolver_Storage::isNeedToResolve()
1087 if (myConstraints.empty())
1090 if (!myNeedToResolve) {
1091 // Verify the updated parameters are used in constraints
1092 std::set<Slvs_hEntity> aPoints;
1093 std::vector<Slvs_Entity>::const_iterator anEntIt = myEntities.begin();
1094 for (; anEntIt != myEntities.end(); ++anEntIt) {
1095 for (int i = 0; i < 4 && anEntIt->param[i] != SLVS_E_UNKNOWN; ++i)
1096 if (myUpdatedParameters.find(anEntIt->param[i]) != myUpdatedParameters.end()) {
1097 aPoints.insert(anEntIt->h);
1101 std::set<Slvs_hEntity> anEntities = aPoints;
1102 for (anEntIt = myEntities.begin(); anEntIt != myEntities.end(); ++anEntIt) {
1103 for (int i = 0; i < 4 && anEntIt->point[i] != SLVS_E_UNKNOWN; ++i)
1104 if (aPoints.find(anEntIt->point[i]) != aPoints.end()) {
1105 anEntities.insert(anEntIt->h);
1110 std::vector<Slvs_Constraint>::const_iterator aCIt = myConstraints.begin();
1111 for (; aCIt != myConstraints.end() && !myNeedToResolve; ++aCIt) {
1112 Slvs_hEntity anAttrs[6] =
1113 {aCIt->ptA, aCIt->ptB, aCIt->entityA, aCIt->entityB, aCIt->entityC, aCIt->entityD};
1114 for (int i = 0; i < 6; i++)
1115 if (anAttrs[i] != SLVS_E_UNKNOWN && anEntities.find(anAttrs[i]) != anEntities.end()) {
1116 myNeedToResolve = true;
1122 myUpdatedParameters.clear();
1123 return myNeedToResolve;
1131 // ========================================================
1132 // ========= Auxiliary functions ===============
1133 // ========================================================
1135 template<typename T>
1136 int Search(const uint32_t& theEntityID, const std::vector<T>& theEntities)
1138 int aResIndex = theEntityID <= theEntities.size() ? theEntityID - 1 : 0;
1139 int aVecSize = theEntities.size();
1140 if (theEntities.empty())
1142 while (aResIndex >= 0 && theEntities[aResIndex].h > theEntityID)
1144 while (aResIndex < aVecSize && aResIndex >= 0 && theEntities[aResIndex].h < theEntityID)
1146 if (aResIndex == -1 || (aResIndex < aVecSize && theEntities[aResIndex].h != theEntityID))
1147 aResIndex = aVecSize;
1151 bool IsNotEqual(const Slvs_Param& theParam1, const Slvs_Param& theParam2)
1153 return fabs(theParam1.val - theParam2.val) > tolerance;
1156 bool IsNotEqual(const Slvs_Entity& theEntity1, const Slvs_Entity& theEntity2)
1159 for (; theEntity1.param[i] != 0 && i < 4; i++)
1160 if (theEntity1.param[i] != theEntity2.param[i])
1163 for (; theEntity1.point[i] != 0 && i < 4; i++)
1164 if (theEntity1.point[i] != theEntity2.point[i])
1169 bool IsNotEqual(const Slvs_Constraint& theConstraint1, const Slvs_Constraint& theConstraint2)
1171 return theConstraint1.ptA != theConstraint2.ptA ||
1172 theConstraint1.ptB != theConstraint2.ptB ||
1173 theConstraint1.entityA != theConstraint2.entityA ||
1174 theConstraint1.entityB != theConstraint2.entityB ||
1175 theConstraint1.entityC != theConstraint2.entityC ||
1176 theConstraint1.entityD != theConstraint2.entityD ||
1177 fabs(theConstraint1.valA - theConstraint2.valA) > tolerance;