1 # Copyright (C) 2003 CEA/DEN, EDF R&D
5 # File : batchmode_smesh.py
6 # Author : Oksana TCHEBANOVA
10 from batchmode_salome import *
11 from batchmode_geompy import ShapeType
14 #--------------------------------------------------------------------------
15 modulecatalog = naming_service.Resolve("/Kernel/ModulCatalog")
17 smesh = lcc.FindOrLoadComponent("FactoryServer", "SMESH")
18 myStudyBuilder = myStudy.NewBuilder()
20 if myStudyBuilder is None:
21 raise RuntimeError, " Null myStudyBuilder"
23 father = myStudy.FindComponent("SMESH")
25 father = myStudyBuilder.NewComponent("SMESH")
26 FName = myStudyBuilder.FindOrCreateAttribute(father, "AttributeName")
27 Comp = modulecatalog.GetComponent("SMESH")
28 FName.SetValue(Comp._get_componentusername())
29 aPixmap = myStudyBuilder.FindOrCreateAttribute(father, "AttributePixMap")
30 aPixmap.SetPixMap("ICON_OBJBROWSER_Mesh")
32 myStudyBuilder.DefineComponentInstance(father,smesh)
34 mySComponentMesh = father._narrow(SALOMEDS.SComponent)
36 Tag_HypothesisRoot = 1
37 Tag_AlgorithmsRoot = 2
40 Tag_RefOnAppliedHypothesis = 2
41 Tag_RefOnAppliedAlgorithms = 3
43 Tag_SubMeshOnVertex = 4
46 Tag_SubMeshOnSolid = 7
47 Tag_SubMeshOnCompound = 8
49 Tag = {"HypothesisRoot":1,"AlgorithmsRoot":2,"RefOnShape":1,"RefOnAppliedHypothesis":2,"RefOnAppliedAlgorithms":3,"SubMeshOnVertex":4,"SubMeshOnEdge":5,"SubMeshOnFace":6,"SubMeshOnSolid":7,"SubMeshOnCompound":8}
51 #------------------------------------------------------------
54 #------------------------------------------------------------
56 # VSR: added temporarily - objects are published automatically by the engine
57 aSO = myStudy.FindObjectIOR( IOR )
60 # VSR ######################################################################
62 res,HypothesisRoot = mySComponentMesh.FindSubObject ( Tag_HypothesisRoot )
63 if HypothesisRoot is None or res == 0:
64 HypothesisRoot = myStudyBuilder.NewObjectToTag(mySComponentMesh, Tag_HypothesisRoot)
65 aName = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributeName")
66 aName.SetValue("Hypotheses")
67 aPixmap = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributePixMap")
68 aPixmap.SetPixMap( "mesh_tree_hypo.png" )
69 aSelAttr = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributeSelectable")
70 aSelAttr.SetSelectable(0)
72 res, AlgorithmsRoot = mySComponentMesh.FindSubObject (Tag_AlgorithmsRoot)
73 if AlgorithmsRoot is None or res == 0:
74 AlgorithmsRoot = myStudyBuilder.NewObjectToTag (mySComponentMesh, Tag_AlgorithmsRoot)
75 aName = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributeName")
76 aName.SetValue("Algorithms")
77 aPixmap = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributePixMap")
78 aPixmap.SetPixMap( "mesh_tree_algo.png" )
79 aSelAttr = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributeSelectable")
80 aSelAttr.SetSelectable(0)
82 HypothesisRoot = HypothesisRoot._narrow(SALOMEDS.SObject)
83 newMesh = myStudyBuilder.NewObject(mySComponentMesh)
84 aPixmap = myStudyBuilder.FindOrCreateAttribute(newMesh, "AttributePixMap")
85 aPixmap.SetPixMap( "mesh_tree_mesh.png" )
86 anIOR = myStudyBuilder.FindOrCreateAttribute(newMesh, "AttributeIOR")
88 return newMesh.GetID()
90 #------------------------------------------------------------
91 def AddNewHypothesis(IOR):
92 # VSR: added temporarily - objects are published automatically by the engine
93 aSO = myStudy.FindObjectIOR( IOR )
96 # VSR ######################################################################
98 res, HypothesisRoot = mySComponentMesh.FindSubObject (Tag_HypothesisRoot)
99 if HypothesisRoot is None or res == 0:
100 HypothesisRoot = myStudyBuilder.NewObjectToTag (mySComponentMesh, Tag_HypothesisRoot)
101 aName = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributeName")
102 aName.SetValue("Hypotheses")
103 aSelAttr = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributeSelectable")
104 aSelAttr.SetSelectable(0)
105 aPixmap = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributePixMap")
106 aPixmap.SetPixMap( "mesh_tree_hypo.png" )
109 newHypo = myStudyBuilder.NewObject(HypothesisRoot)
110 aPixmap = myStudyBuilder.FindOrCreateAttribute(newHypo, "AttributePixMap")
111 H = orb.string_to_object(IOR)
113 aPixmap.SetPixMap( "mesh_tree_hypo.png_" + aType )
114 anIOR = myStudyBuilder.FindOrCreateAttribute(newHypo, "AttributeIOR")
116 return newHypo.GetID()
118 #------------------------------------------------------------
119 def AddNewAlgorithms(IOR):
120 # VSR: added temporarily - objects are published automatically by the engine
121 aSO = myStudy.FindObjectIOR( IOR )
124 # VSR ######################################################################
126 res, AlgorithmsRoot = mySComponentMesh.FindSubObject (Tag_AlgorithmsRoot)
127 if AlgorithmsRoot is None or res == 0:
128 AlgorithmsRoot = myStudyBuilde.NewObjectToTag (mySComponentMesh, Tag_AlgorithmsRoot)
129 aName = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributeName")
130 aName.SetValue("Algorithms")
131 aSelAttr = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributeSelectable")
132 aSelAttr.SetSelectable(0)
133 aPixmap = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributePixMap")
134 aPixmap.SetPixMap( "mesh_tree_algo.png" )
137 newHypo = myStudyBuilder.NewObject(AlgorithmsRoot)
138 aPixmap = myStudyBuilder.FindOrCreateAttribute(newHypo, "AttributePixMap")
139 aPixmap = anAttr._narrow(SALOMEDS.AttributePixMap)
140 H = orb.string_to_object(IOR)
141 aType = H.GetName(); #QString in fact
142 aPixmap.SetPixMap( "mesh_tree_algo.png_" + aType )
143 anIOR = myStudyBuilder.FindOrCreateAttribute(newHypo, "AttributeIOR")
145 return newHypo.GetID()
148 #------------------------------------------------------------
149 def SetShape(ShapeEntry, MeshEntry):
150 SO_MorSM = myStudy.FindObjectID( MeshEntry )
151 SO_GeomShape = myStudy.FindObjectID( ShapeEntry )
153 if SO_MorSM is not None and SO_GeomShape is not None :
154 # VSR: added temporarily - shape reference is published automatically by the engine
155 res, Ref = SO_MorSM.FindSubObject( Tag_RefOnShape )
158 # VSR ######################################################################
160 SO = myStudyBuilder.NewObjectToTag (SO_MorSM, Tag_RefOnShape)
161 myStudyBuilder.Addreference (SO,SO_GeomShape)
164 #------------------------------------------------------------
165 def SetHypothesis(Mesh_Or_SubMesh_Entry, Hypothesis_Entry):
166 SO_MorSM = myStudy.FindObjectID( Mesh_Or_SubMesh_Entry )
167 SO_Hypothesis = myStudy.FindObjectID( Hypothesis_Entry )
169 if SO_MorSM is not None and SO_Hypothesis is not None :
171 #Find or Create Applied Hypothesis root
172 res, AHR = SO_MorSM.FindSubObject (Tag_RefOnAppliedHypothesis)
173 if AHR is None or res == 0:
174 AHR = myStudyBuilder.NewObjectToTag (SO_MorSM, Tag_RefOnAppliedHypothesis)
175 aName = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributeName")
177 # The same name as in SMESH_Mesh_i::AddHypothesis() ##################
178 aName.SetValue("Applied hypotheses")
180 aSelAttr = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributeSelectable")
181 aSelAttr.SetSelectable(0)
182 aPixmap = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributePixMap")
183 aPixmap.SetPixMap( "mesh_tree_hypo.png" )
185 # VSR: added temporarily - reference to applied hypothesis is published automatically by the engine
187 it = myStudy.NewChildIterator(AHR)
189 res, Ref = it.Value().ReferencedObject()
190 if res and Ref is not None and Ref.GetID() == Hypothesis_Entry :
193 # VSR ######################################################################
195 SO = myStudyBuilder.NewObject(AHR)
196 myStudyBuilder.Addreference (SO,SO_Hypothesis)
198 #------------------------------------------------------------
199 def SetAlgorithms(Mesh_Or_SubMesh_Entry, Algorithms_Entry):
200 SO_MorSM = myStudy.FindObjectID( Mesh_Or_SubMesh_Entry )
201 SO_Algorithms = myStudy.FindObjectID( Algorithms_Entry )
202 if SO_MorSM != None and SO_Algorithms != None :
203 #Find or Create Applied Algorithms root
204 res, AHR = SO_MorSM.FindSubObject (Tag_RefOnAppliedAlgorithms)
205 if AHR is None or res == 0:
206 AHR = myStudyBuilder.NewObjectToTag (SO_MorSM, Tag_RefOnAppliedAlgorithms)
207 aName = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributeName")
209 # The same name as in SMESH_Mesh_i::AddHypothesis() ##################
210 aName.SetValue("Applied algorithms")
212 aSelAttr = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributeSelectable")
213 aSelAttr.SetSelectable(0)
214 aPixmap = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributePixMap")
215 aPixmap.SetPixMap( "mesh_tree_algo.png" )
217 # VSR: added temporarily - reference to applied hypothesis is published automatically by the engine
219 it = myStudy.NewChildIterator(AHR)
221 res, Ref = it.Value().ReferencedObject()
222 if res and Ref is not None and Ref.GetID() == Algorithms_Entry :
225 # VSR ######################################################################
227 SO = myStudyBuilder.NewObject(AHR)
228 myStudyBuilder.Addreference (SO,SO_Algorithms)
231 #------------------------------------------------------------
232 def UnSetHypothesis( Applied_Hypothesis_Entry ):
233 SO_Applied_Hypothesis = myStudy.FindObjectID( Applied_Hypothesis_Entry )
234 if SO_Applied_Hypothesis :
235 myStudyBuilder.RemoveObject(SO_Applied_Hypothesis)
238 #------------------------------------------------------------
239 def AddSubMesh ( SO_Mesh_Entry, SM_IOR, ST):
240 # VSR: added temporarily - objects are published automatically by the engine
241 aSO = myStudy.FindObjectIOR( SM_IOR )
244 # VSR ######################################################################
246 SO_Mesh = myStudy.FindObjectID( SO_Mesh_Entry )
249 if ST == ShapeType["COMPSOLID"] :
250 Tag_Shape = Tag_SubMeshOnSolid
251 Name = "SubMeshes on Solid"
252 elif ST == ShapeType["FACE"] :
253 Tag_Shape = Tag_SubMeshOnFace
254 Name = "SubMeshes on Face"
255 elif ST == ShapeType["EDGE"] :
256 Tag_Shape = Tag_SubMeshOnEdge
257 Name = "SubMeshes on Edge"
258 elif ST == ShapeType["VERTEX"] :
259 Tag_Shape = Tag_SubMeshOnVertex
260 Name = "SubMeshes on Vertex"
262 Tag_Shape = Tag_SubMeshOnCompound
263 Name = "SubMeshes on Compound"
265 res, SubmeshesRoot = SO_Mesh.FindSubObject (Tag_Shape)
266 if SubmeshesRoot is None or res == 0:
267 SubmeshesRoot = myStudyBuilder.NewObjectToTag (SO_Mesh, Tag_Shape)
268 aName = myStudyBuilder.FindOrCreateAttribute(SubmeshesRoot, "AttributeName")
270 aSelAttr = myStudyBuilder.FindOrCreateAttribute(SubmeshesRoot, "AttributeSelectable")
271 aSelAttr.SetSelectable(0)
273 SO = myStudyBuilder.NewObject (SubmeshesRoot)
274 anIOR = myStudyBuilder.FindOrCreateAttribute(SO, "AttributeIOR")
275 anIOR.SetValue(SM_IOR)
280 #------------------------------------------------------------
281 def AddSubMeshOnShape (Mesh_Entry, GeomShape_Entry, SM_IOR, ST) :
282 # VSR: added temporarily - objects are published automatically by the engine
283 aSO = myStudy.FindObjectIOR( SM_IOR )
286 # VSR ######################################################################
287 SO_GeomShape = myStudy.FindObjectID( GeomShape_Entry )
288 if SO_GeomShape != None :
289 SM_Entry = AddSubMesh (Mesh_Entry,SM_IOR,ST)
290 SO_SM = myStudy.FindObjectID( SM_Entry )
293 SetShape (GeomShape_Entry, SM_Entry)
299 #------------------------------------------------------------
300 def SetName(Entry, Name):
301 SO = myStudy.FindObjectID( Entry )
303 aName = myStudyBuilder.FindOrCreateAttribute(SO, "AttributeName")