1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: SketchShapePlugin_Feature.cpp
4 // Created: 25 Nov 2015
5 // Author: Natalia ERMOLAEVA
7 #include "SketchShapePlugin_Feature.h"
9 #include <ModelAPI_AttributeSelection.h>
10 #include <ModelAPI_AttributeSelectionList.h>
11 #include <ModelAPI_AttributeBoolean.h>
13 #include <ModelAPI_Session.h>
14 #include <ModelAPI_Validator.h>
16 SketchShapePlugin_Feature::SketchShapePlugin_Feature()
21 void SketchShapePlugin_Feature::initAttributes()
23 data()->addAttribute(SKETCH_ID(), ModelAPI_AttributeSelection::typeId());
25 data()->addAttribute(VERTEX_LIST_ID(), ModelAPI_AttributeSelectionList::typeId());
26 data()->addAttribute(VERTEX_CHOICE_ID(), ModelAPI_AttributeBoolean::typeId());
27 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), VERTEX_CHOICE_ID());
29 data()->addAttribute(EDGE_LIST_ID(), ModelAPI_AttributeSelectionList::typeId());
30 data()->addAttribute(EDGE_CHOICE_ID(), ModelAPI_AttributeBoolean::typeId());
31 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EDGE_CHOICE_ID());
33 data()->addAttribute(FACE_LIST_ID(), ModelAPI_AttributeSelectionList::typeId());
34 data()->addAttribute(FACE_CHOICE_ID(), ModelAPI_AttributeBoolean::typeId());
35 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FACE_CHOICE_ID());
38 void SketchShapePlugin_Feature::execute()
42 void SketchShapePlugin_Feature::attributeChanged(const std::string& theID)
44 if (theID == VERTEX_CHOICE_ID() ||
45 theID == EDGE_CHOICE_ID() ||
46 theID == FACE_CHOICE_ID()) {
47 std::string aListAttrId = theID == VERTEX_CHOICE_ID() ? VERTEX_LIST_ID() : (
48 theID == EDGE_CHOICE_ID() ? EDGE_LIST_ID() :
51 AttributeBooleanPtr aChoiceAttribute = std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(
52 data()->attribute(theID));
53 if (!aChoiceAttribute->value()) {
54 AttributeSelectionListPtr aListAttribute =
55 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(data()->attribute(aListAttrId));
56 aListAttribute->clear();
59 else if (theID == VERTEX_LIST_ID() ||
60 theID == EDGE_LIST_ID() ||
61 theID == FACE_LIST_ID()) {
62 AttributeSelectionListPtr aSelectionListAttr =
63 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(data()->attribute(theID));
64 for (int i = 0, aSize = aSelectionListAttr->size(); i < aSize; i++) {
65 AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i);
66 ObjectPtr anObject = aSelectAttr->context();
70 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);