Class: SkippyLib::DrawingCache

Inherits:
Object
  • Object
show all
Includes:
ObjectUtils
Defined in:
modules/drawing_cache.rb

Overview

Caches drawing instructions so complex calculations for generating the GL data can be reused.

Redirect all Sketchup::View commands to a DrawingCache object and call #render in a Tool's #draw event.

Examples:

class ExampleTool
  def initialize(model)
    @draw_cache = DrawCache.new(model.active_view)
  end
  def deactivate(view)
    @draw_cache.clear
  end
  def resume(view)
    view.invalidate
  end
  def onLButtonUp(flags, x, y, view)
    point = Geom::Point3d.new(x, y, 0)
    view.draw_points(point, 10, 1, 'red')
    view.invalidate
  end
  def draw(view)
    @draw_cache.render
  end
end

Since:

  • 3.0.0

Instance Method Summary collapse

Constructor Details

#initialize(view) ⇒ DrawingCache

Returns a new instance of DrawingCache.

Parameters:

  • view (Sketchup::View)

Since:

  • 3.0.0



40
41
42
43
# File 'modules/drawing_cache.rb', line 40

def initialize(view)
  @view = view
  @commands = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object

Pass through methods to Sketchup::View so that the drawing cache object can easily replace Sketchup::View objects in existing codes.

Since:

  • 3.0.0



89
90
91
# File 'modules/drawing_cache.rb', line 89

def method_missing(method, *args)
  @view.respond_to?(method) ? @view.send(method, *args) : super
end

Instance Method Details

#clearNil

Clears the cache. All drawing instructions are removed.

Returns:

  • (Nil)

Since:

  • 3.0.0



49
50
51
52
# File 'modules/drawing_cache.rb', line 49

def clear
  @commands.clear
  nil
end

#inspectString

Returns:

  • (String)

Since:

  • 3.0.0



99
100
101
# File 'modules/drawing_cache.rb', line 99

def inspect
  inspect_object(commands: @commands.size)
end

#renderSketchup::View

Draws the cached drawing instructions.

Returns:

  • (Sketchup::View)

Since:

  • 3.0.0



58
59
60
61
62
63
64
# File 'modules/drawing_cache.rb', line 58

def render
  view = @view
  @commands.each { |command|
    view.send(*command)
  }
  view
end

#respond_to_missing?(method) ⇒ Boolean

Returns:

  • (Boolean)

Since:

  • 3.0.0



93
94
95
# File 'modules/drawing_cache.rb', line 93

def respond_to_missing?(method, *)
  @view.respond_to?(method) | super
end