Class: TT::Gizmo::Axis

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

Overview

Since:

  • 2.7.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, origin, direction, color, active_color, axis_id) ⇒ Axis

Returns a new instance of Axis

Parameters:

  • origin (Geom::Point3d)
  • direction (Geom::Vector3d)
  • color (Sketchup::Color)
  • active_color (Sketchup::Color)

Since:

  • 2.7.0



273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# File 'TT_Lib2/gizmo_manipulator.rb', line 273

def initialize( parent, origin, direction, color, active_color, axis_id )
  @id = axis_id
  @parent = parent
  @origin = origin.clone
  @direction = direction.clone
  @color = color
  @active_color = active_color
  
  # Event callbacks
  @callback = nil
  @callback_start = nil
  @callback_end = nil
  
  # MoveGizmo
  @move_gizmo = MoveGizmo.new( self, origin, direction, color, active_color )
  @move_gizmo.on_transform_start { |gizmo, action_name|
    @callback_start.call( self, action_name ) unless @callback_start.nil?
  }
  @move_gizmo.on_transform { |gizmo, t_increment, t_total, data|
    @origin = gizmo.origin
    @rotate_gizmo.origin = gizmo.origin
    @scale_gizmo.origin = gizmo.origin
    @callback.call( self, t_increment, t_total, data ) unless @callback.nil?
  }
  @move_gizmo.on_transform_end { |gizmo, action_name|
    @callback_end.call( self, action_name ) unless @callback_end.nil?
  }
  
  # RotateGizmo
  @rotate_gizmo = RotateGizmo.new( self, origin, direction, color, active_color )
  @rotate_gizmo.on_transform_start { |gizmo, action_name|
    @callback_start.call( self, action_name ) unless @callback_start.nil?
  }
  @rotate_gizmo.on_transform { |gizmo, t_increment, t_total, data|
    @callback.call( self, t_increment, t_total, data ) unless @callback.nil?
  }
  @rotate_gizmo.on_transform_end { |gizmo, action_name|
    @callback_end.call( self, action_name ) unless @callback_end.nil?
  }
  
  # ScaleGizmo
  @scale_gizmo = ScaleGizmo.new( self, origin, direction, color, active_color )
  @scale_gizmo.on_transform_start { |gizmo, action_name|
    @callback_start.call( self, action_name ) unless @callback_start.nil?
  }
  @scale_gizmo.on_transform { |gizmo, t_increment, t_total, data|
    @callback.call( self, t_increment, t_total, data ) unless @callback.nil?
  }
  @scale_gizmo.on_transform_end { |gizmo, action_name|
    @callback_end.call( self, action_name ) unless @callback_end.nil?
  }
end

Instance Attribute Details

#directionObject

Since:

  • 2.7.0



264
265
266
# File 'TT_Lib2/gizmo_manipulator.rb', line 264

def direction
  @direction
end

#idObject (readonly)

Since:

  • 2.7.0



265
266
267
# File 'TT_Lib2/gizmo_manipulator.rb', line 265

def id
  @id
end

#originObject

Since:

  • 2.7.0



264
265
266
# File 'TT_Lib2/gizmo_manipulator.rb', line 264

def origin
  @origin
end

#parentObject (readonly)

Since:

  • 2.7.0



265
266
267
# File 'TT_Lib2/gizmo_manipulator.rb', line 265

def parent
  @parent
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)

Since:

  • 2.7.0



350
351
352
# File 'TT_Lib2/gizmo_manipulator.rb', line 350

def active?
  @move_gizmo.active? || @rotate_gizmo.active? || @scale_gizmo.active?
end

#cancelObject

Since:

  • 2.7.0



494
495
496
497
498
# File 'TT_Lib2/gizmo_manipulator.rb', line 494

def cancel
  @move_gizmo.cancel
  @rotate_gizmo.cancel
  @scale_gizmo.cancel
end

#draw(view) ⇒ Nil

Parameters:

  • view (Sketchup::View)

Returns:

  • (Nil)

Since:

  • 2.7.0



487
488
489
490
491
# File 'TT_Lib2/gizmo_manipulator.rb', line 487

def draw( view )
  @move_gizmo.draw( view )
  @rotate_gizmo.draw( view )
  @scale_gizmo.draw( view )
end

#inspectString

Returns:

  • (String)

Since:

  • 2.7.0



328
329
330
331
# File 'TT_Lib2/gizmo_manipulator.rb', line 328

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

#mouse_active?Boolean

Returns:

  • (Boolean)

Since:

  • 2.7.0



369
370
371
# File 'TT_Lib2/gizmo_manipulator.rb', line 369

def mouse_active?
  @mouse_active == true
end

#on_transform(&block) ⇒ Object

Since:

  • 2.7.0



334
335
336
# File 'TT_Lib2/gizmo_manipulator.rb', line 334

def on_transform( &block )
  @callback = block
end

#on_transform_end(&block) ⇒ Object

Since:

  • 2.7.0



344
345
346
# File 'TT_Lib2/gizmo_manipulator.rb', line 344

def on_transform_end( &block )
  @callback_end = block
end

#on_transform_start(&block) ⇒ Object

Since:

  • 2.7.0



339
340
341
# File 'TT_Lib2/gizmo_manipulator.rb', line 339

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



402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
# File 'TT_Lib2/gizmo_manipulator.rb', line 402

def onLButtonDown( flags, x, y, view )
  camera = view.camera
  perpendicular = !camera.perspective? && camera.direction.perpendicular?( @direction )
  can_move   = !(@rotate_gizmo.active? || @scale_gizmo.active?)
  can_rotate = !(@move_gizmo.active? || @scale_gizmo.active?) && !perpendicular
  can_scale  = !(@move_gizmo.active? || @rotate_gizmo.active?)
  if can_move && @move_gizmo.onLButtonDown( flags, x, y, view )
    true
  elsif can_rotate && @rotate_gizmo.onLButtonDown( flags, x, y, view )
    true
  elsif can_scale && @scale_gizmo.onLButtonDown( flags, x, y, view )
    true
  else
    false
  end
end

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

Parameters:

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

Returns:

  • (Boolean)

Since:

  • 2.7.0



426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
# File 'TT_Lib2/gizmo_manipulator.rb', line 426

def onLButtonUp( flags, x, y, view )
  can_move   = !(@rotate_gizmo.active? || @scale_gizmo.active?)
  can_rotate = !(@move_gizmo.active? || @scale_gizmo.active?)
  can_scale  = !(@move_gizmo.active? || @rotate_gizmo.active?)
  if can_move && @move_gizmo.onLButtonUp( flags, x, y, view )
    true
  elsif can_rotate && @rotate_gizmo.onLButtonUp( flags, x, y, view )
    true
  elsif can_scale && @scale_gizmo.onLButtonUp( flags, x, y, view )
    true
  elsif @interacting
    # (!) ...
    @callback_end.call( self ) unless @callback_end.nil?
    @interacting = false
    true
  else
    @interacting = false
    false
  end
end

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

Parameters:

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

Returns:

  • (Boolean)

Since:

  • 2.7.0



454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
# File 'TT_Lib2/gizmo_manipulator.rb', line 454

def onMouseMove( flags, x, y, view )
  camera = view.camera
  perpendicular = !camera.perspective? && camera.direction.perpendicular?( @direction )
  if @interacting
    # (!) ...
    @mouse_active = true
    true
  else
    can_move   = !(@rotate_gizmo.active? || @scale_gizmo.active?)
    can_rotate = !(@move_gizmo.active? || @scale_gizmo.active?) && !perpendicular
    can_scale  = !(@move_gizmo.active? || @rotate_gizmo.active?)
    if can_move && @move_gizmo.onMouseMove( flags, x, y, view )
      @mouse_active = true
      view.invalidate
      return true
    elsif can_rotate && @rotate_gizmo.onMouseMove( flags, x, y, view )
      @mouse_active = true
      view.invalidate
      return true
    elsif can_scale && @scale_gizmo.onMouseMove( flags, x, y, view )
      @mouse_active = true
      view.invalidate
      return true
    end
    @mouse_active = false
    false
  end
end

#tooltipObject

Since:

  • 2.7.0



355
356
357
358
359
360
361
362
363
364
365
# File 'TT_Lib2/gizmo_manipulator.rb', line 355

def tooltip
  if @move_gizmo.mouse_active?
    @move_gizmo.tooltip
  elsif @rotate_gizmo.mouse_active?
    @rotate_gizmo.tooltip
  elsif @scale_gizmo.mouse_active?
    @scale_gizmo.tooltip
  else
    ''
  end
end