1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2011 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
24 # File : batchmode_smesh.py
25 # Author : Oksana TCHEBANOVA
29 from batchmode_salome import *
30 from batchmode_geompy import ShapeType
33 #--------------------------------------------------------------------------
34 modulecatalog = naming_service.Resolve("/Kernel/ModulCatalog")
36 smesh = lcc.FindOrLoadComponent("FactoryServer", "SMESH")
37 smesh.SetCurrentStudy(myStudy)
38 myStudyBuilder = myStudy.NewBuilder()
40 if myStudyBuilder is None:
41 raise RuntimeError, " Null myStudyBuilder"
43 father = myStudy.FindComponent("SMESH")
45 father = myStudyBuilder.NewComponent("SMESH")
46 FName = myStudyBuilder.FindOrCreateAttribute(father, "AttributeName")
47 Comp = modulecatalog.GetComponent("SMESH")
48 FName.SetValue(Comp._get_componentusername())
49 aPixmap = myStudyBuilder.FindOrCreateAttribute(father, "AttributePixMap")
50 aPixmap.SetPixMap("ICON_OBJBROWSER_Mesh")
52 myStudyBuilder.DefineComponentInstance(father,smesh)
54 mySComponentMesh = father._narrow(SALOMEDS.SComponent)
56 Tag_HypothesisRoot = 1
57 Tag_AlgorithmsRoot = 2
60 Tag_RefOnAppliedHypothesis = 2
61 Tag_RefOnAppliedAlgorithms = 3
63 Tag_SubMeshOnVertex = 4
66 Tag_SubMeshOnSolid = 7
67 Tag_SubMeshOnCompound = 8
69 Tag = {"HypothesisRoot":1,"AlgorithmsRoot":2,"RefOnShape":1,"RefOnAppliedHypothesis":2,"RefOnAppliedAlgorithms":3,"SubMeshOnVertex":4,"SubMeshOnEdge":5,"SubMeshOnFace":6,"SubMeshOnSolid":7,"SubMeshOnCompound":8}
71 #------------------------------------------------------------
74 #------------------------------------------------------------
76 # VSR: added temporarily - objects are published automatically by the engine
77 aSO = myStudy.FindObjectIOR( IOR )
80 # VSR ######################################################################
82 res,HypothesisRoot = mySComponentMesh.FindSubObject ( Tag_HypothesisRoot )
83 if HypothesisRoot is None or res == 0:
84 HypothesisRoot = myStudyBuilder.NewObjectToTag(mySComponentMesh, Tag_HypothesisRoot)
85 aName = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributeName")
86 aName.SetValue("Hypotheses")
87 aPixmap = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributePixMap")
88 aPixmap.SetPixMap( "mesh_tree_hypo.png" )
89 aSelAttr = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributeSelectable")
90 aSelAttr.SetSelectable(0)
92 res, AlgorithmsRoot = mySComponentMesh.FindSubObject (Tag_AlgorithmsRoot)
93 if AlgorithmsRoot is None or res == 0:
94 AlgorithmsRoot = myStudyBuilder.NewObjectToTag (mySComponentMesh, Tag_AlgorithmsRoot)
95 aName = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributeName")
96 aName.SetValue("Algorithms")
97 aPixmap = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributePixMap")
98 aPixmap.SetPixMap( "mesh_tree_algo.png" )
99 aSelAttr = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributeSelectable")
100 aSelAttr.SetSelectable(0)
102 HypothesisRoot = HypothesisRoot._narrow(SALOMEDS.SObject)
103 newMesh = myStudyBuilder.NewObject(mySComponentMesh)
104 aPixmap = myStudyBuilder.FindOrCreateAttribute(newMesh, "AttributePixMap")
105 aPixmap.SetPixMap( "mesh_tree_mesh.png" )
106 anIOR = myStudyBuilder.FindOrCreateAttribute(newMesh, "AttributeIOR")
108 return newMesh.GetID()
110 #------------------------------------------------------------
111 def AddNewHypothesis(IOR):
112 # VSR: added temporarily - objects are published automatically by the engine
113 aSO = myStudy.FindObjectIOR( IOR )
116 # VSR ######################################################################
118 res, HypothesisRoot = mySComponentMesh.FindSubObject (Tag_HypothesisRoot)
119 if HypothesisRoot is None or res == 0:
120 HypothesisRoot = myStudyBuilder.NewObjectToTag (mySComponentMesh, Tag_HypothesisRoot)
121 aName = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributeName")
122 aName.SetValue("Hypotheses")
123 aSelAttr = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributeSelectable")
124 aSelAttr.SetSelectable(0)
125 aPixmap = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributePixMap")
126 aPixmap.SetPixMap( "mesh_tree_hypo.png" )
129 newHypo = myStudyBuilder.NewObject(HypothesisRoot)
130 aPixmap = myStudyBuilder.FindOrCreateAttribute(newHypo, "AttributePixMap")
131 H = orb.string_to_object(IOR)
133 aPixmap.SetPixMap( "mesh_tree_hypo.png_" + aType )
134 anIOR = myStudyBuilder.FindOrCreateAttribute(newHypo, "AttributeIOR")
136 return newHypo.GetID()
138 #------------------------------------------------------------
139 def AddNewAlgorithms(IOR):
140 # VSR: added temporarily - objects are published automatically by the engine
141 aSO = myStudy.FindObjectIOR( IOR )
144 # VSR ######################################################################
146 res, AlgorithmsRoot = mySComponentMesh.FindSubObject (Tag_AlgorithmsRoot)
147 if AlgorithmsRoot is None or res == 0:
148 AlgorithmsRoot = myStudyBuilde.NewObjectToTag (mySComponentMesh, Tag_AlgorithmsRoot)
149 aName = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributeName")
150 aName.SetValue("Algorithms")
151 aSelAttr = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributeSelectable")
152 aSelAttr.SetSelectable(0)
153 aPixmap = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributePixMap")
154 aPixmap.SetPixMap( "mesh_tree_algo.png" )
157 newHypo = myStudyBuilder.NewObject(AlgorithmsRoot)
158 aPixmap = myStudyBuilder.FindOrCreateAttribute(newHypo, "AttributePixMap")
159 aPixmap = anAttr._narrow(SALOMEDS.AttributePixMap)
160 H = orb.string_to_object(IOR)
161 aType = H.GetName(); #QString in fact
162 aPixmap.SetPixMap( "mesh_tree_algo.png_" + aType )
163 anIOR = myStudyBuilder.FindOrCreateAttribute(newHypo, "AttributeIOR")
165 return newHypo.GetID()
168 #------------------------------------------------------------
169 def SetShape(ShapeEntry, MeshEntry):
170 SO_MorSM = myStudy.FindObjectID( MeshEntry )
171 SO_GeomShape = myStudy.FindObjectID( ShapeEntry )
173 if SO_MorSM is not None and SO_GeomShape is not None :
174 # VSR: added temporarily - shape reference is published automatically by the engine
175 res, Ref = SO_MorSM.FindSubObject( Tag_RefOnShape )
178 # VSR ######################################################################
180 SO = myStudyBuilder.NewObjectToTag (SO_MorSM, Tag_RefOnShape)
181 myStudyBuilder.Addreference (SO,SO_GeomShape)
184 #------------------------------------------------------------
185 def SetHypothesis(Mesh_Or_SubMesh_Entry, Hypothesis_Entry):
186 SO_MorSM = myStudy.FindObjectID( Mesh_Or_SubMesh_Entry )
187 SO_Hypothesis = myStudy.FindObjectID( Hypothesis_Entry )
189 if SO_MorSM is not None and SO_Hypothesis is not None :
191 #Find or Create Applied Hypothesis root
192 res, AHR = SO_MorSM.FindSubObject (Tag_RefOnAppliedHypothesis)
193 if AHR is None or res == 0:
194 AHR = myStudyBuilder.NewObjectToTag (SO_MorSM, Tag_RefOnAppliedHypothesis)
195 aName = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributeName")
197 # The same name as in SMESH_Mesh_i::AddHypothesis() ##################
198 aName.SetValue("Applied hypotheses")
200 aSelAttr = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributeSelectable")
201 aSelAttr.SetSelectable(0)
202 aPixmap = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributePixMap")
203 aPixmap.SetPixMap( "mesh_tree_hypo.png" )
205 # VSR: added temporarily - reference to applied hypothesis is published automatically by the engine
207 it = myStudy.NewChildIterator(AHR)
209 res, Ref = it.Value().ReferencedObject()
210 if res and Ref is not None and Ref.GetID() == Hypothesis_Entry :
213 # VSR ######################################################################
215 SO = myStudyBuilder.NewObject(AHR)
216 myStudyBuilder.Addreference (SO,SO_Hypothesis)
218 #------------------------------------------------------------
219 def SetAlgorithms(Mesh_Or_SubMesh_Entry, Algorithms_Entry):
220 SO_MorSM = myStudy.FindObjectID( Mesh_Or_SubMesh_Entry )
221 SO_Algorithms = myStudy.FindObjectID( Algorithms_Entry )
222 if SO_MorSM != None and SO_Algorithms != None :
223 #Find or Create Applied Algorithms root
224 res, AHR = SO_MorSM.FindSubObject (Tag_RefOnAppliedAlgorithms)
225 if AHR is None or res == 0:
226 AHR = myStudyBuilder.NewObjectToTag (SO_MorSM, Tag_RefOnAppliedAlgorithms)
227 aName = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributeName")
229 # The same name as in SMESH_Mesh_i::AddHypothesis() ##################
230 aName.SetValue("Applied algorithms")
232 aSelAttr = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributeSelectable")
233 aSelAttr.SetSelectable(0)
234 aPixmap = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributePixMap")
235 aPixmap.SetPixMap( "mesh_tree_algo.png" )
237 # VSR: added temporarily - reference to applied hypothesis is published automatically by the engine
239 it = myStudy.NewChildIterator(AHR)
241 res, Ref = it.Value().ReferencedObject()
242 if res and Ref is not None and Ref.GetID() == Algorithms_Entry :
245 # VSR ######################################################################
247 SO = myStudyBuilder.NewObject(AHR)
248 myStudyBuilder.Addreference (SO,SO_Algorithms)
251 #------------------------------------------------------------
252 def UnSetHypothesis( Applied_Hypothesis_Entry ):
253 SO_Applied_Hypothesis = myStudy.FindObjectID( Applied_Hypothesis_Entry )
254 if SO_Applied_Hypothesis :
255 myStudyBuilder.RemoveObject(SO_Applied_Hypothesis)
258 #------------------------------------------------------------
259 def AddSubMesh ( SO_Mesh_Entry, SM_IOR, ST):
260 # VSR: added temporarily - objects are published automatically by the engine
261 aSO = myStudy.FindObjectIOR( SM_IOR )
264 # VSR ######################################################################
266 SO_Mesh = myStudy.FindObjectID( SO_Mesh_Entry )
269 if ST == ShapeType["COMPSOLID"] :
270 Tag_Shape = Tag_SubMeshOnSolid
271 Name = "SubMeshes on Solid"
272 elif ST == ShapeType["FACE"] :
273 Tag_Shape = Tag_SubMeshOnFace
274 Name = "SubMeshes on Face"
275 elif ST == ShapeType["EDGE"] :
276 Tag_Shape = Tag_SubMeshOnEdge
277 Name = "SubMeshes on Edge"
278 elif ST == ShapeType["VERTEX"] :
279 Tag_Shape = Tag_SubMeshOnVertex
280 Name = "SubMeshes on Vertex"
282 Tag_Shape = Tag_SubMeshOnCompound
283 Name = "SubMeshes on Compound"
285 res, SubmeshesRoot = SO_Mesh.FindSubObject (Tag_Shape)
286 if SubmeshesRoot is None or res == 0:
287 SubmeshesRoot = myStudyBuilder.NewObjectToTag (SO_Mesh, Tag_Shape)
288 aName = myStudyBuilder.FindOrCreateAttribute(SubmeshesRoot, "AttributeName")
290 aSelAttr = myStudyBuilder.FindOrCreateAttribute(SubmeshesRoot, "AttributeSelectable")
291 aSelAttr.SetSelectable(0)
293 SO = myStudyBuilder.NewObject (SubmeshesRoot)
294 anIOR = myStudyBuilder.FindOrCreateAttribute(SO, "AttributeIOR")
295 anIOR.SetValue(SM_IOR)
300 #------------------------------------------------------------
301 def AddSubMeshOnShape (Mesh_Entry, GeomShape_Entry, SM_IOR, ST) :
302 # VSR: added temporarily - objects are published automatically by the engine
303 aSO = myStudy.FindObjectIOR( SM_IOR )
306 # VSR ######################################################################
307 SO_GeomShape = myStudy.FindObjectID( GeomShape_Entry )
308 if SO_GeomShape != None :
309 SM_Entry = AddSubMesh (Mesh_Entry,SM_IOR,ST)
310 SO_SM = myStudy.FindObjectID( SM_Entry )
313 SetShape (GeomShape_Entry, SM_Entry)
319 #------------------------------------------------------------
320 def SetName(Entry, Name):
321 SO = myStudy.FindObjectID( Entry )
323 aName = myStudyBuilder.FindOrCreateAttribute(SO, "AttributeName")