Class: TT::DrawCache

Inherits:
Object
  • Object
show all
Defined in:
TT_Lib2/draw_cache.rb

Overview

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

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

Examples:

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

Since:

  • 2.8.0

Instance Method Summary collapse

Constructor Details

#initialize(view) ⇒ DrawCache

Returns a new instance of DrawCache

Parameters:

  • view (Sketchup::View)

Since:

  • 2.8.0



43
44
45
46
# File 'TT_Lib2/draw_cache.rb', line 43

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args) ⇒ Object

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

Since:

  • 2.8.0



94
95
96
97
98
99
100
101
102
# File 'TT_Lib2/draw_cache.rb', line 94

def method_missing( *args )
  view = @view
  method = args.first
  if view.respond_to?( method )
    view.send(*args)
  else
    raise NoMethodError, "undefined method `#{method}' for #{self.class.name}"
  end
end

Instance Method Details

#clearNil

Clears the cache. All drawing instructions are removed.

Returns:

  • (Nil)

Since:

  • 2.8.0



52
53
54
55
# File 'TT_Lib2/draw_cache.rb', line 52

def clear
  @commands.clear
  nil
end

#inspectString

Returns:

  • (String)

Since:

  • 2.8.0



106
107
108
109
# File 'TT_Lib2/draw_cache.rb', line 106

def inspect
  hex_id = TT.object_id_hex( self )
  "#<#{self.class.name}:#{hex_id} Commands:#{@commands.size}>"
end

#renderSketchup::View

Draws the cached drawing instructions.

Returns:

  • (Sketchup::View)

Since:

  • 2.8.0



61
62
63
64
65
66
67
# File 'TT_Lib2/draw_cache.rb', line 61

def render
  view = @view
  for command in @commands
    view.send( *command )
  end
  view
end