Debian Codegraph @

src/Gui/ViewProviderDragger.h

raw
1 /***************************************************************************
2 * Copyright (c) 2017 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
24 #ifndef GUI_VIEWPROVIDER_DRAGGER_H
25 #define GUI_VIEWPROVIDER_DRAGGER_H
26
27 #include "ViewProviderDocumentObject.h"
28 #include <Base/Placement.h>
29 #include <App/PropertyGeo.h>
30 #include <Base/Bitmask.h>
31
32 class SoDragger;
33 class SoTransform;
34
35 namespace Gui
36 {
37
38 namespace TaskView
39 {
40 class TaskDialog;
41 }
42
43 class SoTransformDragger;
44 class View3DInventorViewer;
45 class GizmoContainer;
46
47 /**
48 * The base class for all view providers modifying the placement
49 * of a geometric feature.
50 * @author Werner Mayer
51 */
52 class GuiExport ViewProviderDragger: public ViewProviderDocumentObject
53 {
54 PROPERTY_HEADER_WITH_OVERRIDE(Gui::ViewProviderDragger);
55
56 public:
57 /// constructor.
58 ViewProviderDragger();
59
60 /// destructor.
61 ~ViewProviderDragger() override;
62
63 /// Origin used when object is transformed. It temporarily changes the origin of object.
64 /// Dragger is normally placed at the transform origin, unless explicitly overridden via
65 /// ViewProviderDragger#setDraggerPlacement() method.
66 App::PropertyPlacement TransformOrigin;
67
68 void attach(App::DocumentObject* pcObject) override;
69
70 /// Convenience method to obtain the transform origin
71 Base::Placement getTransformOrigin() const
72 {
73 return TransformOrigin.getValue();
74 }
75 /// Convenience method to set the transform origin
76 void setTransformOrigin(const Base::Placement& placement);
77 /// Resets transform origin to the object origin
78 void resetTransformOrigin();
79
80 void setGizmoContainer(Gui::GizmoContainer* gizmoContainer);
81
82 public:
83 /** @name Edit methods */
84 //@{
85 bool doubleClicked() override;
86 void setupContextMenu(QMenu*, QObject*, const char*) override;
87 void updateData(const App::Property*) override;
88
89 ViewProvider* startEditing(int ModNum = 0) override;
90
91 /*! synchronize From FC placement to Coin placement*/
92 static void updateTransform(const Base::Placement& from, SoTransform* to);
93
94 enum class DraggerComponent
95 {
96 None = 0,
97 XPos = 1 << 0,
98 YPos = 1 << 1,
99 ZPos = 1 << 2,
100 XRot = 1 << 3,
101 YRot = 1 << 4,
102 ZRot = 1 << 5,
103 All = XPos | YPos | ZPos | XRot | YRot | ZRot
104 };
105 using DraggerComponents = Base::Flags<DraggerComponent>;
106 /// updates placement of object based on dragger position and chosen axes components
107 void updatePlacementFromDragger(DraggerComponents components = DraggerComponent::All);
108 /// updates transform of object based on dragger position, can be used to preview movement
109 void updateTransformFromDragger();
110
111 /// Gets object placement relative to its coordinate system
112 Base::Placement getObjectPlacement() const;
113 /// Gets current dragger placement, including current dragger movement
114 Base::Placement getDraggerPlacement() const;
115 /// Gets original dragger placement, without current dragger movement
116 Base::Placement getOriginalDraggerPlacement() const;
117 /// Sets placement of dragger relative to objects origin
118 void setDraggerPlacement(const Base::Placement& placement);
119
120 protected:
121 bool setEdit(int ModNum) override;
122 void unsetEdit(int ModNum) override;
123 void setEditViewer(View3DInventorViewer*, int ModNum) override;
124 void unsetEditViewer(View3DInventorViewer*) override;
125 //@}
126
127 void onChanged(const App::Property* prop) override;
128
129 bool forwardToLink();
130
131 /**
132 * Returns a newly create dialog for the part to be placed in the task view
133 * Must be reimplemented in subclasses.
134 */
135 virtual TaskView::TaskDialog* getTransformDialog();
136
137 CoinPtr<SoTransformDragger> transformDragger;
138 ViewProvider* forwardedViewProvider = nullptr;
139
140 CoinPtr<SoSwitch> pcPlacement;
141
142 private:
143 static void dragStartCallback(void* data, SoDragger* d);
144 static void dragFinishCallback(void* data, SoDragger* d);
145 static void dragMotionCallback(void* data, SoDragger* d);
146
147 void updateDraggerPosition();
148
149 Base::Placement draggerPlacement {};
150
151 // Rotation by orthonormalizing depending on given axes components
152 Base::Rotation orthonormalize(
153 Base::Vector3d x,
154 Base::Vector3d y,
155 Base::Vector3d z,
156 ViewProviderDragger::DraggerComponents components = DraggerComponent::All
157 );
158
159 GizmoContainer* gizmoContainer = nullptr;
160 };
161
162 } // namespace Gui
163
164 ENABLE_BITMASK_OPERATORS(Gui::ViewProviderDragger::DraggerComponent)
165
166 #endif // GUI_VIEWPROVIDER_DRAGGER_H