Class: MSPhysics::JointTool

Inherits:
Object
  • Object
show all
Defined in:
RubyExtension/MSPhysics/joint_tool.rb

Overview

Since:

  • 1.0.0

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(joint_id) ⇒ JointTool

Returns a new instance of JointTool.

Parameters:

Raises:

  • (TypeError)

Since:

  • 1.0.0



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'RubyExtension/MSPhysics/joint_tool.rb', line 26

def initialize(joint_id)
  @joint_id = joint_id.to_i
  joint_fname = MSPhysics::JOINT_ID_TO_FILE_NAME[@joint_id]
  raise(TypeError, "Given joint ID is invalid!", caller) unless joint_fname
  dir = File.dirname(__FILE__)
  dir.force_encoding('UTF-8') unless AMS::IS_RUBY_VERSION_18
  @path = File.join(dir, 'models')
  @full_path = File.join(@path, joint_fname + '.skp')
  raise(TypeError, "File to the given joint ID doesn't exist!", caller) unless File.exists?(@full_path)
  @ip1 = Sketchup::InputPoint.new
  @ip2 = Sketchup::InputPoint.new
  @ip = Sketchup::InputPoint.new
  @drawn = false
  @state = 0
  @xdown = 0
  @ydown = 0
  @shift_down_time = nil
  @layer_color = Sketchup::Color.new(44, 44, 164)
  @active = false
  @cursor_id = MSPhysics::CURSORS[:click]
  Sketchup.active_model.select_tool(self)
end

Class Method Details

.generate_uniq_idInteger

Returns:

  • (Integer)

Since:

  • 1.0.0



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'RubyExtension/MSPhysics/joint_tool.rb', line 6

def generate_uniq_id
  ids = []
  Sketchup.active_model.definitions.each { |cd|
    cd.instances.each { |inst|
      type = inst.get_attribute('MSPhysics', 'Type', 'Body')
      if type == 'Joint'
        id = inst.get_attribute('MSPhysics Joint', 'ID', nil)
        ids << id if id.is_a?(Integer)
      end
    }
  }
  while true
    id = rand(900000) + 100000
    return id unless ids.include?(id)
  end
end