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 smesh.SetCurrentStudy(myStudy)
37 myStudyBuilder = myStudy.NewBuilder()
39 if myStudyBuilder is None:
40 raise RuntimeError, " Null myStudyBuilder"
42 father = myStudy.FindComponent("SMESH")
44 father = myStudyBuilder.NewComponent("SMESH")
45 FName = myStudyBuilder.FindOrCreateAttribute(father, "AttributeName")
46 Comp = modulecatalog.GetComponent("SMESH")
47 FName.SetValue(Comp._get_componentusername())
48 aPixmap = myStudyBuilder.FindOrCreateAttribute(father, "AttributePixMap")
49 aPixmap.SetPixMap("ICON_OBJBROWSER_Mesh")
51 myStudyBuilder.DefineComponentInstance(father,smesh)
53 mySComponentMesh = father._narrow(SALOMEDS.SComponent)
55 Tag_HypothesisRoot = 1
56 Tag_AlgorithmsRoot = 2
59 Tag_RefOnAppliedHypothesis = 2
60 Tag_RefOnAppliedAlgorithms = 3
62 Tag_SubMeshOnVertex = 4
65 Tag_SubMeshOnSolid = 7
66 Tag_SubMeshOnCompound = 8
68 Tag = {"HypothesisRoot":1,"AlgorithmsRoot":2,"RefOnShape":1,"RefOnAppliedHypothesis":2,"RefOnAppliedAlgorithms":3,"SubMeshOnVertex":4,"SubMeshOnEdge":5,"SubMeshOnFace":6,"SubMeshOnSolid":7,"SubMeshOnCompound":8}
70 #------------------------------------------------------------
73 #------------------------------------------------------------
75 # VSR: added temporarily - objects are published automatically by the engine
76 aSO = myStudy.FindObjectIOR( IOR )
79 # VSR ######################################################################
81 res,HypothesisRoot = mySComponentMesh.FindSubObject ( Tag_HypothesisRoot )
82 if HypothesisRoot is None or res == 0:
83 HypothesisRoot = myStudyBuilder.NewObjectToTag(mySComponentMesh, Tag_HypothesisRoot)
84 aName = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributeName")
85 aName.SetValue("Hypotheses")
86 aPixmap = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributePixMap")
87 aPixmap.SetPixMap( "mesh_tree_hypo.png" )
88 aSelAttr = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributeSelectable")
89 aSelAttr.SetSelectable(0)
91 res, AlgorithmsRoot = mySComponentMesh.FindSubObject (Tag_AlgorithmsRoot)
92 if AlgorithmsRoot is None or res == 0:
93 AlgorithmsRoot = myStudyBuilder.NewObjectToTag (mySComponentMesh, Tag_AlgorithmsRoot)
94 aName = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributeName")
95 aName.SetValue("Algorithms")
96 aPixmap = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributePixMap")
97 aPixmap.SetPixMap( "mesh_tree_algo.png" )
98 aSelAttr = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributeSelectable")
99 aSelAttr.SetSelectable(0)
101 HypothesisRoot = HypothesisRoot._narrow(SALOMEDS.SObject)
102 newMesh = myStudyBuilder.NewObject(mySComponentMesh)
103 aPixmap = myStudyBuilder.FindOrCreateAttribute(newMesh, "AttributePixMap")
104 aPixmap.SetPixMap( "mesh_tree_mesh.png" )
105 anIOR = myStudyBuilder.FindOrCreateAttribute(newMesh, "AttributeIOR")
107 return newMesh.GetID()
109 #------------------------------------------------------------
110 def AddNewHypothesis(IOR):
111 # VSR: added temporarily - objects are published automatically by the engine
112 aSO = myStudy.FindObjectIOR( IOR )
115 # VSR ######################################################################
117 res, HypothesisRoot = mySComponentMesh.FindSubObject (Tag_HypothesisRoot)
118 if HypothesisRoot is None or res == 0:
119 HypothesisRoot = myStudyBuilder.NewObjectToTag (mySComponentMesh, Tag_HypothesisRoot)
120 aName = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributeName")
121 aName.SetValue("Hypotheses")
122 aSelAttr = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributeSelectable")
123 aSelAttr.SetSelectable(0)
124 aPixmap = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributePixMap")
125 aPixmap.SetPixMap( "mesh_tree_hypo.png" )
128 newHypo = myStudyBuilder.NewObject(HypothesisRoot)
129 aPixmap = myStudyBuilder.FindOrCreateAttribute(newHypo, "AttributePixMap")
130 H = orb.string_to_object(IOR)
132 aPixmap.SetPixMap( "mesh_tree_hypo.png_" + aType )
133 anIOR = myStudyBuilder.FindOrCreateAttribute(newHypo, "AttributeIOR")
135 return newHypo.GetID()
137 #------------------------------------------------------------
138 def AddNewAlgorithms(IOR):
139 # VSR: added temporarily - objects are published automatically by the engine
140 aSO = myStudy.FindObjectIOR( IOR )
143 # VSR ######################################################################
145 res, AlgorithmsRoot = mySComponentMesh.FindSubObject (Tag_AlgorithmsRoot)
146 if AlgorithmsRoot is None or res == 0:
147 AlgorithmsRoot = myStudyBuilde.NewObjectToTag (mySComponentMesh, Tag_AlgorithmsRoot)
148 aName = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributeName")
149 aName.SetValue("Algorithms")
150 aSelAttr = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributeSelectable")
151 aSelAttr.SetSelectable(0)
152 aPixmap = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributePixMap")
153 aPixmap.SetPixMap( "mesh_tree_algo.png" )
156 newHypo = myStudyBuilder.NewObject(AlgorithmsRoot)
157 aPixmap = myStudyBuilder.FindOrCreateAttribute(newHypo, "AttributePixMap")
158 aPixmap = anAttr._narrow(SALOMEDS.AttributePixMap)
159 H = orb.string_to_object(IOR)
160 aType = H.GetName(); #QString in fact
161 aPixmap.SetPixMap( "mesh_tree_algo.png_" + aType )
162 anIOR = myStudyBuilder.FindOrCreateAttribute(newHypo, "AttributeIOR")
164 return newHypo.GetID()
167 #------------------------------------------------------------
168 def SetShape(ShapeEntry, MeshEntry):
169 SO_MorSM = myStudy.FindObjectID( MeshEntry )
170 SO_GeomShape = myStudy.FindObjectID( ShapeEntry )
172 if SO_MorSM is not None and SO_GeomShape is not None :
173 # VSR: added temporarily - shape reference is published automatically by the engine
174 res, Ref = SO_MorSM.FindSubObject( Tag_RefOnShape )
177 # VSR ######################################################################
179 SO = myStudyBuilder.NewObjectToTag (SO_MorSM, Tag_RefOnShape)
180 myStudyBuilder.Addreference (SO,SO_GeomShape)
183 #------------------------------------------------------------
184 def SetHypothesis(Mesh_Or_SubMesh_Entry, Hypothesis_Entry):
185 SO_MorSM = myStudy.FindObjectID( Mesh_Or_SubMesh_Entry )
186 SO_Hypothesis = myStudy.FindObjectID( Hypothesis_Entry )
188 if SO_MorSM is not None and SO_Hypothesis is not None :
190 #Find or Create Applied Hypothesis root
191 res, AHR = SO_MorSM.FindSubObject (Tag_RefOnAppliedHypothesis)
192 if AHR is None or res == 0:
193 AHR = myStudyBuilder.NewObjectToTag (SO_MorSM, Tag_RefOnAppliedHypothesis)
194 aName = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributeName")
196 # The same name as in SMESH_Mesh_i::AddHypothesis() ##################
197 aName.SetValue("Applied hypotheses")
199 aSelAttr = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributeSelectable")
200 aSelAttr.SetSelectable(0)
201 aPixmap = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributePixMap")
202 aPixmap.SetPixMap( "mesh_tree_hypo.png" )
204 # VSR: added temporarily - reference to applied hypothesis is published automatically by the engine
206 it = myStudy.NewChildIterator(AHR)
208 res, Ref = it.Value().ReferencedObject()
209 if res and Ref is not None and Ref.GetID() == Hypothesis_Entry :
212 # VSR ######################################################################
214 SO = myStudyBuilder.NewObject(AHR)
215 myStudyBuilder.Addreference (SO,SO_Hypothesis)
217 #------------------------------------------------------------
218 def SetAlgorithms(Mesh_Or_SubMesh_Entry, Algorithms_Entry):
219 SO_MorSM = myStudy.FindObjectID( Mesh_Or_SubMesh_Entry )
220 SO_Algorithms = myStudy.FindObjectID( Algorithms_Entry )
221 if SO_MorSM != None and SO_Algorithms != None :
222 #Find or Create Applied Algorithms root
223 res, AHR = SO_MorSM.FindSubObject (Tag_RefOnAppliedAlgorithms)
224 if AHR is None or res == 0:
225 AHR = myStudyBuilder.NewObjectToTag (SO_MorSM, Tag_RefOnAppliedAlgorithms)
226 aName = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributeName")
228 # The same name as in SMESH_Mesh_i::AddHypothesis() ##################
229 aName.SetValue("Applied algorithms")
231 aSelAttr = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributeSelectable")
232 aSelAttr.SetSelectable(0)
233 aPixmap = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributePixMap")
234 aPixmap.SetPixMap( "mesh_tree_algo.png" )
236 # VSR: added temporarily - reference to applied hypothesis is published automatically by the engine
238 it = myStudy.NewChildIterator(AHR)
240 res, Ref = it.Value().ReferencedObject()
241 if res and Ref is not None and Ref.GetID() == Algorithms_Entry :
244 # VSR ######################################################################
246 SO = myStudyBuilder.NewObject(AHR)
247 myStudyBuilder.Addreference (SO,SO_Algorithms)
250 #------------------------------------------------------------
251 def UnSetHypothesis( Applied_Hypothesis_Entry ):
252 SO_Applied_Hypothesis = myStudy.FindObjectID( Applied_Hypothesis_Entry )
253 if SO_Applied_Hypothesis :
254 myStudyBuilder.RemoveObject(SO_Applied_Hypothesis)
257 #------------------------------------------------------------
258 def AddSubMesh ( SO_Mesh_Entry, SM_IOR, ST):
259 # VSR: added temporarily - objects are published automatically by the engine
260 aSO = myStudy.FindObjectIOR( SM_IOR )
263 # VSR ######################################################################
265 SO_Mesh = myStudy.FindObjectID( SO_Mesh_Entry )
268 if ST == ShapeType["COMPSOLID"] :
269 Tag_Shape = Tag_SubMeshOnSolid
270 Name = "SubMeshes on Solid"
271 elif ST == ShapeType["FACE"] :
272 Tag_Shape = Tag_SubMeshOnFace
273 Name = "SubMeshes on Face"
274 elif ST == ShapeType["EDGE"] :
275 Tag_Shape = Tag_SubMeshOnEdge
276 Name = "SubMeshes on Edge"
277 elif ST == ShapeType["VERTEX"] :
278 Tag_Shape = Tag_SubMeshOnVertex
279 Name = "SubMeshes on Vertex"
281 Tag_Shape = Tag_SubMeshOnCompound
282 Name = "SubMeshes on Compound"
284 res, SubmeshesRoot = SO_Mesh.FindSubObject (Tag_Shape)
285 if SubmeshesRoot is None or res == 0:
286 SubmeshesRoot = myStudyBuilder.NewObjectToTag (SO_Mesh, Tag_Shape)
287 aName = myStudyBuilder.FindOrCreateAttribute(SubmeshesRoot, "AttributeName")
289 aSelAttr = myStudyBuilder.FindOrCreateAttribute(SubmeshesRoot, "AttributeSelectable")
290 aSelAttr.SetSelectable(0)
292 SO = myStudyBuilder.NewObject (SubmeshesRoot)
293 anIOR = myStudyBuilder.FindOrCreateAttribute(SO, "AttributeIOR")
294 anIOR.SetValue(SM_IOR)
299 #------------------------------------------------------------
300 def AddSubMeshOnShape (Mesh_Entry, GeomShape_Entry, SM_IOR, ST) :
301 # VSR: added temporarily - objects are published automatically by the engine
302 aSO = myStudy.FindObjectIOR( SM_IOR )
305 # VSR ######################################################################
306 SO_GeomShape = myStudy.FindObjectID( GeomShape_Entry )
307 if SO_GeomShape != None :
308 SM_Entry = AddSubMesh (Mesh_Entry,SM_IOR,ST)
309 SO_SM = myStudy.FindObjectID( SM_Entry )
312 SetShape (GeomShape_Entry, SM_Entry)
318 #------------------------------------------------------------
319 def SetName(Entry, Name):
320 SO = myStudy.FindObjectID( Entry )
322 aName = myStudyBuilder.FindOrCreateAttribute(SO, "AttributeName")