Salome HOME
spns #19079: Top-ii-vol integration in SMESH
[modules/smesh.git] / src / Tools / TopIIVolMeshPlug / TopIIVolMeshMonitor.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2013-2020  EDF R&D
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 import os
22 import sys
23 import string
24 import types
25 import tempfile
26 import traceback
27 import pprint as PP #pretty print
28
29 from qtsalome import *
30
31 # Import des panels
32
33 from TopIIVolMeshMonitor_ui import Ui_qdLogger
34
35 verbose = True
36
37 class TopIIVolMeshMonitor(Ui_qdLogger, QDialog):
38   def __init__(self, parent, txt):
39     QDialog.__init__(self,parent)
40     self.setupUi(self)
41     self.resize( QSize(1000,600).expandedTo(self.minimumSizeHint()) )
42     self.qpbOK.clicked.connect( self.OnQpbOKClicked )
43     # Button OK is disabled until computation is finished
44     self.qpbOK.setEnabled(False)
45     self.qpbSave.clicked.connect( self.OnQpbSaveClicked )
46     self.qpbSave.setToolTip("Save trace in log file")
47     self.qpbOK.setToolTip("Close view")
48     self.myExecutable=QProcess(self)
49     self.myExecutable.readyReadStandardOutput.connect( self.readFromStdOut )
50     self.myExecutable.readyReadStandardError.connect( self.readFromStdErr )
51     self.myExecutable.finished.connect( self.computationFinished )
52     self.myExecutable.errorOccurred.connect( self.computationOnError )
53     if os.path.exists(self.parent().outputMesh):
54        os.remove(self.parent().outputMesh)
55     self.myExecutable.start(txt)
56     self.myExecutable.closeWriteChannel()
57     self.show()
58
59   def OnQpbOKClicked(self):
60     self.close()
61
62   def OnQpbSaveClicked(self):
63     outputDirectory=os.path.expanduser("~")
64     fn, mask = QFileDialog.getSaveFileName(None,"Save File",outputDirectory)
65     if not fn:
66       return
67     ulfile = os.path.abspath(str(fn))
68     try:
69       f = open(fn, 'wb')
70       f.write(self.qtbLogWindow.toPlainText().encode("utf-8"))
71       f.close()
72     except IOError as why:
73       QMessageBox.critical(self, 'Save File',
74                                  'The file <b>%s</b> could not be saved.<br>Reason: %s'%(str(fn), str(why)))
75
76   def readFromStdErr(self):
77     a=self.myExecutable.readAllStandardError()
78     aa=a.data().decode(errors='ignore')
79     self.qtbLogWindow.append(aa)
80
81   def readFromStdOut(self) :
82     a=self.myExecutable.readAllStandardOutput()
83     aa=a.data().decode(errors='ignore')
84     self.qtbLogWindow.append(aa)
85
86   def computationFinished(self):
87     self.qpbOK.setEnabled(True)
88     if self.myExecutable.exitCode() == 0:
89       self.parent().saveOutputMesh()
90     else:
91       QMessageBox.critical(self, 'Computation failed',
92                                  'The computation has failed.<br>Please, check the log message.')
93
94   def computationOnError(self):
95     self.qpbOK.setEnabled(True)
96     QMessageBox.critical(self, 'Computation failed',
97                                'The computation has failed.<br>Please, check the log message.')