MeasurementOperator
-
class
MeasurementOperator
: public HPS::Operator The MeasurementOperator class defines an operator which allows the user to measure geometry. This operator responds to both mouse and touch events. Five different measuring types are available: Point to Point, Line, Angle, Area and Distance. Whenever a measurement is inserted, an Event of type MeasurementEvent is injected. This event can be handled in order to to get details about the measurement (its type and value), which View it was inserted under, and what Segment it was placed on. This information, and specifically the segment in which the measurement is placed, can be used to customize the appearance of the measurement, to delete it, hide it, etc…
When vertex snapping is enabled, the measurement operator will try to snap to vertices close to the location that was clicked / touched. The value of the proximity snapping is expressed in centimeter. Snapping is not taken into consideration when placing Distance measurements.
If hinting is turned on, which it is by default, the operator will give the user feedback on what would be measured if a click were to happen at the current position. This feedback is given in the form of markers of various shapes. By default, an X means that the clicking the current point will not yield a measurement point. This can happen if the click happens off the geometry or if the current point would otherwise be invalid (for example, if the point would not be on the same plane as the other points which describe an area measurement). When vertex snapping is enabled, a square denotes the position the measurement point would snap to. Finally, a circle indicates that the current selection is valid but would not be snapped to a vertex. The look of these hinting geometry can be changed at anytime by editing the attributes found in their owning segments. The segments can be obtained through a call to GetHintSegment Hinting geometry is not enabled for Distance measurement, since the individual points picked are not relevant in this mode.
The number of decimal place shown in measurement labels can be changed through the SetPrecision function, and defaults to 2.
When working with a CADModel, the CADModel can be passed to this operator through the SetCADModel function. Setting a CADModel allows the operator to detect the unit of measurements used in the loaded file, which will be displayed when inserting measurement labels. When a CADModel is not set, measurements are considered unit-less.
While inserting a measurement, the last point inserted can be undone by pressing CTRL+Z. Note that in order to delete a single measurement that was already inserted, you should delete its associate segment, which can be obtained by intercepting MeasurementEvent events. Deleting all measurements at once can be easily done through the DeleteAllMeasurements function.
Notes about specific measurement types:
- Line Measurements Lines are measured as points are picked. An arbitrary number of points describing a line can be picked. To signal that you are done describing a line, either select the last point inserted, or double click/tap anywhere in the scene The position of the label for Line Measurement can be chosen through the SetLineMeasurementPosition.
- Area Measurements Placing at least three points is required when measuring an area. All points placed should be co-planar. After the third point has been inserted, attempting to insert a point that does not lie on the same plane will result in a warning, and the operator will discard this point. To signal that you are done inserting points for the area measurement, either select the first point inserted, or double click/tap anywhere in the scene.
- Distance Measurements The distance measurement finds the shortest distance between two objects. The two objects in question can be either individual faceted Entities (shells, polygons, meshes, etc…) or Bodies. This setting can be controlled through the SetDistanceMeasurementReference function. When Bodies are selected as the reference, is a CADModel is not associated with this operator, Segments will be used instead. Note that when comparing whole bodies it might take a noticeable amount of time for the operator to complete the calculation.
Public Types
-
enum class
DistanceMeasurementReference
Values:
-
enumerator
Entity
When measuring distance, only the specific entity selected will be considered.
-
enumerator
Body
When measuring distance, all faceted entities belonging to the selected body will be considered.
-
enumerator
-
enum class
LineMeasurementPosition
Values:
-
enumerator
LastPoint
Measurement text should be at the last selected point.
-
enumerator
FirstPoint
Measurement text should be at the first selected point.
-
enumerator
MidPoint
Measurement text should be at the mid-point of the line.
-
enumerator
-
enum class
MeasurementType
Values:
-
enumerator
PointToPoint
Measure the distance between two points.
-
enumerator
Line
Measure the length of a series of lines.
-
enumerator
Angle
Measure the angle between two lines.
-
enumerator
Area
Measure the area of a polygon on a plane.
-
enumerator
Distance
Measure the shortest distance between two objects.
-
enumerator
-
enum class
SelectionHint
Values:
-
enumerator
Snapped
If vertex snapping is enabled, hint goemetry is rendered over the closest vertex within the snapping proximity supplied to SetVertexSnapping.
-
enumerator
Valid
Hint goemetry is rendered under the mouse cursor indicating that a valid measurement point could be inserted at the underlying position. If vertex snapping is enabled this also indicates that the current position is outside the proximity specified to SetVertexSnapping.
-
enumerator
Invalid
Hint goemetry is rendered under the mouse cursor indicating that no valid measurement point could be inserted at the underlying position. This could be due to the cursor being over no visible geometry or the underlying position being invalid for usage with the current measurement type.
-
enumerator
Public Functions
-
void
DeleteAllMeasurements
() Deletes all inserted measurements.
-
inline DistanceMeasurementReference
GetDistanceMeasurementReference
() const Returns the reference used for distance measurements.
-
SegmentKey
GetHintSegment
(SelectionHint in_hint) Retrieves the segment key which contains the marker used for a given snapping hint. The appearance of the marker used for each hint type can be altered by modifying the attributes of the returned segment key.
Parameters: in_hint – Indicates the hint type to retrieve the parent segment for. which contains the marker used to indicate the snapping state given the mouse position.
-
inline LineMeasurementPosition
GetLineMeasurementPosition
() const Returns where the line measurement text will be positioned.
-
inline MeasurementType
GetMeasurementType
() const Returns the type of measurement the operator will insert the next time a measurement operation is started
-
size_t
GetPrecision
() const Returns the precision used in the measurement (number of digits after the decimal point)
-
bool
GetSelectionHinting
() Whether hint geometry is shown during point selection.
-
void
GetVertexSnapping
(bool &out_state, float &out_proximity) const Whether to snap to vertices during selection.
-
MeasurementOperator
(MouseButtons in_mouse_trigger = MouseButtons::ButtonLeft(), ModifierKeys in_modifier_trigger = ModifierKeys())
-
virtual bool
OnKeyDown
(KeyboardState const &in_state) override This function is called whenever HPS receives a KeyboardState event that signals a button was pressed. This function is used to undo a measurement point when CTRL+Z is pressed
Parameters: in_state – A KeyboardState object describing the current keyboard state. Returns: true if the input event was handled, false otherwise.
-
virtual void
OnModelAttached
() override This function is called whenever a model is attached to the view that is attached to this operator. If no view is attached to this operator, this function will not be called.
-
virtual void
OnModelDetached
() override This function is called whenever a model is detached from the view that is attached to this operator. If no view is attached to this operator, this function will not be called.
-
virtual bool
OnMouseDown
(MouseState const &in_state) override This function is called whenever HPS receives a MouseEvent that signals a mouse button was pressed. This function starts the operator and records the position of the mouse click
Parameters: in_state – A MouseState object describing the current mouse state. Returns: true if the input event was handled, false otherwise.
-
virtual bool
OnMouseMove
(MouseState const &in_state) override This function is called whenever HPS receives a MouseEvent that signals the mouse moved This function shows a preview of what would be selected, taking into account vertex snapping
Parameters: in_state – A MouseState object describing the current mouse state. Returns: true if the input event was handled, false otherwise.
-
virtual bool
OnMouseUp
(MouseState const &in_state) override This function is called whenever HPS receives a MouseEvent that signals a mouse button was released. If the mouse position was the same as it was when the mouse button was pressed, a measurement point is inserted.
Parameters: in_state – A MouseState object describing the current mouse state. Returns: true if the input event was handled, false otherwise.
-
virtual bool
OnTouchDown
(TouchState const &in_state) override This function is called whenever HPS receives a TouchEvent that signals that the device was touched. This is the touch equivalent of OnMouseDown
Parameters: in_state – A TouchState object describing the current touch state. Returns: true if the input event was handled, false otherwise.
-
virtual bool
OnTouchMove
(TouchState const &in_state) override This function is called whenever HPS receives a TouchEvent that signals that a touch on the device has moved This is the touch equivalent of OnMouseMove
Parameters: in_state – A TouchState object describing the current touch state. Returns: true if the input event was handled, false otherwise.
-
virtual bool
OnTouchUp
(TouchState const &in_state) override This function is called whenever HPS receives a TouchEvent that signals that a touch on the device was released This is the touch equivalent of OnMouseUp
Parameters: in_state – A TouchState object describing the current touch state. Returns: true if the input event was handled, false otherwise.
-
virtual void
OnViewAttached
(HPS::View const &in_attached_view) override This function is called whenever a view is attached to this operator.
-
virtual void
OnViewDetached
(HPS::View const &in_detached_view) override This function is called whenever a view is detached from this operator.
-
inline void
SetDistanceMeasurementReference
(DistanceMeasurementReference in_reference)
-
inline void
SetLineMeasurementPosition
(LineMeasurementPosition in_position) Sets where to position line measurement text relative to the line.
-
void
SetMeasurementType
(MeasurementType in_measurement_type) Sets the type of measurement to insert. If a measurement of a different type is currently being inserted, that measurement will be deleted.
-
void
SetPrecision
(size_t in_precision) Changes the precision used in the measurement (number of digits after the decimal point) The operator might override this setting if increasing the precision is necessary in order not to display the measurement value as all zeros. Example: When precision is set to 2, and a distance measurement of 0.0012 is performed, the operator will display 3 digits after the decimal point (0.001) in order not to display a value of 0. Only affects future measurements.
-
void
SetSelectionHinting
(bool in_state) Whether to show hint geometry while moving the mouse over the model during point selection. This function is not available on mobile platforms as it requires hovering over geometry.
Parameters: in_state – Indicates whether to enable or disable visual selection hints.
-
void
SetVertexSnapping
(bool in_state, float in_proximity = 0.0f) Whether selections should snap to the closest vertex. This behavior is only relevant when selecting shells, meshes, lines, NURBS curves and polygons. If the selection cannot be snapped to a vertex, the measurement will be taken based on the actual selection point.
Parameters: - in_state – Indicates whether to enable or disable vertex snapping.
- in_proximity – The distance to which a vertex will snap. The value is specified in centimeters.
-
~MeasurementOperator
()
-
class
MeasurementEvent
: public HPS::Event Public Functions
-
inline virtual char const *
ClassName
() const override
-
inline virtual Event *
Clone
() const override Allocates and returns a copy of this MeasurementEvent.
Returns: A copy of this MeasurementEvent.
-
inline
MeasurementEvent
() The default constructor creates an empty MeasurementEvent object.
-
inline
MeasurementEvent
(Event const &in_event) This constructor converts an Event Object to a MeasurementEvent object.
Parameters: in_event – The Event Object to be converted.
-
inline
MeasurementEvent
(HPS::View const &in_view, HPS::SegmentKey const &in_segment_key, MeasurementOperator::MeasurementType in_measurement_type, float in_measurement_value)
-
~MeasurementEvent
()
Public Members
-
MeasurementOperator::MeasurementType
measurement_type
-
float
measurement_value
-
SegmentKey
segment_key
-
inline virtual char const *