From 79e096a9cf620f2d1c16d47381f99d757af47932 Mon Sep 17 00:00:00 2001 From: Robin DEGEILH Date: Thu, 6 Apr 2017 11:02:36 +0200 Subject: [PATCH] bug corrections in Zcracks for V83 --- src/Tools/ZCracksPlug/__init__.py | 16 ++-- src/Tools/ZCracksPlug/casTests/launchCas.py | 10 +-- src/Tools/ZCracksPlug/main.py | 87 ++++++++----------- src/Tools/ZCracksPlug/output.py | 4 +- src/Tools/ZCracksPlug/utilityFunctions.py | 93 ++------------------- 5 files changed, 60 insertions(+), 150 deletions(-) diff --git a/src/Tools/ZCracksPlug/__init__.py b/src/Tools/ZCracksPlug/__init__.py index 61ea883f4..4ae994c94 100644 --- a/src/Tools/ZCracksPlug/__init__.py +++ b/src/Tools/ZCracksPlug/__init__.py @@ -2,15 +2,20 @@ import sys, os, shutil, pickle, tempfile import main, genereCrack, Zset import utilityFunctions as uF +os.environ['QT_QPA_PLATFORM_PLUGIN_PATH']=os.path.join(os.environ['QTDIR'],'plugins','platforms') + +if 'MESHGEMSHOME' in os.environ: + meshgemsdir=os.environ['MESHGEMSHOME'] + if len(meshgemsdir) > 0: + meshgems=meshgemsdir.split(os.sep)[-1] + uF.removeFromSessionPath('LD_LIBRARY_PATH', meshgems) + #commande="/bin/bash -c ""source $HOME/zebulon/Z8.6.6_NEW/do_config_bash""" #os.system(commande) def IHM(): - try: - from PyQt5.QtWidgets import QApplication - except: - from PyQt4.QtGui import QApplication + from PyQt5.QtWidgets import QApplication app = QApplication(sys.argv) myapp = main.ShipHolderApplication() @@ -31,8 +36,7 @@ def SCRIPT(dataFile=None, data=None, dim=3, names=None): print data - tmpdir=tempfile.mkdtemp() - uF.removeFromSessionPath('LD_LIBRARY_PATH', 'Meshgems-2111') + tmpdir=tempfile.mkdtemp(prefix='tmpZcracks') if names==None: names={'saneGeoName':'salome_sane', 'crackGeoName':'salome_crack', 'crackedGeoName':'salome_cracked'} diff --git a/src/Tools/ZCracksPlug/casTests/launchCas.py b/src/Tools/ZCracksPlug/casTests/launchCas.py index e4a4d163c..4672776ec 100644 --- a/src/Tools/ZCracksPlug/casTests/launchCas.py +++ b/src/Tools/ZCracksPlug/casTests/launchCas.py @@ -18,13 +18,13 @@ import string #tmpdir = "/local00/home/B27118/projets/Zcracks/Zcracks/casTests/tmpdir" #if not os.path.isdir(tmpdir): os.mkdir(tmpdir) -tmpdir=tempfile.mktemp(prefix='tmpZcracks') +tmpdir=tempfile.mkdtemp(prefix='tmpZcracks') print "tmpdir=", tmpdir -meshgemsdir=os.environ('MESHGEMSHOME') -if len(meshgemsdir) > 0: - meshgems=string.split(meshgemsdir,os.sep)[-1] - uF.removeFromSessionPath('LD_LIBRARY_PATH', meshgems) +#meshgemsdir=os.environ('MESHGEMSHOME') +#if len(meshgemsdir) > 0: + #meshgems=string.split(meshgemsdir,os.sep)[-1] + #uF.removeFromSessionPath('LD_LIBRARY_PATH', meshgems) def LAUNCH(listCas=[]): if type(listCas)!=list: listCas=[listCas] diff --git a/src/Tools/ZCracksPlug/main.py b/src/Tools/ZCracksPlug/main.py index e4b3e526d..4d3384de0 100644 --- a/src/Tools/ZCracksPlug/main.py +++ b/src/Tools/ZCracksPlug/main.py @@ -1,13 +1,9 @@ import sys, pickle, tempfile, shutil from os import path, getpid, environ, remove, system -try: - from PyQt5.QtCore import * - from PyQt5.QtGui import * - from PyQt5.QtWidgets import * -except: - from PyQt4.QtCore import * - from PyQt4.QtGui import * +from PyQt5.QtCore import * +from PyQt5.QtGui import * +from PyQt5.QtWidgets import * import utilityFunctions as uF import genereCrack, Zset, output, zcracks_ui @@ -21,8 +17,6 @@ from zcracks_ui import Ui_Zui # --------------------- -uF.removeFromSessionPath('LD_LIBRARY_PATH', 'Meshgems-2111') - def stringToFloat(string, typ=float): if str(string).replace(' ','')=='': out=[] @@ -78,25 +72,6 @@ class ShipHolderApplication(QGroupBox): self.verbose=1 - #self.connect(self.ui.CBQuad, SIGNAL("toggled(bool)"),self.pressQuad) - #self.connect(self.ui.btReset, SIGNAL("clicked()"),self.pressReset) - #self.connect(self.ui.btCancel, SIGNAL("clicked()"),self.pressCancel) - #self.connect(self.ui.btApply, SIGNAL("clicked()"),self.pressApply) - #self.connect(self.ui.btApplyClose, SIGNAL("clicked()"),self.pressApplyClose) - #self.connect(self.ui.btLoad, SIGNAL("clicked()"),self.pressCharger) - #self.connect(self.ui.btSave, SIGNAL("clicked()"),self.pressSauver) - #self.connect(self.ui.btLoadCracked, SIGNAL("clicked()"),self.pressLoadCracked) - #self.connect(self.ui.btLoadSane, SIGNAL("clicked()"),self.pressLoadSane) - - #self.connect(self.ui.btGrVol, SIGNAL("clicked()"),self.pressLoadGroupVOL) - #self.connect(self.ui.btGrFace, SIGNAL("clicked()"),self.pressLoadGroupFACE) - #self.connect(self.ui.btGrEdge, SIGNAL("clicked()"),self.pressLoadGroupEDGE) - #self.connect(self.ui.btGrNode, SIGNAL("clicked()"),self.pressLoadGroupNODE) - #self.connect(self.ui.btGrAll, SIGNAL("clicked()"),self.pressLoadGroupALL) - #self.connect(self.ui.btVisu, SIGNAL("clicked()"),self.pressVisu) - - #self.connect(self.ui.CBAdvanced, SIGNAL("toggled(bool)"),self.pressAdvanced) - self.ui.CBQuad.toggled.connect(self.pressQuad) self.ui.btReset.clicked.connect(self.pressReset) self.ui.btCancel.clicked.connect(self.pressCancel) @@ -144,9 +119,9 @@ class ShipHolderApplication(QGroupBox): def pressQuad(self): if self.ui.CBQuad.isChecked(): self.ui.CBBarsoum.setEnabled(True) - self.ui.valGradation.setText(QString('2.3')) + self.ui.valGradation.setText('2.3') else: - self.ui.valGradation.setText(QString('1.3')) + self.ui.valGradation.setText('1.3') self.ui.CBBarsoum.setChecked(False) self.ui.CBBarsoum.setEnabled(False) @@ -162,10 +137,10 @@ class ShipHolderApplication(QGroupBox): tab=onglet.findChildren(QTableWidget)[0] for irow in range(tab.rowCount()): if tab.item(irow,0) != None: - tab.item(irow,0).setText(QString('')) - self.ui.valGradation.setText(QString('1.3')) - self.ui.valLayers.setText(QString('5')) - self.ui.valIterations.setText(QString('2')) + tab.item(irow,0).setText('') + self.ui.valGradation.setText('1.3') + self.ui.valLayers.setText('6') + self.ui.valIterations.setText('2') self.ui.CBIs2D.setChecked(False) self.ui.CBRefine.setChecked(False) @@ -257,7 +232,7 @@ class ShipHolderApplication(QGroupBox): fileNames = fileDiag.selectedFiles() filedef = fileNames[0] filedef = addExtension(str(filedef), 'med') - self.ui.valCrackedName.setText(QString(filedef)) + self.ui.valCrackedName.setText(filedef) def pressLoadSane(self): @@ -268,7 +243,7 @@ class ShipHolderApplication(QGroupBox): if fileDiag.exec_() : fileNames = fileDiag.selectedFiles() filedef = fileNames[0] - self.ui.valSaneName.setText(QString(filedef)) + self.ui.valSaneName.setText(filedef) def pressCharger(self): @@ -287,23 +262,15 @@ class ShipHolderApplication(QGroupBox): for cont, obj in enumerate(self.lineEditObjects): if self.lineEditTypes[cont] in [float, int]: - obj.setText(QString(self.data['TXT'+self.lineEditNames[cont]])) + obj.setText(self.data['TXT'+self.lineEditNames[cont]]) else: - obj.setText(QString(self.data[self.lineEditNames[cont]])) + obj.setText(self.data[self.lineEditNames[cont]]) self.ui.CBQuad.setChecked(True if 'quad' in self.data.keys() and self.data['quad'] else False) self.ui.CBBarsoum.setChecked(True if 'barsoum' in self.data.keys() and self.data['barsoum'] else False) self.ui.CBIs2D.setChecked(True if 'is2D' in self.data.keys() and self.data['is2D'] else False) self.ui.CBRefine.setChecked(True if 'refine' in self.data.keys() and self.data['refine'] else False) - - - - - #if self.data['quad']: self.ui.CBQuad.setChecked(True) - #if self.data['barsoum']: self.ui.CBBarsoum.setChecked(True) - #if self.data['is2D']: self.ui.CBIs2D.setChecked(True) - #if self.data['refine']: self.ui.CBRefine.setChecked(True) self.setTableParameters() @@ -451,7 +418,7 @@ class ShipHolderApplication(QGroupBox): if tab.item(irow,0) == None: item = QTableWidgetItem() tab.setItem(irow, 0, item) - tab.item(irow,0).setText(QString(self.data['TXTcrack'][str(self.ui.tabWidget.tabText(iongl))][str(label)])) + tab.item(irow,0).setText(self.data['TXTcrack'][str(self.ui.tabWidget.tabText(iongl))][str(label)]) if str(self.ui.tabWidget.tabText(iongl)) == self.data['TXTcrack']['actif']: self.ui.tabWidget.setCurrentWidget(onglet) @@ -475,19 +442,19 @@ class ShipHolderApplication(QGroupBox): for group in objetSain.GetGroups(): if (self.GroupToLoad in ['VOL','ALL']) and (group.GetType()==SMESH.VOLUME): - groupsVOL+=group.GetName().replace(' ','')+" " + groupsVOL+=self.cleanGroupName(group) nGr+=1 if (self.GroupToLoad in ['FACE','ALL']) and (group.GetType()==SMESH.FACE): - groupsFAC+=group.GetName().replace(' ','')+" " + groupsFAC+=self.cleanGroupName(group) nGr+=1 if (self.GroupToLoad in ['EDGE','ALL']) and (group.GetType()==SMESH.EDGE): - groupsEDG+=group.GetName().replace(' ','')+" " + groupsEDG+=self.cleanGroupName(group) nGr+=1 if (self.GroupToLoad in ['NODE','ALL']) and (group.GetType()==SMESH.NODE): - groupsNOD+=group.GetName().replace(' ','')+" " + groupsNOD+=self.cleanGroupName(group) nGr+=1 if groupsVOL!='': self.ui.valGrVol.setText(groupsVOL) @@ -503,6 +470,24 @@ class ShipHolderApplication(QGroupBox): remove(f) except: pass + + def cleanGroupName(self, group): + name=group.GetName() + while name.endswith(' '): name=name[:-1] + if ' ' in name: + message('A','%s group has a space in its name --> ignored' %name) + return('') + else: + return(name+" ") + + def checkNamesSpaces(self, names): + if type(names) is str: names=[names] + ok=True + for n in names: + if ' ' in n: + message('E','%s has a space in its name, please remove it' %n, goOn=True) + ok=False + return(ok) # --------------------------------- diff --git a/src/Tools/ZCracksPlug/output.py b/src/Tools/ZCracksPlug/output.py index 8a316b0dd..00b31f59f 100644 --- a/src/Tools/ZCracksPlug/output.py +++ b/src/Tools/ZCracksPlug/output.py @@ -22,9 +22,9 @@ class output(): pass f = open(self.tmpFile,'w') f.write('\n ------------------------------\n') - f.write(' | BIENVENU DANS L\'INTERFACE |\n') + f.write(' | BIENVENUE DANS L\'INTERFACE |\n') f.write(' | ZCRACKS DE SALOME |\n') - f.write(' | VERSION ALPHA |\n') + f.write(' | VERSION BETA |\n') f.write(' ------------------------------\n\n') f.close() diff --git a/src/Tools/ZCracksPlug/utilityFunctions.py b/src/Tools/ZCracksPlug/utilityFunctions.py index 36db72580..9571fd8d9 100644 --- a/src/Tools/ZCracksPlug/utilityFunctions.py +++ b/src/Tools/ZCracksPlug/utilityFunctions.py @@ -178,7 +178,13 @@ def extendElsets(meshFile, outFile=None): smesh = smeshBuilder.New(theStudy) ([mesh], status) = smesh.CreateMeshesFromMED(meshFile) - + + if mesh.NbVolumes()>0: + case2D=False + mesh.Reorient2DBy3D( [ mesh ], mesh, 1 ) + else: + case2D=True + mesh=cleanGroups(mesh) # Node color status @@ -339,91 +345,6 @@ def getMaxAspectRatio(tmpdir): return(float(maxAR)) -#def extendElsets(meshFile): - #if not path.isfile(meshFile): - #message('E','Mesh med file is not valid') - #return(-1) - - #import SMESH, salome - ##salome.salome_init() - #theStudy = salome.myStudy - #from salome.smesh import smeshBuilder - #smesh = smeshBuilder.New(theStudy) - - #([mesh], status) = smesh.CreateMeshesFromMED(meshFile) - - ## Node color status - #nodeList=mesh.GetNodesId() - #colorList=[0]*len(nodeList) - - ## Init using SIDE0 SIDE1 - #for group in mesh.GetGroups(): - #if group.GetType()==SMESH.FACE : - #color=0 - #if group.GetName()[0:4]=='SIDE0' : - #color=1 - #elif group.GetName()[0:4]=='SIDE1' : - #color=2 - #else : continue - ## Get faces - #faces=group.GetIDs() - ## Set faces nodes to given color - #for face_id in faces : - #for face_node_id in mesh.GetElemNodes(face_id) : - #colorList[face_node_id-1]=color - - ## Propagates color using elem connectivity - ## Always propagates max color - #volElemList=mesh.GetElementsByType(SMESH.VOLUME) - #ifChanged=True - #while ifChanged : - #ifChanged=False - #minColor=100 - #maxColor=0 - #for elemId in volElemList: - #for elemNodeId in mesh.GetElemNodes(elemId) : - #nodeColor=colorList[elemNodeId-1] - #if nodeColormaxColor : maxColor=nodeColor - #if minColor!=maxColor : - #ifChanged = True - #for elemNodeId in mesh.GetElemNodes(elemId) : - #colorList[elemNodeId-1]=maxColor - - #velem0 = [] - #velem1 = [] - #for elemId in volElemList: - #elemNodesId=mesh.GetElemNodes(elemId) - #elemColor=colorList[elemNodesId[0]-1] - #if(elemColor==1) : velem0.append(elemId) - #if(elemColor==2) : velem1.append(elemId) - - #mesh.MakeGroupByIds('SIDE_co',SMESH.VOLUME,velem0) - #mesh.MakeGroupByIds('SIDE_ext',SMESH.VOLUME,velem1) - - #surfElemList=mesh.GetElementsByType(SMESH.FACE) - #selem0 = [] - #selem1 = [] - #nbelem0=0 - #nbelem1=0 - - #for elemId in surfElemList: - #elemNodesId=mesh.GetElemNodes(elemId) - #elemColor=colorList[elemNodesId[0]-1] - #if(elemColor==1) : selem0.append(elemId) - #if(elemColor==2) : selem1.append(elemId) - - #mesh.MakeGroupByIds('SIDE_co',SMESH.FACE,selem0) - #mesh.MakeGroupByIds('SIDE_ext',SMESH.FACE,selem1) - - #maxAR=0. - #for elem in volElemList: - #maxAR=max(mesh.GetAspectRatio(elem),maxAR) - #for elem in surfElemList: - #maxAR=max(mesh.GetAspectRatio(elem),maxAR) - - #mesh.ExportMED(meshFile, 0, SMESH.MED_V2_2, 1, None ,1) - #return(maxAR) def removeFromSessionPath(envVar, patern): -- 2.39.2