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.
- checksums.yaml +4 -4
- data/.rubocop/minitest.yml +2 -2
- data/.rubocop/strict.yml +4 -4
- data/.rubocop.yml +36 -33
- data/CHANGELOG.md +5 -5
- data/LICENSE.txt +21 -21
- data/README.md +134 -39
- data/Rakefile +26 -10
- data/exe/autocad +3 -3
- data/gemfiles/rubocop.gemfile +2 -1
- data/lib/autocad/app.rb +127 -28
- data/lib/autocad/arc.rb +3 -0
- data/lib/autocad/block.rb +11 -6
- data/lib/autocad/block_reference.rb +33 -4
- data/lib/autocad/bounding_box.rb +202 -0
- data/lib/autocad/dim_style.rb +4 -0
- data/lib/autocad/drawing.rb +873 -172
- data/lib/autocad/element.rb +217 -25
- data/lib/autocad/errors.rb +9 -0
- data/lib/autocad/filter.rb +502 -168
- data/lib/autocad/layer.rb +129 -41
- data/lib/autocad/layout.rb +120 -0
- data/lib/autocad/line.rb +154 -55
- data/lib/autocad/message_box.rb +95 -95
- data/lib/autocad/model.rb +217 -89
- data/lib/autocad/mtext.rb +189 -110
- data/lib/autocad/plot.rb +45 -0
- data/lib/autocad/plot_configuration.rb +372 -0
- data/lib/autocad/point.rb +7 -0
- data/lib/autocad/point3d.rb +18 -11
- data/lib/autocad/pviewport.rb +136 -21
- data/lib/autocad/selection_filter.rb +358 -180
- data/lib/autocad/selection_set.rb +140 -61
- data/lib/autocad/selection_set_adapter.rb +187 -8
- data/lib/autocad/spline.rb +27 -0
- data/lib/autocad/text.rb +66 -11
- data/lib/autocad/text_style.rb +4 -0
- data/lib/autocad/version.rb +1 -1
- data/lib/autocad/viewport.rb +57 -0
- data/lib/autocad.rb +126 -30
- data/lib/faa/cleanup.rb +137 -0
- data/lib/win32ole_helper.rb +52 -0
- data/rbs_collection.lock.yaml +38 -18
- data/sig/generated/autocad/app.rbs +278 -251
- data/sig/generated/autocad/arc.rbs +6 -3
- data/sig/generated/autocad/block.rbs +8 -5
- data/sig/generated/autocad/block_reference.rbs +99 -59
- data/sig/generated/autocad/bounding_box.rbs +78 -0
- data/sig/generated/autocad/dim_style.rbs +6 -0
- data/sig/generated/autocad/drawing.rbs +597 -158
- data/sig/generated/autocad/element.rbs +233 -166
- data/sig/generated/autocad/errors.rbs +29 -23
- data/sig/generated/autocad/filter.rbs +388 -60
- data/sig/generated/autocad/layer.rbs +76 -19
- data/sig/generated/autocad/layout.rbs +64 -0
- data/sig/generated/autocad/line.rbs +128 -25
- data/sig/generated/autocad/message_box.rbs +81 -81
- data/sig/generated/autocad/model.rbs +115 -41
- data/sig/generated/autocad/mtext.rbs +123 -0
- data/sig/generated/autocad/plot.rbs +26 -0
- data/sig/generated/autocad/plot_configuration.rbs +176 -0
- data/sig/generated/autocad/point.rbs +7 -0
- data/sig/generated/autocad/point3d.rbs +70 -66
- data/sig/generated/autocad/pviewport.rbs +64 -0
- data/sig/generated/autocad/selection_filter.rbs +226 -50
- data/sig/generated/autocad/selection_set.rbs +112 -37
- data/sig/generated/autocad/selection_set_adapter.rbs +235 -28
- data/sig/generated/autocad/spline.rbs +22 -0
- data/sig/generated/autocad/text.rbs +66 -7
- data/sig/generated/autocad/text_style.rbs +6 -0
- data/sig/generated/autocad/viewport.rbs +19 -2
- data/sig/generated/autocad.rbs +140 -68
- data/sig/generated/faa/cleanup.rbs +53 -0
- data/sig/generated/win32ole_helper.rbs +9 -0
- data/sig/prototype/lib/autocad/app.rbs +3 -1
- data/sig/prototype/lib/autocad/bounding_box.rbs +15 -0
- data/sig/prototype/lib/autocad/drawing.rbs +6 -0
- data/sig/prototype/lib/autocad/layer.rbs +5 -0
- data/sig/prototype/lib/autocad/viewport.rbs +7 -0
- data/sig/prototype/lib/autocad.rbs +1 -1
- metadata +29 -5
- data/event_handler.log +0 -24
- data/sig/generated/autocad/text_node.rbs +0 -37
data/lib/autocad/element.rb
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
# rbs_inline: enabled
|
2
|
-
|
2
|
+
require_relative "bounding_box"
|
3
|
+
require "win32ole_helper"
|
3
4
|
# require "autocad/property_handler"
|
4
5
|
|
5
6
|
class WIN32OLE
|
7
|
+
def ole_respond_to?(name)
|
8
|
+
ole_methods.any? { |m| m.name.casecmp?(name.to_s) }
|
9
|
+
end
|
10
|
+
|
6
11
|
def to_ole
|
7
12
|
self
|
8
13
|
end
|
@@ -45,75 +50,231 @@ module Autocad
|
|
45
50
|
def move_to
|
46
51
|
end
|
47
52
|
|
48
|
-
def update
|
49
|
-
end
|
50
|
-
|
51
53
|
def transform_by(matrix)
|
52
54
|
end
|
53
55
|
end
|
54
56
|
|
55
57
|
module ElementTrait
|
58
|
+
# Get the parent drawing of this element
|
59
|
+
# @rbs return Drawing?
|
60
|
+
def drawing
|
61
|
+
app.current_drawing
|
62
|
+
end
|
63
|
+
|
64
|
+
# Check if this element is a paper space viewport
|
65
|
+
# @rbs return bool
|
66
|
+
def pviewport?
|
67
|
+
false
|
68
|
+
end
|
69
|
+
|
70
|
+
# Check if this element is a block reference
|
71
|
+
# @rbs return bool
|
56
72
|
def block_reference?
|
57
73
|
false
|
58
74
|
end
|
59
75
|
|
76
|
+
# def bounds
|
77
|
+
# minpoint = WIN32OLE::Variant.new([0.0, 0.0, 0.0], WIN32OLE::VARIANT::VT_ARRAY | WIN32OLE::VARIANT::VT_R8)
|
78
|
+
# maxpoint = WIN32OLE::Variant.new([0.0, 0.0, 0.0], WIN32OLE::VARIANT::VT_ARRAY | WIN32OLE::VARIANT::VT_R8)
|
60
79
|
#
|
80
|
+
# ole_obj.GetBoundingBox(minpoint, maxpoint)
|
81
|
+
#
|
82
|
+
# min_pt = Point3d.new(minpoint[0], minpoint[1], minpoint[2])
|
83
|
+
# max_pt = Point3d.new(maxpoint[0], maxpoint[1], maxpoint[2])
|
84
|
+
#
|
85
|
+
# BoundingBox.from_min_max(min_pt, max_pt)
|
86
|
+
# rescue => e
|
87
|
+
# raise Autocad::Error.new("Error getting bounds: #{e.message}")
|
88
|
+
# end
|
89
|
+
|
90
|
+
def bounds
|
91
|
+
# For testing purposes, check if we're in a test environment
|
92
|
+
# This is a workaround for the test environment where we don't have actual OLE objects
|
93
|
+
|
94
|
+
begin
|
95
|
+
if ole_obj.ole_respond_to?(:GetBoundingBox)
|
96
|
+
# Create VARIANT objects for output parameters
|
97
|
+
minpoint = WIN32OLE::Variant.new(nil, WIN32OLE::VARIANT::VT_VARIANT | WIN32OLE::VARIANT::VT_BYREF)
|
98
|
+
maxpoint = WIN32OLE::Variant.new(nil, WIN32OLE::VARIANT::VT_VARIANT | WIN32OLE::VARIANT::VT_BYREF)
|
99
|
+
# Last resort - try GetBoundingBox if available
|
100
|
+
|
101
|
+
|
102
|
+
# Get the bounding box coordinates
|
103
|
+
ole_obj.GetBoundingBox(minpoint, maxpoint)
|
104
|
+
|
105
|
+
|
106
|
+
# Convert the VARIANT arrays to Point3d objects
|
107
|
+
min_pt = Point3d.new(minpoint.value[0], minpoint.value[1], minpoint.value[2])
|
108
|
+
max_pt = Point3d.new(maxpoint.value[0], maxpoint.value[1], maxpoint.value[2])
|
109
|
+
|
110
|
+
|
111
|
+
BoundingBox.from_min_max(min_pt, max_pt)
|
112
|
+
# Try different approaches based on object type
|
113
|
+
elsif ole_obj.ole_respond_to?(:Coordinates)
|
114
|
+
# For objects like lines that have Coordinates property
|
115
|
+
coords = ole_obj.Coordinates
|
116
|
+
|
117
|
+
# Find min and max values
|
118
|
+
x_values = []
|
119
|
+
y_values = []
|
120
|
+
z_values = []
|
121
|
+
|
122
|
+
(0...coords.size).step(3) do |i|
|
123
|
+
x_values << coords[i]
|
124
|
+
y_values << coords[i + 1]
|
125
|
+
z_values << coords[i + 2] if i + 2 < coords.size
|
126
|
+
end
|
127
|
+
puts ole_obj.ObjectName
|
128
|
+
binding.irb
|
129
|
+
|
130
|
+
min_pt = Point3d.new(x_values.min, y_values.min, z_values.min || 0)
|
131
|
+
max_pt = Point3d.new(x_values.max, y_values.max, z_values.max || 0)
|
132
|
+
binding.irb
|
133
|
+
|
134
|
+
BoundingBox.from_min_max(min_pt, max_pt)
|
135
|
+
elsif ole_obj.ole_respond_to?(:Center) && ole_obj.respond_to?(:Radius)
|
136
|
+
# For circles
|
137
|
+
center = Point3d.new(ole_obj.Center)
|
138
|
+
radius = ole_obj.Radius
|
139
|
+
|
140
|
+
min_pt = Point3d.new(center.x - radius, center.y - radius, center.z)
|
141
|
+
max_pt = Point3d.new(center.x + radius, center.y + radius, center.z)
|
142
|
+
binding.irb
|
143
|
+
|
144
|
+
BoundingBox.from_min_max(min_pt, max_pt)
|
145
|
+
elsif ole_obj.ole_respond_to?(:StartPoint) && ole_obj.respond_to?(:EndPoint)
|
146
|
+
# For lines with start and end points
|
147
|
+
start_pt = Point3d.new(ole_obj.StartPoint)
|
148
|
+
end_pt = Point3d.new(ole_obj.EndPoint)
|
149
|
+
puts ole_obj.ObjectName
|
150
|
+
|
151
|
+
binding.irb
|
152
|
+
|
153
|
+
min_x = [start_pt.x, end_pt.x].min
|
154
|
+
min_y = [start_pt.y, end_pt.y].min
|
155
|
+
min_z = [start_pt.z, end_pt.z].min
|
156
|
+
|
157
|
+
max_x = [start_pt.x, end_pt.x].max
|
158
|
+
max_y = [start_pt.y, end_pt.y].max
|
159
|
+
max_z = [start_pt.z, end_pt.z].max
|
160
|
+
|
161
|
+
min_pt = Point3d.new(min_x, min_y, min_z)
|
162
|
+
max_pt = Point3d.new(max_x, max_y, max_z)
|
163
|
+
|
164
|
+
binding.irb
|
165
|
+
|
166
|
+
BoundingBox.from_min_max(min_pt, max_pt)
|
167
|
+
else
|
168
|
+
binding.irb
|
169
|
+
nil
|
170
|
+
# If we can't determine bounds, create a default bounding box
|
171
|
+
# This is better than raising an error in many cases
|
172
|
+
end
|
173
|
+
rescue => e
|
174
|
+
puts e.message
|
175
|
+
binding.irb
|
176
|
+
load "win32ole_helper"
|
177
|
+
ole_obj.extend WIN32OLE::Helper
|
178
|
+
load "autocad\element.rb"
|
179
|
+
retry
|
180
|
+
# If all methods fail, return an empty bounding box instead of raising an error
|
181
|
+
# This makes the code more robust when dealing with various object types
|
182
|
+
nil
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
61
186
|
#
|
62
187
|
#
|
63
|
-
# @rbs return bool -- true if ole type is Text
|
64
188
|
#
|
189
|
+
#
|
190
|
+
# @rbs return bool -- true if ole type is Text
|
191
|
+
# def text?
|
192
|
+
# Check if this element is a text object
|
193
|
+
# @rbs return bool
|
65
194
|
def text?
|
66
195
|
ole_obj.ole_type == "IAcadText"
|
67
196
|
end
|
68
197
|
|
69
|
-
#
|
70
|
-
|
71
|
-
|
198
|
+
# Explode this element into its component parts
|
199
|
+
# @rbs &: (Element) -> void
|
200
|
+
# @rbs return Enumerator[Element]
|
201
|
+
def explode
|
202
|
+
return enum_for(__callee__) unless block_given?
|
203
|
+
|
204
|
+
ole = ole_obj.explode
|
205
|
+
ole.each do |ole|
|
206
|
+
yield app.wrap(ole)
|
207
|
+
end
|
208
|
+
rescue => e
|
209
|
+
binding.irb
|
72
210
|
end
|
73
211
|
|
212
|
+
# Check if this element has any tags
|
213
|
+
# @rbs return bool
|
74
214
|
def has_tags?
|
75
215
|
ole_obj.HasAnyTags
|
76
216
|
end
|
77
217
|
|
218
|
+
# Get the underlying OLE object
|
219
|
+
# @rbs return WIN32OLE
|
78
220
|
def to_ole
|
79
221
|
ole_obj
|
80
222
|
end
|
81
223
|
|
82
|
-
#
|
224
|
+
# Check if this element is a cell
|
225
|
+
# @rbs return bool
|
83
226
|
def cell?
|
84
227
|
ole_obj.Type == ::ACAD::MsdElementTypeCellHeader
|
85
228
|
end
|
86
229
|
|
87
|
-
#
|
88
|
-
#
|
89
|
-
#
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
text? || mtext?
|
230
|
+
# Highlight this element in the drawing
|
231
|
+
# @rbs flag: bool
|
232
|
+
# @rbs return void
|
233
|
+
def highlight(flag = true)
|
234
|
+
ole_obj.Highlight(flag)
|
235
|
+
ole_obj.Update
|
94
236
|
end
|
95
237
|
|
238
|
+
def
|
239
|
+
|
240
|
+
# Get the AutoCAD object ID
|
241
|
+
# @rbs return Integer?
|
96
242
|
def autocad_id
|
97
243
|
@ole_obj.ObjectId
|
244
|
+
rescue
|
245
|
+
nil
|
98
246
|
end
|
99
247
|
|
248
|
+
# Check if this element is visible
|
249
|
+
# @rbs return bool
|
100
250
|
def visible?
|
101
251
|
@ole_obj.Visible
|
102
252
|
end
|
103
253
|
|
104
|
-
#
|
254
|
+
# Check if this element is a line
|
255
|
+
# @rbs return bool
|
105
256
|
def line?
|
106
257
|
ole_obj.ObjectName == "AcdbLine"
|
107
258
|
end
|
108
259
|
|
260
|
+
# Check if this element is graphical
|
261
|
+
# @rbs return bool
|
109
262
|
def graphical?
|
110
263
|
ole_obj.IsGraphical
|
111
264
|
end
|
112
265
|
|
266
|
+
# Get string representation of this element
|
267
|
+
# @rbs return String
|
113
268
|
def inspect
|
114
|
-
"<#{self.class}: #{
|
269
|
+
"<#{self.class} -name: #{begin
|
270
|
+
name
|
271
|
+
rescue
|
272
|
+
nil
|
273
|
+
end}> #{acad_type}"
|
115
274
|
end
|
116
275
|
|
276
|
+
# Get the parent element
|
277
|
+
# @rbs return Element?
|
117
278
|
def parent
|
118
279
|
parent_id = ole_obj.ParentID
|
119
280
|
return nil unless parent_id
|
@@ -122,6 +283,9 @@ module Autocad
|
|
122
283
|
app.active_design_file.find_by_id(id)
|
123
284
|
end
|
124
285
|
|
286
|
+
# Convert record ID to element ID
|
287
|
+
# @rbs id: WIN32OLE_RECORD
|
288
|
+
# @rbs return Integer?
|
125
289
|
def id_from_record(id)
|
126
290
|
return unless id.instance_of?(WIN32OLE_RECORD)
|
127
291
|
return id.Low if id.Low > id.High
|
@@ -129,18 +293,20 @@ module Autocad
|
|
129
293
|
id.High
|
130
294
|
end
|
131
295
|
|
296
|
+
# Select this element in the drawing
|
297
|
+
# @rbs return void
|
132
298
|
def select
|
133
299
|
app.active_model_reference.select_element(self)
|
134
300
|
end
|
135
301
|
|
136
|
-
#
|
137
|
-
#
|
138
|
-
# end
|
139
|
-
|
302
|
+
# Get the AutoCAD object type name
|
303
|
+
# @rbs return String
|
140
304
|
def autocad_type
|
141
305
|
ole_obj.ObjectName
|
142
306
|
end
|
143
307
|
|
308
|
+
# Get the model containing this element
|
309
|
+
# @rbs return Model
|
144
310
|
def model
|
145
311
|
Model.new(app, app.current_drawing, ole_obj.ModelReference)
|
146
312
|
end
|
@@ -199,18 +365,43 @@ module Autocad
|
|
199
365
|
::Autocad::Linetype.new(ole, app, typ)
|
200
366
|
when "IAcadText"
|
201
367
|
::Autocad::Text.new(ole, app, typ)
|
368
|
+
when "IAcadModelSpace"
|
369
|
+
::Autocad::ModelSpace.new(ole, app, typ)
|
370
|
+
when "IAcadPaperSpace"
|
371
|
+
::Autocad::PaperSpace.new(ole, app, typ)
|
202
372
|
when "IAcadMText"
|
203
373
|
::Autocad::MText.new(ole, app, typ)
|
204
374
|
when "IAcadPViewport"
|
205
375
|
::Autocad::PViewport.new(ole, app, typ)
|
206
376
|
when "IAcadBlockReference"
|
207
377
|
::Autocad::BlockReference.new(ole, app, typ)
|
378
|
+
when "IAcadBlock"
|
379
|
+
::Autocad::Block.new(ole, app, typ)
|
208
380
|
when "IAcadExternalReference"
|
209
381
|
::Autocad::ExternalReference.new(ole, app, typ)
|
210
382
|
when "IAcadAttributeReference"
|
211
383
|
::Autocad::AttributeReference.new(ole, app, typ)
|
384
|
+
when "IAcadLayout"
|
385
|
+
::Autocad::Layout.new(ole, app, typ)
|
386
|
+
when "IAcadPlotConfiguration"
|
387
|
+
::Autocad::PlotConfiguration.new(ole, app, typ)
|
388
|
+
when "IAcadDimStyle"
|
389
|
+
::Autocad::DimStyle.new(ole, app, typ)
|
390
|
+
when "IAcadTextStyle"
|
391
|
+
::Autocad::TextStyle.new(ole, app, typ)
|
392
|
+
when "IAcadArc"
|
393
|
+
::Autocad::Arc.new(ole, app, typ)
|
394
|
+
when "IAcadPlot"
|
395
|
+
::Autocad::Plot.new(ole, app, typ)
|
396
|
+
when "IAcadSpline"
|
397
|
+
::Autocad::Spline.new(ole, app, typ)
|
398
|
+
when "IAcadViewport"
|
399
|
+
::Autocad::Viewport.new(ole, app, typ)
|
400
|
+
when "IAcadPoint"
|
401
|
+
::Autocad::Point.new(ole, app, typ)
|
212
402
|
|
213
403
|
else
|
404
|
+
# binding.irb
|
214
405
|
Element.new(ole, app, typ)
|
215
406
|
end
|
216
407
|
|
@@ -304,16 +495,17 @@ module Autocad
|
|
304
495
|
def redraw(el = ole_obj)
|
305
496
|
# el.Redraw ::Autocad::MSD::MsdDrawingModeNormal if el.IsGraphical
|
306
497
|
el.Update
|
307
|
-
rescue
|
308
|
-
|
498
|
+
rescue
|
499
|
+
nil
|
309
500
|
end
|
310
501
|
|
311
502
|
def app_ole_obj
|
312
503
|
app.ole_obj
|
313
504
|
end
|
314
505
|
|
315
|
-
def delete
|
506
|
+
def delete(regen: true)
|
316
507
|
ole_obj.Delete
|
508
|
+
drawing.regen if regen
|
317
509
|
rescue => ex
|
318
510
|
raise Autocad::Error.new("Error deleting object #{self} #{ex}")
|
319
511
|
end
|
data/lib/autocad/errors.rb
CHANGED
@@ -28,6 +28,15 @@ module Autocad
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
+
class DrawingClose < Error
|
32
|
+
attr_reader :drawing_name
|
33
|
+
|
34
|
+
def initialize(message, drawing_name)
|
35
|
+
@drawing_name = drawing_name
|
36
|
+
super("#{message}")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
31
40
|
class ExistingFile < Error
|
32
41
|
def initialize(path)
|
33
42
|
msg = "File at path #{path} already exists"
|