microstation 0.8.5 → 0.8.7
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.
- checksums.yaml +4 -4
- data/Gemfile +26 -29
- data/Rakefile +45 -44
- data/bin/dgn2pdf +5 -6
- data/bin/dgn_template +23 -25
- data/bin/pw_print +11 -13
- 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/lib/microstation/app.rb +91 -87
- data/lib/microstation/cad_input_queue.rb +10 -20
- data/lib/microstation/cell.rb +6 -18
- data/lib/microstation/changer.rb +3 -3
- data/lib/microstation/configuration.rb +33 -50
- data/lib/microstation/criteria_creation_t.rb +4 -8
- data/lib/microstation/dir.rb +27 -59
- data/lib/microstation/directory.rb +2 -7
- data/lib/microstation/drawing.rb +103 -102
- data/lib/microstation/element.rb +55 -68
- data/lib/microstation/enumerator.rb +4 -9
- data/lib/microstation/errors.rb +0 -5
- data/lib/microstation/event_handler.rb +1 -5
- data/lib/microstation/ext/pathname.rb +12 -14
- data/lib/microstation/ext/win32ole.rb +0 -2
- data/lib/microstation/extensions/faa.rb +12 -34
- data/lib/microstation/file_tests.rb +15 -50
- data/lib/microstation/functions.rb +10 -20
- data/lib/microstation/graphics.rb +6 -13
- data/lib/microstation/line.rb +2 -6
- data/lib/microstation/model.rb +11 -20
- data/lib/microstation/model_trait.rb +40 -40
- data/lib/microstation/ole_cad_input_message.rb +25 -34
- data/lib/microstation/ole_helper.rb +58 -66
- data/lib/microstation/pdf_support.rb +7 -16
- data/lib/microstation/point3d.rb +17 -30
- data/lib/microstation/primitive_command_interface.rb +8 -14
- data/lib/microstation/properties.rb +29 -17
- data/lib/microstation/property_handler.rb +6 -8
- data/lib/microstation/scan/color.rb +1 -8
- data/lib/microstation/scan/criteria.rb +17 -33
- data/lib/microstation/scan/klass.rb +8 -12
- data/lib/microstation/scan/level.rb +2 -9
- data/lib/microstation/scan/line_style.rb +4 -12
- data/lib/microstation/scan/line_weight.rb +1 -3
- data/lib/microstation/scan/range.rb +2 -8
- data/lib/microstation/scan/scan_trait.rb +48 -51
- data/lib/microstation/scan/subtype.rb +0 -10
- data/lib/microstation/scan/type.rb +9 -15
- data/lib/microstation/scan_trait.rb +13 -20
- data/lib/microstation/scanner.rb +1 -11
- data/lib/microstation/tag.rb +12 -21
- data/lib/microstation/tag_set.rb +52 -71
- data/lib/microstation/tag_set_trait.rb +6 -10
- data/lib/microstation/tagged_element.rb +16 -28
- data/lib/microstation/template.rb +15 -14
- data/lib/microstation/template_info.rb +35 -49
- data/lib/microstation/template_runner.rb +14 -22
- data/lib/microstation/text.rb +15 -19
- data/lib/microstation/text_node.rb +17 -26
- data/lib/microstation/ts/attribute.rb +16 -20
- data/lib/microstation/ts/instance.rb +28 -38
- data/lib/microstation/ts/tagset_trait.rb +5 -12
- data/lib/microstation/types.rb +0 -3
- data/lib/microstation/version.rb +1 -3
- data/lib/microstation/wrap.rb +3 -10
- data/lib/microstation.rb +57 -72
- data/spec/microstation/app_spec.rb +49 -46
- data/spec/microstation/configuration_spec.rb +45 -43
- data/spec/microstation/drawing_spec.rb +103 -101
- data/spec/microstation/functions_spec.rb +18 -12
- data/spec/microstation/tag_set_spec.rb +57 -55
- data/spec/microstation/template_spec.rb +41 -42
- data/spec/microstation/text_node_spec.rb +16 -14
- data/spec/microstation/text_spec.rb +10 -8
- data/spec/microstation_spec.rb +18 -17
- data/spec/spec_helper.rb +18 -18
- metadata +36 -22
@@ -1,25 +1,20 @@
|
|
1
1
|
class Hash
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
new_k,new_v = yield k,v
|
2
|
+
def transform
|
3
|
+
each_with_object({}) do |(k, v), result|
|
4
|
+
new_k, new_v = yield k, v
|
6
5
|
result[new_k] = new_v
|
7
|
-
result
|
8
6
|
end
|
9
7
|
end
|
10
8
|
end
|
11
9
|
|
12
10
|
module Microstation
|
13
|
-
|
14
11
|
module TS
|
15
|
-
|
16
12
|
class Instance
|
17
|
-
|
18
13
|
include Enumerable
|
19
14
|
|
20
|
-
attr_reader :elements
|
15
|
+
attr_reader :elements, :tagset, :microstation_id, :microstation_model
|
21
16
|
|
22
|
-
def initialize(ts,id, elements, model)
|
17
|
+
def initialize(ts, id, elements, model)
|
23
18
|
@tagset = ts
|
24
19
|
@microstation_id = id
|
25
20
|
@elements = elements
|
@@ -35,7 +30,7 @@ module Microstation
|
|
35
30
|
end
|
36
31
|
|
37
32
|
def find_attribute(name)
|
38
|
-
@elements.find{|a| a.name == name.to_s}
|
33
|
+
@elements.find { |a| a.name == name.to_s }
|
39
34
|
end
|
40
35
|
|
41
36
|
def [](name)
|
@@ -43,15 +38,15 @@ module Microstation
|
|
43
38
|
end
|
44
39
|
|
45
40
|
def attributes
|
46
|
-
@elements.map{|e| e.name}
|
41
|
+
@elements.map { |e| e.name }
|
47
42
|
end
|
48
43
|
|
49
|
-
def update_element(name,value)
|
44
|
+
def update_element(name, value)
|
50
45
|
find_attribute(name).update(value)
|
51
46
|
end
|
52
47
|
|
53
|
-
def []=(name,value)
|
54
|
-
update_element(name,value)
|
48
|
+
def []=(name, value)
|
49
|
+
update_element(name, value)
|
55
50
|
end
|
56
51
|
|
57
52
|
def element_value(name)
|
@@ -61,7 +56,7 @@ module Microstation
|
|
61
56
|
def to_hash
|
62
57
|
result = {}
|
63
58
|
@elements.each do |ele|
|
64
|
-
result[ele.name] = ele.value unless
|
59
|
+
result[ele.name] = ele.value unless ele.value == "" || ele.value.nil?
|
65
60
|
end
|
66
61
|
result
|
67
62
|
end
|
@@ -75,13 +70,12 @@ module Microstation
|
|
75
70
|
end
|
76
71
|
|
77
72
|
def to_h
|
78
|
-
result = {
|
79
|
-
|
80
|
-
result[
|
73
|
+
result = {"tagset_name" => tagset.name, "microstation_id" => microstation_id,
|
74
|
+
"microstation_model" => microstation_model}
|
75
|
+
result["attributes"] = attribute_hash
|
81
76
|
result
|
82
77
|
end
|
83
78
|
|
84
|
-
|
85
79
|
def pair(el)
|
86
80
|
[el.name, el.value]
|
87
81
|
end
|
@@ -89,21 +83,19 @@ module Microstation
|
|
89
83
|
def select
|
90
84
|
result = []
|
91
85
|
each do |el|
|
92
|
-
k,v = pair(el)
|
93
|
-
save = yield k,v
|
86
|
+
k, v = pair(el)
|
87
|
+
save = yield k, v
|
94
88
|
result << find_attribute(k) if save
|
95
89
|
end
|
96
|
-
self.class.new(tagset,result)
|
90
|
+
self.class.new(tagset, result)
|
97
91
|
end
|
98
92
|
|
99
93
|
def find(&block)
|
100
|
-
|
94
|
+
find(&block)
|
101
95
|
end
|
102
96
|
|
103
|
-
def each
|
104
|
-
@elements.each
|
105
|
-
yield el
|
106
|
-
end
|
97
|
+
def each(&block)
|
98
|
+
@elements.each(&block)
|
107
99
|
end
|
108
100
|
|
109
101
|
def each_pair
|
@@ -113,34 +105,32 @@ module Microstation
|
|
113
105
|
end
|
114
106
|
|
115
107
|
def map_v
|
116
|
-
each_pair do |k,v|
|
108
|
+
each_pair do |k, v|
|
117
109
|
new_v = yield v
|
118
|
-
update_element(k,new_v)
|
110
|
+
update_element(k, new_v)
|
119
111
|
end
|
120
112
|
end
|
121
113
|
|
122
114
|
def update(value_hash)
|
123
|
-
value_hash = value_hash.transform{|k,v| [k.to_s,v.to_s] }
|
115
|
+
value_hash = value_hash.transform { |k, v| [k.to_s, v.to_s] }
|
124
116
|
valid_atts = attributes & value_hash.keys
|
125
117
|
valid_atts.each do |att|
|
126
|
-
update_element(att,value_hash[att])
|
118
|
+
update_element(att, value_hash[att])
|
127
119
|
end
|
128
120
|
end
|
129
121
|
|
130
|
-
def method_missing(meth
|
122
|
+
def method_missing(meth, *args, &block)
|
131
123
|
base = meth.to_s.sub("=", "")
|
132
124
|
if attributes.include?(base)
|
133
|
-
if
|
134
|
-
update_element(base
|
125
|
+
if /(=)/.match?(meth)
|
126
|
+
update_element(base, *args)
|
135
127
|
else
|
136
128
|
element_value(base.to_s)
|
137
129
|
end
|
138
130
|
else
|
139
|
-
super(meth
|
131
|
+
super(meth, *args, &block)
|
140
132
|
end
|
141
133
|
end
|
142
|
-
|
143
134
|
end
|
144
|
-
|
145
135
|
end
|
146
136
|
end
|
@@ -1,27 +1,23 @@
|
|
1
1
|
module Microstation
|
2
|
-
|
3
2
|
module TS
|
4
|
-
|
5
|
-
|
6
3
|
module TagSetTrait
|
7
|
-
|
8
4
|
def tagsets
|
9
5
|
@tagsets = TagSets.new(ole_obj_tagsets)
|
10
6
|
end
|
11
7
|
|
12
8
|
def tagset_names
|
13
|
-
tagsets.map{|ts| ts.name}
|
9
|
+
tagsets.map { |ts| ts.name }
|
14
10
|
end
|
15
11
|
|
16
|
-
def create_tagset(name
|
12
|
+
def create_tagset(name, &block)
|
17
13
|
ts = tagsets.create(name)
|
18
14
|
block.call ts if block
|
19
15
|
ts
|
20
16
|
end
|
21
17
|
|
22
|
-
def create_tagset!(name
|
18
|
+
def create_tagset!(name, &block)
|
23
19
|
remove_tagset(name)
|
24
|
-
create_tagset(name
|
20
|
+
create_tagset(name, &block)
|
25
21
|
end
|
26
22
|
|
27
23
|
def remove_tagset(name)
|
@@ -39,11 +35,8 @@ module Microstation
|
|
39
35
|
end
|
40
36
|
|
41
37
|
def ensure_tags(tags)
|
42
|
-
tags.map{|t| t.
|
38
|
+
tags.map { |t| t.instance_of?(WIN32OLE) ? app.wrap(t) : t }
|
43
39
|
end
|
44
|
-
|
45
40
|
end
|
46
|
-
|
47
41
|
end
|
48
|
-
|
49
42
|
end
|
data/lib/microstation/types.rb
CHANGED
data/lib/microstation/version.rb
CHANGED
data/lib/microstation/wrap.rb
CHANGED
@@ -1,17 +1,12 @@
|
|
1
1
|
module Microstation
|
2
|
-
|
3
2
|
def self.needs_extending?(ole)
|
4
|
-
ole.
|
3
|
+
ole.instance_of?(WIN32OLE) && (!ole.respond_to? :text?)
|
5
4
|
end
|
6
5
|
|
7
|
-
|
8
6
|
module Microstation
|
9
|
-
|
10
7
|
module Wrap
|
11
|
-
|
12
|
-
|
13
|
-
def self.wrap(item,app,cell=nil)
|
14
|
-
Element.convert_item(item,app, cell)
|
8
|
+
def self.wrap(item, app, cell = nil)
|
9
|
+
Element.convert_item(item, app, cell)
|
15
10
|
end
|
16
11
|
|
17
12
|
# def text?(item)
|
@@ -21,8 +16,6 @@ module Microstation
|
|
21
16
|
# def text_node?(item)
|
22
17
|
# item.Type == Microstation::MSD::MsdElementTypeTextNode
|
23
18
|
# end
|
24
|
-
|
25
19
|
end
|
26
20
|
end
|
27
|
-
|
28
21
|
end
|
data/lib/microstation.rb
CHANGED
@@ -1,34 +1,32 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
16
|
-
require
|
17
|
-
require
|
18
|
-
require
|
19
|
-
require
|
20
|
-
require
|
21
|
-
require
|
22
|
-
require
|
1
|
+
require "microstation/version"
|
2
|
+
require "win32ole"
|
3
|
+
require "microstation/file_tests"
|
4
|
+
require "microstation/app"
|
5
|
+
require "microstation/drawing"
|
6
|
+
require "microstation/configuration"
|
7
|
+
require "microstation/ext/pathname"
|
8
|
+
require "microstation/cad_input_queue"
|
9
|
+
require "microstation/scan/criteria"
|
10
|
+
require "microstation/enumerator"
|
11
|
+
require "microstation/line"
|
12
|
+
require "microstation/text"
|
13
|
+
require "microstation/text_node"
|
14
|
+
require "microstation/template"
|
15
|
+
require "microstation/tag_set"
|
16
|
+
require "microstation/cell"
|
17
|
+
require "microstation/tag"
|
18
|
+
require "microstation/dir"
|
19
|
+
require "microstation/ext/win32ole"
|
20
|
+
require "microstation/template_info"
|
21
|
+
require "microstation/template_runner"
|
22
|
+
require "erb"
|
23
23
|
|
24
24
|
module Microstation
|
25
|
-
|
26
25
|
ROOT = Pathname(__dir__).parent
|
27
26
|
|
28
|
-
TEMPLATES_PATH = ROOT +
|
29
|
-
|
30
|
-
class << self
|
27
|
+
TEMPLATES_PATH = ROOT + "templates"
|
31
28
|
|
29
|
+
class << self
|
32
30
|
def save_as_pdf(d)
|
33
31
|
run do |app|
|
34
32
|
drawing = app.current_drawing
|
@@ -38,43 +36,37 @@ module Microstation
|
|
38
36
|
end
|
39
37
|
|
40
38
|
def default_error_proc
|
41
|
-
@default_error_proc ||= ->(e,f){ puts "Couldn't open drawing #{f}" }
|
39
|
+
@default_error_proc ||= ->(e, f) { puts "Couldn't open drawing #{f}" }
|
42
40
|
end
|
43
41
|
|
44
42
|
def default_drawing_options
|
45
43
|
{read_only: true, error_proc: default_error_proc}
|
46
44
|
end
|
47
45
|
|
48
|
-
|
49
|
-
@default_error_proc = p
|
50
|
-
end
|
46
|
+
attr_writer :default_error_proc
|
51
47
|
|
52
|
-
|
53
|
-
@default_app_options
|
54
|
-
end
|
48
|
+
attr_reader :default_app_options
|
55
49
|
|
56
|
-
|
57
|
-
@default_app_options = opts
|
58
|
-
end
|
50
|
+
attr_writer :default_app_options
|
59
51
|
|
60
52
|
default_app_options = {visible: false}
|
61
53
|
|
62
54
|
def root
|
63
|
-
ROOT
|
55
|
+
ROOT
|
64
56
|
end
|
65
57
|
|
66
58
|
def plot_driver_directory
|
67
59
|
root + "plot"
|
68
60
|
end
|
69
61
|
|
70
|
-
def use_template(template,context, options ={}
|
62
|
+
def use_template(template, context, options = {})
|
71
63
|
def context.binding
|
72
64
|
binding
|
73
65
|
end
|
74
66
|
options = {readonly: true}
|
75
67
|
App.run do |app|
|
76
|
-
tmpfile = Tempfile.new(
|
77
|
-
app.new_drawing(tmpfile,template) do |drawing|
|
68
|
+
tmpfile = Tempfile.new("drawing")
|
69
|
+
app.new_drawing(tmpfile, template) do |drawing|
|
78
70
|
drawing.scan_text do |text|
|
79
71
|
compiled_template = ERB.new(text)
|
80
72
|
new_text = compiled_template.result(context.binding)
|
@@ -97,34 +89,34 @@ module Microstation
|
|
97
89
|
end
|
98
90
|
|
99
91
|
# gets all dwg and dgn dfiles in a directory
|
100
|
-
# @param dir
|
92
|
+
# @param dir
|
101
93
|
def drawings_in_dir(dir)
|
102
94
|
dirpath = Pathname.new(dir).expand_path
|
103
|
-
drawings = dirpath.glob("*.d{gn,wg,xf}").sort_by{ _1.basename(
|
95
|
+
drawings = dirpath.glob("*.d{gn,wg,xf}").sort_by { _1.basename(".*").to_s.downcase }
|
104
96
|
end
|
105
97
|
|
106
|
-
def dump_template_info_for_dir(dir, options
|
98
|
+
def dump_template_info_for_dir(dir, **options)
|
107
99
|
drawings = drawings_in_dir(dir)
|
108
100
|
raise "no drawings in dir #{dir}" if drawings.empty?
|
109
101
|
with_drawings(drawings) do |drawing|
|
110
|
-
template = TemplateInfo.new(drawing,options)
|
102
|
+
template = TemplateInfo.new(drawing, **options)
|
111
103
|
template.dump(dir)
|
112
104
|
end
|
113
105
|
end
|
114
106
|
|
115
|
-
def dump_template_info(dgn, dir: nil,
|
107
|
+
def dump_template_info(dgn, dir: nil, tagset_filter: nil, visible: false)
|
116
108
|
drawing = Pathname(dgn).expand_path
|
117
109
|
output_dir = dir || drawing.parent
|
118
|
-
template = TemplateInfo.new(drawing,tagset_filter: tagset_filter, visible: visible)
|
110
|
+
template = TemplateInfo.new(drawing, tagset_filter: tagset_filter, visible: visible)
|
119
111
|
template.dump(output_dir)
|
120
112
|
end
|
121
113
|
|
122
114
|
# @param dir [String] the directory of drawing [dgn,dwg] to convert
|
123
115
|
# @param outdir [String] the output dir for converted pdf files
|
124
|
-
def dgn2pdf(dir,outdir = dir)
|
116
|
+
def dgn2pdf(dir, outdir = dir)
|
125
117
|
drawings = drawings_in_dir(dir)
|
126
118
|
with_drawings(drawings) do |drawing|
|
127
|
-
drawing.save_as_pdf(name: drawing.name,dir: outdir)
|
119
|
+
drawing.save_as_pdf(name: drawing.name, dir: outdir)
|
128
120
|
end
|
129
121
|
end
|
130
122
|
|
@@ -141,30 +133,29 @@ module Microstation
|
|
141
133
|
|
142
134
|
# opens all the drawings in a drawing
|
143
135
|
# by calling open drawing
|
144
|
-
def with_drawings_in_dir(dir
|
136
|
+
def with_drawings_in_dir(dir, ...)
|
145
137
|
drawings = drawings_in_dir(dir)
|
146
|
-
with_drawings(drawings
|
138
|
+
with_drawings(drawings, ...)
|
147
139
|
end
|
148
140
|
|
149
|
-
|
150
141
|
def with_drawings(...)
|
151
|
-
App.with_drawings(...)
|
142
|
+
App.with_drawings(...)
|
152
143
|
end
|
153
144
|
|
154
|
-
def scan_text(file
|
155
|
-
|
145
|
+
def scan_text(file, &block)
|
146
|
+
App.open_drawing(file) do |d|
|
156
147
|
d.scan_text(&block)
|
157
148
|
end
|
158
149
|
end
|
159
150
|
|
160
151
|
def get_text(file, &block)
|
161
|
-
|
162
|
-
|
152
|
+
App.open_drawing(file) do |d|
|
153
|
+
d.get_text(&block)
|
163
154
|
end
|
164
155
|
end
|
165
156
|
|
166
157
|
def get_all_text(file)
|
167
|
-
|
158
|
+
App.open_drawing(file) do |d|
|
168
159
|
d.get_all_text
|
169
160
|
end
|
170
161
|
end
|
@@ -193,34 +184,28 @@ module Microstation
|
|
193
184
|
drawing.close
|
194
185
|
end
|
195
186
|
end
|
196
|
-
|
197
|
-
def run(options={}, &block)
|
198
|
-
App.run(...)
|
199
|
-
end
|
200
187
|
|
188
|
+
def run(options = {}, &block)
|
189
|
+
App.run(options, &block)
|
190
|
+
end
|
201
191
|
end
|
202
|
-
|
203
192
|
end
|
204
193
|
|
205
194
|
if $0 == __FILE__
|
206
195
|
|
207
|
-
require
|
196
|
+
require "pry"
|
208
197
|
|
209
198
|
app = Microstation::App.new
|
210
|
-
require
|
199
|
+
require "microstation/ole_helper"
|
211
200
|
|
212
|
-
File.
|
213
|
-
f.write app.ole_obj.ole_methods_detail
|
214
|
-
end
|
201
|
+
File.write("app_methods.txt", app.ole_obj.ole_methods_detail)
|
215
202
|
|
216
|
-
tlib = app.ole_obj.ole_typelib
|
217
|
-
File.
|
218
|
-
f.write app.ole_obj.ole_classes_detail
|
219
|
-
end
|
203
|
+
tlib = app.ole_obj.ole_typelib
|
204
|
+
File.write("microstation_classes.txt", app.ole_obj.ole_classes_detail)
|
220
205
|
|
221
206
|
ole_obj = app.ole_obj
|
222
207
|
|
223
|
-
event_classes = ole_obj.select_ole_type(
|
208
|
+
event_classes = ole_obj.select_ole_type("event")
|
224
209
|
puts event_classes
|
225
210
|
|
226
211
|
|