Salome HOME
DATASSIM to ADAO
[modules/adao.git] / src / daSalome / daGUI / daGuiImpl / adaoStudyEditor.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 adaoModuleHelper
26 from daGuiImpl.adaoCase import AdaoCase
27
28 #
29 # ==============================================================================
30 # Constant parameters and identifiers
31 # ==============================================================================
32 #
33 ADAO_ITEM_TYPES = Enumerate([
34     "ADAO_CASE",
35 ])
36
37 #
38 # ==============================================================================
39 # Function dedicated to the data management in the salome study
40 # ==============================================================================
41
42 # For developpers, note that the data structures used here are:
43 # - the SALOME study whose API is defined by SALOMEDS::Study
44 # - an item in a study whose API is defined by SALOMEDS:SObject
45 # - a study component, whose API is defined by SALOMEDS::SComponent
46 #   a SComponent is a reference in a study toward a SALOME component
47 #
48
49 def addInStudy(salomeStudyId, adaoCase):
50     """
51     This function adds in the specified SALOME study a study entry that corresponds
52     to the specified adao case. This study case is put in a folder under
53     the ADAO component and is identified by the case name.
54     """
55
56     studyEditor = studyedit.getStudyEditor(salomeStudyId)
57
58     adaoRootEntry = studyEditor.findOrCreateComponent(
59         engineName    = adaoModuleHelper.componentName(),
60         componentName = adaoModuleHelper.componentUserName())
61
62     itemName  = adaoCase.get_name()
63     itemValue = str(adaoCase.get_filename())
64     itemType  = ADAO_ITEM_TYPES.ADAO_CASE
65
66     salomeStudyItem = studyEditor.createItem(
67         adaoRootEntry, itemName,
68         comment = itemValue,
69         typeId  = itemType)
70     # _MEM_ Note that we use the comment attribute to store the serialize
71     # description of the data.
72
73     return salomeStudyItem
74
75 def updateItem(salomeStudyId, salomeStudyItem, adaoCase):
76
77     studyEditor = studyedit.getStudyEditor(salomeStudyId)
78     
79     if salomeStudyItem.GetName()[:-2] != adaoCase.get_name():
80       itemName  = adaoCase.get_name()
81       itemValue = adaoCase.get_filename()
82     else:
83       itemName  = salomeStudyItem.GetName()
84       itemValue = adaoCase.get_filename()
85
86     studyEditor.setItem(salomeStudyItem,
87         name    = itemName,
88         comment = itemValue)
89
90 def removeItem(salomeStudyId, item):
91     """
92     Remove the item from the specified study.
93     """
94     studyEditor = studyedit.getStudyEditor(salomeStudyId)
95     return studyEditor.removeItem(item,True)
96
97
98 def isValidAdaoCaseItem(salomeStudyId,item):
99     """
100     Return true if the specified item corresponds to a valid adaoCase
101     """
102     if item is None:
103         return False
104
105     studyEditor = studyedit.getStudyEditor(salomeStudyId)
106     itemType = studyEditor.getTypeId(item)
107     if itemType != ADAO_ITEM_TYPES.ADAO_CASE:
108         return False
109
110     return True