MeshLib C++ Docs
Loading...
Searching...
No Matches
MRMoveObjectByMouseImpl.h
Go to the documentation of this file.
1#pragma once
2#include "MRMesh/MRPlane3.h"
5#include "MRViewer/MRMouse.h"
6#include "MRViewer/MRImGui.h"
7
8namespace MR
9{
10
15class MRVIEWER_CLASS MoveObjectByMouseImpl
16{
17public:
19 virtual ~MoveObjectByMouseImpl() = default;
20
24 int minDistance() const { return minDistance_; }
25 void setMinDistance( int minDistance ) { minDistance_ = minDistance; }
26
29 MRVIEWER_API void onDrawDialog( float menuScaling ) const;
30
37 MRVIEWER_API bool onMouseDown( MouseButton button, int modifiers );
38 MRVIEWER_API bool onMouseMove( int x, int y );
39 MRVIEWER_API bool onMouseUp( MouseButton button, int modifiers );
40
43 MRVIEWER_API bool isMoving() const;
44
48 MRVIEWER_API void cancel();
49
51 void enableHistory( bool history ) { historyEnabled_ = history; }
52
54 bool isHistoryEnabled() const { return historyEnabled_; }
55
56protected:
58 enum class TransformMode
59 {
60 None,
63 Scale
64 };
65
72 MRVIEWER_API virtual TransformMode pick_( MouseButton button, int modifiers,
73 std::vector<std::shared_ptr<Object>>& objects, Vector3f& centerPoint, Vector3f& startPoint );
74
77 MRVIEWER_API Box3f getBbox_( const std::vector<std::shared_ptr<Object>>& objects );
78
79private:
80 int minDistance_ = 0;
81
82 void clear_();
83
84 void applyCurrentXf_( bool history );
85 void resetXfs_();
86
87 void setVisualizeVectors_( std::vector<Vector3f> worldPoints );
88
89 std::vector<std::shared_ptr<Object>> objects_;
90 std::vector<AffineXf3f> initialXfs_;
91
92 TransformMode transformMode_ = TransformMode::None;
93 Vector2i screenStartPoint_; // cNoPoint when moving actually started, {} when inactive
94 AffineXf3f currentXf_; // Transform currently applied to objects
95 MouseButton currentButton_ = MouseButton::NoButton;
96
97 // Data used to calculate transform
98 Vector3f worldStartPoint_; // World point corresponding to cursor, for transform calculation
99 Vector3f xfCenterPoint_;
100 float viewportStartPointZ_;
101 Plane3f referencePlane_;
102 float angle_ = 0.f;
103 float shift_ = 0.f;
104 float scale_ = 1.f;
105
106 // only check on real appending history
107 bool historyEnabled_{ true };
108
109 std::vector<ImVec2> visualizeVectors_;
110};
111
112}
Definition MRMoveObjectByMouseImpl.h:16
virtual ~MoveObjectByMouseImpl()=default
MRVIEWER_API void onDrawDialog(float menuScaling) const
MRVIEWER_API bool onMouseMove(int x, int y)
MRVIEWER_API Box3f getBbox_(const std::vector< std::shared_ptr< Object > > &objects)
MRVIEWER_API bool onMouseUp(MouseButton button, int modifiers)
TransformMode
Transformation mode.
Definition MRMoveObjectByMouseImpl.h:59
MRVIEWER_API bool onMouseDown(MouseButton button, int modifiers)
MRVIEWER_API bool isMoving() const
void enableHistory(bool history)
enables or disables adding history to viewer history store by this tool
Definition MRMoveObjectByMouseImpl.h:51
int minDistance() const
Definition MRMoveObjectByMouseImpl.h:24
void setMinDistance(int minDistance)
Definition MRMoveObjectByMouseImpl.h:25
MRVIEWER_API void cancel()
virtual MRVIEWER_API TransformMode pick_(MouseButton button, int modifiers, std::vector< std::shared_ptr< Object > > &objects, Vector3f &centerPoint, Vector3f &startPoint)
bool isHistoryEnabled() const
returns true if appending history to viewer history store is enabled in this tool
Definition MRMoveObjectByMouseImpl.h:54
@ None
special value not to limit path in one slice
Definition MRVoxelPath.h:33
MouseButton
Definition MRMouse.h:9