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