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.
Files changed (61) hide show
  1. data/.autotest +23 -0
  2. data/.gemtest +0 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +17 -0
  5. data/History.txt +6 -0
  6. data/Manifest.txt +60 -0
  7. data/README.txt +75 -0
  8. data/Rakefile +30 -0
  9. data/bin/dgn2pdf +37 -0
  10. data/lib/microstation.rb +88 -0
  11. data/lib/microstation/app.rb +286 -0
  12. data/lib/microstation/attributes.rb +35 -0
  13. data/lib/microstation/cad_input_queue.rb +25 -0
  14. data/lib/microstation/configuration.rb +57 -0
  15. data/lib/microstation/dir.rb +252 -0
  16. data/lib/microstation/drawing.rb +189 -0
  17. data/lib/microstation/enumerator.rb +29 -0
  18. data/lib/microstation/ext/pathname.rb +25 -0
  19. data/lib/microstation/extensions/hash.rb +27 -0
  20. data/lib/microstation/pdf_support.rb +40 -0
  21. data/lib/microstation/properties.rb +57 -0
  22. data/lib/microstation/scan/color.rb +38 -0
  23. data/lib/microstation/scan/criteria.rb +85 -0
  24. data/lib/microstation/scan/klass.rb +43 -0
  25. data/lib/microstation/scan/level.rb +38 -0
  26. data/lib/microstation/scan/line_style.rb +45 -0
  27. data/lib/microstation/scan/line_weight.rb +33 -0
  28. data/lib/microstation/scan/subtype.rb +40 -0
  29. data/lib/microstation/scan/type.rb +109 -0
  30. data/lib/microstation/scanner.rb +24 -0
  31. data/lib/microstation/tag.rb +58 -0
  32. data/lib/microstation/tag_set.rb +280 -0
  33. data/lib/microstation/template.rb +84 -0
  34. data/lib/microstation/text.rb +54 -0
  35. data/lib/microstation/text_node.rb +74 -0
  36. data/lib/microstation/ts/attribute.rb +139 -0
  37. data/lib/microstation/ts/instance.rb +112 -0
  38. data/lib/microstation/types.rb +91 -0
  39. data/lib/microstation/wrap.rb +214 -0
  40. data/plot/pdf-bw.plt +164 -0
  41. data/plot/pdf.plt +163 -0
  42. data/plot/png.plt +383 -0
  43. data/plot/tiff.plt +384 -0
  44. data/plot/wmbw.tbl +66 -0
  45. data/plot/wmcolor.tbl +62 -0
  46. data/spec/app_spec.rb +267 -0
  47. data/spec/configuration_spec.rb +122 -0
  48. data/spec/drawing_spec.rb +247 -0
  49. data/spec/drawings/new_drawing.dgn +0 -0
  50. data/spec/drawings/test.dgn +0 -0
  51. data/spec/drawings/test1.dgn +0 -0
  52. data/spec/drawings/testfile.pdf +0 -0
  53. data/spec/enumerator_spec.rb +60 -0
  54. data/spec/microstation_spec.rb +36 -0
  55. data/spec/scanner_spec.rb +155 -0
  56. data/spec/spec_app.rb +11 -0
  57. data/spec/spec_helper.rb +31 -0
  58. data/spec/tag_set_spec.rb +123 -0
  59. data/spec/text_node_spec.rb +92 -0
  60. data/spec/text_spec.rb +62 -0
  61. metadata +241 -0
@@ -0,0 +1,267 @@
1
+ require File.join(File.dirname(__FILE__) , 'spec_helper')
2
+
3
+ describe "Microstation::App" do
4
+
5
+ before(:all) do
6
+ @app = Microstation::App.new
7
+ @existing_drawing_path = drawing_path('test.dgn')
8
+ @new_drawing_path = drawing_path('my_new_drawing.dgn')
9
+ end
10
+
11
+ before(:each) do
12
+ File.delete(@new_drawing_path) if File.exist?(@new_drawing_path)
13
+ end
14
+
15
+
16
+ after(:all) do
17
+ @app.quit if @app
18
+ @app = nil
19
+ end
20
+
21
+ let(:app){@app}
22
+
23
+ describe "#initialize" do
24
+ it "with no options visible is true" do
25
+ app = Microstation::App.new
26
+ app.should be_visible
27
+ end
28
+
29
+ it "works with options" do
30
+ app = Microstation::App.new(:visible => false)
31
+ app.should_not be_visible
32
+ end
33
+
34
+ end
35
+
36
+ describe "#can_open?" do
37
+
38
+
39
+ it "can open a dwg file" do
40
+ app.can_open?('test.dwg').should be_true
41
+ end
42
+
43
+ it "can open a dgn file" do
44
+ app.can_open?('test.dgn').should be_true
45
+ end
46
+
47
+ it "can't open any other type of files" do
48
+ %w(xls doc txt png tiff odf).each do |format|
49
+ app.can_open?("test.#{format}").should be_false
50
+ end
51
+ end
52
+ end
53
+
54
+ describe "#open_drawing" do
55
+
56
+ after(:each) do
57
+ app.close_active_drawing
58
+ end
59
+
60
+
61
+ let (:valid_file){ @existing_drawing_path }
62
+ let (:invalid_file) {"bogus file"}
63
+
64
+ it "returns a drawing if drawing exists" do
65
+ drawing = app.open_drawing(valid_file)
66
+ drawing.class.should == Microstation::Drawing
67
+ app.active_design_file.should.eql? drawing.ole_obj
68
+ end
69
+
70
+ it "raises error if drawing does not exist" do
71
+ expect {
72
+ app.open_drawing(invalid_file)
73
+ }.to raise_error
74
+ end
75
+
76
+ describe "when given a block" do
77
+
78
+ it "yields the drawing to a block if a block is given" do
79
+ app.open_drawing(valid_file) do |drawing|
80
+ drawing.class.should == Microstation::Drawing
81
+ app.active_design_file.should.eql? drawing.ole_obj
82
+ end
83
+ end
84
+
85
+
86
+ it "closes drawing after block returns" do
87
+ app.active_design_file.should == nil
88
+ app.open_drawing(valid_file) do |drawing|
89
+ app.active_design_file.should.eql? drawing.ole_obj
90
+ end
91
+ app.active_design_file.should == nil
92
+ end
93
+
94
+ end
95
+
96
+ end
97
+
98
+ it "has an ole_object" do
99
+ app.ole_obj.class.should == ::WIN32OLE
100
+ end
101
+
102
+ describe "load constants" do
103
+ it "should load the constants" do
104
+ app.load_constants
105
+ Microstation::MSD::MsdElementTypeTag.should == 37
106
+ end
107
+ end
108
+
109
+ describe "create_scanner" do
110
+ it "should yield a scanner object" do
111
+ app.create_scanner do |scan|
112
+ scan.should be_instance_of Microstation::Scan::Criteria
113
+ scan.include_tags
114
+ scan.include_color(3)
115
+ end
116
+
117
+ end
118
+ end
119
+
120
+
121
+
122
+
123
+ describe "#create_ole_scanner" do
124
+ it "returns an ole scanner" do
125
+ pending
126
+ scanner = app.create_ole_scan_criteria
127
+ scanner.ole_type.to_s.should =~ /_ElementScanCriteria/
128
+ end
129
+ end
130
+
131
+ describe "#normalize_name(name)" do
132
+
133
+ it "returns the name if the name is absolute" do
134
+ app.normalize_name("c:/my_drawings/cool.dng").to_s.should == "c:/my_drawings/cool.dgn"
135
+ end
136
+
137
+ context "when given a relative path and project dir is set" do
138
+ it "returns the name joined with the project_dir" do
139
+ app.project_dir = "c:/projects/new"
140
+ app.normalize_name('cool_beans.dng').to_s.should == "c:/projects/new/cool_beans.dgn"
141
+ end
142
+
143
+ end
144
+
145
+ context "when project_dir is nil" do
146
+ it "returns name relative to the calling process" do
147
+ app.project_dir = nil
148
+ app.normalize_name('cool_beans.dng').to_s.should == (Pathname.getwd + 'cool_beans.dgn').to_s
149
+ end
150
+ end
151
+ end
152
+
153
+ it "#windows path method" do
154
+ pending
155
+ app.windows_path( drawing_path("")).should == "c:\\test"
156
+ end
157
+
158
+
159
+ it "should have a #username" do
160
+ app.username.should == ENV["USERNAME"]
161
+ end
162
+
163
+ describe "#new_drawing" do
164
+ # before(:each) do
165
+ # @new_name = "my_new_drawing.dgn"
166
+ # @new_drawing_path = drawing_path(@new_name)
167
+ # @existing_drawing_path = drawing_path('test.dgn')
168
+ # end
169
+
170
+ after(:each) do
171
+ app.close_active_drawing
172
+ # File.delete(@new_drawing_path) if File.exist?(@new_drawing_path)
173
+ end
174
+
175
+ let(:existing_drawing){ @existing_drawing_path }
176
+ let(:new_drawing) { @new_drawing_path }
177
+
178
+
179
+ it "needs a filename" do
180
+ expect{ app.new_drawing()}.to raise_error
181
+ end
182
+
183
+ it "raises an error if drawing exists" do
184
+ expect {
185
+ app.new_drawing(existing_drawing).to raise_error
186
+ }
187
+ end
188
+
189
+ it "creates a drawing if it's a new drawing_name" do
190
+ drawing = app.new_drawing(new_drawing)
191
+ drawing.should be_an_instance_of Microstation::Drawing
192
+ end
193
+
194
+ describe "when given a block" do
195
+
196
+ it "yields the drawing to a block if a block is given" do
197
+ app.new_drawing(new_drawing) do |drawing|
198
+ drawing.class.should == Microstation::Drawing
199
+ app.active_design_file.should.eql? drawing.ole_obj
200
+ end
201
+ end
202
+
203
+
204
+ it "closes drawing after block returns" do
205
+ app.active_design_file.should == nil
206
+ app.new_drawing(new_drawing) do |drawing|
207
+ app.active_design_file.should.eql? drawing.ole_obj
208
+ end
209
+ app.active_design_file.should == nil
210
+ end
211
+
212
+ end
213
+
214
+ end
215
+
216
+ describe "an app with an open drawing" do
217
+ before(:each) do
218
+ @drawing = app.new_drawing(@new_drawing_path)
219
+ end
220
+
221
+ after(:each) do
222
+ app.close_active_drawing
223
+ # File.delete(@new_drawing_path) if File.exist? (@new_drawing_path)
224
+ end
225
+
226
+ describe "#scan" do
227
+ it "defaults to all objects without a scan criteria" do
228
+ pending
229
+ expect{app.scan}.to_not raise_error
230
+ end
231
+
232
+ it "resolves the scan criteria" do
233
+ scanner = app.create_scanner do |scan|
234
+ scan.include_textual
235
+ end
236
+ scanner.should_receive("resolve")
237
+ app.scan(scanner)
238
+ end
239
+
240
+
241
+
242
+ end
243
+
244
+ # describe "#current_drawing" do
245
+ # it "returns the current drawing" do
246
+ # binding.pry
247
+ # app.current_drawing.should == @drawing
248
+ # end
249
+
250
+ # end
251
+
252
+
253
+
254
+
255
+ end
256
+
257
+ # it "forwards method missing" do
258
+
259
+ # @app.ole_obj.should_receive("Open")
260
+ # @app.Open("this is a drawing")
261
+
262
+
263
+ # end
264
+
265
+
266
+ end
267
+
@@ -0,0 +1,122 @@
1
+ require File.join(File.dirname(__FILE__) , 'spec_helper')
2
+ require 'pry'
3
+
4
+ describe Microstation::Configuration do
5
+
6
+ before(:all) do
7
+ @app = Microstation::App.new
8
+ @configuration = Microstation::Configuration.new(@app)
9
+ @defined_variable = "new_variable"
10
+ @defined_variable_value = "variable_value"
11
+ @configuration[@defined_variable] = @defined_variable_value
12
+ @undefined_variable = 'undefined'
13
+ @configuration.remove_variable('undefined')
14
+ end
15
+
16
+ after(:all) do
17
+ @configuration.remove_variable(@defined_variable)
18
+ @app.quit
19
+ end
20
+
21
+
22
+ describe "#exists" do
23
+ let(:variable){ @defined_variable}
24
+ let(:undefined){ @undefined_variable}
25
+ subject { @configuration}
26
+
27
+ it "should return true if config variable is exists" do
28
+ subject.exists?(variable).should be_true
29
+ end
30
+
31
+ it "should return false if config variable doesn't exist" do
32
+ subject.exists?(undefined).should be_false
33
+ end
34
+
35
+ end
36
+
37
+ describe "#[]" do
38
+ let(:undefined){ @undefined_variable}
39
+ let(:variable){ @defined_variable}
40
+ subject{@configuration}
41
+
42
+ it "should check if value exists" do
43
+ subject.should_receive(:exists?).with('undefined')
44
+ expect(subject[undefined]).to be_nil
45
+ end
46
+
47
+ it "should return the configuration variable if exists" do
48
+ expect(subject[variable]).to eq 'variable_value'
49
+ end
50
+
51
+ it "should return nil if not exists" do
52
+ expect(@configuration[undefined]).to equal nil
53
+ end
54
+
55
+
56
+ end
57
+
58
+ describe "#should update" do
59
+
60
+ let(:undefined){@undefined}
61
+ let(:variable){@defined_variable}
62
+
63
+ it "should return true if key doesn't exist" do
64
+ @configuration.should_update?(undefined).should be_true
65
+ end
66
+
67
+ it "should return false if key exists? and options[:force] is false or nil" do
68
+ @configuration.should_update?(variable).should be_false
69
+ end
70
+
71
+ it "should return true if key exists? and options[:force] is true" do
72
+ @configuration.should_update?(variable, {:force => true}).should be_true
73
+ end
74
+
75
+ end
76
+
77
+ describe "setting variables" do
78
+
79
+ before(:each) do
80
+ @variable = "TEST_VARIABLE"
81
+ @configuration.remove_variable(@variable)
82
+ end
83
+
84
+ context "value not existing yet" do
85
+
86
+ it "should set the variable" do
87
+ @configuration[@variable].should == nil
88
+ @configuration[@variable] = "a new variable"
89
+ @configuration[@variable].should == "a new variable"
90
+ end
91
+
92
+ end
93
+
94
+ context "value existing" do
95
+
96
+ let(:variable){@defined_variable}
97
+ subject{ @configuration}
98
+
99
+ it "should raise variable defined if force option is false" do
100
+ @configuration[variable].should == 'variable_value'
101
+ expect{ @configuration[variable]= "my new value"}.to raise_error Microstation::VariableDefined
102
+ @configuration[variable].should == "variable_value"
103
+ end
104
+
105
+ it "should change the variable if force is true" do
106
+ @configuration[variable].should == "variable_value"
107
+ @configuration.set(variable, "my new value", :force => true)
108
+ @configuration[variable].should == "my new value"
109
+ end
110
+
111
+ end
112
+
113
+ describe "#expand" do
114
+ it "should be able to expand string" do
115
+ @configuration.expand( "$(_USTN_USER)$(_USTN_USERNAME).txt").should_not be_nil
116
+
117
+ end
118
+
119
+ end
120
+
121
+ end
122
+ end
@@ -0,0 +1,247 @@
1
+ require File.join(File.dirname(__FILE__) , 'spec_helper')
2
+
3
+ module DrawingHelpers
4
+
5
+ def create_new_drawing_path(name)
6
+ path = drawing_path(name)
7
+ File.delete(path) if File.exist? path
8
+ return path
9
+ end
10
+
11
+ end
12
+
13
+ describe Microstation::Drawing do
14
+ include DrawingHelpers
15
+
16
+ context "a drawing created with app.new_drawing" do
17
+
18
+ before(:all) do
19
+ @app = Microstation::App.new
20
+ # debugger
21
+ @drawing_name = 'my_new_drawing.dgn'
22
+ @new_drawing_path = create_new_drawing_path('my_new_drawing.dgn')
23
+ @new_drawing = @app.new_drawing(@new_drawing_path)
24
+ end
25
+
26
+ after(:all) do
27
+ @app.close_active_drawing if @app
28
+ @app.quit if @app
29
+ File.delete(@new_drawing_path) if File.exist?(@new_drawing_path || "")
30
+ end
31
+
32
+ let(:new_drawing) { @new_drawing}
33
+ let(:new_drawing_path) { @new_drawing_path }
34
+ let(:new_drawing_name) {@drawing_name}
35
+
36
+ # describe "#name and path" do
37
+
38
+
39
+
40
+
41
+ # context "when given a relative name and no project_dir" do
42
+ # before(:each) do
43
+ # @app.project_dir = nil
44
+ # @drawing_name = "my drawing.dgn"
45
+ # @path = @app.normalize_name(@drawing_name)
46
+
47
+ # end
48
+
49
+ # after(:each) do
50
+ # @path.unlink
51
+ # end
52
+
53
+ # subject{@app.new_drawing(@drawing_name) }
54
+
55
+
56
+ # it "#name should be set to the name of the drawing with .dgn extension" do
57
+ # subject.name.should =~ "my drawing.dgn"
58
+ # end
59
+
60
+ # it "#path should be the working path" do
61
+ # subject.path.should == Pathname.getwd
62
+ # end
63
+
64
+ # end
65
+
66
+ # context "when given a relative name and a project_dir" do
67
+
68
+ # before(:each) do
69
+ # @app.project_dir = "c:/my_projects/"
70
+ # @new_drawing = @app.new_drawing('my drawing')
71
+ # end
72
+
73
+ # after(:each) do
74
+ # File.delete(@new_drawing.full_path)
75
+ # end
76
+
77
+
78
+ # it "name should be the name of the drawing" do
79
+ # @new_drawing.name.should == 'my drawing.dng'
80
+ # end
81
+
82
+ # it "path should == the project_dir" do
83
+ # drawing.path.should == "c:\\my_projects"
84
+ # end
85
+
86
+ # end
87
+ # end
88
+
89
+ it "should be the active drawing" do
90
+ new_drawing.should be_active
91
+ end
92
+
93
+ describe "#author" do
94
+
95
+ it "should be '' to start" do
96
+ pending
97
+ new_drawing.author.should == ""
98
+ end
99
+
100
+ it "should set author if given a new author" do
101
+ new_drawing.author = "A newer author"
102
+ new_drawing.author.should == "A newer author"
103
+ end
104
+
105
+ end
106
+
107
+ describe "#title" do
108
+ it "should be '' to start" do
109
+ new_drawing.title.should == ""
110
+ end
111
+
112
+ it "should set title if given a new title" do
113
+ new_drawing.title = "a new title"
114
+ new_drawing.title.should == "a new title"
115
+ end
116
+
117
+ end
118
+
119
+ describe "#keywords" do
120
+ it "should be empty to start" do
121
+ new_drawing.keywords.should == ""
122
+ end
123
+
124
+ it "should set keywords if given a string of words" do
125
+ new_drawing.keywords = "project, rcl, new"
126
+ new_drawing.keywords.should == "project, rcl, new"
127
+ end
128
+ end
129
+
130
+
131
+ it "should have a #comments method" do
132
+ new_drawing.comments.should == ""
133
+ new_drawing.comments = "these are the comments"
134
+ new_drawing.comments.should == "these are the comments"
135
+ end
136
+
137
+
138
+
139
+
140
+ it "should have a two_d? method" do
141
+ new_drawing.should be_two_d
142
+ end
143
+
144
+ it "should be able to save as pdf" do
145
+ new_drawing.save_as_pdf
146
+ end
147
+
148
+ describe "revision count" do
149
+ it "should have a revision_count" do
150
+ new_drawing.should respond_to "revision_count"
151
+ end
152
+
153
+ it "should forward method" do
154
+ new_drawing.ole_obj.should_receive("DesignRevisionCount").and_return(0)
155
+ new_drawing.revision_count
156
+ end
157
+ end
158
+
159
+ describe "pdf_name" do
160
+ it "should be the passed in dirname + name with pdf changed for ext" do
161
+ new_drawing.pdf_name("my_name","output").to_s.should == File.expand_path(File.join('output', "my_name.pdf"))
162
+ end
163
+
164
+ it "should == the name of the drawing file #basename with pdf ext with no args" do
165
+ new_drawing.stub(:basename).and_return "Drawing Name"
166
+ File.extname(new_drawing.pdf_name).should == '.pdf'
167
+ File.basename(new_drawing.pdf_name, '.pdf').should == "Drawing Name"
168
+ end
169
+
170
+ end
171
+
172
+
173
+ context "save_as_pdf" do
174
+ it "should use the filename if given in args" do
175
+ new_drawing.save_as_pdf("testfile")
176
+ end
177
+ end
178
+
179
+ describe "scanning" do
180
+
181
+ it "should have a #create_scanner" do
182
+ scanner = new_drawing.create_scanner
183
+ scanner.include_textual
184
+ end
185
+
186
+ it "should scan the drawing" do
187
+ scanner = new_drawing.create_scanner do |scan|
188
+ scan.include_textual
189
+ end
190
+ new_drawing.scan(scanner)
191
+ end
192
+ end
193
+
194
+
195
+ describe "#scan_text" do
196
+
197
+ it "only yields textual items" do
198
+
199
+ new_drawing.scan_text do |item|
200
+ item.class.should == (Microstation::Text || Microstation::TextNode)
201
+ end
202
+ end
203
+ end
204
+
205
+
206
+
207
+ end
208
+ end
209
+
210
+
211
+
212
+
213
+
214
+
215
+ # describe "#new_drawing" do
216
+ # before(:each) do
217
+ # ENV["USERNAME"] = "test person"
218
+ # end
219
+
220
+ # after(:each) do
221
+ # @drawing.close
222
+ # @drawing = nil
223
+ # end
224
+
225
+ # it "should set author" do
226
+ # @app.should_receive(:username).and_return("test person")
227
+ # @drawing = @app.new_drawing(new_drawing_path)
228
+ # @drawing.author.should == "test person"
229
+ # end
230
+
231
+ # end
232
+
233
+ # describe "creating a new drawing" do
234
+ # before(:each) do
235
+ # @drawing = @app.new_drawing(new_drawing_path)
236
+ # end
237
+
238
+ # after(:each) do
239
+ # @drawing.close
240
+ # @drawing = nil
241
+ # end
242
+
243
+
244
+
245
+
246
+
247
+