]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Improve updating "Multi" constraints
authorazv <azv@opencascade.com>
Sat, 1 Apr 2017 13:15:37 +0000 (16:15 +0300)
committerazv <azv@opencascade.com>
Sat, 1 Apr 2017 13:15:37 +0000 (16:15 +0300)
src/SketchPlugin/Test/TestMirror.py
src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.cpp
src/SketchSolver/SketchSolver_ConstraintMultiRotation.cpp
src/SketchSolver/SketchSolver_ConstraintMultiTranslation.cpp
src/SketchSolver/SketchSolver_Group.cpp
src/SketchSolver/SketchSolver_Group.h

index 306d02d45808ceaf329443994088925232a008cd..af141ae28fbe5448185295937b1c7a0c899c223a 100644 (file)
@@ -208,6 +208,29 @@ assert (aRefListB.size() == 1)
 assert (aRefListC.size() == 1)
 checkMirror(aRefListB, aRefListC, aMirrorLine)
 assert (model.dof(aSketchFeature) == 12)
+
+#=========================================================================
+# Create distance between original and mirrored entities (check the error appears)
+#=========================================================================
+aSketchErrorAttr = aSketchFeature.string("SolverError")
+assert len(aSketchErrorAttr.value()) == 0, "Sketch failed with error: {}".format(aSketchErrorAttr.value())
+aMirroredArc = model.lastSubFeature(aSketchFeature, "SketchArc")
+aSession.startOperation()
+aConstraint = aSketchFeature.addFeature("SketchConstraintDistance")
+refAttrA = aConstraint.refattr("ConstraintEntityA")
+refAttrB = aConstraint.refattr("ConstraintEntityB")
+anArcStartPoint = geomDataAPI_Point2D(aSketchArc1.attribute("start_point"))
+aMirroredArcStartPoint = geomDataAPI_Point2D(aMirroredArc.attribute("start_point"))
+refAttrA.setAttr(anArcStartPoint)
+refAttrB.setAttr(aMirroredArcStartPoint)
+aConstraint.real("ConstraintValue").setValue(200.)
+aSession.finishOperation()
+print "Sketch error : {}".format(aSketchErrorAttr.value())
+assert len(aSketchErrorAttr.value()) != 0, "ERROR: Sketch has not been failed as expected"
+aSession.startOperation()
+aDocument.removeFeature(aConstraint)
+aSession.finishOperation()
+
 #=========================================================================
 # End of test
 #=========================================================================
index 69b62e970495f766f060e2f8efe5567b2860e54d..547eaef012e1db5fe8705836828045dee92a934e 100644 (file)
@@ -358,7 +358,7 @@ void PlaneGCSSolver_Storage::removeParameters(const GCS::SET_pD& theParams)
 }
 
 // indicates attribute containing in the external feature
-bool isExternalAttribute(const AttributePtr& theAttribute)
+static bool isExternalAttribute(const AttributePtr& theAttribute)
 {
   if (!theAttribute)
     return false;
@@ -367,10 +367,19 @@ bool isExternalAttribute(const AttributePtr& theAttribute)
   return aSketchFeature.get() && aSketchFeature->isExternal();
 }
 
+static void addOwnerToSet(const AttributePtr& theAttribute, std::set<FeaturePtr>& theFeatures)
+{
+  FeaturePtr anOwner = ModelAPI_Feature::feature(theAttribute->owner());
+  if (anOwner)
+    theFeatures.insert(anOwner);
+}
+
 void PlaneGCSSolver_Storage::refresh() const
 {
   const double aTol = 1000. * tolerance; // tolerance to prevent frequent updates
 
+  std::set<FeaturePtr> anUpdatedFeatures;
+
   std::map<AttributePtr, EntityWrapperPtr>::const_iterator anIt = myAttributeMap.begin();
   for (; anIt != myAttributeMap.end(); ++anIt) {
     // the external feature always should keep the up to date values, so,
@@ -385,17 +394,26 @@ void PlaneGCSSolver_Storage::refresh() const
           std::dynamic_pointer_cast<PlaneGCSSolver_PointWrapper>(anIt->second);
       GCSPointPtr aGCSPoint = aPointWrapper->point();
       if (fabs(aPoint2D->x() - (*aGCSPoint->x)) > aTol ||
-          fabs(aPoint2D->y() - (*aGCSPoint->y)) > aTol)
+          fabs(aPoint2D->y() - (*aGCSPoint->y)) > aTol) {
         aPoint2D->setValue(*aGCSPoint->x, *aGCSPoint->y);
+        addOwnerToSet(anIt->first, anUpdatedFeatures);
+      }
       continue;
     }
     AttributeDoublePtr aScalar = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(anIt->first);
     if (aScalar) {
       ScalarWrapperPtr aScalarWrapper =
           std::dynamic_pointer_cast<PlaneGCSSolver_ScalarWrapper>(anIt->second);
-      if (fabs(aScalar->value() - aScalarWrapper->value()) > aTol)
+      if (fabs(aScalar->value() - aScalarWrapper->value()) > aTol) {
         aScalar->setValue(aScalarWrapper->value());
+        addOwnerToSet(anIt->first, anUpdatedFeatures);
+      }
       continue;
     }
   }
+
+  // notify listeners about features update
+  std::set<FeaturePtr>::const_iterator aFIt = anUpdatedFeatures.begin();
+  for (; aFIt != anUpdatedFeatures.end(); ++aFIt)
+    notify(*aFIt);
 }
index 5d857e914bf292817e71513776787d0190b656d8..78bf3312e9d5df3cd74cda047b07a0d4eb65af8e 100644 (file)
@@ -24,7 +24,7 @@ void SketchSolver_ConstraintMultiRotation::getAttributes(
   theAngle = aValueBuilder.createAttribute(anAngleAttr);
   myStorage->addEntity(anAngleAttr, theAngle);
 
-  AttributePtr aCenterAttr = myBaseConstraint->attribute(SketchPlugin_MultiRotation::CENTER_ID());
+  AttributeRefAttrPtr aCenterAttr = myBaseConstraint->refattr(SketchPlugin_MultiRotation::CENTER_ID());
   if (!aCenterAttr || !aCenterAttr->isInitialized()) {
     myErrorMsg = SketchSolver_Error::NOT_INITIALIZED();
     return;
@@ -40,6 +40,11 @@ void SketchSolver_ConstraintMultiRotation::getAttributes(
   theFullValue = aMethodTypeAttr->value() != "SingleAngle";
 
   getEntities(theEntities);
+
+  // add owner of central point of Multi-Rotation to the list of monitored features
+  FeaturePtr anOwner = ModelAPI_Feature::feature(aCenterAttr->attr()->owner());
+  if (anOwner)
+    myFeatures.insert(anOwner);
 }
 
 void SketchSolver_ConstraintMultiRotation::process()
index 5244ec6a4f5f66e1e5f43e6a391c526d2623a59a..b05827b9d4dc45749b00fd55a70646521855288d 100644 (file)
@@ -17,8 +17,8 @@ void SketchSolver_ConstraintMultiTranslation::getAttributes(
     bool& theFullValue, std::list<EntityWrapperPtr>& theEntities)
 {
   DataPtr aData = myBaseConstraint->data();
-  AttributePtr aStartPointAttr = aData->attribute(SketchPlugin_MultiTranslation::START_POINT_ID());
-  AttributePtr aEndPointAttr = aData->attribute(SketchPlugin_MultiTranslation::END_POINT_ID());
+  AttributeRefAttrPtr aStartPointAttr = aData->refattr(SketchPlugin_MultiTranslation::START_POINT_ID());
+  AttributeRefAttrPtr aEndPointAttr = aData->refattr(SketchPlugin_MultiTranslation::END_POINT_ID());
   if (!aStartPointAttr || !aStartPointAttr->isInitialized() ||
       !aEndPointAttr || !aEndPointAttr->isInitialized()) {
     myErrorMsg = SketchSolver_Error::NOT_INITIALIZED();
@@ -36,6 +36,14 @@ void SketchSolver_ConstraintMultiTranslation::getAttributes(
   theFullValue = aMethodTypeAttr->value() != "SingleValue";
 
   getEntities(theEntities);
+
+  // add owner of start and end points of Multi-Translation to the list of monitored features
+  FeaturePtr anOwner = ModelAPI_Feature::feature(aStartPointAttr->attr()->owner());
+  if (anOwner)
+    myFeatures.insert(anOwner);
+  anOwner = ModelAPI_Feature::feature(aEndPointAttr->attr()->owner());
+  if (anOwner)
+    myFeatures.insert(anOwner);
 }
 
 void SketchSolver_ConstraintMultiTranslation::process()
index 4f40f1d9c6376e551c8e7af1b18fad4f9120c1e0..fb82f2cdefeebb980f2a0bdae23daa9dfaff3cec 100644 (file)
@@ -185,7 +185,6 @@ bool SketchSolver_Group::resolveConstraints()
       // additional check that copied entities used in Mirror and other "Multi" constraints
       // is not connected with their originals by constraints.
       myMultiConstraintUpdateStack += 1;
-      updateMultiConstraints();
       aResolved = true;
       if (myStorage->isNeedToResolve())
         aResolved = resolveConstraints();
@@ -366,22 +365,6 @@ void SketchSolver_Group::blockEvents(bool isBlocked)
   myIsEventsBlocked = isBlocked;
 }
 
-// ============================================================================
-//  Function: updateMultiConstraints
-//  Class:    SketchSolver_Group
-//  Purpose:  update multi constraints
-// ============================================================================
-void SketchSolver_Group::updateMultiConstraints()
-{
-  ConstraintConstraintMap::iterator anIt = myConstraints.begin();
-  for (; anIt != myConstraints.end(); ++anIt) {
-    if (anIt->first->getKind() == SketchPlugin_ConstraintMirror::ID() ||
-        anIt->first->getKind() == SketchPlugin_MultiRotation::ID() ||
-        anIt->first->getKind() == SketchPlugin_MultiTranslation::ID())
-      anIt->second->update();
-  }
-}
-
 bool SketchSolver_Group::areConstraintsValid() const
 {
   // Check the constraints are valid
index 53c881c7067cc0717268d2c1b89c4bdfabbe5771..fa590266467fe289621e49dd605838b8ab64ae7d 100644 (file)
@@ -98,9 +98,6 @@ private:
   /// \brief Append given constraint to the group of temporary constraints
   void setTemporary(SolverConstraintPtr theConstraint);
 
-  /// \brief Update dependent (copied) features created by Mirror and other "Multi" constraints
-  void updateMultiConstraints();
-
   /// \brief Compute DoF of the sketch and set corresponding field
   void computeDoF();