1
/***************************************************************************
2
* Copyright (c) 2002 Jürgen Riegel <juergen.riegel@web.de> *
3
* Copyright (c) 2014 Luke Parry <l.parry@warwick.ac.uk> *
5
* This library is free software; you can redistribute it and/or *
6
* modify it under the terms of the GNU Library General Public *
7
* License as published by the Free Software Foundation; either *
8
* version 2 of the License, or (at your option) any later version. *
10
* This library is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU Library General Public License for more details. *
15
* You should have received a copy of the GNU Library General Public *
16
* License along with this library; see the file COPYING.LIB. If not, *
17
* write to the Free Software Foundation, Inc., 59 Temple Place, *
18
* Suite 330, Boston, MA 02111-1307, USA *
20
***************************************************************************/
22
#include "PreCompiled.h"
24
#include <QApplication>
30
#include <App/Document.h>
31
#include <App/DocumentObject.h>
34
#include <Base/Console.h>
35
#include <Base/Tools.h>
37
#include <Gui/Action.h>
38
#include <Gui/Application.h>
39
#include <Gui/BitmapFactory.h>
40
#include <Gui/Command.h>
41
#include <Gui/Control.h>
42
#include <Gui/Document.h>
43
#include <Gui/FileDialog.h>
44
#include <Gui/MainWindow.h>
45
#include <Gui/Selection.h>
46
#include <Gui/SelectionObject.h>
47
#include <Gui/ViewProvider.h>
48
#include <Gui/WaitCursor.h>
50
#include <Mod/Spreadsheet/App/Sheet.h>
52
#include <Mod/TechDraw/App/DrawComplexSection.h>
53
#include <Mod/TechDraw/App/DrawPage.h>
54
#include <Mod/TechDraw/App/DrawProjGroup.h>
55
#include <Mod/TechDraw/App/DrawUtil.h>
56
#include <Mod/TechDraw/App/DrawSVGTemplate.h>
57
#include <Mod/TechDraw/App/DrawViewArch.h>
58
#include <Mod/TechDraw/App/DrawViewClip.h>
59
#include <Mod/TechDraw/App/DrawViewDetail.h>
60
#include <Mod/TechDraw/App/DrawViewDraft.h>
61
#include <Mod/TechDraw/App/DrawViewPart.h>
62
#include <Mod/TechDraw/App/DrawViewSymbol.h>
63
#include <Mod/TechDraw/App/Preferences.h>
65
#include "DrawGuiUtil.h"
66
#include "MDIViewPage.h"
67
#include "QGIViewPart.h"
71
#include "TaskActiveView.h"
72
#include "TaskComplexSection.h"
73
#include "TaskDetail.h"
74
#include "TaskProjGroup.h"
75
#include "TaskProjection.h"
76
#include "TaskSectionView.h"
77
#include "ViewProviderPage.h"
78
#include "ViewProviderDrawingView.h"
80
void execSimpleSection(Gui::Command* cmd);
81
void execComplexSection(Gui::Command* cmd);
84
using namespace TechDrawGui;
85
using namespace TechDraw;
87
//===========================================================================
88
// TechDraw_PageDefault
89
//===========================================================================
91
DEF_STD_CMD_A(CmdTechDrawPageDefault)
93
CmdTechDrawPageDefault::CmdTechDrawPageDefault() : Command("TechDraw_PageDefault")
95
sAppModule = "TechDraw";
96
sGroup = QT_TR_NOOP("TechDraw");
97
sMenuText = QT_TR_NOOP("Insert Default Page");
98
sToolTipText = sMenuText;
99
sWhatsThis = "TechDraw_PageDefault";
100
sStatusTip = sToolTipText;
101
sPixmap = "actions/TechDraw_PageDefault";
104
void CmdTechDrawPageDefault::activated(int iMsg)
108
QString templateFileName = Preferences::defaultTemplate();
109
QFileInfo tfi(templateFileName);
110
if (tfi.isReadable()) {
112
openCommand(QT_TRANSLATE_NOOP("Command", "Drawing create page"));
114
auto page = dynamic_cast<TechDraw::DrawPage *>
115
(getDocument()->addObject("TechDraw::DrawPage", "Page"));
117
throw Base::TypeError("CmdTechDrawPageDefault - page not created");
119
page->translateLabel("DrawPage", "Page", page->getNameInDocument());
121
auto svgTemplate = dynamic_cast<TechDraw::DrawSVGTemplate *>
122
(getDocument()->addObject("TechDraw::DrawSVGTemplate", "Template"));
124
throw Base::TypeError("CmdTechDrawPageDefault - template not created");
126
svgTemplate->translateLabel("DrawSVGTemplate", "Template", svgTemplate->getNameInDocument());
128
page->Template.setValue(svgTemplate);
129
svgTemplate->Template.setValue(templateFileName.toStdString());
134
TechDrawGui::ViewProviderPage *dvp = dynamic_cast<TechDrawGui::ViewProviderPage *>
135
(Gui::Application::Instance->getViewProvider(page));
141
QMessageBox::critical(Gui::getMainWindow(), QLatin1String("No template"),
142
QLatin1String("No default template found"));
146
bool CmdTechDrawPageDefault::isActive() { return hasActiveDocument(); }
148
//===========================================================================
149
// TechDraw_PageTemplate
150
//===========================================================================
152
DEF_STD_CMD_A(CmdTechDrawPageTemplate)
154
CmdTechDrawPageTemplate::CmdTechDrawPageTemplate() : Command("TechDraw_PageTemplate")
156
sAppModule = "TechDraw";
157
sGroup = QT_TR_NOOP("TechDraw");
158
sMenuText = QT_TR_NOOP("Insert Page using Template");
159
sToolTipText = sMenuText;
160
sWhatsThis = "TechDraw_PageTemplate";
161
sStatusTip = sToolTipText;
162
sPixmap = "actions/TechDraw_PageTemplate";
165
void CmdTechDrawPageTemplate::activated(int iMsg)
168
QString work_dir = Gui::FileDialog::getWorkingDirectory();
169
QString templateDir = Preferences::defaultTemplateDir();
170
QString templateFileName = Gui::FileDialog::getOpenFileName(
171
Gui::getMainWindow(), QString::fromUtf8(QT_TR_NOOP("Select a Template File")), templateDir,
172
QString::fromUtf8(QT_TR_NOOP("Template (*.svg)")));
173
Gui::FileDialog::setWorkingDirectory(work_dir);// Don't overwrite WD with templateDir
175
if (templateFileName.isEmpty()) {
179
QFileInfo tfi(templateFileName);
180
if (tfi.isReadable()) {
182
openCommand(QT_TRANSLATE_NOOP("Command", "Drawing create page"));
184
auto page = dynamic_cast<TechDraw::DrawPage *>
185
(getDocument()->addObject("TechDraw::DrawPage", "Page"));
187
throw Base::TypeError("CmdTechDrawPageTemplate - page not created");
189
page->translateLabel("DrawPage", "Page", page->getNameInDocument());
191
auto svgTemplate = dynamic_cast<TechDraw::DrawSVGTemplate *>
192
(getDocument()->addObject("TechDraw::DrawSVGTemplate", "Template"));
194
throw Base::TypeError("CmdTechDrawPageTemplate - template not created");
196
svgTemplate->translateLabel("DrawSVGTemplate", "Template", svgTemplate->getNameInDocument());
198
page->Template.setValue(svgTemplate);
199
svgTemplate->Template.setValue(templateFileName.toStdString());
204
TechDrawGui::ViewProviderPage *dvp = dynamic_cast<TechDrawGui::ViewProviderPage *>
205
(Gui::Application::Instance->getViewProvider(page));
211
QMessageBox::critical(Gui::getMainWindow(), QLatin1String("No template"),
212
QLatin1String("Template file is invalid"));
216
bool CmdTechDrawPageTemplate::isActive() { return hasActiveDocument(); }
218
//===========================================================================
219
// TechDraw_RedrawPage
220
//===========================================================================
222
DEF_STD_CMD_A(CmdTechDrawRedrawPage)
224
CmdTechDrawRedrawPage::CmdTechDrawRedrawPage() : Command("TechDraw_RedrawPage")
226
sAppModule = "TechDraw";
227
sGroup = QT_TR_NOOP("TechDraw");
228
sMenuText = QT_TR_NOOP("Redraw Page");
229
sToolTipText = sMenuText;
230
sWhatsThis = "TechDraw_RedrawPage";
231
sStatusTip = sToolTipText;
232
sPixmap = "actions/TechDraw_RedrawPage";
235
void CmdTechDrawRedrawPage::activated(int iMsg)
238
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
244
page->redrawCommand();
247
bool CmdTechDrawRedrawPage::isActive()
249
bool havePage = DrawGuiUtil::needPage(this);
250
bool haveView = DrawGuiUtil::needView(this, false);
251
return (havePage && haveView);
254
//===========================================================================
256
//===========================================================================
258
DEF_STD_CMD_A(CmdTechDrawPrintAll)
260
CmdTechDrawPrintAll::CmdTechDrawPrintAll() : Command("TechDraw_PrintAll")
262
sAppModule = "TechDraw";
263
sGroup = QT_TR_NOOP("TechDraw");
264
sMenuText = QT_TR_NOOP("Print All Pages");
265
sToolTipText = sMenuText;
266
sWhatsThis = "TechDraw_PrintAll";
267
sStatusTip = sToolTipText;
268
sPixmap = "actions/TechDraw_PrintAll";
271
void CmdTechDrawPrintAll::activated(int iMsg)
274
MDIViewPage::printAllPages();
277
bool CmdTechDrawPrintAll::isActive() { return DrawGuiUtil::needPage(this); }
279
//===========================================================================
281
//===========================================================================
283
DEF_STD_CMD_A(CmdTechDrawView)
285
CmdTechDrawView::CmdTechDrawView() : Command("TechDraw_View")
287
sAppModule = "TechDraw";
288
sGroup = QT_TR_NOOP("TechDraw");
289
sMenuText = QT_TR_NOOP("Insert View");
290
sToolTipText = QT_TR_NOOP("Insert a View");
291
sWhatsThis = "TechDraw_View";
292
sStatusTip = sToolTipText;
293
sPixmap = "actions/TechDraw_View";
296
void CmdTechDrawView::activated(int iMsg)
300
//set projection direction from selected Face
301
//use first object with a face selected
302
std::vector<App::DocumentObject*> shapes;
303
std::vector<App::DocumentObject*> xShapes;
304
App::DocumentObject* partObj = nullptr;
305
std::string faceName;
306
Gui::ResolveMode resolve = Gui::ResolveMode::OldStyleElement;//mystery
307
bool single = false; //mystery
308
auto selection = getSelection().getSelectionEx(nullptr, App::DocumentObject::getClassTypeId(),
310
for (auto& sel : selection) {
311
bool is_linked = false;
312
auto obj = sel.getObject();
313
if (obj->isDerivedFrom(TechDraw::DrawPage::getClassTypeId())) {
316
if (obj->isDerivedFrom(App::LinkElement::getClassTypeId())
317
|| obj->isDerivedFrom(App::LinkGroup::getClassTypeId())
318
|| obj->isDerivedFrom(App::Link::getClassTypeId())) {
321
// If parent of the obj is a link to another document, we possibly need to treat non-link obj as linked, too
322
// 1st, is obj in another document?
323
if (obj->getDocument() != this->getDocument()) {
324
std::set<App::DocumentObject*> parents = obj->getInListEx(true);
325
for (auto& parent : parents) {
326
// Only consider parents in the current document, i.e. possible links in this View's document
327
if (parent->getDocument() != this->getDocument()) {
330
// 2nd, do we really have a link to obj?
331
if (parent->isDerivedFrom(App::LinkElement::getClassTypeId())
332
|| parent->isDerivedFrom(App::LinkGroup::getClassTypeId())
333
|| parent->isDerivedFrom(App::Link::getClassTypeId())) {
334
// We have a link chain from this document to obj, and obj is in another document -> it is an XLink target
340
xShapes.push_back(obj);
343
//not a Link and not null. assume to be drawable. Undrawables will be
345
shapes.push_back(obj);
349
//don't know if this works for an XLink
350
for (auto& sub : sel.getSubNames()) {
351
if (TechDraw::DrawUtil::getGeomTypeFromName(sub) == "Face") {
360
if (shapes.empty() && xShapes.empty()) {
361
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
362
QObject::tr("No Shapes, Groups or Links in this selection"));
366
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
370
std::string PageName = page->getNameInDocument();
372
Base::Vector3d projDir;
375
openCommand(QT_TRANSLATE_NOOP("Command", "Create view"));
376
std::string FeatName = getUniqueObjectName("View");
377
doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawViewPart', '%s')",
379
doCommand(Doc, "App.activeDocument().%s.translateLabel('DrawViewPart', 'View', '%s')",
380
FeatName.c_str(), FeatName.c_str());
381
doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", PageName.c_str(),
384
App::DocumentObject* docObj = getDocument()->getObject(FeatName.c_str());
385
TechDraw::DrawViewPart* dvp = dynamic_cast<TechDraw::DrawViewPart*>(docObj);
387
throw Base::TypeError("CmdTechDrawView DVP not found\n");
389
dvp->Source.setValues(shapes);
390
dvp->XSource.setValues(xShapes);
391
if (!faceName.empty()) {
392
std::pair<Base::Vector3d, Base::Vector3d> dirs =
393
DrawGuiUtil::getProjDirFromFace(partObj, faceName);
394
projDir = dirs.first;
395
getDocument()->setStatus(App::Document::Status::SkipRecompute, true);
396
doCommand(Doc, "App.activeDocument().%s.Direction = FreeCAD.Vector(%.12f, %.12f, %.12f)",
397
FeatName.c_str(), projDir.x, projDir.y, projDir.z);
398
//do something clever with dirs.second;
399
// dvp->setXDir(dirs.second);
400
doCommand(Doc, "App.activeDocument().%s.XDirection = FreeCAD.Vector(%.12f, %.12f, %.12f)",
401
FeatName.c_str(), dirs.second.x, dirs.second.y, dirs.second.z);
402
doCommand(Doc, "App.activeDocument().%s.recompute()", FeatName.c_str());
403
getDocument()->setStatus(App::Document::Status::SkipRecompute, false);
406
std::pair<Base::Vector3d, Base::Vector3d> dirs = DrawGuiUtil::get3DDirAndRot();
407
projDir = dirs.first;
408
getDocument()->setStatus(App::Document::Status::SkipRecompute, true);
409
doCommand(Doc, "App.activeDocument().%s.Direction = FreeCAD.Vector(%.12f, %.12f, %.12f)",
410
FeatName.c_str(), projDir.x, projDir.y, projDir.z);
411
doCommand(Doc, "App.activeDocument().%s.XDirection = FreeCAD.Vector(%.12f, %.12f, %.12f)",
412
FeatName.c_str(), dirs.second.x, dirs.second.y, dirs.second.z);
413
// dvp->setXDir(dirs.second);
414
getDocument()->setStatus(App::Document::Status::SkipRecompute, false);
415
doCommand(Doc, "App.activeDocument().%s.recompute()", FeatName.c_str());
420
bool CmdTechDrawView::isActive() { return DrawGuiUtil::needPage(this); }
422
//===========================================================================
423
// TechDraw_ActiveView
424
//===========================================================================
426
DEF_STD_CMD_A(CmdTechDrawActiveView)
428
CmdTechDrawActiveView::CmdTechDrawActiveView() : Command("TechDraw_ActiveView")
430
sAppModule = "TechDraw";
431
sGroup = QT_TR_NOOP("TechDraw");
432
sMenuText = QT_TR_NOOP("Insert Active View (3D View)");
433
sToolTipText = sMenuText;
434
sWhatsThis = "TechDraw_ActiveView";
435
sStatusTip = sToolTipText;
436
sPixmap = "actions/TechDraw_ActiveView";
439
void CmdTechDrawActiveView::activated(int iMsg)
442
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this, true);
446
std::string PageName = page->getNameInDocument();
447
Gui::Control().showDialog(new TaskDlgActiveView(page));
450
bool CmdTechDrawActiveView::isActive() { return DrawGuiUtil::needPage(this, true); }
452
//===========================================================================
453
// TechDraw_SectionGroup
454
//===========================================================================
456
DEF_STD_CMD_ACL(CmdTechDrawSectionGroup)
458
CmdTechDrawSectionGroup::CmdTechDrawSectionGroup() : Command("TechDraw_SectionGroup")
460
sAppModule = "TechDraw";
461
sGroup = QT_TR_NOOP("TechDraw");
462
sMenuText = QT_TR_NOOP("Insert a simple or complex Section View");
463
sToolTipText = sMenuText;
464
sWhatsThis = "TechDraw_SectionGroup";
465
sStatusTip = sToolTipText;
468
void CmdTechDrawSectionGroup::activated(int iMsg)
470
// Base::Console().Message("CMD::SectionGrp - activated(%d)\n", iMsg);
471
Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog();
473
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
474
QObject::tr("Close active task dialog and try again."));
478
Gui::ActionGroup* pcAction = qobject_cast<Gui::ActionGroup*>(_pcAction);
479
pcAction->setIcon(pcAction->actions().at(iMsg)->icon());
482
execSimpleSection(this);
485
execComplexSection(this);
488
Base::Console().Message("CMD::SectionGrp - invalid iMsg: %d\n", iMsg);
492
Gui::Action* CmdTechDrawSectionGroup::createAction()
494
Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow());
495
pcAction->setDropDownMenu(true);
496
applyCommandData(this->className(), pcAction);
498
QAction* p1 = pcAction->addAction(QString());
499
p1->setIcon(Gui::BitmapFactory().iconFromTheme("actions/TechDraw_SectionView"));
500
p1->setObjectName(QString::fromLatin1("TechDraw_SectionView"));
501
p1->setWhatsThis(QString::fromLatin1("TechDraw_SectionView"));
502
QAction* p2 = pcAction->addAction(QString());
503
p2->setIcon(Gui::BitmapFactory().iconFromTheme("actions/TechDraw_ComplexSection"));
504
p2->setObjectName(QString::fromLatin1("TechDraw_ComplexSection"));
505
p2->setWhatsThis(QString::fromLatin1("TechDraw_ComplexSection"));
507
_pcAction = pcAction;
510
pcAction->setIcon(p1->icon());
512
pcAction->setProperty("defaultAction", QVariant(defaultId));
517
void CmdTechDrawSectionGroup::languageChange()
519
Command::languageChange();
523
Gui::ActionGroup* pcAction = qobject_cast<Gui::ActionGroup*>(_pcAction);
524
QList<QAction*> a = pcAction->actions();
526
QAction* arc1 = a[0];
527
arc1->setText(QApplication::translate("CmdTechDrawSectionGroup", "Section View"));
528
arc1->setToolTip(QApplication::translate("TechDraw_SectionView", "Insert simple Section View"));
529
arc1->setStatusTip(arc1->toolTip());
530
QAction* arc2 = a[1];
531
arc2->setText(QApplication::translate("CmdTechDrawSectionGroup", "Complex Section"));
533
QApplication::translate("TechDraw_ComplexSection", "Insert complex Section View"));
534
arc2->setStatusTip(arc2->toolTip());
537
bool CmdTechDrawSectionGroup::isActive()
539
bool havePage = DrawGuiUtil::needPage(this);
540
bool haveView = DrawGuiUtil::needView(this, false);
541
return (havePage && haveView);
544
//===========================================================================
545
// TechDraw_SectionView
546
//===========================================================================
548
DEF_STD_CMD_A(CmdTechDrawSectionView)
550
CmdTechDrawSectionView::CmdTechDrawSectionView() : Command("TechDraw_SectionView")
552
sAppModule = "TechDraw";
553
sGroup = QT_TR_NOOP("TechDraw");
554
sMenuText = QT_TR_NOOP("Insert Section View");
555
sToolTipText = sMenuText;
556
sWhatsThis = "TechDraw_SectionView";
557
sStatusTip = sToolTipText;
558
sPixmap = "actions/TechDraw_SectionView";
561
void CmdTechDrawSectionView::activated(int iMsg)
564
Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog();
566
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
567
QObject::tr("Close active task dialog and try again."));
571
execSimpleSection(this);
574
bool CmdTechDrawSectionView::isActive()
576
bool havePage = DrawGuiUtil::needPage(this);
577
bool haveView = DrawGuiUtil::needView(this);
578
bool taskInProgress = false;
580
taskInProgress = Gui::Control().activeDialog();
582
return (havePage && haveView && !taskInProgress);
585
void execSimpleSection(Gui::Command* cmd)
587
std::vector<App::DocumentObject*> baseObj =
588
cmd->getSelection().getObjectsOfType(TechDraw::DrawViewPart::getClassTypeId());
589
if (baseObj.empty()) {
590
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
591
QObject::tr("Select at least 1 DrawViewPart object as Base."));
595
TechDraw::DrawPage* page = DrawGuiUtil::findPage(cmd);
600
TechDraw::DrawViewPart* dvp = static_cast<TechDraw::DrawViewPart*>(*baseObj.begin());
601
Gui::Control().showDialog(new TaskDlgSectionView(dvp));
603
cmd->updateActive();//ok here since dialog doesn't call doc.recompute()
604
cmd->commitCommand();
607
//===========================================================================
608
// TechDraw_ComplexSection
609
//===========================================================================
611
DEF_STD_CMD_A(CmdTechDrawComplexSection)
613
CmdTechDrawComplexSection::CmdTechDrawComplexSection() : Command("TechDraw_ComplexSection")
615
sAppModule = "TechDraw";
616
sGroup = QT_TR_NOOP("TechDraw");
617
sMenuText = QT_TR_NOOP("Insert Complex Section");
618
sToolTipText = QT_TR_NOOP("Insert a Complex Section");
619
sWhatsThis = "TechDraw_ComplexSection";
620
sStatusTip = sToolTipText;
621
sPixmap = "actions/TechDraw_ComplexSection";
624
void CmdTechDrawComplexSection::activated(int iMsg)
627
Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog();
629
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
630
QObject::tr("Close active task dialog and try again."));
634
execComplexSection(this);
637
bool CmdTechDrawComplexSection::isActive() { return DrawGuiUtil::needPage(this); }
639
//Complex Sections can be created without a baseView, so the gathering of input
640
//for the dialog is more involved that simple section
641
void execComplexSection(Gui::Command* cmd)
643
TechDraw::DrawViewPart* baseView(nullptr);
644
std::vector<App::DocumentObject*> shapes;
645
std::vector<App::DocumentObject*> xShapes;
646
App::DocumentObject* profileObject(nullptr);
647
std::vector<std::string> profileSubs;
648
Gui::ResolveMode resolve = Gui::ResolveMode::OldStyleElement;//mystery
649
bool single = false; //mystery
650
auto selection = cmd->getSelection().getSelectionEx(
651
nullptr, App::DocumentObject::getClassTypeId(), resolve, single);
652
for (auto& sel : selection) {
653
bool is_linked = false;
654
auto obj = sel.getObject();
655
if (obj->isDerivedFrom(TechDraw::DrawPage::getClassTypeId())) {
658
if (obj->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) {
659
//use the dvp's Sources as sources for this ComplexSection &
660
//check the subelement(s) to see if they can be used as a profile
661
baseView = static_cast<TechDraw::DrawViewPart*>(obj);
662
if (!sel.getSubNames().empty()) {
663
//need to add profile subs as parameter
664
profileObject = baseView;
665
profileSubs = sel.getSubNames();
669
if (obj->isDerivedFrom(App::LinkElement::getClassTypeId())
670
|| obj->isDerivedFrom(App::LinkGroup::getClassTypeId())
671
|| obj->isDerivedFrom(App::Link::getClassTypeId())) {
674
// If parent of the obj is a link to another document, we possibly need to treat non-link obj as linked, too
675
// 1st, is obj in another document?
676
if (obj->getDocument() != cmd->getDocument()) {
677
std::set<App::DocumentObject*> parents = obj->getInListEx(true);
678
for (auto& parent : parents) {
679
// Only consider parents in the current document, i.e. possible links in this View's document
680
if (parent->getDocument() != cmd->getDocument()) {
683
// 2nd, do we really have a link to obj?
684
if (parent->isDerivedFrom(App::LinkElement::getClassTypeId())
685
|| parent->isDerivedFrom(App::LinkGroup::getClassTypeId())
686
|| parent->isDerivedFrom(App::Link::getClassTypeId())) {
687
// We have a link chain from this document to obj, and obj is in another document -> it is an XLink target
693
xShapes.push_back(obj);
696
//not a Link and not null. assume to be drawable. Undrawables will be
698
if (TechDraw::DrawComplexSection::isProfileObject(obj)) {
702
shapes.push_back(obj);
707
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
708
QObject::tr("I do not know what base view to use."));
712
if (shapes.empty() && xShapes.empty() && !baseView) {
713
QMessageBox::warning(
714
Gui::getMainWindow(), QObject::tr("Wrong selection"),
715
QObject::tr("No Base View, Shapes, Groups or Links in this selection"));
718
if (!profileObject) {
719
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
720
QObject::tr("No profile object found in selection"));
724
TechDraw::DrawPage* page = DrawGuiUtil::findPage(cmd);
729
Gui::Control().showDialog(
730
new TaskDlgComplexSection(page, baseView, shapes, xShapes, profileObject, profileSubs));
733
//===========================================================================
734
// TechDraw_DetailView
735
//===========================================================================
737
DEF_STD_CMD_A(CmdTechDrawDetailView)
739
CmdTechDrawDetailView::CmdTechDrawDetailView() : Command("TechDraw_DetailView")
741
sAppModule = "TechDraw";
742
sGroup = QT_TR_NOOP("TechDraw");
743
sMenuText = QT_TR_NOOP("Insert Detail View");
744
sToolTipText = sMenuText;
745
sWhatsThis = "TechDraw_DetailView";
746
sStatusTip = sToolTipText;
747
sPixmap = "actions/TechDraw_DetailView";
750
void CmdTechDrawDetailView::activated(int iMsg)
754
std::vector<App::DocumentObject*> baseObj =
755
getSelection().getObjectsOfType(TechDraw::DrawViewPart::getClassTypeId());
756
if (baseObj.empty()) {
757
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
758
QObject::tr("Select at least 1 DrawViewPart object as Base."));
761
TechDraw::DrawViewPart* dvp = static_cast<TechDraw::DrawViewPart*>(*(baseObj.begin()));
763
Gui::Control().showDialog(new TaskDlgDetail(dvp));
766
bool CmdTechDrawDetailView::isActive()
768
bool havePage = DrawGuiUtil::needPage(this);
769
bool haveView = DrawGuiUtil::needView(this);
770
bool taskInProgress = false;
772
taskInProgress = Gui::Control().activeDialog();
774
return (havePage && haveView && !taskInProgress);
777
//===========================================================================
778
// TechDraw_ProjectionGroup
779
//===========================================================================
781
DEF_STD_CMD_A(CmdTechDrawProjectionGroup)
783
CmdTechDrawProjectionGroup::CmdTechDrawProjectionGroup() : Command("TechDraw_ProjectionGroup")
785
sAppModule = "TechDraw";
786
sGroup = QT_TR_NOOP("TechDraw");
787
sMenuText = QT_TR_NOOP("Insert Projection Group");
788
sToolTipText = QT_TR_NOOP("Insert multiple linked views of drawable object(s)");
789
sWhatsThis = "TechDraw_ProjectionGroup";
790
sStatusTip = sToolTipText;
791
sPixmap = "actions/TechDraw_ProjectionGroup";
794
void CmdTechDrawProjectionGroup::activated(int iMsg)
798
//set projection direction from selected Face
799
//use first object with a face selected
800
std::vector<App::DocumentObject*> shapes;
801
std::vector<App::DocumentObject*> xShapes;
802
App::DocumentObject* partObj = nullptr;
803
std::string faceName;
804
Gui::ResolveMode resolve = Gui::ResolveMode::OldStyleElement;//mystery
805
bool single = false; //mystery
806
auto selection = getSelection().getSelectionEx(nullptr, App::DocumentObject::getClassTypeId(),
808
for (auto& sel : selection) {
809
bool is_linked = false;
810
auto obj = sel.getObject();
811
if (obj->isDerivedFrom(TechDraw::DrawPage::getClassTypeId())) {
814
if (obj->isDerivedFrom(App::LinkElement::getClassTypeId())
815
|| obj->isDerivedFrom(App::LinkGroup::getClassTypeId())
816
|| obj->isDerivedFrom(App::Link::getClassTypeId())) {
819
// If parent of the obj is a link to another document, we possibly need to treat non-link obj as linked, too
820
// 1st, is obj in another document?
821
if (obj->getDocument() != this->getDocument()) {
822
std::set<App::DocumentObject*> parents = obj->getInListEx(true);
823
for (auto& parent : parents) {
824
// Only consider parents in the current document, i.e. possible links in this View's document
825
if (parent->getDocument() != this->getDocument()) {
828
// 2nd, do we really have a link to obj?
829
if (parent->isDerivedFrom(App::LinkElement::getClassTypeId())
830
|| parent->isDerivedFrom(App::LinkGroup::getClassTypeId())
831
|| parent->isDerivedFrom(App::Link::getClassTypeId())) {
832
// We have a link chain from this document to obj, and obj is in another document -> it is an XLink target
838
xShapes.push_back(obj);
841
//not a Link and not null. assume to be drawable. Undrawables will be
843
shapes.push_back(obj);
847
for (auto& sub : sel.getSubNames()) {
848
if (TechDraw::DrawUtil::getGeomTypeFromName(sub) == "Face") {
855
if (shapes.empty() && xShapes.empty()) {
856
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
857
QObject::tr("No Shapes, Groups or Links in this selection"));
861
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
865
std::string PageName = page->getNameInDocument();
867
Base::Vector3d projDir;
870
openCommand(QT_TRANSLATE_NOOP("Command", "Create Projection Group"));
872
std::string multiViewName = getUniqueObjectName("ProjGroup");
873
doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawProjGroup', '%s')",
874
multiViewName.c_str());
875
doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", PageName.c_str(),
876
multiViewName.c_str());
878
App::DocumentObject* docObj = getDocument()->getObject(multiViewName.c_str());
879
auto multiView(static_cast<TechDraw::DrawProjGroup*>(docObj));
880
multiView->Source.setValues(shapes);
881
multiView->XSource.setValues(xShapes);
882
doCommand(Doc, "App.activeDocument().%s.addProjection('Front')", multiViewName.c_str());
884
if (!faceName.empty()) {
885
std::pair<Base::Vector3d, Base::Vector3d> dirs =
886
DrawGuiUtil::getProjDirFromFace(partObj, faceName);
887
getDocument()->setStatus(App::Document::Status::SkipRecompute, true);
889
"App.activeDocument().%s.Anchor.Direction = FreeCAD.Vector(%.12f, %.12f, %.12f)",
890
multiViewName.c_str(), dirs.first.x, dirs.first.y, dirs.first.z);
893
"App.activeDocument().%s.Anchor.RotationVector = FreeCAD.Vector(%.12f, %.12f, %.12f)",
894
multiViewName.c_str(), dirs.second.x, dirs.second.y, dirs.second.z);
896
"App.activeDocument().%s.Anchor.XDirection = FreeCAD.Vector(%.12f, %.12f, %.12f)",
897
multiViewName.c_str(), dirs.second.x, dirs.second.y, dirs.second.z);
898
getDocument()->setStatus(App::Document::Status::SkipRecompute, false);
901
std::pair<Base::Vector3d, Base::Vector3d> dirs = DrawGuiUtil::get3DDirAndRot();
902
getDocument()->setStatus(App::Document::Status::SkipRecompute, true);
904
"App.activeDocument().%s.Anchor.Direction = FreeCAD.Vector(%.12f, %.12f, %.12f)",
905
multiViewName.c_str(), dirs.first.x, dirs.first.y, dirs.first.z);
908
"App.activeDocument().%s.Anchor.RotationVector = FreeCAD.Vector(%.12f, %.12f, %.12f)",
909
multiViewName.c_str(), dirs.second.x, dirs.second.y, dirs.second.z);
911
"App.activeDocument().%s.Anchor.XDirection = FreeCAD.Vector(%.12f, %.12f, %.12f)",
912
multiViewName.c_str(), dirs.second.x, dirs.second.y, dirs.second.z);
913
getDocument()->setStatus(App::Document::Status::SkipRecompute, false);
916
doCommand(Doc, "App.activeDocument().%s.Anchor.recompute()", multiViewName.c_str());
920
// create the rest of the desired views
921
Gui::Control().showDialog(new TaskDlgProjGroup(multiView, true));
924
bool CmdTechDrawProjectionGroup::isActive()
926
bool havePage = DrawGuiUtil::needPage(this);
927
bool taskInProgress = false;
929
taskInProgress = Gui::Control().activeDialog();
931
return (havePage && !taskInProgress);
934
//! common checks of Selection for Dimension commands
935
//non-empty selection, no more than maxObjs selected and at least 1 DrawingPage exists
936
bool _checkSelectionBalloon(Gui::Command* cmd, unsigned maxObjs)
938
std::vector<Gui::SelectionObject> selection = cmd->getSelection().getSelectionEx();
939
if (selection.empty()) {
940
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect selection"),
941
QObject::tr("Select an object first"));
945
const std::vector<std::string> SubNames = selection[0].getSubNames();
946
if (SubNames.size() > maxObjs) {
947
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect selection"),
948
QObject::tr("Too many objects selected"));
952
std::vector<App::DocumentObject*> pages =
953
cmd->getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId());
955
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect selection"),
956
QObject::tr("Create a page first."));
962
bool _checkDrawViewPartBalloon(Gui::Command* cmd)
964
std::vector<Gui::SelectionObject> selection = cmd->getSelection().getSelectionEx();
965
auto objFeat(dynamic_cast<TechDraw::DrawViewPart*>(selection[0].getObject()));
967
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect selection"),
968
QObject::tr("No View of a Part in selection."));
974
bool _checkDirectPlacement(const QGIView* view, const std::vector<std::string>& subNames,
977
// Let's see, if we can help speed up the placement of the balloon:
978
// As of now we support:
979
// Single selected vertex: place the ballon tip end here
980
// Single selected edge: place the ballon tip at its midpoint (suggested placement for e.g. chamfer dimensions)
982
// Single selected faces are currently not supported, but maybe we could in this case use the center of mass?
984
if (subNames.size() != 1) {
985
// If nothing or more than one subjects are selected, let the user decide, where to place the balloon
989
const QGIViewPart* viewPart = dynamic_cast<const QGIViewPart*>(view);
991
//not a view of a part, so no geometry to attach to
995
std::string geoType = TechDraw::DrawUtil::getGeomTypeFromName(subNames[0]);
996
if (geoType == "Vertex") {
997
int index = TechDraw::DrawUtil::getIndexFromName(subNames[0]);
998
TechDraw::VertexPtr vertex =
999
static_cast<DrawViewPart*>(viewPart->getViewObject())->getProjVertexByIndex(index);
1001
placement = viewPart->mapToScene(Rez::guiX(vertex->x()), Rez::guiX(vertex->y()));
1005
else if (geoType == "Edge") {
1006
int index = TechDraw::DrawUtil::getIndexFromName(subNames[0]);
1007
TechDraw::BaseGeomPtr geo =
1008
static_cast<DrawViewPart*>(viewPart->getViewObject())->getGeomByIndex(index);
1010
Base::Vector3d midPoint(Rez::guiX(geo->getMidPoint()));
1011
placement = viewPart->mapToScene(midPoint.x, midPoint.y);
1019
DEF_STD_CMD_A(CmdTechDrawBalloon)
1021
CmdTechDrawBalloon::CmdTechDrawBalloon() : Command("TechDraw_Balloon")
1023
sAppModule = "TechDraw";
1024
sGroup = QT_TR_NOOP("TechDraw");
1025
sMenuText = QT_TR_NOOP("Insert Balloon Annotation");
1026
sToolTipText = sMenuText;
1027
sWhatsThis = "TechDraw_Balloon";
1028
sStatusTip = sToolTipText;
1029
sPixmap = "TechDraw_Balloon";
1032
void CmdTechDrawBalloon::activated(int iMsg)
1035
bool result = _checkSelectionBalloon(this, 1);
1040
std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx();
1042
auto objFeat(dynamic_cast<TechDraw::DrawView*>(selection[0].getObject()));
1047
TechDraw::DrawPage* page = objFeat->findParentPage();
1048
std::string PageName = page->getNameInDocument();
1050
Gui::Document* guiDoc = Gui::Application::Instance->getDocument(page->getDocument());
1051
ViewProviderPage* pageVP = dynamic_cast<ViewProviderPage*>(guiDoc->getViewProvider(page));
1052
ViewProviderDrawingView* viewVP =
1053
dynamic_cast<ViewProviderDrawingView*>(guiDoc->getViewProvider(objFeat));
1055
if (pageVP && viewVP) {
1056
QGVPage* viewPage = pageVP->getQGVPage();
1057
QGSPage* scenePage = pageVP->getQGSPage();
1059
viewPage->startBalloonPlacing(objFeat);
1061
QGIView* view = dynamic_cast<QGIView*>(viewVP->getQView());
1063
if (view && _checkDirectPlacement(view, selection[0].getSubNames(), placement)) {
1064
//this creates the balloon if something is already selected
1065
scenePage->createBalloon(placement, objFeat);
1071
bool CmdTechDrawBalloon::isActive()
1073
bool havePage = DrawGuiUtil::needPage(this);
1074
bool haveView = DrawGuiUtil::needView(this, false);
1075
bool taskInProgress = Gui::Control().activeDialog();
1076
return (havePage && haveView && !taskInProgress);
1079
//===========================================================================
1080
// TechDraw_ClipGroup
1081
//===========================================================================
1083
DEF_STD_CMD_A(CmdTechDrawClipGroup)
1085
CmdTechDrawClipGroup::CmdTechDrawClipGroup() : Command("TechDraw_ClipGroup")
1088
sGroup = QT_TR_NOOP("TechDraw");
1089
sMenuText = QT_TR_NOOP("Insert Clip Group");
1090
sToolTipText = sMenuText;
1091
sWhatsThis = "TechDraw_ClipGroup";
1092
sStatusTip = sToolTipText;
1093
sPixmap = "actions/TechDraw_ClipGroup";
1096
void CmdTechDrawClipGroup::activated(int iMsg)
1099
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
1103
std::string PageName = page->getNameInDocument();
1105
std::string FeatName = getUniqueObjectName("Clip");
1106
openCommand(QT_TRANSLATE_NOOP("Command", "Create Clip"));
1107
doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawViewClip', '%s')",
1109
doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", PageName.c_str(),
1115
bool CmdTechDrawClipGroup::isActive() { return DrawGuiUtil::needPage(this); }
1117
//===========================================================================
1118
// TechDraw_ClipGroupAdd
1119
//===========================================================================
1121
DEF_STD_CMD_A(CmdTechDrawClipGroupAdd)
1123
CmdTechDrawClipGroupAdd::CmdTechDrawClipGroupAdd() : Command("TechDraw_ClipGroupAdd")
1125
sGroup = QT_TR_NOOP("TechDraw");
1126
sMenuText = QT_TR_NOOP("Add View to Clip Group");
1127
sToolTipText = sMenuText;
1128
sWhatsThis = "TechDraw_ClipGroupAdd";
1129
sStatusTip = sToolTipText;
1130
sPixmap = "actions/TechDraw_ClipGroupAdd";
1133
void CmdTechDrawClipGroupAdd::activated(int iMsg)
1136
std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx();
1137
if (selection.size() != 2) {
1138
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
1139
QObject::tr("Select one Clip group and one View."));
1143
TechDraw::DrawViewClip* clip = nullptr;
1144
TechDraw::DrawView* view = nullptr;
1145
std::vector<Gui::SelectionObject>::iterator itSel = selection.begin();
1146
for (; itSel != selection.end(); itSel++) {
1147
if ((*itSel).getObject()->isDerivedFrom(TechDraw::DrawViewClip::getClassTypeId())) {
1148
clip = static_cast<TechDraw::DrawViewClip*>((*itSel).getObject());
1150
else if ((*itSel).getObject()->isDerivedFrom(TechDraw::DrawView::getClassTypeId())) {
1151
view = static_cast<TechDraw::DrawView*>((*itSel).getObject());
1155
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
1156
QObject::tr("Select exactly one View to add to group."));
1160
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
1161
QObject::tr("Select exactly one Clip group."));
1165
TechDraw::DrawPage* pageClip = clip->findParentPage();
1166
TechDraw::DrawPage* pageView = view->findParentPage();
1168
if (pageClip != pageView) {
1169
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
1170
QObject::tr("Clip and View must be from same Page."));
1174
std::string PageName = pageClip->getNameInDocument();
1175
std::string ClipName = clip->getNameInDocument();
1176
std::string ViewName = view->getNameInDocument();
1178
openCommand(QT_TRANSLATE_NOOP("Command", "ClipGroupAdd"));
1179
doCommand(Doc, "App.activeDocument().%s.ViewObject.Visibility = False", ViewName.c_str());
1180
doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", ClipName.c_str(),
1182
doCommand(Doc, "App.activeDocument().%s.ViewObject.Visibility = True", ViewName.c_str());
1187
bool CmdTechDrawClipGroupAdd::isActive()
1189
bool havePage = DrawGuiUtil::needPage(this);
1190
bool haveClip = false;
1192
auto drawClipType(TechDraw::DrawViewClip::getClassTypeId());
1193
auto selClips = getDocument()->getObjectsOfType(drawClipType);
1194
if (!selClips.empty()) {
1198
return (havePage && haveClip);
1201
//===========================================================================
1202
// TechDraw_ClipGroupRemove
1203
//===========================================================================
1205
DEF_STD_CMD_A(CmdTechDrawClipGroupRemove)
1207
CmdTechDrawClipGroupRemove::CmdTechDrawClipGroupRemove() : Command("TechDraw_ClipGroupRemove")
1209
sGroup = QT_TR_NOOP("TechDraw");
1210
sMenuText = QT_TR_NOOP("Remove View from Clip Group");
1211
sToolTipText = sMenuText;
1212
sWhatsThis = "TechDraw_ClipGroupRemove";
1213
sStatusTip = sToolTipText;
1214
sPixmap = "actions/TechDraw_ClipGroupRemove";
1217
void CmdTechDrawClipGroupRemove::activated(int iMsg)
1220
auto dObj(getSelection().getObjectsOfType(TechDraw::DrawView::getClassTypeId()));
1222
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
1223
QObject::tr("Select exactly one View to remove from Group."));
1227
auto view(static_cast<TechDraw::DrawView*>(dObj.front()));
1229
TechDraw::DrawPage* page = view->findParentPage();
1230
const std::vector<App::DocumentObject*> pViews = page->Views.getValues();
1231
TechDraw::DrawViewClip* clip(nullptr);
1232
for (auto& v : pViews) {
1233
clip = dynamic_cast<TechDraw::DrawViewClip*>(v);
1234
if (clip && clip->isViewInClip(view)) {
1241
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
1242
QObject::tr("View does not belong to a Clip"));
1246
std::string ClipName = clip->getNameInDocument();
1247
std::string ViewName = view->getNameInDocument();
1249
openCommand(QT_TRANSLATE_NOOP("Command", "ClipGroupRemove"));
1250
doCommand(Doc, "App.activeDocument().%s.ViewObject.Visibility = False", ViewName.c_str());
1251
doCommand(Doc, "App.activeDocument().%s.removeView(App.activeDocument().%s)", ClipName.c_str(),
1253
doCommand(Doc, "App.activeDocument().%s.ViewObject.Visibility = True", ViewName.c_str());
1258
bool CmdTechDrawClipGroupRemove::isActive()
1260
bool havePage = DrawGuiUtil::needPage(this);
1261
bool haveClip = false;
1263
auto drawClipType(TechDraw::DrawViewClip::getClassTypeId());
1264
auto selClips = getDocument()->getObjectsOfType(drawClipType);
1265
if (!selClips.empty()) {
1269
return (havePage && haveClip);
1273
//===========================================================================
1275
//===========================================================================
1277
DEF_STD_CMD_A(CmdTechDrawSymbol)
1279
CmdTechDrawSymbol::CmdTechDrawSymbol() : Command("TechDraw_Symbol")
1281
// setting the Gui eye-candy
1282
sGroup = QT_TR_NOOP("TechDraw");
1283
sMenuText = QT_TR_NOOP("Insert SVG Symbol");
1284
sToolTipText = QT_TR_NOOP("Insert symbol from an SVG file");
1285
sWhatsThis = "TechDraw_Symbol";
1286
sStatusTip = sToolTipText;
1287
sPixmap = "actions/TechDraw_Symbol";
1290
void CmdTechDrawSymbol::activated(int iMsg)
1293
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
1297
std::string PageName = page->getNameInDocument();
1300
QString filename = Gui::FileDialog::getOpenFileName(
1301
Gui::getMainWindow(), QObject::tr("Choose an SVG file to open"), QString(),
1302
QString::fromLatin1("%1 (*.svg *.svgz);;%2 (*.*)")
1303
.arg(QObject::tr("Scalable Vector Graphic"), QObject::tr("All Files")));
1305
if (!filename.isEmpty()) {
1306
std::string FeatName = getUniqueObjectName("Symbol");
1307
filename = Base::Tools::escapeEncodeFilename(filename);
1308
openCommand(QT_TRANSLATE_NOOP("Command", "Create Symbol"));
1309
doCommand(Doc, "f = open(\"%s\", 'r')", (const char*)filename.toUtf8());
1310
doCommand(Doc, "svg = f.read()");
1311
doCommand(Doc, "f.close()");
1312
doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawViewSymbol', '%s')",
1314
doCommand(Doc, "App.activeDocument().%s.translateLabel('DrawViewSymbol', 'Symbol', '%s')",
1315
FeatName.c_str(), FeatName.c_str());
1316
doCommand(Doc, "App.activeDocument().%s.Symbol = svg", FeatName.c_str());
1317
doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", PageName.c_str(),
1324
bool CmdTechDrawSymbol::isActive() { return DrawGuiUtil::needPage(this); }
1326
//===========================================================================
1327
// TechDraw_DraftView
1328
//===========================================================================
1330
DEF_STD_CMD_A(CmdTechDrawDraftView)
1332
CmdTechDrawDraftView::CmdTechDrawDraftView() : Command("TechDraw_DraftView")
1334
// setting the Gui eye-candy
1335
sGroup = QT_TR_NOOP("TechDraw");
1336
sMenuText = QT_TR_NOOP("Insert Draft Workbench Object");
1337
sToolTipText = QT_TR_NOOP("Insert a View of a Draft Workbench object");
1338
sWhatsThis = "TechDraw_NewDraft";
1339
sStatusTip = sToolTipText;
1340
sPixmap = "actions/TechDraw_DraftView";
1343
void CmdTechDrawDraftView::activated(int iMsg)
1347
std::vector<App::DocumentObject*> objects =
1348
getSelection().getObjectsOfType(App::DocumentObject::getClassTypeId());
1350
if (objects.empty()) {
1351
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
1352
QObject::tr("Select at least one object."));
1356
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
1360
std::string PageName = page->getNameInDocument();
1362
std::pair<Base::Vector3d, Base::Vector3d> dirs = DrawGuiUtil::get3DDirAndRot();
1363
for (std::vector<App::DocumentObject*>::iterator it = objects.begin(); it != objects.end();
1365
if ((*it)->isDerivedFrom(TechDraw::DrawPage::getClassTypeId()) ||
1366
(*it)->isDerivedFrom(TechDraw::DrawView::getClassTypeId())) {
1367
// skip over TechDraw objects as they are not valid subjects for a DraftView
1370
std::string FeatName = getUniqueObjectName("DraftView");
1371
std::string SourceName = (*it)->getNameInDocument();
1372
openCommand(QT_TRANSLATE_NOOP("Command", "Create DraftView"));
1373
doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawViewDraft', '%s')",
1375
doCommand(Doc, "App.activeDocument().%s.translateLabel('DrawViewDraft', 'DraftView', '%s')",
1376
FeatName.c_str(), FeatName.c_str());
1377
doCommand(Doc, "App.activeDocument().%s.Source = App.activeDocument().%s", FeatName.c_str(),
1378
SourceName.c_str());
1379
doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", PageName.c_str(),
1381
doCommand(Doc, "App.activeDocument().%s.Direction = FreeCAD.Vector(%.12f, %.12f, %.12f)",
1382
FeatName.c_str(), dirs.first.x, dirs.first.y, dirs.first.z);
1388
bool CmdTechDrawDraftView::isActive() { return DrawGuiUtil::needPage(this); }
1390
//===========================================================================
1392
//===========================================================================
1394
DEF_STD_CMD_A(CmdTechDrawArchView)
1396
CmdTechDrawArchView::CmdTechDrawArchView() : Command("TechDraw_ArchView")
1398
// setting the Gui eye-candy
1399
sGroup = QT_TR_NOOP("TechDraw");
1400
sMenuText = QT_TR_NOOP("Insert Arch Workbench Object");
1401
sToolTipText = QT_TR_NOOP("Insert a View of a Section Plane from Arch Workbench");
1402
sWhatsThis = "TechDraw_NewArch";
1403
sStatusTip = sToolTipText;
1404
sPixmap = "actions/TechDraw_ArchView";
1407
void CmdTechDrawArchView::activated(int iMsg)
1411
const std::vector<App::DocumentObject*> objects =
1412
getSelection().getObjectsOfType(App::DocumentObject::getClassTypeId());
1413
App::DocumentObject* archObject = nullptr;
1415
for (auto& obj : objects) {
1416
if (obj->isDerivedFrom(TechDraw::DrawPage::getClassTypeId()) ||
1417
obj->isDerivedFrom(TechDraw::DrawView::getClassTypeId())) {
1418
// skip over TechDraw objects as they are not valid subjects for a ArchView
1421
if (DrawGuiUtil::isArchSection(obj)) {
1426
if (archCount > 1) {
1427
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
1428
QObject::tr("Please select only 1 Arch Section."));
1433
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
1434
QObject::tr("No Arch Sections in selection."));
1438
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
1442
std::string PageName = page->getNameInDocument();
1444
std::string FeatName = getUniqueObjectName("ArchView");
1445
std::string SourceName = archObject->getNameInDocument();
1446
openCommand(QT_TRANSLATE_NOOP("Command", "Create ArchView"));
1447
doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawViewArch', '%s')",
1449
doCommand(Doc, "App.activeDocument().%s.translateLabel('DrawViewArch', 'ArchView', '%s')",
1450
FeatName.c_str(), FeatName.c_str());
1451
doCommand(Doc, "App.activeDocument().%s.Source = App.activeDocument().%s", FeatName.c_str(),
1452
SourceName.c_str());
1453
doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", PageName.c_str(),
1459
bool CmdTechDrawArchView::isActive() { return DrawGuiUtil::needPage(this); }
1461
//===========================================================================
1462
// TechDraw_SpreadsheetView
1463
//===========================================================================
1465
DEF_STD_CMD_A(CmdTechDrawSpreadsheetView)
1467
CmdTechDrawSpreadsheetView::CmdTechDrawSpreadsheetView() : Command("TechDraw_SpreadsheetView")
1470
sGroup = QT_TR_NOOP("TechDraw");
1471
sMenuText = QT_TR_NOOP("Insert Spreadsheet View");
1472
sToolTipText = QT_TR_NOOP("Insert View to a spreadsheet");
1473
sWhatsThis = "TechDraw_SpreadsheetView";
1474
sStatusTip = sToolTipText;
1475
sPixmap = "actions/TechDraw_SpreadsheetView";
1478
void CmdTechDrawSpreadsheetView::activated(int iMsg)
1481
const std::vector<App::DocumentObject*> spreads =
1482
getSelection().getObjectsOfType(Spreadsheet::Sheet::getClassTypeId());
1483
if (spreads.size() != 1) {
1484
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
1485
QObject::tr("Select exactly one Spreadsheet object."));
1488
std::string SpreadName = spreads.front()->getNameInDocument();
1490
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
1494
std::string PageName = page->getNameInDocument();
1496
openCommand(QT_TRANSLATE_NOOP("Command", "Create spreadsheet view"));
1497
std::string FeatName = getUniqueObjectName("Sheet");
1498
doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawViewSpreadsheet', '%s')",
1500
doCommand(Doc, "App.activeDocument().%s.translateLabel('DrawViewSpreadsheet', 'Sheet', '%s')",
1501
FeatName.c_str(), FeatName.c_str());
1502
doCommand(Doc, "App.activeDocument().%s.Source = App.activeDocument().%s", FeatName.c_str(),
1503
SpreadName.c_str());
1504
doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", PageName.c_str(),
1510
bool CmdTechDrawSpreadsheetView::isActive()
1512
//need a Page and a SpreadSheet::Sheet
1513
bool havePage = DrawGuiUtil::needPage(this);
1514
bool haveSheet = false;
1516
auto spreadSheetType(Spreadsheet::Sheet::getClassTypeId());
1517
auto selSheets = getDocument()->getObjectsOfType(spreadSheetType);
1518
if (!selSheets.empty()) {
1522
return (havePage && haveSheet);
1526
//===========================================================================
1527
// TechDraw_ExportPageSVG
1528
//===========================================================================
1530
DEF_STD_CMD_A(CmdTechDrawExportPageSVG)
1532
CmdTechDrawExportPageSVG::CmdTechDrawExportPageSVG() : Command("TechDraw_ExportPageSVG")
1534
sGroup = QT_TR_NOOP("File");
1535
sMenuText = QT_TR_NOOP("Export Page as SVG");
1536
sToolTipText = sMenuText;
1537
sWhatsThis = "TechDraw_ExportPageSVG";
1538
sStatusTip = sToolTipText;
1539
sPixmap = "actions/TechDraw_ExportPageSVG";
1542
void CmdTechDrawExportPageSVG::activated(int iMsg)
1545
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
1549
std::string PageName = page->getNameInDocument();
1551
Gui::Document* activeGui = Gui::Application::Instance->getDocument(page->getDocument());
1552
Gui::ViewProvider* vp = activeGui->getViewProvider(page);
1553
ViewProviderPage* dvp = dynamic_cast<ViewProviderPage*>(vp);
1555
if (dvp && dvp->getMDIViewPage()) {
1556
dvp->getMDIViewPage()->saveSVG();
1559
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No Drawing View"),
1560
QObject::tr("Open Drawing View before attempting export to SVG."));
1565
bool CmdTechDrawExportPageSVG::isActive() { return DrawGuiUtil::needPage(this); }
1567
//===========================================================================
1568
// TechDraw_ExportPageDXF
1569
//===========================================================================
1571
DEF_STD_CMD_A(CmdTechDrawExportPageDXF)
1573
CmdTechDrawExportPageDXF::CmdTechDrawExportPageDXF() : Command("TechDraw_ExportPageDXF")
1575
sGroup = QT_TR_NOOP("File");
1576
sMenuText = QT_TR_NOOP("Export Page as DXF");
1577
sToolTipText = sMenuText;
1578
sWhatsThis = "TechDraw_ExportPageDXF";
1579
sStatusTip = sToolTipText;
1580
sPixmap = "actions/TechDraw_ExportPageDXF";
1583
void CmdTechDrawExportPageDXF::activated(int iMsg)
1586
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
1591
std::vector<App::DocumentObject*> views = page->Views.getValues();
1592
for (auto& v : views) {
1593
if (v->isDerivedFrom(TechDraw::DrawViewArch::getClassTypeId())) {
1594
QMessageBox::StandardButton rc = QMessageBox::question(
1595
Gui::getMainWindow(), QObject::tr("Can not export selection"),
1596
QObject::tr("Page contains DrawViewArch which will not be exported. Continue?"),
1597
QMessageBox::StandardButtons(QMessageBox::Yes | QMessageBox::No));
1598
if (rc == QMessageBox::No) {
1607
//WF? allow more than one TD Page per Dxf file?? 1 TD page = 1 DXF file = 1 drawing?
1609
QString fileName = Gui::FileDialog::getSaveFileName(
1610
Gui::getMainWindow(), QString::fromUtf8(QT_TR_NOOP("Save DXF file")), defaultDir,
1611
QString::fromUtf8(QT_TR_NOOP("DXF (*.dxf)")));
1613
if (fileName.isEmpty()) {
1617
std::string PageName = page->getNameInDocument();
1618
openCommand(QT_TRANSLATE_NOOP("Command", "Save page to dxf"));
1619
doCommand(Doc, "import TechDraw");
1620
fileName = Base::Tools::escapeEncodeFilename(fileName);
1621
doCommand(Doc, "TechDraw.writeDXFPage(App.activeDocument().%s, u\"%s\")", PageName.c_str(),
1622
(const char*)fileName.toUtf8());
1627
bool CmdTechDrawExportPageDXF::isActive() { return DrawGuiUtil::needPage(this); }
1629
//===========================================================================
1630
// TechDraw_ProjectShape
1631
//===========================================================================
1633
DEF_STD_CMD_A(CmdTechDrawProjectShape)
1635
CmdTechDrawProjectShape::CmdTechDrawProjectShape() : Command("TechDraw_ProjectShape")
1637
sAppModule = "TechDraw";
1638
sGroup = QT_TR_NOOP("TechDraw");
1639
sMenuText = QT_TR_NOOP("Project shape...");
1640
sToolTipText = sMenuText;
1641
sWhatsThis = "TechDraw_ProjectShape";
1642
sStatusTip = sToolTipText;
1643
sPixmap = "actions/TechDraw_ProjectShape";
1646
void CmdTechDrawProjectShape::activated(int iMsg)
1649
Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog();
1651
Gui::Control().showDialog(new TaskDlgProjection());
1655
bool CmdTechDrawProjectShape::isActive() { return true; }
1657
void CreateTechDrawCommands()
1659
Gui::CommandManager& rcCmdMgr = Gui::Application::Instance->commandManager();
1661
rcCmdMgr.addCommand(new CmdTechDrawPageDefault());
1662
rcCmdMgr.addCommand(new CmdTechDrawPageTemplate());
1663
rcCmdMgr.addCommand(new CmdTechDrawRedrawPage());
1664
rcCmdMgr.addCommand(new CmdTechDrawPrintAll());
1665
rcCmdMgr.addCommand(new CmdTechDrawView());
1666
rcCmdMgr.addCommand(new CmdTechDrawActiveView());
1667
rcCmdMgr.addCommand(new CmdTechDrawSectionGroup());
1668
rcCmdMgr.addCommand(new CmdTechDrawSectionView());
1669
rcCmdMgr.addCommand(new CmdTechDrawComplexSection());
1670
rcCmdMgr.addCommand(new CmdTechDrawDetailView());
1671
rcCmdMgr.addCommand(new CmdTechDrawProjectionGroup());
1672
rcCmdMgr.addCommand(new CmdTechDrawClipGroup());
1673
rcCmdMgr.addCommand(new CmdTechDrawClipGroupAdd());
1674
rcCmdMgr.addCommand(new CmdTechDrawClipGroupRemove());
1675
rcCmdMgr.addCommand(new CmdTechDrawSymbol());
1676
rcCmdMgr.addCommand(new CmdTechDrawExportPageSVG());
1677
rcCmdMgr.addCommand(new CmdTechDrawExportPageDXF());
1678
rcCmdMgr.addCommand(new CmdTechDrawDraftView());
1679
rcCmdMgr.addCommand(new CmdTechDrawArchView());
1680
rcCmdMgr.addCommand(new CmdTechDrawSpreadsheetView());
1681
rcCmdMgr.addCommand(new CmdTechDrawBalloon());
1682
rcCmdMgr.addCommand(new CmdTechDrawProjectShape());