Salome HOME
Fix regression in unit tests
[modules/shaper.git] / src / SketchShapePlugin / SketchShapePlugin_Feature.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        SketchShapePlugin_Feature.cpp
4 // Created:     25 Nov 2015
5 // Author:      Natalia ERMOLAEVA
6
7 #include "SketchShapePlugin_Feature.h"
8
9 #include <ModelAPI_AttributeSelection.h>
10 #include <ModelAPI_AttributeSelectionList.h>
11 #include <ModelAPI_AttributeBoolean.h>
12
13 #include <ModelAPI_Session.h>
14 #include <ModelAPI_Validator.h>
15
16 SketchShapePlugin_Feature::SketchShapePlugin_Feature()
17 : ModelAPI_Feature()
18 {
19 }
20
21 void SketchShapePlugin_Feature::initAttributes()
22 {
23   data()->addAttribute(SKETCH_ID(), ModelAPI_AttributeSelection::typeId());
24
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());
28
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());
32
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());
36 }
37
38 void SketchShapePlugin_Feature::execute()
39 {
40 }
41
42 void SketchShapePlugin_Feature::attributeChanged(const std::string& theID)
43 {
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() :
49                               FACE_LIST_ID());
50
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();
57     }
58   }
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();
67       if (!anObject.get())
68         continue;
69       else {
70         FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
71       }
72     }
73   }
74 }
75