Refactor the Intersection feature.
%feature("kwargs") addCommon;
%feature("kwargs") addCut;
%feature("kwargs") addFuse;
+%feature("kwargs") addIntersection;
%feature("kwargs") addMultiRotation;
%feature("kwargs") addMultiTranslation;
%feature("kwargs") addPartition;
AttributeSelectionListPtr anAttrObjects =
aBase->selectionList(FeaturesPlugin_Intersection::OBJECT_LIST_ID());
- theDumper << aBase << " = model.addIntersection(" << aDocName << ", "
- << anAttrObjects << ")" << std::endl;
+ theDumper << aBase << " = model.addIntersection(" << aDocName << ", " << anAttrObjects;
+
+ if (!aBase->data()->version().empty())
+ theDumper << ", keepSubResults = True";
+
+ theDumper << ")" << std::endl;
}
//==================================================================================================
IntersectionPtr addIntersection(const std::shared_ptr<ModelAPI_Document>& thePart,
- const std::list<ModelHighAPI_Selection>& theObjects)
+ const std::list<ModelHighAPI_Selection>& theObjects,
+ const bool keepSubResults)
{
std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Intersection::ID());
+ if (!keepSubResults)
+ aFeature->data()->setVersion("");
return IntersectionPtr(new FeaturesAPI_Intersection(aFeature, theObjects));
}
/// \ingroup CPPHighAPI
/// \brief Create Intersection feature.
FEATURESAPI_EXPORT
-IntersectionPtr addIntersection(const std::shared_ptr<ModelAPI_Document>& thePart,
- const std::list<ModelHighAPI_Selection>& theObjects);
+IntersectionPtr addIntersection(const std::shared_ptr<ModelAPI_Document>& part,
+ const std::list<ModelHighAPI_Selection>& objects,
+ const bool keepSubResults = false);
#endif // FeaturesAPI_Intersection_H_
TestMultiRotation_MultiLevelCompound_v95_2.py
TestMultiRotation_MultiLevelCompound_v95_3.py
TestMultiRotation_MultiLevelCompound_v95_4.py
+ TestIntersection_MultiLevelCompound_v0_1.py
+ TestIntersection_MultiLevelCompound_v0_2.py
+ TestIntersection_MultiLevelCompound_v95_1.py
+ TestIntersection_MultiLevelCompound_v95_2.py
)
#include <ModelAPI_AttributeSelectionList.h>
#include <GeomAlgoAPI_Intersection.h>
+#include <GeomAlgoAPI_MakeShapeList.h>
#include <GeomAlgoAPI_Tools.h>
#include <GeomAPI_ShapeExplorer.h>
#include <sstream>
+static const std::string INTERSECTION_VERSION_1("v9.5");
+
//=================================================================================================
FeaturesPlugin_Intersection::FeaturesPlugin_Intersection()
{
//=================================================================================================
void FeaturesPlugin_Intersection::initAttributes()
{
- data()->addAttribute(OBJECT_LIST_ID(),
+ AttributePtr anObjectsAttr = data()->addAttribute(OBJECT_LIST_ID(),
ModelAPI_AttributeSelectionList::typeId());
+
+ initVersion(INTERSECTION_VERSION_1, anObjectsAttr, AttributePtr());
}
//=================================================================================================
void FeaturesPlugin_Intersection::execute()
{
- ListOfShape anObjects;
-
+ GeomAPI_ShapeHierarchy anObjectsHierarchy;
+ ListOfShape aPlanes;
// Getting objects.
- AttributeSelectionListPtr anObjectsSelList = selectionList(OBJECT_LIST_ID());
- for (int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) {
- std::shared_ptr<ModelAPI_AttributeSelection> anObjectAttr =
- anObjectsSelList->value(anObjectsIndex);
- std::shared_ptr<GeomAPI_Shape> anObject = anObjectAttr->value();
- if (!anObject.get()) {
- return;
- }
- anObjects.push_back(anObject);
- }
-
- if(anObjects.empty()) {
+ if (!processAttribute(OBJECT_LIST_ID(), anObjectsHierarchy, aPlanes)) {
setError("Error: Objects or tools are empty.");
return;
}
int aResultIndex = 0;
// Create result.
+ const ListOfShape& anObjects = anObjectsHierarchy.objects();
GeomMakeShapePtr anIntersectionAlgo(new GeomAlgoAPI_Intersection(anObjects));
// Checking that the algorithm worked properly.
return;
}
+ std::shared_ptr<GeomAlgoAPI_MakeShapeList> aMakeShapeList(new GeomAlgoAPI_MakeShapeList);
+ aMakeShapeList->appendAlgo(anIntersectionAlgo);
+
+ GeomShapePtr aResShape = anIntersectionAlgo->shape();
+ if (data()->version() == INTERSECTION_VERSION_1) {
+ // merge hierarchies of compounds containing objects and tools
+ // and append the result of the FUSE operation
+ aResShape = keepUnusedSubsOfCompound(aResShape, anObjectsHierarchy,
+ GeomAPI_ShapeHierarchy(), aMakeShapeList);
+ }
+
std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data(), aResultIndex);
- loadNamingDS(aResultBody, anObjects, anIntersectionAlgo);
+ FeaturesPlugin_Tools::loadModifiedShapes(aResultBody,
+ anObjects,
+ ListOfShape(),
+ aMakeShapeList,
+ aResShape);
setResult(aResultBody, aResultIndex);
aResultIndex++;
+ FeaturesPlugin_Tools::loadDeletedShapes(aResultBody,
+ GeomShapePtr(),
+ anObjects,
+ aMakeShapeList,
+ aResShape);
+
// remove the rest results if there were produced in the previous pass
removeResults(aResultIndex);
}
-
-//=================================================================================================
-void FeaturesPlugin_Intersection::loadNamingDS(ResultBodyPtr theResultBody,
- const ListOfShape& theObjects,
- const GeomMakeShapePtr& theMakeShape)
-{
- std::shared_ptr<GeomAPI_Shape> aResultShape = theMakeShape->shape();
-
- if(theObjects.front()->isEqual(aResultShape)) {
- theResultBody->store(aResultShape, false);
- return;
- }
-
- theResultBody->storeModified(theObjects, aResultShape, theMakeShape);
-
- const int aShapeTypesNb = 3;
- const GeomAPI_Shape::ShapeType aShapeTypes[aShapeTypesNb] = {GeomAPI_Shape::VERTEX,
- GeomAPI_Shape::EDGE,
- GeomAPI_Shape::FACE };
- for (ListOfShape::const_iterator anIt = theObjects.cbegin(); anIt != theObjects.cend(); ++anIt) {
- const GeomShapePtr aShape = *anIt;
- for(int anIndex = 0; anIndex < aShapeTypesNb; ++anIndex) {
- theResultBody->loadModifiedShapes(theMakeShape, aShape, aShapeTypes[anIndex]);
- theResultBody->loadGeneratedShapes(theMakeShape, aShape, aShapeTypes[anIndex]);
- }
- }
-}
#ifndef FeaturesPlugin_Intersection_H_
#define FeaturesPlugin_Intersection_H_
-#include "FeaturesPlugin.h"
-
-#include <ModelAPI_Feature.h>
-
-#include <GeomAPI_Shape.h>
+#include "FeaturesPlugin_VersionedBoolean.h"
class GeomAlgoAPI_MakeShape;
/// whole objects, compsoilds, solids, shells, faces or edges.
/// The result is less than the minimal dimension from pair of intersection:
/// for two solids or two faces it is wire, for the edge and face it is vertex, etc.
-class FeaturesPlugin_Intersection : public ModelAPI_Feature
+class FeaturesPlugin_Intersection : public FeaturesPlugin_VersionedBoolean
{
public:
/// Feature kind.
/// Use plugin manager for features creation.
FeaturesPlugin_Intersection();
-
-private:
- /// Load Naming data structure of the feature to the document.
- void loadNamingDS(std::shared_ptr<ModelAPI_ResultBody> theResultBody,
- const ListOfShape& theObjects,
- const std::shared_ptr<GeomAlgoAPI_MakeShape>& theMakeShape);
};
#endif
--- /dev/null
+# Copyright (C) 2020 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
+#
+
+from salome.shaper import model
+
+model.begin()
+partSet = model.moduleDocument()
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
+LinearCopy_1 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "Box_1_1")], model.selection("EDGE", "PartSet/OX"), 20, 2)
+Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 5, 5)
+Plane_4 = model.addPlane(Part_1_doc, model.selection("FACE", "PartSet/XOY"), model.selection("EDGE", "PartSet/OX"), 30)
+Partition_1 = model.addPartition(Part_1_doc, [model.selection("SOLID", "Cylinder_1_1"), model.selection("FACE", "Plane_1")])
+Intersection_1 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "LinearCopy_1_1_1"), model.selection("SOLID", "Partition_1_1_1")])
+model.end()
+
+from GeomAPI import *
+
+model.testNbResults(Intersection_1, 1)
+model.testNbSubResults(Intersection_1, [6])
+model.testNbSubShapes(Intersection_1, GeomAPI_Shape.SOLID, [0])
+model.testNbSubShapes(Intersection_1, GeomAPI_Shape.FACE, [0])
+model.testNbSubShapes(Intersection_1, GeomAPI_Shape.EDGE, [6])
+model.testNbSubShapes(Intersection_1, GeomAPI_Shape.VERTEX, [12])
+model.testResultsVolumes(Intersection_1, [0])
+
+assert(model.checkPythonDump())
--- /dev/null
+# Copyright (C) 2020 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
+#
+
+from salome.shaper import model
+
+model.begin()
+partSet = model.moduleDocument()
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
+LinearCopy_1 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "Box_1_1")], model.selection("EDGE", "PartSet/OX"), 20, 2)
+Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 5, 10)
+LinearCopy_2 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "Cylinder_1_1")], model.selection("EDGE", "PartSet/OY"), 20, 3)
+Intersection_1 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "LinearCopy_1_1_1"), model.selection("SOLID", "LinearCopy_2_1_1")])
+model.end()
+
+from GeomAPI import *
+
+model.testNbResults(Intersection_1, 1)
+model.testNbSubResults(Intersection_1, [8])
+model.testNbSubShapes(Intersection_1, GeomAPI_Shape.SOLID, [0])
+model.testNbSubShapes(Intersection_1, GeomAPI_Shape.FACE, [0])
+model.testNbSubShapes(Intersection_1, GeomAPI_Shape.EDGE, [8])
+model.testNbSubShapes(Intersection_1, GeomAPI_Shape.VERTEX, [16])
+model.testResultsVolumes(Intersection_1, [0])
+
+assert(model.checkPythonDump())
--- /dev/null
+# Copyright (C) 2020 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
+#
+
+from salome.shaper import model
+
+model.begin()
+partSet = model.moduleDocument()
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
+LinearCopy_1 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "Box_1_1")], model.selection("EDGE", "PartSet/OX"), 20, 2, keepSubResults = True)
+Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 5, 5)
+Plane_4 = model.addPlane(Part_1_doc, model.selection("FACE", "PartSet/XOY"), model.selection("EDGE", "PartSet/OX"), 30)
+Partition_1 = model.addPartition(Part_1_doc, [model.selection("SOLID", "Cylinder_1_1"), model.selection("FACE", "Plane_1")], keepSubResults = True)
+Intersection_1 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "LinearCopy_1_1_1"), model.selection("SOLID", "Partition_1_1_1")], keepSubResults = True)
+model.end()
+
+from GeomAPI import *
+
+model.testNbResults(Intersection_1, 1)
+model.testNbSubResults(Intersection_1, [2])
+model.testNbSubShapes(Intersection_1, GeomAPI_Shape.SOLID, [1])
+model.testNbSubShapes(Intersection_1, GeomAPI_Shape.FACE, [6])
+model.testNbSubShapes(Intersection_1, GeomAPI_Shape.EDGE, [30])
+model.testNbSubShapes(Intersection_1, GeomAPI_Shape.VERTEX, [60])
+model.testResultsVolumes(Intersection_1, [1000])
+
+assert(model.checkPythonDump())
--- /dev/null
+# Copyright (C) 2020 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
+#
+
+from salome.shaper import model
+
+model.begin()
+partSet = model.moduleDocument()
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
+LinearCopy_1 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "Box_1_1")], model.selection("EDGE", "PartSet/OX"), 20, 2, keepSubResults = True)
+Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 5, 10)
+LinearCopy_2 = model.addMultiTranslation(Part_1_doc, [model.selection("SOLID", "Cylinder_1_1")], model.selection("EDGE", "PartSet/OY"), 20, 3, keepSubResults = True)
+Intersection_1 = model.addIntersection(Part_1_doc, [model.selection("SOLID", "LinearCopy_1_1_1"), model.selection("SOLID", "LinearCopy_2_1_1")], keepSubResults = True)
+model.end()
+
+from GeomAPI import *
+
+model.testNbResults(Intersection_1, 1)
+model.testNbSubResults(Intersection_1, [3])
+model.testNbSubShapes(Intersection_1, GeomAPI_Shape.SOLID, [3])
+model.testNbSubShapes(Intersection_1, GeomAPI_Shape.FACE, [12])
+model.testNbSubShapes(Intersection_1, GeomAPI_Shape.EDGE, [44])
+model.testNbSubShapes(Intersection_1, GeomAPI_Shape.VERTEX, [88])
+model.testResultsVolumes(Intersection_1, [2570.79632679489714])
+
+assert(model.checkPythonDump())