Delete "activeStudy" in python scripts

This commit is contained in:
imn 2016-11-14 15:25:39 +03:00
parent 3acd170447
commit df81dd7563
4 changed files with 23 additions and 34 deletions

View File

@ -21,13 +21,11 @@
import salome_pluginsmanager import salome_pluginsmanager
def t_shape_fluid(context): def t_shape_fluid():
activeStudy = context.study
#from salome.geom.t_shape import t_shape_builder #from salome.geom.t_shape import t_shape_builder
from salome.geom.t_shape import t_shape_dialog from salome.geom.t_shape import t_shape_dialog
dialog = t_shape_dialog.getDialog() dialog = t_shape_dialog.getDialog()
dialog.setContext(context)
dialog.show() dialog.show()
salome_pluginsmanager.AddFunction('T shape fluid', salome_pluginsmanager.AddFunction('T shape fluid',

View File

@ -29,13 +29,11 @@ import time
geompy = None geompy = None
def demidisk(study, r1, a1, roty=0, solid_thickness=0): def demidisk(r1, a1, roty=0, solid_thickness=0):
if solid_thickness < 1e-7: if solid_thickness < 1e-7:
with_solid = False with_solid = False
else: else:
with_solid = True with_solid = True
#geompy = geomBuilder.New(study)
O = geompy.MakeVertex(0, 0, 0) O = geompy.MakeVertex(0, 0, 0)
OX = geompy.MakeVectorDXDYDZ(1, 0, 0) OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
@ -101,8 +99,7 @@ def demidisk(study, r1, a1, roty=0, solid_thickness=0):
else: else:
return v, l, arc1, part1 return v, l, arc1, part1
def pointsProjetes(study, vref, face): def pointsProjetes(vref, face):
#geompy = geomBuilder.New(study)
vface = geompy.ExtractShapes(face, geompy.ShapeType["VERTEX"], True) vface = geompy.ExtractShapes(face, geompy.ShapeType["VERTEX"], True)
vord = range(len(vref)) vord = range(len(vref))
plan = geompy.MakePlaneThreePnt(vref[0], vref[1], vref[-1], 10000) plan = geompy.MakePlaneThreePnt(vref[0], vref[1], vref[-1], 10000)
@ -114,8 +111,7 @@ def pointsProjetes(study, vref, face):
vord[dist[0][1]] = vface[i] vord[dist[0][1]] = vface[i]
return vord return vord
def arcsProjetes(study, vf, face): def arcsProjetes(vf, face):
#geompy = geomBuilder.New(study)
lface = geompy.ExtractShapes(face, geompy.ShapeType["EDGE"], True) lface = geompy.ExtractShapes(face, geompy.ShapeType["EDGE"], True)
lord = range(3) lord = range(3)
ends = [vf[1], vf[6], vf[7], vf[3]] ends = [vf[1], vf[6], vf[7], vf[3]]
@ -130,7 +126,7 @@ def arcsProjetes(study, vf, face):
pass pass
return lord return lord
def build_shape(study, r1, r2, h1, h2, solid_thickness=0, progressBar=None ): def build_shape(r1, r2, h1, h2, solid_thickness=0, progressBar=None ):
""" Builds the final shape """ """ Builds the final shape """
if progressBar is not None: if progressBar is not None:
@ -143,7 +139,7 @@ def build_shape(study, r1, r2, h1, h2, solid_thickness=0, progressBar=None ):
with_solid = True with_solid = True
global geompy global geompy
geompy = geomBuilder.New(study) geompy = geomBuilder.New(salome.myStudy)
O = geompy.MakeVertex(0, 0, 0) O = geompy.MakeVertex(0, 0, 0)
OX = geompy.MakeVectorDXDYDZ(1, 0, 0) OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
@ -157,7 +153,7 @@ def build_shape(study, r1, r2, h1, h2, solid_thickness=0, progressBar=None ):
a1 = 45.0*(1.0 -ratio)/seuilmax a1 = 45.0*(1.0 -ratio)/seuilmax
# --- Creation of the jonction faces # --- Creation of the jonction faces
[faci, sect45, arc1, l1, lord90, lord45, edges, arcextru] = jonction(study, r1, r2,\ [faci, sect45, arc1, l1, lord90, lord45, edges, arcextru] = jonction(r1, r2,\
h1, h2, a1) h1, h2, a1)
if progressBar is not None: if progressBar is not None:
progressBar.addSteps(2) progressBar.addSteps(2)
@ -167,7 +163,7 @@ def build_shape(study, r1, r2, h1, h2, solid_thickness=0, progressBar=None ):
# The same code is executed again with different external radiuses in order # The same code is executed again with different external radiuses in order
# to get the needed faces and edges to build the solid layer of the pipe # to get the needed faces and edges to build the solid layer of the pipe
[faci_ext, sect45_ext, arc1_ext, l1_ext, \ [faci_ext, sect45_ext, arc1_ext, l1_ext, \
lord90_ext, lord45_ext, edges_ext, arcextru_ext] = jonction(study, r1 + solid_thickness, r2 + solid_thickness,\ lord90_ext, lord45_ext, edges_ext, arcextru_ext] = jonction(r1 + solid_thickness, r2 + solid_thickness,\
h1, h2, a1) h1, h2, a1)
faces_jonction_ext = [] faces_jonction_ext = []
for i,l in enumerate(lord90): for i,l in enumerate(lord90):
@ -246,7 +242,7 @@ def build_shape(study, r1, r2, h1, h2, solid_thickness=0, progressBar=None ):
# --- Partie inférieure # --- Partie inférieure
v3, l3, arc3, part3 = demidisk(study, r1, a1, 180.0, solid_thickness) v3, l3, arc3, part3 = demidisk(r1, a1, 180.0, solid_thickness)
extru3 = geompy.MakePrismVecH(part3, OX, h1) extru3 = geompy.MakePrismVecH(part3, OX, h1)
# --- Symétrie # --- Symétrie
@ -264,11 +260,10 @@ def build_shape(study, r1, r2, h1, h2, solid_thickness=0, progressBar=None ):
return final return final
def jonction(study, r1, r2, h1, h2, a1): def jonction(r1, r2, h1, h2, a1):
""" Builds the jonction faces and """ Builds the jonction faces and
returns what is needed to build the whole pipe returns what is needed to build the whole pipe
""" """
#geompy = geomBuilder.New(study)
O = geompy.MakeVertex(0, 0, 0) O = geompy.MakeVertex(0, 0, 0)
OX = geompy.MakeVectorDXDYDZ(1, 0, 0) OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
@ -276,8 +271,8 @@ def jonction(study, r1, r2, h1, h2, a1):
OZ = geompy.MakeVectorDXDYDZ(0, 0, 1) OZ = geompy.MakeVectorDXDYDZ(0, 0, 1)
# --- sections droites des deux demi cylindres avec le partionnement # --- sections droites des deux demi cylindres avec le partionnement
v1, l1, arc1, part1 = demidisk(study, r1, a1, 0.) v1, l1, arc1, part1 = demidisk(r1, a1, 0.)
v2, l2, arc2, part2 = demidisk(study, r2, a1, 90.0) v2, l2, arc2, part2 = demidisk(r2, a1, 90.0)
# --- extrusion des sections --> demi cylindres de travail, pour en extraire les sections utilisées au niveau du Té # --- extrusion des sections --> demi cylindres de travail, pour en extraire les sections utilisées au niveau du Té
# et enveloppe cylindrique du cylindre principal # et enveloppe cylindrique du cylindre principal
@ -299,13 +294,13 @@ def jonction(study, r1, r2, h1, h2, a1):
# --- liste ordonnée des points projetés sur les deux sections # --- liste ordonnée des points projetés sur les deux sections
vord45 = pointsProjetes(study, v1, sect45) vord45 = pointsProjetes(v1, sect45)
vord90 = pointsProjetes(study, v2, sect90) vord90 = pointsProjetes(v2, sect90)
# --- identification des projections des trois arcs de cercle, sur les deux sections. # --- identification des projections des trois arcs de cercle, sur les deux sections.
lord45 = arcsProjetes(study, vord45, sect45) lord45 = arcsProjetes(vord45, sect45)
lord90 = arcsProjetes(study, vord90, sect90) lord90 = arcsProjetes(vord90, sect90)
# --- abaissement des quatre points centraux de la section du cylindre secondaire # --- abaissement des quatre points centraux de la section du cylindre secondaire
@ -390,8 +385,7 @@ def jonction(study, r1, r2, h1, h2, a1):
def test_t_shape_builder(): def test_t_shape_builder():
"""For testing purpose""" """For testing purpose"""
salome.salome_init() salome.salome_init()
theStudy = salome.myStudy geompy = geomBuilder.New(salome.myStudy)
geompy = geomBuilder.New(theStudy)
for r1 in [1., 100.]: for r1 in [1., 100.]:
for r2 in [0.9*r1, 0.5*r1, 0.1*r1, 0.05*r1]: for r2 in [0.9*r1, 0.5*r1, 0.1*r1, 0.05*r1]:
for thickness in [r1/100., r1/10., r1/2.]: for thickness in [r1/100., r1/10., r1/2.]:
@ -399,7 +393,7 @@ def test_t_shape_builder():
h1 = r1 * 2.0 h1 = r1 * 2.0
h2 = h1 h2 = h1
try: try:
res = build_shape(theStudy, r1, r2, h1, h2, thickness) res = build_shape(r1, r2, h1, h2, thickness)
geompy.addToStudy(res, "res_%f_%f_%f"%(r1,r2, thickness)) geompy.addToStudy(res, "res_%f_%f_%f"%(r1,r2, thickness))
except: except:
print "problem with res_%f_%f_%f"%(r1,r2, thickness) print "problem with res_%f_%f_%f"%(r1,r2, thickness)

View File

@ -39,9 +39,6 @@ class TShapeDialog(Ui_Dialog,QWidget):
self.dsb_smallRadius.setValue(40.0) self.dsb_smallRadius.setValue(40.0)
self.dsb_bigHeight.setValue(80.0) self.dsb_bigHeight.setValue(80.0)
self.dsb_smallHeight.setValue(80.0) self.dsb_smallHeight.setValue(80.0)
def setContext(self, context):
self._activeStudy = context.study
def accept(self): def accept(self):
from salome.geom.t_shape import t_shape_progress from salome.geom.t_shape import t_shape_progress
@ -50,10 +47,10 @@ class TShapeDialog(Ui_Dialog,QWidget):
self.close() self.close()
r1, r2, h1, h2, thickness = self.getData() r1, r2, h1, h2, thickness = self.getData()
#QMessageBox.about(None, "Building in progress", "building shape, please be patient") #QMessageBox.about(None, "Building in progress", "building shape, please be patient")
#shape = t_shape_builder.build_shape(activeStudy, r1, r2, h1, h2, thickness) #shape = t_shape_builder.build_shape(r1, r2, h1, h2, thickness)
shapeBuilder = t_shape_progress.t_shape_progress() shapeBuilder = t_shape_progress.t_shape_progress()
shape = shapeBuilder.run(self._activeStudy, r1, r2, h1, h2, thickness) shape = shapeBuilder.run(r1, r2, h1, h2, thickness)
entry = xalome.addToStudy(self._activeStudy, shape, "T_shape_fluid" ) entry = xalome.addToStudy(shape, "T_shape_fluid" )
xalome.displayShape(entry) xalome.displayShape(entry)
def getData(self): def getData(self):

View File

@ -30,8 +30,8 @@ class t_shape_progress(QProgressDialog):
QProgressDialog.__init__(self, "t_shape fluid build", "stop", 0, self._nmaxSteps, parent, Qt.Tool) QProgressDialog.__init__(self, "t_shape fluid build", "stop", 0, self._nmaxSteps, parent, Qt.Tool)
self.show() self.show()
def run(self, activeStudy, r1, r2, h1, h2, thickness): def run(self, r1, r2, h1, h2, thickness):
shape = t_shape_builder.build_shape(activeStudy, r1, r2, h1, h2, thickness, self) shape = t_shape_builder.build_shape(r1, r2, h1, h2, thickness, self)
self.setValue(self._nmaxSteps) self.setValue(self._nmaxSteps)
return shape return shape