1 # -*- coding: latin-1 -*-
3 # Copyright (C) 2009-2013 CEA/DEN, EDF R&D
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 # Francis KLOSS - 2011-2013 - CEA-Saclay, DEN, DM2S, SFME, LGLS, F-91191 Gif-sur-Yvette, France
23 # =============================================================================================
28 from HEXABLOCK_ORB import *
29 import HEXABLOCKPlugin
33 # Gives the component name
34 # -----------------------------------------------------------
39 # Load HEXABLOCK componant
40 # ------------------------
42 component = salome.lcc.FindOrLoadComponent("FactoryServer", moduleName())
43 component = component._narrow(HEXABLOCK_Gen)
45 for k in dir(component):
48 globals()[k] = getattr(component, k)
53 # -----------------------------------------------------------
58 # Add laws on propagations based on min or max segment length
59 # -----------------------------------------------------------
61 def addLaws(doc, lg, lgmax=True):
63 n = doc.countPropagation()
65 p = doc.getPropagation(i)
70 for e in p.getEdges():
71 a = e.getAssociations()
75 vag = vam.getAssociation()
81 vax, vay, vaz = geompy.PointCoordinates(vag)
84 vbg = vbm.getAssociation()
90 vbx, vby, vbz = geompy.PointCoordinates(vbg)
92 l = ( (vbx-vax)**2 + (vby-vay)**2 + (vbz-vaz)**2 )**0.5
97 le, su, vo = geompy.BasicProperties(gdf.geomObj)
98 l += le * (gdf.fin - gdf.debut)
100 if ( lgmax and l>m ) or ( (not lgmax) and l<m ):
104 if lgmax and (int(nn) != nn):
112 law = doc.addLaw("u_"+str(nn), nn)
117 # Display informations about a document
118 # -------------------------------------
120 def dump(doc, mesh=None, full=False):
122 hn = doc.countUsedHexa()
123 print "Model dump: number of hexas: ", hn
124 for hi in xrange(hn):
125 hh = doc.getUsedHexa(hi)
126 print " hexa: ", hi, "name: ", hh.getName()
129 fa = ff.getAssociations()
130 print " quadrangle: ", fi, "name: ", ff.getName(), " associated: ", fa!=[]
133 ea = ee.getAssociations()
134 print " edge: ", ei, "name: ", ee.getName(), " associated: ", ea!=[]
136 vv = ee.getVertex(vi)
137 va = vv.getAssociation()
138 print " vertex: ", vi, "name: ", vv.getName(), " associated: ", va!=None
139 print " model: x= ", vv.getX(), " y= ", vv.getY(), " z= ", vv.getZ()
141 x, y, z = geompy.PointCoordinates(va)
142 print " assoc: x= ", x, " y= ", y, " z= ", z
144 uv = doc.countUsedVertex()
145 ue = doc.countUsedEdge()
146 uq = doc.countUsedQuad()
147 uh = doc.countUsedHexa()
149 print "Model vertices number: ", uv
150 print "Model edges number: ", ue
151 print "Model quadrangles number: ", uq
152 print "Model blocks number: ", uh
155 print "Mesh nodes number: ", mesh.NbNodes()
156 print "Mesh segments number: ", mesh.NbEdges()
157 print "Mesh quadrangles number: ", mesh.NbQuadrangles()
158 print "Mesh hexas number: ", mesh.NbHexas()
160 return uv, ue, uq, uh
165 def mesh(doc, name=None, dim=3, container="FactoryServer"):
166 study = salome.myStudy
168 if type(doc) == type(""):
169 doc = component.findDocument (doc)
171 #### shape = doc.getShape()
172 #### if shape == None:
173 #### shape = geompy.MakeBox(0, 0, 0, 1, 1, 1)
175 shape = geompy.MakeBox(0, 0, 0, 1, 1, 1)
176 if (name == None) or (name == ""):
179 geompy.addToStudy(shape, name)
180 comp_smesh = salome.lcc.FindOrLoadComponent(container, "SMESH")
181 comp_smesh.init_smesh(study, geompy.geom)
182 meshexa = comp_smesh.Mesh(shape)
184 so = "libHexaBlockEngine.so"
186 algo = smesh.SMESH._objref_SMESH_Gen.CreateHypothesis(comp_smesh, "HEXABLOCK_3D", so)
187 meshexa.mesh.AddHypothesis(shape, algo)
189 hypo = smesh.SMESH._objref_SMESH_Gen.CreateHypothesis(comp_smesh, "HEXABLOCK_Parameters", so)
190 meshexa.mesh.AddHypothesis(shape, hypo)
192 hypo.SetDocument(doc)
193 hypo.SetDimension(dim)
199 # Get a document from the current study
200 # -------------------------------------
202 def getFromStudy(entry):
203 study = salome.myStudy
204 sobject = study.FindObjectID(entry)
206 print " **** Entry ", entry, " is undefined"
209 builder = study.NewBuilder()
210 ok, attname = builder.FindAttribute(sobject, "AttributeName")
211 docname = attname.Value()
212 doc = component.findDocument(docname)
214 print " **** Entry ", entry, " doesn't correspond to an HexaBlock Document"
218 # Find or create HexaBlock Study Component
219 # -------------------------------------
221 def findOrCreateComponent( study, builder ):
222 father = study.FindComponent( moduleName() )
224 father = builder.NewComponent( moduleName() )
225 attr = builder.FindOrCreateAttribute( father, "AttributeName" )
226 attr.SetValue( "HexaBlock" )
227 attr = builder.FindOrCreateAttribute( father, "AttributePixMap" )
228 ### attr.SetPixMap( "ICON_OBJBROWSER_HEXABLOCK" )
229 attr.SetPixMap( "ICO_MODULE_HEXABLOCK_SMALL" )
230 builder.DefineComponentInstance( father, getEngine() )
234 # Add a document in the current study
235 # -------------------------------------
239 print " *** addToStudy : Bad Document Pointer"
242 study = salome.myStudy
243 builder = study.NewBuilder()
244 father = findOrCreateComponent( study, builder )
245 name = doc.getName ()
247 present = study.FindObjectByName(name, moduleName())
249 print " *** addToStudy : Document ", name, "is already in the study"
252 object = builder.NewObject( father )
253 attr = builder.FindOrCreateAttribute( object, "AttributeName" )
254 attr.SetValue( name )
255 return object.GetID ()