1
/***************************************************************************
2
* Copyright (c) 2012 Werner Mayer <wmayer[at]users.sourceforge.net> *
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 <QMessageBox>
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>
39
#include "TaskOffset.h"
40
#include "ui_TaskOffset.h"
43
using namespace PartGui;
45
class OffsetWidget::Private
49
Part::Offset* offset{nullptr};
52
/* TRANSLATOR PartGui::OffsetWidget */
54
OffsetWidget::OffsetWidget(Part::Offset* offset, QWidget* parent)
58
Gui::Command::runCommand(Gui::Command::App, "from FreeCAD import Base");
59
Gui::Command::runCommand(Gui::Command::App, "import Part");
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();
70
bool is_2d = d->offset->isDerivedFrom(Part::Offset2D::getClassTypeId());
71
d->ui.selfIntersection->setVisible(!is_2d);
73
d->ui.modeType->removeItem(2);//remove Recto-Verso mode, not supported by 2d offset
75
//block signals to fill values read out from feature...
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);
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);
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);
105
d->ui.spinOffset->bind(d->offset->Value);
108
OffsetWidget::~OffsetWidget()
113
void OffsetWidget::setupConnections()
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);
133
Part::Offset* OffsetWidget::getObject() const
138
void OffsetWidget::onSpinOffsetValueChanged(double val)
140
d->offset->Value.setValue(val);
141
if (d->ui.updateView->isChecked())
142
d->offset->getDocument()->recomputeFeature(d->offset);
145
void OffsetWidget::onModeTypeActivated(int val)
147
d->offset->Mode.setValue(val);
148
if (d->ui.updateView->isChecked())
149
d->offset->getDocument()->recomputeFeature(d->offset);
152
void OffsetWidget::onJoinTypeActivated(int val)
154
d->offset->Join.setValue((long)val);
155
if (d->ui.updateView->isChecked())
156
d->offset->getDocument()->recomputeFeature(d->offset);
159
void OffsetWidget::onIntersectionToggled(bool on)
161
d->offset->Intersection.setValue(on);
162
if (d->ui.updateView->isChecked())
163
d->offset->getDocument()->recomputeFeature(d->offset);
166
void OffsetWidget::onSelfIntersectionToggled(bool on)
168
d->offset->SelfIntersection.setValue(on);
169
if (d->ui.updateView->isChecked())
170
d->offset->getDocument()->recomputeFeature(d->offset);
173
void OffsetWidget::onFillOffsetToggled(bool on)
175
d->offset->Fill.setValue(on);
176
if (d->ui.updateView->isChecked())
177
d->offset->getDocument()->recomputeFeature(d->offset);
180
void OffsetWidget::onUpdateViewToggled(bool on)
183
d->offset->getDocument()->recomputeFeature(d->offset);
187
bool OffsetWidget::accept()
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");
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();
205
catch (const Base::Exception& e) {
206
QMessageBox::warning(this, tr("Input error"), QCoreApplication::translate("Exception", e.what()));
213
bool OffsetWidget::reject()
215
// get the support and Sketch
216
App::DocumentObject* source = d->offset->Source.getValue();
218
Gui::Application::Instance->getViewProvider(source)->show();
221
// roll back the done things
222
Gui::Command::abortCommand();
223
Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()");
224
Gui::Command::updateActive();
229
void OffsetWidget::changeEvent(QEvent *e)
231
QWidget::changeEvent(e);
232
if (e->type() == QEvent::LanguageChange) {
233
d->ui.retranslateUi(this);
238
/* TRANSLATOR PartGui::TaskOffset */
240
TaskOffset::TaskOffset(Part::Offset* offset)
242
widget = new OffsetWidget(offset);
243
addTaskBox(Gui::BitmapFactory().pixmap("Part_Offset"), widget);
246
TaskOffset::~TaskOffset() = default;
248
Part::Offset* TaskOffset::getObject() const
250
return widget->getObject();
253
void TaskOffset::open()
257
void TaskOffset::clicked(int)
261
bool TaskOffset::accept()
263
return widget->accept();
266
bool TaskOffset::reject()
268
return widget->reject();
271
#include "moc_TaskOffset.cpp"