# -*- coding: utf-8 -*-
-# Copyright (C) 2007-2013 EDF R&D
+# Copyright (C) 2007-2016 EDF R&D
#
# 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.
+# 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
# Modules Eficas
import os, subprocess
+import tempfile
from YamsPlugDialog_ui import Ui_YamsPlugDialog
from monViewText import MonViewText
-from PyQt4.QtGui import *
-from PyQt4.QtCore import *
+from qtsalome import *
+verbose = True
class MonYamsPlugDialog(Ui_YamsPlugDialog,QWidget):
"""
self.num=1
self.__selectedMesh=None
- # complex whith QResources: not used
+ # complex with QResources: not used
# The icon are supposed to be located in the $SMESH_ROOT_DIR/share/salome/resources/smesh folder,
# other solution could be in the same folder than this python module file:
# iconfolder=os.path.dirname(os.path.abspath(__file__))
self.iconfolder=os.environ["SMESH_ROOT_DIR"]+"/share/salome/resources/smesh"
- #print "monYamsPlugDialog iconfolder",iconfolder
+ #print "MGSurfOptPlugDialog iconfolder",iconfolder
icon = QIcon()
icon.addFile(os.path.join(self.iconfolder,"select1.png"))
self.PB_LoadHyp.setIcon(icon)
self.PB_MeshFile.setIcon(icon)
self.PB_MeshFile.setToolTip("source mesh from a file in disk")
- #Ces parametres ne sont pas remis à rien par le clean
- self.paramsFile= os.path.abspath(os.path.join(os.environ["HOME"],".yams.dat"))
+ #Ces parametres ne sont pas remis a rien par le clean
+ self.paramsFile= os.path.abspath(os.path.join(os.environ["HOME"],".MGSurfOpt.dat"))
self.LE_ParamsFile.setText(self.paramsFile)
self.LE_MeshFile.setText("")
self.LE_MeshSmesh.setText("")
-
+
v1=QDoubleValidator(self)
v1.setBottom(0.)
#v1.setTop(1000.) #per thousand... only if relative
self.clean()
def connecterSignaux(self) :
- self.connect(self.PB_Cancel,SIGNAL("clicked()"),self.PBCancelPressed)
- self.connect(self.PB_Default,SIGNAL("clicked()"),self.clean)
- self.connect(self.PB_Help,SIGNAL("clicked()"),self.PBHelpPressed)
- self.connect(self.PB_OK,SIGNAL("clicked()"),self.PBOKPressed)
+ self.PB_Cancel.clicked.connect(self.PBCancelPressed)
+ self.PB_Default.clicked.connect(self.clean)
+ self.PB_Help.clicked.connect(self.PBHelpPressed)
+ self.PB_OK.clicked.connect(self.PBOKPressed)
- self.connect(self.PB_Load,SIGNAL("clicked()"),self.PBLoadPressed)
- self.connect(self.PB_Save,SIGNAL("clicked()"),self.PBSavePressed)
- self.connect(self.PB_LoadHyp,SIGNAL("clicked()"),self.PBLoadHypPressed)
- self.connect(self.PB_SaveHyp,SIGNAL("clicked()"),self.PBSaveHypPressed)
+ self.PB_Load.clicked.connect(self.PBLoadPressed)
+ self.PB_Save.clicked.connect(self.PBSavePressed)
+ self.PB_LoadHyp.clicked.connect(self.PBLoadHypPressed)
+ self.PB_SaveHyp.clicked.connect(self.PBSaveHypPressed)
- self.connect(self.PB_MeshFile,SIGNAL("clicked()"),self.PBMeshFilePressed)
- self.connect(self.PB_MeshSmesh,SIGNAL("clicked()"),self.PBMeshSmeshPressed)
- self.connect(self.LE_MeshSmesh,SIGNAL("returnPressed()"),self.meshSmeshNameChanged)
- self.connect(self.PB_ParamsFileExplorer,SIGNAL("clicked()"),self.setParamsFileName)
- self.connect(self.LE_MeshFile,SIGNAL("returnPressed()"),self.meshFileNameChanged)
- self.connect(self.LE_ParamsFile,SIGNAL("returnPressed()"),self.paramsFileNameChanged)
+ self.PB_MeshFile.clicked.connect(self.PBMeshFilePressed)
+ self.PB_MeshSmesh.clicked.connect(self.PBMeshSmeshPressed)
+ self.LE_MeshSmesh.returnPressed.connect(self.meshSmeshNameChanged)
+ self.PB_ParamsFileExplorer.clicked.connect(self.setParamsFileName)
+ self.LE_MeshFile.returnPressed.connect(self.meshFileNameChanged)
+ self.LE_ParamsFile.returnPressed.connect(self.paramsFileNameChanged)
def PBHelpPressed(self):
import SalomePyQt
sgPyQt = SalomePyQt.SalomePyQt()
- try :
+ try:
mydir=os.environ["SMESH_ROOT_DIR"]
except Exception:
QMessageBox.warning(self, "Help", "Help unavailable $SMESH_ROOT_DIR not found")
import SMESH
from salome.kernel import studyedit
from salome.smesh import smeshBuilder
- smesh = smeshBuilder.New(salome.myStudy)
+ smesh = smeshBuilder.New()
if not os.path.isfile(self.fichierOut):
QMessageBox.warning(self, "Compute", "Result file "+self.fichierOut+" not found")
- maStudy=studyedit.getActiveStudy()
- smesh.SetCurrentStudy(maStudy)
+ maStudy=salome.myStudy
+ smesh.UpdateStudy()
(outputMesh, status) = smesh.CreateMeshesFromGMF(self.fichierOut)
name=str(self.LE_MeshSmesh.text())
initialMeshFile=None
else:
initialMeshObject=maStudy.FindObjectByName(name ,"SMESH")[0]
- meshname = name+"_YAMS_"+str(self.num)
+ 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
monStudyBuilder=maStudy.NewBuilder()
monStudyBuilder.NewCommand()
newStudyIter=monStudyBuilder.NewObject(HypReMeshEntry)
- self.editor.setAttributeValue(newStudyIter, "AttributeName", "YAMS Parameters_"+str(self.num))
+ self.editor.setAttributeValue(newStudyIter, "AttributeName", "MGSurfOpt Parameters_"+str(self.num))
self.editor.setAttributeValue(newStudyIter, "AttributeComment", self.getResumeData(separator=" ; "))
SOMesh=maStudy.FindObjectByName(meshname ,"SMESH")[0]
newLink=monStudyBuilder.NewObject(SOMesh)
monStudyBuilder.Addreference(newLink, newStudyIter)
- if salome.sg.hasDesktop(): salome.sg.updateObjBrowser(0)
+ 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 = "# YAMS hypothesis parameters\n"
+ 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"
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"""
+ """
+ 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
- smesh = smeshBuilder.New(salome.myStudy)
-
- maStudy=studyedit.getActiveStudy()
- smesh.SetCurrentStudy(maStudy)
+ #[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 = "HypoForRemeshing" )
-
+ moduleEntry, name = "Plugins Hypotheses", icon="mesh_tree_hypo.png")
+ #, comment = "HypothesisForRemeshing" )
+
monStudyBuilder=maStudy.NewBuilder()
monStudyBuilder.NewCommand()
newStudyIter=monStudyBuilder.NewObject(HypReMeshEntry)
- self.editor.setAttributeValue(newStudyIter, "AttributeName", "YAMS Parameters_"+str(self.num))
- self.editor.setAttributeValue(newStudyIter, "AttributeComment", self.getResumeData(separator=" ; "))
+ 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(0)
- self.num+=1
+ 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):
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 YAMS Hypothesis", "Problem on '"+lig+"'")
+ QMessageBox.warning(self, "load MGSurfOpt Hypothesis", "Problem on '"+lig+"'")
def PBLoadPressed(self):
"""load last hypothesis saved in tail of file"""
def PBLoadHypPressed(self):
"""load hypothesis saved in Object Browser"""
- #QMessageBox.warning(self, "load Object Browser YAMS hypothesis", "TODO")
+ #QMessageBox.warning(self, "load Object Browser MGSurfOpt hypothesis", "TODO")
import salome
from salome.kernel import studyedit
from salome.smesh.smeshstudytools import SMeshStudyTools
mySObject, myEntry = guihelper.getSObjectSelected()
if CORBA.is_nil(mySObject) or mySObject==None:
- QMessageBox.critical(self, "Hypothese", "select an Object Browser YAMS hypothesis")
+ QMessageBox.critical(self, "Hypothese", "select an Object Browser MGSurfOpt hypothesis")
return
text=mySObject.GetComment()
#a verification
if "Optimisation=" not in text:
- QMessageBox.critical(self, "Load Hypothese", "Object Browser selection not a YAMS Hypothesis")
+ QMessageBox.critical(self, "Load Hypothese", "Object Browser selection not a MGSurfOptHypothesis")
return
self.loadResumeData(text, separator=" ; ")
return
if fd.exec_():
infile = fd.selectedFiles()[0]
self.LE_MeshFile.setText(infile)
- self.fichierIn=infile.toLatin1()
+ self.fichierIn=str(infile)
self.MeshIn=""
self.LE_MeshSmesh.setText("")
+ self.__selectedMesh=None
def setParamsFileName(self):
fd = QFileDialog(self, "select a file", self.LE_ParamsFile.text(), "dat Files (*.dat);;All Files (*)")
if fd.exec_():
infile = fd.selectedFiles()[0]
self.LE_ParamsFile.setText(infile)
- self.paramsFile=infile.toLatin1()
+ self.paramsFile=str(infile)
def meshFileNameChanged(self):
self.fichierIn=str(self.LE_MeshFile.text())
from salome.smesh.smeshstudytools import SMeshStudyTools
from salome.gui import helper as guihelper
from salome.smesh import smeshBuilder
- smesh = smeshBuilder.New(salome.myStudy)
+ smesh = smeshBuilder.New()
mySObject, myEntry = guihelper.getSObjectSelected()
if CORBA.is_nil(mySObject) or mySObject==None:
- #QMessageBox.critical(self, "Mesh", "select an input mesh")
- self.LE_MeshSmesh.setText("")
- self.MeshIn=""
- self.LE_MeshFile.setText("")
- self.fichierIn=""
+ QMessageBox.critical(self, "Mesh", "select an input mesh")
+ #self.LE_MeshSmesh.setText("")
+ #self.MeshIn=""
+ #self.LE_MeshFile.setText("")
+ #self.fichierIn=""
return
self.smeshStudyTool = SMeshStudyTools()
try:
self.fichierIn=""
def prepareFichier(self):
- self.fichierIn="/tmp/ForSurfOpt_"+str(self.num)+".meshb"
+ self.fichierIn=tempfile.mktemp(suffix=".mesh",prefix="ForSurfOpt_")
+ if os.path.exists(self.fichierIn):
+ os.remove(self.fichierIn)
self.__selectedMesh.ExportGMF(self.__selectedMesh, self.fichierIn, True)
def PrepareLigneCommande(self):
except:
pass
- style = self.style.toLatin1()
+ style = str(self.style)
# Translation of old Yams options to new MG-SurfOpt options
if style == "0" :
self.commande+= " --optimisation only"
self.commande+= " -O G" # This option has not been updated to the new option style yet
deb=os.path.splitext(self.fichierIn)
- self.fichierOut=deb[0] + "_output.meshb"
+ self.fichierOut=deb[0] + "_output.mesh"
tolerance=self.SP_toStr(self.SP_Tolerance)
if not self.RB_Absolute.isChecked():
if self.SP_Ridge.value() != 45.0 : self.commande+=" --ridge_angle %f"%self.SP_Ridge.value()
if self.SP_MaxSize.value() != 100 : self.commande+=" --max_size %f" %self.SP_MaxSize.value()
if self.SP_MinSize.value() != 5 : self.commande+=" --min_size %f" %self.SP_MinSize.value()
- if self.SP_Gradation.value() != 1.3 : self.commande+=" --gradation %f" %self.SP_MaxSize.value()
+ if self.SP_Gradation.value() != 1.3 : self.commande+=" --gradation %f" %self.SP_Gradation.value()
if self.SP_Memory.value() != 0 : self.commande+=" --max_memory %d" %self.SP_Memory.value()
if self.SP_Verbosity.value() != 3 : self.commande+=" --verbose %d" %self.SP_Verbosity.value()
- self.commande+=" --in " + self.fichierIn
- self.commande+=" --out " + self.fichierOut
+ self.commande+=' --in "' + self.fichierIn +'"'
+ self.commande+=' --out "' + self.fichierOut +'"'
- print self.commande
+ print(self.commande)
return True
def clean(self):
self.SP_MinSize.setProperty("value", 5)
self.SP_Verbosity.setProperty("value", 3)
self.SP_Memory.setProperty("value", 0)
- self.PBMeshSmeshPressed()
+ #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
global __dialog
if __dialog is None:
__dialog = MonYamsPlugDialog()
- else :
- __dialog.clean()
+ #else :
+ # __dialog.clean()
return __dialog
#
#
def TEST_MonYamsPlugDialog():
import sys
- from PyQt4.QtGui import QApplication
- from PyQt4.QtCore import QObject, SIGNAL, SLOT
+ from qtsalome import QApplication
app = QApplication(sys.argv)
- QObject.connect(app, SIGNAL("lastWindowClosed()"), app, SLOT("quit()"))
+ app.lastWindowClosed.connect(app.quit)
dlg=MonYamsPlugDialog()
dlg.show()