Salome HOME
Issue #567: Wrong result during mirror on different lines
[modules/shaper.git] / src / SketchSolver / SketchSolver_Group.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:    SketchSolver_Group.cpp
4 // Created: 27 May 2014
5 // Author:  Artem ZHIDKOV
6
7 #include "SketchSolver_Group.h"
8
9 #include <SketchSolver_Builder.h>
10 #include <SketchSolver_Constraint.h>
11 #include <SketchSolver_ConstraintCoincidence.h>
12 #include <SketchSolver_Error.h>
13
14 #include <Events_Error.h>
15 #include <Events_Loop.h>
16 #include <GeomAPI_XY.h>
17 #include <GeomAPI_Dir2d.h>
18 #include <GeomAPI_Pnt2d.h>
19 #include <GeomDataAPI_Dir.h>
20 #include <GeomDataAPI_Point.h>
21 #include <GeomDataAPI_Point2D.h>
22 #include <ModelAPI_AttributeDouble.h>
23 #include <ModelAPI_Document.h>
24 #include <ModelAPI_Events.h>
25 #include <ModelAPI_ResultConstruction.h>
26
27 #include <SketchPlugin_Constraint.h>
28 #include <SketchPlugin_ConstraintEqual.h>
29 #include <SketchPlugin_ConstraintFillet.h>
30 #include <SketchPlugin_ConstraintLength.h>
31 #include <SketchPlugin_ConstraintCoincidence.h>
32 #include <SketchPlugin_ConstraintMirror.h>
33 #include <SketchPlugin_ConstraintRigid.h>
34 #include <SketchPlugin_ConstraintTangent.h>
35 #include <SketchPlugin_Feature.h>
36
37 #include <SketchPlugin_Arc.h>
38 #include <SketchPlugin_Circle.h>
39 #include <SketchPlugin_Line.h>
40 #include <SketchPlugin_Point.h>
41 #include <SketchPlugin_Sketch.h>
42
43 #include <math.h>
44 #include <assert.h>
45
46
47 /// \brief This class is used to give unique index to the groups
48 class GroupIndexer
49 {
50 public:
51   /// \brief Return vacant index
52   static Slvs_hGroup NEW_GROUP() { return ++myGroupIndex; }
53   /// \brief Removes the index
54   static void REMOVE_GROUP(const Slvs_hGroup& theIndex) {
55     if (myGroupIndex == theIndex)
56       myGroupIndex--;
57   }
58
59 private:
60   GroupIndexer() {};
61
62   static Slvs_hGroup myGroupIndex; ///< index of the group
63 };
64
65 Slvs_hGroup GroupIndexer::myGroupIndex = 0;
66
67
68
69 // ========================================================
70 // =========  SketchSolver_Group  ===============
71 // ========================================================
72
73 SketchSolver_Group::SketchSolver_Group(
74     std::shared_ptr<ModelAPI_CompositeFeature> theWorkplane)
75     : myID(GroupIndexer::NEW_GROUP())
76 {
77   // Initialize workplane
78   myWorkplaneID = SLVS_E_UNKNOWN;
79 #ifndef NDEBUG
80   assert(addWorkplane(theWorkplane));
81 #else
82   addWorkplane(theWorkplane);
83 #endif
84 }
85
86 SketchSolver_Group::~SketchSolver_Group()
87 {
88   myConstraints.clear();
89   GroupIndexer::REMOVE_GROUP(myID);
90 }
91
92 // ============================================================================
93 //  Function: isBaseWorkplane
94 //  Class:    SketchSolver_Group
95 //  Purpose:  verify the group is based on the given workplane
96 // ============================================================================
97 bool SketchSolver_Group::isBaseWorkplane(CompositeFeaturePtr theWorkplane) const
98 {
99   return theWorkplane == mySketch;
100 }
101
102 // ============================================================================
103 //  Function: isInteract
104 //  Class:    SketchSolver_Group
105 //  Purpose:  verify are there any entities in the group used by given constraint
106 // ============================================================================
107 bool SketchSolver_Group::isInteract(
108     std::shared_ptr<SketchPlugin_Feature> theFeature) const
109 {
110   // Empty group interacts with everything
111   if (isEmpty()) return true;
112   ConstraintPtr aConstraint = std::dynamic_pointer_cast<SketchPlugin_Constraint>(theFeature);
113   if (aConstraint)
114     return myFeatureStorage->isInteract(aConstraint);
115   return myFeatureStorage->isInteract(std::dynamic_pointer_cast<ModelAPI_Feature>(theFeature));
116 }
117
118 // ============================================================================
119 //  Function: getFeatureId
120 //  Class:    SketchSolver_Group
121 //  Purpose:  Find the identifier of the feature, if it already exists in the group
122 // ============================================================================
123 Slvs_hEntity SketchSolver_Group::getFeatureId(FeaturePtr theFeature) const
124 {
125   Slvs_hEntity aResult = SLVS_E_UNKNOWN;
126   if (!myFeatureStorage)
127     return aResult;
128   std::set<ConstraintPtr> aConstraints = myFeatureStorage->getConstraints(theFeature);
129   if (aConstraints.empty())
130     return aResult;
131   std::set<ConstraintPtr>::iterator aConstrIter = aConstraints.begin();
132   for (; aConstrIter != aConstraints.end(); aConstrIter++) {
133     ConstraintConstraintMap::const_iterator aCIter = myConstraints.find(*aConstrIter);
134     if (aCIter == myConstraints.end())
135       continue;
136     aResult = aCIter->second->getId(theFeature);
137     if (aResult != SLVS_E_UNKNOWN)
138       return aResult;
139   }
140   return SLVS_E_UNKNOWN;
141 }
142
143 // ============================================================================
144 //  Function: getAttributeId
145 //  Class:    SketchSolver_Group
146 //  Purpose:  Find the identifier of the attribute, if it already exists in the group
147 // ============================================================================
148 Slvs_hEntity SketchSolver_Group::getAttributeId(AttributePtr theAttribute) const
149 {
150   Slvs_hEntity aResult = SLVS_E_UNKNOWN;
151   if (!myFeatureStorage)
152     return aResult;
153   std::set<ConstraintPtr> aConstraints = myFeatureStorage->getConstraints(theAttribute);
154   if (aConstraints.empty())
155     return aResult;
156   std::set<ConstraintPtr>::iterator aConstrIter = aConstraints.begin();
157   for (; aConstrIter != aConstraints.end(); aConstrIter++) {
158     ConstraintConstraintMap::const_iterator aCIter = myConstraints.find(*aConstrIter);
159     if (aCIter == myConstraints.end())
160       continue;
161     aResult = aCIter->second->getId(theAttribute);
162     if (aResult != SLVS_E_UNKNOWN)
163       return aResult;
164   }
165   return SLVS_E_UNKNOWN;
166 }
167
168 // ============================================================================
169 //  Function: changeConstraint
170 //  Class:    SketchSolver_Group
171 //  Purpose:  create/update the constraint in the group
172 // ============================================================================
173 bool SketchSolver_Group::changeConstraint(
174     std::shared_ptr<SketchPlugin_Constraint> theConstraint)
175 {
176   // There is no workplane yet, something wrong
177   if (myWorkplaneID == SLVS_E_UNKNOWN)
178     return false;
179
180   if (!theConstraint)
181     return false;
182
183   bool isNewConstraint = myConstraints.find(theConstraint) == myConstraints.end();
184   if (isNewConstraint) {
185     // Add constraint to the current group
186     SolverConstraintPtr aConstraint =
187         SketchSolver_Builder::getInstance()->createConstraint(theConstraint);
188     if (!aConstraint)
189       return false;
190     aConstraint->setGroup(this);
191     aConstraint->setStorage(myStorage);
192     if (!aConstraint->error().empty()) {
193       if (aConstraint->error() == SketchSolver_Error::NOT_INITIALIZED())
194         return false; // some attribute are not initialized yet, don't show message
195       Events_Error::send(aConstraint->error(), this);
196     }
197
198     // Additional verification of coincidence of several points
199     if (theConstraint->getKind() == SketchPlugin_ConstraintCoincidence::ID()) {
200       ConstraintConstraintMap::iterator aCIter = myConstraints.begin();
201       for (; aCIter != myConstraints.end(); aCIter++) {
202         std::shared_ptr<SketchSolver_ConstraintCoincidence> aCoincidence =
203           std::dynamic_pointer_cast<SketchSolver_ConstraintCoincidence>(aCIter->second);
204         if (!aCoincidence)
205           continue;
206         std::shared_ptr<SketchSolver_ConstraintCoincidence> aCoinc2 =
207           std::dynamic_pointer_cast<SketchSolver_ConstraintCoincidence>(aConstraint);
208         if (aCoincidence != aCoinc2 && aCoincidence->isCoincide(aCoinc2)) {
209           aCoincidence->attach(aCoinc2);
210           aConstraint = aCoincidence;
211         }
212       }
213     }
214     myConstraints[theConstraint] = aConstraint;
215   }
216   else
217     myConstraints[theConstraint]->update();
218
219   // Fix base features for fillet
220   if (isNewConstraint && theConstraint->getKind() == SketchPlugin_ConstraintFillet::ID()) {
221     std::list<AttributePtr> anAttrList =
222         theConstraint->data()->attributes(ModelAPI_AttributeRefAttr::typeId());
223     std::list<AttributePtr>::iterator anAttrIter = anAttrList.begin();
224     for (; anAttrIter != anAttrList.end(); anAttrIter++) {
225       AttributeRefAttrPtr aRefAttr =
226           std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttrIter);
227       if (!aRefAttr || !aRefAttr->isObject())
228         continue;
229       FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
230       SolverConstraintPtr aConstraint =
231           SketchSolver_Builder::getInstance()->createRigidConstraint(aFeature);
232       if (!aConstraint)
233         continue;
234       aConstraint->setGroup(this);
235       aConstraint->setStorage(myStorage);
236       setTemporary(aConstraint);
237     }
238   }
239   // Fix mirror line
240   if (theConstraint->getKind() == SketchPlugin_ConstraintMirror::ID()) {
241     AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
242         theConstraint->attribute(SketchPlugin_ConstraintMirror::ENTITY_A()));
243     if (aRefAttr && aRefAttr->isObject()) {
244       FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
245       if (aFeature) {
246         SolverConstraintPtr aConstraint =
247             SketchSolver_Builder::getInstance()->createRigidConstraint(aFeature);
248         if (aConstraint) {
249           aConstraint->setGroup(this);
250           aConstraint->setStorage(myStorage);
251           setTemporary(aConstraint);
252         }
253       }
254     }
255   }
256
257   if (!myFeatureStorage)
258     myFeatureStorage = FeatureStoragePtr(new SketchSolver_FeatureStorage);
259   myFeatureStorage->changeConstraint(theConstraint);
260
261   return true;
262 }
263
264
265 bool SketchSolver_Group::updateFeature(std::shared_ptr<SketchPlugin_Feature> theFeature)
266 {
267   std::set<ConstraintPtr> aConstraints =
268       myFeatureStorage->getConstraints(std::dynamic_pointer_cast<ModelAPI_Feature>(theFeature));
269   if (aConstraints.empty())
270     return false;
271   std::set<ConstraintPtr>::iterator aCIter = aConstraints.begin();
272   for (; aCIter != aConstraints.end(); aCIter++) {
273     ConstraintConstraintMap::iterator aSolConIter = myConstraints.find(*aCIter);
274     if (aSolConIter == myConstraints.end() || !aSolConIter->first->data() ||
275         !aSolConIter->first->data()->isValid())
276       continue;
277     myFeatureStorage->changeFeature(theFeature, aSolConIter->first);
278     aSolConIter->second->addFeature(theFeature);
279     aSolConIter->second->update();
280   }
281   return true;
282 }
283
284 void SketchSolver_Group::moveFeature(std::shared_ptr<SketchPlugin_Feature> theFeature)
285 {
286   // Firstly, create temporary rigid constraint
287   SolverConstraintPtr aConstraint =
288       SketchSolver_Builder::getInstance()->createRigidConstraint(theFeature);
289   if (!aConstraint)
290     return;
291   aConstraint->setGroup(this);
292   aConstraint->setStorage(myStorage);
293   if (aConstraint->error().empty())
294     setTemporary(aConstraint);
295   // Secondly, update the feature
296   updateFeature(theFeature);
297 }
298
299 // ============================================================================
300 //  Function: fixFeaturesList
301 //  Class:    SketchSolver_Group
302 //  Purpose:  Apply temporary rigid constraints for the list of features
303 // ============================================================================
304 void SketchSolver_Group::fixFeaturesList(AttributeRefListPtr theList)
305 {
306   std::list<ObjectPtr> aList = theList->list();
307   std::list<ObjectPtr>::iterator anIt = aList.begin();
308   std::list<FeaturePtr> aFeatures;
309   // Sort features, at begining there are features used by Equal constraint
310   for (; anIt != aList.end(); anIt++) {
311     if (!(*anIt))
312       continue;
313     FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
314     std::set<ConstraintPtr> aConstraints = myFeatureStorage->getConstraints(aFeature);
315     std::set<ConstraintPtr>::iterator aCIter = aConstraints.begin();
316     for (; aCIter != aConstraints.end(); aCIter++)
317       if ((*aCIter)->getKind() == SketchPlugin_ConstraintEqual::ID())
318         break;
319     if (aCIter != aConstraints.end())
320       aFeatures.push_front(aFeature);
321     else
322       aFeatures.push_back(aFeature);
323   }
324
325   std::list<FeaturePtr>::iterator aFeatIter = aFeatures.begin();
326   for (; aFeatIter != aFeatures.end(); aFeatIter++) {
327     SolverConstraintPtr aConstraint =
328         SketchSolver_Builder::getInstance()->createRigidConstraint(*aFeatIter);
329     if (!aConstraint)
330       continue;
331     aConstraint->setGroup(this);
332     aConstraint->setStorage(myStorage);
333     setTemporary(aConstraint);
334   }
335 }
336
337 // ============================================================================
338 //  Function: addWorkplane
339 //  Class:    SketchSolver_Group
340 //  Purpose:  create workplane for the group
341 // ============================================================================
342 bool SketchSolver_Group::addWorkplane(CompositeFeaturePtr theSketch)
343 {
344   if (myWorkplaneID != SLVS_E_UNKNOWN || theSketch->getKind() != SketchPlugin_Sketch::ID())
345     return false;  // the workplane already exists or the function parameter is not Sketch
346
347   mySketch = theSketch;
348   updateWorkplane();
349   return true;
350 }
351
352 // ============================================================================
353 //  Function: updateWorkplane
354 //  Class:    SketchSolver_Group
355 //  Purpose:  update parameters of workplane
356 // ============================================================================
357 bool SketchSolver_Group::updateWorkplane()
358 {
359   if (!myStorage) // Create storage if not exists
360     myStorage = StoragePtr(new SketchSolver_Storage);
361   SketchSolver_Builder* aBuilder = SketchSolver_Builder::getInstance();
362
363   std::vector<Slvs_Entity> anEntities;
364   std::vector<Slvs_Param> aParams;
365   if (!aBuilder->createWorkplane(mySketch, anEntities, aParams))
366     return false;
367
368   if (myWorkplaneID == SLVS_E_UNKNOWN) {
369     myWorkplaneID = anEntities.back().h;
370     // Add new workplane elements
371     std::vector<Slvs_Param>::iterator aParIter = aParams.begin();
372     for (; aParIter != aParams.end(); aParIter++) {
373       aParIter->h = SLVS_E_UNKNOWN; // the ID should be generated by storage
374       aParIter->group = myID;
375       aParIter->h = myStorage->addParameter(*aParIter);
376     }
377     std::vector<Slvs_Entity>::iterator anEntIter = anEntities.begin();
378     for (; anEntIter != anEntities.end(); anEntIter++) {
379       anEntIter->h = SLVS_E_UNKNOWN; // the ID should be generated by storage
380       anEntIter->group = myID;
381       anEntIter->wrkpl = myWorkplaneID;
382       for (int i = 0; i < 4; i++)
383         if (anEntIter->param[i] != SLVS_E_UNKNOWN)
384           anEntIter->param[i] = aParams[anEntIter->param[i]-1].h;
385       for (int i = 0; i < 4; i++)
386         if (anEntIter->point[i] != SLVS_E_UNKNOWN)
387           anEntIter->point[i] = anEntities[anEntIter->point[i]-1].h;
388       anEntIter->h = myStorage->addEntity(*anEntIter);
389     }
390   } else {
391     // Update existent workplane
392     const Slvs_Entity& aWP = myStorage->getEntity(myWorkplaneID);
393     const Slvs_Entity& anOrigin = myStorage->getEntity(aWP.point[0]);
394     const Slvs_Entity& aNormal = myStorage->getEntity(aWP.normal);
395     // Get parameters and update them
396     Slvs_hParam aWPParams[7] = {
397         anOrigin.param[0], anOrigin.param[1], anOrigin.param[2],
398         aNormal.param[0], aNormal.param[1], aNormal.param[2], aNormal.param[3]
399       };
400     std::vector<Slvs_Param>::iterator aParIter = aParams.begin();
401     for (int i = 0; aParIter != aParams.end(); aParIter++, i++) {
402       Slvs_Param aParam = myStorage->getParameter(aWPParams[i]);
403       aParam.val = aParIter->val;
404       myStorage->updateParameter(aParam);
405     }
406   }
407   return myWorkplaneID > 0;
408 }
409
410 // ============================================================================
411 //  Function: resolveConstraints
412 //  Class:    SketchSolver_Group
413 //  Purpose:  solve the set of constraints for the current group
414 // ============================================================================
415 bool SketchSolver_Group::resolveConstraints()
416 {
417   bool aResolved = false;
418   if (myStorage->isNeedToResolve() && !isEmpty()) {
419     myConstrSolver.setGroupID(myID);
420     myStorage->initializeSolver(myConstrSolver);
421
422     int aResult = SLVS_RESULT_OKAY;
423     try {
424       if (myStorage->hasDuplicatedConstraint())
425         aResult = SLVS_RESULT_INCONSISTENT;
426       else {
427         // To avoid overconstraint situation, we will remove temporary constraints one-by-one
428         // and try to find the case without overconstraint
429         int aNbTemp = myStorage->numberTemporary();
430         while (true) {
431           aResult = myConstrSolver.solve();
432           if (aResult == SLVS_RESULT_OKAY || aNbTemp <= 0)
433             break;
434           aNbTemp = myStorage->deleteTemporaryConstraint();
435           myStorage->initializeSolver(myConstrSolver);
436         }
437       }
438     } catch (...) {
439       Events_Error::send(SketchSolver_Error::SOLVESPACE_CRASH(), this);
440       return false;
441     }
442     if (aResult == SLVS_RESULT_OKAY) {  // solution succeeded, store results into correspondent attributes
443       myFeatureStorage->blockEvents(true);
444       ConstraintConstraintMap::iterator aConstrIter = myConstraints.begin();
445       for (; aConstrIter != myConstraints.end(); aConstrIter++)
446         aConstrIter->second->refresh();
447       myFeatureStorage->blockEvents(false);
448     } else if (!myConstraints.empty())
449       Events_Error::send(SketchSolver_Error::CONSTRAINTS(), this);
450
451     aResolved = true;
452   }
453   removeTemporaryConstraints();
454   myStorage->setNeedToResolve(false);
455   return aResolved;
456 }
457
458 // ============================================================================
459 //  Function: mergeGroups
460 //  Class:    SketchSolver_Group
461 //  Purpose:  append specified group to the current group
462 // ============================================================================
463 void SketchSolver_Group::mergeGroups(const SketchSolver_Group& theGroup)
464 {
465   // If specified group is empty, no need to merge
466   if (theGroup.isEmpty())
467     return;
468   if (!myFeatureStorage)
469     myFeatureStorage = FeatureStoragePtr(new SketchSolver_FeatureStorage);
470
471   std::vector<ConstraintPtr> aComplexConstraints;
472   ConstraintConstraintMap::const_iterator aConstrIter = theGroup.myConstraints.begin();
473   // append simple constraints
474   for (; aConstrIter != theGroup.myConstraints.end(); aConstrIter++)
475     if (isComplexConstraint(aConstrIter->first))
476       aComplexConstraints.push_back(aConstrIter->first);
477     else
478       changeConstraint(aConstrIter->first);
479   // append complex constraints
480   std::vector<ConstraintPtr>::iterator aComplexIter = aComplexConstraints.begin();
481   for (; aComplexIter != aComplexConstraints.end(); aComplexIter++)
482       changeConstraint(*aComplexIter);
483 }
484
485 // ============================================================================
486 //  Function: splitGroup
487 //  Class:    SketchSolver_Group
488 //  Purpose:  divide the group into several subgroups
489 // ============================================================================
490 void SketchSolver_Group::splitGroup(std::vector<SketchSolver_Group*>& theCuts)
491 {
492   // Obtain constraints, which should be separated
493   FeatureStoragePtr aNewFeatStorage(new SketchSolver_FeatureStorage);
494   std::vector<ConstraintPtr> anUnusedConstraints;
495   ConstraintConstraintMap::iterator aCIter = myConstraints.begin();
496   for ( ; aCIter != myConstraints.end(); aCIter++) {
497     std::list<ConstraintPtr> aBaseConstraints = aCIter->second->constraints();
498     std::list<ConstraintPtr>::iterator anIter = aBaseConstraints.begin();
499     for (; anIter != aBaseConstraints.end(); anIter++)
500       if (aNewFeatStorage->isInteract(*anIter)) {
501         aNewFeatStorage->changeConstraint(*anIter);
502       } else
503         anUnusedConstraints.push_back(*anIter);
504   }
505
506   // Check the unused constraints once again, because they may become interacted with new storage since adding constraints
507   std::vector<ConstraintPtr>::iterator aUnuseIt = anUnusedConstraints.begin();
508   while (aUnuseIt != anUnusedConstraints.end()) {
509     if (aNewFeatStorage->isInteract(*aUnuseIt)) {
510       size_t aShift = aUnuseIt - anUnusedConstraints.begin();
511       anUnusedConstraints.erase(aUnuseIt);
512       aUnuseIt = anUnusedConstraints.begin() + aShift;
513       continue;
514     }
515     aUnuseIt++;
516   }
517
518   std::vector<SketchSolver_Group*>::iterator aCutsIter;
519   aUnuseIt = anUnusedConstraints.begin();
520   for ( ; aUnuseIt != anUnusedConstraints.end(); aUnuseIt++) {
521     // Remove unused constraints
522     removeConstraint(*aUnuseIt);
523     // Try to append constraint to already existent group
524     for (aCutsIter = theCuts.begin(); aCutsIter != theCuts.end(); aCutsIter++)
525       if ((*aCutsIter)->isInteract(*aUnuseIt)) {
526         (*aCutsIter)->changeConstraint(*aUnuseIt);
527         break;
528       }
529     if (aCutsIter == theCuts.end()) {
530       // Add new group
531       SketchSolver_Group* aGroup = new SketchSolver_Group(mySketch);
532       aGroup->changeConstraint(*aUnuseIt);
533       theCuts.push_back(aGroup);
534     }
535   }
536 }
537
538 // ============================================================================
539 //  Function: isConsistent
540 //  Class:    SketchSolver_Group
541 //  Purpose:  search removed entities and constraints
542 // ============================================================================
543 bool SketchSolver_Group::isConsistent()
544 {
545   if (!myFeatureStorage) // no one constraint is initialized yet
546     return true;
547
548   bool aResult = myFeatureStorage->isConsistent();
549   if (!aResult) {
550     // remove invalid entities
551     ConstraintConstraintMap::iterator aCIter = myConstraints.begin();
552     while (aCIter != myConstraints.end()) {
553       std::list<ConstraintPtr> aConstraints = aCIter->second->constraints();
554       std::list<ConstraintPtr>::iterator anIt = aConstraints.begin();
555       for (; anIt != aConstraints.end(); anIt++)
556         if (!(*anIt)->data() || !(*anIt)->data()->isValid())
557           if (aCIter->second->remove(*anIt)) {
558             // the constraint is fully removed, detach it from the list
559             ConstraintConstraintMap::iterator aTmpIt = aCIter++;
560             myFeatureStorage->removeConstraint(aTmpIt->first);
561             myConstraints.erase(aTmpIt);
562             break;
563           }
564       if (anIt == aConstraints.end())
565         aCIter++;
566     }
567   }
568   return aResult;
569 }
570
571 // ============================================================================
572 //  Function: removeTemporaryConstraints
573 //  Class:    SketchSolver_Group
574 //  Purpose:  remove all transient SLVS_C_WHERE_DRAGGED constraints after
575 //            resolving the set of constraints
576 // ============================================================================
577 void SketchSolver_Group::removeTemporaryConstraints()
578 {
579   myTempConstraints.clear();
580   while (myStorage->numberTemporary())
581     myStorage->deleteTemporaryConstraint();
582   // Clean lists of removed entities in the storage
583   std::set<Slvs_hParam> aRemPar;
584   std::set<Slvs_hEntity> aRemEnt;
585   std::set<Slvs_hConstraint> aRemCon;
586   myStorage->getRemoved(aRemPar, aRemEnt, aRemCon);
587   myStorage->setNeedToResolve(false);
588 }
589
590 // ============================================================================
591 //  Function: removeConstraint
592 //  Class:    SketchSolver_Group
593 //  Purpose:  remove constraint and all unused entities
594 // ============================================================================
595 void SketchSolver_Group::removeConstraint(ConstraintPtr theConstraint)
596 {
597   myFeatureStorage->removeConstraint(theConstraint);
598   ConstraintConstraintMap::iterator aCIter = myConstraints.begin();
599   for (; aCIter != myConstraints.end(); aCIter++)
600     if (aCIter->second->hasConstraint(theConstraint)) {
601       if (!aCIter->second->remove(theConstraint)) // the constraint is not fully removed
602         aCIter = myConstraints.end();
603       break;
604     }
605   if (aCIter != myConstraints.end())
606     myConstraints.erase(aCIter);
607 }
608
609 // ============================================================================
610 //  Function: isComplexConstraint
611 //  Class:    SketchSolver_Group
612 //  Purpose:  verifies the constraint is complex, i.e. it needs another constraints to be created before
613 // ============================================================================
614 bool SketchSolver_Group::isComplexConstraint(FeaturePtr theConstraint)
615 {
616   return theConstraint->getKind() == SketchPlugin_ConstraintFillet::ID() ||
617          theConstraint->getKind() == SketchPlugin_ConstraintMirror::ID() ||
618          theConstraint->getKind() == SketchPlugin_ConstraintTangent::ID();
619 }
620
621 // ============================================================================
622 //  Function: setTemporary
623 //  Class:    SketchSolver_Group
624 //  Purpose:  append given constraint to th group of temporary constraints
625 // ============================================================================
626 void SketchSolver_Group::setTemporary(SolverConstraintPtr theConstraint)
627 {
628   theConstraint->makeTemporary();
629   myTempConstraints.insert(theConstraint);
630 }
631