FreeCAD

Форк
0
/
CommandAnnotate.cpp 
1731 строка · 61.3 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2019 WandererFan <wandererfan@gmail.com>                *
3
 *                                                                         *
4
 *   This file is part of the FreeCAD CAx development system.              *
5
 *                                                                         *
6
 *   This library is free software; you can redistribute it and/or         *
7
 *   modify it under the terms of the GNU Library General Public           *
8
 *   License as published by the Free Software Foundation; either          *
9
 *   version 2 of the License, or (at your option) any later version.      *
10
 *                                                                         *
11
 *   This library  is distributed in the hope that it will be useful,      *
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14
 *   GNU Library General Public License for more details.                  *
15
 *                                                                         *
16
 *   You should have received a copy of the GNU Library General Public     *
17
 *   License along with this library; see the file COPYING.LIB. If not,    *
18
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
19
 *   Suite 330, Boston, MA  02111-1307, USA                                *
20
 *                                                                         *
21
 ***************************************************************************/
22

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

30
#include <App/DocumentObject.h>
31
#include <Gui/Action.h>
32
#include <Gui/Application.h>
33
#include <Gui/BitmapFactory.h>
34
#include <Gui/Command.h>
35
#include <Gui/Control.h>
36
#include <Gui/MainWindow.h>
37
#include <Gui/Selection.h>
38
#include <Gui/SelectionObject.h>
39
#include <Gui/ViewProvider.h>
40
#include <Mod/TechDraw/App/Cosmetic.h>
41
#include <Mod/TechDraw/App/Geometry.h>
42
#include <Mod/TechDraw/App/DrawLeaderLine.h>
43
#include <Mod/TechDraw/App/DrawPage.h>
44
#include <Mod/TechDraw/App/DrawView.h>
45
#include <Mod/TechDraw/App/DrawViewAnnotation.h>
46
#include <Mod/TechDraw/App/DrawViewPart.h>
47
#include <Mod/TechDraw/App/DrawViewSymbol.h>
48
#include <Mod/TechDraw/App/DrawWeldSymbol.h>
49
#include <Mod/TechDraw/App/DrawUtil.h>
50

51
#include "DrawGuiUtil.h"
52
#include "QGIView.h"
53
#include "TaskCenterLine.h"
54
#include "TaskCosmeticLine.h"
55
#include "TaskCosVertex.h"
56
#include "TaskLeaderLine.h"
57
#include "TaskLineDecor.h"
58
#include "TaskRichAnno.h"
59
#include "TaskSurfaceFinishSymbols.h"
60
#include "TaskWeldingSymbol.h"
61
#include "TaskCosmeticCircle.h"
62
#include "ViewProviderViewPart.h"
63

64

65
using namespace TechDrawGui;
66
using namespace TechDraw;
67

68
//internal functions
69
bool _checkSelectionHatch(Gui::Command* cmd);
70

71
void execCosmeticVertex(Gui::Command* cmd);
72
void execMidpoints(Gui::Command* cmd);
73
void execQuadrants(Gui::Command* cmd);
74
void execCenterLine(Gui::Command* cmd);
75
void exec2LineCenterLine(Gui::Command* cmd);
76
void exec2PointCenterLine(Gui::Command* cmd);
77
void execLine2Points(Gui::Command* cmd);
78
void execCosmeticCircle(Gui::Command* cmd);
79
std::vector<std::string> getSelectedSubElements(Gui::Command* cmd,
80
                                                TechDraw::DrawViewPart* &dvp,
81
                                                std::string subType = "Edge");
82

83
//===========================================================================
84
// TechDraw_Leader
85
//===========================================================================
86

87
DEF_STD_CMD_A(CmdTechDrawLeaderLine)
88

89
CmdTechDrawLeaderLine::CmdTechDrawLeaderLine()
90
  : Command("TechDraw_LeaderLine")
91
{
92
    sAppModule      = "TechDraw";
93
    sGroup          = QT_TR_NOOP("TechDraw");
94
    sMenuText       = QT_TR_NOOP("Add Leaderline to View");
95
    sToolTipText    = sMenuText;
96
    sWhatsThis      = "TechDraw_LeaderLine";
97
    sStatusTip      = sToolTipText;
98
    sPixmap         = "actions/TechDraw_LeaderLine";
99
}
100

101
void CmdTechDrawLeaderLine::activated(int iMsg)
102
{
103
    Q_UNUSED(iMsg);
104

105
    Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
106
    if (dlg) {
107
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
108
            QObject::tr("Close active task dialog and try again."));
109
        return;
110
    }
111

112
    TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
113
    if (!page) {
114
        return;
115
    }
116

117
    std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx();
118
    TechDraw::DrawView* baseFeat = nullptr;
119
    if (!selection.empty()) {
120
        baseFeat =  dynamic_cast<TechDraw::DrawView *>(selection[0].getObject());
121
        if (!baseFeat) {
122
            QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
123
                                 QObject::tr("Can not attach leader.  No base View selected."));
124
            return;
125
        }
126
    } else {
127
            QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
128
                                 QObject::tr("You must select a base View for the line."));
129
            return;
130
    }
131

132
    Gui::Control().showDialog(new TechDrawGui::TaskDlgLeaderLine(baseFeat,
133
                                                                 page));
134
    updateActive();
135
    Gui::Selection().clearSelection();
136
}
137

138
bool CmdTechDrawLeaderLine::isActive()
139
{
140
    bool havePage = DrawGuiUtil::needPage(this);
141
    bool haveView = DrawGuiUtil::needView(this, false);
142
    return (havePage && haveView);
143
}
144

145
//===========================================================================
146
// TechDraw_RichTextAnnotation
147
//===========================================================================
148

149
DEF_STD_CMD_A(CmdTechDrawRichTextAnnotation)
150

151
CmdTechDrawRichTextAnnotation::CmdTechDrawRichTextAnnotation()
152
  : Command("TechDraw_RichTextAnnotation")
153
{
154
    sAppModule      = "TechDraw";
155
    sGroup          = QT_TR_NOOP("TechDraw");
156
    sMenuText       = QT_TR_NOOP("Insert Rich Text Annotation");
157
    sToolTipText    = sMenuText;
158
    sWhatsThis      = "TechDraw_RichTextAnnotation";
159
    sStatusTip      = sToolTipText;
160
    sPixmap         = "actions/TechDraw_RichTextAnnotation";
161
}
162

163
void CmdTechDrawRichTextAnnotation::activated(int iMsg)
164
{
165
    Q_UNUSED(iMsg);
166
    Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
167
    if (dlg) {
168
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
169
            QObject::tr("Close active task dialog and try again."));
170
        return;
171
    }
172

173
    TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
174
    if (!page) {
175
        return;
176
    }
177

178
    std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx();
179
    TechDraw::DrawView* baseFeat = nullptr;
180
    if (!selection.empty()) {
181
        baseFeat =  dynamic_cast<TechDraw::DrawView *>(selection[0].getObject());
182
    }
183

184
    Gui::Control().showDialog(new TaskDlgRichAnno(baseFeat,
185
                                                  page));
186
    updateActive();
187
    Gui::Selection().clearSelection();
188
}
189

190
bool CmdTechDrawRichTextAnnotation::isActive()
191
{
192
    bool havePage = DrawGuiUtil::needPage(this);
193
    return havePage;
194
}
195

196

197
//===========================================================================
198
// TechDraw_CosmeticVertexGroup
199
//===========================================================================
200

201
DEF_STD_CMD_ACL(CmdTechDrawCosmeticVertexGroup)
202

203
CmdTechDrawCosmeticVertexGroup::CmdTechDrawCosmeticVertexGroup()
204
  : Command("TechDraw_CosmeticVertexGroup")
205
{
206
    sAppModule      = "TechDraw";
207
    sGroup          = QT_TR_NOOP("TechDraw");
208
    sMenuText       = QT_TR_NOOP("Insert Cosmetic Vertex");
209
    sToolTipText    = sMenuText;
210
    sWhatsThis      = "TechDraw_CosmeticVertexGroup";
211
    sStatusTip      = sToolTipText;
212
//    eType           = ForEdit;
213
}
214

215
void CmdTechDrawCosmeticVertexGroup::activated(int iMsg)
216
{
217
//    Base::Console().Message("CMD::CosmeticVertexGroup - activated(%d)\n", iMsg);
218
    Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
219
    if (dlg) {
220
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
221
            QObject::tr("Close active task dialog and try again."));
222
        return;
223
    }
224

225
    Gui::ActionGroup* pcAction = qobject_cast<Gui::ActionGroup*>(_pcAction);
226
    pcAction->setIcon(pcAction->actions().at(iMsg)->icon());
227
    switch(iMsg) {
228
        case 0:
229
            execCosmeticVertex(this);
230
            break;
231
        case 1:
232
            execMidpoints(this);
233
            break;
234
        case 2:
235
            execQuadrants(this);
236
            break;
237
        default:
238
            Base::Console().Message("CMD::CVGrp - invalid iMsg: %d\n", iMsg);
239
    };
240
    updateActive();
241
    Gui::Selection().clearSelection();
242
}
243

244
Gui::Action * CmdTechDrawCosmeticVertexGroup::createAction()
245
{
246
    Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow());
247
    pcAction->setDropDownMenu(true);
248
    applyCommandData(this->className(), pcAction);
249

250
    QAction* p1 = pcAction->addAction(QString());
251
    p1->setIcon(Gui::BitmapFactory().iconFromTheme("actions/TechDraw_CosmeticVertex"));
252
    p1->setObjectName(QString::fromLatin1("TechDraw_CosmeticVertex"));
253
    p1->setWhatsThis(QString::fromLatin1("TechDraw_CosmeticVertex"));
254
    QAction* p2 = pcAction->addAction(QString());
255
    p2->setIcon(Gui::BitmapFactory().iconFromTheme("actions/TechDraw_Midpoints"));
256
    p2->setObjectName(QString::fromLatin1("TechDraw_Midpoints"));
257
    p2->setWhatsThis(QString::fromLatin1("TechDraw_Midpoints"));
258
    QAction* p3 = pcAction->addAction(QString());
259
    p3->setIcon(Gui::BitmapFactory().iconFromTheme("actions/TechDraw_Quadrants"));
260
    p3->setObjectName(QString::fromLatin1("TechDraw_Quadrants"));
261
    p3->setWhatsThis(QString::fromLatin1("TechDraw_Quadrants"));
262

263
    _pcAction = pcAction;
264
    languageChange();
265

266
    pcAction->setIcon(p1->icon());
267
    int defaultId = 0;
268
    pcAction->setProperty("defaultAction", QVariant(defaultId));
269

270
    return pcAction;
271
}
272

273
void CmdTechDrawCosmeticVertexGroup::languageChange()
274
{
275
    Command::languageChange();
276

277
    if (!_pcAction)
278
        return;
279
    Gui::ActionGroup* pcAction = qobject_cast<Gui::ActionGroup*>(_pcAction);
280
    QList<QAction*> a = pcAction->actions();
281

282
    QAction* arc1 = a[0];
283
    arc1->setText(QApplication::translate("CmdTechDrawCosmeticVertexGroup", "Add Cosmetic Vertex"));
284
    arc1->setToolTip(QApplication::translate("TechDraw_CosmeticVertex", "Inserts a Cosmetic Vertex into a View"));
285
    arc1->setStatusTip(arc1->toolTip());
286
    QAction* arc2 = a[1];
287
    arc2->setText(QApplication::translate("CmdMidpoints", "Add Midpoint Vertices"));
288
    arc2->setToolTip(QApplication::translate("TechDraw_Midpoints", "Inserts Cosmetic Vertices at Midpoint of selected Edges"));
289
    arc2->setStatusTip(arc2->toolTip());
290
    QAction* arc3 = a[2];
291
    arc3->setText(QApplication::translate("CmdQuadrants", "Add Quadrant Vertices"));
292
    arc3->setToolTip(QApplication::translate("TechDraw_Quadrants", "Inserts Cosmetic Vertices at Quadrant Points of selected Circles"));
293
    arc3->setStatusTip(arc3->toolTip());
294
}
295

296
bool CmdTechDrawCosmeticVertexGroup::isActive()
297
{
298
    bool havePage = DrawGuiUtil::needPage(this);
299
    bool haveView = DrawGuiUtil::needView(this, true);
300
    return (havePage && haveView);
301
}
302

303

304
//===========================================================================
305
// TechDraw_CosmeticVertex
306
//===========================================================================
307

308
void execCosmeticVertex(Gui::Command* cmd)
309
{
310
//    Base::Console().Message("execCosmeticVertex()\n");
311
    TechDraw::DrawPage* page = DrawGuiUtil::findPage(cmd);
312
    if (!page) {
313
        return;
314
    }
315

316
    std::vector<App::DocumentObject*> shapes = cmd->getSelection().
317
                                       getObjectsOfType(TechDraw::DrawViewPart::getClassTypeId());
318
    if (shapes.empty()) {
319
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
320
            QObject::tr("No DrawViewPart objects in this selection"));
321
        return;
322
    }
323

324
    //shapes not empty and only contains dvp
325
    TechDraw::DrawViewPart* baseFeat = nullptr;
326
    baseFeat =  dynamic_cast<TechDraw::DrawViewPart*>((*shapes.begin()));
327

328
    Gui::Control().showDialog(new TaskDlgCosVertex(baseFeat,
329
                                                   page));
330
}
331

332
void execMidpoints(Gui::Command* cmd)
333
{
334
//    Base::Console().Message("execMidpoints()\n");
335
    TechDraw::DrawViewPart * dvp = nullptr;
336
    std::vector<std::string> selectedEdges = getSelectedSubElements(cmd, dvp, "Edge");
337

338
    if (!dvp || selectedEdges.empty())
339
        return;
340

341
    Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Add Midpoint Vertices"));
342

343
    const TechDraw::BaseGeomPtrVector edges = dvp->getEdgeGeometry();
344
    for (auto& s: selectedEdges) {
345
        int GeoId(TechDraw::DrawUtil::getIndexFromName(s));
346
        TechDraw::BaseGeomPtr geom = edges.at(GeoId);
347
        Base::Vector3d mid = geom->getMidPoint();
348
        // invert the point so the math works correctly
349
        mid = DrawUtil::invertY(mid);
350
        mid = CosmeticVertex::makeCanonicalPoint(dvp, mid);
351
        dvp->addCosmeticVertex(mid);
352
    }
353

354
    Gui::Command::commitCommand();
355

356
    dvp->recomputeFeature();
357
}
358

359
void execQuadrants(Gui::Command* cmd)
360
{
361
//    Base::Console().Message("execQuadrants()\n");
362
    TechDraw::DrawViewPart* dvp = nullptr;
363
    std::vector<std::string> selectedEdges = getSelectedSubElements(cmd, dvp, "Edge");
364

365
    if (!dvp || selectedEdges.empty())
366
        return;
367

368
    Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Add Quadrant Vertices"));
369

370
    const TechDraw::BaseGeomPtrVector edges = dvp->getEdgeGeometry();
371
    for (auto& s: selectedEdges) {
372
        int GeoId(TechDraw::DrawUtil::getIndexFromName(s));
373
        TechDraw::BaseGeomPtr geom = edges.at(GeoId);
374
        std::vector<Base::Vector3d> quads = geom->getQuads();
375
        for (auto& q: quads) {
376
            // invert the point so the math works correctly
377
            Base::Vector3d iq = DrawUtil::invertY(q);
378
            iq = CosmeticVertex::makeCanonicalPoint(dvp, iq);
379
            dvp->addCosmeticVertex(iq);
380
        }
381
    }
382

383
    Gui::Command::commitCommand();
384

385
    dvp->recomputeFeature();
386
}
387

388
DEF_STD_CMD_A(CmdTechDrawCosmeticVertex)
389

390
CmdTechDrawCosmeticVertex::CmdTechDrawCosmeticVertex()
391
  : Command("TechDraw_CosmeticVertex")
392
{
393
    sAppModule      = "TechDraw";
394
    sGroup          = QT_TR_NOOP("TechDraw");
395
    sMenuText       = QT_TR_NOOP("Add Cosmetic Vertex");
396
    sToolTipText    = sMenuText;
397
    sWhatsThis      = "TechDraw_CosmeticVertex";
398
    sStatusTip      = sToolTipText;
399
    sPixmap         = "actions/TechDraw_CosmeticVertex";
400
}
401

402
void CmdTechDrawCosmeticVertex::activated(int iMsg)
403
{
404
    Q_UNUSED(iMsg);
405
    Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
406
    if (dlg) {
407
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
408
            QObject::tr("Close active task dialog and try again."));
409
        return;
410
    }
411

412
    TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
413
    if (!page) {
414
        return;
415
    }
416

417
    std::vector<App::DocumentObject*> shapes = getSelection().
418
                                       getObjectsOfType(TechDraw::DrawViewPart::getClassTypeId());
419
    if (shapes.empty()) {
420
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
421
            QObject::tr("No DrawViewPart objects in this selection"));
422
        return;
423
    }
424

425
    TechDraw::DrawViewPart* baseFeat = nullptr;
426
    baseFeat =  dynamic_cast<TechDraw::DrawViewPart*>((*shapes.begin()));
427
    if (!baseFeat) {
428
        Base::Console().Message("CMD::CosmeticVertex - 1st shape is not DVP.  WTF?\n");
429
        return;
430
    }
431

432
    Gui::Control().showDialog(new TaskDlgCosVertex(baseFeat,
433
                                                   page));
434
    updateActive();
435
    Gui::Selection().clearSelection();
436
}
437

438
bool CmdTechDrawCosmeticVertex::isActive()
439
{
440
    bool havePage = DrawGuiUtil::needPage(this);
441
    bool haveView = DrawGuiUtil::needView(this, true);
442
    return (havePage && haveView);
443
}
444

445
//===========================================================================
446
// TechDraw_Midpoints
447
//===========================================================================
448

449
DEF_STD_CMD_A(CmdTechDrawMidpoints)
450

451
CmdTechDrawMidpoints::CmdTechDrawMidpoints()
452
  : Command("TechDraw_Midpoints")
453
{
454
    sAppModule      = "TechDraw";
455
    sGroup          = QT_TR_NOOP("TechDraw");
456
    sMenuText       = QT_TR_NOOP("Add Midpoint Vertices");
457
    sToolTipText    = sMenuText;
458
    sWhatsThis      = "TechDraw_Midpoints";
459
    sStatusTip      = sToolTipText;
460
    sPixmap         = "actions/TechDraw_Midpoints";
461
}
462

463
void CmdTechDrawMidpoints::activated(int iMsg)
464
{
465
    Q_UNUSED(iMsg);
466
    Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
467
    if (dlg) {
468
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
469
            QObject::tr("Close active task dialog and try again."));
470
        return;
471
    }
472
    execMidpoints(this);
473
    updateActive();
474
    Gui::Selection().clearSelection();
475
}
476

477
bool CmdTechDrawMidpoints::isActive()
478
{
479
    bool havePage = DrawGuiUtil::needPage(this);
480
    bool haveView = DrawGuiUtil::needView(this, true);
481
    return (havePage && haveView);
482
}
483

484
//===========================================================================
485
// TechDraw_Quadrants
486
//===========================================================================
487

488
DEF_STD_CMD_A(CmdTechDrawQuadrants)
489

490
CmdTechDrawQuadrants::CmdTechDrawQuadrants()
491
  : Command("TechDraw_Quadrants")
492
{
493
    sAppModule      = "TechDraw";
494
    sGroup          = QT_TR_NOOP("TechDraw");
495
    sMenuText       = QT_TR_NOOP("Add Quadrant Vertices");
496
    sToolTipText    = sMenuText;
497
    sWhatsThis      = "TechDraw_Quadrants";
498
    sStatusTip      = sToolTipText;
499
    sPixmap         = "actions/TechDraw_Quadrants";
500
}
501

502
void CmdTechDrawQuadrants::activated(int iMsg)
503
{
504
    Q_UNUSED(iMsg);
505
    Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
506
    if (dlg) {
507
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
508
            QObject::tr("Close active task dialog and try again."));
509
        return;
510
    }
511
    execQuadrants(this);
512
    updateActive();
513
    Gui::Selection().clearSelection();
514
}
515

516
bool CmdTechDrawQuadrants::isActive()
517
{
518
    bool havePage = DrawGuiUtil::needPage(this);
519
    bool haveView = DrawGuiUtil::needView(this, true);
520
    return (havePage && haveView);
521
}
522

523
//===========================================================================
524
// TechDraw_Annotation
525
//===========================================================================
526

527
DEF_STD_CMD_A(CmdTechDrawAnnotation)
528

529
CmdTechDrawAnnotation::CmdTechDrawAnnotation()
530
  : Command("TechDraw_Annotation")
531
{
532
    // setting the Gui eye-candy
533
    sGroup        = QT_TR_NOOP("TechDraw");
534
    sMenuText     = QT_TR_NOOP("Insert Annotation");
535
    sToolTipText  = sMenuText;
536
    sWhatsThis    = "TechDraw_NewAnnotation";
537
    sStatusTip    = sToolTipText;
538
    sPixmap       = "actions/TechDraw_Annotation";
539
}
540

541
void CmdTechDrawAnnotation::activated(int iMsg)
542
{
543
    Q_UNUSED(iMsg);
544
    TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
545
    if (!page) {
546
        return;
547
    }
548
    std::string PageName = page->getNameInDocument();
549

550
    std::string FeatName = getUniqueObjectName("Annotation");
551
    openCommand(QT_TRANSLATE_NOOP("Command", "Create Annotation"));
552
    doCommand(Doc, "App.activeDocument().addObject('TechDraw::DrawViewAnnotation', '%s')", FeatName.c_str());
553
    doCommand(Doc, "App.activeDocument().%s.translateLabel('DrawViewAnnotation', 'Annotation', '%s')",
554
              FeatName.c_str(), FeatName.c_str());
555

556
    doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", PageName.c_str(), FeatName.c_str());
557
    updateActive();
558
    commitCommand();
559
}
560

561
bool CmdTechDrawAnnotation::isActive()
562
{
563
    return DrawGuiUtil::needPage(this);
564
}
565

566
//===========================================================================
567
// TechDraw_CenterLineGroup
568
//===========================================================================
569

570
DEF_STD_CMD_ACL(CmdTechDrawCenterLineGroup)
571

572
CmdTechDrawCenterLineGroup::CmdTechDrawCenterLineGroup()
573
  : Command("TechDraw_CenterLineGroup")
574
{
575
    sAppModule      = "TechDraw";
576
    sGroup          = QT_TR_NOOP("TechDraw");
577
    sMenuText       = QT_TR_NOOP("Insert Center Line");
578
    sToolTipText    = sMenuText;
579
    sWhatsThis      = "TechDraw_CenterLineGroup";
580
    sStatusTip      = sToolTipText;
581
//    eType           = ForEdit;
582
}
583

584
void CmdTechDrawCenterLineGroup::activated(int iMsg)
585
{
586
//    Base::Console().Message("CMD::CenterLineGroup - activated(%d)\n", iMsg);
587
    Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
588
    if (dlg) {
589
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
590
            QObject::tr("Close active task dialog and try again."));
591
        return;
592
    }
593

594
    Gui::ActionGroup* pcAction = qobject_cast<Gui::ActionGroup*>(_pcAction);
595
    pcAction->setIcon(pcAction->actions().at(iMsg)->icon());
596
    switch(iMsg) {
597
        case 0:                 //faces
598
            execCenterLine(this);
599
            break;
600
        case 1:                 //2 lines
601
            exec2LineCenterLine(this);
602
            break;
603
        case 2:                 //2 points
604
            exec2PointCenterLine(this);
605
            break;
606
        default:
607
            Base::Console().Message("CMD::CVGrp - invalid iMsg: %d\n", iMsg);
608
    };
609
}
610

611
Gui::Action * CmdTechDrawCenterLineGroup::createAction()
612
{
613
    Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow());
614
    pcAction->setDropDownMenu(true);
615
    applyCommandData(this->className(), pcAction);
616

617
    QAction* p1 = pcAction->addAction(QString());
618
    p1->setIcon(Gui::BitmapFactory().iconFromTheme("actions/TechDraw_FaceCenterLine"));
619
    p1->setObjectName(QString::fromLatin1("TechDraw_FaceCenterLine"));
620
    p1->setWhatsThis(QString::fromLatin1("TechDraw_FaceCenterLine"));
621
    QAction* p2 = pcAction->addAction(QString());
622
    p2->setIcon(Gui::BitmapFactory().iconFromTheme("actions/TechDraw_2LineCenterline"));
623
    p2->setObjectName(QString::fromLatin1("TechDraw_2LineCenterLine"));
624
    p2->setWhatsThis(QString::fromLatin1("TechDraw_2LineCenterLine"));
625
    QAction* p3 = pcAction->addAction(QString());
626
    p3->setIcon(Gui::BitmapFactory().iconFromTheme("actions/TechDraw_2PointCenterline"));
627
    p3->setObjectName(QString::fromLatin1("TechDraw_2PointCenterLine"));
628
    p3->setWhatsThis(QString::fromLatin1("TechDraw_2PointCenterLine"));
629

630
    _pcAction = pcAction;
631
    languageChange();
632

633
    pcAction->setIcon(p1->icon());
634
    int defaultId = 0;
635
    pcAction->setProperty("defaultAction", QVariant(defaultId));
636

637
    return pcAction;
638
}
639

640
void CmdTechDrawCenterLineGroup::languageChange()
641
{
642
    Command::languageChange();
643

644
    if (!_pcAction)
645
        return;
646
    Gui::ActionGroup* pcAction = qobject_cast<Gui::ActionGroup*>(_pcAction);
647
    QList<QAction*> a = pcAction->actions();
648

649
    QAction* arc1 = a[0];
650
    arc1->setText(QApplication::translate("CmdTechDrawCenterLineGroup", "Add Centerline to Faces"));
651
    arc1->setToolTip(QApplication::translate("TechDraw_FaceCenterLine", "Adds a Centerline to Faces"));
652
    arc1->setStatusTip(arc1->toolTip());
653
    QAction* arc2 = a[1];
654
    arc2->setText(QApplication::translate("Cmd2LineCenterLine", "Add Centerline between 2 Lines"));
655
    arc2->setToolTip(QApplication::translate("TechDraw_2LineCenterLine", "Adds a Centerline between 2 Lines"));
656
    arc2->setStatusTip(arc2->toolTip());
657
    QAction* arc3 = a[2];
658
    arc3->setText(QApplication::translate("Cmd2PointCenterLine", "Add Centerline between 2 Points"));
659
    arc3->setToolTip(QApplication::translate("TechDraw_2PointCenterLine", "Adds a Centerline between 2 Points"));
660
    arc3->setStatusTip(arc3->toolTip());
661
}
662

663
bool CmdTechDrawCenterLineGroup::isActive()
664
{
665
    bool havePage = DrawGuiUtil::needPage(this);
666
    bool haveView = DrawGuiUtil::needView(this, true);
667
    return (havePage && haveView);
668
}
669
//===========================================================================
670
// TechDraw_Centerline
671
//===========================================================================
672

673
DEF_STD_CMD_A(CmdTechDrawFaceCenterLine)
674

675
CmdTechDrawFaceCenterLine::CmdTechDrawFaceCenterLine()
676
  : Command("TechDraw_FaceCenterLine")
677
{
678
    sAppModule      = "TechDraw";
679
    sGroup          = QT_TR_NOOP("TechDraw");
680
    sMenuText       = QT_TR_NOOP("Add Centerline to Faces");
681
    sToolTipText    = sMenuText;
682
    sWhatsThis      = "TechDraw_FaceCenterLine";
683
    sStatusTip      = sToolTipText;
684
    sPixmap         = "actions/TechDraw_FaceCenterLine";
685
}
686

687
void CmdTechDrawFaceCenterLine::activated(int iMsg)
688
{
689
    Q_UNUSED(iMsg);
690

691
    Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
692
    if (dlg) {
693
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
694
            QObject::tr("Close active task dialog and try again."));
695
        return;
696
    }
697

698
    execCenterLine(this);
699
}
700

701
bool CmdTechDrawFaceCenterLine::isActive()
702
{
703
    bool havePage = DrawGuiUtil::needPage(this);
704
    bool haveView = DrawGuiUtil::needView(this, false);
705
    return (havePage && haveView);
706
}
707

708
void execCenterLine(Gui::Command* cmd)
709
{
710
    TechDraw::DrawPage* page = DrawGuiUtil::findPage(cmd);
711
    if (!page) {
712
        return;
713
    }
714

715
    std::vector<Gui::SelectionObject> selection = cmd->getSelection().getSelectionEx();
716
    TechDraw::DrawViewPart *baseFeat = nullptr;
717
    if (!selection.empty()) {
718
        baseFeat = dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject());
719
        if (!baseFeat) {
720
            QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
721
                                 QObject::tr("No base View in Selection."));
722
            return;
723
        }
724
    }
725
    else {
726
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
727
                             QObject::tr("You must select a base View for the line."));
728
        return;
729
    }
730

731
    std::vector<std::string> subNames;
732

733
    std::vector<Gui::SelectionObject>::iterator itSel = selection.begin();
734
    for (; itSel != selection.end(); itSel++)  {
735
        if ((*itSel).getObject()->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) {
736
            baseFeat = static_cast<TechDraw::DrawViewPart*> ((*itSel).getObject());
737
            subNames = (*itSel).getSubNames();
738
        }
739
    }
740
    std::vector<std::string> faceNames;
741
    std::vector<std::string> edgeNames;
742
    for (auto& s: subNames) {
743
        std::string geomType = DrawUtil::getGeomTypeFromName(s);
744
        if (geomType == "Face") {
745
            faceNames.push_back(s);
746
        } else if (geomType == "Edge") {
747
            edgeNames.push_back(s);
748
        }
749
    }
750

751
    if ( (faceNames.empty()) &&
752
         (edgeNames.empty()) ) {
753
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
754
                             QObject::tr("You must select Faces or an existing CenterLine."));
755
        return;
756
    }
757
    if (!faceNames.empty()) {
758
        Gui::Control().showDialog(new TaskDlgCenterLine(baseFeat,
759
                                                        page,
760
                                                        faceNames,
761
                                                        false));
762
    } else if (edgeNames.empty()) {
763
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
764
                             QObject::tr("No CenterLine in selection."));
765
        return;
766
    } else {
767
        TechDraw::CenterLine* cl = baseFeat->getCenterLineBySelection(edgeNames.front());
768
        if (!cl) {
769
            QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
770
                             QObject::tr("Selection is not a CenterLine."));
771
            return;
772
        }
773
        Gui::Control().showDialog(new TaskDlgCenterLine(baseFeat,
774
                                                        page,
775
                                                        edgeNames.front(),
776
                                                        true));
777
    }
778
}
779

780
//===========================================================================
781
// TechDraw_2LineCenterline
782
//===========================================================================
783

784
DEF_STD_CMD_A(CmdTechDraw2LineCenterLine)
785

786
CmdTechDraw2LineCenterLine::CmdTechDraw2LineCenterLine()
787
  : Command("TechDraw_2LineCenterLine")
788
{
789
    sAppModule      = "TechDraw";
790
    sGroup          = QT_TR_NOOP("TechDraw");
791
    sMenuText       = QT_TR_NOOP("Add Centerline between 2 Lines");
792
    sToolTipText    = sMenuText;
793
    sWhatsThis      = "TechDraw_2LineCenterLine";
794
    sStatusTip      = sToolTipText;
795
    sPixmap         = "actions/TechDraw_2LineCenterline";
796
}
797

798
void CmdTechDraw2LineCenterLine::activated(int iMsg)
799
{
800
    Q_UNUSED(iMsg);
801

802
    Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
803
    if (dlg) {
804
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
805
            QObject::tr("Close active task dialog and try again."));
806
        return;
807
    }
808

809
    exec2LineCenterLine(this);
810
}
811

812
bool CmdTechDraw2LineCenterLine::isActive()
813
{
814
    bool havePage = DrawGuiUtil::needPage(this);
815
    bool haveView = DrawGuiUtil::needView(this, true);
816
    return (havePage && haveView);
817
}
818

819
void exec2LineCenterLine(Gui::Command* cmd)
820
{
821
    TechDraw::DrawPage* page = DrawGuiUtil::findPage(cmd);
822
    if (!page) {
823
        return;
824
    }
825
    TechDraw::DrawViewPart* dvp = nullptr;
826
    std::vector<std::string> selectedEdges = getSelectedSubElements(cmd, dvp, "Edge");
827

828
    if (!dvp || selectedEdges.empty()) {
829
        return;
830
    }
831

832
    if (selectedEdges.size() == 2) {
833
        Gui::Control().showDialog(new TaskDlgCenterLine(dvp,
834
                                                        page,
835
                                                        selectedEdges,
836
                                                        false));
837
    } else if (selectedEdges.size() == 1) {
838
        TechDraw::CenterLine* cl = dvp->getCenterLineBySelection(selectedEdges.front());
839
        if (!cl) {
840
            QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
841
                             QObject::tr("Selection is not a CenterLine."));
842
            return;
843
        }
844
        Gui::Control().showDialog(new TaskDlgCenterLine(dvp,
845
                                                page,
846
                                                selectedEdges.front(),
847
                                                true));
848
    } else {  //not create, not edit, what is this???
849
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
850
                             QObject::tr("Selection not understood."));
851
        return;
852
    }
853
}
854

855
//===========================================================================
856
// TechDraw_2PointCenterline
857
//===========================================================================
858

859
DEF_STD_CMD_A(CmdTechDraw2PointCenterLine)
860

861
CmdTechDraw2PointCenterLine::CmdTechDraw2PointCenterLine()
862
  : Command("TechDraw_2PointCenterLine")
863
{
864
    sAppModule      = "TechDraw";
865
    sGroup          = QT_TR_NOOP("TechDraw");
866
    sMenuText       = QT_TR_NOOP("Add Centerline between 2 Points");
867
    sToolTipText    = sMenuText;
868
    sWhatsThis      = "TechDraw_2PointCenterLine";
869
    sStatusTip      = sToolTipText;
870
    sPixmap         = "actions/TechDraw_2PointCenterline";
871
}
872

873
void CmdTechDraw2PointCenterLine::activated(int iMsg)
874
{
875
    Q_UNUSED(iMsg);
876

877
    Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
878
    if (dlg) {
879
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
880
            QObject::tr("Close active task dialog and try again."));
881
        return;
882
    }
883

884
    exec2PointCenterLine(this);
885
    updateActive();
886
    Gui::Selection().clearSelection();
887
}
888

889
bool CmdTechDraw2PointCenterLine::isActive()
890
{
891
    bool havePage = DrawGuiUtil::needPage(this);
892
    bool haveView = DrawGuiUtil::needView(this, true);
893
    return (havePage && haveView);
894
}
895

896
void exec2PointCenterLine(Gui::Command* cmd)
897
{
898
    TechDraw::DrawPage* page = DrawGuiUtil::findPage(cmd);
899
    if (!page) {
900
        return;
901
    }
902

903
    std::vector<Gui::SelectionObject> selection = cmd->getSelection().getSelectionEx();
904
    TechDraw::DrawViewPart* baseFeat = nullptr;
905
    if (selection.empty()) {
906
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
907
                                QObject::tr("You must select a base View for the line."));
908
        return;
909
    }
910

911
    baseFeat =  dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject());
912
    if (!baseFeat) {
913
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
914
                                QObject::tr("No base View in Selection."));
915
        return;
916
    }
917

918
    std::vector<std::string> subNames;
919

920
    std::vector<Gui::SelectionObject>::iterator itSel = selection.begin();
921
    for (; itSel != selection.end(); itSel++)  {
922
        if ((*itSel).getObject()->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) {
923
            baseFeat = static_cast<TechDraw::DrawViewPart*> ((*itSel).getObject());
924
            subNames = (*itSel).getSubNames();
925
        }
926
    }
927
    std::vector<std::string> edgeNames;
928
    std::vector<std::string> vertexNames;
929
    for (auto& s: subNames) {
930
        std::string geomType = DrawUtil::getGeomTypeFromName(s);
931
        if (geomType == "Vertex") {
932
            vertexNames.push_back(s);
933
        } else if (geomType == "Edge") {
934
            edgeNames.push_back(s);
935
        }
936
    }
937

938
    if (vertexNames.empty() &&
939
        edgeNames.empty()) {
940
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
941
                             QObject::tr("You must select 2 Vertexes or an existing CenterLine."));
942
        return;
943
    }
944
    if (!vertexNames.empty() && (vertexNames.size() == 2)) {
945
        Gui::Control().showDialog(new TaskDlgCenterLine(baseFeat,
946
                                                        page,
947
                                                        vertexNames,
948
                                                        false));
949
    } else if (!edgeNames.empty() && (edgeNames.size() == 1)) {
950
        TechDraw::CenterLine* cl = baseFeat->getCenterLineBySelection(edgeNames.front());
951
        if (!cl) {
952
            QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
953
                             QObject::tr("Selection is not a CenterLine."));
954
            return;
955
        }
956

957
        Gui::Control().showDialog(new TaskDlgCenterLine(baseFeat,
958
                                                        page,
959
                                                        edgeNames.front(),
960
                                                        false));
961
    } else if (vertexNames.empty()) {
962
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
963
                             QObject::tr("Need 2 Vertices or 1 CenterLine."));
964
        return;
965
    }
966
}
967

968
//===========================================================================
969
// TechDraw_2PointCosmeticLine
970
//===========================================================================
971

972
DEF_STD_CMD_A(CmdTechDraw2PointCosmeticLine)
973

974
CmdTechDraw2PointCosmeticLine::CmdTechDraw2PointCosmeticLine()
975
  : Command("TechDraw_2PointCosmeticLine")
976
{
977
    sAppModule      = "TechDraw";
978
    sGroup          = QT_TR_NOOP("TechDraw");
979
    sMenuText       = QT_TR_NOOP("Add Cosmetic Line Through 2 Points");
980
    sToolTipText    = sMenuText;
981
    sWhatsThis      = "TechDraw_2PointCosmeticLine";
982
    sStatusTip      = sToolTipText;
983
    sPixmap         = "actions/TechDraw_Line2Points";
984
}
985

986
void CmdTechDraw2PointCosmeticLine::activated(int iMsg)
987
{
988
    Q_UNUSED(iMsg);
989

990
    Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
991
    if (dlg) {
992
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
993
            QObject::tr("Close active task dialog and try again."));
994
        return;
995
    }
996

997
    execLine2Points(this);
998

999
    updateActive();
1000
    Gui::Selection().clearSelection();
1001
}
1002

1003
bool CmdTechDraw2PointCosmeticLine::isActive()
1004
{
1005
    bool havePage = DrawGuiUtil::needPage(this);
1006
    bool haveView = DrawGuiUtil::needView(this, true);
1007
    return (havePage && haveView);
1008
}
1009

1010
void execLine2Points(Gui::Command* cmd)
1011
{
1012
    TechDraw::DrawPage* page = DrawGuiUtil::findPage(cmd);
1013
    if (!page) {
1014
        return;
1015
    }
1016

1017
    std::vector<Gui::SelectionObject> selection = cmd->getSelection().getSelectionEx();
1018
    TechDraw::DrawViewPart* baseFeat = nullptr;
1019
    std::vector<std::string> subNames2D;
1020
    std::vector< std::pair<Part::Feature*, std::string> > objs3D;
1021
    if (selection.empty()) {
1022
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
1023
                             QObject::tr("Selection is empty."));
1024
        return;
1025
    }
1026

1027
    for (auto& so: selection) {
1028
        if (so.getObject()->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) {
1029
            baseFeat = static_cast<TechDraw::DrawViewPart*> (so.getObject());
1030
            subNames2D = so.getSubNames();
1031
        } else if (so.getObject()->isDerivedFrom(Part::Feature::getClassTypeId())) {
1032
            std::vector<std::string> subNames3D = so.getSubNames();
1033
            for (auto& sub3D: subNames3D) {
1034
                std::pair<Part::Feature*, std::string> temp;
1035
                temp.first = static_cast<Part::Feature*>(so.getObject());
1036
                temp.second = sub3D;
1037
                objs3D.push_back(temp);
1038
            }
1039
        } else {
1040
            //garbage
1041
        }
1042
    }
1043

1044
    if (!baseFeat) {
1045
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
1046
                             QObject::tr("You must select a base View for the line."));
1047
        return;
1048
    }
1049

1050
    //TODO: should be a smarter check
1051
    if ( (subNames2D.empty()) &&
1052
         (objs3D.empty()) )  {
1053
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
1054
                             QObject::tr("Not enough points in selection."));
1055
        return;
1056
    }
1057

1058
    std::vector<std::string> edgeNames;
1059
    std::vector<std::string> vertexNames;
1060
    for (auto& s: subNames2D) {
1061
        std::string geomType = DrawUtil::getGeomTypeFromName(s);
1062
        if (geomType == "Vertex") {
1063
            vertexNames.push_back(s);
1064
        } else if (geomType == "Edge") {
1065
            edgeNames.push_back(s);
1066
        }
1067
    }
1068

1069
    //check if editing existing edge
1070
    if (!edgeNames.empty() && (edgeNames.size() == 1)) {
1071
        TechDraw::CosmeticEdge* ce = baseFeat->getCosmeticEdgeBySelection(edgeNames.front());
1072
        if (!ce || ce->m_geometry->getGeomType() != TechDraw::GeomType::GENERIC) {
1073
            QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
1074
                             QObject::tr("Selection is not a Cosmetic Line."));
1075
            return;
1076
        }
1077

1078
        Gui::Control().showDialog(new TaskDlgCosmeticLine(baseFeat,
1079
                                                          edgeNames.front()));
1080
        return;
1081
    }
1082

1083
    std::vector<Base::Vector3d> points;
1084
    std::vector<bool> is3d;
1085
    //get the 2D points
1086
    if (!vertexNames.empty()) {
1087
        for (auto& v2d: vertexNames) {
1088
            int idx = DrawUtil::getIndexFromName(v2d);
1089
            TechDraw::VertexPtr v = baseFeat->getProjVertexByIndex(idx);
1090
            if (v) {
1091
                points.push_back(v->point());
1092
                is3d.push_back(false);
1093
            }
1094
        }
1095
    }
1096
    //get the 3D points
1097
    if (!objs3D.empty()) {
1098
        for (auto& o3D: objs3D) {
1099
            int idx = DrawUtil::getIndexFromName(o3D.second);
1100
            Part::TopoShape s = o3D.first->Shape.getShape();
1101
            TopoDS_Vertex v = TopoDS::Vertex(s.getSubShape(TopAbs_VERTEX, idx));
1102
            Base::Vector3d p = DrawUtil::vertex2Vector(v);
1103
            points.push_back(p);
1104
            is3d.push_back(true);
1105
        }
1106
    }
1107

1108
    if (points.size() != 2) {
1109
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
1110
                             QObject::tr("You must select 2 Vertexes."));
1111
        return;
1112
    }
1113

1114
    Gui::Control().showDialog(new TaskDlgCosmeticLine(baseFeat,
1115
                                                      points,
1116
                                                      is3d));
1117
}
1118

1119
//===========================================================================
1120
// TechDraw_CosmeticCircle
1121
//===========================================================================
1122

1123
DEF_STD_CMD_A(CmdTechDrawCosmeticCircle)
1124

1125
CmdTechDrawCosmeticCircle::CmdTechDrawCosmeticCircle()
1126
  : Command("TechDraw_CosmeticCircle")
1127
{
1128
    sAppModule      = "TechDraw";
1129
    sGroup          = QT_TR_NOOP("TechDraw");
1130
    sMenuText       = QT_TR_NOOP("Add Cosmetic Circle");
1131
    sToolTipText    = sMenuText;
1132
    sWhatsThis      = "TechDraw_CosmeticCircle";
1133
    sStatusTip      = sToolTipText;
1134
    sPixmap         = "actions/TechDraw_CosmeticCircle";
1135
}
1136

1137
void CmdTechDrawCosmeticCircle::activated(int iMsg)
1138
{
1139
    Q_UNUSED(iMsg);
1140

1141
    Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
1142
    if (dlg) {
1143
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
1144
            QObject::tr("Close active task dialog and try again."));
1145
        return;
1146
    }
1147

1148
    execCosmeticCircle(this);
1149

1150
    updateActive();
1151
    Gui::Selection().clearSelection();
1152
}
1153

1154
bool CmdTechDrawCosmeticCircle::isActive()
1155
{
1156
    bool havePage = DrawGuiUtil::needPage(this);
1157
    bool haveView = DrawGuiUtil::needView(this, true);
1158
    return (havePage && haveView);
1159
}
1160

1161
void execCosmeticCircle(Gui::Command* cmd)
1162
{
1163
    TechDraw::DrawPage* page = DrawGuiUtil::findPage(cmd);
1164
    if (!page) {
1165
        return;
1166
    }
1167

1168
    std::vector<Gui::SelectionObject> selection = cmd->getSelection().getSelectionEx();
1169
    TechDraw::DrawViewPart* baseFeat = nullptr;
1170
    std::vector<std::string> subNames2D;
1171
    std::vector< std::pair<Part::Feature*, std::string> > objs3D;
1172
    if (selection.empty()) {
1173
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
1174
                             QObject::tr("Selection is empty."));
1175
        return;
1176
    }
1177

1178
    for (auto& so: selection) {
1179
        if (so.getObject()->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) {
1180
            baseFeat = static_cast<TechDraw::DrawViewPart*> (so.getObject());
1181
            subNames2D = so.getSubNames();
1182
        } else if (so.getObject()->isDerivedFrom(Part::Feature::getClassTypeId())) {
1183
            std::vector<std::string> subNames3D = so.getSubNames();
1184
            for (auto& sub3D: subNames3D) {
1185
                std::pair<Part::Feature*, std::string> temp;
1186
                temp.first = static_cast<Part::Feature*>(so.getObject());
1187
                temp.second = sub3D;
1188
                objs3D.push_back(temp);
1189
            }
1190
        } else {
1191
            //garbage
1192
        }
1193
    }
1194

1195
    if (!baseFeat) {
1196
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
1197
                             QObject::tr("You must select a base View for the circle."));
1198
        return;
1199
    }
1200

1201
    std::vector<std::string> edgeNames;
1202
    std::vector<std::string> vertexNames;
1203
    for (auto& s: subNames2D) {
1204
        std::string geomType = DrawUtil::getGeomTypeFromName(s);
1205
        if (geomType == "Vertex") {
1206
            vertexNames.push_back(s);
1207
        } else if (geomType == "Edge") {
1208
            edgeNames.push_back(s);
1209
        }
1210
    }
1211

1212
    //check if editing existing edge
1213
    if (!edgeNames.empty() && (edgeNames.size() == 1)) {
1214
        TechDraw::CosmeticEdge* ce = baseFeat->getCosmeticEdgeBySelection(edgeNames.front());
1215
        if (!ce
1216
            || !(ce->m_geometry->getGeomType() == TechDraw::GeomType::CIRCLE
1217
                || ce->m_geometry->getGeomType() == TechDraw::GeomType::ARCOFCIRCLE)) {
1218
            QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
1219
                             QObject::tr("Selection is not a Cosmetic Circle or a Cosmetic Arc of Circle."));
1220
            return;
1221
        }
1222

1223
        Gui::Control().showDialog(new TaskDlgCosmeticCircle(baseFeat,
1224
                                                          edgeNames.front()));
1225
        return;
1226
    }
1227

1228
    std::vector<Base::Vector3d> points;
1229
    std::vector<bool> is3d;
1230
    //get the 2D points
1231
    if (!vertexNames.empty()) {
1232
        for (auto& v2d: vertexNames) {
1233
            int idx = DrawUtil::getIndexFromName(v2d);
1234
            TechDraw::VertexPtr v = baseFeat->getProjVertexByIndex(idx);
1235
            if (v) {
1236
                points.push_back(v->point());
1237
                is3d.push_back(false);
1238
            }
1239
        }
1240
    }
1241
    //get the 3D points
1242
    if (!objs3D.empty()) {
1243
        for (auto& o3D: objs3D) {
1244
            int idx = DrawUtil::getIndexFromName(o3D.second);
1245
            Part::TopoShape s = o3D.first->Shape.getShape();
1246
            TopoDS_Vertex v = TopoDS::Vertex(s.getSubShape(TopAbs_VERTEX, idx));
1247
            Base::Vector3d p = DrawUtil::vertex2Vector(v);
1248
            points.push_back(p);
1249
            is3d.push_back(true);
1250
        }
1251
    }
1252

1253
    if (points.empty()) {
1254
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
1255
                             QObject::tr("Please select a center for the circle."));
1256
        return;
1257
    }
1258

1259
    bool centerIs3d = false;
1260
    if (!is3d.empty()) {
1261
        centerIs3d = is3d.front();
1262
    }
1263

1264
    Gui::Control().showDialog(new TaskDlgCosmeticCircle(baseFeat,
1265
                                                      points.front(),
1266
                                                      centerIs3d));
1267
}
1268

1269
//===========================================================================
1270
// TechDraw_CosmeticEraser
1271
//===========================================================================
1272

1273
#define GEOMETRYEDGE 0
1274
#define COSMETICEDGE 1
1275
#define CENTERLINE 2
1276

1277
DEF_STD_CMD_A(CmdTechDrawCosmeticEraser)
1278

1279
CmdTechDrawCosmeticEraser::CmdTechDrawCosmeticEraser()
1280
  : Command("TechDraw_CosmeticEraser")
1281
{
1282
    sAppModule      = "TechDraw";
1283
    sGroup          = QT_TR_NOOP("TechDraw");
1284
    sMenuText       = QT_TR_NOOP("Remove Cosmetic Object");
1285
    sToolTipText    = sMenuText;
1286
    sWhatsThis      = "TechDraw_CosmeticEraser";
1287
    sStatusTip      = sToolTipText;
1288
    sPixmap         = "actions/TechDraw_CosmeticEraser";
1289
}
1290

1291
void CmdTechDrawCosmeticEraser::activated(int iMsg)
1292
{
1293
    Q_UNUSED(iMsg);
1294
    Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
1295
    if (dlg) {
1296
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
1297
            QObject::tr("Close active task dialog and try again."));
1298
        return;
1299
    }
1300

1301
    TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
1302
    if (!page) {
1303
        return;
1304
    }
1305

1306
    std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx();
1307

1308
    if (selection.empty()) {
1309
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
1310
                         QObject::tr("Nothing selected"));
1311
        return;
1312
    }
1313

1314
    for (auto& s: selection) {
1315
        TechDraw::DrawViewPart * objFeat = static_cast<TechDraw::DrawViewPart*> (s.getObject());
1316
        if (!objFeat->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) {
1317
            QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
1318
                            QObject::tr("At least 1 object in selection is not a part view"));
1319
            return;
1320
        }
1321
    }
1322

1323
    TechDraw::DrawViewPart * objFeat = nullptr;
1324
    std::vector<std::string> subNames;
1325
    std::vector<Gui::SelectionObject>::iterator itSel = selection.begin();
1326
    for (; itSel != selection.end(); itSel++)  {
1327
        if ((*itSel).getObject()->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) {
1328
            objFeat = static_cast<TechDraw::DrawViewPart*> ((*itSel).getObject());
1329
            subNames = (*itSel).getSubNames();
1330
        }
1331
        if (!objFeat) {
1332
            break;
1333
        }
1334
        std::vector<std::string> cv2Delete;
1335
        std::vector<std::string> ce2Delete;
1336
        std::vector<std::string> cl2Delete;
1337
        for (auto& s: subNames) {
1338
            int idx = TechDraw::DrawUtil::getIndexFromName(s);
1339
            std::string geomType = TechDraw::DrawUtil::getGeomTypeFromName(s);
1340
            if (geomType == "Edge") {
1341
                TechDraw::BaseGeomPtr bg = objFeat->getGeomByIndex(idx);
1342
                if (bg && bg->getCosmetic()) {
1343
                    int source = bg->source();
1344
                    std::string tag = bg->getCosmeticTag();
1345
                    if (source == COSMETICEDGE) {
1346
                        ce2Delete.push_back(tag);
1347
                    } else if (source == CENTERLINE) {
1348
                        cl2Delete.push_back(tag);
1349
                    } else {
1350
                        Base::Console().Message(
1351
                            "CMD::CosmeticEraser - edge: %d is confused - source: %d\n", idx, source);
1352
                    }
1353
                }
1354
            } else if (geomType == "Vertex") {
1355
                TechDraw::VertexPtr tdv = objFeat->getProjVertexByIndex(idx);
1356
                if (!tdv)
1357
                    Base::Console().Message("CMD::eraser - geom: %d not found!\n", idx);
1358

1359
                std::string delTag = tdv->getCosmeticTag();
1360
                if (delTag.empty())
1361
                    Base::Console().Warning("Vertex%d is not cosmetic! Can not erase.\n", idx);
1362
                cv2Delete.push_back(delTag);
1363
            } else {
1364
                QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
1365
                           QObject::tr("Unknown object type in selection"));
1366
                return;
1367
            }
1368

1369
        }
1370
        if (!cv2Delete.empty()) {
1371
            objFeat->removeCosmeticVertex(cv2Delete);
1372
        }
1373

1374
        if (!ce2Delete.empty()) {
1375
            objFeat->removeCosmeticEdge(ce2Delete);
1376
        }
1377
        if (!cl2Delete.empty()) {
1378
            objFeat->removeCenterLine(cl2Delete);
1379
        }
1380
    objFeat->recomputeFeature();
1381
    }
1382
}
1383

1384
bool CmdTechDrawCosmeticEraser::isActive()
1385
{
1386
    bool havePage = DrawGuiUtil::needPage(this);
1387
    bool haveView = DrawGuiUtil::needView(this, true);
1388
    return (havePage && haveView);
1389
}
1390

1391
//===========================================================================
1392
// TechDraw_DecorateLine
1393
//===========================================================================
1394

1395
DEF_STD_CMD_A(CmdTechDrawDecorateLine)
1396

1397
CmdTechDrawDecorateLine::CmdTechDrawDecorateLine()
1398
  : Command("TechDraw_DecorateLine")
1399
{
1400
    sAppModule      = "TechDraw";
1401
    sGroup          = QT_TR_NOOP("TechDraw");
1402
    sMenuText       = QT_TR_NOOP("Change Appearance of Lines");
1403
    sToolTipText    = QT_TR_NOOP("Change Appearance of selected Lines");
1404
    sWhatsThis      = "TechDraw_DecorateLine";
1405
    sStatusTip      = sToolTipText;
1406
    sPixmap         = "actions/TechDraw_DecorateLine";
1407
}
1408

1409
void CmdTechDrawDecorateLine::activated(int iMsg)
1410
{
1411
    Q_UNUSED(iMsg);
1412

1413
    Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
1414
    if (dlg) {
1415
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
1416
            QObject::tr("Close active task dialog and try again."));
1417
        return;
1418
    }
1419

1420
    TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
1421
    if (!page) {
1422
        return;
1423
    }
1424

1425
    std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx();
1426
    TechDraw::DrawViewPart* baseFeat = nullptr;
1427
    if (selection.empty()) {
1428
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
1429
                                QObject::tr("You must select a View and/or lines."));
1430
        return;
1431
    }
1432

1433
    baseFeat =  dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject());
1434
    if (!baseFeat) {
1435
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
1436
                                QObject::tr("No View in Selection."));
1437
        return;
1438
    }
1439

1440
    std::vector<std::string> subNames;
1441

1442
    std::vector<Gui::SelectionObject>::iterator itSel = selection.begin();
1443
    for (; itSel != selection.end(); itSel++)  {
1444
        if ((*itSel).getObject()->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) {
1445
            baseFeat = static_cast<TechDraw::DrawViewPart*> ((*itSel).getObject());
1446
            subNames = (*itSel).getSubNames();
1447
        }
1448
    }
1449
    std::vector<std::string> edgeNames;
1450
    for (auto& s: subNames) {
1451
        std::string geomType = DrawUtil::getGeomTypeFromName(s);
1452
        if (geomType == "Edge") {
1453
            edgeNames.push_back(s);
1454
        }
1455
    }
1456

1457
    Gui::Control().showDialog(new TaskDlgLineDecor(baseFeat,
1458
                                                   edgeNames));
1459
    updateActive();
1460
    Gui::Selection().clearSelection();
1461
}
1462

1463
bool CmdTechDrawDecorateLine::isActive()
1464
{
1465
    bool havePage = DrawGuiUtil::needPage(this);
1466
    bool haveView = DrawGuiUtil::needView(this, true);
1467
    return (havePage && haveView);
1468
}
1469

1470
//===========================================================================
1471
// TechDraw_ShowAll
1472
//===========================================================================
1473

1474
DEF_STD_CMD_A(CmdTechDrawShowAll)
1475

1476
CmdTechDrawShowAll::CmdTechDrawShowAll()
1477
  : Command("TechDraw_ShowAll")
1478
{
1479
    sAppModule      = "TechDraw";
1480
    sGroup          = QT_TR_NOOP("TechDraw");
1481
    sMenuText       = QT_TR_NOOP("Show/Hide Invisible Edges");
1482
    sToolTipText    = sMenuText;
1483
    sWhatsThis      = "TechDraw_ShowAll";
1484
    sStatusTip      = sToolTipText;
1485
    sPixmap         = "actions/TechDraw_ShowAll";
1486
}
1487

1488
void CmdTechDrawShowAll::activated(int iMsg)
1489
{
1490
    Q_UNUSED(iMsg);
1491
    Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
1492
    if (dlg) {
1493
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
1494
            QObject::tr("Close active task dialog and try again."));
1495
        return;
1496
    }
1497

1498
    TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
1499
    if (!page) {
1500
        return;
1501
    }
1502

1503
    std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx();
1504
    TechDraw::DrawViewPart* baseFeat = nullptr;
1505
    if (selection.empty()) {
1506
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
1507
                QObject::tr("Nothing selected"));
1508
        return;
1509
    }
1510

1511
    baseFeat =  dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject());
1512
    if (!baseFeat)  {
1513
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
1514
                QObject::tr("No Part Views in this selection"));
1515
        return;
1516
    }
1517

1518
    Gui::ViewProvider* vp = QGIView::getViewProvider(baseFeat);
1519
    auto partVP = dynamic_cast<ViewProviderViewPart*>(vp);
1520
    if (partVP) {
1521
        bool state = partVP->ShowAllEdges.getValue();
1522
        state = !state;
1523
        partVP->ShowAllEdges.setValue(state);
1524
        baseFeat->requestPaint();
1525
    }
1526
}
1527

1528
bool CmdTechDrawShowAll::isActive()
1529
{
1530
    bool havePage = DrawGuiUtil::needPage(this);
1531
    bool haveView = DrawGuiUtil::needView(this, true);
1532
    return (havePage && haveView);
1533
}
1534

1535
//===========================================================================
1536
// TechDraw_WeldSymbol
1537
//===========================================================================
1538

1539
DEF_STD_CMD_A(CmdTechDrawWeldSymbol)
1540

1541
CmdTechDrawWeldSymbol::CmdTechDrawWeldSymbol()
1542
  : Command("TechDraw_WeldSymbol")
1543
{
1544
    sAppModule      = "TechDraw";
1545
    sGroup          = QT_TR_NOOP("TechDraw");
1546
    sMenuText       = QT_TR_NOOP("Add Welding Information to Leaderline");
1547
    sToolTipText    = sMenuText;
1548
    sWhatsThis      = "TechDraw_WeldSymbol";
1549
    sStatusTip      = sToolTipText;
1550
    sPixmap         = "actions/TechDraw_WeldSymbol";
1551
}
1552

1553
void CmdTechDrawWeldSymbol::activated(int iMsg)
1554
{
1555
    Q_UNUSED(iMsg);
1556

1557
    Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
1558
    if (dlg) {
1559
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
1560
            QObject::tr("Close active task dialog and try again."));
1561
        return;
1562
    }
1563

1564
    TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
1565
    if (!page) {
1566
        return;
1567
    }
1568

1569
    std::vector<App::DocumentObject*> leaders = getSelection().
1570
                                         getObjectsOfType(TechDraw::DrawLeaderLine::getClassTypeId());
1571
    std::vector<App::DocumentObject*> welds = getSelection().
1572
                                         getObjectsOfType(TechDraw::DrawWeldSymbol::getClassTypeId());
1573
    TechDraw::DrawLeaderLine* leadFeat = nullptr;
1574
    TechDraw::DrawWeldSymbol* weldFeat = nullptr;
1575
    if ( (leaders.size() != 1) &&
1576
         (welds.size() != 1) ) {
1577
        QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
1578
            QObject::tr("Select exactly one Leader line or one Weld symbol."));
1579
        return;
1580
    }
1581
    if (!leaders.empty()) {
1582
        leadFeat = static_cast<TechDraw::DrawLeaderLine*> (leaders.front());
1583
        Gui::Control().showDialog(new TaskDlgWeldingSymbol(leadFeat));
1584
    } else if (!welds.empty()) {
1585
        weldFeat = static_cast<TechDraw::DrawWeldSymbol*> (welds.front());
1586
        Gui::Control().showDialog(new TaskDlgWeldingSymbol(weldFeat));
1587
    }
1588
    updateActive();
1589
    Gui::Selection().clearSelection();
1590
}
1591

1592
bool CmdTechDrawWeldSymbol::isActive()
1593
{
1594
    bool havePage = DrawGuiUtil::needPage(this);
1595
    bool haveView = DrawGuiUtil::needView(this, false);
1596
    return (havePage && haveView);
1597
}
1598

1599
//===========================================================================
1600
// TechDraw_SurfaceFinishSymbols
1601
//===========================================================================
1602

1603
DEF_STD_CMD_A(CmdTechDrawSurfaceFinishSymbols)
1604

1605
CmdTechDrawSurfaceFinishSymbols::CmdTechDrawSurfaceFinishSymbols()
1606
  : Command("TechDraw_SurfaceFinishSymbols")
1607
{
1608
    sAppModule      = "TechDraw";
1609
    sGroup          = QT_TR_NOOP("TechDraw");
1610
    sMenuText       = QT_TR_NOOP("Create a Surface Finish Symbol");
1611
    sToolTipText    = QT_TR_NOOP("Select a view<br>\
1612
    - click this button<br>\
1613
    - select surface finish symbol attributes in opened panel");
1614
    sWhatsThis      = "TechDraw_SurfaceFinishSymbols";
1615
    sStatusTip      = sToolTipText;
1616
    sPixmap         = "actions/TechDraw_SurfaceFinishSymbols";
1617
}
1618

1619
void CmdTechDrawSurfaceFinishSymbols::activated(int iMsg)
1620
{
1621
    Q_UNUSED(iMsg);
1622

1623
    std::string ownerName;
1624
    std::vector<Gui::SelectionObject> selection = this->getSelection().getSelectionEx();
1625
    if (selection.empty())
1626
    {
1627
        TechDraw::DrawPage *page = DrawGuiUtil::findPage(this);
1628
        if (!page) {
1629
            return;
1630
        }
1631

1632
        ownerName = page->getNameInDocument();
1633
    }
1634
    else {
1635
        auto objFeat = dynamic_cast<TechDraw::DrawView *>(selection.front().getObject());
1636
        if (!objFeat->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())
1637
            && !objFeat->isDerivedFrom(TechDraw::DrawLeaderLine::getClassTypeId())) {
1638
            QMessageBox::warning(Gui::getMainWindow(), QObject::tr("SurfaceFinishSymbols"),
1639
                                 QObject::tr("Selected object is not a part view, nor a leader line"));
1640
            return;
1641
        }
1642

1643
        ownerName = objFeat->getNameInDocument();
1644

1645
        const std::vector<std::string> &subNames = selection.front().getSubNames();
1646
        if (!subNames.empty()) {
1647
            ownerName += '.';
1648
            ownerName += subNames.front();
1649
        }
1650
    }
1651

1652
    Gui::Control().showDialog(new TechDrawGui::TaskDlgSurfaceFinishSymbols(ownerName));
1653

1654
    updateActive();
1655
    Gui::Selection().clearSelection();
1656
}
1657

1658
bool CmdTechDrawSurfaceFinishSymbols::isActive()
1659
{
1660
    bool havePage = DrawGuiUtil::needPage(this);
1661
    bool haveView = DrawGuiUtil::needView(this);
1662
    return havePage && haveView;
1663
}
1664

1665
void CreateTechDrawCommandsAnnotate()
1666
{
1667
    Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager();
1668

1669
    rcCmdMgr.addCommand(new CmdTechDrawLeaderLine());
1670
    rcCmdMgr.addCommand(new CmdTechDrawRichTextAnnotation());
1671
    rcCmdMgr.addCommand(new CmdTechDrawCosmeticVertexGroup());
1672
    rcCmdMgr.addCommand(new CmdTechDrawCosmeticVertex());
1673
    rcCmdMgr.addCommand(new CmdTechDrawMidpoints());
1674
    rcCmdMgr.addCommand(new CmdTechDrawQuadrants());
1675
    rcCmdMgr.addCommand(new CmdTechDrawCenterLineGroup());
1676
    rcCmdMgr.addCommand(new CmdTechDrawFaceCenterLine());
1677
    rcCmdMgr.addCommand(new CmdTechDraw2LineCenterLine());
1678
    rcCmdMgr.addCommand(new CmdTechDraw2PointCenterLine());
1679
    rcCmdMgr.addCommand(new CmdTechDraw2PointCosmeticLine());
1680
    rcCmdMgr.addCommand(new CmdTechDrawCosmeticCircle());
1681
    rcCmdMgr.addCommand(new CmdTechDrawAnnotation());
1682
    rcCmdMgr.addCommand(new CmdTechDrawCosmeticEraser());
1683
    rcCmdMgr.addCommand(new CmdTechDrawDecorateLine());
1684
    rcCmdMgr.addCommand(new CmdTechDrawShowAll());
1685
    rcCmdMgr.addCommand(new CmdTechDrawWeldSymbol());
1686
    rcCmdMgr.addCommand(new CmdTechDrawSurfaceFinishSymbols());
1687
}
1688

1689
//===========================================================================
1690
// Selection Validation Helpers
1691
//===========================================================================
1692

1693
std::vector<std::string> getSelectedSubElements(Gui::Command* cmd,
1694
                                                TechDraw::DrawViewPart* &dvp,
1695
                                                std::string subType)
1696
{
1697
//    Base::Console().Message("getSelectedSubElements() - dvp: %X\n", dvp);
1698
    std::vector<std::string> selectedSubs;
1699
    std::vector<std::string> subNames;
1700
    dvp = nullptr;
1701
    std::vector<Gui::SelectionObject> selection = cmd->getSelection().getSelectionEx();
1702
    std::vector<Gui::SelectionObject>::iterator itSel = selection.begin();
1703
    for (; itSel != selection.end(); itSel++)  {
1704
        if ((*itSel).getObject()->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) {
1705
            dvp = static_cast<TechDraw::DrawViewPart*> ((*itSel).getObject());
1706
            subNames = (*itSel).getSubNames();
1707
            break;
1708
        }
1709
    }
1710
    if (!dvp) {
1711
      QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
1712
                           QObject::tr("No Part View in Selection"));
1713
      return selectedSubs;
1714
    }
1715

1716
    for (auto& s: subNames) {
1717
        if (TechDraw::DrawUtil::getGeomTypeFromName(s) == subType) {
1718
            selectedSubs.push_back(s);
1719
        }
1720
    }
1721

1722
    if (selectedSubs.empty()) {
1723
        QMessageBox::warning(Gui::getMainWindow(),
1724
                             QObject::tr("Wrong Selection"),
1725
                             QObject::tr("No %1 in Selection")
1726
                                 .arg(QString::fromStdString(subType)));
1727
        return selectedSubs;
1728
    }
1729

1730
    return selectedSubs;
1731
}
1732

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

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

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

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