1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: FeaturesPlugin_ExtrusionCut.cpp
4 // Created: 12 May 2015
5 // Author: Dmitry Bobylev
7 #include <FeaturesPlugin_ExtrusionCut.h>
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>
17 //=================================================================================================
18 FeaturesPlugin_ExtrusionCut::FeaturesPlugin_ExtrusionCut()
22 //=================================================================================================
23 void FeaturesPlugin_ExtrusionCut::initAttributes()
26 data()->addAttribute(SKETCH_OBJECT_ID(), ModelAPI_AttributeReference::typeId());
28 data()->addAttribute(FROM_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
29 data()->addAttribute(FROM_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
31 data()->addAttribute(TO_OBJECT_ID(), ModelAPI_AttributeSelection::typeId());
32 data()->addAttribute(TO_SIZE_ID(), ModelAPI_AttributeDouble::typeId());
34 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FeaturesPlugin_ExtrusionCut::FROM_OBJECT_ID());
35 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FeaturesPlugin_ExtrusionCut::TO_OBJECT_ID());
37 data()->addAttribute(CUTLIST_ID(), ModelAPI_AttributeSelectionList::typeId());
39 // extrusion works with faces always
40 AttributeSelectionListPtr aSelection = data()->selectionList(CUTLIST_ID());
41 aSelection->setSelectionType("SOLID");
45 std::shared_ptr<ModelAPI_Feature> FeaturesPlugin_ExtrusionCut::addFeature(std::string theID)
47 std::shared_ptr<ModelAPI_Feature> aNew = document()->addFeature(theID, false);
49 data()->reference(SKETCH_OBJECT_ID())->setValue(aNew);
51 // set as current also after it becomes sub to set correctly enabled for other sketch subs
52 //document()->setCurrentFeature(aNew, false);
57 int FeaturesPlugin_ExtrusionCut::numberOfSubs() const
59 ObjectPtr aObj = data()->reference(SKETCH_OBJECT_ID())->value();
60 return aObj.get()? 1 : 0;
63 std::shared_ptr<ModelAPI_Feature> FeaturesPlugin_ExtrusionCut::subFeature(const int theIndex) const
66 return std::dynamic_pointer_cast<ModelAPI_Feature>(data()->reference(SKETCH_OBJECT_ID())->value());
67 return std::shared_ptr<ModelAPI_Feature>();
70 int FeaturesPlugin_ExtrusionCut::subFeatureId(const int theIndex) const
72 std::shared_ptr<ModelAPI_Feature> aFeature = subFeature(theIndex);
74 return aFeature->data()->featureId();
78 bool FeaturesPlugin_ExtrusionCut::isSub(ObjectPtr theObject) const
80 // check is this feature of result
81 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
85 ObjectPtr aSub = data()->reference(SKETCH_OBJECT_ID())->value();
86 return aSub == theObject;
89 void FeaturesPlugin_ExtrusionCut::removeFeature(std::shared_ptr<ModelAPI_Feature> theFeature)
93 //=================================================================================================
94 void FeaturesPlugin_ExtrusionCut::execute()