microstation 0.8.6 → 0.8.7

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 (78) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +26 -29
  3. data/Rakefile +45 -45
  4. data/bin/dgn2pdf +5 -6
  5. data/bin/dgn_template +23 -25
  6. data/bin/pw_print +11 -13
  7. data/cad_files/drawing_no_block.dgn +0 -0
  8. data/cad_files/drawing_with_3_block.dgn +0 -0
  9. data/cad_files/drawing_with_block.dgn +0 -0
  10. data/cad_files/drawing_with_text.dgn +0 -0
  11. data/lib/microstation/app.rb +91 -87
  12. data/lib/microstation/cad_input_queue.rb +10 -20
  13. data/lib/microstation/cell.rb +6 -18
  14. data/lib/microstation/changer.rb +3 -3
  15. data/lib/microstation/configuration.rb +33 -50
  16. data/lib/microstation/criteria_creation_t.rb +4 -8
  17. data/lib/microstation/dir.rb +27 -59
  18. data/lib/microstation/directory.rb +2 -7
  19. data/lib/microstation/drawing.rb +103 -102
  20. data/lib/microstation/element.rb +55 -68
  21. data/lib/microstation/enumerator.rb +4 -9
  22. data/lib/microstation/errors.rb +0 -5
  23. data/lib/microstation/event_handler.rb +1 -5
  24. data/lib/microstation/ext/pathname.rb +12 -14
  25. data/lib/microstation/ext/win32ole.rb +0 -2
  26. data/lib/microstation/extensions/faa.rb +12 -34
  27. data/lib/microstation/file_tests.rb +15 -50
  28. data/lib/microstation/functions.rb +10 -20
  29. data/lib/microstation/graphics.rb +6 -13
  30. data/lib/microstation/line.rb +2 -6
  31. data/lib/microstation/model.rb +11 -20
  32. data/lib/microstation/model_trait.rb +40 -40
  33. data/lib/microstation/ole_cad_input_message.rb +25 -34
  34. data/lib/microstation/ole_helper.rb +58 -66
  35. data/lib/microstation/pdf_support.rb +7 -16
  36. data/lib/microstation/point3d.rb +17 -30
  37. data/lib/microstation/primitive_command_interface.rb +8 -14
  38. data/lib/microstation/properties.rb +29 -17
  39. data/lib/microstation/property_handler.rb +6 -8
  40. data/lib/microstation/scan/color.rb +1 -8
  41. data/lib/microstation/scan/criteria.rb +17 -33
  42. data/lib/microstation/scan/klass.rb +8 -12
  43. data/lib/microstation/scan/level.rb +2 -9
  44. data/lib/microstation/scan/line_style.rb +4 -12
  45. data/lib/microstation/scan/line_weight.rb +1 -3
  46. data/lib/microstation/scan/range.rb +2 -8
  47. data/lib/microstation/scan/scan_trait.rb +48 -51
  48. data/lib/microstation/scan/subtype.rb +0 -10
  49. data/lib/microstation/scan/type.rb +9 -15
  50. data/lib/microstation/scan_trait.rb +13 -20
  51. data/lib/microstation/scanner.rb +1 -11
  52. data/lib/microstation/tag.rb +12 -21
  53. data/lib/microstation/tag_set.rb +52 -71
  54. data/lib/microstation/tag_set_trait.rb +6 -10
  55. data/lib/microstation/tagged_element.rb +16 -28
  56. data/lib/microstation/template.rb +15 -14
  57. data/lib/microstation/template_info.rb +35 -49
  58. data/lib/microstation/template_runner.rb +14 -22
  59. data/lib/microstation/text.rb +15 -19
  60. data/lib/microstation/text_node.rb +17 -26
  61. data/lib/microstation/ts/attribute.rb +16 -20
  62. data/lib/microstation/ts/instance.rb +28 -38
  63. data/lib/microstation/ts/tagset_trait.rb +5 -12
  64. data/lib/microstation/types.rb +0 -3
  65. data/lib/microstation/version.rb +1 -3
  66. data/lib/microstation/wrap.rb +3 -10
  67. data/lib/microstation.rb +53 -68
  68. data/spec/microstation/app_spec.rb +49 -46
  69. data/spec/microstation/configuration_spec.rb +45 -43
  70. data/spec/microstation/drawing_spec.rb +103 -101
  71. data/spec/microstation/functions_spec.rb +18 -12
  72. data/spec/microstation/tag_set_spec.rb +57 -55
  73. data/spec/microstation/template_spec.rb +41 -42
  74. data/spec/microstation/text_node_spec.rb +16 -14
  75. data/spec/microstation/text_spec.rb +10 -8
  76. data/spec/microstation_spec.rb +18 -17
  77. data/spec/spec_helper.rb +18 -18
  78. metadata +26 -12
@@ -1,9 +1,9 @@
1
- require_relative 'properties'
2
- require_relative 'tag_set_trait'
3
- require_relative 'model'
4
- require_relative 'errors'
5
- require_relative 'scan_trait'
6
- require 'liquid'
1
+ require_relative "properties"
2
+ require_relative "tag_set_trait"
3
+ require_relative "model"
4
+ require_relative "errors"
5
+ require_relative "scan_trait"
6
+ require "liquid"
7
7
  # /
8
8
  # // MessageId: DISP_E_PARAMNOTFOUND
9
9
  # //
@@ -23,14 +23,14 @@ module Microstation
23
23
  #
24
24
  # Initialize drawing
25
25
  #
26
- # @param app [<Application>] the app instance
26
+ # @param app [<Application>] the app instance
27
27
  # @param ole [<WIN32OLIE>] the ole object returned from app.ole_obj
28
28
  #
29
29
  def initialize(app, ole)
30
30
  @app = app
31
31
  @ole_obj = ole
32
32
  @find_tagset_instances_called = false
33
- @app.register_handler('ISaveAsEvents_AfterSaveAs') do |*args|
33
+ @app.register_handler("ISaveAsEvents_AfterSaveAs") do |*_args|
34
34
  @drawing_saved = true
35
35
  end
36
36
  end
@@ -60,13 +60,13 @@ module Microstation
60
60
  def copy(name: nil, dir: nil)
61
61
  if dir.nil?
62
62
  lname = name || copy_name
63
- dir_path = self.dirname
63
+ dir_path = dirname
64
64
  else
65
65
  lname = name || self.name
66
66
  dir_path = Pathname(dir)
67
67
  end
68
68
  copy_path = dir_path + lname
69
- FileUtils.copy self.path.to_s, copy_path.to_s, verbose: true
69
+ FileUtils.copy path.to_s, copy_path.to_s, verbose: true
70
70
  end
71
71
 
72
72
  # save the drawing as a pdf file
@@ -108,9 +108,9 @@ module Microstation
108
108
  end
109
109
  end
110
110
 
111
- def wait_save_event(secs, interval = 0.5)
111
+ def wait_save_event(_secs, interval = 0.5)
112
112
  elapsed = 0
113
- while (!@drawing_saved && elapsed <= 5)
113
+ while !@drawing_saved && elapsed <= 5
114
114
  elapsed += interval
115
115
  sleep(interval)
116
116
  WIN32OLE_EVENT.message_loop
@@ -129,8 +129,8 @@ module Microstation
129
129
  # @criteria [Scan::Criteria]
130
130
  # @yield
131
131
  def scan_model(criteria, model: default_model_reference, &block)
132
- criteria = criteria || create_scan_criteria
133
- model = model || default_model_reference
132
+ criteria ||= create_scan_criteria
133
+ model ||= default_model_reference
134
134
  model.scan_model(criteria, &block)
135
135
  end
136
136
 
@@ -139,23 +139,23 @@ module Microstation
139
139
  #
140
140
  # calls scan_all_with_block
141
141
  # calls scal_all_with_hash
142
- def scan_all(criteria,&block)
142
+ def scan_all(criteria)
143
143
  return to_enum(__callee__, criteria) unless block_given?
144
+ result = [] if block_given?
144
145
  each_model do |m|
145
146
  m.scan_model(criteria) do |r|
146
147
  if block_given?
147
- yield r
148
+ yield m, r
148
149
  else
149
- result << r
150
+ result << [m, r]
150
151
  end
151
152
  end
152
-
153
153
  end
154
154
  end
155
155
 
156
- def get_text(&block)
156
+ def get_text
157
157
  result = []
158
- scan_text do |te|
158
+ scan_text do |_model, te|
159
159
  if block_given?
160
160
  yield te.to_s
161
161
  else
@@ -167,25 +167,25 @@ module Microstation
167
167
 
168
168
  # scan all text and text regions in all
169
169
  # models
170
- # @yield [String] text that is found
170
+ # @yield [Model,String] text that is found
171
171
  def scan_text(&block)
172
172
  scan_all(text_criteria, &block)
173
173
  end
174
174
 
175
175
  # scan all tags in drawing and
176
- # @yield [Tag] to the block
176
+ # @yield [Model,Tag] to the block
177
177
  def scan_tags(&block)
178
178
  scan_all(tags_criteria, &block)
179
179
  end
180
180
 
181
181
  # scan all cells in drawing and
182
- # @yield [Cell] to the block
182
+ # @yield [Model,Cell] to the block
183
183
  def scan_cells(&block)
184
184
  scan_all(cells_criteria, &block)
185
185
  end
186
186
 
187
187
  def scan_text_in_cells(&block)
188
- scan_cells do |c|
188
+ scan_cells do |_model, c|
189
189
  c.text_elements(&block)
190
190
  end
191
191
  end
@@ -258,9 +258,14 @@ module Microstation
258
258
  app.eval_cexpression(string)
259
259
  end
260
260
 
261
+ # Close the drawing
261
262
  def close
262
263
  @drawing_closed = true
263
- ole_obj.Close rescue nil
264
+ begin
265
+ ole_obj.Close
266
+ rescue
267
+ nil
268
+ end
264
269
  @ole_obj = nil
265
270
  end
266
271
 
@@ -268,17 +273,22 @@ module Microstation
268
273
  @drawing_closed
269
274
  end
270
275
 
276
+ # Return the pdf name for the drawing.
277
+ #
278
+ # If a name is provided use the name provided otherwise use the drawing name
279
+ #
280
+ # @param name [String, nil] @return a Pathname from the name or drawing name
271
281
  def pdf_name(name = nil)
272
- name = self.name unless name
273
- return Pathname(name).sub_ext(".pdf")
282
+ name ||= self.name
283
+ Pathname(name).sub_ext(".pdf")
274
284
  end
275
285
 
276
286
  def pdf_driver
277
- app.windows_path( (::Microstation.plot_driver_directory + "pdf-bw.plt").to_s)
287
+ app.windows_path((::Microstation.plot_driver_directory + "pdf-bw.plt").to_s)
278
288
  end
279
289
 
280
290
  def pen_table
281
- app.windows_path( (::Microstation.plot_driver_directory + 'wmbw.tbl'))
291
+ app.windows_path((::Microstation.plot_driver_directory + "wmbw.tbl"))
282
292
  end
283
293
 
284
294
  # iterate through each model in the drawing
@@ -300,18 +310,17 @@ module Microstation
300
310
  # Create a new model
301
311
  # @param [String] name - the name of the model
302
312
  # @param [String] template - the template to use for the model
303
- def new_model(name,template = nil)
313
+ def new_model(name, template = nil)
304
314
  template_ole = template ? template.ole_obj : app.ole_obj.ActiveDesignFile.DefaultModelReference
305
- el = app.ole_obj.ActiveDesignFile.Models.Add(template_ole,name,"Added ")
306
- m = model_from_ole(el).activate
307
- m
315
+ el = app.ole_obj.ActiveDesignFile.Models.Add(template_ole, name, "Added ")
316
+ model_from_ole(el).activate
308
317
  end
309
318
 
310
319
  # Active a model
311
320
  # @param name [String] a
312
321
  def activate_model(name)
313
322
  model = find_model(name)
314
- model.activate if model
323
+ model&.activate
315
324
  end
316
325
 
317
326
  # Find the model in the drawing
@@ -336,6 +345,7 @@ module Microstation
336
345
 
337
346
  def get_selected_elements
338
347
  return [] unless has_active_model?
348
+
339
349
  active_model.get_selected_elements
340
350
  end
341
351
 
@@ -343,12 +353,12 @@ module Microstation
343
353
  active_model.get_selected_text
344
354
  end
345
355
 
346
- def get_matching_text(re,&block)
347
- active_model.get_matching_text(re,&block)
356
+ def get_matching_text(re, &block)
357
+ active_model.get_matching_text(re, &block)
348
358
  end
349
359
 
350
- def change_text_suffix(reg,offset)
351
- active_model.change_text_suffix(reg,offset)
360
+ def change_text_suffix(reg, offset)
361
+ active_model.change_text_suffix(reg, offset)
352
362
  end
353
363
 
354
364
  # activate the model with name
@@ -359,10 +369,11 @@ module Microstation
359
369
  model = find_model(name)
360
370
 
361
371
  return unless model
372
+
362
373
  model.activate
363
374
  end
364
375
 
365
- alias :activate_model :change_model
376
+ alias_method :activate_model, :change_model
366
377
 
367
378
  #
368
379
  # Returns the model names
@@ -397,7 +408,7 @@ module Microstation
397
408
  range_diff = app_ole_obj.Point3dSubtract(range.High, range.Low)
398
409
  extent = app_ole_obj.Point3dScale(range_diff, zoom)
399
410
 
400
- oview_origin = app_ole_obj.Point3dSubtract(range.Low, app_ole_obj.Point3dScale(extent,0.5))
411
+ oview_origin = app_ole_obj.Point3dSubtract(range.Low, app_ole_obj.Point3dScale(extent, 0.5))
401
412
  oview.Origin = oview_origin
402
413
  oview.Extents = extent
403
414
  oview.Redraw
@@ -407,7 +418,7 @@ module Microstation
407
418
  #
408
419
  # Save the drawing
409
420
  #
410
- # @return [void]
421
+ # @return [void]
411
422
  #
412
423
  def save
413
424
  ole_obj.Save
@@ -417,19 +428,19 @@ module Microstation
417
428
  active_model.add_element(line)
418
429
  end
419
430
 
420
- def create_scanner(name,&block)
421
- app.create_scanner(name,&block)
431
+ def create_scanner(name, &block)
432
+ app.create_scanner(name, &block)
422
433
  end
423
434
 
424
435
  # used
425
- def create_tagset_instances_bak()
436
+ def create_tagset_instances_bak
426
437
  result = []
427
438
  @find_tagset_instances_called = true
428
439
  filtered = if block_given?
429
- get_tagsets_in_drawing_hash.select(&filter)
430
- else
431
- get_tagsets_in_drawing_hash
432
- end
440
+ get_tagsets_in_drawing_hash.select(&filter)
441
+ else
442
+ get_tagsets_in_drawing_hash
443
+ end
433
444
  binding.pry
434
445
  filtered.map do |h|
435
446
  element_id = h[:base_element_id]
@@ -458,21 +469,20 @@ module Microstation
458
469
 
459
470
  def create_tagset_instance_from_tagset_hash(h)
460
471
  ts = tagsets[h[:name]]
461
- ts.create_instance( h[:base_element_id], h[:tags], h[:model])
472
+ ts.create_instance(h[:base_element_id], h[:tags], h[:model])
462
473
  end
463
474
 
464
475
  def save_tagsets_to_file(name)
465
- require 'json'
466
- ::File.open(name, 'w'){ |f| f.write get_tagsets_in_drawing_hash.to_a.to_json }
476
+ require "json"
477
+ ::File.write(name, get_tagsets_in_drawing_hash.to_a.to_json)
467
478
  end
468
479
 
469
- #used
470
- def get_tagsets_in_drawing_hash(ts_name: nil, base_element_id: nil)
471
- return to_enum(__callee__, ts_name: ts_name, base_element_id: base_element_id) unless block_given?
480
+ # used
481
+ def get_tagsets_in_drawing_hash(ts_name: nil, base_element_id: nil, &block)
482
+ return to_enum(__callee__, ts_name: ts_name, base_element_id: base_element_id) unless block
483
+
472
484
  each_model do |m|
473
- m.get_tagsets_in_model_hash(ts_name: ts_name, base_element_id: base_element_id) do |tsi|
474
- yield tsi
475
- end
485
+ m.get_tagsets_in_model_hash(ts_name: ts_name, base_element_id: base_element_id, &block)
476
486
  end
477
487
  end
478
488
 
@@ -484,7 +494,7 @@ module Microstation
484
494
  create_tagset_instances(ts_name: name).first
485
495
  end
486
496
 
487
- def find_tagset_instance_by_name_and_id(name,id)
497
+ def find_tagset_instance_by_name_and_id(name, id)
488
498
  create_tagset_instances(ts_name: name, base_element_id: id).first
489
499
  end
490
500
 
@@ -498,26 +508,25 @@ module Microstation
498
508
  results << ts
499
509
  end
500
510
  end
501
-
502
511
  end
503
512
  return results unless block_given?
504
513
  end
505
514
 
506
- def update_tagset(name,h_local={})
515
+ def update_tagset(name, h_local = {})
507
516
  tset_instances = select_tagset_instances_by_name(name)
508
517
  case tset_instances.size
509
518
  when 0
510
- raise 'no tagset found'
519
+ raise "no tagset found"
511
520
  when 1
512
521
  ts = tset_instances.first
513
522
  ts.update(h_local)
514
523
  else
515
- if (h_local.class == Array && h_local.all?{|l| l.class == Hash})
524
+ if h_local.instance_of?(Array) && h_local.all? { |l| l.instance_of?(Hash) }
516
525
  h_local.each do |update_hash|
517
526
  ts = find_tagset_instance_from_hash(tset_instances, update_hash)
518
527
  ts.update(update_hash)
519
528
  end
520
- elsif h_local.class == Hash
529
+ elsif h_local.instance_of?(Hash)
521
530
  ts = find_tagset_instance_from_hash(tset_instances, h_local)
522
531
  ts.update(h_local)
523
532
  else
@@ -527,33 +536,35 @@ module Microstation
527
536
  end
528
537
 
529
538
  def find_tagset_instance_from_hash(ti_array, h_local)
530
- id = h_local.fetch('microstation_id', :not_found)
539
+ id = h_local.fetch("microstation_id", :not_found)
531
540
  if id == :not_found || id.nil?
532
541
  name = ti_array.first.name
533
542
 
534
- raise MultipleUpdateError, "found #{ti_array.size} instances for tagset #{name}; Need a microstation_id for hash"
543
+ raise MultipleUpdateError,
544
+ "found #{ti_array.size} instances for tagset #{name}; Need a microstation_id for hash"
535
545
  end
536
- ts = ti_array.find{|ti| ti.microstation_id == id}
546
+ ts = ti_array.find { |ti| ti.microstation_id == id }
537
547
  end
538
548
 
539
549
  def update_tagsets(ts_arg)
540
550
  return if ts_arg == []
541
551
  return if ts_arg == {}
542
- ts_array = [ts_arg] if ts_arg.class == Hash
552
+
553
+ ts_array = [ts_arg] if ts_arg.instance_of?(Hash)
543
554
  ts_array.each do |hash_pair|
544
555
  update_tagset(hash_pair.keys[0], hash_pair.values[0])
545
556
  end
546
557
  end
547
558
 
548
559
  def update_error
549
- raise ArgumentError, 'Argument must be an array of hashes'
560
+ raise ArgumentError, "Argument must be an array of hashes"
550
561
  end
551
562
 
552
563
  def update_tagsets_from_template_structure(ts_arg)
553
564
  ts_arg.each do |h|
554
- inst_array = h['instances']
565
+ inst_array = h["instances"]
555
566
  inst_array.each do |ts_hash|
556
- update_tagset(ts_hash['tagset_name'], ts_hash['attributes'])
567
+ update_tagset(ts_hash["tagset_name"], ts_hash["attributes"])
557
568
  end
558
569
  end
559
570
  end
@@ -561,26 +572,24 @@ module Microstation
561
572
  #
562
573
  # returns the internal ole_obj
563
574
  #
564
- # @return [WIN32OLE]
575
+ # @return [WIN32OLE]
565
576
  #
566
577
  def ole_obj
567
578
  is_ok = true
568
579
  begin
569
580
  @ole_obj.Name
570
- rescue StandardError => e
581
+ rescue => e
571
582
  is_ok = false
572
583
  end
573
584
 
574
- unless is_ok || drawing_closed?
575
- binding.pry
576
- end
585
+ binding.pry unless is_ok || drawing_closed?
577
586
 
578
587
  @ole_obj
579
588
  end
580
589
 
581
590
  def find_line_element
582
591
  line = nil
583
- self.scan_lines do |el|
592
+ scan_lines do |el|
584
593
  line = el if el.microstation_type == MSD::MsdElementTypeLine
585
594
  end
586
595
  line
@@ -590,35 +599,32 @@ module Microstation
590
599
  app.to_ole_point3d(pt)
591
600
  end
592
601
 
593
- def create_line(p1,p2,el = nil)
602
+ def create_line(p1, p2, el = nil)
594
603
  # el = find_line_element
595
- pt1,pt2 = [p1,p2].map{ |p| to_ole_point3d(p) }
596
- el = WIN32OLE_VARIANT::Nothing unless el
604
+ pt1, pt2 = [p1, p2].map { |p| to_ole_point3d(p) }
605
+ el ||= WIN32OLE_VARIANT::Nothing
597
606
  el = el.ole_obj if el.respond_to? :ole_obj
598
607
  begin
599
- ole = app.ole_obj.CreateLineElement2(el, pt1,pt2)
608
+ ole = app.ole_obj.CreateLineElement2(el, pt1, pt2)
600
609
  return nil unless ole
610
+
601
611
  app.wrap(ole)
602
- rescue Exception => ex
603
- puts ex.message bb
612
+ rescue Exception => e
613
+ puts e.message bb
604
614
  puts "class: #{el.class}"
605
- return nil
606
- end
615
+ nil
616
+ end
607
617
  end
608
618
 
609
-
610
619
  def to_point(pt)
611
620
  app.to_point(pt)
612
621
  end
613
622
 
614
-
615
623
  protected
616
624
 
617
625
  def normalize_update_hash(h)
618
626
  h = h.to_h if h.respond_to?(:to_h)
619
- if h.kind_of? Hash
620
- h = h.map_keys{|k| k.to_s}
621
- end
627
+ h = h.map_keys { |k| k.to_s } if h.is_a? Hash
622
628
  h
623
629
  end
624
630
 
@@ -633,7 +639,6 @@ module Microstation
633
639
  q << "Print colormode monochrome"
634
640
  q << "Print Execute #{windows_path}"
635
641
  end
636
-
637
642
  end
638
643
 
639
644
  def get_model_for_scan(model = nil)
@@ -643,28 +648,28 @@ module Microstation
643
648
  end
644
649
 
645
650
  def model_from_ole(ole)
646
- Model.new(app,self,ole)
651
+ Model.new(app, self, ole)
647
652
  end
648
653
 
649
- def copy_name(backup_str = '.copy')
650
- lname = self.name.dup
654
+ def copy_name(backup_str = ".copy")
655
+ lname = name.dup
651
656
  ext = File.extname(lname)
652
657
  name = "#{File.basename(lname, ext)}#{backup_str}#{ext}"
653
658
  end
654
659
 
655
660
  def pdf_path(name: nil, dir: nil)
656
- name = name || self.name
657
- dir = Pathname(dir || self.dirname).expand_path
661
+ name ||= self.name
662
+ dir = Pathname(dir || dirname).expand_path
658
663
  dir.mkpath unless dir.directory?
659
664
  dir + pdf_name(name)
660
665
  end
661
666
 
662
667
  def ole_line_element_klass
663
- @line_element ||= ole_classes.find{|c| c.name == '_LineElement'}
668
+ @line_element ||= ole_classes.find { |c| c.name == "_LineElement" }
664
669
  end
665
670
 
666
671
  def ole_element_klass
667
- @element_class ||= ole_classes.find{|c| c.name == '_Element'}
672
+ @element_class ||= ole_classes.find { |c| c.name == "_Element" }
668
673
  end
669
674
 
670
675
  def app_ole_obj
@@ -672,15 +677,11 @@ module Microstation
672
677
  end
673
678
 
674
679
  def typelib
675
- @typelib ||= app_ole_obj.ole_typelib
680
+ @typelib ||= app_ole_obj.ole_typelib
676
681
  end
677
682
 
678
683
  def ole_classes
679
684
  @ole_classes ||= typelib.ole_classes
680
685
  end
681
-
682
-
683
-
684
686
  end
685
-
686
687
  end