1 # Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License.
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 # File : batchmode_smesh.py
23 # Author : Oksana TCHEBANOVA
27 from batchmode_salome import *
28 from batchmode_geompy import ShapeType
31 #--------------------------------------------------------------------------
32 modulecatalog = naming_service.Resolve("/Kernel/ModulCatalog")
34 smesh = lcc.FindOrLoadComponent("FactoryServer", "SMESH")
35 myStudyBuilder = myStudy.NewBuilder()
37 if myStudyBuilder is None:
38 raise RuntimeError, " Null myStudyBuilder"
40 father = myStudy.FindComponent("SMESH")
42 father = myStudyBuilder.NewComponent("SMESH")
43 FName = myStudyBuilder.FindOrCreateAttribute(father, "AttributeName")
44 Comp = modulecatalog.GetComponent("SMESH")
45 FName.SetValue(Comp._get_componentusername())
46 aPixmap = myStudyBuilder.FindOrCreateAttribute(father, "AttributePixMap")
47 aPixmap.SetPixMap("ICON_OBJBROWSER_Mesh")
49 myStudyBuilder.DefineComponentInstance(father,smesh)
51 mySComponentMesh = father._narrow(SALOMEDS.SComponent)
53 Tag_HypothesisRoot = 1
54 Tag_AlgorithmsRoot = 2
57 Tag_RefOnAppliedHypothesis = 2
58 Tag_RefOnAppliedAlgorithms = 3
60 Tag_SubMeshOnVertex = 4
63 Tag_SubMeshOnSolid = 7
64 Tag_SubMeshOnCompound = 8
66 Tag = {"HypothesisRoot":1,"AlgorithmsRoot":2,"RefOnShape":1,"RefOnAppliedHypothesis":2,"RefOnAppliedAlgorithms":3,"SubMeshOnVertex":4,"SubMeshOnEdge":5,"SubMeshOnFace":6,"SubMeshOnSolid":7,"SubMeshOnCompound":8}
68 #------------------------------------------------------------
71 #------------------------------------------------------------
73 # VSR: added temporarily - objects are published automatically by the engine
74 aSO = myStudy.FindObjectIOR( IOR )
77 # VSR ######################################################################
79 res,HypothesisRoot = mySComponentMesh.FindSubObject ( Tag_HypothesisRoot )
80 if HypothesisRoot is None or res == 0:
81 HypothesisRoot = myStudyBuilder.NewObjectToTag(mySComponentMesh, Tag_HypothesisRoot)
82 aName = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributeName")
83 aName.SetValue("Hypotheses")
84 aPixmap = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributePixMap")
85 aPixmap.SetPixMap( "mesh_tree_hypo.png" )
86 aSelAttr = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributeSelectable")
87 aSelAttr.SetSelectable(0)
89 res, AlgorithmsRoot = mySComponentMesh.FindSubObject (Tag_AlgorithmsRoot)
90 if AlgorithmsRoot is None or res == 0:
91 AlgorithmsRoot = myStudyBuilder.NewObjectToTag (mySComponentMesh, Tag_AlgorithmsRoot)
92 aName = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributeName")
93 aName.SetValue("Algorithms")
94 aPixmap = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributePixMap")
95 aPixmap.SetPixMap( "mesh_tree_algo.png" )
96 aSelAttr = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributeSelectable")
97 aSelAttr.SetSelectable(0)
99 HypothesisRoot = HypothesisRoot._narrow(SALOMEDS.SObject)
100 newMesh = myStudyBuilder.NewObject(mySComponentMesh)
101 aPixmap = myStudyBuilder.FindOrCreateAttribute(newMesh, "AttributePixMap")
102 aPixmap.SetPixMap( "mesh_tree_mesh.png" )
103 anIOR = myStudyBuilder.FindOrCreateAttribute(newMesh, "AttributeIOR")
105 return newMesh.GetID()
107 #------------------------------------------------------------
108 def AddNewHypothesis(IOR):
109 # VSR: added temporarily - objects are published automatically by the engine
110 aSO = myStudy.FindObjectIOR( IOR )
113 # VSR ######################################################################
115 res, HypothesisRoot = mySComponentMesh.FindSubObject (Tag_HypothesisRoot)
116 if HypothesisRoot is None or res == 0:
117 HypothesisRoot = myStudyBuilder.NewObjectToTag (mySComponentMesh, Tag_HypothesisRoot)
118 aName = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributeName")
119 aName.SetValue("Hypotheses")
120 aSelAttr = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributeSelectable")
121 aSelAttr.SetSelectable(0)
122 aPixmap = myStudyBuilder.FindOrCreateAttribute(HypothesisRoot, "AttributePixMap")
123 aPixmap.SetPixMap( "mesh_tree_hypo.png" )
126 newHypo = myStudyBuilder.NewObject(HypothesisRoot)
127 aPixmap = myStudyBuilder.FindOrCreateAttribute(newHypo, "AttributePixMap")
128 H = orb.string_to_object(IOR)
130 aPixmap.SetPixMap( "mesh_tree_hypo.png_" + aType )
131 anIOR = myStudyBuilder.FindOrCreateAttribute(newHypo, "AttributeIOR")
133 return newHypo.GetID()
135 #------------------------------------------------------------
136 def AddNewAlgorithms(IOR):
137 # VSR: added temporarily - objects are published automatically by the engine
138 aSO = myStudy.FindObjectIOR( IOR )
141 # VSR ######################################################################
143 res, AlgorithmsRoot = mySComponentMesh.FindSubObject (Tag_AlgorithmsRoot)
144 if AlgorithmsRoot is None or res == 0:
145 AlgorithmsRoot = myStudyBuilde.NewObjectToTag (mySComponentMesh, Tag_AlgorithmsRoot)
146 aName = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributeName")
147 aName.SetValue("Algorithms")
148 aSelAttr = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributeSelectable")
149 aSelAttr.SetSelectable(0)
150 aPixmap = myStudyBuilder.FindOrCreateAttribute(AlgorithmsRoot, "AttributePixMap")
151 aPixmap.SetPixMap( "mesh_tree_algo.png" )
154 newHypo = myStudyBuilder.NewObject(AlgorithmsRoot)
155 aPixmap = myStudyBuilder.FindOrCreateAttribute(newHypo, "AttributePixMap")
156 aPixmap = anAttr._narrow(SALOMEDS.AttributePixMap)
157 H = orb.string_to_object(IOR)
158 aType = H.GetName(); #QString in fact
159 aPixmap.SetPixMap( "mesh_tree_algo.png_" + aType )
160 anIOR = myStudyBuilder.FindOrCreateAttribute(newHypo, "AttributeIOR")
162 return newHypo.GetID()
165 #------------------------------------------------------------
166 def SetShape(ShapeEntry, MeshEntry):
167 SO_MorSM = myStudy.FindObjectID( MeshEntry )
168 SO_GeomShape = myStudy.FindObjectID( ShapeEntry )
170 if SO_MorSM is not None and SO_GeomShape is not None :
171 # VSR: added temporarily - shape reference is published automatically by the engine
172 res, Ref = SO_MorSM.FindSubObject( Tag_RefOnShape )
175 # VSR ######################################################################
177 SO = myStudyBuilder.NewObjectToTag (SO_MorSM, Tag_RefOnShape)
178 myStudyBuilder.Addreference (SO,SO_GeomShape)
181 #------------------------------------------------------------
182 def SetHypothesis(Mesh_Or_SubMesh_Entry, Hypothesis_Entry):
183 SO_MorSM = myStudy.FindObjectID( Mesh_Or_SubMesh_Entry )
184 SO_Hypothesis = myStudy.FindObjectID( Hypothesis_Entry )
186 if SO_MorSM is not None and SO_Hypothesis is not None :
188 #Find or Create Applied Hypothesis root
189 res, AHR = SO_MorSM.FindSubObject (Tag_RefOnAppliedHypothesis)
190 if AHR is None or res == 0:
191 AHR = myStudyBuilder.NewObjectToTag (SO_MorSM, Tag_RefOnAppliedHypothesis)
192 aName = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributeName")
194 # The same name as in SMESH_Mesh_i::AddHypothesis() ##################
195 aName.SetValue("Applied hypotheses")
197 aSelAttr = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributeSelectable")
198 aSelAttr.SetSelectable(0)
199 aPixmap = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributePixMap")
200 aPixmap.SetPixMap( "mesh_tree_hypo.png" )
202 # VSR: added temporarily - reference to applied hypothesis is published automatically by the engine
204 it = myStudy.NewChildIterator(AHR)
206 res, Ref = it.Value().ReferencedObject()
207 if res and Ref is not None and Ref.GetID() == Hypothesis_Entry :
210 # VSR ######################################################################
212 SO = myStudyBuilder.NewObject(AHR)
213 myStudyBuilder.Addreference (SO,SO_Hypothesis)
215 #------------------------------------------------------------
216 def SetAlgorithms(Mesh_Or_SubMesh_Entry, Algorithms_Entry):
217 SO_MorSM = myStudy.FindObjectID( Mesh_Or_SubMesh_Entry )
218 SO_Algorithms = myStudy.FindObjectID( Algorithms_Entry )
219 if SO_MorSM != None and SO_Algorithms != None :
220 #Find or Create Applied Algorithms root
221 res, AHR = SO_MorSM.FindSubObject (Tag_RefOnAppliedAlgorithms)
222 if AHR is None or res == 0:
223 AHR = myStudyBuilder.NewObjectToTag (SO_MorSM, Tag_RefOnAppliedAlgorithms)
224 aName = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributeName")
226 # The same name as in SMESH_Mesh_i::AddHypothesis() ##################
227 aName.SetValue("Applied algorithms")
229 aSelAttr = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributeSelectable")
230 aSelAttr.SetSelectable(0)
231 aPixmap = myStudyBuilder.FindOrCreateAttribute(AHR, "AttributePixMap")
232 aPixmap.SetPixMap( "mesh_tree_algo.png" )
234 # VSR: added temporarily - reference to applied hypothesis is published automatically by the engine
236 it = myStudy.NewChildIterator(AHR)
238 res, Ref = it.Value().ReferencedObject()
239 if res and Ref is not None and Ref.GetID() == Algorithms_Entry :
242 # VSR ######################################################################
244 SO = myStudyBuilder.NewObject(AHR)
245 myStudyBuilder.Addreference (SO,SO_Algorithms)
248 #------------------------------------------------------------
249 def UnSetHypothesis( Applied_Hypothesis_Entry ):
250 SO_Applied_Hypothesis = myStudy.FindObjectID( Applied_Hypothesis_Entry )
251 if SO_Applied_Hypothesis :
252 myStudyBuilder.RemoveObject(SO_Applied_Hypothesis)
255 #------------------------------------------------------------
256 def AddSubMesh ( SO_Mesh_Entry, SM_IOR, ST):
257 # VSR: added temporarily - objects are published automatically by the engine
258 aSO = myStudy.FindObjectIOR( SM_IOR )
261 # VSR ######################################################################
263 SO_Mesh = myStudy.FindObjectID( SO_Mesh_Entry )
266 if ST == ShapeType["COMPSOLID"] :
267 Tag_Shape = Tag_SubMeshOnSolid
268 Name = "SubMeshes on Solid"
269 elif ST == ShapeType["FACE"] :
270 Tag_Shape = Tag_SubMeshOnFace
271 Name = "SubMeshes on Face"
272 elif ST == ShapeType["EDGE"] :
273 Tag_Shape = Tag_SubMeshOnEdge
274 Name = "SubMeshes on Edge"
275 elif ST == ShapeType["VERTEX"] :
276 Tag_Shape = Tag_SubMeshOnVertex
277 Name = "SubMeshes on Vertex"
279 Tag_Shape = Tag_SubMeshOnCompound
280 Name = "SubMeshes on Compound"
282 res, SubmeshesRoot = SO_Mesh.FindSubObject (Tag_Shape)
283 if SubmeshesRoot is None or res == 0:
284 SubmeshesRoot = myStudyBuilder.NewObjectToTag (SO_Mesh, Tag_Shape)
285 aName = myStudyBuilder.FindOrCreateAttribute(SubmeshesRoot, "AttributeName")
287 aSelAttr = myStudyBuilder.FindOrCreateAttribute(SubmeshesRoot, "AttributeSelectable")
288 aSelAttr.SetSelectable(0)
290 SO = myStudyBuilder.NewObject (SubmeshesRoot)
291 anIOR = myStudyBuilder.FindOrCreateAttribute(SO, "AttributeIOR")
292 anIOR.SetValue(SM_IOR)
297 #------------------------------------------------------------
298 def AddSubMeshOnShape (Mesh_Entry, GeomShape_Entry, SM_IOR, ST) :
299 # VSR: added temporarily - objects are published automatically by the engine
300 aSO = myStudy.FindObjectIOR( SM_IOR )
303 # VSR ######################################################################
304 SO_GeomShape = myStudy.FindObjectID( GeomShape_Entry )
305 if SO_GeomShape != None :
306 SM_Entry = AddSubMesh (Mesh_Entry,SM_IOR,ST)
307 SO_SM = myStudy.FindObjectID( SM_Entry )
310 SetShape (GeomShape_Entry, SM_Entry)
316 #------------------------------------------------------------
317 def SetName(Entry, Name):
318 SO = myStudy.FindObjectID( Entry )
320 aName = myStudyBuilder.FindOrCreateAttribute(SO, "AttributeName")