| 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 |
|
| 24 |
#ifndef TASK_TRANSFORM_DRAGGER_H |
| 25 |
#define TASK_TRANSFORM_DRAGGER_H |
| 26 |
|
| 27 |
#include "TaskView/TaskDialog.h" |
| 28 |
#include "TaskView/TaskView.h" |
| 29 |
#include "ViewProviderDragger.h" |
| 30 |
|
| 31 |
#include <Base/ServiceProvider.h> |
| 32 |
|
| 33 |
#include <App/Application.h> |
| 34 |
#include <App/Services.h> |
| 35 |
|
| 36 |
class SoDragger; |
| 37 |
|
| 38 |
namespace Gui |
| 39 |
{ |
| 40 |
class QuantitySpinBox; |
| 41 |
class SoTransformDragger; |
| 42 |
class ViewProviderDragger; |
| 43 |
class Ui_TaskTransformDialog; |
| 44 |
|
| 45 |
class TaskTransform: public Gui::TaskView::TaskBox, public Gui::SelectionObserver |
| 46 |
{ |
| 47 |
Q_OBJECT |
| 48 |
|
| 49 |
static constexpr double tolerance = 1e-7; |
| 50 |
|
| 51 |
public: |
| 52 |
enum class SelectionMode |
| 53 |
{ |
| 54 |
None, |
| 55 |
SelectTransformOrigin, |
| 56 |
SelectAlignTarget |
| 57 |
}; |
| 58 |
enum class PlacementMode |
| 59 |
{ |
| 60 |
ObjectOrigin, |
| 61 |
Centroid, |
| 62 |
Custom |
| 63 |
}; |
| 64 |
enum class PositionMode |
| 65 |
{ |
| 66 |
Local, |
| 67 |
Global |
| 68 |
}; |
| 69 |
|
| 70 |
struct CoordinateSystem |
| 71 |
{ |
| 72 |
std::array<std::string, 3> labels; |
| 73 |
Base::Placement origin; |
| 74 |
}; |
| 75 |
|
| 76 |
Q_ENUM(SelectionMode) |
| 77 |
Q_ENUM(PlacementMode) |
| 78 |
Q_ENUM(PositionMode) |
| 79 |
|
| 80 |
TaskTransform( |
| 81 |
Gui::ViewProviderDragger* vp, |
| 82 |
Gui::SoTransformDragger* dragger, |
| 83 |
QWidget* parent = nullptr, |
| 84 |
App::SubObjectPlacementProvider* subObjectPlacementProvider |
| 85 |
= Base::provideService<App::SubObjectPlacementProvider>(), |
| 86 |
App::CenterOfMassProvider* centerOfMassProvider |
| 87 |
= Base::provideService<App::CenterOfMassProvider>() |
| 88 |
); |
| 89 |
~TaskTransform() override; |
| 90 |
|
| 91 |
private: |
| 92 |
void onSelectionChanged(const SelectionChanges& msg) override; |
| 93 |
|
| 94 |
private Q_SLOTS: |
| 95 |
void onPlacementModeChange(int index); |
| 96 |
|
| 97 |
void onPickTransformOrigin(); |
| 98 |
void onTransformOriginReset(); |
| 99 |
void onAlignRotationChanged(); |
| 100 |
|
| 101 |
void onAlignToOtherObject(); |
| 102 |
void onFlip(); |
| 103 |
|
| 104 |
void onCoordinateSystemChange(int mode); |
| 105 |
|
| 106 |
void onPositionChange(); |
| 107 |
void onRotationChange(QuantitySpinBox* changed); |
| 108 |
|
| 109 |
private: |
| 110 |
static inline bool firstDrag = true; |
| 111 |
static void dragStartCallback(void* data, SoDragger* d); |
| 112 |
static void dragMotionCallback(void* data, SoDragger* d); |
| 113 |
|
| 114 |
void setSelectionMode(SelectionMode mode); |
| 115 |
SelectionMode getSelectionMode() const; |
| 116 |
|
| 117 |
CoordinateSystem globalCoordinateSystem() const; |
| 118 |
CoordinateSystem localCoordinateSystem() const; |
| 119 |
CoordinateSystem currentCoordinateSystem() const; |
| 120 |
|
| 121 |
Base::Rotation::EulerSequence eulerSequence() const; |
| 122 |
|
| 123 |
void setupGui(); |
| 124 |
|
| 125 |
void loadPreferences(); |
| 126 |
void savePreferences(); |
| 127 |
|
| 128 |
void loadPositionModeItems() const; |
| 129 |
void loadPlacementModeItems() const; |
| 130 |
|
| 131 |
void updatePositionAndRotationUi() const; |
| 132 |
void updateDraggerLabels() const; |
| 133 |
void updateInputLabels() const; |
| 134 |
void updateIncrements() const; |
| 135 |
void updateTransformOrigin(); |
| 136 |
void updateSpinBoxesReadOnlyStatus() const; |
| 137 |
|
| 138 |
void resetReferencePlacement(); |
| 139 |
void resetReferenceRotation(); |
| 140 |
|
| 141 |
ViewProviderDragger::DraggerComponents getRelevantComponents(); |
| 142 |
void moveObjectToDragger( |
| 143 |
ViewProviderDragger::DraggerComponents components = ViewProviderDragger::DraggerComponent::All |
| 144 |
); |
| 145 |
|
| 146 |
bool isDraggerAlignedToCoordinateSystem() const; |
| 147 |
|
| 148 |
ViewProviderDragger* vp; |
| 149 |
|
| 150 |
const App::SubObjectPlacementProvider* subObjectPlacementProvider; |
| 151 |
const App::CenterOfMassProvider* centerOfMassProvider; |
| 152 |
|
| 153 |
CoinPtr<SoTransformDragger> dragger; |
| 154 |
|
| 155 |
Ui_TaskTransformDialog* ui; |
| 156 |
|
| 157 |
SelectionMode selectionMode {SelectionMode::None}; |
| 158 |
PlacementMode placementMode {PlacementMode::ObjectOrigin}; |
| 159 |
PositionMode positionMode {PositionMode::Local}; |
| 160 |
|
| 161 |
std::optional<Base::Placement> customTransformOrigin {}; |
| 162 |
Base::Placement referencePlacement {}; |
| 163 |
Base::Placement globalOrigin {}; |
| 164 |
Base::Rotation referenceRotation {}; |
| 165 |
|
| 166 |
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath( |
| 167 |
"User parameter:BaseApp/History/Dragger" |
| 168 |
); |
| 169 |
}; |
| 170 |
|
| 171 |
class TaskTransformDialog: public Gui::TaskView::TaskDialog |
| 172 |
{ |
| 173 |
Q_OBJECT |
| 174 |
|
| 175 |
public: |
| 176 |
TaskTransformDialog(ViewProviderDragger* vp, SoTransformDragger* dragger); |
| 177 |
~TaskTransformDialog() override = default; |
| 178 |
|
| 179 |
QDialogButtonBox::StandardButtons getStandardButtons() const override |
| 180 |
{ |
| 181 |
return QDialogButtonBox::Ok | QDialogButtonBox::Cancel; |
| 182 |
} |
| 183 |
|
| 184 |
void open() override; |
| 185 |
bool accept() override; |
| 186 |
bool reject() override; |
| 187 |
void onUndo() override; |
| 188 |
void onRedo() override; |
| 189 |
|
| 190 |
private: |
| 191 |
void openCommand(); |
| 192 |
void updateDraggerPlacement(); |
| 193 |
|
| 194 |
private: |
| 195 |
ViewProviderDragger* vp; |
| 196 |
TaskTransform* transform; |
| 197 |
}; |
| 198 |
} // namespace Gui |
| 199 |
|
| 200 |
#endif // TASK_TRANSFORM_DRAGGER_H |