1
/***************************************************************************
2
* Copyright (c) 2017 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
#endif // #ifndef _PreComp_
28
#include <App/Document.h>
29
#include <Base/Console.h>
30
#include <Base/Vector3D.h>
31
#include <Gui/BitmapFactory.h>
32
#include <Gui/Command.h>
33
#include <Gui/ViewProvider.h>
34
#include <Mod/TechDraw/App/DrawGeomHatch.h>
35
#include <Mod/TechDraw/App/DrawView.h>
37
#include "TaskGeomHatch.h"
38
#include "ui_TaskGeomHatch.h"
39
#include "ViewProviderGeomHatch.h"
43
using namespace TechDraw;
44
using namespace TechDrawGui;
46
TaskGeomHatch::TaskGeomHatch(TechDraw::DrawGeomHatch* inHatch, TechDrawGui::ViewProviderGeomHatch* inVp, bool mode) :
47
ui(new Ui_TaskGeomHatch),
53
connect(ui->fcFile, &FileChooser::fileNameSelected, this, &TaskGeomHatch::onFileChanged);
55
m_source = m_hatch->Source.getValue();
60
void TaskGeomHatch::initUi()
62
ui->fcFile->setFileName(QString::fromUtf8(m_file.data(), m_file.size()));
63
std::vector<std::string> names = PATLineSpec::getPatternList(m_file);
64
QStringList qsNames = listToQ(names);
66
ui->cbName->addItems(qsNames);
67
int nameIndex = ui->cbName->findText(QString::fromUtf8(m_name.data(), m_name.size()));
69
ui->cbName->setCurrentIndex(nameIndex);
71
Base::Console().Warning("Warning - Pattern name *%s* not found in current PAT File\n", m_name.c_str());
73
connect(ui->cbName, qOverload<int>(&QComboBox::currentIndexChanged), this, &TaskGeomHatch::onNameChanged);
75
ui->sbScale->setValue(m_scale);
76
ui->sbScale->setSingleStep(0.1);
77
connect(ui->sbScale, qOverload<double>(&QuantitySpinBox::valueChanged), this, &TaskGeomHatch::onScaleChanged);
78
ui->sbWeight->setValue(m_weight);
79
ui->sbWeight->setSingleStep(0.1);
80
connect(ui->sbWeight, qOverload<double>(&QuantitySpinBox::valueChanged), this, &TaskGeomHatch::onLineWeightChanged);
81
ui->ccColor->setColor(m_color.asValue<QColor>());
82
connect(ui->ccColor, &ColorButton::changed, this, &TaskGeomHatch::onColorChanged);
84
ui->dsbRotation->setValue(m_rotation);
85
connect(ui->dsbRotation, qOverload<double>(&QDoubleSpinBox::valueChanged), this, &TaskGeomHatch::onRotationChanged);
86
ui->dsbOffsetX->setValue(m_offset.x);
87
connect(ui->dsbOffsetX, qOverload<double>(&QDoubleSpinBox::valueChanged), this, &TaskGeomHatch::onOffsetChanged);
88
ui->dsbOffsetY->setValue(m_offset.y);
89
connect(ui->dsbOffsetY, qOverload<double>(&QDoubleSpinBox::valueChanged), this, &TaskGeomHatch::onOffsetChanged);
92
void TaskGeomHatch::onFileChanged()
94
m_file = ui->fcFile->fileName().toUtf8().constData();
95
std::vector<std::string> names = PATLineSpec::getPatternList(m_file);
96
QStringList qsNames = listToQ(names);
98
ui->cbName->addItems(qsNames);
99
m_hatch->FilePattern.setValue(m_file);
100
onNameChanged(); //pattern name from old file is not
101
//necessarily present in new file!
104
void TaskGeomHatch::onNameChanged()
106
QString cText = ui->cbName->currentText();
107
m_name = cText.toUtf8().constData();
108
m_hatch->NamePattern.setValue(m_name);
111
void TaskGeomHatch::onScaleChanged()
113
m_scale = ui->sbScale->value().getValue();
114
m_hatch->ScalePattern.setValue(ui->sbScale->value().getValue());
115
TechDraw::DrawView* dv = static_cast<TechDraw::DrawView*>(m_source);
119
void TaskGeomHatch::onRotationChanged()
121
m_rotation = ui->dsbRotation->value();
122
m_hatch->PatternRotation.setValue(m_rotation);
123
TechDraw::DrawView* dv = static_cast<TechDraw::DrawView*>(m_source);
127
void TaskGeomHatch::onOffsetChanged()
129
Base::Vector3d offset(ui->dsbOffsetX->value(), ui->dsbOffsetY->value(), 0.0);
131
m_hatch->PatternOffset.setValue(m_offset);
132
TechDraw::DrawView* dv = static_cast<TechDraw::DrawView*>(m_source);
136
void TaskGeomHatch::onLineWeightChanged()
138
m_weight =ui->sbWeight->value().getValue();
139
m_Vp->WeightPattern.setValue(ui->sbWeight->value().getValue());
140
TechDraw::DrawView* dv = static_cast<TechDraw::DrawView*>(m_source);
144
void TaskGeomHatch::onColorChanged()
146
m_color.setValue<QColor>(ui->ccColor->color());
147
m_Vp->ColorPattern.setValue(m_color);
150
bool TaskGeomHatch::accept()
152
// Base::Console().Message("TGH::accept()\n");
154
Gui::Command::doCommand(Gui::Command::Gui, "Gui.ActiveDocument.resetEdit()");
155
m_hatch->recomputeFeature(); //create the hatch lines
156
TechDraw::DrawView* dv = static_cast<TechDraw::DrawView*>(m_source);
161
bool TaskGeomHatch::reject()
163
if (getCreateMode()) {
164
std::string HatchName = m_hatch->getNameInDocument();
165
Gui::Command::doCommand(Gui::Command::Gui, "App.activeDocument().removeObject('%s')", HatchName.c_str());
166
Gui::Command::doCommand(Gui::Command::Gui, "Gui.ActiveDocument.resetEdit()");
168
m_source->getDocument()->recompute();
170
m_hatch->FilePattern.setValue(m_origFile);
171
m_hatch->NamePattern.setValue(m_origName);
172
m_hatch->ScalePattern.setValue(m_origScale);
173
m_hatch->PatternRotation.setValue(m_origRotation);
174
m_hatch->PatternOffset.setValue(m_origOffset);
175
m_Vp->ColorPattern.setValue(m_origColor);
176
m_Vp->WeightPattern.setValue(m_origWeight);
181
void TaskGeomHatch::getParameters()
183
m_file = m_hatch->FilePattern.getValue();
184
m_name = m_hatch->NamePattern.getValue();
185
m_scale = m_hatch->ScalePattern.getValue();
186
m_rotation = m_hatch->PatternRotation.getValue();
187
m_offset = m_hatch->PatternOffset.getValue();
188
m_color = m_Vp->ColorPattern.getValue();
189
m_weight = m_Vp->WeightPattern.getValue();
190
if (!getCreateMode()) {
191
m_origFile = m_hatch->FilePattern.getValue();
192
m_origName = m_hatch->NamePattern.getValue();
193
m_origScale = m_hatch->ScalePattern.getValue();
194
m_origColor = m_Vp->ColorPattern.getValue();
195
m_origWeight = m_Vp->WeightPattern.getValue();
196
m_origRotation = m_hatch->PatternRotation.getValue();
197
m_origOffset = m_hatch->PatternOffset.getValue();
201
//move values from screen to DocObjs
202
void TaskGeomHatch::updateValues()
204
// Base::Console().Message("TGH::updateValues()\n");
205
m_file = (ui->fcFile->fileName()).toUtf8().constData();
206
m_hatch->FilePattern.setValue(m_file);
207
QString cText = ui->cbName->currentText();
208
m_name = cText.toUtf8().constData();
209
m_hatch->NamePattern.setValue(m_name);
210
m_scale = ui->sbScale->value().getValue();
211
m_hatch->ScalePattern.setValue(m_scale);
212
m_color.setValue<QColor>(ui->ccColor->color());
213
m_Vp->ColorPattern.setValue(m_color);
214
m_weight = ui->sbWeight->value().getValue();
215
m_Vp->WeightPattern.setValue(m_weight);
216
m_hatch->PatternRotation.setValue(ui->dsbRotation->value());
219
QStringList TaskGeomHatch::listToQ(std::vector<std::string> inList)
222
for (auto& s: inList) {
223
QString qs = QString::fromUtf8(s.data(), s.size());
229
void TaskGeomHatch::changeEvent(QEvent *event)
231
if (event->type() == QEvent::LanguageChange) {
232
ui->retranslateUi(this);
236
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
237
TaskDlgGeomHatch::TaskDlgGeomHatch(TechDraw::DrawGeomHatch* inHatch, TechDrawGui::ViewProviderGeomHatch* inVp, bool mode) :
239
viewProvider(nullptr)
241
widget = new TaskGeomHatch(inHatch, inVp, mode);
242
taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("TechDraw_TreeView"),
243
widget->windowTitle(), true, nullptr);
244
taskbox->groupLayout()->addWidget(widget);
245
Content.push_back(taskbox);
248
TaskDlgGeomHatch::~TaskDlgGeomHatch()
252
void TaskDlgGeomHatch::setCreateMode(bool mode)
254
widget->setCreateMode(mode);
257
void TaskDlgGeomHatch::update()
259
//widget->updateTask();
262
//==== calls from the TaskView ===============================================================
263
void TaskDlgGeomHatch::open()
267
void TaskDlgGeomHatch::clicked(int i)
272
bool TaskDlgGeomHatch::accept()
278
bool TaskDlgGeomHatch::reject()
284
#include <Mod/TechDraw/Gui/moc_TaskGeomHatch.cpp>