From 8e19277fa67c24032c1c78a0064df3ada2c8b6bb Mon Sep 17 00:00:00 2001 From: FARGETTON-LECRIVAIN Florestan Date: Mon, 20 Nov 2023 10:27:05 +0100 Subject: [PATCH 1/3] fix: case no box checked #21 --- compute_values.py | 245 ++++++++++++++++++++++----------------------- myMmgPlugDialog.py | 197 +++++++++++++++++++----------------- 2 files changed, 225 insertions(+), 217 deletions(-) diff --git a/compute_values.py b/compute_values.py index f7fd700..856135f 100644 --- a/compute_values.py +++ b/compute_values.py @@ -5,127 +5,126 @@ from math import * class Values(): - def __init__(self, MeshName, num, currentName=""): - self.geomapp = 0.01 - self.ridge = 45 - self.hmin = 0.01 - self.hmax = 10 - self.hgrad = 1.3 - self.MeshName = MeshName - if currentName != "": - self.CpyName = currentName + '_Repaired_' + str(num) - else: - self.CpyName = os.path.basename(os.path.splitext(MeshName)[0]) + '_Repaired_' + str(num) - salome.salome_init() - self.study = salome.myStudy - self.smesh_builder = smeshBuilder.New() - self.smesh_builder.UpdateStudy() - self.CpyMesh = None - if (len(self.study.FindObjectByName(self.MeshName, 'SMESH')) > 0): - self.SelectedObject = self.study.FindObjectByName(self.MeshName, 'SMESH')[-1] - else: - self.SelectedObject = None - FullMesh = self.smesh_builder.CreateMeshesFromMED(self.MeshName)[0] #TODO error handling (self.MyMesh[1].code, self.MyMesh[1].hasBadMesh) - self.CpyMesh = FullMesh[0] - self.CpyMesh.SetName(self.CpyName) - if (self.CpyMesh is None) and (self.SelectedObject is not None): - self.CpyMesh = self.smesh_builder.CopyMesh(self.SelectedObject.GetObject(), self.CpyName, True, True) - - self.bb = self.CpyMesh.GetBoundingBox() - self.diag = sqrt((self.bb.maxX - self.bb.minX)**2 + (self.bb.maxY - self.bb.minY)**2 + (self.bb.maxZ - self.bb.minZ)**2) - - self.min_length = 0 - self.AvgAspects = 0 - - self.FreeNodes = [] - self.FreeBorders = [] - self.FreeEdges = [] - - self.CoincidentNodes = [] - - self.DoubleNodes = [] - self.DoubleEdges = [] - self.DoubleFaces = [] - - def GetInfoFromFilter(self, ElementType, FilterName): - aFilter = self.smesh_builder.GetFilter(ElementType, FilterName) - return self.CpyMesh.GetIdsFromFilter(aFilter) - - def FillInfos(self): - # Get the faces aspect ratios - faces = self.CpyMesh.GetElementsByType(SMESH.FACE) - aspects = [self.CpyMesh.GetAspectRatio(id) for id in faces] - self.avg_aspects = sum(aspects) / len(aspects) - - # Get infos about free elements - self.FreeNodes = self.GetInfoFromFilter(SMESH.NODE, SMESH.FT_FreeNodes) - self.FreeBorders = self.GetInfoFromFilter(SMESH.EDGE, SMESH.FT_FreeBorders) - self.FreeEdges = self.GetInfoFromFilter(SMESH.FACE, SMESH.FT_FreeEdges) - - # Get minimal length (approx) - start_treshold = self.diag / 100 - treshold = start_treshold - step = start_treshold - self.min_length = treshold - edges = [] - while True: - if len(edges) == 1: - break - edges = [] - while len(edges) == 0: - LengthFilter = self.smesh_builder.GetFilter(SMESH.FACE, SMESH.FT_Length2D, SMESH.FT_LessThan, treshold) - edges = self.CpyMesh.GetIdsFromFilter(LengthFilter) - treshold += step - self.min_length = treshold - if step < treshold/1000: - break - step /= 1.5 - treshold = start_treshold - - self.CoincidentNodes = self.CpyMesh.FindCoincidentNodesOnPart([self.CpyMesh], self.min_length/1000, [], 0) - # Get infos about double elements - self.DoubleNodes = self.GetInfoFromFilter(SMESH.NODE, SMESH.FT_EqualNodes) - self.DoubleEgdes = self.GetInfoFromFilter(SMESH.EDGE, SMESH.FT_EqualEdges) - self.DoubleFaces = self.GetInfoFromFilter(SMESH.FACE, SMESH.FT_EqualFaces) - - def ComputeNewDefaultValues(self): - self.hmin = (self.diag * 0.01) / 17.25 # Reproduce default MMG values - self.hmax = (self.diag * 2) / 1.723 # Reproduce default MMG values - - - def AnalysisAndRepair(self, GenRepair): - self.FillInfos() - - if len(self.FreeEdges) != 0: - self.CpyMesh.RemoveElements(self.GetInfoFromFilter(SMESH.FACE, SMESH.FT_FreeEdges)) - if len(self.FreeBorders) != 0: - self.CpyMesh.RemoveElements(self.GetInfoFromFilter(SMESH.EDGE, SMESH.FT_FreeBorders)) - if len(self.FreeNodes) != 0: - #sef.CpyMesh.RemoveNodes(self.GetInfoFromFilter(SMESH.NODE, SMESH.FT_FreeNodes)) - self.CpyMesh.RemoveOrphanNodes() - - if len(self.CoincidentNodes) != 0: - self.CpyMesh.MergeNodes(self.CoincidentNodes, AvoidMakingHoles=True) - - tolerance = self.min_length/10 - while len(self.DoubleFaces) != 0: - self.CoincidentNodes = self.CpyMesh.FindCoincidentNodesOnPart([self.CpyMesh], tolerance, [], 0) - self.CpyMesh.MergeNodes(self.CoincidentNodes, AvoidMakingHoles=True) - EqualElements = self.CpyMesh.FindEqualElements() - self.CpyMesh.MergeElements(EqualElements) - self.DoubleFaces = self.GetInfoFromFilter(SMESH.FACE, SMESH.FT_EqualFaces) - tolerance += self.min_length/100 - - self.FillInfos() - if GenRepair: - self.CpyMesh.Compute() - self.smesh_builder.UpdateStudy() - if salome.sg.hasDesktop() and GenRepair and not self.CpyName.endswith('_0'): - salome.sg.updateObjBrowser() - - def DeleteMesh(self): - if self.CpyMesh is not None: - self.smesh_builder.RemoveMesh(self.CpyMesh) - self.CpyMesh = None - if salome.sg.hasDesktop(): salome.sg.updateObjBrowser() + def __init__(self, MeshName, num, currentName=""): + self.geomapp = 0.01 + self.ridge = 45 + self.hmin = 0.01 + self.hmax = 10 + self.hgrad = 1.3 + self.MeshName = MeshName + if currentName != "": + self.CpyName = currentName + '_Repaired_' + str(num) + else: + self.CpyName = os.path.basename(os.path.splitext(MeshName)[0]) + '_Repaired_' + str(num) + salome.salome_init() + self.study = salome.myStudy + self.smesh_builder = smeshBuilder.New() + self.smesh_builder.UpdateStudy() + self.CpyMesh = None + if (len(self.study.FindObjectByName(self.MeshName, 'SMESH')) > 0): + self.SelectedObject = self.study.FindObjectByName(self.MeshName, 'SMESH')[-1] + else: + self.SelectedObject = None + FullMesh = self.smesh_builder.CreateMeshesFromMED(self.MeshName)[0] #TODO error handling (self.MyMesh[1].code, self.MyMesh[1].hasBadMesh) + self.CpyMesh = FullMesh[0] + self.CpyMesh.SetName(self.CpyName) + if (self.CpyMesh is None) and (self.SelectedObject is not None): + self.CpyMesh = self.smesh_builder.CopyMesh(self.SelectedObject.GetObject(), self.CpyName, True, True) + + self.bb = self.CpyMesh.GetBoundingBox() + self.diag = sqrt((self.bb.maxX - self.bb.minX)**2 + (self.bb.maxY - self.bb.minY)**2 + (self.bb.maxZ - self.bb.minZ)**2) + + self.min_length = 0 + self.AvgAspects = 0 + + self.FreeNodes = [] + self.FreeBorders = [] + self.FreeEdges = [] + + self.CoincidentNodes = [] + + self.DoubleNodes = [] + self.DoubleEdges = [] + self.DoubleFaces = [] + + def GetInfoFromFilter(self, ElementType, FilterName): + aFilter = self.smesh_builder.GetFilter(ElementType, FilterName) + return self.CpyMesh.GetIdsFromFilter(aFilter) + + def FillInfos(self): + # Get the faces aspect ratios + faces = self.CpyMesh.GetElementsByType(SMESH.FACE) + aspects = [self.CpyMesh.GetAspectRatio(id) for id in faces] + self.avg_aspects = sum(aspects) / len(aspects) + + # Get infos about free elements + self.FreeNodes = self.GetInfoFromFilter(SMESH.NODE, SMESH.FT_FreeNodes) + self.FreeBorders = self.GetInfoFromFilter(SMESH.EDGE, SMESH.FT_FreeBorders) + self.FreeEdges = self.GetInfoFromFilter(SMESH.FACE, SMESH.FT_FreeEdges) + + # Get minimal length (approx) + start_treshold = self.diag / 100 + treshold = start_treshold + step = start_treshold + self.min_length = treshold + edges = [] + while True: + if len(edges) == 1: + break + edges = [] + while len(edges) == 0: + LengthFilter = self.smesh_builder.GetFilter(SMESH.FACE, SMESH.FT_Length2D, SMESH.FT_LessThan, treshold) + edges = self.CpyMesh.GetIdsFromFilter(LengthFilter) + treshold += step + self.min_length = treshold + if step < treshold/1000: + break + step /= 1.5 + treshold = start_treshold + + self.CoincidentNodes = self.CpyMesh.FindCoincidentNodesOnPart([self.CpyMesh], self.min_length/1000, [], 0) + # Get infos about double elements + self.DoubleNodes = self.GetInfoFromFilter(SMESH.NODE, SMESH.FT_EqualNodes) + self.DoubleEgdes = self.GetInfoFromFilter(SMESH.EDGE, SMESH.FT_EqualEdges) + self.DoubleFaces = self.GetInfoFromFilter(SMESH.FACE, SMESH.FT_EqualFaces) + + def ComputeNewDefaultValues(self): + self.hmin = (self.diag * 0.01) / 17.25 # Reproduce default MMG values + self.hmax = (self.diag * 2) / 1.723 # Reproduce default MMG values + + + def AnalysisAndRepair(self, GenRepair): + self.FillInfos() + + if len(self.FreeEdges) != 0: + self.CpyMesh.RemoveElements(self.GetInfoFromFilter(SMESH.FACE, SMESH.FT_FreeEdges)) + if len(self.FreeBorders) != 0: + self.CpyMesh.RemoveElements(self.GetInfoFromFilter(SMESH.EDGE, SMESH.FT_FreeBorders)) + if len(self.FreeNodes) != 0: + self.CpyMesh.RemoveOrphanNodes() + + if len(self.CoincidentNodes) != 0: + self.CpyMesh.MergeNodes(self.CoincidentNodes, AvoidMakingHoles=True) + + tolerance = self.min_length/10 + while len(self.DoubleFaces) != 0: + self.CoincidentNodes = self.CpyMesh.FindCoincidentNodesOnPart([self.CpyMesh], tolerance, [], 0) + self.CpyMesh.MergeNodes(self.CoincidentNodes, AvoidMakingHoles=True) + EqualElements = self.CpyMesh.FindEqualElements() + self.CpyMesh.MergeElements(EqualElements) + self.DoubleFaces = self.GetInfoFromFilter(SMESH.FACE, SMESH.FT_EqualFaces) + tolerance += self.min_length/100 + + self.FillInfos() + if GenRepair: + self.CpyMesh.Compute() + self.smesh_builder.UpdateStudy() + if salome.sg.hasDesktop() and GenRepair and not self.CpyName.endswith('_0'): + salome.sg.updateObjBrowser() + + def DeleteMesh(self): + if self.CpyMesh is not None: + self.smesh_builder.RemoveMesh(self.CpyMesh) + self.CpyMesh = None + if salome.sg.hasDesktop(): salome.sg.updateObjBrowser() diff --git a/myMmgPlugDialog.py b/myMmgPlugDialog.py index 87fea8e..59bea78 100644 --- a/myMmgPlugDialog.py +++ b/myMmgPlugDialog.py @@ -100,7 +100,7 @@ def connecterSignaux(self) : self.PB_Default.clicked.connect(self.clean) self.PB_Help.clicked.connect(self.PBHelpPressed) self.PB_OK.clicked.connect(self.PBOKPressed) - + self.LE_MeshFile.returnPressed.connect(self.meshFileNameChanged) self.LE_MeshSmesh.returnPressed.connect(self.meshSmeshNameChanged) self.LE_MeshSmesh.returnPressed.connect(self.meshSmeshNameChanged) @@ -121,22 +121,22 @@ def connecterSignaux(self) : def GenMedFromAny(self, fileIn): if fileIn.endswith('.med'): - return + return from salome.smesh import smeshBuilder smesh = smeshBuilder.New() self.fichierIn=tempfile.mktemp(suffix=".med",prefix="ForMMG_") if os.path.exists(self.fichierIn): - os.remove(self.fichierIn) + os.remove(self.fichierIn) ext = os.path.splitext(fileIn)[-1] if ext == '.mesh' or ext == '.meshb': - TmpMesh = smesh.CreateMeshesFromGMF(fileIn)[0] + TmpMesh = smesh.CreateMeshesFromGMF(fileIn)[0] elif ext == '.cgns': - TmpMesh = smesh.CreateMeshesFromCGNS(fileIn)[0][0] + TmpMesh = smesh.CreateMeshesFromCGNS(fileIn)[0][0] elif ext == '.stl': - TmpMesh = smesh.CreateMeshesFromSTL(fileIn) + TmpMesh = smesh.CreateMeshesFromSTL(fileIn) elif ext == '.unv': - TmpMesh = smesh.CreateMeshesFromUNV(fileIn) + TmpMesh = smesh.CreateMeshesFromUNV(fileIn) TmpMesh.ExportMED(self.fichierIn, autoDimension=True) smesh.RemoveMesh(TmpMesh) """ @@ -145,21 +145,25 @@ def GenMedFromAny(self, fileIn): """ def GenMeshFromMed(self): + if self.__selectedMesh is None: + from salome.smesh import smeshBuilder + smesh = smeshBuilder.New() + self.__selectedMesh = smesh.CreateMeshesFromMED(self.fichierIn)[0][0] self.fichierIn=tempfile.mktemp(suffix=".mesh",prefix="ForMMG_") if os.path.exists(self.fichierIn): - os.remove(self.fichierIn) + os.remove(self.fichierIn) if self.__selectedMesh is not None: - if str(type(self.__selectedMesh)) == "": - self.__selectedMesh.ExportGMF(self.fichierIn) - else: - self.__selectedMesh.ExportGMF(self.__selectedMesh, self.fichierIn, True) + if str(type(self.__selectedMesh)) == "": + self.__selectedMesh.ExportGMF(self.fichierIn) + else: + self.__selectedMesh.ExportGMF(self.__selectedMesh, self.fichierIn, True) else: - QMessageBox.critical(self, "Mesh", "internal error") + QMessageBox.critical(self, "Mesh", "internal error") def GetLabelEvent(self, event): - if event.button() == Qt.LeftButton: - self.showInfo() + if event.button() == Qt.LeftButton: + self.showInfo() def showInfo(self): title = "How to use the sandbox with " @@ -230,14 +234,14 @@ def showInfo(self): message+=""" -optimLES enable skewness improvement (for LES computations) """ - + message+=""" ** Parameters for advanced users -nosizreq disable setting of required edge sizes over required vertices. -hgradreq val control gradation from required entities toward others""" - + QMessageBox.about(None, title, message) @@ -252,52 +256,50 @@ def DisplayRemesherLabel(self): self.label_Remesher.setText(_translate("MyPlugDialog", "This remesher handles tetrahedral volume meshes. It performs surface and volume modifications.")) def RepairBeforeComputeStateChanged(self, state): - if state == 2: # Checked - self.CB_RepairOnly.setChecked(False) - self.CB_RepairOnly.setDisabled(True) + if state == 2: # Checked + self.CB_RepairOnly.setChecked(False) + self.CB_RepairOnly.setDisabled(True) - self.CB_GenRepair.setDisabled(False) - #self.CB_GenRepair.setChecked(False) - else: - #self.CB_RepairOnly.setChecked(False) - self.CB_RepairOnly.setDisabled(False) + self.CB_GenRepair.setDisabled(False) + else: + self.CB_RepairOnly.setDisabled(False) - self.CB_GenRepair.setChecked(False) - self.CB_GenRepair.setDisabled(True) + self.CB_GenRepair.setChecked(False) + self.CB_GenRepair.setDisabled(True) def RepairOnlyStateChanged(self, state): - if state == 2: # Checked - self.CB_RepairBeforeCompute.setChecked(False) - self.CB_RepairBeforeCompute.setDisabled(True) + if state == 2: # Checked + self.CB_RepairBeforeCompute.setChecked(False) + self.CB_RepairBeforeCompute.setDisabled(True) - self.CB_GenRepair.setChecked(False) - self.CB_GenRepair.setDisabled(True) - else: - self.CB_RepairBeforeCompute.setChecked(True) - self.CB_RepairBeforeCompute.setDisabled(False) + self.CB_GenRepair.setChecked(False) + self.CB_GenRepair.setDisabled(True) + else: + self.CB_RepairBeforeCompute.setChecked(True) + self.CB_RepairBeforeCompute.setDisabled(False) - self.CB_GenRepair.setChecked(False) - self.CB_GenRepair.setDisabled(False) + self.CB_GenRepair.setChecked(False) + self.CB_GenRepair.setDisabled(False) def GenRepairStateChanged(self, state): - if state == 2: # Checked - self.CB_RepairBeforeCompute.setChecked(True) - self.CB_RepairBeforeCompute.setDisabled(True) + if state == 2: # Checked + self.CB_RepairBeforeCompute.setChecked(True) + self.CB_RepairBeforeCompute.setDisabled(True) - self.CB_RepairOnly.setChecked(False) - self.CB_RepairOnly.setDisabled(True) - else: - self.CB_RepairBeforeCompute.setChecked(True) - self.CB_RepairBeforeCompute.setDisabled(False) + self.CB_RepairOnly.setChecked(False) + self.CB_RepairOnly.setDisabled(True) + else: + self.CB_RepairBeforeCompute.setChecked(True) + self.CB_RepairBeforeCompute.setDisabled(False) - self.CB_RepairOnly.setChecked(False) - self.CB_RepairOnly.setDisabled(False) + self.CB_RepairOnly.setChecked(False) + self.CB_RepairOnly.setDisabled(False) def updateHmaxValue(self): - self.SP_Hmax.setMinimum(self.SP_Hmin.value()) + self.SP_Hmax.setMinimum(self.SP_Hmin.value()) def updateHminValue(self): - self.SP_Hmin.setMaximum(self.SP_Hmax.value()) + self.SP_Hmin.setMaximum(self.SP_Hmax.value()) def PBPlusPressed(self): for elt in self.sandboxes: @@ -370,7 +372,7 @@ def Repair(self): if self.values.SelectedObject is None: self.values.SelectedObject = self.values.study.FindObjectByName(self.values.MeshName, 'SMESH')[-1] self.values.CpyMesh = self.values.smesh_builder.CopyMesh(self.values.SelectedObject.GetObject(), self.values.CpyName, True, True) - + self.numRepair+=1 self.values.AnalysisAndRepair(self.CB_GenRepair.isChecked() or self.CB_RepairOnly.isChecked()) @@ -378,12 +380,12 @@ def PBOKPressed(self): if self.fichierIn=="" and self.MeshIn=="": QMessageBox.critical(self, "Mesh", "select an input mesh") return False - if not self.CB_RepairBeforeCompute.isChecked() and not self.CB_RepairOnly.isChecked(): - QMessageBox.warning(self, "Compute", "No actions triggered. Please set one in Advanced Remeshing Options.") - return False - if self.isFile and os.path.splitext(self.fichierIn)[-1] != '.med' and self.COB_Remesher.currentIndex() == REMESHER_DICT['MMGS']: - self.GenMedFromAny(self.fichierIn) + ext = os.path.splitext(self.fichierIn)[-1] + if self.isFile and ext != '.med' \ + and self.COB_Remesher.currentIndex() == REMESHER_DICT['MMGS']: + if not ((ext == 'mesh' or ext == '.meshb') and not (self.CB_RepairBeforeCompute.isChecked() or self.CB_RepairOnly.isChecked())): + self.GenMedFromAny(self.fichierIn) CpyFichierIn = self.fichierIn CpyMeshIn = self.MeshIn @@ -396,19 +398,24 @@ def PBOKPressed(self): self.values = Values(self.MeshIn, 0, self.currentName) self.Repair() if not self.CB_GenRepair.isChecked() and not self.CB_RepairOnly.isChecked(): - self.numRepair-=1 - self.MeshIn = self.values.CpyName - self.fichierIn="" - self.__selectedMesh = self.values.CpyMesh + self.numRepair-=1 if not self.CB_RepairOnly.isChecked(): + ext = os.path.splitext(self.fichierIn)[-1] + if self.fichierIn != "": + if ext == '.med': + self.GenMeshFromMed() + elif ext != '.mesh' and ext != '.meshb': + self.GenMedFromAny(self.fichierIn) + self.GenMeshFromMed() + self.__selectedMesh = None if not(self.PrepareLigneCommande()): #warning done yet #QMessageBox.warning(self, "Compute", "Command not found") return False - + self.maFenetre=MyViewText(self,self.commande) if not self.CB_GenRepair.isChecked() and self.values is not None: - self.values.DeleteMesh() + self.values.DeleteMesh() self.fichierIn = CpyFichierIn self.MeshIn = CpyMeshIn @@ -422,7 +429,7 @@ def enregistreResultat(self): from salome.kernel import studyedit from salome.smesh import smeshBuilder smesh = smeshBuilder.New() - + if not os.path.isfile(self.fichierOut): QMessageBox.warning(self, "Compute", "Result file "+self.fichierOut+" not found") @@ -436,9 +443,9 @@ def enregistreResultat(self): initialMeshObject=None if name=="": if self.MeshIn =="": - a = re.sub(r'_\d*$', '', str(self.fichierIn)) + a = re.sub(r'_\d*$', '', str(self.fichierIn)) else: # Repaired - a = re.sub(r'_\d*$', '', str(self.MeshIn)) + a = re.sub(r'_\d*$', '', str(self.MeshIn)) name=os.path.basename(os.path.splitext(a)[0]) initialMeshFile=a @@ -453,7 +460,7 @@ def enregistreResultat(self): moduleEntry=self.editor.findOrCreateComponent("SMESH","SMESH") HypReMeshEntry = self.editor.findOrCreateItem( moduleEntry, name = "Plugins Hypotheses", icon="mesh_tree_hypo.png") #, comment = "HypoForRemeshing" ) - + monStudyBuilder=maStudy.NewBuilder() monStudyBuilder.NewCommand() newStudyIter=monStudyBuilder.NewObject(HypReMeshEntry) @@ -572,7 +579,7 @@ def meshSmeshNameChanged(self): return def prepareFichier(self): - self.GenMeshFromMed() + self.GenMeshFromMed() def PrepareLigneCommande(self): if self.fichierIn=="" and self.MeshIn=="": @@ -586,19 +593,19 @@ def PrepareLigneCommande(self): self.commande="" selected_index = self.COB_Remesher.currentIndex() if selected_index == REMESHER_DICT['MMGS']: - self.commande = "mmgs_O3" + self.commande = "mmgs_O3" elif selected_index == REMESHER_DICT['MMG2D']: - self.commande = "mmg2d_O3" + self.commande = "mmg2d_O3" elif selected_index == REMESHER_DICT['MMG3D']: - self.commande = "mmg3d_O3" + self.commande = "mmg3d_O3" else: - self.commande = "mmgs_O3" + self.commande = "mmgs_O3" deb=os.path.splitext(self.fichierIn) self.fichierOut=deb[0] + "_output.mesh" for elt in self.sandboxes: - self.commande+=' ' + elt[0].text() + ' ' + elt[1].text() + self.commande+=' ' + elt[0].text() + ' ' + elt[1].text() if not self.CB_InsertEdge.isChecked() : self.commande+=" -noinsert" if not self.CB_SwapEdge.isChecked() : self.commande+=" -noswap" @@ -617,27 +624,29 @@ def PrepareLigneCommande(self): def clean(self): if self.values is None and self.currentName != "" and self.COB_Remesher.currentIndex() == REMESHER_DICT['MMGS']: - if self.fichierIn != "": - cpy = self.fichierIn - self.GenMedFromAny(self.fichierIn) - self.values = Values(self.fichierIn, 0, self.currentName) - self.fichierIn = cpy - elif self.MeshIn != "": - self.values = Values(self.MeshIn, 0, self.currentName) + if self.fichierIn != "": + cpy = self.fichierIn + self.GenMedFromAny(self.fichierIn) + self.values = Values(self.fichierIn, 0, self.currentName) + self.fichierIn = cpy + elif self.MeshIn != "": + self.values = Values(self.MeshIn, 0, self.currentName) + if self.values is not None: - self.values.ComputeNewDefaultValues() - self.SP_Geomapp.setProperty("value", self.values.geomapp) - self.SP_Ridge.setProperty("value", self.values.ridge) - self.SP_Gradation.setProperty("value", self.values.hgrad) - self.SP_Hmin.setProperty("value", self.values.hmin) - self.SP_Hmax.setProperty("value", self.values.hmax) - self.values.DeleteMesh() + self.values.ComputeNewDefaultValues() + self.SP_Geomapp.setProperty("value", self.values.geomapp) + self.SP_Ridge.setProperty("value", self.values.ridge) + self.SP_Gradation.setProperty("value", self.values.hgrad) + self.SP_Hmin.setProperty("value", self.values.hmin) + self.SP_Hmax.setProperty("value", self.values.hmax) + self.values.DeleteMesh() + else: # No file provided, default from MMG - self.SP_Geomapp.setProperty("value", 0.01) - self.SP_Ridge.setProperty("value", 45.0) - self.SP_Gradation.setProperty("value", 1.3) - self.SP_Hmin.setProperty("value", 0.01) - self.SP_Hmax.setProperty("value", 10) + self.SP_Geomapp.setProperty("value", 0.01) + self.SP_Ridge.setProperty("value", 45.0) + self.SP_Gradation.setProperty("value", 1.3) + self.SP_Hmin.setProperty("value", 0.01) + self.SP_Hmax.setProperty("value", 10) self.values = None self.CB_InsertEdge.setChecked(True) self.CB_MoveEdge.setChecked(True) @@ -650,9 +659,9 @@ def clean(self): from PyQt5 import QtCore, QtGui, QtWidgets _translate = QtCore.QCoreApplication.translate for i in reversed(range(self.gridLayout_5.count())): - widget = self.gridLayout_5.takeAt(i).widget() - if widget is not None: - widget.setParent(None) + widget = self.gridLayout_5.takeAt(i).widget() + if widget is not None: + widget.setParent(None) self.LE_SandboxR_1 = QtWidgets.QLineEdit(self.scrollAreaWidgetContents) self.LE_SandboxR_1.setMinimumSize(QtCore.QSize(0, 30)) @@ -689,7 +698,7 @@ def clean(self): self.LE_SandboxR_1.setText("") self.sandboxes = [(self.LE_SandboxL_1, self.LE_SandboxR_1)] - #self.PBMeshSmeshPressed() #do not that! problem if done in load surfopt hypo from object browser + #self.PBMeshSmeshPressed() #do not that! problem if done in load surfopt hypo from object browser self.TWOptions.setCurrentIndex(0) # Reset current active tab to the first tab __dialog=None From 4f7603edffbbf00b4f81b0a87c1022b17042564d Mon Sep 17 00:00:00 2001 From: FARGETTON-LECRIVAIN Florestan Date: Mon, 20 Nov 2023 10:44:56 +0100 Subject: [PATCH 2/3] fix: generation of trash intermediate mesh #21 --- myMmgPlugDialog.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/myMmgPlugDialog.py b/myMmgPlugDialog.py index 59bea78..ff6df73 100644 --- a/myMmgPlugDialog.py +++ b/myMmgPlugDialog.py @@ -145,10 +145,12 @@ def GenMedFromAny(self, fileIn): """ def GenMeshFromMed(self): + create_mesh = False if self.__selectedMesh is None: from salome.smesh import smeshBuilder smesh = smeshBuilder.New() self.__selectedMesh = smesh.CreateMeshesFromMED(self.fichierIn)[0][0] + create_mesh = True self.fichierIn=tempfile.mktemp(suffix=".mesh",prefix="ForMMG_") if os.path.exists(self.fichierIn): os.remove(self.fichierIn) @@ -160,6 +162,8 @@ def GenMeshFromMed(self): self.__selectedMesh.ExportGMF(self.__selectedMesh, self.fichierIn, True) else: QMessageBox.critical(self, "Mesh", "internal error") + if create_mesh: + smesh.RemoveMesh(self.__selectedMesh) def GetLabelEvent(self, event): if event.button() == Qt.LeftButton: @@ -392,6 +396,7 @@ def PBOKPressed(self): CpySelectedMesh = self.__selectedMesh if (self.CB_RepairBeforeCompute.isChecked() or self.CB_RepairOnly.isChecked()) and self.COB_Remesher.currentIndex() == REMESHER_DICT['MMGS']: if self.values is None: + sys.stderr.write(self.fichierIn + ' | ' + self.currentName + '\n') if self.fichierIn != "": self.values = Values(self.fichierIn, 0, self.currentName) else: @@ -408,13 +413,14 @@ def PBOKPressed(self): self.GenMedFromAny(self.fichierIn) self.GenMeshFromMed() self.__selectedMesh = None + if not(self.PrepareLigneCommande()): #warning done yet #QMessageBox.warning(self, "Compute", "Command not found") return False self.maFenetre=MyViewText(self,self.commande) - if not self.CB_GenRepair.isChecked() and self.values is not None: + if (not self.CB_GenRepair.isChecked()) and self.values is not None: self.values.DeleteMesh() self.fichierIn = CpyFichierIn From f3962d4e20828199c4ea51aa93269eab75b4dd81 Mon Sep 17 00:00:00 2001 From: FARGETTON-LECRIVAIN Florestan Date: Mon, 20 Nov 2023 10:50:08 +0100 Subject: [PATCH 3/3] fix: optimize repair process #21 --- compute_values.py | 41 +++++++++++++++++++++++------------------ myMmgPlugDialog.py | 1 - 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/compute_values.py b/compute_values.py index 856135f..344a493 100644 --- a/compute_values.py +++ b/compute_values.py @@ -62,25 +62,30 @@ def FillInfos(self): self.FreeBorders = self.GetInfoFromFilter(SMESH.EDGE, SMESH.FT_FreeBorders) self.FreeEdges = self.GetInfoFromFilter(SMESH.FACE, SMESH.FT_FreeEdges) - # Get minimal length (approx) - start_treshold = self.diag / 100 - treshold = start_treshold - step = start_treshold - self.min_length = treshold - edges = [] - while True: - if len(edges) == 1: - break - edges = [] - while len(edges) == 0: - LengthFilter = self.smesh_builder.GetFilter(SMESH.FACE, SMESH.FT_Length2D, SMESH.FT_LessThan, treshold) - edges = self.CpyMesh.GetIdsFromFilter(LengthFilter) - treshold += step - self.min_length = treshold - if step < treshold/1000: - break - step /= 1.5 + + self.DoubleNodes = self.GetInfoFromFilter(SMESH.NODE, SMESH.FT_EqualNodes) + self.DoubleEgdes = self.GetInfoFromFilter(SMESH.EDGE, SMESH.FT_EqualEdges) + self.DoubleFaces = self.GetInfoFromFilter(SMESH.FACE, SMESH.FT_EqualFaces) + if self.DoubleFaces != [] or self.DoubleEgdes != [] or self.DoubleNodes != []: + # Get minimal length (approx) + start_treshold = self.diag / 100 treshold = start_treshold + step = start_treshold + self.min_length = treshold + edges = [] + while True: + if len(edges) == 1: + break + edges = [] + while len(edges) == 0: + LengthFilter = self.smesh_builder.GetFilter(SMESH.FACE, SMESH.FT_Length2D, SMESH.FT_LessThan, treshold) + edges = self.CpyMesh.GetIdsFromFilter(LengthFilter) + treshold += step + self.min_length = treshold + if step < treshold/1000: + break + step /= 1.5 + treshold = start_treshold self.CoincidentNodes = self.CpyMesh.FindCoincidentNodesOnPart([self.CpyMesh], self.min_length/1000, [], 0) # Get infos about double elements diff --git a/myMmgPlugDialog.py b/myMmgPlugDialog.py index ff6df73..af1b665 100644 --- a/myMmgPlugDialog.py +++ b/myMmgPlugDialog.py @@ -396,7 +396,6 @@ def PBOKPressed(self): CpySelectedMesh = self.__selectedMesh if (self.CB_RepairBeforeCompute.isChecked() or self.CB_RepairOnly.isChecked()) and self.COB_Remesher.currentIndex() == REMESHER_DICT['MMGS']: if self.values is None: - sys.stderr.write(self.fichierIn + ' | ' + self.currentName + '\n') if self.fichierIn != "": self.values = Values(self.fichierIn, 0, self.currentName) else: