MeshLib C++ Docs
Loading...
Searching...
No Matches
MRMeshBoundarySelectionWidget.h
Go to the documentation of this file.
1#pragma once
2
4#include "MRMesh/MRMeshFwd.h"
6#include "MRHistoryStore.h"
8#include <unordered_map>
12#include "MRMesh/MRMesh.h"
13
14namespace MR
15{
18
19
22class MRVIEWER_CLASS BoundarySelectionWidget : public MultiListener<
23 MouseDownListener,
24 MouseMoveListener>
25{
26public:
27
29
30 MR::Color ordinaryColor = MR::Color::gray();
31 float ordinaryLineWidth = 3;
32
33 MR::Color hoveredColor = MR::Color::green();
34 float hoveredLineWidth = 4;
35
36 MR::Color selectedColor = MR::Color::purple();
37 float selectedLineWidth = 3;
38
39 };
40
41 using BoundarySelectionWidgetCallBack = std::function<void( std::shared_ptr<const MR::ObjectMeshHolder> )>;
42 using BoundarySelectionWidgetChecker = std::function<bool( std::shared_ptr<const MR::ObjectMeshHolder> )>;
43
44 using HolesOnObject = std::vector<MR::EdgeId>;
45 using PerObjectHoles = std::unordered_map <std::shared_ptr<MR::ObjectMeshHolder>, HolesOnObject>;
46 using PerObjectHolesPolylines = std::unordered_map <std::shared_ptr<MR::ObjectMeshHolder>, std::vector<AncillaryLines>>;
47 using PerObjectMeshChangedSignals = std::unordered_map < std::shared_ptr<MR::ObjectMeshHolder>, boost::signals2::scoped_connection>;
48
49
51 MRVIEWER_API void enable( bool isEnabled );
52
58 MRVIEWER_API void create(
59 BoundarySelectionWidgetCallBack onBoundarySelected,
60 BoundarySelectionWidgetChecker isObjectValidToPick
61 );
62
65
67 MRVIEWER_API void reset();
68
70 MRVIEWER_API bool selectHole( std::shared_ptr<MR::ObjectMeshHolder> object, int index );
71
73 MRVIEWER_API void clear();
74
76 MRVIEWER_API std::pair< std::shared_ptr<MR::ObjectMeshHolder>, EdgeId > getSelectHole() const;
77
79 MRVIEWER_API std::vector<MR::Vector3f> getPointsForSelectedHole() const;
80
83private:
84
85 float mouseAccuracy_{ 5.5f };
86
87 bool isSelectorActive_ = false;
88
89 PerObjectHoles holes_;
90 PerObjectHolesPolylines holeLines_;
91 PerObjectMeshChangedSignals onMeshChangedSignals_;
92
93 MRVIEWER_API bool onMouseDown_( MouseButton button, int modifier ) override;
94 MRVIEWER_API bool onMouseMove_( int mouse_x, int mouse_y ) override;
95
97 AncillaryLines createAncillaryLines_( std::shared_ptr<ObjectMeshHolder>& obj, MR::EdgeId hole );
98
100 std::shared_ptr<MR::Polyline3> getHoleBorder_( const std::shared_ptr<ObjectMeshHolder> obj, EdgeId initEdge );
101
104 std::pair<std::shared_ptr<MR::ObjectMeshHolder>, HoleEdgePoint> getHoverdHole_();
105
107 bool selectHole_( std::shared_ptr<ObjectMeshHolder> object, int index, bool writeHistory = true );
108
110 bool updateHole_( std::shared_ptr<MR::ObjectMeshHolder> object, int index, MR::Color color, float lineWidth );
111
112
113 enum class ActionType {
114 SelectHole,
115 HoverHole
116 };
117
119 bool actionByPick_( ActionType actionType );
120
122 BoundarySelectionWidgetCallBack onBoundarySelected_;
123 BoundarySelectionWidgetChecker isObjectValidToPick_;
124
126 std::shared_ptr<MR::ObjectMeshHolder> selectedHoleObject_;
127 int selectedHoleIndex_;
128
130 std::shared_ptr<MR::ObjectMeshHolder> hoveredHoleObject_;
131 int hoveredHoleIndex_;
132
134 bool isSelectedAndHoveredTheSame_();
135
137 bool hoverHole_( std::shared_ptr<MR::ObjectMeshHolder> object, int index );
138
140 void calculateHoles_();
141
143};
144
146{
147public:
148 ChangeBoundarySelectionHistoryAction( std::string name, BoundarySelectionWidget& widget, std::shared_ptr<ObjectMeshHolder> object, int index );
149
150public:
152 [[nodiscard]] std::string name() const override { return name_; }
153
154 void action( Type type ) override;
155
156 [[nodiscard]] size_t heapBytes() const override;
157
158private:
159 std::string name_;
161 std::shared_ptr<ObjectMeshHolder> prevSelectedHoleObject_;
162 std::shared_ptr<ObjectMeshHolder> nextSelectedHoleObject_;
163 int prevSelectedHoleIndex_;
164 int nextSelectedHoleIndex_;
165};
166
167}
Definition MRMeshBoundarySelectionWidget.h:25
Definition MRMeshBoundarySelectionWidget.h:146
Definition MRHistoryAction.h:15
static constexpr Color green() noexcept
Definition MRColor.h:32
MouseButton
Definition MRMouse.h:12
MRVIEWER_API void enable(bool isEnabled)
enable or disable widget
static constexpr Color purple() noexcept
Definition MRColor.h:36
MRVIEWER_API void create(BoundarySelectionWidgetCallBack onBoundarySelected, BoundarySelectionWidgetChecker isObjectValidToPick)
std::function< bool(std::shared_ptr< const MR::ObjectMeshHolder >)> BoundarySelectionWidgetChecker
Definition MRMeshBoundarySelectionWidget.h:42
std::unordered_map< std::shared_ptr< MR::ObjectMeshHolder >, boost::signals2::scoped_connection > PerObjectMeshChangedSignals
Definition MRMeshBoundarySelectionWidget.h:47
std::unordered_map< std::shared_ptr< MR::ObjectMeshHolder >, std::vector< AncillaryLines > > PerObjectHolesPolylines
Definition MRMeshBoundarySelectionWidget.h:46
MRVIEWER_API void clear()
clear selection
MRVIEWER_API std::vector< MR::Vector3f > getPointsForSelectedHole() const
collect and return vector of points ( verts coord ) for all edges in selected mesh boundary
MRVIEWER_API std::pair< std::shared_ptr< MR::ObjectMeshHolder >, EdgeId > getSelectHole() const
returns pair of selected hole ( in Edge representations) and objects on which particular hole is pres...
BoundarySelectionWidgetParams params
configuration params
Definition MRMeshBoundarySelectionWidget.h:82
void action(Type type) override
This function is called on history action (undo, redo, etc.)
std::string name() const override
HistoryAction.
Definition MRMeshBoundarySelectionWidget.h:152
std::function< void(std::shared_ptr< const MR::ObjectMeshHolder >)> BoundarySelectionWidgetCallBack
Definition MRMeshBoundarySelectionWidget.h:41
std::vector< MR::EdgeId > HolesOnObject
Definition MRMeshBoundarySelectionWidget.h:44
MRVIEWER_API void reset()
reset widget, clear internal variables and detach from signals.
static constexpr Color gray() noexcept
Definition MRColor.h:30
std::unordered_map< std::shared_ptr< MR::ObjectMeshHolder >, HolesOnObject > PerObjectHoles
Definition MRMeshBoundarySelectionWidget.h:45
ChangeBoundarySelectionHistoryAction(std::string name, BoundarySelectionWidget &widget, std::shared_ptr< ObjectMeshHolder > object, int index)
Type
Definition MRHistoryAction.h:22
MRVIEWER_API bool selectHole(std::shared_ptr< MR::ObjectMeshHolder > object, int index)
select one of the holes. Return true on success.
size_t heapBytes() const override
returns the amount of memory this object occupies on heap
void onObjectChange_()
meshChangedSignal processor
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
Helper class to manage ancillary visual lines used by plugins.
Definition MRAncillaryLines.h:16
Definition MRMeshBoundarySelectionWidget.h:28
Definition MRColor.h:12
Definition MRPickHoleBorderElement.h:14
Definition MRViewerEventsListener.h:32