1
/***************************************************************************
2
* Copyright (c) 2015 Thomas Anderson <blobfish[at]gmx.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"
27
#include <QApplication>
31
#include <App/Document.h>
32
#include "Document.h" // must be before TaskCSysDragger.h
33
#include "TaskCSysDragger.h"
34
#include "Application.h"
35
#include "BitmapFactory.h"
37
#include "QuantitySpinBox.h"
38
#include "SoFCCSysDragger.h"
39
#include "ViewProviderDragger.h"
40
#include "TaskView/TaskView.h"
46
static double degreesToRadians(const double °reesIn)
48
return degreesIn * (M_PI / 180.0);
52
TaskCSysDragger::TaskCSysDragger(Gui::ViewProviderDocumentObject* vpObjectIn, Gui::SoFCCSysDragger* draggerIn) :
57
vpObject = vpObjectIn->getObject();
63
TaskCSysDragger::~TaskCSysDragger()
66
Gui::Application::Instance->commandManager().getCommandByName("Std_OrthographicCamera")->setEnabled(true);
67
Gui::Application::Instance->commandManager().getCommandByName("Std_PerspectiveCamera")->setEnabled(true);
70
void TaskCSysDragger::dragStartCallback(void *, SoDragger *)
72
// This is called when a manipulator is about to manipulating
75
Gui::Application::Instance->activeDocument()->openCommand(QT_TRANSLATE_NOOP("Command", "Transform"));
80
void TaskCSysDragger::setupGui()
82
auto incrementsBox = new Gui::TaskView::TaskBox(
83
Gui::BitmapFactory().pixmap("button_valid"),
84
tr("Increments"), true, nullptr);
86
auto gridLayout = new QGridLayout();
87
gridLayout->setColumnStretch(1, 1);
89
auto tLabel = new QLabel(tr("Translation Increment:"), incrementsBox);
90
gridLayout->addWidget(tLabel, 0, 0, Qt::AlignRight);
92
QFontMetrics metrics(QApplication::font());
93
int spinBoxWidth = metrics.averageCharWidth() * 20;
94
tSpinBox = new QuantitySpinBox(incrementsBox);
95
tSpinBox->setMinimum(0.0);
96
tSpinBox->setMaximum(std::numeric_limits<double>::max());
97
tSpinBox->setUnit(Base::Unit::Length);
98
tSpinBox->setMinimumWidth(spinBoxWidth);
99
gridLayout->addWidget(tSpinBox, 0, 1, Qt::AlignLeft);
101
auto rLabel = new QLabel(tr("Rotation Increment:"), incrementsBox);
102
gridLayout->addWidget(rLabel, 1, 0, Qt::AlignRight);
104
rSpinBox = new QuantitySpinBox(incrementsBox);
105
rSpinBox->setMinimum(0.0);
106
rSpinBox->setMaximum(180.0);
107
rSpinBox->setUnit(Base::Unit::Angle);
108
rSpinBox->setMinimumWidth(spinBoxWidth);
109
gridLayout->addWidget(rSpinBox, 1, 1, Qt::AlignLeft);
111
incrementsBox->groupLayout()->addLayout(gridLayout);
112
Content.push_back(incrementsBox);
114
connect(tSpinBox, qOverload<double>(&QuantitySpinBox::valueChanged), this, &TaskCSysDragger::onTIncrementSlot);
115
connect(rSpinBox, qOverload<double>(&QuantitySpinBox::valueChanged), this, &TaskCSysDragger::onRIncrementSlot);
118
void TaskCSysDragger::onTIncrementSlot(double freshValue)
120
dragger->translationIncrement.setValue(freshValue);
123
void TaskCSysDragger::onRIncrementSlot(double freshValue)
125
dragger->rotationIncrement.setValue(degreesToRadians(freshValue));
128
void TaskCSysDragger::open()
130
dragger->addStartCallback(dragStartCallback, this);
131
//we can't have user switching camera types while dragger is shown.
132
Gui::Application::Instance->commandManager().getCommandByName("Std_OrthographicCamera")->setEnabled(false);
133
Gui::Application::Instance->commandManager().getCommandByName("Std_PerspectiveCamera")->setEnabled(false);
134
// dragger->translationIncrement.setValue(lastTranslationIncrement);
135
// dragger->rotationIncrement.setValue(lastRotationIncrement);
136
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/History/Dragger");
137
double lastTranslationIncrement = hGrp->GetFloat("LastTranslationIncrement", 1.0);
138
double lastRotationIncrement = hGrp->GetFloat("LastRotationIncrement", 15.0);
139
tSpinBox->setValue(lastTranslationIncrement);
140
rSpinBox->setValue(lastRotationIncrement);
142
Gui::TaskView::TaskDialog::open();
145
bool TaskCSysDragger::accept()
147
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/History/Dragger");
148
hGrp->SetFloat("LastTranslationIncrement", tSpinBox->rawValue());
149
hGrp->SetFloat("LastRotationIncrement", rSpinBox->rawValue());
151
App::DocumentObject* dObject = vpObject.getObject();
153
Gui::Document* document = Gui::Application::Instance->getDocument(dObject->getDocument());
156
document->commitCommand();
157
document->resetEdit();
158
document->getDocument()->recompute();
160
return Gui::TaskView::TaskDialog::accept();
163
bool TaskCSysDragger::reject()
165
App::DocumentObject* dObject = vpObject.getObject();
167
Gui::Document* document = Gui::Application::Instance->getDocument(dObject->getDocument());
170
document->abortCommand();
171
document->resetEdit();
172
document->getDocument()->recompute();
174
return Gui::TaskView::TaskDialog::reject();
177
#include "moc_TaskCSysDragger.cpp"