Salome HOME
ExtrusionCut launch
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_ExtrusionCut.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        FeaturesPlugin_ExtrusionCut.cpp
4 // Created:     12 May 2015
5 // Author:      Dmitry Bobylev
6
7 #include <FeaturesPlugin_ExtrusionCut.h>
8
9 #include <ModelAPI_AttributeDouble.h>
10 #include <ModelAPI_AttributeSelectionList.h>
11 #include <ModelAPI_AttributeReference.h>
12 #include <ModelAPI_Validator.h>
13 #include <ModelAPI_Session.h>
14 #include <ModelAPI_Data.h>
15 #include <ModelAPI_AttributeRefList.h>
16
17 //=================================================================================================
18 FeaturesPlugin_ExtrusionCut::FeaturesPlugin_ExtrusionCut()
19 {
20 }
21
22 //=================================================================================================
23 void FeaturesPlugin_ExtrusionCut::initAttributes()
24 {
25
26   data()->addAttribute(SKETCH_OBJECT_ID(), ModelAPI_AttributeReference::typeId());
27
28   data()->addAttribute(FROM_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
29   data()->addAttribute(FROM_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
30
31   data()->addAttribute(TO_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
32   data()->addAttribute(TO_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
33
34   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FeaturesPlugin_ExtrusionCut::FROM_OBJECT_ID());
35   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FeaturesPlugin_ExtrusionCut::TO_OBJECT_ID());
36
37   data()->addAttribute(CUTLIST_ID(), ModelAPI_AttributeSelectionList::typeId());
38
39   // extrusion works with faces always
40   AttributeSelectionListPtr aSelection = data()->selectionList(CUTLIST_ID());
41   aSelection->setSelectionType("SOLID");
42 }
43
44
45 std::shared_ptr<ModelAPI_Feature> FeaturesPlugin_ExtrusionCut::addFeature(std::string theID)
46 {
47   std::shared_ptr<ModelAPI_Feature> aNew = document()->addFeature(theID, false);
48   if (aNew) {
49     data()->reference(SKETCH_OBJECT_ID())->setValue(aNew);
50   }
51    // set as current also after it becomes sub to set correctly enabled for other sketch subs
52   //document()->setCurrentFeature(aNew, false);
53   return aNew;
54 }
55
56   
57 int FeaturesPlugin_ExtrusionCut::numberOfSubs() const
58 {
59   ObjectPtr aObj = data()->reference(SKETCH_OBJECT_ID())->value();
60   return aObj.get()? 1 : 0;
61 }
62
63 std::shared_ptr<ModelAPI_Feature> FeaturesPlugin_ExtrusionCut::subFeature(const int theIndex) const
64 {
65   if (theIndex == 0)
66     return std::dynamic_pointer_cast<ModelAPI_Feature>(data()->reference(SKETCH_OBJECT_ID())->value());
67   return std::shared_ptr<ModelAPI_Feature>();
68 }
69
70 int FeaturesPlugin_ExtrusionCut::subFeatureId(const int theIndex) const
71 {
72   std::shared_ptr<ModelAPI_Feature> aFeature = subFeature(theIndex);
73   if (aFeature.get())
74     return aFeature->data()->featureId();
75   return -1;
76 }
77
78 bool FeaturesPlugin_ExtrusionCut::isSub(ObjectPtr theObject) const
79 {
80   // check is this feature of result
81   FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
82   if (!aFeature)
83     return false;
84  
85   ObjectPtr aSub = data()->reference(SKETCH_OBJECT_ID())->value();
86   return aSub == theObject;
87 }
88
89 void FeaturesPlugin_ExtrusionCut::removeFeature(std::shared_ptr<ModelAPI_Feature> theFeature)
90 {
91 }
92
93 //=================================================================================================
94 void FeaturesPlugin_ExtrusionCut::execute()
95 {
96 }