23
#include "PreCompiled.h"
25
#include <App/Document.h>
26
#include <Base/Console.h>
27
#include <Base/Tools.h>
28
#include <Base/UnitsApi.h>
29
#include <Gui/Application.h>
30
#include <Gui/BitmapFactory.h>
31
#include <Gui/Command.h>
32
#include <Gui/Document.h>
33
#include <Gui/Selection.h>
34
#include <Gui/ViewProvider.h>
35
#include <Mod/TechDraw/App/DrawPage.h>
36
#include <Mod/TechDraw/App/DrawProjGroup.h>
37
#include <Mod/TechDraw/App/DrawProjGroupItem.h>
38
#include <Mod/TechDraw/App/DrawViewDetail.h>
39
#include <Mod/TechDraw/App/DrawViewPart.h>
41
#include "ui_TaskDetail.h"
42
#include "TaskDetail.h"
43
#include "QGIGhostHighlight.h"
46
#include "ViewProviderPage.h"
49
using namespace TechDrawGui;
50
using namespace TechDraw;
53
static constexpr int CREATEMODE(0);
54
static constexpr int EDITMODE(1);
57
TaskDetail::TaskDetail(TechDraw::DrawViewPart* baseFeat):
58
ui(new Ui_TaskDetail),
61
m_detailFeat(nullptr),
65
m_inProgressLock(false),
68
m_saveAnchor(Base::Vector3d(0.0, 0.0, 0.0)),
71
m_baseName(std::string()),
72
m_pageName(std::string()),
73
m_detailName(std::string()),
80
m_basePage = m_baseFeat->findParentPage();
83
Base::Console().Error("TaskDetail - bad parameters - base page. Can not proceed.\n");
87
m_baseName = m_baseFeat->getNameInDocument();
88
m_doc = m_baseFeat->getDocument();
89
m_pageName = m_basePage->getNameInDocument();
93
Gui::Document* activeGui = Gui::Application::Instance->getDocument(m_doc);
94
Gui::ViewProvider* vp = activeGui->getViewProvider(m_basePage);
95
m_vpp = static_cast<ViewProviderPage*>(vp);
99
setWindowTitle(QObject::tr("New Detail View"));
101
connect(ui->pbDragger, &QPushButton::clicked,
102
this, &TaskDetail::onDraggerClicked);
106
connect(ui->qsbX, qOverload<double>(&QuantitySpinBox::valueChanged),
107
this, &TaskDetail::onXEdit);
108
connect(ui->qsbY, qOverload<double>(&QuantitySpinBox::valueChanged),
109
this, &TaskDetail::onYEdit);
110
connect(ui->qsbRadius, qOverload<double>(&QuantitySpinBox::valueChanged),
111
this, &TaskDetail::onRadiusEdit);
112
connect(ui->cbScaleType, qOverload<int>(&QComboBox::currentIndexChanged),
113
this, &TaskDetail::onScaleTypeEdit);
114
connect(ui->qsbScale, qOverload<double>(&QuantitySpinBox::valueChanged),
115
this, &TaskDetail::onScaleEdit);
116
connect(ui->leReference, &QLineEdit::editingFinished,
117
this, &TaskDetail::onReferenceEdit);
119
m_ghost = new QGIGhostHighlight();
120
m_vpp->getQGSPage()->addItem(m_ghost);
122
connect(m_ghost, &QGIGhostHighlight::positionChange,
123
this, &TaskDetail::onHighlightMoved);
127
TaskDetail::TaskDetail(TechDraw::DrawViewDetail* detailFeat):
128
ui(new Ui_TaskDetail),
131
m_detailFeat(detailFeat),
135
m_inProgressLock(false),
137
m_btnCancel(nullptr),
138
m_saveAnchor(Base::Vector3d(0.0, 0.0, 0.0)),
141
m_baseName(std::string()),
142
m_pageName(std::string()),
143
m_detailName(std::string()),
150
Base::Console().Error("TaskDetail - bad parameters. Can not proceed.\n");
154
m_doc = m_detailFeat->getDocument();
155
m_detailName = m_detailFeat->getNameInDocument();
157
m_basePage = m_detailFeat->findParentPage();
159
m_pageName = m_basePage->getNameInDocument();
162
App::DocumentObject* baseObj = m_detailFeat->BaseView.getValue();
163
m_baseFeat = dynamic_cast<TechDraw::DrawViewPart*>(baseObj);
165
m_baseName = m_baseFeat->getNameInDocument();
167
Base::Console().Error("TaskDetail - no BaseView. Can not proceed.\n");
173
Gui::Document* activeGui = Gui::Application::Instance->getDocument(m_basePage->getDocument());
174
Gui::ViewProvider* vp = activeGui->getViewProvider(m_basePage);
175
m_vpp = static_cast<ViewProviderPage*>(vp);
179
setWindowTitle(QObject::tr("Edit Detail View"));
181
connect(ui->pbDragger, &QPushButton::clicked,
182
this, &TaskDetail::onDraggerClicked);
186
connect(ui->qsbX, qOverload<double>(&QuantitySpinBox::valueChanged),
187
this, &TaskDetail::onXEdit);
188
connect(ui->qsbY, qOverload<double>(&QuantitySpinBox::valueChanged),
189
this, &TaskDetail::onYEdit);
190
connect(ui->qsbRadius, qOverload<double>(&QuantitySpinBox::valueChanged),
191
this, &TaskDetail::onRadiusEdit);
192
connect(ui->cbScaleType, qOverload<int>(&QComboBox::currentIndexChanged),
193
this, &TaskDetail::onScaleTypeEdit);
194
connect(ui->qsbScale, qOverload<double>(&QuantitySpinBox::valueChanged),
195
this, &TaskDetail::onScaleEdit);
196
connect(ui->leReference, &QLineEdit::editingFinished,
197
this, &TaskDetail::onReferenceEdit);
199
m_ghost = new QGIGhostHighlight();
200
m_vpp->getQGSPage()->addItem(m_ghost);
202
connect(m_ghost, &QGIGhostHighlight::positionChange,
203
this, &TaskDetail::onHighlightMoved);
206
void TaskDetail::updateTask()
213
void TaskDetail::changeEvent(QEvent *e)
215
if (e->type() == QEvent::LanguageChange) {
216
ui->retranslateUi(this);
221
void TaskDetail::saveDetailState()
224
TechDraw::DrawViewDetail* dvd = getDetailFeat();
225
m_saveAnchor = dvd->AnchorPoint.getValue();
226
m_saveRadius = dvd->Radius.getValue();
230
void TaskDetail::restoreDetailState()
233
TechDraw::DrawViewDetail* dvd = getDetailFeat();
234
dvd->AnchorPoint.setValue(m_saveAnchor);
235
dvd->Radius.setValue(m_saveRadius);
240
void TaskDetail::setUiFromFeat()
244
std::string baseName = getBaseFeat()->getNameInDocument();
245
ui->leBaseView->setText(Base::Tools::fromStdString(baseName));
248
Base::Vector3d anchor;
250
TechDraw::DrawViewDetail* detailFeat = getDetailFeat();
251
QString detailDisplay = QString::fromUtf8(detailFeat->getNameInDocument()) +
252
QString::fromUtf8(" / ") +
253
QString::fromUtf8(detailFeat->Label.getValue());
254
ui->leDetailView->setText(detailDisplay);
255
anchor = detailFeat->AnchorPoint.getValue();
256
double radius = detailFeat->Radius.getValue();
257
long ScaleType = detailFeat->ScaleType.getValue();
258
double scale = detailFeat->Scale.getValue();
259
QString ref = QString::fromUtf8(detailFeat->Reference.getValue());
261
ui->pbDragger->setText(tr("Drag Highlight"));
262
ui->pbDragger->setEnabled(true);
263
int decimals = Base::UnitsApi::getDecimals();
264
ui->qsbX->setUnit(Base::Unit::Length);
265
ui->qsbX->setDecimals(decimals);
266
ui->qsbX->setValue(anchor.x);
267
ui->qsbY->setUnit(Base::Unit::Length);
268
ui->qsbY->setDecimals(decimals);
269
ui->qsbY->setValue(anchor.y);
270
ui->qsbRadius->setDecimals(decimals);
271
ui->qsbRadius->setUnit(Base::Unit::Length);
272
ui->qsbRadius->setValue(radius);
273
ui->qsbScale->setDecimals(decimals);
274
ui->cbScaleType->setCurrentIndex(ScaleType);
275
if (ui->cbScaleType->currentIndex() == 2)
276
ui->qsbScale->setEnabled(true);
278
ui->qsbScale->setEnabled(false);
279
ui->qsbScale->setValue(scale);
280
ui->leReference->setText(ref);
284
void TaskDetail::updateUi(QPointF pos)
286
ui->qsbX->setValue(pos.x());
287
ui->qsbY->setValue(- pos.y());
290
void TaskDetail::enableInputFields(bool isEnabled)
292
ui->qsbX->setEnabled(isEnabled);
293
ui->qsbY->setEnabled(isEnabled);
294
if (ui->cbScaleType->currentIndex() == 2)
295
ui->qsbScale->setEnabled(isEnabled);
296
ui->qsbRadius->setEnabled(isEnabled);
297
ui->leReference->setEnabled(isEnabled);
300
void TaskDetail::onXEdit()
305
void TaskDetail::onYEdit()
310
void TaskDetail::onRadiusEdit()
315
void TaskDetail::onScaleTypeEdit()
317
TechDraw::DrawViewDetail* detailFeat = getDetailFeat();
319
if (ui->cbScaleType->currentIndex() == 0) {
321
ui->qsbScale->setEnabled(false);
322
detailFeat->ScaleType.setValue(0.0);
326
detailFeat->Scale.setValue(m_basePage->Scale.getValue());
327
ui->qsbScale->setValue(m_basePage->Scale.getValue());
332
else if (ui->cbScaleType->currentIndex() == 1) {
334
ui->qsbScale->setEnabled(false);
335
detailFeat->ScaleType.setValue(1.0);
339
else if (ui->cbScaleType->currentIndex() == 2) {
341
ui->qsbScale->setEnabled(true);
342
detailFeat->ScaleType.setValue(2.0);
347
void TaskDetail::onScaleEdit()
352
void TaskDetail::onReferenceEdit()
357
void TaskDetail::onDraggerClicked(bool clicked)
360
ui->pbDragger->setEnabled(false);
361
enableInputFields(false);
366
void TaskDetail::editByHighlight()
370
Base::Console().Error("TaskDetail::editByHighlight - no ghost object\n");
374
double scale = getBaseFeat()->getScale();
375
m_vpp->getQGSPage()->clearSelection();
376
m_ghost->setSelected(true);
377
m_ghost->setRadius(ui->qsbRadius->rawValue() * scale);
378
m_ghost->setPos(getAnchorScene());
384
void TaskDetail::onHighlightMoved(QPointF dragEnd)
388
ui->pbDragger->setEnabled(true);
390
double scale = getBaseFeat()->getScale();
391
double x = Rez::guiX(getBaseFeat()->X.getValue());
392
double y = Rez::guiX(getBaseFeat()->Y.getValue());
394
DrawViewPart* dvp = getBaseFeat();
395
DrawProjGroupItem* dpgi = dynamic_cast<DrawProjGroupItem*>(dvp);
397
DrawProjGroup* dpg = dpgi->getPGroup();
399
Base::Console().Message("TD::getAnchorScene - projection group is confused\n");
403
x += Rez::guiX(dpg->X.getValue());
404
y += Rez::guiX(dpg->Y.getValue());
407
QPointF basePosScene(x, -y);
408
QPointF anchorDisplace = dragEnd - basePosScene;
409
QPointF newAnchorPos = Rez::appX(anchorDisplace / scale);
411
updateUi(newAnchorPos);
413
enableInputFields(true);
414
m_ghost->setSelected(false);
418
void TaskDetail::saveButtons(QPushButton* btnOK,
419
QPushButton* btnCancel)
422
m_btnCancel = btnCancel;
425
void TaskDetail::enableTaskButtons(bool button)
427
m_btnOK->setEnabled(button);
428
m_btnCancel->setEnabled(button);
432
void TaskDetail::createDetail()
435
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Create Detail View"));
437
const std::string objectName{"Detail"};
438
m_detailName = m_doc->getUniqueObjectName(objectName.c_str());
439
std::string generatedSuffix {m_detailName.substr(objectName.length())};
441
Gui::Command::doCommand(Command::Doc, "App.activeDocument().addObject('TechDraw::DrawViewDetail', '%s')",
442
m_detailName.c_str());
444
Gui::Command::doCommand(Command::Doc, "App.activeDocument().%s.translateLabel('DrawViewDetail', 'Detail', '%s')",
445
m_detailName.c_str(), m_detailName.c_str());
447
App::DocumentObject *docObj = m_baseFeat->getDocument()->getObject(m_detailName.c_str());
448
TechDraw::DrawViewDetail* dvd = dynamic_cast<TechDraw::DrawViewDetail *>(docObj);
450
throw Base::TypeError("TaskDetail - new detail view not found\n");
453
dvd->Source.setValues(getBaseFeat()->Source.getValues());
455
Gui::Command::doCommand(Command::Doc, "App.activeDocument().%s.BaseView = App.activeDocument().%s",
456
m_detailName.c_str(), m_baseName.c_str());
457
Gui::Command::doCommand(Command::Doc, "App.activeDocument().%s.Direction = App.activeDocument().%s.Direction",
458
m_detailName.c_str(), m_baseName.c_str());
459
Gui::Command::doCommand(Command::Doc, "App.activeDocument().%s.XDirection = App.activeDocument().%s.XDirection",
460
m_detailName.c_str(), m_baseName.c_str());
461
Gui::Command::doCommand(Command::Doc, "App.activeDocument().%s.Scale = App.activeDocument().%s.Scale",
462
m_detailName.c_str(), m_baseName.c_str());
463
Gui::Command::doCommand(Command::Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)",
464
m_pageName.c_str(), m_detailName.c_str());
466
Gui::Command::updateActive();
467
Gui::Command::commitCommand();
469
getBaseFeat()->requestPaint();
473
void TaskDetail::updateDetail()
477
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Update Detail"));
478
double x = ui->qsbX->rawValue();
479
double y = ui->qsbY->rawValue();
480
Base::Vector3d temp(x, y, 0.0);
481
TechDraw::DrawViewDetail* detailFeat = getDetailFeat();
482
detailFeat->AnchorPoint.setValue(temp);
483
double scale = ui->qsbScale->rawValue();
484
detailFeat->Scale.setValue(scale);
485
double radius = ui->qsbRadius->rawValue();
486
detailFeat->Radius.setValue(radius);
487
QString qRef = ui->leReference->text();
488
std::string ref = Base::Tools::toStdString(qRef);
489
detailFeat->Reference.setValue(ref);
491
detailFeat->recomputeFeature();
492
getBaseFeat()->requestPaint();
493
Gui::Command::updateActive();
494
Gui::Command::commitCommand();
498
Base::Console().Error("Task Detail - detail feature update failed.\n");
505
QPointF TaskDetail::getAnchorScene()
507
DrawViewPart* dvp = getBaseFeat();
508
DrawProjGroupItem* dpgi = dynamic_cast<DrawProjGroupItem*>(dvp);
509
DrawViewDetail* dvd = getDetailFeat();
510
Base::Vector3d anchorPos = dvd->AnchorPoint.getValue();
511
anchorPos.y = -anchorPos.y;
512
Base::Vector3d basePos;
516
double x = dvp->X.getValue();
517
double y = dvp->Y.getValue();
518
basePos = Base::Vector3d (x, -y, 0.0);
519
scale = dvp->getScale();
522
DrawProjGroup* dpg = dpgi->getPGroup();
524
Base::Console().Message("TD::getAnchorScene - projection group is confused\n");
526
return QPointF(0.0, 0.0);
528
double x = dpg->X.getValue();
529
x += dpgi->X.getValue();
530
double y = dpg->Y.getValue();
531
y += dpgi->Y.getValue();
532
basePos = Base::Vector3d(x, -y, 0.0);
533
scale = dpgi->getScale();
536
Base::Vector3d xyScene = Rez::guiX(basePos);
537
Base::Vector3d anchorOffsetScene = Rez::guiX(anchorPos) * scale;
538
Base::Vector3d netPos = xyScene + anchorOffsetScene;
539
return QPointF(netPos.x, netPos.y);
543
DrawViewPart* TaskDetail::getBaseFeat()
548
App::DocumentObject* baseObj = m_doc->getObject(m_baseName.c_str());
550
return static_cast<DrawViewPart*>(baseObj);
554
std::string msg = "TaskDetail - base feature " +
557
throw Base::TypeError(msg);
562
DrawViewDetail* TaskDetail::getDetailFeat()
567
App::DocumentObject* detailObj = m_baseFeat->getDocument()->getObject(m_detailName.c_str());
569
return static_cast<DrawViewDetail*>(detailObj);
573
std::string msg = "TaskDetail - detail feature " +
577
throw Base::TypeError(msg);
583
bool TaskDetail::accept()
587
Gui::Document* doc = Gui::Application::Instance->getDocument(m_basePage->getDocument());
592
getDetailFeat()->requestPaint();
593
getBaseFeat()->requestPaint();
594
Gui::Command::doCommand(Gui::Command::Gui, "Gui.ActiveDocument.resetEdit()");
599
bool TaskDetail::reject()
602
Gui::Document* doc = Gui::Application::Instance->getDocument(m_basePage->getDocument());
607
if (m_mode == CREATEMODE) {
609
Gui::Command::doCommand(Gui::Command::Gui, "App.activeDocument().removeObject('%s')",
610
m_detailName.c_str());
613
restoreDetailState();
614
getDetailFeat()->recomputeFeature();
615
getBaseFeat()->requestPaint();
618
Gui::Command::doCommand(Gui::Command::Gui, "App.activeDocument().recompute()");
619
Gui::Command::doCommand(Gui::Command::Gui, "Gui.ActiveDocument.resetEdit()");
625
TaskDlgDetail::TaskDlgDetail(TechDraw::DrawViewPart* baseFeat)
628
widget = new TaskDetail(baseFeat);
629
taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/TechDraw_DetailView"),
630
widget->windowTitle(), true, nullptr);
631
taskbox->groupLayout()->addWidget(widget);
632
Content.push_back(taskbox);
635
TaskDlgDetail::TaskDlgDetail(TechDraw::DrawViewDetail* detailFeat)
638
widget = new TaskDetail(detailFeat);
639
taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/TechDraw_DetailView"),
640
widget->windowTitle(), true, nullptr);
641
taskbox->groupLayout()->addWidget(widget);
642
Content.push_back(taskbox);
645
TaskDlgDetail::~TaskDlgDetail()
649
void TaskDlgDetail::update()
654
void TaskDlgDetail::modifyStandardButtons(QDialogButtonBox* box)
656
QPushButton* btnOK = box->button(QDialogButtonBox::Ok);
657
QPushButton* btnCancel = box->button(QDialogButtonBox::Cancel);
658
widget->saveButtons(btnOK, btnCancel);
662
void TaskDlgDetail::open()
666
void TaskDlgDetail::clicked(int)
670
bool TaskDlgDetail::accept()
676
bool TaskDlgDetail::reject()
682
#include <Mod/TechDraw/Gui/moc_TaskDetail.cpp>