1
/***************************************************************************
3
* This program is free software; you can redistribute it and/or modify *
4
* it under the terms of the GNU Library General Public License as *
5
* published by the Free Software Foundation; either version 2 of the *
6
* License, or (at your option) any later version. *
7
* for detail see the LICENCE text file. *
10
***************************************************************************/
12
#include "PreCompiled.h"
17
#include <QCoreApplication>
22
#include <QRegularExpression>
25
#include <App/Document.h>
26
#include <App/PropertyGeo.h>
27
#include <Base/Tools.h>
28
#include <Gui/Action.h>
29
#include <Gui/Application.h>
30
#include <Gui/BitmapFactory.h>
31
#include <Gui/Command.h>
32
#include <Gui/Control.h>
33
#include <Gui/FileDialog.h>
34
#include <Gui/MainWindow.h>
35
#include <Gui/Selection.h>
36
#include <Mod/Drawing/App/FeaturePage.h>
37
#include <Mod/Part/App/PartFeature.h>
38
#include <Mod/Spreadsheet/App/Sheet.h>
40
#include "TaskDialog.h"
41
#include "TaskOrthoViews.h"
44
using namespace DrawingGui;
48
//===========================================================================
50
//===========================================================================
52
DEF_STD_CMD(CmdDrawingOpen)
54
CmdDrawingOpen::CmdDrawingOpen()
55
: Command("Drawing_Open")
57
sAppModule = "Drawing";
58
sGroup = QT_TR_NOOP("Drawing");
59
sMenuText = QT_TR_NOOP("Open SVG...");
60
sToolTipText = QT_TR_NOOP("Open a scalable vector graphic");
61
sWhatsThis = "Drawing_Open";
62
sStatusTip = sToolTipText;
63
sPixmap = "actions/document-new";
66
void CmdDrawingOpen::activated(int iMsg)
70
QString filename = Gui::FileDialog::getOpenFileName(
72
QObject::tr("Choose an SVG file to open"),
74
QString::fromLatin1("%1 (*.svg *.svgz)").arg(QObject::tr("Scalable Vector Graphic")));
75
if (!filename.isEmpty()) {
76
filename = Base::Tools::escapeEncodeFilename(filename);
77
// load the file with the module
78
Command::doCommand(Command::Gui, "import Drawing, DrawingGui");
79
Command::doCommand(Command::Gui, "DrawingGui.open(\"%s\")", (const char*)filename.toUtf8());
83
//===========================================================================
85
//===========================================================================
87
DEF_STD_CMD_ACL(CmdDrawingNewPage)
89
CmdDrawingNewPage::CmdDrawingNewPage()
90
: Command("Drawing_NewPage")
92
sAppModule = "Drawing";
93
sGroup = QT_TR_NOOP("Drawing");
94
sMenuText = QT_TR_NOOP("Insert new drawing");
95
sToolTipText = QT_TR_NOOP("Insert new drawing");
96
sWhatsThis = "Drawing_NewPage";
97
sStatusTip = sToolTipText;
100
void CmdDrawingNewPage::activated(int iMsg)
102
Gui::ActionGroup* pcAction = qobject_cast<Gui::ActionGroup*>(_pcAction);
103
QAction* a = qAsConst(pcAction)->actions()[iMsg];
105
std::string FeatName = getUniqueObjectName(
106
QCoreApplication::translate("Drawing_NewPage", "Page").toStdString().c_str());
108
QFileInfo tfi(a->property("Template").toString());
109
if (tfi.isReadable()) {
110
QString filename = Base::Tools::escapeEncodeFilename(tfi.filePath());
111
openCommand("Create page");
113
"App.activeDocument().addObject('Drawing::FeaturePage','%s')",
116
"App.activeDocument().%s.Template = '%s'",
118
(const char*)filename.toUtf8());
119
doCommand(Doc, "App.activeDocument().recompute()");
120
doCommand(Doc, "Gui.activeDocument().getObject('%s').show()", FeatName.c_str());
124
QMessageBox::critical(Gui::getMainWindow(),
125
QLatin1String("No template"),
126
QLatin1String("No template available for this page size"));
130
Gui::Action* CmdDrawingNewPage::createAction(void)
132
Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow());
133
pcAction->setDropDownMenu(true);
134
applyCommandData(this->className(), pcAction);
136
QAction* defaultAction = nullptr;
142
std::string path = App::Application::getResourceDir();
143
path += "Mod/Drawing/Templates/";
144
QDir dir(QString::fromUtf8(path.c_str()), QString::fromLatin1("*.svg"));
145
for (unsigned int i = 0; i < dir.count(); i++) {
146
QRegularExpression rx(
147
QString::fromLatin1("(A|B|C|D|E)(\\d)_(Landscape|Portrait)(_.*\\.|\\.)svg$"));
148
auto match = rx.match(dir[i]);
149
if (match.hasMatch()) {
150
QString paper = match.captured(1);
151
int id = match.captured(2).toInt();
152
QString orientation = match.captured(3);
153
QString info = match.captured(4).mid(1);
155
if (!info.isEmpty()) {
156
info[0] = info[0].toUpper();
159
// group by paper size
160
if (!lastPaper.isEmpty()) {
161
if (lastPaper != paper) {
162
QAction* sep = pcAction->addAction(QString());
163
sep->setSeparator(true);
165
else if (lastId != id) {
166
QAction* sep = pcAction->addAction(QString());
167
sep->setSeparator(true);
174
QFile file(QString::fromLatin1(":/icons/actions/drawing-%1-%2%3.svg")
175
.arg(orientation.toLower(), paper)
177
QAction* a = pcAction->addAction(QString());
178
if (file.open(QFile::ReadOnly)) {
179
QByteArray data = file.readAll();
180
a->setIcon(Gui::BitmapFactory().pixmapFromSvg(data, QSize(64, 64)));
183
a->setProperty("TemplatePaper", paper);
184
a->setProperty("TemplateOrientation", orientation);
185
a->setProperty("TemplateId", id);
186
a->setProperty("TemplateInfo", info);
187
a->setProperty("Template", dir.absoluteFilePath(dir[i]));
190
if (!defaultAction) {
191
// set the first found A3 (A3_Landscape) as default
193
defaultId = pcAction->actions().size() - 1;
199
_pcAction = pcAction;
203
pcAction->setIcon(defaultAction->icon());
204
pcAction->setProperty("defaultAction", QVariant(defaultId));
206
else if (!pcAction->actions().isEmpty()) {
207
pcAction->setIcon(qAsConst(pcAction)->actions()[0]->icon());
208
pcAction->setProperty("defaultAction", QVariant(0));
214
void CmdDrawingNewPage::languageChange()
216
Command::languageChange();
221
Gui::ActionGroup* pcAction = qobject_cast<Gui::ActionGroup*>(_pcAction);
222
QList<QAction*> a = pcAction->actions();
223
for (QList<QAction*>::iterator it = a.begin(); it != a.end(); ++it) {
224
if ((*it)->isSeparator()) {
227
QString paper = (*it)->property("TemplatePaper").toString();
228
int id = (*it)->property("TemplateId").toInt();
229
QString orientation = (*it)->property("TemplateOrientation").toString();
230
if (orientation.compare(QLatin1String("landscape"), Qt::CaseInsensitive) == 0) {
231
orientation = QCoreApplication::translate("Drawing_NewPage", "Landscape");
233
else if (orientation.compare(QLatin1String("portrait"), Qt::CaseInsensitive) == 0) {
234
orientation = QCoreApplication::translate("Drawing_NewPage", "Portrait");
236
QString info = (*it)->property("TemplateInfo").toString();
238
if (info.isEmpty()) {
239
(*it)->setText(QCoreApplication::translate("Drawing_NewPage", "%1%2 %3")
240
.arg(paper, QString::number(id), orientation));
242
QCoreApplication::translate("Drawing_NewPage", "Insert new %1%2 %3 drawing")
243
.arg(paper, QString::number(id), orientation));
246
(*it)->setText(QCoreApplication::translate("Drawing_NewPage", "%1%2 %3 (%4)")
247
.arg(paper, QString::number(id), orientation, info));
249
QCoreApplication::translate("Drawing_NewPage", "Insert new %1%2 %3 (%4) drawing")
250
.arg(paper, QString::number(id), orientation, info));
255
bool CmdDrawingNewPage::isActive(void)
257
if (getActiveGuiDocument()) {
265
//===========================================================================
266
// Drawing_NewA3Landscape
267
//===========================================================================
269
DEF_STD_CMD_A(CmdDrawingNewA3Landscape)
271
CmdDrawingNewA3Landscape::CmdDrawingNewA3Landscape()
272
: Command("Drawing_NewA3Landscape")
274
sAppModule = "Drawing";
275
sGroup = QT_TR_NOOP("Drawing");
276
sMenuText = QT_TR_NOOP("Insert new A3 landscape drawing");
277
sToolTipText = QT_TR_NOOP("Insert new A3 landscape drawing");
278
sWhatsThis = "Drawing_NewA3Landscape";
279
sStatusTip = sToolTipText;
280
sPixmap = "actions/drawing-landscape-A3";
283
void CmdDrawingNewA3Landscape::activated(int iMsg)
286
std::string FeatName = getUniqueObjectName("Page");
288
openCommand("Create page");
289
doCommand(Doc, "App.activeDocument().addObject('Drawing::FeaturePage','%s')", FeatName.c_str());
290
doCommand(Doc, "App.activeDocument().%s.Template = 'A3_Landscape.svg'", FeatName.c_str());
291
doCommand(Doc, "App.activeDocument().recompute()");
295
bool CmdDrawingNewA3Landscape::isActive(void)
297
if (getActiveGuiDocument()) {
306
//===========================================================================
308
//===========================================================================
310
DEF_STD_CMD(CmdDrawingNewView)
312
CmdDrawingNewView::CmdDrawingNewView()
313
: Command("Drawing_NewView")
315
sAppModule = "Drawing";
316
sGroup = QT_TR_NOOP("Drawing");
317
sMenuText = QT_TR_NOOP("Insert view in drawing");
318
sToolTipText = QT_TR_NOOP("Insert a new View of a Part in the active drawing");
319
sWhatsThis = "Drawing_NewView";
320
sStatusTip = sToolTipText;
321
sPixmap = "actions/drawing-view";
324
void CmdDrawingNewView::activated(int iMsg)
327
std::vector<App::DocumentObject*> shapes =
328
getSelection().getObjectsOfType(Part::Feature::getClassTypeId());
329
if (shapes.empty()) {
330
QMessageBox::warning(Gui::getMainWindow(),
331
QObject::tr("Wrong selection"),
332
QObject::tr("Select a Part object."));
336
std::vector<App::DocumentObject*> pages =
337
getSelection().getObjectsOfType(Drawing::FeaturePage::getClassTypeId());
339
pages = this->getDocument()->getObjectsOfType(Drawing::FeaturePage::getClassTypeId());
341
QMessageBox::warning(Gui::getMainWindow(),
342
QObject::tr("No page found"),
343
QObject::tr("Create a page first."));
348
const std::vector<App::DocumentObject*> selectedProjections =
349
getSelection().getObjectsOfType(Drawing::FeatureView::getClassTypeId());
352
float newScale = 1.0;
353
float newRotation = 0.0;
354
Base::Vector3d newDirection(0.0, 0.0, 1.0);
355
if (!selectedProjections.empty()) {
356
const Drawing::FeatureView* const myView =
357
static_cast<Drawing::FeatureView*>(selectedProjections.front());
359
newX = myView->X.getValue();
360
newY = myView->Y.getValue();
361
newScale = myView->Scale.getValue();
362
newRotation = myView->Rotation.getValue();
364
// The "Direction" property does not belong to Drawing::FeatureView, but to one of the
365
// many child classes that are projecting objects into the drawing. Therefore, we get the
367
const App::PropertyVector* const propDirection =
368
dynamic_cast<App::PropertyVector*>(myView->getPropertyByName("Direction"));
370
newDirection = propDirection->getValue();
374
std::string PageName = pages.front()->getNameInDocument();
376
openCommand("Create view");
377
for (std::vector<App::DocumentObject*>::iterator it = shapes.begin(); it != shapes.end();
379
std::string FeatName = getUniqueObjectName("View");
381
"App.activeDocument().addObject('Drawing::FeatureViewPart','%s')",
384
"App.activeDocument().%s.Source = App.activeDocument().%s",
386
(*it)->getNameInDocument());
388
"App.activeDocument().%s.Direction = (%e,%e,%e)",
393
doCommand(Doc, "App.activeDocument().%s.X = %e", FeatName.c_str(), newX);
394
doCommand(Doc, "App.activeDocument().%s.Y = %e", FeatName.c_str(), newY);
395
doCommand(Doc, "App.activeDocument().%s.Scale = %e", FeatName.c_str(), newScale);
396
doCommand(Doc, "App.activeDocument().%s.Rotation = %e", FeatName.c_str(), newRotation);
398
"App.activeDocument().%s.addObject(App.activeDocument().%s)",
406
//===========================================================================
408
//===========================================================================
410
DEF_STD_CMD_A(CmdDrawingOrthoViews)
412
CmdDrawingOrthoViews::CmdDrawingOrthoViews()
413
: Command("Drawing_OrthoViews")
415
sAppModule = "Drawing";
416
sGroup = QT_TR_NOOP("Drawing");
417
sMenuText = QT_TR_NOOP("Insert orthographic views");
418
sToolTipText = QT_TR_NOOP("Insert an orthographic projection of a part in the active drawing");
419
sWhatsThis = "Drawing_OrthoView";
420
sStatusTip = sToolTipText;
421
sPixmap = "actions/drawing-orthoviews";
424
void CmdDrawingOrthoViews::activated(int iMsg)
427
const std::vector<App::DocumentObject*> shapes =
428
getSelection().getObjectsOfType(Part::Feature::getClassTypeId());
429
if (shapes.size() != 1) {
430
QMessageBox::warning(Gui::getMainWindow(),
431
QObject::tr("Wrong selection"),
432
QObject::tr("Select exactly one Part object."));
436
// Check that a page object exists. TaskDlgOrthoViews will then check for a selected page object
437
// and use that, otherwise it will use the first page in the document.
438
const std::vector<App::DocumentObject*> pages =
439
this->getDocument()->getObjectsOfType(Drawing::FeaturePage::getClassTypeId());
441
QMessageBox::warning(Gui::getMainWindow(),
442
QObject::tr("No page found"),
443
QObject::tr("Create a page first."));
447
TaskDlgOrthoViews* dlg = new TaskDlgOrthoViews();
448
dlg->setDocumentName(this->getDocument()->getName());
449
Gui::Control().showDialog(dlg);
452
bool CmdDrawingOrthoViews::isActive(void)
454
if (Gui::Control().activeDialog()) {
461
//===========================================================================
462
// Drawing_OpenBrowserView
463
//===========================================================================
465
DEF_STD_CMD_A(CmdDrawingOpenBrowserView)
467
CmdDrawingOpenBrowserView::CmdDrawingOpenBrowserView()
468
: Command("Drawing_OpenBrowserView")
471
sGroup = QT_TR_NOOP("Drawing");
472
sMenuText = QT_TR_NOOP("Open &browser view");
473
sToolTipText = QT_TR_NOOP("Opens the selected page in a browser view");
474
sWhatsThis = "Drawing_OpenBrowserView";
475
sStatusTip = QT_TR_NOOP("Opens the selected page in a browser view");
476
sPixmap = "actions/drawing-openbrowser";
479
void CmdDrawingOpenBrowserView::activated(int iMsg)
482
unsigned int n = getSelection().countObjectsOfType(Drawing::FeaturePage::getClassTypeId());
484
QMessageBox::warning(Gui::getMainWindow(),
485
QObject::tr("Wrong selection"),
486
QObject::tr("Select one Page object."));
489
std::vector<Gui::SelectionSingleton::SelObj> Sel = getSelection().getSelection();
490
doCommand(Doc, "PageName = App.activeDocument().%s.PageResult", Sel[0].FeatName);
491
doCommand(Doc, "import WebGui");
492
doCommand(Doc, "WebGui.openBrowser(PageName)");
495
bool CmdDrawingOpenBrowserView::isActive(void)
497
return (getActiveGuiDocument() ? true : false);
500
//===========================================================================
502
//===========================================================================
504
DEF_STD_CMD_A(CmdDrawingAnnotation)
506
CmdDrawingAnnotation::CmdDrawingAnnotation()
507
: Command("Drawing_Annotation")
510
sGroup = QT_TR_NOOP("Drawing");
511
sMenuText = QT_TR_NOOP("&Annotation");
512
sToolTipText = QT_TR_NOOP("Inserts an Annotation view in the active drawing");
513
sWhatsThis = "Drawing_Annotation";
514
sStatusTip = QT_TR_NOOP("Inserts an Annotation view in the active drawing");
515
sPixmap = "actions/drawing-annotation";
518
void CmdDrawingAnnotation::activated(int iMsg)
521
std::vector<App::DocumentObject*> pages =
522
getSelection().getObjectsOfType(Drawing::FeaturePage::getClassTypeId());
524
pages = this->getDocument()->getObjectsOfType(Drawing::FeaturePage::getClassTypeId());
526
QMessageBox::warning(Gui::getMainWindow(),
527
QObject::tr("No page found"),
528
QObject::tr("Create a page first."));
532
std::string PageName = pages.front()->getNameInDocument();
533
std::string FeatName = getUniqueObjectName("Annotation");
534
openCommand("Create Annotation");
536
"App.activeDocument().addObject('Drawing::FeatureViewAnnotation','%s')",
538
doCommand(Doc, "App.activeDocument().%s.X = 10.0", FeatName.c_str());
539
doCommand(Doc, "App.activeDocument().%s.Y = 10.0", FeatName.c_str());
540
doCommand(Doc, "App.activeDocument().%s.Scale = 7.0", FeatName.c_str());
542
"App.activeDocument().%s.addObject(App.activeDocument().%s)",
549
bool CmdDrawingAnnotation::isActive(void)
551
return (getActiveGuiDocument() ? true : false);
555
//===========================================================================
557
//===========================================================================
559
DEF_STD_CMD_A(CmdDrawingClip)
561
CmdDrawingClip::CmdDrawingClip()
562
: Command("Drawing_Clip")
565
sGroup = QT_TR_NOOP("Drawing");
566
sMenuText = QT_TR_NOOP("&Clip");
567
sToolTipText = QT_TR_NOOP("Inserts a clip group in the active drawing");
568
sWhatsThis = "Drawing_Annotation";
569
sStatusTip = QT_TR_NOOP("Inserts a clip group in the active drawing");
570
sPixmap = "actions/drawing-clip";
573
void CmdDrawingClip::activated(int iMsg)
576
std::vector<App::DocumentObject*> pages =
577
getSelection().getObjectsOfType(Drawing::FeaturePage::getClassTypeId());
579
pages = this->getDocument()->getObjectsOfType(Drawing::FeaturePage::getClassTypeId());
581
QMessageBox::warning(Gui::getMainWindow(),
582
QObject::tr("No page found"),
583
QObject::tr("Create a page first."));
587
std::string PageName = pages.front()->getNameInDocument();
588
std::string FeatName = getUniqueObjectName("Clip");
589
openCommand("Create Clip");
590
doCommand(Doc, "App.activeDocument().addObject('Drawing::FeatureClip','%s')", FeatName.c_str());
592
"App.activeDocument().%s.addObject(App.activeDocument().%s)",
599
bool CmdDrawingClip::isActive(void)
601
return (getActiveGuiDocument() ? true : false);
605
//===========================================================================
607
//===========================================================================
609
DEF_STD_CMD_A(CmdDrawingSymbol)
611
CmdDrawingSymbol::CmdDrawingSymbol()
612
: Command("Drawing_Symbol")
615
sGroup = QT_TR_NOOP("Drawing");
616
sMenuText = QT_TR_NOOP("&Symbol");
617
sToolTipText = QT_TR_NOOP("Inserts a symbol from a svg file in the active drawing");
618
sWhatsThis = "Drawing_Symbol";
619
sStatusTip = QT_TR_NOOP("Inserts a symbol from a svg file in the active drawing");
620
sPixmap = "actions/drawing-symbol";
623
void CmdDrawingSymbol::activated(int iMsg)
626
std::vector<App::DocumentObject*> pages =
627
getSelection().getObjectsOfType(Drawing::FeaturePage::getClassTypeId());
629
pages = this->getDocument()->getObjectsOfType(Drawing::FeaturePage::getClassTypeId());
631
QMessageBox::warning(Gui::getMainWindow(),
632
QObject::tr("No page found"),
633
QObject::tr("Create a page first."));
638
QString filename = Gui::FileDialog::getOpenFileName(
639
Gui::getMainWindow(),
640
QObject::tr("Choose an SVG file to open"),
642
QString::fromLatin1("%1 (*.svg *.svgz)").arg(QObject::tr("Scalable Vector Graphic")));
643
if (!filename.isEmpty()) {
644
std::string PageName = pages.front()->getNameInDocument();
645
std::string FeatName = getUniqueObjectName("Symbol");
646
filename = Base::Tools::escapeEncodeFilename(filename);
647
openCommand("Create Symbol");
648
doCommand(Doc, "import Drawing");
649
doCommand(Doc, "f = open(\"%s\",'r')", (const char*)filename.toUtf8());
650
doCommand(Doc, "svg = f.read()");
651
doCommand(Doc, "f.close()");
653
"App.activeDocument().addObject('Drawing::FeatureViewSymbol','%s')",
656
"App.activeDocument().%s.Symbol = Drawing.removeSvgTags(svg)",
659
"App.activeDocument().%s.addObject(App.activeDocument().%s)",
667
bool CmdDrawingSymbol::isActive(void)
669
return (getActiveGuiDocument() ? true : false);
673
//===========================================================================
675
//===========================================================================
677
DEF_STD_CMD_A(CmdDrawingExportPage)
679
CmdDrawingExportPage::CmdDrawingExportPage()
680
: Command("Drawing_ExportPage")
683
sGroup = QT_TR_NOOP("File");
684
sMenuText = QT_TR_NOOP("&Export page...");
685
sToolTipText = QT_TR_NOOP("Export a page to an SVG file");
686
sWhatsThis = "Drawing_ExportPage";
687
sStatusTip = QT_TR_NOOP("Export a page to an SVG file");
688
sPixmap = "document-save";
691
void CmdDrawingExportPage::activated(int iMsg)
694
unsigned int n = getSelection().countObjectsOfType(Drawing::FeaturePage::getClassTypeId());
696
QMessageBox::warning(Gui::getMainWindow(),
697
QObject::tr("Wrong selection"),
698
QObject::tr("Select one Page object."));
703
filter << QString::fromLatin1("%1 (*.svg)").arg(QObject::tr("Scalable Vector Graphic"));
704
filter << QString::fromLatin1("%1 (*.*)").arg(QObject::tr("All Files"));
706
QString fn = Gui::FileDialog::getSaveFileName(Gui::getMainWindow(),
707
QObject::tr("Export page"),
709
filter.join(QLatin1String(";;")));
711
std::vector<Gui::SelectionSingleton::SelObj> Sel = getSelection().getSelection();
712
openCommand("Drawing export page");
714
doCommand(Doc, "PageFile = open(App.activeDocument().%s.PageResult,'r')", Sel[0].FeatName);
715
std::string fname = (const char*)fn.toUtf8();
716
fname = Base::Tools::escapeEncodeFilename(fname);
717
doCommand(Doc, "OutFile = open(\"%s\",'w')", fname.c_str());
718
doCommand(Doc, "OutFile.write(PageFile.read())");
719
doCommand(Doc, "del OutFile,PageFile");
725
bool CmdDrawingExportPage::isActive(void)
727
return (getActiveGuiDocument() ? true : false);
730
//===========================================================================
731
// Drawing_ProjectShape
732
//===========================================================================
734
DEF_STD_CMD_A(CmdDrawingProjectShape)
736
CmdDrawingProjectShape::CmdDrawingProjectShape()
737
: Command("Drawing_ProjectShape")
740
sGroup = QT_TR_NOOP("Drawing");
741
sMenuText = QT_TR_NOOP("Project shape...");
742
sToolTipText = QT_TR_NOOP("Project shape onto a user-defined plane");
743
sStatusTip = QT_TR_NOOP("Project shape onto a user-defined plane");
744
sWhatsThis = "Drawing_ProjectShape";
747
void CmdDrawingProjectShape::activated(int iMsg)
750
Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog();
752
dlg = new DrawingGui::TaskProjection();
753
dlg->setButtonPosition(Gui::TaskView::TaskDialog::South);
755
Gui::Control().showDialog(dlg);
758
bool CmdDrawingProjectShape::isActive(void)
760
int ct = Gui::Selection().countObjectsOfType(Part::Feature::getClassTypeId());
761
return (ct > 0 && !Gui::Control().activeDialog());
765
//===========================================================================
767
//===========================================================================
769
DEF_STD_CMD_A(CmdDrawingDraftView)
771
CmdDrawingDraftView::CmdDrawingDraftView()
772
: Command("Drawing_DraftView")
775
sGroup = QT_TR_NOOP("Drawing");
776
sMenuText = QT_TR_NOOP("&Draft View");
778
QT_TR_NOOP("Inserts a Draft view of the selected object(s) in the active drawing");
779
sWhatsThis = "Drawing_DraftView";
780
sStatusTip = QT_TR_NOOP("Inserts a Draft view of the selected object(s) in the active drawing");
781
sPixmap = "actions/drawing-draft-view";
784
void CmdDrawingDraftView::activated(int iMsg)
787
addModule(Gui, "Draft");
788
doCommand(Gui, "Gui.runCommand(\"Draft_Drawing\")");
791
bool CmdDrawingDraftView::isActive(void)
793
return (getActiveGuiDocument() ? true : false);
797
//===========================================================================
798
// Drawing_Spreadheet_View
799
//===========================================================================
801
DEF_STD_CMD_A(CmdDrawingSpreadsheetView)
803
CmdDrawingSpreadsheetView::CmdDrawingSpreadsheetView()
804
: Command("Drawing_SpreadsheetView")
807
sGroup = QT_TR_NOOP("Drawing");
808
sMenuText = QT_TR_NOOP("&Spreadsheet View");
809
sToolTipText = QT_TR_NOOP("Inserts a view of a selected spreadsheet in the active drawing");
810
sWhatsThis = "Drawing_SpreadsheetView";
811
sStatusTip = QT_TR_NOOP("Inserts a view of a selected spreadsheet in the active drawing");
812
sPixmap = "actions/drawing-spreadsheet";
815
void CmdDrawingSpreadsheetView::activated(int iMsg)
818
const std::vector<App::DocumentObject*> spreads =
819
getSelection().getObjectsOfType(Spreadsheet::Sheet::getClassTypeId());
820
if (spreads.size() != 1) {
821
QMessageBox::warning(Gui::getMainWindow(),
822
QObject::tr("Wrong selection"),
823
QObject::tr("Select exactly one Spreadsheet object."));
826
const std::vector<App::DocumentObject*> pages =
827
this->getDocument()->getObjectsOfType(Drawing::FeaturePage::getClassTypeId());
829
QMessageBox::warning(Gui::getMainWindow(),
830
QObject::tr("No page found"),
831
QObject::tr("Create a page first."));
834
std::string SpreadName = spreads.front()->getNameInDocument();
835
std::string PageName = pages.front()->getNameInDocument();
836
openCommand("Create spreadsheet view");
837
std::string FeatName = getUniqueObjectName("View");
839
"App.activeDocument().addObject('Drawing::FeatureViewSpreadsheet','%s')",
842
"App.activeDocument().%s.Source = App.activeDocument().%s",
846
"App.activeDocument().%s.addObject(App.activeDocument().%s)",
853
bool CmdDrawingSpreadsheetView::isActive(void)
855
return (getActiveGuiDocument() ? true : false);
859
void CreateDrawingCommands(void)
861
Gui::CommandManager& rcCmdMgr = Gui::Application::Instance->commandManager();
863
rcCmdMgr.addCommand(new CmdDrawingOpen());
864
rcCmdMgr.addCommand(new CmdDrawingNewPage());
865
rcCmdMgr.addCommand(new CmdDrawingNewA3Landscape());
866
rcCmdMgr.addCommand(new CmdDrawingNewView());
867
rcCmdMgr.addCommand(new CmdDrawingOrthoViews());
868
rcCmdMgr.addCommand(new CmdDrawingOpenBrowserView());
869
rcCmdMgr.addCommand(new CmdDrawingAnnotation());
870
rcCmdMgr.addCommand(new CmdDrawingClip());
871
rcCmdMgr.addCommand(new CmdDrawingSymbol());
872
rcCmdMgr.addCommand(new CmdDrawingExportPage());
873
rcCmdMgr.addCommand(new CmdDrawingProjectShape());
874
rcCmdMgr.addCommand(new CmdDrawingDraftView());
875
rcCmdMgr.addCommand(new CmdDrawingSpreadsheetView());