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