ModraUp Ruby API Documentation Ruby API Reference

Class: ModraUp::PickHelper

Inherits:
Object
  • Object
show all

Overview

Viewport picking. Obtain it from ModraUp::View#pick_helper. The same instance will be reused. #do_pick / #window_pick / #boundingbox_pick record the pick results; #init / #test_point / #pick_segment only test the screen aperture, unrelated to those records.

Examples:

ph = ModraUp.active_model.active_view.pick_helper
ph.do_pick(10, 10)
path = ph.path_at(0)

Constants # collapse

ModraUp::PickHelper::PICK_INSIDE

#window_pick / #boundingbox_pick: The entity is completely inside the box.

Returns:

  • (Integer)

Examples:

ModraUp::PickHelper::PICK_INSIDE  #=> 0
ModraUp::PickHelper::PICK_CROSSING

#window_pick / #boundingbox_pick: The element intersects with the box to be picked.

Returns:

  • (Integer)

Examples:

ModraUp::PickHelper::PICK_CROSSING  #=> 1

Instance Method Summary # collapse

Instance Method Details

pick_helper.do_pick(x, y) ⇒ Integerpick_helper.do_pick(x, y, aperture) ⇒ Integer

Picks at screen coordinates and returns the number of pick records. The aperture argument gives the side length of a square. Omit it or pass 0 to use the viewport's default click tolerance. If an edge takes priority, the results also include the face under the cursor and its path. The first record remains the native selection tool's best hit.

Parameters:

  • x (Numeric)
  • y (Numeric)
  • aperture (Numeric)

Returns:

  • (Integer)

Examples:

n = ModraUp.active_model.active_view.pick_helper.do_pick(100, 80)

pick_helper.init(x, y) ⇒ pick_helperpick_helper.init(x, y, aperture) ⇒ pick_helper

Record the screen coordinates and square aperture for subsequent multiple #test_point calls (only pass model points). The aperture is the width and height of the square in pixels; omit or use 0 for the default 5. No need to call #do_pick first.

Parameters:

  • x (Numeric) X-coordinate on the screen
  • y (Numeric) viewport Y
  • aperture (Numeric) Square edge length, default 0 (picks 5 pixels).

Returns:

  • (ModraUp::PickHelper)

Examples:

ph = ModraUp.active_model.active_view.pick_helper
ph.init(100, 80)
ph.test_point([0, 0, 0])

pick_helper.test_point(point) ⇒ Booleanpick_helper.test_point(point, x, y) ⇒ Booleanpick_helper.test_point(point, x, y, aperture) ⇒ Boolean

The projected model point falls within a square centered at (x, y) with side length aperture. The single-parameter form must be initialized with #init; it is independent of the result of #do_pick.

Parameters:

  • point (Geom::Point3d, Array<Numeric>) model coordinates
  • x (Numeric) X-coordinate on the screen
  • y (Numeric) viewport Y
  • aperture (Numeric) Square edge length, default 0 (picks 5 pixels).

Returns:

  • (Boolean)

Examples:

view = ModraUp.active_model.active_view
ph = view.pick_helper
scr = view.screen_coords([0, 0, 0])
ph.init(scr.x, scr.y)
ph.test_point([0, 0, 0], scr.x, scr.y, 40)

pick_helper.count ⇒ Integer

The number of hits from the most recent #do_pick / #window_pick / #boundingbox_pick.

Returns:

  • (Integer)

Examples:

ph = ModraUp.active_model.active_view.pick_helper
ph.do_pick(10, 10)
ph.count

pick_helper.path_at(index) ⇒ Array, nil

The indexth pick path: from the current edit context group/instance to the leaf element. Out of bounds returns nil.

Parameters:

  • index (Integer)

Returns:

  • (Array<ModraUp::Drawingelement>, nil)

Examples:

ph = ModraUp.active_model.active_view.pick_helper
ph.do_pick(100, 80)
ph.path_at(0)

pick_helper.all_picked ⇒ Array

The first element of each pick path in the current editing context. Nested hits will repeat groups/instances.

Returns:

  • (Array<ModraUp::Drawingelement>)

Examples:

ph = ModraUp.active_model.active_view.pick_helper
ph.do_pick(10, 10)
ph.all_picked

pick_helper.best_picked ⇒ ModraUp::Drawingelement, nil

The frontmost hit in the current editing context (a group/instance or face/edge).

Returns:

  • (ModraUp::Drawingelement, nil)

Examples:

ph = ModraUp.active_model.active_view.pick_helper
ph.do_pick(10, 10)
ph.best_picked

pick_helper.view ⇒ ModraUp::View

The viewport to which this picker belongs.

Returns:

  • (ModraUp::View)

Examples:

ModraUp.active_model.active_view.pick_helper.view

pick_helper.leaf_at(index) ⇒ ModraUp::Drawingelement, nil

The leaf geometry at the index path (typically a face or edge).

Parameters:

  • index (Integer)

Returns:

  • (ModraUp::Drawingelement, nil)

Examples:

ph = ModraUp.active_model.active_view.pick_helper
ph.do_pick(100, 80)
ph.leaf_at(0)

pick_helper.element_at(index) ⇒ ModraUp::Drawingelement, nil

The indexth path in the current edit context, corresponding to the item picked by #all_picked.

Parameters:

  • index (Integer)

Returns:

  • (ModraUp::Drawingelement, nil)

Examples:

ph = ModraUp.active_model.active_view.pick_helper
ph.do_pick(100, 80)
ph.element_at(0)

pick_helper.depth_at(index) ⇒ Integer

The depth (path length) of the path at index index. Out of bounds returns 0.

Parameters:

  • index (Integer)

Returns:

  • (Integer)

Examples:

ph = ModraUp.active_model.active_view.pick_helper
ph.do_pick(100, 80)
ph.depth_at(0)

pick_helper.transformation_at(index) ⇒ Geom::Transformation, nil

Transform the leaf geometry coordinates to the current edit context's transformation. Out-of-bounds results in nil.

Parameters:

  • index (Integer)

Returns:

  • (Geom::Transformation, nil)

Examples:

ph = ModraUp.active_model.active_view.pick_helper
ph.do_pick(100, 80)
ph.transformation_at(0)

pick_helper.picked_face ⇒ ModraUp::Face, nil

The best face from the most recent #do_pick. Must precede a #do_pick. Returns the face corresponding to a #path_at record; returns nil if no face is hit.

Returns:

  • (ModraUp::Face, nil)

Examples:

ph = ModraUp.active_model.active_view.pick_helper
ph.do_pick(100, 80)
ph.picked_face

pick_helper.picked_edge ⇒ ModraUp::Edge, nil

The best edge from the most recent #do_pick. Must be called after #do_pick.

Returns:

  • (ModraUp::Edge, nil)

Examples:

ph = ModraUp.active_model.active_view.pick_helper
ph.do_pick(100, 80)
ph.picked_edge

pick_helper.picked_element ⇒ ModraUp::Drawingelement, nilpick_helper.picked_element(index) ⇒ ModraUp::Drawingelement, nil

The best non-face-non-edge element (usually a group or component instance). With index, it refers to the element at that position in the path.

Parameters:

  • index (Integer)

Returns:

  • (ModraUp::Drawingelement, nil)

Examples:

ph = ModraUp.active_model.active_view.pick_helper
ph.do_pick(100, 80)
ph.picked_element

pick_helper.pick_segment(points) ⇒ Integer, falsepick_helper.pick_segment(points, x, y) ⇒ Integer, falsepick_helper.pick_segment(points, x, y, aperture) ⇒ Integer, false

Determine if a pick segment falls within the screen aperture. Returns the index starting from 0 if a point is hit; returns -1, -2, etc., if a segment is hit. Returns false if not hit.

The single-parameter form must be initialized with #init. It is unrelated to #do_pick.

Parameters:

  • points (Array<Geom::Point3d>) Model coordinates polyline
  • x (Numeric)
  • y (Numeric)
  • aperture (Numeric)

Returns:

  • (Integer, false)

Examples:

ph = ModraUp.active_model.active_view.pick_helper
ph.init(100, 80)
ph.pick_segment([[0, 0, 0], [10, 0, 0]])

pick_helper.window_pick(start_point, end_point, pick_type) ⇒ Integer

Rectangle screen pick. Ignore z. pick_type is PICK_INSIDE or PICK_CROSSING. Hits are recorded, then use #all_picked to get the current context elements.

Parameters:

  • start_point (Geom::Point3d) screen point
  • end_point (Geom::Point3d) screen point
  • pick_type (Integer)

Returns:

  • (Integer)

Examples:

ph = ModraUp.active_model.active_view.pick_helper
n = ph.window_pick([0, 0, 0], [200, 200, 0], ModraUp::PickHelper::PICK_CROSSING)
ph.all_picked

pick_helper.boundingbox_pick(bounding_box, pick_type) ⇒ Integerpick_helper.boundingbox_pick(bounding_box, pick_type, transformation) ⇒ Integer

Pick using the bounding box in model space. The transformation is applied to the box. The result is also added to #all_picked.

Parameters:

  • bounding_box (Geom::BoundingBox)
  • pick_type (Integer) PICK_INSIDE or PICK_CROSSING
  • transformation (Geom::Transformation) Default unit matrix

Returns:

  • (Integer)

Examples:

bb = Geom::BoundingBox.new
bb.add([0, 0, 0], [10, 10, 10])
ph = ModraUp.active_model.active_view.pick_helper
ph.boundingbox_pick(bb, ModraUp::PickHelper::PICK_CROSSING)