1 // File: FeaturesPlugin_Boolean.cpp
2 // Created: 02 Sept 2014
3 // Author: Vitaly SMETANNIKOV
5 #include "FeaturesPlugin_Boolean.h"
7 #include <ModelAPI_Data.h>
8 #include <ModelAPI_Document.h>
9 #include <ModelAPI_AttributeReference.h>
10 #include <ModelAPI_AttributeInteger.h>
11 #include <ModelAPI_ResultBody.h>
12 #include <GeomAlgoAPI_Boolean.h>
17 #define _DELETED_TAG 2
18 FeaturesPlugin_Boolean::FeaturesPlugin_Boolean()
22 void FeaturesPlugin_Boolean::initAttributes()
24 data()->addAttribute(FeaturesPlugin_Boolean::TYPE_ID(), ModelAPI_AttributeInteger::type());
25 data()->addAttribute(FeaturesPlugin_Boolean::OBJECT_ID(), ModelAPI_AttributeReference::type());
26 data()->addAttribute(FeaturesPlugin_Boolean::TOOL_ID(), ModelAPI_AttributeReference::type());
29 std::shared_ptr<GeomAPI_Shape> FeaturesPlugin_Boolean::getShape(const std::string& theAttrName)
31 std::shared_ptr<ModelAPI_AttributeReference> aObjRef = std::dynamic_pointer_cast<
32 ModelAPI_AttributeReference>(data()->attribute(theAttrName));
34 std::shared_ptr<ModelAPI_ResultBody> aConstr = std::dynamic_pointer_cast<
35 ModelAPI_ResultBody>(aObjRef->value());
37 return aConstr->shape();
39 return std::shared_ptr<GeomAPI_Shape>();
43 void FeaturesPlugin_Boolean::execute()
45 std::shared_ptr<ModelAPI_AttributeInteger> aTypeAttr = std::dynamic_pointer_cast<
46 ModelAPI_AttributeInteger>(data()->attribute(FeaturesPlugin_Boolean::TYPE_ID()));
49 int aType = aTypeAttr->value();
51 std::shared_ptr<GeomAPI_Shape> anObject = this->getShape(FeaturesPlugin_Boolean::OBJECT_ID());
55 std::shared_ptr<GeomAPI_Shape> aTool = this->getShape(FeaturesPlugin_Boolean::TOOL_ID());
59 std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data());
61 GeomAlgoAPI_Boolean* aFeature = new GeomAlgoAPI_Boolean(anObject, aTool, aType);
62 if(aFeature && !aFeature->isDone()) {
63 static const std::string aFeatureError = "Boolean feature: algorithm failed";
64 setError(aFeatureError);
67 // Check if shape is valid
68 if (aFeature->shape()->isNull()) {
69 static const std::string aShapeError = "Boolean feature: resulting shape is Null";
70 setError(aShapeError);
73 if(!aFeature->isValid()) {
74 static const std::string aFeatureError = "Boolean feature: resulting shape is not valid";
75 setError(aFeatureError);
78 // if result of Boolean operation is same as was before it means that Boolean operation has no sence
79 // and naming provides no result, so, generate an error in this case
80 if (anObject->isEqual(aFeature->shape())) {
81 static const std::string aFeatureError = "Boolean feature: operation was not performed";
82 setError(aFeatureError);
86 LoadNamingDS(aFeature, aResultBody, anObject, aTool, aType);
88 setResult(aResultBody);
91 //============================================================================
92 void FeaturesPlugin_Boolean::LoadNamingDS(GeomAlgoAPI_Boolean* theFeature,
93 std::shared_ptr<ModelAPI_ResultBody> theResultBody,
94 std::shared_ptr<GeomAPI_Shape> theObject,
95 std::shared_ptr<GeomAPI_Shape> theTool,
100 theResultBody->storeModified(theObject, theFeature->shape());
102 GeomAPI_DataMapOfShapeShape* aSubShapes = new GeomAPI_DataMapOfShapeShape();
103 theFeature->mapOfShapes(*aSubShapes);
105 // Put in DF modified faces
106 theResultBody->loadAndOrientModifiedShapes(theFeature->makeShape(), theObject, FACE, _MODIFY_TAG, *aSubShapes);
107 theResultBody->loadAndOrientModifiedShapes(theFeature->makeShape(), theTool, FACE, _MODIFY_TAG, *aSubShapes);
109 //Put in DF deleted faces
110 theResultBody->loadDeletedShapes(theFeature->makeShape(), theObject, FACE, _DELETED_TAG);
111 theResultBody->loadDeletedShapes(theFeature->makeShape(), theTool, FACE, _DELETED_TAG);