ModraUp Ruby API Documentation Ruby API Reference

Class: Layout::Label

Inherits:
Layout::Entity show all

Overview

Annotation: Arrows, leader lines, and text. The arrow end can be attached to a model point in the viewport.

Examples:

label = Layout::Label.new("Cabinet door", Layout::Label::LEADER_LINE_TYPE_TWO_SEGMENT,
                          Geom::Point2d.new(2, 2), Geom::Point2d.new(4, 1),
                          Layout::FormattedText::ANCHOR_TYPE_CENTER_LEFT)

Constants # collapse

Layout::Label::LEADER_LINE_TYPE_SINGLE_SEGMENT

Single-segment leader line in LayOut.

Returns:

  • (Integer)
Note: ModraUp extension. Does not support this; an ArgumentError is thrown when used.

Examples:

Layout::Label::LEADER_LINE_TYPE_SINGLE_SEGMENT
Layout::Label::LEADER_LINE_TYPE_TWO_SEGMENT

A leader with two line segments.

Returns:

  • (Integer)

Examples:

Layout::Label::LEADER_LINE_TYPE_TWO_SEGMENT
Layout::Label::LEADER_LINE_TYPE_BEZIER

Curved leader line.

Returns:

  • (Integer)

Examples:

Layout::Label::LEADER_LINE_TYPE_BEZIER
Layout::Label::LEADER_LINE_TYPE_UNKNOWN

Unknown leader line type.

Returns:

  • (Integer)

Examples:

Layout::Label::LEADER_LINE_TYPE_UNKNOWN

Class Method Summary # collapse

Instance Method Summary # collapse

Inherited from Layout::Entity

Class Method Details

Layout::Label.new(text, leader_type, target_point, anchor_point, anchor_type) ⇒ Layout::LabelLayout::Label.new(text, leader_type, target_point, bounds) ⇒ Layout::Label

Create a leader. The arrowhead is at the target_point, and the text is anchored at the anchor_point (or the midpoint of the text box near the arrowhead); break points are automatically placed 5 mm above the anchor point on the same horizontal line toward the arrowhead direction.

Parameters:

  • text (String)
  • leader_type (Integer) LEADER_LINE_TYPE_TWO_SEGMENT or LEADER_LINE_TYPE_BEZIER
  • target_point (Geom::Point2d) Arrow position, sheet inches
  • anchor_point (Geom::Point2d) Leader attachment point on the text
  • anchor_type (Integer) Layout::FormattedText::ANCHOR_TYPE_*, used for compatibility but not utilized.
  • bounds (Geom::Bounds2d) Label text box

Returns:

  • (Layout::Label)

Raises:

  • [ArgumentError] Unsupported leader type
Note: ModraUp extension. Leaders are fixed as "arrow—kink—text," with the text position following the leader point.

Examples:

Layout::Label.new("Cabinet door", Layout::Label::LEADER_LINE_TYPE_TWO_SEGMENT,
                  Geom::Point2d.new(2, 2), Geom::Point2d.new(4, 1),
                  Layout::FormattedText::ANCHOR_TYPE_CENTER_LEFT)

Instance Method Details

label.connect(connection_point) ⇒ Layout::Label

Associate the arrow to a model point in the viewport, one step undo (takes effect upon addition if not already joined).

Parameters:

  • connection_point (Layout::ConnectionPoint)

Returns:

  • (Layout::Label) self

Raises:

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

Examples:

# label.connect(Layout::ConnectionPoint.new(front, door_corner))

label.disconnect ⇒ Layout::Label

Disconnect association, one step undo.

Returns:

  • (Layout::Label) self

Examples:

Layout::Label.new("A", Layout::Label::LEADER_LINE_TYPE_TWO_SEGMENT, Geom::Point2d.new(2, 2),
                  Geom::Point2d.new(4, 1), 0).disconnect

label.text ⇒ Layout::FormattedText

Duplicates the text of the leader; changes to the duplicate do not affect the leader.

Returns:

  • (Layout::FormattedText)

Examples:

Layout::Label.new("A", Layout::Label::LEADER_LINE_TYPE_TWO_SEGMENT, Geom::Point2d.new(2, 2),
                  Geom::Point2d.new(4, 1), 0).text.plain_text  #=> "A"

label.text = formatted_text

Render the label text as plain text, and undo the last step.

Parameters:

  • formatted_text (Layout::FormattedText, String)

Returns:

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

Examples:

l = Layout::Label.new("A", Layout::Label::LEADER_LINE_TYPE_TWO_SEGMENT, Geom::Point2d.new(2, 2),
                      Geom::Point2d.new(4, 1), 0)
l.text = "B"

label.leader_line_type ⇒ Integer

Leader line type.

Returns:

  • (Integer)

Examples:

Layout::Label.new("A", Layout::Label::LEADER_LINE_TYPE_BEZIER, Geom::Point2d.new(2, 2),
                  Geom::Point2d.new(4, 1), 0).leader_line_type

label.leader_line_type = type

Change the leader line type, one step undo.

Parameters:

  • type (Integer) LEADER_LINE_TYPE_TWO_SEGMENT or LEADER_LINE_TYPE_BEZIER

Returns:

  • (Integer)

Raises:

  • [ArgumentError] Unsupported type

Examples:

l = Layout::Label.new("A", Layout::Label::LEADER_LINE_TYPE_TWO_SEGMENT, Geom::Point2d.new(2, 2),
                      Geom::Point2d.new(4, 1), 0)
l.leader_line_type = Layout::Label::LEADER_LINE_TYPE_BEZIER