Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.70 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Wed Apr 17 14:23:06 2019
  4.  
  5. @authors:
  6. Jonatan Lindholm
  7. Le Kuai
  8. Shaheda Tahmina Akter
  9. """
  10.  
  11. import sys
  12.  
  13. from PyQt5.QtCore import pyqtSlot, pyqtSignal, QThread
  14. from PyQt5.QtWidgets import QApplication, QDialog, QWidget, QMainWindow, QFileDialog
  15. from PyQt5.uic import loadUi
  16.  
  17. import calfem.ui as cfui
  18. import input_data
  19. import output_data
  20. import solver
  21. import report
  22. import visualize
  23. ''' TODO list:
  24. - implementera New
  25. - implementera Open
  26. - implementera Save
  27. - implementera Save as...
  28. - implementera Exit
  29.  
  30. - implementera ShowGeo
  31. - implementera ShowMesh
  32. - implementera ShowNodal
  33. - implementera ShowEle
  34.  
  35. - implementera initModel
  36. - implementera updateControls
  37. - implementera updateModel
  38.  
  39. - implementera onActionExecute
  40. - implementera onSolverFinished
  41.  
  42. - implementera closeAll (S)
  43.  
  44. - default values for w,h,a,b,t
  45. - ...
  46. '''
  47. ''' QUESTIONS:
  48. - calcDone, class SolverThread. Where do solver.execute() ?
  49. - EV: "When the calculation ends, the thread object will automatically
  50. invoke the self.onSolverFinished method." (S) men okej.
  51.  
  52. -
  53.  
  54.  
  55. '''
  56. class SolverThread(QThread):
  57. def __init__(self, solver, paramStudy = False):
  58. QThread.__init__(self)
  59. self.solver = solver
  60.  
  61. def __del__(self):
  62. self.wait()
  63.  
  64. def run(self):
  65. self.solver.execute()
  66.  
  67.  
  68. class MainWindow(QMainWindow):
  69. # Purpose: load the interface description
  70. # and implement the event methods
  71. def __init__(self):
  72. super(QMainWindow, self).__init__()
  73. self.app = app
  74.  
  75. self.ui = loadUi('mainwindow.ui', self)
  76. self.ui.show()
  77. self.ui.raise_()
  78.  
  79. # Connect menu options to event handling functions:
  80. self.ui.actionNew.triggered.connect(self.onActionNew)
  81. self.ui.actionOpen.triggered.connect(self.onActionOpen)
  82. self.ui.actionSave.triggered.connect(self.onActionSave)
  83. self.ui.actionSave_as.triggered.connect(self.onActionSave_as)
  84. self.ui.actionExit.triggered.connect(self.onActionExit)
  85. self.ui.actionExecute.triggered.connect(self.onActionExecute)
  86.  
  87. # Connect buttons to event handling functions:
  88. self.ui.showGeometryButton.clicked.connect(self.onShowGeometry)
  89. self.ui.showMeshButton.clicked.connect(self.onShowMesh)
  90. self.ui.showNodalValuesButton.clicked.connect(self.onShowNodalValues)
  91. self.ui.showElementValuesButton.clicked.connect(self.onShowElementValues)
  92. self.calcDone = True
  93.  
  94. def onActionExecute(self):
  95. self.ui.setEnabled(False)
  96. self.updateModel()
  97. self.solver = fm.Solver(self.inputData, self.outputData)
  98. self.solverThread = SolverThread(self.solver)
  99. self.solverThread.finished.connect(self.onSolverFinished)
  100. self.calcDone = False
  101. self.solverThread.start()
  102. # "this thread finishes automatically."
  103.  
  104. def onSolverFinished(self):
  105. self.ui.setEnabled(True)
  106. self.calcDone = True
  107. self.report = report.Report(self.inputData, self.outputData)
  108. self.ui.reportEdit.setPlainText(self.report.__str__())
  109.  
  110. def initModel(self):
  111. #Creates the necessary items needed for input, output and
  112. #resolution of the problem. Also sets default values for
  113. #the parameters in the model.
  114. self.outputData = output_data.OutputData()
  115. self.inputData = input_data.InputData()
  116. self.inputData.load_standard_input()
  117. self.report = None #instead defined in function onSolverFinished.
  118.  
  119. def updateControls(self):
  120. #Takes values from a InputData object and assigns the
  121. #controls to these values.
  122. self.ui.wEdit.setText(str(self.inputData.w))
  123. self.ui.hEdit.setText(str(self.inputData.h))
  124. self.ui.aEdit.setText(str(self.inputData.a))
  125. self.ui.bEdit.setText(str(self.inputData.b))
  126. self.ui.tEdit.setText(str(self.inputData.t))
  127.  
  128. def updateModel(self):
  129. #Reads the specified values in the controls and assigns
  130. #them to the InputData object.
  131. self.inputData.w = float(self.ui.wEdit.text())
  132.  
  133. def onActionNew(self):
  134. print("onActionNew")
  135. '''TODO'''
  136. def onActionOpen(self):
  137. print("onActionOpen")
  138. self.filename, _ = QFileDialog.getOpenFileName(self.ui,
  139. "Open model", "", "Model files (*.txt)");
  140. if self.filename!="":
  141. # input_data.load , typ.
  142. pass
  143.  
  144. def onActionSave(self):
  145. print("onActionSave")
  146. self.updateModel()
  147. if self.filename == "":
  148. self.filename, _ = QFileDialog.getSaveFileName(self.ui,
  149. "Save model", "", "Model files (*.txt)");
  150. # input_data.save , typ.
  151. if self.filename!="":
  152. # input_data.save , typ.
  153. pass
  154.  
  155. def onActionSave_as(self):
  156. print("onActionSave_as")
  157. '''TODO'''
  158. def onActionExit(self):
  159. print("onActionExit")
  160. '''TODO'''
  161.  
  162. def onShowGeometry(self):
  163. print("onShowGeometry")
  164. '''TODO'''
  165. def onShowMesh(self):
  166. print("onShowMesh")
  167. '''TODO'''
  168. def onShowNodalValues(self):
  169. print("onShowNodalValues")
  170. '''TODO'''
  171. def onShowElementValues(self):
  172. print("onShowElementValues")
  173. '''TODO'''
  174.  
  175.  
  176.  
  177. if __name__ == '__main__':
  178. app = QApplication(sys.argv)
  179. widget = MainWindow()
  180. widget.show()
  181. sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement