FreeCAD

Форк
0
/
Command.cpp 
1683 строки · 62.7 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2002 Jürgen Riegel <juergen.riegel@web.de>              *
3
 *   Copyright (c) 2014 Luke Parry <l.parry@warwick.ac.uk>                 *
4
 *                                                                         *
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.      *
9
 *                                                                         *
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.                  *
14
 *                                                                         *
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                                *
19
 *                                                                         *
20
 ***************************************************************************/
21

22
#include "PreCompiled.h"
23
#ifndef _PreComp_
24
#include <QApplication>
25
#include <QFileInfo>
26
#include <QMessageBox>
27
#include <vector>
28
#endif
29

30
#include <App/Document.h>
31
#include <App/DocumentObject.h>
32
#include <App/Link.h>
33

34
#include <Base/Console.h>
35
#include <Base/Tools.h>
36

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>
49

50
#include <Mod/Spreadsheet/App/Sheet.h>
51

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>
64

65
#include "DrawGuiUtil.h"
66
#include "MDIViewPage.h"
67
#include "QGIViewPart.h"
68
#include "QGSPage.h"
69
#include "QGVPage.h"
70
#include "Rez.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"
79

80
void execSimpleSection(Gui::Command* cmd);
81
void execComplexSection(Gui::Command* cmd);
82

83
class Vertex;
84
using namespace TechDrawGui;
85
using namespace TechDraw;
86

87
//===========================================================================
88
// TechDraw_PageDefault
89
//===========================================================================
90

91
DEF_STD_CMD_A(CmdTechDrawPageDefault)
92

93
CmdTechDrawPageDefault::CmdTechDrawPageDefault() : Command("TechDraw_PageDefault")
94
{
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";
102
}
103

104
void CmdTechDrawPageDefault::activated(int iMsg)
105
{
106
    Q_UNUSED(iMsg);
107

108
    QString templateFileName = Preferences::defaultTemplate();
109
    QFileInfo tfi(templateFileName);
110
    if (tfi.isReadable()) {
111
        Gui::WaitCursor wc;
112
        openCommand(QT_TRANSLATE_NOOP("Command", "Drawing create page"));
113

114
        auto page = dynamic_cast<TechDraw::DrawPage *>
115
                        (getDocument()->addObject("TechDraw::DrawPage", "Page"));
116
        if (!page) {
117
            throw Base::TypeError("CmdTechDrawPageDefault - page not created");
118
        }
119
        page->translateLabel("DrawPage", "Page", page->getNameInDocument());
120

121
        auto svgTemplate = dynamic_cast<TechDraw::DrawSVGTemplate *>
122
                               (getDocument()->addObject("TechDraw::DrawSVGTemplate", "Template"));
123
        if (!svgTemplate) {
124
            throw Base::TypeError("CmdTechDrawPageDefault - template not created");
125
        }
126
        svgTemplate->translateLabel("DrawSVGTemplate", "Template", svgTemplate->getNameInDocument());
127

128
        page->Template.setValue(svgTemplate);
129
        svgTemplate->Template.setValue(templateFileName.toStdString());
130

131
        updateActive();
132
        commitCommand();
133

134
        TechDrawGui::ViewProviderPage *dvp = dynamic_cast<TechDrawGui::ViewProviderPage *>
135
                                                 (Gui::Application::Instance->getViewProvider(page));
136
        if (dvp) {
137
            dvp->show();
138
        }
139
    }
140
    else {
141
        QMessageBox::critical(Gui::getMainWindow(), QLatin1String("No template"),
142
                              QLatin1String("No default template found"));
143
    }
144
}
145

146
bool CmdTechDrawPageDefault::isActive() { return hasActiveDocument(); }
147

148
//===========================================================================
149
// TechDraw_PageTemplate
150
//===========================================================================
151

152
DEF_STD_CMD_A(CmdTechDrawPageTemplate)
153

154
CmdTechDrawPageTemplate::CmdTechDrawPageTemplate() : Command("TechDraw_PageTemplate")
155
{
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";
163
}
164

165
void CmdTechDrawPageTemplate::activated(int iMsg)
166
{
167
    Q_UNUSED(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
174

175
    if (templateFileName.isEmpty()) {
176
        return;
177
    }
178

179
    QFileInfo tfi(templateFileName);
180
    if (tfi.isReadable()) {
181
        Gui::WaitCursor wc;
182
        openCommand(QT_TRANSLATE_NOOP("Command", "Drawing create page"));
183

184
        auto page = dynamic_cast<TechDraw::DrawPage *>
185
                        (getDocument()->addObject("TechDraw::DrawPage", "Page"));
186
        if (!page) {
187
            throw Base::TypeError("CmdTechDrawPageTemplate - page not created");
188
        }
189
        page->translateLabel("DrawPage", "Page", page->getNameInDocument());
190

191
        auto svgTemplate = dynamic_cast<TechDraw::DrawSVGTemplate *>
192
                               (getDocument()->addObject("TechDraw::DrawSVGTemplate", "Template"));
193
        if (!svgTemplate) {
194
            throw Base::TypeError("CmdTechDrawPageTemplate - template not created");
195
        }
196
        svgTemplate->translateLabel("DrawSVGTemplate", "Template", svgTemplate->getNameInDocument());
197

198
        page->Template.setValue(svgTemplate);
199
        svgTemplate->Template.setValue(templateFileName.toStdString());
200

201
        updateActive();
202
        commitCommand();
203

204
        TechDrawGui::ViewProviderPage *dvp = dynamic_cast<TechDrawGui::ViewProviderPage *>
205
                                                 (Gui::Application::Instance->getViewProvider(page));
206
        if (dvp) {
207
            dvp->show();
208
        }
209
    }
210
    else {
211
        QMessageBox::critical(Gui::getMainWindow(), QLatin1String("No template"),
212
                              QLatin1String("Template file is invalid"));
213
    }
214
}
215

216
bool CmdTechDrawPageTemplate::isActive() { return hasActiveDocument(); }
217

218
//===========================================================================
219
// TechDraw_RedrawPage
220
//===========================================================================
221

222
DEF_STD_CMD_A(CmdTechDrawRedrawPage)
223

224
CmdTechDrawRedrawPage::CmdTechDrawRedrawPage() : Command("TechDraw_RedrawPage")
225
{
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";
233
}
234

235
void CmdTechDrawRedrawPage::activated(int iMsg)
236
{
237
    Q_UNUSED(iMsg);
238
    TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
239
    if (!page) {
240
        return;
241
    }
242
    Gui::WaitCursor wc;
243

244
    page->redrawCommand();
245
}
246

247
bool CmdTechDrawRedrawPage::isActive()
248
{
249
    bool havePage = DrawGuiUtil::needPage(this);
250
    bool haveView = DrawGuiUtil::needView(this, false);
251
    return (havePage && haveView);
252
}
253

254
//===========================================================================
255
// TechDraw_PrintAll
256
//===========================================================================
257

258
DEF_STD_CMD_A(CmdTechDrawPrintAll)
259

260
CmdTechDrawPrintAll::CmdTechDrawPrintAll() : Command("TechDraw_PrintAll")
261
{
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";
269
}
270

271
void CmdTechDrawPrintAll::activated(int iMsg)
272
{
273
    Q_UNUSED(iMsg);
274
    MDIViewPage::printAllPages();
275
}
276

277
bool CmdTechDrawPrintAll::isActive() { return DrawGuiUtil::needPage(this); }
278

279
//===========================================================================
280
// TechDraw_View
281
//===========================================================================
282

283
DEF_STD_CMD_A(CmdTechDrawView)
284

285
CmdTechDrawView::CmdTechDrawView() : Command("TechDraw_View")
286
{
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";
294
}
295

296
void CmdTechDrawView::activated(int iMsg)
297
{
298
    Q_UNUSED(iMsg);
299

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(),
309
                                                   resolve, single);
310
    for (auto& sel : selection) {
311
        bool is_linked = false;
312
        auto obj = sel.getObject();
313
        if (obj->isDerivedFrom(TechDraw::DrawPage::getClassTypeId())) {
314
            continue;
315
        }
316
        if (obj->isDerivedFrom(App::LinkElement::getClassTypeId())
317
            || obj->isDerivedFrom(App::LinkGroup::getClassTypeId())
318
            || obj->isDerivedFrom(App::Link::getClassTypeId())) {
319
            is_linked = true;
320
        }
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()) {
328
                    continue;
329
                }
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
335
                    is_linked = true;
336
                }
337
            }
338
        }
339
        if (is_linked) {
340
            xShapes.push_back(obj);
341
            continue;
342
        }
343
        //not a Link and not null.  assume to be drawable.  Undrawables will be
344
        // skipped later.
345
        shapes.push_back(obj);
346
        if (partObj) {
347
            continue;
348
        }
349
        //don't know if this works for an XLink
350
        for (auto& sub : sel.getSubNames()) {
351
            if (TechDraw::DrawUtil::getGeomTypeFromName(sub) == "Face") {
352
                faceName = sub;
353
                //
354
                partObj = obj;
355
                break;
356
            }
357
        }
358
    }
359

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"));
363
        return;
364
    }
365

366
    TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
367
    if (!page) {
368
        return;
369
    }
370
    std::string PageName = page->getNameInDocument();
371

372
    Base::Vector3d projDir;
373

374
    Gui::WaitCursor wc;
375
    openCommand(QT_TRANSLATE_NOOP("Command", "Create view"));
376
    std::string FeatName = getUniqueObjectName("View");
377
    doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawViewPart', '%s')",
378
              FeatName.c_str());
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(),
382
              FeatName.c_str());
383

384
    App::DocumentObject* docObj = getDocument()->getObject(FeatName.c_str());
385
    TechDraw::DrawViewPart* dvp = dynamic_cast<TechDraw::DrawViewPart*>(docObj);
386
    if (!dvp) {
387
        throw Base::TypeError("CmdTechDrawView DVP not found\n");
388
    }
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);
404
    }
405
    else {
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());
416
    }
417
    commitCommand();
418
}
419

420
bool CmdTechDrawView::isActive() { return DrawGuiUtil::needPage(this); }
421

422
//===========================================================================
423
// TechDraw_ActiveView
424
//===========================================================================
425

426
DEF_STD_CMD_A(CmdTechDrawActiveView)
427

428
CmdTechDrawActiveView::CmdTechDrawActiveView() : Command("TechDraw_ActiveView")
429
{
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";
437
}
438

439
void CmdTechDrawActiveView::activated(int iMsg)
440
{
441
    Q_UNUSED(iMsg);
442
    TechDraw::DrawPage* page = DrawGuiUtil::findPage(this, true);
443
    if (!page) {
444
        return;
445
    }
446
    std::string PageName = page->getNameInDocument();
447
    Gui::Control().showDialog(new TaskDlgActiveView(page));
448
}
449

450
bool CmdTechDrawActiveView::isActive() { return DrawGuiUtil::needPage(this, true); }
451

452
//===========================================================================
453
// TechDraw_SectionGroup
454
//===========================================================================
455

456
DEF_STD_CMD_ACL(CmdTechDrawSectionGroup)
457

458
CmdTechDrawSectionGroup::CmdTechDrawSectionGroup() : Command("TechDraw_SectionGroup")
459
{
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;
466
}
467

468
void CmdTechDrawSectionGroup::activated(int iMsg)
469
{
470
    //    Base::Console().Message("CMD::SectionGrp - activated(%d)\n", iMsg);
471
    Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog();
472
    if (dlg) {
473
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
474
                             QObject::tr("Close active task dialog and try again."));
475
        return;
476
    }
477

478
    Gui::ActionGroup* pcAction = qobject_cast<Gui::ActionGroup*>(_pcAction);
479
    pcAction->setIcon(pcAction->actions().at(iMsg)->icon());
480
    switch (iMsg) {
481
        case 0:
482
            execSimpleSection(this);
483
            break;
484
        case 1:
485
            execComplexSection(this);
486
            break;
487
        default:
488
            Base::Console().Message("CMD::SectionGrp - invalid iMsg: %d\n", iMsg);
489
    };
490
}
491

492
Gui::Action* CmdTechDrawSectionGroup::createAction()
493
{
494
    Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow());
495
    pcAction->setDropDownMenu(true);
496
    applyCommandData(this->className(), pcAction);
497

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"));
506

507
    _pcAction = pcAction;
508
    languageChange();
509

510
    pcAction->setIcon(p1->icon());
511
    int defaultId = 0;
512
    pcAction->setProperty("defaultAction", QVariant(defaultId));
513

514
    return pcAction;
515
}
516

517
void CmdTechDrawSectionGroup::languageChange()
518
{
519
    Command::languageChange();
520

521
    if (!_pcAction)
522
        return;
523
    Gui::ActionGroup* pcAction = qobject_cast<Gui::ActionGroup*>(_pcAction);
524
    QList<QAction*> a = pcAction->actions();
525

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"));
532
    arc2->setToolTip(
533
        QApplication::translate("TechDraw_ComplexSection", "Insert complex Section View"));
534
    arc2->setStatusTip(arc2->toolTip());
535
}
536

537
bool CmdTechDrawSectionGroup::isActive()
538
{
539
    bool havePage = DrawGuiUtil::needPage(this);
540
    bool haveView = DrawGuiUtil::needView(this, false);
541
    return (havePage && haveView);
542
}
543

544
//===========================================================================
545
// TechDraw_SectionView
546
//===========================================================================
547

548
DEF_STD_CMD_A(CmdTechDrawSectionView)
549

550
CmdTechDrawSectionView::CmdTechDrawSectionView() : Command("TechDraw_SectionView")
551
{
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";
559
}
560

561
void CmdTechDrawSectionView::activated(int iMsg)
562
{
563
    Q_UNUSED(iMsg);
564
    Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog();
565
    if (dlg) {
566
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
567
                             QObject::tr("Close active task dialog and try again."));
568
        return;
569
    }
570

571
    execSimpleSection(this);
572
}
573

574
bool CmdTechDrawSectionView::isActive()
575
{
576
    bool havePage = DrawGuiUtil::needPage(this);
577
    bool haveView = DrawGuiUtil::needView(this);
578
    bool taskInProgress = false;
579
    if (havePage) {
580
        taskInProgress = Gui::Control().activeDialog();
581
    }
582
    return (havePage && haveView && !taskInProgress);
583
}
584

585
void execSimpleSection(Gui::Command* cmd)
586
{
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."));
592
        return;
593
    }
594

595
    TechDraw::DrawPage* page = DrawGuiUtil::findPage(cmd);
596
    if (!page) {
597
        return;
598
    }
599

600
    TechDraw::DrawViewPart* dvp = static_cast<TechDraw::DrawViewPart*>(*baseObj.begin());
601
    Gui::Control().showDialog(new TaskDlgSectionView(dvp));
602

603
    cmd->updateActive();//ok here since dialog doesn't call doc.recompute()
604
    cmd->commitCommand();
605
}
606

607
//===========================================================================
608
// TechDraw_ComplexSection
609
//===========================================================================
610

611
DEF_STD_CMD_A(CmdTechDrawComplexSection)
612

613
CmdTechDrawComplexSection::CmdTechDrawComplexSection() : Command("TechDraw_ComplexSection")
614
{
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";
622
}
623

624
void CmdTechDrawComplexSection::activated(int iMsg)
625
{
626
    Q_UNUSED(iMsg);
627
    Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog();
628
    if (dlg) {
629
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
630
                             QObject::tr("Close active task dialog and try again."));
631
        return;
632
    }
633

634
    execComplexSection(this);
635
}
636

637
bool CmdTechDrawComplexSection::isActive() { return DrawGuiUtil::needPage(this); }
638

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)
642
{
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())) {
656
            continue;
657
        }
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();
666
            }
667
            continue;
668
        }
669
        if (obj->isDerivedFrom(App::LinkElement::getClassTypeId())
670
            || obj->isDerivedFrom(App::LinkGroup::getClassTypeId())
671
            || obj->isDerivedFrom(App::Link::getClassTypeId())) {
672
            is_linked = true;
673
        }
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()) {
681
                    continue;
682
                }
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
688
                    is_linked = true;
689
                }
690
            }
691
        }
692
        if (is_linked) {
693
            xShapes.push_back(obj);
694
            continue;
695
        }
696
        //not a Link and not null.  assume to be drawable.  Undrawables will be
697
        // skipped later.
698
        if (TechDraw::DrawComplexSection::isProfileObject(obj)) {
699
            profileObject = obj;
700
        }
701
        else {
702
            shapes.push_back(obj);
703
        }
704
    }
705

706
    if (!baseView) {
707
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
708
                             QObject::tr("I do not know what base view to use."));
709
        return;
710
    }
711

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"));
716
        return;
717
    }
718
    if (!profileObject) {
719
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
720
                             QObject::tr("No profile object found in selection"));
721
        return;
722
    }
723

724
    TechDraw::DrawPage* page = DrawGuiUtil::findPage(cmd);
725
    if (!page) {
726
        return;
727
    }
728

729
    Gui::Control().showDialog(
730
        new TaskDlgComplexSection(page, baseView, shapes, xShapes, profileObject, profileSubs));
731
}
732

733
//===========================================================================
734
// TechDraw_DetailView
735
//===========================================================================
736

737
DEF_STD_CMD_A(CmdTechDrawDetailView)
738

739
CmdTechDrawDetailView::CmdTechDrawDetailView() : Command("TechDraw_DetailView")
740
{
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";
748
}
749

750
void CmdTechDrawDetailView::activated(int iMsg)
751
{
752
    Q_UNUSED(iMsg);
753

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."));
759
        return;
760
    }
761
    TechDraw::DrawViewPart* dvp = static_cast<TechDraw::DrawViewPart*>(*(baseObj.begin()));
762

763
    Gui::Control().showDialog(new TaskDlgDetail(dvp));
764
}
765

766
bool CmdTechDrawDetailView::isActive()
767
{
768
    bool havePage = DrawGuiUtil::needPage(this);
769
    bool haveView = DrawGuiUtil::needView(this);
770
    bool taskInProgress = false;
771
    if (havePage) {
772
        taskInProgress = Gui::Control().activeDialog();
773
    }
774
    return (havePage && haveView && !taskInProgress);
775
}
776

777
//===========================================================================
778
// TechDraw_ProjectionGroup
779
//===========================================================================
780

781
DEF_STD_CMD_A(CmdTechDrawProjectionGroup)
782

783
CmdTechDrawProjectionGroup::CmdTechDrawProjectionGroup() : Command("TechDraw_ProjectionGroup")
784
{
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";
792
}
793

794
void CmdTechDrawProjectionGroup::activated(int iMsg)
795
{
796
    Q_UNUSED(iMsg);
797

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(),
807
                                                   resolve, single);
808
    for (auto& sel : selection) {
809
        bool is_linked = false;
810
        auto obj = sel.getObject();
811
        if (obj->isDerivedFrom(TechDraw::DrawPage::getClassTypeId())) {
812
            continue;
813
        }
814
        if (obj->isDerivedFrom(App::LinkElement::getClassTypeId())
815
            || obj->isDerivedFrom(App::LinkGroup::getClassTypeId())
816
            || obj->isDerivedFrom(App::Link::getClassTypeId())) {
817
            is_linked = true;
818
        }
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()) {
826
                    continue;
827
                }
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
833
                    is_linked = true;
834
                }
835
            }
836
        }
837
        if (is_linked) {
838
            xShapes.push_back(obj);
839
            continue;
840
        }
841
        //not a Link and not null.  assume to be drawable.  Undrawables will be
842
        // skipped later.
843
        shapes.push_back(obj);
844
        if (partObj) {
845
            continue;
846
        }
847
        for (auto& sub : sel.getSubNames()) {
848
            if (TechDraw::DrawUtil::getGeomTypeFromName(sub) == "Face") {
849
                faceName = sub;
850
                partObj = obj;
851
                break;
852
            }
853
        }
854
    }
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"));
858
        return;
859
    }
860

861
    TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
862
    if (!page) {
863
        return;
864
    }
865
    std::string PageName = page->getNameInDocument();
866

867
    Base::Vector3d projDir;
868
    Gui::WaitCursor wc;
869

870
    openCommand(QT_TRANSLATE_NOOP("Command", "Create Projection Group"));
871

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());
877

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());
883

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);
888
        doCommand(Doc,
889
                  "App.activeDocument().%s.Anchor.Direction = FreeCAD.Vector(%.12f, %.12f, %.12f)",
890
                  multiViewName.c_str(), dirs.first.x, dirs.first.y, dirs.first.z);
891
        doCommand(
892
            Doc,
893
            "App.activeDocument().%s.Anchor.RotationVector = FreeCAD.Vector(%.12f, %.12f, %.12f)",
894
            multiViewName.c_str(), dirs.second.x, dirs.second.y, dirs.second.z);
895
        doCommand(Doc,
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);
899
    }
900
    else {
901
        std::pair<Base::Vector3d, Base::Vector3d> dirs = DrawGuiUtil::get3DDirAndRot();
902
        getDocument()->setStatus(App::Document::Status::SkipRecompute, true);
903
        doCommand(Doc,
904
                  "App.activeDocument().%s.Anchor.Direction = FreeCAD.Vector(%.12f, %.12f, %.12f)",
905
                  multiViewName.c_str(), dirs.first.x, dirs.first.y, dirs.first.z);
906
        doCommand(
907
            Doc,
908
            "App.activeDocument().%s.Anchor.RotationVector = FreeCAD.Vector(%.12f, %.12f, %.12f)",
909
            multiViewName.c_str(), dirs.second.x, dirs.second.y, dirs.second.z);
910
        doCommand(Doc,
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);
914
    }
915

916
    doCommand(Doc, "App.activeDocument().%s.Anchor.recompute()", multiViewName.c_str());
917
    commitCommand();
918
    updateActive();
919

920
    // create the rest of the desired views
921
    Gui::Control().showDialog(new TaskDlgProjGroup(multiView, true));
922
}
923

924
bool CmdTechDrawProjectionGroup::isActive()
925
{
926
    bool havePage = DrawGuiUtil::needPage(this);
927
    bool taskInProgress = false;
928
    if (havePage) {
929
        taskInProgress = Gui::Control().activeDialog();
930
    }
931
    return (havePage && !taskInProgress);
932
}
933

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)
937
{
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"));
942
        return false;
943
    }
944

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"));
949
        return false;
950
    }
951

952
    std::vector<App::DocumentObject*> pages =
953
        cmd->getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId());
954
    if (pages.empty()) {
955
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect selection"),
956
                             QObject::tr("Create a page first."));
957
        return false;
958
    }
959
    return true;
960
}
961

962
bool _checkDrawViewPartBalloon(Gui::Command* cmd)
963
{
964
    std::vector<Gui::SelectionObject> selection = cmd->getSelection().getSelectionEx();
965
    auto objFeat(dynamic_cast<TechDraw::DrawViewPart*>(selection[0].getObject()));
966
    if (!objFeat) {
967
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect selection"),
968
                             QObject::tr("No View of a Part in selection."));
969
        return false;
970
    }
971
    return true;
972
}
973

974
bool _checkDirectPlacement(const QGIView* view, const std::vector<std::string>& subNames,
975
                           QPointF& placement)
976
{
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)
981
    //
982
    // Single selected faces are currently not supported, but maybe we could in this case use the center of mass?
983

984
    if (subNames.size() != 1) {
985
        // If nothing or more than one subjects are selected, let the user decide, where to place the balloon
986
        return false;
987
    }
988

989
    const QGIViewPart* viewPart = dynamic_cast<const QGIViewPart*>(view);
990
    if (!viewPart) {
991
        //not a view of a part, so no geometry to attach to
992
        return false;
993
    }
994

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);
1000
        if (vertex) {
1001
            placement = viewPart->mapToScene(Rez::guiX(vertex->x()), Rez::guiX(vertex->y()));
1002
            return true;
1003
        }
1004
    }
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);
1009
        if (geo) {
1010
            Base::Vector3d midPoint(Rez::guiX(geo->getMidPoint()));
1011
            placement = viewPart->mapToScene(midPoint.x, midPoint.y);
1012
            return true;
1013
        }
1014
    }
1015

1016
    return false;
1017
}
1018

1019
DEF_STD_CMD_A(CmdTechDrawBalloon)
1020

1021
CmdTechDrawBalloon::CmdTechDrawBalloon() : Command("TechDraw_Balloon")
1022
{
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";
1030
}
1031

1032
void CmdTechDrawBalloon::activated(int iMsg)
1033
{
1034
    Q_UNUSED(iMsg);
1035
    bool result = _checkSelectionBalloon(this, 1);
1036
    if (!result) {
1037
        return;
1038
    }
1039

1040
    std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx();
1041

1042
    auto objFeat(dynamic_cast<TechDraw::DrawView*>(selection[0].getObject()));
1043
    if (!objFeat) {
1044
        return;
1045
    }
1046

1047
    TechDraw::DrawPage* page = objFeat->findParentPage();
1048
    std::string PageName = page->getNameInDocument();
1049

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));
1054

1055
    if (pageVP && viewVP) {
1056
        QGVPage* viewPage = pageVP->getQGVPage();
1057
        QGSPage* scenePage = pageVP->getQGSPage();
1058
        if (viewPage) {
1059
            viewPage->startBalloonPlacing(objFeat);
1060

1061
            QGIView* view = dynamic_cast<QGIView*>(viewVP->getQView());
1062
            QPointF placement;
1063
            if (view && _checkDirectPlacement(view, selection[0].getSubNames(), placement)) {
1064
                //this creates the balloon if something is already selected
1065
                scenePage->createBalloon(placement, objFeat);
1066
            }
1067
        }
1068
    }
1069
}
1070

1071
bool CmdTechDrawBalloon::isActive()
1072
{
1073
    bool havePage = DrawGuiUtil::needPage(this);
1074
    bool haveView = DrawGuiUtil::needView(this, false);
1075
    bool taskInProgress = Gui::Control().activeDialog();
1076
    return (havePage && haveView && !taskInProgress);
1077
}
1078

1079
//===========================================================================
1080
// TechDraw_ClipGroup
1081
//===========================================================================
1082

1083
DEF_STD_CMD_A(CmdTechDrawClipGroup)
1084

1085
CmdTechDrawClipGroup::CmdTechDrawClipGroup() : Command("TechDraw_ClipGroup")
1086
{
1087
    // setting the
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";
1094
}
1095

1096
void CmdTechDrawClipGroup::activated(int iMsg)
1097
{
1098
    Q_UNUSED(iMsg);
1099
    TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
1100
    if (!page) {
1101
        return;
1102
    }
1103
    std::string PageName = page->getNameInDocument();
1104

1105
    std::string FeatName = getUniqueObjectName("Clip");
1106
    openCommand(QT_TRANSLATE_NOOP("Command", "Create Clip"));
1107
    doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawViewClip', '%s')",
1108
              FeatName.c_str());
1109
    doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", PageName.c_str(),
1110
              FeatName.c_str());
1111
    updateActive();
1112
    commitCommand();
1113
}
1114

1115
bool CmdTechDrawClipGroup::isActive() { return DrawGuiUtil::needPage(this); }
1116

1117
//===========================================================================
1118
// TechDraw_ClipGroupAdd
1119
//===========================================================================
1120

1121
DEF_STD_CMD_A(CmdTechDrawClipGroupAdd)
1122

1123
CmdTechDrawClipGroupAdd::CmdTechDrawClipGroupAdd() : Command("TechDraw_ClipGroupAdd")
1124
{
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";
1131
}
1132

1133
void CmdTechDrawClipGroupAdd::activated(int iMsg)
1134
{
1135
    Q_UNUSED(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."));
1140
        return;
1141
    }
1142

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());
1149
        }
1150
        else if ((*itSel).getObject()->isDerivedFrom(TechDraw::DrawView::getClassTypeId())) {
1151
            view = static_cast<TechDraw::DrawView*>((*itSel).getObject());
1152
        }
1153
    }
1154
    if (!view) {
1155
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
1156
                             QObject::tr("Select exactly one View to add to group."));
1157
        return;
1158
    }
1159
    if (!clip) {
1160
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
1161
                             QObject::tr("Select exactly one Clip group."));
1162
        return;
1163
    }
1164

1165
    TechDraw::DrawPage* pageClip = clip->findParentPage();
1166
    TechDraw::DrawPage* pageView = view->findParentPage();
1167

1168
    if (pageClip != pageView) {
1169
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
1170
                             QObject::tr("Clip and View must be from same Page."));
1171
        return;
1172
    }
1173

1174
    std::string PageName = pageClip->getNameInDocument();
1175
    std::string ClipName = clip->getNameInDocument();
1176
    std::string ViewName = view->getNameInDocument();
1177

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(),
1181
              ViewName.c_str());
1182
    doCommand(Doc, "App.activeDocument().%s.ViewObject.Visibility = True", ViewName.c_str());
1183
    updateActive();
1184
    commitCommand();
1185
}
1186

1187
bool CmdTechDrawClipGroupAdd::isActive()
1188
{
1189
    bool havePage = DrawGuiUtil::needPage(this);
1190
    bool haveClip = false;
1191
    if (havePage) {
1192
        auto drawClipType(TechDraw::DrawViewClip::getClassTypeId());
1193
        auto selClips = getDocument()->getObjectsOfType(drawClipType);
1194
        if (!selClips.empty()) {
1195
            haveClip = true;
1196
        }
1197
    }
1198
    return (havePage && haveClip);
1199
}
1200

1201
//===========================================================================
1202
// TechDraw_ClipGroupRemove
1203
//===========================================================================
1204

1205
DEF_STD_CMD_A(CmdTechDrawClipGroupRemove)
1206

1207
CmdTechDrawClipGroupRemove::CmdTechDrawClipGroupRemove() : Command("TechDraw_ClipGroupRemove")
1208
{
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";
1215
}
1216

1217
void CmdTechDrawClipGroupRemove::activated(int iMsg)
1218
{
1219
    Q_UNUSED(iMsg);
1220
    auto dObj(getSelection().getObjectsOfType(TechDraw::DrawView::getClassTypeId()));
1221
    if (dObj.empty()) {
1222
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
1223
                             QObject::tr("Select exactly one View to remove from Group."));
1224
        return;
1225
    }
1226

1227
    auto view(static_cast<TechDraw::DrawView*>(dObj.front()));
1228

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)) {
1235
            break;
1236
        }
1237
        clip = nullptr;
1238
    }
1239

1240
    if (!clip) {
1241
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
1242
                             QObject::tr("View does not belong to a Clip"));
1243
        return;
1244
    }
1245

1246
    std::string ClipName = clip->getNameInDocument();
1247
    std::string ViewName = view->getNameInDocument();
1248

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(),
1252
              ViewName.c_str());
1253
    doCommand(Doc, "App.activeDocument().%s.ViewObject.Visibility = True", ViewName.c_str());
1254
    updateActive();
1255
    commitCommand();
1256
}
1257

1258
bool CmdTechDrawClipGroupRemove::isActive()
1259
{
1260
    bool havePage = DrawGuiUtil::needPage(this);
1261
    bool haveClip = false;
1262
    if (havePage) {
1263
        auto drawClipType(TechDraw::DrawViewClip::getClassTypeId());
1264
        auto selClips = getDocument()->getObjectsOfType(drawClipType);
1265
        if (!selClips.empty()) {
1266
            haveClip = true;
1267
        }
1268
    }
1269
    return (havePage && haveClip);
1270
}
1271

1272

1273
//===========================================================================
1274
// TechDraw_Symbol
1275
//===========================================================================
1276

1277
DEF_STD_CMD_A(CmdTechDrawSymbol)
1278

1279
CmdTechDrawSymbol::CmdTechDrawSymbol() : Command("TechDraw_Symbol")
1280
{
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";
1288
}
1289

1290
void CmdTechDrawSymbol::activated(int iMsg)
1291
{
1292
    Q_UNUSED(iMsg);
1293
    TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
1294
    if (!page) {
1295
        return;
1296
    }
1297
    std::string PageName = page->getNameInDocument();
1298

1299
    // Reading an image
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")));
1304

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')",
1313
                  FeatName.c_str());
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(),
1318
                  FeatName.c_str());
1319
        updateActive();
1320
        commitCommand();
1321
    }
1322
}
1323

1324
bool CmdTechDrawSymbol::isActive() { return DrawGuiUtil::needPage(this); }
1325

1326
//===========================================================================
1327
// TechDraw_DraftView
1328
//===========================================================================
1329

1330
DEF_STD_CMD_A(CmdTechDrawDraftView)
1331

1332
CmdTechDrawDraftView::CmdTechDrawDraftView() : Command("TechDraw_DraftView")
1333
{
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";
1341
}
1342

1343
void CmdTechDrawDraftView::activated(int iMsg)
1344
{
1345
    Q_UNUSED(iMsg);
1346

1347
    std::vector<App::DocumentObject*> objects =
1348
        getSelection().getObjectsOfType(App::DocumentObject::getClassTypeId());
1349

1350
    if (objects.empty()) {
1351
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
1352
                             QObject::tr("Select at least one object."));
1353
        return;
1354
    }
1355

1356
    TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
1357
    if (!page) {
1358
        return;
1359
    }
1360
    std::string PageName = page->getNameInDocument();
1361

1362
    std::pair<Base::Vector3d, Base::Vector3d> dirs = DrawGuiUtil::get3DDirAndRot();
1363
    for (std::vector<App::DocumentObject*>::iterator it = objects.begin(); it != objects.end();
1364
         ++it) {
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
1368
            continue;
1369
        }
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')",
1374
                  FeatName.c_str());
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(),
1380
                  FeatName.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);
1383
        updateActive();
1384
        commitCommand();
1385
    }
1386
}
1387

1388
bool CmdTechDrawDraftView::isActive() { return DrawGuiUtil::needPage(this); }
1389

1390
//===========================================================================
1391
// TechDraw_ArchView
1392
//===========================================================================
1393

1394
DEF_STD_CMD_A(CmdTechDrawArchView)
1395

1396
CmdTechDrawArchView::CmdTechDrawArchView() : Command("TechDraw_ArchView")
1397
{
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";
1405
}
1406

1407
void CmdTechDrawArchView::activated(int iMsg)
1408
{
1409
    Q_UNUSED(iMsg);
1410

1411
    const std::vector<App::DocumentObject*> objects =
1412
        getSelection().getObjectsOfType(App::DocumentObject::getClassTypeId());
1413
    App::DocumentObject* archObject = nullptr;
1414
    int archCount = 0;
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
1419
            continue;
1420
        }
1421
        if (DrawGuiUtil::isArchSection(obj)) {
1422
            archCount++;
1423
            archObject = obj;
1424
        }
1425
    }
1426
    if (archCount > 1) {
1427
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
1428
                             QObject::tr("Please select only 1 Arch Section."));
1429
        return;
1430
    }
1431

1432
    if (!archObject) {
1433
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
1434
                             QObject::tr("No Arch Sections in selection."));
1435
        return;
1436
    }
1437

1438
    TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
1439
    if (!page) {
1440
        return;
1441
    }
1442
    std::string PageName = page->getNameInDocument();
1443

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')",
1448
              FeatName.c_str());
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(),
1454
              FeatName.c_str());
1455
    updateActive();
1456
    commitCommand();
1457
}
1458

1459
bool CmdTechDrawArchView::isActive() { return DrawGuiUtil::needPage(this); }
1460

1461
//===========================================================================
1462
// TechDraw_SpreadsheetView
1463
//===========================================================================
1464

1465
DEF_STD_CMD_A(CmdTechDrawSpreadsheetView)
1466

1467
CmdTechDrawSpreadsheetView::CmdTechDrawSpreadsheetView() : Command("TechDraw_SpreadsheetView")
1468
{
1469
    // setting the
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";
1476
}
1477

1478
void CmdTechDrawSpreadsheetView::activated(int iMsg)
1479
{
1480
    Q_UNUSED(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."));
1486
        return;
1487
    }
1488
    std::string SpreadName = spreads.front()->getNameInDocument();
1489

1490
    TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
1491
    if (!page) {
1492
        return;
1493
    }
1494
    std::string PageName = page->getNameInDocument();
1495

1496
    openCommand(QT_TRANSLATE_NOOP("Command", "Create spreadsheet view"));
1497
    std::string FeatName = getUniqueObjectName("Sheet");
1498
    doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawViewSpreadsheet', '%s')",
1499
              FeatName.c_str());
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(),
1505
              FeatName.c_str());
1506
    updateActive();
1507
    commitCommand();
1508
}
1509

1510
bool CmdTechDrawSpreadsheetView::isActive()
1511
{
1512
    //need a Page and a SpreadSheet::Sheet
1513
    bool havePage = DrawGuiUtil::needPage(this);
1514
    bool haveSheet = false;
1515
    if (havePage) {
1516
        auto spreadSheetType(Spreadsheet::Sheet::getClassTypeId());
1517
        auto selSheets = getDocument()->getObjectsOfType(spreadSheetType);
1518
        if (!selSheets.empty()) {
1519
            haveSheet = true;
1520
        }
1521
    }
1522
    return (havePage && haveSheet);
1523
}
1524

1525

1526
//===========================================================================
1527
// TechDraw_ExportPageSVG
1528
//===========================================================================
1529

1530
DEF_STD_CMD_A(CmdTechDrawExportPageSVG)
1531

1532
CmdTechDrawExportPageSVG::CmdTechDrawExportPageSVG() : Command("TechDraw_ExportPageSVG")
1533
{
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";
1540
}
1541

1542
void CmdTechDrawExportPageSVG::activated(int iMsg)
1543
{
1544
    Q_UNUSED(iMsg);
1545
    TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
1546
    if (!page) {
1547
        return;
1548
    }
1549
    std::string PageName = page->getNameInDocument();
1550

1551
    Gui::Document* activeGui = Gui::Application::Instance->getDocument(page->getDocument());
1552
    Gui::ViewProvider* vp = activeGui->getViewProvider(page);
1553
    ViewProviderPage* dvp = dynamic_cast<ViewProviderPage*>(vp);
1554

1555
    if (dvp && dvp->getMDIViewPage()) {
1556
        dvp->getMDIViewPage()->saveSVG();
1557
    }
1558
    else {
1559
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No Drawing View"),
1560
                             QObject::tr("Open Drawing View before attempting export to SVG."));
1561
        return;
1562
    }
1563
}
1564

1565
bool CmdTechDrawExportPageSVG::isActive() { return DrawGuiUtil::needPage(this); }
1566

1567
//===========================================================================
1568
// TechDraw_ExportPageDXF
1569
//===========================================================================
1570

1571
DEF_STD_CMD_A(CmdTechDrawExportPageDXF)
1572

1573
CmdTechDrawExportPageDXF::CmdTechDrawExportPageDXF() : Command("TechDraw_ExportPageDXF")
1574
{
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";
1581
}
1582

1583
void CmdTechDrawExportPageDXF::activated(int iMsg)
1584
{
1585
    Q_UNUSED(iMsg);
1586
    TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
1587
    if (!page) {
1588
        return;
1589
    }
1590

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) {
1599
                return;
1600
            }
1601
            else {
1602
                break;
1603
            }
1604
        }
1605
    }
1606

1607
    //WF? allow more than one TD Page per Dxf file??  1 TD page = 1 DXF file = 1 drawing?
1608
    QString defaultDir;
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)")));
1612

1613
    if (fileName.isEmpty()) {
1614
        return;
1615
    }
1616

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());
1623
    commitCommand();
1624
}
1625

1626

1627
bool CmdTechDrawExportPageDXF::isActive() { return DrawGuiUtil::needPage(this); }
1628

1629
//===========================================================================
1630
// TechDraw_ProjectShape
1631
//===========================================================================
1632

1633
DEF_STD_CMD_A(CmdTechDrawProjectShape)
1634

1635
CmdTechDrawProjectShape::CmdTechDrawProjectShape() : Command("TechDraw_ProjectShape")
1636
{
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";
1644
}
1645

1646
void CmdTechDrawProjectShape::activated(int iMsg)
1647
{
1648
    Q_UNUSED(iMsg);
1649
    Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog();
1650
    if (!dlg) {
1651
        Gui::Control().showDialog(new TaskDlgProjection());
1652
    }
1653
}
1654

1655
bool CmdTechDrawProjectShape::isActive() { return true; }
1656

1657
void CreateTechDrawCommands()
1658
{
1659
    Gui::CommandManager& rcCmdMgr = Gui::Application::Instance->commandManager();
1660

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());
1683
}
1684

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.