microstation 0.4.1
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.
- data/.autotest +23 -0
- data/.gemtest +0 -0
- data/.rspec +2 -0
- data/Gemfile +17 -0
- data/History.txt +6 -0
- data/Manifest.txt +60 -0
- data/README.txt +75 -0
- data/Rakefile +30 -0
- data/bin/dgn2pdf +37 -0
- data/lib/microstation.rb +88 -0
- data/lib/microstation/app.rb +286 -0
- data/lib/microstation/attributes.rb +35 -0
- data/lib/microstation/cad_input_queue.rb +25 -0
- data/lib/microstation/configuration.rb +57 -0
- data/lib/microstation/dir.rb +252 -0
- data/lib/microstation/drawing.rb +189 -0
- data/lib/microstation/enumerator.rb +29 -0
- data/lib/microstation/ext/pathname.rb +25 -0
- data/lib/microstation/extensions/hash.rb +27 -0
- data/lib/microstation/pdf_support.rb +40 -0
- data/lib/microstation/properties.rb +57 -0
- data/lib/microstation/scan/color.rb +38 -0
- data/lib/microstation/scan/criteria.rb +85 -0
- data/lib/microstation/scan/klass.rb +43 -0
- data/lib/microstation/scan/level.rb +38 -0
- data/lib/microstation/scan/line_style.rb +45 -0
- data/lib/microstation/scan/line_weight.rb +33 -0
- data/lib/microstation/scan/subtype.rb +40 -0
- data/lib/microstation/scan/type.rb +109 -0
- data/lib/microstation/scanner.rb +24 -0
- data/lib/microstation/tag.rb +58 -0
- data/lib/microstation/tag_set.rb +280 -0
- data/lib/microstation/template.rb +84 -0
- data/lib/microstation/text.rb +54 -0
- data/lib/microstation/text_node.rb +74 -0
- data/lib/microstation/ts/attribute.rb +139 -0
- data/lib/microstation/ts/instance.rb +112 -0
- data/lib/microstation/types.rb +91 -0
- data/lib/microstation/wrap.rb +214 -0
- data/plot/pdf-bw.plt +164 -0
- data/plot/pdf.plt +163 -0
- data/plot/png.plt +383 -0
- data/plot/tiff.plt +384 -0
- data/plot/wmbw.tbl +66 -0
- data/plot/wmcolor.tbl +62 -0
- data/spec/app_spec.rb +267 -0
- data/spec/configuration_spec.rb +122 -0
- data/spec/drawing_spec.rb +247 -0
- data/spec/drawings/new_drawing.dgn +0 -0
- data/spec/drawings/test.dgn +0 -0
- data/spec/drawings/test1.dgn +0 -0
- data/spec/drawings/testfile.pdf +0 -0
- data/spec/enumerator_spec.rb +60 -0
- data/spec/microstation_spec.rb +36 -0
- data/spec/scanner_spec.rb +155 -0
- data/spec/spec_app.rb +11 -0
- data/spec/spec_helper.rb +31 -0
- data/spec/tag_set_spec.rb +123 -0
- data/spec/text_node_spec.rb +92 -0
- data/spec/text_spec.rb +62 -0
- metadata +241 -0
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__) , 'spec_helper')
|
2
|
+
|
3
|
+
describe "Microstation::Enumerator" do
|
4
|
+
|
5
|
+
context "given a drawing scanned with a textual criteria" do
|
6
|
+
|
7
|
+
before(:all) do
|
8
|
+
@app = Microstation::App.new
|
9
|
+
@drawing = open_existing_drawing(@app)
|
10
|
+
@criteria = @app.create_scanner do |scan|
|
11
|
+
scan.include_textual
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
after(:all) do
|
17
|
+
@app.close_active_drawing
|
18
|
+
@app.quit
|
19
|
+
# path = @drawing.full_path
|
20
|
+
#path.delete
|
21
|
+
end
|
22
|
+
|
23
|
+
let(:app) { @app}
|
24
|
+
let(:drawing){@drawing}
|
25
|
+
|
26
|
+
describe "app.scan" do
|
27
|
+
it "returns an Enumerator" do
|
28
|
+
pending
|
29
|
+
enum = app.scan(@criteria)
|
30
|
+
enum.should be_an_instance_of Microstation::Enumerator
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should be a text node" do
|
34
|
+
enum = app.scan(@criteria).to_enum
|
35
|
+
first = enum.next
|
36
|
+
first.should be_an_instance_of Microstation::Text
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should all be textual" do
|
40
|
+
pending
|
41
|
+
enum = app.scan(@criteria)
|
42
|
+
values = enum.map{|i| i}
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
|
@@ -0,0 +1,36 @@
|
|
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
|
+
|
@@ -0,0 +1,155 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__) , 'spec_helper')
|
2
|
+
|
3
|
+
|
4
|
+
describe Microstation::Scan::Criteria do
|
5
|
+
|
6
|
+
before(:all) do
|
7
|
+
@app = Microstation::App.new
|
8
|
+
end
|
9
|
+
|
10
|
+
after(:all) do
|
11
|
+
@app.quit
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:app) { @app}
|
15
|
+
|
16
|
+
describe "#initialize" do
|
17
|
+
|
18
|
+
before(:each) do
|
19
|
+
@ole = double("scan_enum")
|
20
|
+
app.stub(:create_ole_scan_criteria).and_return(@ole)
|
21
|
+
app.stub(:load_constants)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "requires an app as argument" do
|
25
|
+
expect {
|
26
|
+
Microstation::Scan::Criteria.new()
|
27
|
+
}.to raise_error
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
it "sets the ole_obj to the passed in ole_obj" do
|
32
|
+
scanner = Microstation::Scan::Criteria.new(app)
|
33
|
+
scanner.send(:app).should equal(app)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "sets the ole_obj variable" do
|
37
|
+
scanner = Microstation::Scan::Criteria.new(app)
|
38
|
+
scanner.send(:ole_obj).should equal(@ole)
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
describe "Microstation::Scan::Criteria" do
|
45
|
+
before(:each) do
|
46
|
+
@scanner = Microstation::Scan::Criteria.create(app)
|
47
|
+
end
|
48
|
+
|
49
|
+
after(:each) do
|
50
|
+
@scanner.close
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
# after(:all) do
|
55
|
+
# @scanner = nil
|
56
|
+
# @app.quit
|
57
|
+
# end
|
58
|
+
|
59
|
+
let(:scanner){ @scanner}
|
60
|
+
|
61
|
+
it "removes the object from the scanner array on close" do
|
62
|
+
app.scanners.should have(1).item
|
63
|
+
app.scanners.find{|s| s == scanner}.should == scanner
|
64
|
+
scanner.close
|
65
|
+
app.scanners.should_not include(scanner)
|
66
|
+
scanner.ole_obj.should be_nil
|
67
|
+
scanner.app.should be_nil
|
68
|
+
end
|
69
|
+
|
70
|
+
it "can be reset level" do
|
71
|
+
scanner.reset_levels
|
72
|
+
end
|
73
|
+
|
74
|
+
it "can reset types" do
|
75
|
+
scanner.reset_types
|
76
|
+
end
|
77
|
+
|
78
|
+
it "can reset classes" do
|
79
|
+
scanner.reset_classes
|
80
|
+
end
|
81
|
+
|
82
|
+
it "can reset all exclusions" do
|
83
|
+
|
84
|
+
%w(classes colors levels linestyles lineweights subtypes types).each do |method|
|
85
|
+
scanner.send("reset_#{method}")
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe 'the win32ole object' do
|
90
|
+
before(:each) do
|
91
|
+
@ole = double('ole')
|
92
|
+
@ole.stub('load_constants')
|
93
|
+
scanner.stub('ole_obj').and_return @ole
|
94
|
+
end
|
95
|
+
|
96
|
+
after(:each) do
|
97
|
+
@ole = nil
|
98
|
+
end
|
99
|
+
|
100
|
+
let(:ole){@ole}
|
101
|
+
|
102
|
+
it "can scan by type" do
|
103
|
+
ole.should_receive('ExcludeAllTypes')
|
104
|
+
ole.should_receive('IncludeType').with 37# Microstation::MSD::MsdElementTypeTag
|
105
|
+
scanner.include_tags
|
106
|
+
scanner.resolve
|
107
|
+
end
|
108
|
+
|
109
|
+
it "can scan by color" do
|
110
|
+
ole.should_receive('ExcludeAllColors')
|
111
|
+
ole.should_receive('IncludeColor').with(3)
|
112
|
+
scanner.include_color(3)
|
113
|
+
scanner.resolve
|
114
|
+
end
|
115
|
+
|
116
|
+
it "can scan by linestyle" do
|
117
|
+
ole.should_receive('ExcludeAllLineStyles')
|
118
|
+
ole.should_receive('IncludeLineStyle')
|
119
|
+
scanner.include_linestyle( scanner.linestyles[0])
|
120
|
+
scanner.resolve
|
121
|
+
end
|
122
|
+
|
123
|
+
it "can scan by lineweight" do
|
124
|
+
ole.should_receive('ExcludeAllLineWeights')
|
125
|
+
ole.should_receive('IncludeLineWeight')
|
126
|
+
scanner.include_lineweight(3)
|
127
|
+
scanner.resolve
|
128
|
+
end
|
129
|
+
|
130
|
+
it "can scan by subtype" do
|
131
|
+
ole.should_receive('ExcludeAllSubtypes')
|
132
|
+
ole.should_receive('IncludeSubtype')
|
133
|
+
scanner.include_subtype( Microstation::MSD::MsdElementSubtypeAuxiliaryCoordinateSystem)
|
134
|
+
scanner.resolve
|
135
|
+
end
|
136
|
+
|
137
|
+
it "can scan by multiple" do
|
138
|
+
ole.should_receive('ExcludeAllColors')
|
139
|
+
ole.should_receive('IncludeColor').with(3)
|
140
|
+
ole.should_receive('ExcludeAllTypes')
|
141
|
+
ole.should_receive('IncludeType').with(37)
|
142
|
+
scanner.include_color(3)
|
143
|
+
scanner.include_tags
|
144
|
+
scanner.resolve
|
145
|
+
end
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
154
|
+
|
155
|
+
|
data/spec/spec_app.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,31 @@
|
|
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
|
+
|
@@ -0,0 +1,123 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__) , 'spec_helper')
|
2
|
+
require 'tempfile'
|
3
|
+
|
4
|
+
|
5
|
+
module Helper
|
6
|
+
|
7
|
+
def create_temp_drawing
|
8
|
+
file = Tempfile.new('drawing.dgn')
|
9
|
+
file.close
|
10
|
+
@app.new_drawing(file.path)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
describe Microstation::TagSet do
|
17
|
+
|
18
|
+
include Helper
|
19
|
+
|
20
|
+
before(:all) do
|
21
|
+
@app = Microstation::App.new
|
22
|
+
end
|
23
|
+
|
24
|
+
after(:all) do
|
25
|
+
@app.close_active_drawing if @app
|
26
|
+
@app.quit
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'a new drawing' do
|
30
|
+
let(:new_drawing){ create_temp_drawing}
|
31
|
+
|
32
|
+
|
33
|
+
context 'creating a new tag set' do
|
34
|
+
let(:tagsets){ new_drawing.tagsets}
|
35
|
+
|
36
|
+
it 'should have no initial tagsets' do
|
37
|
+
tagsets['test'].should be_nil
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should return a tagset' do
|
41
|
+
ts = tagsets.create('test')
|
42
|
+
ts.should be_instance_of Microstation::TagSet
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should be the same as a found tagset' do
|
46
|
+
ts = tagsets.create('test')
|
47
|
+
tagsets['test'].should == ts
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should allow you to remove a tagset' do
|
51
|
+
tagsets.create('test')
|
52
|
+
tagsets.size.should == 1
|
53
|
+
tagsets.remove('test')
|
54
|
+
tagsets.should be_empty
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe 'A Tag Set' do
|
61
|
+
let(:app) { @app}
|
62
|
+
let(:new_drawing){ create_temp_drawing}
|
63
|
+
|
64
|
+
describe "#create_tagset" do
|
65
|
+
|
66
|
+
it 'should allow you to create' do
|
67
|
+
ts = new_drawing.create_tagset('faatitle')
|
68
|
+
ts.should be_instance_of Microstation::TagSet
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should yield to block if given a block' do
|
72
|
+
new_drawing.create_tagset('faatitle') do |ts|
|
73
|
+
ts.should be_an_instance_of Microstation::TagSet
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'given a new TagSet' do
|
78
|
+
let(:tagset){ new_drawing.create_tagset('faatitle')}
|
79
|
+
|
80
|
+
it 'should have no attributes' do
|
81
|
+
tagset.attributes.should be_empty
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'should allow you to add new definitions' do
|
85
|
+
tagset.attributes.should be_empty
|
86
|
+
td = tagset.add_attribute('title', String, :prompt => 'My title')
|
87
|
+
|
88
|
+
td.prompt.should == 'My title'
|
89
|
+
tagset.attributes.size.should == 1
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
context 'given a tagset with tag definitions' do
|
96
|
+
let(:tagset){ new_drawing.create_tagset('faatitle')}
|
97
|
+
# let(:td1){ tagset.definition('title',String)}
|
98
|
+
# let(:td2){ tagset.definition('city', String)}
|
99
|
+
|
100
|
+
it 'should have correct size' do
|
101
|
+
tagset.attributes.size.should == 0
|
102
|
+
tagset.add_attribute('title', String)
|
103
|
+
tagset.attributes.size.should == 1
|
104
|
+
tagset.add_attribute('city',String)
|
105
|
+
tagset.attributes.size.should == 2
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'should allow you to retrieve a td' do
|
109
|
+
td = tagset.add_attribute('title', String)
|
110
|
+
tagset['title'].should == td
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__) , 'spec_helper')
|
2
|
+
|
3
|
+
module NodeHelper
|
4
|
+
|
5
|
+
def text_node_scanner(app)
|
6
|
+
app.create_scanner do |scan|
|
7
|
+
scan.include_text_nodes
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
describe "Microstation::TextNode" do
|
16
|
+
|
17
|
+
include NodeHelper
|
18
|
+
|
19
|
+
context "given a TextNode" do
|
20
|
+
|
21
|
+
before(:all) do
|
22
|
+
@app = Microstation::App.new
|
23
|
+
@scanner = text_node_scanner(app)
|
24
|
+
end
|
25
|
+
after(:all) do
|
26
|
+
@app.quit
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
let(:app){ @app }
|
31
|
+
let(:drawing) { open_existing_drawing(app) }
|
32
|
+
let(:text_node) { drawing.scan(@scanner).find{|t| !(t.empty?) }}
|
33
|
+
|
34
|
+
it "should forward Capitalized methods to @ole_obj" do
|
35
|
+
ole = double('ole')
|
36
|
+
text_node.stub(:ole_obj).and_return(ole)
|
37
|
+
ole.should_receive('Type').and_return
|
38
|
+
text_node.Type
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "ruby string methods" do
|
42
|
+
|
43
|
+
context "calling with methods that don't change the string" do
|
44
|
+
|
45
|
+
it "should not call the update method" do
|
46
|
+
ole = double('ole')
|
47
|
+
text_node.stub(:ole_obj).and_return(ole)
|
48
|
+
text_node.should_not_receive('update_ole')
|
49
|
+
ole.should_not_receive("Rewrite")
|
50
|
+
text_node.reverse
|
51
|
+
text_node.downcase
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should give the correct value" do
|
55
|
+
value = text_node.to_s
|
56
|
+
text_node.reverse.to_s.should == value.reverse
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should retain the same value" do
|
60
|
+
value = text_node.to_s
|
61
|
+
text_node.reverse
|
62
|
+
text_node.to_s.should == value
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context "calling with methods that change the string" do
|
67
|
+
|
68
|
+
it "should call the update method" do
|
69
|
+
value = text_node.to_s
|
70
|
+
reversed = value.reverse
|
71
|
+
text_node.should_receive('update_ole').with(reversed)
|
72
|
+
text_node.reverse!
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should change to value" do
|
76
|
+
value = text_node.to_s
|
77
|
+
reversed = value.reverse
|
78
|
+
text_node.reverse!
|
79
|
+
text_node.to_s.should == reversed
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|