1
/***************************************************************************
2
* Copyright (c) 2019 WandererFan <wandererfan@gmail.com> *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 59 Temple Place, *
19
* Suite 330, Boston, MA 02111-1307, USA *
21
***************************************************************************/
23
#include "PreCompiled.h"
25
# include <QApplication>
26
# include <QMessageBox>
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>
51
#include "DrawGuiUtil.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"
65
using namespace TechDrawGui;
66
using namespace TechDraw;
69
bool _checkSelectionHatch(Gui::Command* cmd);
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");
83
//===========================================================================
85
//===========================================================================
87
DEF_STD_CMD_A(CmdTechDrawLeaderLine)
89
CmdTechDrawLeaderLine::CmdTechDrawLeaderLine()
90
: Command("TechDraw_LeaderLine")
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";
101
void CmdTechDrawLeaderLine::activated(int iMsg)
105
Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
107
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
108
QObject::tr("Close active task dialog and try again."));
112
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
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());
122
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
123
QObject::tr("Can not attach leader. No base View selected."));
127
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
128
QObject::tr("You must select a base View for the line."));
132
Gui::Control().showDialog(new TechDrawGui::TaskDlgLeaderLine(baseFeat,
135
Gui::Selection().clearSelection();
138
bool CmdTechDrawLeaderLine::isActive()
140
bool havePage = DrawGuiUtil::needPage(this);
141
bool haveView = DrawGuiUtil::needView(this, false);
142
return (havePage && haveView);
145
//===========================================================================
146
// TechDraw_RichTextAnnotation
147
//===========================================================================
149
DEF_STD_CMD_A(CmdTechDrawRichTextAnnotation)
151
CmdTechDrawRichTextAnnotation::CmdTechDrawRichTextAnnotation()
152
: Command("TechDraw_RichTextAnnotation")
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";
163
void CmdTechDrawRichTextAnnotation::activated(int iMsg)
166
Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
168
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
169
QObject::tr("Close active task dialog and try again."));
173
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
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());
184
Gui::Control().showDialog(new TaskDlgRichAnno(baseFeat,
187
Gui::Selection().clearSelection();
190
bool CmdTechDrawRichTextAnnotation::isActive()
192
bool havePage = DrawGuiUtil::needPage(this);
197
//===========================================================================
198
// TechDraw_CosmeticVertexGroup
199
//===========================================================================
201
DEF_STD_CMD_ACL(CmdTechDrawCosmeticVertexGroup)
203
CmdTechDrawCosmeticVertexGroup::CmdTechDrawCosmeticVertexGroup()
204
: Command("TechDraw_CosmeticVertexGroup")
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;
215
void CmdTechDrawCosmeticVertexGroup::activated(int iMsg)
217
// Base::Console().Message("CMD::CosmeticVertexGroup - activated(%d)\n", iMsg);
218
Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
220
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
221
QObject::tr("Close active task dialog and try again."));
225
Gui::ActionGroup* pcAction = qobject_cast<Gui::ActionGroup*>(_pcAction);
226
pcAction->setIcon(pcAction->actions().at(iMsg)->icon());
229
execCosmeticVertex(this);
238
Base::Console().Message("CMD::CVGrp - invalid iMsg: %d\n", iMsg);
241
Gui::Selection().clearSelection();
244
Gui::Action * CmdTechDrawCosmeticVertexGroup::createAction()
246
Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow());
247
pcAction->setDropDownMenu(true);
248
applyCommandData(this->className(), pcAction);
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"));
263
_pcAction = pcAction;
266
pcAction->setIcon(p1->icon());
268
pcAction->setProperty("defaultAction", QVariant(defaultId));
273
void CmdTechDrawCosmeticVertexGroup::languageChange()
275
Command::languageChange();
279
Gui::ActionGroup* pcAction = qobject_cast<Gui::ActionGroup*>(_pcAction);
280
QList<QAction*> a = pcAction->actions();
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());
296
bool CmdTechDrawCosmeticVertexGroup::isActive()
298
bool havePage = DrawGuiUtil::needPage(this);
299
bool haveView = DrawGuiUtil::needView(this, true);
300
return (havePage && haveView);
304
//===========================================================================
305
// TechDraw_CosmeticVertex
306
//===========================================================================
308
void execCosmeticVertex(Gui::Command* cmd)
310
// Base::Console().Message("execCosmeticVertex()\n");
311
TechDraw::DrawPage* page = DrawGuiUtil::findPage(cmd);
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"));
324
//shapes not empty and only contains dvp
325
TechDraw::DrawViewPart* baseFeat = nullptr;
326
baseFeat = dynamic_cast<TechDraw::DrawViewPart*>((*shapes.begin()));
328
Gui::Control().showDialog(new TaskDlgCosVertex(baseFeat,
332
void execMidpoints(Gui::Command* cmd)
334
// Base::Console().Message("execMidpoints()\n");
335
TechDraw::DrawViewPart * dvp = nullptr;
336
std::vector<std::string> selectedEdges = getSelectedSubElements(cmd, dvp, "Edge");
338
if (!dvp || selectedEdges.empty())
341
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Add Midpoint Vertices"));
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);
354
Gui::Command::commitCommand();
356
dvp->recomputeFeature();
359
void execQuadrants(Gui::Command* cmd)
361
// Base::Console().Message("execQuadrants()\n");
362
TechDraw::DrawViewPart* dvp = nullptr;
363
std::vector<std::string> selectedEdges = getSelectedSubElements(cmd, dvp, "Edge");
365
if (!dvp || selectedEdges.empty())
368
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Add Quadrant Vertices"));
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);
383
Gui::Command::commitCommand();
385
dvp->recomputeFeature();
388
DEF_STD_CMD_A(CmdTechDrawCosmeticVertex)
390
CmdTechDrawCosmeticVertex::CmdTechDrawCosmeticVertex()
391
: Command("TechDraw_CosmeticVertex")
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";
402
void CmdTechDrawCosmeticVertex::activated(int iMsg)
405
Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
407
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
408
QObject::tr("Close active task dialog and try again."));
412
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
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"));
425
TechDraw::DrawViewPart* baseFeat = nullptr;
426
baseFeat = dynamic_cast<TechDraw::DrawViewPart*>((*shapes.begin()));
428
Base::Console().Message("CMD::CosmeticVertex - 1st shape is not DVP. WTF?\n");
432
Gui::Control().showDialog(new TaskDlgCosVertex(baseFeat,
435
Gui::Selection().clearSelection();
438
bool CmdTechDrawCosmeticVertex::isActive()
440
bool havePage = DrawGuiUtil::needPage(this);
441
bool haveView = DrawGuiUtil::needView(this, true);
442
return (havePage && haveView);
445
//===========================================================================
447
//===========================================================================
449
DEF_STD_CMD_A(CmdTechDrawMidpoints)
451
CmdTechDrawMidpoints::CmdTechDrawMidpoints()
452
: Command("TechDraw_Midpoints")
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";
463
void CmdTechDrawMidpoints::activated(int iMsg)
466
Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
468
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
469
QObject::tr("Close active task dialog and try again."));
474
Gui::Selection().clearSelection();
477
bool CmdTechDrawMidpoints::isActive()
479
bool havePage = DrawGuiUtil::needPage(this);
480
bool haveView = DrawGuiUtil::needView(this, true);
481
return (havePage && haveView);
484
//===========================================================================
486
//===========================================================================
488
DEF_STD_CMD_A(CmdTechDrawQuadrants)
490
CmdTechDrawQuadrants::CmdTechDrawQuadrants()
491
: Command("TechDraw_Quadrants")
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";
502
void CmdTechDrawQuadrants::activated(int iMsg)
505
Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
507
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
508
QObject::tr("Close active task dialog and try again."));
513
Gui::Selection().clearSelection();
516
bool CmdTechDrawQuadrants::isActive()
518
bool havePage = DrawGuiUtil::needPage(this);
519
bool haveView = DrawGuiUtil::needView(this, true);
520
return (havePage && haveView);
523
//===========================================================================
524
// TechDraw_Annotation
525
//===========================================================================
527
DEF_STD_CMD_A(CmdTechDrawAnnotation)
529
CmdTechDrawAnnotation::CmdTechDrawAnnotation()
530
: Command("TechDraw_Annotation")
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";
541
void CmdTechDrawAnnotation::activated(int iMsg)
544
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
548
std::string PageName = page->getNameInDocument();
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());
556
doCommand(Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", PageName.c_str(), FeatName.c_str());
561
bool CmdTechDrawAnnotation::isActive()
563
return DrawGuiUtil::needPage(this);
566
//===========================================================================
567
// TechDraw_CenterLineGroup
568
//===========================================================================
570
DEF_STD_CMD_ACL(CmdTechDrawCenterLineGroup)
572
CmdTechDrawCenterLineGroup::CmdTechDrawCenterLineGroup()
573
: Command("TechDraw_CenterLineGroup")
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;
584
void CmdTechDrawCenterLineGroup::activated(int iMsg)
586
// Base::Console().Message("CMD::CenterLineGroup - activated(%d)\n", iMsg);
587
Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
589
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
590
QObject::tr("Close active task dialog and try again."));
594
Gui::ActionGroup* pcAction = qobject_cast<Gui::ActionGroup*>(_pcAction);
595
pcAction->setIcon(pcAction->actions().at(iMsg)->icon());
598
execCenterLine(this);
601
exec2LineCenterLine(this);
604
exec2PointCenterLine(this);
607
Base::Console().Message("CMD::CVGrp - invalid iMsg: %d\n", iMsg);
611
Gui::Action * CmdTechDrawCenterLineGroup::createAction()
613
Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow());
614
pcAction->setDropDownMenu(true);
615
applyCommandData(this->className(), pcAction);
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"));
630
_pcAction = pcAction;
633
pcAction->setIcon(p1->icon());
635
pcAction->setProperty("defaultAction", QVariant(defaultId));
640
void CmdTechDrawCenterLineGroup::languageChange()
642
Command::languageChange();
646
Gui::ActionGroup* pcAction = qobject_cast<Gui::ActionGroup*>(_pcAction);
647
QList<QAction*> a = pcAction->actions();
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());
663
bool CmdTechDrawCenterLineGroup::isActive()
665
bool havePage = DrawGuiUtil::needPage(this);
666
bool haveView = DrawGuiUtil::needView(this, true);
667
return (havePage && haveView);
669
//===========================================================================
670
// TechDraw_Centerline
671
//===========================================================================
673
DEF_STD_CMD_A(CmdTechDrawFaceCenterLine)
675
CmdTechDrawFaceCenterLine::CmdTechDrawFaceCenterLine()
676
: Command("TechDraw_FaceCenterLine")
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";
687
void CmdTechDrawFaceCenterLine::activated(int iMsg)
691
Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
693
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
694
QObject::tr("Close active task dialog and try again."));
698
execCenterLine(this);
701
bool CmdTechDrawFaceCenterLine::isActive()
703
bool havePage = DrawGuiUtil::needPage(this);
704
bool haveView = DrawGuiUtil::needView(this, false);
705
return (havePage && haveView);
708
void execCenterLine(Gui::Command* cmd)
710
TechDraw::DrawPage* page = DrawGuiUtil::findPage(cmd);
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());
720
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
721
QObject::tr("No base View in Selection."));
726
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
727
QObject::tr("You must select a base View for the line."));
731
std::vector<std::string> subNames;
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();
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);
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."));
757
if (!faceNames.empty()) {
758
Gui::Control().showDialog(new TaskDlgCenterLine(baseFeat,
762
} else if (edgeNames.empty()) {
763
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
764
QObject::tr("No CenterLine in selection."));
767
TechDraw::CenterLine* cl = baseFeat->getCenterLineBySelection(edgeNames.front());
769
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
770
QObject::tr("Selection is not a CenterLine."));
773
Gui::Control().showDialog(new TaskDlgCenterLine(baseFeat,
780
//===========================================================================
781
// TechDraw_2LineCenterline
782
//===========================================================================
784
DEF_STD_CMD_A(CmdTechDraw2LineCenterLine)
786
CmdTechDraw2LineCenterLine::CmdTechDraw2LineCenterLine()
787
: Command("TechDraw_2LineCenterLine")
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";
798
void CmdTechDraw2LineCenterLine::activated(int iMsg)
802
Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
804
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
805
QObject::tr("Close active task dialog and try again."));
809
exec2LineCenterLine(this);
812
bool CmdTechDraw2LineCenterLine::isActive()
814
bool havePage = DrawGuiUtil::needPage(this);
815
bool haveView = DrawGuiUtil::needView(this, true);
816
return (havePage && haveView);
819
void exec2LineCenterLine(Gui::Command* cmd)
821
TechDraw::DrawPage* page = DrawGuiUtil::findPage(cmd);
825
TechDraw::DrawViewPart* dvp = nullptr;
826
std::vector<std::string> selectedEdges = getSelectedSubElements(cmd, dvp, "Edge");
828
if (!dvp || selectedEdges.empty()) {
832
if (selectedEdges.size() == 2) {
833
Gui::Control().showDialog(new TaskDlgCenterLine(dvp,
837
} else if (selectedEdges.size() == 1) {
838
TechDraw::CenterLine* cl = dvp->getCenterLineBySelection(selectedEdges.front());
840
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
841
QObject::tr("Selection is not a CenterLine."));
844
Gui::Control().showDialog(new TaskDlgCenterLine(dvp,
846
selectedEdges.front(),
848
} else { //not create, not edit, what is this???
849
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
850
QObject::tr("Selection not understood."));
855
//===========================================================================
856
// TechDraw_2PointCenterline
857
//===========================================================================
859
DEF_STD_CMD_A(CmdTechDraw2PointCenterLine)
861
CmdTechDraw2PointCenterLine::CmdTechDraw2PointCenterLine()
862
: Command("TechDraw_2PointCenterLine")
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";
873
void CmdTechDraw2PointCenterLine::activated(int iMsg)
877
Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
879
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
880
QObject::tr("Close active task dialog and try again."));
884
exec2PointCenterLine(this);
886
Gui::Selection().clearSelection();
889
bool CmdTechDraw2PointCenterLine::isActive()
891
bool havePage = DrawGuiUtil::needPage(this);
892
bool haveView = DrawGuiUtil::needView(this, true);
893
return (havePage && haveView);
896
void exec2PointCenterLine(Gui::Command* cmd)
898
TechDraw::DrawPage* page = DrawGuiUtil::findPage(cmd);
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."));
911
baseFeat = dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject());
913
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
914
QObject::tr("No base View in Selection."));
918
std::vector<std::string> subNames;
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();
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);
938
if (vertexNames.empty() &&
940
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
941
QObject::tr("You must select 2 Vertexes or an existing CenterLine."));
944
if (!vertexNames.empty() && (vertexNames.size() == 2)) {
945
Gui::Control().showDialog(new TaskDlgCenterLine(baseFeat,
949
} else if (!edgeNames.empty() && (edgeNames.size() == 1)) {
950
TechDraw::CenterLine* cl = baseFeat->getCenterLineBySelection(edgeNames.front());
952
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
953
QObject::tr("Selection is not a CenterLine."));
957
Gui::Control().showDialog(new TaskDlgCenterLine(baseFeat,
961
} else if (vertexNames.empty()) {
962
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
963
QObject::tr("Need 2 Vertices or 1 CenterLine."));
968
//===========================================================================
969
// TechDraw_2PointCosmeticLine
970
//===========================================================================
972
DEF_STD_CMD_A(CmdTechDraw2PointCosmeticLine)
974
CmdTechDraw2PointCosmeticLine::CmdTechDraw2PointCosmeticLine()
975
: Command("TechDraw_2PointCosmeticLine")
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";
986
void CmdTechDraw2PointCosmeticLine::activated(int iMsg)
990
Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
992
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
993
QObject::tr("Close active task dialog and try again."));
997
execLine2Points(this);
1000
Gui::Selection().clearSelection();
1003
bool CmdTechDraw2PointCosmeticLine::isActive()
1005
bool havePage = DrawGuiUtil::needPage(this);
1006
bool haveView = DrawGuiUtil::needView(this, true);
1007
return (havePage && haveView);
1010
void execLine2Points(Gui::Command* cmd)
1012
TechDraw::DrawPage* page = DrawGuiUtil::findPage(cmd);
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."));
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);
1045
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
1046
QObject::tr("You must select a base View for the line."));
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."));
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);
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."));
1078
Gui::Control().showDialog(new TaskDlgCosmeticLine(baseFeat,
1079
edgeNames.front()));
1083
std::vector<Base::Vector3d> points;
1084
std::vector<bool> is3d;
1086
if (!vertexNames.empty()) {
1087
for (auto& v2d: vertexNames) {
1088
int idx = DrawUtil::getIndexFromName(v2d);
1089
TechDraw::VertexPtr v = baseFeat->getProjVertexByIndex(idx);
1091
points.push_back(v->point());
1092
is3d.push_back(false);
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);
1108
if (points.size() != 2) {
1109
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
1110
QObject::tr("You must select 2 Vertexes."));
1114
Gui::Control().showDialog(new TaskDlgCosmeticLine(baseFeat,
1119
//===========================================================================
1120
// TechDraw_CosmeticCircle
1121
//===========================================================================
1123
DEF_STD_CMD_A(CmdTechDrawCosmeticCircle)
1125
CmdTechDrawCosmeticCircle::CmdTechDrawCosmeticCircle()
1126
: Command("TechDraw_CosmeticCircle")
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";
1137
void CmdTechDrawCosmeticCircle::activated(int iMsg)
1141
Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
1143
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
1144
QObject::tr("Close active task dialog and try again."));
1148
execCosmeticCircle(this);
1151
Gui::Selection().clearSelection();
1154
bool CmdTechDrawCosmeticCircle::isActive()
1156
bool havePage = DrawGuiUtil::needPage(this);
1157
bool haveView = DrawGuiUtil::needView(this, true);
1158
return (havePage && haveView);
1161
void execCosmeticCircle(Gui::Command* cmd)
1163
TechDraw::DrawPage* page = DrawGuiUtil::findPage(cmd);
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."));
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);
1196
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
1197
QObject::tr("You must select a base View for the circle."));
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);
1212
//check if editing existing edge
1213
if (!edgeNames.empty() && (edgeNames.size() == 1)) {
1214
TechDraw::CosmeticEdge* ce = baseFeat->getCosmeticEdgeBySelection(edgeNames.front());
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."));
1223
Gui::Control().showDialog(new TaskDlgCosmeticCircle(baseFeat,
1224
edgeNames.front()));
1228
std::vector<Base::Vector3d> points;
1229
std::vector<bool> is3d;
1231
if (!vertexNames.empty()) {
1232
for (auto& v2d: vertexNames) {
1233
int idx = DrawUtil::getIndexFromName(v2d);
1234
TechDraw::VertexPtr v = baseFeat->getProjVertexByIndex(idx);
1236
points.push_back(v->point());
1237
is3d.push_back(false);
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);
1253
if (points.empty()) {
1254
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
1255
QObject::tr("Please select a center for the circle."));
1259
bool centerIs3d = false;
1260
if (!is3d.empty()) {
1261
centerIs3d = is3d.front();
1264
Gui::Control().showDialog(new TaskDlgCosmeticCircle(baseFeat,
1269
//===========================================================================
1270
// TechDraw_CosmeticEraser
1271
//===========================================================================
1273
#define GEOMETRYEDGE 0
1274
#define COSMETICEDGE 1
1277
DEF_STD_CMD_A(CmdTechDrawCosmeticEraser)
1279
CmdTechDrawCosmeticEraser::CmdTechDrawCosmeticEraser()
1280
: Command("TechDraw_CosmeticEraser")
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";
1291
void CmdTechDrawCosmeticEraser::activated(int iMsg)
1294
Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
1296
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
1297
QObject::tr("Close active task dialog and try again."));
1301
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
1306
std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx();
1308
if (selection.empty()) {
1309
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
1310
QObject::tr("Nothing selected"));
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"));
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();
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);
1350
Base::Console().Message(
1351
"CMD::CosmeticEraser - edge: %d is confused - source: %d\n", idx, source);
1354
} else if (geomType == "Vertex") {
1355
TechDraw::VertexPtr tdv = objFeat->getProjVertexByIndex(idx);
1357
Base::Console().Message("CMD::eraser - geom: %d not found!\n", idx);
1359
std::string delTag = tdv->getCosmeticTag();
1361
Base::Console().Warning("Vertex%d is not cosmetic! Can not erase.\n", idx);
1362
cv2Delete.push_back(delTag);
1364
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
1365
QObject::tr("Unknown object type in selection"));
1370
if (!cv2Delete.empty()) {
1371
objFeat->removeCosmeticVertex(cv2Delete);
1374
if (!ce2Delete.empty()) {
1375
objFeat->removeCosmeticEdge(ce2Delete);
1377
if (!cl2Delete.empty()) {
1378
objFeat->removeCenterLine(cl2Delete);
1380
objFeat->recomputeFeature();
1384
bool CmdTechDrawCosmeticEraser::isActive()
1386
bool havePage = DrawGuiUtil::needPage(this);
1387
bool haveView = DrawGuiUtil::needView(this, true);
1388
return (havePage && haveView);
1391
//===========================================================================
1392
// TechDraw_DecorateLine
1393
//===========================================================================
1395
DEF_STD_CMD_A(CmdTechDrawDecorateLine)
1397
CmdTechDrawDecorateLine::CmdTechDrawDecorateLine()
1398
: Command("TechDraw_DecorateLine")
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";
1409
void CmdTechDrawDecorateLine::activated(int iMsg)
1413
Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
1415
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
1416
QObject::tr("Close active task dialog and try again."));
1420
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
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."));
1433
baseFeat = dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject());
1435
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
1436
QObject::tr("No View in Selection."));
1440
std::vector<std::string> subNames;
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();
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);
1457
Gui::Control().showDialog(new TaskDlgLineDecor(baseFeat,
1460
Gui::Selection().clearSelection();
1463
bool CmdTechDrawDecorateLine::isActive()
1465
bool havePage = DrawGuiUtil::needPage(this);
1466
bool haveView = DrawGuiUtil::needView(this, true);
1467
return (havePage && haveView);
1470
//===========================================================================
1472
//===========================================================================
1474
DEF_STD_CMD_A(CmdTechDrawShowAll)
1476
CmdTechDrawShowAll::CmdTechDrawShowAll()
1477
: Command("TechDraw_ShowAll")
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";
1488
void CmdTechDrawShowAll::activated(int iMsg)
1491
Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
1493
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
1494
QObject::tr("Close active task dialog and try again."));
1498
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
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"));
1511
baseFeat = dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject());
1513
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
1514
QObject::tr("No Part Views in this selection"));
1518
Gui::ViewProvider* vp = QGIView::getViewProvider(baseFeat);
1519
auto partVP = dynamic_cast<ViewProviderViewPart*>(vp);
1521
bool state = partVP->ShowAllEdges.getValue();
1523
partVP->ShowAllEdges.setValue(state);
1524
baseFeat->requestPaint();
1528
bool CmdTechDrawShowAll::isActive()
1530
bool havePage = DrawGuiUtil::needPage(this);
1531
bool haveView = DrawGuiUtil::needView(this, true);
1532
return (havePage && haveView);
1535
//===========================================================================
1536
// TechDraw_WeldSymbol
1537
//===========================================================================
1539
DEF_STD_CMD_A(CmdTechDrawWeldSymbol)
1541
CmdTechDrawWeldSymbol::CmdTechDrawWeldSymbol()
1542
: Command("TechDraw_WeldSymbol")
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";
1553
void CmdTechDrawWeldSymbol::activated(int iMsg)
1557
Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
1559
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"),
1560
QObject::tr("Close active task dialog and try again."));
1564
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
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."));
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));
1589
Gui::Selection().clearSelection();
1592
bool CmdTechDrawWeldSymbol::isActive()
1594
bool havePage = DrawGuiUtil::needPage(this);
1595
bool haveView = DrawGuiUtil::needView(this, false);
1596
return (havePage && haveView);
1599
//===========================================================================
1600
// TechDraw_SurfaceFinishSymbols
1601
//===========================================================================
1603
DEF_STD_CMD_A(CmdTechDrawSurfaceFinishSymbols)
1605
CmdTechDrawSurfaceFinishSymbols::CmdTechDrawSurfaceFinishSymbols()
1606
: Command("TechDraw_SurfaceFinishSymbols")
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";
1619
void CmdTechDrawSurfaceFinishSymbols::activated(int iMsg)
1623
std::string ownerName;
1624
std::vector<Gui::SelectionObject> selection = this->getSelection().getSelectionEx();
1625
if (selection.empty())
1627
TechDraw::DrawPage *page = DrawGuiUtil::findPage(this);
1632
ownerName = page->getNameInDocument();
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"));
1643
ownerName = objFeat->getNameInDocument();
1645
const std::vector<std::string> &subNames = selection.front().getSubNames();
1646
if (!subNames.empty()) {
1648
ownerName += subNames.front();
1652
Gui::Control().showDialog(new TechDrawGui::TaskDlgSurfaceFinishSymbols(ownerName));
1655
Gui::Selection().clearSelection();
1658
bool CmdTechDrawSurfaceFinishSymbols::isActive()
1660
bool havePage = DrawGuiUtil::needPage(this);
1661
bool haveView = DrawGuiUtil::needView(this);
1662
return havePage && haveView;
1665
void CreateTechDrawCommandsAnnotate()
1667
Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager();
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());
1689
//===========================================================================
1690
// Selection Validation Helpers
1691
//===========================================================================
1693
std::vector<std::string> getSelectedSubElements(Gui::Command* cmd,
1694
TechDraw::DrawViewPart* &dvp,
1695
std::string subType)
1697
// Base::Console().Message("getSelectedSubElements() - dvp: %X\n", dvp);
1698
std::vector<std::string> selectedSubs;
1699
std::vector<std::string> subNames;
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();
1711
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"),
1712
QObject::tr("No Part View in Selection"));
1713
return selectedSubs;
1716
for (auto& s: subNames) {
1717
if (TechDraw::DrawUtil::getGeomTypeFromName(s) == subType) {
1718
selectedSubs.push_back(s);
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;
1730
return selectedSubs;