1
/***************************************************************************
2
* Copyright (c) Jļæ½rgen Riegel (juergen.riegel@web.de) 2002 *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 59 Temple Place, *
19
* Suite 330, Boston, MA 02111-1307, USA *
21
***************************************************************************/
24
#include "PreCompiled.h"
27
# include <qfileinfo.h>
28
# include <qlineedit.h>
29
# include <Inventor/events/SoMouseButtonEvent.h>
32
#include <Base/Exception.h>
33
#include <App/Document.h>
34
#include <Gui/Application.h>
35
#include <Gui/BitmapFactory.h>
36
#include <Gui/Command.h>
37
#include <Gui/Document.h>
38
#include <Gui/FileDialog.h>
39
#include <Gui/MainWindow.h>
40
#include <Gui/Selection.h>
41
#include <Gui/View3DInventor.h>
42
#include <Gui/View3DInventorViewer.h>
44
#include <BRepPrimAPI_MakeBox.hxx>
45
#include <TopoDS_Shape.hxx>
47
#include "../App/PartFeature.h"
48
#include "DlgPartImportStepImp.h"
49
#include "DlgBooleanOperation.h"
50
#include "DlgExtrusion.h"
51
#include "DlgFilletEdges.h"
52
#include "DlgPrimitives.h"
53
#include "ViewProvider.h"
56
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
58
//===========================================================================
60
//===========================================================================
61
DEF_STD_CMD(CmdPartPickCurveNet);
63
CmdPartPickCurveNet::CmdPartPickCurveNet()
64
:Command("Part_PickCurveNet")
67
sGroup = QT_TR_NOOP("Part");
68
sMenuText = QT_TR_NOOP("Pick curve network");
69
sToolTipText = QT_TR_NOOP("Pick a curve network");
70
sWhatsThis = sToolTipText;
71
sStatusTip = sToolTipText;
76
void CmdPartPickCurveNet::activated(int iMsg)
81
//===========================================================================
83
//===========================================================================
84
DEF_STD_CMD(CmdPartNewDoc);
86
CmdPartNewDoc::CmdPartNewDoc()
87
:Command("Part_NewDoc")
91
sMenuText = "New document";
92
sToolTipText = "Create an empty part document";
93
sWhatsThis = sToolTipText;
94
sStatusTip = sToolTipText;
99
void CmdPartNewDoc::activated(int iMsg)
101
doCommand(Doc,"d = App.New()");
105
//===========================================================================
107
//===========================================================================
108
DEF_STD_CMD_A(CmdPartBox2);
110
CmdPartBox2::CmdPartBox2()
111
:Command("Part_Box2")
114
sGroup = QT_TR_NOOP("Part");
115
sMenuText = QT_TR_NOOP("Box fix 1");
116
sToolTipText = QT_TR_NOOP("Create a Box feature without dialog");
117
sWhatsThis = "Part_Box2";
118
sStatusTip = sToolTipText;
119
sPixmap = "Part_Box";
124
void CmdPartBox2::activated(int iMsg)
126
openCommand("Part Box Create");
127
doCommand(Doc,"from FreeCAD import Base");
128
doCommand(Doc,"import Part");
129
doCommand(Doc,"__fb__ = App.ActiveDocument.addObject(\"Part::Box\",\"PartBox\")");
130
doCommand(Doc,"__fb__.Location = Base.Vector(0.0,0.0,0.0)");
131
doCommand(Doc,"__fb__.Length = 100.0");
132
doCommand(Doc,"__fb__.Width = 100.0");
133
doCommand(Doc,"__fb__.Height = 100.0");
134
doCommand(Doc,"del __fb__");
139
bool CmdPartBox2::isActive(void)
141
if (getActiveGuiDocument())
147
//===========================================================================
149
//===========================================================================
150
DEF_STD_CMD_A(CmdPartBox3);
152
CmdPartBox3::CmdPartBox3()
153
:Command("Part_Box3")
156
sGroup = QT_TR_NOOP("Part");
157
sMenuText = QT_TR_NOOP("Box fix 2");
158
sToolTipText = QT_TR_NOOP("Create a box feature without dialog");
159
sWhatsThis = "Part_Box3";
160
sStatusTip = sToolTipText;
161
sPixmap = "Part_Box";
165
void CmdPartBox3::activated(int iMsg)
167
openCommand("Part Box Create");
168
doCommand(Doc,"from FreeCAD import Base");
169
doCommand(Doc,"import Part");
170
doCommand(Doc,"__fb__ = App.ActiveDocument.addObject(\"Part::Box\",\"PartBox\")");
171
doCommand(Doc,"__fb__.Location = Base.Vector(50.0,50.0,50.0)");
172
doCommand(Doc,"__fb__.Length = 100.0");
173
doCommand(Doc,"__fb__.Width = 100.0");
174
doCommand(Doc,"__fb__.Height = 100.0");
175
doCommand(Doc,"del __fb__");
180
bool CmdPartBox3::isActive(void)
182
if (getActiveGuiDocument())
188
//===========================================================================
190
//===========================================================================
191
DEF_STD_CMD_A(CmdPartPrimitives);
193
CmdPartPrimitives::CmdPartPrimitives()
194
:Command("Part_Primitives")
197
sGroup = QT_TR_NOOP("Part");
198
sMenuText = QT_TR_NOOP("Create primitives...");
199
sToolTipText = QT_TR_NOOP("Creation of parametrized geometric primitives");
200
sWhatsThis = "Part_Primitives";
201
sStatusTip = sToolTipText;
202
//sPixmap = "Part_Box";
206
void CmdPartPrimitives::activated(int iMsg)
208
static QPointer<QDialog> dlg = 0;
210
dlg = new PartGui::DlgPrimitives(Gui::getMainWindow());
211
dlg->setAttribute(Qt::WA_DeleteOnClose);
215
bool CmdPartPrimitives::isActive(void)
217
return hasActiveDocument();
220
//===========================================================================
222
//===========================================================================
223
DEF_STD_CMD_A(CmdPartCut);
225
CmdPartCut::CmdPartCut()
229
sGroup = QT_TR_NOOP("Part");
230
sMenuText = QT_TR_NOOP("Cut");
231
sToolTipText = QT_TR_NOOP("Create a Cut feature");
232
sWhatsThis = "Part_Cut";
233
sStatusTip = sToolTipText;
234
sPixmap = "Part_Box";
239
void CmdPartCut::activated(int iMsg)
241
unsigned int n = getSelection().countObjectsOfType(Part::Feature::getClassTypeId());
243
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
244
QObject::tr("Select two shapes please."));
248
std::string FeatName = getUniqueObjectName("Cut");
250
std::vector<Gui::SelectionSingleton::SelObj> Sel = getSelection().getSelection();
252
openCommand("Part Cut");
253
doCommand(Doc,"App.activeDocument().addObject(\"Part::Cut\",\"%s\")",FeatName.c_str());
254
doCommand(Doc,"App.activeDocument().%s.Base = App.activeDocument().%s",FeatName.c_str(),Sel[0].FeatName);
255
doCommand(Doc,"App.activeDocument().%s.Tool = App.activeDocument().%s",FeatName.c_str(),Sel[1].FeatName);
256
doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",Sel[0].FeatName);
257
doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",Sel[1].FeatName);
262
bool CmdPartCut::isActive(void)
264
return getSelection().countObjectsOfType(Part::Feature::getClassTypeId())==2;
267
//===========================================================================
269
//===========================================================================
270
DEF_STD_CMD_A(CmdPartCommon);
272
CmdPartCommon::CmdPartCommon()
273
:Command("Part_Common")
276
sGroup = QT_TR_NOOP("Part");
277
sMenuText = QT_TR_NOOP("Intersection");
278
sToolTipText = QT_TR_NOOP("Intersection of two shapes");
279
sWhatsThis = "Part_Common";
280
sStatusTip = sToolTipText;
281
sPixmap = "Part_Box";
285
void CmdPartCommon::activated(int iMsg)
287
unsigned int n = getSelection().countObjectsOfType(Part::Feature::getClassTypeId());
289
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
290
QObject::tr("Select two shapes please."));
294
std::string FeatName = getUniqueObjectName("Common");
296
std::vector<Gui::SelectionSingleton::SelObj> Sel = getSelection().getSelection();
298
openCommand("Common");
299
doCommand(Doc,"App.activeDocument().addObject(\"Part::Common\",\"%s\")",FeatName.c_str());
300
doCommand(Doc,"App.activeDocument().%s.Base = App.activeDocument().%s",FeatName.c_str(),Sel[0].FeatName);
301
doCommand(Doc,"App.activeDocument().%s.Tool = App.activeDocument().%s",FeatName.c_str(),Sel[1].FeatName);
302
doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",Sel[0].FeatName);
303
doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",Sel[1].FeatName);
308
bool CmdPartCommon::isActive(void)
310
return getSelection().countObjectsOfType(Part::Feature::getClassTypeId())==2;
313
//===========================================================================
315
//===========================================================================
316
DEF_STD_CMD_A(CmdPartFuse);
318
CmdPartFuse::CmdPartFuse()
319
:Command("Part_Fuse")
322
sGroup = QT_TR_NOOP("Part");
323
sMenuText = QT_TR_NOOP("Union");
324
sToolTipText = QT_TR_NOOP("Make union of two shapes");
325
sWhatsThis = "Part_Fuse";
326
sStatusTip = sToolTipText;
327
sPixmap = "Part_Box";
332
void CmdPartFuse::activated(int iMsg)
334
unsigned int n = getSelection().countObjectsOfType(Part::Feature::getClassTypeId());
336
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
337
QObject::tr("Select two shapes please."));
341
std::string FeatName = getUniqueObjectName("Fusion");
343
std::vector<Gui::SelectionSingleton::SelObj> Sel = getSelection().getSelection();
345
openCommand("Fusion");
346
doCommand(Doc,"App.activeDocument().addObject(\"Part::Fuse\",\"%s\")",FeatName.c_str());
347
doCommand(Doc,"App.activeDocument().%s.Base = App.activeDocument().%s",FeatName.c_str(),Sel[0].FeatName);
348
doCommand(Doc,"App.activeDocument().%s.Tool = App.activeDocument().%s",FeatName.c_str(),Sel[1].FeatName);
349
doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",Sel[0].FeatName);
350
doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",Sel[1].FeatName);
355
bool CmdPartFuse::isActive(void)
357
return getSelection().countObjectsOfType(Part::Feature::getClassTypeId())==2;
360
//===========================================================================
362
//===========================================================================
363
DEF_STD_CMD_A(CmdPartSection);
365
CmdPartSection::CmdPartSection()
366
:Command("Part_Section")
369
sGroup = QT_TR_NOOP("Part");
370
sMenuText = QT_TR_NOOP("Section");
371
sToolTipText = QT_TR_NOOP("Make section of two shapes");
372
sWhatsThis = "Part_Section";
373
sStatusTip = sToolTipText;
374
sPixmap = "Part_Box";
379
void CmdPartSection::activated(int iMsg)
381
unsigned int n = getSelection().countObjectsOfType(Part::Feature::getClassTypeId());
383
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
384
QObject::tr("Select two shapes please."));
388
std::string FeatName = getUniqueObjectName("Section");
390
std::vector<Gui::SelectionSingleton::SelObj> Sel = getSelection().getSelection();
392
openCommand("Section");
393
doCommand(Doc,"App.activeDocument().addObject(\"Part::Section\",\"%s\")",FeatName.c_str());
394
doCommand(Doc,"App.activeDocument().%s.Base = App.activeDocument().%s",FeatName.c_str(),Sel[0].FeatName);
395
doCommand(Doc,"App.activeDocument().%s.Tool = App.activeDocument().%s",FeatName.c_str(),Sel[1].FeatName);
396
doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",Sel[0].FeatName);
397
doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",Sel[1].FeatName);
402
bool CmdPartSection::isActive(void)
404
return getSelection().countObjectsOfType(Part::Feature::getClassTypeId())==2;
407
//===========================================================================
409
//===========================================================================
410
DEF_STD_CMD_A(CmdPartImport);
412
CmdPartImport::CmdPartImport()
413
:Command("Part_Import")
416
sGroup = QT_TR_NOOP("Part");
417
sMenuText = QT_TR_NOOP("Import CAD...");
418
sToolTipText = QT_TR_NOOP("Imports a CAD file");
419
sWhatsThis = "Part_Import";
420
sStatusTip = sToolTipText;
421
sPixmap = "Part_Box";
426
void CmdPartImport::activated(int iMsg)
429
filter << QObject::tr("All CAD Files (*.stp *.step *.igs *.iges *.brp *.brep)");
430
filter << QObject::tr("STEP (*.stp *.step)");
431
filter << QObject::tr("IGES (*.igs *.iges)");
432
filter << QObject::tr("BREP (*.brp *.brep)");
433
filter << QObject::tr("All Files (*.*)");
435
QString fn = Gui::FileDialog::getOpenFileName(Gui::getMainWindow(), QString(), QString(), filter.join(QLatin1String(";;")));
437
App::Document* pDoc = getDocument();
438
if (!pDoc) return; // no document
439
openCommand("Part Import Create");
440
doCommand(Doc, "import Part");
441
doCommand(Doc, "Part.insert(\"%s\",\"%s\")", (const char*)fn.toAscii(), pDoc->getName());
446
bool CmdPartImport::isActive(void)
448
if (getActiveGuiDocument())
454
//===========================================================================
455
// PartImportCurveNet
456
//===========================================================================
457
DEF_STD_CMD_A(CmdPartImportCurveNet);
459
CmdPartImportCurveNet::CmdPartImportCurveNet()
460
:Command("Part_ImportCurveNet")
463
sGroup = QT_TR_NOOP("Part");
464
sMenuText = QT_TR_NOOP("Import curve network...");
465
sToolTipText= QT_TR_NOOP("Import a curve network");
466
sWhatsThis = "Part_ImportCurveNet";
467
sStatusTip = sToolTipText;
468
sPixmap = "Part_Box";
472
void CmdPartImportCurveNet::activated(int iMsg)
475
filter << QObject::tr("All CAD Files (*.stp *.step *.igs *.iges *.brp *.brep)");
476
filter << QObject::tr("STEP (*.stp *.step)");
477
filter << QObject::tr("IGES (*.igs *.iges)");
478
filter << QObject::tr("BREP (*.brp *.brep)");
479
filter << QObject::tr("All Files (*.*)");
481
QString fn = Gui::FileDialog::getOpenFileName(Gui::getMainWindow(), QString(), QString(), filter.join(QLatin1String(";;")));
483
QFileInfo fi; fi.setFile(fn);
484
openCommand("Part Import Curve Net");
485
doCommand(Doc,"f = App.activeDocument().addObject(\"Part::CurveNet\",\"%s\")", (const char*)fi.baseName().toAscii());
486
doCommand(Doc,"f.FileName = \"%s\"",(const char*)fn.toAscii());
492
bool CmdPartImportCurveNet::isActive(void)
494
if (getActiveGuiDocument())
500
//===========================================================================
502
//===========================================================================
503
DEF_STD_CMD_A(CmdPartBoolean);
505
CmdPartBoolean::CmdPartBoolean()
506
:Command("Part_Boolean")
509
sGroup = QT_TR_NOOP("Part");
510
sMenuText = QT_TR_NOOP("Boolean...");
511
sToolTipText = QT_TR_NOOP("Run a boolean operation with two shapes selected");
512
sWhatsThis = "Part_Boolean";
513
sStatusTip = sToolTipText;
514
//sPixmap = "Part_Box";
518
void CmdPartBoolean::activated(int iMsg)
520
PartGui::DlgBooleanOperation dlg(Gui::getMainWindow());
524
bool CmdPartBoolean::isActive(void)
526
return hasActiveDocument();
529
//===========================================================================
531
//===========================================================================
532
DEF_STD_CMD_A(CmdPartExtrude);
534
CmdPartExtrude::CmdPartExtrude()
535
:Command("Part_Extrude")
538
sGroup = QT_TR_NOOP("Part");
539
sMenuText = QT_TR_NOOP("Extrude...");
540
sToolTipText = QT_TR_NOOP("Extrude a selected sketch");
541
sWhatsThis = sToolTipText;
542
sStatusTip = sToolTipText;
546
void CmdPartExtrude::activated(int iMsg)
548
PartGui::DlgExtrusion dlg(Gui::getMainWindow());
552
bool CmdPartExtrude::isActive(void)
554
return hasActiveDocument();
557
//===========================================================================
559
//===========================================================================
560
DEF_STD_CMD_A(CmdPartFilletEdges);
562
CmdPartFilletEdges::CmdPartFilletEdges()
563
:Command("Part_FilletEdges")
566
sGroup = QT_TR_NOOP("Part");
567
sMenuText = QT_TR_NOOP("Fillet...");
568
sToolTipText = QT_TR_NOOP("Fillet the selected edges of a shape");
569
sWhatsThis = sToolTipText;
570
sStatusTip = sToolTipText;
574
void CmdPartFilletEdges::activated(int iMsg)
576
PartGui::DlgFilletEdges dlg(Gui::getMainWindow());
580
bool CmdPartFilletEdges::isActive(void)
582
return hasActiveDocument();
585
//--------------------------------------------------------------------------------------
587
DEF_STD_CMD_A(CmdShapeInfo);
589
CmdShapeInfo::CmdShapeInfo()
590
:Command("Part_ShapeInfo")
594
sMenuText = "Shape info...";
595
sToolTipText = "Info about shape";
596
sWhatsThis = sToolTipText;
597
sStatusTip = sToolTipText;
600
void CmdShapeInfo::activated(int iMsg)
602
static const char * const part_pipette[]={
621
"................................",
622
".....................#####......",
623
"...................#######......",
624
"...................#########....",
625
"..................##########....",
626
"..................##########....",
627
"..................##########....",
628
".................###########....",
629
"...............#############....",
630
".............###############....",
631
".............#############......",
632
".............#############......",
633
"...............ab######.........",
634
"..............cdef#####.........",
635
".............ghdacf####.........",
636
"............#ehiacj####.........",
637
"............awiaaf####..........",
638
"...........iheacf##.............",
639
"..........#kdaag##..............",
640
".........gedaacb#...............",
641
".........lwiac##................",
642
".......#amlaaf##................",
643
".......cheaag#..................",
644
"......#ndaag##..................",
645
".....#imaacb#...................",
646
".....iwlacf#....................",
647
"....#nlaag##....................",
648
"....feaagj#.....................",
649
"....caag##......................",
650
"....ffbj##......................",
651
"................................",
652
"................................"};
654
Gui::Document* doc = Gui::Application::Instance->activeDocument();
655
Gui::View3DInventor* view = static_cast<Gui::View3DInventor*>(doc->getActiveView());
657
Gui::View3DInventorViewer* viewer = view->getViewer();
658
viewer->setEditing(true);
659
viewer->getWidget()->setCursor(QCursor(QPixmap(part_pipette),4,29));
660
viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(), PartGui::ViewProviderPart::shapeInfoCallback);
664
bool CmdShapeInfo::isActive(void)
666
App::Document* doc = App::GetApplication().getActiveDocument();
667
if (!doc || doc->countObjectsOfType(Part::Feature::getClassTypeId()) == 0)
670
Gui::MDIView* view = Gui::getMainWindow()->activeWindow();
671
if (view && view->isDerivedFrom(Gui::View3DInventor::getClassTypeId())) {
672
Gui::View3DInventorViewer* viewer = static_cast<Gui::View3DInventor*>(view)->getViewer();
673
return !viewer->isEditing();
680
void CreatePartCommands(void)
682
Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager();
684
rcCmdMgr.addCommand(new CmdPartBoolean());
685
rcCmdMgr.addCommand(new CmdPartExtrude());
686
rcCmdMgr.addCommand(new CmdPartFilletEdges());
687
rcCmdMgr.addCommand(new CmdPartCommon());
688
rcCmdMgr.addCommand(new CmdPartCut());
689
rcCmdMgr.addCommand(new CmdPartFuse());
690
rcCmdMgr.addCommand(new CmdPartSection());
691
rcCmdMgr.addCommand(new CmdPartBox2());
692
rcCmdMgr.addCommand(new CmdPartBox3());
693
rcCmdMgr.addCommand(new CmdPartPrimitives());
695
rcCmdMgr.addCommand(new CmdPartImport());
696
rcCmdMgr.addCommand(new CmdPartImportCurveNet());
697
rcCmdMgr.addCommand(new CmdPartPickCurveNet());
698
rcCmdMgr.addCommand(new CmdShapeInfo());