-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMBdynGui.py
1638 lines (1369 loc) · 69.4 KB
/
MBdynGui.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
# -*- coding: utf-8 -*-
###################################################################################
#
# Copyright 2021 Jose Gabriel Egas Ortuno
#
# 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.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
#
###################################################################################
import FreeCAD
import FreeCADGui
#from PyQt4 import QtGui,QtCore
from PySide import QtGui,QtCore
import os
#import subprocess
from tospreadsheet import Tospreadsheet
from info import Infonode, Infojoint
from dynamics import Dynamics
#from sys import platform
dyn = Dynamics()
__dir__ = os.path.dirname(__file__)
"""//////////////////////////////////////////////////////////////////////////////IN-PLANE JOINT////////////////////////////////////////////////////"""
class _AddInPlaneCmd:
def Activated(self):
b = FreeCADGui.Selection.getSelection()
if(len(b)==2):
node1 = FreeCADGui.Selection.getSelection()[0]
node2 = FreeCADGui.Selection.getSelection()[1]
dyn.AddInPlaneJoint(node1,node2)
else:
QtGui.QMessageBox.information(None,"Error","Select two nodes first. The second node will be constrained a plane attached to the first node.")
def GetResources(self):
MenuText = QtCore.QT_TRANSLATE_NOOP(
'MBDyn_add_in_plane_joint',
'Add in plane joint')
ToolTip = QtCore.QT_TRANSLATE_NOOP(
'MBDyn_add_in_plane_joint',
'Add in plane joint')
return {
'Pixmap': __dir__ + '/icons/in-plane.png',
'MenuText': MenuText,
'ToolTip': ToolTip}
def IsActive(self):
return not FreeCAD.ActiveDocument is None
FreeCADGui.addCommand('MBdyn_AddInPlane', _AddInPlaneCmd())
"""//////////////////////////////////////////////////////////////////////////////PRISMATIC JOINT////////////////////////////////////////////////////"""
class _AddPrismaticCmd:
def Activated(self):
b = FreeCADGui.Selection.getSelection()
if(len(b)==2):
node1 = FreeCADGui.Selection.getSelection()[0]
node2 = FreeCADGui.Selection.getSelection()[1]
dyn.AddPrismaticJoint(node1,node2)
else:
QtGui.QMessageBox.information(None,"Error","Select two nodes first. The orientation of the second node will be constrained to the orientation of the first node.")
def GetResources(self):
MenuText = QtCore.QT_TRANSLATE_NOOP(
'MBDyn_add_prismatic_joint',
'Add prismatic joint')
ToolTip = QtCore.QT_TRANSLATE_NOOP(
'MBDyn_add_prismatic_joint',
'Add prismatic joint')
return {
'Pixmap': __dir__ + '/icons/prismatic.png',
'MenuText': MenuText,
'ToolTip': ToolTip}
def IsActive(self):
return not FreeCAD.ActiveDocument is None
FreeCADGui.addCommand('MBdyn_AddPrismatic', _AddPrismaticCmd())
"""//////////////////////////////////////////////////////////////////////////////DEFORMABLE DISPLACEMENT JOINT////////////////////////////////////////////////////"""
class _AddDeformableDisplacementCmd:
def Activated(self):
b = FreeCADGui.Selection.getSelection()
if(len(b)==2):
node1 = FreeCADGui.Selection.getSelection()[0]
node2 = FreeCADGui.Selection.getSelection()[1]
dyn.AddDeformableDisplacementJoint(node1,node2)
else:
QtGui.QMessageBox.information(None,"Error","Select two nodes first. The second node will be attached, through a deformable displacement joint, to the first node.")
def GetResources(self):
MenuText = QtCore.QT_TRANSLATE_NOOP(
'Add deformable displacement joint',
'Add deformable displacement joint')
ToolTip = QtCore.QT_TRANSLATE_NOOP(
'Add deformable displacement joint',
'Add deformable displacement joint')
return {
'Pixmap': __dir__ + '/icons/spring.png',
'MenuText': MenuText,
'ToolTip': ToolTip}
def IsActive(self):
return not FreeCAD.ActiveDocument is None
FreeCADGui.addCommand('MBdyn_DeformableDisplacement', _AddDeformableDisplacementCmd())
"""//////////////////////////////////////////////////////////////////////////////IN-LINE JOINT////////////////////////////////////////////////////"""
class _AddInLineCmd:
def Activated(self):
b = FreeCADGui.Selection.getSelection()
if(len(b)==2):
node1 = FreeCADGui.Selection.getSelection()[0]
node2 = FreeCADGui.Selection.getSelection()[1]
dyn.AddInLineJoint(node1,node2)
else:
helpp = """An in-line joint forces a node to move along a line attached to another node.
The second node, optionally offset by 'relative offset' from the position of the first node, slides along a line that passes through a point that is rigidly offset by 'relative line position' from the position of the first node, and is directed along the Z axis of its 'relative orientation'.
HINT: Select two nodes and apply the in-line joint. The second node will be constrained to a line fixed to the first node.
You can afterwards set the appropriate 'relative offset', 'relative line position'
"""
QtGui.QMessageBox.information(None,"Error",helpp)
def GetResources(self):
MenuText = QtCore.QT_TRANSLATE_NOOP(
'Apply an in-line joint between two nodes',
'Apply an in-line joint between two nodes')
ToolTip = QtCore.QT_TRANSLATE_NOOP(
'Apply an in-line joint between two nodes',
'Apply an in-line joint between two nodes')
return {
'Pixmap': __dir__ + '/icons/in-line.png',
'MenuText': MenuText,
'ToolTip': ToolTip}
def IsActive(self):
return not FreeCAD.ActiveDocument is None
FreeCADGui.addCommand('MBdyn_AddInLine', _AddInLineCmd())
"""//////////////////////////////////////////////////////////////////////////////INFO////////////////////////////////////////////////////"""
class _InfoCmd:
def Activated(self):
b = FreeCADGui.Selection.getSelection()
if(len(b)==0):
QtGui.QMessageBox.information(None,"Error","Select a node or a joint first.")
else:
if(b[0].Label.startswith('structural:')):
node = int(b[0].label)
Infonode(node)#Show node's info
if(b[0].Label.startswith('joint:')):
joint = int(b[0].label)
Infojoint(joint)#Show joint's info
def GetResources(self):
MenuText = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_export_summarized_simulation_results_to_a_FreeCAD_spreadsheet',
'Export summarized simulation results to a FreeCAD spreadsheet')
ToolTip = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_export_summarized_simulation_results_to_a_FreeCAD_spreadsheet',
'Export summarized simulation results to a FreeCAD spreadsheet')
return {
'Pixmap': __dir__ + '/icons/spread1.png',
'MenuText': MenuText,
'ToolTip': ToolTip}
def IsActive(self):
return not FreeCAD.ActiveDocument is None
FreeCADGui.addCommand('MBdyn_Info', _InfoCmd())
"""//////////////////////////////////////////////////////////////////////////////NODE/JOINT CENTER OF MASS////////////////////////////////////////////////////"""
class _Cm1Cmd:
def Activated(self):
b = FreeCADGui.Selection.getSelection()
if(len(b)!=1):
QtGui.QMessageBox.information(None,"Error","Select only one structural node, joint or rigid body firs.")
else:
if(b[0].Label.startswith('structural:')):
x = FreeCAD.Units.Quantity(b[0].position_X).Value
y = FreeCAD.Units.Quantity(b[0].position_Y).Value
z = FreeCAD.Units.Quantity(b[0].position_Z).Value
if(b[0].Label.startswith('joint:')):
x = float(b[0].absolute_pin_position[:-2].split(",")[0])*1000.0
y = float(b[0].absolute_pin_position[:-2].split(",")[1])*1000.0
z = float(b[0].absolute_pin_position[:-2].split(",")[2])*1000.0
if(b[0].Label.startswith('body:')):
x = FreeCAD.Units.Quantity(b[0].absolute_center_of_mass_X).Value
y = FreeCAD.Units.Quantity(b[0].absolute_center_of_mass_Y).Value
z = FreeCAD.Units.Quantity(b[0].absolute_center_of_mass_Z).Value
length = FreeCAD.ActiveDocument.getObject("Line").End[0]
FreeCAD.ActiveDocument.cmx.X1=x+length
FreeCAD.ActiveDocument.cmx.Y1=y
FreeCAD.ActiveDocument.cmx.Z1=z
FreeCAD.ActiveDocument.cmx.X2=x-length
FreeCAD.ActiveDocument.cmx.Y2=y
FreeCAD.ActiveDocument.cmx.Z2=z
FreeCAD.ActiveDocument.cmy.X1=x
FreeCAD.ActiveDocument.cmy.Y1=y+length
FreeCAD.ActiveDocument.cmy.Z1=z
FreeCAD.ActiveDocument.cmy.X2=x
FreeCAD.ActiveDocument.cmy.Y2=y-length
FreeCAD.ActiveDocument.cmy.Z2=z
FreeCAD.ActiveDocument.cmz.X1=x
FreeCAD.ActiveDocument.cmz.Y1=y
FreeCAD.ActiveDocument.cmz.Z1=z+length
FreeCAD.ActiveDocument.cmz.X2=x
FreeCAD.ActiveDocument.cmz.Y2=y
FreeCAD.ActiveDocument.cmz.Z2=z-length
def GetResources(self):
MenuText = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_highlight_the_position_of_a_node_joint_or_center_of_mass_of_a_rigid_body',
'Highlight the position of a node, joint, or center of mass of a rigid body')
ToolTip = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_highlight_the_position_of_a_node_joint_or_center_of_mass_of_a_rigid_body',
'Highlight the position of a node, joint, or center of mass of a rigid body')
return {
'Pixmap': __dir__ + '/icons/center_of_mass.png',
'MenuText': MenuText,
'ToolTip': ToolTip}
def IsActive(self):
return not FreeCAD.ActiveDocument is None
FreeCADGui.addCommand('MBdyn_Cm1', _Cm1Cmd())
"""//////////////////////////////////////////////////////////////////////////////SOLID BODY INFO////////////////////////////////////////////////////"""
class _CmCmd:
def Activated(self):
b = FreeCADGui.Selection.getSelection()
if(len(b)==1):
reply = QtGui.QInputDialog.getText(None,"Dynamics","Provide the material's density, in kg/m^3:")
if reply[1]:
BaseBody = FreeCADGui.Selection.getSelection()[0]
#Convert density into FreeCAD unit, in kg/mm^3:
density = FreeCAD.Units.Quantity(float(reply[0])/(1000.0*1000.0),FreeCAD.Units.Unit('kg/mm^3'))
dyn.Inspect(BaseBody, density)
else:
QtGui.QMessageBox.information(None,"Error","Select only one simple solid body first.")
def GetResources(self):
MenuText = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_display_physical_properties_and_highlight_center_of_mass',
'Display physical properties and highlight center of mass')
ToolTip = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_display_physical_properties_and_highlight_center_of_mass',
'Display physical properties and highlight center of mass')
return {
'Pixmap': __dir__ + '/icons/info1.png',
'MenuText': MenuText,
'ToolTip': ToolTip}
def IsActive(self):
return not FreeCAD.ActiveDocument is None
FreeCADGui.addCommand('MBdyn_Cm', _CmCmd())
"""//////////////////////////////////////////////////////////////////////////////SPREADSHEET////////////////////////////////////////////////////"""
class _SpreadsheetCmd:
def Activated(self):
b = FreeCADGui.Selection.getSelection()
if(len(b)==0):
QtGui.QMessageBox.information(None,"Error","Select a node or a joint first.")
else:
choice = QtGui.QMessageBox.question(None,'Continue?',"Depending on your computer's resources and the simulation resolution, this may take some time. Hint: you can reduce the simulation resolution by increasing the time_step or reducing the final_time of the MBDyn object, in the MBDyn_simulation container. Continue?", QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
if choice == QtGui.QMessageBox.Yes:
Tospreadsheet(b[0])
def GetResources(self):
MenuText = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_export_full_simulation_results_to_a_FreeCAD_spreadsheet',
'Export full simulation results to a FreeCAD spreadsheet')
ToolTip = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_export_full_simulation_results_to_a_FreeCAD_spreadsheet',
'Export full simulation results to a FreeCAD spreadsheet')
return {
'Pixmap': __dir__ + '/icons/spread.png',
'MenuText': MenuText,
'ToolTip': ToolTip}
def IsActive(self):
return not FreeCAD.ActiveDocument is None
FreeCADGui.addCommand('MBdyn_Spreadsheet', _SpreadsheetCmd())
"""//////////////////////////////////////////////////////////////////////////////START ANIMATION////////////////////////////////////////////////////"""
class _Animate1Cmd:
def Activated(self):
#dyn.WriteInputFile()
#dyn.Run()
dyn.StartAnimation()
def GetResources(self):
MenuText = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_start_animation',
'Start animation')
ToolTip = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_start_animation',
'Start animation')
return {
'Pixmap': __dir__ + '/icons/play1.png',
'MenuText': MenuText,
'ToolTip': ToolTip}
def IsActive(self):
return not FreeCAD.ActiveDocument is None
FreeCADGui.addCommand('MBdyn_Animate1', _Animate1Cmd())
"""//////////////////////////////////////////////////////////////////////////////STOP ANIMATION////////////////////////////////////////////////////"""
class _AnimateStopCmd:
def Activated(self):
dyn.StopAnimation()
def GetResources(self):
MenuText = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_stop_animation',
'Stop animation')
ToolTip = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_stop_animation',
'Stop animation')
return {
'Pixmap': __dir__ + '/icons/stop.png',
'MenuText': MenuText,
'ToolTip': ToolTip}
def IsActive(self):
return not FreeCAD.ActiveDocument is None
FreeCADGui.addCommand('AnimateStopCmd', _AnimateStopCmd())
"""//////////////////////////////////////////////////////////////////////////////RESTORE ALL BODIES AND VECTORS TO THEIR POSSITIONS////////////////////////////////////////////////////"""
class _RestoreCmd:
def Activated(self):
dyn.RestoreScene()
def GetResources(self):
MenuText = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_restore_the_3D_scene',
'Restore the 3D scene')
ToolTip = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_restore_the_3D_scene',
'Restore the 3D scene')
return {
'Pixmap': __dir__ + '/icons/restore.png',
'MenuText': MenuText,
'ToolTip': ToolTip}
def IsActive(self):
return not FreeCAD.ActiveDocument is None
FreeCADGui.addCommand('MBdyn_Restore', _RestoreCmd())
"""//////////////////////////////////////////////////////////////////////////////EXECUTE MBDYN////////////////////////////////////////////////////"""
class _RunCmd:
def Activated(self):
#dyn.WriteInputFile()
dyn.Run()
def GetResources(self):
MenuText = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_execute_mbdyn_simulation',
'Execute MBDyn simulation')
ToolTip = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_execute_mbdyn_simulation',
'Execute MBDyn simulation')
return {
'Pixmap': __dir__ + '/icons/play.png',
'MenuText': MenuText,
'ToolTip': ToolTip}
def IsActive(self):
return not FreeCAD.ActiveDocument is None
FreeCADGui.addCommand('MBdyn_Run', _RunCmd())
"""//////////////////////////////////////////////////////////////////////////////SPHERICAL HINGE////////////////////////////////////////////"""
class _AddSphericalHingeCmd:
def Activated(self):
b = FreeCADGui.Selection.getSelection()
if(len(b)<1):
QtGui.QMessageBox.information(None,"Error...","Select a structural static node and a structural dynamic node first.")
if(len(b)==2):
node1 = FreeCADGui.Selection.getSelection()[0]
node2 = FreeCADGui.Selection.getSelection()[1]
dyn.AddSphericalHinge(node1, node2)
def GetResources(self):
MenuText = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_add_spherical_hinge',
'Add spherical hinge')
ToolTip = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_add_spherical_hinge',
'Add spherical hinge')
return {
'Pixmap': __dir__ + '/icons/spherical.png',
'MenuText': MenuText,
'ToolTip': ToolTip}
def IsActive(self):
return not FreeCAD.ActiveDocument is None
FreeCADGui.addCommand('MBdyn_AddSphericalHinge', _AddSphericalHingeCmd())
"""//////////////////////////////////////////////////////////////////////////////WRITE INPUT FILE////////////////////////////////////////////"""
class _AddMBDCmd:
def Activated(self):
dyn.WriteInputFile()
def GetResources(self):
MenuText = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_write_mbdyn_input_file',
'Write MBDyn input file')
ToolTip = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_write_mbdyn_input_file',
'Write MBDyn input file')
return {
'Pixmap': __dir__ + '/icons/mbd.png',
'MenuText': MenuText,
'ToolTip': ToolTip}
def IsActive(self):
return not FreeCAD.ActiveDocument is None
FreeCADGui.addCommand('MBdyn_AddMBD', _AddMBDCmd())
"""//////////////////////////////////////////////////////////////////////////////AXIAL ROTATION JOINT////////////////////////////////////////////////////"""
class _AddAxialRotationCmd:
def Activated(self):
b = FreeCADGui.Selection.getSelection()
if(len(b)<1):
QtGui.QMessageBox.information(None,"Error...","Select a structural static node and a structural dynamic node first.")
if(len(b)==2):
static = FreeCADGui.Selection.getSelection()[0]
dynamic = FreeCADGui.Selection.getSelection()[1]
dyn.AddAxialRotationJoint(static, dynamic)
def GetResources(self):
MenuText = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_add_axial_rotation_joint',
'Add axial rotation joint')
ToolTip = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_add_axial_rotation_joint',
'Add axial rotation joint')
return {
'Pixmap': __dir__ + '/icons/axial.png',
'MenuText': MenuText,
'ToolTip': ToolTip}
def IsActive(self):
return not FreeCAD.ActiveDocument is None
FreeCADGui.addCommand('MBdyn_AxialRotation', _AddAxialRotationCmd())
"""//////////////////////////////////////////////////////////////////////////////NERLY FINISHED/////////////////////////////////////////////"""
"""//////////////////////////////////////////////////////////////////////////////CLAMP JOINT///////////////////////////////////////////"""
class _AddClampCmd:
def Activated(self):
b = FreeCADGui.Selection.getSelection()
if(len(b)<1):
QtGui.QMessageBox.information(None,"Error...","Select a structural static node first.")
if(len(b)==1):
node = FreeCADGui.Selection.getSelection()[0]
dyn.AddClampJoint(node)
def GetResources(self):
MenuText = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_add_clamp_joint',
'Add clamp joint')
ToolTip = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_add_clamp_joint',
'Add clamp joint')
return {
'Pixmap': __dir__ + '/icons/clamp.png',
'MenuText': MenuText,
'ToolTip': ToolTip}
def IsActive(self):
return not FreeCAD.ActiveDocument is None
FreeCADGui.addCommand('MBdyn_AddClamp', _AddClampCmd())
"""//////////////////////////////////////////////////////////////////////////////STRUCTURAL STATIC NODE///////////////////////////////////////////"""
class _AddStructuralStaticCmd:
def Activated(self):
b = FreeCADGui.Selection.getSelection()
if(len(b)==0):
QtGui.QMessageBox.information(None,"","Select a solid object first.")
else:
body = FreeCADGui.Selection.getSelection()[0]
dyn.AddStructuralStaticNode(body)
def GetResources(self):
MenuText = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_add_structural_static_node',
'Add structural static node')
ToolTip = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_add_structural_static_node',
'Add structural static node')
return {
'Pixmap': __dir__ + '/icons/StructuralStatic.png',
'MenuText': MenuText,
'ToolTip': ToolTip}
def IsActive(self):
return not FreeCAD.ActiveDocument is None
FreeCADGui.addCommand('MBdyn_AddStructuralStatic', _AddStructuralStaticCmd())
"""//////////////////////////////////////////////////////////////////////////////PLOT////////////////////////////////////////////////////"""
class _PlotCmd:
def Activated(self):
b = FreeCADGui.Selection.getSelection()
if(len(b)==0):
QtGui.QMessageBox.information(None,"Error","Select one node or one joint first.")
else:
if(b[0].Label.startswith('structural:')):
node = int(b[0].label)
reply = QtGui.QInputDialog.getText(None,"FreeDyn","Enter plot expression:")
dyn.PlotNode(node, reply[0])#Plot all the data contained in the .mov file
if(b[0].Label.startswith('joint:')):
joint = int(b[0].label)
reply = QtGui.QInputDialog.getText(None,"FreeDyn","Enter plot expression:")
dyn.PlotJoint(joint, reply[0])#Plot all the data contained in the .mov file
def GetResources(self):
MenuText = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_plot_simulation_results',
'Plot simulation results')
ToolTip = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_plot_simulation_results',
'Plot simulation results')
return {
'Pixmap': __dir__ + '/icons/Matplotlib.png',
'MenuText': MenuText,
'ToolTip': ToolTip}
def IsActive(self):
return not FreeCAD.ActiveDocument is None
FreeCADGui.addCommand('MBdyn_Plot', _PlotCmd())
"""//////////////////////////////////////////////////////////////////////////////REVOLUTE HINGE JOINT///////////////////////////////////////////////////"""
class _AddRevolutehingeCmd:
def Activated(self):
b = FreeCADGui.Selection.getSelection()
if(len(b)<3):
QtGui.QMessageBox.information(None,"Error...","Select two structural dynamic nodes and a reference cylinder first.")
if(len(b)==3):
node1 = FreeCADGui.Selection.getSelection()[0]
node2 = FreeCADGui.Selection.getSelection()[1]
cylinder = FreeCADGui.Selection.getSelection()[2]
dyn.AddRevoluteHingeJoint(node1, node2, cylinder)
def GetResources(self):
MenuText = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_create_revolute_hinge_joint',
'Create revolute hinge joint')
ToolTip = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_create_revolute_hinge_joint',
'Create revolute hinge joint')
return {
'Pixmap': __dir__ + '/icons/hinge1.png',
'MenuText': MenuText,
'ToolTip': ToolTip}
def IsActive(self):
return not FreeCAD.ActiveDocument is None
FreeCADGui.addCommand('MBdyn_AddRevolutehinge', _AddRevolutehingeCmd())
"""//////////////////////////////////////////////////////////////////////////////DRIVE HINGE JOINT///////////////////////////////////////////////////"""
class _AddDrivehingeCmd:
def Activated(self):
b = FreeCADGui.Selection.getSelection()
if(len(b)!=2):
QtGui.QMessageBox.information(None,"Error...","Select two structural nodes first.")
if(len(b)==2):
node1 = FreeCADGui.Selection.getSelection()[0]
node2 = FreeCADGui.Selection.getSelection()[1]
dyn.AddDriveHingeJoint(node1, node2)
def GetResources(self):
MenuText = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_Create_drive_hinge_joint',
'Create drive hinge joint')
ToolTip = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_Create_drive_hinge_joint',
'Create drive hinge joint')
return {
'Pixmap': __dir__ + '/icons/drivehinge.png',
'MenuText': MenuText,
'ToolTip': ToolTip}
def IsActive(self):
return not FreeCAD.ActiveDocument is None
FreeCADGui.addCommand('MBdyn_AddDrivehinge', _AddDrivehingeCmd())
"""//////////////////////////////////////////////////////////////////////////////DUMMY/STATIC BODY////////////////////////////////////////////////////"""
class _AddDummyBodyCmd:
def Activated(self):
b = FreeCADGui.Selection.getSelection()
if(len(b)==1):
dyn.AddDummyOrStaticBody(b[0])
else:
QtGui.QMessageBox.information(None,"FreeDyn", "Dummy bodies do not have mass or inertia. They are only required to visualize the motion of dummy nodes. Select a solid object first. A dummy body associated to it's respective dummy node will be created.")
def GetResources(self):
MenuText = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_create_dummy_static_body',
'Create dummy/static body')
ToolTip = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_create_dummy_static_body',
'Create dummy/static body')
return {
'Pixmap': __dir__ + '/icons/viga1.png',
'MenuText': MenuText,
'ToolTip': ToolTip}
def IsActive(self):
return not FreeCAD.ActiveDocument is None
FreeCADGui.addCommand('MBdyn_AddDummyBody', _AddDummyBodyCmd())
"""//////////////////////////////////////////////////////////////////////////////REVOLUTE PIN JOINT////////////////////////////////////////////////////"""
class _AddRevolutepinCmd:
def Activated(self):
b = FreeCADGui.Selection.getSelection()
if(len(b)==2):
dyn.AddRevolutePin(FreeCADGui.Selection.getSelection()[0],FreeCADGui.Selection.getSelection()[1])
else:
QtGui.QMessageBox.information(None,"FreeDyn","Select a structural dynamic node and a reference cylinder first.")
def GetResources(self):
MenuText = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_create_revolute_pin_joint',
'Create revolute pin joint')
ToolTip = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_create_revolute_pin_joint',
'Create revolute pin joint')
return {
'Pixmap': __dir__ + '/icons/hinge.png',
'MenuText': MenuText,
'ToolTip': ToolTip}
def IsActive(self):
return not FreeCAD.ActiveDocument is None
FreeCADGui.addCommand('MBdyn_AddRevolutepin', _AddRevolutepinCmd())
"""//////////////////////////////////////////////////////////////////////////////RIGID BODY///////////////////////////////////////////"""
class _AddRigidBodyCmd:
def Activated(self):
b = FreeCADGui.Selection.getSelection()
if(len(b)!=1):
QtGui.QMessageBox.information(None,"FreeDyn","A structural node provides the degrees of freedom for a rigid body but it does not define a body. To define a body, mass, center of mass, and moments of inertia are required. A rigid body carries this information.\n\n Hint: select a simple (non-parametric) solid object first, enter the material's density, and FreeDyn will calculate the body's volume, mass, and moments of inertia. The rigid body will inherit the shape of the original solid object, and will be placed in the Rigid_bodies container, within Bodies.")
else:
dyn.AddRigidBody(b[0])
def GetResources(self):
MenuText = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_create_rigid_body',
'Create rigid body')
ToolTip = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_create_rigid_body',
'Create rigid body')
return {
'Pixmap': __dir__ + '/icons/viga.png',
'MenuText': MenuText,
'ToolTip': ToolTip}
def IsActive(self):
return not FreeCAD.ActiveDocument is None
FreeCADGui.addCommand('MBdyn_AddRigidBody', _AddRigidBodyCmd())
"""//////////////////////////////////////////////////////////////////////////////STRUCTURAL DUMMY NODE////////////////////////////////////////////////////"""
class _AddDummyNodeCmd:
def Activated(self):
b = FreeCADGui.Selection.getSelection()
if(len(b)==2):
dyn.AddStructuralDumyNode(FreeCADGui.Selection.getSelection()[0],FreeCADGui.Selection.getSelection()[1])
else:
QtGui.QMessageBox.information(None,"FreeDyn","Unlike dynamic nodes, a dummy node cannot assume any degree of freedom, and has to be attached to another node. Hint: select a structural dynamic node and a solid object firts. A dummy node will be attached to the selected dynamic node, and will be positioned at the center of mass of the solid object.")
def GetResources(self):
MenuText = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_add_structural_dummy_node',
'Add structural dummy node')
ToolTip = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_add_structural_dummy_node',
'Add structural dummy node')
return {
'Pixmap': __dir__ + '/icons/StructuralDummy.png',
'MenuText': MenuText,
'ToolTip': ToolTip}
def IsActive(self):
return not FreeCAD.ActiveDocument is None
FreeCADGui.addCommand('MBdyn_AddDummyNode', _AddDummyNodeCmd())
"""//////////////////////////////////////////////////////////////////////////////STRUCTURAL DYNAMIC NODE///////////////////////////////////////////////////////////////"""
class _AddStructuralDynamicNodeCmd:
def Activated(self):
b = FreeCADGui.Selection.getSelection()
if(len(b)==1):
dyn.AddStructuralDynamicNode(b[0])
else:
QtGui.QMessageBox.information(None,"FreeDyn","A structural node is a point in space which has six degrees of freedom, three define its possition, using cartesian coordinates (x,y,z), and three define its orientation, using Euler angles (Yaw, Pitch, Roll). A structural node is dynamic when it has inertia (linear and angular momentum). Hint: select a simple (non-parametric) solid object first. A structural dynamic node will be created at the center of mass of the object, and added to the Dynamic_nodes container, inside Structural_nodes. You can change the node's initial conditions in the node's properties.")
def GetResources(self):
MenuText = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_add_structural_dynamic_node',
'Add structural dynamic node')
ToolTip = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_add_structural_dynamic_node',
'Add structural dynamic node')
return {
'Pixmap': __dir__ + '/icons/StructuralDynamic.png',
'MenuText': MenuText,
'ToolTip': ToolTip}
def IsActive(self):
return not FreeCAD.ActiveDocument is None
FreeCADGui.addCommand('MBdyn_AddStructuralDynamicNodeCmd', _AddStructuralDynamicNodeCmd())
"""//////////////////////////////////////////////////////////////////////////////StructuralForce////////////////////////////////////////////////////"""
class _AddStructuralForceCmd:
def Activated(self):
b = FreeCADGui.Selection.getSelection()
if((len(b)==1)and(b[0].Label.startswith('structural:'))):
dyn.AddStructuralForce(b[0])
else:
QtGui.QMessageBox.information(None,"FreeDyn","Select only one structural dynamic node first.")
def GetResources(self):
MenuText = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_add_structural_force',
'Add structural force')
ToolTip = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_add_structural_force',
'Add structural force')
return {
'Pixmap': __dir__ + '/icons/force.png',
'MenuText': MenuText,
'ToolTip': ToolTip}
def IsActive(self):
return not FreeCAD.ActiveDocument is None
FreeCADGui.addCommand('MBdyn_AddStructuralForce', _AddStructuralForceCmd())
"""//////////////////////////////////////////////////////////////////////////////GRAVITY////////////////////////////////////////////////////"""
class _AddGravityCmd:
def Activated(self):
dyn.AddGravity()
def GetResources(self):
MenuText = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_add_gravity',
'Add gravity')
ToolTip = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_add_gravity',
'Add gravity')
return {
'Pixmap': __dir__ + '/icons/apple.svg',
'MenuText': MenuText,
'ToolTip': ToolTip}
def IsActive(self):
return not FreeCAD.ActiveDocument is None
FreeCADGui.addCommand('MBdyn_AddGravity', _AddGravityCmd())
"""//////////////////////////////////////////////////////////////////////////////RANDOM Color////////////////////////////////////////////////////"""
class _RandomColorCmd:
def Activated(self):
b = FreeCADGui.Selection.getSelection()
if((len(b)==1)and(b[0].Label.startswith('body:'))):
dyn.RandomColor(b[0])
else:
QtGui.QMessageBox.information(None,"FreeDyn","Select only one rigid body first.")
def GetResources(self):
MenuText = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_give_a_random_color_to_a_rigid_body',
'Gives a random color to a rigid body')
ToolTip = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_give_a_random_color_to_a_rigid_body',
'Gives a random color to a rigid body')
return {
'Pixmap': __dir__ + '/icons/colors.png',
'MenuText': MenuText,
'ToolTip': ToolTip}
def IsActive(self):
return not FreeCAD.ActiveDocument is None
FreeCADGui.addCommand('MBdyn_RandomColor', _RandomColorCmd())
"""//////////////////////////////////////////////////////////////////////////////RECALCULATE////////////////////////////////////////////////////"""
class _RecalculateOrientation:
def Activated(self):
objeto = FreeCADGui.Selection.getSelection()[0]
if(objeto.Label.startswith('structural: ')):
dyn.UpdateDynamicNode(objeto.Label)
if(objeto.Label.startswith('joint: ')):
dyn.UpdateJoint(objeto.Label)
if(objeto.Label.startswith('body: ')):#Update the rigid body physical properties:
dyn.UpdateRigidBody(objeto)
def GetResources(self):
MenuText = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_recalculate_the_phisical_properties_of_a_rigid_body',
'Select a rigid body, a structural node or a joint to recalculate')
ToolTip = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_recalculate_the_phisical_properties_of_a_rigid_body',
'Select a rigid body, a structural node or a joint to recalculate')
return {
'Pixmap': __dir__ + '/icons/recalculate_node.png',
'MenuText': MenuText,
'ToolTip': ToolTip}
def IsActive(self):
return not FreeCAD.ActiveDocument is None
FreeCADGui.addCommand('MBdyn_RecalculateOrientation', _RecalculateOrientation())
"""//////////////////////////////////////////////////////////////////////////////CREATE GLOBAL REFERENCE FRAME AND ADD CONTAINERS//////////////////////////////////////////////////"""
class _AddXYZCmd:
def Activated(self):
dyn.CreateWorld();
def GetResources(self):
MenuText = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_add_global_reference_frame_and_all_the_necesary_containers',
'Add global reference frame and all the necesary containers')
ToolTip = QtCore.QT_TRANSLATE_NOOP(
'MBdyn_add_global_reference_frame_and_all_the_necesary_containers',
'Add global reference frame and all the necesary containers')
return {
'Pixmap': __dir__ + '/icons/earth.png',
'MenuText': MenuText,
'ToolTip': ToolTip}
def IsActive(self):
return not FreeCAD.ActiveDocument is None
FreeCADGui.addCommand('MBdyn_AddXYZ', _AddXYZCmd())
"""//////////////////////////////////////////////////////////////////////////////LOAD WORKING EXAMPLES//////////////////////////////////////////////////"""
"""//////////////////////////////////////////////////////////////////////////////Free Fall//////////////////////////////////////////////////"""
class _MBdyn_LoadExampleFreeFallingBody1Cmd:
def Activated(self):
FreeCAD.open(__dir__ +u"/Samples/Basic examples/1. Free falling body/Solved simulation/FreeFallingBody.FCStd")
FreeCAD.setActiveDocument("FreeFallingBody")
FreeCAD.ActiveDocument=FreeCAD.getDocument("FreeFallingBody")
FreeCADGui.ActiveDocument=FreeCADGui.getDocument("FreeFallingBody")
FreeCADGui.SendMsgToActiveView("ViewFit")
def GetResources(self):
MenuText = QtCore.QT_TRANSLATE_NOOP(
'Free falling body',
'Free falling body')
ToolTip = QtCore.QT_TRANSLATE_NOOP(
'Free falling body',
'Free falling body')
return {
'Pixmap': __dir__ + '/icons/load.png',
'MenuText': MenuText,
'ToolTip': ToolTip}
def IsActive(self):
return not FreeCAD.ActiveDocument is None
FreeCADGui.addCommand('MBdyn_LoadExampleFreeFallingBody1', _MBdyn_LoadExampleFreeFallingBody1Cmd())
class _MBdyn_LoadExampleFreeFallingBody2Cmd:
def Activated(self):
FreeCAD.open(__dir__ +u"/Samples/Basic examples/1. Free falling body/CAD only/FreeFallingBodyCAD.FCStd")
FreeCAD.setActiveDocument("FreeFallingBodyCAD")
FreeCAD.ActiveDocument=FreeCAD.getDocument("FreeFallingBodyCAD")
FreeCADGui.ActiveDocument=FreeCADGui.getDocument("FreeFallingBodyCAD")
FreeCADGui.SendMsgToActiveView("ViewFit")
def GetResources(self):
MenuText = QtCore.QT_TRANSLATE_NOOP(
'Free falling body - CAD only',
'Free falling body - CAD only')
ToolTip = QtCore.QT_TRANSLATE_NOOP(
'Free falling body - CAD only',
'Free falling body - CAD only')
return {
'Pixmap': __dir__ + '/icons/load.png',
'MenuText': MenuText,
'ToolTip': ToolTip}
def IsActive(self):
return not FreeCAD.ActiveDocument is None
FreeCADGui.addCommand('MBdyn_LoadExampleFreeFallingBody2', _MBdyn_LoadExampleFreeFallingBody2Cmd())
"""//////////////////////////////////////////////////////////////////////////////Tennis racket theorem//////////////////////////////////////////////////"""
class _MBdyn_LoadExampleTennisRacketStableCmd:
def Activated(self):
FreeCAD.open(__dir__ +u"/Samples/Basic examples/2. Tennis racket theorem/Solved simulation/Stable/TennisRacketStable.FCStd")
FreeCAD.setActiveDocument("TennisRacketStable")
FreeCAD.ActiveDocument=FreeCAD.getDocument("TennisRacketStable")
FreeCADGui.ActiveDocument=FreeCADGui.getDocument("TennisRacketStable")
FreeCADGui.SendMsgToActiveView("ViewFit")
def GetResources(self):
MenuText = QtCore.QT_TRANSLATE_NOOP(
'Tennis racket theorem - stable rotation',
'Tennis racket theorem - stable rotation')
ToolTip = QtCore.QT_TRANSLATE_NOOP(
'Tennis racket theorem - solved simulation - stable rotation',
'Tennis racket theorem - solved simulation - stable rotation')
return {
'Pixmap': __dir__ + '/icons/load.png',
'MenuText': MenuText,
'ToolTip': ToolTip}
def IsActive(self):
return not FreeCAD.ActiveDocument is None
FreeCADGui.addCommand('MBdyn_LoadExampleTennisRacketStable', _MBdyn_LoadExampleTennisRacketStableCmd())
class _MBdyn_LoadExampleTennisRacketUnStableCmd:
def Activated(self):
FreeCAD.open(__dir__ +u"/Samples/Basic examples/2. Tennis racket theorem/Solved simulation/Unstable/TennisRacketUnstable.FCStd")
FreeCAD.setActiveDocument("TennisRacketUnstable")
FreeCAD.ActiveDocument=FreeCAD.getDocument("TennisRacketUnstable")
FreeCADGui.ActiveDocument=FreeCADGui.getDocument("TennisRacketUnstable")
FreeCADGui.SendMsgToActiveView("ViewFit")
def GetResources(self):
MenuText = QtCore.QT_TRANSLATE_NOOP(
'Tennis racket theorem - unstable rotation',
'Tennis racket theorem - unstable rotation')
ToolTip = QtCore.QT_TRANSLATE_NOOP(
'Tennis racket theorem - unstable rotation',
'Tennis racket theorem - unstable rotation')
return {
'Pixmap': __dir__ + '/icons/load.png',
'MenuText': MenuText,
'ToolTip': ToolTip}
def IsActive(self):
return not FreeCAD.ActiveDocument is None
FreeCADGui.addCommand('MBdyn_LoadExampleTennisRacketUnStable', _MBdyn_LoadExampleTennisRacketUnStableCmd())
class _MBdyn_LoadExampleTennisRacketCADCmd:
def Activated(self):
FreeCAD.open(__dir__ +u"/Samples/Basic examples/2. Tennis racket theorem/CAD only/TennisRacketCAD.FCStd")
FreeCAD.setActiveDocument("TennisRacketCAD")
FreeCAD.ActiveDocument=FreeCAD.getDocument("TennisRacketCAD")
FreeCADGui.ActiveDocument=FreeCADGui.getDocument("TennisRacketCAD")
FreeCADGui.SendMsgToActiveView("ViewFit")
def GetResources(self):
MenuText = QtCore.QT_TRANSLATE_NOOP(
'Tennis racket theorem - CAD only',
'Tennis racket theorem - CAD only')
ToolTip = QtCore.QT_TRANSLATE_NOOP(
'Tennis racket theorem - CAD only',
'Tennis racket theorem - CAD only')
return {
'Pixmap': __dir__ + '/icons/load.png',
'MenuText': MenuText,
'ToolTip': ToolTip}