]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Correct change of mirror line in the Mirror operation
authorazv <azv@opencascade.com>
Fri, 17 Apr 2015 05:06:29 +0000 (08:06 +0300)
committerazv <azv@opencascade.com>
Fri, 17 Apr 2015 05:06:29 +0000 (08:06 +0300)
src/SketchSolver/SketchSolver_Constraint.cpp
src/SketchSolver/SketchSolver_Constraint.h
src/SketchSolver/SketchSolver_ConstraintMirror.cpp
src/SketchSolver/SketchSolver_ConstraintMirror.h

index 4db4c4636bfcfa54936257b11bda9c9c28841d63..4e815d649a632a0c73132394dc7aa998f0b569cb 100644 (file)
@@ -113,48 +113,45 @@ void SketchSolver_Constraint::process()
   adjustConstraint();
 }
 
-void SketchSolver_Constraint::update(ConstraintPtr theConstraint)
+bool SketchSolver_Constraint::checkAttributesChanged(ConstraintPtr theConstraint)
 {
-  cleanErrorMsg();
-  bool needToRebuild = (theConstraint && theConstraint != myBaseConstraint);
-  if (!needToRebuild) {
-    // Check the attrbutes of constraint are changed
-    ConstraintPtr aConstraint = theConstraint ? theConstraint : myBaseConstraint;
-    std::list<AttributePtr> anAttrList = aConstraint->data()->attributes(std::string());
-    std::list<AttributePtr>::iterator anAttrIter = anAttrList.begin();
-    for (; anAttrIter != anAttrList.end(); anAttrIter++) {
-      AttributeRefAttrPtr aRefAttr =
-          std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttrIter);
-      if (aRefAttr) {
-        if (aRefAttr->isObject()) {
-          FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
-          if (aFeature && myFeatureMap.find(aFeature) == myFeatureMap.end()) {
-            needToRebuild = true;
-            break;
-          }
-        } else if (aRefAttr->attr() &&
-                    myAttributeMap.find(aRefAttr->attr()) == myAttributeMap.end()) {
-          needToRebuild = true;
-          break;
-        }
-      }
-      AttributeRefListPtr aRefList =
-          std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(*anAttrIter);
-      if (aRefList) {
-        std::list<ObjectPtr> anItems = aRefList->list();
-        std::list<ObjectPtr>::iterator anIt = anItems.begin();
-        for (; anIt != anItems.end(); anIt++) {
-          FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
-          if (aFeature && myFeatureMap.find(aFeature) == myFeatureMap.end()) {
-            needToRebuild = true;
-            break;
-          }
-        }
-        if (needToRebuild)
-          break;
+  // Check the attrbutes of constraint are changed
+  ConstraintPtr aConstraint = theConstraint ? theConstraint : myBaseConstraint;
+  std::list<AttributePtr> anAttrList = aConstraint->data()->attributes(std::string());
+  std::list<AttributePtr>::iterator anAttrIter = anAttrList.begin();
+  for (; anAttrIter != anAttrList.end(); anAttrIter++) {
+    AttributeRefAttrPtr aRefAttr =
+        std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttrIter);
+    if (aRefAttr) {
+      if (aRefAttr->isObject()) {
+        FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
+        if (aFeature && myFeatureMap.find(aFeature) == myFeatureMap.end())
+          return true;
+      } else if (aRefAttr->attr() &&
+                 myAttributeMap.find(aRefAttr->attr()) == myAttributeMap.end())
+        return true;
+    }
+    AttributeRefListPtr aRefList =
+        std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(*anAttrIter);
+    if (aRefList) {
+      std::list<ObjectPtr> anItems = aRefList->list();
+      std::list<ObjectPtr>::iterator anIt = anItems.begin();
+      for (; anIt != anItems.end(); anIt++) {
+        FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
+        if (aFeature && myFeatureMap.find(aFeature) == myFeatureMap.end())
+          return true;
       }
     }
   }
+  return false;
+}
+
+void SketchSolver_Constraint::update(ConstraintPtr theConstraint)
+{
+  cleanErrorMsg();
+  bool needToRebuild = (theConstraint && theConstraint != myBaseConstraint);
+  if (!needToRebuild)
+    needToRebuild = checkAttributesChanged(theConstraint);
   if (needToRebuild) {
     if (theConstraint && theConstraint->getKind() != myBaseConstraint->getKind())
       return;
index b6ff8f55bdca282594442ec350b5e550d3bb3464..0ceac28125645ed10fc5aa39649ccc1cc1d21695 100644 (file)
@@ -82,6 +82,11 @@ protected:
   /// \param[out] theAttributes list of attributes to be filled
   virtual void getAttributes(double& theValue, std::vector<Slvs_hEntity>& theAttributes);
 
+  /// \brief Verify the attributes of constraint are changed (and constraint need to rebuild)
+  /// \param[in] theConstraint constraint, which attributes should be checked (if NULL, the myBaseConstraint is used)
+  /// \return \c true if some attributes are changed
+  virtual bool checkAttributesChanged(ConstraintPtr theConstraint);
+
   /// \brief This method is used in derived objects to check consistence of constraint.
   ///        E.g. the distance between line and point may be signed.
   virtual void adjustConstraint()
index 8ed85ff49cbfc140c1e1b57065a9040ce602c8eb..c27000bd14eb292ddee8239d80eaa601f68cd092 100644 (file)
@@ -233,6 +233,39 @@ bool SketchSolver_ConstraintMirror::remove(ConstraintPtr theConstraint)
   return true;
 }
 
+bool SketchSolver_ConstraintMirror::checkAttributesChanged(ConstraintPtr theConstraint)
+{
+  // First of all, check the mirror line is changed.
+  // It may be changed to one of mirrored lines, which is already in this constraint
+  // (this case is not marked as attribute changing)
+  ConstraintPtr aConstraint = theConstraint ? theConstraint : myBaseConstraint;
+  AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+      aConstraint->attribute(SketchPlugin_Constraint::ENTITY_A()));
+  if (!aRefAttr || !aRefAttr->isObject() || !aRefAttr->object())
+    return true;
+  FeaturePtr aMirrorLine = ModelAPI_Feature::feature(aRefAttr->object());
+  if (!aMirrorLine)
+    return true;
+
+  std::map<FeaturePtr, Slvs_hEntity>::iterator aMirrorIter = myFeatureMap.find(aMirrorLine);
+  if (aMirrorIter == myFeatureMap.end())
+    return true;
+
+  // Check the entity is not used as mirror line
+  std::vector<Slvs_hConstraint>::iterator aCIter = mySlvsConstraints.begin();
+  for (; aCIter != mySlvsConstraints.end(); aCIter++) {
+    Slvs_Constraint aMirrorConstr = myStorage->getConstraint(*aCIter);
+    if (aMirrorConstr.type != SLVS_C_SYMMETRIC_LINE)
+      continue;
+    if (aMirrorConstr.entityA != aMirrorIter->second)
+      return true;
+    else break; // check just one symmetric constraint
+  }
+
+  // Base verification
+  return SketchSolver_Constraint::checkAttributesChanged(theConstraint);
+}
+
 void SketchSolver_ConstraintMirror::makeMirrorEntity(
     const Slvs_Entity& theBase,
     const Slvs_Entity& theMirror,
index eb3af1fb34aeeba34cce6a084953c519f47896c0..e65dcb90bc77363098636fda0ef710fb3c07a52b 100644 (file)
@@ -42,6 +42,11 @@ protected:
   virtual void getAttributes(double& theValue, std::vector<Slvs_hEntity>& theAttributes)
   { /* do nothing here */ }
 
+  /// \brief Verify the attributes of constraint are changed (and constraint need to rebuild)
+  /// \param[in] theConstraint constraint, which attributes should be checked (if NULL, the myBaseConstraint is used)
+  /// \return \c true if some attributes are changed
+  virtual bool checkAttributesChanged(ConstraintPtr theConstraint);
+
   /// \brief Generate list of entities of mirror constraint
   /// \param[out] theMirrorLine     entity corresponding to mirror line
   /// \param[out] theBaseEntities   list of entities to mirror