MeshLib Documentation
Loading...
Searching...
No Matches
MRObjectLabel.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRSymbolMeshFwd.h"
4#include "MRSymbolMesh.h"
5
7
8namespace MR
9{
10
11enum class MRSYMBOLMESH_CLASS LabelVisualizePropertyType
12{
17 _count [[maybe_unused]],
18};
19template <> struct IsVisualizeMaskEnum<LabelVisualizePropertyType> : std::true_type {};
20
25{
26public:
28
29 ObjectLabel( ObjectLabel&& ) noexcept = default;
30 ObjectLabel& operator = ( ObjectLabel&& ) noexcept = default;
31
32 constexpr static const char* TypeName() noexcept
33 {
34 return "ObjectLabel";
35 }
36 virtual const char* typeName() const override
37 {
38 return TypeName();
39 }
40
41 MRSYMBOLMESH_API virtual void applyScale( float scaleFactor ) override;
42
43 virtual bool hasVisualRepresentation() const override { return true; }
44
45 MRSYMBOLMESH_API virtual std::shared_ptr<Object> clone() const override;
46 MRSYMBOLMESH_API virtual std::shared_ptr<Object> shallowClone() const override;
47
49 MRSYMBOLMESH_API virtual void setFontHeight( float size );
51 float getFontHeight() const { return fontHeight_; }
52
55 const PositionedText& getLabel() const { return label_; }
56
58 MRSYMBOLMESH_API void setFontPath( const std::filesystem::path& pathToFont );
59 const std::filesystem::path& getFontPath() const { return pathToFont_; }
60
66 MRSYMBOLMESH_API void setPivotPoint( const Vector2f& pivotPoint );
67
69 const Vector2f& getPivotPoint() const { return pivotPoint_; }
70
72 const Vector2f& getPivotShift() const { return pivotShift_; }
73
75 MRSYMBOLMESH_API virtual void setLeaderLineWidth( float width );
77 float getLeaderLineWidth() const { return leaderLineWidth_; }
79 MRSYMBOLMESH_API virtual void setSourcePointSize( float size );
81 float getSourcePointSize() const { return sourcePointSize_; }
83 MRSYMBOLMESH_API virtual void setBackgroundPadding( float padding );
85 float getBackgroundPadding() const { return backgroundPadding_; }
86
88 MRSYMBOLMESH_API virtual void setSourcePointColor( const Color& color, ViewportId id = {} );
90 const Color& getSourcePointColor( ViewportId id = {} ) const
91 {
92 return sourcePointColor_.get( id );
93 }
95 MRSYMBOLMESH_API virtual void setLeaderLineColor( const Color& color, ViewportId id = {} );
97 const Color& getLeaderLineColor( ViewportId id = {} ) const
98 {
99 return leaderLineColor_.get( id );
100 }
102 MRSYMBOLMESH_API void setContourColor( const Color& color, ViewportId id = {} );
104 const Color& getContourColor( ViewportId id = {} ) const
105 {
106 return contourColor_.get( id );
107 }
108
111
114
117
120 {}
121
124 MRSYMBOLMESH_API virtual Box3f getWorldBox( ViewportId = {} ) const override;
125
128 const std::shared_ptr<Mesh>& labelRepresentingMesh() const { return mesh_; }
129
131 [[nodiscard]] MRSYMBOLMESH_API virtual size_t heapBytes() const override;
132
137
141
142protected:
144 std::filesystem::path pathToFont_;
145 Vector2f pivotPoint_;
146
148 float fontHeight_{ 25.0f };
150 float leaderLineWidth_{ 1.0f };
152 float sourcePointSize_{ 5.f };
154 float backgroundPadding_{ 8.f };
155
160
164
165 ObjectLabel( const ObjectLabel& other ) = default;
166
168 MRSYMBOLMESH_API virtual void swapBase_( Object& other ) override;
169
170 MRSYMBOLMESH_API virtual Box3f computeBoundingBox_() const override;
171
172 MRSYMBOLMESH_API virtual void serializeFields_( Json::Value& root ) const override;
173
174 MRSYMBOLMESH_API virtual void deserializeFields_( const Json::Value& root ) override;
175
176 MRSYMBOLMESH_API virtual void setupRenderObject_() const override;
177
179 MRSYMBOLMESH_API void setAllVisualizeProperties_( const AllVisualizeProperties& properties, std::size_t& pos ) override;
180
181private:
183 void setDefaultColors_();
184
186 void setDefaultSceneProperties_();
187
188 void updatePivotShift_() const;
189
190 mutable bool needRebuild_{ true };
191 mutable Vector2f pivotShift_;
192 mutable std::shared_ptr<Mesh> mesh_;
193 mutable Box3f meshBox_; // needed for pivot update
194};
195
196}
Contour
Definition MRObjectLabel.h:16
Background
Definition MRObjectLabel.h:15
SourcePoint
Definition MRObjectLabel.h:13
LeaderLine
Definition MRObjectLabel.h:14
#define MRSYMBOLMESH_API
Definition MRSymbolMeshFwd.h:11
#define MRSYMBOLMESH_CLASS
Definition MRSymbolMeshFwd.h:12
Definition MRVisualObject.h:67
Definition MRObjectLabel.h:25
Vector2f pivotPoint_
Definition MRObjectLabel.h:145
ObjectLabel(ObjectLabel &&) noexcept=default
virtual MRSYMBOLMESH_API void setSourcePointColorsForAllViewports(ViewportProperty< Color > val)
MRSYMBOLMESH_API const ViewportProperty< Color > & getSourcePointColorsForAllViewports() const
ViewportProperty< Color > contourColor_
Definition MRObjectLabel.h:163
virtual MRSYMBOLMESH_API void deserializeFields_(const Json::Value &root) override
virtual MRSYMBOLMESH_API Box3f getWorldBox(ViewportId={}) const override
const PositionedText & getLabel() const
Definition MRObjectLabel.h:55
MRSYMBOLMESH_API const ViewportProperty< Color > & getContourColorsForAllViewports() const
virtual MRSYMBOLMESH_API std::shared_ptr< Object > shallowClone() const override
ObjectLabel(ProtectedStruct, const ObjectLabel &obj)
Definition MRObjectLabel.h:119
const std::filesystem::path & getFontPath() const
Definition MRObjectLabel.h:59
const Vector2f & getPivotShift() const
get pivot shift (pivot point * text diagonal)
Definition MRObjectLabel.h:72
virtual MRSYMBOLMESH_API void setupRenderObject_() const override
const std::shared_ptr< Mesh > & labelRepresentingMesh() const
Definition MRObjectLabel.h:128
float getSourcePointSize() const
returns size of source point in pixels
Definition MRObjectLabel.h:81
MRSYMBOLMESH_API void setLabel(const PositionedText &label)
sets text and position of label
virtual MRSYMBOLMESH_API void setContourColorsForAllViewports(ViewportProperty< Color > val)
virtual MRSYMBOLMESH_API void swapBase_(Object &other) override
swaps this object with other
virtual MRSYMBOLMESH_API void setFontHeight(float size)
sets size of label font in pixels
ViewportMask sourcePoint_
Definition MRObjectLabel.h:156
const Vector2f & getPivotPoint() const
get pivot point
Definition MRObjectLabel.h:69
MRSYMBOLMESH_API AllVisualizeProperties getAllVisualizeProperties() const override
get all visualize properties masks
const Color & getLeaderLineColor(ViewportId id={}) const
return color of leader line
Definition MRObjectLabel.h:97
virtual const char * typeName() const override
Definition MRObjectLabel.h:36
virtual MRSYMBOLMESH_API void setLeaderLineColorsForAllViewports(ViewportProperty< Color > val)
virtual MRSYMBOLMESH_API void serializeFields_(Json::Value &root) const override
ViewportProperty< Color > leaderLineColor_
Definition MRObjectLabel.h:162
MRSYMBOLMESH_API void setFontPath(const std::filesystem::path &pathToFont)
sets path to font file
ViewportProperty< Color > sourcePointColor_
Definition MRObjectLabel.h:161
virtual MRSYMBOLMESH_API void setSourcePointColor(const Color &color, ViewportId id={})
sets color of source point
virtual MRSYMBOLMESH_API void setLeaderLineColor(const Color &color, ViewportId id={})
sets color of leader line
MRSYMBOLMESH_API void setAllVisualizeProperties_(const AllVisualizeProperties &properties, std::size_t &pos) override
set all visualize properties masks
float getBackgroundPadding() const
returns background padding in pixels
Definition MRObjectLabel.h:85
virtual MRSYMBOLMESH_API void setBackgroundPadding(float padding)
sets background padding in pixels
virtual MRSYMBOLMESH_API void setLeaderLineWidth(float width)
sets width of leader line in pixels
virtual MRSYMBOLMESH_API Box3f computeBoundingBox_() const override
MRSYMBOLMESH_API const ViewportProperty< Color > & getLeaderLineColorsForAllViewports() const
virtual MRSYMBOLMESH_API void applyScale(float scaleFactor) override
scale object size (all point positions)
MRSYMBOLMESH_API void setPivotPoint(const Vector2f &pivotPoint)
MRSYMBOLMESH_API void buildMeshFromText() const
float getLeaderLineWidth() const
returns width of leader line in pixels
Definition MRObjectLabel.h:77
ViewportMask background_
Definition MRObjectLabel.h:157
ObjectLabel(const ObjectLabel &other)=default
virtual MRSYMBOLMESH_API std::shared_ptr< Object > clone() const override
virtual bool hasVisualRepresentation() const override
does the object have any visual representation (visible points, triangles, edges, etc....
Definition MRObjectLabel.h:43
float getFontHeight() const
returns size of label font on screen in pixels
Definition MRObjectLabel.h:51
ViewportMask leaderLine_
Definition MRObjectLabel.h:159
virtual MRSYMBOLMESH_API size_t heapBytes() const override
returns the amount of memory this object occupies on heap
std::filesystem::path pathToFont_
Definition MRObjectLabel.h:144
MRSYMBOLMESH_API ObjectLabel()
MRSYMBOLMESH_API void setContourColor(const Color &color, ViewportId id={})
sets contour color
PositionedText label_
Definition MRObjectLabel.h:143
virtual MRSYMBOLMESH_API void setSourcePointSize(float size)
sets size of source point in pixels
const Color & getContourColor(ViewportId id={}) const
return contour color
Definition MRObjectLabel.h:104
ViewportMask contour_
Definition MRObjectLabel.h:158
const Color & getSourcePointColor(ViewportId id={}) const
returns color of source point
Definition MRObjectLabel.h:90
MRSYMBOLMESH_API const ViewportMask & getVisualizePropertyMask(AnyVisualizeMaskEnum type) const override
returns mask of viewports where given property is set
named object in the data model
Definition MRObject.h:60
Definition MRViewportId.h:16
stores mask of viewport unique identifiers
Definition MRViewportId.h:38
Definition MRViewportProperty.h:17
Visual Object.
Definition MRVisualObject.h:131
std::vector< ViewportMask > AllVisualizeProperties
Definition MRVisualObject.h:85
Definition MRCameraOrientationPlugin.h:8
Definition MRColor.h:9
Definition MRVisualObject.h:45
Definition MRObject.h:246
Definition MRPositionedText.h:9