ModraUp Ruby API Documentation Ruby API Reference

Class: Layout::LinearDimension

Inherits:
Layout::Entity show all

Overview

Linear dimensions. Once associated with a viewport model point (#connect), the value displays in model units and updates automatically with viewport movement, scaling, and model changes; unassociated dimensions show the paper length in millimeters, which can be converted using #scale=.

Examples:

Attach to component's two corner points

# front is a parallel-projection viewport in the document, and box is a component in that view
# a = front.model_to_paper_point(p1); b = front.model_to_paper_point(p2)
# dim = Layout::LinearDimension.new(a, b, -8.mm)
# dim.connect(Layout::ConnectionPoint.new(front, p1), Layout::ConnectionPoint.new(front, p2))
# doc.add_entity(dim, doc.layers.active, page)

Constants # collapse

Layout::LinearDimension::DIMENSION_LINE_ALIGNED

The dimension line is parallel to the line connecting two points.

Returns:

  • (Integer)

Examples:

Layout::LinearDimension::DIMENSION_LINE_ALIGNED
Layout::LinearDimension::DIMENSION_LINE_VERTICAL

Vertical dimension.

Returns:

  • (Integer)

Examples:

Layout::LinearDimension::DIMENSION_LINE_VERTICAL
Layout::LinearDimension::DIMENSION_LINE_HORIZONTAL

Horizontal dimension.

Returns:

  • (Integer)

Examples:

Layout::LinearDimension::DIMENSION_LINE_HORIZONTAL

Class Method Summary # collapse

Instance Method Summary # collapse

Inherited from Layout::Entity

Class Method Details

Layout::LinearDimension.new(start_point, end_point, height) ⇒ Layout::LinearDimension

Create a linear dimension. height is the distance from the dimension line to the start point, with a positive value on the left side of the direction from start to end (above the dimension line when annotated from left to right).

Parameters:

  • start_point (Geom::Point2d) inch on the drawing sheet
  • end_point (Geom::Point2d)
  • height (Length, Numeric) inch

Returns:

  • (Layout::LinearDimension)

Examples:

Below 8 mm

Layout::LinearDimension.new(Geom::Point2d.new(1, 2), Geom::Point2d.new(3, 2), -8.mm)

Layout::LinearDimension.create_chain(points, height, mode: :continuous, orientation: Layout::LinearDimension::DIMENSION_LINE_HORIZONTAL) ⇒ Array<Layout::LinearDimension>

A chain of horizontally or vertically aligned dimensions (not yet added to the document).:continuous segments are connected end-to-end sharing a single dimension line;:baseline all segments start from the first point and incrementally offset vertically (offset 7 mm). The first segment is the baseline, and:height determines the position of the dimension line. After adding to the document, the entire chain aligns to the baseline, and when associated with a viewport, it updates with the viewport.

Parameters:

  • points (Array<Geom::Point2d>) At least two points, drawing sheet inches
  • height (Length, Numeric) The distance from the dimension line to the start of the first segment, symbols the same as #initialize.
  • mode (Symbol) :continuous or :baseline
  • orientation (Integer) DIMENSION_LINE_HORIZONTAL or DIMENSION_LINE_VERTICAL

Returns:

  • (Array<Layout::LinearDimension>) Create one per segment, in order.

Raises:

  • [ArgumentError] Less than two points, direction is not horizontal or vertical, unknown keyword
Note: ModraUp extension.

Examples:

Create a chain of four consecutive linear dimensions.

pts = [0, 1, 2.5, 4].map { |x| Geom::Point2d.new(1 + x, 3) }
dims = Layout::LinearDimension.create_chain(pts, -0.3)
# dims.each { |d| doc.add_entity(d, doc.layers.active, page) }

Instance Method Details

dimension.connect(start_connection, end_connection) ⇒ Layout::LinearDimension

Connect two endpoints to model points in the viewport, one step undoable (takes effect upon addition if not already added). If one end is nil, it is not associated. During writing, recalculate the paper position and value based on the viewport.

Parameters:

  • start_connection (Layout::ConnectionPoint, nil)
  • end_connection (Layout::ConnectionPoint, nil)

Returns:

  • (Layout::LinearDimension) self

Raises:

  • [ArgumentError] The viewport has not been added to the document or is a perspective viewport.

Examples:

# dim.connect(Layout::ConnectionPoint.new(front, p1), Layout::ConnectionPoint.new(front, p2))

dimension.disconnect ⇒ Layout::LinearDimension

Disconnect the association, leaving the dimension in its current position; a single undo step.

Returns:

  • (Layout::LinearDimension) self

Examples:

Layout::LinearDimension.new(Geom::Point2d.new(1, 2), Geom::Point2d.new(3, 2), 0.3).disconnect

dimension.start_connection_point ⇒ Layout::ConnectionPoint, nil

The connection point at the start; nil if unconnected or the viewport has been deleted.

Returns:

  • (Layout::ConnectionPoint, nil)

Examples:

Layout::LinearDimension.new(Geom::Point2d.new(1, 2), Geom::Point2d.new(3, 2), 0.3).start_connection_point  #=> nil

dimension.end_connection_point ⇒ Layout::ConnectionPoint, nil

The connection point at the end.

Returns:

  • (Layout::ConnectionPoint, nil)

Examples:

Layout::LinearDimension.new(Geom::Point2d.new(1, 2), Geom::Point2d.new(3, 2), 0.3).end_connection_point

dimension.start_extent_point ⇒ Geom::Point2d

The measured start extent point (paper inches).

Returns:

  • (Geom::Point2d)

Examples:

Layout::LinearDimension.new(Geom::Point2d.new(1, 2), Geom::Point2d.new(3, 2), 0.3).start_extent_point

dimension.end_extent_point ⇒ Geom::Point2d

The end extent point of the measured feature.

Returns:

  • (Geom::Point2d)

Examples:

Layout::LinearDimension.new(Geom::Point2d.new(1, 2), Geom::Point2d.new(3, 2), 0.3).end_extent_point

dimension.start_extent_point = point

Move the start extent point one step back, undoing the change. Like dragging in the interface: the associated endpoint will be disassociated.

Parameters:

  • point (Geom::Point2d)

Returns:

  • (Geom::Point2d)

Examples:

d = Layout::LinearDimension.new(Geom::Point2d.new(1, 2), Geom::Point2d.new(3, 2), 0.3)
d.start_extent_point = Geom::Point2d.new(0.5, 2)

dimension.end_extent_point = point

Move the end point, one step undo.

Parameters:

  • point (Geom::Point2d)

Returns:

  • (Geom::Point2d)

Examples:

d = Layout::LinearDimension.new(Geom::Point2d.new(1, 2), Geom::Point2d.new(3, 2), 0.3)
d.end_extent_point = Geom::Point2d.new(4, 2)

dimension.start_offset_point ⇒ Geom::Point2d

The start of the dimension line.

Returns:

  • (Geom::Point2d)

Examples:

Layout::LinearDimension.new(Geom::Point2d.new(1, 2), Geom::Point2d.new(3, 2), 0.3).start_offset_point

dimension.end_offset_point ⇒ Geom::Point2d

The end of the dimension line.

Returns:

  • (Geom::Point2d)

Examples:

Layout::LinearDimension.new(Geom::Point2d.new(1, 2), Geom::Point2d.new(3, 2), 0.3).end_offset_point

dimension.text ⇒ Layout::FormattedText

The copy of the displayed dimension text (formatted in model units for model length when associated), located at the center of the dimension; this copy does not affect the dimension.

Returns:

  • (Layout::FormattedText)

Examples:

Layout::LinearDimension.new(Geom::Point2d.new(1, 2), Geom::Point2d.new(3, 2), 0.3).text.plain_text

dimension.text = formatted_text

Customize the text (use plain text), where <> represents the measurement value, and allow one step of undo.

Parameters:

  • formatted_text (Layout::FormattedText, String)

Returns:

  • (Layout::FormattedText, String)
Note: ModraUp extension. Also accepts strings.

Examples:

d = Layout::LinearDimension.new(Geom::Point2d.new(1, 2), Geom::Point2d.new(3, 2), 0.3)
d.text = "L=<>"

dimension.custom_text? ⇒ Boolean

Whether to use custom text.

Returns:

  • (Boolean)

Examples:

Layout::LinearDimension.new(Geom::Point2d.new(1, 2), Geom::Point2d.new(3, 2), 0.3).custom_text?  #=> false

dimension.custom_text = custom

Pass false to restore the measurement value display; use #text= to set custom text.

Parameters:

  • custom (Boolean)

Returns:

  • (Boolean)

Examples:

d = Layout::LinearDimension.new(Geom::Point2d.new(1, 2), Geom::Point2d.new(3, 2), 0.3)
d.custom_text = false

dimension.scale ⇒ Float

Scale factor (ratio). Automatically equals the viewport scale when associated.

Returns:

  • (Float)

Examples:

Layout::LinearDimension.new(Geom::Point2d.new(1, 2), Geom::Point2d.new(3, 2), 0.3).scale  #=> 1.0

dimension.scale = ratio

Set the scale factor for unassociated dimensions, undoing the last change.

Parameters:

  • ratio (Numeric)

Returns:

  • (Numeric)

Raises:

  • [ArgumentError] The dimension is associated (scale derived from the viewport).

Examples:

1:20

d = Layout::LinearDimension.new(Geom::Point2d.new(1, 2), Geom::Point2d.new(3, 2), 0.3)
d.scale = 1.0 / 20

dimension.auto_scale? ⇒ Boolean

Is the scale automatically derived from the associated viewport.

Returns:

  • (Boolean)

Examples:

Layout::LinearDimension.new(Geom::Point2d.new(1, 2), Geom::Point2d.new(3, 2), 0.3).auto_scale?  #=> false

dimension.orientation ⇒ Integer

Orientation: DIMENSION_LINE_ALIGNED, DIMENSION_LINE_HORIZONTAL, or DIMENSION_LINE_VERTICAL.

Returns:

  • (Integer)
Note: ModraUp extension.

Examples:

Layout::LinearDimension.new(Geom::Point2d.new(1, 2), Geom::Point2d.new(3, 2), 0.3).orientation

dimension.orientation = orientation

Set the orientation, one step in the undo.

Parameters:

  • orientation (Integer)

Returns:

  • (Integer)

Raises:

  • [ArgumentError] Unknown constant
Note: ModraUp extension.

Examples:

d = Layout::LinearDimension.new(Geom::Point2d.new(1, 2), Geom::Point2d.new(3, 3), 0.3)
d.orientation = Layout::LinearDimension::DIMENSION_LINE_HORIZONTAL

dimension.precision ⇒ Integer

Decimal places; -1 follows the model's setting.

Returns:

  • (Integer)
Note: ModraUp extension.

Examples:

Layout::LinearDimension.new(Geom::Point2d.new(1, 2), Geom::Point2d.new(3, 2), 0.3).precision  #=> -1

dimension.precision = digits

Set the decimal precision, with one step in undo.

Parameters:

  • digits (Integer) -1 (follow model) or 0~3

Returns:

  • (Integer)

Raises:

  • [ArgumentError] Out of range
Note: ModraUp extension.

Examples:

d = Layout::LinearDimension.new(Geom::Point2d.new(1, 2), Geom::Point2d.new(3, 2), 0.3)
d.precision = 0

dimension.chain_mode ⇒ Symbol, nil

The group type: :continuous, :baseline, or nil if not grouped.

Returns:

  • (Symbol, nil)
Note: ModraUp extension.

Examples:

Layout::LinearDimension.new(Geom::Point2d.new(1, 2), Geom::Point2d.new(3, 2), 0.3).chain_mode  #=> nil

dimension.chain_members ⇒ Array<Layout::LinearDimension>

All dimensions in the same group (including itself), in the order defined within the group; an empty array if not grouped or not added to the document.

Returns:

  • (Array<Layout::LinearDimension>)
Note: ModraUp extension.

Examples:

Layout::LinearDimension.new(Geom::Point2d.new(1, 2), Geom::Point2d.new(3, 2), 0.3).chain_members  #=> []