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"
26
# include <QPushButton>
27
#endif // #ifndef _PreComp_
29
#include <App/Document.h>
30
#include <Base/Console.h>
31
#include <Base/Tools.h>
32
#include <Gui/BitmapFactory.h>
33
#include <Gui/Command.h>
34
#include <Gui/Document.h>
36
#include <Mod/TechDraw/App/DrawPage.h>
37
#include <Mod/TechDraw/App/DrawLeaderLine.h>
38
#include <Mod/TechDraw/App/DrawTileWeld.h>
39
#include <Mod/TechDraw/App/DrawWeldSymbol.h>
41
#include "TaskWeldingSymbol.h"
42
#include "ui_TaskWeldingSymbol.h"
43
#include "PreferencesGui.h"
44
#include "SymbolChooser.h"
48
using namespace TechDraw;
49
using namespace TechDrawGui;
52
TaskWeldingSymbol::TaskWeldingSymbol(TechDraw::DrawLeaderLine* leadFeat) :
53
ui(new Ui_TaskWeldingSymbol),
64
//existence of leader is guaranteed by CmdTechDrawWeldSymbol (CommandAnnotate.cpp)
69
connect(ui->pbArrowSymbol, &QPushButton::clicked,
70
this, &TaskWeldingSymbol::onArrowSymbolCreateClicked);
71
connect(ui->pbOtherSymbol, &QPushButton::clicked,
72
this, &TaskWeldingSymbol::onOtherSymbolCreateClicked);
73
connect(ui->pbOtherErase, &QPushButton::clicked,
74
this, &TaskWeldingSymbol::onOtherEraseCreateClicked);
75
connect(ui->pbFlipSides, &QPushButton::clicked,
76
this, &TaskWeldingSymbol::onFlipSidesCreateClicked);
77
connect(ui->fcSymbolDir, &FileChooser::fileNameSelected,
78
this, &TaskWeldingSymbol::onDirectorySelected);
82
TaskWeldingSymbol::TaskWeldingSymbol(TechDraw::DrawWeldSymbol* weld) :
83
ui(new Ui_TaskWeldingSymbol),
93
//existence of weld is guaranteed by CmdTechDrawWeldSymbol (CommandAnnotate.cpp)
94
// or ViewProviderWeld.setEdit
96
App::DocumentObject* obj = m_weldFeat->Leader.getValue();
98
!obj->isDerivedFrom(TechDraw::DrawLeaderLine::getClassTypeId()) ) {
99
Base::Console().Error("TaskWeldingSymbol - no leader for welding symbol. Can not proceed.\n");
103
m_leadFeat = static_cast<TechDraw::DrawLeaderLine*>(obj);
109
connect(ui->pbArrowSymbol, &QPushButton::clicked,
110
this, &TaskWeldingSymbol::onArrowSymbolClicked);
111
connect(ui->pbOtherSymbol, &QPushButton::clicked,
112
this, &TaskWeldingSymbol::onOtherSymbolClicked);
113
connect(ui->pbOtherErase, &QPushButton::clicked,
114
this, &TaskWeldingSymbol::onOtherEraseClicked);
115
connect(ui->pbFlipSides, &QPushButton::clicked,
116
this, &TaskWeldingSymbol::onFlipSidesClicked);
118
connect(ui->fcSymbolDir, &FileChooser::fileNameSelected,
119
this, &TaskWeldingSymbol::onDirectorySelected);
121
connect(ui->leArrowTextL, &QLineEdit::textEdited,
122
this, &TaskWeldingSymbol::onArrowTextChanged);
123
connect(ui->leArrowTextR, &QLineEdit::textEdited,
124
this, &TaskWeldingSymbol::onArrowTextChanged);
125
connect(ui->leArrowTextC, &QLineEdit::textEdited,
126
this, &TaskWeldingSymbol::onArrowTextChanged);
128
connect(ui->leOtherTextL, &QLineEdit::textEdited,
129
this, &TaskWeldingSymbol::onOtherTextChanged);
130
connect(ui->leOtherTextR, &QLineEdit::textEdited,
131
this, &TaskWeldingSymbol::onOtherTextChanged);
132
connect(ui->leOtherTextC, &QLineEdit::textEdited,
133
this, &TaskWeldingSymbol::onOtherTextChanged);
135
connect(ui->leTailText, &QLineEdit::textEdited,
136
this, &TaskWeldingSymbol::onWeldingChanged);
137
connect(ui->cbFieldWeld, &QCheckBox::toggled,
138
this, &TaskWeldingSymbol::onWeldingChanged);
139
connect(ui->cbAllAround, &QCheckBox::toggled,
140
this, &TaskWeldingSymbol::onWeldingChanged);
141
connect(ui->cbAltWeld, &QCheckBox::toggled,
142
this, &TaskWeldingSymbol::onWeldingChanged);
145
TaskWeldingSymbol::~TaskWeldingSymbol()
149
void TaskWeldingSymbol::updateTask()
151
// blockUpdate = true;
153
// blockUpdate = false;
156
void TaskWeldingSymbol::changeEvent(QEvent *event)
158
if (event->type() == QEvent::LanguageChange) {
159
ui->retranslateUi(this);
163
void TaskWeldingSymbol::setUiPrimary()
165
// Base::Console().Message("TWS::setUiPrimary()\n");
166
setWindowTitle(QObject::tr("Create Welding Symbol"));
167
m_currDir = PreferencesGui::weldingDirectory();
168
ui->fcSymbolDir->setFileName(m_currDir);
170
ui->pbArrowSymbol->setFocus();
172
m_arrowPath = QString();
173
m_arrowSymbol = QString();
175
m_otherPath = QString();
176
m_otherSymbol = QString();
178
// we must mark the other side dirty to assure it gets created
182
void TaskWeldingSymbol::setUiEdit()
184
// Base::Console().Message("TWS::setUiEdit()\n");
185
setWindowTitle(QObject::tr("Edit Welding Symbol"));
187
m_currDir = PreferencesGui::weldingDirectory();
188
ui->fcSymbolDir->setFileName(m_currDir);
190
ui->cbAllAround->setChecked(m_weldFeat->AllAround.getValue());
191
ui->cbFieldWeld->setChecked(m_weldFeat->FieldWeld.getValue());
192
ui->cbAltWeld->setChecked(m_weldFeat->AlternatingWeld.getValue());
193
ui->leTailText->setText(QString::fromUtf8(m_weldFeat->TailText.getValue()));
197
QString qTemp = QString::fromUtf8(m_arrowFeat->LeftText.getValue());
198
ui->leArrowTextL->setText(qTemp);
199
qTemp = QString::fromUtf8(m_arrowFeat->RightText.getValue());
200
ui->leArrowTextR->setText(qTemp);
201
qTemp = QString::fromUtf8(m_arrowFeat->CenterText.getValue());
202
ui->leArrowTextC->setText(qTemp);
204
std::string inFile = m_arrowFeat->SymbolFile.getValue();
205
auto fi = Base::FileInfo(inFile);
206
if (fi.isReadable()) {
207
qTemp = QString::fromUtf8(m_arrowFeat->SymbolFile.getValue());
208
QIcon targetIcon(qTemp);
209
QSize iconSize(32, 32);
210
ui->pbArrowSymbol->setIcon(targetIcon);
211
ui->pbArrowSymbol->setIconSize(iconSize);
212
ui->pbArrowSymbol->setText(QString());
214
ui->pbArrowSymbol->setText(tr("Symbol"));
219
QString qTemp = QString::fromUtf8(m_otherFeat->LeftText.getValue());
220
ui->leOtherTextL->setText(qTemp);
221
qTemp = QString::fromUtf8(m_otherFeat->RightText.getValue());
222
ui->leOtherTextR->setText(qTemp);
223
qTemp = QString::fromUtf8(m_otherFeat->CenterText.getValue());
224
ui->leOtherTextC->setText(qTemp);
226
std::string inFile = m_otherFeat->SymbolFile.getValue();
227
auto fi = Base::FileInfo(inFile);
228
if (fi.isReadable()) {
229
qTemp = QString::fromUtf8(m_otherFeat->SymbolFile.getValue());
230
QIcon targetIcon(qTemp);
231
QSize iconSize(32, 32);
232
ui->pbOtherSymbol->setIcon(targetIcon);
233
ui->pbOtherSymbol->setIconSize(iconSize);
234
ui->pbOtherSymbol->setText(QString());
236
ui->pbOtherSymbol->setText(tr("Symbol"));
240
ui->pbArrowSymbol->setFocus();
243
void TaskWeldingSymbol::symbolDialog(const char* source)
245
QString _source = tr(source);
246
SymbolChooser* dlg = new SymbolChooser(this, m_currDir, _source);
247
connect(dlg, &SymbolChooser::symbolSelected,
248
this, &TaskWeldingSymbol::onSymbolSelected);
249
dlg->setAttribute(Qt::WA_DeleteOnClose);
253
void TaskWeldingSymbol::onArrowSymbolCreateClicked()
255
symbolDialog("arrow");
258
void TaskWeldingSymbol::onArrowSymbolClicked()
260
symbolDialog("arrow");
262
m_weldFeat->requestPaint();
265
void TaskWeldingSymbol::onOtherSymbolCreateClicked()
267
symbolDialog("other");
270
void TaskWeldingSymbol::onOtherSymbolClicked()
272
symbolDialog("other");
274
m_weldFeat->requestPaint();
277
void TaskWeldingSymbol::onOtherEraseCreateClicked()
279
ui->leOtherTextL->setText(QString());
280
ui->leOtherTextC->setText(QString());
281
ui->leOtherTextR->setText(QString());
282
ui->pbOtherSymbol->setIcon(QIcon());
283
ui->pbOtherSymbol->setText(tr("Symbol"));
285
m_otherPath = QString();
288
void TaskWeldingSymbol::onOtherEraseClicked()
291
ui->leOtherTextL->setText(QString());
292
ui->leOtherTextC->setText(QString());
293
ui->leOtherTextR->setText(QString());
294
ui->pbOtherSymbol->setIcon(QIcon());
295
ui->pbOtherSymbol->setText(tr("Symbol"));
297
m_otherPath = QString();
299
m_weldFeat->requestPaint();
302
void TaskWeldingSymbol::onFlipSidesCreateClicked()
304
QString tempText = ui->leOtherTextL->text();
305
ui->leOtherTextL->setText(ui->leArrowTextL->text());
306
ui->leArrowTextL->setText(tempText);
307
tempText = ui->leOtherTextC->text();
308
ui->leOtherTextC->setText(ui->leArrowTextC->text());
309
ui->leArrowTextC->setText(tempText);
310
tempText = ui->leOtherTextR->text();
311
ui->leOtherTextR->setText(ui->leArrowTextR->text());
312
ui->leArrowTextR->setText(tempText);
314
QString tempPathArrow = m_otherPath;
315
m_otherPath = m_arrowPath;
316
m_arrowPath = tempPathArrow;
317
tempText = ui->pbOtherSymbol->text();
318
ui->pbOtherSymbol->setText(ui->pbArrowSymbol->text());
319
ui->pbArrowSymbol->setText(tempText);
320
QIcon tempIcon = ui->pbOtherSymbol->icon();
321
ui->pbOtherSymbol->setIcon(ui->pbArrowSymbol->icon());
322
ui->pbArrowSymbol->setIcon(tempIcon);
325
void TaskWeldingSymbol::onFlipSidesClicked()
327
QString tempText = ui->leOtherTextL->text();
328
ui->leOtherTextL->setText(ui->leArrowTextL->text());
329
ui->leArrowTextL->setText(tempText);
330
tempText = ui->leOtherTextC->text();
331
ui->leOtherTextC->setText(ui->leArrowTextC->text());
332
ui->leArrowTextC->setText(tempText);
333
tempText = ui->leOtherTextR->text();
334
ui->leOtherTextR->setText(ui->leArrowTextR->text());
335
ui->leArrowTextR->setText(tempText);
337
// one cannot get the path from the icon therefore read out
339
auto tempPathArrow = m_arrowFeat->SymbolFile.getValue();
340
auto tempPathOther = m_otherFeat->SymbolFile.getValue();
341
m_otherPath = QString::fromLatin1(tempPathArrow);
342
m_arrowPath = QString::fromLatin1(tempPathOther);
343
QIcon tempIcon = ui->pbOtherSymbol->icon();
344
ui->pbOtherSymbol->setIcon(ui->pbArrowSymbol->icon());
345
ui->pbArrowSymbol->setIcon(tempIcon);
349
m_weldFeat->requestPaint();
352
void TaskWeldingSymbol::onArrowTextChanged()
355
m_weldFeat->requestPaint();
358
void TaskWeldingSymbol::onOtherTextChanged()
362
m_weldFeat->requestPaint();
365
void TaskWeldingSymbol::onWeldingChanged()
367
updateWeldingSymbol();
368
m_weldFeat->requestPaint();
371
void TaskWeldingSymbol::onDirectorySelected(const QString& newDir)
373
// Base::Console().Message("TWS::onDirectorySelected(%s)\n", qPrintable(newDir));
374
m_currDir = newDir + QString::fromUtf8("/");
377
void TaskWeldingSymbol::onSymbolSelected(QString symbolPath,
380
// Base::Console().Message("TWS::onSymbolSelected(%s) - source: %s\n",
381
// qPrintable(symbolPath), qPrintable(source));
382
QIcon targetIcon(symbolPath);
383
QSize iconSize(32, 32);
384
QString arrow = tr("arrow");
385
QString other = tr("other");
386
if (source == arrow) {
387
ui->pbArrowSymbol->setIcon(targetIcon);
388
ui->pbArrowSymbol->setIconSize(iconSize);
389
ui->pbArrowSymbol->setText(QString());
390
m_arrowPath = symbolPath;
391
} else if (source == other) {
393
ui->pbOtherSymbol->setIcon(targetIcon);
394
ui->pbOtherSymbol->setIconSize(iconSize);
395
ui->pbOtherSymbol->setText(QString());
396
m_otherPath = symbolPath;
400
void TaskWeldingSymbol::collectArrowData()
402
// Base::Console().Message("TWS::collectArrowData()\n");
403
m_arrowOut.toBeSaved = true;
404
m_arrowOut.arrowSide = false;
407
m_arrowOut.leftText = ui->leArrowTextL->text().toStdString();
408
m_arrowOut.centerText = ui->leArrowTextC->text().toStdString();
409
m_arrowOut.rightText = ui->leArrowTextR->text().toStdString();
410
m_arrowOut.symbolPath= m_arrowPath.toStdString();
411
m_arrowOut.tileName = "";
414
void TaskWeldingSymbol::collectOtherData()
416
// Base::Console().Message("TWS::collectOtherData()\n");
417
m_otherOut.toBeSaved = true;
418
m_otherOut.arrowSide = false;
421
m_otherOut.leftText = ui->leOtherTextL->text().toStdString();
422
m_otherOut.centerText = ui->leOtherTextC->text().toStdString();
423
m_otherOut.rightText = ui->leOtherTextR->text().toStdString();
424
m_otherOut.symbolPath = m_otherPath.toStdString();
425
m_otherOut.tileName = "";
428
void TaskWeldingSymbol::getTileFeats()
430
// Base::Console().Message("TWS::getTileFeats()\n");
431
std::vector<TechDraw::DrawTileWeld*> tiles = m_weldFeat->getTiles();
432
m_arrowFeat = nullptr;
433
m_otherFeat = nullptr;
439
TechDraw::DrawTileWeld* tempTile = tiles.at(0);
440
if (tempTile->TileRow.getValue() == 0) {
441
m_arrowFeat = tempTile;
443
m_otherFeat = tempTile;
445
if (tiles.size() > 1) {
446
TechDraw::DrawTileWeld* tempTile = tiles.at(1);
447
if (tempTile->TileRow.getValue() == 0) {
448
m_arrowFeat = tempTile;
450
m_otherFeat = tempTile;
455
//******************************************************************************
456
TechDraw::DrawWeldSymbol* TaskWeldingSymbol::createWeldingSymbol()
458
// Base::Console().Message("TWS::createWeldingSymbol()\n");
459
App::Document *doc = Application::Instance->activeDocument()->getDocument();
460
auto weldSymbol = dynamic_cast<TechDraw::DrawWeldSymbol*>(doc->addObject("TechDraw::DrawWeldSymbol", "WeldSymbol"));
462
throw Base::RuntimeError("TaskWeldingSymbol - new symbol object not found");
465
weldSymbol->AllAround.setValue(ui->cbAllAround->isChecked());
466
weldSymbol->FieldWeld.setValue(ui->cbFieldWeld->isChecked());
467
weldSymbol->AlternatingWeld.setValue(ui->cbAltWeld->isChecked());
468
weldSymbol->TailText.setValue(ui->leTailText->text().toStdString());
469
weldSymbol->Leader.setValue(m_leadFeat);
471
TechDraw::DrawPage *page = m_leadFeat->findParentPage();
473
page->addView(weldSymbol);
479
void TaskWeldingSymbol::updateWeldingSymbol()
481
m_weldFeat->AllAround.setValue(ui->cbAllAround->isChecked());
482
m_weldFeat->FieldWeld.setValue(ui->cbFieldWeld->isChecked());
483
m_weldFeat->AlternatingWeld.setValue(ui->cbAltWeld->isChecked());
484
m_weldFeat->TailText.setValue(ui->leTailText->text().toStdString());
487
void TaskWeldingSymbol::updateTiles()
489
// Base::Console().Message("TWS::updateTiles()\n");
493
Base::Console().Message("TWS::updateTiles - no arrow tile!\n");
496
if (m_arrowOut.toBeSaved) {
497
std::string tileName = m_arrowFeat->getNameInDocument();
498
std::string leftText = Base::Tools::escapeEncodeString(m_arrowOut.leftText);
499
std::string rightText = Base::Tools::escapeEncodeString(m_arrowOut.rightText);
500
std::string centerText = Base::Tools::escapeEncodeString(m_arrowOut.centerText);
501
Command::doCommand(Command::Doc, "App.activeDocument().%s.TileColumn = %d",
502
tileName.c_str(), m_arrowOut.col);
503
Command::doCommand(Command::Doc, "App.activeDocument().%s.LeftText = '%s'",
504
tileName.c_str(), leftText.c_str());
505
Command::doCommand(Command::Doc, "App.activeDocument().%s.RightText = '%s'",
506
tileName.c_str(), rightText.c_str());
507
Command::doCommand(Command::Doc, "App.activeDocument().%s.CenterText = '%s'",
508
tileName.c_str(), centerText.c_str());
509
if (!m_arrowOut.symbolPath.empty()) {
510
// m_arrowFeat->replaceSymbol(m_arrowOut.symbolPath);
511
m_arrowFeat->SymbolFile.setValue(m_arrowOut.symbolPath);
517
// Base::Console().Message("TWS::updateTiles - no other tile!\n");
521
if (m_otherOut.toBeSaved) {
522
std::string tileName = m_otherFeat->getNameInDocument();
523
std::string leftText = Base::Tools::escapeEncodeString(m_otherOut.leftText);
524
std::string rightText = Base::Tools::escapeEncodeString(m_otherOut.rightText);
525
std::string centerText = Base::Tools::escapeEncodeString(m_otherOut.centerText);
526
Command::doCommand(Command::Doc, "App.activeDocument().%s.TileColumn = %d",
527
tileName.c_str(), m_otherOut.col);
528
Command::doCommand(Command::Doc, "App.activeDocument().%s.LeftText = '%s'",
529
tileName.c_str(), leftText.c_str());
530
Command::doCommand(Command::Doc, "App.activeDocument().%s.RightText = '%s'",
531
tileName.c_str(), rightText.c_str());
532
Command::doCommand(Command::Doc, "App.activeDocument().%s.CenterText = '%s'",
533
tileName.c_str(), centerText.c_str());
534
// m_otherFeat->replaceSymbol(m_otherOut.symbolPath);
535
m_otherFeat->SymbolFile.setValue(m_otherOut.symbolPath);
542
void TaskWeldingSymbol::saveButtons(QPushButton* btnOK,
543
QPushButton* btnCancel)
546
m_btnCancel = btnCancel;
549
void TaskWeldingSymbol::enableTaskButtons(bool enable)
551
m_btnOK->setEnabled(enable);
552
m_btnCancel->setEnabled(enable);
555
//******************************************************************************
557
bool TaskWeldingSymbol::accept()
559
// Base::Console().Message("TWS::accept()\n");
561
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Create WeldSymbol"));
562
m_weldFeat = createWeldingSymbol();
564
Gui::Command::updateActive();
565
Gui::Command::commitCommand();
566
m_weldFeat->recomputeFeature();
567
// m_weldFeat->requestPaint(); //not a dv!
569
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Edit WeldSymbol"));
571
updateWeldingSymbol();
575
Base::Console().Error("TWS::accept - failed to update symbol\n");
578
Gui::Command::updateActive();
579
Gui::Command::commitCommand();
580
m_weldFeat->recomputeFeature();
581
// m_weldFeat->requestPaint(); //not a dv!
583
Gui::Command::doCommand(Gui::Command::Gui, "Gui.ActiveDocument.resetEdit()");
588
bool TaskWeldingSymbol::reject()
590
// Base::Console().Message("TWS::reject()\n");
593
Gui::Command::doCommand(Gui::Command::Gui, "App.activeDocument().recompute()");
594
Gui::Command::doCommand(Gui::Command::Gui, "Gui.ActiveDocument.resetEdit()");
598
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
599
TaskDlgWeldingSymbol::TaskDlgWeldingSymbol(TechDraw::DrawLeaderLine* leader)
602
widget = new TaskWeldingSymbol(leader);
603
taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/TechDraw_WeldSymbol"),
604
widget->windowTitle(), true, nullptr);
605
taskbox->groupLayout()->addWidget(widget);
606
Content.push_back(taskbox);
609
TaskDlgWeldingSymbol::TaskDlgWeldingSymbol(TechDraw::DrawWeldSymbol* weld)
612
widget = new TaskWeldingSymbol(weld);
613
taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/TechDraw_WeldSymbol"),
614
widget->windowTitle(), true, nullptr);
615
taskbox->groupLayout()->addWidget(widget);
616
Content.push_back(taskbox);
619
TaskDlgWeldingSymbol::~TaskDlgWeldingSymbol()
623
void TaskDlgWeldingSymbol::update()
625
// widget->updateTask();
628
void TaskDlgWeldingSymbol::modifyStandardButtons(QDialogButtonBox* box)
630
QPushButton* btnOK = box->button(QDialogButtonBox::Ok);
631
QPushButton* btnCancel = box->button(QDialogButtonBox::Cancel);
632
widget->saveButtons(btnOK, btnCancel);
635
//==== calls from the TaskView ===============================================================
636
void TaskDlgWeldingSymbol::open()
640
void TaskDlgWeldingSymbol::clicked(int)
644
bool TaskDlgWeldingSymbol::accept()
650
bool TaskDlgWeldingSymbol::reject()
656
#include <Mod/TechDraw/Gui/moc_TaskWeldingSymbol.cpp>