autocad 0.4.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rubocop/minitest.yml +2 -0
- data/.rubocop/strict.yml +4 -0
- data/.rubocop.yml +33 -0
- data/.solargraph.yml +22 -0
- data/.vscode/launch.json +30 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/Guardfile +66 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +10 -0
- data/Steepfile +35 -0
- data/WASD-D-TDS-C001.dwg +0 -0
- data/WASD-D-TDS-C001.pdf +0 -0
- data/autocad.log +1 -0
- data/autocad_example.rb +26 -0
- data/event_handler.log +24 -0
- data/examples/example_save_pdf.rb +5 -0
- data/exe/autocad +3 -0
- data/exe/dgn2pdf +50 -0
- data/exe/pw_print +43 -0
- data/gemfiles/rubocop.gemfile +6 -0
- data/lib/autocad/app.rb +655 -0
- data/lib/autocad/arc.rb +29 -0
- data/lib/autocad/block.rb +141 -0
- data/lib/autocad/block_reference.rb +198 -0
- data/lib/autocad/drawing.rb +426 -0
- data/lib/autocad/element.rb +454 -0
- data/lib/autocad/enumerator.rb +24 -0
- data/lib/autocad/errors.rb +37 -0
- data/lib/autocad/event_handler.rb +30 -0
- data/lib/autocad/filter.rb +168 -0
- data/lib/autocad/layer.rb +41 -0
- data/lib/autocad/line.rb +55 -0
- data/lib/autocad/message_box.rb +95 -0
- data/lib/autocad/model.rb +89 -0
- data/lib/autocad/mtext.rb +110 -0
- data/lib/autocad/paths.rb +29 -0
- data/lib/autocad/point3d.rb +143 -0
- data/lib/autocad/pviewport.rb +21 -0
- data/lib/autocad/selection_filter.rb +180 -0
- data/lib/autocad/selection_set.rb +61 -0
- data/lib/autocad/selection_set_adapter.rb +146 -0
- data/lib/autocad/text.rb +74 -0
- data/lib/autocad/version.rb +5 -0
- data/lib/autocad.rb +161 -0
- data/olegen.rb +341 -0
- data/rbs_collection.lock.yaml +188 -0
- data/rbs_collection.yaml +19 -0
- data/scanner.obj +0 -0
- data/sig/generated/autocad/app.rbs +251 -0
- data/sig/generated/autocad/arc.rbs +17 -0
- data/sig/generated/autocad/block.rbs +63 -0
- data/sig/generated/autocad/block_reference.rbs +59 -0
- data/sig/generated/autocad/drawing.rbs +158 -0
- data/sig/generated/autocad/element.rbs +166 -0
- data/sig/generated/autocad/enumerator.rbs +15 -0
- data/sig/generated/autocad/errors.rbs +23 -0
- data/sig/generated/autocad/event_handler.rbs +14 -0
- data/sig/generated/autocad/filter.rbs +60 -0
- data/sig/generated/autocad/layer.rbs +19 -0
- data/sig/generated/autocad/line.rbs +25 -0
- data/sig/generated/autocad/message_box.rbs +81 -0
- data/sig/generated/autocad/model.rbs +41 -0
- data/sig/generated/autocad/paths.rbs +19 -0
- data/sig/generated/autocad/point3d.rbs +66 -0
- data/sig/generated/autocad/selection_filter.rbs +50 -0
- data/sig/generated/autocad/selection_set.rbs +37 -0
- data/sig/generated/autocad/selection_set_adapter.rbs +28 -0
- data/sig/generated/autocad/text.rbs +19 -0
- data/sig/generated/autocad/text_node.rbs +37 -0
- data/sig/generated/autocad/version.rbs +5 -0
- data/sig/generated/autocad/viewport.rbs +11 -0
- data/sig/generated/autocad.rbs +68 -0
- data/sig/prototype/lib/autocad/app.rbs +34 -0
- data/sig/prototype/lib/autocad/block.rbs +5 -0
- data/sig/prototype/lib/autocad/block_reference.rbs +5 -0
- data/sig/prototype/lib/autocad/drawing.rbs +13 -0
- data/sig/prototype/lib/autocad/element.rbs +9 -0
- data/sig/prototype/lib/autocad/enumerator.rbs +5 -0
- data/sig/prototype/lib/autocad/event_handler.rbs +7 -0
- data/sig/prototype/lib/autocad/model.rbs +5 -0
- data/sig/prototype/lib/autocad/paths.rbs +5 -0
- data/sig/prototype/lib/autocad.rbs +3 -0
- data/temp/autocad.dwg +0 -0
- data/temp/autocad.log +1 -0
- data/temp/event_handler.log +0 -0
- metadata +147 -0
@@ -0,0 +1,454 @@
|
|
1
|
+
# rbs_inline: enabled
|
2
|
+
|
3
|
+
# require "autocad/property_handler"
|
4
|
+
|
5
|
+
class WIN32OLE
|
6
|
+
def to_ole
|
7
|
+
self
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module Autocad
|
12
|
+
end
|
13
|
+
|
14
|
+
module Autocad
|
15
|
+
module AcadEntity
|
16
|
+
def layer
|
17
|
+
ole_obj.Layer
|
18
|
+
end
|
19
|
+
|
20
|
+
def layer=(name)
|
21
|
+
ole_obj.Layer = name
|
22
|
+
end
|
23
|
+
|
24
|
+
def line_type
|
25
|
+
ole_obj.LineType
|
26
|
+
end
|
27
|
+
|
28
|
+
def line_type=(name)
|
29
|
+
ole_obj.LineType = name
|
30
|
+
end
|
31
|
+
|
32
|
+
def visible?
|
33
|
+
ole_obj.Visible
|
34
|
+
end
|
35
|
+
|
36
|
+
def copy
|
37
|
+
end
|
38
|
+
|
39
|
+
def intersects_with(obj)
|
40
|
+
end
|
41
|
+
|
42
|
+
def mirror
|
43
|
+
end
|
44
|
+
|
45
|
+
def move_to
|
46
|
+
end
|
47
|
+
|
48
|
+
def update
|
49
|
+
end
|
50
|
+
|
51
|
+
def transform_by(matrix)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
module ElementTrait
|
56
|
+
def block_reference?
|
57
|
+
false
|
58
|
+
end
|
59
|
+
|
60
|
+
#
|
61
|
+
#
|
62
|
+
#
|
63
|
+
# @rbs return bool -- true if ole type is Text
|
64
|
+
#
|
65
|
+
def text?
|
66
|
+
ole_obj.ole_type == "IAcadText"
|
67
|
+
end
|
68
|
+
|
69
|
+
# @rbs return bool -- true if ole type is TextNode
|
70
|
+
def mtext?
|
71
|
+
ole_obj.ole_type == "IAcadMText"
|
72
|
+
end
|
73
|
+
|
74
|
+
def has_tags?
|
75
|
+
ole_obj.HasAnyTags
|
76
|
+
end
|
77
|
+
|
78
|
+
def to_ole
|
79
|
+
ole_obj
|
80
|
+
end
|
81
|
+
|
82
|
+
# @rbs return bool -- true if object is of type cell
|
83
|
+
def cell?
|
84
|
+
ole_obj.Type == ::ACAD::MsdElementTypeCellHeader
|
85
|
+
end
|
86
|
+
|
87
|
+
# def complex
|
88
|
+
# ole_obj.IsComplexElement
|
89
|
+
# end
|
90
|
+
|
91
|
+
# @rbs return bool -- true if Text or TextNode
|
92
|
+
def textual?
|
93
|
+
text? || mtext?
|
94
|
+
end
|
95
|
+
|
96
|
+
def autocad_id
|
97
|
+
@ole_obj.ObjectId
|
98
|
+
end
|
99
|
+
|
100
|
+
def visible?
|
101
|
+
@ole_obj.Visible
|
102
|
+
end
|
103
|
+
|
104
|
+
# @rbs return bool -- true if ole type is TypeLine
|
105
|
+
def line?
|
106
|
+
ole_obj.ObjectName == "AcdbLine"
|
107
|
+
end
|
108
|
+
|
109
|
+
def graphical?
|
110
|
+
ole_obj.IsGraphical
|
111
|
+
end
|
112
|
+
|
113
|
+
def inspect
|
114
|
+
"<#{self.class}: #{autocad_id}>"
|
115
|
+
end
|
116
|
+
|
117
|
+
def parent
|
118
|
+
parent_id = ole_obj.ParentID
|
119
|
+
return nil unless parent_id
|
120
|
+
|
121
|
+
id = id_from_record(parent_id)
|
122
|
+
app.active_design_file.find_by_id(id)
|
123
|
+
end
|
124
|
+
|
125
|
+
def id_from_record(id)
|
126
|
+
return unless id.instance_of?(WIN32OLE_RECORD)
|
127
|
+
return id.Low if id.Low > id.High
|
128
|
+
|
129
|
+
id.High
|
130
|
+
end
|
131
|
+
|
132
|
+
def select
|
133
|
+
app.active_model_reference.select_element(self)
|
134
|
+
end
|
135
|
+
|
136
|
+
# def Type
|
137
|
+
# ole_obj.Type
|
138
|
+
# end
|
139
|
+
|
140
|
+
def autocad_type
|
141
|
+
ole_obj.ObjectName
|
142
|
+
end
|
143
|
+
|
144
|
+
def model
|
145
|
+
Model.new(app, app.current_drawing, ole_obj.ModelReference)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
class Element
|
150
|
+
include ElementTrait
|
151
|
+
|
152
|
+
def self.convert_item(ole, app, cell = nil)
|
153
|
+
return Point3d.from_ole(ole) if ole.instance_of?(WIN32OLE_RECORD) && ole.typename == "Point3d"
|
154
|
+
return ole unless ole.instance_of?(WIN32OLE)
|
155
|
+
|
156
|
+
if ole.respond_to? :ObjectName
|
157
|
+
typ = case ole.ObjectName
|
158
|
+
when "AcDbModelSpace"
|
159
|
+
::Autocad::ModelSpace.new(ole, app, typ)
|
160
|
+
when "AcDbPaperSpace"
|
161
|
+
::Autocad::PaperSpace.new(ole, app, typ)
|
162
|
+
when "AcDbBlockTableRecord"
|
163
|
+
::Autocad::Block.new(ole, app, typ, cell)
|
164
|
+
when "AcDbPolyline"
|
165
|
+
::Autocad::Polyline.new(ole, app, typ, cell)
|
166
|
+
when "AcDbText"
|
167
|
+
::Autocad::Text.new(ole, app, typ, cell)
|
168
|
+
when "AcDbMText"
|
169
|
+
::Autocad::TextNode.new(ole, app, typ, cell)
|
170
|
+
when "AcDbArc"
|
171
|
+
::Autocad::Arc.new(ole, app, typ, cell)
|
172
|
+
when "AcDbViewport"
|
173
|
+
::Autocad::Viewport.new(ole, app, typ)
|
174
|
+
when "AcDbBlock"
|
175
|
+
::Autocad::Block.new(ole, app, typ)
|
176
|
+
when "AcDbLayerTableRecord"
|
177
|
+
::Autocad::Layer.new(ole, app, typ)
|
178
|
+
when AcDbLayerTableRecord
|
179
|
+
end
|
180
|
+
|
181
|
+
return typ if typ
|
182
|
+
binding.irb
|
183
|
+
|
184
|
+
else
|
185
|
+
typ = ole.ole_type
|
186
|
+
result = case typ.name
|
187
|
+
when "IAcadSelectionSet"
|
188
|
+
drawing = app.current_drawing
|
189
|
+
::Autocad::SelectionSetAdapter.from_ole_obj(drawing, ole)
|
190
|
+
when "IAcadLayer"
|
191
|
+
::Autocad::Layer.new(ole, app, typ)
|
192
|
+
when "IAcadLine"
|
193
|
+
::Autocad::Line.new(ole, app, typ)
|
194
|
+
when "IAcadCircle"
|
195
|
+
::Autocad::Circle.new(ole, app, typ)
|
196
|
+
when "IAcadLWPolyline"
|
197
|
+
::Autocad::Polyline.new(ole, app, typ)
|
198
|
+
when "IAcadLineType"
|
199
|
+
::Autocad::Linetype.new(ole, app, typ)
|
200
|
+
when "IAcadText"
|
201
|
+
::Autocad::Text.new(ole, app, typ)
|
202
|
+
when "IAcadMText"
|
203
|
+
::Autocad::MText.new(ole, app, typ)
|
204
|
+
when "IAcadPViewport"
|
205
|
+
::Autocad::PViewport.new(ole, app, typ)
|
206
|
+
when "IAcadBlockReference"
|
207
|
+
::Autocad::BlockReference.new(ole, app, typ)
|
208
|
+
when "IAcadExternalReference"
|
209
|
+
::Autocad::ExternalReference.new(ole, app, typ)
|
210
|
+
when "IAcadAttributeReference"
|
211
|
+
::Autocad::AttributeReference.new(ole, app, typ)
|
212
|
+
|
213
|
+
else
|
214
|
+
Element.new(ole, app, typ)
|
215
|
+
end
|
216
|
+
|
217
|
+
return result if result
|
218
|
+
binding.irb
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
def self.ole_object?
|
223
|
+
ole.instance_of?(WIN32OLE)
|
224
|
+
end
|
225
|
+
|
226
|
+
attr_reader :ole_obj, :app, :acad_type, :original
|
227
|
+
|
228
|
+
def initialize(ole, app, typ, cell = nil)
|
229
|
+
@ole_obj = ole
|
230
|
+
@original = read_ole(ole)
|
231
|
+
@app = app
|
232
|
+
@cell = cell
|
233
|
+
@acad_type = typ
|
234
|
+
end
|
235
|
+
|
236
|
+
def in_cell?
|
237
|
+
!!@cell
|
238
|
+
end
|
239
|
+
|
240
|
+
def read_ole(ole)
|
241
|
+
end
|
242
|
+
|
243
|
+
def write_ole(value)
|
244
|
+
end
|
245
|
+
|
246
|
+
def method_missing(meth, *, &)
|
247
|
+
if /^[A-Z]/.match?(meth.to_s)
|
248
|
+
result = ole_obj.send(meth, *, &)
|
249
|
+
Element.convert_item(result, app)
|
250
|
+
else
|
251
|
+
super
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
def get_property_handler
|
256
|
+
ph_ole = app_ole_obj.CreatePropertyHandler(ole_obj)
|
257
|
+
PropertyHandler.new(ph_ole)
|
258
|
+
end
|
259
|
+
|
260
|
+
def property_handler
|
261
|
+
@property_handler ||= get_property_handler
|
262
|
+
end
|
263
|
+
|
264
|
+
def [](name)
|
265
|
+
property_handler[name]
|
266
|
+
end
|
267
|
+
|
268
|
+
def do_update(value)
|
269
|
+
return false if value == original
|
270
|
+
|
271
|
+
saved_original = original
|
272
|
+
begin
|
273
|
+
write_ole(value)
|
274
|
+
@original = read_ole(ole_obj)
|
275
|
+
true
|
276
|
+
rescue
|
277
|
+
@original = saved_original
|
278
|
+
false
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
def update(value)
|
283
|
+
redraw_el = ole_obj
|
284
|
+
if do_update(value)
|
285
|
+
if in_cell?
|
286
|
+
@cell.ReplaceCurrentElement @ole_obj
|
287
|
+
redraw_el = @cell
|
288
|
+
end
|
289
|
+
redraw(redraw_el)
|
290
|
+
@updated = true
|
291
|
+
true
|
292
|
+
else
|
293
|
+
@updated = false
|
294
|
+
false
|
295
|
+
end
|
296
|
+
rescue => e
|
297
|
+
app.error_proc.call(e, nil)
|
298
|
+
end
|
299
|
+
|
300
|
+
def updated?
|
301
|
+
@updated
|
302
|
+
end
|
303
|
+
|
304
|
+
def redraw(el = ole_obj)
|
305
|
+
# el.Redraw ::Autocad::MSD::MsdDrawingModeNormal if el.IsGraphical
|
306
|
+
el.Update
|
307
|
+
rescue => e
|
308
|
+
app.error_proc.call(e, nil)
|
309
|
+
end
|
310
|
+
|
311
|
+
def app_ole_obj
|
312
|
+
app.ole_obj
|
313
|
+
end
|
314
|
+
|
315
|
+
def delete
|
316
|
+
ole_obj.Delete
|
317
|
+
rescue => ex
|
318
|
+
raise Autocad::Error.new("Error deleting object #{self} #{ex}")
|
319
|
+
end
|
320
|
+
|
321
|
+
def clone(new_insertion_point)
|
322
|
+
pt = Point3d.new(new_insertion_point)
|
323
|
+
ole = ole_obj.Copy(pt.to_ole)
|
324
|
+
app.wrap(ole)
|
325
|
+
rescue => ex
|
326
|
+
raise Autocad::Error.new("Error cloning object #{ex}")
|
327
|
+
end
|
328
|
+
|
329
|
+
def move_x(amt)
|
330
|
+
pt1 = Point3d(0, 0, 0)
|
331
|
+
pt2 = Point3d(amt, 0, 0)
|
332
|
+
move_ole(pt1.to_ole, pt2.to_ole)
|
333
|
+
end
|
334
|
+
|
335
|
+
def move_y(amt)
|
336
|
+
pt1 = Point3d(0, 0, 0)
|
337
|
+
pt2 = Point3d(0, 1, 0)
|
338
|
+
move_ole(pt1.to_ole, pt2.to_ole)
|
339
|
+
end
|
340
|
+
|
341
|
+
def move(x, y)
|
342
|
+
pt1 = Point3d(0, 0, 0)
|
343
|
+
pt2 = Point3d(x, y, 0)
|
344
|
+
move_ole(pt1.to_ole, pt2.to_ole)
|
345
|
+
end
|
346
|
+
|
347
|
+
def move_ole(pt1, pt2)
|
348
|
+
ole_obj.Move(pt1, pt2)
|
349
|
+
app.wrap(ole_obj)
|
350
|
+
rescue => ex
|
351
|
+
raise Autocad::Error.new("Error moving object #{ex}")
|
352
|
+
end
|
353
|
+
|
354
|
+
def ole_cell(ole)
|
355
|
+
ole.IsCellElement || ole.IsSharedCellElement
|
356
|
+
end
|
357
|
+
|
358
|
+
# def each_cell(ole, &)
|
359
|
+
# cell = ole if ole_cell(ole)
|
360
|
+
# begin
|
361
|
+
# ole.ResetElementEnumeration
|
362
|
+
# rescue
|
363
|
+
# binding.break
|
364
|
+
# end
|
365
|
+
# while ole.MoveToNextElement
|
366
|
+
# component = ole.CopyCurrentElement
|
367
|
+
# if component.IsTextNodeElement
|
368
|
+
# yield Autocad::Wrap.wrap(component.AsTextNodeElement, app, cell)
|
369
|
+
# elsif component.IsTextElement
|
370
|
+
# yield Autocad::Wrap.wrap(component.AsTextElement, app, cell)
|
371
|
+
# elsif component.IsComplexElement
|
372
|
+
# each(component, &)
|
373
|
+
# else
|
374
|
+
# yield Autocad::Wrap.wrap(component, app, cell)
|
375
|
+
# end
|
376
|
+
# end
|
377
|
+
# end
|
378
|
+
|
379
|
+
# def each(ole = ole_obj, &block)
|
380
|
+
# return unless ole.IsComplexElement
|
381
|
+
# return to_enum(:each) unless block
|
382
|
+
|
383
|
+
# if ole.IsCellElement
|
384
|
+
# each_cell(ole, &block)
|
385
|
+
# else
|
386
|
+
# each_complex(ole, &block)
|
387
|
+
# end
|
388
|
+
# end
|
389
|
+
|
390
|
+
def each_complex(ole, &)
|
391
|
+
cell = nil
|
392
|
+
components = ole.GetSubElements
|
393
|
+
while components.MoveNext
|
394
|
+
component = components.Current
|
395
|
+
if component.IsTextNodeElement
|
396
|
+
yield Autocad::Wrap.wrap(component.AsTextNodeElement, app, cell)
|
397
|
+
elsif component.IsTextElement
|
398
|
+
yield Autocad::Wrap.wrap(component.AsTextElement, app, cell)
|
399
|
+
elsif component.IsComplexElement
|
400
|
+
each(component, &)
|
401
|
+
else
|
402
|
+
yield Autocad::Wrap.wrap(component, app, cell)
|
403
|
+
end
|
404
|
+
end
|
405
|
+
end
|
406
|
+
end
|
407
|
+
|
408
|
+
class App
|
409
|
+
def ole_to_ruby(ole)
|
410
|
+
Element.convert_item(ole, self)
|
411
|
+
end
|
412
|
+
end
|
413
|
+
end
|
414
|
+
|
415
|
+
module Autocad
|
416
|
+
class Arc < Element
|
417
|
+
end
|
418
|
+
end
|
419
|
+
|
420
|
+
module Autocad
|
421
|
+
class Ellipse < Element
|
422
|
+
end
|
423
|
+
end
|
424
|
+
|
425
|
+
module Autocad
|
426
|
+
class BSplineSurface < Element
|
427
|
+
end
|
428
|
+
end
|
429
|
+
|
430
|
+
module Autocad
|
431
|
+
class Linetype < Element
|
432
|
+
CONTINUOUS = "Continuous"
|
433
|
+
DASHED = "Dashed"
|
434
|
+
CENTER = "Center"
|
435
|
+
HIDDEN = "Hidden"
|
436
|
+
PHANTOM = "Phantom"
|
437
|
+
BREAK = "Break"
|
438
|
+
BORDER = "Border"
|
439
|
+
DOT2 = "Dot2"
|
440
|
+
DOTX2 = "DotX2"
|
441
|
+
DIVIDE = "Divide"
|
442
|
+
TRACKING = "Tracking"
|
443
|
+
DASHDOT = "Daskdot"
|
444
|
+
|
445
|
+
def name
|
446
|
+
ole_obj.Name
|
447
|
+
end
|
448
|
+
end
|
449
|
+
end
|
450
|
+
|
451
|
+
module Autocad
|
452
|
+
class BSplineCurve < Element
|
453
|
+
end
|
454
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Autocad
|
2
|
+
class Enumerator
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
attr_reader :app
|
6
|
+
|
7
|
+
def initialize(ole, app)
|
8
|
+
@ole_obj = ole
|
9
|
+
@app = app
|
10
|
+
end
|
11
|
+
|
12
|
+
def each
|
13
|
+
return enum_for(:each) unless block_given?
|
14
|
+
|
15
|
+
@ole_obj.each do |ole|
|
16
|
+
yield app.wrap(ole)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def reset
|
21
|
+
@ole_obj.reset
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# rbs_enabled: true
|
2
|
+
|
3
|
+
module Autocad
|
4
|
+
Error = Class.new(::RuntimeError)
|
5
|
+
NonDGNFile = Class.new(Error)
|
6
|
+
|
7
|
+
class FileNotFound < Error
|
8
|
+
def initialize(path)
|
9
|
+
super("File at path #{path} not found")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
MultipleUpdateError = Class.new(Error)
|
13
|
+
|
14
|
+
# class RetryableError < Error
|
15
|
+
# attr_reader :num_tries
|
16
|
+
# def initialize(message, num_tries)
|
17
|
+
# @num_tries = num_tries
|
18
|
+
# super("#{message} (##{num_tries})")
|
19
|
+
# end
|
20
|
+
# end
|
21
|
+
|
22
|
+
class DrawingError < Error
|
23
|
+
attr_reader :drawing
|
24
|
+
|
25
|
+
def initialize(message, drawing)
|
26
|
+
@drawing = drawing
|
27
|
+
super("#{message} for #{drawing.path}")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class ExistingFile < Error
|
32
|
+
def initialize(path)
|
33
|
+
msg = "File at path #{path} already exists"
|
34
|
+
super(msg)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# rbs_inline: enabled
|
2
|
+
|
3
|
+
module Autocad
|
4
|
+
class EventHandler
|
5
|
+
def initialize
|
6
|
+
@handlers = {}
|
7
|
+
@file = File.open("event_handler.log", "w")
|
8
|
+
end
|
9
|
+
|
10
|
+
# @rbs event: String -- the event name to handle
|
11
|
+
def add_handler(event, &block)
|
12
|
+
@handlers[event] = block if block
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_handler(event)
|
16
|
+
@handlers[event]
|
17
|
+
end
|
18
|
+
|
19
|
+
def method_missing(event, *args)
|
20
|
+
if @handlers[event.to_s]
|
21
|
+
@handlers[event.to_s].call(*args)
|
22
|
+
else
|
23
|
+
@file.puts "Unhandled event: #{event} args: #{args}"
|
24
|
+
@file.puts "Event class is: #{event.class}, args are: #{args}"
|
25
|
+
# event = event.to_sym if event.is_a? String
|
26
|
+
# super
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,168 @@
|
|
1
|
+
module Autocad
|
2
|
+
class Filter
|
3
|
+
attr_reader :types, :values, :clauses
|
4
|
+
|
5
|
+
def initialize(clauses: {})
|
6
|
+
@clauses = clauses
|
7
|
+
@types = []
|
8
|
+
@values = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def new_filter(clause, value)
|
12
|
+
new_clauses = clauses.dup
|
13
|
+
new_clauses[clause] = value
|
14
|
+
Filter.new(clauses: new_clauses)
|
15
|
+
end
|
16
|
+
|
17
|
+
def has_filters?
|
18
|
+
true
|
19
|
+
end
|
20
|
+
|
21
|
+
# convert the clauses to the values and types needed for autocad filter
|
22
|
+
# rbs return Array[Array,Array] -- the types and values array
|
23
|
+
def convert_clauses
|
24
|
+
types = []
|
25
|
+
values = []
|
26
|
+
|
27
|
+
case clauses.keys.first
|
28
|
+
when :type
|
29
|
+
types << 0
|
30
|
+
values << clauses[:type]
|
31
|
+
when :layer
|
32
|
+
types << 8
|
33
|
+
values << clauses[:layer]
|
34
|
+
when :color
|
35
|
+
types << 62
|
36
|
+
values << clauses[:color]
|
37
|
+
when :block_reference
|
38
|
+
types << 0
|
39
|
+
values << 'INSERT'
|
40
|
+
if clauses[:block_reference]
|
41
|
+
types << 1
|
42
|
+
values << clauses[:block_reference]
|
43
|
+
end
|
44
|
+
when :paper_space
|
45
|
+
types << 67
|
46
|
+
values << 1
|
47
|
+
when :model_space
|
48
|
+
types << 67
|
49
|
+
values << 0
|
50
|
+
when :text_content
|
51
|
+
types << 1 # DXF type code 1 for text content
|
52
|
+
values << clauses[:text_content]
|
53
|
+
when :and, :or, :xor
|
54
|
+
operator = clauses.keys.first.to_s.upcase
|
55
|
+
types << -4
|
56
|
+
values << "<#{operator}"
|
57
|
+
|
58
|
+
clauses[clauses.keys.first].each do |condition|
|
59
|
+
sub_types, sub_values = condition.convert_clauses
|
60
|
+
types.concat(sub_types)
|
61
|
+
values.concat(sub_values)
|
62
|
+
end
|
63
|
+
|
64
|
+
types << -4
|
65
|
+
values << "#{operator}>"
|
66
|
+
when :not
|
67
|
+
types << -4
|
68
|
+
values << '<NOT'
|
69
|
+
|
70
|
+
sub_types, sub_values = clauses[:not].convert_clauses
|
71
|
+
types.concat(sub_types)
|
72
|
+
values.concat(sub_values)
|
73
|
+
|
74
|
+
types << -4
|
75
|
+
values << 'NOT>'
|
76
|
+
when :gt
|
77
|
+
types.concat([-4, 40])
|
78
|
+
values.concat(['>=', clauses[:gt]])
|
79
|
+
when :lt
|
80
|
+
types.concat([-4, 40])
|
81
|
+
values.concat(['<=', clauses[:lt]])
|
82
|
+
when :eq
|
83
|
+
types.concat([-4, 40])
|
84
|
+
values.concat(['=', clauses[:eq]])
|
85
|
+
when :neq
|
86
|
+
types.concat([-4, 40])
|
87
|
+
values.concat(['<>', clauses[:neq]])
|
88
|
+
end
|
89
|
+
|
90
|
+
[types, values]
|
91
|
+
end
|
92
|
+
|
93
|
+
# Logical Operators
|
94
|
+
def and(*conditions)
|
95
|
+
new_filter(:and, conditions)
|
96
|
+
end
|
97
|
+
|
98
|
+
def merge_conditions(existing, new_condition)
|
99
|
+
end
|
100
|
+
|
101
|
+
def or(*conditions)
|
102
|
+
new_filter(:or, conditions)
|
103
|
+
end
|
104
|
+
|
105
|
+
def xor(condition1, condition2)
|
106
|
+
new_filter(:xor, [condition1, condition2])
|
107
|
+
end
|
108
|
+
|
109
|
+
def not(condition)
|
110
|
+
new_filter(:not, condition)
|
111
|
+
end
|
112
|
+
|
113
|
+
# Relational Operators
|
114
|
+
# f.type("Circle").greater_than(5)
|
115
|
+
def greater_than(value)
|
116
|
+
new_filter(:gt, value)
|
117
|
+
end
|
118
|
+
|
119
|
+
def less_than(value)
|
120
|
+
new_filter(:lt, value)
|
121
|
+
end
|
122
|
+
|
123
|
+
def equal_to(value)
|
124
|
+
new_filter(:eq, value)
|
125
|
+
end
|
126
|
+
|
127
|
+
def not_equal_to(value)
|
128
|
+
new_filter(:neq, value)
|
129
|
+
end
|
130
|
+
|
131
|
+
def block_reference(name = nil)
|
132
|
+
new_filter(:block_reference, name)
|
133
|
+
end
|
134
|
+
|
135
|
+
def name(value)
|
136
|
+
new_filter(:name, value)
|
137
|
+
end
|
138
|
+
|
139
|
+
def type(kind)
|
140
|
+
new_filter(:type, kind)
|
141
|
+
end
|
142
|
+
|
143
|
+
def layer(name)
|
144
|
+
new_filter(:layer, name)
|
145
|
+
end
|
146
|
+
|
147
|
+
def visible(vis = true)
|
148
|
+
new_filter(:visible, vis)
|
149
|
+
end
|
150
|
+
|
151
|
+
def color(num)
|
152
|
+
new_filter(:color, num)
|
153
|
+
end
|
154
|
+
|
155
|
+
def paper_space
|
156
|
+
new_filter(:paper_space, nil)
|
157
|
+
end
|
158
|
+
|
159
|
+
def model_space
|
160
|
+
new_filter(:model_space, nil)
|
161
|
+
end
|
162
|
+
|
163
|
+
def has_text(str)
|
164
|
+
new_filter(:text_content, str)
|
165
|
+
end
|
166
|
+
|
167
|
+
end
|
168
|
+
end
|