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 && 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 // Check external feature
157 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
158 std::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
159 if (aSketchFeature && aSketchFeature->isExternal())
160 aGroup = GID_OUTOFGROUP;
161 aRelated = aBuilder->createFeature(theFeature, aSubs, aGroup);
164 addEntity(theFeature, aRelated);
165 } else if (theGroup != GID_UNKNOWN)
166 changeGroup(aRelated, theGroup);
167 return update(aRelated) || isUpdated;
170 bool SketchSolver_Storage::update(AttributePtr theAttribute, const GroupID& theGroup)
172 AttributePtr anAttribute = theAttribute;
173 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttribute);
175 if (aRefAttr->isObject()) {
176 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
177 return update(aFeature, theGroup);
179 anAttribute = aRefAttr->attr();
182 EntityWrapperPtr aRelated = entity(anAttribute);
183 if (!aRelated) { // Attribute is not exist, create it
184 // verify the attribute is a point of arc and add whole arc
185 if (anAttribute->owner()) {
186 FeaturePtr aFeature = ModelAPI_Feature::feature(anAttribute->owner());
187 if (aFeature->getKind() == SketchPlugin_Arc::ID() &&
188 myFeatureMap.find(aFeature) == myFeatureMap.end()) {
189 // Additional checking that all attributes are initialized
190 if (aFeature->attribute(SketchPlugin_Arc::CENTER_ID())->isInitialized() &&
191 aFeature->attribute(SketchPlugin_Arc::START_ID())->isInitialized() &&
192 aFeature->attribute(SketchPlugin_Arc::END_ID())->isInitialized()) {
193 return SketchSolver_Storage::update(aFeature);
195 myFeatureMap[aFeature] = EntityWrapperPtr();
200 BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
201 GroupID aGroup = theGroup != GID_UNKNOWN ? theGroup : myGroupID;
202 // Check attribute of external features
203 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
204 std::dynamic_pointer_cast<SketchPlugin_Feature>(theAttribute->owner());
205 if (aSketchFeature && aSketchFeature->isExternal())
206 aGroup = GID_OUTOFGROUP;
207 aRelated = aBuilder->createAttribute(anAttribute, aGroup);
210 addEntity(anAttribute, aRelated);
211 } else if (theGroup != GID_UNKNOWN)
212 changeGroup(aRelated, theGroup);
213 return update(aRelated);
218 const std::list<ConstraintWrapperPtr>& SketchSolver_Storage::constraint(
219 const ConstraintPtr& theConstraint) const
221 static std::list<ConstraintWrapperPtr> aDummy;
223 std::map<ConstraintPtr, std::list<ConstraintWrapperPtr>>::const_iterator
224 aFound = myConstraintMap.find(theConstraint);
225 if (aFound != myConstraintMap.end())
226 return aFound->second;
230 const EntityWrapperPtr& SketchSolver_Storage::entity(const FeaturePtr& theFeature) const
232 static EntityWrapperPtr aDummy;
234 std::map<FeaturePtr, EntityWrapperPtr>::const_iterator aFound = myFeatureMap.find(theFeature);
235 if (aFound != myFeatureMap.end())
236 return aFound->second;
240 const EntityWrapperPtr& SketchSolver_Storage::entity(const AttributePtr& theAttribute) const
242 static EntityWrapperPtr aDummy;
244 std::map<AttributePtr, EntityWrapperPtr>::const_iterator
245 aFound = myAttributeMap.find(theAttribute);
246 if (aFound != myAttributeMap.end())
247 return aFound->second;
249 AttributeRefAttrPtr aRefAttr =
250 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
252 if (aRefAttr->isObject()) {
253 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
254 return entity(aFeature);
256 return entity(aRefAttr->attr());
261 bool SketchSolver_Storage::removeConstraint(ConstraintPtr theConstraint)
263 std::map<ConstraintPtr, std::list<ConstraintWrapperPtr> >::iterator
264 aFound = myConstraintMap.find(theConstraint);
265 if (aFound == myConstraintMap.end())
266 return true; // no constraint, already deleted
269 std::list<ConstraintWrapperPtr> aConstrList = aFound->second;
270 myConstraintMap.erase(aFound);
271 // Remove SolveSpace constraints
272 bool isFullyRemoved = true;
273 std::list<ConstraintWrapperPtr>::iterator anIt = aConstrList.begin();
274 while (anIt != aConstrList.end()) {
276 std::list<ConstraintWrapperPtr>::iterator aRemoveIt = anIt++;
277 aConstrList.erase(aRemoveIt);
279 isFullyRemoved = false;
283 return isFullyRemoved;
286 template <class ENT_TYPE>
287 static bool isUsed(ConstraintWrapperPtr theConstraint, ENT_TYPE theEntity)
289 if (!theConstraint || !theEntity)
291 std::list<EntityWrapperPtr>::const_iterator anEntIt = theConstraint->entities().begin();
292 for (; anEntIt != theConstraint->entities().end(); ++anEntIt)
293 if ((*anEntIt)->isBase(theEntity))
298 static bool isUsed(EntityWrapperPtr theFeature, AttributePtr theSubEntity)
300 if (!theFeature || !theSubEntity)
302 std::list<EntityWrapperPtr>::const_iterator aSubIt = theFeature->subEntities().begin();
303 for (; aSubIt != theFeature->subEntities().end(); ++aSubIt)
304 if ((*aSubIt)->isBase(theSubEntity))
309 static bool isUsed(ConstraintPtr theConstraint, AttributePtr theAttribute)
311 if (!theConstraint || !theAttribute)
313 std::list<AttributePtr> anAttrList = theConstraint->data()->attributes(std::string());
314 std::list<AttributePtr>::const_iterator anIt = anAttrList.begin();
315 for (; anIt != anAttrList.end(); ++anIt) {
316 if (*anIt == theAttribute)
318 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anIt);
319 if (aRefAttr && !aRefAttr->isObject() && aRefAttr->attr() == theAttribute)
325 bool SketchSolver_Storage::isUsed(FeaturePtr theFeature) const
327 if (myFeatureMap.find(theFeature) != myFeatureMap.end())
330 std::map<ConstraintPtr, std::list<ConstraintWrapperPtr> >::const_iterator
331 aCIt = myConstraintMap.begin();
332 std::list<ConstraintWrapperPtr>::const_iterator aCWIt;
333 for (; aCIt != myConstraintMap.end(); ++aCIt)
334 for (aCWIt = aCIt->second.begin(); aCWIt != aCIt->second.end(); ++aCWIt)
335 if (::isUsed(*aCWIt, theFeature))
338 std::list<AttributePtr> anAttrList = theFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
339 std::list<AttributePtr>::const_iterator anIt = anAttrList.begin();
340 for (; anIt != anAttrList.end(); ++anIt)
346 bool SketchSolver_Storage::isUsed(AttributePtr theAttribute) const
348 AttributePtr anAttribute = theAttribute;
349 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttribute);
351 if (aRefAttr->isObject())
352 return isUsed(ModelAPI_Feature::feature(aRefAttr->object()));
354 anAttribute = aRefAttr->attr();
357 if (myAttributeMap.find(theAttribute) != myAttributeMap.end())
359 // check in constraints
360 std::map<ConstraintPtr, std::list<ConstraintWrapperPtr> >::const_iterator
361 aCIt = myConstraintMap.begin();
362 std::list<ConstraintWrapperPtr>::const_iterator aCWIt;
363 for (; aCIt != myConstraintMap.end(); ++aCIt) {
364 for (aCWIt = aCIt->second.begin(); aCWIt != aCIt->second.end(); ++aCWIt)
365 if (::isUsed(*aCWIt, anAttribute))
367 // Additional check for the Fixed constraints, which have no wrapper associated.
368 if (aCIt->first->getKind() == SketchPlugin_ConstraintRigid::ID() &&
369 ::isUsed(aCIt->first, anAttribute))
373 std::map<FeaturePtr, EntityWrapperPtr>::const_iterator aFIt = myFeatureMap.begin();
374 for (; aFIt != myFeatureMap.end(); ++aFIt)
375 if (::isUsed(aFIt->second, anAttribute))
381 bool SketchSolver_Storage::removeEntity(FeaturePtr theFeature)
383 std::map<FeaturePtr, EntityWrapperPtr>::iterator aFound = myFeatureMap.find(theFeature);
384 if (aFound == myFeatureMap.end())
385 return true; // feature not found, nothing to delete
387 EntityWrapperPtr anEntity = aFound->second;
388 myFeatureMap.erase(aFound);
390 // Check if the feature is not used by constraints, remove it
391 if (!anEntity || (!isUsed(theFeature) && remove(anEntity)))
394 // feature is not removed, revert operation
395 myFeatureMap[theFeature] = anEntity;
400 bool SketchSolver_Storage::removeEntity(AttributePtr theAttribute)
402 std::map<AttributePtr, EntityWrapperPtr>::iterator aFound = myAttributeMap.find(theAttribute);
403 if (aFound == myAttributeMap.end())
404 return true; // attribute not found, nothing to delete
406 EntityWrapperPtr anEntity = aFound->second;
407 myAttributeMap.erase(aFound);
409 // Check if the attribute is not used by constraints and features, remove it
410 if (!anEntity || (!isUsed(theAttribute) && remove(anEntity)))
413 // attribute is not removed, revert operation
414 myAttributeMap[theAttribute] = anEntity;
420 bool SketchSolver_Storage::remove(ConstraintWrapperPtr theConstraint)
422 bool isFullyRemoved = true;
423 std::list<EntityWrapperPtr>::const_iterator anIt = theConstraint->entities().begin();
424 for (; anIt != theConstraint->entities().end(); ++anIt) {
425 FeaturePtr aBaseFeature = (*anIt)->baseFeature();
427 isFullyRemoved = SketchSolver_Storage::removeEntity(aBaseFeature) && isFullyRemoved;
429 isFullyRemoved = SketchSolver_Storage::removeEntity((*anIt)->baseAttribute()) && isFullyRemoved;
431 return isFullyRemoved;
434 bool SketchSolver_Storage::remove(EntityWrapperPtr theEntity)
436 bool isFullyRemoved = true;
437 std::list<EntityWrapperPtr>::const_iterator anEntIt = theEntity->subEntities().begin();
438 for (; anEntIt != theEntity->subEntities().end(); ++anEntIt) {
439 FeaturePtr aBaseFeature = (*anEntIt)->baseFeature();
441 isFullyRemoved = SketchSolver_Storage::removeEntity(aBaseFeature) && isFullyRemoved;
443 isFullyRemoved = SketchSolver_Storage::removeEntity((*anEntIt)->baseAttribute()) && isFullyRemoved;
446 std::list<ParameterWrapperPtr>::const_iterator aParIt = theEntity->parameters().begin();
447 for (; aParIt != theEntity->parameters().end(); ++aParIt)
448 isFullyRemoved = remove(*aParIt) && isFullyRemoved;
449 return isFullyRemoved;
453 bool SketchSolver_Storage::isInteract(const FeaturePtr& theFeature) const
457 if (myConstraintMap.empty())
458 return true; // empty storage interacts with each feature
460 ConstraintPtr aConstraint = std::dynamic_pointer_cast<SketchPlugin_Constraint>(theFeature);
462 if (myConstraintMap.find(aConstraint) != myConstraintMap.end())
464 } else if (myFeatureMap.find(theFeature) != myFeatureMap.end())
467 std::list<AttributePtr> anAttrList = theFeature->data()->attributes(std::string());
468 std::list<AttributePtr>::const_iterator anIt = anAttrList.begin();
469 for (; anIt != anAttrList.end(); ++anIt)
470 if (isInteract(*anIt))
476 bool SketchSolver_Storage::isInteract(const AttributePtr& theAttribute) const
481 AttributeRefListPtr aRefList =
482 std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
484 std::list<ObjectPtr> anObjects = aRefList->list();
485 std::list<ObjectPtr>::iterator anObjIt = anObjects.begin();
486 for (; anObjIt != anObjects.end(); ++anObjIt) {
487 FeaturePtr aFeature = ModelAPI_Feature::feature(*anObjIt);
488 if (isInteract(aFeature))
494 AttributeRefAttrPtr aRefAttr =
495 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
497 return myAttributeMap.find(theAttribute) != myAttributeMap.end();
498 if (!aRefAttr->isObject())
499 return myAttributeMap.find(aRefAttr->attr()) != myAttributeMap.end();
501 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
502 return isInteract(aFeature);
505 bool SketchSolver_Storage::isConsistent() const
507 // Check the constraints are valid
508 std::map<ConstraintPtr, std::list<ConstraintWrapperPtr> >::const_iterator
509 aCIter = myConstraintMap.begin();
510 for (; aCIter != myConstraintMap.end(); ++aCIter)
511 if (!aCIter->first->data() || !aCIter->first->data()->isValid())
513 // Check the features are valid
514 std::map<FeaturePtr, EntityWrapperPtr>::const_iterator aFIter = myFeatureMap.begin();
515 for (; aFIter != myFeatureMap.end(); aFIter++)
516 if (!aFIter->first->data() || !aFIter->first->data()->isValid())
521 bool SketchSolver_Storage::isFixed(EntityWrapperPtr theEntity) const
523 if (theEntity->group() != myGroupID)
525 // no need additional checking for entities differ than point
526 if (theEntity->type() != ENTITY_POINT)
529 CoincidentPointsMap::const_iterator anIt = myCoincidentPoints.begin();
530 for (; anIt != myCoincidentPoints.end(); ++anIt)
531 if (anIt->first == theEntity || anIt->second.find(theEntity) != anIt->second.end()) {
532 if (anIt->first->group() != myGroupID)
534 std::set<EntityWrapperPtr>::const_iterator anEntIt = anIt->second.begin();
535 for (; anEntIt != anIt->second.end(); ++anEntIt)
536 if ((*anEntIt)->group() != myGroupID)
540 std::map<ConstraintPtr, std::list<ConstraintWrapperPtr> >::const_iterator aCIt = myConstraintMap.begin();
541 std::list<ConstraintWrapperPtr>::const_iterator aCWIt;
542 for (; aCIt != myConstraintMap.end(); ++aCIt) {
543 if (aCIt->second.empty())
545 aCWIt = aCIt->second.begin();
546 if ((*aCWIt)->type() != CONSTRAINT_FIXED)
548 for (; aCWIt != aCIt->second.end(); ++aCIt)
549 if ((theEntity->baseAttribute() && (*aCWIt)->isUsed(theEntity->baseAttribute())) ||
550 (theEntity->baseFeature() && (*aCWIt)->isUsed(theEntity->baseFeature())))
557 void SketchSolver_Storage::removeInvalidEntities()
559 // Remove invalid constraints
560 std::list<ConstraintPtr> anInvalidConstraints;
561 std::map<ConstraintPtr, std::list<ConstraintWrapperPtr> >::const_iterator
562 aCIter = myConstraintMap.begin();
563 for (; aCIter != myConstraintMap.end(); ++aCIter)
564 if (!aCIter->first->data() || !aCIter->first->data()->isValid())
565 anInvalidConstraints.push_back(aCIter->first);
566 std::list<ConstraintPtr>::const_iterator anInvCIt = anInvalidConstraints.begin();
567 for (; anInvCIt != anInvalidConstraints.end(); ++anInvCIt)
568 removeConstraint(*anInvCIt);
569 // Remove invalid features
570 std::list<FeaturePtr> anInvalidFeatures;
571 std::map<FeaturePtr, EntityWrapperPtr>::const_iterator aFIter = myFeatureMap.begin();
572 for (; aFIter != myFeatureMap.end(); aFIter++)
573 if (!aFIter->first->data() || !aFIter->first->data()->isValid())
574 anInvalidFeatures.push_back(aFIter->first);
575 std::list<FeaturePtr>::const_iterator anInvFIt = anInvalidFeatures.begin();
576 for (; anInvFIt != anInvalidFeatures.end(); ++anInvFIt)
577 removeEntity(*anInvFIt);
580 EntityWrapperPtr SketchSolver_Storage::getNormal() const
582 EntityWrapperPtr aSketch = sketch();
586 // Find normal entity
587 const std::list<EntityWrapperPtr>& aSketchSubs = aSketch->subEntities();
588 std::list<EntityWrapperPtr>::const_iterator aSIt = aSketchSubs.begin();
589 for (; aSIt != aSketchSubs.end(); ++aSIt)
590 if ((*aSIt)->type() == ENTITY_NORMAL)
592 return EntityWrapperPtr();
595 const EntityWrapperPtr& SketchSolver_Storage::sketch() const
597 static EntityWrapperPtr aDummySketch;
599 std::map<FeaturePtr, EntityWrapperPtr>::const_iterator aFIt = myFeatureMap.begin();
600 for (; aFIt != myFeatureMap.end(); ++aFIt)
601 if (aFIt->second && aFIt->second->type() == ENTITY_SKETCH)
603 if (aFIt == myFeatureMap.end())
608 void SketchSolver_Storage::setSketch(const EntityWrapperPtr& theSketch)
612 addEntity(FeaturePtr(), theSketch);
615 void SketchSolver_Storage::processArcs()
618 std::map<FeaturePtr, EntityWrapperPtr>::iterator aFIt = myFeatureMap.begin();
619 for (; aFIt != myFeatureMap.end(); ++aFIt)
620 if (!aFIt->second && aFIt->first->getKind() == SketchPlugin_Arc::ID()) {
621 // Additional checking the attributes are initialized
622 if (aFIt->first->attribute(SketchPlugin_Arc::CENTER_ID())->isInitialized() &&
623 aFIt->first->attribute(SketchPlugin_Arc::START_ID())->isInitialized() &&
624 aFIt->first->attribute(SketchPlugin_Arc::END_ID())->isInitialized())
631 void SketchSolver_Storage::blockEvents(bool isBlocked)
633 if (isBlocked == myEventsBlocked)
636 std::map<ConstraintPtr, std::list<ConstraintWrapperPtr> >::const_iterator
637 aCIter = myConstraintMap.begin();
638 for (; aCIter != myConstraintMap.end(); aCIter++)
639 if (aCIter->first->data() && aCIter->first->data()->isValid())
640 aCIter->first->data()->blockSendAttributeUpdated(isBlocked);
642 std::map<FeaturePtr, EntityWrapperPtr>::const_iterator aFIter = myFeatureMap.begin();
643 for (; aFIter != myFeatureMap.end(); aFIter++)
644 if (aFIter->first->data() && aFIter->first->data()->isValid())
645 aFIter->first->data()->blockSendAttributeUpdated(isBlocked);
647 std::map<AttributePtr, EntityWrapperPtr>::const_iterator anAtIter = myAttributeMap.begin();
648 for (; anAtIter != myAttributeMap.end(); anAtIter++)
649 if (anAtIter->first->owner() && anAtIter->first->owner()->data() &&
650 anAtIter->first->owner()->data()->isValid())
651 anAtIter->first->owner()->data()->blockSendAttributeUpdated(isBlocked);
652 myEventsBlocked = isBlocked;
655 std::set<ObjectPtr> SketchSolver_Storage::getConflictingConstraints(SolverPtr theSolver) const
657 std::set<ObjectPtr> aConflicting;
658 std::map<ConstraintPtr, std::list<ConstraintWrapperPtr> >::const_iterator
659 aConstrIt = myConstraintMap.begin();
660 for (; aConstrIt != myConstraintMap.end(); ++aConstrIt) {
661 std::list<ConstraintWrapperPtr>::const_iterator anIt = aConstrIt->second.begin();
662 for (; anIt != aConstrIt->second.end(); ++anIt)
663 if (theSolver->isConflicting((*anIt)->id())) {
664 aConflicting.insert(aConstrIt->first);
675 // ============== Auxiliary functions ====================================
676 bool isEqual(const std::list<ConstraintWrapperPtr>& theCVec1,
677 const std::list<ConstraintWrapperPtr>& theCVec2)
679 if (theCVec1.size() != theCVec2.size())
682 std::list<bool> aChecked(theCVec2.size(), false);
683 std::list<ConstraintWrapperPtr>::const_iterator anIt1 = theCVec1.begin();
684 for (; anIt1 != theCVec1.end(); ++anIt1) {
685 std::list<ConstraintWrapperPtr>::const_iterator anIt2 = theCVec2.begin();
686 std::list<bool>::iterator aCheckIt = aChecked.begin();
687 while (aCheckIt != aChecked.end() && *aCheckIt) {
691 for (; anIt2 != theCVec2.end(); ++anIt2, ++aCheckIt)
692 if (!(*aCheckIt) && (*anIt1)->isEqual(*anIt2)) {
696 // the same constraint is not found
697 if (anIt2 == theCVec2.end())