1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2008-2015 EDF R&D
4 # This file is part of SALOME ADAO module
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.
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.
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
20 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 __author__="aribes/gboulant"
25 from daUtils.enumerate import Enumerate
27 from salome.kernel import studyedit
29 import adaoModuleHelper
32 # ==============================================================================
33 # Constant parameters and identifiers
34 # ==============================================================================
36 ADAO_ITEM_TYPES = Enumerate([
41 # ==============================================================================
42 # Function dedicated to the data management in the salome study
43 # ==============================================================================
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
52 def addInStudy(salomeStudyId, adaoCase):
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.
59 studyEditor = studyedit.getStudyEditor(salomeStudyId)
61 adaoRootEntry = studyEditor.findOrCreateComponent(
62 moduleName = adaoModuleHelper.componentName(),
63 componentName = adaoModuleHelper.componentUserName(),
64 icon = adaoModuleHelper.modulePixmap())
66 itemName = adaoCase.name
67 itemValue = adaoCase.filename
68 itemType = ADAO_ITEM_TYPES.ADAO_CASE
70 icon = adaoModuleHelper.studyItemPixmapNOk()
72 icon = adaoModuleHelper.studyItemPixmapOk()
74 salomeStudyItem = studyEditor.createItem(
75 adaoRootEntry, itemName,
80 return salomeStudyItem
82 def updateItem(salomeStudyId, salomeStudyItem, adaoCase):
84 studyEditor = studyedit.getStudyEditor(salomeStudyId)
86 if salomeStudyItem.GetName()[:-2] != adaoCase.name:
87 itemName = adaoCase.name
88 itemValue = adaoCase.filename
90 itemName = salomeStudyItem.GetName()
91 itemValue = adaoCase.filename
93 icon = adaoModuleHelper.studyItemPixmapNOk()
95 icon = adaoModuleHelper.studyItemPixmapOk()
97 studyEditor.setItem(salomeStudyItem,
102 def removeItem(salomeStudyId, item):
104 Remove the item from the specified study.
106 studyEditor = studyedit.getStudyEditor(salomeStudyId)
107 return studyEditor.removeItem(item,True)
110 def isValidAdaoCaseItem(salomeStudyId,item):
112 Return true if the specified item corresponds to a valid adaoCase
117 studyEditor = studyedit.getStudyEditor(salomeStudyId)
118 itemType = studyEditor.getTypeId(item)
119 if itemType != ADAO_ITEM_TYPES.ADAO_CASE: