FreeCAD

Форк
0
/
TaskGeomHatch.cpp 
284 строки · 10.1 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2017 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
#endif // #ifndef _PreComp_
27

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>
36

37
#include "TaskGeomHatch.h"
38
#include "ui_TaskGeomHatch.h"
39
#include "ViewProviderGeomHatch.h"
40

41

42
using namespace Gui;
43
using namespace TechDraw;
44
using namespace TechDrawGui;
45

46
TaskGeomHatch::TaskGeomHatch(TechDraw::DrawGeomHatch* inHatch, TechDrawGui::ViewProviderGeomHatch* inVp, bool mode) :
47
    ui(new Ui_TaskGeomHatch),
48
    m_hatch(inHatch),
49
    m_Vp(inVp),
50
    m_createMode(mode)
51
{
52
    ui->setupUi(this);
53
    connect(ui->fcFile, &FileChooser::fileNameSelected, this, &TaskGeomHatch::onFileChanged);
54

55
    m_source = m_hatch->Source.getValue();
56
    getParameters();
57
    initUi();
58
}
59

60
void TaskGeomHatch::initUi()
61
{
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);
65

66
    ui->cbName->addItems(qsNames);
67
    int nameIndex = ui->cbName->findText(QString::fromUtf8(m_name.data(), m_name.size()));
68
    if (nameIndex > -1) {
69
        ui->cbName->setCurrentIndex(nameIndex);
70
    } else {
71
        Base::Console().Warning("Warning - Pattern name *%s* not found in current PAT File\n", m_name.c_str());
72
    }
73
    connect(ui->cbName, qOverload<int>(&QComboBox::currentIndexChanged), this, &TaskGeomHatch::onNameChanged);
74

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);
83

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);
90
}
91

92
void TaskGeomHatch::onFileChanged()
93
{
94
    m_file = ui->fcFile->fileName().toUtf8().constData();
95
    std::vector<std::string> names = PATLineSpec::getPatternList(m_file);
96
    QStringList qsNames = listToQ(names);
97
    ui->cbName->clear();
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!
102
}
103

104
void TaskGeomHatch::onNameChanged()
105
{
106
    QString cText = ui->cbName->currentText();
107
    m_name = cText.toUtf8().constData();
108
    m_hatch->NamePattern.setValue(m_name);
109
}
110

111
void TaskGeomHatch::onScaleChanged()
112
{
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);
116
    dv->requestPaint();
117
}
118

119
void TaskGeomHatch::onRotationChanged()
120
{
121
    m_rotation = ui->dsbRotation->value();
122
    m_hatch->PatternRotation.setValue(m_rotation);
123
    TechDraw::DrawView* dv = static_cast<TechDraw::DrawView*>(m_source);
124
    dv->requestPaint();
125
}
126

127
void TaskGeomHatch::onOffsetChanged()
128
{
129
    Base::Vector3d offset(ui->dsbOffsetX->value(), ui->dsbOffsetY->value(), 0.0);
130
    m_offset = offset;
131
    m_hatch->PatternOffset.setValue(m_offset);
132
    TechDraw::DrawView* dv = static_cast<TechDraw::DrawView*>(m_source);
133
    dv->requestPaint();
134
}
135

136
void TaskGeomHatch::onLineWeightChanged()
137
{
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);
141
    dv->requestPaint();
142
}
143

144
void TaskGeomHatch::onColorChanged()
145
{
146
    m_color.setValue<QColor>(ui->ccColor->color());
147
    m_Vp->ColorPattern.setValue(m_color);
148
}
149

150
bool TaskGeomHatch::accept()
151
{
152
//    Base::Console().Message("TGH::accept()\n");
153
    updateValues();
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);
157
    dv->requestPaint();
158
    return true;
159
}
160

161
bool TaskGeomHatch::reject()
162
{
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()");
167
        m_source->touch();
168
        m_source->getDocument()->recompute();
169
    } else {
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);
177
    }
178
    return false;
179
}
180

181
void TaskGeomHatch::getParameters()
182
{
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();
198
    }
199
}
200

201
//move values from screen to DocObjs
202
void TaskGeomHatch::updateValues()
203
{
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());
217
}
218

219
QStringList TaskGeomHatch::listToQ(std::vector<std::string> inList)
220
{
221
    QStringList result;
222
    for (auto& s: inList) {
223
        QString qs = QString::fromUtf8(s.data(), s.size());
224
        result.append(qs);
225
    }
226
    return result;
227
}
228

229
void TaskGeomHatch::changeEvent(QEvent *event)
230
{
231
    if (event->type() == QEvent::LanguageChange) {
232
        ui->retranslateUi(this);
233
    }
234
}
235

236
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
237
TaskDlgGeomHatch::TaskDlgGeomHatch(TechDraw::DrawGeomHatch* inHatch, TechDrawGui::ViewProviderGeomHatch* inVp, bool mode) :
238
    TaskDialog(),
239
    viewProvider(nullptr)
240
{
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);
246
}
247

248
TaskDlgGeomHatch::~TaskDlgGeomHatch()
249
{
250
}
251

252
void TaskDlgGeomHatch::setCreateMode(bool mode)
253
{
254
    widget->setCreateMode(mode);
255
}
256

257
void TaskDlgGeomHatch::update()
258
{
259
    //widget->updateTask();
260
}
261

262
//==== calls from the TaskView ===============================================================
263
void TaskDlgGeomHatch::open()
264
{
265
}
266

267
void TaskDlgGeomHatch::clicked(int i)
268
{
269
    Q_UNUSED(i);
270
}
271

272
bool TaskDlgGeomHatch::accept()
273
{
274
    widget->accept();
275
    return true;
276
}
277

278
bool TaskDlgGeomHatch::reject()
279
{
280
    widget->reject();
281
    return true;
282
}
283

284
#include <Mod/TechDraw/Gui/moc_TaskGeomHatch.cpp>
285

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

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

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

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