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