Salome HOME
42eac25c7b6728cce226d204a710a992cafea968
[modules/adao.git] / src / daSalome / daGUI / daGuiImpl / datassimStudyEditor.py
1 # -*- coding: iso-8859-1 -*-
2 #  Copyright (C) 2010 EDF R&D
3 #
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.
8 #
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.
13 #
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
17 #
18 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 __author__="aribes/gboulant"
22
23 from enumerate import Enumerate
24 import studyedit
25 import datassimModuleHelper
26
27 #
28 # ==============================================================================
29 # Constant parameters and identifiers
30 # ==============================================================================
31 #
32 DATASSIM_ITEM_TYPES = Enumerate([
33     "DATASSIM_CASE",
34 ])
35
36 #
37 # ==============================================================================
38 # Function dedicated to the data management in the salome study
39 # ==============================================================================
40
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
46 #
47
48 def addInStudy(salomeStudyId, datassimCase):
49     """
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.
53     """
54
55     studyEditor = studyedit.getStudyEditor(salomeStudyId)
56
57     datassimRootEntry = studyEditor.findOrCreateComponent(
58         engineName    = datassimModuleHelper.componentName(),
59         componentName = datassimModuleHelper.componentUserName())
60
61     itemName  = datassimCase
62     itemValue = ""
63     itemType  = DATASSIM_ITEM_TYPES.DATASSIM_CASE
64
65     salomeStudyItem = studyEditor.createItem(
66         datassimRootEntry, itemName,
67         comment = itemValue,
68         typeId  = itemType)
69     # _MEM_ Note that we use the comment attribute to store the serialize
70     # description of the data.
71
72     return salomeStudyItem
73
74 def updateItem(salomeStudyId, salomeStudyItem, datassimCase):
75
76     studyEditor = studyedit.getStudyEditor(salomeStudyId)
77     
78     itemName  = datassimCase
79     itemValue = ""
80
81     studyEditor.setItem(salomeStudyItem,
82         name    = itemName,
83         comment = itemValue)
84
85 def removeItem(salomeStudyId, item):
86     """
87     Remove the item from the specified study.
88     """
89     if not isValidDatassimCaseItem(salomeStudyId, item):
90         return False
91     studyEditor = studyedit.getStudyEditor(salomeStudyId)
92     return studyEditor.removeItem(item,True)
93
94
95 def isValidDatassimCaseItem(salomeStudyId,item):
96     """
97     Return true if the specified item corresponds to a valid datassimCase
98     """
99     if item is None:
100         return False
101
102     studyEditor = studyedit.getStudyEditor(salomeStudyId)
103     itemType = studyEditor.getTypeId(item)
104     if itemType != DATASSIM_ITEM_TYPES.DATASSIM_CASE:
105         return False
106
107     return True
108
109
110 def getDatassimCaseFromItem(salomeStudyId, item):
111     """
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.
115     """
116     if not isValidDatassimCaseItem(salomeStudyId, item):
117         return None
118
119     itemName  = item.GetName()
120     itemValue = item.GetComment()
121     return itemName
122