mirror of
https://git.salome-platform.org/gitpub/modules/smesh.git
synced 2025-03-07 01:55:36 +05:00
PR: distributed geom and smesh scripts: first step
This commit is contained in:
parent
79f0b7244b
commit
1b57300c82
@ -52,8 +52,8 @@ salomeinclude_HEADERS = \
|
|||||||
SMESH.hxx
|
SMESH.hxx
|
||||||
|
|
||||||
# Scripts to be installed.
|
# Scripts to be installed.
|
||||||
dist_salomescript_DATA= \
|
#dist_salomescript_DATA= \
|
||||||
smeshpy.py
|
# smeshpy.py
|
||||||
|
|
||||||
# Libraries targets
|
# Libraries targets
|
||||||
|
|
||||||
|
@ -22,8 +22,8 @@
|
|||||||
# Python API for the standard meshing plug-in module.
|
# Python API for the standard meshing plug-in module.
|
||||||
|
|
||||||
from smesh_algorithm import Mesh_Algorithm
|
from smesh_algorithm import Mesh_Algorithm
|
||||||
from smesh import AssureGeomPublished, IsEqual, ParseParameters
|
from smeshDC import AssureGeomPublished, IsEqual, ParseParameters
|
||||||
from smesh import GetName, TreatHypoStatus
|
from smeshDC import GetName, TreatHypoStatus
|
||||||
from smeshDC import Mesh
|
from smeshDC import Mesh
|
||||||
|
|
||||||
import StdMeshers
|
import StdMeshers
|
||||||
|
@ -33,15 +33,16 @@ import salome
|
|||||||
from salome import *
|
from salome import *
|
||||||
|
|
||||||
import geompy
|
import geompy
|
||||||
|
import SMESH, SALOMEDS
|
||||||
import smeshDC
|
import smeshDC
|
||||||
from smeshDC import *
|
#from smeshDC import *
|
||||||
|
|
||||||
# retrieve SMESH engine in try/except block
|
# retrieve SMESH engine in try/except block
|
||||||
# to avoid problems in some cases, e.g. when generating documentation
|
# to avoid problems in some cases, e.g. when generating documentation
|
||||||
try:
|
try:
|
||||||
# get instance of class smeshDC
|
# get instance of class smeshDC
|
||||||
smesh = salome.lcc.FindOrLoadComponent( "FactoryServer", "SMESH" )
|
engineSmesh = salome.lcc.FindOrLoadComponent( "FactoryServer", "SMESH" )
|
||||||
smesh.init_smesh( salome.myStudy, geompy.geom )
|
smesh = smeshDC.smeshInstance(salome.myStudy, engineSmesh)
|
||||||
except:
|
except:
|
||||||
smesh = None
|
smesh = None
|
||||||
pass
|
pass
|
||||||
@ -81,3 +82,30 @@ if smesh:
|
|||||||
globals()[k] = getattr( smesh, k )
|
globals()[k] = getattr( smesh, k )
|
||||||
del k
|
del k
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
print """
|
||||||
|
===============================================================================
|
||||||
|
WARNING: |
|
||||||
|
Usage of smesh.py is deprecated in SALOME V7.2! |
|
||||||
|
smesh.py will be removed in a future version! |
|
||||||
|
TODO: |
|
||||||
|
The following changes in your scripts are required to avoid this message: |
|
||||||
|
|
|
||||||
|
replace |
|
||||||
|
------- |
|
||||||
|
|
|
||||||
|
import smesh, SMESH, SALOMEDS |
|
||||||
|
smesh.SetCurrentStudy(theStudy) |
|
||||||
|
|
|
||||||
|
with |
|
||||||
|
---- |
|
||||||
|
|
|
||||||
|
import smeshDC, SMESH, SALOMEDS |
|
||||||
|
smesh = smeshDC.smeshInstance(theStudy) |
|
||||||
|
|
|
||||||
|
you also need to modify some lines where smeshDC is used instead of smesh: |
|
||||||
|
|
|
||||||
|
algo=smesh.xxxx ==> algo.smeshDC.xxxx |
|
||||||
|
|
|
||||||
|
===============================================================================
|
||||||
|
"""
|
||||||
|
@ -16,11 +16,11 @@
|
|||||||
#
|
#
|
||||||
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
|
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
|
||||||
#
|
#
|
||||||
# File : smesh.py
|
# File : smeshDC.py
|
||||||
# Author : Francis KLOSS, OCC
|
# Author : Francis KLOSS, OCC
|
||||||
# Module : SMESH
|
# Module : SMESH
|
||||||
|
|
||||||
## @package smesh
|
## @package smeshDC
|
||||||
# Python API for SALOME %Mesh module
|
# Python API for SALOME %Mesh module
|
||||||
|
|
||||||
## @defgroup l1_auxiliary Auxiliary methods and structures
|
## @defgroup l1_auxiliary Auxiliary methods and structures
|
||||||
@ -91,6 +91,7 @@ from smesh_algorithm import Mesh_Algorithm
|
|||||||
|
|
||||||
import SALOME
|
import SALOME
|
||||||
import SALOMEDS
|
import SALOMEDS
|
||||||
|
import os
|
||||||
|
|
||||||
## @addtogroup l1_auxiliary
|
## @addtogroup l1_auxiliary
|
||||||
## @{
|
## @{
|
||||||
@ -271,17 +272,16 @@ def AssureGeomPublished(mesh, geom, name=''):
|
|||||||
mesh.geompyD.addToStudyInFather( mesh.geom, geom, name )
|
mesh.geompyD.addToStudyInFather( mesh.geom, geom, name )
|
||||||
return
|
return
|
||||||
|
|
||||||
## Return the first vertex of a geomertical edge by ignoring orienation
|
## Return the first vertex of a geometrical edge by ignoring orientation
|
||||||
def FirstVertexOnCurve(edge):
|
def FirstVertexOnCurve(edge):
|
||||||
from geompy import SubShapeAll, ShapeType, KindOfShape, PointCoordinates
|
vv = geompyDC.SubShapeAll( edge, geompyDC.ShapeType["VERTEX"])
|
||||||
vv = SubShapeAll( edge, ShapeType["VERTEX"])
|
|
||||||
if not vv:
|
if not vv:
|
||||||
raise TypeError, "Given object has no vertices"
|
raise TypeError, "Given object has no vertices"
|
||||||
if len( vv ) == 1: return vv[0]
|
if len( vv ) == 1: return vv[0]
|
||||||
info = KindOfShape(edge)
|
info = geompyDC.KindOfShape(edge)
|
||||||
xyz = info[1:4] # coords of the first vertex
|
xyz = info[1:4] # coords of the first vertex
|
||||||
xyz1 = PointCoordinates( vv[0] )
|
xyz1 = geompyDC.PointCoordinates( vv[0] )
|
||||||
xyz2 = PointCoordinates( vv[1] )
|
xyz2 = geompyDC.PointCoordinates( vv[1] )
|
||||||
dist1, dist2 = 0,0
|
dist1, dist2 = 0,0
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
dist1 += abs( xyz[i] - xyz1[i] )
|
dist1 += abs( xyz[i] - xyz1[i] )
|
||||||
@ -294,8 +294,53 @@ def FirstVertexOnCurve(edge):
|
|||||||
# end of l1_auxiliary
|
# end of l1_auxiliary
|
||||||
## @}
|
## @}
|
||||||
|
|
||||||
# All methods of this class are accessible directly from the smesh.py package.
|
|
||||||
class smeshDC(SMESH._objref_SMESH_Gen):
|
# Warning: smeshInst is a singleton
|
||||||
|
smeshInst = None
|
||||||
|
engine = None
|
||||||
|
doLcc = False
|
||||||
|
|
||||||
|
class smeshDC(object, SMESH._objref_SMESH_Gen):
|
||||||
|
|
||||||
|
def __new__(cls):
|
||||||
|
global engine
|
||||||
|
global smeshInst
|
||||||
|
global doLcc
|
||||||
|
print "__new__", engine, smeshInst, doLcc
|
||||||
|
|
||||||
|
if smeshInst is None:
|
||||||
|
# smesh engine is either retrieved from engine, or created
|
||||||
|
smeshInst = engine
|
||||||
|
# Following test avoids a recursive loop
|
||||||
|
if doLcc:
|
||||||
|
if smeshInst is not None:
|
||||||
|
# smesh engine not created: existing engine found
|
||||||
|
doLcc = False
|
||||||
|
if doLcc:
|
||||||
|
doLcc = False
|
||||||
|
# FindOrLoadComponent called:
|
||||||
|
# 1. CORBA resolution of server
|
||||||
|
# 2. the __new__ method is called again
|
||||||
|
print "smeshInst = lcc.FindOrLoadComponent ", engine, smeshInst, doLcc
|
||||||
|
smeshInst = salome.lcc.FindOrLoadComponent( "FactoryServer", "SMESH" )
|
||||||
|
else:
|
||||||
|
# FindOrLoadComponent not called
|
||||||
|
if smeshInst is None:
|
||||||
|
# smeshDC instance is created from lcc.FindOrLoadComponent
|
||||||
|
print "smeshInst = super(smeshDC,cls).__new__(cls) ", engine, smeshInst, doLcc
|
||||||
|
smeshInst = super(smeshDC,cls).__new__(cls)
|
||||||
|
else:
|
||||||
|
# smesh engine not created: existing engine found
|
||||||
|
print "existing ", engine, smeshInst, doLcc
|
||||||
|
pass
|
||||||
|
|
||||||
|
return smeshInst
|
||||||
|
|
||||||
|
return smeshInst
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
print "__init__"
|
||||||
|
SMESH._objref_SMESH_Gen.__init__(self)
|
||||||
|
|
||||||
## Dump component to the Python script
|
## Dump component to the Python script
|
||||||
# This method overrides IDL function to allow default values for the parameters.
|
# This method overrides IDL function to allow default values for the parameters.
|
||||||
@ -314,7 +359,8 @@ class smeshDC(SMESH._objref_SMESH_Gen):
|
|||||||
|
|
||||||
## Sets the current study and Geometry component
|
## Sets the current study and Geometry component
|
||||||
# @ingroup l1_auxiliary
|
# @ingroup l1_auxiliary
|
||||||
def init_smesh(self,theStudy,geompyD):
|
def init_smesh(self,theStudy,geompyD = None):
|
||||||
|
print "init_smesh"
|
||||||
self.SetCurrentStudy(theStudy,geompyD)
|
self.SetCurrentStudy(theStudy,geompyD)
|
||||||
|
|
||||||
## Creates an empty Mesh. This mesh can have an underlying geometry.
|
## Creates an empty Mesh. This mesh can have an underlying geometry.
|
||||||
@ -436,8 +482,8 @@ class smeshDC(SMESH._objref_SMESH_Gen):
|
|||||||
def SetCurrentStudy( self, theStudy, geompyD = None ):
|
def SetCurrentStudy( self, theStudy, geompyD = None ):
|
||||||
#self.SetCurrentStudy(theStudy)
|
#self.SetCurrentStudy(theStudy)
|
||||||
if not geompyD:
|
if not geompyD:
|
||||||
import geompy
|
import geompyDC
|
||||||
geompyD = geompy.geom
|
geompyD = geompyDC.geom
|
||||||
pass
|
pass
|
||||||
self.geompyD=geompyD
|
self.geompyD=geompyD
|
||||||
self.SetGeomEngine(geompyD)
|
self.SetGeomEngine(geompyD)
|
||||||
@ -950,6 +996,19 @@ import omniORB
|
|||||||
omniORB.registerObjref(SMESH._objref_SMESH_Gen._NP_RepositoryId, smeshDC)
|
omniORB.registerObjref(SMESH._objref_SMESH_Gen._NP_RepositoryId, smeshDC)
|
||||||
|
|
||||||
|
|
||||||
|
def smeshInstance( study, instance=None):
|
||||||
|
global engine
|
||||||
|
global smeshInst
|
||||||
|
global doLcc
|
||||||
|
engine = instance
|
||||||
|
if engine is None:
|
||||||
|
doLcc = True
|
||||||
|
smeshInst = smeshDC()
|
||||||
|
assert isinstance(smeshInst,smeshDC), "Smesh engine class is %s but should be smeshDC.smeshDC. Import smeshmapi before creating the instance."%smeshInst.__class__
|
||||||
|
smeshInst.init_smesh(study)
|
||||||
|
return smeshInst
|
||||||
|
|
||||||
|
|
||||||
# Public class: Mesh
|
# Public class: Mesh
|
||||||
# ==================
|
# ==================
|
||||||
|
|
||||||
@ -1015,6 +1074,7 @@ class Mesh:
|
|||||||
for attrName in dir(self):
|
for attrName in dir(self):
|
||||||
attr = getattr( self, attrName )
|
attr = getattr( self, attrName )
|
||||||
if isinstance( attr, algoCreator ):
|
if isinstance( attr, algoCreator ):
|
||||||
|
print "algoCreator ", attrName
|
||||||
setattr( self, attrName, attr.copy( self ))
|
setattr( self, attrName, attr.copy( self ))
|
||||||
|
|
||||||
## Initializes the Mesh object from an instance of SMESH_Mesh interface
|
## Initializes the Mesh object from an instance of SMESH_Mesh interface
|
||||||
@ -4264,3 +4324,32 @@ class hypMethodWrapper:
|
|||||||
raise ValueError, detail # wrong variable name
|
raise ValueError, detail # wrong variable name
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
for pluginName in os.environ[ "SMESH_MeshersList" ].split( ":" ):
|
||||||
|
#
|
||||||
|
print "pluginName: ", pluginName
|
||||||
|
pluginName += "DC"
|
||||||
|
try:
|
||||||
|
exec( "from %s import *" % pluginName )
|
||||||
|
except Exception, e:
|
||||||
|
print "Exception while loading %s: %s" % ( pluginName, e )
|
||||||
|
continue
|
||||||
|
exec( "import %s" % pluginName )
|
||||||
|
plugin = eval( pluginName )
|
||||||
|
print " plugin:" , str(plugin)
|
||||||
|
|
||||||
|
# add methods creating algorithms to Mesh
|
||||||
|
for k in dir( plugin ):
|
||||||
|
if k[0] == '_': continue
|
||||||
|
algo = getattr( plugin, k )
|
||||||
|
print " algo:", str(algo)
|
||||||
|
if type( algo ).__name__ == 'classobj' and hasattr( algo, "meshMethod" ):
|
||||||
|
print " meshMethod:" , str(algo.meshMethod)
|
||||||
|
if not hasattr( Mesh, algo.meshMethod ):
|
||||||
|
setattr( Mesh, algo.meshMethod, algoCreator() )
|
||||||
|
pass
|
||||||
|
getattr( Mesh, algo.meshMethod ).add( algo )
|
||||||
|
pass
|
||||||
|
pass
|
||||||
|
pass
|
||||||
|
del pluginName
|
||||||
|
@ -166,7 +166,7 @@ class Mesh_Algorithm:
|
|||||||
|
|
||||||
## Gets the name of the algorithm
|
## Gets the name of the algorithm
|
||||||
def GetName(self):
|
def GetName(self):
|
||||||
from smesh import GetName
|
from smeshDC import GetName
|
||||||
return GetName(self.algo)
|
return GetName(self.algo)
|
||||||
|
|
||||||
## Sets the name to the algorithm
|
## Sets the name to the algorithm
|
||||||
@ -190,7 +190,7 @@ class Mesh_Algorithm:
|
|||||||
|
|
||||||
## Private method
|
## Private method
|
||||||
def Assign(self, algo, mesh, geom):
|
def Assign(self, algo, mesh, geom):
|
||||||
from smesh import AssureGeomPublished, TreatHypoStatus, GetName
|
from smeshDC import AssureGeomPublished, TreatHypoStatus, GetName
|
||||||
if geom is None:
|
if geom is None:
|
||||||
raise RuntimeError, "Attemp to create " + algo + " algoritm on None shape"
|
raise RuntimeError, "Attemp to create " + algo + " algoritm on None shape"
|
||||||
self.mesh = mesh
|
self.mesh = mesh
|
||||||
@ -221,7 +221,7 @@ class Mesh_Algorithm:
|
|||||||
## Private method
|
## Private method
|
||||||
def Hypothesis (self, hyp, args=[], so="libStdMeshersEngine.so",
|
def Hypothesis (self, hyp, args=[], so="libStdMeshersEngine.so",
|
||||||
UseExisting=0, CompareMethod=""):
|
UseExisting=0, CompareMethod=""):
|
||||||
from smesh import TreatHypoStatus, GetName
|
from smeshDC import TreatHypoStatus, GetName
|
||||||
hypo = None
|
hypo = None
|
||||||
if UseExisting:
|
if UseExisting:
|
||||||
if CompareMethod == "": CompareMethod = self.CompareHyp
|
if CompareMethod == "": CompareMethod = self.CompareHyp
|
||||||
@ -310,7 +310,7 @@ class Mesh_Algorithm:
|
|||||||
# into a list acceptable to SetReversedEdges() of some 1D hypotheses
|
# into a list acceptable to SetReversedEdges() of some 1D hypotheses
|
||||||
# @ingroup l3_hypos_1dhyps
|
# @ingroup l3_hypos_1dhyps
|
||||||
def ReversedEdgeIndices(self, reverseList):
|
def ReversedEdgeIndices(self, reverseList):
|
||||||
from smesh import FirstVertexOnCurve
|
from smeshDC import FirstVertexOnCurve
|
||||||
resList = []
|
resList = []
|
||||||
geompy = self.mesh.geompyD
|
geompy = self.mesh.geompyD
|
||||||
for i in reverseList:
|
for i in reverseList:
|
||||||
|
Loading…
Reference in New Issue
Block a user