]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Fix for the issue #2413
authormpv <mpv@opencascade.com>
Thu, 18 Jan 2018 14:34:34 +0000 (17:34 +0300)
committermpv <mpv@opencascade.com>
Thu, 18 Jan 2018 14:34:51 +0000 (17:34 +0300)
17 files changed:
src/BuildPlugin/BuildPlugin_CompSolid.cpp
src/BuildPlugin/BuildPlugin_Plugin.cpp
src/BuildPlugin/BuildPlugin_Solid.cpp
src/BuildPlugin/BuildPlugin_Solid.h
src/BuildPlugin/BuildPlugin_Validators.cpp
src/BuildPlugin/BuildPlugin_Validators.h
src/BuildPlugin/compsolid_widget.xml
src/BuildPlugin/solid_widget.xml
src/FeaturesPlugin/FeaturesPlugin_Validators.cpp
src/FeaturesPlugin/FeaturesPlugin_Validators.h
src/GeomValidators/GeomValidators_MinObjectsSelected.cpp
src/GeomValidators/GeomValidators_MinObjectsSelected.h
src/ModelAPI/CMakeLists.txt
src/ModelAPI/ModelAPI_FeatureValidator.cpp
src/ModelAPI/ModelAPI_FeatureValidator.h
src/ModelAPI/Test/Test2413.py [new file with mode: 0644]
src/ModelHighAPI/ModelHighAPI_Interface.cpp

index 8b19e13f3c815dfb68b68b71491a8cf96cc49e6f..c88cac3248d2257c631c505b5b7af7efc495d114 100644 (file)
@@ -20,7 +20,7 @@
 
 #include "BuildPlugin_CompSolid.h"
 
-#include <GeomAlgoAPI_MakeShape.h>
+#include <GeomAlgoAPI_MakeVolume.h>
 #include <ModelAPI_AttributeSelectionList.h>
 
 //=================================================================================================
@@ -37,22 +37,20 @@ void BuildPlugin_CompSolid::initAttributes()
 //=================================================================================================
 void BuildPlugin_CompSolid::execute()
 {
+  // all the needed checkings are in validator, so, here just make and store result
   ListOfShape anOriginalShapes;
-  std::shared_ptr<GeomAlgoAPI_MakeShape> aVolumeMaker;
-  if (!build(anOriginalShapes, aVolumeMaker))
-    return;
-
-  GeomShapePtr aVolumeRes = aVolumeMaker->shape();
+  AttributeSelectionListPtr aSelectionList = selectionList(BASE_OBJECTS_ID());
+  for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
+    AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
+    GeomShapePtr aShape = aSelection->value();
+    if (!aShape.get())
+      aShape = aSelection->context()->shape();
+    anOriginalShapes.push_back(aShape);
+  }
+  std::shared_ptr<GeomAlgoAPI_MakeVolume> anAlgo(new GeomAlgoAPI_MakeVolume(anOriginalShapes));
+  GeomShapePtr aVolumeRes = anAlgo->shape();
 
   // check and process result of volume maker
-  GeomShapePtr aResShape = getSingleSubshape(aVolumeRes, GeomAPI_Shape::COMPSOLID);
-  if (!aResShape) // try to build a solid
-    aResShape = getSingleSubshape(aVolumeRes, GeomAPI_Shape::SOLID);
-
-  int anIndex = 0;
-  if (aResShape) {
-    storeResult(anOriginalShapes, aResShape, aVolumeMaker);
-    ++anIndex;
-  }
-  removeResults(anIndex);
+  GeomShapePtr aResShape = getSingleSubshape(aVolumeRes);
+  storeResult(anOriginalShapes, aResShape, anAlgo);
 }
index 7915c14479ce4a13a0658632ff3882e8e557fe5d..800884c1021f81a47c4d2572a1891b2243b26324 100644 (file)
@@ -50,6 +50,8 @@ BuildPlugin_Plugin::BuildPlugin_Plugin()
                               new BuildPlugin_ValidatorBaseForWire());
   aFactory->registerValidator("BuildPlugin_ValidatorBaseForFace",
                               new BuildPlugin_ValidatorBaseForFace());
+  aFactory->registerValidator("BuildPlugin_ValidatorBaseForSolids",
+                              new BuildPlugin_ValidatorBaseForSolids());
   aFactory->registerValidator("BuildPlugin_ValidatorSubShapesSelection",
                               new BuildPlugin_ValidatorSubShapesSelection());
   aFactory->registerValidator("BuildPlugin_ValidatorFillingSelection",
index 1066c3f587c76ba7c9cfa13b8551b95dc34cd386..5a98995260263c28b974e5450ec122570b6e317a 100644 (file)
@@ -41,48 +41,20 @@ void BuildPlugin_Solid::initAttributes()
 //=================================================================================================
 void BuildPlugin_Solid::execute()
 {
+  // all the needed checkings are in validator, so, here just make and store result
   ListOfShape anOriginalShapes;
-  std::shared_ptr<GeomAlgoAPI_MakeShape> aVolumeMaker;
-  if (!build(anOriginalShapes, aVolumeMaker))
-    return;
-
-  // check and process result of volume maker
-  GeomShapePtr aResShape = getSingleSubshape(aVolumeMaker->shape(), GeomAPI_Shape::SOLID);
-  int anIndex = 0;
-  if (aResShape) {
-    storeResult(anOriginalShapes, aResShape, aVolumeMaker);
-    ++anIndex;
-  }
-  removeResults(anIndex);
-}
-
-//=================================================================================================
-bool BuildPlugin_Solid::build(ListOfShape& theOriginalShapes,
-                              std::shared_ptr<GeomAlgoAPI_MakeShape>& theAlgorithm)
-{
-  // Get base objects list.
   AttributeSelectionListPtr aSelectionList = selectionList(BASE_OBJECTS_ID());
-  if (!aSelectionList.get()) {
-    setError("Error: Could not get selection list.");
-    return false;
-  }
-  if (aSelectionList->size() == 0) {
-    setError("Error: Empty selection list.");
-    return false;
-  }
-
-  // Collect base shapes.
   for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
     AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
     GeomShapePtr aShape = aSelection->value();
     if (!aShape.get())
       aShape = aSelection->context()->shape();
-    theOriginalShapes.push_back(aShape);
+    anOriginalShapes.push_back(aShape);
   }
-
-  theAlgorithm =
-      std::shared_ptr<GeomAlgoAPI_MakeVolume>(new GeomAlgoAPI_MakeVolume(theOriginalShapes));
-  return !isAlgorithmFailed(theAlgorithm);
+  std::shared_ptr<GeomAlgoAPI_MakeVolume> anAlgo(new GeomAlgoAPI_MakeVolume(anOriginalShapes));
+  // check and process result of volume maker
+  GeomShapePtr aResShape = getSingleSubshape(anAlgo->shape());
+  storeResult(anOriginalShapes, aResShape, anAlgo);
 }
 
 void BuildPlugin_Solid::storeResult(const ListOfShape& theOriginalShapes,
@@ -101,55 +73,17 @@ void BuildPlugin_Solid::storeResult(const ListOfShape& theOriginalShapes,
     aResultBody->loadAndOrientModifiedShapes(theAlgorithm.get(), aShape, GeomAPI_Shape::FACE,
         aModifiedTag, "Modified_Face", *aMapOfSubs.get(), false, true, true);
   }
-
   setResult(aResultBody);
 }
 
-GeomShapePtr BuildPlugin_Solid::getSingleSubshape(const GeomShapePtr& theCompound,
-                                                  const GeomAPI_Shape::ShapeType theShapeType)
+GeomShapePtr BuildPlugin_Solid::getSingleSubshape(const GeomShapePtr& theCompound)
 {
-  if (theCompound->shapeType() == theShapeType)
-    return theCompound;
-  else if (theCompound->shapeType() == GeomAPI_Shape::COMPOUND) {
+  if (theCompound->shapeType() == GeomAPI_Shape::COMPOUND) {
     GeomAPI_ShapeIterator anIt(theCompound);
     GeomShapePtr aFoundSub;
     for (; anIt.more() && !aFoundSub; anIt.next()) {
-      aFoundSub = anIt.current();
-      if (aFoundSub->shapeType() != theShapeType)
-        return GeomShapePtr(); // not alone sub-shape
+      return anIt.current();
     }
-    if (anIt.more()) {
-      std::string anError = "Error: unable to build a ";
-      switch (theShapeType) {
-      case GeomAPI_Shape::SOLID: anError += "solid"; break;
-      case GeomAPI_Shape::COMPSOLID: anError += "compsolid"; break;
-      default: anError += "subshape"; break;
-      }
-      setError(anError);
-    } else
-      return aFoundSub;
-  }
-  // not a solid
-  return GeomShapePtr();
-}
-
-bool BuildPlugin_Solid::isAlgorithmFailed(
-    const std::shared_ptr<GeomAlgoAPI_MakeShape>& theAlgorithm)
-{
-  if (!theAlgorithm->isDone()) {
-    static const std::string aFeatureError = "Error: MakeVolume algorithm failed.";
-    setError(aFeatureError);
-    return true;
-  }
-  if (theAlgorithm->shape()->isNull()) {
-    static const std::string aShapeError = "Error: Resulting shape of MakeVolume is Null.";
-    setError(aShapeError);
-    return true;
-  }
-  if (!theAlgorithm->isValid()) {
-    std::string aFeatureError = "Error: Resulting shape of MakeVolume is not valid.";
-    setError(aFeatureError);
-    return true;
   }
-  return false;
+  return theCompound;
 }
index 549ee49d0299de8eb144b5abb0920ce10a5c7c64..1fce3df589b7968ea228226b5ce75e718398183a 100644 (file)
@@ -65,24 +65,13 @@ public:
   BUILDPLUGIN_EXPORT virtual void execute();
 
 protected:
-  /// Build result
-  /// \param[out] theOriginalShapes list of original shapes
-  /// \param[out] theAlgorithm      algorithm to build result
-  /// \return \c true if algorithm finished without errors
-  bool build(ListOfShape& theOriginalShapes, std::shared_ptr<GeomAlgoAPI_MakeShape>& theAlgorithm);
-
   /// Store result of algorithm
   void storeResult(const ListOfShape& theOriginalShapes,
                    const GeomShapePtr& theResultShape,
                    const std::shared_ptr<GeomAlgoAPI_MakeShape>& theAlgorithm);
 
-  /// Check the algorithm is failed
-  bool isAlgorithmFailed(const std::shared_ptr<GeomAlgoAPI_MakeShape>& theAlgorithm);
-
-  /// Explode compound to get single shape of specified type
-  /// \return Empty shape if there is more than one shape in compound
-  GeomShapePtr getSingleSubshape(const GeomShapePtr& theCompound,
-                                 const GeomAPI_Shape::ShapeType theShapeType);
+  /// Explode compound to get single shape
+  GeomShapePtr getSingleSubshape(const GeomShapePtr& theCompound);
 };
 
 #endif
index 833536d400a170fd6f1d89cc6b12cab67d8e8baa..8c58b47772f8332b23483e73fbab521a0d87ff13 100644 (file)
@@ -33,6 +33,9 @@
 #include <GeomAlgoAPI_ShapeTools.h>
 #include <GeomAlgoAPI_SketchBuilder.h>
 #include <GeomAlgoAPI_WireBuilder.h>
+#include <GeomAlgoAPI_MakeVolume.h>
+#include <GeomAPI_ShapeIterator.h>
+#include <GeomAPI_ShapeExplorer.h>
 
 #include <GeomValidators_FeatureKind.h>
 #include <GeomValidators_ShapeType.h>
@@ -160,13 +163,6 @@ bool BuildPlugin_ValidatorBaseForWire::isValid(const std::shared_ptr<ModelAPI_Fe
   return true;
 }
 
-//=================================================================================================
-bool BuildPlugin_ValidatorBaseForWire::isNotObligatory(std::string theFeature,
-                                                       std::string theAttribute)
-{
-  return false;
-}
-
 //=================================================================================================
 bool BuildPlugin_ValidatorBaseForFace::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
                                                const std::list<std::string>& theArguments,
@@ -264,12 +260,87 @@ bool BuildPlugin_ValidatorBaseForFace::isValid(const std::shared_ptr<ModelAPI_Fe
 }
 
 //=================================================================================================
-bool BuildPlugin_ValidatorBaseForFace::isNotObligatory(std::string theFeature,
-                                                       std::string theAttribute)
+bool BuildPlugin_ValidatorBaseForSolids::isValid(
+  const std::shared_ptr<ModelAPI_Feature>& theFeature, const std::list<std::string>& theArguments,
+  Events_InfoMessage& theError) const
 {
-  return false;
+  // Get base objects list.
+  AttributeSelectionListPtr aSelectionList = theFeature->selectionList(theArguments.front());
+  if (!aSelectionList.get()) {
+    theError = "Could not get selection list.";
+    return false;
+  }
+  if (aSelectionList->size() == 0) {
+    theError = "Empty selection list.";
+    return false;
+  }
+
+  // Collect base shapes.
+  ListOfShape anOriginalShapes;
+  for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
+    AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
+    GeomShapePtr aShape = aSelection->value();
+    if (!aShape.get())
+      aShape = aSelection->context()->shape();
+    anOriginalShapes.push_back(aShape);
+  }
+
+  std::shared_ptr<GeomAlgoAPI_MakeVolume> anAlgorithm(new GeomAlgoAPI_MakeVolume(anOriginalShapes));
+
+  if (!anAlgorithm->isDone()) {
+    theError = "MakeVolume algorithm failed.";
+    return false;
+  }
+  if (anAlgorithm->shape()->isNull()) {
+    theError = "Resulting shape of MakeVolume is Null.";
+    return false;
+  }
+  if (!anAlgorithm->isValid()) {
+    theError = "Resulting shape of MakeVolume is not valid.";
+    return false;
+  }
+
+  // set of allowed types of results
+  std::set<GeomAPI_Shape::ShapeType> aResultType;
+  std::string aType = theArguments.back();
+  if (aType == "solid")
+    aResultType.insert(GeomAPI_Shape::SOLID);
+  else if (aType == "compsolid") {
+    aResultType.insert(GeomAPI_Shape::COMPSOLID);
+    aResultType.insert(GeomAPI_Shape::SOLID);
+  }
+
+  GeomShapePtr aCompound = anAlgorithm->shape();
+  if (aCompound->shapeType() == GeomAPI_Shape::COMPOUND) {
+    GeomAPI_ShapeIterator anIt(aCompound);
+    GeomShapePtr aFoundSub;
+    for (; anIt.more() && !aFoundSub; anIt.next()) {
+      aFoundSub = anIt.current();
+      if (aResultType.count(aFoundSub->shapeType()) == 0) {
+        theError = "Unable to build a solid";
+        return false;
+      }
+    }
+    if (anIt.more() || !aFoundSub.get()) {
+      theError = "Unable to build a solid";
+      return false;
+    }
+  } else if (aResultType.count(aCompound->shapeType()) == 0) {
+    theError = "Unable to build a solid";
+    return false;
+  }
+  // check the internal faces presence
+  for(GeomAPI_ShapeExplorer aFaces(aCompound, GeomAPI_Shape::FACE); aFaces.more(); aFaces.next()) {
+    if (aFaces.current()->orientation() == GeomAPI_Shape::INTERNAL) {
+      theError = "Internal faces are not allowed in the resulting solid";
+      return false;
+    }
+  }
+
+  return true;
 }
 
+
 //=================================================================================================
 bool BuildPlugin_ValidatorSubShapesSelection::isValid(const AttributePtr& theAttribute,
                                                       const std::list<std::string>& theArguments,
index 5f3be35daf884d20edcc659bfd054f3c2eca5dcd..d69f0b8b7b3ae4f3148d759b3a1f6013c163d60d 100644 (file)
@@ -55,9 +55,6 @@ public:
   virtual bool isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
                        const std::list<std::string>& theArguments,
                        Events_InfoMessage& theError) const;
-
-  /// \return true if the attribute in feature is not obligatory for the feature execution
-  virtual bool isNotObligatory(std::string theFeature, std::string theAttribute);
 };
 
 /// \class BuildPlugin_ValidatorBaseForFace
@@ -74,9 +71,22 @@ public:
   virtual bool isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
                        const std::list<std::string>& theArguments,
                        Events_InfoMessage& theError) const;
+};
 
-  /// \return true if the attribute in feature is not obligatory for the feature execution
-  virtual bool isNotObligatory(std::string theFeature, std::string theAttribute);
+/// \class BuildPlugin_ValidatorBaseForSolids
+/// \ingroup Validators
+/// \brief A validator for selection base shapes for solid. Allows to select faces closed enough
+/// to create a solid.
+class BuildPlugin_ValidatorBaseForSolids: public ModelAPI_FeatureValidator
+{
+public:
+  //! Returns true if attributes is ok.
+  //! \param theFeature the checked feature.
+  //! \param theArguments arguments of the feature.
+  //! \param theError error message.
+  virtual bool isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                       const std::list<std::string>& theArguments,
+                       Events_InfoMessage& theError) const;
 };
 
 /// \class BuildPlugin_ValidatorSubShapesSelection
index ab3626ab9e8910e15603ce1de7876808a0024bf5..bdeb1df498d763e6ea807581f29ffc2d99b9a3e1 100644 (file)
@@ -27,4 +27,5 @@ email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com
                   concealment="true">
     <validator id="BuildPlugin_ValidatorBaseForBuild" parameters="face,shell,solid,compsolid"/>
   </multi_selector>
+  <validator id="BuildPlugin_ValidatorBaseForSolids" parameters="base_objects,compsolid"/>
 </source>
index f45b981d709f4f8e627c7a5818141e7c1e11f93c..c427af36ee8ce3a8d8980c7685832d24b56ff220 100644 (file)
@@ -27,4 +27,5 @@ email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com
                   concealment="true">
     <validator id="BuildPlugin_ValidatorBaseForBuild" parameters="face,shell"/>
   </multi_selector>
+  <validator id="BuildPlugin_ValidatorBaseForSolids" parameters="base_objects,solid"/>
 </source>
index 41fcdc65288f4bfb88ae06a93976034d32033a36..b4ca4332fd22bd0347be0ffe5f115e1ed28a2f90 100644 (file)
@@ -132,13 +132,6 @@ bool FeaturesPlugin_ValidatorPipeLocations::isValid(
   return true;
 }
 
-//==================================================================================================
-bool FeaturesPlugin_ValidatorPipeLocations::isNotObligatory(std::string theFeature,
-                                                            std::string theAttribute)
-{
-  return false;
-}
-
 //==================================================================================================
 bool FeaturesPlugin_ValidatorBaseForGeneration::isValid(const AttributePtr& theAttribute,
                                                         const std::list<std::string>& theArguments,
@@ -282,14 +275,6 @@ bool FeaturesPlugin_ValidatorBaseForGenerationSketchOrSketchObjects::isValid(
   return true;
 }
 
-//==================================================================================================
-bool FeaturesPlugin_ValidatorBaseForGenerationSketchOrSketchObjects::isNotObligatory(
-    std::string theFeature,
-    std::string theAttribute)
-{
-  return false;
-}
-
 //==================================================================================================
 bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const AttributePtr& theAttribute,
                                                         const std::list<std::string>& theArguments,
@@ -525,13 +510,6 @@ bool FeaturesPlugin_ValidatorExtrusionDir::isValid(
   return true;
 }
 
-//==================================================================================================
-bool FeaturesPlugin_ValidatorExtrusionDir::isNotObligatory(std::string theFeature,
-                                                           std::string theAttribute)
-{
-  return false;
-}
-
 //==================================================================================================
 bool FeaturesPlugin_ValidatorExtrusionDir::isShapesCanBeEmpty(const AttributePtr& theAttribute,
                                                               Events_InfoMessage& theError) const
@@ -872,13 +850,6 @@ bool FeaturesPlugin_ValidatorRemoveSubShapesResult::isValid(
   return true;
 }
 
-//==================================================================================================
-bool FeaturesPlugin_ValidatorRemoveSubShapesResult::isNotObligatory(std::string theFeature,
-                                                                    std::string theAttribute)
-{
-  return false;
-}
-
 //==================================================================================================
 bool FeaturesPlugin_ValidatorUnionSelection::isValid(const AttributePtr& theAttribute,
                                                      const std::list<std::string>& theArguments,
@@ -983,13 +954,6 @@ bool FeaturesPlugin_ValidatorUnionArguments::isValid(
   return true;
 }
 
-//==================================================================================================
-bool FeaturesPlugin_ValidatorUnionArguments::isNotObligatory(std::string theFeature,
-                                                             std::string theAttribute)
-{
-  return false;
-}
-
 bool FeaturesPlugin_ValidatorConcealedResult::isValid(const AttributePtr& theAttribute,
                                             const std::list<std::string>& theArguments,
                                             Events_InfoMessage& theError) const
index 62edcb2bf7fdf7fa8128a2f809a02cd117c6fea8..b54b3f0be54992f8d699d2c322e82c6a0cd72905 100644 (file)
@@ -52,9 +52,6 @@ class FeaturesPlugin_ValidatorPipeLocations: public ModelAPI_FeatureValidator
   virtual bool isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
                        const std::list<std::string>& theArguments,
                        Events_InfoMessage& theError) const;
-
-  /// Returns true if the attribute in feature is not obligatory for the feature execution
-  virtual bool isNotObligatory(std::string theFeature, std::string theAttribute);
 };
 
 /// \class FeaturesPlugin_ValidatorBaseForGeneration
@@ -93,9 +90,6 @@ class FeaturesPlugin_ValidatorBaseForGenerationSketchOrSketchObjects:
   virtual bool isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
                        const std::list<std::string>& theArguments,
                        Events_InfoMessage& theError) const;
-
-  /// Returns true if the attribute in feature is not obligatory for the feature execution
-  virtual bool isNotObligatory(std::string theFeature, std::string theAttribute);
 };
 
 /// \class FeaturesPlugin_ValidatorCompositeLauncher
@@ -128,9 +122,6 @@ public:
                        const std::list<std::string>& theArguments,
                        Events_InfoMessage& theError) const;
 
-  /// \return true if the attribute in feature is not obligatory for the feature execution
-  virtual bool isNotObligatory(std::string theFeature, std::string theAttribute);
-
 private:
   bool isShapesCanBeEmpty(const AttributePtr& theAttribute,
                           Events_InfoMessage& theError) const;
@@ -213,9 +204,6 @@ class FeaturesPlugin_ValidatorRemoveSubShapesResult: public ModelAPI_FeatureVali
   virtual bool isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
                        const std::list<std::string>& theArguments,
                        Events_InfoMessage& theError) const;
-
-  /// \return true if the attribute in feature is not obligatory for the feature execution
-  virtual bool isNotObligatory(std::string theFeature, std::string theAttribute);
 };
 
 /// \class FeaturesPlugin_ValidatorUnionSelection
@@ -247,9 +235,6 @@ class FeaturesPlugin_ValidatorUnionArguments: public ModelAPI_FeatureValidator
   virtual bool isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
                        const std::list<std::string>& theArguments,
                        Events_InfoMessage& theError) const;
-
-  /// \return true if the attribute in feature is not obligatory for the feature execution
-  virtual bool isNotObligatory(std::string theFeature, std::string theAttribute);
 };
 
 /// \class FeaturesPlugin_ValidatorConcealedResult
index 6b615acaccaac3775097ba82f2faf8466ea844a7..8a7d171db46265395473cb69ce87cd13a9887850 100644 (file)
@@ -55,10 +55,3 @@ bool GeomValidators_MinObjectsSelected::isValid(const std::shared_ptr<ModelAPI_F
 
   return true;
 }
-
-//================================================================================================
-bool GeomValidators_MinObjectsSelected::isNotObligatory(std::string theFeature,
-                                                        std::string theAttribute)
-{
-  return false;
-}
index d1bbd45cdc60124d1afe486712fdc74d6866faf6..a1146189f25ffa9c6192b051d0016a2514102c34 100644 (file)
@@ -39,10 +39,6 @@ public:
   GEOMVALIDATORS_EXPORT virtual bool isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
                                              const std::list<std::string>& theArguments,
                                              Events_InfoMessage& theError) const;
-
-  /// \return true if the attribute in feature is not obligatory for the feature execution.
-  GEOMVALIDATORS_EXPORT virtual bool isNotObligatory(std::string theFeature,
-                                                     std::string theAttribute);
 };
 
 #endif
index b9818c04c8e3bfa684716136b5f6183bec80d1dc..d1633aa42bcd5dd87d642cd3c2d184f3f1de1b58 100644 (file)
@@ -200,4 +200,5 @@ ADD_UNIT_TESTS(TestConstants.py
                Test2358_2.py
                Test2396.py
                Test2401.py
+               Test2413.py
 )
index be6abef50da25e2408b14f2002ce74f5cf595a8e..1f679054bf73b49ec1c5239c547ec3a945788738 100644 (file)
@@ -29,3 +29,8 @@ ModelAPI_FeatureValidator::~ModelAPI_FeatureValidator()
 {
 
 }
+
+bool ModelAPI_FeatureValidator::isNotObligatory(std::string theFeature, std::string theAttribute)
+{
+  return false;
+}
\ No newline at end of file
index b61b98f4111a00d1a04abe9dcc99949ed06494cb..2d87158b7ec881ecb1908c90fe7227addd99a831 100644 (file)
@@ -48,8 +48,9 @@ class MODELAPI_EXPORT ModelAPI_FeatureValidator : public ModelAPI_Validator
                        const std::list<std::string>& theArguments,
                        Events_InfoMessage& theError) const = 0;
 
-  /// Returns true if the attribute in feature is not obligatory for the feature execution
-  virtual bool isNotObligatory(std::string theFeature, std::string theAttribute) = 0;
+  /// Returns true if the attribute in feature is not obligatory for the feature execution.
+  ///Returns false by default.
+  virtual bool isNotObligatory(std::string theFeature, std::string theAttribute);
 };
 
 #endif
diff --git a/src/ModelAPI/Test/Test2413.py b/src/ModelAPI/Test/Test2413.py
new file mode 100644 (file)
index 0000000..cb70bf6
--- /dev/null
@@ -0,0 +1,80 @@
+## 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()
+Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
+SketchLine_1 = Sketch_1.addLine(0, 0, 0, 50)
+SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
+SketchPoint_1 = SketchProjection_1.createdFeature()
+SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchPoint_1.result())
+SketchProjection_2 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OY"), False)
+SketchLine_2 = SketchProjection_2.createdFeature()
+SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.result())
+SketchArc_1 = Sketch_1.addArc(0, 0, 0, 50, 50, 0, True)
+SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchArc_1.center())
+SketchLine_3 = Sketch_1.addLine(0, 0, 50, 0)
+SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchLine_3.startPoint())
+SketchConstraintCoincidence_4.setName("SketchConstraintCoincidence_5")
+SketchProjection_3 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OX"), False)
+SketchLine_4 = SketchProjection_3.createdFeature()
+SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.result())
+SketchConstraintCoincidence_5.setName("SketchConstraintCoincidence_6")
+SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchArc_1.endPoint(), SketchLine_3.endPoint())
+SketchConstraintCoincidence_6.setName("SketchConstraintCoincidence_7")
+SketchConstraintCoincidence_7 = Sketch_1.setCoincident(SketchArc_1.startPoint(), SketchLine_1.endPoint())
+SketchConstraintCoincidence_7.setName("SketchConstraintCoincidence_8")
+SketchConstraintRadius_1 = Sketch_1.setRadius(SketchArc_1.results()[1], 50)
+model.do()
+Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_1r-SketchArc_1_2f-SketchLine_3f")], model.selection(), 100, 0)
+model.do()
+Solid_1_objects = [model.selection("FACE", "Extrusion_1_1/Generated_Face_3")]
+Solid_1 = model.addSolid(Part_1_doc, Solid_1_objects)
+# check that resulting build-solid feature is invalid: only one not-closed face is used
+from ModelAPI import *
+aFactory = ModelAPI_Session.get().validators()
+assert(aFactory.validate(Solid_1.feature()) == False)
+ModelAPI_Session.get().abortOperation()
+# another try: to make a solid with a face inside
+model.begin()
+Plane_4 = model.addPlane(Part_1_doc, model.selection("FACE", "Extrusion_1_1/To_Face_1"), 70, True)
+Sketch_2 = model.addSketch(Part_1_doc, model.selection("FACE", "Plane_1"))
+SketchLine_5 = Sketch_2.addLine(14.9039069695087, 8.923908092675951, 26.86805702948195, 11.13714035991706)
+SketchLine_6 = Sketch_2.addLine(26.86805702948195, 11.13714035991706, 18.50962242738747, 32.13572332177004)
+SketchConstraintCoincidence_8 = Sketch_2.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint())
+SketchConstraintCoincidence_8.setName("SketchConstraintCoincidence_9")
+SketchLine_7 = Sketch_2.addLine(18.50962242738747, 32.13572332177004, 14.9039069695087, 8.923908092675951)
+SketchConstraintCoincidence_9 = Sketch_2.setCoincident(SketchLine_6.endPoint(), SketchLine_7.startPoint())
+SketchConstraintCoincidence_9.setName("SketchConstraintCoincidence_10")
+SketchConstraintCoincidence_10 = Sketch_2.setCoincident(SketchLine_5.startPoint(), SketchLine_7.endPoint())
+SketchConstraintCoincidence_10.setName("SketchConstraintCoincidence_11")
+model.do()
+Face_1 = model.addFace(Part_1_doc, [model.selection("FACE", "Sketch_2/Face-SketchLine_5f-SketchLine_6f-SketchLine_7f")])
+Solid_2_objects = [model.selection("FACE", "Extrusion_1_1/Generated_Face_3"), model.selection("FACE", "Extrusion_1_1/Generated_Face_2"), model.selection("FACE", "Extrusion_1_1/To_Face_1"), model.selection("FACE", "Extrusion_1_1/From_Face_1"), model.selection("FACE", "Extrusion_1_1/Generated_Face_1"), model.selection("FACE", "Face_1_1")]
+Solid_2 = model.addSolid(Part_1_doc, Solid_2_objects)
+model.end()
+
+assert(aFactory.validate(Solid_2.feature()) == False)
+
+assert(model.checkPythonDump())
index d5b6332a3edac800c39907303082f5b461df9548..8e35b13be1b88f0fec6a144d58b11d7bcdf38f82 100644 (file)
@@ -27,6 +27,7 @@
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Validator.h>
+#include <ModelAPI_Result.h>
 
 #include "ModelHighAPI_Selection.h"
 //--------------------------------------------------------------------------------------
@@ -98,9 +99,10 @@ std::string ModelHighAPI_Interface::name() const
 
 ModelHighAPI_Selection ModelHighAPI_Interface::result() const
 {
-  const_cast<ModelHighAPI_Interface*>(this)->execute();
-
-  return ModelHighAPI_Selection(feature()->firstResult());
+  std::list<ModelHighAPI_Selection> aResults = results();
+  if (aResults.empty())
+    return ModelHighAPI_Selection(std::shared_ptr<ModelAPI_Result>());
+  return aResults.front();
 }
 
 std::list<ModelHighAPI_Selection> ModelHighAPI_Interface::results() const
@@ -111,7 +113,8 @@ std::list<ModelHighAPI_Selection> ModelHighAPI_Interface::results() const
 
   std::list<std::shared_ptr<ModelAPI_Result> > aResults = feature()->results();
   for (auto it = aResults.begin(), end = aResults.end(); it != end; ++it) {
-    aSelectionList.push_back(ModelHighAPI_Selection(*it));
+    if (!(*it)->isDisabled())
+      aSelectionList.push_back(ModelHighAPI_Selection(*it));
   }
 
   return aSelectionList;