microstation 0.8.3 → 0.8.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6cca38a310ee39f8557bfcdef2653c8ddd7aa71500d35f26a4d42beecd2a67b3
4
- data.tar.gz: 422e4761645e7f090668768bb924c06fd1e1408c7f3ef3676f4e065b979bd648
3
+ metadata.gz: c9e258964e3bdc19c8148e0c28f075c20e4a3b7432671d4738eeb928ec2d3e54
4
+ data.tar.gz: 24656d582226c6d708c2bb2dc1f05a4e5109bb0ebcd6e2c75ea1c94d0377f495
5
5
  SHA512:
6
- metadata.gz: 596e5f21984f6398fab508602a72a6f0a944a00839488254c429805a7216d6970daad21a8787e19411f772a09475f505ffb84edd81db928fa97bcdeecce1a138
7
- data.tar.gz: 443971dc34318bf02c939450c63f57451973db5d0eddd42ba4a7ee136a9db887b10245c3a8f7f18ba3c61149b69b8315a1d79eeb4130fe66a4105ef0a4c814a7
6
+ metadata.gz: b251be1af95e568c99fd52ad9cf02ead81681b1decf5c799b35a0d674cb96c457c3011c737658bab1ce52d4620dae59800f0f2a93fbcd4b9b22a09847b4ce9c6
7
+ data.tar.gz: 8d6220c777a73e1d90182469aa77511a3ceffe8970b94ddb1155d15b1d878ccfdc41a0eb20bfb858c03e55512f9891ad7a739feff2dfc5fb8902b7dc8d68b389
data/Manifest.txt CHANGED
@@ -7,15 +7,15 @@ Manifest.txt
7
7
  README.adoc
8
8
  Rakefile
9
9
  bin/dgn2pdf
10
- bin/microstation
11
10
  bin/dgn_template
12
11
  bin/pw_print
13
12
  cad_files/drawing_faatitle_in_non_default_model.dgn
14
13
  cad_files/drawing_no_block.dgn
15
14
  cad_files/drawing_with_3_block.dgn
16
15
  cad_files/drawing_with_block.dgn
16
+ cad_files/drawing_with_text.dgn
17
17
  cad_files/seed2d.dgn
18
- cad_files/test.dgn
18
+ cad_files/seed3d.dgn
19
19
  lib/microstation.rb
20
20
  lib/microstation/app.rb
21
21
  lib/microstation/cad_input_queue.rb
@@ -79,3 +79,13 @@ plot/png.plt
79
79
  plot/tiff.plt
80
80
  plot/wmbw.tbl
81
81
  plot/wmcolor.tbl
82
+ spec/microstation/app_spec.rb
83
+ spec/microstation/configuration_spec.rb
84
+ spec/microstation/drawing_spec.rb
85
+ spec/microstation/functions_spec.rb
86
+ spec/microstation/tag_set_spec.rb
87
+ spec/microstation/template_spec.rb
88
+ spec/microstation/text_node_spec.rb
89
+ spec/microstation/text_spec.rb
90
+ spec/microstation_spec.rb
91
+ spec/spec_helper.rb
Binary file
Binary file
Binary file
Binary file
data/cad_files/seed2d.dgn CHANGED
Binary file
Binary file
@@ -1,5 +1,5 @@
1
1
  module Microstation
2
2
 
3
- VERSION = '0.8.3'
3
+ VERSION = '0.8.4'
4
4
 
5
5
  end
@@ -0,0 +1,184 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../spec_helper'
4
+
5
+ describe Microstation::App do
6
+
7
+ after(:all) do
8
+ app.quit rescue nil
9
+ end
10
+ describe '#initialize' do
11
+ describe 'visibility' do
12
+ it 'is invisible with no options' do
13
+ app = Microstation::App.new
14
+ _(app).wont_be :visible
15
+ end
16
+
17
+ it 'can be set with option' do
18
+ app = Microstation::App.new(visible: true)
19
+ _(app).must_be :visible
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ describe 'an open Microstation App' do
26
+ after(:all) do
27
+ app.quit rescue nil
28
+ end
29
+ let(:app) { Microstation::App.new }
30
+
31
+ it 'loads the constants' do
32
+ app
33
+ _(Microstation::MSD::MsdElementTypeTag).must_equal 37
34
+ end
35
+
36
+ describe '#can_open?' do
37
+ it 'is true for dgn and dwg files' do
38
+ %w[dgn dwg].each do |ext|
39
+ name = "test.#{ext}"
40
+ _(app.can_open?(name)).must_equal true
41
+ end
42
+ end
43
+
44
+ it 'is false for other filetypes' do
45
+ %w[pdf doc jpg pgn].each do |ext|
46
+ name = "test.#{ext}"
47
+ _(app.can_open?(name)).wont_equal true
48
+ end
49
+ end
50
+ end
51
+
52
+ describe 'open_drawing' do
53
+ describe 'when valid drawing' do
54
+ let(:path) { drawing_path('drawing_with_text.dgn') }
55
+
56
+ it 'returns a drawing' do
57
+ drawing = app.open_drawing(path)
58
+ _(drawing).must_be_instance_of Microstation::Drawing
59
+ drawing.close
60
+ end
61
+
62
+ describe 'when given a block' do
63
+ it 'yield the drawing to the block' do
64
+ app.open_drawing(path) do |d|
65
+ _(d).must_be_instance_of Microstation::Drawing
66
+ end
67
+ end
68
+
69
+ it 'closes the drawing after block returns' do
70
+ _(app.active_design_file).must_be_nil
71
+ app.open_drawing(path) do |d|
72
+ _(d).must_be_instance_of Microstation::Drawing
73
+ _(app.active_design_file).must_be_instance_of Microstation::Drawing
74
+ end
75
+ _(app.active_design_file).must_be_nil
76
+ end
77
+ end
78
+ end
79
+
80
+ describe 'when a non existent drawing' do
81
+ it 'raises an error' do
82
+ _ { app.open_drawing('a_bogus_file.dgn') }.must_raise Microstation::Error
83
+ end
84
+ end
85
+ end
86
+
87
+ describe '#ole_obj' do
88
+ it 'returns an instance of the WIN32OLE' do
89
+ _(app.ole_obj).must_be_instance_of WIN32OLE
90
+ end
91
+ end
92
+
93
+ describe '#create_scanner' do
94
+ it 'can yield a Microstation::Scan::Criteria' do
95
+ scan = app.create_scanner do |sc|
96
+ _(sc).must_be_instance_of Microstation::Scan::Criteria
97
+ end
98
+ end
99
+
100
+ it 'can accept a name' do
101
+ scanner = app.create_scanner(:my_scanner) do |sc|
102
+ sc.include_textual
103
+ sc.include_tags
104
+ end
105
+ _(scanner).must_be_instance_of Microstation::Scan::Criteria
106
+ _(app.scanners[:my_scanner]).must_be_same_as scanner
107
+ end
108
+ end
109
+
110
+ describe '#normalize_name' do
111
+ it 'returns the name if the name is absolute' do
112
+ _(app.normalize_name('c:/my_drawings/test.dgn').to_s).must_equal 'c:/my_drawings/test.dgn'
113
+ end
114
+
115
+ # describe "with relative path" do
116
+ # let(:app){ Microstation::App.new}
117
+ # let(:drawing_name){ "test.dgn"}
118
+
119
+ # describe "when project dir is set" do
120
+ # app.project_dir = "c:/projects/new"
121
+ # _(app.normalize_name(drawing_name)).must_equal "c:/projects/new/#{drawing_name}"
122
+ # end
123
+
124
+ # describe "when project dir is not set" do
125
+ # _(app.normalize_name(drawing_name)).must_equal (Pathname.getwd + drawing_name).to_s
126
+ # end
127
+
128
+ # end
129
+ end
130
+
131
+ it 'has a username method' do
132
+ _(app.username).must_equal ENV['USERNAME']
133
+ end
134
+
135
+ describe '#new_drawing' do
136
+ let(:new_path) { output_path('new_drawing.dgn') }
137
+
138
+ after do
139
+ app.close_active_drawing
140
+ File.delete(new_path) if File.exist? new_path
141
+ end
142
+
143
+ it 'needs a filename' do
144
+ _ { app.new_drawing }.must_raise
145
+ end
146
+
147
+ it 'raises an error if drawing exists' do
148
+ path = drawing_path('drawing_with_text.dgn')
149
+ _ { app.new_drawing(path) }.must_raise
150
+ end
151
+
152
+ it 'creates a drawing if the drawing path is new' do
153
+ drawing = app.new_drawing(new_path)
154
+ _(drawing).must_be_instance_of Microstation::Drawing
155
+ end
156
+
157
+ describe 'when given a block' do
158
+ it 'yields the drawing to a block if a block is given' do
159
+ app.new_drawing(new_path) do |d|
160
+ _(d).must_be_instance_of Microstation::Drawing
161
+ end
162
+ end
163
+
164
+ it 'closes drawing after block returns' do
165
+ _(app.active_design_file).must_be_nil
166
+ app.new_drawing(new_path) do |d|
167
+ _(d).must_be_instance_of Microstation::Drawing
168
+ _(app.active_design_file).must_be_instance_of Microstation::Drawing
169
+ end
170
+ _(app.active_design_file).must_be_nil
171
+ end
172
+ end
173
+ end
174
+
175
+ describe 'render_template' do
176
+ describe 'with a valid dgn' do
177
+ let(:dgn) { drawing_path('drawing_with_block.dgn') }
178
+
179
+ it 'completes' do
180
+ app.render_template(dgn)
181
+ end
182
+ end
183
+ end
184
+ end
@@ -0,0 +1,131 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../spec_helper'
4
+
5
+ describe Microstation::Configuration 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
+ let(:config) { Microstation::Configuration.new(@app) }
17
+ let(:defined_name) { 'new_variable' }
18
+ let(:defined_value) { 'new_variable_value' }
19
+ let(:undefined_name) { 'undefined_variable' }
20
+
21
+ before do
22
+ config.remove_variable(undefined_name)
23
+ config.set!(defined_name, defined_value)
24
+ end
25
+
26
+ describe '#remove_variable' do
27
+ it 'removes an existing variable' do
28
+ _(config[defined_name]).must_equal defined_value
29
+ config.remove_variable(defined_name)
30
+ _(config[defined_name]).must_be_nil
31
+ end
32
+
33
+ it "doesn't error if variable nonexistent" do
34
+ config.remove_variable 'this_bogus_variable_should_not_exist'
35
+ end
36
+ end
37
+
38
+ describe '#[]' do
39
+ it 'should check if value exists' do
40
+ skip
41
+ config_mock = Minitest::Mock.new
42
+ config_mock.expect :exists?, true
43
+ config.stub :[], config_mock do
44
+ config['undefined']
45
+ end
46
+ config_mock.verify
47
+ end
48
+
49
+ it 'should return the configuration variable if exists' do
50
+ _(config[defined_name]).must_equal defined_value
51
+ end
52
+
53
+ it 'should return nil if not exists' do
54
+ _(config[undefined_name]).must_be_nil
55
+ end
56
+ end
57
+
58
+ describe '[]=, setting variables' do
59
+ describe 'value not existing yet' do
60
+ it 'should set the variable' do
61
+ _(config[undefined_name]).must_be_nil
62
+ config[undefined_name] = 'its set'
63
+ _(config[undefined_name]).must_equal 'its set'
64
+ end
65
+ end
66
+
67
+ describe 'value existing' do
68
+ it 'should raise variable defined if force option is false' do
69
+ _ { config[defined_name] = 'my new value' }.must_raise ::Microstation::VariableDefined
70
+ end
71
+
72
+ it 'should keep existing value' do
73
+ _(config[defined_name]).must_equal defined_value
74
+ _ { config[defined_name] = 'my new value' }.must_raise
75
+ _(config[defined_name]).must_equal defined_value
76
+ end
77
+
78
+ it 'should change the variable if force is true' do
79
+ _(config[defined_name]).must_equal(defined_value)
80
+ config.set!(defined_name, 'my new value')
81
+ _(config[defined_name]).must_equal 'my new value'
82
+ end
83
+ end
84
+ end
85
+
86
+ describe '#exists' do
87
+ it 'should return true if config variable exists' do
88
+ _((config).exists?(defined_name)).must_equal true
89
+ end
90
+
91
+ it "should return false if config variable doesn't exist" do
92
+ _(config.exists?(undefined_name)).wont_equal true
93
+ end
94
+ end
95
+
96
+ describe '#prepend' do
97
+ describe 'variable exists' do
98
+ it 'should prepend the value' do
99
+ value_before = config[defined_name]
100
+ config.prepend(defined_name, 'added')
101
+ value_after = config[defined_name]
102
+ _(value_after).must_equal "added;#{value_before}"
103
+ end
104
+
105
+ describe 'variable nonexistent' do
106
+ it 'should add the value' do
107
+ value_before = config[undefined_name]
108
+ config.prepend(undefined_name, 'added')
109
+ value_after = config[undefined_name]
110
+ _(value_after).must_equal 'added'
111
+ end
112
+ end
113
+ end
114
+ end
115
+
116
+ describe '#expand' do
117
+ let(:dir) {}
118
+
119
+ before do
120
+ config['DIR'] = 'c:/Users/Tom'
121
+ end
122
+
123
+ after do
124
+ config.remove_variable('DIR')
125
+ end
126
+
127
+ it 'should expand the string' do
128
+ _(config.expand('$(DIR)/project')).must_equal 'c:/Users/Tom/project'
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,245 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../spec_helper'
4
+
5
+ $LOAD_PATH.unshift(File.join(__dir__, '../lib'))
6
+
7
+ # require 'minitest/spec'
8
+ # require 'minitest/autorun'
9
+
10
+ describe 'Lets start the Microstation once' do
11
+ include Minitest::Hooks
12
+ before(:all) do
13
+ @app = Microstation::App.new
14
+ config_app(@app)
15
+ end
16
+
17
+ after(:all) do
18
+ @app.quit rescue nil
19
+ end
20
+
21
+ describe 'a drawing created with app.new drawing' do
22
+ let(:drawing) { new_drawing('temp.dgn', seedfile: 'seed2d') }
23
+
24
+ it 'should be active drawing' do
25
+ _(drawing).must_be :active?
26
+ end
27
+
28
+ it 'should have an ole_obj' do
29
+ _(drawing.ole_obj).must_be_instance_of WIN32OLE
30
+ end
31
+
32
+ describe '#author' do
33
+ it "should be '' for new drawing" do
34
+ skip
35
+ _(drawing.author).must_equal ''
36
+ end
37
+
38
+ it 'should set author if given a new author' do
39
+ drawing.author = 'A newer author'
40
+ _(drawing.author).must_equal 'A newer author'
41
+ end
42
+ end
43
+
44
+ describe '#title' do
45
+ it "should be '' to start" do
46
+ expect(drawing.title).must_equal('')
47
+ end
48
+
49
+ it 'should set title if given a new title' do
50
+ drawing.title = 'a new title'
51
+ expect(drawing.title).must_equal 'a new title'
52
+ end
53
+ end
54
+
55
+ describe '#keywords' do
56
+ it 'should be empty string to start' do
57
+ _(drawing.keywords).must_equal ''
58
+ end
59
+
60
+ it 'should set keywords if given a string of words' do
61
+ drawing.keywords = 'project, rcl, new'
62
+ _(drawing.keywords).must_equal 'project, rcl, new'
63
+ end
64
+ end
65
+
66
+ describe '#comments' do
67
+ it 'should be nil to start' do
68
+ _(drawing.comments).must_equal ''
69
+ end
70
+
71
+ it 'should be able to be set' do
72
+ drawing.comments = 'these are comments'
73
+ _(drawing.comments).must_equal 'these are comments'
74
+ end
75
+ end
76
+
77
+ it 'should be able to save as pdf' do
78
+ drawing.save_as_pdf
79
+ end
80
+
81
+ describe 'revision count' do
82
+ it 'should have a revision_count' do
83
+ _(drawing).must_respond_to(:revision_count)
84
+ end
85
+
86
+ it 'should forward revision count to ole_obj' do
87
+ skip
88
+ ole = drawing.ole_obj
89
+ ole.stub :DesignRevisionCount, true do
90
+ assert drawing.revision_count
91
+ end
92
+ end
93
+ end
94
+
95
+ describe 'pdf_name' do
96
+ describe 'with no args' do
97
+ it 'should equal the drawing path with ext changed' do
98
+ drawing.stub(:name, 'Drawing Name.dgn') do
99
+ _(drawing.pdf_name.to_s).must_equal 'Drawing Name.pdf'
100
+ end
101
+ end
102
+ end
103
+
104
+ describe 'with arg for name' do
105
+ it 'should equal the arg and the current directory' do
106
+ _(drawing.pdf_name('my_drawing').to_s).must_equal('my_drawing.pdf')
107
+ end
108
+ end
109
+ end
110
+
111
+ describe 'save_as_pdf' do
112
+ it 'should find the pdf name with pdf_name rules' do
113
+ skip
114
+ path = drawing.path
115
+ _(drawing).to receive(:pdf_name).with('testfile', nil)
116
+ drawing.save_as_pdf('testfile')
117
+ end
118
+ end
119
+
120
+ describe 'scanning' do
121
+ it 'should have a #create_scanner' do
122
+ scanner = drawing.create_scanner(:test)
123
+ _(scanner).must_be_instance_of Microstation::Scan::Criteria
124
+ end
125
+
126
+ it 'should scan the drawing' do
127
+ scanner = drawing.create_scanner(:test) do |scan|
128
+ _(scan).must_be_instance_of Microstation::Scan::Criteria
129
+ end
130
+ drawing.scan_model(scanner)
131
+ end
132
+ end
133
+
134
+ describe '#scan_text' do
135
+ it 'only yields textual items' do
136
+ drawing.scan_text do |item|
137
+ _(item.class).must_equal(Microstation::Text || Microstation::TextNode)
138
+ end
139
+ end
140
+ end
141
+
142
+ describe '#update_tagset' do
143
+ describe 'when 1 block exists' do
144
+ end
145
+
146
+ describe 'when 1 block not in default drawing' do
147
+ let(:drawing) { new_drawing('test.dgn', seedfile: 'drawing_faatitle_in_non_default_model.dgn') }
148
+ let(:app) { @app }
149
+
150
+ it 'finds tagsets in drawing' do
151
+ tagsets = drawing.tagsets_in_drawing.to_a
152
+ _(tagsets.size).must_be :>, 0
153
+ end
154
+
155
+ it 'updates tagset' do
156
+ ts = drawing.find_tagset_instance_by_name('faatitle')
157
+ ts_title = ts['title1'].to_s
158
+ _(ts_title).must_equal('TITLE 1')
159
+ drawing.update_tagset('faatitle', { 'title1' => 'MY NEW TITLE' })
160
+ ts = drawing.find_tagset_instance_by_name('faatitle')
161
+ _(ts['title1'].to_s).must_equal('MY NEW TITLE')
162
+ end
163
+ end
164
+ describe 'when multiple blocks' do
165
+ let(:drawing) { new_drawing('test.dgn', seedfile: 'drawing_with_3_block.dgn') }
166
+ let(:panel_atts) { { 'brk_1_service' => 'OUTLETS', 'brk_2_service' => 'AIR CONDITIONER' } }
167
+ let(:app) { @app }
168
+
169
+ before do
170
+ before_new_drawing
171
+ end
172
+
173
+ describe '#save_tagsets' do
174
+ it 'saves the atts to a file' do
175
+ drawing.save_tagsets_to_file("#{Microstation::ROOT}drawing_atts.txt")
176
+ end
177
+ end
178
+
179
+ describe 'with no microstation_id' do
180
+ it 'errors' do
181
+ _ { drawing.update_tagset('electrical_panel_42', panel_atts) }.must_raise Microstation::MultipleUpdateError
182
+ end
183
+ end
184
+
185
+ describe 'when multiple blocks exist and microstation_id' do
186
+ it 'updates drawing with block' do
187
+ ts = drawing.find_tagset_instance_by_name_and_id('electrical_panel_42', 324)
188
+ _(ts.brk_1_service).must_equal('')
189
+ _(ts.brk_2_service).must_equal('')
190
+ panel = panel_atts.merge({ 'microstation_id' => 324 })
191
+ drawing.update_tagset('electrical_panel_42', panel)
192
+ ts = drawing.find_tagset_instance_by_name_and_id('electrical_panel_42', 324)
193
+ _(ts.brk_2_service).must_equal('AIR CONDITIONER')
194
+ _(ts.brk_1_service).must_equal('OUTLETS')
195
+ end
196
+ end
197
+ end
198
+ end
199
+ describe '#get_text' do
200
+ describe 'drawing with no text' do
201
+ let(:drawing) { open_existing_drawing('drawing_no_block.dgn') }
202
+ it 'returns empty array if text has no text' do
203
+ _(drawing.get_text.to_a).must_equal([])
204
+ end
205
+ end
206
+
207
+ describe 'drawing_with_text in block' do
208
+ let(:drawing) { open_existing_drawing('drawing_with_block.dgn') }
209
+ let(:text_in_drawing) do
210
+ ['text1 {{ a1 }}',
211
+ 'text2 {{ a2 }}',
212
+ 'text3 {{ a3 }}',
213
+ "node1 {{ a4 }}\nnode1 {{ a5 }}",
214
+ "node2 {{ a7 }}\nnode2 {{ a7 }}",
215
+ 'text a1 again {{ a1 }}']
216
+ end
217
+
218
+ it 'gets all the text if drawing has text' do
219
+ text_from_drawing = drawing.get_text
220
+ _(text_from_drawing.to_a.sort).must_equal(text_in_drawing.sort)
221
+ end
222
+ end
223
+ end
224
+
225
+ describe '2d and 3d' do
226
+ describe 'when have a 2d drawing' do
227
+ let(:drawing) { new_drawing('temp.dgn', seedfile: 'seed2d') }
228
+
229
+ it 'should be 2d and not 3d two_d? ' do
230
+ _(drawing).must_be :two_d?
231
+ _(drawing).wont_be :three_d?
232
+ end
233
+ end
234
+
235
+ describe 'when we have a 3d drawing' do
236
+ let(:drawing) { new_drawing('temp.dgn', seedfile: 'seed3d') }
237
+
238
+ it 'should be 3d and not 2d' do
239
+ _(drawing).must_be :three_d?
240
+ _(drawing).wont_be :two_d?
241
+ end
242
+ end
243
+ end
244
+ end
245
+ end