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#include "MRMesh/MRHeapBytes.h"
11
12namespace MR
13{
16
18class MRVIEWER_CLASS DirectionWidget : public MultiListener<MouseDownListener, MouseMoveListener, MouseUpListener>
19{
20public:
22 using OnDirectionChangedCallback = std::function<void( const Vector3f&, bool )>;
23
26 {
27 public:
28 ChangeDirAction( DirectionWidget& widget, const std::string& name = "Change Direction" ) :
29 ChangeXfAction( name, static_pointer_cast<Object>( widget.directionObj_ ) )
30 {}
31 };
32
35 {
36 public:
38 widget_{ widget },
39 visible_{ widget.directionObj_->visibilityMask() }
40 {}
41 virtual void action( Type ) override
42 {
43 auto oldVisible = widget_.directionObj_->visibilityMask();
44 widget_.directionObj_->setVisibilityMask( visible_ );
45 visible_ = oldVisible;
46 }
47 virtual std::string name() const override
48 {
49 return name_;
50 }
51 [[nodiscard]] virtual size_t heapBytes() const override
52 {
53 return name_.capacity();
54 }
55 private:
56 DirectionWidget& widget_;
57 ViewportMask visible_;
58 std::string name_ = "Change Visible";
59 };
60
61private:
62 std::shared_ptr<ObjectMesh> directionObj_;
63
65 bool blockedMouse_{ false };
66 bool mousePressed_ = false;
68 Vector3f draggingViewportStartPoint_;
70 Vector3f draggingViewportStartPointOffset_;
71
72 OnDirectionChangedCallback onDirectionChanged_;
73 Color color_ = Color::red();
74 bool needToSaveHistory_ = true;
75 void clear_();
76
77public:
78 struct Arrow
79 {
80 Vector3f dir;
81 Vector3f base;
82 float length = 1;
83 };
84
88 MRVIEWER_API void create( Object* parent = nullptr );
89
97 MRVIEWER_API void create( const Vector3f& worldDir, const Vector3f& worldBase, float worldLength, OnDirectionChangedCallback onDirectionChanged, Object* parent = nullptr );
98
101 MRVIEWER_API void reset();
102
105
107 MRVIEWER_API void updateArrow( const Arrow& arrow );
108
110 MRVIEWER_API void updateLocalArrow( const Arrow& arrow );
111
113 MRVIEWER_API void updateDirection( const Vector3f& dir );
114
116 MRVIEWER_API void updateLocalDirection( const Vector3f& dir );
117
119 MRVIEWER_API void updateBase( const Vector3f& base );
120
122 MRVIEWER_API void updateLocalBase( const Vector3f& base );
123
125 MRVIEWER_API void updateLength( float length );
126
128 MRVIEWER_API void updateLocalLength( float length );
129
131 const std::shared_ptr<ObjectMesh>& obj() const { return directionObj_; }
132
134 MRVIEWER_API void setVisible( bool visible );
135
136 MRVIEWER_API bool isVisible() const;
137
139 MRVIEWER_API void setColor( const Color& color );
140
142 MRVIEWER_API const Color& getColor() const;
143
145 MRVIEWER_API Arrow getArrow() const;
146
148 MRVIEWER_API Arrow getLocalArrow() const;
149
151 MRVIEWER_API Vector3f getBase() const;
152
154 MRVIEWER_API Vector3f getLocalBase() const;
155
157 MRVIEWER_API Vector3f getDirection() const;
158
160 MRVIEWER_API Vector3f getLocalDirection() const;
161
163 MRVIEWER_API float getLength() const;
164
166 MRVIEWER_API float getLocalLength() const;
167
169 MRVIEWER_API Object* getParentPtr() const;
170
172 bool isMouseBlocked() const { return blockedMouse_; }
173
174 void setMouseBlocked( bool blocked ) { blockedMouse_ = blocked; }
175
176private:
177 MRVIEWER_API virtual bool onMouseDown_( MouseButton button, int modifier ) override;
178 MRVIEWER_API virtual bool onMouseUp_( MouseButton button, int modifier ) override;
179 MRVIEWER_API virtual bool onMouseMove_( int mouse_x, int mouse_y ) override;
180};
181
182}
Widget for visualizing the direction.
Definition MRDirectionWidget.h:19
named object in the data model
Definition MRObject.h:61
stores mask of viewport unique identifiers
Definition MRViewportId.h:42
void setColor(const Color &color)
Sets the color of the widget.
Vector3f getLocalBase() const
Returns the base of the widget in parent's space.
Vector3f dir
unit direction along arrow
Definition MRDirectionWidget.h:80
bool isMouseBlocked() const
Block or allow mouse editing (allowed by default)
Definition MRDirectionWidget.h:172
ChangeDirAction(DirectionWidget &widget, const std::string &name="Change Direction")
Definition MRDirectionWidget.h:28
float getLocalLength() const
Returns the length of the arrow in parent's space.
MouseButton
Definition MRMouse.h:13
void updateBase(const Vector3f &base)
Updates the base of the arrow, in world space.
bool isVisible() const
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRDirectionWidget.h:51
Vector3f base
the point from which the arrow starts
Definition MRDirectionWidget.h:81
void updateLength(float length)
Updates the length of the arrow, in world space.
Arrow getArrow() const
Returns the arrow's properties, in world space.
void create(const Vector3f &worldDir, const Vector3f &worldBase, float worldLength, OnDirectionChangedCallback onDirectionChanged, Object *parent=nullptr)
void updateLocalArrow(const Arrow &arrow)
Updates the arrow in parent's space.
void setOnDirectionChangedCallback(OnDirectionChangedCallback cb)
Manually set callback function.
float getLength() const
Returns the length of the arrow in world space.
virtual std::string name() const override
Definition MRChangeXfAction.h:36
virtual std::string name() const override
Definition MRDirectionWidget.h:47
Object * getParentPtr() const
Returns pointer to parent object, always not-null after create() and before reset()
std::function< void(const Vector3f &, bool)> OnDirectionChangedCallback
This callback is invoked every time when the direction is changed by mouse.
Definition MRDirectionWidget.h:22
Vector3f getLocalDirection() const
Returns the direction of the widget in parent's space.
const std::shared_ptr< ObjectMesh > & obj() const
Returns internal data model object of this widget.
Definition MRDirectionWidget.h:131
void setMouseBlocked(bool blocked)
Definition MRDirectionWidget.h:174
void create(Object *parent=nullptr)
Arrow getLocalArrow() const
Returns the arrow's properties in parent's space.
void updateLocalDirection(const Vector3f &dir)
Updates the direction of the arrow in parent's space.
Vector3f getBase() const
Returns the base of the widget, in world space.
Type
Definition MRHistoryAction.h:27
virtual void action(Type) override
This function is called on history action (undo, redo, etc.)
Definition MRDirectionWidget.h:41
void updateDirection(const Vector3f &dir)
Updates the direction of the arrow, in world space.
float length
the length of the arrow
Definition MRDirectionWidget.h:82
ChangeVisibleAction(DirectionWidget &widget)
Definition MRDirectionWidget.h:37
Vector3f getDirection() const
Returns the direction of the widget, in world space.
ChangeXfAction(const std::string &name, const std::shared_ptr< Object > &obj)
use this constructor to remember object's transformation before making any changes in it
Definition MRChangeXfAction.h:19
const Color & getColor() const
Returns the color of the widget.
void updateArrow(const Arrow &arrow)
Updates the arrow, in world space.
HistoryAction()=default
explicitly define ctors to avoid warning C5267: definition of implicit copy constructor is deprecated...
void updateLocalLength(float length)
Updates the length of the arrow in parent's space.
length
Definition MRObjectDimensionsEnum.h:17
void updateLocalBase(const Vector3f &base)
Updates the base of the arrow in parent's space.
void setVisible(bool visible)
Sets the visibility of the widget.
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
Definition MRColor.h:12
Definition MRDirectionWidget.h:79
Definition MRViewerEventsListener.h:32