FreeCAD

Форк
0
/
TaskCSysDragger.cpp 
177 строк · 6.6 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2015 Thomas Anderson <blobfish[at]gmx.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 <cassert>
26
#include <limits>
27
#include <QApplication>
28
#include <QGridLayout>
29
#endif
30

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"
36
#include "Command.h"
37
#include "QuantitySpinBox.h"
38
#include "SoFCCSysDragger.h"
39
#include "ViewProviderDragger.h"
40
#include "TaskView/TaskView.h"
41

42

43
using namespace Gui;
44

45

46
static double degreesToRadians(const double &degreesIn)
47
{
48
  return degreesIn * (M_PI / 180.0);
49
}
50

51

52
TaskCSysDragger::TaskCSysDragger(Gui::ViewProviderDocumentObject* vpObjectIn, Gui::SoFCCSysDragger* draggerIn) :
53
  dragger(draggerIn)
54
{
55
  assert(vpObjectIn);
56
  assert(draggerIn);
57
  vpObject = vpObjectIn->getObject();
58
  dragger->ref();
59

60
  setupGui();
61
}
62

63
TaskCSysDragger::~TaskCSysDragger()
64
{
65
  dragger->unref();
66
  Gui::Application::Instance->commandManager().getCommandByName("Std_OrthographicCamera")->setEnabled(true);
67
  Gui::Application::Instance->commandManager().getCommandByName("Std_PerspectiveCamera")->setEnabled(true);
68
}
69

70
void TaskCSysDragger::dragStartCallback(void *, SoDragger *)
71
{
72
    // This is called when a manipulator is about to manipulating
73
  if(firstDrag)
74
    {
75
       Gui::Application::Instance->activeDocument()->openCommand(QT_TRANSLATE_NOOP("Command", "Transform"));
76
       firstDrag=false;
77
    }
78
}
79

80
void TaskCSysDragger::setupGui()
81
{
82
    auto incrementsBox = new Gui::TaskView::TaskBox(
83
      Gui::BitmapFactory().pixmap("button_valid"),
84
      tr("Increments"), true, nullptr);
85

86
    auto gridLayout = new QGridLayout();
87
  gridLayout->setColumnStretch(1, 1);
88

89
  auto tLabel = new QLabel(tr("Translation Increment:"), incrementsBox);
90
  gridLayout->addWidget(tLabel, 0, 0, Qt::AlignRight);
91

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

101
  auto rLabel = new QLabel(tr("Rotation Increment:"), incrementsBox);
102
  gridLayout->addWidget(rLabel, 1, 0, Qt::AlignRight);
103

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

111
  incrementsBox->groupLayout()->addLayout(gridLayout);
112
  Content.push_back(incrementsBox);
113

114
  connect(tSpinBox, qOverload<double>(&QuantitySpinBox::valueChanged), this, &TaskCSysDragger::onTIncrementSlot);
115
  connect(rSpinBox, qOverload<double>(&QuantitySpinBox::valueChanged), this, &TaskCSysDragger::onRIncrementSlot);
116
}
117

118
void TaskCSysDragger::onTIncrementSlot(double freshValue)
119
{
120
  dragger->translationIncrement.setValue(freshValue);
121
}
122

123
void TaskCSysDragger::onRIncrementSlot(double freshValue)
124
{
125
  dragger->rotationIncrement.setValue(degreesToRadians(freshValue));
126
}
127

128
void TaskCSysDragger::open()
129
{
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);
141

142
  Gui::TaskView::TaskDialog::open();
143
}
144

145
bool TaskCSysDragger::accept()
146
{
147
  ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/History/Dragger");
148
  hGrp->SetFloat("LastTranslationIncrement", tSpinBox->rawValue());
149
  hGrp->SetFloat("LastRotationIncrement", rSpinBox->rawValue());
150

151
  App::DocumentObject* dObject = vpObject.getObject();
152
  if (dObject) {
153
    Gui::Document* document = Gui::Application::Instance->getDocument(dObject->getDocument());
154
    assert(document);
155
    firstDrag = true;
156
    document->commitCommand();
157
    document->resetEdit();
158
    document->getDocument()->recompute();
159
  }
160
  return Gui::TaskView::TaskDialog::accept();
161
}
162

163
bool TaskCSysDragger::reject()
164
{
165
  App::DocumentObject* dObject = vpObject.getObject();
166
  if (dObject) {
167
    Gui::Document* document = Gui::Application::Instance->getDocument(dObject->getDocument());
168
    assert(document);
169
    firstDrag = true;
170
    document->abortCommand();
171
    document->resetEdit();
172
    document->getDocument()->recompute();
173
  }
174
  return Gui::TaskView::TaskDialog::reject();
175
}
176

177
#include "moc_TaskCSysDragger.cpp"
178

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

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

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

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