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_Line.h>
16 #include <SketchPlugin_Point.h>
17 #include <SketchPlugin_IntersectionPoint.h>
18 #include <SketchPlugin_ConstraintRigid.h>
21 /// \brief Verify two vectors of constraints are equal.
22 /// Vectors differ by the order of elements are equal.
23 static bool isEqual(const std::list<ConstraintWrapperPtr>& theCVec1,
24 const std::list<ConstraintWrapperPtr>& theCVec2);
27 void SketchSolver_Storage::addConstraint(ConstraintPtr theConstraint,
28 ConstraintWrapperPtr theSolverConstraint)
30 if (theSolverConstraint) {
31 std::list<ConstraintWrapperPtr> aConstrList(1, theSolverConstraint);
32 addConstraint(theConstraint, aConstrList);
34 addConstraint(theConstraint, std::list<ConstraintWrapperPtr>());
37 void SketchSolver_Storage::addConstraint(
38 ConstraintPtr theConstraint,
39 std::list<ConstraintWrapperPtr> theSolverConstraints)
41 std::map<ConstraintPtr, std::list<ConstraintWrapperPtr> >::const_iterator
42 aFound = myConstraintMap.find(theConstraint);
43 if (aFound == myConstraintMap.end() || !isEqual(aFound->second, theSolverConstraints))
44 setNeedToResolve(true);
46 if (theSolverConstraints.empty()) {
47 // constraint links to the empty list, add its attributes linked to the empty entities
48 std::list<AttributePtr> aRefAttrs =
49 theConstraint->data()->attributes(ModelAPI_AttributeRefAttr::typeId());
50 std::list<AttributePtr>::const_iterator anAttrIt = aRefAttrs.begin();
51 for (; anAttrIt != aRefAttrs.end(); ++anAttrIt) {
52 AttributeRefAttrPtr aRef = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttrIt);
53 if (aRef->isObject()) {
54 FeaturePtr aFeature = ModelAPI_Feature::feature(aRef->object());
55 if (aFeature) addEntity(aFeature, EntityWrapperPtr());
57 addEntity(aRef->attr(), EntityWrapperPtr());
59 std::list<AttributePtr> aRefLists =
60 theConstraint->data()->attributes(ModelAPI_AttributeRefList::typeId());
61 for (anAttrIt = aRefLists.begin(); anAttrIt != aRefLists.end(); ++anAttrIt) {
62 AttributeRefListPtr aRef = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(*anAttrIt);
63 std::list<ObjectPtr> anObj = aRef->list();
64 std::list<ObjectPtr>::iterator anIt = anObj.begin();
65 for (; anIt != anObj.end(); ++anIt) {
66 FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
67 if (aFeature) addEntity(aFeature, EntityWrapperPtr());
71 else if (theSolverConstraints.front()->type() != CONSTRAINT_PT_PT_COINCIDENT) {
72 // Do not add point-point coincidence, because it is already made by setting
73 // the same parameters for both points
74 std::list<ConstraintWrapperPtr>::iterator aCIt = theSolverConstraints.begin();
75 for (; aCIt != theSolverConstraints.end(); ++aCIt)
79 if (!theSolverConstraints.empty() || aFound == myConstraintMap.end())
80 myConstraintMap[theConstraint] = theSolverConstraints;
81 // block events if necessary
82 if (myEventsBlocked && theConstraint && theConstraint->data() && theConstraint->data()->isValid())
83 theConstraint->data()->blockSendAttributeUpdated(myEventsBlocked);
86 static std::list<AttributePtr> pointAttributes(FeaturePtr theFeature)
88 std::list<AttributePtr> aPoints;
89 if (theFeature->getKind() == SketchPlugin_Arc::ID()) {
90 aPoints.push_back(theFeature->attribute(SketchPlugin_Arc::CENTER_ID()));
91 aPoints.push_back(theFeature->attribute(SketchPlugin_Arc::START_ID()));
92 aPoints.push_back(theFeature->attribute(SketchPlugin_Arc::END_ID()));
94 else if (theFeature->getKind() == SketchPlugin_Circle::ID())
95 aPoints.push_back(theFeature->attribute(SketchPlugin_Circle::CENTER_ID()));
96 else if (theFeature->getKind() == SketchPlugin_Line::ID()) {
97 aPoints.push_back(theFeature->attribute(SketchPlugin_Line::START_ID()));
98 aPoints.push_back(theFeature->attribute(SketchPlugin_Line::END_ID()));
100 else if (theFeature->getKind() == SketchPlugin_Point::ID() ||
101 theFeature->getKind() == SketchPlugin_IntersectionPoint::ID())
102 aPoints.push_back(theFeature->attribute(SketchPlugin_Point::COORD_ID()));
106 void SketchSolver_Storage::addEntity(FeaturePtr theFeature,
107 EntityWrapperPtr theSolverEntity)
109 std::map<FeaturePtr, EntityWrapperPtr>::const_iterator aFound = myFeatureMap.find(theFeature);
110 if (aFound == myFeatureMap.end() || !aFound->second ||
111 (theSolverEntity && !aFound->second->isEqual(theSolverEntity)))
112 setNeedToResolve(true); // the entity is new or modified
114 if (!theSolverEntity) {
115 // feature links to the empty entity, add its attributes
116 std::list<AttributePtr> aPntAttrs = pointAttributes(theFeature);
117 std::list<AttributePtr>::const_iterator anAttrIt = aPntAttrs.begin();
118 for (; anAttrIt != aPntAttrs.end(); ++anAttrIt)
119 addEntity(*anAttrIt, EntityWrapperPtr());
120 if (aFound == myFeatureMap.end())
121 myFeatureMap[theFeature] = theSolverEntity;
123 myFeatureMap[theFeature] = theSolverEntity;
125 // block events if necessary
126 if (myEventsBlocked && theFeature->data() && theFeature->data()->isValid())
127 theFeature->data()->blockSendAttributeUpdated(myEventsBlocked);
130 void SketchSolver_Storage::addEntity(AttributePtr theAttribute,
131 EntityWrapperPtr theSolverEntity)
133 std::map<AttributePtr, EntityWrapperPtr>::const_iterator aFound = myAttributeMap.find(theAttribute);
134 if (aFound == myAttributeMap.end() || !aFound->second ||
135 (theSolverEntity && !aFound->second->isEqual(theSolverEntity)))
136 setNeedToResolve(true); // the entity is new or modified
138 if (theSolverEntity || aFound == myAttributeMap.end())
139 myAttributeMap[theAttribute] = theSolverEntity;
140 // block events if necessary
141 if (myEventsBlocked && theAttribute->owner() &&
142 theAttribute->owner()->data() && theAttribute->owner()->data()->isValid())
143 theAttribute->owner()->data()->blockSendAttributeUpdated(myEventsBlocked);
147 bool SketchSolver_Storage::update(FeaturePtr theFeature, const GroupID& theGroup)
149 bool isUpdated = false;
150 EntityWrapperPtr aRelated = entity(theFeature);
151 if (!aRelated) { // Feature is not exist, create it
152 std::list<EntityWrapperPtr> aSubs;
153 // Reserve the feature in the map of features (do not want to add several copies of it)
154 myFeatureMap[theFeature] = aRelated;
155 // Firstly, create/update its attributes
156 std::list<AttributePtr> anAttrs = pointAttributes(theFeature);
157 std::list<AttributePtr>::const_iterator anIt = anAttrs.begin();
158 for (; anIt != anAttrs.end(); ++anIt) {
159 isUpdated = update(*anIt, theGroup) || isUpdated;
160 aSubs.push_back(entity(*anIt));
162 // If the feature is a circle, add its radius as a sub
163 if (theFeature->getKind() == SketchPlugin_Circle::ID()) {
164 AttributePtr aRadius = theFeature->attribute(SketchPlugin_Circle::RADIUS_ID());
165 isUpdated = update(aRadius, theGroup) || isUpdated;
166 aSubs.push_back(entity(aRadius));
168 // If the feature if circle or arc, we need to add normal of the sketch to the list of subs
169 if (theFeature->getKind() == SketchPlugin_Arc::ID() ||
170 theFeature->getKind() == SketchPlugin_Circle::ID()) {
171 EntityWrapperPtr aNormal = getNormal();
172 if (aNormal) aSubs.push_back(aNormal);
174 // Secondly, convert feature
175 BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
176 GroupID aGroup = theGroup != GID_UNKNOWN ? theGroup : myGroupID;
177 // Check external feature
178 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
179 std::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
180 if (aSketchFeature && aSketchFeature->isExternal())
181 aGroup = GID_OUTOFGROUP;
182 aRelated = aBuilder->createFeature(theFeature, aSubs, aGroup);
185 addEntity(theFeature, aRelated);
186 } else if (theGroup != GID_UNKNOWN)
187 changeGroup(aRelated, theGroup);
188 return update(aRelated) || isUpdated;
191 bool SketchSolver_Storage::update(AttributePtr theAttribute, const GroupID& theGroup)
193 AttributePtr anAttribute = theAttribute;
194 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttribute);
196 if (aRefAttr->isObject()) {
197 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
198 return update(aFeature, theGroup);
200 anAttribute = aRefAttr->attr();
203 EntityWrapperPtr aRelated = entity(anAttribute);
204 if (!aRelated) { // Attribute is not exist, create it
205 // verify the attribute is a point of arc and add whole arc
206 if (anAttribute->owner()) {
207 FeaturePtr aFeature = ModelAPI_Feature::feature(anAttribute->owner());
208 if (aFeature->getKind() == SketchPlugin_Arc::ID() &&
209 myFeatureMap.find(aFeature) == myFeatureMap.end()) {
210 // Additional checking that all attributes are initialized
211 if (aFeature->attribute(SketchPlugin_Arc::CENTER_ID())->isInitialized() &&
212 aFeature->attribute(SketchPlugin_Arc::START_ID())->isInitialized() &&
213 aFeature->attribute(SketchPlugin_Arc::END_ID())->isInitialized()) {
214 return SketchSolver_Storage::update(aFeature);
216 myFeatureMap[aFeature] = EntityWrapperPtr();
221 BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
222 GroupID aGroup = theGroup != GID_UNKNOWN ? theGroup : myGroupID;
223 // Check attribute of external features
224 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
225 std::dynamic_pointer_cast<SketchPlugin_Feature>(theAttribute->owner());
226 if (aSketchFeature && aSketchFeature->isExternal())
227 aGroup = GID_OUTOFGROUP;
228 aRelated = aBuilder->createAttribute(anAttribute, aGroup);
231 addEntity(anAttribute, aRelated);
232 } else if (theGroup != GID_UNKNOWN)
233 changeGroup(aRelated, theGroup);
234 return update(aRelated);
239 const std::list<ConstraintWrapperPtr>& SketchSolver_Storage::constraint(
240 const ConstraintPtr& theConstraint) const
242 static std::list<ConstraintWrapperPtr> aDummy;
244 std::map<ConstraintPtr, std::list<ConstraintWrapperPtr>>::const_iterator
245 aFound = myConstraintMap.find(theConstraint);
246 if (aFound != myConstraintMap.end())
247 return aFound->second;
251 const EntityWrapperPtr& SketchSolver_Storage::entity(const FeaturePtr& theFeature) const
253 static EntityWrapperPtr aDummy;
255 std::map<FeaturePtr, EntityWrapperPtr>::const_iterator aFound = myFeatureMap.find(theFeature);
256 if (aFound != myFeatureMap.end())
257 return aFound->second;
261 const EntityWrapperPtr& SketchSolver_Storage::entity(const AttributePtr& theAttribute) const
263 static EntityWrapperPtr aDummy;
265 std::map<AttributePtr, EntityWrapperPtr>::const_iterator
266 aFound = myAttributeMap.find(theAttribute);
267 if (aFound != myAttributeMap.end())
268 return aFound->second;
270 AttributeRefAttrPtr aRefAttr =
271 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
273 if (aRefAttr->isObject()) {
274 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
275 return entity(aFeature);
277 return entity(aRefAttr->attr());
282 bool SketchSolver_Storage::removeConstraint(ConstraintPtr theConstraint)
284 std::map<ConstraintPtr, std::list<ConstraintWrapperPtr> >::iterator
285 aFound = myConstraintMap.find(theConstraint);
286 if (aFound == myConstraintMap.end())
287 return true; // no constraint, already deleted
290 std::list<ConstraintWrapperPtr> aConstrList = aFound->second;
291 myConstraintMap.erase(aFound);
292 // Remove SolveSpace constraints
293 bool isFullyRemoved = true;
294 std::list<ConstraintWrapperPtr>::iterator anIt = aConstrList.begin();
295 while (anIt != aConstrList.end()) {
297 std::list<ConstraintWrapperPtr>::iterator aRemoveIt = anIt++;
298 aConstrList.erase(aRemoveIt);
300 isFullyRemoved = false;
304 return isFullyRemoved;
307 template <class ENT_TYPE>
308 static bool isUsed(ConstraintWrapperPtr theConstraint, ENT_TYPE theEntity)
310 if (!theConstraint || !theEntity)
312 std::list<EntityWrapperPtr>::const_iterator anEntIt = theConstraint->entities().begin();
313 for (; anEntIt != theConstraint->entities().end(); ++anEntIt)
314 if ((*anEntIt)->isBase(theEntity))
319 static bool isUsed(EntityWrapperPtr theFeature, AttributePtr theSubEntity)
321 if (!theFeature || !theSubEntity)
323 std::list<EntityWrapperPtr>::const_iterator aSubIt = theFeature->subEntities().begin();
324 for (; aSubIt != theFeature->subEntities().end(); ++aSubIt)
325 if ((*aSubIt)->isBase(theSubEntity))
330 static bool isUsed(ConstraintPtr theConstraint, AttributePtr theAttribute)
332 if (!theConstraint || !theAttribute)
334 std::list<AttributePtr> anAttrList = theConstraint->data()->attributes(std::string());
335 std::list<AttributePtr>::const_iterator anIt = anAttrList.begin();
336 for (; anIt != anAttrList.end(); ++anIt) {
337 if (*anIt == theAttribute)
339 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anIt);
340 if (aRefAttr && !aRefAttr->isObject() && aRefAttr->attr() == theAttribute)
346 bool SketchSolver_Storage::isUsed(FeaturePtr theFeature) const
348 if (myFeatureMap.find(theFeature) != myFeatureMap.end())
351 std::map<ConstraintPtr, std::list<ConstraintWrapperPtr> >::const_iterator
352 aCIt = myConstraintMap.begin();
353 std::list<ConstraintWrapperPtr>::const_iterator aCWIt;
354 for (; aCIt != myConstraintMap.end(); ++aCIt)
355 for (aCWIt = aCIt->second.begin(); aCWIt != aCIt->second.end(); ++aCWIt)
356 if (::isUsed(*aCWIt, theFeature))
359 std::list<AttributePtr> anAttrList = pointAttributes(theFeature);
360 std::list<AttributePtr>::const_iterator anIt = anAttrList.begin();
361 for (; anIt != anAttrList.end(); ++anIt)
367 bool SketchSolver_Storage::isUsed(AttributePtr theAttribute) const
369 AttributePtr anAttribute = theAttribute;
370 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttribute);
372 if (aRefAttr->isObject())
373 return isUsed(ModelAPI_Feature::feature(aRefAttr->object()));
375 anAttribute = aRefAttr->attr();
378 if (myAttributeMap.find(theAttribute) != myAttributeMap.end())
380 // check in constraints
381 std::map<ConstraintPtr, std::list<ConstraintWrapperPtr> >::const_iterator
382 aCIt = myConstraintMap.begin();
383 std::list<ConstraintWrapperPtr>::const_iterator aCWIt;
384 for (; aCIt != myConstraintMap.end(); ++aCIt) {
385 for (aCWIt = aCIt->second.begin(); aCWIt != aCIt->second.end(); ++aCWIt)
386 if (::isUsed(*aCWIt, anAttribute))
388 // Additional check for the Fixed constraints, which have no wrapper associated.
389 if (aCIt->first->getKind() == SketchPlugin_ConstraintRigid::ID() &&
390 ::isUsed(aCIt->first, anAttribute))
394 std::map<FeaturePtr, EntityWrapperPtr>::const_iterator aFIt = myFeatureMap.begin();
395 for (; aFIt != myFeatureMap.end(); ++aFIt)
396 if (::isUsed(aFIt->second, anAttribute))
402 bool SketchSolver_Storage::removeEntity(FeaturePtr theFeature)
404 std::map<FeaturePtr, EntityWrapperPtr>::iterator aFound = myFeatureMap.find(theFeature);
405 if (aFound == myFeatureMap.end())
406 return true; // feature not found, nothing to delete
408 EntityWrapperPtr anEntity = aFound->second;
409 myFeatureMap.erase(aFound);
411 // Check if the feature is not used by constraints, remove it
412 if (!anEntity || (!isUsed(theFeature) && remove(anEntity)))
415 // feature is not removed, revert operation
416 myFeatureMap[theFeature] = anEntity;
421 bool SketchSolver_Storage::removeEntity(AttributePtr theAttribute)
423 std::map<AttributePtr, EntityWrapperPtr>::iterator aFound = myAttributeMap.find(theAttribute);
424 if (aFound == myAttributeMap.end())
425 return true; // attribute not found, nothing to delete
427 EntityWrapperPtr anEntity = aFound->second;
428 myAttributeMap.erase(aFound);
430 // Check if the attribute is not used by constraints and features, remove it
431 if (!anEntity || (!isUsed(theAttribute) && remove(anEntity)))
434 // attribute is not removed, revert operation
435 myAttributeMap[theAttribute] = anEntity;
441 bool SketchSolver_Storage::remove(ConstraintWrapperPtr theConstraint)
443 bool isFullyRemoved = true;
444 std::list<EntityWrapperPtr>::const_iterator anIt = theConstraint->entities().begin();
445 for (; anIt != theConstraint->entities().end(); ++anIt) {
446 FeaturePtr aBaseFeature = (*anIt)->baseFeature();
448 isFullyRemoved = SketchSolver_Storage::removeEntity(aBaseFeature) && isFullyRemoved;
450 isFullyRemoved = SketchSolver_Storage::removeEntity((*anIt)->baseAttribute()) && isFullyRemoved;
452 return isFullyRemoved;
455 bool SketchSolver_Storage::remove(EntityWrapperPtr theEntity)
457 bool isFullyRemoved = true;
458 std::list<EntityWrapperPtr>::const_iterator anEntIt = theEntity->subEntities().begin();
459 for (; anEntIt != theEntity->subEntities().end(); ++anEntIt) {
460 FeaturePtr aBaseFeature = (*anEntIt)->baseFeature();
462 isFullyRemoved = SketchSolver_Storage::removeEntity(aBaseFeature) && isFullyRemoved;
464 isFullyRemoved = SketchSolver_Storage::removeEntity((*anEntIt)->baseAttribute()) && isFullyRemoved;
467 std::list<ParameterWrapperPtr>::const_iterator aParIt = theEntity->parameters().begin();
468 for (; aParIt != theEntity->parameters().end(); ++aParIt)
469 isFullyRemoved = remove(*aParIt) && isFullyRemoved;
470 return isFullyRemoved;
474 bool SketchSolver_Storage::isInteract(const FeaturePtr& theFeature) const
478 if (myConstraintMap.empty())
479 return true; // empty storage interacts with each feature
481 ConstraintPtr aConstraint = std::dynamic_pointer_cast<SketchPlugin_Constraint>(theFeature);
483 if (myConstraintMap.find(aConstraint) != myConstraintMap.end())
485 } else if (myFeatureMap.find(theFeature) != myFeatureMap.end())
488 std::list<AttributePtr> anAttrList = theFeature->data()->attributes(std::string());
489 std::list<AttributePtr>::const_iterator anIt = anAttrList.begin();
490 for (; anIt != anAttrList.end(); ++anIt)
491 if (isInteract(*anIt))
497 bool SketchSolver_Storage::isInteract(const AttributePtr& theAttribute) const
502 AttributeRefListPtr aRefList =
503 std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
505 std::list<ObjectPtr> anObjects = aRefList->list();
506 std::list<ObjectPtr>::iterator anObjIt = anObjects.begin();
507 for (; anObjIt != anObjects.end(); ++anObjIt) {
508 FeaturePtr aFeature = ModelAPI_Feature::feature(*anObjIt);
509 if (isInteract(aFeature))
515 AttributeRefAttrPtr aRefAttr =
516 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
518 return myAttributeMap.find(theAttribute) != myAttributeMap.end();
519 if (!aRefAttr->isObject())
520 return myAttributeMap.find(aRefAttr->attr()) != myAttributeMap.end();
522 FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
523 return isInteract(aFeature);
526 bool SketchSolver_Storage::isConsistent() const
528 // Check the constraints are valid
529 std::map<ConstraintPtr, std::list<ConstraintWrapperPtr> >::const_iterator
530 aCIter = myConstraintMap.begin();
531 for (; aCIter != myConstraintMap.end(); ++aCIter)
532 if (!aCIter->first->data() || !aCIter->first->data()->isValid())
534 // Check the features are valid
535 std::map<FeaturePtr, EntityWrapperPtr>::const_iterator aFIter = myFeatureMap.begin();
536 for (; aFIter != myFeatureMap.end(); aFIter++)
537 if (!aFIter->first->data() || !aFIter->first->data()->isValid())
542 bool SketchSolver_Storage::isFixed(EntityWrapperPtr theEntity) const
544 if (theEntity->group() != myGroupID)
546 // no need additional checking for entities differ than point
547 if (theEntity->type() != ENTITY_POINT)
550 CoincidentPointsMap::const_iterator anIt = myCoincidentPoints.begin();
551 for (; anIt != myCoincidentPoints.end(); ++anIt)
552 if (anIt->first == theEntity || anIt->second.find(theEntity) != anIt->second.end()) {
553 if (anIt->first->group() != myGroupID)
555 std::set<EntityWrapperPtr>::const_iterator anEntIt = anIt->second.begin();
556 for (; anEntIt != anIt->second.end(); ++anEntIt)
557 if ((*anEntIt)->group() != myGroupID)
561 std::map<ConstraintPtr, std::list<ConstraintWrapperPtr> >::const_iterator aCIt = myConstraintMap.begin();
562 std::list<ConstraintWrapperPtr>::const_iterator aCWIt;
563 for (; aCIt != myConstraintMap.end(); ++aCIt) {
564 if (aCIt->second.empty())
566 aCWIt = aCIt->second.begin();
567 if ((*aCWIt)->type() != CONSTRAINT_FIXED)
569 for (; aCWIt != aCIt->second.end(); ++aCIt)
570 if ((theEntity->baseAttribute() && (*aCWIt)->isUsed(theEntity->baseAttribute())) ||
571 (theEntity->baseFeature() && (*aCWIt)->isUsed(theEntity->baseFeature())))
578 void SketchSolver_Storage::removeInvalidEntities()
580 // Remove invalid constraints
581 std::list<ConstraintPtr> anInvalidConstraints;
582 std::map<ConstraintPtr, std::list<ConstraintWrapperPtr> >::const_iterator
583 aCIter = myConstraintMap.begin();
584 for (; aCIter != myConstraintMap.end(); ++aCIter)
585 if (!aCIter->first->data() || !aCIter->first->data()->isValid())
586 anInvalidConstraints.push_back(aCIter->first);
587 std::list<ConstraintPtr>::const_iterator anInvCIt = anInvalidConstraints.begin();
588 for (; anInvCIt != anInvalidConstraints.end(); ++anInvCIt)
589 removeConstraint(*anInvCIt);
590 // Remove invalid features
591 std::list<FeaturePtr> anInvalidFeatures;
592 std::map<FeaturePtr, EntityWrapperPtr>::const_iterator aFIter = myFeatureMap.begin();
593 for (; aFIter != myFeatureMap.end(); aFIter++)
594 if (!aFIter->first->data() || !aFIter->first->data()->isValid())
595 anInvalidFeatures.push_back(aFIter->first);
596 std::list<FeaturePtr>::const_iterator anInvFIt = anInvalidFeatures.begin();
597 for (; anInvFIt != anInvalidFeatures.end(); ++anInvFIt)
598 removeEntity(*anInvFIt);
601 EntityWrapperPtr SketchSolver_Storage::getNormal() const
603 EntityWrapperPtr aSketch = sketch();
607 // Find normal entity
608 const std::list<EntityWrapperPtr>& aSketchSubs = aSketch->subEntities();
609 std::list<EntityWrapperPtr>::const_iterator aSIt = aSketchSubs.begin();
610 for (; aSIt != aSketchSubs.end(); ++aSIt)
611 if ((*aSIt)->type() == ENTITY_NORMAL)
613 return EntityWrapperPtr();
616 const EntityWrapperPtr& SketchSolver_Storage::sketch() const
618 static EntityWrapperPtr aDummySketch;
620 std::map<FeaturePtr, EntityWrapperPtr>::const_iterator aFIt = myFeatureMap.begin();
621 for (; aFIt != myFeatureMap.end(); ++aFIt)
622 if (aFIt->second && aFIt->second->type() == ENTITY_SKETCH)
624 if (aFIt == myFeatureMap.end())
629 void SketchSolver_Storage::setSketch(const EntityWrapperPtr& theSketch)
633 addEntity(FeaturePtr(), theSketch);
636 void SketchSolver_Storage::processArcs()
639 std::map<FeaturePtr, EntityWrapperPtr>::iterator aFIt = myFeatureMap.begin();
640 for (; aFIt != myFeatureMap.end(); ++aFIt)
641 if (!aFIt->second && aFIt->first->getKind() == SketchPlugin_Arc::ID()) {
642 // Additional checking the attributes are initialized
643 if (aFIt->first->attribute(SketchPlugin_Arc::CENTER_ID())->isInitialized() &&
644 aFIt->first->attribute(SketchPlugin_Arc::START_ID())->isInitialized() &&
645 aFIt->first->attribute(SketchPlugin_Arc::END_ID())->isInitialized())
652 void SketchSolver_Storage::blockEvents(bool isBlocked)
654 if (isBlocked == myEventsBlocked)
657 std::map<ConstraintPtr, std::list<ConstraintWrapperPtr> >::const_iterator
658 aCIter = myConstraintMap.begin();
659 for (; aCIter != myConstraintMap.end(); aCIter++)
660 if (aCIter->first->data() && aCIter->first->data()->isValid())
661 aCIter->first->data()->blockSendAttributeUpdated(isBlocked);
663 std::map<FeaturePtr, EntityWrapperPtr>::const_iterator aFIter = myFeatureMap.begin();
664 for (; aFIter != myFeatureMap.end(); aFIter++)
665 if (aFIter->first->data() && aFIter->first->data()->isValid())
666 aFIter->first->data()->blockSendAttributeUpdated(isBlocked);
668 std::map<AttributePtr, EntityWrapperPtr>::const_iterator anAtIter = myAttributeMap.begin();
669 for (; anAtIter != myAttributeMap.end(); anAtIter++)
670 if (anAtIter->first->owner() && anAtIter->first->owner()->data() &&
671 anAtIter->first->owner()->data()->isValid())
672 anAtIter->first->owner()->data()->blockSendAttributeUpdated(isBlocked);
673 myEventsBlocked = isBlocked;
676 std::set<ObjectPtr> SketchSolver_Storage::getConflictingConstraints(SolverPtr theSolver) const
678 std::set<ObjectPtr> aConflicting;
679 std::map<ConstraintPtr, std::list<ConstraintWrapperPtr> >::const_iterator
680 aConstrIt = myConstraintMap.begin();
681 for (; aConstrIt != myConstraintMap.end(); ++aConstrIt) {
682 std::list<ConstraintWrapperPtr>::const_iterator anIt = aConstrIt->second.begin();
683 for (; anIt != aConstrIt->second.end(); ++anIt)
684 if (theSolver->isConflicting((*anIt)->id())) {
685 aConflicting.insert(aConstrIt->first);
696 // ============== Auxiliary functions ====================================
697 bool isEqual(const std::list<ConstraintWrapperPtr>& theCVec1,
698 const std::list<ConstraintWrapperPtr>& theCVec2)
700 if (theCVec1.size() != theCVec2.size())
703 std::list<bool> aChecked(theCVec2.size(), false);
704 std::list<ConstraintWrapperPtr>::const_iterator anIt1 = theCVec1.begin();
705 for (; anIt1 != theCVec1.end(); ++anIt1) {
706 std::list<ConstraintWrapperPtr>::const_iterator anIt2 = theCVec2.begin();
707 std::list<bool>::iterator aCheckIt = aChecked.begin();
708 while (aCheckIt != aChecked.end() && *aCheckIt) {
712 for (; anIt2 != theCVec2.end(); ++anIt2, ++aCheckIt)
713 if (!(*aCheckIt) && (*anIt1)->isEqual(*anIt2)) {
717 // the same constraint is not found
718 if (anIt2 == theCVec2.end())