microstation 0.4.1 → 0.8.3

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 (102) hide show
  1. checksums.yaml +7 -0
  2. data/.autotest +23 -23
  3. data/.rspec +2 -2
  4. data/Gemfile +28 -10
  5. data/History.txt +6 -6
  6. data/LICENSE.adoc +22 -0
  7. data/Manifest.txt +81 -60
  8. data/README.adoc +131 -0
  9. data/Rakefile +71 -30
  10. data/bin/dgn2pdf +36 -37
  11. data/bin/dgn_template +107 -0
  12. data/bin/microstation +231 -0
  13. data/bin/pw_print +35 -0
  14. data/cad_files/drawing_faatitle_in_non_default_model.dgn +0 -0
  15. data/cad_files/drawing_no_block.dgn +0 -0
  16. data/cad_files/drawing_with_3_block.dgn +0 -0
  17. data/cad_files/drawing_with_block.dgn +0 -0
  18. data/cad_files/seed2d.dgn +0 -0
  19. data/cad_files/test.dgn +0 -0
  20. data/lib/microstation.rb +252 -88
  21. data/lib/microstation/app.rb +781 -286
  22. data/lib/microstation/cad_input_queue.rb +100 -25
  23. data/lib/microstation/cell.rb +191 -0
  24. data/lib/microstation/changer.rb +70 -0
  25. data/lib/microstation/configuration.rb +193 -57
  26. data/lib/microstation/criteria_creation_t.rb +23 -0
  27. data/lib/microstation/dir.rb +252 -252
  28. data/lib/microstation/directory.rb +46 -0
  29. data/lib/microstation/drawing.rb +690 -189
  30. data/lib/microstation/element.rb +311 -0
  31. data/lib/microstation/enumerator.rb +32 -29
  32. data/lib/microstation/errors.rb +17 -0
  33. data/lib/microstation/event_handler.rb +28 -0
  34. data/lib/microstation/ext/pathname.rb +23 -25
  35. data/lib/microstation/ext/win32ole.rb +7 -0
  36. data/lib/microstation/extensions/faa.rb +124 -0
  37. data/lib/microstation/file_tests.rb +68 -0
  38. data/lib/microstation/functions.rb +60 -0
  39. data/lib/microstation/graphics.rb +35 -0
  40. data/lib/microstation/line.rb +19 -0
  41. data/lib/microstation/model.rb +45 -0
  42. data/lib/microstation/model_trait.rb +189 -0
  43. data/lib/microstation/ole_cad_input_message.rb +101 -0
  44. data/lib/microstation/ole_helper.rb +152 -0
  45. data/lib/microstation/pdf_support.rb +40 -40
  46. data/lib/microstation/point3d.rb +71 -0
  47. data/lib/microstation/primitive_command_interface.rb +66 -0
  48. data/lib/microstation/properties.rb +61 -57
  49. data/lib/microstation/property_handler.rb +48 -0
  50. data/lib/microstation/scan/color.rb +38 -38
  51. data/lib/microstation/scan/criteria.rb +89 -85
  52. data/lib/microstation/scan/klass.rb +43 -43
  53. data/lib/microstation/scan/level.rb +38 -38
  54. data/lib/microstation/scan/line_style.rb +45 -45
  55. data/lib/microstation/scan/line_weight.rb +33 -33
  56. data/lib/microstation/scan/range.rb +19 -0
  57. data/lib/microstation/scan/scan_trait.rb +51 -0
  58. data/lib/microstation/scan/subtype.rb +40 -40
  59. data/lib/microstation/scan/type.rb +134 -109
  60. data/lib/microstation/scan_trait.rb +62 -0
  61. data/lib/microstation/scanner.rb +24 -24
  62. data/lib/microstation/tag.rb +87 -58
  63. data/lib/microstation/tag_set.rb +385 -280
  64. data/lib/microstation/tag_set_trait.rb +51 -0
  65. data/lib/microstation/tagged_element.rb +105 -0
  66. data/lib/microstation/template.rb +90 -84
  67. data/lib/microstation/template_info.rb +172 -0
  68. data/lib/microstation/template_runner.rb +65 -0
  69. data/lib/microstation/text.rb +79 -54
  70. data/lib/microstation/text_node.rb +124 -74
  71. data/lib/microstation/ts/attribute.rb +140 -139
  72. data/lib/microstation/ts/instance.rb +146 -112
  73. data/lib/microstation/ts/tagset_trait.rb +49 -0
  74. data/lib/microstation/types.rb +91 -91
  75. data/lib/microstation/version.rb +5 -0
  76. data/lib/microstation/wrap.rb +28 -214
  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. metadata +301 -86
  84. data/.gemtest +0 -0
  85. data/README.txt +0 -75
  86. data/lib/microstation/attributes.rb +0 -35
  87. data/lib/microstation/extensions/hash.rb +0 -27
  88. data/spec/app_spec.rb +0 -267
  89. data/spec/configuration_spec.rb +0 -122
  90. data/spec/drawing_spec.rb +0 -247
  91. data/spec/drawings/new_drawing.dgn +0 -0
  92. data/spec/drawings/test.dgn +0 -0
  93. data/spec/drawings/test1.dgn +0 -0
  94. data/spec/drawings/testfile.pdf +0 -0
  95. data/spec/enumerator_spec.rb +0 -60
  96. data/spec/microstation_spec.rb +0 -36
  97. data/spec/scanner_spec.rb +0 -155
  98. data/spec/spec_app.rb +0 -11
  99. data/spec/spec_helper.rb +0 -31
  100. data/spec/tag_set_spec.rb +0 -123
  101. data/spec/text_node_spec.rb +0 -92
  102. data/spec/text_spec.rb +0 -62
@@ -0,0 +1,311 @@
1
+ require 'microstation/property_handler'
2
+
3
+ class WIN32OLE
4
+
5
+ def to_ole
6
+ self
7
+ end
8
+
9
+ end
10
+ module Microstation
11
+ end
12
+
13
+ module Microstation
14
+
15
+ module ElementTrait
16
+
17
+ #
18
+ #
19
+ #
20
+ # @return [Boolean] true if ole type is Text
21
+ #
22
+ def text?
23
+ ole_obj.Type == ::Microstation::MSD::MsdElementTypeText
24
+ end
25
+
26
+ # @return [Boolean] true if ole type is TextNode
27
+ def text_node?
28
+ ole_obj.Type == ::Microstation::MSD::MsdElementTypeTextNode
29
+ end
30
+
31
+ def has_tags?
32
+ ole_obj.HasAnyTags
33
+ end
34
+
35
+ def to_ole
36
+ ole_obj
37
+ end
38
+
39
+ def cell?
40
+ ole_obj.Type == ::Microstation::MSD::MsdElementTypeCellHeader
41
+ end
42
+
43
+ def complex?
44
+ ole_obj.IsComplexElement
45
+ end
46
+
47
+ # @return [Boolean] true if Text or TextNode
48
+ def textual?
49
+ text? || text_node?
50
+ end
51
+
52
+ def microstation_id()
53
+ id = ole_obj.Id || ole_obj.ID64
54
+ return nil unless id
55
+ id_from_record(id)
56
+ end
57
+
58
+ # @return [Boolean] true if ole type is TypeLine
59
+ def line?
60
+ ole_obj.Type == ::Microstation::MSD::MsdElementTypeLine
61
+ end
62
+
63
+ def graphical?
64
+ ole_obj.IsGraphical
65
+ end
66
+
67
+ def parent
68
+ parent_id = ole_obj.ParentID
69
+ return nil unless parent_id
70
+ id = id_from_record(parent_id)
71
+ app.active_design_file.find_by_id(id)
72
+ end
73
+
74
+ def id_from_record(id)
75
+ if id.class == WIN32OLE_RECORD
76
+ if id.Low > id.High
77
+ return id.Low
78
+ else
79
+ return id.High
80
+ end
81
+ end
82
+ end
83
+
84
+ def select
85
+ app.active_model_reference.select_element(self)
86
+ end
87
+
88
+ # def Type
89
+ # ole_obj.Type
90
+ # end
91
+
92
+ def microstation_type
93
+ ole_obj.Type
94
+ end
95
+
96
+
97
+ def model
98
+ Model.new(app, app.current_drawing, ole_obj.ModelReference)
99
+ end
100
+
101
+ end
102
+
103
+ class Element
104
+
105
+ include ElementTrait
106
+
107
+ def self.convert_item(ole,app, cell=nil)
108
+ return Point3d.from_ole(ole) if ole.class == WIN32OLE_RECORD && ole.typename == 'Point3d'
109
+ return ole unless ole.class == WIN32OLE
110
+ case ole.Type
111
+ when ::Microstation::MSD::MsdElementTypeText
112
+ ::Microstation::Text.new(ole,app,cell)
113
+ when ::Microstation::MSD::MsdElementTypeLine
114
+ ::Microstation::Line.new(ole,app,cell)
115
+ when ::Microstation::MSD::MsdElementTypeTextNode
116
+ ::Microstation::TextNode.new(ole,app,cell)
117
+ when ::Microstation::MSD::MsdElementTypeTag
118
+ ::Microstation::Tag.new(ole,app,cell)
119
+ when ::Microstation::MSD::MsdElementTypeCellHeader
120
+ ::Microstation::Cell.new(ole,app,cell)
121
+ when ::Microstation::MSD::MsdElementTypeSharedCell
122
+ ::Microstation::Cell.new(ole,app,cell)
123
+ when ::Microstation::MSD::MsdElementTypeArc
124
+ ::Microstation::Arc.new(ole,app,cell)
125
+ when ::Microstation::MSD::MsdElementTypeEllipse
126
+ ::Microstation::Ellipse.new(ole,app,cell)
127
+ when ::Microstation::MSD::MsdElementTypeBsplineSurface
128
+ ::Microstation::BSplineSurface.new(ole,app,cell)
129
+ when ::Microstation::MSD::MsdElementTypeBsplineCurve
130
+ ::Microstation::BSplineCurve.new(ole,app,cell)
131
+
132
+ else
133
+ new(ole,app,cell)
134
+ end
135
+ end
136
+
137
+ def self.ole_object?
138
+ ole.class == WIN32OLE
139
+ end
140
+
141
+
142
+ attr_reader :ole_obj, :app, :original
143
+
144
+ def initialize(ole,app, cell = nil)
145
+ @ole_obj = ole
146
+ @original = read_ole(ole)
147
+ @app = app
148
+ @cell = cell
149
+ end
150
+
151
+ def in_cell?
152
+ !!@cell
153
+ end
154
+
155
+ def read_ole(ole)
156
+
157
+ end
158
+
159
+ def write_ole(value)
160
+
161
+ end
162
+
163
+ def method_missing(meth,*args,&block)
164
+ if meth.to_s =~ /^[A-Z]/
165
+ result = ole_obj.send(meth,*args,&block)
166
+ Element.convert_item(result,app)
167
+ else
168
+ super(meth,*args,&block)
169
+ end
170
+ end
171
+
172
+
173
+ def get_property_handler
174
+ ph_ole = app_ole_obj.CreatePropertyHandler(ole_obj)
175
+ PropertyHandler.new(ph_ole)
176
+ end
177
+
178
+ def property_handler
179
+ @property_handler ||= get_property_handler
180
+ end
181
+
182
+ def [](name)
183
+ property_handler[name]
184
+ end
185
+
186
+
187
+ def do_update(value)
188
+ return false if value == original
189
+ saved_original = original
190
+ begin
191
+ write_ole(value)
192
+ @original = read_ole(ole_obj)
193
+ return true
194
+
195
+ rescue => e
196
+ @original = saved_original
197
+ false
198
+ end
199
+ end
200
+
201
+ def update(value)
202
+ redraw_el = ole_obj
203
+ if do_update(value)
204
+ if in_cell?
205
+ @cell.ReplaceCurrentElement @ole_obj
206
+ redraw_el = @cell
207
+ end
208
+ redraw(redraw_el)
209
+ @updated = true
210
+ true
211
+ else
212
+ @updated = false
213
+ false
214
+ end
215
+ end
216
+
217
+ def updated?
218
+ @updated
219
+ end
220
+
221
+ def redraw(el = ole_obj)
222
+ el.Redraw ::Microstation::MSD::MsdDrawingModeNormal
223
+ el.Rewrite
224
+ end
225
+
226
+ def app_ole_obj
227
+ app.ole_obj
228
+ end
229
+
230
+ def ole_cell(ole)
231
+ ole.IsCellElement || ole.IsSharedCellElement
232
+ end
233
+
234
+ def each_cell(ole,&block)
235
+ cell = ole if ole_cell(ole)
236
+ ole.ResetElementEnumeration rescue binding.pry
237
+ while ole.MoveToNextElement
238
+ component = ole.CopyCurrentElement
239
+ if component.IsTextNodeElement
240
+ yield Microstation::Wrap.wrap(component.AsTextNodeElement,app,cell)
241
+ elsif component.IsTextElement
242
+ yield Microstation::Wrap.wrap(component.AsTextElement,app,cell)
243
+ elsif component.IsComplexElement
244
+ each(component)
245
+ else
246
+ yield Microstation::Wrap.wrap(component,app,cell)
247
+ end
248
+ end
249
+ end
250
+
251
+ def each(ole = ole_obj,&block)
252
+ return unless ole.IsComplexElement
253
+ return to_enum(:each) unless block_given?
254
+ if ole.IsCellElement
255
+ each_cell(ole,&block)
256
+ else
257
+ each_complex(ole,&block)
258
+ end
259
+ end
260
+
261
+ def each_complex(ole,&block)
262
+ cell = nil
263
+ components = ole.GetSubElements
264
+ while components.MoveNext
265
+ component = components.Current
266
+ if component.IsTextNodeElement
267
+ yield Microstation::Wrap.wrap(component.AsTextNodeElement,app,cell)
268
+ elsif component.IsTextElement
269
+ yield Microstation::Wrap.wrap(component.AsTextElement,app,cell)
270
+ elsif component.IsComplexElement
271
+ each(component,&block)
272
+ else
273
+ yield Microstation::Wrap.wrap(component,app,cell)
274
+ end
275
+ end
276
+ end
277
+
278
+ end
279
+
280
+
281
+ class App
282
+
283
+ def ole_to_ruby(ole)
284
+ Element.convert_item(ole,self)
285
+ end
286
+
287
+ end
288
+
289
+ end
290
+
291
+
292
+
293
+ module Microstation
294
+ class Arc < Element
295
+ end
296
+ end
297
+
298
+ module Microstation
299
+ class Ellipse < Element
300
+ end
301
+ end
302
+
303
+ module Microstation
304
+ class BSplineSurface < Element
305
+ end
306
+ end
307
+
308
+ module Microstation
309
+ class BSplineCurve < Element
310
+ end
311
+ end
@@ -1,29 +1,32 @@
1
- require_relative 'wrap'
2
-
3
- module Microstation
4
-
5
- class Enumerator
6
-
7
- include Enumerable
8
- include Wrap
9
-
10
- def initialize(ole)
11
- @ole_obj = ole
12
- end
13
-
14
- def each
15
- while @ole_obj.MoveNext
16
- item = @ole_obj.Current
17
- yield wrap(item)
18
- end
19
- end
20
-
21
- def reset
22
- @ole_obj.reset
23
- end
24
-
25
-
26
-
27
- end
28
-
29
- end
1
+ require_relative 'wrap'
2
+
3
+ module Microstation
4
+
5
+ class Enumerator
6
+
7
+ include Enumerable
8
+
9
+ attr_reader :app
10
+
11
+ def initialize(ole,app)
12
+ @ole_obj = ole
13
+ @app = app
14
+ end
15
+
16
+ def each
17
+ return enum_for(:each) unless block_given?
18
+ while @ole_obj.MoveNext
19
+ item = @ole_obj.Current
20
+ yield Microstation::Wrap.wrap(item,app)
21
+ end
22
+ end
23
+
24
+ def reset
25
+ @ole_obj.reset
26
+ end
27
+
28
+
29
+
30
+ end
31
+
32
+ end
@@ -0,0 +1,17 @@
1
+ module Microstation
2
+
3
+ Error = Class.new(::RuntimeError)
4
+ NonDGNFile = Class.new(Error)
5
+ FileNotFound = Class.new(Error)
6
+ MultipleUpdateError = Class.new(Error)
7
+ class ExistingFile < Error
8
+
9
+ def initialize(path)
10
+ msg = "File at path #{path} already exists"
11
+ super(msg)
12
+ end
13
+ end
14
+
15
+
16
+
17
+ end
@@ -0,0 +1,28 @@
1
+ module Microstation
2
+
3
+ class EventHandler
4
+ def initialize
5
+ @handlers = {}
6
+ end
7
+
8
+ def add_handler(event, &block)
9
+ if block_given?
10
+ @handlers[event] = block
11
+ end
12
+ end
13
+
14
+ def get_handler(event)
15
+ @handlers[event]
16
+ end
17
+
18
+ def method_missing(event, *args)
19
+ if @handlers[event.to_s]
20
+ @handlers[event.to_s].call(*args)
21
+ else
22
+ puts "Unhandled event: #{event} args: #{args}"
23
+ super
24
+ end
25
+ end
26
+ end
27
+
28
+ end
@@ -1,25 +1,23 @@
1
- require 'pathname'
2
-
3
-
4
- class Pathname
5
-
6
- def ext(newext = '')
7
- str = self.to_s
8
- return self.dup if ['.', '..'].include? str
9
- if newext != ''
10
- newext = (newext =~ /^\./) ? newext : ("." + newext)
11
- end
12
- Pathname.new(str.dup.sub!(%r(([^/\\])\.[^./\\]*$)) { $1 + newext } || str + newext)
13
- end
14
-
15
- def extstr(newext='')
16
- Pathname.new( self.to_s.ext(newext))
17
- end
18
-
19
-
20
- def glob(pattern)
21
- self.class.glob("#{self.to_s}/#{pattern}")
22
- end
23
-
24
-
25
- end
1
+ require 'pathname'
2
+
3
+
4
+ class Pathname
5
+
6
+ def ext(newext = '')
7
+ str = self.to_s
8
+ return self.dup if ['.', '..'].include? str
9
+ if newext != ''
10
+ newext = (newext =~ /^\./) ? newext : ("." + newext)
11
+ end
12
+ Pathname.new(str.dup.sub!(%r(([^/\\])\.[^./\\]*$)) { $1 + newext } || str + newext)
13
+ end
14
+
15
+ def extstr(newext='')
16
+ Pathname.new( self.to_s.ext(newext))
17
+ end
18
+
19
+ def glob(pattern)
20
+ self.class.glob("#{self.to_s}/#{pattern}")
21
+ end
22
+
23
+ end