]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #2650: Crash when create pipe
authordbv <dbv@opencascade.com>
Fri, 28 Sep 2018 13:31:44 +0000 (16:31 +0300)
committerdbv <dbv@opencascade.com>
Fri, 28 Sep 2018 13:32:14 +0000 (16:32 +0300)
Added validator to allow selection for pipe locations only vertices on path shape.

src/FeaturesPlugin/CMakeLists.txt
src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp
src/FeaturesPlugin/FeaturesPlugin_Validators.cpp
src/FeaturesPlugin/FeaturesPlugin_Validators.h
src/FeaturesPlugin/Test/Test2650.py [new file with mode: 0644]
src/FeaturesPlugin/pipe_widget.xml

index 07a31f551b0bbb89382f5a252e2cfa1ee4ef1e06..fdad01eaa1f83fa5395feef7aeedd95a8210d0a5 100644 (file)
@@ -367,4 +367,5 @@ ADD_UNIT_TESTS(TestExtrusion.py
                TestBooleanFuse_CompSolidCompound_CompSolidCompound.py
                Test1816.py
                Test2631.py
+               Test2650.py
 )
index f39e5fc1e8741ec56ac0f9d31e132988647c5b1b..68b1001e9241f2e45f78897796a7e004a48571cd 100644 (file)
@@ -73,6 +73,8 @@ FeaturesPlugin_Plugin::FeaturesPlugin_Plugin()
                               new FeaturesPlugin_ValidatorBaseForGenerationSketchOrSketchObjects);
   aFactory->registerValidator("FeaturesPlugin_ValidatorPipeLocations",
                               new FeaturesPlugin_ValidatorPipeLocations);
+  aFactory->registerValidator("FeaturesPlugin_ValidatorPipeLocationsNumber",
+                              new FeaturesPlugin_ValidatorPipeLocationsNumber);
   aFactory->registerValidator("FeaturesPlugin_ValidatorExtrusionDir",
                               new FeaturesPlugin_ValidatorExtrusionDir);
   aFactory->registerValidator("FeaturesPlugin_ValidatorBooleanSelection",
index bfb36543ceb53136d00af6a42301ad6027b25a33..411a6470ba67a5ef1daa2270d86c70a7e8482df9 100644 (file)
@@ -24,6 +24,7 @@
 #include "FeaturesPlugin_BooleanFuse.h"
 #include "FeaturesPlugin_BooleanCommon.h"
 #include "FeaturesPlugin_BooleanSmash.h"
+#include "FeaturesPlugin_Pipe.h"
 #include "FeaturesPlugin_Union.h"
 
 #include <Events_InfoMessage.h>
@@ -88,7 +89,85 @@ bool FeaturesPlugin_ValidatorPipePath::isValid(const AttributePtr& theAttribute,
 }
 
 //==================================================================================================
-bool FeaturesPlugin_ValidatorPipeLocations::isValid(
+bool FeaturesPlugin_ValidatorPipeLocations::isValid(const AttributePtr& theAttribute,
+                                                    const std::list<std::string>& theArguments,
+                                                    Events_InfoMessage& theError) const
+{
+  AttributeSelectionListPtr anAttrSelectionList =
+    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+  if(!anAttrSelectionList.get()) {
+    theError =
+      "Error: This validator can only work with selection list attributes in \"Pipe\" feature.";
+    return false;
+  }
+  std::shared_ptr<FeaturesPlugin_Pipe> aFeature =
+    std::dynamic_pointer_cast<FeaturesPlugin_Pipe>(theAttribute->owner());
+
+  AttributeSelectionPtr aPathSelection = aFeature->selection(FeaturesPlugin_Pipe::PATH_OBJECT_ID());
+  if (!aPathSelection.get()) {
+    theError = "Error: Path not selected.";
+    return false;
+  }
+
+  GeomShapePtr aPathShape = aPathSelection->value();
+  if (!aPathShape.get()) {
+    ResultPtr aContext = aPathSelection->context();
+    if (!aContext.get()) {
+      FeaturePtr aContFeat = aPathSelection->contextFeature();
+      if (!aContFeat.get() || !aContFeat->results().size()) {
+        theError = "Error: Empty selection context.";
+        return false;
+      }
+    }
+    aPathShape = aContext->shape();
+  }
+
+  if (!aPathShape.get()) {
+    theError = "Error: Empty path shape.";
+    return false;
+  }
+
+  for (int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
+    AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
+    if (!anAttrSelection.get()) {
+      theError = "Error: Empty attribute selection.";
+      return false;
+    }
+    ResultPtr aContext = anAttrSelection->context();
+    if (!aContext.get()) {
+      FeaturePtr aContFeat = anAttrSelection->contextFeature();
+      if (!aContFeat.get() || !aContFeat->results().size()) {
+        theError = "Error: Empty selection context.";
+        return false;
+      }
+    }
+    ResultConstructionPtr aResultConstruction =
+      std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
+    if (aResultConstruction.get()) {
+      theError = "Error: Result construction not allowed for selection.";
+      return false;
+    }
+    std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
+    if (!aShape.get() && aContext.get()) {
+      GeomShapePtr aContextShape = aContext->shape();
+      aShape = aContextShape;
+    }
+    if (!aShape.get()) {
+      theError = "Error: Empty shape.";
+      return false;
+    }
+
+    if (!aPathShape->isSubShape(aShape)) {
+      theError = "Error: Location should be a vertex subshape from path shape.";
+      return false;
+    }
+  }
+
+  return true;
+}
+
+//==================================================================================================
+bool FeaturesPlugin_ValidatorPipeLocationsNumber::isValid(
   const std::shared_ptr<ModelAPI_Feature>& theFeature,
   const std::list<std::string>& theArguments,
   Events_InfoMessage& theError) const
index 18e1c241d21756a590d3a5069050da08ffdae891..7b81dfb4708a34159a0f8ddc3a2b8c49d36e412b 100644 (file)
@@ -41,8 +41,23 @@ public:
 
 /// \class FeaturesPlugin_ValidatorPipeLocations
 /// \ingroup Validators
+/// \brief A validator for selection pipe locations.
+class FeaturesPlugin_ValidatorPipeLocations: public ModelAPI_AttributeValidator
+{
+public:
+  //! \return True if the attribute is valid.
+  //! \param[in] theAttribute the checked attribute.
+  //! \param[in] theArguments arguments of the attribute.
+  //! \param[out] theError error message.
+  virtual bool isValid(const AttributePtr& theAttribute,
+                       const std::list<std::string>& theArguments,
+                       Events_InfoMessage& theError) const;
+};
+
+/// \class FeaturesPlugin_ValidatorPipeLocationsNumber
+/// \ingroup Validators
 /// \brief Validator for the pipe locations.
-class FeaturesPlugin_ValidatorPipeLocations: public ModelAPI_FeatureValidator
+class FeaturesPlugin_ValidatorPipeLocationsNumber: public ModelAPI_FeatureValidator
 {
  public:
   //! \return true if number of selected locations the same as number of selected bases, or empty.
diff --git a/src/FeaturesPlugin/Test/Test2650.py b/src/FeaturesPlugin/Test/Test2650.py
new file mode 100644 (file)
index 0000000..e321411
--- /dev/null
@@ -0,0 +1,60 @@
+## 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>
+##
+
+from salome.shaper import model
+
+model.begin()
+partSet = model.moduleDocument()
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+Import_1 = model.addImport(Part_1_doc, "D:/rq_1.brep")
+model.do()
+Import_1.setName("rq_1")
+Import_1.result().setName("rq_1_1")
+Import_2 = model.addImport(Part_1_doc, "D:/rq2_1.brep")
+model.do()
+Import_2.setName("rq2_1")
+Import_2.result().setName("rq2_1_1")
+Import_3 = model.addImport(Part_1_doc, "D:/spine.brep")
+model.do()
+Import_3.setName("spine")
+Import_3.result().setName("spine_1")
+Import_4 = model.addImport(Part_1_doc, "D:/v1.brep")
+model.do()
+Import_4.setName("v1")
+Import_4.result().setName("v1_1")
+Import_5 = model.addImport(Part_1_doc, "D:/v2.brep")
+model.do()
+Import_5.setName("v2")
+Import_5.result().setName("v2_1")
+Pipe_1 = model.addPipe(Part_1_doc, [model.selection("WIRE", "rq_1_1"), model.selection("WIRE", "rq2_1_1")], model.selection("WIRE", "spine_1"), [model.selection("VERTEX", "spine_1/Shape2"), model.selection("VERTEX", "spine_1/Shape3")])
+model.do()
+model.end()
+
+from GeomAPI import  GeomAPI_Shape
+
+model.testNbResults(Pipe_1, 1)
+model.testNbSubResults(Pipe_1, [0])
+model.testNbSubShapes(Pipe_1, GeomAPI_Shape.SOLID, [0])
+model.testNbSubShapes(Pipe_1, GeomAPI_Shape.FACE, [4])
+model.testNbSubShapes(Pipe_1, GeomAPI_Shape.EDGE, [16])
+model.testNbSubShapes(Pipe_1, GeomAPI_Shape.VERTEX, [32])
+
+assert(model.checkPythonDump())
index a258e00fe16c0f0ada8adf9b400ca2016ce181a3..f472fb00e308691e92fdd10c2c7db15ef9c9894b 100644 (file)
@@ -49,9 +49,10 @@ email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com
                       label="Locations:"
                       tooltip="Select one or more vertices to specify the locations"
                       type_choice="vertex">
+        <validator id="FeaturesPlugin_ValidatorPipeLocations"/>
       </multi_selector>
     </box>
   </toolbox>
-  <validator id="FeaturesPlugin_ValidatorPipeLocations"/>
+  <validator id="FeaturesPlugin_ValidatorPipeLocationsNumber"/>
   <validator id="FeaturesPlugin_ValidatorBaseForGenerationSketchOrSketchObjects" parameters="base_objects"/>
 </source>