Salome HOME
Delete key regression corrections: in previous implementation sketch entities did...
[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_Constraint.h>
10 #include <SketchSolver_ConstraintCoincidence.h>
11 #include <SketchSolver_ConstraintMulti.h>
12 #include <SketchSolver_Error.h>
13 #include <SketchSolver_Manager.h>
14
15 #include <Events_Error.h>
16 #include <Events_Loop.h>
17 #include <ModelAPI_AttributeString.h>
18 #include <ModelAPI_Events.h>
19 #include <ModelAPI_Session.h>
20 #include <ModelAPI_Validator.h>
21
22 #include <SketchPlugin_ConstraintAngle.h>
23 #include <SketchPlugin_ConstraintCoincidence.h>
24 #include <SketchPlugin_ConstraintDistance.h>
25 #include <SketchPlugin_ConstraintEqual.h>
26 #include <SketchPlugin_ConstraintHorizontal.h>
27 #include <SketchPlugin_ConstraintLength.h>
28 #include <SketchPlugin_ConstraintFillet.h>
29 #include <SketchPlugin_ConstraintMirror.h>
30 #include <SketchPlugin_ConstraintParallel.h>
31 #include <SketchPlugin_ConstraintPerpendicular.h>
32 #include <SketchPlugin_ConstraintRadius.h>
33 #include <SketchPlugin_ConstraintRigid.h>
34 #include <SketchPlugin_ConstraintTangent.h>
35 #include <SketchPlugin_ConstraintVertical.h>
36 #include <SketchPlugin_MultiRotation.h>
37 #include <SketchPlugin_MultiTranslation.h>
38
39 #include <math.h>
40 #include <assert.h>
41
42
43 /// \brief This class is used to give unique index to the groups
44 class GroupIndexer
45 {
46 public:
47   /// \brief Return vacant index
48   static GroupID NEW_GROUP() { return ++myGroupIndex; }
49   /// \brief Removes the index
50   static void REMOVE_GROUP(const GroupID& theIndex) {
51     if (myGroupIndex == theIndex)
52       myGroupIndex--;
53   }
54
55 private:
56   GroupIndexer() {};
57
58   static GroupID myGroupIndex; ///< index of the group
59 };
60
61 GroupID GroupIndexer::myGroupIndex = GID_OUTOFGROUP;
62
63
64 static void sendMessage(const char* theMessageName)
65 {
66   std::shared_ptr<Events_Message> aMessage = std::shared_ptr<Events_Message>(
67       new Events_Message(Events_Loop::eventByName(theMessageName)));
68   Events_Loop::loop()->send(aMessage);
69 }
70
71
72
73 // ========================================================
74 // =========  SketchSolver_Group  ===============
75 // ========================================================
76
77 SketchSolver_Group::SketchSolver_Group(
78     std::shared_ptr<ModelAPI_CompositeFeature> theWorkplane)
79     : myID(GroupIndexer::NEW_GROUP()),
80       myPrevResult(STATUS_UNKNOWN)
81 {
82   // Initialize workplane
83   myWorkplaneID = EID_UNKNOWN;
84   addWorkplane(theWorkplane);
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(FeaturePtr theFeature) const
109 {
110   // Empty group interacts with everything
111   if (isEmpty())
112     return true;
113   // Check interaction with the storage
114   return myStorage->isInteract(theFeature);
115 }
116
117 // ============================================================================
118 //  Function: changeConstraint
119 //  Class:    SketchSolver_Group
120 //  Purpose:  create/update the constraint in the group
121 // ============================================================================
122 bool SketchSolver_Group::changeConstraint(
123     std::shared_ptr<SketchPlugin_Constraint> theConstraint)
124 {
125   // There is no workplane yet, something wrong
126   if (myWorkplaneID == EID_UNKNOWN)
127     return false;
128
129   if (!theConstraint || !theConstraint->data())
130     return false;
131
132   if (!checkFeatureValidity(theConstraint))
133     return false;
134
135   BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
136   myStorage->blockEvents(true);
137
138   bool isNewConstraint = myConstraints.find(theConstraint) == myConstraints.end();
139   if (isNewConstraint) {
140     // Add constraint to the current group
141     SolverConstraintPtr aConstraint = aBuilder->createConstraint(theConstraint);
142     if (!aConstraint)
143       return false;
144     aConstraint->process(myStorage, getId(), getWorkplaneId());
145     if (!aConstraint->error().empty()) {
146       if (aConstraint->error() == SketchSolver_Error::NOT_INITIALIZED())
147         return false; // some attribute are not initialized yet, don't show message
148       Events_Error::send(aConstraint->error(), this);
149     }
150     myConstraints[theConstraint] = aConstraint;
151   }
152   else
153     myConstraints[theConstraint]->update();
154
155   // Fix mirror line
156   if (theConstraint->getKind() == SketchPlugin_ConstraintMirror::ID()) {
157     AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
158         theConstraint->attribute(SketchPlugin_ConstraintMirror::ENTITY_A()));
159     if (aRefAttr && aRefAttr->isObject()) {
160       std::shared_ptr<SketchPlugin_Feature> aFeature =
161           std::dynamic_pointer_cast<SketchPlugin_Feature>(
162           ModelAPI_Feature::feature(aRefAttr->object()));
163       if (aFeature) {
164         SolverConstraintPtr aConstraint = aBuilder->createFixedConstraint(aFeature);
165         if (aConstraint) {
166           aConstraint->process(myStorage, getId(), getWorkplaneId());
167           setTemporary(aConstraint);
168         }
169       }
170     }
171   }
172   return true;
173 }
174
175 static void updateMultiConstraints(ConstraintConstraintMap& theConstraints, FeaturePtr theFeature)
176 {
177   ConstraintConstraintMap::iterator aCIt = theConstraints.begin();
178   for (; aCIt != theConstraints.end(); ++aCIt) {
179     if ((aCIt->second->getType() == CONSTRAINT_MULTI_ROTATION ||
180          aCIt->second->getType() == CONSTRAINT_MULTI_TRANSLATION)
181         && aCIt->second->isUsed(theFeature))
182       std::dynamic_pointer_cast<SketchSolver_ConstraintMulti>(aCIt->second)->update(true);
183   }
184 }
185
186 bool SketchSolver_Group::updateFeature(FeaturePtr theFeature)
187 {
188   if (!checkFeatureValidity(theFeature))
189     return false;
190
191   bool isBlocked = myStorage->isEventsBlocked();
192   if (!isBlocked)
193     myStorage->blockEvents(true);
194
195   myStorage->refresh(true);
196   bool isUpdated = myStorage->update(theFeature);
197
198   updateMultiConstraints(myConstraints, theFeature);
199
200   // events were not blocked before, the feature has not been updated,
201   // so it is necessary to revert blocking
202   if (!isUpdated && !isBlocked)
203     myStorage->blockEvents(false);
204   return isUpdated;
205 }
206
207 void SketchSolver_Group::moveFeature(FeaturePtr theFeature)
208 {
209   BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
210
211   // Firstly, revert changes in the fixed entities
212   myStorage->blockEvents(true);
213   myStorage->refresh(true);
214
215   // Then, create temporary Fixed constraint
216   SolverConstraintPtr aConstraint = aBuilder->createMovementConstraint(theFeature);
217   if (!aConstraint)
218     return;
219   aConstraint->process(myStorage, getId(), getWorkplaneId());
220   if (aConstraint->error().empty())
221     setTemporary(aConstraint);
222
223   // Secondly, search attributes of the feature in the list of the Multi constraints and update them
224   updateMultiConstraints(myConstraints, theFeature);
225 }
226
227 // ============================================================================
228 //  Function: addWorkplane
229 //  Class:    SketchSolver_Group
230 //  Purpose:  create workplane for the group
231 // ============================================================================
232 bool SketchSolver_Group::addWorkplane(CompositeFeaturePtr theSketch)
233 {
234   if (myWorkplaneID != EID_UNKNOWN || theSketch->getKind() != SketchPlugin_Sketch::ID())
235     return false;  // the workplane already exists or the function parameter is not Sketch
236
237   mySketch = theSketch;
238   if (!updateWorkplane()) {
239     mySketch = CompositeFeaturePtr();
240     return false;
241   }
242   return true;
243 }
244
245 // ============================================================================
246 //  Function: updateWorkplane
247 //  Class:    SketchSolver_Group
248 //  Purpose:  update parameters of workplane
249 // ============================================================================
250 bool SketchSolver_Group::updateWorkplane()
251 {
252   BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
253   if (!myStorage) // Create storage if not exists
254     myStorage = aBuilder->createStorage(getId());
255
256   // sketch should be unchanged, set it out of current group
257   bool isUpdated = myStorage->update(FeaturePtr(mySketch), GID_OUTOFGROUP);
258   if (isUpdated) {
259     EntityWrapperPtr anEntity = myStorage->entity(FeaturePtr(mySketch));
260     myWorkplaneID = anEntity->id();
261   }
262   return isUpdated;
263 }
264
265 // ============================================================================
266 //  Function: resolveConstraints
267 //  Class:    SketchSolver_Group
268 //  Purpose:  solve the set of constraints for the current group
269 // ============================================================================
270 bool SketchSolver_Group::resolveConstraints()
271 {
272   bool aResolved = false;
273   bool isGroupEmpty = isEmpty();
274   if (myStorage->isNeedToResolve() && !isGroupEmpty) {
275     if (!mySketchSolver)
276       mySketchSolver = SketchSolver_Manager::instance()->builder()->createSolver();
277
278     mySketchSolver->setGroup(myID);
279     mySketchSolver->calculateFailedConstraints(false);
280     myStorage->initializeSolver(mySketchSolver);
281     mySketchSolver->prepare();
282
283     SketchSolver_SolveStatus aResult = STATUS_OK;
284     try {
285       if (myStorage->hasDuplicatedConstraint())
286         aResult = STATUS_INCONSISTENT;
287       else {
288         // To avoid overconstraint situation, we will remove temporary constraints one-by-one
289         // and try to find the case without overconstraint
290         bool isLastChance = false;
291         while (true) {
292           aResult = mySketchSolver->solve();
293           if (aResult == STATUS_OK || aResult == STATUS_EMPTYSET || isLastChance)
294             break;
295           // try to update parameters and resolve once again
296           ConstraintConstraintMap::iterator aConstrIt = myConstraints.begin();
297           for (; aConstrIt != myConstraints.end(); ++aConstrIt)
298             aConstrIt->second->update();
299           isLastChance = true;
300
301           removeTemporaryConstraints();
302           mySketchSolver->calculateFailedConstraints(true); // something failed => need to find it
303           myStorage->initializeSolver(mySketchSolver);
304         }
305       }
306     } catch (...) {
307 //      Events_Error::send(SketchSolver_Error::SOLVESPACE_CRASH(), this);
308       getWorkplane()->string(SketchPlugin_Sketch::SOLVER_ERROR())->setValue(SketchSolver_Error::SOLVESPACE_CRASH());
309       if (myPrevResult == STATUS_OK || myPrevResult == STATUS_UNKNOWN) {
310         // the error message should be changed before sending the message
311         sendMessage(EVENT_SOLVER_FAILED);
312         myPrevResult = STATUS_FAILED;
313       }
314       mySketchSolver->undo();
315       return false;
316     }
317     if (aResult == STATUS_OK || aResult == STATUS_EMPTYSET) {  // solution succeeded, store results into correspondent attributes
318       myStorage->refresh();
319       if (myPrevResult != STATUS_OK || myPrevResult == STATUS_UNKNOWN) {
320         getWorkplane()->string(SketchPlugin_Sketch::SOLVER_ERROR())->setValue("");
321         // the error message should be changed before sending the message
322         sendMessage(EVENT_SOLVER_REPAIRED);
323         myPrevResult = STATUS_OK;
324       }
325     } else {
326       mySketchSolver->undo();
327       if (!myConstraints.empty()) {
328 //      Events_Error::send(SketchSolver_Error::CONSTRAINTS(), this);
329         getWorkplane()->string(SketchPlugin_Sketch::SOLVER_ERROR())->setValue(SketchSolver_Error::CONSTRAINTS());
330         if (myPrevResult != aResult || myPrevResult == STATUS_UNKNOWN) {
331           // the error message should be changed before sending the message
332           sendMessage(EVENT_SOLVER_FAILED);
333           myPrevResult = aResult;
334         }
335       }
336     }
337
338     aResolved = true;
339   } else if (!isGroupEmpty) {
340     // Check there are constraints Fixed. If they exist, update parameters by stored values
341     ConstraintConstraintMap::iterator aCIt = myConstraints.begin();
342     for (; aCIt != myConstraints.end(); ++aCIt)
343       if (aCIt->first->getKind() == SketchPlugin_ConstraintRigid::ID()) {
344         aResolved = true;
345         break;
346       }
347     if (aCIt != myConstraints.end())
348       myStorage->refresh();
349   }
350   removeTemporaryConstraints();
351   myStorage->blockEvents(false);
352   myStorage->setNeedToResolve(false);
353   return aResolved;
354 }
355
356 // ============================================================================
357 //  Function: mergeGroups
358 //  Class:    SketchSolver_Group
359 //  Purpose:  append specified group to the current group
360 // ============================================================================
361 void SketchSolver_Group::mergeGroups(const SketchSolver_Group& theGroup)
362 {
363   // If specified group is empty, no need to merge
364   if (theGroup.isEmpty())
365     return;
366
367   std::set<ObjectPtr> aConstraints;
368   ConstraintConstraintMap::const_iterator aConstrIter = theGroup.myConstraints.begin();
369   for (; aConstrIter != theGroup.myConstraints.end(); aConstrIter++)
370     aConstraints.insert(aConstrIter->first);
371
372   std::list<FeaturePtr> aSortedConstraints = selectApplicableFeatures(aConstraints);
373   std::list<FeaturePtr>::iterator aSCIter = aSortedConstraints.begin();
374   for (; aSCIter != aSortedConstraints.end(); ++aSCIter) {
375     ConstraintPtr aConstr = std::dynamic_pointer_cast<SketchPlugin_Constraint>(*aSCIter);
376     if (!aConstr)
377       continue;
378     changeConstraint(aConstr);
379   }
380 }
381
382 // ============================================================================
383 //  Function: splitGroup
384 //  Class:    SketchSolver_Group
385 //  Purpose:  divide the group into several subgroups
386 // ============================================================================
387 void SketchSolver_Group::splitGroup(std::list<SketchSolver_Group*>& theCuts)
388 {
389   // New storage will be used in trimmed way to store the list of constraint interacted together.
390   StoragePtr aNewStorage = SketchSolver_Manager::instance()->builder()->createStorage(getId());
391   std::list<ConstraintWrapperPtr> aDummyVec; // empty vector to avoid creation of solver's constraints
392
393   // Obtain constraints, which should be separated
394   std::list<ConstraintPtr> anUnusedConstraints;
395   ConstraintConstraintMap::iterator aCIter = myConstraints.begin();
396   for ( ; aCIter != myConstraints.end(); aCIter++) {
397     if (aNewStorage->isInteract(FeaturePtr(aCIter->first)))
398       aNewStorage->addConstraint(aCIter->first, aDummyVec);
399     else
400       anUnusedConstraints.push_back(aCIter->first);
401   }
402
403   // Check the unused constraints once again, because they may become interacted with new storage since adding constraints
404   std::list<ConstraintPtr>::iterator aUnuseIt = anUnusedConstraints.begin();
405   while (aUnuseIt != anUnusedConstraints.end()) {
406     if (aNewStorage->isInteract(FeaturePtr(*aUnuseIt))) {
407       aNewStorage->addConstraint(*aUnuseIt, aDummyVec);
408       anUnusedConstraints.erase(aUnuseIt);
409       aUnuseIt = anUnusedConstraints.begin();
410       continue;
411     }
412     aUnuseIt++;
413   }
414
415   std::list<SketchSolver_Group*>::iterator aCutsIter;
416   aUnuseIt = anUnusedConstraints.begin();
417   for ( ; aUnuseIt != anUnusedConstraints.end(); ++aUnuseIt) {
418     // Remove unused constraints
419     removeConstraint(*aUnuseIt);
420     // Try to append constraint to already existent group
421     for (aCutsIter = theCuts.begin(); aCutsIter != theCuts.end(); ++aCutsIter)
422       if ((*aCutsIter)->isInteract(*aUnuseIt)) {
423         (*aCutsIter)->changeConstraint(*aUnuseIt);
424         break;
425       }
426     if (aCutsIter == theCuts.end()) {
427       // Add new group
428       SketchSolver_Group* aGroup = new SketchSolver_Group(mySketch);
429       aGroup->changeConstraint(*aUnuseIt);
430       theCuts.push_back(aGroup);
431     } else {
432       // Find other groups interacting with constraint
433       std::list<SketchSolver_Group*>::iterator aBaseGroupIt = aCutsIter;
434       for (++aCutsIter; aCutsIter != theCuts.end(); ++aCutsIter)
435         if ((*aCutsIter)->isInteract(*aUnuseIt)) {
436           (*aBaseGroupIt)->mergeGroups(**aCutsIter);
437           std::list<SketchSolver_Group*>::iterator aRemoveIt = aCutsIter--;
438           theCuts.erase(aRemoveIt);
439         }
440     }
441   }
442 }
443
444 // ============================================================================
445 //  Function: isConsistent
446 //  Class:    SketchSolver_Group
447 //  Purpose:  search removed entities and constraints
448 // ============================================================================
449 bool SketchSolver_Group::isConsistent()
450 {
451   if (isEmpty()) // no one constraint is initialized yet
452     return true;
453
454   // Check the features and constraint is the storage are valid
455   bool aResult = myStorage->isConsistent();
456   if (aResult) {
457     // additional check of consistency of the Fixed constraint,
458     // because they are not added to the storage
459     ConstraintConstraintMap::iterator aCIter = myConstraints.begin();
460     for (; aCIter != myConstraints.end(); ++aCIter)
461       if (aCIter->first->getKind() == SketchPlugin_ConstraintRigid::ID() &&
462          (!aCIter->first->data() || !aCIter->first->data()->isValid())) {
463         aResult = false;
464         break;
465       }
466   }
467   if (!aResult) {
468     // remove invalid constraints
469     std::set<ConstraintPtr> anInvalidConstraints;
470     ConstraintConstraintMap::iterator aCIter = myConstraints.begin();
471     for (; aCIter != myConstraints.end(); ++aCIter) {
472       if (!aCIter->first->data() || !aCIter->first->data()->isValid())
473         anInvalidConstraints.insert(aCIter->first);
474     }
475     std::set<ConstraintPtr>::const_iterator aRemoveIt = anInvalidConstraints.begin();
476     for (; aRemoveIt != anInvalidConstraints.end(); ++aRemoveIt)
477       removeConstraint(*aRemoveIt);
478     // remove invalid features
479     myStorage->removeInvalidEntities();
480   }
481   return aResult;
482 }
483
484 // ============================================================================
485 //  Function: removeTemporaryConstraints
486 //  Class:    SketchSolver_Group
487 //  Purpose:  remove all transient SLVS_C_WHERE_DRAGGED constraints after
488 //            resolving the set of constraints
489 // ============================================================================
490 void SketchSolver_Group::removeTemporaryConstraints()
491 {
492   std::set<SolverConstraintPtr>::iterator aTmpIt = myTempConstraints.begin();
493   for (; aTmpIt != myTempConstraints.end(); ++aTmpIt)
494     (*aTmpIt)->remove();
495
496   if (!myTempConstraints.empty())
497     myStorage->verifyFixed();
498   myStorage->setNeedToResolve(false);
499   myTempConstraints.clear();
500 }
501
502 // ============================================================================
503 //  Function: removeConstraint
504 //  Class:    SketchSolver_Group
505 //  Purpose:  remove constraint and all unused entities
506 // ============================================================================
507 void SketchSolver_Group::removeConstraint(ConstraintPtr theConstraint)
508 {
509   ConstraintConstraintMap::iterator aCIter = myConstraints.begin();
510   for (; aCIter != myConstraints.end(); aCIter++)
511     if (aCIter->first == theConstraint) {
512       aCIter->second->remove(); // the constraint is not fully removed
513       break;
514     }
515   if (aCIter != myConstraints.end())
516     myConstraints.erase(aCIter);
517 }
518
519 // ============================================================================
520 //  Function: setTemporary
521 //  Class:    SketchSolver_Group
522 //  Purpose:  append given constraint to the group of temporary constraints
523 // ============================================================================
524 void SketchSolver_Group::setTemporary(SolverConstraintPtr theConstraint)
525 {
526   myTempConstraints.insert(theConstraint);
527 }
528
529
530 // ============================================================================
531 //  Function: checkFeatureValidity
532 //  Class:    SketchSolver_Group
533 //  Purpose:  verifies is the feature valid
534 // ============================================================================
535 bool SketchSolver_Group::checkFeatureValidity(FeaturePtr theFeature)
536 {
537   if (!theFeature || !theFeature->data()->isValid())
538     return true;
539
540   SessionPtr aMgr = ModelAPI_Session::get();
541   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
542   return aFactory->validate(theFeature);
543 }
544
545
546
547
548 // ===========   Auxiliary functions   ========================================
549 static double featureToVal(FeaturePtr theFeature)
550 {
551   if (theFeature->getKind() == SketchPlugin_Sketch::ID())
552     return 0.0; // sketch
553   ConstraintPtr aConstraint = std::dynamic_pointer_cast<SketchPlugin_Constraint>(theFeature);
554   if (!aConstraint)
555     return 1.0; // features (arc, circle, line, point)
556
557   const std::string& anID = aConstraint->getKind();
558   if (anID == SketchPlugin_ConstraintCoincidence::ID()) {
559     AttributeRefAttrPtr anAttrA = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
560         aConstraint->attribute(SketchPlugin_Constraint::ENTITY_A()));
561     AttributeRefAttrPtr anAttrB = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
562         aConstraint->attribute(SketchPlugin_Constraint::ENTITY_B()));
563     if (anAttrA && anAttrB && (anAttrA->isObject() || anAttrB->isObject()))
564       return 2.0; // point-on-line and point-on-circle should go before points coincidence constraint
565     return 2.5;
566   }
567   if (anID == SketchPlugin_ConstraintDistance::ID() ||
568       anID == SketchPlugin_ConstraintLength::ID() ||
569       anID == SketchPlugin_ConstraintRadius::ID())
570     return 3.0;
571   if (anID == SketchPlugin_ConstraintAngle::ID())
572     return 3.5;
573   if (anID == SketchPlugin_ConstraintHorizontal::ID() ||
574       anID == SketchPlugin_ConstraintVertical::ID() ||
575       anID == SketchPlugin_ConstraintParallel::ID() ||
576       anID == SketchPlugin_ConstraintPerpendicular::ID())
577     return 4.0;
578   if (anID == SketchPlugin_ConstraintEqual::ID())
579     return 5.0;
580   if (anID == SketchPlugin_ConstraintTangent::ID() ||
581       anID == SketchPlugin_ConstraintMirror::ID())
582     return 6.0;
583   if (anID == SketchPlugin_ConstraintRigid::ID())
584     return 7.0;
585   if (anID == SketchPlugin_MultiRotation::ID() ||
586       anID == SketchPlugin_MultiTranslation::ID())
587     return 8.0;
588
589   // all other constraints are placed between Equal and Tangent constraints
590   return 5.5;
591 }
592
593 static bool isLess(FeaturePtr theFeature1, FeaturePtr theFeature2)
594 {
595   return featureToVal(theFeature1) < featureToVal(theFeature2);
596 }
597
598 std::list<FeaturePtr> SketchSolver_Group::selectApplicableFeatures(const std::set<ObjectPtr>& theObjects)
599 {
600   std::list<FeaturePtr> aResult;
601   std::list<FeaturePtr>::iterator aResIt;
602
603   std::set<ObjectPtr>::const_iterator anObjIter = theObjects.begin();
604   for (; anObjIter != theObjects.end(); ++anObjIter) {
605     // Operate sketch itself and SketchPlugin features only.
606     // Also, the Fillet need to be skipped, because there are several separated constraints composing it.
607     FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*anObjIter);
608     if (!aFeature)
609       continue;
610     std::shared_ptr<SketchPlugin_Feature> aSketchFeature = 
611         std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
612     if ((aFeature->getKind() != SketchPlugin_Sketch::ID() && !aSketchFeature) ||
613         aFeature->getKind() == SketchPlugin_ConstraintFillet::ID())
614       continue;
615
616     // Find the place where to insert a feature
617     for (aResIt = aResult.begin(); aResIt != aResult.end(); ++aResIt)
618       if (isLess(aFeature, *aResIt))
619         break;
620     aResult.insert(aResIt, aFeature);
621   }
622
623   return aResult;
624 }
625