Salome HOME
Issue #2565: CEA 2018-1 Intersection
authordbv <dbv@opencascade.com>
Sun, 12 Aug 2018 17:08:48 +0000 (20:08 +0300)
committerdbv <dbv@opencascade.com>
Sun, 12 Aug 2018 17:09:24 +0000 (20:09 +0300)
Now intersection feature contains only one "Objects" field ("Tools" field was removed)

21 files changed:
src/BuildPlugin/Test/Test2398.py
src/FeaturesAPI/FeaturesAPI_Intersection.cpp
src/FeaturesAPI/FeaturesAPI_Intersection.h
src/FeaturesPlugin/FeaturesPlugin_Intersection.cpp
src/FeaturesPlugin/FeaturesPlugin_Intersection.h
src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp
src/FeaturesPlugin/FeaturesPlugin_Validators.cpp
src/FeaturesPlugin/FeaturesPlugin_Validators.h
src/FeaturesPlugin/Test/Test1942.py
src/FeaturesPlugin/Test/Test2023.py
src/FeaturesPlugin/Test/TestIntersection.py
src/FeaturesPlugin/intersection_widget.xml
src/GeomAlgoAPI/GeomAlgoAPI_Intersection.cpp
src/GeomAlgoAPI/GeomAlgoAPI_Intersection.h
src/GeomValidators/CMakeLists.txt
src/GeomValidators/GeomValidators_IntersectionSelection.cpp [deleted file]
src/GeomValidators/GeomValidators_IntersectionSelection.h [deleted file]
src/GeomValidators/GeomValidators_Plugin.cpp
src/SketchPlugin/Test/TestIntersectionChangeEdge.py
src/SketchPlugin/Test/TestIntersectionWithSpline.py
test.API/SHAPER/Transformations/TestTranslation_2.py

index 128a26af0e875c20da09c6fd8befb6381ac878a8..8ce7bf34bd908e0c73e95df5cff0d15d0d6aec31 100644 (file)
@@ -46,7 +46,7 @@ model.do()
 Extrusion_2 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_2/Face-SketchCircle_2_2f")], model.selection(), 100, 0)
 Rotation_1 = model.addRotation(Part_1_doc, [model.selection("SOLID", "Extrusion_1_1")], model.selection("EDGE", "PartSet/OX"), 90)
 
-Intersection_1 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Rotation_1_1")], [model.selection("SOLID", "Extrusion_2_1")])
+Intersection_1 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Rotation_1_1")model.selection("SOLID", "Extrusion_2_1")])
 
 Sketch_3 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
 SketchLine_1 = Sketch_3.addLine(7.903534676574237, 7.903534676574236, -7.903534676574236, 7.903534676574236)
index db967b22c0f24e154cc131f4e5b7d27b22fa05ca..72d82355f4159158477bafa50226afdeb3e2efe4 100644 (file)
@@ -34,13 +34,11 @@ FeaturesAPI_Intersection::FeaturesAPI_Intersection(
 //==================================================================================================
 FeaturesAPI_Intersection::FeaturesAPI_Intersection(
   const std::shared_ptr<ModelAPI_Feature>& theFeature,
-  const std::list<ModelHighAPI_Selection>& theObjects,
-  const std::list<ModelHighAPI_Selection>& theTools)
+  const std::list<ModelHighAPI_Selection>& theObjects)
 : ModelHighAPI_Interface(theFeature)
 {
   if(initialize()) {
     fillAttribute(theObjects, myobjects);
-    fillAttribute(theTools, mytools);
 
     execute();
   }
@@ -60,14 +58,6 @@ void FeaturesAPI_Intersection::setObjects(const std::list<ModelHighAPI_Selection
   execute();
 }
 
-//==================================================================================================
-void FeaturesAPI_Intersection::setTools(const std::list<ModelHighAPI_Selection>& theTools)
-{
-  fillAttribute(theTools, mytools);
-
-  execute();
-}
-
 //==================================================================================================
 void FeaturesAPI_Intersection::dump(ModelHighAPI_Dumper& theDumper) const
 {
@@ -76,18 +66,15 @@ void FeaturesAPI_Intersection::dump(ModelHighAPI_Dumper& theDumper) const
 
   AttributeSelectionListPtr anAttrObjects =
     aBase->selectionList(FeaturesPlugin_Intersection::OBJECT_LIST_ID());
-  AttributeSelectionListPtr anAttrTools =
-    aBase->selectionList(FeaturesPlugin_Intersection::TOOL_LIST_ID());
 
   theDumper << aBase << " = model.addIntersection(" << aDocName << ", "
-            << anAttrObjects << ", " << anAttrTools << ")" << std::endl;
+            << anAttrObjects << ")" << std::endl;
 }
 
 //==================================================================================================
 IntersectionPtr addIntersection(const std::shared_ptr<ModelAPI_Document>& thePart,
-                                const std::list<ModelHighAPI_Selection>& theObjects,
-                                const std::list<ModelHighAPI_Selection>& theTools)
+                                const std::list<ModelHighAPI_Selection>& theObjects)
 {
   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Intersection::ID());
-  return IntersectionPtr(new FeaturesAPI_Intersection(aFeature, theObjects, theTools));
+  return IntersectionPtr(new FeaturesAPI_Intersection(aFeature, theObjects));
 }
index 93dce650575ee34792c229213e0cea9f4ff94e48..3720b25e475e8615bda29c611ea4542316b456f2 100644 (file)
@@ -44,27 +44,20 @@ public:
   /// Constructor with values.
   FEATURESAPI_EXPORT
   explicit FeaturesAPI_Intersection(const std::shared_ptr<ModelAPI_Feature>& theFeature,
-                                    const std::list<ModelHighAPI_Selection>& theObjects,
-                                    const std::list<ModelHighAPI_Selection>& theTools);
+                                    const std::list<ModelHighAPI_Selection>& theObjects);
 
   /// Destructor.
   FEATURESAPI_EXPORT
   virtual ~FeaturesAPI_Intersection();
 
-  INTERFACE_2(FeaturesPlugin_Intersection::ID(),
+  INTERFACE_1(FeaturesPlugin_Intersection::ID(),
               objects, FeaturesPlugin_Intersection::OBJECT_LIST_ID(),
-              ModelAPI_AttributeSelectionList, /** Objects */,
-              tools, FeaturesPlugin_Intersection::TOOL_LIST_ID(),
-              ModelAPI_AttributeSelectionList, /** Tools */)
+              ModelAPI_AttributeSelectionList, /** Objects */)
 
   /// Modify objects attribute of the feature.
   FEATURESAPI_EXPORT
   void setObjects(const std::list<ModelHighAPI_Selection>& theObjects);
 
-  /// Modify tools attribute of the feature.
-  FEATURESAPI_EXPORT
-  void setTools(const std::list<ModelHighAPI_Selection>& theTools);
-
   /// Dump wrapped feature
   FEATURESAPI_EXPORT
   virtual void dump(ModelHighAPI_Dumper& theDumper) const;
@@ -77,7 +70,6 @@ typedef std::shared_ptr<FeaturesAPI_Intersection> IntersectionPtr;
 /// \brief Create Intersection feature.
 FEATURESAPI_EXPORT
 IntersectionPtr addIntersection(const std::shared_ptr<ModelAPI_Document>& thePart,
-                                const std::list<ModelHighAPI_Selection>& theObjects,
-                                const std::list<ModelHighAPI_Selection>& theTools);
+                                const std::list<ModelHighAPI_Selection>& theObjects);
 
 #endif // FeaturesAPI_Intersection_H_
index e557498945a3add650f18bbbd6c4fa805341670b..7a33f2d463cf4e09dd340ae3ee9a247beac11f3e 100644 (file)
@@ -39,20 +39,17 @@ FeaturesPlugin_Intersection::FeaturesPlugin_Intersection()
 //=================================================================================================
 void FeaturesPlugin_Intersection::initAttributes()
 {
-  data()->addAttribute(FeaturesPlugin_Intersection::OBJECT_LIST_ID(),
-                       ModelAPI_AttributeSelectionList::typeId());
-  data()->addAttribute(FeaturesPlugin_Intersection::TOOL_LIST_ID(),
+  data()->addAttribute(OBJECT_LIST_ID(),
                        ModelAPI_AttributeSelectionList::typeId());
 }
 
 //=================================================================================================
 void FeaturesPlugin_Intersection::execute()
 {
-  ListOfShape anObjects, aTools;
+  ListOfShape anObjects;
 
   // Getting objects.
-  AttributeSelectionListPtr anObjectsSelList =
-    selectionList(FeaturesPlugin_Intersection::OBJECT_LIST_ID());
+  AttributeSelectionListPtr anObjectsSelList = selectionList(OBJECT_LIST_ID());
   for (int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) {
     std::shared_ptr<ModelAPI_AttributeSelection> anObjectAttr =
       anObjectsSelList->value(anObjectsIndex);
@@ -63,54 +60,38 @@ void FeaturesPlugin_Intersection::execute()
     anObjects.push_back(anObject);
   }
 
-  // Getting tools.
-  AttributeSelectionListPtr aToolsSelList =
-    selectionList(FeaturesPlugin_Intersection::TOOL_LIST_ID());
-  for (int aToolsIndex = 0; aToolsIndex < aToolsSelList->size(); aToolsIndex++) {
-    std::shared_ptr<ModelAPI_AttributeSelection> aToolAttr = aToolsSelList->value(aToolsIndex);
-    std::shared_ptr<GeomAPI_Shape> aTool = aToolAttr->value();
-    if (!aTool.get()) {
-      return;
-    }
-    aTools.push_back(aTool);
-  }
-
-  if(anObjects.empty() || aTools.empty()) {
+  if(anObjects.empty()) {
     setError("Error: Objects or tools are empty.");
     return;
   }
 
   int aResultIndex = 0;
 
-  // Create result for each object.
-  for (ListOfShape::iterator
-       anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end(); anObjectsIt++) {
-    std::shared_ptr<GeomAPI_Shape> anObject = *anObjectsIt;
-    ListOfShape aListWithObject; aListWithObject.push_back(anObject);
-    GeomAlgoAPI_Intersection anIntersectionAlgo(aListWithObject, aTools);
-
-    // Checking that the algorithm worked properly.
-    if (!anIntersectionAlgo.isDone()) {
-      static const std::string aFeatureError = "Error: Intersection algorithm failed.";
-      setError(aFeatureError);
-      return;
-    }
-    if (anIntersectionAlgo.shape()->isNull()) {
-      static const std::string aShapeError = "Error: Resulting shape is Null.";
-      setError(aShapeError);
-      return;
-    }
-    if (!anIntersectionAlgo.isValid()) {
-      std::string aFeatureError = "Error: Resulting shape is not valid.";
-      setError(aFeatureError);
-      return;
-    }
+  // Create result.
+  GeomAlgoAPI_Intersection anIntersectionAlgo(anObjects);
 
-    std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data(), aResultIndex);
-    loadNamingDS(aResultBody, anObject, aTools, anIntersectionAlgo);
-    setResult(aResultBody, aResultIndex);
-    aResultIndex++;
+  // Checking that the algorithm worked properly.
+  if (!anIntersectionAlgo.isDone()) {
+    static const std::string aFeatureError = "Error: Intersection algorithm failed.";
+    setError(aFeatureError);
+    return;
   }
+  if (anIntersectionAlgo.shape()->isNull()) {
+    static const std::string aShapeError = "Error: Resulting shape is Null.";
+    setError(aShapeError);
+    return;
+  }
+  if (!anIntersectionAlgo.isValid()) {
+    std::string aFeatureError = "Error: Resulting shape is not valid.";
+    setError(aFeatureError);
+    return;
+  }
+
+  std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data(), aResultIndex);
+  loadNamingDS(aResultBody, anObjects, anIntersectionAlgo);
+  setResult(aResultBody, aResultIndex);
+  aResultIndex++;
+
 
   // remove the rest results if there were produced in the previous pass
   removeResults(aResultIndex);
@@ -118,37 +99,17 @@ void FeaturesPlugin_Intersection::execute()
 
 //=================================================================================================
 void FeaturesPlugin_Intersection::loadNamingDS(std::shared_ptr<ModelAPI_ResultBody> theResultBody,
-                                               const std::shared_ptr<GeomAPI_Shape> theBaseShape,
-                                               const ListOfShape& theTools,
+                                               const ListOfShape& theObjects,
                                                GeomAlgoAPI_MakeShape& theMakeShape)
 {
   std::shared_ptr<GeomAPI_Shape> aResultShape = theMakeShape.shape();
-  theResultBody->storeModified(theBaseShape, aResultShape);
-
-  const int aDeletedVertexTag = 1;
-  const int aDeletedEdgeTag   = 2;
-  const int aDeletedFaceTag   = 3;
-
-  theResultBody->loadDeletedShapes(&theMakeShape,
-                                   theBaseShape,
-                                   GeomAPI_Shape::VERTEX,
-                                   aDeletedVertexTag);
-  theResultBody->loadDeletedShapes(&theMakeShape,
-                                   theBaseShape,
-                                   GeomAPI_Shape::EDGE,
-                                   aDeletedEdgeTag);
-  theResultBody->loadDeletedShapes(&theMakeShape,
-                                   theBaseShape,
-                                   GeomAPI_Shape::FACE,
-                                   aDeletedFaceTag);
-
-  ListOfShape aShapes = theTools;
-  aShapes.push_back(theBaseShape);
+  theResultBody->storeModified(theObjects.front(), aResultShape);
+
   GeomAPI_DataMapOfShapeShape aShapesMap; // Map to store {result_shape, original_shape}
   const int aShapeTypesNb = 2;
   const GeomAPI_Shape::ShapeType aShapeTypes[aShapeTypesNb] =
     {GeomAPI_Shape::VERTEX, GeomAPI_Shape::EDGE};
-  for(ListOfShape::const_iterator anIt = aShapes.cbegin(); anIt != aShapes.cend(); ++anIt) {
+  for (ListOfShape::const_iterator anIt = theObjects.cbegin(); anIt != theObjects.cend(); ++anIt) {
     const GeomShapePtr aShape = *anIt;
     for(int anIndex = 0; anIndex < aShapeTypesNb; ++anIndex) {
       for(GeomAPI_ShapeExplorer anOrigShapeExp(aShape, aShapeTypes[anIndex]);
index d7672cffba78b0ee880219ca011c0981d261d415..c4a210fc857ae269dacd0f3a2f6eef998333709d 100644 (file)
@@ -53,13 +53,6 @@ public:
     return MY_OBJECT_LIST_ID;
   }
 
-  /// Attribute name of tools.
-  inline static const std::string& TOOL_LIST_ID()
-  {
-    static const std::string MY_TOOL_LIST_ID("tool_objects");
-    return MY_TOOL_LIST_ID;
-  }
-
   /// Returns the kind of a feature.
   FEATURESPLUGIN_EXPORT virtual const std::string& getKind()
   {
@@ -79,8 +72,7 @@ public:
 private:
   /// Load Naming data structure of the feature to the document.
   void loadNamingDS(std::shared_ptr<ModelAPI_ResultBody> theResultBody,
-                    const std::shared_ptr<GeomAPI_Shape> theBaseShape,
-                    const ListOfShape& theTools,
+                    const ListOfShape& theObjects,
                     GeomAlgoAPI_MakeShape& theMakeShape);
 };
 
index 9d61541af75801ba06f00ae212093439c9d8ec83..8105f04b7190abe5a36dc0970e6cd4cae5cd1302 100644 (file)
@@ -98,6 +98,8 @@ FeaturesPlugin_Plugin::FeaturesPlugin_Plugin()
                               new FeaturesPlugin_ValidatorBooleanArguments);
   aFactory->registerValidator("FeaturesPlugin_ValidatorBooleanSmashSelection",
                               new FeaturesPlugin_ValidatorBooleanSmashSelection);
+  aFactory->registerValidator("FeaturesPlugin_IntersectionSelection",
+                              new FeaturesPlugin_IntersectionSelection);
 
   // register this plugin
   ModelAPI_Session::get()->registerPlugin(this);
index cfe4ed74377143f4d242a7b07314ce564b15c857..f0005c790e02ff254e2c5f6f268dfb3ce2b510f4 100644 (file)
@@ -1289,3 +1289,68 @@ bool FeaturesPlugin_ValidatorBooleanSmashSelection::isValid(
 
   return true;
 }
+
+//==================================================================================================
+bool FeaturesPlugin_IntersectionSelection::isValid(const AttributePtr& theAttribute,
+                                                   const std::list<std::string>& theArguments,
+                                                   Events_InfoMessage& theError) const
+{
+  if (!theAttribute.get()) {
+    theError = "Error: empty selection.";
+    return false;
+  }
+  FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
+  AttributeSelectionListPtr anAttrSelectionList =
+    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+  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()) {
+      theError = "Error: empty selection context.";
+      return false;
+    }
+    FeaturePtr aFeature = ModelAPI_Feature::feature(aContext);
+    if (!aFeature.get()) {
+      theError = "Error: empty feature.";
+      return false;
+    }
+    std::string aFeatureKind = aFeature->getKind();
+    if (aFeatureKind == "Sketch" ||
+        aFeatureKind == "Plane" ||
+        aFeatureKind == "Axis") {
+      theError = "Error: %1 shape is not allowed for selection.";
+      theError.arg(aFeatureKind);
+      return false;
+    }
+    std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
+    GeomShapePtr aContextShape = aContext->shape();
+    if (!aShape.get()) {
+      aShape = aContextShape;
+    }
+    if (!aShape.get()) {
+      theError = "Error: empty shape.";
+      return false;
+    }
+    if (!aShape->isEqual(aContextShape)) {
+      theError = "Error: Local selection not allowed.";
+      return false;
+    }
+
+    int aShapeType = aShape->shapeType();
+    // Allow to select edges, faces and solids.
+    if (aShapeType != GeomAPI_Shape::EDGE &&
+        aShapeType != GeomAPI_Shape::FACE &&
+        aShapeType != GeomAPI_Shape::SOLID &&
+        aShapeType != GeomAPI_Shape::COMPSOLID &&
+        aShapeType != GeomAPI_Shape::COMPOUND) {
+      theError = "Error: selected shape has the wrong type.";
+      return false;
+    }
+  }
+
+  return true;
+}
index ca731ef0e7de141a8a9d8c88f2bb5e732dc0041d..0001a37fb62a3de55cc927d1509e8ac3193b6678 100644 (file)
@@ -303,4 +303,19 @@ public:
                        Events_InfoMessage& theError) const;
 };
 
+/// \class FeaturesPlugin_IntersectionSelection
+/// \ingroup Validators
+/// \brief Verifies the selected object for intersection feature
+class FeaturesPlugin_IntersectionSelection: 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;
+};
+
 #endif
index 93272c18752581d0a4de093c5d518a8128ddfdc8..b4ffe91438f218b9271aefe20685a41dd60527ba 100644 (file)
@@ -180,7 +180,7 @@ Partition_1 = model.addPartition(Part_1_doc, [model.selection("FACE", "PartSet/P
 Recover_1 = model.addRecover(Part_1_doc, Partition_1, [Revolution_1.result()])
 Plane_5 = model.addPlane(Part_1_doc, model.selection("EDGE", "PartSet/Axis_4"), model.selection("VERTEX", "PartSet/Point_2"), True)
 Face_1 = model.addFace(Part_1_doc, [model.selection("EDGE", "Sketch_1/Edge-SketchArc_2_2"), model.selection("EDGE", "Sketch_1/Edge-SketchLine_4"), model.selection("EDGE", "Sketch_1/Edge-SketchLine_5"), model.selection("EDGE", "Sketch_1/Edge-SketchLine_6"), model.selection("EDGE", "Sketch_1/Edge-SketchLine_7"), model.selection("EDGE", "Sketch_1/Edge-SketchLine_8"), model.selection("EDGE", "Sketch_1/Edge-SketchLine_1"), model.selection("EDGE", "Sketch_1/Edge-SketchLine_2")])
-Intersection_1 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Recover_1_1")], [model.selection("FACE", "Face_1_1")])
+Intersection_1 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Recover_1_1")model.selection("FACE", "Face_1_1")])
 Group_1 = model.addGroup(Part_1_doc, [model.selection("VERTEX", "Intersection_1_1/Modified_Vertex_2_1"), model.selection("VERTEX", "Intersection_1_1/Generated_Vertex_2"), model.selection("VERTEX", "Intersection_1_1/Modified_Vertex_6_1"), model.selection("VERTEX", "Intersection_1_1/Modified_Vertex_4_1"), model.selection("VERTEX", "Intersection_1_1/Generated_Vertex_3"), model.selection("VERTEX", "Intersection_1_1/Generated_Vertex_1"), model.selection("VERTEX", "Intersection_1_1/Modified_Vertex_1_1"), model.selection("VERTEX", "Intersection_1_1/Generated_Vertex_4"), model.selection("VERTEX", "Intersection_1_1/Modified_Vertex_3_1"), model.selection("VERTEX", "Intersection_1_1/Modified_Vertex_7_1"), model.selection("VERTEX", "Intersection_1_1/Modified_Vertex_5_1")])
 Group_2 = model.addGroup(Part_1_doc, [model.selection("EDGE", "Intersection_1_1_7"), model.selection("EDGE", "Intersection_1_1_6"), model.selection("EDGE", "Intersection_1_1_3"), model.selection("EDGE", "Intersection_1_1_11"), model.selection("EDGE", "Intersection_1_1_5"), model.selection("EDGE", "Intersection_1_1_1"), model.selection("EDGE", "Intersection_1_1_4"), model.selection("EDGE", "Intersection_1_1_2"), model.selection("EDGE", "Intersection_1_1_10"), model.selection("EDGE", "Intersection_1_1_9"), model.selection("EDGE", "Intersection_1_1_8")])
 model.end()
index d025a0785c569201a8cd6a0b02a8351136881594..cfde51a8180d3d226c77776801a989319f542b9e 100644 (file)
@@ -54,7 +54,7 @@ SketchConstraintHorizontal_4 = Sketch_2.setHorizontal(SketchLine_7.result())
 SketchConstraintVertical_4 = Sketch_2.setVertical(SketchLine_8.result())
 model.do()
 Extrusion_2 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_2/Face-SketchLine_5f-SketchLine_6f-SketchLine_7f-SketchLine_8f")], model.selection(), 10, 110)
-Intersection_1 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Extrusion_1_1")], [model.selection("SOLID", "Extrusion_2_1")])
+Intersection_1 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Extrusion_1_1")model.selection("SOLID", "Extrusion_2_1")])
 Rotation_1 = model.addRotation(Part_1_doc, [model.selection("COMPOUND", "Intersection_1_1")], model.selection("EDGE", "PartSet/OZ"), 45)
 model.end()
 
index 9dac987c90cffc63e9f0bccffe1abfdace8fabd6..ea47ba331366afb14fc08647e9e4c750ba191993 100644 (file)
@@ -154,7 +154,7 @@ aSession.startOperation()
 anIntersectionFt = aPart.addFeature("Intersection")
 assert (anIntersectionFt.getKind() == "Intersection")
 anIntersectionFt.selectionList("main_objects").append(anExtrusionResult1, None)
-anIntersectionFt.selectionList("tool_objects").append(anExtrusionResult2, None)
+anIntersectionFt.selectionList("main_objects").append(anExtrusionResult2, None)
 anIntersectionFt.execute()
 aSession.finishOperation()
 
index e760c26b61ead428bef9d61921d8146af989bcf3..69723c22e6ff6b47c8fe374b0bf77cddb31552cf 100644 (file)
@@ -28,16 +28,6 @@ email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com
     use_choice="false"
     concealment="true">
     <validator id="PartSet_DifferentObjects"/>
-    <validator id="GeomValidators_IntersectionSelection"/>
-  </multi_selector>
-  <multi_selector id="tool_objects"
-    label="Tool objects"
-    icon="icons/Features/cut_tool.png"
-    tooltip="Select tools(compounds, compsolids, solids, shells, faces or edges)"
-    type_choice="edges faces shells solids compsolids compounds"
-    use_choice="false"
-    concealment="true">
-    <validator id="PartSet_DifferentObjects"/>
-    <validator id="GeomValidators_IntersectionSelection"/>
+    <validator id="FeaturesPlugin_IntersectionSelection"/>
   </multi_selector>
 </source>
index 8cf31feba39aece75bf243ac508ddc31aa852b28..5793dbf0bd49a6e4bbd8330cf0276551403e7f40 100644 (file)
 #include "GeomAlgoAPI_Intersection.h"
 
 #include <GeomAlgoAPI_DFLoader.h>
-#include <GeomAlgoAPI_ShapeTools.h>
 
-#include <BRepAlgoAPI_Section.hxx>
-#include <TopExp_Explorer.hxx>
-#include <TopoDS_Builder.hxx>
+#include <BOPAlgo_PaveFiller.hxx>
+#include <BOPAlgo_Section.hxx>
 
-//=================================================================================================
-GeomAlgoAPI_Intersection::GeomAlgoAPI_Intersection(const ListOfShape& theObjects,
-                                                   const ListOfShape& theTools)
+//==================================================================================================
+GeomAlgoAPI_Intersection::GeomAlgoAPI_Intersection(const ListOfShape& theObjects)
 {
-  build(theObjects, theTools);
+  build(theObjects);
 }
 
-//=================================================================================================
-void GeomAlgoAPI_Intersection::build(const ListOfShape& theObjects,
-                                     const ListOfShape& theTools)
+//==================================================================================================
+void GeomAlgoAPI_Intersection::build(const ListOfShape& theObjects)
 {
-  if (theObjects.empty() || theTools.empty()) {
+  if (theObjects.empty()) {
     return;
   }
 
   // Creating partition operation.
-  BRepAlgoAPI_Section* anOperation = new BRepAlgoAPI_Section;
+  BOPAlgo_Section* anOperation = new BOPAlgo_Section;
   this->setImpl(anOperation);
-  this->setBuilderType(OCCT_BRepBuilderAPI_MakeShape);
-
-  TopAbs_ShapeEnum aShapeType = TopAbs_COMPOUND;
+  this->setBuilderType(OCCT_BOPAlgo_Builder);
 
   // Getting objects.
   TopTools_ListOfShape anObjects;
@@ -58,25 +52,31 @@ void GeomAlgoAPI_Intersection::build(const ListOfShape& theObjects,
       anObjects.Append(aShape);
     }
   }
-  anOperation->SetArguments(anObjects);
 
-  // Getting tools.
-  TopTools_ListOfShape aTools;
-  for (ListOfShape::const_iterator
-    aToolsIt = theTools.begin(); aToolsIt != theTools.end(); aToolsIt++) {
-    const TopoDS_Shape& aShape = (*aToolsIt)->impl<TopoDS_Shape>();
-    if(!aShape.IsNull()) {
-      aTools.Append(aShape);
-    }
-  }
-  anOperation->SetTools(aTools);
+  BOPAlgo_PaveFiller aDSFiller;
+  aDSFiller.SetArguments(anObjects);
+
+  aDSFiller.SetRunParallel(false);
+  aDSFiller.SetNonDestructive(false);
+  aDSFiller.SetGlue(BOPAlgo_GlueOff);
+
   // optimization for the issue #2399
-  anOperation->Approximation(Standard_True);
-  anOperation->ComputePCurveOn1(Standard_True);
-  anOperation->ComputePCurveOn2(Standard_True);
-  // Building and getting result.
-  anOperation->Build();
-  if(!anOperation->IsDone()) {
+  BOPAlgo_SectionAttribute theSecAttr(Standard_True,
+                                      Standard_True,
+                                      Standard_True);
+  aDSFiller.SetSectionAttribute(theSecAttr);
+
+  aDSFiller.Perform();
+  if (aDSFiller.HasErrors()) {
+    return;
+  }
+
+  anOperation->SetArguments(anObjects);
+  anOperation->SetRunParallel(false);
+  anOperation->SetCheckInverted(true);
+
+  anOperation->PerformWithFiller(aDSFiller);
+  if(anOperation->HasErrors()) {
     return;
   }
   TopoDS_Shape aResult = anOperation->Shape();
index 5605b64d9d243eb3e517c87812c757403cf1590c..2ea3e0c14d2bce03b2f614d1eac6ac0640730cb3 100644 (file)
@@ -35,13 +35,11 @@ public:
   /// \brief Constructor.
   /// \param[in] theObjects list of objects.
   /// \param[in] theTools list of tools.
-  GEOMALGOAPI_EXPORT GeomAlgoAPI_Intersection(const ListOfShape& theObjects,
-                                              const ListOfShape& theTools);
+  GEOMALGOAPI_EXPORT GeomAlgoAPI_Intersection(const ListOfShape& theObjects);
 
 private:
   /// Builds resulting shape.
-  void build(const ListOfShape& theObjects,
-             const ListOfShape& theTools);
+  void build(const ListOfShape& theObjects);
 };
 
 #endif
index 529ba42b0e333c3379cfbcb197b02dcd6702385f..24f732949edd1f83bc758189e00374bc13a9b666 100644 (file)
@@ -35,7 +35,6 @@ SET(PROJECT_HEADERS
     GeomValidators_Tools.h
     GeomValidators_ZeroOffset.h
     GeomValidators_Different.h
-    GeomValidators_IntersectionSelection.h
     GeomValidators_MinObjectsSelected.h
     GeomValidators_ValueOrder.h
     GeomValidators_Intersected.h
@@ -55,7 +54,6 @@ SET(PROJECT_SOURCES
     GeomValidators_Tools.cpp
     GeomValidators_ZeroOffset.cpp
     GeomValidators_Different.cpp
-    GeomValidators_IntersectionSelection.cpp
     GeomValidators_MinObjectsSelected.cpp
     GeomValidators_ValueOrder.cpp
     GeomValidators_Intersected.cpp
diff --git a/src/GeomValidators/GeomValidators_IntersectionSelection.cpp b/src/GeomValidators/GeomValidators_IntersectionSelection.cpp
deleted file mode 100644 (file)
index 0100988..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-// 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>
-//
-
-#include "GeomValidators_IntersectionSelection.h"
-
-#include <GeomAPI_Shape.h>
-
-#include <Events_InfoMessage.h>
-
-#include <ModelAPI_AttributeInteger.h>
-#include <ModelAPI_AttributeSelectionList.h>
-#include <ModelAPI_Feature.h>
-
-bool GeomValidators_IntersectionSelection::isValid(const AttributePtr& theAttribute,
-                                                   const std::list<std::string>& theArguments,
-                                                   Events_InfoMessage& theError) const
-{
-  if(!theAttribute.get()) {
-    theError = "Error: empty selection.";
-    return false;
-  }
-  FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
-  AttributeSelectionListPtr anAttrSelectionList =
-    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
-  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()) {
-      theError = "Error: empty selection context.";
-      return false;
-    }
-    FeaturePtr aFeature = ModelAPI_Feature::feature(aContext);
-    if(!aFeature.get()) {
-      theError = "Error: empty feature.";
-      return false;
-    }
-    std::string aFeatureKind = aFeature->getKind();
-    if(aFeatureKind == "Sketch" ||
-       aFeatureKind == "Plane" ||
-       aFeatureKind == "Axis") {
-      theError = "Error: %1 shape is not allowed for selection.";
-      theError.arg(aFeatureKind);
-      return false;
-    }
-    std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
-    GeomShapePtr aContextShape = aContext->shape();
-    if(!aShape.get()) {
-      aShape = aContextShape;
-    }
-    if(!aShape.get()) {
-      theError = "Error: empty shape.";
-      return false;
-    }
-    if(!aShape->isEqual(aContextShape)) {
-      theError = "Error: Local selection not allowed.";
-      return false;
-    }
-
-    int aShapeType = aShape->shapeType();
-    // Allow to select edges, faces and solids.
-    if(aShapeType != GeomAPI_Shape::EDGE &&
-       aShapeType != GeomAPI_Shape::FACE &&
-       aShapeType != GeomAPI_Shape::SOLID &&
-       aShapeType != GeomAPI_Shape::COMPSOLID &&
-       aShapeType != GeomAPI_Shape::COMPOUND) {
-      theError = "Error: selected shape has the wrong type.";
-      return false;
-    }
-  }
-
-  return true;
-}
diff --git a/src/GeomValidators/GeomValidators_IntersectionSelection.h b/src/GeomValidators/GeomValidators_IntersectionSelection.h
deleted file mode 100644 (file)
index a9c1369..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-// 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>
-//
-
-#ifndef GeomValidators_IntersectionSelection_H
-#define GeomValidators_IntersectionSelection_H
-
-#include <GeomValidators.h>
-
-#include <ModelAPI_AttributeValidator.h>
-#include <ModelAPI_Attribute.h>
-
-/// \class GeomValidators_IntersectionSelection
-/// \ingroup Validators
-/// \brief Validates selection for intersection operation.
-class GeomValidators_IntersectionSelection: public ModelAPI_AttributeValidator
-{
-public:
-  /// \return True if the attribute is valid. It checks whether the selection
-  /// is acceptable for intersection operation.
-  /// \param[in] theAttribute an attribute to check.
-  /// \param[in] theArguments a filter parameters.
-  /// \param[out] theError error message.
-  GEOMVALIDATORS_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
-                                             const std::list<std::string>& theArguments,
-                                             Events_InfoMessage& theError) const;
-};
-
-#endif
index a5f7386a05850916a64ac4c9d72204b27cd685d8..3a0d06ee0cb125c88d2a3170077cc67ac5f05b1e 100644 (file)
@@ -29,7 +29,6 @@
 #include <GeomValidators_PartitionArguments.h>
 #include <GeomValidators_ShapeType.h>
 #include <GeomValidators_ZeroOffset.h>
-#include <GeomValidators_IntersectionSelection.h>
 #include <GeomValidators_FeatureKind.h>
 #include <GeomValidators_MinObjectsSelected.h>
 #include <GeomValidators_Intersected.h>
@@ -58,8 +57,6 @@ GeomValidators_Plugin::GeomValidators_Plugin()
                               new GeomValidators_PartitionArguments);
   aFactory->registerValidator("GeomValidators_ShapeType", new GeomValidators_ShapeType);
   aFactory->registerValidator("GeomValidators_ZeroOffset", new GeomValidators_ZeroOffset);
-  aFactory->registerValidator("GeomValidators_IntersectionSelection",
-                              new GeomValidators_IntersectionSelection);
   aFactory->registerValidator("GeomValidators_FeatureKind", new GeomValidators_FeatureKind);
   aFactory->registerValidator("GeomValidators_MinObjectsSelected",
                               new GeomValidators_MinObjectsSelected);
index f328df99851c31719327464a156ba8ae93894283..b6ef8dc27ca89ee4f179c75e6aa33f37955e2bc8 100644 (file)
@@ -75,7 +75,7 @@ SketchConstraintDistance_3 = Sketch_2.setDistance(SketchAPI_Point(SketchPoint_2)
 SketchConstraintDistance_4 = Sketch_2.setDistance(SketchAPI_Point(SketchPoint_2).coordinates(), SketchLine_6.result(), 70, True)
 model.do()
 Face_1 = model.addFace(Part_1_doc, [model.selection("FACE", "Sketch_2/Face-SketchLine_3r-SketchLine_4r-SketchLine_5r-SketchLine_6r")])
-Intersection_1 = model.addIntersection(Part_1_doc, [model.selection("FACE", "Filling_1_1")], [model.selection("FACE", "Face_1_1")])
+Intersection_1 = model.addIntersection(Part_1_doc, [model.selection("FACE", "Filling_1_1")model.selection("FACE", "Face_1_1")])
 
 # set different edges used for intersection and check reference data: number of intersection points and their coordinates
 REF_DATA = [("Sketch_1/Edge-SketchArc_1_2", 1, [[30, 0]]),
index 9fffb54f676c72330a635bbc298ec14cb5e29225..a3f39656611fda9bfcfc348ce20b15ed63e9aa6d 100644 (file)
@@ -53,7 +53,7 @@ model.do()
 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchArc_1_2f-SketchLine_1f-SketchLine_2f")], model.selection(), 25, 25)
 Filling_1 = model.addFilling(Part_1_doc, [model.selection("EDGE", "Extrusion_1_1/Generated_Face_1&Extrusion_1_1/From_Face_1"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_3&Extrusion_1_1/To_Face_1")])
 Face_1 = model.addFace(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchArc_1_2f-SketchLine_1f-SketchLine_2f")])
-Intersection_1 = model.addIntersection(Part_1_doc, [model.selection("FACE", "Filling_1_1")], [model.selection("FACE", "Face_1_1")])
+Intersection_1 = model.addIntersection(Part_1_doc, [model.selection("FACE", "Filling_1_1")model.selection("FACE", "Face_1_1")])
 Sketch_2 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
 SketchLine_4 = Sketch_2.addLine(-34.11217447219568, 40, 20, -37.28019411294778)
 SketchLine_5 = Sketch_2.addLine(20, -37.28019411294778, 20, 40)
index a78c57eb1cfd860a586f672e52a1cef8b66a3296..152f759ac6b5aaba12244b175c038c62255cb274 100644 (file)
@@ -91,47 +91,47 @@ model.addParameter(Part_1_doc, "d", "15")
 
 # Translation 27
 Translation_27_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_1_1")], model.selection("EDGE", "PartSet/OX"), 5)
-Intersection_1 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_2_1")], [model.selection("SOLID", "Translation_1_1")])
+Intersection_1 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_2_1")model.selection("SOLID", "Translation_1_1")])
 Translation_27 = model.addTranslation(Part_1_doc, [model.selection("COMPOUND", "Intersection_1_1")], model.selection("EDGE", "PartSet/OX"), 15)
 
 # Translation 28
 Translation_28_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_3_1")], model.selection("EDGE", "PartSet/OX"), 5)
-Intersection_2 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_4_1")], [model.selection("SOLID", "Translation_3_1")])
+Intersection_2 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_4_1")model.selection("SOLID", "Translation_3_1")])
 Translation_28 = model.addTranslation(Part_1_doc, [model.selection("COMPOUND", "Intersection_2_1")], model.selection("EDGE", "PartSet/OX"), 0)
 
 # Translation 29
 Translation_29_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_5_1")], model.selection("EDGE", "PartSet/OX"), 5)
-Intersection_3 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_6_1")], [model.selection("SOLID", "Translation_5_1")])
+Intersection_3 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_6_1")model.selection("SOLID", "Translation_5_1")])
 Translation_29 = model.addTranslation(Part_1_doc, [model.selection("COMPOUND", "Intersection_3_1")], model.selection("EDGE", "PartSet/OX"), -15)
 
 # Translation 30
 Translation_30_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_7_1")], model.selection("EDGE", "PartSet/OX"), 5)
-Intersection_4 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_8_1")], [model.selection("SOLID", "Translation_7_1")])
+Intersection_4 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_8_1")model.selection("SOLID", "Translation_7_1")])
 Translation_30 = model.addTranslation(Part_1_doc, [model.selection("COMPOUND", "Intersection_4_1")], model.selection("EDGE", "InvalidName"), -15)
 
 # Translation 31
 Translation_31_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_9_1")], model.selection("EDGE", "PartSet/OX"), 5)
-Intersection_5 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_10_1")], [model.selection("SOLID", "Translation_9_1")])
+Intersection_5 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_10_1")model.selection("SOLID", "Translation_9_1")])
 Translation_31 = model.addTranslation(Part_1_doc, [model.selection("COMPOUND", "Intersection_5_1")], model.selection("EDGE", "PartSet/OY"), "d")
 
 # Translation 32
 Translation_32_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_11_1")], model.selection("EDGE", "PartSet/OX"), 5)
-Intersection_6 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_12_1")], [model.selection("SOLID", "Translation_11_1")])
+Intersection_6 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_12_1")model.selection("SOLID", "Translation_11_1")])
 Translation_32 = model.addTranslation(Part_1_doc, [model.selection("COMPOUND", "Intersection_6_1")], model.selection("EDGE", "Sketch_1/Edge-SketchLine_1"), 15)
 
 # Translation 33
 Translation_33_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_13_1")], model.selection("EDGE", "PartSet/OX"), 5)
-Intersection_7 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_14_1")], [model.selection("SOLID", "Translation_13_1")])
+Intersection_7 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_14_1")model.selection("SOLID", "Translation_13_1")])
 Translation_33 = model.addTranslation(Part_1_doc, [model.selection("COMPOUND", "Intersection_7_1")], model.selection("EDGE", "Edge_1_1"), 15)
 
 # Translation 34
 Translation_34_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_15_1")], model.selection("EDGE", "PartSet/OX"), 5)
-Intersection_8 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_16_1")], [model.selection("SOLID", "Translation_15_1")])
+Intersection_8 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_16_1")model.selection("SOLID", "Translation_15_1")])
 Translation_34 = model.addTranslation(Part_1_doc, [model.selection("COMPOUND", "Intersection_8_1")], model.selection("EDGE", "Intersection_8_1_6"), 15)
 
 # Translation 35
 Translation_35_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_17_1")], model.selection("EDGE", "PartSet/OX"), 5)
-Intersection_9 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_18_1")], [model.selection("SOLID", "Translation_17_1")])
+Intersection_9 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "Box_18_1")model.selection("SOLID", "Translation_17_1")])
 Translation_35 = model.addTranslation(Part_1_doc, [model.selection("COMPOUND", "Intersection_9_1")], model.selection("EDGE", "Axis_1"), 15)
 
 #Translation 36