/
ChEsher.py
519 lines (440 loc) · 19.3 KB
/
ChEsher.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
#!/usr/bin/python -d
#
# Copyright (C) 2016 Reinhard Fleissner
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
"""Main module"""
__author__="Reinhard Fleissner"
__date__ ="$31.03.2015 18:21:40$"
import os
import sys
import platform
import webbrowser
lib_modules = os.path.abspath(os.path.join('py/modules'))
lib_ui = os.path.abspath(os.path.join('py/ui'))
lib_py = os.path.abspath(os.path.join('py/py'))
sys.path.append(lib_modules)
sys.path.append(lib_ui)
sys.path.append(lib_py)
from moduleDXF2BK import WrapDXF2BK
from moduleBK2DXF import WrapBK2DXF
from moduleMesh import WrapMesh
from moduleLandXML import WrapLandXML
from moduleScalarDXF import WrapScalarDXF
from moduleVectorDXF import WrapVectorDXF
from moduleCS import WrapCS
from module2DM2BK import Wrap2DM2BK
from moduleCont2DXF import WrapCont2DXF
from moduleTube import WrapTube
from moduleHyDesign import WrapHyDesign
from moduleXYZ2Profiles import WrapXYZ2Profiles
from moduleHEC2DXF import WrapHEC2DXF
from moduleXYZ2DXF import WrapXYZ2DXF
from moduleProfilesDXF import WrapProfilesDXF
from moduleMergeMesh import WrapMergeMesh
from PyQt4 import QtCore, QtGui
from PyQt4.QtGui import QFileDialog, QAction, QMessageBox, QIcon, QMessageBox
from PyQt4.QtCore import PYQT_VERSION_STR, QT_VERSION_STR, Qt, SIGNAL
from uiChEsher import Ui_MainWindow
from resource_rc import *
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s
class ChEsher(QtGui.QMainWindow):
"""Main class.
Create menubar, toolbar, actions.
Translate the application.
Switch between module ENGINEERING and EDUCATION.
"""
def __init__(self, app, parent=None):
"""Constructor for main class.
Keyword arguments:
app -- the application
"""
super(ChEsher, self).__init__(parent)
self._app = app
# setup user interface of main window
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
# variables
self.directory = ""
# setup instance of module DXF2BK
self.moduleDXF2BK = WrapDXF2BK()
self.widgetDXF2BK = self.moduleDXF2BK.widget
self.ui.stackedWidget.insertWidget(0, self.widgetDXF2BK)
# setup instance of module BK2DXF
self.moduleBK2DXF = WrapBK2DXF()
self.widgetBK2DXF = self.moduleBK2DXF.widget
self.ui.stackedWidget.insertWidget(1, self.widgetBK2DXF)
# setup instance of module Mesh
self.moduleMesh = WrapMesh()
self.widgetMesh = self.moduleMesh.widget
self.ui.stackedWidget.insertWidget(2, self.widgetMesh)
# setup instance of module LandXML
self.moduleLandXML = WrapLandXML()
self.widgetLandXML = self.moduleLandXML.widget
self.ui.stackedWidget.insertWidget(3, self.widgetLandXML)
# setup instance of module ScalarDXF
self.moduleScalarDXF = WrapScalarDXF()
self.widgetScalarDXF = self.moduleScalarDXF.widget
self.ui.stackedWidget.insertWidget(4, self.widgetScalarDXF)
# setup instance of module VectorDXF
self.moduleVectorDXF = WrapVectorDXF()
self.widgetVectorDXF = self.moduleVectorDXF.widget
self.ui.stackedWidget.insertWidget(5, self.widgetVectorDXF)
# setup instance of module CS
self.moduleCS = WrapCS()
self.widgetCS = self.moduleCS.widget
self.ui.stackedWidget.insertWidget(6, self.widgetCS)
# setup instance of module 2DM2BK
self.module2DM2BK = Wrap2DM2BK()
self.widget2DM2BK = self.module2DM2BK.widget
self.ui.stackedWidget.insertWidget(7, self.widget2DM2BK)
# setup instance of module Cont2DXF
self.moduleCont2DXF = WrapCont2DXF()
self.widgetCont2DXF = self.moduleCont2DXF.widget
self.ui.stackedWidget.insertWidget(8, self.widgetCont2DXF)
# setup instance of module Tube
self.moduleTube = WrapTube()
self.widgetTube = self.moduleTube.widget
self.ui.stackedWidget.insertWidget(9, self.widgetTube)
# setup instance of module XYZ2Profiles
self.moduleXYZ2Profiles = WrapXYZ2Profiles()
self.widgetXYZ2Profiles = self.moduleXYZ2Profiles.widget
self.ui.stackedWidget.insertWidget(10, self.widgetXYZ2Profiles)
# setup instance of module ProfilesDXF
self.moduleProfilesDXF = WrapProfilesDXF()
self.widgetProfilesDXF = self.moduleProfilesDXF.widget
self.ui.stackedWidget.insertWidget(11, self.widgetProfilesDXF)
# setup instance of module HEC2DXF
self.moduleHEC2DXF = WrapHEC2DXF()
self.widgetHEC2DXF = self.moduleHEC2DXF.widget
self.ui.stackedWidget.insertWidget(12, self.widgetHEC2DXF)
# setup instance of module XYZ2DXF
self.moduleXYZ2DXF = WrapXYZ2DXF()
self.widgetXYZ2DXF = self.moduleXYZ2DXF.widget
self.ui.stackedWidget.insertWidget(13, self.widgetXYZ2DXF)
# setup instance of module HyDesign
self.moduleMergeMesh = WrapMergeMesh()
self.widgetMergeMesh = self.moduleMergeMesh.widget
self.ui.stackedWidget.insertWidget(14, self.widgetMergeMesh)
# setup instance of module HyDesign
self.moduleHyDesign = WrapHyDesign()
self.widgetHyDesign = self.moduleHyDesign.widget
self.ui.stackedWidget.insertWidget(15, self.widgetHyDesign)
# actions in menu
self.fileSetDirectory = self.createAction("Set working directory", slot=self.setDirectory)
self.fileQuitAction = self.createAction("Close", slot=self.close, \
shortcut="Ctrl+Q")
self.fileSetExamples = self.createAction("Initialize examples", slot=self.initializeModules)
self.helpAction = self.createAction("Help", slot=self.help, shortcut="F1")
# modules
self.setDXFtoBKAction = self.createAction("1 DXF2BK", slot=self.setDXF2BK)
self.setBK2DXFAction = self.createAction("2 BK2DXF", slot=self.setBK2DXF)
self.setMeshAction = self.createAction("3 Mesh", slot=self.setMesh)
self.setXMLAction = self.createAction("4 LandXML", slot=self.setLandXML)
self.setScalarAction = self.createAction("5 ScalarDXF", slot=self.setScalarDXF)
self.setVectorAction = self.createAction("6 VectorDXF", slot=self.setVectorDXF)
self.setCSAction = self.createAction("7 CS", slot=self.setCS)
self.set2DMAction = self.createAction("8 2DM2BK", slot=self.set2DM2BK)
self.setCont2DXFAction = self.createAction("9 Cont2DXF", slot=self.setCont2DXF)
self.setTubeAction = self.createAction("10 Tube", slot=self.setTube)
self.setProfilesAction = self.createAction("11 XYZ2Profiles", slot=self.setXYZ2Profiles)
self.setProfilesDXFAction = self.createAction("12 ProfilesDXF", slot=self.setProfilesDXF)
self.setHEC2DXFAction = self.createAction("13 HEC2DXF", slot=self.setHEC2DXF)
self.setXYZ2DXFAction = self.createAction("14 XYZ2DXF", slot=self.setXYZ2DXF)
self.setMergeMeshAction = self.createAction("15 MergeMesh", slot=self.setMergeMesh)
# tools
self.setHyDesignAction = self.createAction("1 HyDesign", slot=self.setHyDesign)
# help
self.helpAboutAction = self.createAction("&About", \
self.helpAbout)
# create menu
self.fileMenu = self.menuBar().addMenu("ChEsher")
self.modulesMenu = self.menuBar().addMenu("Modules")
self.toolsMenu = self.menuBar().addMenu("Tools")
self.helpMenu = self.menuBar().addMenu("Help")
# add actions to menu
self.addActions(self.fileMenu, ( \
self.fileSetDirectory,
self.fileSetExamples,
None,
self.fileQuitAction
))
self.addActions(self.modulesMenu, ( \
self.setDXFtoBKAction, \
self.setBK2DXFAction,
self.setMeshAction,
self.setXMLAction,
self.setScalarAction,
self.setVectorAction,
self.setCSAction,
self.set2DMAction,
self.setCont2DXFAction,
self.setTubeAction,
self.setProfilesAction,
self.setProfilesDXFAction,
self.setHEC2DXFAction,
self.setXYZ2DXFAction,
self.setMergeMeshAction
))
self.addActions(self.toolsMenu, ( \
self.setHyDesignAction,
))
self.addActions(self.helpMenu, (self.helpAction, None, self.helpAboutAction))
# self.setDXF2BK()
# self.setMesh()
# self.setCont2DXF()
# self.setTube()
# self.setHEC2DXF()
# self.setXYZ2Profiles()
# self.setProfilesDXF()
# self.setXYZ2DXF()
# self.initialize()
# self.setMergeMesh()
# self.setScalarDXF()
# self.initialize()
def setType(self):
self.calcDischarge()
self.updateUi()
def initializeModules(self):
answer = QMessageBox.question(self, "Initialize examples", "Do you really want to overwrite all inputs to initialize examples?", QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
if answer == QtGui.QMessageBox.Yes:
self.initialize()
elif answer == QtGui.QMessageBox.No:
return
def initialize(self):
def makedir(dir):
if not os.path.exists(dir):
os.makedirs(dir)
abs_path = os.path.abspath('.')
self.directory = os.path.join(abs_path, 'examples/').replace('\\', '/')
makedir(self.directory + "example_01/output/")
makedir(self.directory + "example_02/output/")
makedir(self.directory + "example_03/output/")
makedir(self.directory + "example_04/output/")
makedir(self.directory + "example_05/output/")
makedir(self.directory + "example_06/output/")
makedir(self.directory + "example_07/output/")
makedir(self.directory + "example_08/output/")
makedir(self.directory + "example_09/output/")
makedir(self.directory + "example_10/output/")
makedir(self.directory + "example_11/output/")
makedir(self.directory + "example_12/output/")
makedir(self.directory + "example_13/output/")
makedir(self.directory + "example_14/output/")
makedir(self.directory + "example_15/output/")
self.moduleDXF2BK.initialize()
self.moduleBK2DXF.initialize()
self.moduleMesh.initialize()
self.moduleLandXML.initialize()
self.moduleScalarDXF.initialize()
self.moduleVectorDXF.initialize()
self.moduleCS.initialize()
self.module2DM2BK.initialize()
self.moduleCont2DXF.initialize()
self.moduleTube.initialize()
self.moduleXYZ2Profiles.initialize()
self.moduleProfilesDXF.initialize()
self.moduleHEC2DXF.initialize()
self.moduleXYZ2DXF.initialize()
self.moduleMergeMesh.initialize()
def setDXF2BK(self):
self.ui.labelModule.setText("~ Module DXF2BK ~")
self.ui.stackedWidget.setCurrentIndex(0)
def setBK2DXF(self):
self.ui.labelModule.setText("~ Module BK2DXF ~")
self.ui.stackedWidget.setCurrentIndex(1)
def setMesh(self):
self.ui.labelModule.setText("~ Module Mesh ~")
self.ui.stackedWidget.setCurrentIndex(2)
def setLandXML(self):
self.ui.labelModule.setText("~ Module LandXML ~")
self.ui.stackedWidget.setCurrentIndex(3)
def setScalarDXF(self):
self.ui.labelModule.setText("~ Module ScalarDXF ~")
self.ui.stackedWidget.setCurrentIndex(4)
def setVectorDXF(self):
self.ui.labelModule.setText("~ Module VectorDXF ~")
self.ui.stackedWidget.setCurrentIndex(5)
def setCS(self):
self.ui.labelModule.setText("~ Module CS ~")
self.ui.stackedWidget.setCurrentIndex(6)
def set2DM2BK(self):
self.ui.labelModule.setText("~ Module 2DM2BK ~")
self.ui.stackedWidget.setCurrentIndex(7)
def setCont2DXF(self):
self.ui.labelModule.setText("~ Module Cont2DXF ~")
self.ui.stackedWidget.setCurrentIndex(8)
def setTube(self):
self.ui.labelModule.setText("~ Module Tube ~")
self.ui.stackedWidget.setCurrentIndex(9)
def setXYZ2Profiles(self):
self.ui.labelModule.setText("~ Module XYZ2Profiles ~")
self.ui.stackedWidget.setCurrentIndex(10)
def setProfilesDXF(self):
self.ui.labelModule.setText("~ Module ProfilesDXF ~")
self.ui.stackedWidget.setCurrentIndex(11)
def setHEC2DXF(self):
self.ui.labelModule.setText("~ HEC2DXF ~")
self.ui.stackedWidget.setCurrentIndex(12)
def setXYZ2DXF(self):
self.ui.labelModule.setText("~ XYZ2DXF ~")
self.ui.stackedWidget.setCurrentIndex(13)
def setMergeMesh(self):
self.ui.labelModule.setText("~ Module MergeMesh ~")
self.ui.stackedWidget.setCurrentIndex(14)
def setHyDesign(self):
self.ui.labelModule.setText("~ Tool HyDesign ~")
self.ui.stackedWidget.setCurrentIndex(15)
def setDirectory(self):
dir = QFileDialog.getExistingDirectory(self, "Select directory", self.directory)
if dir != "":
self.moduleDXF2BK.setDir(dir)
self.moduleBK2DXF.setDir(dir)
self.moduleMesh.setDir(dir)
self.moduleLandXML.setDir(dir)
self.moduleScalarDXF.setDir(dir)
self.moduleVectorDXF.setDir(dir)
self.moduleCS.setDir(dir)
self.module2DM2BK.setDir(dir)
self.moduleCont2DXF.setDir(dir)
self.moduleTube.setDir(dir)
self.moduleProfilesDXF.setDir(dir)
self.moduleHEC2DXF.setDir(dir)
self.moduleXYZ2DXF.setDir(dir)
self.moduleXYZ2Profiles.setDir(dir)
self.moduleMergeMesh.setDir(dir)
self.directory = dir
else:
return
# def interpolatePoint(self, xa, ya, za, xb, yb, zb, xc, yc, zc, xp, yp):
# dot1 = (yb - ya)*(xp - xa) + (-xb + xa)*(yp - ya)
# dot2 = (yc - yb)*(xp - xb) + (-xc + xb)*(yp - yb)
# dot3 = (ya - yc)*(xp - xc) + (-xa + xc)*(yp - yc)
#
# zp = 0.0
# counter = 0
# if dot1 <= 0.0 and dot2 <= 0.0 and dot3 <= 0.0:
#
# #Determine two vectors from the points:
# v1 = [xc - xa, yc - ya, zc - za]
# v2 = [xb - xa, yb - ya, zb - za]
#
# #Determine the cross product of the two vectors:
# cp = [v1[1] * v2[2] - v1[2] * v2[1],
# v1[2] * v2[0] - v1[0] * v2[2],
# v1[0] * v2[1] - v1[1] * v2[0]]
#
# #A plane can be described using a simple equation ax + by + cz = d. The three coefficients from the cross product are a, b and c, and d can be solved by substituting a known point, for example the first:
# a, b, c = cp
# d = a * xa + b * ya + c * za
#
# #Determine the z value at x, y. Re-arrange the simple equation, and solve for z:
# zp = (d - a * xp - b * yp) / float(c)
# counter = 1
# else:
# counter = 0
# return zp, counter
#
# def insideBoundingBox(self, xa, ya, xb, yb, xc, yc, xp, yp):
#
# xMin = min([xa, xb, xc])
# xMax = max([xa, xb, xc])
# yMin = min([ya, yb, yc])
# yMax = max([ya, yb, yc])
#
# if xp >= xMin and xp <= xMax and yp >= yMin and yp <= yMax:
# return True
# else:
# return False
#
# def getTriangles(self, mesh, nodesMajor, nodesMinor):
#
# x = []
# y = []
# zMajor = []
# zMinor = []
#
# triangles = []
# for nID in nodesMajor:
# x.append(nodesMajor[nID][0])
# y.append(nodesMajor[nID][1])
# zMajor.append(nodesMajor[nID][2])
# if nodesMinor is not None:
# zMinor.append(nodesMinor[nID][2])
#
# for eID in mesh:
# n1 = mesh[eID][0]-1
# n2 = mesh[eID][1]-1
# n3 = mesh[eID][2]-1
# triangles.append([n1,n2,n3])
#
# return x, y, zMajor, zMinor, triangles
def createAction(self, text="", slot=None, shortcut=None, icon=None,
tip=None, checkable=False, signal="triggered()"):
"""Create action out of keyword arguments. Return action.
Keyword arguments:
text -- User visible text (default "")
slot -- function to call (default None)
shortcut -- Key sequence (default None)
icon -- Name of icon file (default None)
tip -- Tooltip (default None)
checkable -- Should action be checkable (default None)
signal -- Signal to emit (default "triggered()")
"""
action = QAction(text, self)
if icon is not None:
action.setIcon(QIcon(":/resource/{0}.png".format(icon)))
if shortcut is not None:
action.setShortcut(shortcut)
if tip is not None:
action.setToolTip(tip)
action.setStatusTip(tip)
if slot is not None:
self.connect(action, SIGNAL(signal), slot)
if checkable:
action.setCheckable(True)
return action
def addActions(self, target, actions):
"""Add action or separator to menu.
Keyword arguments:
target -- name of menu
actions -- tuple with names of actions
"""
for action in actions:
if action is None:
target.addSeparator()
else:
target.addAction(action)
def help(self):
abs_path = os.path.abspath('.')
filename = os.path.join(abs_path, 'documentation/00_index.html')
webbrowser.open(filename)
def helpAbout(self):
"""Setup the About-dialog."""
msg = u"""<p><b>ChEsher</b> V 1.1</p>
<p>Additional tool to <a href="http://www.nrc-cnrc.gc.ca/eng/solutions/advisory/blue_kenue_index.html">Blue Kenue™</a> that is a pre and post processing software for the <a href="http://www.opentelemac.org/">open TELEMAC-MASCARET</a> system - an integrated suite of solvers for use in the field of free-surface flow of hydraulic modeling. </p>
<p>Copyright \u00A9 2016 <a href="mailto:reinhard.fleissner@gmail.com?subject=ChEsher">Reinhard Flei\xdfner</a></p>
<hr/>
<p>Python {0} - Qt {1} - PyQt {2} - {3}</p>""".format(
platform.python_version(),
QT_VERSION_STR,
PYQT_VERSION_STR,
platform.system()
)
QMessageBox.about(self, "About ChEsher", msg)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = ChEsher(app)
myapp.show()
sys.exit(app.exec_())