]> SALOME platform Git repositories - modules/adao.git/blob - src/daSalome/daGUI/daGuiImpl/adaoStudyEditor.py
Salome HOME
Correction for Qt5/Eficas/Adao/Salome embedded frames compatibility
[modules/adao.git] / src / daSalome / daGUI / daGuiImpl / adaoStudyEditor.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2008-2016 EDF R&D
3 #
4 # This file is part of SALOME ADAO module
5 #
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License.
10 #
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 # Lesser General Public License for more details.
15 #
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 #
20 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #
22
23 __author__="aribes/gboulant"
24
25 from daUtils.enumerate import Enumerate
26
27 from salome.kernel import studyedit
28
29 import adaoModuleHelper
30
31 #
32 # ==============================================================================
33 # Constant parameters and identifiers
34 # ==============================================================================
35 #
36 ADAO_ITEM_TYPES = Enumerate([
37     "ADAO_CASE",
38 ])
39
40 #
41 # ==============================================================================
42 # Function dedicated to the data management in the salome study
43 # ==============================================================================
44
45 # For developpers, note that the data structures used here are:
46 # - the SALOME study whose API is defined by SALOMEDS::Study
47 # - an item in a study whose API is defined by SALOMEDS:SObject
48 # - a study component, whose API is defined by SALOMEDS::SComponent
49 #   a SComponent is a reference in a study toward a SALOME component
50 #
51
52 def addInStudy(salomeStudyId, adaoCase):
53     """
54     This function adds in the specified SALOME study a study entry that corresponds
55     to the specified adao case. This study case is put in a folder under
56     the ADAO component and is identified by the case name.
57     """
58
59     studyEditor = studyedit.getStudyEditor(salomeStudyId)
60
61     adaoRootEntry = studyEditor.findOrCreateComponent(
62         moduleName    = adaoModuleHelper.componentName(),
63         componentName = adaoModuleHelper.componentUserName(),
64         icon          = adaoModuleHelper.modulePixmap())
65
66     itemName  = adaoCase.name
67     itemValue = adaoCase.filename
68     itemType  = ADAO_ITEM_TYPES.ADAO_CASE
69
70     icon = adaoModuleHelper.studyItemPixmapNOk()
71     if adaoCase.isOk():
72       icon = adaoModuleHelper.studyItemPixmapOk()
73
74     salomeStudyItem = studyEditor.createItem(
75         adaoRootEntry, itemName,
76         comment = itemValue,
77         typeId  = itemType,
78         icon    = icon)
79
80     return salomeStudyItem
81
82 def updateItem(salomeStudyId, salomeStudyItem, adaoCase):
83
84     studyEditor = studyedit.getStudyEditor(salomeStudyId)
85
86     if salomeStudyItem.GetName()[:-2] != adaoCase.name:
87       itemName  = adaoCase.name
88       itemValue = adaoCase.filename
89     else:
90       itemName  = salomeStudyItem.GetName()
91       itemValue = adaoCase.filename
92
93     icon = adaoModuleHelper.studyItemPixmapNOk()
94     if adaoCase.isOk():
95       icon = adaoModuleHelper.studyItemPixmapOk()
96
97     studyEditor.setItem(salomeStudyItem,
98         name    = itemName,
99         comment = itemValue,
100         icon    = icon)
101
102 def removeItem(salomeStudyId, item):
103     """
104     Remove the item from the specified study.
105     """
106     studyEditor = studyedit.getStudyEditor(salomeStudyId)
107     return studyEditor.removeItem(item,True)
108
109
110 def isValidAdaoCaseItem(salomeStudyId,item):
111     """
112     Return true if the specified item corresponds to a valid adaoCase
113     """
114     if item is None:
115         return False
116
117     studyEditor = studyedit.getStudyEditor(salomeStudyId)
118     itemType = studyEditor.getTypeId(item)
119     if itemType != ADAO_ITEM_TYPES.ADAO_CASE:
120         return False
121
122     return True