MeshLib
 
Loading...
Searching...
No Matches
MRDirectionWidget.h
Go to the documentation of this file.
1#pragma once
2
3#include "exports.h"
5#include "MRViewer/MRViewer.h"
6#include "MRMesh/MRMeshFwd.h"
7#include "MRMesh/MRVector3.h"
9#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 Dir", 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
40private:
41 std::shared_ptr<ObjectMesh> directionObj_;
42 VisualObject* parent_;
43
44 Vector3f dir_;
45 Vector3f base_;
46 float length_;
47 bool mousePressed_ = false;
48 // if blocked cannot be moved with mouse
49 bool blockedMouse_{ false };
50 Vector3f worldStartPoint_;
51 float viewportStartPointZ_{ 0.0f };
52 OnDirectionChangedCallback onDirectionChanged_;
53 Color color_ = Color::red();
54 bool needToSaveHistory_ = true;
55 void clear_();
56
57public:
64 MRVIEWER_API void create( const Vector3f& dir, const Vector3f& base, float length, OnDirectionChangedCallback onDirectionChanged, VisualObject* parent = nullptr );
65
68 MRVIEWER_API void reset();
69
72
74 MRVIEWER_API void updateDirection( const Vector3f& dir );
76 MRVIEWER_API void updateBase( const Vector3f& base );
78 MRVIEWER_API void updateLength( float length );
80 MRVIEWER_API void updateArrow( const Vector3f& base, float length );
81
83 MRVIEWER_API void setVisible( bool visible );
85 MRVIEWER_API void setColor( const Color& color );
87 MRVIEWER_API const Color& getColor() const;
89 MRVIEWER_API const Vector3f& getBase() const;
91 MRVIEWER_API const Vector3f& getDirection() const;
93 MRVIEWER_API const VisualObject* getParentPtr() const;
94
96 bool isMouseBlocked() const { return blockedMouse_; }
97 void setMouseBlocked( bool blocked ) { blockedMouse_ = blocked; }
98private:
99 MRVIEWER_API virtual bool onMouseDown_( Viewer::MouseButton button, int modifier ) override;
100 MRVIEWER_API virtual bool onMouseUp_( Viewer::MouseButton button, int modifier ) override;
101 MRVIEWER_API virtual bool onMouseMove_( int mouse_x, int mouse_y ) override;
102};
103
104}
length
Definition MRObjectDimensionsEnum.h:14
Definition MRChangeXfAction.h:13
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
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:96
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:97
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)
Type
Definition MRHistoryAction.h:19
named object in the data model
Definition MRObject.h:60
Visual Object.
Definition MRVisualObject.h:131
represents a 3-dimentional float-typed vector
Definition MRDotNet/MRVector3.h:8
Definition MRCameraOrientationPlugin.h:7
MouseButton
Definition MRMouse.h:9
Definition MRColor.h:9
Definition MRViewerEventsListener.h:29