FreeCAD

Форк
0
/
TaskLeaderLine.cpp 
869 строк · 28.4 Кб
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 <cmath>
26
# include <QStatusBar>
27
#endif
28

29
#include <App/Document.h>
30
#include <Base/Console.h>
31
#include <Base/Tools.h>
32
#include <Gui/Application.h>
33
#include <Gui/BitmapFactory.h>
34
#include <Gui/Command.h>
35
#include <Gui/Document.h>
36
#include <Gui/MainWindow.h>
37
#include <Gui/ViewProvider.h>
38
#include <Mod/TechDraw/App/ArrowPropEnum.h>
39
#include <Mod/TechDraw/App/DrawLeaderLine.h>
40
#include <Mod/TechDraw/App/DrawPage.h>
41
#include <Mod/TechDraw/App/DrawView.h>
42
#include <Mod/TechDraw/App/LineGroup.h>
43

44
#include "TaskLeaderLine.h"
45
#include "ui_TaskLeaderLine.h"
46
#include "DrawGuiUtil.h"
47
#include "MDIViewPage.h"
48
#include "PreferencesGui.h"
49
#include "QGILeaderLine.h"
50
#include "QGIView.h"
51
#include "QGSPage.h"
52
#include "QGTracker.h"
53
#include "Rez.h"
54
#include "ViewProviderLeader.h"
55
#include "ViewProviderPage.h"
56

57

58
using namespace Gui;
59
using namespace TechDraw;
60
using namespace TechDrawGui;
61

62
//ctor for edit
63
TaskLeaderLine::TaskLeaderLine(TechDrawGui::ViewProviderLeader* leadVP) :
64
    ui(new Ui_TaskLeaderLine),
65
    m_tracker(nullptr),
66
    m_lineVP(leadVP),
67
    m_baseFeat(nullptr),
68
    m_basePage(nullptr),
69
    m_lineFeat(nullptr),
70
    m_qgParent(nullptr),
71
    m_createMode(false),
72
    m_trackerMode(QGTracker::None),
73
    m_saveContextPolicy(Qt::DefaultContextMenu),
74
    m_inProgressLock(false),
75
    m_qgLine(nullptr),
76
    m_btnOK(nullptr),
77
    m_btnCancel(nullptr),
78
    m_pbTrackerState(TRACKEREDIT),
79
    m_saveX(0.0),
80
    m_saveY(0.0)
81
{
82
    //existence of leadVP is guaranteed by caller being ViewProviderLeaderLine.setEdit
83

84
    m_lineFeat = m_lineVP->getFeature();
85

86
    m_basePage = m_lineFeat->findParentPage();
87
    if (!m_basePage) {
88
        Base::Console().Error("TaskRichAnno - bad parameters (2).  Can not proceed.\n");
89
        return;
90
    }
91
    App::DocumentObject* obj = m_lineFeat->LeaderParent.getValue();
92
    if (obj) {
93
        if (obj->isDerivedFrom(TechDraw::DrawView::getClassTypeId()) )  {
94
            m_baseFeat = static_cast<TechDraw::DrawView*>(m_lineFeat->LeaderParent.getValue());
95
        }
96
    }
97

98
    Gui::Document* activeGui = Gui::Application::Instance->getDocument(m_basePage->getDocument());
99
    Gui::ViewProvider* vp = activeGui->getViewProvider(m_basePage);
100
    m_vpp = static_cast<ViewProviderPage*>(vp);
101

102
    m_qgParent = nullptr;
103
    if (m_baseFeat) {
104
        m_qgParent = m_vpp->getQGSPage()->findQViewForDocObj(m_baseFeat);
105
    }
106

107
    //TODO: when/if leaders are allowed to be parented to Page, check for m_baseFeat will be removed
108
    if (!m_baseFeat || !m_basePage) {
109
        Base::Console().Error("TaskLeaderLine - bad parameters (2).  Can not proceed.\n");
110
        return;
111
    }
112

113
    ui->setupUi(this);
114

115
    setUiEdit();
116

117
    m_attachPoint = Rez::guiX(Base::Vector3d(m_lineFeat->X.getValue(),
118
                                            -m_lineFeat->Y.getValue(),
119
                                             0.0));
120

121
    connect(ui->pbTracker, &QPushButton::clicked,
122
            this, &TaskLeaderLine::onTrackerClicked);
123
    connect(ui->pbCancelEdit, &QPushButton::clicked,
124
            this, &TaskLeaderLine::onCancelEditClicked);
125
    ui->pbCancelEdit->setEnabled(false);
126

127
    saveState();
128

129
    m_trackerMode = QGTracker::TrackerMode::Line;
130
    if (m_vpp->getMDIViewPage())
131
        m_saveContextPolicy = m_vpp->getMDIViewPage()->contextMenuPolicy();
132
}
133

134
//ctor for creation
135
TaskLeaderLine::TaskLeaderLine(TechDraw::DrawView* baseFeat,
136
                               TechDraw::DrawPage* page) :
137
    ui(new Ui_TaskLeaderLine),
138
    m_tracker(nullptr),
139
    m_lineVP(nullptr),
140
    m_baseFeat(baseFeat),
141
    m_basePage(page),
142
    m_lineFeat(nullptr),
143
    m_qgParent(nullptr),
144
    m_createMode(true),
145
    m_trackerMode(QGTracker::None),
146
    m_saveContextPolicy(Qt::DefaultContextMenu),
147
    m_inProgressLock(false),
148
    m_qgLine(nullptr),
149
    m_btnOK(nullptr),
150
    m_btnCancel(nullptr),
151
    m_pbTrackerState(TRACKERPICK),
152
    m_saveX(0.0),
153
    m_saveY(0.0)
154
{
155
    //existence of basePage and baseFeat is checked in CmdTechDrawLeaderLine (CommandAnnotate.cpp)
156

157
    Gui::Document* activeGui = Gui::Application::Instance->getDocument(m_basePage->getDocument());
158
    Gui::ViewProvider* vp = activeGui->getViewProvider(m_basePage);
159
    m_vpp = static_cast<ViewProviderPage*>(vp);
160

161
    m_qgParent = nullptr;
162
    if (m_baseFeat) {
163
        m_qgParent = m_vpp->getQGSPage()->findQViewForDocObj(baseFeat);
164
    }
165

166
    ui->setupUi(this);
167

168
    setUiPrimary();
169

170
    connect(ui->pbTracker, &QPushButton::clicked,
171
            this, &TaskLeaderLine::onTrackerClicked);
172
    connect(ui->pbCancelEdit, &QPushButton::clicked,
173
            this, &TaskLeaderLine::onCancelEditClicked);
174
    ui->pbCancelEdit->setEnabled(false);
175

176
    m_trackerMode = QGTracker::TrackerMode::Line;
177
    if (m_vpp->getMDIViewPage())
178
        m_saveContextPolicy = m_vpp->getMDIViewPage()->contextMenuPolicy();
179
}
180

181
void TaskLeaderLine::saveState()
182
{
183
    if (m_lineFeat) {
184
        m_savePoints = m_lineFeat->WayPoints.getValues();
185
        m_saveX = m_lineFeat->X.getValue();
186
        m_saveY = m_lineFeat->Y.getValue();
187
    }
188
}
189

190
void TaskLeaderLine::restoreState()
191
{
192
    if (m_lineFeat) {
193
        m_lineFeat->WayPoints.setValues(m_savePoints);
194
        m_lineFeat->X.setValue(m_saveX);
195
        m_lineFeat->Y.setValue(m_saveY);
196
    }
197
}
198

199
void TaskLeaderLine::updateTask()
200
{
201
//    blockUpdate = true;
202

203
//    blockUpdate = false;
204
}
205

206
void TaskLeaderLine::changeEvent(QEvent *event)
207
{
208
    if (event->type() == QEvent::LanguageChange) {
209
        ui->retranslateUi(this);
210
    }
211
}
212

213
void TaskLeaderLine::setUiPrimary()
214
{
215
//    Base::Console().Message("TTL::setUiPrimary()\n");
216
    enableVPUi(true);
217
    setWindowTitle(QObject::tr("New Leader Line"));
218

219
    if (m_baseFeat) {
220
        std::string baseName = m_baseFeat->getNameInDocument();
221
        ui->tbBaseView->setText(Base::Tools::fromStdString(baseName));
222
    }
223

224
    ui->pbTracker->setText(tr("Pick points"));
225
    if (m_vpp->getMDIViewPage()) {
226
        ui->pbTracker->setEnabled(true);
227
        ui->pbCancelEdit->setEnabled(true);
228
    } else {
229
        ui->pbTracker->setEnabled(false);
230
        ui->pbCancelEdit->setEnabled(false);
231
    }
232

233
    DrawGuiUtil::loadArrowBox(ui->cboxStartSym);
234
    int aStyle = getPrefArrowStyle();
235
    ui->cboxStartSym->setCurrentIndex(aStyle);
236

237
    DrawGuiUtil::loadArrowBox(ui->cboxEndSym);
238
    ui->cboxEndSym->setCurrentIndex(TechDraw::ArrowType::NONE);
239

240
    ui->dsbWeight->setUnit(Base::Unit::Length);
241
    ui->dsbWeight->setMinimum(0);
242
    ui->dsbWeight->setValue(prefWeight());
243

244
    ui->cpLineColor->setColor(prefLineColor().asValue<QColor>());
245
}
246

247
//switch widgets related to ViewProvider on/off
248
//there is no ViewProvider until some time after feature is created.
249
void TaskLeaderLine::enableVPUi(bool enable)
250
{
251
    ui->cpLineColor->setEnabled(enable);
252
    ui->dsbWeight->setEnabled(enable);
253
    ui->cboxStyle->setEnabled(enable);
254
}
255

256
void TaskLeaderLine::setUiEdit()
257
{
258
//    Base::Console().Message("TTL::setUiEdit()\n");
259
    enableVPUi(true);
260
    setWindowTitle(QObject::tr("Edit Leader Line"));
261

262
    if (m_lineFeat) {
263
        std::string baseName = m_lineFeat->LeaderParent.getValue()->getNameInDocument();
264
        ui->tbBaseView->setText(Base::Tools::fromStdString(baseName));
265

266
        DrawGuiUtil::loadArrowBox(ui->cboxStartSym);
267
        ui->cboxStartSym->setCurrentIndex(m_lineFeat->StartSymbol.getValue());
268
        connect(ui->cboxStartSym, qOverload<int>(&QComboBox::currentIndexChanged), this, &TaskLeaderLine::onStartSymbolChanged);
269
        DrawGuiUtil::loadArrowBox(ui->cboxEndSym);
270
        ui->cboxEndSym->setCurrentIndex(m_lineFeat->EndSymbol.getValue());
271
        connect(ui->cboxEndSym, qOverload<int>(&QComboBox::currentIndexChanged), this, &TaskLeaderLine::onEndSymbolChanged);
272

273
        ui->pbTracker->setText(tr("Edit points"));
274
        if (m_vpp->getMDIViewPage()) {
275
            ui->pbTracker->setEnabled(true);
276
            ui->pbCancelEdit->setEnabled(true);
277
        } else {
278
            ui->pbTracker->setEnabled(false);
279
            ui->pbCancelEdit->setEnabled(false);
280
        }
281
    }
282

283
    if (m_lineVP) {
284
        ui->cpLineColor->setColor(m_lineVP->Color.getValue().asValue<QColor>());
285
        ui->dsbWeight->setValue(m_lineVP->LineWidth.getValue());
286
        ui->cboxStyle->setCurrentIndex(m_lineVP->LineStyle.getValue());
287
    }
288
    connect(ui->cpLineColor, &ColorButton::changed, this, &TaskLeaderLine::onColorChanged);
289
    ui->dsbWeight->setMinimum(0);
290
    connect(ui->dsbWeight, qOverload<double>(&QuantitySpinBox::valueChanged), this, &TaskLeaderLine::onLineWidthChanged);
291
    connect(ui->cboxStyle, qOverload<int>(&QComboBox::currentIndexChanged), this, &TaskLeaderLine::onLineStyleChanged);
292
}
293

294
void TaskLeaderLine::recomputeFeature()
295
{
296
    App::DocumentObject* objVP = m_lineVP->getObject();
297
    assert(objVP);
298
    objVP->getDocument()->recomputeFeature(objVP);
299
}
300

301
void TaskLeaderLine::onStartSymbolChanged()
302
{
303
    m_lineFeat->StartSymbol.setValue(ui->cboxStartSym->currentIndex());
304
    recomputeFeature();
305
}
306

307
void TaskLeaderLine::onEndSymbolChanged()
308
{
309
    m_lineFeat->EndSymbol.setValue(ui->cboxEndSym->currentIndex());
310
    recomputeFeature();
311
}
312

313
void TaskLeaderLine::onColorChanged()
314
{
315
    App::Color ac;
316
    ac.setValue<QColor>(ui->cpLineColor->color());
317
    m_lineVP->Color.setValue(ac);
318
    recomputeFeature();
319
}
320

321
void TaskLeaderLine::onLineWidthChanged()
322
{
323
    m_lineVP->LineWidth.setValue(ui->dsbWeight->rawValue());
324
    recomputeFeature();
325
}
326

327
void TaskLeaderLine::onLineStyleChanged()
328
{
329
    m_lineVP->LineStyle.setValue(ui->cboxStyle->currentIndex());
330
    recomputeFeature();
331
}
332

333

334
//******************************************************************************
335
void TaskLeaderLine::createLeaderFeature(std::vector<Base::Vector3d> converted)
336
{
337
//    Base::Console().Message("TTL::createLeaderFeature()\n");
338
    const std::string objectName{"LeaderLine"};
339
    std::string m_leaderName = m_basePage->getDocument()->getUniqueObjectName(objectName.c_str());
340
    m_leaderType = "TechDraw::DrawLeaderLine";
341

342
    std::string PageName = m_basePage->getNameInDocument();
343

344
    Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Create Leader"));
345
    Command::doCommand(Command::Doc, "App.activeDocument().addObject('%s', '%s')",
346
                       m_leaderType.c_str(), m_leaderName.c_str());
347
    Command::doCommand(Command::Doc, "App.activeDocument().%s.translateLabel('DrawLeaderLine', 'LeaderLine', '%s')",
348
              m_leaderName.c_str(), m_leaderName.c_str());
349

350
    Command::doCommand(Command::Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)",
351
                       PageName.c_str(), m_leaderName.c_str());
352
    if (m_baseFeat) {
353
        Command::doCommand(Command::Doc, "App.activeDocument().%s.LeaderParent = App.activeDocument().%s",
354
                               m_leaderName.c_str(), m_baseFeat->getNameInDocument());
355
    }
356

357
    App::DocumentObject* obj = m_basePage->getDocument()->getObject(m_leaderName.c_str());
358
    if (!obj)
359
        throw Base::RuntimeError("TaskLeaderLine - new markup object not found");
360
    if (obj->isDerivedFrom(TechDraw::DrawLeaderLine::getClassTypeId())) {
361
        m_lineFeat = static_cast<TechDraw::DrawLeaderLine*>(obj);
362
        m_lineFeat->setPosition(Rez::appX(m_attachPoint.x), Rez::appX(- m_attachPoint.y), true);
363
        if (!converted.empty()) {
364
            m_lineFeat->WayPoints.setValues(converted);
365
            if (m_lineFeat->AutoHorizontal.getValue()) {
366
                m_lineFeat->adjustLastSegment();
367
            }
368
        }
369
        commonFeatureUpdate();
370
    }
371

372
    if (m_lineFeat) {
373
        Gui::ViewProvider* vp = QGIView::getViewProvider(m_lineFeat);
374
        auto leadVP = dynamic_cast<ViewProviderLeader*>(vp);
375
        if (leadVP) {
376
            App::Color ac;
377
            ac.setValue<QColor>(ui->cpLineColor->color());
378
            leadVP->Color.setValue(ac);
379
            leadVP->LineWidth.setValue(ui->dsbWeight->rawValue());
380
            leadVP->LineStyle.setValue(ui->cboxStyle->currentIndex());
381
        }
382
    }
383

384
    Gui::Command::updateActive();
385
    Gui::Command::commitCommand();
386

387
    //trigger claimChildren in tree
388
    if (m_baseFeat) {
389
        m_baseFeat->touch();
390
    }
391

392
    m_basePage->touch();
393

394
    if (m_lineFeat) {
395
        m_lineFeat->requestPaint();
396
    }
397
}
398

399
void TaskLeaderLine::updateLeaderFeature()
400
{
401
//    Base::Console().Message("TTL::updateLeaderFeature()\n");
402
    Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Edit Leader"));
403
    //waypoints & x, y are updated by QGILeaderLine (for edits only!)
404
    commonFeatureUpdate();
405
    App::Color ac;
406
    ac.setValue<QColor>(ui->cpLineColor->color());
407
    m_lineVP->Color.setValue(ac);
408
    m_lineVP->LineWidth.setValue(ui->dsbWeight->rawValue());
409
    m_lineVP->LineStyle.setValue(ui->cboxStyle->currentIndex());
410

411
    Gui::Command::updateActive();
412
    Gui::Command::commitCommand();
413

414
    if (m_baseFeat) {
415
        m_baseFeat->requestPaint();
416
    }
417
    m_lineFeat->requestPaint();
418
}
419

420
void TaskLeaderLine::commonFeatureUpdate()
421
{
422
    int start = ui->cboxStartSym->currentIndex();
423
    int end   = ui->cboxEndSym->currentIndex();
424
    m_lineFeat->StartSymbol.setValue(start);
425
    m_lineFeat->EndSymbol.setValue(end);
426
}
427

428
void TaskLeaderLine::removeFeature()
429
{
430
//    Base::Console().Message("TTL::removeFeature()\n");
431
    if (!m_lineFeat)
432
        return;
433

434
    if (m_createMode) {
435
        try {
436
            std::string PageName = m_basePage->getNameInDocument();
437
            Gui::Command::doCommand(Gui::Command::Gui, "App.activeDocument().%s.removeView(App.activeDocument().%s)",
438
                                    PageName.c_str(), m_lineFeat->getNameInDocument());
439
            Gui::Command::doCommand(Gui::Command::Gui, "App.activeDocument().removeObject('%s')",
440
                                        m_lineFeat->getNameInDocument());
441
        }
442
        catch (...) {
443
            Base::Console().Message("TTL::removeFeature - failed to delete feature\n");
444
            return;
445
        }
446
    } else {
447
        if (Gui::Command::hasPendingCommand()) {
448
            std::vector<std::string> undos = Gui::Application::Instance->activeDocument()->getUndoVector();
449
            Gui::Application::Instance->activeDocument()->undo(1);
450
        }
451
    }
452
}
453

454
//********** Tracker routines *******************************************************************
455
void TaskLeaderLine::onTrackerClicked(bool clicked)
456
{
457
    Q_UNUSED(clicked);
458
//    Base::Console().Message("TTL::onTrackerClicked() m_pbTrackerState: %d\n",
459
//                            m_pbTrackerState);
460
    if (!m_vpp->getMDIViewPage()) {
461
        Base::Console().Message("TLL::onTrackerClicked - no Mdi, no Tracker!\n");
462
        return;
463
    }
464

465
    if ( (m_pbTrackerState == TRACKERSAVE) &&
466
         (getCreateMode())  ){
467
        if (m_tracker) {
468
            m_tracker->terminateDrawing();
469
        }
470
        m_pbTrackerState = TRACKERPICK;
471
        ui->pbTracker->setText(tr("Pick Points"));
472
        ui->pbCancelEdit->setEnabled(false);
473
        enableTaskButtons(true);
474

475
        setEditCursor(Qt::ArrowCursor);
476
        return;
477
    } else  if ( (m_pbTrackerState == TRACKERSAVE) &&
478
                 (!getCreateMode()) ) {                //edit mode
479
        if (m_qgLine) {
480
            m_qgLine->closeEdit();
481
        }
482
        m_pbTrackerState = TRACKERPICK;
483
        ui->pbTracker->setText(tr("Edit Points"));
484
        ui->pbCancelEdit->setEnabled(false);
485
        enableTaskButtons(true);
486

487
        setEditCursor(Qt::ArrowCursor);
488
        return;
489
    }
490

491
    //TRACKERPICK or TRACKEREDIT
492
    if (getCreateMode()) {
493
        m_inProgressLock = true;
494
        m_saveContextPolicy = m_vpp->getMDIViewPage()->contextMenuPolicy();
495
        m_vpp->getMDIViewPage()->setContextMenuPolicy(Qt::PreventContextMenu);
496
        m_trackerMode = QGTracker::TrackerMode::Line;
497
        setEditCursor(Qt::CrossCursor);
498
        startTracker();
499

500
        QString msg = tr("Pick a starting point for leader line");
501
        getMainWindow()->statusBar()->show();
502
        Gui::getMainWindow()->showMessage(msg, 3000);
503
        ui->pbTracker->setText(tr("Save Points"));
504
        ui->pbTracker->setEnabled(true);
505
        ui->pbCancelEdit->setEnabled(true);
506
        m_pbTrackerState = TRACKERSAVE;
507
        enableTaskButtons(false);
508
    } else {    //edit mode
509
        m_trackerPoints = m_lineFeat->WayPoints.getValues();
510
        if (!m_trackerPoints.empty()) {    //regular edit session
511
            m_inProgressLock = true;
512
            m_saveContextPolicy = m_vpp->getMDIViewPage()->contextMenuPolicy();
513
            m_vpp->getMDIViewPage()->setContextMenuPolicy(Qt::PreventContextMenu);
514
            QGIView* qgiv = m_vpp->getQGSPage()->findQViewForDocObj(m_lineFeat);
515
            QGILeaderLine* qgLead = dynamic_cast<QGILeaderLine*>(qgiv);
516

517
            if (!qgLead) {
518
                //tarfu
519
                Base::Console().Error("TaskLeaderLine - can't find leader graphic\n");
520
                //now what? throw will generate "unknown unhandled exception"
521
            } else {
522
                m_qgLine = qgLead;
523
                connect(qgLead, &QGILeaderLine::editComplete,
524
                this, &TaskLeaderLine::onPointEditComplete);
525
                qgLead->startPathEdit();
526
                QString msg = tr("Click and drag markers to adjust leader line");
527
                getMainWindow()->statusBar()->show();
528
                Gui::getMainWindow()->showMessage(msg, 3000);
529
                ui->pbTracker->setText(tr("Save changes"));
530
                ui->pbTracker->setEnabled(true);
531
                ui->pbCancelEdit->setEnabled(true);
532
                m_pbTrackerState = TRACKERSAVE;
533
                enableTaskButtons(false);
534
            }
535
        } else { // need to recreate leaderline
536
            m_inProgressLock = true;
537
            m_saveContextPolicy = m_vpp->getMDIViewPage()->contextMenuPolicy();
538
            m_vpp->getMDIViewPage()->setContextMenuPolicy(Qt::PreventContextMenu);
539
            m_trackerMode = QGTracker::TrackerMode::Line;
540
            setEditCursor(Qt::CrossCursor);
541
            startTracker();
542

543
            QString msg = tr("Pick a starting point for leader line");
544
            getMainWindow()->statusBar()->show();
545
            Gui::getMainWindow()->showMessage(msg, 3000);
546
            ui->pbTracker->setText(tr("Save changes"));
547
            ui->pbTracker->setEnabled(true);
548
            ui->pbCancelEdit->setEnabled(true);
549
            m_pbTrackerState = TRACKERSAVE;
550
            enableTaskButtons(false);
551
        }
552
    }
553
}
554

555
void TaskLeaderLine::startTracker()
556
{
557
//    Base::Console().Message("TTL::startTracker()\n");
558
    if (!m_vpp->getQGSPage())
559
        return;
560
    if (m_trackerMode == QGTracker::TrackerMode::None)
561
        return;
562

563
    if (!m_tracker) {
564
        m_tracker = new QGTracker(m_vpp->getQGSPage(), m_trackerMode);
565
        QObject::connect(
566
            m_tracker, &QGTracker::drawingFinished,
567
            this     , &TaskLeaderLine::onTrackerFinished
568
           );
569
    } else {
570
        //this is too harsh. but need to avoid restarting process
571
        throw Base::RuntimeError("TechDrawNewLeader - tracker already active\n");
572
    }
573
    setEditCursor(Qt::CrossCursor);
574
    QString msg = tr("Left click to set a point");
575
    Gui::getMainWindow()->statusBar()->show();
576
    Gui::getMainWindow()->showMessage(msg, 3000);
577
}
578

579
void TaskLeaderLine::onTrackerFinished(std::vector<QPointF> pts, QGIView* qgParent)
580
{
581
    //in this case, we already know who the parent is.  We don't need QGTracker to tell us.
582
    (void) qgParent;
583
//    Base::Console().Message("TTL::onTrackerFinished() - parent: %X\n", qgParent);
584
    if (pts.empty()) {
585
        Base::Console().Error("TaskLeaderLine - no points available\n");
586
        return;
587
    }
588

589
    if (m_qgParent) {
590
        double scale = m_qgParent->getScale();
591
        QPointF mapped = m_qgParent->mapFromScene(pts.front()) / scale;
592
        m_attachPoint = Base::Vector3d(mapped.x(), mapped.y(), 0.0);
593
        trackerPointsFromQPoints(pts);
594
    } else {
595
        Base::Console().Message("TTL::onTrackerFinished - can't find parent graphic!\n");
596
        //blow up!?
597
        throw Base::RuntimeError("TaskLeaderLine - can not find parent graphic");
598
    }
599

600
    QString msg = tr("Press OK or Cancel to continue");
601
    getMainWindow()->statusBar()->show();
602
    Gui::getMainWindow()->showMessage(msg, 3000);
603
    enableTaskButtons(true);
604

605
    m_tracker->sleep(true);
606
    m_inProgressLock = false;
607
    ui->pbTracker->setEnabled(false);
608
    ui->pbCancelEdit->setEnabled(false);
609
    enableTaskButtons(true);
610
    setEditCursor(Qt::ArrowCursor);
611
}
612

613
void TaskLeaderLine::removeTracker()
614
{
615
//    Base::Console().Message("TTL::removeTracker()\n");
616
    if (!m_vpp->getQGSPage())
617
        return;
618
    if (m_tracker && m_tracker->scene()) {
619
        m_vpp->getQGSPage()->removeItem(m_tracker);
620
        delete m_tracker;
621
        m_tracker = nullptr;
622
    }
623
}
624

625
void TaskLeaderLine::onCancelEditClicked(bool clicked)
626
{
627
    Q_UNUSED(clicked);
628
//    Base::Console().Message("TTL::onCancelEditClicked() m_pbTrackerState: %d\n",
629
//                            m_pbTrackerState);
630
    abandonEditSession();
631
    if (m_lineFeat) {
632
        m_lineFeat->requestPaint();
633
    }
634

635
    m_pbTrackerState = TRACKEREDIT;
636
    ui->pbTracker->setText(tr("Edit points"));
637
    ui->pbCancelEdit->setEnabled(false);
638
    enableTaskButtons(true);
639

640
    m_inProgressLock = false;
641
    setEditCursor(Qt::ArrowCursor);
642
}
643

644
QGIView* TaskLeaderLine::findParentQGIV()
645
{
646
    if (!m_baseFeat)
647
        return nullptr;
648

649
    Gui::ViewProvider* gvp = QGIView::getViewProvider(m_baseFeat);
650
    ViewProviderDrawingView* vpdv = dynamic_cast<ViewProviderDrawingView*>(gvp);
651
    if (!vpdv)
652
        return nullptr;
653

654
    return vpdv->getQView();;
655
}
656

657
void TaskLeaderLine::setEditCursor(QCursor cursor)
658
{
659
    if (!m_vpp->getQGSPage()) {
660
        return;
661
    }
662
    if (m_baseFeat) {
663
        QGIView* qgivBase = m_vpp->getQGSPage()->findQViewForDocObj(m_baseFeat);
664
        qgivBase->setCursor(cursor);
665
    }
666
}
667

668
//from 1:1 scale scene QPointF to zero origin Vector3d points
669
void TaskLeaderLine::trackerPointsFromQPoints(std::vector<QPointF> pts)
670
{
671
//    Base::Console().Message("TTL::trackerPointsFromQPoints(%d)\n", pts.size());
672
    m_trackerPoints.clear();
673
    for (auto& p: pts) {
674
        QPointF mapped = p - pts.front();
675
        Base::Vector3d convert(mapped.x(), mapped.y(), 0.0);
676
        m_trackerPoints.push_back(convert);
677
    }
678
}
679

680
//******************************************************************************
681
//void TaskLeaderLine::onPointEditComplete(std::vector<QPointF> pts, QGIView* parent)
682
void TaskLeaderLine::onPointEditComplete()
683
{
684
//    Base::Console().Message("TTL::onPointEditComplete()\n");
685
    m_inProgressLock = false;
686

687
    m_pbTrackerState = TRACKEREDIT;
688
    ui->pbTracker->setText(tr("Edit points"));
689
    ui->pbTracker->setEnabled(true);
690
    ui->pbCancelEdit->setEnabled(true);
691
    enableTaskButtons(true);
692
}
693

694
void TaskLeaderLine::abandonEditSession()
695
{
696
//    Base::Console().Message("TTL::abandonEditSession()\n");
697
    if (m_qgLine) {
698
        m_qgLine->abandonEdit();
699
    }
700
    QString msg = tr("In progress edit abandoned. Start over.");
701
    getMainWindow()->statusBar()->show();
702
    Gui::getMainWindow()->showMessage(msg, 4000);
703

704
    m_pbTrackerState = TRACKEREDIT;
705
    ui->pbTracker->setText(tr("Edit points"));
706
    enableTaskButtons(true);
707
    ui->pbTracker->setEnabled(true);
708
    ui->pbCancelEdit->setEnabled(false);
709

710
    setEditCursor(Qt::ArrowCursor);
711
}
712

713
void TaskLeaderLine::saveButtons(QPushButton* btnOK,
714
                             QPushButton* btnCancel)
715
{
716
    m_btnOK = btnOK;
717
    m_btnCancel = btnCancel;
718
}
719

720
void TaskLeaderLine::enableTaskButtons(bool enable)
721
{
722
    m_btnOK->setEnabled(enable);
723
    m_btnCancel->setEnabled(enable);
724
}
725

726
int TaskLeaderLine::getPrefArrowStyle()
727
{
728
    return PreferencesGui::dimArrowStyle();
729
}
730

731
double TaskLeaderLine::prefWeight() const
732
{
733
    return TechDraw::LineGroup::getDefaultWidth("Thin");
734
}
735

736
App::Color TaskLeaderLine::prefLineColor()
737
{
738
    return PreferencesGui::leaderColor();
739
}
740

741
//******************************************************************************
742

743
bool TaskLeaderLine::accept()
744
{
745
//    Base::Console().Message("TTL::accept()\n");
746
    if (m_inProgressLock) {
747
        //accept() button shouldn't be available if there is an edit in progress.
748
        abandonEditSession();
749
        removeTracker();
750
        return true;
751
    }
752

753
    Gui::Document* doc = Gui::Application::Instance->getDocument(m_basePage->getDocument());
754
    if (!doc)
755
        return false;
756

757
    if (!getCreateMode())  {
758
//        removeTracker();
759
        updateLeaderFeature();
760
    } else {
761
//        removeTracker();
762
        createLeaderFeature(m_trackerPoints);
763
    }
764
    m_trackerMode = QGTracker::TrackerMode::None;
765
    removeTracker();
766

767
    Gui::Command::doCommand(Gui::Command::Gui, "Gui.ActiveDocument.resetEdit()");
768

769
    if (m_vpp->getMDIViewPage())
770
        m_vpp->getMDIViewPage()->setContextMenuPolicy(m_saveContextPolicy);
771

772
    return true;
773
}
774

775
bool TaskLeaderLine::reject()
776
{
777
    if (m_inProgressLock) {
778
//        Base::Console().Message("TTL::reject - edit in progress!!\n");
779
        //reject() button shouldn't be available if there is an edit in progress.
780
        abandonEditSession();
781
        removeTracker();
782
        return false;
783
    }
784

785
    Gui::Document* doc = Gui::Application::Instance->getDocument(m_basePage->getDocument());
786
    if (!doc)
787
        return false;
788

789
    if (getCreateMode() && m_lineFeat)  {
790
        removeFeature();
791
    }
792
    else  {
793
        restoreState();
794
    }
795

796
    m_trackerMode = QGTracker::TrackerMode::None;
797
    removeTracker();
798

799
    //make sure any dangling objects are cleaned up
800
    Gui::Command::doCommand(Gui::Command::Gui, "App.activeDocument().recompute()");
801
    Gui::Command::doCommand(Gui::Command::Gui, "Gui.ActiveDocument.resetEdit()");
802

803
    if (m_vpp->getMDIViewPage()) {
804
        m_vpp->getMDIViewPage()->setContextMenuPolicy(m_saveContextPolicy);
805
    }
806

807
    return false;
808
}
809

810
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
811
TaskDlgLeaderLine::TaskDlgLeaderLine(TechDraw::DrawView* baseFeat,
812
                                     TechDraw::DrawPage* page)
813
    : TaskDialog()
814
{
815
    widget  = new TaskLeaderLine(baseFeat, page);
816
    taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/TechDraw_LeaderLine"),
817
                                             widget->windowTitle(), true, nullptr);
818
    taskbox->groupLayout()->addWidget(widget);
819
    Content.push_back(taskbox);
820
}
821

822
TaskDlgLeaderLine::TaskDlgLeaderLine(TechDrawGui::ViewProviderLeader* leadVP)
823
    : TaskDialog()
824
{
825
    widget  = new TaskLeaderLine(leadVP);
826
    taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/TechDraw_LeaderLine"),
827
                                             widget->windowTitle(), true, nullptr);
828
    taskbox->groupLayout()->addWidget(widget);
829
    Content.push_back(taskbox);
830
}
831

832
TaskDlgLeaderLine::~TaskDlgLeaderLine()
833
{
834
}
835

836
void TaskDlgLeaderLine::update()
837
{
838
//    widget->updateTask();
839
}
840

841
void TaskDlgLeaderLine::modifyStandardButtons(QDialogButtonBox* box)
842
{
843
    QPushButton* btnOK = box->button(QDialogButtonBox::Ok);
844
    QPushButton* btnCancel = box->button(QDialogButtonBox::Cancel);
845
    widget->saveButtons(btnOK, btnCancel);
846
}
847

848
//==== calls from the TaskView ===============================================================
849
void TaskDlgLeaderLine::open()
850
{
851
}
852

853
void TaskDlgLeaderLine::clicked(int)
854
{
855
}
856

857
bool TaskDlgLeaderLine::accept()
858
{
859
    widget->accept();
860
    return true;
861
}
862

863
bool TaskDlgLeaderLine::reject()
864
{
865
    widget->reject();
866
    return true;
867
}
868

869
#include <Mod/TechDraw/Gui/moc_TaskLeaderLine.cpp>
870

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

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

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

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