FreeCAD

Форк
0
/
TaskOffset.cpp 
271 строка · 8.7 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2012 Werner Mayer <wmayer[at]users.sourceforge.net>     *
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

25
#ifndef _PreComp_
26
# include <QMessageBox>
27
#endif
28

29
#include <App/Application.h>
30
#include <App/Document.h>
31
#include <App/DocumentObject.h>
32
#include <Gui/Application.h>
33
#include <Gui/BitmapFactory.h>
34
#include <Gui/CommandT.h>
35
#include <Gui/Document.h>
36
#include <Gui/ViewProvider.h>
37
#include <Mod/Part/App/FeatureOffset.h>
38

39
#include "TaskOffset.h"
40
#include "ui_TaskOffset.h"
41

42

43
using namespace PartGui;
44

45
class OffsetWidget::Private
46
{
47
public:
48
    Ui_TaskOffset ui{};
49
    Part::Offset* offset{nullptr};
50
};
51

52
/* TRANSLATOR PartGui::OffsetWidget */
53

54
OffsetWidget::OffsetWidget(Part::Offset* offset, QWidget* parent)
55
  : d(new Private())
56
{
57
    Q_UNUSED(parent);
58
    Gui::Command::runCommand(Gui::Command::App, "from FreeCAD import Base");
59
    Gui::Command::runCommand(Gui::Command::App, "import Part");
60

61
    d->offset = offset;
62
    d->ui.setupUi(this);
63
    setupConnections();
64

65
    d->ui.spinOffset->setUnit(Base::Unit::Length);
66
    d->ui.spinOffset->setRange(-INT_MAX, INT_MAX);
67
    d->ui.spinOffset->setSingleStep(0.1);
68
    d->ui.facesButton->hide();
69

70
    bool is_2d = d->offset->isDerivedFrom(Part::Offset2D::getClassTypeId());
71
    d->ui.selfIntersection->setVisible(!is_2d);
72
    if(is_2d)
73
        d->ui.modeType->removeItem(2);//remove Recto-Verso mode, not supported by 2d offset
74

75
    //block signals to fill values read out from feature...
76
    bool block = true;
77
    d->ui.fillOffset->blockSignals(block);
78
    d->ui.intersection->blockSignals(block);
79
    d->ui.selfIntersection->blockSignals(block);
80
    d->ui.modeType->blockSignals(block);
81
    d->ui.joinType->blockSignals(block);
82
    d->ui.spinOffset->blockSignals(block);
83

84
    //read values from feature
85
    d->ui.spinOffset->setValue(d->offset->Value.getValue());
86
    d->ui.fillOffset->setChecked(offset->Fill.getValue());
87
    d->ui.intersection->setChecked(offset->Intersection.getValue());
88
    d->ui.selfIntersection->setChecked(offset->SelfIntersection.getValue());
89
    long mode = offset->Mode.getValue();
90
    if (mode >= 0 && mode < d->ui.modeType->count())
91
        d->ui.modeType->setCurrentIndex(mode);
92
    long join = offset->Join.getValue();
93
    if (join >= 0 && join < d->ui.joinType->count())
94
        d->ui.joinType->setCurrentIndex(join);
95

96
    //unblock signals
97
    block = false;
98
    d->ui.fillOffset->blockSignals(block);
99
    d->ui.intersection->blockSignals(block);
100
    d->ui.selfIntersection->blockSignals(block);
101
    d->ui.modeType->blockSignals(block);
102
    d->ui.joinType->blockSignals(block);
103
    d->ui.spinOffset->blockSignals(block);
104

105
    d->ui.spinOffset->bind(d->offset->Value);
106
}
107

108
OffsetWidget::~OffsetWidget()
109
{
110
    delete d;
111
}
112

113
void OffsetWidget::setupConnections()
114
{
115
    // clang-format off
116
    connect(d->ui.spinOffset, qOverload<double>(&Gui::QuantitySpinBox::valueChanged),
117
            this, &OffsetWidget::onSpinOffsetValueChanged);
118
    connect(d->ui.modeType, qOverload<int>(&QComboBox::activated),
119
            this, &OffsetWidget::onModeTypeActivated);
120
    connect(d->ui.joinType, qOverload<int>(&QComboBox::activated),
121
            this, &OffsetWidget::onJoinTypeActivated);
122
    connect(d->ui.intersection, &QCheckBox::toggled,
123
            this, &OffsetWidget::onIntersectionToggled);
124
    connect(d->ui.selfIntersection, &QCheckBox::toggled,
125
            this, &OffsetWidget::onSelfIntersectionToggled);
126
    connect(d->ui.fillOffset, &QCheckBox::toggled,
127
            this, &OffsetWidget::onFillOffsetToggled);
128
    connect(d->ui.updateView, &QCheckBox::toggled,
129
            this, &OffsetWidget::onUpdateViewToggled);
130
    // clang-format on
131
}
132

133
Part::Offset* OffsetWidget::getObject() const
134
{
135
    return d->offset;
136
}
137

138
void OffsetWidget::onSpinOffsetValueChanged(double val)
139
{
140
    d->offset->Value.setValue(val);
141
    if (d->ui.updateView->isChecked())
142
        d->offset->getDocument()->recomputeFeature(d->offset);
143
}
144

145
void OffsetWidget::onModeTypeActivated(int val)
146
{
147
    d->offset->Mode.setValue(val);
148
    if (d->ui.updateView->isChecked())
149
        d->offset->getDocument()->recomputeFeature(d->offset);
150
}
151

152
void OffsetWidget::onJoinTypeActivated(int val)
153
{
154
    d->offset->Join.setValue((long)val);
155
    if (d->ui.updateView->isChecked())
156
        d->offset->getDocument()->recomputeFeature(d->offset);
157
}
158

159
void OffsetWidget::onIntersectionToggled(bool on)
160
{
161
    d->offset->Intersection.setValue(on);
162
    if (d->ui.updateView->isChecked())
163
        d->offset->getDocument()->recomputeFeature(d->offset);
164
}
165

166
void OffsetWidget::onSelfIntersectionToggled(bool on)
167
{
168
    d->offset->SelfIntersection.setValue(on);
169
    if (d->ui.updateView->isChecked())
170
        d->offset->getDocument()->recomputeFeature(d->offset);
171
}
172

173
void OffsetWidget::onFillOffsetToggled(bool on)
174
{
175
    d->offset->Fill.setValue(on);
176
    if (d->ui.updateView->isChecked())
177
        d->offset->getDocument()->recomputeFeature(d->offset);
178
}
179

180
void OffsetWidget::onUpdateViewToggled(bool on)
181
{
182
    if (on) {
183
        d->offset->getDocument()->recomputeFeature(d->offset);
184
    }
185
}
186

187
bool OffsetWidget::accept()
188
{
189
    try {
190
        double offsetValue = d->ui.spinOffset->value().getValue();
191
        Gui::cmdAppObjectArgs(d->offset, "Value = %f", offsetValue);
192
        d->ui.spinOffset->apply();
193
        Gui::cmdAppObjectArgs(d->offset, "Mode = %d", d->ui.modeType->currentIndex());
194
        Gui::cmdAppObjectArgs(d->offset, "Join = %d", d->ui.joinType->currentIndex());
195
        Gui::cmdAppObjectArgs(d->offset, "Intersection = %s", d->ui.intersection->isChecked() ? "True" : "False");
196
        Gui::cmdAppObjectArgs(d->offset, "SelfIntersection = %s", d->ui.selfIntersection->isChecked() ? "True" : "False");
197
        Gui::cmdAppObjectArgs(d->offset, "Fill = %s", d->ui.fillOffset->isChecked() ? "True" : "False");
198

199
        Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()");
200
        if (!d->offset->isValid())
201
            throw Base::CADKernelError(d->offset->getStatusString());
202
        Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()");
203
        Gui::Command::commitCommand();
204
    }
205
    catch (const Base::Exception& e) {
206
        QMessageBox::warning(this, tr("Input error"), QCoreApplication::translate("Exception", e.what()));
207
        return false;
208
    }
209

210
    return true;
211
}
212

213
bool OffsetWidget::reject()
214
{
215
    // get the support and Sketch
216
    App::DocumentObject* source = d->offset->Source.getValue();
217
    if (source){
218
        Gui::Application::Instance->getViewProvider(source)->show();
219
    }
220

221
    // roll back the done things
222
    Gui::Command::abortCommand();
223
    Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()");
224
    Gui::Command::updateActive();
225

226
    return true;
227
}
228

229
void OffsetWidget::changeEvent(QEvent *e)
230
{
231
    QWidget::changeEvent(e);
232
    if (e->type() == QEvent::LanguageChange) {
233
        d->ui.retranslateUi(this);
234
    }
235
}
236

237

238
/* TRANSLATOR PartGui::TaskOffset */
239

240
TaskOffset::TaskOffset(Part::Offset* offset)
241
{
242
    widget = new OffsetWidget(offset);
243
    addTaskBox(Gui::BitmapFactory().pixmap("Part_Offset"), widget);
244
}
245

246
TaskOffset::~TaskOffset() = default;
247

248
Part::Offset* TaskOffset::getObject() const
249
{
250
    return widget->getObject();
251
}
252

253
void TaskOffset::open()
254
{
255
}
256

257
void TaskOffset::clicked(int)
258
{
259
}
260

261
bool TaskOffset::accept()
262
{
263
    return widget->accept();
264
}
265

266
bool TaskOffset::reject()
267
{
268
    return widget->reject();
269
}
270

271
#include "moc_TaskOffset.cpp"
272

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

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

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

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