1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
4 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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
23 # File : batchmode_smesh.py
24 # Author : Oksana TCHEBANOVA
28 from batchmode_salome import *
29 from batchmode_geompy import ShapeType
32 #--------------------------------------------------------------------------
33 modulecatalog = naming_service.Resolve("/Kernel/ModulCatalog")
35 smesh = lcc.FindOrLoadComponent("FactoryServer", "SMESH")
36 myStudyBuilder = myStudy.NewBuilder()
38 if myStudyBuilder is None:
39 raise RuntimeError, " Null myStudyBuilder"
41 father = myStudy.FindComponent("SMESH")
43 father = myStudyBuilder.NewComponent("SMESH")
44 FName = myStudyBuilder.FindOrCreateAttribute(father, "AttributeName")
45 Comp = modulecatalog.GetComponent("SMESH")
46 FName.SetValue(Comp._get_componentusername())
47 aPixmap = myStudyBuilder.FindOrCreateAttribute(father, "AttributePixMap")
48 aPixmap.SetPixMap("ICON_OBJBROWSER_Mesh")
50 myStudyBuilder.DefineComponentInstance(father,smesh)
52 mySComponentMesh = father._narrow(SALOMEDS.SComponent)
54 Tag_HypothesisRoot = 1
55 Tag_AlgorithmsRoot = 2
58 Tag_RefOnAppliedHypothesis = 2
59 Tag_RefOnAppliedAlgorithms = 3
61 Tag_SubMeshOnVertex = 4
64 Tag_SubMeshOnSolid = 7
65 Tag_SubMeshOnCompound = 8
67 Tag = {"HypothesisRoot":1,"AlgorithmsRoot":2,"RefOnShape":1,"RefOnAppliedHypothesis":2,"RefOnAppliedAlgorithms":3,"SubMeshOnVertex":4,"SubMeshOnEdge":5,"SubMeshOnFace":6,"SubMeshOnSolid":7,"SubMeshOnCompound":8}
69 #------------------------------------------------------------
72 #------------------------------------------------------------
74 # VSR: added temporarily - objects are published automatically by the engine
75 aSO = myStudy.FindObjectIOR( IOR )
78 # VSR ######################################################################
80 res,HypothesisRoot = mySComponentMesh.FindSubObject ( Tag_HypothesisRoot )
81 if HypothesisRoot is None or res == 0:
82 HypothesisRoot = myStudyBuilder.NewObjectToTag(mySComponentMesh, Tag_HypothesisRoot)
83 aName = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributeName")
84 aName.SetValue("Hypotheses")
85 aPixmap = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributePixMap")
86 aPixmap.SetPixMap( "mesh_tree_hypo.png" )
87 aSelAttr = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributeSelectable")
88 aSelAttr.SetSelectable(0)
90 res, AlgorithmsRoot = mySComponentMesh.FindSubObject (Tag_AlgorithmsRoot)
91 if AlgorithmsRoot is None or res == 0:
92 AlgorithmsRoot = myStudyBuilder.NewObjectToTag (mySComponentMesh, Tag_AlgorithmsRoot)
93 aName = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributeName")
94 aName.SetValue("Algorithms")
95 aPixmap = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributePixMap")
96 aPixmap.SetPixMap( "mesh_tree_algo.png" )
97 aSelAttr = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributeSelectable")
98 aSelAttr.SetSelectable(0)
100 HypothesisRoot = HypothesisRoot._narrow(SALOMEDS.SObject)
101 newMesh = myStudyBuilder.NewObject(mySComponentMesh)
102 aPixmap = myStudyBuilder.FindOrCreateAttribute(newMesh, "AttributePixMap")
103 aPixmap.SetPixMap( "mesh_tree_mesh.png" )
104 anIOR = myStudyBuilder.FindOrCreateAttribute(newMesh, "AttributeIOR")
106 return newMesh.GetID()
108 #------------------------------------------------------------
109 def AddNewHypothesis(IOR):
110 # VSR: added temporarily - objects are published automatically by the engine
111 aSO = myStudy.FindObjectIOR( IOR )
114 # VSR ######################################################################
116 res, HypothesisRoot = mySComponentMesh.FindSubObject (Tag_HypothesisRoot)
117 if HypothesisRoot is None or res == 0:
118 HypothesisRoot = myStudyBuilder.NewObjectToTag (mySComponentMesh, Tag_HypothesisRoot)
119 aName = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributeName")
120 aName.SetValue("Hypotheses")
121 aSelAttr = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributeSelectable")
122 aSelAttr.SetSelectable(0)
123 aPixmap = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributePixMap")
124 aPixmap.SetPixMap( "mesh_tree_hypo.png" )
127 newHypo = myStudyBuilder.NewObject(HypothesisRoot)
128 aPixmap = myStudyBuilder.FindOrCreateAttribute(newHypo, "AttributePixMap")
129 H = orb.string_to_object(IOR)
131 aPixmap.SetPixMap( "mesh_tree_hypo.png_" + aType )
132 anIOR = myStudyBuilder.FindOrCreateAttribute(newHypo, "AttributeIOR")
134 return newHypo.GetID()
136 #------------------------------------------------------------
137 def AddNewAlgorithms(IOR):
138 # VSR: added temporarily - objects are published automatically by the engine
139 aSO = myStudy.FindObjectIOR( IOR )
142 # VSR ######################################################################
144 res, AlgorithmsRoot = mySComponentMesh.FindSubObject (Tag_AlgorithmsRoot)
145 if AlgorithmsRoot is None or res == 0:
146 AlgorithmsRoot = myStudyBuilde.NewObjectToTag (mySComponentMesh, Tag_AlgorithmsRoot)
147 aName = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributeName")
148 aName.SetValue("Algorithms")
149 aSelAttr = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributeSelectable")
150 aSelAttr.SetSelectable(0)
151 aPixmap = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributePixMap")
152 aPixmap.SetPixMap( "mesh_tree_algo.png" )
155 newHypo = myStudyBuilder.NewObject(AlgorithmsRoot)
156 aPixmap = myStudyBuilder.FindOrCreateAttribute(newHypo, "AttributePixMap")
157 aPixmap = anAttr._narrow(SALOMEDS.AttributePixMap)
158 H = orb.string_to_object(IOR)
159 aType = H.GetName(); #QString in fact
160 aPixmap.SetPixMap( "mesh_tree_algo.png_" + aType )
161 anIOR = myStudyBuilder.FindOrCreateAttribute(newHypo, "AttributeIOR")
163 return newHypo.GetID()
166 #------------------------------------------------------------
167 def SetShape(ShapeEntry, MeshEntry):
168 SO_MorSM = myStudy.FindObjectID( MeshEntry )
169 SO_GeomShape = myStudy.FindObjectID( ShapeEntry )
171 if SO_MorSM is not None and SO_GeomShape is not None :
172 # VSR: added temporarily - shape reference is published automatically by the engine
173 res, Ref = SO_MorSM.FindSubObject( Tag_RefOnShape )
176 # VSR ######################################################################
178 SO = myStudyBuilder.NewObjectToTag (SO_MorSM, Tag_RefOnShape)
179 myStudyBuilder.Addreference (SO,SO_GeomShape)
182 #------------------------------------------------------------
183 def SetHypothesis(Mesh_Or_SubMesh_Entry, Hypothesis_Entry):
184 SO_MorSM = myStudy.FindObjectID( Mesh_Or_SubMesh_Entry )
185 SO_Hypothesis = myStudy.FindObjectID( Hypothesis_Entry )
187 if SO_MorSM is not None and SO_Hypothesis is not None :
189 #Find or Create Applied Hypothesis root
190 res, AHR = SO_MorSM.FindSubObject (Tag_RefOnAppliedHypothesis)
191 if AHR is None or res == 0:
192 AHR = myStudyBuilder.NewObjectToTag (SO_MorSM, Tag_RefOnAppliedHypothesis)
193 aName = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributeName")
195 # The same name as in SMESH_Mesh_i::AddHypothesis() ##################
196 aName.SetValue("Applied hypotheses")
198 aSelAttr = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributeSelectable")
199 aSelAttr.SetSelectable(0)
200 aPixmap = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributePixMap")
201 aPixmap.SetPixMap( "mesh_tree_hypo.png" )
203 # VSR: added temporarily - reference to applied hypothesis is published automatically by the engine
205 it = myStudy.NewChildIterator(AHR)
207 res, Ref = it.Value().ReferencedObject()
208 if res and Ref is not None and Ref.GetID() == Hypothesis_Entry :
211 # VSR ######################################################################
213 SO = myStudyBuilder.NewObject(AHR)
214 myStudyBuilder.Addreference (SO,SO_Hypothesis)
216 #------------------------------------------------------------
217 def SetAlgorithms(Mesh_Or_SubMesh_Entry, Algorithms_Entry):
218 SO_MorSM = myStudy.FindObjectID( Mesh_Or_SubMesh_Entry )
219 SO_Algorithms = myStudy.FindObjectID( Algorithms_Entry )
220 if SO_MorSM != None and SO_Algorithms != None :
221 #Find or Create Applied Algorithms root
222 res, AHR = SO_MorSM.FindSubObject (Tag_RefOnAppliedAlgorithms)
223 if AHR is None or res == 0:
224 AHR = myStudyBuilder.NewObjectToTag (SO_MorSM, Tag_RefOnAppliedAlgorithms)
225 aName = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributeName")
227 # The same name as in SMESH_Mesh_i::AddHypothesis() ##################
228 aName.SetValue("Applied algorithms")
230 aSelAttr = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributeSelectable")
231 aSelAttr.SetSelectable(0)
232 aPixmap = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributePixMap")
233 aPixmap.SetPixMap( "mesh_tree_algo.png" )
235 # VSR: added temporarily - reference to applied hypothesis is published automatically by the engine
237 it = myStudy.NewChildIterator(AHR)
239 res, Ref = it.Value().ReferencedObject()
240 if res and Ref is not None and Ref.GetID() == Algorithms_Entry :
243 # VSR ######################################################################
245 SO = myStudyBuilder.NewObject(AHR)
246 myStudyBuilder.Addreference (SO,SO_Algorithms)
249 #------------------------------------------------------------
250 def UnSetHypothesis( Applied_Hypothesis_Entry ):
251 SO_Applied_Hypothesis = myStudy.FindObjectID( Applied_Hypothesis_Entry )
252 if SO_Applied_Hypothesis :
253 myStudyBuilder.RemoveObject(SO_Applied_Hypothesis)
256 #------------------------------------------------------------
257 def AddSubMesh ( SO_Mesh_Entry, SM_IOR, ST):
258 # VSR: added temporarily - objects are published automatically by the engine
259 aSO = myStudy.FindObjectIOR( SM_IOR )
262 # VSR ######################################################################
264 SO_Mesh = myStudy.FindObjectID( SO_Mesh_Entry )
267 if ST == ShapeType["COMPSOLID"] :
268 Tag_Shape = Tag_SubMeshOnSolid
269 Name = "SubMeshes on Solid"
270 elif ST == ShapeType["FACE"] :
271 Tag_Shape = Tag_SubMeshOnFace
272 Name = "SubMeshes on Face"
273 elif ST == ShapeType["EDGE"] :
274 Tag_Shape = Tag_SubMeshOnEdge
275 Name = "SubMeshes on Edge"
276 elif ST == ShapeType["VERTEX"] :
277 Tag_Shape = Tag_SubMeshOnVertex
278 Name = "SubMeshes on Vertex"
280 Tag_Shape = Tag_SubMeshOnCompound
281 Name = "SubMeshes on Compound"
283 res, SubmeshesRoot = SO_Mesh.FindSubObject (Tag_Shape)
284 if SubmeshesRoot is None or res == 0:
285 SubmeshesRoot = myStudyBuilder.NewObjectToTag (SO_Mesh, Tag_Shape)
286 aName = myStudyBuilder.FindOrCreateAttribute(SubmeshesRoot, "AttributeName")
288 aSelAttr = myStudyBuilder.FindOrCreateAttribute(SubmeshesRoot, "AttributeSelectable")
289 aSelAttr.SetSelectable(0)
291 SO = myStudyBuilder.NewObject (SubmeshesRoot)
292 anIOR = myStudyBuilder.FindOrCreateAttribute(SO, "AttributeIOR")
293 anIOR.SetValue(SM_IOR)
298 #------------------------------------------------------------
299 def AddSubMeshOnShape (Mesh_Entry, GeomShape_Entry, SM_IOR, ST) :
300 # VSR: added temporarily - objects are published automatically by the engine
301 aSO = myStudy.FindObjectIOR( SM_IOR )
304 # VSR ######################################################################
305 SO_GeomShape = myStudy.FindObjectID( GeomShape_Entry )
306 if SO_GeomShape != None :
307 SM_Entry = AddSubMesh (Mesh_Entry,SM_IOR,ST)
308 SO_SM = myStudy.FindObjectID( SM_Entry )
311 SetShape (GeomShape_Entry, SM_Entry)
317 #------------------------------------------------------------
318 def SetName(Entry, Name):
319 SO = myStudy.FindObjectID( Entry )
321 aName = myStudyBuilder.FindOrCreateAttribute(SO, "AttributeName")