ModraUp Ruby API Documentation Ruby API Reference

Class: ModraUp::Tools

Inherits:
Object
  • Object
show all

Overview

Model tool manager. Obtain it from ModraUp::Model#tools. Ruby custom tool protocol see ModraUp::Tool.

Examples:

ModraUp.active_model.tools.add_observer(ModraUp::ToolsObserver.new)

Instance Method Summary # collapse

Instance Method Details

tools.add_observer(observer) ⇒ Boolean

Register ModraUp::ToolsObserver. Adding the same object a second time returns false. The cut tool dispatches onActiveToolChanged(tools, tool_name, tool_id); for a start state of 1 and end state of 0, the move/scale gesture dispatches onToolStateChanged.

Parameters:

  • observer (ModraUp::ToolsObserver)

Returns:

  • (Boolean)

Examples:

class MyTools < ModraUp::ToolsObserver
  def onActiveToolChanged(tools, tool_name, tool_id)
    tool_name
  end
end
ModraUp.active_model.tools.add_observer(MyTools.new)

tools.remove_observer(observer) ⇒ Boolean

Remove tool observers.

Parameters:

  • observer (ModraUp::ToolsObserver)

Returns:

  • (Boolean)

Examples:

tools = ModraUp.active_model.tools
obs = ModraUp::ToolsObserver.new
tools.add_observer(obs)
tools.remove_observer(obs)

tools.active_tool ⇒ Object, nil

The current Ruby tool activated by ModraUp::Model#select_tool (protocol see ModraUp::Tool). Built-in C tools are nil.

Returns:

  • (Object, nil)

Examples:

ModraUp.active_model.tools.active_tool

tools.push_tool(tool) ⇒ true

Push the Ruby tool to the top of the stack, saving the current Ruby or built-in tool. If the Ruby tool implements suspend(view), it will be suspended.

Parameters:

  • tool (Object)

Returns:

  • (true)

Examples:

ModraUp.active_model.tools.push_tool(Object.new)

tools.pop_tool ⇒ Object or nil

Pop the current Ruby tool, restoring the stack to the previous Ruby or built-in tool; the Ruby tool will receive resume. Returns the popped Ruby tool. Returns nil if the current tool is built-in, and nil if the stack is empty, reverting to the select tool.

Returns:

  • (Object, nil)

Examples:

ModraUp.active_model.tools.pop_tool

tools.active_tool_id ⇒ Integer

Current tool ID. The Ruby tool ID is 0. Built-in tools use SketchUp common IDs (select 21022, move 21048, scale 21236, etc.).

Returns:

  • (Integer)

Examples:

ModraUp.active_model.tools.active_tool_id

tools.active_tool_name ⇒ String

The current tool name. Ruby tools are named after their class names, while built-in tools are named in English.

Returns:

  • (String)

Examples:

ModraUp.active_model.tools.active_tool_name

tools.model ⇒ ModraUp::Model

This tool manager belongs to the model.

Returns:

  • (ModraUp::Model)

Examples:

ModraUp.active_model.tools.model == ModraUp.active_model