-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtruss.py
2628 lines (2247 loc) · 112 KB
/
truss.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
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
GPL-3.0 License
Copyright (C) 2020-2022 Monirul Shawon
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 3 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.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import datetime
import os
import pickle
import re
import subprocess
import sys
import tempfile
from io import BytesIO
from math import ceil
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.backends.backend_qt5agg import \
FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt5agg import \
NavigationToolbar2QT as NavigationToolbar
from numpy.linalg import norm
from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *
from reportlab.lib import colors
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.lib.units import inch
from reportlab.lib.utils import ImageReader
from reportlab.pdfgen import canvas
from reportlab.platypus import (Image, PageBreak, Paragraph, SimpleDocTemplate,
Spacer, Table, TableStyle)
from supports import *
from ui_truss import Ui_WizardPage
plt.style.use('seaborn-bright')
class NumberedCanvas(canvas.Canvas):
def __init__(self, *args, **kwargs):
canvas.Canvas.__init__(self, *args, **kwargs)
self._saved_page_states = []
def showPage(self):
self._saved_page_states.append(dict(self.__dict__))
self._startPage()
def save(self):
"""add page info to each page (page x of y)"""
num_pages = len(self._saved_page_states)
for state in self._saved_page_states:
self.__dict__.update(state)
self.draw_page_number(num_pages)
canvas.Canvas.showPage(self)
canvas.Canvas.save(self)
def draw_page_number(self, page_count):
if self._pageNumber == 1:
self.setFillColor('steelblue')
self.drawString(
inch, 9.2*inch, """{+}##############################{+}############################## {+}""")
self.drawString(
inch, 9.4*inch, """{+}--------------------------------------------------{+}---------------------------------------------------{+}""")
self.drawString(inch, 9*inch, "{+}")
self.drawString(7*inch, 9*inch, "{+}")
self.drawString(inch, 8.8*inch, "{+}")
self.drawString(7*inch, 8.8*inch, "{+}")
self.drawString(inch, 8.6*inch, "{+}")
self.drawString(7*inch, 8.6*inch, "{+}")
self.drawString(inch, 8.4*inch, "{+}")
self.drawString(7*inch, 8.4*inch, "{+}")
self.drawString(inch, 8.2*inch, "{+}")
self.drawString(7*inch, 8.2*inch, "{+}")
self.drawString(inch, 8*inch, "{+}")
self.drawString(7*inch, 8*inch, "{+}")
self.drawString(inch, 7.8*inch, "{+}")
self.drawString(7*inch, 7.8*inch, "{+}")
self.drawString(
inch, 7.6*inch, """{+}##############################{+}############################## {+}""")
self.drawString(
inch, 7.4*inch, """{+}--------------------------------------------------{+}---------------------------------------------------{+}""")
self.setFillColor('black')
self.setAuthor("Monirul Shawon")
self.setTitle("Report")
self.setSubject("Details report for Truss 101")
self.setCreator("Truss 101")
elif self._pageNumber == 2:
im = ImageReader(buf_node)
self.drawImage(im, inch*2.8, inch*4, width=5.1*inch, height=4*inch)
elif self._pageNumber == member_page_start:
im = ImageReader(buf_element)
self.drawImage(im, inch*3.0, inch*6,
width=4.8*inch, height=3.7*inch)
elif self._pageNumber == support_page_start:
im = ImageReader(buf_support)
self.drawImage(im, inch*3.4, inch*6.2,
width=4.5*inch, height=3.5*inch)
# support
data = [('Support', 'Node', 'Type')]
for i, k in enumerate(support_report.keys()):
node = re.findall(r'\d+', k)
data.append((i+1, node[0], k.replace(node[0], '')))
t = Table(data, hAlign='RIGHT', repeatRows=1)
t.setStyle(TableStyle([
('ALIGN', (0, 0), (-1, -1), 'CENTER'),
('INNERGRID', (0, 0), (-1, -1), 0.25, colors.black),
('LINEBELOW', (0, 0), (2, 0), 2, colors.black),
]))
t.wrapOn(self, 400, 100)
t.drawOn(self, inch*4.5, inch*5)
elif self._pageNumber == page_count - stress_page_end:
im = ImageReader(buf_bar_force)
self.drawImage(im, inch*0.1, inch*3.5, width=8*inch, height=6*inch)
im = ImageReader(buf_reaction)
self.drawImage(im, inch*1, inch*0.1, width=6*inch, height=4*inch)
elif self._pageNumber == page_count - displacement_page_end:
im = ImageReader(buf_displacement)
self.drawImage(im, inch*3.8, inch*6,
width=4.5*inch, height=3.5*inch)
self.setFont("Helvetica", 7)
self.drawRightString(inch, 0.75 * inch,
"Page %d of %d" % (self._pageNumber, page_count))
class NavigationToolbar(NavigationToolbar):
'''
This is used to set customized navigation toolbar in graphs
'''
# toolitems = [t for t in NavigationToolbar.toolitems if
# t[0] in ('Home', 'Back', 'Forward', 'Pan', 'Zoom', 'Save')]
NavigationToolbar.toolitems = (
('Home', 'Reset original view', 'home', 'home'),
('Back', 'Back to previous view', 'back', 'back'),
('Forward', 'Forward to next view', 'forward', 'forward'),
(None, None, None, None),
('Pan', 'Pan axes with left mouse, zoom with right', 'move', 'pan'),
('Zoom', 'Zoom to rectangle', 'zoom_to_rect', 'zoom'),
('Tight layout', 'Use tight layout if everything doesn\'t fit in graph',
'subplots', 'configure_subplots'),
(None, None, None, None),
('Save', 'Save the figure', 'filesave', 'save_figure'),
)
class AlignDelegate(QStyledItemDelegate):
def initStyleOption(self, option, index):
super(AlignDelegate, self).initStyleOption(option, index)
option.displayAlignment = Qt.AlignCenter
class MainPage(QWizardPage):
def __init__(self, open=None, filename=None, demo=None, logger=None):
super(MainPage, self).__init__()
self.ui = Ui_WizardPage()
self.ui.setupUi(self)
self.open = open
self.filename = filename
self.demo = demo
self.logger = logger
self.save = 0
self.change = 0
self.savedemo = None
if self.demo:
self.savedemo = True
self.name = os.path.basename(self.filename[0])
'Unit conversion'
self.current_metric_index = []
self.current_imperial_index = [[0, 0, 0]]
self.unit_node = 1
self.displacement_unit = 12
self.reverse_unit = 1
self.displacement_factor = 0.1
self.force_unit = 1
self.bar_force_unit = 1
self.stress_unit = 1000
self.force_unit_name = 'k'
self.unit_report = [
'ft', 'kip (k)', 'kip (k)', 'ksi', 'in<super size=6>2</super>', 'in']
'Modified close event to close all matplotlib graph'
self.ui.closeEvent = self.closeEvent
'Graph widget 1'
self.graph_widget = QWidget()
self.graph_widget.figure1 = plt.figure()
self.graph_widget.canvas1 = FigureCanvas(self.graph_widget.figure1)
self.graph_widget.toolbar1 = NavigationToolbar(
self.graph_widget.canvas1, self.graph_widget)
self.ui.graphLayout_geometry.addWidget(self.graph_widget.toolbar1)
self.ui.graphLayout_geometry.addWidget(self.graph_widget.canvas1)
ax = self.graph_widget.figure1.add_subplot(111)
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
ax.grid(True)
'Graph widget 2'
self.graph_widget2 = QWidget()
self.graph_widget2.figure2 = plt.figure()
self.graph_widget2.canvas2 = FigureCanvas(self.graph_widget2.figure2)
self.graph_widget2.toolbar2 = NavigationToolbar(
self.graph_widget2.canvas2, self.graph_widget2)
self.ui.graphLayout_displacement.addWidget(self.graph_widget2.toolbar2)
self.ui.graphLayout_displacement.addWidget(self.graph_widget2.canvas2)
ax2 = self.graph_widget2.figure2.add_subplot(111)
ax2.axis('off')
'Graph widget 3'
self.graph_widget3 = QWidget()
self.graph_widget3.figure3 = plt.figure()
self.graph_widget3.canvas3 = FigureCanvas(self.graph_widget3.figure3)
self.graph_widget3.toolbar3 = NavigationToolbar(
self.graph_widget3.canvas3, self.graph_widget3)
self.ui.graphLayout_result.addWidget(self.graph_widget3.toolbar3)
self.ui.graphLayout_result.addWidget(self.graph_widget3.canvas3)
ax3 = self.graph_widget3.figure3.add_subplot(111)
ax3.axis('off')
'Graph widget 4'
self.graph_widget4 = QWidget()
self.graph_widget4.figure4 = plt.figure()
self.graph_widget4.canvas4 = FigureCanvas(self.graph_widget4.figure4)
self.graph_widget4.toolbar4 = NavigationToolbar(
self.graph_widget4.canvas4, self.graph_widget4)
self.ui.graphLayout_influenceLine.addWidget(
self.graph_widget4.toolbar4)
self.ui.graphLayout_influenceLine.addWidget(self.graph_widget4.canvas4)
self.ax4 = self.graph_widget4.figure4.add_subplot(211)
self.ax5 = self.graph_widget4.figure4.add_subplot(212)
'''
page changing by clicking pushButton and connecting them to stackedWidget
'''
self.ui.pushbutton_nodes.clicked.connect(
lambda: self.ui.stackedWidget.setCurrentWidget(self.ui.page_geometry))
self.ui.pushbutton_nodes.clicked.connect(
lambda: self.ui.stackedWidget_2.setCurrentWidget(self.ui.page_node))
self.ui.pushbutton_members.clicked.connect(
lambda: self.ui.stackedWidget.setCurrentWidget(self.ui.page_geometry))
self.ui.pushbutton_members.clicked.connect(
lambda: self.ui.stackedWidget_2.setCurrentWidget(self.ui.page_member))
self.ui.pushbutton_supports.clicked.connect(
lambda: self.ui.stackedWidget.setCurrentWidget(self.ui.page_geometry))
self.ui.pushbutton_supports.clicked.connect(
lambda: self.ui.stackedWidget_2.setCurrentWidget(self.ui.page_supports))
self.ui.pushbutton_loads.clicked.connect(
lambda: self.ui.stackedWidget.setCurrentWidget(self.ui.page_geometry))
self.ui.pushbutton_loads.clicked.connect(
lambda: self.ui.stackedWidget_2.setCurrentWidget(self.ui.page_loads))
self.ui.pushbutton_properties.clicked.connect(
lambda: self.ui.stackedWidget.setCurrentWidget(self.ui.page_geometry))
self.ui.pushbutton_properties.clicked.connect(
lambda: self.ui.stackedWidget_2.setCurrentWidget(self.ui.page_properties))
self.ui.pushbutton_displacement.clicked.connect(
lambda: self.ui.stackedWidget.setCurrentWidget(self.ui.page_displacement))
self.ui.pushbutton_forces.clicked.connect(
lambda: self.ui.stackedWidget.setCurrentWidget(self.ui.page_forces))
'This is special for influence line development'
self.ui.pushbutton_influenceLine.clicked.connect(
lambda: self.ui.stackedWidget.setCurrentWidget(self.ui.page_influenceLine))
self.ui.pushbutton_report.clicked.connect(
lambda: self.ui.stackedWidget.setCurrentWidget(self.ui.page_report))
self.ui.lineEdit_startingNode.textChanged[str].connect(self.movingload)
self.ui.lineEdit_endingNode.textChanged[str].connect(self.movingload)
'''
connecting desired functions by clicking pushButtons
'''
self.ui.pushbutton_nodes.clicked.connect(self.node)
self.ui.pushbutton_members.clicked.connect(self.member)
self.ui.pushbutton_supports.clicked.connect(self.support)
self.ui.pushbutton_loads.clicked.connect(self.force)
self.ui.pushbutton_properties.clicked.connect(self.assign_property)
self.ui.pushbutton_displacement.clicked.connect(self.node)
self.ui.pushbutton_displacement.clicked.connect(self.displacement)
self.ui.pushbutton_forces.clicked.connect(self.node)
self.ui.pushbutton_forces.clicked.connect(self.displacement)
self.ui.pushbutton_influenceLine.clicked.connect(self.influence_table)
self.ui.pushButton_calculate.clicked.connect(self.influence_line)
'Supports combo add in support table'
for i in range(2):
supports_cb = QComboBox()
supports_cb.addItems(
['pinned', 'horizontal roller', 'vertical roller'])
self.ui.tableWidget_supports.setCellWidget(i, 1, supports_cb)
supports_cb.currentIndexChanged.connect(self.support)
if self.open:
self.open_from_file()
'''table update'''
self.ui.update_loads.clicked.connect(
lambda: self.ui.tableWidget_loads.setRowCount(self.ui.spinBox_loads.value()))
self.ui.update_members.clicked.connect(self.member_table)
self.ui.update_supports.clicked.connect(self.support_table)
self.ui.update_property.clicked.connect(self.property_table)
self.ui.update_nodes.clicked.connect(self.node)
self.ui.tableWidget_nodes.cellChanged.connect(self.node)
self.ui.tableWidget_nodes.cellChanged.connect(self.update_change)
self.ui.update_members.clicked.connect(self.member)
self.ui.tableWidget_members.cellChanged.connect(self.member)
self.ui.tableWidget_members.cellChanged.connect(self.update_change)
self.ui.update_supports.clicked.connect(self.support)
self.ui.tableWidget_supports.cellChanged.connect(self.support)
self.ui.tableWidget_supports.cellChanged.connect(
self.update_change)
self.ui.update_loads.clicked.connect(self.force)
self.ui.tableWidget_loads.cellChanged.connect(self.force)
self.ui.tableWidget_loads.cellChanged.connect(self.update_change)
self.ui.update_property.clicked.connect(self.assign_property)
self.ui.tableWidget_property.cellChanged.connect(self.assign_property)
self.ui.pushbutton_properties.clicked.connect(self.assign_property)
self.ui.tableWidget_property.cellChanged.connect(
self.update_change)
'Member colour change in graph'
self.ui.radioButtonDefault.toggled.connect(self.graph)
self.ui.radioButtonBlack.toggled.connect(self.graph)
'Animation'
self.ui.pushButton_start.clicked.connect(self.animation)
self.ui.pushButton_stop.clicked.connect(self.stop_animation)
self.ui.horizontalSlider.valueChanged.connect(self.displacement_graph)
'Force, stress radio button'
self.ui.radioButton_force.toggled.connect(self.force_or_stress)
'Nodes,loads,reactions and members checkbox in stress graph'
self.ui.checkBox_nodes.stateChanged.connect(self.stress_graph)
self.ui.checkBox_members.stateChanged.connect(self.stress_graph)
self.ui.checkBox_forces.stateChanged.connect(self.stress_graph)
self.ui.checkBox_loads.stateChanged.connect(self.stress_graph)
self.ui.checkBox_reactions.stateChanged.connect(self.stress_graph)
'Report generate'
self.ui.pushbutton_generate.clicked.connect(self.generate_report)
self.ui.projectName.setPlaceholderText('Project Truss')
self.ui.userName.setPlaceholderText('Anonymous')
'Table no edit triggers and setColumnWidth'
self.ui.tableWidget_loads.setColumnWidth(1, 100)
self.ui.tableWidget_displacement.setEditTriggers(
QAbstractItemView.NoEditTriggers)
self.ui.tableWidget_result.setEditTriggers(
QAbstractItemView.NoEditTriggers)
self.ui.tableWidget_result.setColumnWidth(0, 60)
self.ui.tableWidget_result.setColumnWidth(1, 60)
self.ui.tableWidget_result.setColumnWidth(2, 100)
self.ui.tableWidget_influenceLine.setEditTriggers(
QAbstractItemView.NoEditTriggers)
'To allow only int in influence line starting and ending node'
self.onlyInt = QIntValidator()
self.ui.lineEdit_startingNode.setValidator(self.onlyInt)
self.ui.lineEdit_endingNode.setValidator(self.onlyInt)
'''
Align Delegate
Set table item alignment in center
'''
delegate = AlignDelegate(self.ui.tableWidget_nodes)
self.ui.tableWidget_nodes.setItemDelegate(delegate)
delegate = AlignDelegate(self.ui.tableWidget_members)
self.ui.tableWidget_members.setItemDelegate(delegate)
delegate = AlignDelegate(self.ui.tableWidget_supports)
self.ui.tableWidget_supports.setItemDelegate(delegate)
delegate = AlignDelegate(self.ui.tableWidget_loads)
self.ui.tableWidget_loads.setItemDelegate(delegate)
delegate = AlignDelegate(self.ui.tableWidget_property)
self.ui.tableWidget_property.setItemDelegate(delegate)
delegate = AlignDelegate(self.ui.tableWidget_displacement)
self.ui.tableWidget_displacement.setItemDelegate(delegate)
delegate = AlignDelegate(self.ui.tableWidget_result)
self.ui.tableWidget_result.setItemDelegate(delegate)
delegate = AlignDelegate(self.ui.tableWidget_influenceLine)
self.ui.tableWidget_influenceLine.setItemDelegate(delegate)
self.ui.comboBox_influence.currentIndexChanged.connect(
self.influence_table)
'''
opening from a file
'''
def open_from_file(self):
currentdirectory = os.path.expanduser('~/Documents')
if not self.filename:
self.filename = QFileDialog.getOpenFileName(
self, 'Open file', currentdirectory, "Truss101 files (*.trs)")
with open(self.filename[0], 'rb') as outfile:
try:
self.current_metric_index = pickle.load(outfile)
self.current_imperial_index = pickle.load(outfile)
self.ndofs = pickle.load(outfile)
self.X = pickle.load(outfile)
self.Y = pickle.load(outfile)
self.X_withoutunit = pickle.load(outfile)
self.Y_withoutunit = pickle.load(outfile)
self.node_values = pickle.load(outfile)
self.degrees_of_freedom = pickle.load(outfile)
self.member_values = pickle.load(outfile)
self.elements = pickle.load(outfile)
self.plot_final = pickle.load(outfile)
self.plot_displacement_final = pickle.load(outfile)
self.restrained_dofs = pickle.load(outfile)
self.support_node = pickle.load(outfile)
self.support_graph = pickle.load(outfile)
self.support_displacement_graph = pickle.load(outfile)
self.support_force = pickle.load(outfile)
self.forces = pickle.load(outfile)
self.force_graph = pickle.load(outfile)
self.properties = pickle.load(outfile)
self.properties_list = pickle.load(outfile)
self.max_X = max(self.X)
self.max_Y = max(self.Y)
self.min_X = min(self.X)
self.min_Y = min(self.Y)
self.max_XY = max(self.max_X, self.max_Y)
self.min_XY = min(self.max_X, self.max_Y)
except:
self.max_X = max(self.X)
self.max_Y = max(self.Y)
self.min_X = min(self.X)
self.min_Y = min(self.Y)
self.max_XY = max(self.max_X, self.max_Y)
self.min_XY = min(self.max_X, self.max_Y)
self.graph()
pass
# node
try:
self.ui.tableWidget_nodes.setRowCount(len(self.X_withoutunit))
self.ui.spinBox_nodes.setValue(len(self.X_withoutunit))
for i, (j, k) in enumerate(zip(self.X_withoutunit, self.Y_withoutunit)):
self.ui.tableWidget_nodes.setItem(
i, 0, QTableWidgetItem(str(j)))
self.ui.tableWidget_nodes.setItem(
i, 1, QTableWidgetItem(str(k)))
# member
self.ui.tableWidget_members.setRowCount(len(self.elements))
self.ui.spinBox_members.setValue(len(self.elements))
if len(self.properties_list) > 1:
self.ui.spinBox_property.setValue(len(self.properties_list))
self.ui.tableWidget_members.setColumnCount(3)
self.ui.tableWidget_members.setHorizontalHeaderLabels(
['From\nNode', 'To\nNode', 'property'])
self.ui.tableWidget_members.setColumnWidth(0, 80)
self.ui.tableWidget_members.setColumnWidth(1, 80)
for k, v in self.elements.items():
property_cb = QComboBox()
item = [str(i) for i in range(
1, self.ui.spinBox_property.value()+1)]
property_cb.addItems(item)
property_cb.setCurrentText(str(self.properties[k][1]))
self.ui.tableWidget_members.setCellWidget(
k-1, 2, property_cb)
self.ui.tableWidget_members.setItem(
k-1, 0, QTableWidgetItem(str(v[0])))
self.ui.tableWidget_members.setItem(
k-1, 1, QTableWidgetItem(str(v[1])))
else:
for k, v in self.elements.items():
self.ui.tableWidget_members.setItem(
k-1, 0, QTableWidgetItem(str(v[0])))
self.ui.tableWidget_members.setItem(
k-1, 1, QTableWidgetItem(str(v[1])))
# supports
self.ui.tableWidget_supports.setRowCount(len(self.support_node))
self.ui.spinBox_supports.setValue(len(self.support_node))
for i, j in enumerate(self.support_graph.keys()):
supports_cb = QComboBox()
supports_cb.addItems(
['pinned', 'horizontal roller', 'vertical roller'])
node = re.findall(r'\d+', j)
string = j.replace(node[0], '')
supports_cb.setCurrentText(string)
self.ui.tableWidget_supports.setItem(
i, 0, QTableWidgetItem(node[0]))
self.ui.tableWidget_supports.setCellWidget(i, 1, supports_cb)
supports_cb.currentIndexChanged.connect(self.support)
# loads
self.ui.tableWidget_loads.setRowCount(len(self.force_graph))
self.ui.spinBox_loads.setValue(len(self.force_graph))
for k, v in self.force_graph.items():
self.ui.tableWidget_loads.setItem(
k, 0, QTableWidgetItem(str(v[-2])))
self.ui.tableWidget_loads.setItem(
k, 1, QTableWidgetItem(str(v[3])))
self.ui.tableWidget_loads.setItem(
k, 2, QTableWidgetItem(str(v[2])))
# property
self.ui.tableWidget_property.setRowCount(len(self.properties_list))
self.ui.spinBox_property.setValue(len(self.properties_list))
for k, v in self.properties_list.items():
self.ui.tableWidget_property.setItem(
k-1, 0, QTableWidgetItem(str(v[0])))
self.ui.tableWidget_property.setItem(
k-1, 1, QTableWidgetItem(str(v[1])))
except:
pass
if self.current_imperial_index:
self.change_unit_label(
unit=self.current_imperial_index, type='imperial')
self.unit_convert(type='imperial')
elif self.current_metric_index:
self.change_unit_label(
unit=self.current_metric_index, type='metric')
self.unit_convert(type='metric')
self.change = 0
self.save += 1
'''
save into a file
'''
def save_to_file(self, saveas=None):
self.saveas = saveas
currentdirectory = os.path.expanduser('~/Documents')
if self.save == 0:
self.filename = QFileDialog.getSaveFileName(
self, 'Save file', currentdirectory, "Truss101 files (*.trs)")
elif self.saveas:
self.filename = QFileDialog.getSaveFileName(
self, 'Save file', currentdirectory, "Truss101 files (*.trs)")
elif self.savedemo:
self.filename = QFileDialog.getSaveFileName(
self, 'Save file', currentdirectory, "Truss101 files (*.trs)")
with open(self.filename[0], 'wb') as outfile:
self.change = 0
self.save += 1
try:
pickle.dump(self.current_metric_index, outfile)
pickle.dump(self.current_imperial_index, outfile)
pickle.dump(self.ndofs, outfile)
pickle.dump(self.X, outfile)
pickle.dump(self.Y, outfile)
pickle.dump(self.X_withoutunit, outfile)
pickle.dump(self.Y_withoutunit, outfile)
pickle.dump(self.node_values, outfile)
pickle.dump(self.degrees_of_freedom, outfile)
pickle.dump(self.member_values, outfile)
pickle.dump(self.elements, outfile)
pickle.dump(self.plot_final, outfile)
pickle.dump(self.plot_displacement_final, outfile)
pickle.dump(self.restrained_dofs, outfile)
pickle.dump(self.support_node, outfile)
pickle.dump(self.support_graph, outfile)
pickle.dump(self.support_displacement_graph, outfile)
pickle.dump(self.support_force, outfile)
pickle.dump(self.forces, outfile)
pickle.dump(self.force_graph, outfile)
pickle.dump(self.properties, outfile)
pickle.dump(self.properties_list, outfile)
except:
pass
'''
add comboBox in table
'''
def member_table(self):
previous = self.ui.tableWidget_members.rowCount()
self.ui.tableWidget_members.setRowCount(
self.ui.spinBox_members.value())
if self.ui.spinBox_property.value() > 1:
self.ui.tableWidget_members.setColumnCount(3)
self.ui.tableWidget_members.setHorizontalHeaderLabels(
['From\nNode', 'To\nNode', 'property'])
total = self.ui.spinBox_property.value()+1
for row in range(self.ui.spinBox_members.value()-previous):
property_cb = QComboBox()
item = [str(i) for i in range(1, total)]
property_cb.addItems(item)
self.ui.tableWidget_members.setCellWidget(
row+previous, 2, property_cb)
property_cb.currentIndexChanged.connect(self.assign_property)
self.ui.tableWidget_members.setColumnWidth(0, 80)
self.ui.tableWidget_members.setColumnWidth(1, 80)
def support_table(self):
previous = self.ui.tableWidget_supports.rowCount()
self.ui.tableWidget_supports.setRowCount(
self.ui.spinBox_supports.value())
for row in range(self.ui.spinBox_supports.value()-previous):
supports_cb = QComboBox()
supports_cb.addItems(
['pinned', 'horizontal roller', 'vertical roller'])
self.ui.tableWidget_supports.setItem(
row+previous, 0, QTableWidgetItem('1'))
self.ui.tableWidget_supports.setCellWidget(
row+previous, 1, supports_cb)
supports_cb.currentIndexChanged.connect(self.support)
def property_table(self):
self.ui.tableWidget_property.setRowCount(
self.ui.spinBox_property.value())
if self.ui.spinBox_property.value() > 1:
self.ui.tableWidget_members.setColumnCount(3)
self.ui.tableWidget_members.setHorizontalHeaderLabels(
['From\nNode', 'To\nNode', 'property'])
self.ui.tableWidget_members.setColumnWidth(0, 80)
self.ui.tableWidget_members.setColumnWidth(1, 80)
for row in range(self.ui.spinBox_members.value()):
property_cb = QComboBox()
item = [str(i) for i in range(
1, self.ui.spinBox_property.value()+1)]
property_cb.addItems(item)
self.ui.tableWidget_members.setCellWidget(row, 2, property_cb)
property_cb.currentIndexChanged.connect(self.assign_property)
elif self.ui.spinBox_property.value() == 1:
self.ui.tableWidget_members.setColumnCount(2)
self.ui.tableWidget_members.setHorizontalHeaderLabels(
['From\nNode', 'To\nNode'])
self.ui.tableWidget_members.setColumnWidth(0, 150)
self.ui.tableWidget_members.setColumnWidth(1, 150)
'''
constructing lists and dictionary to collect data from tables and then calculating.
'''
def node(self):
self.ui.tableWidget_nodes.setRowCount(self.ui.spinBox_nodes.value())
self.X = []
self.Y = []
self.X_withoutunit = []
self.Y_withoutunit = []
self.node_values = {}
self.degrees_of_freedom = {}
for row in range(1, self.ui.spinBox_nodes.value()+1):
try:
x = float(self.ui.tableWidget_nodes.item(row-1, 0).text())
y = float(self.ui.tableWidget_nodes.item(row-1, 1).text())
self.X.append(x*self.unit_node)
self.Y.append(y*self.unit_node)
self.X_withoutunit.append(x)
self.Y_withoutunit.append(y)
self.node_values[row] = x*self.unit_node, y*self.unit_node
self.degrees_of_freedom[row] = 2*row-1, 2*row
except:
continue
self.ndofs = 2*len(self.node_values)
self.logger.debug('Number of degrees of freedom : %s', self.ndofs)
self.logger.debug('Degrees of freedom : %s', self.degrees_of_freedom)
self.logger.debug('Node values : %s', self.node_values)
try:
self.max_X = max(self.X)
self.max_Y = max(self.Y)
self.min_X = min(self.X)
self.min_Y = min(self.Y)
self.max_XY = max(self.max_X, self.max_Y)
self.min_XY = min(self.max_X, self.max_Y)
except:
pass
self.member()
def member(self):
self.ui.tableWidget_members.setRowCount(
self.ui.spinBox_members.value())
self.member_values = {}
self.elements = {}
From_node = []
To_node = []
plot_x1 = []
plot_x2 = []
plot_y1 = []
plot_y2 = []
self.plot_final = {}
self.plot_displacement_final = {}
for row in range(self.ui.spinBox_members.value()):
try:
node1 = int(self.ui.tableWidget_members.item(row, 0).text())
node2 = int(self.ui.tableWidget_members.item(row, 1).text())
for k, v in self.node_values.items():
if node1 == k:
From_node = v
plot_x1 = v[0]
plot_y1 = v[1]
elif node2 == k:
To_node = v
plot_x2 = v[0]
plot_y2 = v[1]
self.plot_final[row+1] = (plot_x1,
plot_x2), (plot_y1, plot_y2)
self.plot_displacement_final[row+1] = (plot_x1*self.reverse_unit, plot_x2 *
self.reverse_unit), (plot_y1*self.reverse_unit, plot_y2*self.reverse_unit)
self.member_values[row+1] = From_node, To_node
self.elements[row+1] = node1, node2
except:
continue
self.logger.debug('Member values : %s', self.member_values)
self.logger.debug('Elements : %s', self.elements)
self.logger.debug('Member plot data : %s', self.plot_final)
self.logger.debug('Member displacement data : %s',
self.plot_displacement_final)
self.support()
def support(self):
self.ui.tableWidget_supports.setRowCount(
self.ui.spinBox_supports.value())
self.restrained_dofs = []
self.support_node = []
self.support_graph = {}
self.support_displacement_graph = {}
self.support_force = {}
global support_report
for row in range(self.ui.spinBox_supports.value()):
try:
node = int(self.ui.tableWidget_supports.item(row, 0).text())
support_type = self.ui.tableWidget_supports.cellWidget(
row, 1).currentIndex()
self.support_node.append(node)
p = self.node_values[node][0]
q = self.node_values[node][1]
# Pinned Support
if support_type == 0:
self.restrained_dofs.append(2*node-1)
self.restrained_dofs.append(2*node)
self.support_force[2*node-1] = 0
self.support_force[2*node] = 0
if q > 0:
if p == 0:
self.support_graph[f'pinned{node}'] = [p, q], 270
self.support_displacement_graph[f'pinned{node}'] = [
p*self.reverse_unit, q*self.reverse_unit], 270
elif p == self.max_X:
self.support_graph[f'pinned{node}'] = [p, q], 90
self.support_displacement_graph[f'pinned{node}'] = [
p*self.reverse_unit, q*self.reverse_unit], 90
elif q == self.max_Y:
self.support_graph[f'pinned{node}'] = [p, q], 180
self.support_displacement_graph[f'pinned{node}'] = [
p*self.reverse_unit, q*self.reverse_unit], 180
else:
self.support_graph[f'pinned{node}'] = [p, q], 0
self.support_displacement_graph[f'pinned{node}'] = [
p*self.reverse_unit, q*self.reverse_unit], 0
else:
self.support_graph[f'pinned{node}'] = [p, q], 0
self.support_displacement_graph[f'pinned{node}'] = [
p*self.reverse_unit, q*self.reverse_unit], 0
# Horizontal ROller Support
elif support_type == 1:
self.restrained_dofs.append(2*node)
self.support_force[2*node] = 0
# Bottom
if q == self.max_Y:
self.support_graph[f'horizontal roller{node}'] = [
p, q], 180
self.support_displacement_graph[f'horizontal roller{node}'] = [
p*self.reverse_unit, q*self.reverse_unit], 180
# Top
else:
self.support_graph[f'horizontal roller{node}'] = [
p, q], 0
self.support_displacement_graph[f'horizontal roller{node}'] = [
p*self.reverse_unit, q*self.reverse_unit], 0
# Vertical Roller support
elif support_type == 2:
self.restrained_dofs.append(2*node-1)
self.support_force[2*node-1] = 0
# Left
if p < self.max_X/2:
self.support_graph[f'vertical roller{node}'] = [
p, q], 270
self.support_displacement_graph[f'vertical roller{node}'] = [
p*self.reverse_unit, q*self.reverse_unit], 270
# Right
else:
self.support_graph[f'vertical roller{node}'] = [
p, q], 90
self.support_displacement_graph[f'vertical roller{node}'] = [
p*self.reverse_unit, q*self.reverse_unit], 90
except:
continue
self.restrained_dofs.sort()
self.logger.debug('Restrained dofs sorted: %s', self.restrained_dofs)
self.logger.debug('Support Node : %s', self.support_node)
self.logger.debug('Support graph : %s', self.support_graph)
self.logger.debug('Support displacement graph : %s',
self.support_displacement_graph)
self.logger.debug('Support force : %s', self.support_force)
support_report = self.support_graph
self.force()
def force(self):
self.forces = {}
self.force_graph = {}
for i in range(1, self.ui.spinBox_nodes.value()+1):
self.forces[i] = 0, 0
for row in range(self.ui.spinBox_loads.value()):
try:
node = int(self.ui.tableWidget_loads.item(row, 0).text())
magnitude = float(
self.ui.tableWidget_loads.item(row, 1).text())
angle = float(self.ui.tableWidget_loads.item(row, 2).text())
force_x = np.around((np.cos(np.radians(
angle)))*magnitude*self.force_unit, decimals=10) + self.forces[node][0]
force_y = np.around((np.sin(np.radians(
angle)))*magnitude*self.force_unit, decimals=10) + self.forces[node][1]
self.forces[node] = force_x, force_y
if node in self.support_node:
self.support_force[node*2-1] = force_x
self.support_force[node*2] = force_y
p = self.node_values[node][0]
q = self.node_values[node][1]
positive_angle = angle % 360
if positive_angle >= 0 and positive_angle < 60:
self.force_graph[row] = p, q, angle, magnitude, node, f'right'
elif positive_angle >= 60 and positive_angle < 120:
self.force_graph[row] = p, q, angle, magnitude, node, f'center'
elif positive_angle >= 120 and positive_angle < 240:
self.force_graph[row] = p, q, angle, magnitude, node, f'left'
elif positive_angle >= 240 and positive_angle < 300:
self.force_graph[row] = p, q, angle, magnitude, node, f'center'
else:
self.force_graph[row] = p, q, angle, magnitude, node, f'right'
except:
continue
self.logger.debug('Forces : %s', self.forces)
self.logger.debug('Force graph : %s', self.force_graph)
self.assign_property()
def assign_property(self):
self.properties_list = {}
self.properties = {}
properties_number = int(self.ui.spinBox_property.value())
member = int(self.ui.spinBox_members.value())
if properties_number == 1:
stiffness = float(self.ui.tableWidget_property.item(0, 0).text())
area = float(self.ui.tableWidget_property.item(0, 1).text())
self.properties_list[1] = stiffness, area
for i in range(1, member+1):
self.properties[i] = (stiffness, area), 1
else:
for i in range(1, properties_number+1):
try:
stiffness = float(
self.ui.tableWidget_property.item(i-1, 0).text())
area = float(
self.ui.tableWidget_property.item(i-1, 1).text())
self.properties_list[i] = stiffness, area
except:
continue
for row in range(member):
try:
number = int(self.ui.tableWidget_members.cellWidget(
row, 2).currentText())
self.properties[row +
1] = self.properties_list[number], number
except:
continue
self.logger.debug('Unique properties : %s', self.properties_list)
self.logger.debug('Member assigned properties : %s', self.properties)
self.calculation()
self.graph()
def change_unit_label(self, unit=None, type=None):
self.unit = unit
self.type = type
self.current_metric_index = []
self.current_imperial_index = []
if self.type == 'metric':
self.current_metric_index = self.unit
self.unit_report = [
'm', 'kilo newton (kN)', 'kilo newton (kN)', 'GPa', 'mm<super size=6>2</super>', 'mm']
self.ui.label_unit_property.setText(
'* Unit of E : Giga Pascal (GPa)')
self.ui.label.setText(
'* Unit of Area (A) : milimeter squared (mm^2)')
self.ui.label_unit_displacement.setText(
'* Unit of displacement : milimeter (mm)')
if self.current_metric_index[0][0] == 0:
self.ui.label_unit_node.setText(
'* Unit of x and y : meter (m)')
if self.current_metric_index[0][0] == 1:
self.unit_report[0] = 'mm'
self.ui.label_unit_node.setText(
'* Unit of x and y : milimeter (mm)')
if self.current_metric_index[0][1] == 0:
self.ui.label_unit_load.setText(
'* Unit of load : kilo Newton (kN)')
self.ui.label_unitLoad.setText(
'* Unit Load : 1 kilo Newton (kN)')
if self.current_metric_index[0][1] == 1:
self.unit_report[1] = 'Newton (N)'
self.ui.label_unit_load.setText('* Unit of load : Newton (N)')
self.ui.label_unitLoad.setText('* Unit Load : 1 Newton (N)')
if self.current_metric_index[0][1] == 2:
self.unit_report[1] = 'kilogram (kg)'
self.ui.label_unit_load.setText(
'* Unit of load : kilogram (kg)')
self.ui.label_unitLoad.setText('* Unit Load : 1 kilogram (kg)')
if self.current_metric_index[0][2] == 0:
self.ui.label_unit_stress.setText(
'* Unit of force : kilo Newton (kN)')
self.ui.tableWidget_influenceLine.setHorizontalHeaderLabels(
['Load\nPosition', 'Force\n(kN)'])
if self.current_metric_index[0][2] == 1:
self.unit_report[2] = 'Newton (N)'
self.ui.label_unit_stress.setText(
'* Unit of force : Newton (N)')
self.ui.tableWidget_influenceLine.setHorizontalHeaderLabels(
['Load\nPosition', 'Force\n(N)'])
if self.current_metric_index[0][2] == 2:
self.unit_report[2] = 'kilogram (kg)'
self.ui.label_unit_stress.setText(
'* Unit of force : kilogram (kg)')
self.ui.tableWidget_influenceLine.setHorizontalHeaderLabels(
['Load\nPosition', 'Force\n(kg)'])
else:
self.current_imperial_index = self.unit
self.unit_report = [
'ft', 'kip (k)', 'kip (k)', 'ksi', 'in<super size=6>2</super>', 'in']
self.ui.label_unit_property.setText(
'* Unit of E : kip per inch squared (ksi)')