- if not(os.path.isfile(self.fichierOut)) : return
- import smesh
- import SMESH
- import salome
- from salome.kernel import studyedit
-
- maStudy=studyedit.getActiveStudy()
- smesh.SetCurrentStudy(maStudy)
- (outputMesh, status) = smesh.CreateMeshesFromGMF(self.fichierOut)
- meshname = 'yams'+str(self.num)
- smesh.SetName(outputMesh.GetMesh(), meshname)
- outputMesh.Compute()
-
-
- self.editor = studyedit.getStudyEditor() #
- moduleEntry=self.editor.findOrCreateComponent("SMESH","SMESH")
- HypReMeshEntry = self.editor.findOrCreateItem( moduleEntry, name = 'HypoForRemesh',
- comment = 'HypoForRemshing')
- monStudyBuilder=maStudy.NewBuilder();
- monStudyBuilder.NewCommand();
- newStudyIter=monStudyBuilder.NewObject(HypReMeshEntry)
- aNameAttrib=monStudyBuilder.FindOrCreateAttribute(newStudyIter,"AttributeName")
- hypoName = 'monHypo_Yams_'+str(self.num)
- aNameAttrib.SetValue(hypoName)
- aCommentAttrib=monStudyBuilder.FindOrCreateAttribute(newStudyIter,"AttributeComment")
- aCommentAttrib.SetValue(str(self.commande))
-
- SOMesh=maStudy.FindObjectByName(meshname ,"SMESH")[0]
- newLink=monStudyBuilder.NewObject(SOMesh)
- monStudyBuilder.Addreference(newLink, newStudyIter);
- if salome.sg.hasDesktop(): salome.sg.updateObjBrowser(0)
- self.num+=1
- return True
-
- def PBSavePressed(self,NomHypo=False):
- if NomHypo : text = '# Params for Hypothese : monHypo_Yams_'+str(self.num - 1)+"\n"
- else : text = '# Save intermediate params \n'
- text += "# Params for mesh : " + self.LE_MeshSmesh.text() +'\n'
- for RB in self.GBOptim.findChildren(QRadioButton,):
- if RB.isChecked()==True:
- text+="Optimisation ='"+RB.text()+"'\n"
- break
- for RB in self.GBUnit.findChildren(QRadioButton,):
- if RB.isChecked()==True:
- text+="Units ='"+RB.text()+"'\n"
- text+='Chordal_Tolerance_Deviation='+str(self.SP_Tolerance.value())+'\n'
-
- text+='Ridge_Detection=' + str(self.CB_Ridge.isChecked())+'\n'
- text+='Split_Edge=' + str(self.CB_SplitEdge.isChecked())+'\n'
- text+='Point_Smoothing=' + str(self.CB_Point.isChecked())+'\n'
- text+='Geometrical_Approximation='+ str(self.SP_Geomapp.value()) +'\n'
- text+='Ridge_Angle=' + str(self.SP_Ridge.value()) +'\n'
- text+='Maximum_Size=' + str(self.SP_MaxSize.value()) +'\n'
- text+='Minimum_Size=' + str(self.SP_MaxSize.value()) +'\n'
- text+='Mesh_Gradation=' + str(self.SP_Gradation.value())+'\n'
-
- text+='Verbosity=' + str(self.SP_Verbosity.value())+'\n'
- text+='Memory=' + str(self.SP_Memory.value())+'\n'
- text+='\n\n'
-
- try :
- f=open(self.paramsFile,'a')
- except :
- QMessageBox.warning( self, "File", "Unable to open "+self.paramsFile)
- return
- try :
- f.write(text)
- except :
- QMessageBox.warning( self, "File", "Unable to write "+self.paramsFile)
- return
- f.close()
+ import salome
+ import SMESH
+ 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")
+
+ maStudy=salome.myStudy
+ smesh.UpdateStudy()
+ (outputMesh, status) = smesh.CreateMeshesFromGMF(self.fichierOut)
+ name=str(self.LE_MeshSmesh.text())
+ initialMeshFile=None
+ initialMeshObject=None
+ if name=="":
+ a=str(self.fichierIn)
+ name=os.path.basename(os.path.splitext(a)[0])
+ initialMeshFile=a
+ else:
+ initialMeshObject=maStudy.FindObjectByName(name ,"SMESH")[0]
+
+ meshname = name+"_MGSO_"+str(self.num)
+ smesh.SetName(outputMesh.GetMesh(), meshname)
+ outputMesh.Compute() #no algorithms message for "Mesh_x" has been computed with warnings: - global 1D algorithm is missing
+
+ self.editor = studyedit.getStudyEditor()
+ 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)
+ self.editor.setAttributeValue(newStudyIter, "AttributeName", "MGSurfOpt Parameters_"+str(self.num))
+ self.editor.setAttributeValue(newStudyIter, "AttributeComment", self.getResumeData(separator=" ; "))
+
+ SOMesh=maStudy.FindObjectByName(meshname ,"SMESH")[0]
+
+ if initialMeshFile!=None:
+ newStudyFileName=monStudyBuilder.NewObject(SOMesh)
+ self.editor.setAttributeValue(newStudyFileName, "AttributeName", "meshFile")
+ self.editor.setAttributeValue(newStudyFileName, "AttributeExternalFileDef", initialMeshFile)
+ self.editor.setAttributeValue(newStudyFileName, "AttributeComment", initialMeshFile)
+
+ if initialMeshObject!=None:
+ newLink=monStudyBuilder.NewObject(SOMesh)
+ monStudyBuilder.Addreference(newLink, initialMeshObject)
+
+ newLink=monStudyBuilder.NewObject(SOMesh)
+ monStudyBuilder.Addreference(newLink, newStudyIter)
+
+ if salome.sg.hasDesktop(): salome.sg.updateObjBrowser()
+ self.num+=1
+ return True
+
+ def PBSavePressed(self):
+ from datetime import datetime
+ if not(self.PrepareLigneCommande()): return
+ text = "# MGSurfOpt hypothesis parameters\n"
+ text += "# Params for mesh : " + self.LE_MeshSmesh.text() +"\n"
+ text += datetime.now().strftime("# Date : %d/%m/%y %H:%M:%S\n")
+ text += "# Command : "+self.commande+"\n"
+ text += self.getResumeData(separator="\n")
+ text += "\n\n"
+
+ try:
+ f=open(self.paramsFile,"a")
+ except:
+ QMessageBox.warning(self, "File", "Unable to open "+self.paramsFile)
+ return
+ try:
+ f.write(text)
+ except:
+ QMessageBox.warning(self, "File", "Unable to write "+self.paramsFile)
+ return
+ f.close()
+
+ def PBSaveHypPressed_risky(self):
+ """
+ save hypothesis in Object Browser outside GEOM ou MESH
+ WARNING: at root of Object Browser is not politically correct
+ """
+ import salome
+
+ if verbose: print("save hypothesis in Object Browser")
+
+ name = "MGSurfOpt"
+ #how ??? icon = "mesh_tree_hypo.png"
+ namei = "MGSurfOpt Parameters_%i" % self.num
+ datai = self.getResumeData(separator=" ; ")
+
+ myStudy = salome.myStudy
+ myBuilder = myStudy.NewBuilder()
+ #myStudy.IsStudyLocked()
+ myComponent = myStudy.FindComponent(name)
+ if myComponent == None:
+ print("myComponent not found, create")
+ myComponent = myBuilder.NewComponent(name)
+ AName = myBuilder.FindOrCreateAttribute(myComponent, "AttributeName")
+ AName.SetValue(name)
+ ACmt = myBuilder.FindOrCreateAttribute(myComponent, "AttributeComment")
+ ACmt.SetValue(name)
+
+ myObject = myBuilder.NewObject(myComponent)
+ AName = myBuilder.FindOrCreateAttribute(myObject, "AttributeName")
+ AName.SetValue(namei)
+ ACmt = myBuilder.FindOrCreateAttribute(myObject, "AttributeComment")
+ ACmt.SetValue(datai)
+
+ if salome.sg.hasDesktop(): salome.sg.updateObjBrowser()
+ self.num += 1
+ if verbose: print(("save %s in Object Browser done: %s\n%s" % (name, myObject.GetID(), datai)))
+ return True
+
+ def PBSaveHypPressed(self):
+ """
+ save hypothesis in Object Browser
+ bug: affichage ne marche pas si inclusion dans dans GEOM ou MESH depuis salome 730
+ """
+ import salome
+ import SMESH
+ from salome.kernel import studyedit
+ from salome.smesh import smeshBuilder
+ #[PAL issue tracker:issue1871] Les nouveaux objets ne s'affichent pas dans SMESH
+ QMessageBox.warning(self, "Save", "waiting for fix: Object Browser will not display hypothesis")
+
+ if verbose: print("save hypothesis in Object Browser")
+ smesh = smeshBuilder.New()
+
+ maStudy=salome.myStudy
+ smesh.UpdateStudy()
+
+ self.editor = studyedit.getStudyEditor()
+ moduleEntry=self.editor.findOrCreateComponent("SMESH","SMESH")
+ HypReMeshEntry = self.editor.findOrCreateItem(
+ moduleEntry, name = "Plugins Hypotheses", icon="mesh_tree_hypo.png")
+ #, comment = "HypothesisForRemeshing" )
+
+ monStudyBuilder=maStudy.NewBuilder()
+ monStudyBuilder.NewCommand()
+ newStudyIter=monStudyBuilder.NewObject(HypReMeshEntry)
+ name = "MGSurfOpt Parameters_%i" % self.num
+ self.editor.setAttributeValue(newStudyIter, "AttributeName", name)
+ data = self.getResumeData(separator=" ; ")
+ self.editor.setAttributeValue(newStudyIter, "AttributeComment", data)
+
+ if salome.sg.hasDesktop(): salome.sg.updateObjBrowser()
+ self.num += 1
+ if verbose: print(("save %s in Object Browser done:\n%s" % (name, data)))
+ return True
+
+ def SP_toStr(self, widget):
+ """only for a QLineEdit widget"""
+ #cr, pos=widget.validator().validate(res, 0) #n.b. "1,3" is acceptable !locale!
+ try:
+ val=float(widget.text())
+ except:
+ QMessageBox.warning(self, widget.titleForWarning, "float value is incorrect: '"+widget.text()+"'")
+ res=str(widget.validator().bottom())
+ widget.setProperty("text", res)
+ return res
+ valtest=widget.validator().bottom()
+ if valtest!=None:
+ if val<valtest:
+ QMessageBox.warning(self, widget.titleForWarning, "float value is under minimum: "+str(val)+" < "+str(valtest))
+ res=str(valtest)
+ widget.setProperty("text", res)
+ return res
+ valtest=widget.validator().top()
+ if valtest!=None:
+ if val>valtest:
+ QMessageBox.warning(self, widget.titleForWarning, "float value is over maximum: "+str(val)+" > "+str(valtest))
+ res=str(valtest)
+ widget.setProperty("text", res)
+ return res
+ return str(val)
+
+ def getResumeData(self, separator="\n"):
+ text=""
+ for RB in self.GBOptim.findChildren(QRadioButton,):
+ if RB.isChecked()==True:
+ text+="Optimisation="+RB.text()+separator
+ break
+ if self.RB_Absolute.isChecked():
+ text+="Units=absolute"+separator
+ else:
+ text+="Units=relative"+separator
+ v=self.SP_toStr(self.SP_Tolerance)
+ text+="ChordalToleranceDeviation="+v+separator
+ text+="RidgeDetection="+str(self.CB_Ridge.isChecked())+separator
+ text+="SplitEdge="+str(self.CB_SplitEdge.isChecked())+separator
+ text+="PointSmoothing="+str(self.CB_Point.isChecked())+separator
+ text+="GeometricalApproximation="+str(self.SP_Geomapp.value())+separator
+ text+="RidgeAngle="+str(self.SP_Ridge.value())+separator
+ text+="MaximumSize="+str(self.SP_MaxSize.value())+separator
+ text+="MinimumSize="+str(self.SP_MinSize.value())+separator
+ text+="MeshGradation="+str(self.SP_Gradation.value())+separator
+ text+="Verbosity="+str(self.SP_Verbosity.value())+separator
+ text+="Memory="+str(self.SP_Memory.value())+separator
+ return str(text)
+
+ def loadResumeData(self, hypothesis, separator="\n"):
+ text=str(hypothesis)
+ self.clean()
+ for slig in reversed(text.split(separator)):
+ lig=slig.strip()
+ #print "load ResumeData",lig
+ if lig=="": continue #skip blank lines
+ if lig[0]=="#": break
+ try:
+ tit,value=lig.split("=")
+ if tit=="Optimisation":
+ #no need: exlusives QRadioButton
+ #for RB in self.GBOptim.findChildren(QRadioButton,):
+ # RB.setChecked(False)
+ for RB in self.GBOptim.findChildren(QRadioButton,):
+ if RB.text()==value :
+ RB.setChecked(True)
+ break
+ if tit=="Units":
+ if value=="absolute":
+ self.RB_Absolute.setChecked(True)
+ self.RB_Relative.setChecked(False)
+ else:
+ self.RB_Absolute.setChecked(False)
+ self.RB_Relative.setChecked(True)
+ if tit=="ChordalToleranceDeviation": self.SP_Tolerance.setProperty("text", float(value))
+ if tit=="RidgeDetection": self.CB_Ridge.setChecked(value=="True")
+ if tit=="SplitEdge": self.CB_SplitEdge.setChecked(value=="True")
+ if tit=="PointSmoothing": self.CB_Point.setChecked(value=="True")
+ if tit=="GeometricalApproximation": self.SP_Geomapp.setProperty("value", float(value))
+ if tit=="RidgeAngle": self.SP_Ridge.setProperty("value", float(value))
+ if tit=="MaximumSize": self.SP_MaxSize.setProperty("value", float(value))
+ if tit=="MinimumSize": self.SP_MinSize.setProperty("value", float(value))
+ if tit=="MeshGradation": self.SP_Gradation.setProperty("value", float(value))
+ if tit=="Verbosity": self.SP_Verbosity.setProperty("value", int(float(value)))
+ if tit=="Memory": self.SP_Memory.setProperty("value", float(value))
+ except:
+ QMessageBox.warning(self, "load MGSurfOpt Hypothesis", "Problem on '"+lig+"'")