1 # Copyright (C) 2003 CEA/DEN, EDF R&D
5 # File : batchmode_smesh.py
6 # Author : Oksana TCHEBANOVA
10 from batchmode_salome import *
13 #--------------------------------------------------------------------------
14 modulecatalog = naming_service.Resolve("/Kernel/ModulCatalog")
16 smesh = lcc.FindOrLoadComponent("FactoryServer", "SMESH")
17 myStudyBuilder = myStudy.NewBuilder()
19 if myStudyBuilder is None:
20 raise RuntimeError, " Null myStudyBuilder"
22 father = myStudy.FindComponent("MESH")
24 father = myStudyBuilder.NewComponent("MESH")
25 FName = myStudyBuilder.FindOrCreateAttribute(father, "AttributeName");
26 Comp = modulecatalog.GetComponent( "SMESH" )
27 FName.SetValue( Comp._get_componentusername() )
28 aPixmap = myStudyBuilder.FindOrCreateAttribute(father, "AttributePixMap");
29 aPixmap.SetPixMap( "ICON_OBJBROWSER_Mesh" );
31 myStudyBuilder.DefineComponentInstance(father,smesh)
33 mySComponentMesh = father._narrow(SALOMEDS.SComponent)
35 Tag_HypothesisRoot = 1;
36 Tag_AlgorithmsRoot = 2;
39 Tag_RefOnAppliedHypothesis = 2;
40 Tag_RefOnAppliedAlgorithms = 3;
42 Tag_SubMeshOnVertex = 4;
43 Tag_SubMeshOnEdge = 5;
44 Tag_SubMeshOnFace = 6;
45 Tag_SubMeshOnSolid = 7;
46 Tag_SubMeshOnCompound = 8;
48 Tag = {"HypothesisRoot":1,"AlgorithmsRoot":2,"RefOnShape":1,"RefOnAppliedHypothesis":2,"RefOnAppliedAlgorithms":3,"SubMeshOnVertex":4,"SubMeshOnEdge":5,"SubMeshOnFace":6,"SubMeshOnSolid":7,"SubMeshOnCompound":8}
51 ShapeTypeCompSolid = 1
59 # -- enumeration ShapeType as a dictionary --
60 ShapeType = {"CompSolid":1, "Solid":2, "Shell":3, "Face":4, "Wire":5, "Edge":6, "Vertex":7}
62 #------------------------------------------------------------
65 #------------------------------------------------------------
67 # VSR: added temporarily - objects are published automatically by the engine
68 aSO = myStudy.FindObjectIOR( IOR )
71 # VSR ######################################################################
73 res,HypothesisRoot = mySComponentMesh.FindSubObject ( Tag_HypothesisRoot )
74 if HypothesisRoot is None or res == 0:
75 HypothesisRoot = myStudyBuilder.NewObjectToTag(mySComponentMesh, Tag_HypothesisRoot)
76 aName = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributeName")
77 aName.SetValue("Hypotheses")
78 aPixmap = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributePixMap")
79 aPixmap.SetPixMap( "mesh_tree_hypo.png" )
80 aSelAttr = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributeSelectable")
81 aSelAttr.SetSelectable(0);
83 res, AlgorithmsRoot = mySComponentMesh.FindSubObject (Tag_AlgorithmsRoot)
84 if AlgorithmsRoot is None or res == 0:
85 AlgorithmsRoot = myStudyBuilder.NewObjectToTag (mySComponentMesh, Tag_AlgorithmsRoot)
86 aName = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributeName")
87 aName.SetValue("Algorithms");
88 aPixmap = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributePixMap");
89 aPixmap.SetPixMap( "mesh_tree_algo.png" );
90 aSelAttr = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributeSelectable");
91 aSelAttr.SetSelectable(0);
93 HypothesisRoot = HypothesisRoot._narrow(SALOMEDS.SObject)
94 newMesh = myStudyBuilder.NewObject(mySComponentMesh)
95 aPixmap = myStudyBuilder.FindOrCreateAttribute(newMesh, "AttributePixMap")
96 aPixmap.SetPixMap( "mesh_tree_mesh.png" )
97 anIOR = myStudyBuilder.FindOrCreateAttribute(newMesh, "AttributeIOR")
99 return newMesh.GetID()
101 #------------------------------------------------------------
102 def AddNewHypothesis(IOR):
103 # VSR: added temporarily - objects are published automatically by the engine
104 aSO = myStudy.FindObjectIOR( IOR )
107 # VSR ######################################################################
109 res, HypothesisRoot = mySComponentMesh.FindSubObject (Tag_HypothesisRoot)
110 if HypothesisRoot is None or res == 0:
111 HypothesisRoot = myStudyBuilder.NewObjectToTag (mySComponentMesh, Tag_HypothesisRoot)
112 aName = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributeName");
113 aName.SetValue("Hypotheses");
114 aSelAttr = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributeSelectable");
115 aSelAttr.SetSelectable(0);
116 aPixmap = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributePixMap");
117 aPixmap.SetPixMap( "mesh_tree_hypo.png" );
120 newHypo = myStudyBuilder.NewObject(HypothesisRoot)
121 aPixmap = myStudyBuilder.FindOrCreateAttribute(newHypo, "AttributePixMap")
122 H = orb.string_to_object(IOR)
124 aPixmap.SetPixMap( "mesh_tree_hypo.png_" + aType );
125 anIOR = myStudyBuilder.FindOrCreateAttribute(newHypo, "AttributeIOR");
127 return newHypo.GetID();
129 #------------------------------------------------------------
130 def AddNewAlgorithms(IOR):
131 # VSR: added temporarily - objects are published automatically by the engine
132 aSO = myStudy.FindObjectIOR( IOR )
135 # VSR ######################################################################
137 res, AlgorithmsRoot = mySComponentMesh.FindSubObject (Tag_AlgorithmsRoot)
138 if AlgorithmsRoot is None or res == 0:
139 AlgorithmsRoot = myStudyBuilde.NewObjectToTag (mySComponentMesh, Tag_AlgorithmsRoot)
140 aName = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributeName")
141 aName.SetValue("Algorithms");
142 aSelAttr = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributeSelectable")
143 aSelAttr.SetSelectable(0);
144 aPixmap = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributePixMap");
145 aPixmap.SetPixMap( "mesh_tree_algo.png" );
148 newHypo = myStudyBuilder.NewObject(AlgorithmsRoot)
149 aPixmap = myStudyBuilder.FindOrCreateAttribute(newHypo, "AttributePixMap");
150 aPixmap = anAttr._narrow(SALOMEDS.AttributePixMap);
151 H = orb.string_to_object(IOR)
152 aType = H.GetName(); #QString in fact
153 aPixmap.SetPixMap( "mesh_tree_algo.png_" + aType );
154 anIOR = myStudyBuilder.FindOrCreateAttribute(newHypo, "AttributeIOR");
156 return newHypo.GetID();
159 #------------------------------------------------------------
160 def SetShape(ShapeEntry, MeshEntry):
161 SO_MorSM = myStudy.FindObjectID( MeshEntry )
162 SO_GeomShape = myStudy.FindObjectID( ShapeEntry );
164 if SO_MorSM is not None and SO_GeomShape is not None :
165 # VSR: added temporarily - shape reference is published automatically by the engine
166 res, Ref = SO_MorSM.FindSubObject( Tag_RefOnShape );
169 # VSR ######################################################################
171 SO = myStudyBuilder.NewObjectToTag (SO_MorSM, Tag_RefOnShape);
172 myStudyBuilder.Addreference (SO,SO_GeomShape);
175 #------------------------------------------------------------
176 def SetHypothesis(Mesh_Or_SubMesh_Entry, Hypothesis_Entry):
177 SO_MorSM = myStudy.FindObjectID( Mesh_Or_SubMesh_Entry );
178 SO_Hypothesis = myStudy.FindObjectID( Hypothesis_Entry );
180 if SO_MorSM is not None and SO_Hypothesis is not None :
182 #Find or Create Applied Hypothesis root
183 res, AHR = SO_MorSM.FindSubObject (Tag_RefOnAppliedHypothesis)
184 if AHR is None or res == 0:
185 AHR = myStudyBuilder.NewObjectToTag (SO_MorSM, Tag_RefOnAppliedHypothesis);
186 aName = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributeName");
188 # The same name as in SMESH_Mesh_i::AddHypothesis() ##################
189 aName.SetValue("Applied hypotheses");
191 aSelAttr = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributeSelectable");
192 aSelAttr.SetSelectable(0);
193 aPixmap = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributePixMap");
194 aPixmap.SetPixMap( "mesh_tree_hypo.png" );
196 # VSR: added temporarily - reference to applied hypothesis is published automatically by the engine
198 it = myStudy.NewChildIterator(AHR);
200 res, Ref = it.Value().ReferencedObject();
201 if res and Ref is not None and Ref.GetID() == Hypothesis_Entry :
204 # VSR ######################################################################
206 SO = myStudyBuilder.NewObject(AHR);
207 myStudyBuilder.Addreference (SO,SO_Hypothesis);
209 #------------------------------------------------------------
210 def SetAlgorithms(Mesh_Or_SubMesh_Entry, Algorithms_Entry):
211 SO_MorSM = myStudy.FindObjectID( Mesh_Or_SubMesh_Entry )
212 SO_Algorithms = myStudy.FindObjectID( Algorithms_Entry )
213 if SO_MorSM != None and SO_Algorithms != None :
214 #Find or Create Applied Algorithms root
215 res, AHR = SO_MorSM.FindSubObject (Tag_RefOnAppliedAlgorithms);
216 if AHR is None or res == 0:
217 AHR = myStudyBuilder.NewObjectToTag (SO_MorSM, Tag_RefOnAppliedAlgorithms);
218 aName = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributeName");
220 # The same name as in SMESH_Mesh_i::AddHypothesis() ##################
221 aName.SetValue("Applied algorithms");
223 aSelAttr = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributeSelectable");
224 aSelAttr.SetSelectable(0);
225 aPixmap = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributePixMap");
226 aPixmap.SetPixMap( "mesh_tree_algo.png" );
228 # VSR: added temporarily - reference to applied hypothesis is published automatically by the engine
230 it = myStudy.NewChildIterator(AHR);
232 res, Ref = it.Value().ReferencedObject();
233 if res and Ref is not None and Ref.GetID() == Algorithms_Entry :
236 # VSR ######################################################################
238 SO = myStudyBuilder.NewObject(AHR);
239 myStudyBuilder.Addreference (SO,SO_Algorithms);
242 #------------------------------------------------------------
243 def UnSetHypothesis( Applied_Hypothesis_Entry ):
244 SO_Applied_Hypothesis = myStudy.FindObjectID( Applied_Hypothesis_Entry );
245 if SO_Applied_Hypothesis :
246 myStudyBuilder.RemoveObject(SO_Applied_Hypothesis);
249 #------------------------------------------------------------
250 def AddSubMesh ( SO_Mesh_Entry, SM_IOR, ST):
251 # VSR: added temporarily - objects are published automatically by the engine
252 aSO = myStudy.FindObjectIOR( SM_IOR )
255 # VSR ######################################################################
257 SO_Mesh = myStudy.FindObjectID( SO_Mesh_Entry )
260 if ST == ShapeTypeCompSolid :
261 Tag_Shape = Tag_SubMeshOnSolid;
262 Name = "SubMeshes on Solid";
263 elif ST == ShapeTypeFace :
264 Tag_Shape = Tag_SubMeshOnFace;
265 Name = "SubMeshes on Face";
266 elif ST == ShapeTypeEdge :
267 Tag_Shape = Tag_SubMeshOnEdge;
268 Name = "SubMeshes on Edge";
269 elif ST == ShapeTypeVertex :
270 Tag_Shape = Tag_SubMeshOnVertex;
271 Name = "SubMeshes on Vertex";
273 Tag_Shape = Tag_SubMeshOnCompound;
274 Name = "SubMeshes on Compound";
276 res, SubmeshesRoot = SO_Mesh.FindSubObject (Tag_Shape)
277 if SubmeshesRoot is None or res == 0:
278 SubmeshesRoot = myStudyBuilder.NewObjectToTag (SO_Mesh, Tag_Shape);
279 aName = myStudyBuilder.FindOrCreateAttribute(SubmeshesRoot, "AttributeName");
280 aName.SetValue(Name);
281 aSelAttr = myStudyBuilder.FindOrCreateAttribute(SubmeshesRoot, "AttributeSelectable");
282 aSelAttr.SetSelectable(0);
284 SO = myStudyBuilder.NewObject (SubmeshesRoot);
285 anIOR = myStudyBuilder.FindOrCreateAttribute(SO, "AttributeIOR");
286 anIOR.SetValue(SM_IOR);
291 #------------------------------------------------------------
292 def AddSubMeshOnShape (Mesh_Entry, GeomShape_Entry, SM_IOR, ST) :
293 # VSR: added temporarily - objects are published automatically by the engine
294 aSO = myStudy.FindObjectIOR( SM_IOR )
297 # VSR ######################################################################
298 SO_GeomShape = myStudy.FindObjectID( GeomShape_Entry );
299 if SO_GeomShape != None :
300 SM_Entry = AddSubMesh (Mesh_Entry,SM_IOR,ST);
301 SO_SM = myStudy.FindObjectID( SM_Entry );
304 SetShape (GeomShape_Entry, SM_Entry);
310 #------------------------------------------------------------
311 def SetName(Entry, Name):
312 SO = myStudy.FindObjectID( Entry );
314 aName = myStudyBuilder.FindOrCreateAttribute(SO, "AttributeName");
315 aName.SetValue(Name);