MeshLib C++ Docs
Loading...
Searching...
No Matches
MRMoveObjectByMouseImpl.h
Go to the documentation of this file.
1#pragma once
2#include "MRViewerFwd.h"
3#include "MRMouse.h"
4#include "MRImGui.h"
5#include "MRMesh/MRPlane3.h"
7#include "MRMesh/MRSignal.h"
8
9namespace MR
10{
13
14
19class MRVIEWER_CLASS MoveObjectByMouseImpl
20{
21public:
23 virtual ~MoveObjectByMouseImpl() = default;
24
28 int minDistance() const { return minDistance_; }
29 void setMinDistance( int minDistance ) { minDistance_ = minDistance; }
30
33 MRVIEWER_API void onDrawDialog() const;
34
41 MRVIEWER_API bool onMouseDown( MouseButton button, int modifiers );
42 MRVIEWER_API bool onMouseMove( int x, int y );
43 MRVIEWER_API bool onMouseUp( MouseButton button, int modifiers );
44
47 MRVIEWER_API bool isMoving() const;
48
52 MRVIEWER_API void cancel();
53
55 void enableHistory( bool history ) { historyEnabled_ = history; }
56
58 bool isHistoryEnabled() const { return historyEnabled_; }
59
60protected:
62 enum class TransformMode
63 {
64 None,
67 UniformScale,
68 NonUniformScale,
69 };
70
73 float deadZonePixelRadius_{ 20.0f };
74
77 MRVIEWER_API virtual ObjAndPick pickObjects_( std::vector<std::shared_ptr<Object>>& objects, int modifiers ) const;
78
80 MRVIEWER_API virtual TransformMode modeFromPickModifiers_( int modifiers ) const;
81
83 MRVIEWER_API virtual TransformMode modeFromPick_( MouseButton button, int modifiers ) const;
84
86 MRVIEWER_API virtual void setStartPoint_( const ObjAndPick& pick, Vector3f& startPoint ) const;
87
89 MRVIEWER_API virtual void setCenterPoint_( const std::vector<std::shared_ptr<Object>>& objects, Vector3f& centerPoint ) const;
90
93 MRVIEWER_API virtual Plane3f calcControlPlane_( const Viewport& vp, const Vector3f& viewportCenterPoint, const Vector3f& xfCenterPoint ) const;
94
97 MRVIEWER_API Box3f getBbox_( const std::vector<std::shared_ptr<Object>>& objects ) const;
98
99 AffineXf3f currentXf_;
100private:
101 int minDistance_ = 0;
102
108 TransformMode pick_( MouseButton button, int modifiers );
109
111 MRVIEWER_API virtual void onPick_(
112 TransformMode mode, const std::vector<std::shared_ptr<Object>>& objects,
113 const Vector3f& centerPoint, const Vector3f& startPoint );
114
115 void clear_();
116
117 void applyCurrentXf_();
118
119 void setVisualizeVectors_( std::vector<Vector3f> worldPoints );
120
121 std::vector<std::shared_ptr<Object>> objects_;
122 std::vector<AffineXf3f> initialXfs_;
123
124 TransformMode transformMode_ = TransformMode::None;
125 Vector2i screenStartPoint_;
126 bool xfChanged_ = false;
127 MouseButton currentButton_ = MouseButton::NoButton;
128
130 Vector3f worldStartPoint_;
131 Vector3f xfCenterPoint_;
132 float viewportStartPointZ_;
133 Plane3f referencePlane_;
134 float angle_ = 0.f;
135 float shift_ = 0.f;
136 float scale_ = 1.f;
137
139 bool historyEnabled_{ true };
140
141 std::vector<ImVec2> visualizeVectors_;
142
144 std::vector<boost::signals2::scoped_connection> connections_;
145 bool changingXfFromMouseMove_{ false };
146};
147
148}
Definition MRMoveObjectByMouseImpl.h:20
Definition MRViewport.h:49
virtual MRVIEWER_API void setCenterPoint_(const std::vector< std::shared_ptr< Object > > &objects, Vector3f &centerPoint) const
centerPoint - a point that will be used as center of rotation/scaling in world space
MouseButton
Definition MRMouse.h:12
virtual MRVIEWER_API TransformMode modeFromPickModifiers_(int modifiers) const
Helper function to determine TransformMode based on modifiers.
virtual ~MoveObjectByMouseImpl()=default
MRVIEWER_API Box3f getBbox_(const std::vector< std::shared_ptr< Object > > &objects) const
MRVIEWER_API bool onMouseMove(int x, int y)
MRVIEWER_API bool onMouseUp(MouseButton button, int modifiers)
virtual MRVIEWER_API ObjAndPick pickObjects_(std::vector< std::shared_ptr< Object > > &objects, int modifiers) const
TransformMode
Transformation mode.
Definition MRMoveObjectByMouseImpl.h:63
MRVIEWER_API bool onMouseDown(MouseButton button, int modifiers)
virtual MRVIEWER_API Plane3f calcControlPlane_(const Viewport &vp, const Vector3f &viewportCenterPoint, const Vector3f &xfCenterPoint) const
MRVIEWER_API void onDrawDialog() const
MRVIEWER_API bool isMoving() const
void enableHistory(bool history)
enables or disables adding history to viewer history store by this tool
Definition MRMoveObjectByMouseImpl.h:55
virtual MRVIEWER_API TransformMode modeFromPick_(MouseButton button, int modifiers) const
this function is called from onMouseDown to verify if pick should proceed, if None is returned - onMo...
int minDistance() const
Definition MRMoveObjectByMouseImpl.h:28
void setMinDistance(int minDistance)
Definition MRMoveObjectByMouseImpl.h:29
MRVIEWER_API void cancel()
virtual MRVIEWER_API void setStartPoint_(const ObjAndPick &pick, Vector3f &startPoint) const
startPoint - a point under cursor for transform calculation, can be the picked point or else (world c...
AffineXf3f currentXf_
Definition MRMoveObjectByMouseImpl.h:99
bool isHistoryEnabled() const
returns true if appending history to viewer history store is enabled in this tool
Definition MRMoveObjectByMouseImpl.h:58
@ Translation
Rotate camera around selected point.
@ None
special value not to limit path in one slice
Definition MRVoxelPath.h:33
only for bindings generation
Definition MRCameraOrientationPlugin.h:8