forked from jjcremmers/PyFEM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
XPyFEM.py
197 lines (151 loc) · 6.84 KB
/
XPyFEM.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
############################################################################
# This Python file is part of PyFEM, the code that accompanies the book: #
# #
# 'Non-Linear Finite Element Analysis of Solids and Structures' #
# R. de Borst, M.A. Crisfield, J.J.C. Remmers and C.V. Verhoosel #
# John Wiley and Sons, 2012, ISBN 978-0470666449 #
# #
# The code is written by J.J.C. Remmers, C.V. Verhoosel and R. de Borst. #
# #
# The latest stable version can be downloaded from the web-site: #
# http://www.wiley.com/go/deborst #
# #
# A github repository, with the most up to date version of the code, #
# can be found here: #
# https://github.com/jjcremmers/PyFEM #
# #
# The code is open source and intended for educational and scientific #
# purposes only. If you use PyFEM in your research, the developers would #
# be grateful if you could cite the book. #
# #
# Disclaimer: #
# The authors reserve all rights but do not guarantee that the code is #
# free from errors. Furthermore, the authors shall not be liable in any #
# event caused by the use of the program. #
############################################################################
import sys
from PyQt5 import QtGui,QtCore
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QAction, QFileDialog
from PyQt5.QtGui import QIcon
#from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
#from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar
#import matplotlib.pyplot as plt
import os.path
from pyfem.io.InputReader import InputRead
from pyfem.io.OutputManager import OutputManager
from pyfem.solvers.Solver import Solver
class MyPopup(QWidget):
def __init__(self):
QWidget.__init__(self)
def paintEvent(self, e):
dc = QtGui.QPainter(self)
dc.drawLine(0, 0, 100, 100)
dc.drawLine(100, 0, 0, 100)
class XPyFEM(QMainWindow):
def __init__(self):
super(XPyFEM, self).__init__()
self.initUI()
def initUI(self):
#self.textEdit = QtGui.QTextEdit()
#self.setCentralWidget(self.textEdit)
self.statusBar()
menubar = self.menuBar()
fileMenu = menubar.addMenu('File')
editMenu = menubar.addMenu('Edit')
viewMenu = menubar.addMenu('View')
searchMenu = menubar.addMenu('Search')
toolsMenu = menubar.addMenu('Tools')
helpMenu = menubar.addMenu('Help')
# Add exit button
newFile = QAction(QIcon('new128.png'),'&New', self )
newFile.setShortcut('Ctrl+N')
newFile.setStatusTip('New project')
openFile = QAction(QIcon('pyfem/qt/img/open128.png'),'&Open', self )
openFile.setShortcut('Ctrl+O')
openFile.setStatusTip('Open new File')
openFile.triggered.connect(self.showDialog)
saveFile = QAction(QIcon('pyfem/qt/img/save128.png'),'&Save', self )
saveFile.setShortcut('Ctrl+S')
saveFile.setStatusTip('Save File')
saveFile.triggered.connect(self.showDialog)
# Add exit button
exitButton = QAction(QIcon('new128.png'),'&Exit', self)
exitButton.setShortcut('Ctrl+Q')
exitButton.setStatusTip('Exit application')
exitButton.setIconText("Exit")
exitButton.triggered.connect(self.close)
fileMenu.addAction(exitButton)
# Add exit button
editProButton = QAction(QtGui.QIcon('pyfem/qt/img/edit128.png'),'&Edit', self)
editProButton.setStatusTip('EDit')
editProButton.setIconText("Edit Pro")
editProButton.triggered.connect(self.doit)
# Add exit button
runButton = QAction(QtGui.QIcon('pyfem/qt/img/run128.png'),'&Run', self)
runButton.setShortcut('Ctrl+R')
runButton.setStatusTip('Run simulation')
runButton.setIconText("Run")
runButton.triggered.connect(self.runIt)
# Add exit button
abortButton = QAction(QtGui.QIcon('pyfem/qt/img/abort128.png'),'&Exit', self)
abortButton.setShortcut('Ctrl+C')
abortButton.setStatusTip('Abort simulation')
abortButton.setIconText("Abort")
abortButton.triggered.connect(self.cancelIt)
fileMenu.addAction(newFile)
fileMenu.addAction(openFile)
fileMenu.addAction(saveFile)
fileMenu.addAction(exitButton)
editMenu = menubar.addMenu('&Edit')
editMenu.addAction(editProButton)
# editMenu.addAction(openFile)
# editMenu.addAction(saveFile)
# editMenu.addAction(exitButton)
runMenu = menubar.addMenu('&Run')
runMenu.addAction(runButton)
runMenu.addAction(abortButton)
# runMenu.addAction(saveFile)
# runMenu.addAction(exitButton)
self.setGeometry(600, 400, 650, 400)
self.setWindowTitle('PyFEM')
self.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)
self.toolbar = self.addToolBar('Exit')
self.toolbar.addAction(openFile)
self.toolbar.addAction(runButton)
self.toolbar.addAction(abortButton)
"""
self.figure = plt.figure()
self.canvas = FigureCanvas(self.figure)
self.toolbar2 = NavigationToolbar(self.canvas, self)
layout = QtGui.QVBoxLayout()
layout.addWidget(self.toolbar)
layout.addWidget(self.canvas)
"""
self.setWindowIcon(QtGui.QIcon('pyfem/qt/img/pyfem_icon.png'))
self.show()
def showDialog(self):
fname = QFileDialog.getOpenFileName(self, 'Open file','.pro')[0]
os.chdir(os.path.dirname(str(fname)))
self.props,self.globdat = InputRead( str(fname) )
print("File ",os.path.basename(str(fname))," is ready. Press RUN to start the simulation.\n\n")
def runIt(self):
solver = Solver ( self.props , self.globdat )
output = OutputManager ( self.props , self.globdat )
while self.globdat.active:
solver.run( self.props , self.globdat )
output.run( self.props , self.globdat )
print("Simulation finished.")
sys.exit()
def cancelIt(self):
print("Abort simulation.")
def doit(self):
print("Opening a new popup window...")
self.w = MyPopup()
self.w.setGeometry(100, 100, 400, 200)
self.w.show()
def main():
app = QApplication(sys.argv)
ex = XPyFEM()
sys.exit(app.exec_())
if __name__ == '__main__':
main()