1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2010 EDF R&D
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 __author__="aribes/gboulant"
23 from enumerate import Enumerate
25 import datassimModuleHelper
28 # ==============================================================================
29 # Constant parameters and identifiers
30 # ==============================================================================
32 DATASSIM_ITEM_TYPES = Enumerate([
37 # ==============================================================================
38 # Function dedicated to the data management in the salome study
39 # ==============================================================================
41 # For developpers, note that the data structures used here are:
42 # - the SALOME study whose API is defined by SALOMEDS::Study
43 # - an item in a study whose API is defined by SALOMEDS:SObject
44 # - a study component, whose API is defined by SALOMEDS::SComponent
45 # a SComponent is a reference in a study toward a SALOME component
48 def addInStudy(salomeStudyId, datassimCase):
50 This function adds in the specified SALOME study a study entry that corresponds
51 to the specified datassim case. This study case is put in a folder under
52 the DATASSIM component and is identified by the case name.
55 studyEditor = studyedit.getStudyEditor(salomeStudyId)
57 datassimRootEntry = studyEditor.findOrCreateComponent(
58 engineName = datassimModuleHelper.componentName(),
59 componentName = datassimModuleHelper.componentUserName())
61 itemName = datassimCase
63 itemType = DATASSIM_ITEM_TYPES.DATASSIM_CASE
65 salomeStudyItem = studyEditor.createItem(
66 datassimRootEntry, itemName,
69 # _MEM_ Note that we use the comment attribute to store the serialize
70 # description of the data.
72 return salomeStudyItem
74 def updateItem(salomeStudyId, salomeStudyItem, datassimCase):
76 studyEditor = studyedit.getStudyEditor(salomeStudyId)
78 itemName = datassimCase
81 studyEditor.setItem(salomeStudyItem,
85 def removeItem(salomeStudyId, item):
87 Remove the item from the specified study.
89 if not isValidDatassimCaseItem(salomeStudyId, item):
91 studyEditor = studyedit.getStudyEditor(salomeStudyId)
92 return studyEditor.removeItem(item,True)
95 def isValidDatassimCaseItem(salomeStudyId,item):
97 Return true if the specified item corresponds to a valid datassimCase
102 studyEditor = studyedit.getStudyEditor(salomeStudyId)
103 itemType = studyEditor.getTypeId(item)
104 if itemType != DATASSIM_ITEM_TYPES.DATASSIM_CASE:
110 def getDatassimCaseFromItem(salomeStudyId, item):
112 Get the datassim case from the selected item.
113 Note that the study must be specify to retrieve the attributes value from
114 the item reference. The attribute values are stored in the study object.
116 if not isValidDatassimCaseItem(salomeStudyId, item):
119 itemName = item.GetName()
120 itemValue = item.GetComment()