1 # -*- coding: utf-8 -*-
3 # Copyright (C) 2008-2024 EDF R&D
5 # This file is part of SALOME ADAO module
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.
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.
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
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 __author__="aribes/gboulant"
26 from daUtils.enumerate import Enumerate
28 from salome.kernel import studyedit
30 from . import adaoModuleHelper
33 # ==============================================================================
34 # Constant parameters and identifiers
35 # ==============================================================================
37 ADAO_ITEM_TYPES = Enumerate([
42 # ==============================================================================
43 # Function dedicated to the data management in the salome study
44 # ==============================================================================
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
53 def addInStudy(adaoCase): # salomeStudyId, adaoCase):
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.
60 studyEditor = studyedit.getStudyEditor() # salomeStudyId)
62 adaoRootEntry = studyEditor.findOrCreateComponent(
63 moduleName = adaoModuleHelper.componentName(),
64 componentName = adaoModuleHelper.componentUserName(),
65 icon = adaoModuleHelper.modulePixmap())
67 itemName = adaoCase.name
68 itemValue = adaoCase.filename
69 itemType = ADAO_ITEM_TYPES.ADAO_CASE
71 icon = adaoModuleHelper.studyItemPixmapNOk()
73 icon = adaoModuleHelper.studyItemPixmapOk()
75 salomeStudyItem = studyEditor.createItem(
76 adaoRootEntry, itemName,
81 return salomeStudyItem
83 def updateItem(salomeStudyItem, adaoCase): # salomeStudyId, salomeStudyItem, adaoCase):
85 studyEditor = studyedit.getStudyEditor() # salomeStudyId)
87 if salomeStudyItem.GetName()[:-2] != adaoCase.name:
88 itemName = adaoCase.name
89 itemValue = adaoCase.filename
91 itemName = salomeStudyItem.GetName()
92 itemValue = adaoCase.filename
94 icon = adaoModuleHelper.studyItemPixmapNOk()
96 icon = adaoModuleHelper.studyItemPixmapOk()
98 studyEditor.setItem(salomeStudyItem,
103 def removeItem(item): # salomeStudyId, item):
105 Remove the item from the specified study.
107 studyEditor = studyedit.getStudyEditor() # salomeStudyId)
108 return studyEditor.removeItem(item,True)
111 def isValidAdaoCaseItem(item): # salomeStudyId,item):
113 Return true if the specified item corresponds to a valid adaoCase
118 studyEditor = studyedit.getStudyEditor() # salomeStudyId)
119 itemType = studyEditor.getTypeId(item)
120 if itemType != ADAO_ITEM_TYPES.ADAO_CASE: