1 # Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 # File : batchmode_smesh.py
21 # Author : Oksana TCHEBANOVA
25 from batchmode_salome import *
26 from batchmode_geompy import ShapeType
29 #--------------------------------------------------------------------------
30 modulecatalog = naming_service.Resolve("/Kernel/ModulCatalog")
32 smesh = lcc.FindOrLoadComponent("FactoryServer", "SMESH")
33 myStudyBuilder = myStudy.NewBuilder()
35 if myStudyBuilder is None:
36 raise RuntimeError, " Null myStudyBuilder"
38 father = myStudy.FindComponent("SMESH")
40 father = myStudyBuilder.NewComponent("SMESH")
41 FName = myStudyBuilder.FindOrCreateAttribute(father, "AttributeName")
42 Comp = modulecatalog.GetComponent("SMESH")
43 FName.SetValue(Comp._get_componentusername())
44 aPixmap = myStudyBuilder.FindOrCreateAttribute(father, "AttributePixMap")
45 aPixmap.SetPixMap("ICON_OBJBROWSER_Mesh")
47 myStudyBuilder.DefineComponentInstance(father,smesh)
49 mySComponentMesh = father._narrow(SALOMEDS.SComponent)
51 Tag_HypothesisRoot = 1
52 Tag_AlgorithmsRoot = 2
55 Tag_RefOnAppliedHypothesis = 2
56 Tag_RefOnAppliedAlgorithms = 3
58 Tag_SubMeshOnVertex = 4
61 Tag_SubMeshOnSolid = 7
62 Tag_SubMeshOnCompound = 8
64 Tag = {"HypothesisRoot":1,"AlgorithmsRoot":2,"RefOnShape":1,"RefOnAppliedHypothesis":2,"RefOnAppliedAlgorithms":3,"SubMeshOnVertex":4,"SubMeshOnEdge":5,"SubMeshOnFace":6,"SubMeshOnSolid":7,"SubMeshOnCompound":8}
66 #------------------------------------------------------------
69 #------------------------------------------------------------
71 # VSR: added temporarily - objects are published automatically by the engine
72 aSO = myStudy.FindObjectIOR( IOR )
75 # VSR ######################################################################
77 res,HypothesisRoot = mySComponentMesh.FindSubObject ( Tag_HypothesisRoot )
78 if HypothesisRoot is None or res == 0:
79 HypothesisRoot = myStudyBuilder.NewObjectToTag(mySComponentMesh, Tag_HypothesisRoot)
80 aName = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributeName")
81 aName.SetValue("Hypotheses")
82 aPixmap = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributePixMap")
83 aPixmap.SetPixMap( "mesh_tree_hypo.png" )
84 aSelAttr = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributeSelectable")
85 aSelAttr.SetSelectable(0)
87 res, AlgorithmsRoot = mySComponentMesh.FindSubObject (Tag_AlgorithmsRoot)
88 if AlgorithmsRoot is None or res == 0:
89 AlgorithmsRoot = myStudyBuilder.NewObjectToTag (mySComponentMesh, Tag_AlgorithmsRoot)
90 aName = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributeName")
91 aName.SetValue("Algorithms")
92 aPixmap = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributePixMap")
93 aPixmap.SetPixMap( "mesh_tree_algo.png" )
94 aSelAttr = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributeSelectable")
95 aSelAttr.SetSelectable(0)
97 HypothesisRoot = HypothesisRoot._narrow(SALOMEDS.SObject)
98 newMesh = myStudyBuilder.NewObject(mySComponentMesh)
99 aPixmap = myStudyBuilder.FindOrCreateAttribute(newMesh, "AttributePixMap")
100 aPixmap.SetPixMap( "mesh_tree_mesh.png" )
101 anIOR = myStudyBuilder.FindOrCreateAttribute(newMesh, "AttributeIOR")
103 return newMesh.GetID()
105 #------------------------------------------------------------
106 def AddNewHypothesis(IOR):
107 # VSR: added temporarily - objects are published automatically by the engine
108 aSO = myStudy.FindObjectIOR( IOR )
111 # VSR ######################################################################
113 res, HypothesisRoot = mySComponentMesh.FindSubObject (Tag_HypothesisRoot)
114 if HypothesisRoot is None or res == 0:
115 HypothesisRoot = myStudyBuilder.NewObjectToTag (mySComponentMesh, Tag_HypothesisRoot)
116 aName = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributeName")
117 aName.SetValue("Hypotheses")
118 aSelAttr = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributeSelectable")
119 aSelAttr.SetSelectable(0)
120 aPixmap = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributePixMap")
121 aPixmap.SetPixMap( "mesh_tree_hypo.png" )
124 newHypo = myStudyBuilder.NewObject(HypothesisRoot)
125 aPixmap = myStudyBuilder.FindOrCreateAttribute(newHypo, "AttributePixMap")
126 H = orb.string_to_object(IOR)
128 aPixmap.SetPixMap( "mesh_tree_hypo.png_" + aType )
129 anIOR = myStudyBuilder.FindOrCreateAttribute(newHypo, "AttributeIOR")
131 return newHypo.GetID()
133 #------------------------------------------------------------
134 def AddNewAlgorithms(IOR):
135 # VSR: added temporarily - objects are published automatically by the engine
136 aSO = myStudy.FindObjectIOR( IOR )
139 # VSR ######################################################################
141 res, AlgorithmsRoot = mySComponentMesh.FindSubObject (Tag_AlgorithmsRoot)
142 if AlgorithmsRoot is None or res == 0:
143 AlgorithmsRoot = myStudyBuilde.NewObjectToTag (mySComponentMesh, Tag_AlgorithmsRoot)
144 aName = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributeName")
145 aName.SetValue("Algorithms")
146 aSelAttr = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributeSelectable")
147 aSelAttr.SetSelectable(0)
148 aPixmap = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributePixMap")
149 aPixmap.SetPixMap( "mesh_tree_algo.png" )
152 newHypo = myStudyBuilder.NewObject(AlgorithmsRoot)
153 aPixmap = myStudyBuilder.FindOrCreateAttribute(newHypo, "AttributePixMap")
154 aPixmap = anAttr._narrow(SALOMEDS.AttributePixMap)
155 H = orb.string_to_object(IOR)
156 aType = H.GetName(); #QString in fact
157 aPixmap.SetPixMap( "mesh_tree_algo.png_" + aType )
158 anIOR = myStudyBuilder.FindOrCreateAttribute(newHypo, "AttributeIOR")
160 return newHypo.GetID()
163 #------------------------------------------------------------
164 def SetShape(ShapeEntry, MeshEntry):
165 SO_MorSM = myStudy.FindObjectID( MeshEntry )
166 SO_GeomShape = myStudy.FindObjectID( ShapeEntry )
168 if SO_MorSM is not None and SO_GeomShape is not None :
169 # VSR: added temporarily - shape reference is published automatically by the engine
170 res, Ref = SO_MorSM.FindSubObject( Tag_RefOnShape )
173 # VSR ######################################################################
175 SO = myStudyBuilder.NewObjectToTag (SO_MorSM, Tag_RefOnShape)
176 myStudyBuilder.Addreference (SO,SO_GeomShape)
179 #------------------------------------------------------------
180 def SetHypothesis(Mesh_Or_SubMesh_Entry, Hypothesis_Entry):
181 SO_MorSM = myStudy.FindObjectID( Mesh_Or_SubMesh_Entry )
182 SO_Hypothesis = myStudy.FindObjectID( Hypothesis_Entry )
184 if SO_MorSM is not None and SO_Hypothesis is not None :
186 #Find or Create Applied Hypothesis root
187 res, AHR = SO_MorSM.FindSubObject (Tag_RefOnAppliedHypothesis)
188 if AHR is None or res == 0:
189 AHR = myStudyBuilder.NewObjectToTag (SO_MorSM, Tag_RefOnAppliedHypothesis)
190 aName = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributeName")
192 # The same name as in SMESH_Mesh_i::AddHypothesis() ##################
193 aName.SetValue("Applied hypotheses")
195 aSelAttr = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributeSelectable")
196 aSelAttr.SetSelectable(0)
197 aPixmap = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributePixMap")
198 aPixmap.SetPixMap( "mesh_tree_hypo.png" )
200 # VSR: added temporarily - reference to applied hypothesis is published automatically by the engine
202 it = myStudy.NewChildIterator(AHR)
204 res, Ref = it.Value().ReferencedObject()
205 if res and Ref is not None and Ref.GetID() == Hypothesis_Entry :
208 # VSR ######################################################################
210 SO = myStudyBuilder.NewObject(AHR)
211 myStudyBuilder.Addreference (SO,SO_Hypothesis)
213 #------------------------------------------------------------
214 def SetAlgorithms(Mesh_Or_SubMesh_Entry, Algorithms_Entry):
215 SO_MorSM = myStudy.FindObjectID( Mesh_Or_SubMesh_Entry )
216 SO_Algorithms = myStudy.FindObjectID( Algorithms_Entry )
217 if SO_MorSM != None and SO_Algorithms != None :
218 #Find or Create Applied Algorithms root
219 res, AHR = SO_MorSM.FindSubObject (Tag_RefOnAppliedAlgorithms)
220 if AHR is None or res == 0:
221 AHR = myStudyBuilder.NewObjectToTag (SO_MorSM, Tag_RefOnAppliedAlgorithms)
222 aName = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributeName")
224 # The same name as in SMESH_Mesh_i::AddHypothesis() ##################
225 aName.SetValue("Applied algorithms")
227 aSelAttr = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributeSelectable")
228 aSelAttr.SetSelectable(0)
229 aPixmap = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributePixMap")
230 aPixmap.SetPixMap( "mesh_tree_algo.png" )
232 # VSR: added temporarily - reference to applied hypothesis is published automatically by the engine
234 it = myStudy.NewChildIterator(AHR)
236 res, Ref = it.Value().ReferencedObject()
237 if res and Ref is not None and Ref.GetID() == Algorithms_Entry :
240 # VSR ######################################################################
242 SO = myStudyBuilder.NewObject(AHR)
243 myStudyBuilder.Addreference (SO,SO_Algorithms)
246 #------------------------------------------------------------
247 def UnSetHypothesis( Applied_Hypothesis_Entry ):
248 SO_Applied_Hypothesis = myStudy.FindObjectID( Applied_Hypothesis_Entry )
249 if SO_Applied_Hypothesis :
250 myStudyBuilder.RemoveObject(SO_Applied_Hypothesis)
253 #------------------------------------------------------------
254 def AddSubMesh ( SO_Mesh_Entry, SM_IOR, ST):
255 # VSR: added temporarily - objects are published automatically by the engine
256 aSO = myStudy.FindObjectIOR( SM_IOR )
259 # VSR ######################################################################
261 SO_Mesh = myStudy.FindObjectID( SO_Mesh_Entry )
264 if ST == ShapeType["COMPSOLID"] :
265 Tag_Shape = Tag_SubMeshOnSolid
266 Name = "SubMeshes on Solid"
267 elif ST == ShapeType["FACE"] :
268 Tag_Shape = Tag_SubMeshOnFace
269 Name = "SubMeshes on Face"
270 elif ST == ShapeType["EDGE"] :
271 Tag_Shape = Tag_SubMeshOnEdge
272 Name = "SubMeshes on Edge"
273 elif ST == ShapeType["VERTEX"] :
274 Tag_Shape = Tag_SubMeshOnVertex
275 Name = "SubMeshes on Vertex"
277 Tag_Shape = Tag_SubMeshOnCompound
278 Name = "SubMeshes on Compound"
280 res, SubmeshesRoot = SO_Mesh.FindSubObject (Tag_Shape)
281 if SubmeshesRoot is None or res == 0:
282 SubmeshesRoot = myStudyBuilder.NewObjectToTag (SO_Mesh, Tag_Shape)
283 aName = myStudyBuilder.FindOrCreateAttribute(SubmeshesRoot, "AttributeName")
285 aSelAttr = myStudyBuilder.FindOrCreateAttribute(SubmeshesRoot, "AttributeSelectable")
286 aSelAttr.SetSelectable(0)
288 SO = myStudyBuilder.NewObject (SubmeshesRoot)
289 anIOR = myStudyBuilder.FindOrCreateAttribute(SO, "AttributeIOR")
290 anIOR.SetValue(SM_IOR)
295 #------------------------------------------------------------
296 def AddSubMeshOnShape (Mesh_Entry, GeomShape_Entry, SM_IOR, ST) :
297 # VSR: added temporarily - objects are published automatically by the engine
298 aSO = myStudy.FindObjectIOR( SM_IOR )
301 # VSR ######################################################################
302 SO_GeomShape = myStudy.FindObjectID( GeomShape_Entry )
303 if SO_GeomShape != None :
304 SM_Entry = AddSubMesh (Mesh_Entry,SM_IOR,ST)
305 SO_SM = myStudy.FindObjectID( SM_Entry )
308 SetShape (GeomShape_Entry, SM_Entry)
314 #------------------------------------------------------------
315 def SetName(Entry, Name):
316 SO = myStudy.FindObjectID( Entry )
318 aName = myStudyBuilder.FindOrCreateAttribute(SO, "AttributeName")