From 8fb7cb1a010fc361256db5905c6bcd1623244041 Mon Sep 17 00:00:00 2001 From: Paul RASCLE Date: Sun, 10 Jan 2016 23:13:10 +0100 Subject: [PATCH] progress bar on t_shape_builder plugin --- src/Tools/CMakeLists.txt | 2 +- src/Tools/geom_plugins.py | 7 +++-- src/Tools/t_shape/CMakeLists.txt | 1 + src/Tools/t_shape/t_shape_builder.py | 33 ++++++++++++++++++++--- src/Tools/t_shape/t_shape_progress.py | 39 +++++++++++++++++++++++++++ 5 files changed, 76 insertions(+), 6 deletions(-) create mode 100644 src/Tools/t_shape/t_shape_progress.py diff --git a/src/Tools/CMakeLists.txt b/src/Tools/CMakeLists.txt index 435c5fdae..741357566 100644 --- a/src/Tools/CMakeLists.txt +++ b/src/Tools/CMakeLists.txt @@ -21,7 +21,7 @@ ADD_SUBDIRECTORY(t_shape) # scripts / static SET(plugin_SCRIPTS - geom_plugins.py + geom_plugins.py ) # --- rules --- diff --git a/src/Tools/geom_plugins.py b/src/Tools/geom_plugins.py index d9ed81f41..395961595 100644 --- a/src/Tools/geom_plugins.py +++ b/src/Tools/geom_plugins.py @@ -22,8 +22,9 @@ import salome_pluginsmanager def t_shape_fluid(context): - 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_progress import xalome from PyQt4.QtGui import QMessageBox activeStudy = context.study @@ -37,7 +38,9 @@ def t_shape_fluid(context): if dialog.wasOk(): r1, r2, h1, h2, thickness = dialog.getData() #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(activeStudy, r1, r2, h1, h2, thickness) + shapeBuilder = t_shape_progress.t_shape_progress() + shape = shapeBuilder.run(activeStudy, r1, r2, h1, h2, thickness) entry = xalome.addToStudy(activeStudy, shape, "T_shape_fluid" ) xalome.displayShape(entry) #if dialog.wasOk(): diff --git a/src/Tools/t_shape/CMakeLists.txt b/src/Tools/t_shape/CMakeLists.txt index 98f580077..e3fb538c3 100644 --- a/src/Tools/t_shape/CMakeLists.txt +++ b/src/Tools/t_shape/CMakeLists.txt @@ -27,6 +27,7 @@ SET(plugin_SCRIPTS t_shape_builder.py t_shape_dialog.py t_shape_dialog.ui + t_shape_progress.py ) # uic files / to be processed by pyuic diff --git a/src/Tools/t_shape/t_shape_builder.py b/src/Tools/t_shape/t_shape_builder.py index d4230cf23..872899ae5 100644 --- a/src/Tools/t_shape/t_shape_builder.py +++ b/src/Tools/t_shape/t_shape_builder.py @@ -111,7 +111,7 @@ def arcsProjetes(study, vf, face): pass return lord -def build_shape(study, r1, r2, h1, h2, solid_thickness=0): +def build_shape(study, r1, r2, h1, h2, solid_thickness=0, progressBar=None ): """ Builds the final shape """ if solid_thickness < 1e-7: @@ -136,6 +136,9 @@ def build_shape(study, r1, r2, h1, h2, solid_thickness=0): # --- Creation of the jonction faces [faci, sect45, arc1, l1, lord90, lord45, edges, arcextru] = jonction(study, r1, r2,\ h1, h2, a1) + if progressBar is not None: + progressBar.addSteps(1) + if with_solid: # 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 @@ -150,11 +153,17 @@ def build_shape(study, r1, r2, h1, h2, solid_thickness=0): for i,l in enumerate(lord45): faces_jonction_ext.append(geompy.MakeQuad2Edges(lord45[i],lord45_ext[i])) + if progressBar is not None: + progressBar.addSteps(1) + # --- extrusion droite des faces de jonction, pour reconstituer les demi cylindres if with_solid: sect45 = geompy.MakeCompound([sect45]+faces_jonction_ext[-3:]) sect45 = geompy.MakeGlueEdges(sect45, 1e-7) + if progressBar is not None: + progressBar.addSteps(1) + extru1 = geompy.MakePrismVecH(sect45, OX, h1+10) faces_coupe = faci[5:] @@ -163,6 +172,9 @@ def build_shape(study, r1, r2, h1, h2, solid_thickness=0): base2 = geompy.MakePartition(faces_coupe, [], [], [], geompy.ShapeType["FACE"], 0, [], 0, True) extru2 = geompy.MakePrismVecH(base2, OZ, h2) + if progressBar is not None: + progressBar.addSteps(1) + # --- partition et coupe if with_solid: @@ -171,24 +183,36 @@ def build_shape(study, r1, r2, h1, h2, solid_thickness=0): demiDisque = geompy.MakeFaceWires([arc1, l1[0]], 1) demiCylindre = geompy.MakePrismVecH(demiDisque, OX, h1) + if progressBar is not None: + progressBar.addSteps(1) + box = geompy.MakeBox(0, -2*(r1+h1), -2*(r1+h1), 2*(r1+h1), 2*(r1+h1), 2*(r1+h1)) rot = geompy.MakeRotation(box, OY, 45*math.pi/180.0) # NOTE: The following Cut takes almost half of the total execution time garder = geompy.MakeCutList(demiCylindre, [extru2, rot], True) + if progressBar is not None: + progressBar.addSteps(10) + faces_coupe = faci[:5] if with_solid: faces_coupe.extend(faces_jonction_ext[-7:]) raccord = geompy.MakePartition([garder], faces_coupe + [arcextru], [], [], geompy.ShapeType["SOLID"], 0, [], 0, True) assemblage = geompy.MakeCompound([raccord, extru1, extru2]) assemblage = geompy.MakeGlueFaces(assemblage, 1e-7) - + + if progressBar is not None: + progressBar.addSteps(2) + box = geompy.MakeBox(-1, -(r1+r2+2*solid_thickness), -1, h1, r1+r2+2*solid_thickness, h2) # NOTE: This operation takes about 1/4 of the total execution time final = geompy.MakeCommonList([box, assemblage], True) + if progressBar is not None: + progressBar.addSteps(5) + # --- Partie inférieure v3, l3, arc3, part3 = demidisk(study, r1, a1, 180.0, solid_thickness) @@ -200,7 +224,10 @@ def build_shape(study, r1, r2, h1, h2, solid_thickness=0): plane = geompy.MakePlane(O,OX,2000) compound_mirrored = geompy.MakeMirrorByPlane(compound, plane) final = geompy.MakeCompound([compound, compound_mirrored]) - + + if progressBar is not None: + progressBar.addSteps(1) + return final diff --git a/src/Tools/t_shape/t_shape_progress.py b/src/Tools/t_shape/t_shape_progress.py new file mode 100644 index 000000000..cc4533b16 --- /dev/null +++ b/src/Tools/t_shape/t_shape_progress.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2010-2014 CEA/DEN, EDF R&D, OPEN CASCADE +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# Author : Renaud Nédélec (OpenCascade S.A.S) + +from salome.geom.t_shape import t_shape_builder +from PyQt4.QtGui import QProgressDialog + +class t_shape_progress(QProgressDialog): + _totSteps = 0 + _nmaxSteps = 20 + + def __init__(self): + QProgressDialog.__init__(self, "t_shape fluid build", "stop", 0, self._nmaxSteps) + + def run(self, activeStudy, r1, r2, h1, h2, thickness): + shape = t_shape_builder.build_shape(activeStudy, r1, r2, h1, h2, thickness, self) + self.setValue(self._nmaxSteps) + return shape + + def addSteps(self, nbSteps): + self._totSteps += nbSteps + self.setValue(self._totSteps) -- 2.39.2