Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """
- Created on Wed Apr 17 14:23:06 2019
- @authors:
- Jonatan Lindholm
- Le Kuai
- Shaheda Tahmina Akter
- """
- import sys
- from PyQt5.QtCore import pyqtSlot, pyqtSignal, QThread
- from PyQt5.QtWidgets import QApplication, QDialog, QWidget, QMainWindow, QFileDialog
- from PyQt5.uic import loadUi
- import calfem.ui as cfui
- import input_data
- import output_data
- import solver
- import report
- import visualize
- ''' TODO list:
- - implementera New
- - implementera Open
- - implementera Save
- - implementera Save as...
- - implementera Exit
- - implementera ShowGeo
- - implementera ShowMesh
- - implementera ShowNodal
- - implementera ShowEle
- - implementera initModel
- - implementera updateControls
- - implementera updateModel
- - implementera onActionExecute
- - implementera onSolverFinished
- - implementera closeAll (S)
- - default values for w,h,a,b,t
- - ...
- '''
- ''' QUESTIONS:
- - calcDone, class SolverThread. Where do solver.execute() ?
- - EV: "When the calculation ends, the thread object will automatically
- invoke the self.onSolverFinished method." (S) men okej.
- -
- '''
- class SolverThread(QThread):
- def __init__(self, solver, paramStudy = False):
- QThread.__init__(self)
- self.solver = solver
- def __del__(self):
- self.wait()
- def run(self):
- self.solver.execute()
- class MainWindow(QMainWindow):
- # Purpose: load the interface description
- # and implement the event methods
- def __init__(self):
- super(QMainWindow, self).__init__()
- self.app = app
- self.ui = loadUi('mainwindow.ui', self)
- self.ui.show()
- self.ui.raise_()
- # Connect menu options to event handling functions:
- self.ui.actionNew.triggered.connect(self.onActionNew)
- self.ui.actionOpen.triggered.connect(self.onActionOpen)
- self.ui.actionSave.triggered.connect(self.onActionSave)
- self.ui.actionSave_as.triggered.connect(self.onActionSave_as)
- self.ui.actionExit.triggered.connect(self.onActionExit)
- self.ui.actionExecute.triggered.connect(self.onActionExecute)
- # Connect buttons to event handling functions:
- self.ui.showGeometryButton.clicked.connect(self.onShowGeometry)
- self.ui.showMeshButton.clicked.connect(self.onShowMesh)
- self.ui.showNodalValuesButton.clicked.connect(self.onShowNodalValues)
- self.ui.showElementValuesButton.clicked.connect(self.onShowElementValues)
- self.calcDone = True
- def onActionExecute(self):
- self.ui.setEnabled(False)
- self.updateModel()
- self.solver = fm.Solver(self.inputData, self.outputData)
- self.solverThread = SolverThread(self.solver)
- self.solverThread.finished.connect(self.onSolverFinished)
- self.calcDone = False
- self.solverThread.start()
- # "this thread finishes automatically."
- def onSolverFinished(self):
- self.ui.setEnabled(True)
- self.calcDone = True
- self.report = report.Report(self.inputData, self.outputData)
- self.ui.reportEdit.setPlainText(self.report.__str__())
- def initModel(self):
- #Creates the necessary items needed for input, output and
- #resolution of the problem. Also sets default values for
- #the parameters in the model.
- self.outputData = output_data.OutputData()
- self.inputData = input_data.InputData()
- self.inputData.load_standard_input()
- self.report = None #instead defined in function onSolverFinished.
- def updateControls(self):
- #Takes values from a InputData object and assigns the
- #controls to these values.
- self.ui.wEdit.setText(str(self.inputData.w))
- self.ui.hEdit.setText(str(self.inputData.h))
- self.ui.aEdit.setText(str(self.inputData.a))
- self.ui.bEdit.setText(str(self.inputData.b))
- self.ui.tEdit.setText(str(self.inputData.t))
- def updateModel(self):
- #Reads the specified values in the controls and assigns
- #them to the InputData object.
- self.inputData.w = float(self.ui.wEdit.text())
- def onActionNew(self):
- print("onActionNew")
- '''TODO'''
- def onActionOpen(self):
- print("onActionOpen")
- self.filename, _ = QFileDialog.getOpenFileName(self.ui,
- "Open model", "", "Model files (*.txt)");
- if self.filename!="":
- # input_data.load , typ.
- pass
- def onActionSave(self):
- print("onActionSave")
- self.updateModel()
- if self.filename == "":
- self.filename, _ = QFileDialog.getSaveFileName(self.ui,
- "Save model", "", "Model files (*.txt)");
- # input_data.save , typ.
- if self.filename!="":
- # input_data.save , typ.
- pass
- def onActionSave_as(self):
- print("onActionSave_as")
- '''TODO'''
- def onActionExit(self):
- print("onActionExit")
- '''TODO'''
- def onShowGeometry(self):
- print("onShowGeometry")
- '''TODO'''
- def onShowMesh(self):
- print("onShowMesh")
- '''TODO'''
- def onShowNodalValues(self):
- print("onShowNodalValues")
- '''TODO'''
- def onShowElementValues(self):
- print("onShowElementValues")
- '''TODO'''
- if __name__ == '__main__':
- app = QApplication(sys.argv)
- widget = MainWindow()
- widget.show()
- sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement