1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include <ModuleBase_WidgetSelectorStore.h>
21 #include <ModuleBase_Tools.h>
22 #include <ModuleBase_IWorkshop.h>
24 #include <ModelAPI_AttributeRefAttr.h>
25 #include <ModelAPI_AttributeSelectionList.h>
26 #include <ModelAPI_AttributeRefList.h>
27 #include <ModelAPI_AttributeRefAttrList.h>
29 ModuleBase_WidgetSelectorStore::ModuleBase_WidgetSelectorStore()
30 : myIsObject(false), mySelectionType(""), mySelectionCount(0)
34 void ModuleBase_WidgetSelectorStore::storeAttributeValue(const AttributePtr& theAttribute,
35 ModuleBase_IWorkshop* theWorkshop)
37 if (!theAttribute.get())
40 std::string aType = theAttribute->attributeType();
41 if (aType == ModelAPI_AttributeSelectionList::typeId()) {
42 AttributeSelectionListPtr aSelectionListAttr =
43 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
44 mySelectionType = aSelectionListAttr->selectionType();
45 mySelectionCount = aSelectionListAttr->size();
47 else if (aType == ModelAPI_AttributeRefList::typeId()) {
48 AttributeRefListPtr aRefListAttr =
49 std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
50 mySelectionCount = aRefListAttr->size();
52 else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
53 AttributeRefAttrListPtr aRefAttrListAttr =
54 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(theAttribute);
55 mySelectionCount = aRefAttrListAttr->size();
58 myObject = ModuleBase_Tools::getObject(theAttribute);
59 myShape = ModuleBase_Tools::getShape(theAttribute, theWorkshop);
60 myRefAttribute = AttributePtr();
62 AttributeRefAttrPtr aRefAttr =
63 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
65 myIsObject = aRefAttr->isObject();
66 myRefAttribute = aRefAttr->attr();
71 //********************************************************************
72 void ModuleBase_WidgetSelectorStore::restoreAttributeValue(const AttributePtr& theAttribute,
73 ModuleBase_IWorkshop* theWorkshop)
75 std::string aType = theAttribute->attributeType();
76 if (aType == ModelAPI_AttributeSelectionList::typeId()) {
77 AttributeSelectionListPtr aSelectionListAttr =
78 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
79 aSelectionListAttr->setSelectionType(mySelectionType);
80 // restore selection in the attribute. Indeed there is only one stored object
81 int aCountAppened = aSelectionListAttr->size() - mySelectionCount;
82 for (int i = 0; i < aCountAppened; i++)
83 aSelectionListAttr->removeLast();
85 else if (aType == ModelAPI_AttributeRefList::typeId()) {
86 AttributeRefListPtr aRefListAttr =
87 std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
88 // restore objects in the attribute. Indeed there is only one stored object
89 int aCountAppened = aRefListAttr->size() - mySelectionCount;
90 for (int i = 0; i < aCountAppened; i++)
91 aRefListAttr->removeLast();
93 else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
94 AttributeRefAttrListPtr aRefAttrListAttr =
95 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(theAttribute);
96 // restore objects in the attribute. Indeed there is only one stored object
97 int aCountAppened = aRefAttrListAttr->size() - mySelectionCount;
98 for (int i = 0; i < aCountAppened; i++)
99 aRefAttrListAttr->removeLast();
102 ModuleBase_Tools::setObject(theAttribute, myObject, myShape, theWorkshop, true, true);
103 AttributeRefAttrPtr aRefAttr =
104 std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
107 aRefAttr->setAttr(myRefAttribute);