ModraUp Ruby API Documentation Ruby API Reference

Class: Layout::PaperView

Inherits:
Object
  • Object
show all

Overview

The paper view callback receives the view: it handles the conversion between paper pixels and paper coordinates (in inches), picks objects, and draws a preview in draw(view). The drawing coordinates are in paper inches (e.g., 20.mm), with line widths, point sizes, and font sizes in pixels. The drawing methods only take effect within draw(view); otherwise, calling them has no effect.

Note: ModraUp extension.

Examples:

# In the tool draw callback:
# view.drawing_color = "blue"
# view.draw_line([10.mm, 10.mm], [50.mm, 10.mm])

Instance Method Summary # collapse

Instance Method Details

view.paper_point(x, y, snap = false) ⇒ Geom::Point2d

The pixel coordinates on the paper plane in inches, with the origin at the top-left corner of the paper, and y directed downward. When snap is true, it snaps to the endpoints, midpoints, intersections, centers, edge points of paper objects, and visible model lines within visible viewports (model lines in viewports must be generated in the background before snapping).

Parameters:

  • x (Numeric)
  • y (Numeric)
  • snap (Boolean)

Returns:

  • (Geom::Point2d)

Examples:

# def onLButtonDown(flags, x, y, view)
#   pt = view.paper_point(x, y, true)
# end

view.paper_to_screen(point) ⇒ Geom::Point2d

The pixel coordinates corresponding to the paper area on the paper view.

Parameters:

  • point (Geom::Point2d, Array(Length, Length)) inch on the drawing sheet

Returns:

  • (Geom::Point2d) pixels

Examples:

# px = view.paper_to_screen(Geom::Point2d.new(10.mm, 10.mm))

view.pick_entity(x, y) ⇒ Layout::Entity or nil

The editable PaperView object at the top layer in pixel coordinates (following the selection tool's point selection rules); objects on locked or hidden layers are not considered.

Parameters:

  • x (Numeric)
  • y (Numeric)

Returns:

  • (Layout::Entity, nil)

Examples:

# viewport = view.pick_entity(x, y)
# viewport = nil unless viewport.is_a?(Layout::SketchUpModel)

view.zoom ⇒ Float

Current Paper View Zoom: pixels per inch on the paper.

Returns:

  • (Float)

Examples:

# tolerance = 6 / view.zoom   # six pixels in paper-space inches

view.pixels_to_paper(pixels) ⇒ Length

The pixel length corresponding to the paper length.

Parameters:

  • pixels (Numeric)

Returns:

  • (Length)

Examples:

# tolerance = view.pixels_to_paper(6)

view.invalidate ⇒ Layout::PaperView

Request redrawing the tool preview (call draw(view) later).

Returns:

  • (Layout::PaperView)

Examples:

# def onMouseMove(flags, x, y, view)
#   @cursor = view.paper_point(x, y)
#   view.invalidate
# end

view.document ⇒ Layout::Document

The document containing the tools.

Returns:

  • (Layout::Document)

Examples:

# page = view.document.active_page

view.drawing_color = color

The color used for drawing after this.

Parameters:

  • color (ModraUp::Color, String, Array)

Returns:

  • (ModraUp::Color, String, Array)

Examples:

# view.drawing_color = "red"

view.line_width = pixels

The line width (pixels, unchanged with scaling) used for drawing.

Parameters:

  • pixels (Numeric)

Returns:

  • (Numeric)

Examples:

# view.line_width = 2

view.line_stipple = pattern

Sets the line pattern for subsequent drawing. Accepts the same values as ModraUp::View#line_stipple=, including "" for solid lines, ".", "-", "_", and "-.-".

Parameters:

  • pattern (String)

Returns:

  • (String)

Examples:

# view.line_stipple = "-"

view.draw(mode, points) ⇒ Layout::PaperViewview.draw(mode, point1, point2, ...) ⇒ Layout::PaperView

Draw using OpenGL methods: GL_POINTS, GL_LINES, GL_LINE_STRIP, GL_LINE_LOOP, GL_TRIANGLES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_QUADS, GL_QUAD_STRIP, GL_POLYGON. Points are in paper inches as Geom::Point2d or [x, y].

Parameters:

  • mode (Integer)
  • points (Array<Geom::Point2d>)

Returns:

  • (Layout::PaperView)

Raises:

  • [ArgumentError] Unknown mode

Examples:

# view.draw(GL_LINE_LOOP, [[10.mm, 10.mm], [60.mm, 10.mm], [60.mm, 40.mm]])

view.draw_line(point1, point2, ...) ⇒ Layout::PaperView

Draw a line segment between every two points (GL_LINES).

Parameters:

  • points (Array<Geom::Point2d>)

Returns:

  • (Layout::PaperView)

Examples:

# view.draw_line([10.mm, 10.mm], [50.mm, 10.mm])

view.draw_polyline(point1, point2, ...) ⇒ Layout::PaperView

Connect the points in sequence with a polyline (GL_LINE_STRIP).

Parameters:

  • points (Array<Geom::Point2d>)

Returns:

  • (Layout::PaperView)

Examples:

# view.draw_polyline([10.mm, 10.mm], [50.mm, 10.mm], [50.mm, 30.mm])

view.draw_points(points, size = 6, style = 3, color = "black") ⇒ Layout::PaperView

Draw point markers, size in pixels, and style as in ModraUp::View#draw_points (1 hollow square, 2 solid square, 3 plus, 4 times, 5 star, 6 hollow triangle, 7 solid triangle).

Parameters:

  • points (Array<Geom::Point2d>)
  • size (Integer)
  • style (Integer)
  • color (ModraUp::Color, String)

Returns:

  • (Layout::PaperView)

Examples:

# view.draw_points([[30.mm, 30.mm]], 10, 2, "red")

view.draw_text(point, text, options = {}) ⇒ Layout::PaperView

Write screen text at a paper view point. options: size (pixels, default 12), bold, align (TextAlignLeft / TextAlignCenter / TextAlignRight), color.

Parameters:

  • point (Geom::Point2d)
  • text (String)
  • options (Hash)

Returns:

  • (Layout::PaperView)

Examples:

# view.draw_text([20.mm, 20.mm], "600", size: 14, color: "blue")