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:
24 ChangeDirAction( DirectionWidget& widget, const std::string& name = "Change Direction" ) :
25 ChangeXfAction( name, static_pointer_cast<Object>( widget.directionObj_ ) )
26 {}
27 };
28
31 {
32 public:
34 widget_{ widget },
35 visible_{ widget.directionObj_->visibilityMask() }
36 {}
37 virtual void action( Type ) override
38 {
39 auto oldVisible = widget_.directionObj_->visibilityMask();
40 widget_.directionObj_->setVisibilityMask( visible_ );
41 visible_ = oldVisible;
42 }
43 virtual std::string name() const override
44 {
45 return name_;
46 }
47 [[nodiscard]] virtual size_t heapBytes() const override
48 {
49 return name_.capacity();
50 }
51 private:
52 DirectionWidget& widget_;
53 ViewportMask visible_;
54 std::string name_ = "Change Visible";
55 };
56
57private:
58 std::shared_ptr<ObjectMesh> directionObj_;
59
60 bool mousePressed_ = false;
61 // if blocked cannot be moved with mouse
62 bool blockedMouse_{ false };
63 Vector3f worldStartPoint_;
64 float viewportStartPointZ_{ 0.0f };
65 OnDirectionChangedCallback onDirectionChanged_;
66 Color color_ = Color::red();
67 bool needToSaveHistory_ = true;
68 void clear_();
69
70public:
71 struct Arrow
72 {
73 Vector3f dir;
74 Vector3f base;
75 float length = 1;
76 };
77
81 MRVIEWER_API void create( Object* parent = nullptr );
82
90 MRVIEWER_API void create( const Vector3f& worldDir, const Vector3f& worldBase, float worldLength, OnDirectionChangedCallback onDirectionChanged, Object* parent = nullptr );
91
94 MRVIEWER_API void reset();
95
98
100 MRVIEWER_API void updateArrow( const Arrow& arrow );
101
103 MRVIEWER_API void updateLocalArrow( const Arrow& arrow );
104
106 MRVIEWER_API void updateDirection( const Vector3f& dir );
107
109 MRVIEWER_API void updateLocalDirection( const Vector3f& dir );
110
112 MRVIEWER_API void updateBase( const Vector3f& base );
113
115 MRVIEWER_API void updateLocalBase( const Vector3f& base );
116
118 MRVIEWER_API void updateLength( float length );
119
121 MRVIEWER_API void updateLocalLength( float length );
122
124 const std::shared_ptr<ObjectMesh>& obj() const { return directionObj_; }
125
127 MRVIEWER_API void setVisible( bool visible );
128
129 MRVIEWER_API bool isVisible() const;
130
132 MRVIEWER_API void setColor( const Color& color );
133
135 MRVIEWER_API const Color& getColor() const;
136
138 MRVIEWER_API Arrow getArrow() const;
139
141 MRVIEWER_API Arrow getLocalArrow() const;
142
144 MRVIEWER_API Vector3f getBase() const;
145
147 MRVIEWER_API Vector3f getLocalBase() const;
148
150 MRVIEWER_API Vector3f getDirection() const;
151
153 MRVIEWER_API Vector3f getLocalDirection() const;
154
156 MRVIEWER_API float getLength() const;
157
159 MRVIEWER_API float getLocalLength() const;
160
162 MRVIEWER_API Object* getParentPtr() const;
163
165 bool isMouseBlocked() const { return blockedMouse_; }
166
167 void setMouseBlocked( bool blocked ) { blockedMouse_ = blocked; }
168
169private:
170 MRVIEWER_API virtual bool onMouseDown_( MouseButton button, int modifier ) override;
171 MRVIEWER_API virtual bool onMouseUp_( MouseButton button, int modifier ) override;
172 MRVIEWER_API virtual bool onMouseMove_( int mouse_x, int mouse_y ) override;
173};
174
175} //namespace MR
length
Definition MRObjectDimensionsEnum.h:14
Definition MRChangeXfAction.h:13
This history action must be created before the change in widget's direction, base or length to make t...
Definition MRDirectionWidget.h:22
ChangeDirAction(DirectionWidget &widget, const std::string &name="Change Direction")
Definition MRDirectionWidget.h:24
history action for changing the visible. It should be added to the history stack by user code
Definition MRDirectionWidget.h:31
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRDirectionWidget.h:47
virtual std::string name() const override
Definition MRDirectionWidget.h:43
virtual void action(Type) override
This function is called on history action (undo, redo, etc.)
Definition MRDirectionWidget.h:37
ChangeVisibleAction(DirectionWidget &widget)
Definition MRDirectionWidget.h:33
Widget for visualizing the direction.
Definition MRDirectionWidget.h:15
MRVIEWER_API float getLength() const
Returns the length of the arrow in world space.
MRVIEWER_API void updateBase(const Vector3f &base)
Updates the base of the arrow, in world space.
bool isMouseBlocked() const
Block or allow mouse editing (allowed by default)
Definition MRDirectionWidget.h:165
MRVIEWER_API const Color & getColor() const
Returns the color of the widget.
MRVIEWER_API void updateLocalArrow(const Arrow &arrow)
Updates the arrow in parent's space.
MRVIEWER_API void updateDirection(const Vector3f &dir)
Updates the direction of the arrow, in world space.
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 updateLocalBase(const Vector3f &base)
Updates the base of the arrow in parent's space.
MRVIEWER_API Vector3f getDirection() const
Returns the direction of the widget, in world space.
MRVIEWER_API bool isVisible() const
MRVIEWER_API Object * getParentPtr() const
Returns pointer to parent object, always not-null after create() and before reset()
MRVIEWER_API Arrow getArrow() const
Returns the arrow's properties, in world space.
MRVIEWER_API void reset()
MRVIEWER_API void setOnDirectionChangedCallback(OnDirectionChangedCallback cb)
Manually set callback function.
MRVIEWER_API void create(const Vector3f &worldDir, const Vector3f &worldBase, float worldLength, OnDirectionChangedCallback onDirectionChanged, Object *parent=nullptr)
MRVIEWER_API Arrow getLocalArrow() const
Returns the arrow's properties in parent's space.
MRVIEWER_API void updateLocalDirection(const Vector3f &dir)
Updates the direction of the arrow in parent's space.
MRVIEWER_API void updateLocalLength(float length)
Updates the length of the arrow in parent's space.
MRVIEWER_API void updateLength(float length)
Updates the length of the arrow, in world space.
std::function< void(const Vector3f &, bool)> OnDirectionChangedCallback
This callback is invoked every time when the direction is changed by mouse.
Definition MRDirectionWidget.h:18
const std::shared_ptr< ObjectMesh > & obj() const
Returns internal data model object of this widget.
Definition MRDirectionWidget.h:124
MRVIEWER_API void create(Object *parent=nullptr)
void setMouseBlocked(bool blocked)
Definition MRDirectionWidget.h:167
MRVIEWER_API float getLocalLength() const
Returns the length of the arrow in parent's space.
MRVIEWER_API Vector3f getBase() const
Returns the base of the widget, in world space.
MRVIEWER_API void updateArrow(const Arrow &arrow)
Updates the arrow, in world space.
MRVIEWER_API Vector3f getLocalDirection() const
Returns the direction of the widget in parent's space.
MRVIEWER_API Vector3f getLocalBase() const
Returns the base of the widget in parent's space.
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
MouseButton
Definition MRMouse.h:9
Definition MRMesh/MRColor.h:9
Definition MRDirectionWidget.h:72
Vector3f dir
unit direction along arrow
Definition MRDirectionWidget.h:73
Vector3f base
the point from which the arrow starts
Definition MRDirectionWidget.h:74
Definition MRViewerEventsListener.h:29