Salome HOME
794eb1a3f355ec24bee87d9065ff3c69cf2cf186
[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       SolverConstraintPtr aConstraint =
246           SketchSolver_Builder::getInstance()->createRigidConstraint(aFeature);
247       if (aConstraint) {
248         aConstraint->setGroup(this);
249         aConstraint->setStorage(myStorage);
250         setTemporary(aConstraint);
251       }
252     }
253   }
254
255   if (!myFeatureStorage)
256     myFeatureStorage = FeatureStoragePtr(new SketchSolver_FeatureStorage);
257   myFeatureStorage->changeConstraint(theConstraint);
258
259   return true;
260 }
261
262
263 bool SketchSolver_Group::updateFeature(std::shared_ptr<SketchPlugin_Feature> theFeature)
264 {
265   std::set<ConstraintPtr> aConstraints =
266       myFeatureStorage->getConstraints(std::dynamic_pointer_cast<ModelAPI_Feature>(theFeature));
267   if (aConstraints.empty())
268     return false;
269   std::set<ConstraintPtr>::iterator aCIter = aConstraints.begin();
270   for (; aCIter != aConstraints.end(); aCIter++) {
271     ConstraintConstraintMap::iterator aSolConIter = myConstraints.find(*aCIter);
272     if (aSolConIter == myConstraints.end() || !aSolConIter->first->data() ||
273         !aSolConIter->first->data()->isValid())
274       continue;
275     myFeatureStorage->changeFeature(theFeature, aSolConIter->first);
276     aSolConIter->second->addFeature(theFeature);
277     aSolConIter->second->update();
278   }
279   return true;
280 }
281
282 void SketchSolver_Group::moveFeature(std::shared_ptr<SketchPlugin_Feature> theFeature)
283 {
284   // Firstly, create temporary rigid constraint
285   SolverConstraintPtr aConstraint =
286       SketchSolver_Builder::getInstance()->createRigidConstraint(theFeature);
287   if (!aConstraint)
288     return;
289   aConstraint->setGroup(this);
290   aConstraint->setStorage(myStorage);
291   if (aConstraint->error().empty())
292     setTemporary(aConstraint);
293   // Secondly, update the feature
294   updateFeature(theFeature);
295 }
296
297 // ============================================================================
298 //  Function: fixFeaturesList
299 //  Class:    SketchSolver_Group
300 //  Purpose:  Apply temporary rigid constraints for the list of features
301 // ============================================================================
302 void SketchSolver_Group::fixFeaturesList(AttributeRefListPtr theList)
303 {
304   std::list<ObjectPtr> aList = theList->list();
305   std::list<ObjectPtr>::iterator anIt = aList.begin();
306   std::list<FeaturePtr> aFeatures;
307   // Sort features, at begining there are features used by Equal constraint
308   for (; anIt != aList.end(); anIt++) {
309     if (!(*anIt))
310       continue;
311     FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
312     std::set<ConstraintPtr> aConstraints = myFeatureStorage->getConstraints(aFeature);
313     std::set<ConstraintPtr>::iterator aCIter = aConstraints.begin();
314     for (; aCIter != aConstraints.end(); aCIter++)
315       if ((*aCIter)->getKind() == SketchPlugin_ConstraintEqual::ID())
316         break;
317     if (aCIter != aConstraints.end())
318       aFeatures.push_front(aFeature);
319     else
320       aFeatures.push_back(aFeature);
321   }
322
323   std::list<FeaturePtr>::iterator aFeatIter = aFeatures.begin();
324   for (; aFeatIter != aFeatures.end(); aFeatIter++) {
325     SolverConstraintPtr aConstraint =
326         SketchSolver_Builder::getInstance()->createRigidConstraint(*aFeatIter);
327     if (!aConstraint)
328       continue;
329     aConstraint->setGroup(this);
330     aConstraint->setStorage(myStorage);
331     setTemporary(aConstraint);
332   }
333 }
334
335 // ============================================================================
336 //  Function: addWorkplane
337 //  Class:    SketchSolver_Group
338 //  Purpose:  create workplane for the group
339 // ============================================================================
340 bool SketchSolver_Group::addWorkplane(CompositeFeaturePtr theSketch)
341 {
342   if (myWorkplaneID != SLVS_E_UNKNOWN || theSketch->getKind() != SketchPlugin_Sketch::ID())
343     return false;  // the workplane already exists or the function parameter is not Sketch
344
345   mySketch = theSketch;
346   updateWorkplane();
347   return true;
348 }
349
350 // ============================================================================
351 //  Function: updateWorkplane
352 //  Class:    SketchSolver_Group
353 //  Purpose:  update parameters of workplane
354 // ============================================================================
355 bool SketchSolver_Group::updateWorkplane()
356 {
357   if (!myStorage) // Create storage if not exists
358     myStorage = StoragePtr(new SketchSolver_Storage);
359   SketchSolver_Builder* aBuilder = SketchSolver_Builder::getInstance();
360
361   std::vector<Slvs_Entity> anEntities;
362   std::vector<Slvs_Param> aParams;
363   if (!aBuilder->createWorkplane(mySketch, anEntities, aParams))
364     return false;
365
366   if (myWorkplaneID == SLVS_E_UNKNOWN) {
367     myWorkplaneID = anEntities.back().h;
368     // Add new workplane elements
369     std::vector<Slvs_Param>::iterator aParIter = aParams.begin();
370     for (; aParIter != aParams.end(); aParIter++) {
371       aParIter->h = SLVS_E_UNKNOWN; // the ID should be generated by storage
372       aParIter->group = myID;
373       aParIter->h = myStorage->addParameter(*aParIter);
374     }
375     std::vector<Slvs_Entity>::iterator anEntIter = anEntities.begin();
376     for (; anEntIter != anEntities.end(); anEntIter++) {
377       anEntIter->h = SLVS_E_UNKNOWN; // the ID should be generated by storage
378       anEntIter->group = myID;
379       anEntIter->wrkpl = myWorkplaneID;
380       for (int i = 0; i < 4; i++)
381         if (anEntIter->param[i] != SLVS_E_UNKNOWN)
382           anEntIter->param[i] = aParams[anEntIter->param[i]-1].h;
383       for (int i = 0; i < 4; i++)
384         if (anEntIter->point[i] != SLVS_E_UNKNOWN)
385           anEntIter->point[i] = anEntities[anEntIter->point[i]-1].h;
386       anEntIter->h = myStorage->addEntity(*anEntIter);
387     }
388   } else {
389     // Update existent workplane
390     const Slvs_Entity& aWP = myStorage->getEntity(myWorkplaneID);
391     const Slvs_Entity& anOrigin = myStorage->getEntity(aWP.point[0]);
392     const Slvs_Entity& aNormal = myStorage->getEntity(aWP.normal);
393     // Get parameters and update them
394     Slvs_hParam aWPParams[7] = {
395         anOrigin.param[0], anOrigin.param[1], anOrigin.param[2],
396         aNormal.param[0], aNormal.param[1], aNormal.param[2], aNormal.param[3]
397       };
398     std::vector<Slvs_Param>::iterator aParIter = aParams.begin();
399     for (int i = 0; aParIter != aParams.end(); aParIter++, i++) {
400       Slvs_Param aParam = myStorage->getParameter(aWPParams[i]);
401       aParam.val = aParIter->val;
402       myStorage->updateParameter(aParam);
403     }
404   }
405   return myWorkplaneID > 0;
406 }
407
408 // ============================================================================
409 //  Function: resolveConstraints
410 //  Class:    SketchSolver_Group
411 //  Purpose:  solve the set of constraints for the current group
412 // ============================================================================
413 bool SketchSolver_Group::resolveConstraints()
414 {
415   bool aResolved = false;
416   if (myStorage->isNeedToResolve() && !isEmpty()) {
417     myConstrSolver.setGroupID(myID);
418     myStorage->initializeSolver(myConstrSolver);
419
420     int aResult = SLVS_RESULT_OKAY;
421     try {
422       if (myStorage->hasDuplicatedConstraint())
423         aResult = SLVS_RESULT_INCONSISTENT;
424       else {
425         // To avoid overconstraint situation, we will remove temporary constraints one-by-one
426         // and try to find the case without overconstraint
427         int aNbTemp = myStorage->numberTemporary();
428         while (true) {
429           aResult = myConstrSolver.solve();
430           if (aResult == SLVS_RESULT_OKAY || aNbTemp <= 0)
431             break;
432           aNbTemp = myStorage->deleteTemporaryConstraint();
433           myStorage->initializeSolver(myConstrSolver);
434         }
435       }
436     } catch (...) {
437       Events_Error::send(SketchSolver_Error::SOLVESPACE_CRASH(), this);
438       return false;
439     }
440     if (aResult == SLVS_RESULT_OKAY) {  // solution succeeded, store results into correspondent attributes
441       myFeatureStorage->blockEvents(true);
442       ConstraintConstraintMap::iterator aConstrIter = myConstraints.begin();
443       for (; aConstrIter != myConstraints.end(); aConstrIter++)
444         aConstrIter->second->refresh();
445       myFeatureStorage->blockEvents(false);
446     } else if (!myConstraints.empty())
447       Events_Error::send(SketchSolver_Error::CONSTRAINTS(), this);
448
449     aResolved = true;
450   }
451   removeTemporaryConstraints();
452   myStorage->setNeedToResolve(false);
453   return aResolved;
454 }
455
456 // ============================================================================
457 //  Function: mergeGroups
458 //  Class:    SketchSolver_Group
459 //  Purpose:  append specified group to the current group
460 // ============================================================================
461 void SketchSolver_Group::mergeGroups(const SketchSolver_Group& theGroup)
462 {
463   // If specified group is empty, no need to merge
464   if (theGroup.isEmpty())
465     return;
466   if (!myFeatureStorage)
467     myFeatureStorage = FeatureStoragePtr(new SketchSolver_FeatureStorage);
468
469   std::vector<ConstraintPtr> aComplexConstraints;
470   ConstraintConstraintMap::const_iterator aConstrIter = theGroup.myConstraints.begin();
471   // append simple constraints
472   for (; aConstrIter != theGroup.myConstraints.end(); aConstrIter++)
473     if (isComplexConstraint(aConstrIter->first))
474       aComplexConstraints.push_back(aConstrIter->first);
475     else
476       changeConstraint(aConstrIter->first);
477   // append complex constraints
478   std::vector<ConstraintPtr>::iterator aComplexIter = aComplexConstraints.begin();
479   for (; aComplexIter != aComplexConstraints.end(); aComplexIter++)
480       changeConstraint(*aComplexIter);
481 }
482
483 // ============================================================================
484 //  Function: splitGroup
485 //  Class:    SketchSolver_Group
486 //  Purpose:  divide the group into several subgroups
487 // ============================================================================
488 void SketchSolver_Group::splitGroup(std::vector<SketchSolver_Group*>& theCuts)
489 {
490   // Obtain constraints, which should be separated
491   FeatureStoragePtr aNewFeatStorage(new SketchSolver_FeatureStorage);
492   std::vector<ConstraintPtr> anUnusedConstraints;
493   ConstraintConstraintMap::iterator aCIter = myConstraints.begin();
494   for ( ; aCIter != myConstraints.end(); aCIter++) {
495     std::list<ConstraintPtr> aBaseConstraints = aCIter->second->constraints();
496     std::list<ConstraintPtr>::iterator anIter = aBaseConstraints.begin();
497     for (; anIter != aBaseConstraints.end(); anIter++)
498       if (aNewFeatStorage->isInteract(*anIter)) {
499         aNewFeatStorage->changeConstraint(*anIter);
500       } else
501         anUnusedConstraints.push_back(*anIter);
502   }
503
504   // Check the unused constraints once again, because they may become interacted with new storage since adding constraints
505   std::vector<ConstraintPtr>::iterator aUnuseIt = anUnusedConstraints.begin();
506   while (aUnuseIt != anUnusedConstraints.end()) {
507     if (aNewFeatStorage->isInteract(*aUnuseIt)) {
508       size_t aShift = aUnuseIt - anUnusedConstraints.begin();
509       anUnusedConstraints.erase(aUnuseIt);
510       aUnuseIt = anUnusedConstraints.begin() + aShift;
511       continue;
512     }
513     aUnuseIt++;
514   }
515
516   std::vector<SketchSolver_Group*>::iterator aCutsIter;
517   aUnuseIt = anUnusedConstraints.begin();
518   for ( ; aUnuseIt != anUnusedConstraints.end(); aUnuseIt++) {
519     // Remove unused constraints
520     removeConstraint(*aUnuseIt);
521     // Try to append constraint to already existent group
522     for (aCutsIter = theCuts.begin(); aCutsIter != theCuts.end(); aCutsIter++)
523       if ((*aCutsIter)->isInteract(*aUnuseIt)) {
524         (*aCutsIter)->changeConstraint(*aUnuseIt);
525         break;
526       }
527     if (aCutsIter == theCuts.end()) {
528       // Add new group
529       SketchSolver_Group* aGroup = new SketchSolver_Group(mySketch);
530       aGroup->changeConstraint(*aUnuseIt);
531       theCuts.push_back(aGroup);
532     }
533   }
534 }
535
536 // ============================================================================
537 //  Function: isConsistent
538 //  Class:    SketchSolver_Group
539 //  Purpose:  search removed entities and constraints
540 // ============================================================================
541 bool SketchSolver_Group::isConsistent()
542 {
543   if (!myFeatureStorage) // no one constraint is initialized yet
544     return true;
545
546   bool aResult = myFeatureStorage->isConsistent();
547   if (!aResult) {
548     // remove invalid entities
549     ConstraintConstraintMap::iterator aCIter = myConstraints.begin();
550     while (aCIter != myConstraints.end()) {
551       std::list<ConstraintPtr> aConstraints = aCIter->second->constraints();
552       std::list<ConstraintPtr>::iterator anIt = aConstraints.begin();
553       for (; anIt != aConstraints.end(); anIt++)
554         if (!(*anIt)->data() || !(*anIt)->data()->isValid())
555           if (aCIter->second->remove(*anIt)) {
556             // the constraint is fully removed, detach it from the list
557             ConstraintConstraintMap::iterator aTmpIt = aCIter++;
558             myFeatureStorage->removeConstraint(aTmpIt->first);
559             myConstraints.erase(aTmpIt);
560             break;
561           }
562       if (anIt == aConstraints.end())
563         aCIter++;
564     }
565   }
566   return aResult;
567 }
568
569 // ============================================================================
570 //  Function: removeTemporaryConstraints
571 //  Class:    SketchSolver_Group
572 //  Purpose:  remove all transient SLVS_C_WHERE_DRAGGED constraints after
573 //            resolving the set of constraints
574 // ============================================================================
575 void SketchSolver_Group::removeTemporaryConstraints()
576 {
577   myTempConstraints.clear();
578   while (myStorage->numberTemporary())
579     myStorage->deleteTemporaryConstraint();
580   // Clean lists of removed entities in the storage
581   std::set<Slvs_hParam> aRemPar;
582   std::set<Slvs_hEntity> aRemEnt;
583   std::set<Slvs_hConstraint> aRemCon;
584   myStorage->getRemoved(aRemPar, aRemEnt, aRemCon);
585   myStorage->setNeedToResolve(false);
586 }
587
588 // ============================================================================
589 //  Function: removeConstraint
590 //  Class:    SketchSolver_Group
591 //  Purpose:  remove constraint and all unused entities
592 // ============================================================================
593 void SketchSolver_Group::removeConstraint(ConstraintPtr theConstraint)
594 {
595   myFeatureStorage->removeConstraint(theConstraint);
596   ConstraintConstraintMap::iterator aCIter = myConstraints.begin();
597   for (; aCIter != myConstraints.end(); aCIter++)
598     if (aCIter->second->hasConstraint(theConstraint)) {
599       if (!aCIter->second->remove(theConstraint)) // the constraint is not fully removed
600         aCIter = myConstraints.end();
601       break;
602     }
603   if (aCIter != myConstraints.end())
604     myConstraints.erase(aCIter);
605 }
606
607 // ============================================================================
608 //  Function: isComplexConstraint
609 //  Class:    SketchSolver_Group
610 //  Purpose:  verifies the constraint is complex, i.e. it needs another constraints to be created before
611 // ============================================================================
612 bool SketchSolver_Group::isComplexConstraint(FeaturePtr theConstraint)
613 {
614   return theConstraint->getKind() == SketchPlugin_ConstraintFillet::ID() ||
615          theConstraint->getKind() == SketchPlugin_ConstraintMirror::ID() ||
616          theConstraint->getKind() == SketchPlugin_ConstraintTangent::ID();
617 }
618
619 // ============================================================================
620 //  Function: setTemporary
621 //  Class:    SketchSolver_Group
622 //  Purpose:  append given constraint to th group of temporary constraints
623 // ============================================================================
624 void SketchSolver_Group::setTemporary(SolverConstraintPtr theConstraint)
625 {
626   theConstraint->makeTemporary();
627   myTempConstraints.insert(theConstraint);
628 }
629