]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_WidgetSelectorStore.cpp
Salome HOME
Issue #2052: Modification of parameters don't work (sketch, extrusion)
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetSelectorStore.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModuleBase_WidgetSelectorStore.cpp
4 // Created:     2 June 2014
5 // Author:      Vitaly Smetannikov
6
7 #include <ModuleBase_WidgetSelectorStore.h>
8 #include <ModuleBase_Tools.h>
9 #include <ModuleBase_IWorkshop.h>
10
11 #include <ModelAPI_AttributeRefAttr.h>
12 #include <ModelAPI_AttributeSelectionList.h>
13 #include <ModelAPI_AttributeRefList.h>
14 #include <ModelAPI_AttributeRefAttrList.h>
15
16 ModuleBase_WidgetSelectorStore::ModuleBase_WidgetSelectorStore()
17 : myIsObject(false), mySelectionType(""), mySelectionCount(0)
18 {
19 }
20
21 void ModuleBase_WidgetSelectorStore::storeAttributeValue(const AttributePtr& theAttribute,
22                                                          ModuleBase_IWorkshop* theWorkshop)
23 {
24   if (!theAttribute.get())
25     return;
26
27   std::string aType = theAttribute->attributeType();
28   if (aType == ModelAPI_AttributeSelectionList::typeId()) {
29     AttributeSelectionListPtr aSelectionListAttr =
30                          std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
31     mySelectionType = aSelectionListAttr->selectionType();
32     mySelectionCount = aSelectionListAttr->size();
33   }
34   else if (aType == ModelAPI_AttributeRefList::typeId()) {
35     AttributeRefListPtr aRefListAttr =
36                          std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
37     mySelectionCount = aRefListAttr->size();
38   }
39   else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
40     AttributeRefAttrListPtr aRefAttrListAttr =
41                          std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(theAttribute);
42     mySelectionCount = aRefAttrListAttr->size();
43   }
44   else {
45     myObject = ModuleBase_Tools::getObject(theAttribute);
46     myShape = ModuleBase_Tools::getShape(theAttribute, theWorkshop);
47     myRefAttribute = AttributePtr();
48     myIsObject = false;
49     AttributeRefAttrPtr aRefAttr =
50       std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
51     if (aRefAttr) {
52       myIsObject = aRefAttr->isObject();
53       myRefAttribute = aRefAttr->attr();
54     }
55   }
56 }
57
58 //********************************************************************
59 void ModuleBase_WidgetSelectorStore::restoreAttributeValue(const AttributePtr& theAttribute,
60                                                            ModuleBase_IWorkshop* theWorkshop)
61 {
62   std::string aType = theAttribute->attributeType();
63   if (aType == ModelAPI_AttributeSelectionList::typeId()) {
64     AttributeSelectionListPtr aSelectionListAttr =
65                    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
66     aSelectionListAttr->setSelectionType(mySelectionType);
67     // restore selection in the attribute. Indeed there is only one stored object
68     int aCountAppened = aSelectionListAttr->size() - mySelectionCount;
69     for (int i = 0; i < aCountAppened; i++)
70       aSelectionListAttr->removeLast();
71   }
72   else if (aType == ModelAPI_AttributeRefList::typeId()) {
73     AttributeRefListPtr aRefListAttr =
74                          std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
75     // restore objects in the attribute. Indeed there is only one stored object
76     int aCountAppened = aRefListAttr->size() - mySelectionCount;
77     for (int i = 0; i < aCountAppened; i++)
78       aRefListAttr->removeLast();
79   }
80   else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
81     AttributeRefAttrListPtr aRefAttrListAttr =
82                      std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(theAttribute);
83     // restore objects in the attribute. Indeed there is only one stored object
84     int aCountAppened = aRefAttrListAttr->size() - mySelectionCount;
85     for (int i = 0; i < aCountAppened; i++)
86       aRefAttrListAttr->removeLast();
87   }
88   else {
89     ModuleBase_Tools::setObject(theAttribute, myObject, myShape, theWorkshop, true, true);
90     AttributeRefAttrPtr aRefAttr =
91       std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
92     if (aRefAttr) {
93       if (!myIsObject)
94         aRefAttr->setAttr(myRefAttribute);
95     }
96   }
97 }