]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #2273: Error when reading HDF and Python dump
authorazv <azv@opencascade.com>
Tue, 10 Oct 2017 09:20:29 +0000 (12:20 +0300)
committerazv <azv@opencascade.com>
Tue, 10 Oct 2017 09:20:29 +0000 (12:20 +0300)
Implemented validator which deny referring to generated features by Multi-Rotation, Multi-Translation and Mirror

src/SketchPlugin/CMakeLists.txt
src/SketchPlugin/SketchPlugin_Plugin.cpp
src/SketchPlugin/SketchPlugin_Validators.cpp
src/SketchPlugin/SketchPlugin_Validators.h
src/SketchPlugin/Test/Test2273.py [new file with mode: 0644]
src/SketchPlugin/plugin-Sketch.xml
src/SketchSolver/SketchSolver_ConstraintMultiRotation.cpp
src/SketchSolver/SketchSolver_ConstraintMultiTranslation.cpp

index 7c89b5e5c2f6270098d37e92824cdda19841089f..1fb666420b538d8451e902480832d87571e5b610 100644 (file)
@@ -221,6 +221,7 @@ ADD_UNIT_TESTS(TestSketchPointLine.py
                TestDistanceSignedVsUnsigned05.py
                TestSignedDistancePointPoint.py
                TestSignedDistancePointLine.py
+               Test2273.py
 )
 
 if(${SKETCHER_CHANGE_RADIUS_WHEN_MOVE})
index 8967c182d4c2aaf165ec2d02171277f8159b7f71..ecc760c1e5226c889f900364e39efa826013e1c5 100644 (file)
@@ -134,6 +134,8 @@ SketchPlugin_Plugin::SketchPlugin_Plugin()
   aFactory->registerValidator("SketchPlugin_ArcEndPointIntersectionValidator",
                               new SketchPlugin_ArcEndPointIntersectionValidator);
   aFactory->registerValidator("SketchPlugin_HasNoConstraint", new SketchPlugin_HasNoConstraint);
+  aFactory->registerValidator("SketchPlugin_ReplicationReference",
+                              new SketchPlugin_ReplicationReferenceValidator);
 
   // register this plugin
   ModelAPI_Session::get()->registerPlugin(this);
index ed22a6420b086cae59f833b975ccedc47b0d3e5a..3c6fcc3471828c096c8eab647290c5953d7dcec4 100755 (executable)
@@ -1565,3 +1565,47 @@ bool SketchPlugin_HasNoConstraint::isValid(const AttributePtr& theAttribute,
   }
   return true;
 }
+
+bool SketchPlugin_ReplicationReferenceValidator::isValid(
+    const AttributePtr& theAttribute,
+    const std::list<std::string>& theArguments,
+    Events_InfoMessage& theError) const
+{
+  AttributeRefAttrPtr aRefAttr =
+      std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+  if (!aRefAttr)
+  {
+    theError = "Incorrect attribute";
+    return false;
+  }
+
+  ObjectPtr anOwner;
+  if (aRefAttr->isObject())
+    anOwner = aRefAttr->object();
+  else
+  {
+    AttributePtr anAttr = aRefAttr->attr();
+    anOwner = anAttr->owner();
+  }
+  FeaturePtr anAttrOwnerFeature = ModelAPI_Feature::feature(anOwner);
+  if (!anAttrOwnerFeature)
+    return true;
+  AttributeBooleanPtr aCopyAttr = anAttrOwnerFeature->boolean(SketchPlugin_SketchEntity::COPY_ID());
+  if (!aCopyAttr || !aCopyAttr->value())
+    return true; // feature is not a copy, thus valid
+
+  // check the copy feature is already referred by the "Multi" feature
+  FeaturePtr aMultiFeature = ModelAPI_Feature::feature(theAttribute->owner());
+  AttributeRefListPtr aRefList = aMultiFeature->reflist(theArguments.front());
+  for (int i = 0; i < aRefList->size(); ++i)
+  {
+    FeaturePtr aRefOwner = ModelAPI_Feature::feature(aRefList->object(i));
+    if (aRefOwner == anAttrOwnerFeature)
+    {
+      theError = "Attribute refers to the object generated by this feature";
+      return false;
+    }
+  }
+
+  return true;
+}
index ccfe6432824aaef8313f9d54c8e26a5ef0e1ddea..d2cf26bbc29580efa7fcd08ff55edb5277586eb4 100644 (file)
@@ -447,4 +447,21 @@ class SketchPlugin_HasNoConstraint: public ModelAPI_AttributeValidator
                        Events_InfoMessage& theError) const;
 };
 
+/**\class SketchPlugin_ReplicationReferenceValidator
+ * \ingroup Validators
+ * \brief Validator checking that the replications features (Mirror,
+ *        Multi-Rotation, Mutli-Translation) do not refer to the shapes they produce.
+ */
+class SketchPlugin_ReplicationReferenceValidator: public ModelAPI_AttributeValidator
+{
+ public:
+  //! returns true if attribute is valid
+  //! \param theAttribute the checked attribute
+  //! \param theArguments arguments of the attribute
+  //! \param theError error message
+  virtual bool isValid(const AttributePtr& theAttribute,
+                       const std::list<std::string>& theArguments,
+                       Events_InfoMessage& theError) const;
+};
+
 #endif
diff --git a/src/SketchPlugin/Test/Test2273.py b/src/SketchPlugin/Test/Test2273.py
new file mode 100644 (file)
index 0000000..399c9d2
--- /dev/null
@@ -0,0 +1,99 @@
+## Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+##
+## This library is free software; you can redistribute it and/or
+## modify it under the terms of the GNU Lesser General Public
+## License as published by the Free Software Foundation; either
+## version 2.1 of the License, or (at your option) any later version.
+##
+## This library is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## Lesser General Public License for more details.
+##
+## You should have received a copy of the GNU Lesser General Public
+## License along with this library; if not, write to the Free Software
+## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+##
+## See http:##www.salome-platform.org/ or
+## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+##
+
+"""
+    Test2273.py
+    Test case for issue #2273 "Error when reading HDF and Python dump"
+                              (multi-rotation center refers to a feature produced by itself)
+"""
+
+from salome.shaper import model
+from SketchAPI import *
+
+model.begin()
+partSet = model.moduleDocument()
+Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY"))
+SketchLine_1 = Sketch_1.addLine(-65.36884900412264, 10.74954405845571, -18.59380593895045, 62.75409504395774)
+SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "Origin"), False)
+SketchPoint_1 = SketchProjection_1.createdFeature()
+
+
+# Test 1. Check MultiRotation error
+
+SketchMultiRotation_1 = Sketch_1.addRotation([SketchLine_1.result()], SketchAPI_Point(SketchPoint_1).coordinates(), 90, 3)
+[SketchLine_2, SketchLine_3] = SketchMultiRotation_1.rotated()
+model.do()
+# check MultiRotation has NO error
+assert(SketchMultiRotation_1.feature().error() == "")
+# change center of MultiRotation to extremity of generated feature, check an error appears
+SketchMultiRotation_1.center().setAttr(SketchAPI_Line(SketchLine_2).startPoint())
+model.do()
+assert(SketchMultiRotation_1.feature().error() != "")
+# revert changes => no error
+SketchMultiRotation_1.center().setAttr(SketchAPI_Point(SketchPoint_1).coordinates())
+model.do()
+assert(SketchMultiRotation_1.feature().error() == "")
+
+
+# Test 2. Check MultiRotation error
+
+SketchMultiTranslation_1 = Sketch_1.addTranslation([SketchLine_1.result()], SketchLine_1.startPoint(), SketchAPI_Line(SketchLine_2).endPoint(), 2)
+[SketchLine_4] = SketchMultiTranslation_1.translated()
+model.do()
+# check MultiTranslation has NO error
+assert(SketchMultiTranslation_1.feature().error() == "")
+# change start point to extremity of generated feature, check an error appears
+SketchMultiTranslation_1.startPoint().setAttr(SketchAPI_Line(SketchLine_4).endPoint())
+model.do()
+assert(SketchMultiTranslation_1.feature().error() != "")
+# revert changes => no error
+SketchMultiTranslation_1.startPoint().setAttr(SketchLine_1.startPoint())
+model.do()
+assert(SketchMultiTranslation_1.feature().error() == "")
+# change end point to extremity of generated feature, check an error appears
+SketchMultiTranslation_1.endPoint().setAttr(SketchAPI_Line(SketchLine_4).endPoint())
+model.do()
+assert(SketchMultiTranslation_1.feature().error() != "")
+# revert changes => no error
+SketchMultiTranslation_1.endPoint().setAttr(SketchAPI_Line(SketchLine_2).endPoint())
+model.do()
+assert(SketchMultiTranslation_1.feature().error() == "")
+
+
+# Test 3. Check Mirror error
+
+SketchConstraintMirror_1 = Sketch_1.addMirror(SketchLine_2.result(), [SketchLine_1.result(), SketchLine_3.result()])
+[SketchLine_5, SketchLine_6] = SketchConstraintMirror_1.mirrored()
+model.do()
+# check Mirror has NO error
+assert(SketchConstraintMirror_1.feature().error() == "")
+# change mirror line to generated feature, check an error appears
+SketchConstraintMirror_1.mirrorLine().setObject(SketchLine_5.feature().firstResult())
+model.do()
+assert(SketchConstraintMirror_1.feature().error() != "")
+# revert changes => no error
+SketchConstraintMirror_1.mirrorLine().setObject(SketchLine_2.feature().firstResult())
+model.do()
+assert(SketchConstraintMirror_1.feature().error() == "")
+
+model.end()
+
+
+assert(model.checkPythonDump())
index 0c03eb5ce4a1f813fe06b72e03c5b9f4931dc78e..e5b3de3396748a1deaaea65b1fc202521a1c5bda 100644 (file)
@@ -499,6 +499,7 @@ email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com
         <sketch_shape_selector id="ConstraintEntityA"
             label="Mirror line" tooltip="Select mirror line" shape_types="edge">
           <validator id="GeomValidators_ShapeType" parameters="line"/>
+          <validator id="SketchPlugin_ReplicationReference" parameters="ConstraintEntityC"/>
         </sketch_shape_selector>
         <sketch_multi_selector id="ConstraintMirrorList"
             label="Segments:"
@@ -534,6 +535,7 @@ email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com
                     shape_types="vertex">
                 <validator id="PartSet_DifferentObjects"/>
                 <validator id="GeomValidators_ShapeType" parameters="vertex"/>
+                <validator id="SketchPlugin_ReplicationReference" parameters="ConstraintEntityB"/>
               </sketch_shape_selector>
               <sketch_shape_selector
                     id="MultiTranslationEndPoint"
@@ -542,6 +544,7 @@ email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com
                     shape_types="vertex">
                 <validator id="PartSet_DifferentObjects"/>
                 <validator id="GeomValidators_ShapeType" parameters="vertex"/>
+                <validator id="SketchPlugin_ReplicationReference" parameters="ConstraintEntityB"/>
               </sketch_shape_selector>
             </groupbox>
           </box>
@@ -554,6 +557,7 @@ email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com
                     shape_types="vertex">
                 <validator id="PartSet_DifferentObjects"/>
                 <validator id="GeomValidators_ShapeType" parameters="vertex"/>
+                <validator id="SketchPlugin_ReplicationReference" parameters="ConstraintEntityB"/>
               </sketch_shape_selector>
               <sketch_shape_selector
                     id="MultiTranslationEndPoint"
@@ -562,6 +566,7 @@ email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com
                     shape_types="vertex">
                 <validator id="PartSet_DifferentObjects"/>
                 <validator id="GeomValidators_ShapeType" parameters="vertex"/>
+                <validator id="SketchPlugin_ReplicationReference" parameters="ConstraintEntityB"/>
               </sketch_shape_selector>
             </groupbox>
           </box>
@@ -594,6 +599,7 @@ email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com
               tooltip="Center of rotation"
               shape_types="vertex">
           <validator id="GeomValidators_ShapeType" parameters="vertex"/>
+          <validator id="SketchPlugin_ReplicationReference" parameters="ConstraintEntityB"/>
         </sketch_shape_selector>
         <toolbox id="AngleType">
           <box id="SingleAngle" title="Single angle" icon="icons/Sketch/angle_up_32x32.png">
index 25d1507a68323ee7b903520027a252be5e8b5bf2..bd57785ef95fbaf3ee299ad758c900855abb8154 100644 (file)
@@ -125,12 +125,23 @@ void SketchSolver_ConstraintMultiRotation::adjustConstraint()
   }
 
   // Obtain coordinates of rotation center
+  AttributeRefAttrPtr aCenterAttr =
+      myBaseConstraint->refattr(SketchPlugin_MultiRotation::CENTER_ID());
   std::shared_ptr<PlaneGCSSolver_PointWrapper> aRotCenter =
-      std::dynamic_pointer_cast<PlaneGCSSolver_PointWrapper>(myStorage->entity(
-      myBaseConstraint->attribute(SketchPlugin_MultiRotation::CENTER_ID())));
-  GCSPointPtr aCenterPoint = aRotCenter->point();
-  myCenterCoord[0] = *(aCenterPoint->x);
-  myCenterCoord[1] = *(aCenterPoint->y);
+      std::dynamic_pointer_cast<PlaneGCSSolver_PointWrapper>(myStorage->entity(aCenterAttr));
+  if (aRotCenter)
+  {
+    GCSPointPtr aCenterPoint = aRotCenter->point();
+    myCenterCoord[0] = *(aCenterPoint->x);
+    myCenterCoord[1] = *(aCenterPoint->y);
+  }
+  else
+  {
+    AttributePoint2DPtr aCenterPnt =
+        std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aCenterAttr->attr());
+    myCenterCoord[0] = aCenterPnt->x();
+    myCenterCoord[1] = aCenterPnt->y();
+  }
 
   if (myIsFullValue && myNumberOfCopies > 0)
     anAngleValue /= myNumberOfCopies;
index 454d1e3aa18cdc47b6474c3af1b6f2c3c4376808..8028c1ddfb0480c2b4340f035d9a2ce6be92692e 100644 (file)
@@ -122,18 +122,32 @@ void SketchSolver_ConstraintMultiTranslation::adjustConstraint()
     return;
 
   // Obtain delta between start and end points of translation
-  std::shared_ptr<PlaneGCSSolver_PointWrapper> aStartWrapper =
-      std::dynamic_pointer_cast<PlaneGCSSolver_PointWrapper>(myStorage->entity(
-      myBaseConstraint->attribute(SketchPlugin_MultiTranslation::START_POINT_ID())));
-  std::shared_ptr<PlaneGCSSolver_PointWrapper> aEndWrapper =
-      std::dynamic_pointer_cast<PlaneGCSSolver_PointWrapper>(myStorage->entity(
-      myBaseConstraint->attribute(SketchPlugin_MultiTranslation::END_POINT_ID())));
-
-  GCSPointPtr aStart = aStartWrapper->point();
-  GCSPointPtr aEnd   = aEndWrapper->point();
-
-  myDelta[0] = *(aEnd->x) - *(aStart->x);
-  myDelta[1] = *(aEnd->y) - *(aStart->y);
+  AttributeRefAttrPtr aStartEnd[2] = {
+      myBaseConstraint->refattr(SketchPlugin_MultiTranslation::START_POINT_ID()),
+      myBaseConstraint->refattr(SketchPlugin_MultiTranslation::END_POINT_ID())
+  };
+  double aCoords[2][2];
+  for (int i = 0; i < 2; ++i)
+  {
+    std::shared_ptr<PlaneGCSSolver_PointWrapper> aPointWrapper =
+        std::dynamic_pointer_cast<PlaneGCSSolver_PointWrapper>(myStorage->entity(aStartEnd[i]));
+    if (aPointWrapper)
+    {
+      GCSPointPtr aPnt = aPointWrapper->point();
+      aCoords[i][0] = *(aPnt->x);
+      aCoords[i][1] = *(aPnt->y);
+    }
+    else
+    {
+      AttributePoint2DPtr aPnt =
+          std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aStartEnd[i]->attr());
+      aCoords[i][0] = aPnt->x();
+      aCoords[i][1] = aPnt->y();
+    }
+  }
+
+  myDelta[0] = aCoords[1][0] - aCoords[0][0];
+  myDelta[1] = aCoords[1][1] - aCoords[0][1];
 
   if (myIsFullValue && myNumberOfCopies > 0) {
     myDelta[0] /= myNumberOfCopies;