MeshLib C++ Docs
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
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 UniformScale,
64 NonUniformScale,
65 };
66
69 float deadZonePixelRadius_{ 20.0f };
70
73 MRVIEWER_API virtual ObjAndPick pickObjects_( std::vector<std::shared_ptr<Object>>& objects, int modifiers ) const;
74
76 MRVIEWER_API virtual TransformMode modeFromPickModifiers_( int modifiers ) const;
77
79 MRVIEWER_API virtual TransformMode modeFromPick_( MouseButton button, int modifiers ) const;
80
82 MRVIEWER_API virtual void setStartPoint_( const ObjAndPick& pick, Vector3f& startPoint ) const;
83
85 MRVIEWER_API virtual void setCenterPoint_( const std::vector<std::shared_ptr<Object>>& objects, Vector3f& centerPoint ) const;
86
89 MRVIEWER_API Box3f getBbox_( const std::vector<std::shared_ptr<Object>>& objects ) const;
90
91 AffineXf3f currentXf_; // Transform currently applied to objects
92private:
93 int minDistance_ = 0;
94
100 TransformMode pick_( MouseButton button, int modifiers );
101
103 MRVIEWER_API virtual void onPick_(
104 TransformMode mode, const std::vector<std::shared_ptr<Object>>& objects,
105 const Vector3f& centerPoint, const Vector3f& startPoint );
106
107 void clear_();
108
109 void applyCurrentXf_( bool history );
110 void resetXfs_();
111
112 void setVisualizeVectors_( std::vector<Vector3f> worldPoints );
113
114 std::vector<std::shared_ptr<Object>> objects_;
115 std::vector<AffineXf3f> initialXfs_;
116
117 TransformMode transformMode_ = TransformMode::None;
118 Vector2i screenStartPoint_; // cNoPoint when moving actually started, {} when inactive
119 MouseButton currentButton_ = MouseButton::NoButton;
120
121 // Data used to calculate transform
122 Vector3f worldStartPoint_; // World point corresponding to cursor, for transform calculation
123 Vector3f xfCenterPoint_;
124 float viewportStartPointZ_;
125 Plane3f referencePlane_;
126 float angle_ = 0.f;
127 float shift_ = 0.f;
128 float scale_ = 1.f;
129
130 // only check on real appending history
131 bool historyEnabled_{ true };
132
133 std::vector<ImVec2> visualizeVectors_;
134};
135
136}
Definition MRMoveObjectByMouseImpl.h:16
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
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 void onDrawDialog(float menuScaling) 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: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
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:24
void setMinDistance(int minDistance)
Definition MRMoveObjectByMouseImpl.h:25
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:91
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
std::pair< std::shared_ptr< MR::VisualObject >, MR::PointOnObject > ObjAndPick
Definition MRViewerFwd.h:69