/
Command.cpp
1606 lines (1276 loc) · 60.7 KB
/
Command.cpp
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) 2008 Jürgen Riegel (juergen.riegel@web.de) *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library 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 library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
# include <Standard_math.hxx>
# include <QApplication>
# include <QMessageBox>
# include <QAction>
#endif
#include <Inventor/nodes/SoEventCallback.h>
#include <Inventor/nodes/SoCamera.h>
#include <Inventor/events/SoMouseButtonEvent.h>
#include <App/Application.h>
#include <App/Document.h>
#include <App/DocumentObject.h>
#include <Gui/Application.h>
#include <Gui/Control.h>
#include <Gui/Command.h>
#include <Gui/MainWindow.h>
#include <Gui/FileDialog.h>
#include <Gui/Selection.h>
#include <Gui/SelectionFilter.h>
#include <Gui/Document.h>
#include <Gui/WaitCursor.h>
#include <Gui/View3DInventor.h>
#include <Gui/View3DInventorViewer.h>
#include <Gui/Utilities.h>
#include <Gui/Action.h>
#include <Gui/BitmapFactory.h>
#include <SMESH_Mesh.hxx>
#include <SMESHDS_Mesh.hxx>
#include <SMDSAbs_ElementType.hxx>
#include <Mod/Part/App/PartFeature.h>
#include <Mod/Fem/App/FemMeshObject.h>
#include <Mod/Fem/App/FemSetNodesObject.h>
#include <Mod/Fem/App/FemConstraint.h>
#include <Mod/Fem/App/FemAnalysis.h>
#include "ActiveAnalysisObserver.h"
#ifdef FC_USE_VTK
#include <Mod/Fem/App/FemPostPipeline.h>
#endif
using namespace std;
bool getConstraintPrerequisits(Fem::FemAnalysis **Analysis)
{
Fem::FemAnalysis* ActiveAnalysis = FemGui::ActiveAnalysisObserver::instance()->getActiveObject();
if (!ActiveAnalysis || !ActiveAnalysis->getTypeId().isDerivedFrom(Fem::FemAnalysis::getClassTypeId())){
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No active Analysis"),
QObject::tr("You need to create or activate a Analysis"));
return true;
}
*Analysis = static_cast<Fem::FemAnalysis*>(ActiveAnalysis);
// return with no error
return false;
}
//OvG: Visibility automation show parts and hide meshes on activation of a constraint
std::string gethideMeshShowPartStr(std::string showConstr="")
{
return "for amesh in App.activeDocument().Objects:\n\
if \""+showConstr+"\" == amesh.Name:\n\
amesh.ViewObject.Visibility = True\n\
elif \"Mesh\" in amesh.TypeId:\n\
aparttoshow = amesh.Name.replace(\"_Mesh\",\"\")\n\
for apart in App.activeDocument().Objects:\n\
if aparttoshow == apart.Name:\n\
apart.ViewObject.Visibility = True\n\
amesh.ViewObject.Visibility = False\n";
}
//=====================================================================================
DEF_STD_CMD_A(CmdFemCreateAnalysis);
CmdFemCreateAnalysis::CmdFemCreateAnalysis()
: Command("FEM_CreateAnalysis")
{
sAppModule = "Fem";
sGroup = QT_TR_NOOP("Fem");
sMenuText = QT_TR_NOOP("Create a FEM analysis");
sToolTipText = QT_TR_NOOP("Create a FEM analysis");
sWhatsThis = "FEM_CreateAnalysis";
sStatusTip = sToolTipText;
sPixmap = "fem-analysis";
}
void CmdFemCreateAnalysis::activated(int)
{
#ifndef FCWithNetgen
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Your FreeCAD is build without NETGEN support. Meshing will not work...."));
return;
#endif
std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx();
if (selection.size() != 1) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Select an edge, face or body. Only one body is allowed."));
return;
}
if (!selection[0].isObjectTypeOf(Part::Feature::getClassTypeId())){
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong object type"),
QObject::tr("Fillet works only on parts"));
return;
}
Part::Feature *base = static_cast<Part::Feature*>(selection[0].getObject());
std::string AnalysisName = getUniqueObjectName("FemAnalysis");
std::string MeshName = getUniqueObjectName((std::string(base->getNameInDocument()) +"_Mesh").c_str());
openCommand("Create FEM analysis");
doCommand(Doc,"App.activeDocument().addObject('Fem::FemAnalysis','%s')",AnalysisName.c_str());
doCommand(Doc,"App.activeDocument().addObject('Fem::FemMeshShapeNetgenObject','%s')",MeshName.c_str());
doCommand(Doc,"App.activeDocument().ActiveObject.Shape = App.activeDocument().%s",base->getNameInDocument());
doCommand(Doc,"App.activeDocument().%s.Member = App.activeDocument().%s",AnalysisName.c_str(),MeshName.c_str());
addModule(Gui,"FemGui");
doCommand(Gui,"FemGui.setActiveAnalysis(App.activeDocument().%s)",AnalysisName.c_str());
commitCommand();
updateActive();
}
bool CmdFemCreateAnalysis::isActive(void)
{
return !FemGui::ActiveAnalysisObserver::instance()->hasActiveObject();
}
//=====================================================================================
DEF_STD_CMD_A(CmdFemAddPart);
CmdFemAddPart::CmdFemAddPart()
: Command("FEM_FemAddPart")
{
sAppModule = "Fem";
sGroup = QT_TR_NOOP("Fem");
sMenuText = QT_TR_NOOP("Add a part to the Analysis");
sToolTipText = QT_TR_NOOP("Add a part to the Analysis");
sWhatsThis = "FEM_FemAddPart";
sStatusTip = sToolTipText;
sPixmap = "fem-add-fem-mesh";
}
void CmdFemAddPart::activated(int)
{
#ifndef FCWithNetgen
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Your FreeCAD is build without NETGEN support. Meshing will not work...."));
return;
#endif
std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx();
if (selection.size() != 1) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Select an edge, face or body. Only one body is allowed."));
return;
}
if (!selection[0].isObjectTypeOf(Part::Feature::getClassTypeId())){
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong object type"),
QObject::tr("Fillet works only on parts"));
return;
}
Part::Feature *base = static_cast<Part::Feature*>(selection[0].getObject());
std::string AnalysisName = getUniqueObjectName("FemAnalysis");
std::string MeshName = getUniqueObjectName((std::string(base->getNameInDocument()) +"_Mesh").c_str());
openCommand("Create FEM analysis");
doCommand(Doc,"App.activeDocument().addObject('Fem::FemAnalysis','%s')",AnalysisName.c_str());
doCommand(Doc,"App.activeDocument().addObject('Fem::FemMeshShapeNetgenObject','%s')",MeshName.c_str());
doCommand(Doc,"App.activeDocument().ActiveObject.Shape = App.activeDocument().%s",base->getNameInDocument());
doCommand(Doc,"App.activeDocument().%s.Member = App.activeDocument().%s",AnalysisName.c_str(),MeshName.c_str());
addModule(Gui,"FemGui");
doCommand(Gui,"FemGui.setActiveAnalysis(App.activeDocument().%s)",AnalysisName.c_str());
commitCommand();
updateActive();
}
bool CmdFemAddPart::isActive(void)
{
if (Gui::Control().activeDialog())
return false;
Base::Type type = Base::Type::fromName("Part::Feature");
return Gui::Selection().countObjectsOfType(type) > 0;
}
//=====================================================================================
DEF_STD_CMD_A(CmdFemCreateSolver);
CmdFemCreateSolver::CmdFemCreateSolver()
: Command("FEM_CreateSolver")
{
sAppModule = "Fem";
sGroup = QT_TR_NOOP("Fem");
sMenuText = QT_TR_NOOP("Add a solver to the Analysis");
sToolTipText = QT_TR_NOOP("Add a solver to the Analysis");
sWhatsThis = "FEM_CreateSolver";
sStatusTip = sToolTipText;
sPixmap = "fem-solver";
}
void CmdFemCreateSolver::activated(int)
{
#ifndef FCWithNetgen
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Your FreeCAD is build without NETGEN support. Meshing will not work...."));
return;
#endif
Fem::FemAnalysis *Analysis;
if(getConstraintPrerequisits(&Analysis))
return;
std::string FeatName = getUniqueObjectName("Solver");
openCommand("Create solver for FEM or CFD analysis");
doCommand(Doc,"App.activeDocument().addObject(\"Fem::FemSolverObject\",\"%s\")",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Member = App.activeDocument().%s.Member + [App.activeDocument().%s]",Analysis->getNameInDocument(),Analysis->getNameInDocument(),FeatName.c_str());
updateActive();
doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
}
bool CmdFemCreateSolver::isActive(void)
{
return hasActiveDocument();
}
//=====================================================================================
DEF_STD_CMD_A(CmdFemConstraintBearing);
CmdFemConstraintBearing::CmdFemConstraintBearing()
: Command("FEM_ConstraintBearing")
{
sAppModule = "Fem";
sGroup = QT_TR_NOOP("Fem");
sMenuText = QT_TR_NOOP("Constraint bearing");
sToolTipText = QT_TR_NOOP("Creates a FEM constraint for a bearing");
sWhatsThis = "FEM_ConstraintBearing";
sStatusTip = sToolTipText;
sPixmap = "fem-constraint-bearing";
}
void CmdFemConstraintBearing::activated(int)
{
Fem::FemAnalysis *Analysis;
if(getConstraintPrerequisits(&Analysis))
return;
std::string FeatName = getUniqueObjectName("FemConstraintBearing");
openCommand("Make FEM constraint for bearing");
doCommand(Doc,"App.activeDocument().addObject(\"Fem::ConstraintBearing\",\"%s\")",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Member = App.activeDocument().%s.Member + [App.activeDocument().%s]",Analysis->getNameInDocument(),Analysis->getNameInDocument(),FeatName.c_str());
doCommand(Doc,"%s",gethideMeshShowPartStr(FeatName).c_str()); //OvG: Hide meshes and show parts
updateActive();
doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
}
bool CmdFemConstraintBearing::isActive(void)
{
return FemGui::ActiveAnalysisObserver::instance()->hasActiveObject();
}
//=====================================================================================
DEF_STD_CMD_A(CmdFemConstraintFixed);
CmdFemConstraintFixed::CmdFemConstraintFixed()
: Command("FEM_ConstraintFixed")
{
sAppModule = "Fem";
sGroup = QT_TR_NOOP("Fem");
sMenuText = QT_TR_NOOP("Constraint fixed");
sToolTipText = QT_TR_NOOP("Creates a FEM constraint for a fixed geometric entity");
sWhatsThis = "FEM_ConstraintFixed";
sStatusTip = sToolTipText;
sPixmap = "fem-constraint-fixed";
}
void CmdFemConstraintFixed::activated(int)
{
Fem::FemAnalysis *Analysis;
if(getConstraintPrerequisits(&Analysis))
return;
std::string FeatName = getUniqueObjectName("FemConstraintFixed");
openCommand("Make FEM constraint fixed geometry");
doCommand(Doc,"App.activeDocument().addObject(\"Fem::ConstraintFixed\",\"%s\")",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Scale = 1",FeatName.c_str()); //OvG: set initial scale to 1
doCommand(Doc,"App.activeDocument().%s.Member = App.activeDocument().%s.Member + [App.activeDocument().%s]",Analysis->getNameInDocument(),Analysis->getNameInDocument(),FeatName.c_str());
doCommand(Doc,"%s",gethideMeshShowPartStr(FeatName).c_str()); //OvG: Hide meshes and show parts
updateActive();
doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
}
bool CmdFemConstraintFixed::isActive(void)
{
return FemGui::ActiveAnalysisObserver::instance()->hasActiveObject();
}
//=====================================================================================
DEF_STD_CMD_A(CmdFemConstraintPlaneRotation);
CmdFemConstraintPlaneRotation::CmdFemConstraintPlaneRotation()
: Command("FEM_ConstraintPlaneRotation")
{
sAppModule = "Fem";
sGroup = QT_TR_NOOP("Fem");
sMenuText = QT_TR_NOOP("Constraint plane rotation");
sToolTipText = QT_TR_NOOP("Creates a FEM constraint for plane rotation face");
sWhatsThis = "FEM_ConstraintPlaneRotation";
sStatusTip = sToolTipText;
sPixmap = "fem-constraint-planerotation";
}
void CmdFemConstraintPlaneRotation::activated(int)
{
Fem::FemAnalysis *Analysis;
if(getConstraintPrerequisits(&Analysis))
return;
std::string FeatName = getUniqueObjectName("FemConstraintPlaneRotation");
openCommand("Make FEM constraint Plane Rotation face");
doCommand(Doc,"App.activeDocument().addObject(\"Fem::ConstraintPlaneRotation\",\"%s\")",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Scale = 1",FeatName.c_str()); //OvG: set initial scale to 1
doCommand(Doc,"App.activeDocument().%s.Member = App.activeDocument().%s.Member + [App.activeDocument().%s]",Analysis->getNameInDocument(),Analysis->getNameInDocument(),FeatName.c_str());
doCommand(Doc,"%s",gethideMeshShowPartStr(FeatName).c_str()); //OvG: Hide meshes and show parts
updateActive();
doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
}
bool CmdFemConstraintPlaneRotation::isActive(void)
{
return FemGui::ActiveAnalysisObserver::instance()->hasActiveObject();
}
//=====================================================================================
DEF_STD_CMD_A(CmdFemConstraintContact);
CmdFemConstraintContact::CmdFemConstraintContact()
: Command("FEM_ConstraintContact")
{
sAppModule = "Fem";
sGroup = QT_TR_NOOP("Fem");
sMenuText = QT_TR_NOOP("Constraint contact ");
sToolTipText = QT_TR_NOOP("Creates a FEM constraint for contact between faces");
sWhatsThis = "FEM_ConstraintContact";
sStatusTip = sToolTipText;
sPixmap = "fem-constraint-contact";
}
void CmdFemConstraintContact::activated(int)
{
Fem::FemAnalysis *Analysis;
if(getConstraintPrerequisits(&Analysis))
return;
std::string FeatName = getUniqueObjectName("FemConstraintContact");
openCommand("Make FEM constraint contact on face");
doCommand(Doc,"App.activeDocument().addObject(\"Fem::ConstraintContact\",\"%s\")",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Slope = 1000000.00",FeatName.c_str()); //OvG: set default not equal to 0
doCommand(Doc,"App.activeDocument().%s.Friction = 0.0",FeatName.c_str()); //OvG: set default not equal to 0
doCommand(Doc,"App.activeDocument().%s.Scale = 1",FeatName.c_str()); //OvG: set initial scale to 1
doCommand(Doc,"App.activeDocument().%s.Member = App.activeDocument().%s.Member + [App.activeDocument().%s]",
Analysis->getNameInDocument(),Analysis->getNameInDocument(),FeatName.c_str());
doCommand(Doc,"%s",gethideMeshShowPartStr(FeatName).c_str()); //OvG: Hide meshes and show parts
updateActive();
doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
}
bool CmdFemConstraintContact::isActive(void)
{
return FemGui::ActiveAnalysisObserver::instance()->hasActiveObject();
}
//=====================================================================================
DEF_STD_CMD_A(CmdFemConstraintTransform);
CmdFemConstraintTransform::CmdFemConstraintTransform()
: Command("FEM_ConstraintTransform")
{
sAppModule = "Fem";
sGroup = QT_TR_NOOP("Fem");
sMenuText = QT_TR_NOOP("Create FEM transform constraint");
sToolTipText = QT_TR_NOOP("Create FEM constraint for transforming a face");
sWhatsThis = "FEM_ConstraintTransform";
sStatusTip = sToolTipText;
sPixmap = "fem-constraint-transform";
}
void CmdFemConstraintTransform::activated(int)
{
Fem::FemAnalysis *Analysis;
if(getConstraintPrerequisits(&Analysis))
return;
std::string FeatName = getUniqueObjectName("FemConstraintTransform");
openCommand("Make FEM constraint transform on face");
doCommand(Doc,"App.activeDocument().addObject(\"Fem::ConstraintTransform\",\"%s\")",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.X_rot = 0.0",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Y_rot = 0.0",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Z_rot = 0.0",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Scale = 1",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Member = App.activeDocument().%s.Member + [App.activeDocument().%s]",
Analysis->getNameInDocument(),Analysis->getNameInDocument(),FeatName.c_str());
doCommand(Doc,"%s",gethideMeshShowPartStr(FeatName).c_str()); //OvG: Hide meshes and show parts
updateActive();
doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
}
bool CmdFemConstraintTransform::isActive(void)
{
return FemGui::ActiveAnalysisObserver::instance()->hasActiveObject();
}
//=====================================================================================
DEF_STD_CMD_A(CmdFemConstraintHeatflux);
CmdFemConstraintHeatflux::CmdFemConstraintHeatflux()
: Command("FEM_ConstraintHeatflux")
{
sAppModule = "Fem";
sGroup = QT_TR_NOOP("Fem");
sMenuText = QT_TR_NOOP("Constraint heatflux ");
sToolTipText = QT_TR_NOOP("Creates a FEM constraint for a heatflux acting on a face");
sWhatsThis = "FEM_ConstraintHeatflux";
sStatusTip = sToolTipText;
sPixmap = "fem-constraint-heatflux";
}
void CmdFemConstraintHeatflux::activated(int)
{
Fem::FemAnalysis *Analysis;
if(getConstraintPrerequisits(&Analysis))
return;
std::string FeatName = getUniqueObjectName("FemConstraintHeatflux");
openCommand("Make FEM constraint heatflux on face");
doCommand(Doc,"App.activeDocument().addObject(\"Fem::ConstraintHeatflux\",\"%s\")",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.AmbientTemp = 300.0",FeatName.c_str()); //OvG: set default not equal to 0
doCommand(Doc,"App.activeDocument().%s.FilmCoef = 10.0",FeatName.c_str()); //OvG: set default not equal to 0
doCommand(Doc,"App.activeDocument().%s.Scale = 1",FeatName.c_str()); //OvG: set initial scale to 1
doCommand(Doc,"App.activeDocument().%s.Member = App.activeDocument().%s.Member + [App.activeDocument().%s]",
Analysis->getNameInDocument(),Analysis->getNameInDocument(),FeatName.c_str());
doCommand(Doc,"%s",gethideMeshShowPartStr().c_str()); //OvG: Hide meshes and show parts
updateActive();
doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
}
bool CmdFemConstraintHeatflux::isActive(void)
{
return FemGui::ActiveAnalysisObserver::instance()->hasActiveObject();
}
//=====================================================================================
DEF_STD_CMD_A(CmdFemConstraintForce);
CmdFemConstraintForce::CmdFemConstraintForce()
: Command("FEM_ConstraintForce")
{
sAppModule = "Fem";
sGroup = QT_TR_NOOP("Fem");
sMenuText = QT_TR_NOOP("Constraint force");
sToolTipText = QT_TR_NOOP("Creates a FEM constraint for a force acting on a geometric entity");
sWhatsThis = "FEM_ConstraintForce";
sStatusTip = sToolTipText;
sPixmap = "fem-constraint-force";
}
void CmdFemConstraintForce::activated(int)
{
Fem::FemAnalysis *Analysis;
if(getConstraintPrerequisits(&Analysis))
return;
std::string FeatName = getUniqueObjectName("FemConstraintForce");
openCommand("Make FEM constraint force on geometry");
doCommand(Doc,"App.activeDocument().addObject(\"Fem::ConstraintForce\",\"%s\")",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Force = 1.0",FeatName.c_str()); //OvG: set default not equal to 0
doCommand(Doc,"App.activeDocument().%s.Reversed = False",FeatName.c_str()); //OvG: set default to False
doCommand(Doc,"App.activeDocument().%s.Scale = 1",FeatName.c_str()); //OvG: set initial scale to 1
doCommand(Doc,"App.activeDocument().%s.Member = App.activeDocument().%s.Member + [App.activeDocument().%s]",Analysis->getNameInDocument(),Analysis->getNameInDocument(),FeatName.c_str());
doCommand(Doc,"%s",gethideMeshShowPartStr(FeatName).c_str()); //OvG: Hide meshes and show parts
updateActive();
doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
}
bool CmdFemConstraintForce::isActive(void)
{
return FemGui::ActiveAnalysisObserver::instance()->hasActiveObject();
}
//=====================================================================================
DEF_STD_CMD_A(CmdFemConstraintFluidBoundary);
CmdFemConstraintFluidBoundary::CmdFemConstraintFluidBoundary()
: Command("FEM_ConstraintFluidBoundary")
{
sAppModule = "Fem";
sGroup = QT_TR_NOOP("Fem");
sMenuText = QT_TR_NOOP("Create fluid boundary condition");
sToolTipText = QT_TR_NOOP("Create fluid boundary condition on face entity for Computional Fluid Dynamics");
sWhatsThis = "FEM_ConstraintFluidBoundary";
sStatusTip = sToolTipText;
sPixmap = "fem-constraint-fluid-boundary";
}
void CmdFemConstraintFluidBoundary::activated(int)
{
Fem::FemAnalysis *Analysis;
if(getConstraintPrerequisits(&Analysis))
return;
std::string FeatName = getUniqueObjectName("FluidBoundary");
openCommand("Create fluid boundary condition");
doCommand(Doc,"App.activeDocument().addObject(\"Fem::ConstraintFluidBoundary\",\"%s\")",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Scale = 1",FeatName.c_str()); //OvG: set initial scale to 1
//BoundaryValue is already the default value, zero is acceptable
doCommand(Doc,"App.activeDocument().%s.Member = App.activeDocument().%s.Member + [App.activeDocument().%s]",
Analysis->getNameInDocument(),Analysis->getNameInDocument(),FeatName.c_str());
doCommand(Doc,"%s",gethideMeshShowPartStr(FeatName).c_str()); //OvG: Hide meshes and show parts
updateActive();
doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
}
bool CmdFemConstraintFluidBoundary::isActive(void)
{
return FemGui::ActiveAnalysisObserver::instance()->hasActiveObject();
}
//=====================================================================================
DEF_STD_CMD_A(CmdFemConstraintPressure);
CmdFemConstraintPressure::CmdFemConstraintPressure()
: Command("FEM_ConstraintPressure")
{
sAppModule = "Fem";
sGroup = QT_TR_NOOP("Fem");
sMenuText = QT_TR_NOOP("Constraint pressure");
sToolTipText = QT_TR_NOOP("Creates a FEM constraint for a pressure acting on a face");
sWhatsThis = "FEM_ConstraintPressure";
sStatusTip = sToolTipText;
sPixmap = "fem-constraint-pressure";
}
void CmdFemConstraintPressure::activated(int)
{
Fem::FemAnalysis *Analysis;
if(getConstraintPrerequisits(&Analysis))
return;
std::string FeatName = getUniqueObjectName("FemConstraintPressure");
openCommand("Make FEM constraint pressure on face");
doCommand(Doc,"App.activeDocument().addObject(\"Fem::ConstraintPressure\",\"%s\")",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Pressure = 1000.0",FeatName.c_str()); //OvG: set default not equal to 0
doCommand(Doc,"App.activeDocument().%s.Reversed = False",FeatName.c_str()); //OvG: set default to False
doCommand(Doc,"App.activeDocument().%s.Scale = 1",FeatName.c_str()); //OvG: set initial scale to 1
doCommand(Doc,"App.activeDocument().%s.Member = App.activeDocument().%s.Member + [App.activeDocument().%s]",
Analysis->getNameInDocument(),Analysis->getNameInDocument(),FeatName.c_str());
doCommand(Doc,"%s",gethideMeshShowPartStr(FeatName).c_str()); //OvG: Hide meshes and show parts
updateActive();
doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
}
bool CmdFemConstraintPressure::isActive(void)
{
return FemGui::ActiveAnalysisObserver::instance()->hasActiveObject();
}
//=====================================================================================
DEF_STD_CMD_A(CmdFemConstraintGear);
CmdFemConstraintGear::CmdFemConstraintGear()
: Command("FEM_ConstraintGear")
{
sAppModule = "Fem";
sGroup = QT_TR_NOOP("Fem");
sMenuText = QT_TR_NOOP("Constraint gear");
sToolTipText = QT_TR_NOOP("Creates a FEM constraint for a gear");
sWhatsThis = "FEM_ConstraintGear";
sStatusTip = sToolTipText;
sPixmap = "fem-constraint-gear";
}
void CmdFemConstraintGear::activated(int)
{
Fem::FemAnalysis *Analysis;
if(getConstraintPrerequisits(&Analysis))
return;
std::string FeatName = getUniqueObjectName("FemConstraintGear");
openCommand("Make FEM constraint for gear");
doCommand(Doc,"App.activeDocument().addObject(\"Fem::ConstraintGear\",\"%s\")",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Diameter = 100.0",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Member = App.activeDocument().%s.Member + [App.activeDocument().%s]",Analysis->getNameInDocument(),Analysis->getNameInDocument(),FeatName.c_str());
doCommand(Doc,"%s",gethideMeshShowPartStr(FeatName).c_str()); //OvG: Hide meshes and show parts
updateActive();
doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
}
bool CmdFemConstraintGear::isActive(void)
{
return FemGui::ActiveAnalysisObserver::instance()->hasActiveObject();
}
//=====================================================================================
DEF_STD_CMD_A(CmdFemConstraintPulley);
CmdFemConstraintPulley::CmdFemConstraintPulley()
: Command("FEM_ConstraintPulley")
{
sAppModule = "Fem";
sGroup = QT_TR_NOOP("Fem");
sMenuText = QT_TR_NOOP("Constraint pulley");
sToolTipText = QT_TR_NOOP("Creates a FEM constraint for a pulley");
sWhatsThis = "FEM_ConstraintPulley";
sStatusTip = sToolTipText;
sPixmap = "fem-constraint-pulley";
}
void CmdFemConstraintPulley::activated(int)
{
Fem::FemAnalysis *Analysis;
if(getConstraintPrerequisits(&Analysis))
return;
std::string FeatName = getUniqueObjectName("FemConstraintPulley");
openCommand("Make FEM constraint for pulley");
doCommand(Doc,"App.activeDocument().addObject(\"Fem::ConstraintPulley\",\"%s\")",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Diameter = 300.0",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.OtherDiameter = 100.0",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.CenterDistance = 500.0",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Force = 100.0",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.TensionForce = 100.0",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Member = App.activeDocument().%s.Member + [App.activeDocument().%s]",Analysis->getNameInDocument(),Analysis->getNameInDocument(),FeatName.c_str());
doCommand(Doc,"%s",gethideMeshShowPartStr(FeatName).c_str()); //OvG: Hide meshes and show parts
updateActive();
doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
}
bool CmdFemConstraintPulley::isActive(void)
{
return FemGui::ActiveAnalysisObserver::instance()->hasActiveObject();
}
//=====================================================================================
DEF_STD_CMD_A(CmdFemConstraintDisplacement);
CmdFemConstraintDisplacement::CmdFemConstraintDisplacement()
: Command("FEM_ConstraintDisplacement")
{
sAppModule = "Fem";
sGroup = QT_TR_NOOP("Fem");
sMenuText = QT_TR_NOOP("Constraint displacement");
sToolTipText = QT_TR_NOOP("Creates a FEM constraint for a displacement acting on a geometric entity");
sWhatsThis = "FEM_ConstraintDisplacement";
sStatusTip = sToolTipText;
sPixmap = "fem-constraint-displacement";
}
void CmdFemConstraintDisplacement::activated(int)
{
Fem::FemAnalysis *Analysis;
if(getConstraintPrerequisits(&Analysis))
return;
std::string FeatName = getUniqueObjectName("FemConstraintDisplacement");
openCommand("Make FEM constraint displacement on face");
doCommand(Doc,"App.activeDocument().addObject(\"Fem::ConstraintDisplacement\",\"%s\")",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Scale = 1",FeatName.c_str()); //OvG: set initial scale to 1
doCommand(Doc,"App.activeDocument().%s.Member = App.activeDocument().%s.Member + [App.activeDocument().%s]",
Analysis->getNameInDocument(),Analysis->getNameInDocument(),FeatName.c_str());
doCommand(Doc,"%s",gethideMeshShowPartStr(FeatName).c_str()); //OvG: Hide meshes and show parts
updateActive();
doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
}
bool CmdFemConstraintDisplacement::isActive(void)
{
return FemGui::ActiveAnalysisObserver::instance()->hasActiveObject();
}
//=====================================================================================
DEF_STD_CMD_A(CmdFemConstraintTemperature);
CmdFemConstraintTemperature::CmdFemConstraintTemperature()
: Command("FEM_ConstraintTemperature")
{
sAppModule = "Fem";
sGroup = QT_TR_NOOP("Fem");
sMenuText = QT_TR_NOOP("Constraint temperature ");
sToolTipText = QT_TR_NOOP("Creates a FEM constraint for a temperature/concentrated heat flux acting on a face");
sWhatsThis = "FEM_ConstraintTemperature";
sStatusTip = sToolTipText;
sPixmap = "fem-constraint-temperature";
}
void CmdFemConstraintTemperature::activated(int)
{
Fem::FemAnalysis *Analysis;
if(getConstraintPrerequisits(&Analysis))
return;
std::string FeatName = getUniqueObjectName("FemConstraintTemperature");
openCommand("Make FEM constraint temperature on face");
doCommand(Doc,"App.activeDocument().addObject(\"Fem::ConstraintTemperature\",\"%s\")",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Scale = 1",FeatName.c_str()); //OvG: set initial scale to 1
doCommand(Doc,"App.activeDocument().%s.Member = App.activeDocument().%s.Member + [App.activeDocument().%s]",
Analysis->getNameInDocument(),Analysis->getNameInDocument(),FeatName.c_str());
doCommand(Doc,"%s",gethideMeshShowPartStr().c_str()); //OvG: Hide meshes and show parts
updateActive();
doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
}
bool CmdFemConstraintTemperature::isActive(void)
{
return FemGui::ActiveAnalysisObserver::instance()->hasActiveObject();
}
//=====================================================================================
DEF_STD_CMD_A(CmdFemConstraintInitialTemperature);
CmdFemConstraintInitialTemperature::CmdFemConstraintInitialTemperature()
: Command("FEM_ConstraintInitialTemperature")
{
sAppModule = "Fem";
sGroup = QT_TR_NOOP("Fem");
sMenuText = QT_TR_NOOP("Constraint initial temperature");
sToolTipText = QT_TR_NOOP("Creates a FEM constraint for initial temperature acting on a body");
sWhatsThis = "FEM_ConstraintInitialTemperature";
sStatusTip = sToolTipText;
sPixmap = "fem-constraint-InitialTemperature";
}
void CmdFemConstraintInitialTemperature::activated(int)
{
Fem::FemAnalysis *Analysis;
if(getConstraintPrerequisits(&Analysis))
return;
std::string FeatName = getUniqueObjectName("FemConstraintInitialTemperature");
openCommand("Make FEM constraint initial temperature on body");
doCommand(Doc,"App.activeDocument().addObject(\"Fem::ConstraintInitialTemperature\",\"%s\")",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Scale = 1",FeatName.c_str()); //OvG: set initial scale to 1
doCommand(Doc,"App.activeDocument().%s.Member = App.activeDocument().%s.Member + [App.activeDocument().%s]",
Analysis->getNameInDocument(),Analysis->getNameInDocument(),FeatName.c_str());
doCommand(Doc,"%s",gethideMeshShowPartStr().c_str()); //OvG: Hide meshes and show parts
updateActive();
doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
}
bool CmdFemConstraintInitialTemperature::isActive(void)
{
return FemGui::ActiveAnalysisObserver::instance()->hasActiveObject();
}
// #####################################################################################################
DEF_STD_CMD_A(CmdFemDefineNodesSet);
void DefineNodesCallback(void * ud, SoEventCallback * n)
{
Fem::FemAnalysis *Analysis;
if(getConstraintPrerequisits(&Analysis))
return;
// show the wait cursor because this could take quite some time
Gui::WaitCursor wc;
// When this callback function is invoked we must in either case leave the edit mode
Gui::View3DInventorViewer* view = reinterpret_cast<Gui::View3DInventorViewer*>(n->getUserData());
view->setEditing(false);
view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), DefineNodesCallback,ud);
n->setHandled();
SbBool clip_inner;
std::vector<SbVec2f> clPoly = view->getGLPolygon(&clip_inner);
if (clPoly.size() < 3)
return;
if (clPoly.front() != clPoly.back())
clPoly.push_back(clPoly.front());
SoCamera* cam = view->getSoRenderManager()->getCamera();
SbViewVolume vv = cam->getViewVolume();
Gui::ViewVolumeProjection proj(vv);
Base::Polygon2d polygon;
for (std::vector<SbVec2f>::const_iterator it = clPoly.begin(); it != clPoly.end(); ++it)
polygon.Add(Base::Vector2d((*it)[0],(*it)[1]));
std::vector<App::DocumentObject*> docObj = Gui::Selection().getObjectsOfType(Fem::FemMeshObject::getClassTypeId());
if(docObj.size() !=1)
return;
const SMESHDS_Mesh* data = const_cast<SMESH_Mesh*>(static_cast<Fem::FemMeshObject*>(docObj[0])->FemMesh.getValue().getSMesh())->GetMeshDS();
SMDS_NodeIteratorPtr aNodeIter = data->nodesIterator();
Base::Vector3f pt2d;
std::set<int> IntSet;
while (aNodeIter->more()) {
const SMDS_MeshNode* aNode = aNodeIter->next();
Base::Vector3f vec(aNode->X(),aNode->Y(),aNode->Z());
pt2d = proj(vec);
if (polygon.Contains(Base::Vector2d(pt2d.x, pt2d.y)) == true)
IntSet.insert(aNode->GetID());
}
std::stringstream set;
set << "[";
for(std::set<int>::const_iterator it=IntSet.begin();it!=IntSet.end();++it)
if(it==IntSet.begin())
set << *it ;
else
set << "," << *it ;
set << "]";
Gui::Command::openCommand("Place robot");
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.addObject('Fem::FemSetNodesObject','NodeSet')");
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.ActiveObject.Nodes = %s",set.str().c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.Member = App.activeDocument().%s.Member + [App.activeDocument().NodeSet]",Analysis->getNameInDocument(),Analysis->getNameInDocument());
////Gui::Command::updateActive();
Gui::Command::commitCommand();
//std::vector<Gui::ViewProvider*> views = view->getViewProvidersOfType(ViewProviderMesh::getClassTypeId());
//if (!views.empty()) {
// Gui::Application::Instance->activeDocument()->openCommand("Cut");
// for (std::vector<Gui::ViewProvider*>::iterator it = views.begin(); it != views.end(); ++it) {
// ViewProviderMesh* that = static_cast<ViewProviderMesh*>(*it);
// if (that->getEditingMode() > -1) {
// that->finishEditing();
// that->cutMesh(clPoly, *view, clip_inner);
// }
// }
// Gui::Application::Instance->activeDocument()->commitCommand();
// view->render();
//}
}
CmdFemDefineNodesSet::CmdFemDefineNodesSet()
: Command("FEM_DefineNodesSet")
{
sAppModule = "Fem";
sGroup = QT_TR_NOOP("Fem");
sMenuText = QT_TR_NOOP("Create node set by Poly");
sToolTipText = QT_TR_NOOP("Create node set by Poly");
sWhatsThis = "Create node set by Poly";
sStatusTip = QT_TR_NOOP("Create node set by Poly");
sPixmap = "fem-femmesh-create-node-by-poly";
}
void CmdFemDefineNodesSet::activated(int)
{
std::vector<App::DocumentObject*> docObj = Gui::Selection().getObjectsOfType(Fem::FemMeshObject::getClassTypeId());
for (std::vector<App::DocumentObject*>::iterator it = docObj.begin(); it != docObj.end(); ++it) {
if (it == docObj.begin()) {
Gui::Document* doc = getActiveGuiDocument();
Gui::MDIView* view = doc->getActiveView();
if (view->getTypeId().isDerivedFrom(Gui::View3DInventor::getClassTypeId())) {
Gui::View3DInventorViewer* viewer = ((Gui::View3DInventor*)view)->getViewer();
viewer->setEditing(true);
viewer->startSelection(Gui::View3DInventorViewer::Clip);
viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(), DefineNodesCallback);
}
else {
return;
}
}
//Gui::ViewProvider* pVP = getActiveGuiDocument()->getViewProvider(*it);