MeshLib C++ Docs
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 std::string getClassNameInPlural() const override { return "Distances"; }
26
27 MRMESH_API std::shared_ptr<Object> clone() const override;
28 MRMESH_API std::shared_ptr<Object> shallowClone() const override;
29
30 // Get the starting point in world coordinates.
31 [[nodiscard]] MRMESH_API Vector3f getWorldPoint() const;
32 // Get the starting point in local coordinates.
33 [[nodiscard]] MRMESH_API Vector3f getLocalPoint() const;
34
35 // The delta from the starting point to the other point.
36 [[nodiscard]] MRMESH_API Vector3f getWorldDelta() const;
37 [[nodiscard]] MRMESH_API Vector3f getLocalDelta() const;
38
39 // Set the start point in the local coordinates.
40 MRMESH_API virtual void setLocalPoint( const MR::Vector3f& point );
41 // Set the delta vector in the local coordinates.
42 MRMESH_API virtual void setLocalDelta( const MR::Vector3f& delta );
43
44 // Whether the distance should be displayed as a negative one.
45 [[nodiscard]] MRMESH_API bool getDrawAsNegative() const;
46 MRMESH_API virtual void setDrawAsNegative( bool value );
47
48 enum class PerCoordDeltas
49 {
50 none, // Hide.
51 withSign, // Display as is.
52 absolute, // Display absolute values.
53 };
54 // Whether we should draw the individual X/Y/Z deltas in addition to the distance itself.
57
58 // Computes the distance value: `getWorldDelta().length() * (getDrawAsNegative() ? -1 : 1)`.
59 [[nodiscard]] MRMESH_API float computeDistance() const;
60
61 [[nodiscard]] MRMESH_API std::vector<std::string> getInfoLines() const override;
62
63protected:
65
66 MRMESH_API void swapBase_( Object& other ) override;
67
68 MRMESH_API void serializeFields_( Json::Value& root ) const override;
69 MRMESH_API void deserializeFields_( const Json::Value& root ) override;
70
71 MRMESH_API void setupRenderObject_() const override;
72
74
75private:
76 // Don't forget to add all the new fields to serialization.
77
78 // Whether the distance should be displayed as a negative one.
79 bool drawAsNegative_ = false;
80
81 // Whether we should draw the individual X/Y/Z deltas in addition to the distance itself.
82 PerCoordDeltas perCoordDeltas_ = PerCoordDeltas::none;
83
84 // The cached value for `computeDistance()`.
85 mutable std::optional<float> cachedValue_;
86};
87
88} // namespace MR
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:79
#define MRMESH_CLASS
Definition MRMesh/MRMeshFwd.h:83
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:49
std::string getClassNameInPlural() const override
return human readable name of subclass in plural form
Definition MRDistanceMeasurementObject.h:25
MRMESH_API Vector3f getWorldDelta() const
MRMESH_API void onWorldXfChanged_() override
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
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
Definition MRObject.h:253