MeshLib C++ Docs
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 auto tempDir = widget_.dir_;
33 widget_.updateDirection( dir_ );
34 dir_ = tempDir;
35 }
36 private:
37 DirectionWidget& widget_;
38 Vector3f dir_;
39 };
40
43 {
44 public:
46 ChangeXfAction( "Change Base", static_pointer_cast< Object >( widget.directionObj_ ) ),
47 widget_{ widget },
48 base_{ widget.base_ }
49 {}
50 virtual void action( Type type ) override
51 {
52 ChangeXfAction::action( type );
53 std::swap( base_, widget_.base_ );
54 }
55 private:
56 DirectionWidget& widget_;
57 Vector3f base_;
58 };
59
62 {
63 public:
65 ChangeXfAction( "Change Length", static_pointer_cast< Object >( widget.directionObj_ ) ),
66 widget_{ widget },
67 length_{ widget.length_ }
68 {}
69 virtual void action( Type ) override
70 {
71 auto len = widget_.length_;
72 widget_.updateLength( length_ );
73 length_ = len;
74
75 }
76 private:
77 DirectionWidget& widget_;
78 float length_;
79 };
80
83 {
84 public:
86 widget_{ widget },
87 visible_{ widget.directionObj_->visibilityMask() }
88 {}
89 virtual void action( Type ) override
90 {
91 auto oldVisible = widget_.directionObj_->visibilityMask();
92 widget_.directionObj_->setVisibilityMask( visible_ );
93 visible_ = oldVisible;
94 }
95 virtual std::string name() const override
96 {
97 return name_;
98 }
99 [[nodiscard]] virtual size_t heapBytes() const override
100 {
101 return name_.capacity();
102 }
103 private:
104 DirectionWidget& widget_;
105 ViewportMask visible_;
106 std::string name_ = "Change Visible";
107 };
108
109private:
110 std::shared_ptr<ObjectMesh> directionObj_;
111 VisualObject* parent_;
112
113 Vector3f dir_;
114 Vector3f base_;
115 float length_;
116 bool mousePressed_ = false;
117 // if blocked cannot be moved with mouse
118 bool blockedMouse_{ false };
119 Vector3f worldStartPoint_;
120 float viewportStartPointZ_{ 0.0f };
121 OnDirectionChangedCallback onDirectionChanged_;
122 Color color_ = Color::red();
123 bool needToSaveHistory_ = true;
124 void clear_();
125
126public:
133 MRVIEWER_API void create( const Vector3f& dir, const Vector3f& base, float length, OnDirectionChangedCallback onDirectionChanged, VisualObject* parent = nullptr );
134
137 MRVIEWER_API void reset();
138
141
143 MRVIEWER_API void updateDirection( const Vector3f& dir );
144
146 MRVIEWER_API void updateBase( const Vector3f& base );
147
149 MRVIEWER_API void updateLength( float length );
150
152 MRVIEWER_API void updateArrow( const Vector3f& base, float length );
153
155 std::shared_ptr<ObjectMesh> obj() const { return directionObj_; }
156
158 MRVIEWER_API void setVisible( bool visible );
159
160 MRVIEWER_API bool isVisible() const;
161
163 MRVIEWER_API void setColor( const Color& color );
164
166 MRVIEWER_API const Color& getColor() const;
167
169 MRVIEWER_API const Vector3f& getBase() const;
170
172 MRVIEWER_API const Vector3f& getDirection() const;
173
175 MRVIEWER_API const VisualObject* getParentPtr() const;
176
178 bool isMouseBlocked() const { return blockedMouse_; }
179
180 void setMouseBlocked( bool blocked ) { blockedMouse_ = blocked; }
181private:
182 MRVIEWER_API virtual bool onMouseDown_( MouseButton button, int modifier ) override;
183 MRVIEWER_API virtual bool onMouseUp_( MouseButton button, int modifier ) override;
184 MRVIEWER_API virtual bool onMouseMove_( int mouse_x, int mouse_y ) override;
185};
186
187}
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:43
ChangeBaseAction(DirectionWidget &widget)
Definition MRDirectionWidget.h:45
virtual void action(Type type) override
This function is called on history action (undo, redo, etc.)
Definition MRDirectionWidget.h:50
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:62
ChangeLengthAction(DirectionWidget &widget)
Definition MRDirectionWidget.h:64
virtual void action(Type) override
This function is called on history action (undo, redo, etc.)
Definition MRDirectionWidget.h:69
history action for changing the visible. It should be added to the history stack by user code
Definition MRDirectionWidget.h:83
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRDirectionWidget.h:99
virtual std::string name() const override
Definition MRDirectionWidget.h:95
virtual void action(Type) override
This function is called on history action (undo, redo, etc.)
Definition MRDirectionWidget.h:89
ChangeVisibleAction(DirectionWidget &widget)
Definition MRDirectionWidget.h:85
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:178
MRVIEWER_API const Color & getColor() const
Returns the color of the widget.
std::shared_ptr< ObjectMesh > obj() const
Returns internal data model object of this widget.
Definition MRDirectionWidget.h:155
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 bool isVisible() const
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:180
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
MouseButton
Definition MRMouse.h:9
Definition MRMesh/MRColor.h:9
Definition MRViewerEventsListener.h:29