Salome HOME
Merge commit 'refs/merge-requests/11' of git://cli70rw.der.edf.fr/adao/adao into...
[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 daUtils.enumerate import Enumerate
24
25 from salome.kernel import studyedit
26
27 import adaoModuleHelper
28
29 #
30 # ==============================================================================
31 # Constant parameters and identifiers
32 # ==============================================================================
33 #
34 ADAO_ITEM_TYPES = Enumerate([
35     "ADAO_CASE",
36 ])
37
38 #
39 # ==============================================================================
40 # Function dedicated to the data management in the salome study
41 # ==============================================================================
42
43 # For developpers, note that the data structures used here are:
44 # - the SALOME study whose API is defined by SALOMEDS::Study
45 # - an item in a study whose API is defined by SALOMEDS:SObject
46 # - a study component, whose API is defined by SALOMEDS::SComponent
47 #   a SComponent is a reference in a study toward a SALOME component
48 #
49
50 def addInStudy(salomeStudyId, adaoCase):
51     """
52     This function adds in the specified SALOME study a study entry that corresponds
53     to the specified adao case. This study case is put in a folder under
54     the ADAO component and is identified by the case name.
55     """
56
57     studyEditor = studyedit.getStudyEditor(salomeStudyId)
58
59     adaoRootEntry = studyEditor.findOrCreateComponent(
60         moduleName    = adaoModuleHelper.componentName(),
61         componentName = adaoModuleHelper.componentUserName(),
62         icon          = adaoModuleHelper.modulePixmap())
63
64     itemName  = adaoCase.name
65     itemValue = adaoCase.filename
66     itemType  = ADAO_ITEM_TYPES.ADAO_CASE
67
68     icon = adaoModuleHelper.studyItemPixmapNOk()
69     if adaoCase.isOk():
70       icon = adaoModuleHelper.studyItemPixmapOk()
71
72     salomeStudyItem = studyEditor.createItem(
73         adaoRootEntry, itemName,
74         comment = itemValue,
75         typeId  = itemType,
76         icon    = icon)
77
78     return salomeStudyItem
79
80 def updateItem(salomeStudyId, salomeStudyItem, adaoCase):
81
82     studyEditor = studyedit.getStudyEditor(salomeStudyId)
83
84     if salomeStudyItem.GetName()[:-2] != adaoCase.name:
85       itemName  = adaoCase.name
86       itemValue = adaoCase.filename
87     else:
88       itemName  = salomeStudyItem.GetName()
89       itemValue = adaoCase.filename
90
91     icon = adaoModuleHelper.studyItemPixmapNOk()
92     if adaoCase.isOk():
93       icon = adaoModuleHelper.studyItemPixmapOk()
94
95     studyEditor.setItem(salomeStudyItem,
96         name    = itemName,
97         comment = itemValue,
98         icon    = icon)
99
100 def removeItem(salomeStudyId, item):
101     """
102     Remove the item from the specified study.
103     """
104     studyEditor = studyedit.getStudyEditor(salomeStudyId)
105     return studyEditor.removeItem(item,True)
106
107
108 def isValidAdaoCaseItem(salomeStudyId,item):
109     """
110     Return true if the specified item corresponds to a valid adaoCase
111     """
112     if item is None:
113         return False
114
115     studyEditor = studyedit.getStudyEditor(salomeStudyId)
116     itemType = studyEditor.getTypeId(item)
117     if itemType != ADAO_ITEM_TYPES.ADAO_CASE:
118         return False
119
120     return True