]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Constraint attributes may be changed (issue #1200)
authorazv <azv@opencascade.com>
Thu, 21 Jan 2016 12:31:29 +0000 (15:31 +0300)
committerazv <azv@opencascade.com>
Thu, 21 Jan 2016 14:04:10 +0000 (17:04 +0300)
src/SketchPlugin/Test/TestConstraintDistance.py
src/SketchSolver/SketchSolver_Constraint.cpp

index e9703fa63e5911217ed65ce9cccf409095a14740..3adefded128f5ded102ea8d0410c4c8c6bc5fb6d 100644 (file)
@@ -165,5 +165,13 @@ aDistance.setValue(PT_LINE_DIST)
 aSession.finishOperation()
 assert (distancePointLine(aSketchPointCoords, aSketchLine) == PT_LINE_DIST)
 #=========================================================================
+# Set distance between line boundaries
+#=========================================================================
+aSession.startOperation()
+refattrA.setAttr(aLineAStartPoint)
+refattrB.setAttr(aLineAEndPoint)
+aSession.finishOperation()
+assert (distancePointPoint(aLineAStartPoint, aLineAEndPoint) != PT_LINE_DIST)
+#=========================================================================
 # End of test
 #=========================================================================
index 7dbde50c73130c4ffba06118fc35165b95b2fe7c..ef10bf57ebb2d0486037b89c2badc09ff86521d0 100644 (file)
@@ -115,13 +115,57 @@ void SketchSolver_Constraint::process()
 void SketchSolver_Constraint::update()
 {
   cleanErrorMsg();
-
   std::list<ConstraintWrapperPtr> aWrapper = myStorage->constraint(myBaseConstraint);
+  std::list<ConstraintWrapperPtr>::iterator aWIt = aWrapper.begin();
+
+  // Check if attributes of constraint are changed, rebuild constraint
+  std::set<AttributePtr> anAttributes;
+  std::set<AttributePtr>::iterator aFoundAttr;
+  std::set<FeaturePtr> aFeatures;
+  std::set<FeaturePtr>::iterator aFoundFeat;
+  for (int anEntIndex = 0; anEntIndex < 4; ++anEntIndex) {
+    AttributePtr anAttr =
+        myBaseConstraint->attribute(SketchPlugin_Constraint::ATTRIBUTE(anEntIndex));
+    if (!anAttr)
+      continue;
+
+    AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttr);
+    if (aRefAttr) {
+      if (aRefAttr->isObject()) {
+        FeaturePtr aFeat = ModelAPI_Feature::feature(aRefAttr->object());
+        aFeatures.insert(aFeat);
+      } else
+        anAttributes.insert(aRefAttr->attr());
+    } else
+      anAttributes.insert(anAttr);
+  }
+  bool hasNewAttr = !(anAttributes.empty() && aFeatures.empty());
+  for (; hasNewAttr && aWIt != aWrapper.end(); ++ aWIt) {
+    const std::list<EntityWrapperPtr>& aSubs = (*aWIt)->entities();
+    std::list<EntityWrapperPtr>::const_iterator aSIt = aSubs.begin();
+    for (; hasNewAttr && aSIt != aSubs.end(); ++aSIt) {
+      if ((*aSIt)->baseAttribute()) {
+        aFoundAttr = anAttributes.find((*aSIt)->baseAttribute());
+        if (aFoundAttr != anAttributes.end())
+          anAttributes.erase(aFoundAttr);
+      } else {
+        aFoundFeat = aFeatures.find((*aSIt)->baseFeature());
+        if (aFoundFeat != aFeatures.end())
+          aFeatures.erase(aFoundFeat);
+      }
+      hasNewAttr = !(anAttributes.empty() && aFeatures.empty());
+    }
+  }
+  if (hasNewAttr) {
+    remove();
+    process();
+    return;
+  }
+
   AttributeDoublePtr aValueAttr = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
       myBaseConstraint->attribute(SketchPlugin_Constraint::VALUE()));
   if (aValueAttr) {
-    std::list<ConstraintWrapperPtr>::iterator aWIt = aWrapper.begin();
-    for (; aWIt != aWrapper.end(); ++aWIt)
+    for (aWIt = aWrapper.begin(); aWIt != aWrapper.end(); ++aWIt)
       if (fabs((*aWIt)->value() - aValueAttr->value()) > tolerance) {
         (*aWIt)->setValue(aValueAttr->value());
         myStorage->setNeedToResolve(true);