# Copyright 2005, @Last Software, Inc. # This software is provided as an example of using the Ruby interface # to SketchUp. # Permission to use, copy, modify, and distribute this software for # any purpose and without fee is hereby granted, provided that the above # copyright notice appear in all copies. # THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. #----------------------------------------------------------------------------- require 'sketchup.rb' class ViewToolTests # Called when you select the tool def activate puts "activate called" @counter = 0 @ip1 = Sketchup::InputPoint.new end # Called when I select another tool or quit SketchUp def deactivate(view) puts "deactivate called" end def onLButtonDown(flags, x, y, view) view.invalidate end # Each click on the left button invokes view.invalidate which, in turn, calls # draw. Draw keeps track of the number of click using the @status variable. # For each click a seperate branch of a case statement is followed to test # some method in the View class. def draw(view) puts "draw called" case @counter # First left click we test view.draw_lines when 0 point1 = Geom::Point3d.new 0,0,0 point2 = Geom::Point3d.new 100,100,100 status = view.draw_lines point1, point2 # returns a view @counter +=1 # Second click we test view.draw_points when 1 point3 = Geom::Point3d.new 0,0,0 # returns a view status = view.draw_points point3, 10, 1, "red" @counter +=1 when 2 # Third click we test view.drawing_color point4 = Geom::Point3d.new 0,0,0 point5 = Geom::Point3d.new 100,100,100 # returns a view status = view.drawing_color="red" status = view.draw_lines point4, point5 @counter +=1 when 3 # Fourth click we test view.draw point6 = Geom::Point3d.new 0,0,0 point7 = Geom::Point3d.new 100,0,0 view.line_width=10 status = view.draw GL_LINES, [point6, point7] @counter +=1 # Fifth left click we test view.line_stipple= when 4 point8 = Geom::Point3d.new 0,0,0 point9 = Geom::Point3d.new 100,100,100 # Stipple types documented in ConstructionLine class view.line_stipple = "-.-" status = view.draw_lines point8, point9 @counter +=1 # Sixth click we test view.line_width= when 5 point10 = Geom::Point3d.new 0,0,0 point11 = Geom::Point3d.new 100,100,100 view.line_width=10 status = view.draw_lines point10, point11 @counter+=1 # Seventh click we test view.draw_text when 6 point16 = Geom::Point3d.new 0,0,0 status = view.draw_text point16, "This is a test" @counter +=1 # Eighth click we test view.set_color_from_line when 7 point17 = Geom::Point3d.new 0,0,0 point18 = Geom::Point3d.new 100,0,0 view.line_width=10 status = view.set_color_from_line point17, point18 status = view.draw_lines point17, point18 @counter +=1 # Ninth click we test view.draw_polyline when 8 point12 = Geom::Point3d.new 0,0,0 point13 = Geom::Point3d.new 10,10,10 point14 = Geom::Point3d.new 20,20,20 point15 = Geom::Point3d.new 30,30,30 #status = view.draw_polyline point12, point13, point14, point15 UI.messsagebox status @counter +=1 end end end # end of class ViewToolTests # Add a menu choice for viewtooltests if( not file_loaded?("viewtooltests.rb") ) plugins_menu = UI.menu("Plugins") plugins_menu.add_item("ViewToolTests") { Sketchup.active_model.select_tool ViewToolTests.new } end