FeaturesPlugin_Translation.h
FeaturesPlugin_Boolean.h
FeaturesPlugin_Group.h
+ FeaturesPlugin_Intersection.h
FeaturesPlugin_Partition.h
FeaturesPlugin_Placement.h
FeaturesPlugin_CompositeBoolean.h
FeaturesPlugin_Translation.cpp
FeaturesPlugin_Boolean.cpp
FeaturesPlugin_Group.cpp
+ FeaturesPlugin_Intersection.cpp
FeaturesPlugin_Partition.cpp
FeaturesPlugin_Placement.cpp
FeaturesPlugin_CompositeBoolean.cpp
group_widget.xml
partition_widget.xml
placement_widget.xml
+ intersection_widget.xml
)
INCLUDE_DIRECTORIES(
SET(PROJECT_LIBRARIES
Events
- ModelAPI
- GeomAPI
+ ModelAPI
+ GeomAPI
GeomAlgoAPI
)
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File: FeaturesPlugin_Intersection.cpp
+// Created: 15 Feb 2016
+// Author: Dmitry Bobylev
+
+#include "FeaturesPlugin_Intersection.h"
+
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_BodyBuilder.h>
+#include <ModelAPI_ResultBody.h>
+#include <ModelAPI_AttributeSelectionList.h>
+
+#include <GeomAlgoAPI_Intersection.h>
+
+#include <sstream>
+
+//=================================================================================================
+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(), ModelAPI_AttributeSelectionList::typeId());
+}
+
+//=================================================================================================
+void FeaturesPlugin_Intersection::execute()
+{
+ ListOfShape anObjects, aTools;
+
+ // Getting objects.
+ AttributeSelectionListPtr anObjectsSelList = selectionList(FeaturesPlugin_Intersection::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);
+ }
+
+ // 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()) {
+ 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;
+ }
+
+ std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data(), aResultIndex);
+ loadNamingDS(aResultBody, anObject, aTools, anIntersectionAlgo);
+ setResult(aResultBody, aResultIndex);
+ aResultIndex++;
+ }
+
+ // remove the rest results if there were produced in the previous pass
+ removeResults(aResultIndex);
+}
+
+//=================================================================================================
+void FeaturesPlugin_Intersection::loadNamingDS(std::shared_ptr<ModelAPI_ResultBody> theResultBody,
+ const std::shared_ptr<GeomAPI_Shape> theBaseShape,
+ const ListOfShape& theTools,
+ GeomAlgoAPI_MakeShape& theMakeShape)
+{
+ //load result
+ std::shared_ptr<GeomAPI_Shape> aResultShape = theMakeShape.shape();
+ std::shared_ptr<GeomAPI_DataMapOfShapeShape> aMapOfShapes = theMakeShape.mapOfSubShapes();
+ const int aDeletedTag = 1;
+ const int aSubsolidsTag = 2; /// sub solids will be placed at labels 3, 4, etc. if result is compound of solids
+ const int aModifyTag = 100000;
+ int aModifyToolsTag = 200000;
+ std::ostringstream aStream;
+
+ theResultBody->storeModified(theBaseShape, aResultShape, aSubsolidsTag);
+
+ std::string aModName = "Modified";
+ theResultBody->loadAndOrientModifiedShapes(&theMakeShape, theBaseShape, GeomAPI_Shape::VERTEX,
+ aModifyTag, aModName, *aMapOfShapes.get(), true);
+ theResultBody->loadAndOrientModifiedShapes(&theMakeShape, theBaseShape, GeomAPI_Shape::EDGE,
+ aModifyTag, aModName, *aMapOfShapes.get(), true);
+ theResultBody->loadDeletedShapes(&theMakeShape, theBaseShape, GeomAPI_Shape::FACE, aDeletedTag);
+
+ int anIndex = 1;
+ for(ListOfShape::const_iterator anIter = theTools.begin(); anIter != theTools.end(); anIter++) {
+ aStream.str(std::string());
+ aStream.clear();
+ aStream << aModName << "_" << anIndex++;
+ theResultBody->loadAndOrientModifiedShapes(&theMakeShape, *anIter, GeomAPI_Shape::VERTEX,
+ aModifyToolsTag, aStream.str(), *aMapOfShapes.get(), true);
+ theResultBody->loadAndOrientModifiedShapes(&theMakeShape, *anIter, GeomAPI_Shape::EDGE,
+ aModifyToolsTag, aStream.str(), *aMapOfShapes.get(), true);
+ theResultBody->loadDeletedShapes(&theMakeShape, *anIter, GeomAPI_Shape::FACE, aDeletedTag);
+ aModifyToolsTag += 10000;
+ }
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File: FeaturesPlugin_Intersection.h
+// Created: 15 Feb 2016
+// Author: Dmitry Bobylev
+
+#ifndef FeaturesPlugin_Intersection_H_
+#define FeaturesPlugin_Intersection_H_
+
+#include "FeaturesPlugin.h"
+
+#include <ModelAPI_Feature.h>
+
+#include <GeomAPI_Shape.h>
+
+class GeomAlgoAPI_MakeShape;
+
+/// \class FeaturesPlugin_Intersection
+/// \ingroup Plugins
+/// \brief Intersection feature takes a list of shapes as objects and list of shapes as tools.
+/// The types of objects and tools may be different: 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
+{
+public:
+ /// Feature kind.
+ inline static const std::string& ID()
+ {
+ static const std::string MY_ID("Intersection");
+ return MY_ID;
+ }
+
+ /// Attribute name of objects.
+ inline static const std::string& OBJECT_LIST_ID()
+ {
+ static const std::string MY_OBJECT_LIST_ID("main_objects");
+ 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()
+ {
+ static std::string MY_KIND = FeaturesPlugin_Intersection::ID();
+ return MY_KIND;
+ }
+
+ /// Executes feature.
+ FEATURESPLUGIN_EXPORT virtual void execute();
+
+ /// Request for initialization of data model of the feature: adding all attributes.
+ FEATURESPLUGIN_EXPORT virtual void initAttributes();
+
+ /// 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 std::shared_ptr<GeomAPI_Shape> theBaseShape,
+ const ListOfShape& theTools,
+ GeomAlgoAPI_MakeShape& theMakeShape);
+};
+
+#endif
#include <FeaturesPlugin_ExtrusionCut.h>
#include <FeaturesPlugin_ExtrusionFuse.h>
#include <FeaturesPlugin_Group.h>
+#include <FeaturesPlugin_Intersection.h>
#include <FeaturesPlugin_Translation.h>
#include <FeaturesPlugin_Partition.h>
#include <FeaturesPlugin_Placement.h>
return FeaturePtr(new FeaturesPlugin_Boolean);
} else if (theFeatureID == FeaturesPlugin_Group::ID()) {
return FeaturePtr(new FeaturesPlugin_Group);
+ } else if (theFeatureID == FeaturesPlugin_Intersection::ID()) {
+ return FeaturePtr(new FeaturesPlugin_Intersection);
} else if (theFeatureID == FeaturesPlugin_Partition::ID()) {
return FeaturePtr(new FeaturesPlugin_Partition);
} else if (theFeatureID == FeaturesPlugin_Placement::ID()) {
--- /dev/null
+<!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+<source>
+ <multi_selector id="main_objects"
+ label="Main objects"
+ icon=":icons/cut_shape.png"
+ tooltip="Select objects(objects, compsoilds, solids, shells, faces or edges)"
+ type_choice="Solids Objects"
+ use_choice="false"
+ concealment="true">
+ <validator id="PartSet_DifferentObjects"/>
+ <validator id="GeomValidators_ShapeType" parameters="edge,face,solid"/>
+ </multi_selector>
+ <multi_selector id="tool_objects"
+ label="Tool objects"
+ icon=":icons/cut_tool.png"
+ tooltip="Select tools(objects, compsoilds, solids, shells, faces or edges)"
+ type_choice="Solids Objects"
+ use_choice="false"
+ concealment="true">
+ <validator id="PartSet_DifferentObjects"/>
+ <validator id="GeomValidators_ShapeType" parameters="edge,face,solid"/>
+ </multi_selector>
+</source>
<feature id="Partition" title="Partition" tooltip="Perform partition operations with solids" icon=":icons/partition.png">
<source path="partition_widget.xml"/>
</feature>
+ <feature id="Intersection" title="Intersection" tooltip="Intersect objects with tools" icon=":icons/intersection.png">
+ <source path="intersection_widget.xml"/>
+ </feature>
</group>
<group id="Collections">
<feature id="Group"
GeomAlgoAPI_ShapeTools.h
GeomAlgoAPI_Partition.h
GeomAlgoAPI_PaveFiller.h
+ GeomAlgoAPI_Intersection.h
)
SET(PROJECT_SOURCES
GeomAlgoAPI_ShapeTools.cpp
GeomAlgoAPI_Partition.cpp
GeomAlgoAPI_PaveFiller.cpp
+ GeomAlgoAPI_Intersection.cpp
)
SET(PROJECT_LIBRARIES
ModelAPI
${CAS_OCAF}
${CAS_SHAPE}
- ${CAS_TKBO}
- ${CAS_TKBool}
+ ${CAS_TKBO}
+ ${CAS_TKBool}
${CAS_TKBRep}
${CAS_TKCAF}
${CAS_TKCAF}
%include "GeomAlgoAPI_Tools.h"
%include "GeomAlgoAPI_Transform.h"
%include "GeomAlgoAPI_PaveFiller.h"
+%include "GeomAlgoAPI_Intersection.h"
%typemap(out) std::list< std::shared_ptr< GeomAPI_Shape > >::value_type & {
$result = SWIG_NewPointerObj(SWIG_as_voidptr(new std::shared_ptr<GeomAPI_Shape>(*$1)), $descriptor(std::shared_ptr<GeomAPI_Shape> *), SWIG_POINTER_OWN | 0 );
}
-%template(ShapeList) std::list<std::shared_ptr<GeomAPI_Shape> >;
\ No newline at end of file
+%template(ShapeList) std::list<std::shared_ptr<GeomAPI_Shape> >;
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: GeomAlgoAPI_Intersection.cpp
+// Created: 16 Feb 2016
+// Author: Dmitry Bobylev
+
+#include "GeomAlgoAPI_Intersection.h"
+
+#include <GeomAlgoAPI_DFLoader.h>
+#include <GeomAlgoAPI_ShapeTools.h>
+
+#include <BRepAlgoAPI_Section.hxx>
+#include <TopExp_Explorer.hxx>
+#include <TopoDS_Builder.hxx>
+
+//=================================================================================================
+GeomAlgoAPI_Intersection::GeomAlgoAPI_Intersection(const ListOfShape& theObjects,
+ const ListOfShape& theTools)
+{
+ build(theObjects, theTools);
+}
+
+//=================================================================================================
+void GeomAlgoAPI_Intersection::build(const ListOfShape& theObjects,
+ const ListOfShape& theTools)
+{
+ if (theObjects.empty() || theTools.empty()) {
+ return;
+ }
+
+ // Creating partition operation.
+ BRepAlgoAPI_Section* anOperation = new BRepAlgoAPI_Section;
+ this->setImpl(anOperation);
+ this->setBuilderType(OCCT_BRepBuilderAPI_MakeShape);
+
+ TopAbs_ShapeEnum aShapeType = TopAbs_COMPOUND;
+
+ // Getting objects.
+ TopTools_ListOfShape anObjects;
+ for (ListOfShape::const_iterator anObjectsIt = theObjects.begin(); anObjectsIt != theObjects.end(); anObjectsIt++) {
+ const TopoDS_Shape& aShape = (*anObjectsIt)->impl<TopoDS_Shape>();
+ if(!aShape.IsNull()) {
+ 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);
+
+ // Building and getting result.
+ anOperation->Build();
+ if(!anOperation->IsDone()) {
+ return;
+ }
+ TopoDS_Shape aResult = anOperation->Shape();
+
+ if(aResult.ShapeType() == TopAbs_COMPOUND) {
+ aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
+ }
+
+ std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
+ aShape->setImpl(new TopoDS_Shape(aResult));
+ this->setShape(aShape);
+ this->setDone(true);
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: GeomAlgoAPI_Intersection.h
+// Created: 16 Feb 2016
+// Author: Dmitry Bobylev
+
+#ifndef GeomAlgoAPI_Intersection_H_
+#define GeomAlgoAPI_Intersection_H_
+
+#include <GeomAlgoAPI.h>
+#include <GeomAlgoAPI_MakeShape.h>
+
+#include <GeomAPI_Shape.h>
+
+/// \class GeomAlgoAPI_Intersection
+/// \ingroup DataAlgo
+/// \brief Performs the intersection operations.
+class GeomAlgoAPI_Intersection : public GeomAlgoAPI_MakeShape
+{
+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);
+
+private:
+ /// Builds resulting shape.
+ void build(const ListOfShape& theObjects,
+ const ListOfShape& theTools);
+};
+
+#endif
#include "GeomAlgoAPI_Tools.h"
#include "GeomAlgoAPI_Transform.h"
#include "GeomAlgoAPI_PaveFiller.h"
+ #include "GeomAlgoAPI_Intersection.h"
#include <memory>
#include <string>
return false;
}
std::string aFeatureKind = aFeature->getKind();
- if(aFeatureKind == "Sketch") {
- theError = "Error: sketch shape is selected, but only objects are acceptable.";
+ if(aFeatureKind == "Sketch" ||
+ aFeatureKind == "Plane" ||
+ aFeatureKind == "Axis") {
+ theError = "Error: ";
+ theError += aFeatureKind;
+ theError += " shape is not allowed for selection.";
return false;
}
aShape = aContext->shape();