ModraUp Ruby API Documentation Ruby API Reference

Class: ModraUp::Procedure

Inherits:
Object
  • Object
show all

Class Method Summary # collapse

Instance Method Summary # collapse

  • #id ⇒ String
  • #description ⇒ String
  • #version ⇒ Integer
  • #declare_params_and_ui(args) ⇒ String
    Must be implemented. Returns a JSON object string: keys are parameter IDs (matching the keys in attach_procedure), values are control descriptions. This procedure reads these fields: type (number/length/angle/integer/boolean/checkbox/string/text/dropdown/choice/button), label, default, min, max, step, options (string, or value, label), group. Buttons are not parameters. Args: :model.
  • #validate(args) ⇒ Boolean, Array<Hash>
    Must be implemented. Args: :model, :control_entities, :parameters (Symbol keys). Do not modify the model. Return true, false, or an error Hash array (:title, :description, :involved_entities).
  • #run(args) ⇒ Boolean, Array<Hash>
    Must be implemented. Args: model, definition, parameters. Call within the operation started by this procedure; do not call start_operation. Clear definition.entities (i.e., clear the output), then generate geometry. Return value is the same as for #validate; revert the entire step on failure.
  • #draw(args) ⇒ nil
    Optional. Called every time the view is refreshed when the component is opened for editing, to draw the preview. Args: +model+, +view+, +control_entities+, +parameters+.
  • #get_extents(args) ⇒ Geom::BoundingBox
    Optional. #draw Returns the extent when drawing outside the component; defaults to an empty bounding box. Drawing or modifying the model is not allowed.
  • #get_widget_states(args) ⇒ Hash
    Optional. Control id → enabled:, visible:; omitted controls remain unchanged. Args: model, parameters.
  • #on_button_clicked(args) ⇒ Symbol, nil
    Optional. The button control was clicked. Args: :model, :definition, :button_id, :parameters. Perform an operation on the model when modifying it. Return :reload_ui to rebuild the control.
  • #on_open_close(args) ⇒ nil
    Optional. Component opens or closes for editing. Args: action (:open / :close), +from_undo_redo+, +model+, +definition+. Only observe, do not modify the model.

Class Method Details

ModraUp::Procedure.new(id:, description:, version:)

Abstract base class. Subclasses call super in initialize, providing a unique ID (e.g., Company.Extend.Procedure), a visible name, and an integer version.

Parameters:

  • id (String)
  • description (String)
  • version (Integer)

Raises:

  • [TypeError] id / description is not a String, or version is not an Integer
  • [ArgumentError] id or description is empty, or missing keywords

Examples:

class Fence < ModraUp::Procedure
  def initialize
    super(id: 'example.fence', description: 'Fence', version: 1)
  end
end

Instance Method Details

procedure.id ⇒ String

Returns:

  • (String)

Examples:

Fence.new.id  #=> "example.fence"

procedure.description ⇒ String

Returns:

  • (String)

Examples:

Fence.new.description

procedure.version ⇒ Integer

Returns:

  • (Integer)

Examples:

Fence.new.version

procedure.declare_params_and_ui(args) ⇒ String

Must be implemented. Returns a JSON object string: keys are parameter IDs (matching the keys in attach_procedure), values are control descriptions. This procedure reads these fields: type (number/length/angle/integer/boolean/checkbox/string/text/dropdown/choice/button), label, default, min, max, step, options (string, or value, label), group. Buttons are not parameters. Args: :model.

Parameters:

  • args (Hash)

Returns:

  • (String)

Examples:

def declare_params_and_ui(args)
  { length: { type: 'length', label: 'Length', default: 120 } }.to_json
end

procedure.validate(args) ⇒ Boolean, Array<Hash>

Must be implemented. Args: :model, :control_entities, :parameters (Symbol keys). Do not modify the model. Return true, false, or an error Hash array (:title, :description, :involved_entities).

Parameters:

  • args (Hash)

Returns:

  • (Boolean, Array<Hash>)

Examples:

def validate(args)
  args[:parameters][:length] > 0
end

procedure.run(args) ⇒ Boolean, Array<Hash>

Must be implemented. Args: model, definition, parameters. Call within the operation started by this procedure; do not call start_operation. Clear definition.entities (i.e., clear the output), then generate geometry. Return value is the same as for #validate; revert the entire step on failure.

Parameters:

  • args (Hash)

Returns:

  • (Boolean, Array<Hash>)

Examples:

def run(args)
  ents = args[:definition].entities
  ents.clear!
  ents.add_line([0, 0, 0], [args[:parameters][:length], 0, 0])
  true
end

procedure.draw(args) ⇒ nil

Optional. Called every time the view is refreshed when the component is opened for editing, to draw the preview. Args: +model+, +view+, +control_entities+, +parameters+.

Parameters:

  • args (Hash)

Returns:

  • (nil)

Examples:

def draw(args)
  args[:view].draw(GL_LINES, [0, 0, 0], [10, 0, 0])
end

procedure.get_extents(args) ⇒ Geom::BoundingBox

Optional. #draw Returns the extent when drawing outside the component; defaults to an empty bounding box. Drawing or modifying the model is not allowed.

Parameters:

  • args (Hash)

Returns:

  • (Geom::BoundingBox)

Examples:

def get_extents(args)
  Geom::BoundingBox.new
end

procedure.get_widget_states(args) ⇒ Hash

Optional. Control id → enabled:, visible:; omitted controls remain unchanged. Args: model, parameters.

Parameters:

  • args (Hash)

Returns:

  • (Hash)

Examples:

def get_widget_states(args)
  { gap: { enabled: args[:parameters][:count] > 1 } }
end

procedure.on_button_clicked(args) ⇒ Symbol, nil

Optional. The button control was clicked. Args: :model, :definition, :button_id, :parameters. Perform an operation on the model when modifying it. Return :reload_ui to rebuild the control.

Parameters:

  • args (Hash)

Returns:

  • (Symbol, nil)

Examples:

def on_button_clicked(args)
  :reload_ui if args[:button_id] == :reset
end

procedure.on_open_close(args) ⇒ nil

Optional. Component opens or closes for editing. Args: action (:open / :close), +from_undo_redo+, +model+, +definition+. Only observe, do not modify the model.

Parameters:

  • args (Hash)

Returns:

  • (nil)

Examples:

def on_open_close(args)
  puts args[:action]
end