1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: SketchSolver_Group.cpp
4 // Created: 27 May 2014
5 // Author: Artem ZHIDKOV
7 #include "SketchSolver_Group.h"
9 #include <SketchSolver_Builder.h>
10 #include <SketchSolver_Constraint.h>
11 #include <SketchSolver_ConstraintCoincidence.h>
12 #include <SketchSolver_Error.h>
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>
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_MultiRotation.h>
37 #include <SketchPlugin_MultiTranslation.h>
39 #include <SketchPlugin_Arc.h>
40 #include <SketchPlugin_Circle.h>
41 #include <SketchPlugin_Line.h>
42 #include <SketchPlugin_Point.h>
43 #include <SketchPlugin_Sketch.h>
49 /// \brief This class is used to give unique index to the groups
53 /// \brief Return vacant index
54 static Slvs_hGroup NEW_GROUP() { return ++myGroupIndex; }
55 /// \brief Removes the index
56 static void REMOVE_GROUP(const Slvs_hGroup& theIndex) {
57 if (myGroupIndex == theIndex)
64 static Slvs_hGroup myGroupIndex; ///< index of the group
67 Slvs_hGroup GroupIndexer::myGroupIndex = 0;
70 static void sendMessage(const char* theMessageName)
72 std::shared_ptr<Events_Message> aMessage = std::shared_ptr<Events_Message>(
73 new Events_Message(Events_Loop::eventByName(theMessageName)));
74 Events_Loop::loop()->send(aMessage);
79 // ========================================================
80 // ========= SketchSolver_Group ===============
81 // ========================================================
83 SketchSolver_Group::SketchSolver_Group(
84 std::shared_ptr<ModelAPI_CompositeFeature> theWorkplane)
85 : myID(GroupIndexer::NEW_GROUP()),
88 // Initialize workplane
89 myWorkplaneID = SLVS_E_UNKNOWN;
91 assert(addWorkplane(theWorkplane));
93 addWorkplane(theWorkplane);
97 SketchSolver_Group::~SketchSolver_Group()
99 myConstraints.clear();
100 GroupIndexer::REMOVE_GROUP(myID);
103 // ============================================================================
104 // Function: isBaseWorkplane
105 // Class: SketchSolver_Group
106 // Purpose: verify the group is based on the given workplane
107 // ============================================================================
108 bool SketchSolver_Group::isBaseWorkplane(CompositeFeaturePtr theWorkplane) const
110 return theWorkplane == mySketch;
113 // ============================================================================
114 // Function: isInteract
115 // Class: SketchSolver_Group
116 // Purpose: verify are there any entities in the group used by given constraint
117 // ============================================================================
118 bool SketchSolver_Group::isInteract(
119 std::shared_ptr<SketchPlugin_Feature> theFeature) const
121 // Empty group interacts with everything
122 if (isEmpty()) return true;
123 ConstraintPtr aConstraint = std::dynamic_pointer_cast<SketchPlugin_Constraint>(theFeature);
125 return myFeatureStorage->isInteract(aConstraint);
126 return myFeatureStorage->isInteract(std::dynamic_pointer_cast<ModelAPI_Feature>(theFeature));
129 // ============================================================================
130 // Function: getFeatureId
131 // Class: SketchSolver_Group
132 // Purpose: Find the identifier of the feature, if it already exists in the group
133 // ============================================================================
134 Slvs_hEntity SketchSolver_Group::getFeatureId(FeaturePtr theFeature) const
136 Slvs_hEntity aResult = SLVS_E_UNKNOWN;
137 if (!myFeatureStorage)
139 std::set<ConstraintPtr> aConstraints = myFeatureStorage->getConstraints(theFeature);
140 if (aConstraints.empty())
142 std::set<ConstraintPtr>::iterator aConstrIter = aConstraints.begin();
143 for (; aConstrIter != aConstraints.end(); aConstrIter++) {
144 ConstraintConstraintMap::const_iterator aCIter = myConstraints.find(*aConstrIter);
145 if (aCIter == myConstraints.end())
147 aResult = aCIter->second->getId(theFeature);
148 if (aResult != SLVS_E_UNKNOWN)
151 return SLVS_E_UNKNOWN;
154 // ============================================================================
155 // Function: getAttributeId
156 // Class: SketchSolver_Group
157 // Purpose: Find the identifier of the attribute, if it already exists in the group
158 // ============================================================================
159 Slvs_hEntity SketchSolver_Group::getAttributeId(AttributePtr theAttribute) const
161 Slvs_hEntity aResult = SLVS_E_UNKNOWN;
162 if (!myFeatureStorage)
164 std::set<ConstraintPtr> aConstraints = myFeatureStorage->getConstraints(theAttribute);
165 if (aConstraints.empty())
167 std::set<ConstraintPtr>::iterator aConstrIter = aConstraints.begin();
168 for (; aConstrIter != aConstraints.end(); aConstrIter++) {
169 ConstraintConstraintMap::const_iterator aCIter = myConstraints.find(*aConstrIter);
170 if (aCIter == myConstraints.end())
172 aResult = aCIter->second->getId(theAttribute);
173 if (aResult != SLVS_E_UNKNOWN)
176 return SLVS_E_UNKNOWN;
179 // ============================================================================
180 // Function: changeConstraint
181 // Class: SketchSolver_Group
182 // Purpose: create/update the constraint in the group
183 // ============================================================================
184 bool SketchSolver_Group::changeConstraint(
185 std::shared_ptr<SketchPlugin_Constraint> theConstraint)
187 // There is no workplane yet, something wrong
188 if (myWorkplaneID == SLVS_E_UNKNOWN)
194 bool isNewConstraint = myConstraints.find(theConstraint) == myConstraints.end();
195 if (isNewConstraint) {
196 // Add constraint to the current group
197 SolverConstraintPtr aConstraint =
198 SketchSolver_Builder::getInstance()->createConstraint(theConstraint);
201 aConstraint->setGroup(this);
202 aConstraint->setStorage(myStorage);
203 if (!aConstraint->error().empty()) {
204 if (aConstraint->error() == SketchSolver_Error::NOT_INITIALIZED())
205 return false; // some attribute are not initialized yet, don't show message
206 Events_Error::send(aConstraint->error(), this);
209 // Additional verification of coincidence of several points
210 if (theConstraint->getKind() == SketchPlugin_ConstraintCoincidence::ID()) {
211 ConstraintConstraintMap::iterator aCIter = myConstraints.begin();
212 for (; aCIter != myConstraints.end(); aCIter++) {
213 std::shared_ptr<SketchSolver_ConstraintCoincidence> aCoincidence =
214 std::dynamic_pointer_cast<SketchSolver_ConstraintCoincidence>(aCIter->second);
217 std::shared_ptr<SketchSolver_ConstraintCoincidence> aCoinc2 =
218 std::dynamic_pointer_cast<SketchSolver_ConstraintCoincidence>(aConstraint);
219 if (aCoincidence != aCoinc2 && aCoincidence->isCoincide(aCoinc2)) {
220 aCoinc2->attach(aCoincidence);
221 // update other coincidences
222 ConstraintConstraintMap::iterator anIt = aCIter;
223 for (++anIt; anIt != myConstraints.end(); ++anIt)
224 if (anIt->second == aCIter->second)
225 anIt->second = aCoinc2;
226 aCIter->second = aCoinc2;
230 myConstraints[theConstraint] = aConstraint;
233 myConstraints[theConstraint]->update();
235 // Fix base features for fillet
236 if (isNewConstraint && theConstraint->getKind() == SketchPlugin_ConstraintFillet::ID()) {
237 std::list<AttributePtr> anAttrList =
238 theConstraint->data()->attributes(ModelAPI_AttributeRefAttr::typeId());
239 std::list<AttributePtr>::iterator anAttrIter = anAttrList.begin();
240 for (; anAttrIter != anAttrList.end(); anAttrIter++) {
241 AttributeRefAttrPtr aRefAttr =
242 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttrIter);
243 if (!aRefAttr || !aRefAttr->isObject())
245 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
246 SolverConstraintPtr aConstraint =
247 SketchSolver_Builder::getInstance()->createRigidConstraint(aFeature);
250 aConstraint->setGroup(this);
251 aConstraint->setStorage(myStorage);
252 setTemporary(aConstraint);
256 if (theConstraint->getKind() == SketchPlugin_ConstraintMirror::ID()) {
257 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
258 theConstraint->attribute(SketchPlugin_ConstraintMirror::ENTITY_A()));
259 if (aRefAttr && aRefAttr->isObject()) {
260 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
262 SolverConstraintPtr aConstraint =
263 SketchSolver_Builder::getInstance()->createRigidConstraint(aFeature);
265 aConstraint->setGroup(this);
266 aConstraint->setStorage(myStorage);
267 setTemporary(aConstraint);
273 if (!myFeatureStorage)
274 myFeatureStorage = FeatureStoragePtr(new SketchSolver_FeatureStorage);
275 myFeatureStorage->changeConstraint(theConstraint);
281 bool SketchSolver_Group::updateFeature(std::shared_ptr<SketchPlugin_Feature> theFeature)
283 std::set<ConstraintPtr> aConstraints =
284 myFeatureStorage->getConstraints(std::dynamic_pointer_cast<ModelAPI_Feature>(theFeature));
285 if (aConstraints.empty())
287 std::set<ConstraintPtr>::iterator aCIter = aConstraints.begin();
288 std::set<SolverConstraintPtr> aPostponed; // postponed constraints Multi-Rotation and Multi-Translation
289 for (; aCIter != aConstraints.end(); aCIter++) {
290 ConstraintConstraintMap::iterator aSolConIter = myConstraints.find(*aCIter);
291 if (aSolConIter == myConstraints.end() || !aSolConIter->first->data() ||
292 !aSolConIter->first->data()->isValid())
294 myFeatureStorage->changeFeature(theFeature, aSolConIter->first);
296 if (aSolConIter->first->getKind() == SketchPlugin_MultiRotation::ID() ||
297 aSolConIter->first->getKind() == SketchPlugin_MultiTranslation::ID()) {
298 aPostponed.insert(aSolConIter->second);
301 aSolConIter->second->addFeature(theFeature);
302 aSolConIter->second->update();
305 // Update postponed constraints
306 std::set<SolverConstraintPtr>::iterator aSCIter = aPostponed.begin();
307 for (; aSCIter != aPostponed.end(); ++aSCIter) {
308 (*aSCIter)->addFeature(theFeature);
309 (*aSCIter)->update();
314 void SketchSolver_Group::moveFeature(std::shared_ptr<SketchPlugin_Feature> theFeature)
316 // Firstly, create temporary rigid constraint
317 SolverConstraintPtr aConstraint =
318 SketchSolver_Builder::getInstance()->createMovementConstraint(theFeature);
321 aConstraint->setGroup(this);
322 aConstraint->setStorage(myStorage);
323 if (aConstraint->error().empty())
324 setTemporary(aConstraint);
325 // Secondly, update the feature
326 updateFeature(theFeature);
329 // ============================================================================
330 // Function: fixFeaturesList
331 // Class: SketchSolver_Group
332 // Purpose: Apply temporary rigid constraints for the list of features
333 // ============================================================================
334 void SketchSolver_Group::fixFeaturesList(AttributeRefListPtr theList)
336 std::list<ObjectPtr> aList = theList->list();
337 std::list<ObjectPtr>::iterator anIt = aList.begin();
338 std::list<FeaturePtr> aFeatures;
339 // Sort features, at begining there are features used by Equal constraint
340 for (; anIt != aList.end(); anIt++) {
343 FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
344 std::set<ConstraintPtr> aConstraints = myFeatureStorage->getConstraints(aFeature);
345 std::set<ConstraintPtr>::iterator aCIter = aConstraints.begin();
346 for (; aCIter != aConstraints.end(); aCIter++)
347 if ((*aCIter)->getKind() == SketchPlugin_ConstraintEqual::ID())
349 if (aCIter != aConstraints.end())
350 aFeatures.push_front(aFeature);
352 aFeatures.push_back(aFeature);
355 std::list<FeaturePtr>::iterator aFeatIter = aFeatures.begin();
356 for (; aFeatIter != aFeatures.end(); aFeatIter++) {
357 SolverConstraintPtr aConstraint =
358 SketchSolver_Builder::getInstance()->createRigidConstraint(*aFeatIter);
361 aConstraint->setGroup(this);
362 aConstraint->setStorage(myStorage);
363 setTemporary(aConstraint);
367 // ============================================================================
368 // Function: addWorkplane
369 // Class: SketchSolver_Group
370 // Purpose: create workplane for the group
371 // ============================================================================
372 bool SketchSolver_Group::addWorkplane(CompositeFeaturePtr theSketch)
374 if (myWorkplaneID != SLVS_E_UNKNOWN || theSketch->getKind() != SketchPlugin_Sketch::ID())
375 return false; // the workplane already exists or the function parameter is not Sketch
377 mySketch = theSketch;
382 // ============================================================================
383 // Function: updateWorkplane
384 // Class: SketchSolver_Group
385 // Purpose: update parameters of workplane
386 // ============================================================================
387 bool SketchSolver_Group::updateWorkplane()
389 if (!myStorage) // Create storage if not exists
390 myStorage = StoragePtr(new SketchSolver_Storage);
391 SketchSolver_Builder* aBuilder = SketchSolver_Builder::getInstance();
393 std::vector<Slvs_Entity> anEntities;
394 std::vector<Slvs_Param> aParams;
395 if (!aBuilder->createWorkplane(mySketch, anEntities, aParams))
398 if (myWorkplaneID == SLVS_E_UNKNOWN) {
399 myWorkplaneID = anEntities.back().h;
400 // Add new workplane elements
401 std::vector<Slvs_Param>::iterator aParIter = aParams.begin();
402 for (; aParIter != aParams.end(); aParIter++) {
403 aParIter->h = SLVS_E_UNKNOWN; // the ID should be generated by storage
404 aParIter->group = myID;
405 aParIter->h = myStorage->addParameter(*aParIter);
407 std::vector<Slvs_Entity>::iterator anEntIter = anEntities.begin();
408 for (; anEntIter != anEntities.end(); anEntIter++) {
409 anEntIter->h = SLVS_E_UNKNOWN; // the ID should be generated by storage
410 anEntIter->group = myID;
411 anEntIter->wrkpl = myWorkplaneID;
412 for (int i = 0; i < 4; i++)
413 if (anEntIter->param[i] != SLVS_E_UNKNOWN)
414 anEntIter->param[i] = aParams[anEntIter->param[i]-1].h;
415 for (int i = 0; i < 4; i++)
416 if (anEntIter->point[i] != SLVS_E_UNKNOWN)
417 anEntIter->point[i] = anEntities[anEntIter->point[i]-1].h;
418 anEntIter->h = myStorage->addEntity(*anEntIter);
421 // Update existent workplane
422 const Slvs_Entity& aWP = myStorage->getEntity(myWorkplaneID);
423 const Slvs_Entity& anOrigin = myStorage->getEntity(aWP.point[0]);
424 const Slvs_Entity& aNormal = myStorage->getEntity(aWP.normal);
425 // Get parameters and update them
426 Slvs_hParam aWPParams[7] = {
427 anOrigin.param[0], anOrigin.param[1], anOrigin.param[2],
428 aNormal.param[0], aNormal.param[1], aNormal.param[2], aNormal.param[3]
430 std::vector<Slvs_Param>::iterator aParIter = aParams.begin();
431 for (int i = 0; aParIter != aParams.end(); aParIter++, i++) {
432 Slvs_Param aParam = myStorage->getParameter(aWPParams[i]);
433 aParam.val = aParIter->val;
434 myStorage->updateParameter(aParam);
437 return myWorkplaneID > 0;
440 // ============================================================================
441 // Function: resolveConstraints
442 // Class: SketchSolver_Group
443 // Purpose: solve the set of constraints for the current group
444 // ============================================================================
445 bool SketchSolver_Group::resolveConstraints()
447 bool aResolved = false;
448 if (myStorage->isNeedToResolve() && !isEmpty()) {
449 myConstrSolver.setGroupID(myID);
450 myStorage->initializeSolver(myConstrSolver);
452 int aResult = SLVS_RESULT_OKAY;
454 if (myStorage->hasDuplicatedConstraint())
455 aResult = SLVS_RESULT_INCONSISTENT;
457 // To avoid overconstraint situation, we will remove temporary constraints one-by-one
458 // and try to find the case without overconstraint
459 bool isLastChance = false;
460 int aNbTemp = myStorage->numberTemporary();
462 aResult = myConstrSolver.solve();
463 if (aResult == SLVS_RESULT_OKAY || isLastChance)
466 // try to update parameters and resolve once again
467 ConstraintConstraintMap::iterator aConstrIt = myConstraints.begin();
468 for (; aConstrIt != myConstraints.end(); ++aConstrIt)
469 aConstrIt->second->update();
472 aNbTemp = myStorage->deleteTemporaryConstraint();
473 myStorage->initializeSolver(myConstrSolver);
477 Events_Error::send(SketchSolver_Error::SOLVESPACE_CRASH(), this);
479 sendMessage(EVENT_SOLVER_FAILED);
480 myPrevSolved = false;
484 if (aResult == SLVS_RESULT_OKAY) { // solution succeeded, store results into correspondent attributes
485 myFeatureStorage->blockEvents(true);
486 ConstraintConstraintMap::iterator aConstrIter = myConstraints.begin();
487 for (; aConstrIter != myConstraints.end(); aConstrIter++)
488 aConstrIter->second->refresh();
489 myFeatureStorage->blockEvents(false);
491 sendMessage(EVENT_SOLVER_REPAIRED);
494 } else if (!myConstraints.empty()) {
495 Events_Error::send(SketchSolver_Error::CONSTRAINTS(), this);
497 sendMessage(EVENT_SOLVER_FAILED);
498 myPrevSolved = false;
504 removeTemporaryConstraints();
505 myStorage->setNeedToResolve(false);
509 // ============================================================================
510 // Function: mergeGroups
511 // Class: SketchSolver_Group
512 // Purpose: append specified group to the current group
513 // ============================================================================
514 void SketchSolver_Group::mergeGroups(const SketchSolver_Group& theGroup)
516 // If specified group is empty, no need to merge
517 if (theGroup.isEmpty())
519 if (!myFeatureStorage)
520 myFeatureStorage = FeatureStoragePtr(new SketchSolver_FeatureStorage);
522 std::vector<ConstraintPtr> aComplexConstraints;
523 ConstraintConstraintMap::const_iterator aConstrIter = theGroup.myConstraints.begin();
524 // append simple constraints
525 for (; aConstrIter != theGroup.myConstraints.end(); aConstrIter++)
526 if (isComplexConstraint(aConstrIter->first))
527 aComplexConstraints.push_back(aConstrIter->first);
529 changeConstraint(aConstrIter->first);
530 // append complex constraints
531 std::vector<ConstraintPtr>::iterator aComplexIter = aComplexConstraints.begin();
532 for (; aComplexIter != aComplexConstraints.end(); aComplexIter++)
533 changeConstraint(*aComplexIter);
536 // ============================================================================
537 // Function: splitGroup
538 // Class: SketchSolver_Group
539 // Purpose: divide the group into several subgroups
540 // ============================================================================
541 void SketchSolver_Group::splitGroup(std::vector<SketchSolver_Group*>& theCuts)
543 // Obtain constraints, which should be separated
544 FeatureStoragePtr aNewFeatStorage(new SketchSolver_FeatureStorage);
545 std::vector<ConstraintPtr> anUnusedConstraints;
546 ConstraintConstraintMap::iterator aCIter = myConstraints.begin();
547 for ( ; aCIter != myConstraints.end(); aCIter++) {
548 std::list<ConstraintPtr> aBaseConstraints = aCIter->second->constraints();
549 std::list<ConstraintPtr>::iterator anIter = aBaseConstraints.begin();
550 for (; anIter != aBaseConstraints.end(); anIter++)
551 if (aNewFeatStorage->isInteract(*anIter)) {
552 aNewFeatStorage->changeConstraint(*anIter);
554 anUnusedConstraints.push_back(*anIter);
557 // Check the unused constraints once again, because they may become interacted with new storage since adding constraints
558 std::vector<ConstraintPtr>::iterator aUnuseIt = anUnusedConstraints.begin();
559 while (aUnuseIt != anUnusedConstraints.end()) {
560 if (aNewFeatStorage->isInteract(*aUnuseIt)) {
561 size_t aShift = aUnuseIt - anUnusedConstraints.begin();
562 anUnusedConstraints.erase(aUnuseIt);
563 aUnuseIt = anUnusedConstraints.begin() + aShift;
569 std::vector<SketchSolver_Group*>::iterator aCutsIter;
570 aUnuseIt = anUnusedConstraints.begin();
571 for ( ; aUnuseIt != anUnusedConstraints.end(); aUnuseIt++) {
572 // Remove unused constraints
573 removeConstraint(*aUnuseIt);
574 // Try to append constraint to already existent group
575 for (aCutsIter = theCuts.begin(); aCutsIter != theCuts.end(); aCutsIter++)
576 if ((*aCutsIter)->isInteract(*aUnuseIt)) {
577 (*aCutsIter)->changeConstraint(*aUnuseIt);
580 if (aCutsIter == theCuts.end()) {
582 SketchSolver_Group* aGroup = new SketchSolver_Group(mySketch);
583 aGroup->changeConstraint(*aUnuseIt);
584 theCuts.push_back(aGroup);
589 // ============================================================================
590 // Function: isConsistent
591 // Class: SketchSolver_Group
592 // Purpose: search removed entities and constraints
593 // ============================================================================
594 bool SketchSolver_Group::isConsistent()
596 if (!myFeatureStorage) // no one constraint is initialized yet
599 bool aResult = myFeatureStorage->isConsistent();
601 // remove invalid entities
602 std::set<ConstraintPtr> anInvalidConstraints;
603 ConstraintConstraintMap::iterator aCIter = myConstraints.begin();
604 for (; aCIter != myConstraints.end(); ++aCIter) {
605 if (!aCIter->first->data() || !aCIter->first->data()->isValid())
606 anInvalidConstraints.insert(aCIter->first);
608 std::set<ConstraintPtr>::const_iterator aRemoveIt = anInvalidConstraints.begin();
609 for (; aRemoveIt != anInvalidConstraints.end(); ++aRemoveIt)
610 removeConstraint(*aRemoveIt);
615 // ============================================================================
616 // Function: removeTemporaryConstraints
617 // Class: SketchSolver_Group
618 // Purpose: remove all transient SLVS_C_WHERE_DRAGGED constraints after
619 // resolving the set of constraints
620 // ============================================================================
621 void SketchSolver_Group::removeTemporaryConstraints()
623 myTempConstraints.clear();
624 while (myStorage->numberTemporary())
625 myStorage->deleteTemporaryConstraint();
626 // Clean lists of removed entities in the storage
627 std::set<Slvs_hParam> aRemPar;
628 std::set<Slvs_hEntity> aRemEnt;
629 std::set<Slvs_hConstraint> aRemCon;
630 myStorage->getRemoved(aRemPar, aRemEnt, aRemCon);
631 myStorage->setNeedToResolve(false);
634 // ============================================================================
635 // Function: removeConstraint
636 // Class: SketchSolver_Group
637 // Purpose: remove constraint and all unused entities
638 // ============================================================================
639 void SketchSolver_Group::removeConstraint(ConstraintPtr theConstraint)
641 bool isFullyRemoved = true;
642 myFeatureStorage->removeConstraint(theConstraint);
643 ConstraintConstraintMap::iterator aCIter = myConstraints.begin();
644 for (; aCIter != myConstraints.end(); aCIter++)
645 if (aCIter->second->hasConstraint(theConstraint)) {
646 if (!aCIter->second->remove(theConstraint)) // the constraint is not fully removed
647 isFullyRemoved = false;
650 if (aCIter == myConstraints.end())
654 myConstraints.erase(aCIter);
655 else if (aCIter != myConstraints.end() &&
656 aCIter->first->getKind() == SketchPlugin_ConstraintCoincidence::ID()) {
657 // Update multicoincidence
658 std::list<ConstraintPtr> aMultiCoinc;
659 SolverConstraintPtr aCoincidence = aCIter->second;
660 while (aCIter != myConstraints.end()) {
661 if (aCIter->second != aCoincidence) {
665 if (aCIter->first != theConstraint)
666 aMultiCoinc.push_back(aCIter->first);
667 aCIter->second->remove(aCIter->first);
668 ConstraintConstraintMap::iterator aRemoveIt = aCIter++;
669 myConstraints.erase(aRemoveIt);
672 std::list<ConstraintPtr>::iterator anIt = aMultiCoinc.begin();
673 for (; anIt != aMultiCoinc.end(); ++anIt)
674 changeConstraint(*anIt);
678 // ============================================================================
679 // Function: isComplexConstraint
680 // Class: SketchSolver_Group
681 // Purpose: verifies the constraint is complex, i.e. it needs another constraints to be created before
682 // ============================================================================
683 bool SketchSolver_Group::isComplexConstraint(FeaturePtr theConstraint)
685 return theConstraint->getKind() == SketchPlugin_ConstraintFillet::ID() ||
686 theConstraint->getKind() == SketchPlugin_ConstraintMirror::ID() ||
687 theConstraint->getKind() == SketchPlugin_ConstraintTangent::ID();
690 // ============================================================================
691 // Function: setTemporary
692 // Class: SketchSolver_Group
693 // Purpose: append given constraint to th group of temporary constraints
694 // ============================================================================
695 void SketchSolver_Group::setTemporary(SolverConstraintPtr theConstraint)
697 theConstraint->makeTemporary();
698 myTempConstraints.insert(theConstraint);