MeshLib Documentation
Loading...
Searching...
No Matches
MRDirectionWidget.h
Go to the documentation of this file.
1#pragma once
2
3#include "exports.h"
5#include "MRMesh/MRMeshFwd.h"
6#include "MRMesh/MRVector3.h"
8#include "MRMesh/MRColor.h"
10
11namespace MR
12{
14class MRVIEWER_CLASS DirectionWidget : public MultiListener<MouseDownListener, MouseMoveListener, MouseUpListener>
15{
16public:
18 using OnDirectionChangedCallback = std::function<void( const Vector3f&, bool )>;
19
22 {
23 public:
25 ChangeXfAction( "Change Direction", static_pointer_cast<Object>( widget.directionObj_ ) ),
26 widget_{ widget },
27 dir_{ widget.dir_ }
28 {}
29 virtual void action( Type type ) override
30 {
31 ChangeXfAction::action( type );
32 std::swap( dir_, widget_.dir_ );
33
34 }
35 private:
36 DirectionWidget& widget_;
37 Vector3f dir_;
38 };
39
42 {
43 public:
45 ChangeXfAction( "Change Base", static_pointer_cast< Object >( widget.directionObj_ ) ),
46 widget_{ widget },
47 base_{ widget.base_ }
48 {}
49 virtual void action( Type type ) override
50 {
51 ChangeXfAction::action( type );
52 std::swap( base_, widget_.base_ );
53 }
54 private:
55 DirectionWidget& widget_;
56 Vector3f base_;
57 };
58
61 {
62 public:
64 ChangeXfAction( "Change Length", static_pointer_cast< Object >( widget.directionObj_ ) ),
65 widget_{ widget },
66 length_{ widget.length_ }
67 {}
68 virtual void action( Type ) override
69 {
70 widget_.updateLength( length_ );
71 }
72 private:
73 DirectionWidget& widget_;
74 float length_;
75 };
76
79 {
80 public:
82 widget_{ widget },
83 visible_{ widget.directionObj_->visibilityMask() }
84 {}
85 virtual void action( Type ) override
86 {
87 widget_.directionObj_->setVisibilityMask( visible_ );
88 }
89 virtual std::string name() const override
90 {
91 return name_;
92 }
93 [[nodiscard]] virtual size_t heapBytes() const override
94 {
95 return name_.capacity();
96 }
97 private:
98 DirectionWidget& widget_;
99 ViewportMask visible_;
100 std::string name_ = "Change Visible";
101 };
102
103private:
104 std::shared_ptr<ObjectMesh> directionObj_;
105 VisualObject* parent_;
106
107 Vector3f dir_;
108 Vector3f base_;
109 float length_;
110 bool mousePressed_ = false;
111 // if blocked cannot be moved with mouse
112 bool blockedMouse_{ false };
113 Vector3f worldStartPoint_;
114 float viewportStartPointZ_{ 0.0f };
115 OnDirectionChangedCallback onDirectionChanged_;
116 Color color_ = Color::red();
117 bool needToSaveHistory_ = true;
118 void clear_();
119
120public:
127 MRVIEWER_API void create( const Vector3f& dir, const Vector3f& base, float length, OnDirectionChangedCallback onDirectionChanged, VisualObject* parent = nullptr );
128
131 MRVIEWER_API void reset();
132
135
137 MRVIEWER_API void updateDirection( const Vector3f& dir );
139 MRVIEWER_API void updateBase( const Vector3f& base );
141 MRVIEWER_API void updateLength( float length );
143 MRVIEWER_API void updateArrow( const Vector3f& base, float length );
144
146 MRVIEWER_API void setVisible( bool visible );
148 MRVIEWER_API void setColor( const Color& color );
150 MRVIEWER_API const Color& getColor() const;
152 MRVIEWER_API const Vector3f& getBase() const;
154 MRVIEWER_API const Vector3f& getDirection() const;
156 MRVIEWER_API const VisualObject* getParentPtr() const;
157
159 bool isMouseBlocked() const { return blockedMouse_; }
160 void setMouseBlocked( bool blocked ) { blockedMouse_ = blocked; }
161private:
162 MRVIEWER_API virtual bool onMouseDown_( MouseButton button, int modifier ) override;
163 MRVIEWER_API virtual bool onMouseUp_( MouseButton button, int modifier ) override;
164 MRVIEWER_API virtual bool onMouseMove_( int mouse_x, int mouse_y ) override;
165};
166
167}
length
Definition MRObjectDimensionsEnum.h:14
Definition MRChangeXfAction.h:13
history action for changing the base. It should be added to the history stack by user code
Definition MRDirectionWidget.h:42
ChangeBaseAction(DirectionWidget &widget)
Definition MRDirectionWidget.h:44
virtual void action(Type type) override
This function is called on history action (undo, redo, etc.)
Definition MRDirectionWidget.h:49
history action for changing the direction. It should be added to the history stack by user code
Definition MRDirectionWidget.h:22
ChangeDirAction(DirectionWidget &widget)
Definition MRDirectionWidget.h:24
virtual void action(Type type) override
This function is called on history action (undo, redo, etc.)
Definition MRDirectionWidget.h:29
history action for changing the length. It should be added to the history stack by user code
Definition MRDirectionWidget.h:61
ChangeLengthAction(DirectionWidget &widget)
Definition MRDirectionWidget.h:63
virtual void action(Type) override
This function is called on history action (undo, redo, etc.)
Definition MRDirectionWidget.h:68
history action for changing the visible. It should be added to the history stack by user code
Definition MRDirectionWidget.h:79
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRDirectionWidget.h:93
virtual std::string name() const override
Definition MRDirectionWidget.h:89
virtual void action(Type) override
This function is called on history action (undo, redo, etc.)
Definition MRDirectionWidget.h:85
ChangeVisibleAction(DirectionWidget &widget)
Definition MRDirectionWidget.h:81
Widget for visualizing the direction.
Definition MRDirectionWidget.h:15
MRVIEWER_API void updateBase(const Vector3f &base)
Updates the base of the arrow.
MRVIEWER_API const VisualObject * getParentPtr() const
Returns pointer to parent object.
bool isMouseBlocked() const
Block or allow mouse editing (allowed by default)
Definition MRDirectionWidget.h:159
MRVIEWER_API const Color & getColor() const
Returns the color of the widget.
MRVIEWER_API void updateDirection(const Vector3f &dir)
Updates the direction of the arrow.
MRVIEWER_API void setVisible(bool visible)
Sets the visibility of the widget.
MRVIEWER_API void setColor(const Color &color)
Sets the color of the widget.
MRVIEWER_API void reset()
MRVIEWER_API void setOnDirectionChangedCallback(OnDirectionChangedCallback cb)
Manually set callback function.
MRVIEWER_API const Vector3f & getDirection() const
Returns the direction of the widget.
MRVIEWER_API void updateLength(float length)
Updates the length of the arrow.
std::function< void(const Vector3f &, bool)> OnDirectionChangedCallback
This callback is invoked every time when the direction is changed by mouse.
Definition MRDirectionWidget.h:18
void setMouseBlocked(bool blocked)
Definition MRDirectionWidget.h:160
MRVIEWER_API void updateArrow(const Vector3f &base, float length)
Updates the base and the length of the arrow.
MRVIEWER_API const Vector3f & getBase() const
Returns the base of the widget.
MRVIEWER_API void create(const Vector3f &dir, const Vector3f &base, float length, OnDirectionChangedCallback onDirectionChanged, VisualObject *parent=nullptr)
Definition MRHistoryAction.h:12
Type
Definition MRHistoryAction.h:19
named object in the data model
Definition MRObject.h:60
stores mask of viewport unique identifiers
Definition MRViewportId.h:38
Visual Object.
Definition MRVisualObject.h:131
Definition MRCameraOrientationPlugin.h:8
MouseButton
Definition MRMouse.h:9
Definition MRColor.h:9
Definition MRViewerEventsListener.h:29