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"
7#include "MRViewer/MRGladGlfw.h"
8#include <unordered_map>
12#include "MRMesh/MRMesh.h"
13#include "MRMesh/MRHeapBytes.h"
14
15namespace MR
16{
19
20
23class MRVIEWER_CLASS BoundarySelectionWidget : public MultiListener<
24 MouseDownListener,
25 MouseMoveListener>
26{
27public:
28
41
42 using BoundarySelectionWidgetCallBack = std::function<void( std::shared_ptr<const MR::ObjectMeshHolder> )>;
43 using BoundarySelectionWidgetChecker = std::function<bool( std::shared_ptr<const MR::ObjectMeshHolder> )>;
44
45 using HolesOnObject = std::vector<MR::EdgeId>;
46 using PerObjectHoles = std::unordered_map <std::shared_ptr<MR::ObjectMeshHolder>, HolesOnObject>;
47 using PerObjectHolesPolylines = std::unordered_map <std::shared_ptr<MR::ObjectMeshHolder>, std::vector<AncillaryLines>>;
48 using PerObjectMeshChangedSignals = std::unordered_map < std::shared_ptr<MR::ObjectMeshHolder>, boost::signals2::scoped_connection>;
49
50
52 MRVIEWER_API void enable( bool isEnabled );
53
59 MRVIEWER_API void create(
60 BoundarySelectionWidgetCallBack onBoundarySelected,
61 BoundarySelectionWidgetChecker isObjectValidToPick
62 );
63
66
68 MRVIEWER_API void reset();
69
71 MRVIEWER_API bool selectHole( std::shared_ptr<MR::ObjectMeshHolder> object, int index );
72
74 MRVIEWER_API void clear();
75
77 MRVIEWER_API std::pair< std::shared_ptr<MR::ObjectMeshHolder>, EdgeId > getSelectHole() const;
78
80 MRVIEWER_API std::vector<MR::Vector3f> getPointsForSelectedHole() const;
81
84private:
85
86 float mouseAccuracy_{ 5.5f };
87
88 bool isSelectorActive_ = false;
89
90 PerObjectHoles holes_;
91 PerObjectHolesPolylines holeLines_;
92 PerObjectMeshChangedSignals onMeshChangedSignals_;
93
94 MRVIEWER_API bool onMouseDown_( MouseButton button, int modifier ) override;
95 MRVIEWER_API bool onMouseMove_( int mouse_x, int mouse_y ) override;
96
98 AncillaryLines createAncillaryLines_( std::shared_ptr<ObjectMeshHolder>& obj, MR::EdgeId hole );
99
101 std::shared_ptr<MR::Polyline3> getHoleBorder_( const std::shared_ptr<ObjectMeshHolder> obj, EdgeId initEdge );
102
105 std::pair<std::shared_ptr<MR::ObjectMeshHolder>, HoleEdgePoint> getHoverdHole_();
106
108 bool selectHole_( std::shared_ptr<ObjectMeshHolder> object, int index, bool writeHistory = true );
109
111 bool updateHole_( std::shared_ptr<MR::ObjectMeshHolder> object, int index, MR::Color color, float lineWidth );
112
113
114 enum class ActionType {
115 SelectHole,
116 HoverHole
117 };
118
120 bool actionByPick_( ActionType actionType );
121
123 BoundarySelectionWidgetCallBack onBoundarySelected_;
124 BoundarySelectionWidgetChecker isObjectValidToPick_;
125
127 std::shared_ptr<MR::ObjectMeshHolder> selectedHoleObject_;
128 int selectedHoleIndex_;
129
131 std::shared_ptr<MR::ObjectMeshHolder> hoveredHoleObject_;
132 int hoveredHoleIndex_;
133
135 bool isSelectedAndHoveredTheSame_();
136
138 bool hoverHole_( std::shared_ptr<MR::ObjectMeshHolder> object, int index );
139
141 void calculateHoles_();
142
144};
145
147{
148public:
149 ChangeBoundarySelectionHistoryAction( std::string name, BoundarySelectionWidget& widget, std::shared_ptr<ObjectMeshHolder> object, int index );
150
151public:
153 [[nodiscard]] std::string name() const override { return name_; }
154
155 void action( Type type ) override;
156
157 [[nodiscard]] size_t heapBytes() const override;
158
159private:
160 std::string name_;
162 std::shared_ptr<ObjectMeshHolder> prevSelectedHoleObject_;
163 std::shared_ptr<ObjectMeshHolder> nextSelectedHoleObject_;
164 int prevSelectedHoleIndex_;
165 int nextSelectedHoleIndex_;
166};
167
168}
Definition MRMeshBoundarySelectionWidget.h:26
static constexpr Color green() noexcept
Definition MRColor.h:32
float ordinaryLineWidth
Definition MRMeshBoundarySelectionWidget.h:32
MouseButton
Definition MRMouse.h:13
friend class ChangeBoundarySelectionHistoryAction
Definition MRMeshBoundarySelectionWidget.h:143
static constexpr Color purple() noexcept
Definition MRColor.h:36
void create(BoundarySelectionWidgetCallBack onBoundarySelected, BoundarySelectionWidgetChecker isObjectValidToPick)
std::function< bool(std::shared_ptr< const MR::ObjectMeshHolder >)> BoundarySelectionWidgetChecker
Definition MRMeshBoundarySelectionWidget.h:43
std::unordered_map< std::shared_ptr< MR::ObjectMeshHolder >, boost::signals2::scoped_connection > PerObjectMeshChangedSignals
Definition MRMeshBoundarySelectionWidget.h:48
std::unordered_map< std::shared_ptr< MR::ObjectMeshHolder >, std::vector< AncillaryLines > > PerObjectHolesPolylines
Definition MRMeshBoundarySelectionWidget.h:47
bool selectHole(std::shared_ptr< MR::ObjectMeshHolder > object, int index)
select one of the holes. Return true on success.
MR::Color hoveredColor
Definition MRMeshBoundarySelectionWidget.h:34
void enable(bool isEnabled)
enable or disable widget
std::vector< MR::Vector3f > getPointsForSelectedHole() const
collect and return vector of points ( verts coord ) for all edges in selected mesh boundary
BoundarySelectionWidgetParams params
configuration params
Definition MRMeshBoundarySelectionWidget.h:83
MR::Color ordinaryColor
Definition MRMeshBoundarySelectionWidget.h:31
void action(Type type) override
This function is called on history action (undo, redo, etc.)
std::string name() const override
HistoryAction.
Definition MRMeshBoundarySelectionWidget.h:153
std::function< void(std::shared_ptr< const MR::ObjectMeshHolder >)> BoundarySelectionWidgetCallBack
Definition MRMeshBoundarySelectionWidget.h:42
std::vector< MR::EdgeId > HolesOnObject
Definition MRMeshBoundarySelectionWidget.h:45
MR::Color selectedColor
Definition MRMeshBoundarySelectionWidget.h:37
static constexpr Color gray() noexcept
Definition MRColor.h:30
std::unordered_map< std::shared_ptr< MR::ObjectMeshHolder >, HolesOnObject > PerObjectHoles
Definition MRMeshBoundarySelectionWidget.h:46
ChangeBoundarySelectionHistoryAction(std::string name, BoundarySelectionWidget &widget, std::shared_ptr< ObjectMeshHolder > object, int index)
Type
Definition MRHistoryAction.h:27
void clear()
clear selection
float selectedLineWidth
Definition MRMeshBoundarySelectionWidget.h:38
HistoryAction()=default
explicitly define ctors to avoid warning C5267: definition of implicit copy constructor is deprecated...
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...
float hoveredLineWidth
Definition MRMeshBoundarySelectionWidget.h:35
size_t heapBytes() const override
returns the amount of memory this object occupies on heap
void onObjectChange_()
meshChangedSignal processor
void reset()
reset widget, clear internal variables and detach from signals.
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:29
Definition MRColor.h:12
Definition MRPickHoleBorderElement.h:14
Definition MRViewerEventsListener.h:32