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 = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
51 myIsObject = aRefAttr->isObject();
52 myRefAttribute = aRefAttr->attr();
57 //********************************************************************
58 void ModuleBase_WidgetSelectorStore::restoreAttributeValue(const AttributePtr& theAttribute,
59 ModuleBase_IWorkshop* theWorkshop)
61 std::string aType = theAttribute->attributeType();
62 if (aType == ModelAPI_AttributeSelectionList::typeId()) {
63 AttributeSelectionListPtr aSelectionListAttr =
64 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
65 aSelectionListAttr->setSelectionType(mySelectionType);
66 // restore selection in the attribute. Indeed there is only one stored object
67 int aCountAppened = aSelectionListAttr->size() - mySelectionCount;
68 for (int i = 0; i < aCountAppened; i++)
69 aSelectionListAttr->removeLast();
71 else if (aType == ModelAPI_AttributeRefList::typeId()) {
72 AttributeRefListPtr aRefListAttr =
73 std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
74 // restore objects in the attribute. Indeed there is only one stored object
75 int aCountAppened = aRefListAttr->size() - mySelectionCount;
76 for (int i = 0; i < aCountAppened; i++)
77 aRefListAttr->removeLast();
79 else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
80 AttributeRefAttrListPtr aRefAttrListAttr =
81 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(theAttribute);
82 // restore objects in the attribute. Indeed there is only one stored object
83 int aCountAppened = aRefAttrListAttr->size() - mySelectionCount;
84 for (int i = 0; i < aCountAppened; i++)
85 aRefAttrListAttr->removeLast();
88 ModuleBase_Tools::setObject(theAttribute, myObject, myShape, theWorkshop, true);
89 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
92 aRefAttr->setAttr(myRefAttribute);