Class: TT::Gizmo::Manipulator

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

Overview

Since:

  • 2.7.0

Constant Summary

CLR_X_AXIS =

Since:

  • 2.7.0

Sketchup::Color.new( 255,   0,   0 )
CLR_Y_AXIS =

Since:

  • 2.7.0

Sketchup::Color.new(   0, 128,   0 )
CLR_Z_AXIS =

Since:

  • 2.7.0

Sketchup::Color.new(   0,   0, 255 )
CLR_SELECTED =

Since:

  • 2.7.0

Sketchup::Color.new( 255, 255,   0 )

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(origin, xaxis, yaxis, zaxis) ⇒ Manipulator

Returns a new instance of Manipulator

Parameters:

  • origin (Geom::Point3d)
  • xaxis (Geom::Vector3d)
  • yaxis (Geom::Vector3d)
  • zaxis (Geom::Vector3d)

Since:

  • 2.7.0



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'TT_Lib2/gizmo_manipulator.rb', line 35

def initialize( origin, xaxis, yaxis, zaxis )
  # Event callbacks
  @callback = nil
  @callback_start = nil
  @callback_end = nil
  
  @size = 150 # pixels
  
  # Origin
  @origin = origin
  
  # Set up axis and events
  @axes = []
  @axes << TT::Gizmo::Axis.new( self, @origin, xaxis, CLR_X_AXIS, CLR_SELECTED, :x )
  @axes << TT::Gizmo::Axis.new( self, @origin, yaxis, CLR_Y_AXIS, CLR_SELECTED, :y )
  @axes << TT::Gizmo::Axis.new( self, @origin, zaxis, CLR_Z_AXIS, CLR_SELECTED, :z )
  
  @active_axis = nil # Current Axis active due to a mouse down event.
  @mouse_axis = nil  # Current Axis the mouse hovers over.
  
  for axis in @axes
    axis.on_transform_start { |axis, action_name|
      @callback_start.call( action_name ) unless @callback_start.nil?
    }
    axis.on_transform_end { |axis, action_name|
      @callback_end.call( action_name ) unless @callback_end.nil?
    }
    axis.on_transform { |axis, t_increment, t_total, data|
      @origin = axis.origin
      update_axes( axis.origin, axis )
      @callback.call( t_increment, t_total, data ) unless @callback.nil?
    }
  end
end

Instance Attribute Details

#axesObject (readonly)

Since:

  • 2.7.0



25
26
27
# File 'TT_Lib2/gizmo_manipulator.rb', line 25

def axes
  @axes
end

#callbackObject (readonly)

Since:

  • 2.7.0



27
28
29
# File 'TT_Lib2/gizmo_manipulator.rb', line 27

def callback
  @callback
end

#callback_endObject (readonly)

Since:

  • 2.7.0



27
28
29
# File 'TT_Lib2/gizmo_manipulator.rb', line 27

def callback_end
  @callback_end
end

#callback_startObject (readonly)

Since:

  • 2.7.0



27
28
29
# File 'TT_Lib2/gizmo_manipulator.rb', line 27

def callback_start
  @callback_start
end

#originObject

Since:

  • 2.7.0



25
26
27
# File 'TT_Lib2/gizmo_manipulator.rb', line 25

def origin
  @origin
end

#sizeObject

Since:

  • 2.7.0



26
27
28
# File 'TT_Lib2/gizmo_manipulator.rb', line 26

def size
  @size
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)

Since:

  • 2.7.0



90
91
92
# File 'TT_Lib2/gizmo_manipulator.rb', line 90

def active?
  !@active_axis.nil?
end

#cancelObject

Since:

  • 2.7.0



230
231
232
233
234
235
# File 'TT_Lib2/gizmo_manipulator.rb', line 230

def cancel
  for axis in @axes
    axis.cancel
  end
  reset()
end

#draw(view) ⇒ Nil

Parameters:

  • view (Sketchup::View)

Returns:

  • (Nil)

Since:

  • 2.7.0



217
218
219
220
221
222
# File 'TT_Lib2/gizmo_manipulator.rb', line 217

def draw( view )
  for axis in @axes
    axis.draw( view )
  end
  nil
end

#mouse_over?Boolean

Returns:

  • (Boolean)

Since:

  • 2.7.0



225
226
227
# File 'TT_Lib2/gizmo_manipulator.rb', line 225

def mouse_over?
  !@mouse_axis.nil?
end

#normalGeom::Vector3d

Returns:

  • (Geom::Vector3d)

Since:

  • 2.7.0



104
105
106
# File 'TT_Lib2/gizmo_manipulator.rb', line 104

def normal
  @axes.z.direction
end

#on_transform(&block) ⇒ Object

Since:

  • 2.7.0



109
110
111
# File 'TT_Lib2/gizmo_manipulator.rb', line 109

def on_transform( &block )
  @callback = block
end

#on_transform_end(&block) ⇒ Object

Since:

  • 2.7.0



119
120
121
# File 'TT_Lib2/gizmo_manipulator.rb', line 119

def on_transform_end( &block )
  @callback_end = block
end

#on_transform_start(&block) ⇒ Object

Since:

  • 2.7.0



114
115
116
# File 'TT_Lib2/gizmo_manipulator.rb', line 114

def on_transform_start( &block )
  @callback_start = block
end

#onLButtonDown(flags, x, y, view) ⇒ Boolean

Parameters:

  • flags (Integer)
  • x (Integer)
  • y (Integer)
  • view (Sketchup::View)

Returns:

  • (Boolean)

Since:

  • 2.7.0



186
187
188
189
190
191
192
193
194
# File 'TT_Lib2/gizmo_manipulator.rb', line 186

def onLButtonDown( flags, x, y, view )
  for axis in @axes
    if axis.onLButtonDown( flags, x, y, view )
      @active_axis = axis
      return true 
    end
  end
  false
end

#onLButtonUp(flags, x, y, view) ⇒ Boolean

Parameters:

  • flags (Integer)
  • x (Integer)
  • y (Integer)
  • view (Sketchup::View)

Returns:

  • (Boolean)

Since:

  • 2.7.0



203
204
205
206
207
208
209
210
211
# File 'TT_Lib2/gizmo_manipulator.rb', line 203

def onLButtonUp( flags, x, y, view )
  for axis in @axes
    if axis.onLButtonUp( flags, x, y, view )
      @active_axis = nil
      return true
    end
  end
  false
end

#onMouseMove(flags, x, y, view) ⇒ Boolean

Parameters:

  • flags (Integer)
  • x (Integer)
  • y (Integer)
  • view (Sketchup::View)

Returns:

  • (Boolean)

Since:

  • 2.7.0



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'TT_Lib2/gizmo_manipulator.rb', line 142

def onMouseMove( flags, x, y, view )
  # (!) Hotfix. Some times it appear that button up event is not detected
  #     and the gizmo thinks an axis is active. Some times due to cursor
  #     being released outside SketchUp's viewport or - it appear - with
  #     glitch that occur with quick clicks and released.
  if @active_axis && flags & MK_LBUTTON != MK_LBUTTON
    #puts 'Out of state!'
    #puts flags
    #puts @active_axis.id
    #puts '> Restore!'
    @active_axis = nil
  end

  if @active_axis
    @active_axis.onMouseMove( flags, x, y, view )
    return true
  else
    # Prioritise last axis the mouse hovered over.
    if @mouse_axis && @mouse_axis.onMouseMove( flags, x, y, view )
      return true
    else
      @mouse_axis = nil
    end
    
    # If the mouse doesn't interact with the last axis any more, check the
    # rest.
    for axis in @axes
      if axis.onMouseMove( flags, x, y, view )
        @mouse_axis = axis
        return true
      end
    end
  end
  @mouse_axis = nil
  false
end

#tooltipObject

Since:

  • 2.7.0



95
96
97
98
99
100
# File 'TT_Lib2/gizmo_manipulator.rb', line 95

def tooltip
  for axis in @axes
    return axis.tooltip if axis.mouse_active?
  end
  ''
end

#xaxis=(vector) ⇒ Boolean

Returns:

  • (Boolean)

Since:

  • 2.7.0



72
73
74
# File 'TT_Lib2/gizmo_manipulator.rb', line 72

def xaxis=( vector )
  @axes.x.direction = vector
end

#yaxis=(vector) ⇒ Boolean

Returns:

  • (Boolean)

Since:

  • 2.7.0



78
79
80
# File 'TT_Lib2/gizmo_manipulator.rb', line 78

def yaxis=( vector )
  @axes.y.direction = vector
end

#zaxis=(vector) ⇒ Boolean

Returns:

  • (Boolean)

Since:

  • 2.7.0



84
85
86
# File 'TT_Lib2/gizmo_manipulator.rb', line 84

def zaxis=( vector )
  @axes.z.direction = vector
end