1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: SketchSolver_Storage.cpp
4 // Created: 30 Nov 2015
5 // Author: Artem ZHIDKOV
7 #include <SketchSolver_Storage.h>
8 #include <SketchSolver_Manager.h>
10 #include <GeomDataAPI_Point2D.h>
11 #include <ModelAPI_AttributeRefAttr.h>
12 #include <ModelAPI_AttributeRefList.h>
13 #include <SketchPlugin_Arc.h>
14 #include <SketchPlugin_Circle.h>
15 #include <SketchPlugin_ConstraintRigid.h>
18 /// \brief Verify two vectors of constraints are equal.
19 /// Vectors differ by the order of elements are equal.
20 static bool isEqual(const std::list<ConstraintWrapperPtr>& theCVec1,
21 const std::list<ConstraintWrapperPtr>& theCVec2);
24 void SketchSolver_Storage::addConstraint(ConstraintPtr theConstraint,
25 ConstraintWrapperPtr theSolverConstraint)
27 if (theSolverConstraint) {
28 std::list<ConstraintWrapperPtr> aConstrList(1, theSolverConstraint);
29 addConstraint(theConstraint, aConstrList);
31 addConstraint(theConstraint, std::list<ConstraintWrapperPtr>());
34 void SketchSolver_Storage::addConstraint(
35 ConstraintPtr theConstraint,
36 std::list<ConstraintWrapperPtr> theSolverConstraints)
38 std::map<ConstraintPtr, std::list<ConstraintWrapperPtr> >::const_iterator
39 aFound = myConstraintMap.find(theConstraint);
40 if (aFound == myConstraintMap.end() || !isEqual(aFound->second, theSolverConstraints))
41 setNeedToResolve(true);
43 if (theSolverConstraints.empty()) {
44 // constraint links to the empty list, add its attributes linked to the empty entities
45 std::list<AttributePtr> aRefAttrs =
46 theConstraint->data()->attributes(ModelAPI_AttributeRefAttr::typeId());
47 std::list<AttributePtr>::const_iterator anAttrIt = aRefAttrs.begin();
48 for (; anAttrIt != aRefAttrs.end(); ++anAttrIt) {
49 AttributeRefAttrPtr aRef = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttrIt);
50 if (aRef->isObject()) {
51 FeaturePtr aFeature = ModelAPI_Feature::feature(aRef->object());
52 if (aFeature) addEntity(aFeature, EntityWrapperPtr());
54 addEntity(aRef->attr(), EntityWrapperPtr());
56 std::list<AttributePtr> aRefLists =
57 theConstraint->data()->attributes(ModelAPI_AttributeRefList::typeId());
58 for (anAttrIt = aRefLists.begin(); anAttrIt != aRefLists.end(); ++anAttrIt) {
59 AttributeRefListPtr aRef = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(*anAttrIt);
60 std::list<ObjectPtr> anObj = aRef->list();
61 std::list<ObjectPtr>::iterator anIt = anObj.begin();
62 for (; anIt != anObj.end(); ++anIt) {
63 FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
64 if (aFeature) addEntity(aFeature, EntityWrapperPtr());
68 else if (theSolverConstraints.front()->type() != CONSTRAINT_PT_PT_COINCIDENT) {
69 // Do not add point-point coincidence, because it is already made by setting
70 // the same parameters for both points
71 std::list<ConstraintWrapperPtr>::iterator aCIt = theSolverConstraints.begin();
72 for (; aCIt != theSolverConstraints.end(); ++aCIt)
76 if (!theSolverConstraints.empty() || aFound == myConstraintMap.end())
77 myConstraintMap[theConstraint] = theSolverConstraints;
78 // block events if necessary
79 if (myEventsBlocked && theConstraint->data() && theConstraint->data()->isValid())
80 theConstraint->data()->blockSendAttributeUpdated(myEventsBlocked);
83 void SketchSolver_Storage::addEntity(FeaturePtr theFeature,
84 EntityWrapperPtr theSolverEntity)
86 std::map<FeaturePtr, EntityWrapperPtr>::const_iterator aFound = myFeatureMap.find(theFeature);
87 if (aFound == myFeatureMap.end() || !aFound->second ||
88 (theSolverEntity && !aFound->second->isEqual(theSolverEntity)))
89 setNeedToResolve(true); // the entity is new or modified
91 if (!theSolverEntity) {
92 // feature links to the empty entity, add its attributes
93 std::list<AttributePtr> aPntAttrs =
94 theFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
95 std::list<AttributePtr>::const_iterator anAttrIt = aPntAttrs.begin();
96 for (; anAttrIt != aPntAttrs.end(); ++anAttrIt)
97 addEntity(*anAttrIt, EntityWrapperPtr());
98 if (aFound == myFeatureMap.end())
99 myFeatureMap[theFeature] = theSolverEntity;
101 myFeatureMap[theFeature] = theSolverEntity;
103 // block events if necessary
104 if (myEventsBlocked && theFeature->data() && theFeature->data()->isValid())
105 theFeature->data()->blockSendAttributeUpdated(myEventsBlocked);
108 void SketchSolver_Storage::addEntity(AttributePtr theAttribute,
109 EntityWrapperPtr theSolverEntity)
111 std::map<AttributePtr, EntityWrapperPtr>::const_iterator aFound = myAttributeMap.find(theAttribute);
112 if (aFound == myAttributeMap.end() || !aFound->second ||
113 (theSolverEntity && !aFound->second->isEqual(theSolverEntity)))
114 setNeedToResolve(true); // the entity is new or modified
116 if (theSolverEntity || aFound == myAttributeMap.end())
117 myAttributeMap[theAttribute] = theSolverEntity;
118 // block events if necessary
119 if (myEventsBlocked && theAttribute->owner() &&
120 theAttribute->owner()->data() && theAttribute->owner()->data()->isValid())
121 theAttribute->owner()->data()->blockSendAttributeUpdated(myEventsBlocked);
125 bool SketchSolver_Storage::update(FeaturePtr theFeature, const GroupID& theGroup)
127 bool isUpdated = false;
128 EntityWrapperPtr aRelated = entity(theFeature);
129 if (!aRelated) { // Feature is not exist, create it
130 std::list<EntityWrapperPtr> aSubs;
131 // Reserve the feature in the map of features (do not want to add several copies of it)
132 myFeatureMap[theFeature] = aRelated;
133 // Firstly, create/update its attributes
134 std::list<AttributePtr> anAttrs =
135 theFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
136 std::list<AttributePtr>::const_iterator anIt = anAttrs.begin();
137 for (; anIt != anAttrs.end(); ++anIt) {
138 isUpdated = update(*anIt, theGroup) || isUpdated;
139 aSubs.push_back(entity(*anIt));
141 // If the feature is a circle, add its radius as a sub
142 if (theFeature->getKind() == SketchPlugin_Circle::ID()) {
143 AttributePtr aRadius = theFeature->attribute(SketchPlugin_Circle::RADIUS_ID());
144 isUpdated = update(aRadius, theGroup) || isUpdated;
145 aSubs.push_back(entity(aRadius));
147 // If the feature if circle or arc, we need to add normal of the sketch to the list of subs
148 if (theFeature->getKind() == SketchPlugin_Arc::ID() ||
149 theFeature->getKind() == SketchPlugin_Circle::ID()) {
150 EntityWrapperPtr aNormal = getNormal();
151 if (aNormal) aSubs.push_back(aNormal);
153 // Secondly, convert feature
154 BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
155 GroupID aGroup = theGroup != GID_UNKNOWN ? theGroup : myGroupID;
156 aRelated = aBuilder->createFeature(theFeature, aSubs, aGroup);
159 addEntity(theFeature, aRelated);
160 } else if (theGroup != GID_UNKNOWN)
161 changeGroup(aRelated, theGroup);
162 return update(aRelated) || isUpdated;
165 bool SketchSolver_Storage::update(AttributePtr theAttribute, const GroupID& theGroup)
167 AttributePtr anAttribute = theAttribute;
168 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttribute);
170 if (aRefAttr->isObject()) {
171 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
172 return update(aFeature, theGroup);
174 anAttribute = aRefAttr->attr();
177 EntityWrapperPtr aRelated = entity(anAttribute);
178 if (!aRelated) { // Attribute is not exist, create it
179 // verify the attribute is a point of arc and add whole arc
180 if (anAttribute->owner()) {
181 FeaturePtr aFeature = ModelAPI_Feature::feature(anAttribute->owner());
182 if (aFeature->getKind() == SketchPlugin_Arc::ID() &&
183 myFeatureMap.find(aFeature) == myFeatureMap.end()) {
184 // Additional checking that all attributes are initialized
185 if (aFeature->attribute(SketchPlugin_Arc::CENTER_ID())->isInitialized() &&
186 aFeature->attribute(SketchPlugin_Arc::START_ID())->isInitialized() &&
187 aFeature->attribute(SketchPlugin_Arc::END_ID())->isInitialized()) {
188 return SketchSolver_Storage::update(aFeature);
190 myFeatureMap[aFeature] = EntityWrapperPtr();
195 BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
196 GroupID aGroup = theGroup != GID_UNKNOWN ? theGroup : myGroupID;
197 aRelated = aBuilder->createAttribute(anAttribute, aGroup);
200 addEntity(anAttribute, aRelated);
201 } else if (theGroup != GID_UNKNOWN)
202 changeGroup(aRelated, theGroup);
203 return update(aRelated);
208 const std::list<ConstraintWrapperPtr>& SketchSolver_Storage::constraint(
209 const ConstraintPtr& theConstraint) const
211 static std::list<ConstraintWrapperPtr> aDummy;
213 std::map<ConstraintPtr, std::list<ConstraintWrapperPtr>>::const_iterator
214 aFound = myConstraintMap.find(theConstraint);
215 if (aFound != myConstraintMap.end())
216 return aFound->second;
220 const EntityWrapperPtr& SketchSolver_Storage::entity(const FeaturePtr& theFeature) const
222 static EntityWrapperPtr aDummy;
224 std::map<FeaturePtr, EntityWrapperPtr>::const_iterator aFound = myFeatureMap.find(theFeature);
225 if (aFound != myFeatureMap.end())
226 return aFound->second;
230 const EntityWrapperPtr& SketchSolver_Storage::entity(const AttributePtr& theAttribute) const
232 static EntityWrapperPtr aDummy;
234 std::map<AttributePtr, EntityWrapperPtr>::const_iterator
235 aFound = myAttributeMap.find(theAttribute);
236 if (aFound != myAttributeMap.end())
237 return aFound->second;
239 AttributeRefAttrPtr aRefAttr =
240 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
242 if (aRefAttr->isObject()) {
243 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
244 return entity(aFeature);
246 return entity(aRefAttr->attr());
251 bool SketchSolver_Storage::removeConstraint(ConstraintPtr theConstraint)
253 std::map<ConstraintPtr, std::list<ConstraintWrapperPtr> >::iterator
254 aFound = myConstraintMap.find(theConstraint);
255 if (aFound == myConstraintMap.end())
256 return true; // no constraint, already deleted
259 std::list<ConstraintWrapperPtr> aConstrList = aFound->second;
260 myConstraintMap.erase(aFound);
261 // Remove SolveSpace constraints
262 bool isFullyRemoved = true;
263 std::list<ConstraintWrapperPtr>::iterator anIt = aConstrList.begin();
264 while (anIt != aConstrList.end()) {
266 std::list<ConstraintWrapperPtr>::iterator aRemoveIt = anIt++;
267 aConstrList.erase(aRemoveIt);
269 isFullyRemoved = false;
273 return isFullyRemoved;
276 template <class ENT_TYPE>
277 static bool isUsed(ConstraintWrapperPtr theConstraint, ENT_TYPE theEntity)
279 if (!theConstraint || !theEntity)
281 std::list<EntityWrapperPtr>::const_iterator anEntIt = theConstraint->entities().begin();
282 for (; anEntIt != theConstraint->entities().end(); ++anEntIt)
283 if ((*anEntIt)->isBase(theEntity))
288 static bool isUsed(EntityWrapperPtr theFeature, AttributePtr theSubEntity)
290 if (!theFeature || !theSubEntity)
292 std::list<EntityWrapperPtr>::const_iterator aSubIt = theFeature->subEntities().begin();
293 for (; aSubIt != theFeature->subEntities().end(); ++aSubIt)
294 if ((*aSubIt)->isBase(theSubEntity))
299 static bool isUsed(ConstraintPtr theConstraint, AttributePtr theAttribute)
301 if (!theConstraint || !theAttribute)
303 std::list<AttributePtr> anAttrList = theConstraint->data()->attributes(std::string());
304 std::list<AttributePtr>::const_iterator anIt = anAttrList.begin();
305 for (; anIt != anAttrList.end(); ++anIt) {
306 if (*anIt == theAttribute)
308 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anIt);
309 if (aRefAttr && !aRefAttr->isObject() && aRefAttr->attr() == theAttribute)
315 bool SketchSolver_Storage::isUsed(FeaturePtr theFeature) const
317 if (myFeatureMap.find(theFeature) != myFeatureMap.end())
320 std::map<ConstraintPtr, std::list<ConstraintWrapperPtr> >::const_iterator
321 aCIt = myConstraintMap.begin();
322 std::list<ConstraintWrapperPtr>::const_iterator aCWIt;
323 for (; aCIt != myConstraintMap.end(); ++aCIt)
324 for (aCWIt = aCIt->second.begin(); aCWIt != aCIt->second.end(); ++aCWIt)
325 if (::isUsed(*aCWIt, theFeature))
328 std::list<AttributePtr> anAttrList = theFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
329 std::list<AttributePtr>::const_iterator anIt = anAttrList.begin();
330 for (; anIt != anAttrList.end(); ++anIt)
336 bool SketchSolver_Storage::isUsed(AttributePtr theAttribute) const
338 AttributePtr anAttribute = theAttribute;
339 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttribute);
341 if (aRefAttr->isObject())
342 return isUsed(ModelAPI_Feature::feature(aRefAttr->object()));
344 anAttribute = aRefAttr->attr();
347 if (myAttributeMap.find(theAttribute) != myAttributeMap.end())
349 // check in constraints
350 std::map<ConstraintPtr, std::list<ConstraintWrapperPtr> >::const_iterator
351 aCIt = myConstraintMap.begin();
352 std::list<ConstraintWrapperPtr>::const_iterator aCWIt;
353 for (; aCIt != myConstraintMap.end(); ++aCIt) {
354 for (aCWIt = aCIt->second.begin(); aCWIt != aCIt->second.end(); ++aCWIt)
355 if (::isUsed(*aCWIt, anAttribute))
357 // Additional check for the Fixed constraints, which have no wrapper associated.
358 if (aCIt->first->getKind() == SketchPlugin_ConstraintRigid::ID() &&
359 ::isUsed(aCIt->first, anAttribute))
363 std::map<FeaturePtr, EntityWrapperPtr>::const_iterator aFIt = myFeatureMap.begin();
364 for (; aFIt != myFeatureMap.end(); ++aFIt)
365 if (::isUsed(aFIt->second, anAttribute))
371 bool SketchSolver_Storage::removeEntity(FeaturePtr theFeature)
373 std::map<FeaturePtr, EntityWrapperPtr>::iterator aFound = myFeatureMap.find(theFeature);
374 if (aFound == myFeatureMap.end())
375 return true; // feature not found, nothing to delete
377 EntityWrapperPtr anEntity = aFound->second;
378 myFeatureMap.erase(aFound);
380 // Check if the feature is not used by constraints, remove it
381 if (!anEntity || (!isUsed(theFeature) && remove(anEntity)))
384 // feature is not removed, revert operation
385 myFeatureMap[theFeature] = anEntity;
390 bool SketchSolver_Storage::removeEntity(AttributePtr theAttribute)
392 std::map<AttributePtr, EntityWrapperPtr>::iterator aFound = myAttributeMap.find(theAttribute);
393 if (aFound == myAttributeMap.end())
394 return true; // attribute not found, nothing to delete
396 EntityWrapperPtr anEntity = aFound->second;
397 myAttributeMap.erase(aFound);
399 // Check if the attribute is not used by constraints and features, remove it
400 if (!anEntity || (!isUsed(theAttribute) && remove(anEntity)))
403 // attribute is not removed, revert operation
404 myAttributeMap[theAttribute] = anEntity;
410 bool SketchSolver_Storage::remove(ConstraintWrapperPtr theConstraint)
412 bool isFullyRemoved = true;
413 std::list<EntityWrapperPtr>::const_iterator anIt = theConstraint->entities().begin();
414 for (; anIt != theConstraint->entities().end(); ++anIt) {
415 FeaturePtr aBaseFeature = (*anIt)->baseFeature();
417 isFullyRemoved = SketchSolver_Storage::removeEntity(aBaseFeature) && isFullyRemoved;
419 isFullyRemoved = SketchSolver_Storage::removeEntity((*anIt)->baseAttribute()) && isFullyRemoved;
421 return isFullyRemoved;
424 bool SketchSolver_Storage::remove(EntityWrapperPtr theEntity)
426 bool isFullyRemoved = true;
427 std::list<EntityWrapperPtr>::const_iterator anEntIt = theEntity->subEntities().begin();
428 for (; anEntIt != theEntity->subEntities().end(); ++anEntIt) {
429 FeaturePtr aBaseFeature = (*anEntIt)->baseFeature();
431 isFullyRemoved = SketchSolver_Storage::removeEntity(aBaseFeature) && isFullyRemoved;
433 isFullyRemoved = SketchSolver_Storage::removeEntity((*anEntIt)->baseAttribute()) && isFullyRemoved;
436 std::list<ParameterWrapperPtr>::const_iterator aParIt = theEntity->parameters().begin();
437 for (; aParIt != theEntity->parameters().end(); ++aParIt)
438 isFullyRemoved = remove(*aParIt) && isFullyRemoved;
439 return isFullyRemoved;
443 bool SketchSolver_Storage::isInteract(const FeaturePtr& theFeature) const
447 if (myConstraintMap.empty())
448 return true; // empty storage interacts with each feature
450 ConstraintPtr aConstraint = std::dynamic_pointer_cast<SketchPlugin_Constraint>(theFeature);
452 if (myConstraintMap.find(aConstraint) != myConstraintMap.end())
454 } else if (myFeatureMap.find(theFeature) != myFeatureMap.end())
457 std::list<AttributePtr> anAttrList = theFeature->data()->attributes(std::string());
458 std::list<AttributePtr>::const_iterator anIt = anAttrList.begin();
459 for (; anIt != anAttrList.end(); ++anIt)
460 if (isInteract(*anIt))
466 bool SketchSolver_Storage::isInteract(const AttributePtr& theAttribute) const
471 AttributeRefListPtr aRefList =
472 std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
474 std::list<ObjectPtr> anObjects = aRefList->list();
475 std::list<ObjectPtr>::iterator anObjIt = anObjects.begin();
476 for (; anObjIt != anObjects.end(); ++anObjIt) {
477 FeaturePtr aFeature = ModelAPI_Feature::feature(*anObjIt);
478 if (isInteract(aFeature))
484 AttributeRefAttrPtr aRefAttr =
485 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
487 return myAttributeMap.find(theAttribute) != myAttributeMap.end();
488 if (!aRefAttr->isObject())
489 return myAttributeMap.find(aRefAttr->attr()) != myAttributeMap.end();
491 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
492 return isInteract(aFeature);
495 bool SketchSolver_Storage::isConsistent() const
497 // Check the constraints are valid
498 std::map<ConstraintPtr, std::list<ConstraintWrapperPtr> >::const_iterator
499 aCIter = myConstraintMap.begin();
500 for (; aCIter != myConstraintMap.end(); ++aCIter)
501 if (!aCIter->first->data() || !aCIter->first->data()->isValid())
503 // Check the features are valid
504 std::map<FeaturePtr, EntityWrapperPtr>::const_iterator aFIter = myFeatureMap.begin();
505 for (; aFIter != myFeatureMap.end(); aFIter++)
506 if (!aFIter->first->data() || !aFIter->first->data()->isValid())
511 bool SketchSolver_Storage::isFixed(EntityWrapperPtr theEntity) const
513 if (theEntity->group() != myGroupID)
515 // no need additional checking for entities differ than point
516 if (theEntity->type() != ENTITY_POINT)
519 CoincidentPointsMap::const_iterator anIt = myCoincidentPoints.begin();
520 for (; anIt != myCoincidentPoints.end(); ++anIt)
521 if (anIt->first == theEntity || anIt->second.find(theEntity) != anIt->second.end()) {
522 if (anIt->first->group() != myGroupID)
524 std::set<EntityWrapperPtr>::const_iterator anEntIt = anIt->second.begin();
525 for (; anEntIt != anIt->second.end(); ++anEntIt)
526 if ((*anEntIt)->group() != myGroupID)
530 std::map<ConstraintPtr, std::list<ConstraintWrapperPtr> >::const_iterator aCIt = myConstraintMap.begin();
531 std::list<ConstraintWrapperPtr>::const_iterator aCWIt;
532 for (; aCIt != myConstraintMap.end(); ++aCIt) {
533 if (aCIt->second.empty())
535 aCWIt = aCIt->second.begin();
536 if ((*aCWIt)->type() != CONSTRAINT_FIXED)
538 for (; aCWIt != aCIt->second.end(); ++aCIt)
539 if ((theEntity->baseAttribute() && (*aCWIt)->isUsed(theEntity->baseAttribute())) ||
540 (theEntity->baseFeature() && (*aCWIt)->isUsed(theEntity->baseFeature())))
547 void SketchSolver_Storage::removeInvalidEntities()
549 // Remove invalid constraints
550 std::list<ConstraintPtr> anInvalidConstraints;
551 std::map<ConstraintPtr, std::list<ConstraintWrapperPtr> >::const_iterator
552 aCIter = myConstraintMap.begin();
553 for (; aCIter != myConstraintMap.end(); ++aCIter)
554 if (!aCIter->first->data() || !aCIter->first->data()->isValid())
555 anInvalidConstraints.push_back(aCIter->first);
556 std::list<ConstraintPtr>::const_iterator anInvCIt = anInvalidConstraints.begin();
557 for (; anInvCIt != anInvalidConstraints.end(); ++anInvCIt)
558 removeConstraint(*anInvCIt);
559 // Remove invalid features
560 std::list<FeaturePtr> anInvalidFeatures;
561 std::map<FeaturePtr, EntityWrapperPtr>::const_iterator aFIter = myFeatureMap.begin();
562 for (; aFIter != myFeatureMap.end(); aFIter++)
563 if (!aFIter->first->data() || !aFIter->first->data()->isValid())
564 anInvalidFeatures.push_back(aFIter->first);
565 std::list<FeaturePtr>::const_iterator anInvFIt = anInvalidFeatures.begin();
566 for (; anInvFIt != anInvalidFeatures.end(); ++anInvFIt)
567 removeEntity(*anInvFIt);
570 EntityWrapperPtr SketchSolver_Storage::getNormal() const
572 EntityWrapperPtr aSketch = sketch();
576 // Find normal entity
577 const std::list<EntityWrapperPtr>& aSketchSubs = aSketch->subEntities();
578 std::list<EntityWrapperPtr>::const_iterator aSIt = aSketchSubs.begin();
579 for (; aSIt != aSketchSubs.end(); ++aSIt)
580 if ((*aSIt)->type() == ENTITY_NORMAL)
582 return EntityWrapperPtr();
585 const EntityWrapperPtr& SketchSolver_Storage::sketch() const
587 static EntityWrapperPtr aDummySketch;
589 std::map<FeaturePtr, EntityWrapperPtr>::const_iterator aFIt = myFeatureMap.begin();
590 for (; aFIt != myFeatureMap.end(); ++aFIt)
591 if (aFIt->second && aFIt->second->type() == ENTITY_SKETCH)
593 if (aFIt == myFeatureMap.end())
598 void SketchSolver_Storage::setSketch(const EntityWrapperPtr& theSketch)
602 addEntity(FeaturePtr(), theSketch);
605 void SketchSolver_Storage::processArcs()
608 std::map<FeaturePtr, EntityWrapperPtr>::iterator aFIt = myFeatureMap.begin();
609 for (; aFIt != myFeatureMap.end(); ++aFIt)
610 if (!aFIt->second && aFIt->first->getKind() == SketchPlugin_Arc::ID()) {
611 // Additional checking the attributes are initialized
612 if (aFIt->first->attribute(SketchPlugin_Arc::CENTER_ID())->isInitialized() &&
613 aFIt->first->attribute(SketchPlugin_Arc::START_ID())->isInitialized() &&
614 aFIt->first->attribute(SketchPlugin_Arc::END_ID())->isInitialized())
621 void SketchSolver_Storage::blockEvents(bool isBlocked)
623 if (isBlocked == myEventsBlocked)
626 std::map<ConstraintPtr, std::list<ConstraintWrapperPtr> >::const_iterator
627 aCIter = myConstraintMap.begin();
628 for (; aCIter != myConstraintMap.end(); aCIter++)
629 if (aCIter->first->data() && aCIter->first->data()->isValid())
630 aCIter->first->data()->blockSendAttributeUpdated(isBlocked);
632 std::map<FeaturePtr, EntityWrapperPtr>::const_iterator aFIter = myFeatureMap.begin();
633 for (; aFIter != myFeatureMap.end(); aFIter++)
634 if (aFIter->first->data() && aFIter->first->data()->isValid())
635 aFIter->first->data()->blockSendAttributeUpdated(isBlocked);
637 std::map<AttributePtr, EntityWrapperPtr>::const_iterator anAtIter = myAttributeMap.begin();
638 for (; anAtIter != myAttributeMap.end(); anAtIter++)
639 if (anAtIter->first->owner() && anAtIter->first->owner()->data() &&
640 anAtIter->first->owner()->data()->isValid())
641 anAtIter->first->owner()->data()->blockSendAttributeUpdated(isBlocked);
642 myEventsBlocked = isBlocked;
650 // ============== Auxiliary functions ====================================
651 bool isEqual(const std::list<ConstraintWrapperPtr>& theCVec1,
652 const std::list<ConstraintWrapperPtr>& theCVec2)
654 if (theCVec1.size() != theCVec2.size())
657 std::list<bool> aChecked(theCVec2.size(), false);
658 std::list<ConstraintWrapperPtr>::const_iterator anIt1 = theCVec1.begin();
659 for (; anIt1 != theCVec1.end(); ++anIt1) {
660 std::list<ConstraintWrapperPtr>::const_iterator anIt2 = theCVec2.begin();
661 std::list<bool>::iterator aCheckIt = aChecked.begin();
662 while (aCheckIt != aChecked.end() && *aCheckIt) {
666 for (; anIt2 != theCVec2.end(); ++anIt2, ++aCheckIt)
667 if (!(*aCheckIt) && (*anIt1)->isEqual(*anIt2)) {
671 // the same constraint is not found
672 if (anIt2 == theCVec2.end())