autocad 0.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. checksums.yaml +7 -0
  2. data/.rubocop/minitest.yml +2 -0
  3. data/.rubocop/strict.yml +4 -0
  4. data/.rubocop.yml +33 -0
  5. data/.solargraph.yml +22 -0
  6. data/.vscode/launch.json +30 -0
  7. data/CHANGELOG.md +5 -0
  8. data/CODE_OF_CONDUCT.md +132 -0
  9. data/Guardfile +66 -0
  10. data/LICENSE.txt +21 -0
  11. data/README.md +39 -0
  12. data/Rakefile +10 -0
  13. data/Steepfile +35 -0
  14. data/WASD-D-TDS-C001.dwg +0 -0
  15. data/WASD-D-TDS-C001.pdf +0 -0
  16. data/autocad.log +1 -0
  17. data/autocad_example.rb +26 -0
  18. data/event_handler.log +24 -0
  19. data/examples/example_save_pdf.rb +5 -0
  20. data/exe/autocad +3 -0
  21. data/exe/dgn2pdf +50 -0
  22. data/exe/pw_print +43 -0
  23. data/gemfiles/rubocop.gemfile +6 -0
  24. data/lib/autocad/app.rb +655 -0
  25. data/lib/autocad/arc.rb +29 -0
  26. data/lib/autocad/block.rb +141 -0
  27. data/lib/autocad/block_reference.rb +198 -0
  28. data/lib/autocad/drawing.rb +426 -0
  29. data/lib/autocad/element.rb +454 -0
  30. data/lib/autocad/enumerator.rb +24 -0
  31. data/lib/autocad/errors.rb +37 -0
  32. data/lib/autocad/event_handler.rb +30 -0
  33. data/lib/autocad/filter.rb +168 -0
  34. data/lib/autocad/layer.rb +41 -0
  35. data/lib/autocad/line.rb +55 -0
  36. data/lib/autocad/message_box.rb +95 -0
  37. data/lib/autocad/model.rb +89 -0
  38. data/lib/autocad/mtext.rb +110 -0
  39. data/lib/autocad/paths.rb +29 -0
  40. data/lib/autocad/point3d.rb +143 -0
  41. data/lib/autocad/pviewport.rb +21 -0
  42. data/lib/autocad/selection_filter.rb +180 -0
  43. data/lib/autocad/selection_set.rb +61 -0
  44. data/lib/autocad/selection_set_adapter.rb +146 -0
  45. data/lib/autocad/text.rb +74 -0
  46. data/lib/autocad/version.rb +5 -0
  47. data/lib/autocad.rb +161 -0
  48. data/olegen.rb +341 -0
  49. data/rbs_collection.lock.yaml +188 -0
  50. data/rbs_collection.yaml +19 -0
  51. data/scanner.obj +0 -0
  52. data/sig/generated/autocad/app.rbs +251 -0
  53. data/sig/generated/autocad/arc.rbs +17 -0
  54. data/sig/generated/autocad/block.rbs +63 -0
  55. data/sig/generated/autocad/block_reference.rbs +59 -0
  56. data/sig/generated/autocad/drawing.rbs +158 -0
  57. data/sig/generated/autocad/element.rbs +166 -0
  58. data/sig/generated/autocad/enumerator.rbs +15 -0
  59. data/sig/generated/autocad/errors.rbs +23 -0
  60. data/sig/generated/autocad/event_handler.rbs +14 -0
  61. data/sig/generated/autocad/filter.rbs +60 -0
  62. data/sig/generated/autocad/layer.rbs +19 -0
  63. data/sig/generated/autocad/line.rbs +25 -0
  64. data/sig/generated/autocad/message_box.rbs +81 -0
  65. data/sig/generated/autocad/model.rbs +41 -0
  66. data/sig/generated/autocad/paths.rbs +19 -0
  67. data/sig/generated/autocad/point3d.rbs +66 -0
  68. data/sig/generated/autocad/selection_filter.rbs +50 -0
  69. data/sig/generated/autocad/selection_set.rbs +37 -0
  70. data/sig/generated/autocad/selection_set_adapter.rbs +28 -0
  71. data/sig/generated/autocad/text.rbs +19 -0
  72. data/sig/generated/autocad/text_node.rbs +37 -0
  73. data/sig/generated/autocad/version.rbs +5 -0
  74. data/sig/generated/autocad/viewport.rbs +11 -0
  75. data/sig/generated/autocad.rbs +68 -0
  76. data/sig/prototype/lib/autocad/app.rbs +34 -0
  77. data/sig/prototype/lib/autocad/block.rbs +5 -0
  78. data/sig/prototype/lib/autocad/block_reference.rbs +5 -0
  79. data/sig/prototype/lib/autocad/drawing.rbs +13 -0
  80. data/sig/prototype/lib/autocad/element.rbs +9 -0
  81. data/sig/prototype/lib/autocad/enumerator.rbs +5 -0
  82. data/sig/prototype/lib/autocad/event_handler.rbs +7 -0
  83. data/sig/prototype/lib/autocad/model.rbs +5 -0
  84. data/sig/prototype/lib/autocad/paths.rbs +5 -0
  85. data/sig/prototype/lib/autocad.rbs +3 -0
  86. data/temp/autocad.dwg +0 -0
  87. data/temp/autocad.log +1 -0
  88. data/temp/event_handler.log +0 -0
  89. metadata +147 -0
@@ -0,0 +1,41 @@
1
+ module Autocad
2
+ class Layer < Element
3
+ def name
4
+ ole_obj.name
5
+ end
6
+
7
+ def description
8
+ ole_obj.description
9
+ end
10
+
11
+ def lock(lk = true)
12
+ ole_obj.Lock = lk
13
+ rescue
14
+ raise Autocad::Error.new("Error locking layer #{name}")
15
+ end
16
+
17
+ def visible?
18
+ ole_obj.Visible
19
+ end
20
+
21
+ def visible=(vis)
22
+ ole_obj.Visible = vis
23
+ end
24
+
25
+ def delete
26
+ ole_obj.Delete
27
+ rescue => e
28
+ raise Autocad::Error.new("Error deleting layer #{name} #{e}")
29
+ end
30
+
31
+ def linetype=(ltname)
32
+ found_lt = app.current_drawing.linetypes.find { |lt| lt.name == ltname }
33
+
34
+ app.current_drawing.ole_obj.Linetypes.Load(ltname, ltname) unless found_lt
35
+
36
+ ole_obj.Linetype = ltname
37
+ rescue => e
38
+ raise Autocad::Error.new("Error setting linetype of layer #{name} : #{e}")
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,55 @@
1
+ # rbs_inline: enabled
2
+
3
+ require_relative 'element'
4
+
5
+ module Autocad
6
+ class Line < Element
7
+ def length
8
+ ole_obj.length
9
+ end
10
+
11
+ def line?
12
+ true
13
+ end
14
+
15
+ def start_point # : Point3d
16
+ Point3d(ole_obj.StartPoint)
17
+ end
18
+
19
+ def end_point # : Point3d
20
+ Point3d(ole_obj.EndPoint)
21
+ end
22
+
23
+ def normal
24
+ ole_obj.Normal
25
+ end
26
+
27
+ def thickness
28
+ ole_obj.Thickness
29
+ end
30
+
31
+ def delta
32
+ ole_obj.Delta
33
+ end
34
+ end
35
+
36
+ class Circle < Element
37
+ def center
38
+ Point3d.new(ole_obj.Center)
39
+ end
40
+
41
+ def radius
42
+ Point3d.new(ole_obj.Radius)
43
+ end
44
+ end
45
+
46
+ class Polyline < Element
47
+ def length
48
+ @ole_obj.Length
49
+ end
50
+
51
+ def coordinates
52
+ @ole_obj.coordinates
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,95 @@
1
+ require "fiddle/import"
2
+ require "fiddle/types"
3
+
4
+ module WinAPI
5
+ extend Fiddle::Importer
6
+ dlload "user32.dll"
7
+ include Fiddle::BasicTypes
8
+ include Fiddle::Win32Types
9
+
10
+ typealias "LPCWSTR", "wchar_t*"
11
+
12
+ extern "int MessageBoxA(HWND, LPCSTR, LPCSTR, DWORD)"
13
+ extern "int MessageBoxW(HWND, LPCWSTR, LPCWSTR, DWORD)"
14
+ # window handling
15
+ extern "HWND GetForegroundWindow()"
16
+ extern "int GetWindowText(HWND, char*, int)"
17
+ extern "int GetWindowTextLength(HWND)"
18
+
19
+ def get_foreground_window
20
+ GetForegroundWindow()
21
+ end
22
+
23
+ def self.get_text_of_active_window
24
+ hwnd = GetForegroundWindow()
25
+ buf_size = GetWindowTextLength(hwnd)
26
+ str = " " * (buf_size + 1)
27
+ GetWindowText(hwnd, str, str.length)
28
+ str.encode(Encoding.default_external)
29
+ end
30
+
31
+ module MB
32
+ OK = 1
33
+ CANCEL = 1
34
+ ABORT = 3
35
+ RETRY = 4
36
+ IGNORE = 5
37
+ YES = 6
38
+ NO = 7
39
+
40
+ module ICON
41
+ ERROR = 16
42
+ QUESTION = 32
43
+ INFORMATION = 64
44
+ WARNING = 128
45
+ end
46
+
47
+ module BTN
48
+ OK = 0
49
+ OKCANCEL = 1
50
+ ABORTRETRYIGNORE = 2
51
+ YESNO = 4
52
+ end
53
+ end
54
+ end
55
+
56
+ # msgbox_yesno('Do you want to continue?') do |y|
57
+ # if y
58
+ # puts 'proceeding with ...'
59
+ # else
60
+ # puts 'cancelled ...'
61
+ # end
62
+ # end
63
+ #
64
+ # msgbox('We are finished here')
65
+ #
66
+ # loop do
67
+ # puts WinAPI.get_text_of_active_window
68
+ # sleep 1
69
+ # end
70
+ module Kernel
71
+ module_function
72
+
73
+ # @rbs str: String
74
+ # @rbs return String
75
+ def L(str)
76
+ str.encode("UTF-16LE")
77
+ end
78
+
79
+ # @example
80
+ # msg_box_yesno("Do you want to continue") do |y|
81
+ # if y
82
+ # puts "proceeding"
83
+ # else
84
+ # puts "cancelled"
85
+ # end
86
+ # end
87
+ def msgbox_yesno(content, title: "Alert")
88
+ result = WinAPI::MessageBoxW(0, L(content), L(title), WinAPI::MB::BTN::YESNO) == WinAPI::MB::YES
89
+ yield(result)
90
+ end
91
+
92
+ def msgbox(content, title: "Alert")
93
+ WinAPI::MessageBoxW(0, L(content), L(title), WinAPI::MB::BTN::OK)
94
+ end
95
+ end
@@ -0,0 +1,89 @@
1
+ # require_relative 'scan/scan_trait'
2
+ # require_relative "model_trait"
3
+
4
+ # require_relative 'ts/tagset_trait'
5
+ # require_relative 'graphics'
6
+ # require_relative 'ts/instance'
7
+
8
+ module Autocad
9
+ module ModelTrait
10
+ def each
11
+ return enum_for(:each) unless block_given?
12
+
13
+ @ole_obj.each do |ole|
14
+ yield app.wrap(ole)
15
+ end
16
+ end
17
+
18
+ # @rbs pt1: Autocad::Point3d
19
+ # @rbs return Autocad::Line
20
+ def add_line(pt1, pt2, layer: nil)
21
+ pt1 = Point3d.new(pt1)
22
+ pt2 = Point3d.new(pt2)
23
+ ole_line = ole_obj.AddLine(pt1.to_ole, pt2.to_ole)
24
+ if layer
25
+ layer = app.create_layer(layer)
26
+ ole_line.layer = layer.ole_obj
27
+ end
28
+ app.wrap(ole_line)
29
+ rescue ex
30
+ puts ex.message
31
+ end
32
+
33
+ # @rbs center: [] | Point3d -- center of circle
34
+ # @rbs radius:
35
+ def add_circle(center, radius)
36
+ pt = Point3d(center)
37
+ ole_circle = ole_obj.AddCircle(pt.to_ole, radius)
38
+ app.wrap(ole_circle)
39
+ rescue
40
+ raise Autocad::Error.new('Error adding circle #{ex}')
41
+ end
42
+
43
+ def add_rectangle(upper_left, lower_right)
44
+ x1, y1, _z = Point3d(upper_left).to_a
45
+ x2, y2, _z2 = Point3d(lower_right)
46
+ pts = [x1, y1, x2, y1, x2, y1, x2, y2]
47
+ pts_variant = WIN32OLE::Variant.new(pts, WIN32OLE::VARIANT::VT_ARRAY | WIN32OLE::VARIANT::VT_R8)
48
+ ole = ole_obj.AddLightweightPolyline(pts_variant)
49
+ app.wrap(ole)
50
+ rescue => e
51
+ raise Autocad::Error.new("Error adding rectangle #{e}")
52
+ end
53
+
54
+ def add_spline(points)
55
+ pts = Point3d.pts_to_array(points)
56
+ pts_variant = Point3d.array_to_ole(pts)
57
+ ole = ole_obj.AddSpline(pts_variant)
58
+ puts "pts #{pts}"
59
+ puts "pts_variant #{pts_variant.class} #{pts_variant}"
60
+ app.wrap(ole)
61
+ rescue => e
62
+ raise Autocad::Error.new("Error adding spline #{e}")
63
+ end
64
+
65
+ def drawing
66
+ @drawing ||= ::Autocad::Drawing.from_ole_obj(app, ole_obj.Document)
67
+ end
68
+ end
69
+
70
+ class PaperSpace
71
+ include ModelTrait
72
+ attr_reader :app, :ole_obj
73
+
74
+ def initialize(ole, app)
75
+ @ole_obj = ole
76
+ @app = app
77
+ end
78
+ end
79
+
80
+ class ModelSpace
81
+ include ModelTrait
82
+ attr_reader :app, :ole_obj
83
+
84
+ def initialize(ole, app)
85
+ @ole_obj = ole
86
+ @app = app
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,110 @@
1
+ module Autocad
2
+ class MText < Element
3
+ attr_reader :original, :ole_obj
4
+
5
+ def to_regexp
6
+ Regexp.new(original.to_s)
7
+ end
8
+
9
+ def empty?
10
+ ole_obj.TextLinesCount == 0
11
+ end
12
+
13
+ def mtext?
14
+ true
15
+ end
16
+
17
+ def text?
18
+ false
19
+ end
20
+
21
+ def size
22
+ ole_obj.TextLinesCount
23
+ end
24
+
25
+ def read_ole(ole)
26
+ ole.TextString
27
+ end
28
+
29
+ # def _update(text)
30
+ # update_ole!(text)
31
+ # @original = text
32
+ # end
33
+
34
+ def write_ole(text)
35
+ if in_cell?
36
+ write_ole_in_cell(text)
37
+ else
38
+ write_ole_regular(text)
39
+ end
40
+ end
41
+
42
+ def write_ole_regular(text)
43
+ ole_obj.TextString = text
44
+ end
45
+
46
+ def write_ole_in_cell(text)
47
+ orig_ole = ole_obj
48
+ new_text_ole = ole_obj.Clone
49
+ new_text_ole.DeleteAllTextLines
50
+ text.each_line do |line|
51
+ new_text_ole.AddTextLine(line)
52
+ end
53
+ @ole_obj = new_text_ole
54
+ rescue
55
+ @ole_obj = orig_ole
56
+ end
57
+
58
+ def update_ole!(text)
59
+ ole_obj.DeleteAllTextLines
60
+ text.each_line do |line|
61
+ ole_obj.AddTextLine(line)
62
+ end
63
+ ole_obj.Redraw Autocad::MSD::MsdDrawingModeNormal
64
+ ole_obj.Rewrite
65
+ end
66
+
67
+ def to_s
68
+ @original.to_s
69
+ end
70
+
71
+ def =~(reg)
72
+ @original =~ reg
73
+ end
74
+
75
+ def template?
76
+ !!(@original =~ /{{.+}}/)
77
+ end
78
+
79
+ def render(h = {})
80
+ return self unless template?
81
+
82
+ template = Liquid::Template.parse(to_s)
83
+ result = template.render(h)
84
+ update(result) unless result == @original
85
+ self
86
+ end
87
+
88
+ def method_missing(meth, *, &)
89
+ if /^[A-Z]/.match?(meth)
90
+ ole_obj.send(meth, *)
91
+ else
92
+ copy = @original.dup
93
+ result = copy.send(meth, *, &)
94
+ update(result) unless copy == @original
95
+ result
96
+ end
97
+ end
98
+
99
+ # def method_missing2(meth,*args,&block)
100
+ # if meth.to_s =~ /^[A-Z]/
101
+ # ole_obj.send(meth,*args)
102
+ # else
103
+ # dup = @original.dup
104
+ # result = dup.send(meth,*args,&block)
105
+ # _update(dup) unless dup == @original
106
+ # result
107
+ # end
108
+ # end
109
+ end
110
+ end
@@ -0,0 +1,29 @@
1
+ module Autocad
2
+ class Paths
3
+ include Enumerable
4
+
5
+ def initialize(path)
6
+ @paths = path.split(";").map { |p| Pathname(p) }
7
+ end
8
+
9
+ def <<(path)
10
+ @paths << Path(path)
11
+ end
12
+
13
+ def append(path)
14
+ @paths.append Path(path)
15
+ end
16
+
17
+ def prepend(path)
18
+ paths.prepend Path(path)
19
+ end
20
+
21
+ def each(...)
22
+ paths.each(...)
23
+ end
24
+
25
+ def to_s
26
+ parhs.join(";")
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,143 @@
1
+ # rbs_inline: enabled
2
+
3
+ module Autocad
4
+ class Point3d
5
+ class << self
6
+ def cartesian_to_polar(x, y)
7
+ r = Math.sqrt(x * x + y * y)
8
+ angle = Angle.radians(Math.atan2(y, x))
9
+ [r, angle]
10
+ end
11
+
12
+ def from_polar_degrees(r, a)
13
+ end
14
+
15
+ def from_ole(ole)
16
+ new(ole.X, ole.Y, ole.Z)
17
+ end
18
+
19
+ def polar_to_cartesian(r, a)
20
+ end
21
+
22
+ # convert array of points to array of x,y coordinates
23
+ # array can be [ Point3d, Point3d, ..]
24
+ # array can be [ [x,y,z], [x,y,z], [x,y,z] ..]
25
+ # array can be [x,y, x1, y1, x2,y2, x3,y3]
26
+ # array can be [[x,y], [x2,y2], [x3,y3]]
27
+ # all coordinates are converted to float
28
+ # z coordinates are ignored
29
+ # @rbs return Array[Float]
30
+ def pts_to_array(pts)
31
+ case pts.first
32
+ when Point3d
33
+ pts.flat_map(&:to_xy)
34
+ when Array
35
+ pts.flat_map { |pt| [pt[0].to_f, pt[1].to_f] }
36
+ when Numeric
37
+ pts.each_slice(2).flat_map { |x, y| [x.to_f, y.to_f] }
38
+ end
39
+ end
40
+
41
+ def array_to_ole(ar)
42
+ WIN32OLE::Variant.new(ar, WIN32OLE::VARIANT::VT_ARRAY | WIN32OLE::VARIANT::VT_R8)
43
+ end
44
+ end
45
+
46
+ attr_reader :x, :y, :z
47
+
48
+ def initialize(_x = nil, _y = nil, _z = nil, x: _x, y: _y, z: _z)
49
+ case [x, y, z]
50
+ in [Point3d, y, z]
51
+ @x = x.x
52
+ @y = x.y
53
+ @z = x.z
54
+ in [Array, nil, nil]
55
+ @x = x[0].to_f
56
+ @y = x[1].to_f
57
+ @z = x[2].to_f
58
+ in [Float, Float, Float]
59
+ @x = x
60
+ @y = y
61
+ @z = z
62
+ else
63
+ @x = x.to_f || 0.0
64
+ @y = y.to_f || 0.0
65
+ @z = z.to_f || 0.0
66
+ end
67
+ end
68
+
69
+ # @rbs other: Point3d | [Float,Float,Float]
70
+ def +(other) # : Point3d
71
+ case other
72
+ when Point3d
73
+ self.class.new(x + other.x, y + other.y, z + other.z)
74
+ when Array
75
+ self.class.new(x + other[0], y + other[1])
76
+ end
77
+ end
78
+
79
+ def distance_to(other)
80
+ pt2 = Point3d.new(other)
81
+ Math.sqrt((x - pt2.x)**2 + (y - pt2.y)**2 + (z - pt2.z)**2)
82
+ end
83
+
84
+ # @rbs return [Float,Float, Float]
85
+ def deconstruct
86
+ [@x, @y, @z]
87
+ end
88
+
89
+ # @rbs return { x: Float, y: Float, z: Float}
90
+ def deconstruct_keys
91
+ {x: @x, y: @y, z: @z}
92
+ end
93
+
94
+ # @rbs return [Float,Float, Float]
95
+ def to_ary
96
+ [x, y, z]
97
+ end
98
+
99
+ # @rbs other: Point3d | [Float,Float,Float]
100
+ def -(other) # : Point3d
101
+ case other
102
+ when Point3d
103
+ self.class.new(x - other.x, y - other.y, z - other.z)
104
+ when Array
105
+ self.class.new(x - other[0], y - other[1])
106
+ end
107
+ end
108
+
109
+ def to_xy
110
+ [x, y]
111
+ end
112
+
113
+ def xy_bounds(other)
114
+ x2, y2 = Points3d.new(other).to_xy
115
+ [x, y, x2, y, x2, y2, x, y2, x, y]
116
+ end
117
+
118
+ def to_s
119
+ "Point3d(#{x}, #{y}, #{z})"
120
+ end
121
+
122
+ # @rbs return [Float,Float, Float]
123
+ def to_a
124
+ [x, y, z]
125
+ end
126
+
127
+ # @rbs return Point3d -- return a Point3d at [0,0,0]
128
+ def zero
129
+ new(0.0, 0.0, 0, 0)
130
+ end
131
+
132
+ def to_cartesian
133
+ end
134
+
135
+ def to_ole
136
+ ole = WIN32OLE::Variant.array([3], WIN32OLE::VARIANT::VT_R8)
137
+ ole[0] = x
138
+ ole[1] = y
139
+ ole[z] = z
140
+ ole
141
+ end
142
+ end
143
+ end
@@ -0,0 +1,21 @@
1
+ require_relative "element"
2
+
3
+ module Autocad
4
+ class PViewport < Element
5
+ def width
6
+ @ole_obj.Width
7
+ end
8
+
9
+ def height
10
+ @ole_obj.Height
11
+ end
12
+
13
+ def each
14
+ return enum_for(:each) unless block_given?
15
+
16
+ @ole_obj.each do |ole|
17
+ yield app.wrap(ole)
18
+ end
19
+ end
20
+ end
21
+ end