autocad 0.4.6 → 0.5

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 (83) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop/minitest.yml +2 -2
  3. data/.rubocop/strict.yml +4 -4
  4. data/.rubocop.yml +36 -33
  5. data/CHANGELOG.md +5 -5
  6. data/LICENSE.txt +21 -21
  7. data/README.md +134 -39
  8. data/Rakefile +26 -10
  9. data/exe/autocad +3 -3
  10. data/gemfiles/rubocop.gemfile +2 -1
  11. data/lib/autocad/app.rb +127 -28
  12. data/lib/autocad/arc.rb +3 -0
  13. data/lib/autocad/block.rb +11 -6
  14. data/lib/autocad/block_reference.rb +33 -4
  15. data/lib/autocad/bounding_box.rb +202 -0
  16. data/lib/autocad/dim_style.rb +4 -0
  17. data/lib/autocad/drawing.rb +873 -172
  18. data/lib/autocad/element.rb +217 -25
  19. data/lib/autocad/errors.rb +9 -0
  20. data/lib/autocad/filter.rb +502 -168
  21. data/lib/autocad/layer.rb +129 -41
  22. data/lib/autocad/layout.rb +120 -0
  23. data/lib/autocad/line.rb +154 -55
  24. data/lib/autocad/message_box.rb +95 -95
  25. data/lib/autocad/model.rb +217 -89
  26. data/lib/autocad/mtext.rb +189 -110
  27. data/lib/autocad/plot.rb +45 -0
  28. data/lib/autocad/plot_configuration.rb +372 -0
  29. data/lib/autocad/point.rb +7 -0
  30. data/lib/autocad/point3d.rb +18 -11
  31. data/lib/autocad/pviewport.rb +136 -21
  32. data/lib/autocad/selection_filter.rb +358 -180
  33. data/lib/autocad/selection_set.rb +140 -61
  34. data/lib/autocad/selection_set_adapter.rb +187 -8
  35. data/lib/autocad/spline.rb +27 -0
  36. data/lib/autocad/text.rb +66 -11
  37. data/lib/autocad/text_style.rb +4 -0
  38. data/lib/autocad/version.rb +1 -1
  39. data/lib/autocad/viewport.rb +57 -0
  40. data/lib/autocad.rb +126 -30
  41. data/lib/faa/cleanup.rb +137 -0
  42. data/lib/win32ole_helper.rb +52 -0
  43. data/rbs_collection.lock.yaml +38 -18
  44. data/sig/generated/autocad/app.rbs +278 -251
  45. data/sig/generated/autocad/arc.rbs +6 -3
  46. data/sig/generated/autocad/block.rbs +8 -5
  47. data/sig/generated/autocad/block_reference.rbs +99 -59
  48. data/sig/generated/autocad/bounding_box.rbs +78 -0
  49. data/sig/generated/autocad/dim_style.rbs +6 -0
  50. data/sig/generated/autocad/drawing.rbs +597 -158
  51. data/sig/generated/autocad/element.rbs +233 -166
  52. data/sig/generated/autocad/errors.rbs +29 -23
  53. data/sig/generated/autocad/filter.rbs +388 -60
  54. data/sig/generated/autocad/layer.rbs +76 -19
  55. data/sig/generated/autocad/layout.rbs +64 -0
  56. data/sig/generated/autocad/line.rbs +128 -25
  57. data/sig/generated/autocad/message_box.rbs +81 -81
  58. data/sig/generated/autocad/model.rbs +115 -41
  59. data/sig/generated/autocad/mtext.rbs +123 -0
  60. data/sig/generated/autocad/plot.rbs +26 -0
  61. data/sig/generated/autocad/plot_configuration.rbs +176 -0
  62. data/sig/generated/autocad/point.rbs +7 -0
  63. data/sig/generated/autocad/point3d.rbs +70 -66
  64. data/sig/generated/autocad/pviewport.rbs +64 -0
  65. data/sig/generated/autocad/selection_filter.rbs +226 -50
  66. data/sig/generated/autocad/selection_set.rbs +112 -37
  67. data/sig/generated/autocad/selection_set_adapter.rbs +235 -28
  68. data/sig/generated/autocad/spline.rbs +22 -0
  69. data/sig/generated/autocad/text.rbs +66 -7
  70. data/sig/generated/autocad/text_style.rbs +6 -0
  71. data/sig/generated/autocad/viewport.rbs +19 -2
  72. data/sig/generated/autocad.rbs +140 -68
  73. data/sig/generated/faa/cleanup.rbs +53 -0
  74. data/sig/generated/win32ole_helper.rbs +9 -0
  75. data/sig/prototype/lib/autocad/app.rbs +3 -1
  76. data/sig/prototype/lib/autocad/bounding_box.rbs +15 -0
  77. data/sig/prototype/lib/autocad/drawing.rbs +6 -0
  78. data/sig/prototype/lib/autocad/layer.rbs +5 -0
  79. data/sig/prototype/lib/autocad/viewport.rbs +7 -0
  80. data/sig/prototype/lib/autocad.rbs +1 -1
  81. metadata +29 -5
  82. data/event_handler.log +0 -24
  83. data/sig/generated/autocad/text_node.rbs +0 -37
data/lib/autocad/block.rb CHANGED
@@ -12,23 +12,28 @@ module Autocad
12
12
  end
13
13
  end
14
14
 
15
- def attributes? # : bool
15
+ # @rbs return bool
16
+ def block? # : bool
17
+ true
18
+ end
19
+
20
+ def attributes? #:bool
16
21
  @ole_obj.HasAttributes
17
22
  end
18
23
 
19
- def name # : String
24
+ def name #:String
20
25
  @ole_obj.Name
21
26
  end
22
27
 
23
- def layout? # : bool
28
+ def layout? #:bool
24
29
  @ole_obj.IsLayout
25
30
  end
26
31
 
27
- def xref? # : bool
32
+ def xref? #:bool
28
33
  @ole_obj.IsXRef
29
34
  end
30
35
 
31
- def dynamic? # : bool
36
+ def dynamic? #:bool
32
37
  @ole_obj.IsDynamicBlock
33
38
  end
34
39
 
@@ -49,7 +54,7 @@ module Autocad
49
54
  end
50
55
 
51
56
  def inspect
52
- "<Block #{block_type}: '#{name}#' #{autocad_id}>"
57
+ "<Block #{block_type}: '#{name}#'"
53
58
  end
54
59
 
55
60
  def attributes
@@ -1,4 +1,4 @@
1
- require_relative 'element'
1
+ require_relative "element"
2
2
 
3
3
  module Autocad
4
4
  class BlockReference < Element
@@ -6,6 +6,17 @@ module Autocad
6
6
  true
7
7
  end
8
8
 
9
+ def explode
10
+ return enum_for(__callee__) unless block_given?
11
+
12
+ ole = ole_obj.explode
13
+ ole.each do |ole|
14
+ yield app.wrap(ole)
15
+ end
16
+ rescue => e
17
+ binding.irb
18
+ end
19
+
9
20
  def each
10
21
  return enum_for(:each) unless block_given?
11
22
 
@@ -18,9 +29,15 @@ module Autocad
18
29
  false
19
30
  end
20
31
 
32
+ def get_block_extents
33
+ min_point = ole_obj.GeometricExtents.MinPoint
34
+ max_point = ole_obj.GeometricExtents.MaxPoint
35
+ BoundingBox.from_min_max(min_point, max_point)
36
+ end
37
+
21
38
  def insertion_point
22
39
  Point3d(ole_obj.InsertionPoint)
23
- rescue StandardError
40
+ rescue
24
41
  Autocad::Error.new("error getting insertion point of block #{name}")
25
42
  end
26
43
 
@@ -36,6 +53,11 @@ module Autocad
36
53
  @ole_obj.Name
37
54
  end
38
55
 
56
+ def scale_by(amt)
57
+ @ole_obj.XScaleFactor = amt
58
+ @ole_obj.YScaleFactor = amt
59
+ end
60
+
39
61
  def x_scale_factor
40
62
  @ole_obj.XScaleFactor
41
63
  end
@@ -62,6 +84,8 @@ module Autocad
62
84
 
63
85
  def layout?
64
86
  @ole_obj.IsLayout
87
+ rescue
88
+ false
65
89
  end
66
90
 
67
91
  def attribute_hash
@@ -71,7 +95,7 @@ module Autocad
71
95
  end
72
96
 
73
97
  def inspect
74
- "<BlockReference: #{autocad_id}>"
98
+ "<BlockReference: name:#{name}>"
75
99
  end
76
100
 
77
101
  def attributes
@@ -89,6 +113,11 @@ module Autocad
89
113
  true
90
114
  end
91
115
 
116
+ # @rbs return Pathname -- the path of the external reference
117
+ def path
118
+ Pathname(ole_obj.Path)
119
+ end
120
+
92
121
  def ins_units
93
122
  @ole_obj.InsUnits
94
123
  end
@@ -98,7 +127,7 @@ module Autocad
98
127
  end
99
128
 
100
129
  def inspect
101
- "<ExternalReference: #{autocad_id}>"
130
+ "<ExternalReference: name: #{name}>"
102
131
  end
103
132
  end
104
133
 
@@ -0,0 +1,202 @@
1
+ module Autocad
2
+ # A BoundingBox represents a bounding box around a picture.
3
+ #
4
+ # A bounding box also defines a local coordinate system for a picture. The
5
+ # bounding box must contain the origin of the coordinate system. However the
6
+ # origin need not be centered within the box.
7
+ #
8
+ # No particular guarantees are made about the tightness of the bounding box,
9
+ # though it can assumed to be reasonably tight.
10
+ class BoundingBox
11
+ class << self
12
+ def empty
13
+ new(0, 0, 0, 0)
14
+ end
15
+
16
+ # Create a BoundingBox with the given width and height and
17
+ # the origin centered within the box.
18
+ def centered(width, height)
19
+ w = width / 2.0
20
+ h = height / 2.0
21
+ new(-w, h, w, -h)
22
+ end
23
+
24
+ # Create a BoundingBox from minimum and maximum points
25
+ def from_min_max(min_pt, max_pt)
26
+ min_pt = Point3d.new(min_pt)
27
+ max_pt = Point3d.new(max_pt)
28
+
29
+ new(
30
+ min_pt.x, # left
31
+ max_pt.y, # top
32
+ max_pt.x, # right
33
+ min_pt.y # bottom
34
+ )
35
+ end
36
+ end
37
+
38
+ attr_reader :left, :top, :right, :bottom
39
+
40
+ def initialize(left, top, right, bottom)
41
+ @left = left
42
+ @top = top
43
+ @right = right
44
+ @bottom = bottom
45
+ end
46
+
47
+ def hash
48
+ [self.class, left, top, right, bottom].hash
49
+ end
50
+
51
+ def eql?(other)
52
+ other.class == self.class &&
53
+ other.left == left &&
54
+ other.top == top &&
55
+ other.right == right &&
56
+ other.bottom == bottom
57
+ end
58
+
59
+ def ==(other)
60
+ return false unless other.is_a?(BoundingBox)
61
+
62
+ left.round(6) == other.left.round(6) &&
63
+ top.round(6) == other.top.round(6) &&
64
+ right.round(6) == other.right.round(6) &&
65
+ bottom.round(6) == other.bottom.round(6)
66
+ end
67
+
68
+ def upper_right
69
+ Point3d.new(right, top, 0)
70
+ end
71
+
72
+ alias_method :top_right, :upper_right
73
+
74
+ def lower_left
75
+ Point3d.new(left, bottom, 0)
76
+ end
77
+
78
+ alias_method :bottom_left, :lower_left
79
+
80
+ def center
81
+ Point3d.new((left + right) / 2.0, (top + bottom) / 2.0, 0)
82
+ end
83
+
84
+ def contains?(pt)
85
+ pt.x >= left && pt.x <= right && pt.y >= bottom && pt.y <= top
86
+ end
87
+
88
+ def width
89
+ right - left
90
+ end
91
+
92
+ def height
93
+ top - bottom
94
+ end
95
+
96
+ def on(other)
97
+ self.class.new(
98
+ [left, other.left].min,
99
+ [top, other.top].max,
100
+ [right, other.right].max,
101
+ [bottom, other.bottom].min
102
+ )
103
+ end
104
+
105
+ def beside(other)
106
+ self.class.new(
107
+ -(width + other.width) / 2.0,
108
+ [top, other.top].max,
109
+ (width + other.width) / 2.0,
110
+ [bottom, other.bottom].min
111
+ )
112
+ end
113
+
114
+ def above(other)
115
+ self.class.new(
116
+ [left, other.left].min,
117
+ (height + other.height) / 2.0,
118
+ [right, other.right].max,
119
+ -(height + other.height) / 2.0
120
+ )
121
+ end
122
+
123
+ # Evaluate the landmark relative to the origin of this bounding box,
124
+ # returning the location described by the landmark.
125
+ def eval(landmark)
126
+ Point3d.new(
127
+ landmark.x.eval(left, right),
128
+ landmark.y.eval(bottom, top),
129
+ 0
130
+ )
131
+ end
132
+
133
+ def at(point)
134
+ x = point.x
135
+ y = point.y
136
+
137
+ new_left = [left + x, 0].min
138
+ new_top = [top + y, 0].max
139
+ new_right = [right + x, 0].max
140
+ new_bottom = [bottom + y, 0].min
141
+
142
+ self.class.new(new_left, new_top, new_right, new_bottom)
143
+ end
144
+
145
+ def at_landmark(landmark)
146
+ at(eval(landmark))
147
+ end
148
+
149
+ def origin_at(point)
150
+ # Vector maths to work out where the edges of the bounding box lie in
151
+ # relation to the new origin
152
+ new_top_left = Point3d.new(left, top, 0) - point
153
+ new_bottom_right = Point3d.new(right, bottom, 0) - point
154
+
155
+ # Make sure the bounding box includes the origin
156
+ new_left = [new_top_left.x, 0].min
157
+ new_top = [new_top_left.y, 0].max
158
+ new_right = [new_bottom_right.x, 0].max
159
+ new_bottom = [new_bottom_right.y, 0].min
160
+
161
+ self.class.new(new_left, new_top, new_right, new_bottom)
162
+ end
163
+
164
+ def origin_at_landmark(landmark)
165
+ origin_at(eval(landmark))
166
+ end
167
+
168
+ # Expand bounding box to enclose the given Point
169
+ def enclose(point)
170
+ self.class.new(
171
+ [left, point.x].min,
172
+ [top, point.y].max,
173
+ [right, point.x].max,
174
+ [bottom, point.y].min
175
+ )
176
+ end
177
+
178
+ def scale_to_fit(bb)
179
+ return 1 if bb.width == 0 || bb.height == 0
180
+
181
+ [width / bb.width, height / bb.height].min
182
+ end
183
+
184
+ # Add expansion to all sides of this bounding box
185
+ def expand(expansion)
186
+ self.class.new(
187
+ left - expansion,
188
+ top + expansion,
189
+ right + expansion,
190
+ bottom - expansion
191
+ )
192
+ end
193
+
194
+ def transform(transform)
195
+ self.class.empty
196
+ .enclose(transform.call(Point3d.new(left, top, 0)))
197
+ .enclose(transform.call(Point3d.new(right, top, 0)))
198
+ .enclose(transform.call(Point3d.new(left, bottom, 0)))
199
+ .enclose(transform.call(Point3d.new(right, bottom, 0)))
200
+ end
201
+ end
202
+ end
@@ -0,0 +1,4 @@
1
+ module Autocad
2
+ class DimStyle < Element
3
+ end
4
+ end