MeshLib
 
Loading...
Searching...
No Matches
MRDistanceMeasurementObject.h
Go to the documentation of this file.
1#pragma once
2
4
5namespace MR
6{
7
8// Represents a distance measurement.
10{
11 // The xf encodes the distance: the origin is one point, and (1,0,0) is another.
12public:
14
16 DistanceMeasurementObject& operator=( DistanceMeasurementObject&& ) noexcept = default;
17
18 constexpr static const char* TypeName() noexcept { return "DistanceMeasurementObject"; }
19 const char* typeName() const override { return TypeName(); }
20
21 // For `std::make_shared()` in `clone()`.
23
24 std::string getClassName() const override { return "Distance"; }
25
26 MRMESH_API std::shared_ptr<Object> clone() const override;
27 MRMESH_API std::shared_ptr<Object> shallowClone() const override;
28
29 // Get the starting point in world coordinates.
30 [[nodiscard]] MRMESH_API Vector3f getWorldPoint() const;
31 // Get the starting point in local coordinates.
32 [[nodiscard]] MRMESH_API Vector3f getLocalPoint() const;
33
34 // The delta from the starting point to the other point.
35 [[nodiscard]] MRMESH_API Vector3f getWorldDelta() const;
36 [[nodiscard]] MRMESH_API Vector3f getLocalDelta() const;
37
38 // Set the start point in the local coordinates.
39 MRMESH_API virtual void setLocalPoint( const MR::Vector3f& point );
40 // Set the delta vector in the local coordinates.
41 MRMESH_API virtual void setLocalDelta( const MR::Vector3f& delta );
42
43 // Whether the distance should be displayed as a negative one.
44 [[nodiscard]] MRMESH_API bool getDrawAsNegative() const;
45 MRMESH_API virtual void setDrawAsNegative( bool value );
46
47 enum class PerCoordDeltas
48 {
49 none, // Hide.
50 withSign, // Display as is.
51 absolute, // Display absolute values.
52 };
53 // Whether we should draw the individual X/Y/Z deltas in addition to the distance itself.
56
57 // Computes the distance value: `getWorldDelta().length() * (getDrawAsNegative() ? -1 : 1)`.
58 [[nodiscard]] MRMESH_API float computeDistance() const;
59
60 [[nodiscard]] MRMESH_API std::vector<std::string> getInfoLines() const override;
61
62protected:
64
65 MRMESH_API void swapBase_( Object& other ) override;
66
67 MRMESH_API void serializeFields_( Json::Value& root ) const override;
68 MRMESH_API void deserializeFields_( const Json::Value& root ) override;
69
70 MRMESH_API void setupRenderObject_() const override;
71
73
74private:
75 // Don't forget to add all the new fields to serialization.
76
77 // Whether the distance should be displayed as a negative one.
78 bool drawAsNegative_ = false;
79
80 // Whether we should draw the individual X/Y/Z deltas in addition to the distance itself.
81 PerCoordDeltas perCoordDeltas_ = PerCoordDeltas::none;
82
83 // The cached value for `computeDistance()`.
84 mutable std::optional<float> cachedValue_;
85};
86
87} // namespace MR
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:46
#define MRMESH_CLASS
Definition MRMesh/MRMeshFwd.h:50
Definition MRDistanceMeasurementObject.h:10
virtual MRMESH_API void setLocalDelta(const MR::Vector3f &delta)
MRMESH_API Vector3f getLocalPoint() const
virtual MRMESH_API void setLocalPoint(const MR::Vector3f &point)
DistanceMeasurementObject(const DistanceMeasurementObject &other)=default
MRMESH_API void deserializeFields_(const Json::Value &root) override
MRMESH_API float computeDistance() const
DistanceMeasurementObject()
Definition MRDistanceMeasurementObject.h:13
MRMESH_API Vector3f getLocalDelta() const
MRMESH_API void serializeFields_(Json::Value &root) const override
const char * typeName() const override
Definition MRDistanceMeasurementObject.h:19
MRMESH_API void setupRenderObject_() const override
MRMESH_API Vector3f getWorldPoint() const
DistanceMeasurementObject(DistanceMeasurementObject &&) noexcept=default
MRMESH_API std::shared_ptr< Object > shallowClone() const override
DistanceMeasurementObject(ProtectedStruct, const DistanceMeasurementObject &obj)
Definition MRDistanceMeasurementObject.h:22
virtual MRMESH_API void setPerCoordDeltasMode(PerCoordDeltas mode)
MRMESH_API bool getDrawAsNegative() const
PerCoordDeltas
Definition MRDistanceMeasurementObject.h:48
MRMESH_API Vector3f getWorldDelta() const
MRMESH_API std::shared_ptr< Object > clone() const override
MRMESH_API PerCoordDeltas getPerCoordDeltasMode() const
virtual MRMESH_API void setDrawAsNegative(bool value)
MRMESH_API void swapBase_(Object &other) override
swaps this object with other
MRMESH_API void propagateWorldXfChangedSignal_() override
std::string getClassName() const override
return human readable name of subclass
Definition MRDistanceMeasurementObject.h:24
MRMESH_API std::vector< std::string > getInfoLines() const override
return several info lines that can better describe the object in the UI
Definition MRMeasurementObject.h:11
named object in the data model
Definition MRObject.h:60
represents a 3-dimentional float-typed vector
Definition MRDotNet/MRVector3.h:8
Definition MRCameraOrientationPlugin.h:7
Definition MRObject.h:246