Salome HOME
Update unit tests for the PlaneGCS solver. Bug fixes.
[modules/shaper.git] / src / SketchSolver / SketchSolver_Storage.cpp
index e54aec7e42ca3233a6de81668ae6a370872d2de7..8370549174a16d7acc09de33e539a67599f88123 100644 (file)
@@ -76,7 +76,7 @@ void SketchSolver_Storage::addConstraint(
   if (!theSolverConstraints.empty() || aFound == myConstraintMap.end())
     myConstraintMap[theConstraint] = theSolverConstraints;
   // block events if necessary
-  if (myEventsBlocked && theConstraint->data() && theConstraint->data()->isValid())
+  if (myEventsBlocked && theConstraint && theConstraint->data() && theConstraint->data()->isValid())
     theConstraint->data()->blockSendAttributeUpdated(myEventsBlocked);
 }
 
@@ -153,6 +153,11 @@ bool SketchSolver_Storage::update(FeaturePtr theFeature, const GroupID& theGroup
     // Secondly, convert feature
     BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
     GroupID aGroup = theGroup != GID_UNKNOWN ? theGroup : myGroupID;
+    // Check external feature
+    std::shared_ptr<SketchPlugin_Feature> aSketchFeature = 
+        std::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
+    if (aSketchFeature && aSketchFeature->isExternal())
+      aGroup = GID_OUTOFGROUP;
     aRelated = aBuilder->createFeature(theFeature, aSubs, aGroup);
     if (!aRelated)
       return false;
@@ -194,6 +199,11 @@ bool SketchSolver_Storage::update(AttributePtr theAttribute, const GroupID& theG
     }
     BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
     GroupID aGroup = theGroup != GID_UNKNOWN ? theGroup : myGroupID;
+    // Check attribute of external features
+    std::shared_ptr<SketchPlugin_Feature> aSketchFeature = 
+        std::dynamic_pointer_cast<SketchPlugin_Feature>(theAttribute->owner());
+    if (aSketchFeature && aSketchFeature->isExternal())
+      aGroup = GID_OUTOFGROUP;
     aRelated = aBuilder->createAttribute(anAttribute, aGroup);
     if (!aRelated)
       return false;
@@ -642,6 +652,21 @@ void SketchSolver_Storage::blockEvents(bool isBlocked)
   myEventsBlocked = isBlocked;
 }
 
+std::set<ObjectPtr> SketchSolver_Storage::getConflictingConstraints(SolverPtr theSolver) const
+{
+  std::set<ObjectPtr> aConflicting;
+  std::map<ConstraintPtr, std::list<ConstraintWrapperPtr> >::const_iterator
+      aConstrIt = myConstraintMap.begin();
+  for (; aConstrIt != myConstraintMap.end(); ++aConstrIt) {
+    std::list<ConstraintWrapperPtr>::const_iterator anIt = aConstrIt->second.begin();
+    for (; anIt != aConstrIt->second.end(); ++anIt)
+      if (theSolver->isConflicting((*anIt)->id())) {
+        aConflicting.insert(aConstrIt->first);
+        break;
+      }
+  }
+  return aConflicting;
+}