From: dbv Date: Sun, 12 Aug 2018 17:08:48 +0000 (+0300) Subject: Issue #2565: CEA 2018-1 Intersection X-Git-Tag: SHAPER_V9_1_0RC1~77 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3aea5a1acd6517908c57799ad6debac35ae337f6;p=modules%2Fshaper.git Issue #2565: CEA 2018-1 Intersection Now intersection feature contains only one "Objects" field ("Tools" field was removed) --- diff --git a/src/BuildPlugin/Test/Test2398.py b/src/BuildPlugin/Test/Test2398.py index 128a26af0..8ce7bf34b 100644 --- a/src/BuildPlugin/Test/Test2398.py +++ b/src/BuildPlugin/Test/Test2398.py @@ -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) diff --git a/src/FeaturesAPI/FeaturesAPI_Intersection.cpp b/src/FeaturesAPI/FeaturesAPI_Intersection.cpp index db967b22c..72d82355f 100644 --- a/src/FeaturesAPI/FeaturesAPI_Intersection.cpp +++ b/src/FeaturesAPI/FeaturesAPI_Intersection.cpp @@ -34,13 +34,11 @@ FeaturesAPI_Intersection::FeaturesAPI_Intersection( //================================================================================================== FeaturesAPI_Intersection::FeaturesAPI_Intersection( const std::shared_ptr& theFeature, - const std::list& theObjects, - const std::list& theTools) + const std::list& theObjects) : ModelHighAPI_Interface(theFeature) { if(initialize()) { fillAttribute(theObjects, myobjects); - fillAttribute(theTools, mytools); execute(); } @@ -60,14 +58,6 @@ void FeaturesAPI_Intersection::setObjects(const std::list& 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& thePart, - const std::list& theObjects, - const std::list& theTools) + const std::list& theObjects) { std::shared_ptr aFeature = thePart->addFeature(FeaturesAPI_Intersection::ID()); - return IntersectionPtr(new FeaturesAPI_Intersection(aFeature, theObjects, theTools)); + return IntersectionPtr(new FeaturesAPI_Intersection(aFeature, theObjects)); } diff --git a/src/FeaturesAPI/FeaturesAPI_Intersection.h b/src/FeaturesAPI/FeaturesAPI_Intersection.h index 93dce6505..3720b25e4 100644 --- a/src/FeaturesAPI/FeaturesAPI_Intersection.h +++ b/src/FeaturesAPI/FeaturesAPI_Intersection.h @@ -44,27 +44,20 @@ public: /// Constructor with values. FEATURESAPI_EXPORT explicit FeaturesAPI_Intersection(const std::shared_ptr& theFeature, - const std::list& theObjects, - const std::list& theTools); + const std::list& 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& theObjects); - /// Modify tools attribute of the feature. - FEATURESAPI_EXPORT - void setTools(const std::list& theTools); - /// Dump wrapped feature FEATURESAPI_EXPORT virtual void dump(ModelHighAPI_Dumper& theDumper) const; @@ -77,7 +70,6 @@ typedef std::shared_ptr IntersectionPtr; /// \brief Create Intersection feature. FEATURESAPI_EXPORT IntersectionPtr addIntersection(const std::shared_ptr& thePart, - const std::list& theObjects, - const std::list& theTools); + const std::list& theObjects); #endif // FeaturesAPI_Intersection_H_ diff --git a/src/FeaturesPlugin/FeaturesPlugin_Intersection.cpp b/src/FeaturesPlugin/FeaturesPlugin_Intersection.cpp index e55749894..7a33f2d46 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Intersection.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Intersection.cpp @@ -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 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 aToolAttr = aToolsSelList->value(aToolsIndex); - std::shared_ptr 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 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 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 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 theResultBody, - const std::shared_ptr theBaseShape, - const ListOfShape& theTools, + const ListOfShape& theObjects, GeomAlgoAPI_MakeShape& theMakeShape) { std::shared_ptr 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]); diff --git a/src/FeaturesPlugin/FeaturesPlugin_Intersection.h b/src/FeaturesPlugin/FeaturesPlugin_Intersection.h index d7672cffb..c4a210fc8 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Intersection.h +++ b/src/FeaturesPlugin/FeaturesPlugin_Intersection.h @@ -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 theResultBody, - const std::shared_ptr theBaseShape, - const ListOfShape& theTools, + const ListOfShape& theObjects, GeomAlgoAPI_MakeShape& theMakeShape); }; diff --git a/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp b/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp index 9d61541af..8105f04b7 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp @@ -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); diff --git a/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp b/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp index cfe4ed743..f0005c790 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp @@ -1289,3 +1289,68 @@ bool FeaturesPlugin_ValidatorBooleanSmashSelection::isValid( return true; } + +//================================================================================================== +bool FeaturesPlugin_IntersectionSelection::isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + Events_InfoMessage& theError) const +{ + if (!theAttribute.get()) { + theError = "Error: empty selection."; + return false; + } + FeaturePtr aFeature = std::dynamic_pointer_cast(theAttribute->owner()); + AttributeSelectionListPtr anAttrSelectionList = + std::dynamic_pointer_cast(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 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/FeaturesPlugin/FeaturesPlugin_Validators.h b/src/FeaturesPlugin/FeaturesPlugin_Validators.h index ca731ef0e..0001a37fb 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Validators.h +++ b/src/FeaturesPlugin/FeaturesPlugin_Validators.h @@ -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& theArguments, + Events_InfoMessage& theError) const; +}; + #endif diff --git a/src/FeaturesPlugin/Test/Test1942.py b/src/FeaturesPlugin/Test/Test1942.py index 93272c187..b4ffe9143 100644 --- a/src/FeaturesPlugin/Test/Test1942.py +++ b/src/FeaturesPlugin/Test/Test1942.py @@ -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() diff --git a/src/FeaturesPlugin/Test/Test2023.py b/src/FeaturesPlugin/Test/Test2023.py index d025a0785..cfde51a81 100644 --- a/src/FeaturesPlugin/Test/Test2023.py +++ b/src/FeaturesPlugin/Test/Test2023.py @@ -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() diff --git a/src/FeaturesPlugin/Test/TestIntersection.py b/src/FeaturesPlugin/Test/TestIntersection.py index 9dac987c9..ea47ba331 100644 --- a/src/FeaturesPlugin/Test/TestIntersection.py +++ b/src/FeaturesPlugin/Test/TestIntersection.py @@ -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() diff --git a/src/FeaturesPlugin/intersection_widget.xml b/src/FeaturesPlugin/intersection_widget.xml index e760c26b6..69723c22e 100644 --- a/src/FeaturesPlugin/intersection_widget.xml +++ b/src/FeaturesPlugin/intersection_widget.xml @@ -28,16 +28,6 @@ email : webmaster.salome@opencascade.com - - - - - + diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Intersection.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Intersection.cpp index 8cf31feba..5793dbf0b 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Intersection.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Intersection.cpp @@ -21,33 +21,27 @@ #include "GeomAlgoAPI_Intersection.h" #include -#include -#include -#include -#include +#include +#include -//================================================================================================= -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(); - 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(); diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Intersection.h b/src/GeomAlgoAPI/GeomAlgoAPI_Intersection.h index 5605b64d9..2ea3e0c14 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Intersection.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Intersection.h @@ -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 diff --git a/src/GeomValidators/CMakeLists.txt b/src/GeomValidators/CMakeLists.txt index 529ba42b0..24f732949 100644 --- a/src/GeomValidators/CMakeLists.txt +++ b/src/GeomValidators/CMakeLists.txt @@ -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 index 010098800..000000000 --- a/src/GeomValidators/GeomValidators_IntersectionSelection.cpp +++ /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 -// - -#include "GeomValidators_IntersectionSelection.h" - -#include - -#include - -#include -#include -#include - -bool GeomValidators_IntersectionSelection::isValid(const AttributePtr& theAttribute, - const std::list& theArguments, - Events_InfoMessage& theError) const -{ - if(!theAttribute.get()) { - theError = "Error: empty selection."; - return false; - } - FeaturePtr aFeature = std::dynamic_pointer_cast(theAttribute->owner()); - AttributeSelectionListPtr anAttrSelectionList = - std::dynamic_pointer_cast(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 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 index a9c136992..000000000 --- a/src/GeomValidators/GeomValidators_IntersectionSelection.h +++ /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 -// - -#ifndef GeomValidators_IntersectionSelection_H -#define GeomValidators_IntersectionSelection_H - -#include - -#include -#include - -/// \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& theArguments, - Events_InfoMessage& theError) const; -}; - -#endif diff --git a/src/GeomValidators/GeomValidators_Plugin.cpp b/src/GeomValidators/GeomValidators_Plugin.cpp index a5f7386a0..3a0d06ee0 100644 --- a/src/GeomValidators/GeomValidators_Plugin.cpp +++ b/src/GeomValidators/GeomValidators_Plugin.cpp @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include @@ -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); diff --git a/src/SketchPlugin/Test/TestIntersectionChangeEdge.py b/src/SketchPlugin/Test/TestIntersectionChangeEdge.py index f328df998..b6ef8dc27 100644 --- a/src/SketchPlugin/Test/TestIntersectionChangeEdge.py +++ b/src/SketchPlugin/Test/TestIntersectionChangeEdge.py @@ -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]]), diff --git a/src/SketchPlugin/Test/TestIntersectionWithSpline.py b/src/SketchPlugin/Test/TestIntersectionWithSpline.py index 9fffb54f6..a3f396566 100644 --- a/src/SketchPlugin/Test/TestIntersectionWithSpline.py +++ b/src/SketchPlugin/Test/TestIntersectionWithSpline.py @@ -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) diff --git a/test.API/SHAPER/Transformations/TestTranslation_2.py b/test.API/SHAPER/Transformations/TestTranslation_2.py index a78c57eb1..152f759ac 100644 --- a/test.API/SHAPER/Transformations/TestTranslation_2.py +++ b/test.API/SHAPER/Transformations/TestTranslation_2.py @@ -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