Class: Cosmos::StlShape
- Defined in:
- lib/cosmos/gui/opengl/stl_shape.rb
Constant Summary collapse
- @@splash =
nil
Instance Attribute Summary collapse
-
#show_load_progress ⇒ Object
Returns the value of attribute show_load_progress.
-
#stl_file ⇒ Object
Returns the value of attribute stl_file.
-
#stl_scaling_factor ⇒ Object
Returns the value of attribute stl_scaling_factor.
-
#window ⇒ Object
Returns the value of attribute window.
Attributes inherited from GlShape
#base_color, #click_handler, #color, #doubleclick_handler, #dragable, #position, #rotation_x, #rotation_y, #rotation_z, #tipText
Class Method Summary collapse
Instance Method Summary collapse
-
#drawshape(viewer) ⇒ Object
Draw the StlShape.
- #export ⇒ Object
-
#initialize(x, y, z) ⇒ StlShape
constructor
A new instance of StlShape.
- #load_stl ⇒ Object
Methods inherited from GlShape
#drag, #draw, #handle_click, #handle_doubleclick, #hit, #identify
Constructor Details
#initialize(x, y, z) ⇒ StlShape
Returns a new instance of StlShape.
25 26 27 28 29 30 31 32 |
# File 'lib/cosmos/gui/opengl/stl_shape.rb', line 25 def initialize(x, y, z) super(x, y, z) @mystl = StlReader.new @show_load_progress = false @stl_scaling_factor = 1.0 @stl_file = nil @progress_dialog = nil end |
Instance Attribute Details
#show_load_progress ⇒ Object
Returns the value of attribute show_load_progress.
22 23 24 |
# File 'lib/cosmos/gui/opengl/stl_shape.rb', line 22 def show_load_progress @show_load_progress end |
#stl_file ⇒ Object
Returns the value of attribute stl_file.
20 21 22 |
# File 'lib/cosmos/gui/opengl/stl_shape.rb', line 20 def stl_file @stl_file end |
#stl_scaling_factor ⇒ Object
Returns the value of attribute stl_scaling_factor.
21 22 23 |
# File 'lib/cosmos/gui/opengl/stl_shape.rb', line 21 def stl_scaling_factor @stl_scaling_factor end |
#window ⇒ Object
Returns the value of attribute window.
23 24 25 |
# File 'lib/cosmos/gui/opengl/stl_shape.rb', line 23 def window @window end |
Class Method Details
.splash=(splash) ⇒ Object
85 86 87 |
# File 'lib/cosmos/gui/opengl/stl_shape.rb', line 85 def self.splash=(splash) @@splash = splash end |
Instance Method Details
#drawshape(viewer) ⇒ Object
Draw the StlShape
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/cosmos/gui/opengl/stl_shape.rb', line 58 def drawshape(viewer) @viewer = viewer GL.PushMatrix GL.Enable(GL::BLEND) GL.BlendFunc(GL::SRC_ALPHA, GL::ONE_MINUS_SRC_ALPHA) GL.Color4f(@color[0], @color[1], @color[2], @color[3]) GL.Rotate(@rotation_x, 1.0, 0.0, 0.0) if @rotation_x GL.Rotate(@rotation_y, 0.0, 1.0, 0.0) if @rotation_y GL.Rotate(@rotation_z, 0.0, 0.0, 1.0) if @rotation_z GL.Material(GL::FRONT_AND_BACK, GL::AMBIENT_AND_DIFFUSE, @color) draw_stl() GL.Disable(GL::BLEND) GL.PopMatrix end |
#export ⇒ Object
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/cosmos/gui/opengl/stl_shape.rb', line 74 def export string = "STL_FILE \"#{@stl_file}\" #{@stl_scaling_factor}\n" string << " TIP_TEXT \"#{@tipText}\"\n" if @tipText string << " COLOR #{color[0]} #{color[1]} #{color[2]} #{color[3]}\n" string << " POSITION #{self.position[0]} #{self.position[1]} #{self.position[2]}\n" string << " ROTATION_X #{@rotation_x}\n" if @rotation_x string << " ROTATION_Y #{@rotation_y}\n" if @rotation_y string << " ROTATION_Z #{@rotation_z}\n" if @rotation_z return string end |
#load_stl ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/cosmos/gui/opengl/stl_shape.rb', line 34 def load_stl if @show_load_progress load_setup() estimate = @mystl.estimate_num_triangles(@stl_file) total_read = 0 num_read = 1 while num_read > 0 num_read = @mystl.process_with_progress(@stl_file, @stl_scaling_factor) total_read += num_read progress = total_read.to_f / estimate.to_f if @@splash @@splash.progress = progress else @progress_dialog.set_overall_progress(progress) end end @progress_dialog.dispose if @progress_dialog @progress_dialog = nil else @mystl.process(@stl_file, @stl_scaling_factor) end end |