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 +4 -4
- data/Manifest.txt +12 -2
- data/cad_files/drawing_faatitle_in_non_default_model.dgn +0 -0
- data/cad_files/drawing_no_block.dgn +0 -0
- data/cad_files/drawing_with_3_block.dgn +0 -0
- data/cad_files/drawing_with_block.dgn +0 -0
- data/cad_files/drawing_with_text.dgn +0 -0
- data/cad_files/seed2d.dgn +0 -0
- data/cad_files/seed3d.dgn +0 -0
- data/lib/microstation/version.rb +1 -1
- data/spec/microstation/app_spec.rb +184 -0
- data/spec/microstation/configuration_spec.rb +131 -0
- data/spec/microstation/drawing_spec.rb +245 -0
- data/spec/microstation/functions_spec.rb +36 -0
- data/spec/microstation/tag_set_spec.rb +159 -0
- data/spec/microstation/template_spec.rb +159 -0
- data/spec/microstation/text_node_spec.rb +67 -0
- data/spec/microstation/text_spec.rb +42 -0
- data/spec/microstation_spec.rb +47 -0
- data/spec/spec_helper.rb +97 -0
- metadata +13 -4
- data/bin/microstation +0 -231
- data/cad_files/test.dgn +0 -0
@@ -0,0 +1,47 @@
|
|
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
ADDED
@@ -0,0 +1,97 @@
|
|
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
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: microstation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dominic Sisneros
|
@@ -339,7 +339,6 @@ email:
|
|
339
339
|
executables:
|
340
340
|
- dgn2pdf
|
341
341
|
- dgn_template
|
342
|
-
- microstation
|
343
342
|
- pw_print
|
344
343
|
extensions: []
|
345
344
|
extra_rdoc_files:
|
@@ -356,14 +355,14 @@ files:
|
|
356
355
|
- Rakefile
|
357
356
|
- bin/dgn2pdf
|
358
357
|
- bin/dgn_template
|
359
|
-
- bin/microstation
|
360
358
|
- bin/pw_print
|
361
359
|
- cad_files/drawing_faatitle_in_non_default_model.dgn
|
362
360
|
- cad_files/drawing_no_block.dgn
|
363
361
|
- cad_files/drawing_with_3_block.dgn
|
364
362
|
- cad_files/drawing_with_block.dgn
|
363
|
+
- cad_files/drawing_with_text.dgn
|
365
364
|
- cad_files/seed2d.dgn
|
366
|
-
- cad_files/
|
365
|
+
- cad_files/seed3d.dgn
|
367
366
|
- lib/microstation.rb
|
368
367
|
- lib/microstation/app.rb
|
369
368
|
- lib/microstation/cad_input_queue.rb
|
@@ -427,6 +426,16 @@ files:
|
|
427
426
|
- plot/tiff.plt
|
428
427
|
- plot/wmbw.tbl
|
429
428
|
- plot/wmcolor.tbl
|
429
|
+
- spec/microstation/app_spec.rb
|
430
|
+
- spec/microstation/configuration_spec.rb
|
431
|
+
- spec/microstation/drawing_spec.rb
|
432
|
+
- spec/microstation/functions_spec.rb
|
433
|
+
- spec/microstation/tag_set_spec.rb
|
434
|
+
- spec/microstation/template_spec.rb
|
435
|
+
- spec/microstation/text_node_spec.rb
|
436
|
+
- spec/microstation/text_spec.rb
|
437
|
+
- spec/microstation_spec.rb
|
438
|
+
- spec/spec_helper.rb
|
430
439
|
homepage: https://github.com/dsisnero/microstation
|
431
440
|
licenses:
|
432
441
|
- MIT
|
data/bin/microstation
DELETED
@@ -1,231 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require_relative '../lib/microstation'
|
3
|
-
|
4
|
-
# app = Microstation::App.new
|
5
|
-
# drawing = app.current_drawing if app.has_current_drawing?
|
6
|
-
# drawing.scan_text do |t|
|
7
|
-
# puts t if t.to_s =~ /{/
|
8
|
-
# end
|
9
|
-
|
10
|
-
module Faa
|
11
|
-
|
12
|
-
module Templates
|
13
|
-
|
14
|
-
:0
|
15
|
-
class App
|
16
|
-
|
17
|
-
attr_reader :racks, :lid, :factype
|
18
|
-
|
19
|
-
def initialize(lid: nil, factype:nil)
|
20
|
-
@lid = lid || 'LID'
|
21
|
-
@factype = factype || 'FACTYPE'
|
22
|
-
@racks = []
|
23
|
-
end
|
24
|
-
|
25
|
-
def add_rco_rack(name: nil)
|
26
|
-
rack = Rco::Rack.new(name):
|
27
|
-
yield rack if block_given?
|
28
|
-
racks << rack
|
29
|
-
rack
|
30
|
-
end
|
31
|
-
|
32
|
-
def dry_run(lid: @lid, factype: @factype, starting_number: 1,dir: nil)
|
33
|
-
accum = { result: [], next_number: nil}
|
34
|
-
result =racks.each_with_object(accum) do |r, o|
|
35
|
-
result, next_number = r.dry_run(lid: lid, factype: factype,ending_number: o[:next_number], starting_number: starting_number )
|
36
|
-
o[:result].concat(result)
|
37
|
-
o[:next_number] = next_number
|
38
|
-
o
|
39
|
-
end
|
40
|
-
result[:result]
|
41
|
-
end
|
42
|
-
|
43
|
-
def run_bak(lid: @lid, factype: @factype, starting_number: 1, dir: Pathname.getwd)
|
44
|
-
changes = dry_run(lid: lid, factype: factype, starting_number: starting_number, dir: dir)
|
45
|
-
return if changes.size == 0
|
46
|
-
Microstation.run do |app|
|
47
|
-
changes.each do |change|
|
48
|
-
app.change_drawing(change[:template], change[:new_name]) do |drawing|
|
49
|
-
drawing.change_template_text(change[:updates])
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def run2(lid: @lid, factype: @factype, starting_number: 1, dir: Pathname.getwd)
|
56
|
-
changes = dry_run(lid: lid, factype: factype, starting_number: starting_number, dir: dir)
|
57
|
-
return if changes.size == 0
|
58
|
-
require 'pry'; binding.pry
|
59
|
-
Microstation.run(visible: true) do |app|
|
60
|
-
changes.each do |change|
|
61
|
-
app.change_drawing(change[:template], name: change[:new_name], output_dir: dir ) do |drawing|
|
62
|
-
drawing.change_template_text(change[:updates])
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def run(lid: @lid, factype: @factype, starting_number: 1, dir: Pathname.getwd)
|
69
|
-
changes = dry_run(lid: lid, factype: factype, starting_number: starting_number, dir: dir)
|
70
|
-
return if changes.size == 0
|
71
|
-
require 'pry'; binding.pry
|
72
|
-
Microstation.run(visible: true) do |app|
|
73
|
-
changes.each do |change|
|
74
|
-
app.render_template(change[:template], name: change[:new_name], output_dir: dir, locals: change[:updates])
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
end
|
80
|
-
|
81
|
-
module Rco
|
82
|
-
|
83
|
-
DIR = ::Microstation::TEMPLATES_PATH + 'rco'
|
84
|
-
|
85
|
-
|
86
|
-
class Rack
|
87
|
-
|
88
|
-
DRAWINGS = (1..3).map{ |n| DIR + "t#{n}.dgn" }
|
89
|
-
CHANNEL_TO_DWG = { 1 => DIR + 't1.dgn',
|
90
|
-
2 => DIR + 't2.dgn',
|
91
|
-
}
|
92
|
-
|
93
|
-
attr_reader :change_steps
|
94
|
-
|
95
|
-
attr_accessor :telco1_tx_drop, :telco1_rx_drop, :telco2_tx_drop, :telco2_rx_drop, :name
|
96
|
-
|
97
|
-
|
98
|
-
def initialize(name = nil, &block)
|
99
|
-
@name = name
|
100
|
-
@change_steps = {}
|
101
|
-
instance_eval(&block) if block_given?
|
102
|
-
end
|
103
|
-
|
104
|
-
def add_channel(freq,number)
|
105
|
-
add_transmitter(freq,number)
|
106
|
-
add_receiver(freq, number)
|
107
|
-
end
|
108
|
-
|
109
|
-
def channel_to_radio_number(chan)
|
110
|
-
number_start = case chan
|
111
|
-
when 1
|
112
|
-
1
|
113
|
-
when 2
|
114
|
-
3
|
115
|
-
when 3
|
116
|
-
5
|
117
|
-
when 4
|
118
|
-
7
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
def channel_to_drawing(chan)
|
123
|
-
case chan
|
124
|
-
when 1
|
125
|
-
DIR + 't1.dgn'
|
126
|
-
when 2
|
127
|
-
DIR + 't2.dgn'
|
128
|
-
end
|
129
|
-
|
130
|
-
end
|
131
|
-
def add_radio( freq, number: 1, type: :tx, func: main)
|
132
|
-
result = []
|
133
|
-
string_type = case type
|
134
|
-
when :tx, 'transmitter', 'tx'
|
135
|
-
'TRANSMITTER'
|
136
|
-
when :rx, 'receiver', 'rx'
|
137
|
-
'RECEIVER'
|
138
|
-
else
|
139
|
-
raise
|
140
|
-
end
|
141
|
-
string_func = case func
|
142
|
-
when :main, /\bmain\b/
|
143
|
-
'MAIN'
|
144
|
-
when :stby, /\bstby\b/i, /\bstandby\b/i
|
145
|
-
'STBY'
|
146
|
-
end
|
147
|
-
|
148
|
-
result << "#{string_type}#{number}"
|
149
|
-
result << "#{freq} MHz #{string_func}"
|
150
|
-
result << "CM-300 V2"
|
151
|
-
result.join("\n")
|
152
|
-
end
|
153
|
-
|
154
|
-
def add_channel(freq:, channel: 1)
|
155
|
-
change_steps[channel] = add_channel_changes(freq, channel)
|
156
|
-
end
|
157
|
-
|
158
|
-
def add_channel_changes(freq, ch)
|
159
|
-
changes = {}
|
160
|
-
changes[:channel] = ch
|
161
|
-
changes[:updates] = text_for_freq_and_channel(freq,ch)
|
162
|
-
end
|
163
|
-
|
164
|
-
def text_for_freq_and_channel(freq,ch)
|
165
|
-
number_start = channel_to_radio_number(ch)
|
166
|
-
{ 'tx1' => add_radio(freq, number: number_start, type: :tx, func: :main),
|
167
|
-
'rx1' => add_radio(freq, number: number_start, type: :rx, func: :main),
|
168
|
-
'tx2' => add_radio( freq, number: number_start + 1, type: :tx, func: :stby),
|
169
|
-
'rx2' => add_radio( freq, number: number_start + 1, type: :rx, func: :stby),
|
170
|
-
}
|
171
|
-
end
|
172
|
-
|
173
|
-
|
174
|
-
def dry_run(lid: , factype: , starting_number: 1, ending_number: nil)
|
175
|
-
starting_number = ending_number || starting_number
|
176
|
-
results = []
|
177
|
-
DRAWINGS.each.with_index(1) do |drawing,ch|
|
178
|
-
new_name = "%s-%s-Q-%03d.dgn" % [lid,factype, starting_number]
|
179
|
-
changes = change_steps.fetch(ch, {})
|
180
|
-
ch = ch + 1
|
181
|
-
starting_number += 1
|
182
|
-
result_hash = { template: drawing, new_name: new_name, updates: changes}
|
183
|
-
results << result_hash
|
184
|
-
|
185
|
-
end
|
186
|
-
|
187
|
-
[results,starting_number]
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
end
|
192
|
-
|
193
|
-
end
|
194
|
-
|
195
|
-
end
|
196
|
-
|
197
|
-
|
198
|
-
if $0 == __FILE__
|
199
|
-
app = Faa::Templates::App.new
|
200
|
-
|
201
|
-
|
202
|
-
app.add_rco_rack do |r|
|
203
|
-
r.add_channel(freq: 255.4, channel: 1)
|
204
|
-
end
|
205
|
-
app.add_rco_rack do |r|
|
206
|
-
r.add_channel(freq: 122.2, channel: 1)
|
207
|
-
r.add_channel(freq: 122.6, channel: 2)
|
208
|
-
end
|
209
|
-
app.add_rco_rack do |r|
|
210
|
-
r.add_channel(freq: 121.5, channel: 1)
|
211
|
-
r.add_channel(freq: 243, channel: 2)
|
212
|
-
end
|
213
|
-
app.run(lid: 'BTF', factype: 'RTR', starting_number: 110, dir: 'btf')
|
214
|
-
|
215
|
-
end
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
# drawing.scan_cells_for_text do |t|
|
224
|
-
# puts t
|
225
|
-
# end
|
226
|
-
|
227
|
-
|
228
|
-
# drawing.scan_cells_for_text do |t|
|
229
|
-
# if t =~ /{{\s+(\w+)\s+}}/
|
230
|
-
# end
|
231
|
-
# end
|
data/cad_files/test.dgn
DELETED
Binary file
|