Salome HOME
220b4144c6e05edfdfe87eb12124309be7ea5e4f
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Boolean.cpp
1 // File:        FeaturesPlugin_Boolean.cpp
2 // Created:     02 Sept 2014
3 // Author:      Vitaly SMETANNIKOV
4
5 #include "FeaturesPlugin_Boolean.h"
6
7 #include <ModelAPI_Data.h>
8 #include <ModelAPI_Document.h>
9 #include <ModelAPI_AttributeReference.h>
10 #include <ModelAPI_ResultBody.h>
11 #include <GeomAlgoAPI_Boolean.h>
12
13 using namespace std;
14
15 FeaturesPlugin_Boolean::FeaturesPlugin_Boolean()
16 {
17 }
18
19 void FeaturesPlugin_Boolean::initAttributes()
20 {
21   data()->addAttribute(FeaturesPlugin_Boolean::TYPE_ID(), ModelAPI_AttributeReference::type());
22   data()->addAttribute(FeaturesPlugin_Boolean::OBJECT_ID(), ModelAPI_AttributeReference::type());
23   data()->addAttribute(FeaturesPlugin_Boolean::TOOL_ID(), ModelAPI_AttributeReference::type());
24 }
25
26 boost::shared_ptr<GeomAPI_Shape> FeaturesPlugin_Boolean::getShape(const std::string& theAttrName)
27 {
28   boost::shared_ptr<ModelAPI_AttributeReference> aObjRef = boost::dynamic_pointer_cast<
29       ModelAPI_AttributeReference>(data()->attribute(theAttrName));
30   if (aObjRef) {
31     boost::shared_ptr<ModelAPI_ResultBody> aConstr = boost::dynamic_pointer_cast<
32         ModelAPI_ResultBody>(aObjRef->value());
33     if (aConstr)
34       return aConstr->shape();
35   }
36   return boost::shared_ptr<GeomAPI_Shape>();
37 }
38
39
40 void FeaturesPlugin_Boolean::execute()
41 {
42   boost::shared_ptr<GeomAPI_Shape> aObject = this->getShape(FeaturesPlugin_Boolean::OBJECT_ID());
43   if (!aObject)
44     return;
45
46   boost::shared_ptr<GeomAPI_Shape> aTool = this->getShape(FeaturesPlugin_Boolean::TOOL_ID());
47   if (!aTool)
48     return;
49
50   boost::shared_ptr<ModelAPI_ResultBody> aResult = document()->createBody(data());
51   aResult->store(GeomAlgoAPI_Boolean::makeCut(aObject, aTool));
52   setResult(aResult);
53 }