1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ModuleBase_WidgetSelectorStore.cpp
4 // Created: 2 June 2014
5 // Author: Vitaly Smetannikov
7 #include <ModuleBase_WidgetSelectorStore.h>
8 #include <ModuleBase_Tools.h>
9 #include <ModuleBase_IWorkshop.h>
11 #include <ModelAPI_AttributeRefAttr.h>
12 #include <ModelAPI_AttributeSelectionList.h>
13 #include <ModelAPI_AttributeRefList.h>
14 #include <ModelAPI_AttributeRefAttrList.h>
16 ModuleBase_WidgetSelectorStore::ModuleBase_WidgetSelectorStore()
17 : myIsObject(false), mySelectionType(""), mySelectionCount(0)
21 void ModuleBase_WidgetSelectorStore::storeAttributeValue(const AttributePtr& theAttribute,
22 ModuleBase_IWorkshop* theWorkshop)
24 if (!theAttribute.get())
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();
34 else if (aType == ModelAPI_AttributeRefList::typeId()) {
35 AttributeRefListPtr aRefListAttr =
36 std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
37 mySelectionCount = aRefListAttr->size();
39 else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
40 AttributeRefAttrListPtr aRefAttrListAttr =
41 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(theAttribute);
42 mySelectionCount = aRefAttrListAttr->size();
45 myObject = ModuleBase_Tools::getObject(theAttribute);
46 myShape = ModuleBase_Tools::getShape(theAttribute, theWorkshop);
47 myRefAttribute = AttributePtr();
49 AttributeRefAttrPtr aRefAttr =
50 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
52 myIsObject = aRefAttr->isObject();
53 myRefAttribute = aRefAttr->attr();
58 //********************************************************************
59 void ModuleBase_WidgetSelectorStore::restoreAttributeValue(const AttributePtr& theAttribute,
60 ModuleBase_IWorkshop* theWorkshop)
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();
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();
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();
89 ModuleBase_Tools::setObject(theAttribute, myObject, myShape, theWorkshop, true, true);
90 AttributeRefAttrPtr aRefAttr =
91 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
94 aRefAttr->setAttr(myRefAttribute);