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>
13 #include <Events_Error.h>
22 #define _DELETED_TAG 2
23 FeaturesPlugin_Boolean::FeaturesPlugin_Boolean()
27 void FeaturesPlugin_Boolean::initAttributes()
29 data()->addAttribute(FeaturesPlugin_Boolean::TYPE_ID(), ModelAPI_AttributeInteger::type());
30 data()->addAttribute(FeaturesPlugin_Boolean::OBJECT_ID(), ModelAPI_AttributeReference::type());
31 data()->addAttribute(FeaturesPlugin_Boolean::TOOL_ID(), ModelAPI_AttributeReference::type());
34 boost::shared_ptr<GeomAPI_Shape> FeaturesPlugin_Boolean::getShape(const std::string& theAttrName)
36 boost::shared_ptr<ModelAPI_AttributeReference> aObjRef = boost::dynamic_pointer_cast<
37 ModelAPI_AttributeReference>(data()->attribute(theAttrName));
39 boost::shared_ptr<ModelAPI_ResultBody> aConstr = boost::dynamic_pointer_cast<
40 ModelAPI_ResultBody>(aObjRef->value());
42 return aConstr->shape();
44 return boost::shared_ptr<GeomAPI_Shape>();
48 void FeaturesPlugin_Boolean::execute()
50 boost::shared_ptr<ModelAPI_AttributeInteger> aTypeAttr = boost::dynamic_pointer_cast<
51 ModelAPI_AttributeInteger>(data()->attribute(FeaturesPlugin_Boolean::TYPE_ID()));
54 int aType = aTypeAttr->value();
56 boost::shared_ptr<GeomAPI_Shape> anObject = this->getShape(FeaturesPlugin_Boolean::OBJECT_ID());
60 boost::shared_ptr<GeomAPI_Shape> aTool = this->getShape(FeaturesPlugin_Boolean::TOOL_ID());
64 boost::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data());
66 GeomAlgoAPI_Boolean* aFeature = new GeomAlgoAPI_Boolean(anObject, aTool, aType);
67 if(aFeature && !aFeature->isDone()) {
68 std::string aFeatureError = "Boolean feature: algorithm failed";
69 Events_Error::send(aFeatureError, this);
72 // Check if shape is valid
73 if (aFeature->shape()->isNull()) {
74 std::string aShapeError = "Boolean feature: resulting shape is Null";
75 Events_Error::send(aShapeError, this);
77 std::cerr << aShapeError << std::endl;
81 if(!aFeature->isValid()) {
82 std::string aFeatureError = "Boolean feature: resulting shape is not valid";
83 Events_Error::send(aFeatureError, this);
87 LoadNamingDS(aFeature, aResultBody, anObject, aTool, aType);
89 setResult(aResultBody);
92 //============================================================================
93 void FeaturesPlugin_Boolean::LoadNamingDS(GeomAlgoAPI_Boolean* theFeature,
94 boost::shared_ptr<ModelAPI_ResultBody> theResultBody,
95 boost::shared_ptr<GeomAPI_Shape> theObject,
96 boost::shared_ptr<GeomAPI_Shape> theTool,
101 theResultBody->storeModified(theObject, theFeature->shape());
103 GeomAPI_DataMapOfShapeShape* aSubShapes = new GeomAPI_DataMapOfShapeShape();
104 theFeature->mapOfShapes(*aSubShapes);
106 // Put in DF modified faces
107 theResultBody->loadAndOrientModifiedShapes(theFeature->makeShape(), theObject, FACE, _MODIFY_TAG, *aSubShapes);
108 theResultBody->loadAndOrientModifiedShapes(theFeature->makeShape(), theTool, FACE, _MODIFY_TAG, *aSubShapes);
110 //Put in DF deleted faces
111 theResultBody->loadDeletedShapes(theFeature->makeShape(), theObject, FACE, _DELETED_TAG);
112 theResultBody->loadDeletedShapes(theFeature->makeShape(), theTool, FACE, _DELETED_TAG);