microstation 0.4.1 → 0.8.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. checksums.yaml +7 -0
  2. data/.autotest +23 -23
  3. data/.rspec +2 -2
  4. data/Gemfile +29 -10
  5. data/History.txt +6 -6
  6. data/LICENSE.adoc +22 -0
  7. data/Manifest.txt +91 -60
  8. data/README.adoc +131 -0
  9. data/Rakefile +72 -30
  10. data/bin/dgn2pdf +36 -37
  11. data/bin/dgn_template +107 -0
  12. data/bin/pw_print +35 -0
  13. data/cad_files/drawing_faatitle_in_non_default_model.dgn +0 -0
  14. data/cad_files/drawing_no_block.dgn +0 -0
  15. data/cad_files/drawing_with_3_block.dgn +0 -0
  16. data/cad_files/drawing_with_block.dgn +0 -0
  17. data/cad_files/drawing_with_text.dgn +0 -0
  18. data/cad_files/seed2d.dgn +0 -0
  19. data/cad_files/seed3d.dgn +0 -0
  20. data/lib/microstation/app.rb +781 -286
  21. data/lib/microstation/cad_input_queue.rb +100 -25
  22. data/lib/microstation/cell.rb +191 -0
  23. data/lib/microstation/changer.rb +70 -0
  24. data/lib/microstation/configuration.rb +193 -57
  25. data/lib/microstation/criteria_creation_t.rb +23 -0
  26. data/lib/microstation/dir.rb +252 -252
  27. data/lib/microstation/directory.rb +46 -0
  28. data/lib/microstation/drawing.rb +686 -189
  29. data/lib/microstation/element.rb +311 -0
  30. data/lib/microstation/enumerator.rb +32 -29
  31. data/lib/microstation/errors.rb +17 -0
  32. data/lib/microstation/event_handler.rb +28 -0
  33. data/lib/microstation/ext/pathname.rb +23 -25
  34. data/lib/microstation/ext/win32ole.rb +7 -0
  35. data/lib/microstation/extensions/faa.rb +124 -0
  36. data/lib/microstation/file_tests.rb +68 -0
  37. data/lib/microstation/functions.rb +60 -0
  38. data/lib/microstation/graphics.rb +35 -0
  39. data/lib/microstation/line.rb +19 -0
  40. data/lib/microstation/model.rb +45 -0
  41. data/lib/microstation/model_trait.rb +189 -0
  42. data/lib/microstation/ole_cad_input_message.rb +101 -0
  43. data/lib/microstation/ole_helper.rb +152 -0
  44. data/lib/microstation/pdf_support.rb +40 -40
  45. data/lib/microstation/point3d.rb +71 -0
  46. data/lib/microstation/primitive_command_interface.rb +66 -0
  47. data/lib/microstation/properties.rb +61 -57
  48. data/lib/microstation/property_handler.rb +48 -0
  49. data/lib/microstation/scan/color.rb +38 -38
  50. data/lib/microstation/scan/criteria.rb +89 -85
  51. data/lib/microstation/scan/klass.rb +43 -43
  52. data/lib/microstation/scan/level.rb +38 -38
  53. data/lib/microstation/scan/line_style.rb +45 -45
  54. data/lib/microstation/scan/line_weight.rb +33 -33
  55. data/lib/microstation/scan/range.rb +19 -0
  56. data/lib/microstation/scan/scan_trait.rb +51 -0
  57. data/lib/microstation/scan/subtype.rb +40 -40
  58. data/lib/microstation/scan/type.rb +134 -109
  59. data/lib/microstation/scan_trait.rb +62 -0
  60. data/lib/microstation/scanner.rb +24 -24
  61. data/lib/microstation/tag.rb +87 -58
  62. data/lib/microstation/tag_set.rb +385 -280
  63. data/lib/microstation/tag_set_trait.rb +51 -0
  64. data/lib/microstation/tagged_element.rb +105 -0
  65. data/lib/microstation/template.rb +90 -84
  66. data/lib/microstation/template_info.rb +172 -0
  67. data/lib/microstation/template_runner.rb +65 -0
  68. data/lib/microstation/text.rb +79 -54
  69. data/lib/microstation/text_node.rb +124 -74
  70. data/lib/microstation/ts/attribute.rb +140 -139
  71. data/lib/microstation/ts/instance.rb +146 -112
  72. data/lib/microstation/ts/tagset_trait.rb +49 -0
  73. data/lib/microstation/types.rb +91 -91
  74. data/lib/microstation/version.rb +5 -0
  75. data/lib/microstation/wrap.rb +28 -214
  76. data/lib/microstation.rb +252 -88
  77. data/plot/pdf-bw.plt +164 -164
  78. data/plot/pdf.plt +163 -163
  79. data/plot/png.plt +383 -383
  80. data/plot/tiff.plt +384 -384
  81. data/plot/wmbw.tbl +324 -66
  82. data/plot/wmcolor.tbl +62 -62
  83. data/spec/microstation/app_spec.rb +184 -0
  84. data/spec/microstation/configuration_spec.rb +131 -0
  85. data/spec/microstation/drawing_spec.rb +245 -0
  86. data/spec/microstation/functions_spec.rb +36 -0
  87. data/spec/microstation/tag_set_spec.rb +159 -0
  88. data/spec/microstation/template_spec.rb +159 -0
  89. data/spec/microstation/text_node_spec.rb +67 -0
  90. data/spec/microstation/text_spec.rb +42 -0
  91. data/spec/microstation_spec.rb +47 -36
  92. data/spec/spec_helper.rb +97 -31
  93. metadata +308 -84
  94. data/.gemtest +0 -0
  95. data/README.txt +0 -75
  96. data/lib/microstation/attributes.rb +0 -35
  97. data/lib/microstation/extensions/hash.rb +0 -27
  98. data/spec/app_spec.rb +0 -267
  99. data/spec/configuration_spec.rb +0 -122
  100. data/spec/drawing_spec.rb +0 -247
  101. data/spec/drawings/new_drawing.dgn +0 -0
  102. data/spec/drawings/test.dgn +0 -0
  103. data/spec/drawings/test1.dgn +0 -0
  104. data/spec/drawings/testfile.pdf +0 -0
  105. data/spec/enumerator_spec.rb +0 -60
  106. data/spec/scanner_spec.rb +0 -155
  107. data/spec/spec_app.rb +0 -11
  108. data/spec/tag_set_spec.rb +0 -123
  109. data/spec/text_node_spec.rb +0 -92
  110. data/spec/text_spec.rb +0 -62
@@ -0,0 +1,159 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../spec_helper'
4
+ require 'fileutils'
5
+ require 'digest/md5'
6
+
7
+ require 'minitest/spec'
8
+ require 'minitest/autorun'
9
+
10
+ require 'microstation/template'
11
+
12
+ module TestHelper
13
+ def digest_for_path(file)
14
+ Digest::MD5.hexdigest(File.read(file))
15
+ end
16
+
17
+ def file_same?(p, p2)
18
+ digest_path(p) == digest_path(p2)
19
+ end
20
+ end
21
+
22
+ describe Microstation::Template do
23
+ include TestHelper
24
+
25
+ describe 'initialization' do
26
+ it 'needs a drawing argument' do
27
+ assert_raises { Microstation::Template.new }
28
+ end
29
+
30
+ it 'requires a valid and existing microstation file' do
31
+ %w[draw.dgn file://adoc.doc file://anexcel.xls file://autocad.dwg].each do |ftype|
32
+ assert_raises { Microstation::Template.new(ftype) }
33
+ end
34
+ end
35
+
36
+ describe 'given a good dgn file and file exists' do
37
+ let(:file) { 'file.dgn' }
38
+
39
+ it 'does not error' do
40
+ mock = Minitest::Mock.new
41
+ mock.expect(:file?, true)
42
+ File.stub :file?, true do
43
+ Microstation::Template.new(file)
44
+ end
45
+ end
46
+
47
+ it 'sets the template' do
48
+ mock = Minitest::Mock.new
49
+ mock.expect(:file?, true)
50
+ File.stub :file?, true do
51
+ temp = Microstation::Template.new(file)
52
+ _(temp.template).must_equal(file)
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ describe 'a drawing with tags' do
59
+ before do
60
+ @dgn_name = 'drawing_with_block.dgn'
61
+ @dgn_file = drawing_path('drawing_with_block.dgn')
62
+ @template = Microstation::Template.new(@dgn_file)
63
+ end
64
+
65
+ subject { @template }
66
+
67
+ describe '.render' do
68
+ let(:dgn_name) { @dgn_name }
69
+ let(:template) { @template }
70
+ let(:dgn_file) { @dgn_file }
71
+ let(:copied_file) { drawing_path('copied_file.dgn') }
72
+ let(:output_file) { output_path(dgn_name) }
73
+ let(:changed_name) { 'changed_name.dgn' }
74
+ let(:locals) do
75
+ { 'a1' => 'change 1', 'a2' => 'change 2',
76
+ 'a3' => 'c3', 'a4' => 'c4' }
77
+ end
78
+
79
+ before do
80
+ FileUtils.rm(copied_file) if File.exist? copied_file
81
+ FileUtils.cp(dgn_file, copied_file)
82
+ FileUtils.rm(output_file) if File.exist? output_file
83
+ FileUtils.rm(output_path(changed_name)) if File.exist?(output_path(changed_name))
84
+ end
85
+
86
+ after do
87
+ FileUtils.rm(output_file) if File.exist? output_file
88
+ FileUtils.rm(output_path(changed_name)) if File.exist?(output_path(changed_name))
89
+ end
90
+
91
+ it "it doesn't error" do
92
+ template.render(output_dir: OUTPUT_DIR)
93
+ end
94
+
95
+ describe 'when locals or tagsets not input' do
96
+ it 'does nothing unless either locals or tagsets' do
97
+ template.render(output_dir: OUTPUT_DIR)
98
+ _(File.file?(output_file)).must_equal false
99
+ end
100
+ end
101
+
102
+ describe 'when locals or tagset is set' do
103
+ it 'creates a file' do
104
+ template.render(output_dir: OUTPUT_DIR, locals: locals)
105
+ _(File.file?(output_file)).must_equal true
106
+ end
107
+
108
+ it 'changes text' do
109
+ template.render(output_dir: OUTPUT_DIR,
110
+ locals: { 'a1' => 'change 1', 'a2' => 'change 2', 'a3' => 'c3', 'a4' => 'c4' })
111
+ text = Microstation.get_text(output_file)
112
+ ['text1 change 1', 'text2 change 2', 'text3 c3', "node1 c4\nnode1 ", "node2 \nnode2 ",
113
+ 'text a1 again change 1'].each do |t|
114
+ _(text).must_include(t)
115
+ end
116
+ end
117
+
118
+ it "doesn't change input file" do
119
+ template.render(output_dir: OUTPUT_DIR, locals: locals)
120
+ _(FileUtils.compare_file(dgn_file, copied_file)).must_equal true
121
+ end
122
+
123
+ it 'changes the output' do
124
+ template.render(output_dir: OUTPUT_DIR, locals: locals)
125
+ _(FileUtils.compare_file(output_file, copied_file)).must_equal false
126
+ end
127
+ end
128
+
129
+ describe 'a drawing with multiple blocks of the same block' do
130
+ # before :all do
131
+ # @dgn_file = drawing_path('drawing_with_block.dgn')
132
+ # @template = Microstation::Template.new(@dgn_file)
133
+ # end
134
+
135
+ let(:filename) { 'drawing_with_3_block.dgn' }
136
+ let(:drawing_file) { drawing_path(filename) }
137
+ let(:template) { Microstation::Template.new(drawing_file) }
138
+ let(:output_file) { output_path(filename) }
139
+
140
+ before do
141
+ FileUtils.rm(output_file) if File.exist? output_file
142
+ end
143
+
144
+ it 'updates the drawing_blocks' do
145
+ panel = { 'brk_1_service' => 'OUTLETS',
146
+ 'brk_2_service' => 'AIR CONDITIONER',
147
+ 'microstation_id' => 324 }
148
+ template.render(output_dir: OUTPUT_DIR, tagsets: [{ 'electrical_panel_42' => panel }])
149
+ Microstation.run do |app|
150
+ drawing = app.open_drawing(output_file)
151
+ ts = drawing.find_tagset_instance_by_name_and_id('electrical_panel_42', 324)
152
+ _(ts.brk_2_service).must_equal('AIR CONDITIONER')
153
+ end
154
+ end
155
+ end
156
+
157
+ end
158
+ end
159
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../spec_helper'
4
+
5
+ describe 'Microstation::TextNode' do
6
+ include Minitest::Hooks
7
+ before(:all) do
8
+ @app = Microstation::App.new
9
+ config_app(@app)
10
+ end
11
+
12
+ after(:all) do
13
+ @app.quit rescue nil
14
+ end
15
+
16
+ describe 'given a TextNode' do
17
+ let(:app) { @app }
18
+ let(:scanner) { app.create_scanner(:text, &:include_text_nodes) }
19
+ let(:drawing) { open_existing_drawing('drawing_with_text.dgn') }
20
+ let(:text_node) { drawing.scan_model(scanner).find { |t| !t.empty? } }
21
+
22
+ it 'should forward Capitalized methods to @ole_obj' do
23
+ ole = Minitest::Mock.new
24
+ ole.expect(:Type, 'A ole type')
25
+ text_node.stub(:ole_obj, ole) do
26
+ _(text_node.Type).must_equal 'A ole type'
27
+ end
28
+ ole.verify
29
+ end
30
+
31
+ describe 'ruby string methods' do
32
+ describe "calling with methods that don't change the string" do
33
+ it 'should not call the update method' do
34
+ skip
35
+ ole = Minitest::Mock.new
36
+ mock.expect(:update, true)
37
+ text_node.stub(:upcase, true)
38
+
39
+ ole = Minitest::Mock.new
40
+ text_node.reverse
41
+ text_node.downcase
42
+ end
43
+
44
+ it 'should give the correct value' do
45
+ value = text_node.to_s
46
+ _(text_node.reverse.to_s).must_equal(value.reverse)
47
+ end
48
+
49
+ it 'should retain the same value' do
50
+ value = text_node.to_s
51
+ result = text_node.reverse
52
+ _(text_node.to_s).must_equal(value)
53
+ _(text_node.to_s).wont_equal result
54
+ end
55
+ end
56
+
57
+ describe 'calling with methods that change the string' do
58
+ it 'should change the value' do
59
+ value = text_node.to_s
60
+ result = text_node.reverse!
61
+ _(text_node.to_s).must_equal(result)
62
+ _(text_node.to_s).wont_equal(value)
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../spec_helper'
4
+
5
+ describe 'Microstation:Text and Microstation::TextNode' do
6
+ include Minitest::Hooks
7
+ before(:all) do
8
+ @app = Microstation::App.new
9
+ config_app(@app)
10
+ end
11
+ after(:all) do
12
+ @app.quit rescue nil
13
+ end
14
+
15
+ describe 'given a text node initialized by a scan' do
16
+ let(:drawing) { open_existing_drawing('drawing_with_text.dgn') }
17
+ let(:criteria) { @app.create_scanner(&:include_textual) }
18
+
19
+ before do
20
+ text_array = drawing.scan_model(criteria).to_a
21
+ @text = text_array.find { |t| t.instance_of?(Microstation::Text) }
22
+ end
23
+
24
+ let(:text) { @text }
25
+
26
+ it 'should be an instance of text' do
27
+ _(text).must_be_instance_of Microstation::Text
28
+ end
29
+
30
+ it 'should forward all the Microstation commands to ole_obj' do
31
+ _(text.IsTextElement).must_equal true
32
+ end
33
+
34
+ it 'should update the drawing if the text is changed' do
35
+ id = text.microstation_id
36
+ val = text.to_s
37
+ text.reverse!
38
+ drawing_text = drawing.find_by_id(id)
39
+ _(drawing_text.to_s).must_equal(val.reverse)
40
+ end
41
+ end
42
+ end
@@ -1,36 +1,47 @@
1
- #require File.join(File.dirname(__FILE__) , 'spec_helper')
2
- require 'spec_helper.rb'
3
-
4
-
5
- describe Microstation do
6
-
7
- context "#root" do
8
-
9
- subject { Microstation.root}
10
-
11
- it { should be_instance_of Pathname}
12
- it "to_s" do
13
- subject.to_s.should == Pathname.getwd.to_s
14
- end
15
-
16
- end
17
-
18
-
19
- describe "#run" do
20
- it "opens up and yields an app" do
21
- Microstation.run do |app|
22
- app.class.should == Microstation::App
23
- end
24
- end
25
-
26
- it "can be called with implicit receiver" do
27
- Microstation.run do
28
- self.class.should == Microstation::App
29
- end
30
- end
31
-
32
- end
33
-
34
- end
35
-
36
-
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'spec_helper'
4
+
5
+
6
+ describe Microstation do
7
+ describe '#root' do
8
+ subject { Microstation.root }
9
+
10
+ it 'to_s' do
11
+ _(subject.to_s).must_equal(Pathname.getwd.to_s)
12
+ end
13
+ end
14
+
15
+ describe '#run' do
16
+ it 'opens up and yields an app' do
17
+ result = nil
18
+ Microstation.run do |app|
19
+ _(app).must_be_instance_of(Microstation::App)
20
+ end
21
+ end
22
+ end
23
+
24
+ describe '#get_text' do
25
+ let(:drawing_with_text) { drawing_path('drawing_with_text.dgn') }
26
+ let(:drawing_no_text) { drawing_path('drawing_no_block.dgn') }
27
+ let(:text_for_drawing_with_text){ [
28
+ "Four score and seven years ago our fathers brought forth",
29
+ "Out out brief candle\nLifes but a walking shadow",
30
+ "It is my lady, it is my love\nOh that she knew she were"
31
+ ]
32
+ }
33
+
34
+ describe 'when drawing has text' do
35
+ it 'returns the text' do
36
+ text = Microstation.get_text(drawing_with_text)
37
+ _(text.sort).must_equal(text_for_drawing_with_text.sort)
38
+ end
39
+ end
40
+
41
+ describe 'when drawing has no text' do
42
+ it 'returns an empty array' do
43
+ _(Microstation.get_text(drawing_no_text)).must_equal([])
44
+ end
45
+ end
46
+ end
47
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,31 +1,97 @@
1
- # This file was generated by the `rspec --init` command. Conventionally, all
2
- # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
- # Require this file using `require "spec_helper.rb"` to ensure that it is only
4
- # loaded once.
5
- #
6
- # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
-
8
- if RUBY_VERSION =~ /1\.8/
9
- require 'rubygems'
10
- require 'require_relative'
11
- require 'ruby-debug'
12
- end
13
- require 'microstation'
14
- #
15
- DRAWING_DIR = File.join(File.dirname(__FILE__) , 'drawings')
16
- RSpec.configure do |config|
17
- config.treat_symbols_as_metadata_keys_with_true_values = true
18
- config.run_all_when_everything_filtered = true
19
- config.filter_run :focus
20
- end
21
-
22
- def drawing_path(file)
23
- drawing = File.join(DRAWING_DIR,file)
24
- File.expand_path(drawing)
25
- end
26
-
27
- def open_existing_drawing(app)
28
- app.open_drawing( drawing_path('test.dgn'))
29
- end
30
-
31
-
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+ SPEC_DIR = Pathname(__dir__).expand_path
5
+ ROOT_DIR = SPEC_DIR.parent
6
+ DRAWING_DIR = ROOT_DIR + 'cad_files'
7
+ OUTPUT_DIR = ROOT_DIR + 'test_outdir'
8
+ TEMP_DIR = ROOT_DIR + 'tmp'
9
+
10
+ require 'bundler/setup'
11
+ $LOAD_PATH.unshift( ROOT_DIR + 'lib')
12
+
13
+ require 'minitest/spec'
14
+ require 'minitest/autorun'
15
+ require 'minitest/hooks/default'
16
+ require 'microstation'
17
+ require 'pry'
18
+ def drawing_path(file)
19
+ (DRAWING_DIR + file).expand_path
20
+ end
21
+
22
+ def output_path(file = nil)
23
+ if file
24
+ (OUTPUT_DIR + file).expand_path.to_s
25
+ else
26
+ OUTPUT_DIR
27
+ end
28
+ end
29
+
30
+ def seedfile_path(file)
31
+ drawing_path(file)
32
+ end
33
+
34
+ def normalize_path(p)
35
+ p.to_s.sub(/[c,C]:/, 'C:')
36
+ end
37
+
38
+ def config_app(app)
39
+ conf = app.configuration
40
+ conf.prepend('MS_SEEDFILES', DRAWING_DIR)
41
+ # conf.set!('MS_DESIGNSEED','seed2d')
42
+ end
43
+
44
+ def open_existing_drawing(name)
45
+ path = drawing_path(name)
46
+ raise "drawing #{name} doesn't exist" unless File.file?(path)
47
+
48
+ @app.open_drawing(path)
49
+ end
50
+
51
+ def new_drawing(name, seedfile: 'seed2d' )
52
+ seed_path = (drawing_path(seedfile) if seedfile)
53
+ begin
54
+ @app.close_active_drawing
55
+ rescue StandardError
56
+ nil
57
+ end
58
+ @path = output_path(name)
59
+ File.delete(@path) if File.exist? @path
60
+ @app.new_drawing(@path, seedfile: seed_path)
61
+ end
62
+
63
+ def non_existent_path(name)
64
+ path = drawing_path(name)
65
+ File.delete(path) if File.exist? path
66
+ path
67
+ end
68
+
69
+ def delete_current_drawing
70
+ if drawing = @app.current_drawing
71
+ path = drawing.path
72
+ begin
73
+ @app.close_active_drawing
74
+ rescue StandardError
75
+ nil
76
+ end
77
+ begin
78
+ File.delete path
79
+ rescue StandardError
80
+ nil
81
+ end
82
+ end
83
+ end
84
+
85
+ def before_new_drawing
86
+ @app.close_active_drawing
87
+ begin
88
+ File.delete(@path)
89
+ rescue StandardError
90
+ nil
91
+ end
92
+ end
93
+
94
+ # def before_new_drawing
95
+ # @app.close_active_drawing
96
+ # File.delete(@drawing_path) if (@drawing_path && File.exist? @drawing_path)
97
+ # end