/
commands.py
1253 lines (1112 loc) · 41.6 KB
/
commands.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
# ***************************************************************************
# * Copyright (c) 2016 Bernd Hahnebach <bernd@bimstatik.org> *
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU Lesser General Public License (LGPL) *
# * as published by the Free Software Foundation; either version 2 of *
# * the License, or (at your option) any later version. *
# * for detail see the LICENCE text file. *
# * *
# * 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 Library General Public License for more details. *
# * *
# * You should have received a copy of the GNU Library General Public *
# * License along with this program; if not, write to the Free Software *
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# * USA *
# * *
# ***************************************************************************
import FreeCAD
import FreeCADGui
from .manager import CommandManager
from PySide import QtCore
# Python command definitions
# for C++ command definitions see src/Mod/Fem/Command.cpp
# TODO, may be even more generic class creation
# with type() and identifier instead of class for
# the commands which add new document objects.
# see https://www.python-course.eu/python3_classes_and_type.php
class _Analysis(CommandManager):
"The FEM_Analysis command definition"
def __init__(self):
super(_Analysis, self).__init__()
self.resources = {
"Pixmap": "FEM_Analysis",
"MenuText": QtCore.QT_TRANSLATE_NOOP(
"FEM_Analysis",
"Analysis container"
),
"Accel": "N, A",
"ToolTip": QtCore.QT_TRANSLATE_NOOP(
"FEM_Analysis",
"Creates an analysis container with standard solver CalculiX"
)
}
self.is_active = "with_document"
def Activated(self):
FreeCAD.ActiveDocument.openTransaction("Create Analysis")
FreeCADGui.addModule("FemGui")
FreeCADGui.addModule("ObjectsFem")
FreeCADGui.doCommand("ObjectsFem.makeAnalysis(FreeCAD.ActiveDocument, 'Analysis')")
FreeCADGui.doCommand("FemGui.setActiveAnalysis(FreeCAD.ActiveDocument.ActiveObject)")
# create a CalculiX ccx tools solver for any new analysis
# to be on the safe side for new users
FreeCADGui.doCommand("ObjectsFem.makeSolverCalculixCcxTools(FreeCAD.ActiveDocument)")
FreeCADGui.doCommand(
"FemGui.getActiveAnalysis().addObject(FreeCAD.ActiveDocument.ActiveObject)"
)
FreeCAD.ActiveDocument.recompute()
class _ClippingPlaneAdd(CommandManager):
"The FEM_ClippingPlaneAdd command definition"
def __init__(self):
super(_ClippingPlaneAdd, self).__init__()
self.resources = {
"Pixmap": "FEM_ClippingPlaneAdd",
"MenuText": QtCore.QT_TRANSLATE_NOOP(
"FEM_ClippingPlaneAdd",
"Clipping plane on face"
),
# "Accel": "Z, Z",
"ToolTip": QtCore.QT_TRANSLATE_NOOP(
"FEM_ClippingPlaneAdd",
"Add a clipping plane on a selected face"
)
}
self.is_active = "with_document"
def Activated(self):
from femtools import femutils
overalboundbox = femutils.getBoundBoxOfAllDocumentShapes(FreeCAD.ActiveDocument)
# print(overalboundbox)
min_bb_length = (min(set([
overalboundbox.XLength,
overalboundbox.YLength,
overalboundbox.ZLength
])))
dbox = min_bb_length * 0.2
aFace = femutils.getSelectedFace(FreeCADGui.Selection.getSelectionEx())
if aFace:
f_CoM = aFace.CenterOfMass
f_uvCoM = aFace.Surface.parameter(f_CoM) # u,v at CoM for normalAt calculation
f_normal = aFace.normalAt(f_uvCoM[0], f_uvCoM[1])
else:
f_CoM = FreeCAD.Vector(0, 0, 0)
f_normal = FreeCAD.Vector(0, 0, 1)
from pivy import coin
coin_normal_vector = coin.SbVec3f(-f_normal.x, -f_normal.y, -f_normal.z)
coin_bound_box = coin.SbBox3f(
f_CoM.x - dbox, f_CoM.y - dbox,
f_CoM.z - dbox * 0.15,
f_CoM.x + dbox,
f_CoM.y + dbox,
f_CoM.z + dbox * 0.15
)
clip_plane = coin.SoClipPlaneManip()
clip_plane.setValue(coin_bound_box, coin_normal_vector, 1)
FreeCADGui.ActiveDocument.ActiveView.getSceneGraph().insertChild(clip_plane, 1)
class _ClippingPlaneRemoveAll(CommandManager):
"The FEM_ClippingPlaneemoveAll command definition"
def __init__(self):
super(_ClippingPlaneRemoveAll, self).__init__()
self.resources = {
"Pixmap": "FEM_ClippingPlaneRemoveAll",
"MenuText": QtCore.QT_TRANSLATE_NOOP(
"FEM_ClippingPlaneRemoveAll",
"Remove all clipping planes"
),
# "Accel": "Z, Z",
"ToolTip": QtCore.QT_TRANSLATE_NOOP(
"FEM_ClippingPlaneRemoveAll",
"Remove all clipping planes"
)
}
self.is_active = "with_document"
def Activated(self):
line1 = "for node in list(sg.getChildren()):\n"
line2 = " if isinstance(node, coin.SoClipPlane):\n"
line3 = " sg.removeChild(node)"
FreeCADGui.doCommand("from pivy import coin")
FreeCADGui.doCommand("sg = Gui.ActiveDocument.ActiveView.getSceneGraph()")
FreeCADGui.doCommand("nodes = sg.getChildren()")
FreeCADGui.doCommand(line1 + line2 + line3)
class _ConstraintBodyHeatSource(CommandManager):
"The FEM_ConstraintBodyHeatSource command definition"
def __init__(self):
super(_ConstraintBodyHeatSource, self).__init__()
self.resources = {
"Pixmap": "FEM_ConstraintHeatflux", # the heatflux icon is used
"MenuText": QtCore.QT_TRANSLATE_NOOP(
"FEM_ConstraintBodyHeatSource",
"Constraint body heat source"
),
"ToolTip": QtCore.QT_TRANSLATE_NOOP(
"FEM_ConstraintBodyHeatSource",
"Creates a FEM constraint body heat source"
)
}
self.is_active = "with_analysis"
self.do_activated = "add_obj_on_gui_noset_edit"
class _ConstraintElectrostaticPotential(CommandManager):
"The FEM_ConstraintElectrostaticPotential command definition"
def __init__(self):
super(_ConstraintElectrostaticPotential, self).__init__()
self.resources = {
"Pixmap": "FEM_ConstraintElectrostaticPotential",
"MenuText": QtCore.QT_TRANSLATE_NOOP(
"FEM_ConstraintElectrostaticPotential",
"Constraint electrostatic potential"
),
"ToolTip": QtCore.QT_TRANSLATE_NOOP(
"FEM_ConstraintElectrostaticPotential",
"Creates a FEM constraint electrostatic potential"
)
}
self.is_active = "with_analysis"
self.do_activated = "add_obj_on_gui_set_edit"
class _ConstraintFlowVelocity(CommandManager):
"The FEM_ConstraintFlowVelocity command definition"
def __init__(self):
super(_ConstraintFlowVelocity, self).__init__()
self.resources = {
"Pixmap": "FEM_ConstraintFlowVelocity",
"MenuText": QtCore.QT_TRANSLATE_NOOP(
"FEM_ConstraintFlowVelocity",
"Constraint flow velocity"
),
"ToolTip": QtCore.QT_TRANSLATE_NOOP(
"FEM_ConstraintFlowVelocity",
"Creates a FEM constraint flow velocity"
)
}
self.is_active = "with_analysis"
self.do_activated = "add_obj_on_gui_set_edit"
class _ConstraintInitialFlowVelocity(CommandManager):
"The FEM_ConstraintInitialFlowVelocity command definition"
def __init__(self):
super(_ConstraintInitialFlowVelocity, self).__init__()
self.resources = {
"Pixmap": "FEM_ConstraintInitialFlowVelocity",
"MenuText": QtCore.QT_TRANSLATE_NOOP(
"FEM_ConstraintInitialFlowVelocity",
"Constraint initial flow velocity"
),
"ToolTip": QtCore.QT_TRANSLATE_NOOP(
"FEM_ConstraintInitialFlowVelocity",
"Creates a FEM constraint initial flow velocity"
)
}
self.is_active = "with_analysis"
self.do_activated = "add_obj_on_gui_set_edit"
class _ConstraintSelfWeight(CommandManager):
"The FEM_ConstraintSelfWeight command definition"
def __init__(self):
super(_ConstraintSelfWeight, self).__init__()
self.resources = {
"Pixmap": "FEM_ConstraintSelfWeight",
"MenuText": QtCore.QT_TRANSLATE_NOOP(
"FEM_ConstraintSelfWeight",
"Constraint self weight"
),
"Accel": "C, W",
"ToolTip": QtCore.QT_TRANSLATE_NOOP(
"FEM_ConstraintSelfWeight",
"Creates a FEM constraint self weight"
)
}
self.is_active = "with_analysis"
self.do_activated = "add_obj_on_gui_noset_edit"
class _ConstraintTie(CommandManager):
"The FEM_ConstraintTie command definition"
def __init__(self):
super(_ConstraintTie, self).__init__()
self.resources = {
"Pixmap": "FEM_ConstraintTie",
"MenuText": QtCore.QT_TRANSLATE_NOOP(
"FEM_ConstraintTie",
"Constraint tie"
),
"Accel": "C, T",
"ToolTip": QtCore.QT_TRANSLATE_NOOP(
"FEM_ConstraintTie",
"Creates a FEM constraint tie"
)
}
self.is_active = "with_analysis"
self.do_activated = "add_obj_on_gui_set_edit"
class _ElementFluid1D(CommandManager):
"The FEM_ElementFluid1D command definition"
def __init__(self):
super(_ElementFluid1D, self).__init__()
self.resources = {
"Pixmap": "FEM_ElementFluid1D",
"MenuText": QtCore.QT_TRANSLATE_NOOP(
"FEM_ElementFluid1D",
"Fluid section for 1D flow"
),
"Accel": "C, B",
"ToolTip": QtCore.QT_TRANSLATE_NOOP(
"FEM_ElementFluid1D",
"Creates a FEM fluid section for 1D flow"
)
}
self.is_active = "with_analysis"
self.do_activated = "add_obj_on_gui_set_edit"
class _ElementGeometry1D(CommandManager):
"The Fem_ElementGeometry1D command definition"
def __init__(self):
super(_ElementGeometry1D, self).__init__()
self.resources = {
"Pixmap": "FEM_ElementGeometry1D",
"MenuText": QtCore.QT_TRANSLATE_NOOP(
"FEM_ElementGeometry1D",
"Beam cross section"
),
"Accel": "C, B",
"ToolTip": QtCore.QT_TRANSLATE_NOOP(
"FEM_ElementGeometry1D",
"Creates a FEM beam cross section"
)
}
self.is_active = "with_analysis"
self.do_activated = "add_obj_on_gui_set_edit"
class _ElementGeometry2D(CommandManager):
"The FEM_ElementGeometry2D command definition"
def __init__(self):
super(_ElementGeometry2D, self).__init__()
self.resources = {
"Pixmap": "FEM_ElementGeometry2D",
"MenuText": QtCore.QT_TRANSLATE_NOOP(
"FEM_ElementGeometry2D",
"Shell plate thickness"
),
"Accel": "C, S",
"ToolTip": QtCore.QT_TRANSLATE_NOOP(
"FEM_ElementGeometry2D",
"Creates a FEM shell plate thickness"
)
}
self.is_active = "with_analysis"
self.do_activated = "add_obj_on_gui_set_edit"
class _ElementRotation1D(CommandManager):
"The Fem_ElementRotation1D command definition"
def __init__(self):
super(_ElementRotation1D, self).__init__()
self.resources = {
"Pixmap": "FEM_ElementRotation1D",
"MenuText": QtCore.QT_TRANSLATE_NOOP(
"FEM_ElementRotation1D",
"Beam rotation"
),
"Accel": "C, R",
"ToolTip": QtCore.QT_TRANSLATE_NOOP(
"FEM_ElementRotation1D",
"Creates a FEM beam rotation"
)
}
self.is_active = "with_analysis"
self.do_activated = "add_obj_on_gui_noset_edit"
class _EquationElectrostatic(CommandManager):
"The FEM_EquationElectrostatic command definition"
def __init__(self):
super(_EquationElectrostatic, self).__init__()
self.resources = {
"Pixmap": "FEM_EquationElectrostatic",
"MenuText": QtCore.QT_TRANSLATE_NOOP(
"FEM_EquationElectrostatic",
"Electrostatic equation"
),
"ToolTip": QtCore.QT_TRANSLATE_NOOP(
"FEM_EquationElectrostatic",
"Creates a FEM equation for electrostatic"
)
}
self.is_active = "with_solver_elmer"
self.do_activated = "add_obj_on_gui_selobj_noset_edit"
class _EquationElasticity(CommandManager):
"The FEM_EquationElasticity command definition"
def __init__(self):
super(_EquationElasticity, self).__init__()
self.resources = {
"Pixmap": "FEM_EquationElasticity",
"MenuText": QtCore.QT_TRANSLATE_NOOP(
"FEM_EquationElasticity",
"Elasticity equation"
),
"ToolTip": QtCore.QT_TRANSLATE_NOOP(
"FEM_EquationElasticity",
"Creates a FEM equation for elasticity"
)
}
self.is_active = "with_solver_elmer"
self.do_activated = "add_obj_on_gui_selobj_noset_edit"
class _EquationFlow(CommandManager):
"The FEM_EquationFlow command definition"
def __init__(self):
super(_EquationFlow, self).__init__()
self.resources = {
"Pixmap": "FEM_EquationFlow",
"MenuText": QtCore.QT_TRANSLATE_NOOP(
"FEM_EquationFlow",
"Flow equation"
),
"ToolTip": QtCore.QT_TRANSLATE_NOOP(
"FEM_EquationFlow",
"Creates a FEM equation for flow"
)
}
self.is_active = "with_solver_elmer"
self.do_activated = "add_obj_on_gui_selobj_noset_edit"
class _EquationFluxsolver(CommandManager):
"The FEM_EquationFluxsolver command definition"
def __init__(self):
super(_EquationFluxsolver, self).__init__()
self.resources = {
"Pixmap": "FEM_EquationFluxsolver",
"MenuText": QtCore.QT_TRANSLATE_NOOP(
"FEM_EquationFluxsolver",
"Fluxsolver equation"
),
"ToolTip": QtCore.QT_TRANSLATE_NOOP(
"FEM_EquationFluxsolver",
"Creates a FEM equation for fluxsolver"
)
}
self.is_active = "with_solver_elmer"
self.do_activated = "add_obj_on_gui_selobj_noset_edit"
class _EquationHeat(CommandManager):
"The FEM_EquationHeat command definition"
def __init__(self):
super(_EquationHeat, self).__init__()
self.resources = {
"Pixmap": "FEM_EquationHeat",
"MenuText": QtCore.QT_TRANSLATE_NOOP(
"FEM_EquationHeat",
"Fluxsolver heat"
),
"ToolTip": QtCore.QT_TRANSLATE_NOOP(
"FEM_EquationHeat",
"Creates a FEM equation for heat"
)
}
self.is_active = "with_solver_elmer"
self.do_activated = "add_obj_on_gui_selobj_noset_edit"
class _MaterialEditor(CommandManager):
"The FEM_MaterialEditor command definition"
def __init__(self):
super(_MaterialEditor, self).__init__()
self.resources = {
"Pixmap": "Arch_Material_Group",
"MenuText": QtCore.QT_TRANSLATE_NOOP(
"Material_Editor",
"Material editor"
),
# "Accel": "Z, Z",
"ToolTip": QtCore.QT_TRANSLATE_NOOP(
"Material_Editor",
"Opens the FreeCAD material editor"
)
}
self.is_active = "always"
def Activated(self):
FreeCADGui.addModule("MaterialEditor")
FreeCADGui.doCommand("MaterialEditor.openEditor()")
class _MaterialFluid(CommandManager):
"The FEM_MaterialFluid command definition"
def __init__(self):
super(_MaterialFluid, self).__init__()
self.resources = {
"Pixmap": "FEM_MaterialFluid",
"MenuText": QtCore.QT_TRANSLATE_NOOP(
"FEM_MaterialFluid",
"Material for fluid"
),
"Accel": "M, M",
"ToolTip": QtCore.QT_TRANSLATE_NOOP(
"FEM_MaterialFluid",
"Creates a FEM material for fluid"
)
}
self.is_active = "with_analysis"
self.do_activated = "add_obj_on_gui_set_edit"
class _MaterialMechanicalNonlinear(CommandManager):
"The FEM_MaterialMechanicalNonlinear command definition"
def __init__(self):
super(_MaterialMechanicalNonlinear, self).__init__()
self.resources = {
"Pixmap": "FEM_MaterialMechanicalNonlinear",
"MenuText": QtCore.QT_TRANSLATE_NOOP(
"FEM_MaterialMechanicalNonlinear",
"Nonlinear mechanical material"
),
"Accel": "C, W",
"ToolTip": QtCore.QT_TRANSLATE_NOOP(
"FEM_MaterialMechanicalNonlinear",
"Creates a nonlinear mechanical material"
)
}
self.is_active = "with_material_solid"
def Activated(self):
# test if there is a nonlinear material which has the selected material as base material
for o in self.selobj.Document.Objects:
if (
hasattr(o, "Proxy")
and o.Proxy is not None
and hasattr(o.Proxy, "Type")
and o.Proxy.Type == "Fem::MaterialMechanicalNonlinear"
and o.LinearBaseMaterial == self.selobj
):
FreeCAD.Console.PrintError(
"Nonlinear material {} is based on the selected material {}. "
"Only one nonlinear object allowed for each material.\n"
.format(o.Name, self.selobj.Name)
)
return
# add a nonlinear material
string_lin_mat_obj = "FreeCAD.ActiveDocument.getObject('" + self.selobj.Name + "')"
command_to_run = (
"FemGui.getActiveAnalysis().addObject(ObjectsFem."
"makeMaterialMechanicalNonlinear(FreeCAD.ActiveDocument, {}))"
.format(string_lin_mat_obj)
)
FreeCAD.ActiveDocument.openTransaction("Create FemMaterialMechanicalNonlinear")
FreeCADGui.addModule("ObjectsFem")
FreeCADGui.doCommand(command_to_run)
# set some property of the solver to nonlinear
# (only if one solver is available and if this solver is a CalculiX solver):
# nonlinear material
# nonlinear geometry --> it is triggered anyway
# https://forum.freecadweb.org/viewtopic.php?f=18&t=23101&p=180489#p180489
solver_object = None
for m in self.active_analysis.Group:
if m.isDerivedFrom("Fem::FemSolverObjectPython"):
if not solver_object:
solver_object = m
else:
# we do not change attributes if we have more than one solver
# since we do not know which one to take
solver_object = None
break
# set solver attribute for nonlinearity for ccxtools
# CalculiX solver or new frame work CalculiX solver
if solver_object \
and hasattr(solver_object, "Proxy") \
and (
solver_object.Proxy.Type == "Fem::FemSolverCalculixCcxTools"
or solver_object.Proxy.Type == "Fem::FemSolverObjectCalculix"
):
FreeCAD.Console.PrintMessage(
"Set MaterialNonlinearity and GeometricalNonlinearity to nonlinear for {}\n"
.format(solver_object.Label)
)
solver_object.MaterialNonlinearity = "nonlinear"
solver_object.GeometricalNonlinearity = "nonlinear"
FreeCADGui.Selection.clearSelection()
FreeCAD.ActiveDocument.recompute()
class _MaterialReinforced(CommandManager):
"The FEM_MaterialReinforced command definition"
def __init__(self):
super(_MaterialReinforced, self).__init__()
self.resources = {
"Pixmap": "FEM_MaterialReinforced",
"MenuText": QtCore.QT_TRANSLATE_NOOP(
"FEM_MaterialReinforced",
"Reinforced material (concrete)"
),
"Accel": "M, M",
"ToolTip": QtCore.QT_TRANSLATE_NOOP(
"FEM_MaterialReinforced",
"Creates a material for reinforced matrix material such as concrete"
)
}
self.is_active = "with_analysis"
self.do_activated = "add_obj_on_gui_set_edit"
class _MaterialSolid(CommandManager):
"The FEM_MaterialSolid command definition"
def __init__(self):
super(_MaterialSolid, self).__init__()
self.resources = {
"Pixmap": "FEM_MaterialSolid",
"MenuText": QtCore.QT_TRANSLATE_NOOP(
"FEM_MaterialSolid",
"Material for solid"
),
"Accel": "M, M",
"ToolTip": QtCore.QT_TRANSLATE_NOOP(
"FEM_MaterialSolid",
"Creates a FEM material for solid"
)
}
self.is_active = "with_analysis"
self.do_activated = "add_obj_on_gui_set_edit"
class _Mesh2Mesh(CommandManager):
"The FEM_FemMesh2Mesh command definition"
def __init__(self):
super(_Mesh2Mesh, self).__init__()
self.resources = {
"Pixmap": "FEM_FEMMesh2Mesh",
"MenuText": QtCore.QT_TRANSLATE_NOOP(
"FEM_FEMMesh2Mesh",
"FEM mesh to mesh"
),
"ToolTip": QtCore.QT_TRANSLATE_NOOP(
"FEM_FEMMesh2Mesh",
"Convert the surface of a FEM mesh to a mesh"
)
}
self.is_active = "with_femmesh_andor_res"
def Activated(self):
FreeCAD.ActiveDocument.openTransaction("Create Mesh from FEMMesh")
if self.selobj and not self.selobj2: # no result object selected
FreeCADGui.addModule("femmesh.femmesh2mesh")
FreeCADGui.doCommand(
"out_mesh = femmesh.femmesh2mesh.femmesh_2_mesh("
"FreeCAD.ActiveDocument.{}.FemMesh)"
.format(self.selobj.Name)
)
FreeCADGui.addModule("Mesh")
FreeCADGui.doCommand("Mesh.show(Mesh.Mesh(out_mesh))")
FreeCADGui.doCommand(
"FreeCAD.ActiveDocument." + self.selobj.Name + ".ViewObject.hide()"
)
if self.selobj and self.selobj2:
femmesh = self.selobj
res = self.selobj2
FreeCADGui.addModule("femmesh.femmesh2mesh")
FreeCADGui.doCommand(
"out_mesh = femmesh.femmesh2mesh.femmesh_2_mesh("
"FreeCAD.ActiveDocument.{}.FemMesh, FreeCAD.ActiveDocument.{})"
.format(femmesh.Name, res.Name)
)
FreeCADGui.addModule("Mesh")
FreeCADGui.doCommand("Mesh.show(Mesh.Mesh(out_mesh))")
FreeCADGui.doCommand(
"FreeCAD.ActiveDocument." + femmesh.Name + ".ViewObject.hide()"
)
FreeCADGui.Selection.clearSelection()
FreeCAD.ActiveDocument.recompute()
class _MeshBoundaryLayer(CommandManager):
"The FEM_MeshBoundaryLayer command definition"
def __init__(self):
super(_MeshBoundaryLayer, self).__init__()
self.resources = {
"Pixmap": "FEM_MeshBoundaryLayer",
"MenuText": QtCore.QT_TRANSLATE_NOOP(
"FEM_MeshBoundaryLayer",
"FEM mesh boundary layer"
),
"Accel": "M, B",
"ToolTip": QtCore.QT_TRANSLATE_NOOP(
"FEM_MeshBoundaryLayer",
"Creates a FEM mesh boundary layer"
)
}
self.is_active = "with_gmsh_femmesh"
self.do_activated = "add_obj_on_gui_selobj_set_edit"
class _MeshClear(CommandManager):
"The FEM_MeshClear command definition"
def __init__(self):
super(_MeshClear, self).__init__()
self.resources = {
"Pixmap": "FEM_MeshClear",
"MenuText": QtCore.QT_TRANSLATE_NOOP(
"FEM_MeshClear",
"Clear FEM mesh"
),
# "Accel": "Z, Z",
"ToolTip": QtCore.QT_TRANSLATE_NOOP(
"FEM_MeshClear",
"Clear the Mesh of a FEM mesh object"
)
}
self.is_active = "with_femmesh"
def Activated(self):
FreeCAD.ActiveDocument.openTransaction("Clear FEM mesh")
FreeCADGui.addModule("Fem")
FreeCADGui.doCommand(
"FreeCAD.ActiveDocument." + self.selobj.Name + ".FemMesh = Fem.FemMesh()"
)
FreeCADGui.Selection.clearSelection()
FreeCAD.ActiveDocument.recompute()
class _MeshDisplayInfo(CommandManager):
"The FEM_MeshDisplayInfo command definition"
def __init__(self):
super(_MeshDisplayInfo, self).__init__()
self.resources = {
"Pixmap": "FEM_MeshDisplayInfo",
"MenuText": QtCore.QT_TRANSLATE_NOOP(
"FEM_MeshDisplayInfo",
"Display FEM mesh info"
),
# "Accel": "Z, Z",
"ToolTip": QtCore.QT_TRANSLATE_NOOP(
"FEM_MeshDisplayInfo",
"Display FEM mesh info"
)
}
self.is_active = "with_femmesh"
def Activated(self):
FreeCAD.ActiveDocument.openTransaction("Display FEM mesh info")
FreeCADGui.doCommand("print(FreeCAD.ActiveDocument." + self.selobj.Name + ".FemMesh)")
FreeCADGui.addModule("PySide")
FreeCADGui.doCommand(
"mesh_info = str(FreeCAD.ActiveDocument." + self.selobj.Name + ".FemMesh)"
)
FreeCADGui.doCommand(
"PySide.QtGui.QMessageBox.information(None, 'FEM Mesh Info', mesh_info)"
)
FreeCADGui.Selection.clearSelection()
FreeCAD.ActiveDocument.recompute()
class _MeshGmshFromShape(CommandManager):
"The FEM_MeshGmshFromShape command definition"
def __init__(self):
super(_MeshGmshFromShape, self).__init__()
self.resources = {
"Pixmap": "FEM_MeshGmshFromShape",
"MenuText": QtCore.QT_TRANSLATE_NOOP(
"FEM_MeshGmshFromShape",
"FEM mesh from shape by Gmsh"
),
"ToolTip": QtCore.QT_TRANSLATE_NOOP(
"FEM_MeshGmshFromShape",
"Create a FEM mesh from a shape by Gmsh mesher"
)
}
self.is_active = "with_part_feature"
def Activated(self):
# a mesh could be made with and without an analysis,
# we're going to check not for an analysis in command manager module
FreeCAD.ActiveDocument.openTransaction("Create FEM mesh by Gmsh")
mesh_obj_name = "FEMMeshGmsh"
# if requested by some people add Preference for this
# mesh_obj_name = self.selobj.Name + "_Mesh"
FreeCADGui.addModule("ObjectsFem")
FreeCADGui.doCommand(
"ObjectsFem.makeMeshGmsh(FreeCAD.ActiveDocument, '" + mesh_obj_name + "')"
)
FreeCADGui.doCommand(
"FreeCAD.ActiveDocument.ActiveObject.Part = FreeCAD.ActiveDocument.{}"
.format(self.selobj.Name)
)
# Gmsh mesh object could be added without an active analysis
# but if there is an active analysis move it in there
import FemGui
if FemGui.getActiveAnalysis():
FreeCADGui.addModule("FemGui")
FreeCADGui.doCommand(
"FemGui.getActiveAnalysis().addObject(FreeCAD.ActiveDocument.ActiveObject)"
)
FreeCADGui.doCommand(
"FreeCADGui.ActiveDocument.setEdit(FreeCAD.ActiveDocument.ActiveObject.Name)"
)
FreeCADGui.Selection.clearSelection()
FreeCAD.ActiveDocument.recompute()
class _MeshGroup(CommandManager):
"The FEM_MeshGroup command definition"
def __init__(self):
super(_MeshGroup, self).__init__()
self.resources = {
"Pixmap": "fem-femmesh-from-shape",
"MenuText": QtCore.QT_TRANSLATE_NOOP(
"FEM_MeshGroup",
"FEM mesh group"
),
"Accel": "M, G",
"ToolTip": QtCore.QT_TRANSLATE_NOOP(
"FEM_MeshGroup",
"Creates a FEM mesh group"
)
}
self.is_active = "with_gmsh_femmesh"
self.do_activated = "add_obj_on_gui_selobj_set_edit"
class _MeshNetgenFromShape(CommandManager):
"The FEM_MeshNetgenFromShape command definition"
def __init__(self):
super(_MeshNetgenFromShape, self).__init__()
self.resources = {
"Pixmap": "FEM_MeshNetgenFromShape",
"MenuText": QtCore.QT_TRANSLATE_NOOP(
"FEM_MeshNetgenFromShape",
"FEM mesh from shape by Netgen"
),
"ToolTip": QtCore.QT_TRANSLATE_NOOP(
"FEM_MeshNetgenFromShape",
"Create a FEM volume mesh from a solid or face shape by Netgen internal mesher"
)
}
self.is_active = "with_part_feature"
def Activated(self):
# a mesh could be made with and without an analysis,
# we're going to check not for an analysis in command manager module
FreeCAD.ActiveDocument.openTransaction("Create FEM mesh Netgen")
mesh_obj_name = "FEMMeshNetgen"
# if requested by some people add Preference for this
# mesh_obj_name = sel[0].Name + "_Mesh"
FreeCADGui.addModule("ObjectsFem")
FreeCADGui.doCommand(
"ObjectsFem.makeMeshNetgen(FreeCAD.ActiveDocument, '" + mesh_obj_name + "')"
)
FreeCADGui.doCommand(
"FreeCAD.ActiveDocument.ActiveObject.Shape = FreeCAD.ActiveDocument.{}"
.format(self.selobj.Name)
)
# Netgen mesh object could be added without an active analysis
# but if there is an active analysis move it in there
import FemGui
if FemGui.getActiveAnalysis():
FreeCADGui.addModule("FemGui")
FreeCADGui.doCommand(
"FemGui.getActiveAnalysis().addObject(FreeCAD.ActiveDocument.ActiveObject)"
)
FreeCADGui.doCommand(
"FreeCADGui.ActiveDocument.setEdit(FreeCAD.ActiveDocument.ActiveObject.Name)"
)
FreeCADGui.Selection.clearSelection()
# a recompute immediately starts meshing when task panel is opened, this is not intended
class _MeshRegion(CommandManager):
"The FEM_MeshRegion command definition"
def __init__(self):
super(_MeshRegion, self).__init__()
self.resources = {
"Pixmap": "FEM_MeshRegion",
"MenuText": QtCore.QT_TRANSLATE_NOOP(
"FEM_MeshRegion",
"FEM mesh region"
),
"Accel": "M, R",
"ToolTip": QtCore.QT_TRANSLATE_NOOP(
"FEM_MeshRegion",
"Creates a FEM mesh region"
)
}
self.is_active = "with_gmsh_femmesh"
self.do_activated = "add_obj_on_gui_selobj_set_edit"
class _ResultShow(CommandManager):
"The FEM_ResultShow command definition"
def __init__(self):
super(_ResultShow, self).__init__()
self.resources = {
"Pixmap": "fem-post-result-show",
"MenuText": QtCore.QT_TRANSLATE_NOOP(
"FEM_ResultShow",
"Show result"
),
"Accel": "S, R",
"ToolTip": QtCore.QT_TRANSLATE_NOOP(
"FEM_ResultShow",
"Shows and visualizes selected result data"
)
}
self.is_active = "with_selresult"
def Activated(self):
self.selobj.ViewObject.Document.setEdit(self.selobj.ViewObject, 0)
class _ResultsPurge(CommandManager):
"The FEM_ResultsPurge command definition"
def __init__(self):
super(_ResultsPurge, self).__init__()
self.resources = {
"Pixmap": "fem-post-results-purge",
"MenuText": QtCore.QT_TRANSLATE_NOOP(
"FEM_ResultsPurge",
"Purge results"
),
"Accel": "S, S",
"ToolTip": QtCore.QT_TRANSLATE_NOOP(
"FEM_ResultsPurge",
"Purges all results from active analysis"
)
}
self.is_active = "with_results"
def Activated(self):
import femresult.resulttools as resulttools
resulttools.purge_results(self.active_analysis)
class _SolverCxxtools(CommandManager):
"The FEM_SolverCalculix ccx tools command definition"
def __init__(self):
super(_SolverCxxtools, self).__init__()
self.resources = {
"Pixmap": "fem-solver-standard",
"MenuText": QtCore.QT_TRANSLATE_NOOP(
"FEM_SolverCalculix",
"Solver CalculiX Standard"
),
"Accel": "S, X",
"ToolTip": QtCore.QT_TRANSLATE_NOOP(
"FEM_SolverCalculix",
"Creates a standard FEM solver CalculiX with ccx tools"
)
}
self.is_active = "with_analysis"
def Activated(self):
has_nonlinear_material_obj = False
for m in self.active_analysis.Group:
if hasattr(m, "Proxy") and m.Proxy.Type == "Fem::MaterialMechanicalNonlinear":
has_nonlinear_material_obj = True
FreeCAD.ActiveDocument.openTransaction("Create SolverCalculix")
FreeCADGui.addModule("ObjectsFem")
FreeCADGui.addModule("FemGui")
if has_nonlinear_material_obj:
FreeCADGui.doCommand(
"solver = ObjectsFem.makeSolverCalculixCcxTools(FreeCAD.ActiveDocument)"
)
FreeCADGui.doCommand("solver.GeometricalNonlinearity = 'nonlinear'")
FreeCADGui.doCommand("solver.MaterialNonlinearity = 'nonlinear'")
FreeCADGui.doCommand("FemGui.getActiveAnalysis().addObject(solver)")
else:
FreeCADGui.doCommand(
"FemGui.getActiveAnalysis().addObject(ObjectsFem."
"makeSolverCalculixCcxTools(FreeCAD.ActiveDocument))"
)
FreeCAD.ActiveDocument.commitTransaction()
FreeCAD.ActiveDocument.recompute()
class _SolverCalculix(CommandManager):
"The FEM_SolverCalculix command definition"
def __init__(self):
super(_SolverCalculix, self).__init__()
self.resources = {
"Pixmap": "fem-solver-standard",
"MenuText": QtCore.QT_TRANSLATE_NOOP(
"FEM_SolverCalculiX", "Solver CalculiX (experimental)"
),
"Accel": "S, C",
"ToolTip": QtCore.QT_TRANSLATE_NOOP(
"FEM_SolverCalculiX",
"Creates a FEM solver CalculiX (experimental)"
)