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,20 +1,13 @@
|
|
1
1
|
module Microstation
|
2
|
-
|
3
2
|
class TaggedElement
|
4
|
-
|
5
3
|
class Set
|
4
|
+
attr_reader :element, :name
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
def initialize(name,element)
|
6
|
+
def initialize(name, element)
|
10
7
|
@name = name
|
11
8
|
@element = element
|
12
9
|
end
|
13
10
|
|
14
|
-
def name
|
15
|
-
@name
|
16
|
-
end
|
17
|
-
|
18
11
|
def elements=(elements)
|
19
12
|
elements.each do |ele|
|
20
13
|
ele.base_element = @element
|
@@ -23,7 +16,7 @@ module Microstation
|
|
23
16
|
end
|
24
17
|
|
25
18
|
def find_attribute(name)
|
26
|
-
@elements.find{|a| a.name == name.to_s}
|
19
|
+
@elements.find { |a| a.name == name.to_s }
|
27
20
|
end
|
28
21
|
|
29
22
|
def [](name)
|
@@ -31,10 +24,10 @@ module Microstation
|
|
31
24
|
end
|
32
25
|
|
33
26
|
def attributes
|
34
|
-
@elements.map{|e| e.name}
|
27
|
+
@elements.map { |e| e.name }
|
35
28
|
end
|
36
29
|
|
37
|
-
def update_element(name,value)
|
30
|
+
def update_element(name, value)
|
38
31
|
find_attribute(name)._update(value)
|
39
32
|
end
|
40
33
|
|
@@ -45,14 +38,14 @@ module Microstation
|
|
45
38
|
def to_hash
|
46
39
|
result = {}
|
47
40
|
@elements.each do |ele|
|
48
|
-
result[ele.name] = ele.value unless
|
41
|
+
result[ele.name] = ele.value unless ele.value == "" || ele.value.nil?
|
49
42
|
end
|
50
43
|
result
|
51
44
|
end
|
52
45
|
|
53
46
|
def stringify_keys(hash)
|
54
47
|
result = {}
|
55
|
-
hash.each do |key,value|
|
48
|
+
hash.each do |key, value|
|
56
49
|
result[key.to_s] = value
|
57
50
|
end
|
58
51
|
result
|
@@ -62,44 +55,39 @@ module Microstation
|
|
62
55
|
value_hash = stringify_keys(value_hash)
|
63
56
|
valid_atts = attributes & value_hash.keys
|
64
57
|
valid_atts.each do |att|
|
65
|
-
update_element(att,value_hash[att])
|
58
|
+
update_element(att, value_hash[att])
|
66
59
|
end
|
67
60
|
end
|
68
61
|
|
69
|
-
def method_missing(meth
|
62
|
+
def method_missing(meth, *args, &block)
|
70
63
|
# binding.pry
|
71
64
|
base = meth.to_s.sub("=", "")
|
72
65
|
if attributes.include?(base)
|
73
|
-
if
|
74
|
-
update_element(base
|
66
|
+
if /(=)/.match?(meth)
|
67
|
+
update_element(base, *args)
|
75
68
|
else
|
76
69
|
element_value(base.to_s)
|
77
70
|
end
|
78
71
|
else
|
79
|
-
super(meth
|
72
|
+
super(meth, *args, &block)
|
80
73
|
end
|
81
74
|
end
|
82
|
-
|
83
75
|
end
|
84
76
|
|
85
|
-
def initialize(ole=nil)
|
77
|
+
def initialize(ole = nil)
|
86
78
|
@ole_obj = ole
|
87
79
|
@tag_sets = []
|
88
80
|
end
|
89
81
|
|
90
|
-
def add_tagset(name,elements)
|
91
|
-
ts = TaggedElement::Set.new(name,self)
|
82
|
+
def add_tagset(name, elements)
|
83
|
+
ts = TaggedElement::Set.new(name, self)
|
92
84
|
ts.elements = elements
|
93
85
|
@tag_sets << ts
|
94
86
|
ts
|
95
87
|
end
|
96
88
|
|
97
89
|
def get_tagset(name)
|
98
|
-
@tagsets.find{|ts| ts.name == name}
|
90
|
+
@tagsets.find { |ts| ts.name == name }
|
99
91
|
end
|
100
|
-
|
101
|
-
|
102
92
|
end
|
103
|
-
|
104
|
-
|
105
93
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require_relative
|
9
|
-
require File.join(File.dirname(__FILE__),
|
10
|
-
require File.join(File.dirname(__FILE__),
|
3
|
+
require "erb"
|
4
|
+
require "microstation"
|
5
|
+
require "liquid"
|
6
|
+
require "fileutils"
|
7
|
+
require "tmpdir"
|
8
|
+
require_relative "changer"
|
9
|
+
require File.join(File.dirname(__FILE__), "file_tests")
|
10
|
+
require File.join(File.dirname(__FILE__), "errors")
|
11
11
|
|
12
12
|
module Microstation
|
13
13
|
class Template
|
@@ -23,6 +23,7 @@ module Microstation
|
|
23
23
|
|
24
24
|
def render(name: nil, output_dir: nil, locals: EMPTY_HASH, tagsets: EMPTY_ARRAY)
|
25
25
|
return if locals == EMPTY_HASH && tagsets == EMPTY_ARRAY
|
26
|
+
|
26
27
|
@changer.run(name: name, output_dir: output_dir) do |drawing|
|
27
28
|
locals = normalize_hash(locals)
|
28
29
|
update_text(drawing, locals)
|
@@ -46,14 +47,14 @@ module Microstation
|
|
46
47
|
end
|
47
48
|
|
48
49
|
def change_template_text_normal(drawing, locals = {})
|
49
|
-
drawing.scan_text do |text|
|
50
|
+
drawing.scan_text do |_model, text|
|
50
51
|
new_text = update_liquid_text(text, locals)
|
51
52
|
text.replace new_text if new_text != text.to_s
|
52
53
|
end
|
53
54
|
end
|
54
55
|
|
55
56
|
def change_template_text_in_cells(drawing, locals = {})
|
56
|
-
drawing.scan_cells do |c|
|
57
|
+
drawing.scan_cells do |_model, c|
|
57
58
|
c.text_elements do |text|
|
58
59
|
new_text = update_liquid_text(text, locals)
|
59
60
|
text.replace new_text if new_text != text.to_s
|
@@ -65,10 +66,10 @@ module Microstation
|
|
65
66
|
update_hash = normalize_hash(locals)
|
66
67
|
compiled = ::Liquid::Template.parse(text.to_s)
|
67
68
|
new_text = begin
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
69
|
+
compiled.render(update_hash)
|
70
|
+
rescue
|
71
|
+
text
|
72
|
+
end
|
72
73
|
end
|
73
74
|
|
74
75
|
def normalize_hash(scope)
|
@@ -1,33 +1,27 @@
|
|
1
1
|
module Microstation
|
2
|
-
|
3
2
|
class TemplateInfo
|
4
|
-
|
5
3
|
class TagSetMap
|
6
|
-
|
7
|
-
def initialize(filter,block)
|
4
|
+
def initialize(filter, block)
|
8
5
|
@filter = filter
|
9
6
|
@block = block
|
10
7
|
end
|
11
8
|
|
12
9
|
def call(tagsets)
|
13
10
|
instances = tagsets.select(&filter)
|
14
|
-
instances.map{ |ti| block.call(ti)}
|
11
|
+
instances.map { |ti| block.call(ti) }
|
15
12
|
end
|
16
13
|
end
|
17
14
|
|
15
|
+
LIQUID_REGEXP = /{{([^}]+)}}/
|
18
16
|
|
19
|
-
|
20
|
-
LIQUID_REGEXP = /{{([^}}]+)}}/
|
21
|
-
|
22
|
-
|
23
|
-
attr_reader :drawing,:placeholder_keys, :template, :tagsets,:locals,:drawing_path, :tagset_filter,:tagset_map
|
17
|
+
attr_reader :drawing, :placeholder_keys, :template, :tagsets, :locals, :drawing_path, :tagset_filter, :tagset_map
|
24
18
|
|
25
19
|
def initialize(drawing, tagset_filter: nil, tagset_map: faa_map, visible: false)
|
26
20
|
case drawing
|
27
21
|
when ::Microstation::Drawing
|
28
22
|
initialize_attributes(drawing)
|
29
23
|
return
|
30
|
-
when String,Pathname
|
24
|
+
when String, Pathname
|
31
25
|
drawing_path = drawing
|
32
26
|
else
|
33
27
|
drawing_path = drawing.to_path
|
@@ -40,7 +34,7 @@ module Microstation
|
|
40
34
|
end
|
41
35
|
@tagset_filter = tagset_filter
|
42
36
|
@tagset_map = tagset_map
|
43
|
-
|
37
|
+
self
|
44
38
|
end
|
45
39
|
|
46
40
|
def initialize_attributes(drawing)
|
@@ -54,7 +48,7 @@ module Microstation
|
|
54
48
|
end
|
55
49
|
|
56
50
|
def drawing_tagsets(drawing)
|
57
|
-
#drawing.tagsets_in_drawing_to_hash
|
51
|
+
# drawing.tagsets_in_drawing_to_hash
|
58
52
|
drawing.tagsets_in_drawing_to_hash
|
59
53
|
end
|
60
54
|
|
@@ -63,36 +57,35 @@ module Microstation
|
|
63
57
|
end
|
64
58
|
|
65
59
|
def to_h
|
66
|
-
if tagset_filter
|
67
|
-
|
60
|
+
filtered = if tagset_filter
|
61
|
+
tagsets.select { |ts| tagset_filter.call(ts) }
|
68
62
|
else
|
69
|
-
|
63
|
+
tagsets.dup
|
70
64
|
end
|
71
|
-
mapped_tsets = filtered.map{|ts| tagset_map.call(ts)}
|
72
|
-
{
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
}
|
65
|
+
mapped_tsets = filtered.map { |ts| tagset_map.call(ts) }
|
66
|
+
{template: template,
|
67
|
+
output_dir: output_dir,
|
68
|
+
name: drawing_name,
|
69
|
+
locals: locals,
|
70
|
+
tagsets: mapped_tsets}
|
78
71
|
end
|
79
72
|
|
80
73
|
def default_filter
|
81
|
-
->(ts){ ts.name ==
|
74
|
+
->(ts) { ts.name == "faatitle" }
|
82
75
|
end
|
83
76
|
|
84
77
|
def before_locals(locals)
|
85
78
|
locals
|
86
79
|
end
|
87
80
|
|
88
|
-
def map_tagset(mapname
|
81
|
+
def map_tagset(mapname:, filter: tagset_name_filter, &block)
|
89
82
|
@tagset_mappings[tname] = TagSetMap.new(filter, block)
|
90
83
|
end
|
91
84
|
|
92
85
|
def do_tagset_mappings
|
93
86
|
@tagset_mappings.each do |ts_mapper|
|
94
87
|
ts_mapper.call(tagsets)
|
95
|
-
ti_instances = tagsets.select{|ts| ts[
|
88
|
+
ti_instances = tagsets.select { |ts| ts["tag_name"] == k }
|
96
89
|
ti_instances.each do |ti|
|
97
90
|
ti.attributes.map
|
98
91
|
end
|
@@ -100,11 +93,11 @@ module Microstation
|
|
100
93
|
end
|
101
94
|
|
102
95
|
def faa_map
|
103
|
-
|
104
|
-
if ts[
|
105
|
-
atts = ts[
|
106
|
-
new_atts = atts.keep_if{|k,
|
107
|
-
ts[
|
96
|
+
lambda { |ts|
|
97
|
+
if ts["tagset_name"] == "faatitle"
|
98
|
+
atts = ts["attributes"]
|
99
|
+
new_atts = atts.keep_if { |k, _v| faa_title_keys.include? k }
|
100
|
+
ts["attributes"] = new_atts
|
108
101
|
ts
|
109
102
|
else
|
110
103
|
ts
|
@@ -113,21 +106,20 @@ module Microstation
|
|
113
106
|
end
|
114
107
|
|
115
108
|
def faa_title_keys
|
116
|
-
%w
|
109
|
+
%w[microstation_id fac title1 title2 title3 subnam subttle appname appttl file dnnew jcnno city state]
|
117
110
|
end
|
118
111
|
|
119
|
-
|
120
112
|
def drawing_name
|
121
113
|
drawing_path.basename.to_s
|
122
114
|
end
|
123
115
|
|
124
116
|
def yaml_filename
|
125
|
-
drawing_path.basename.ext(
|
117
|
+
drawing_path.basename.ext("yaml")
|
126
118
|
end
|
127
119
|
|
128
120
|
def dump(dir = output_dir)
|
129
121
|
dir = Pathname(dir)
|
130
|
-
File.open(dir + yaml_filename,
|
122
|
+
File.open(dir + yaml_filename, "w") { |f| f.puts to_yaml }
|
131
123
|
end
|
132
124
|
|
133
125
|
def to_yaml
|
@@ -136,37 +128,31 @@ module Microstation
|
|
136
128
|
|
137
129
|
protected
|
138
130
|
|
139
|
-
def entry_points(
|
131
|
+
def entry_points(_drawing)
|
140
132
|
@entry_points ||= get_entry_points
|
141
133
|
end
|
142
134
|
|
143
135
|
def get_entry_points(drawing)
|
144
136
|
result = []
|
145
|
-
drawing.
|
146
|
-
|
147
|
-
|
148
|
-
result << [m, text.to_s] if text.to_s =~ /{{([^}}])+}}/
|
137
|
+
drawing.scan_text do |model, text|
|
138
|
+
result << [model, text.to_s] if /{{([^}])+}}/.match?(text.to_s)
|
149
139
|
end
|
150
|
-
binding.pry
|
151
140
|
result
|
152
141
|
end
|
153
142
|
|
154
|
-
def keys_from_entry_points(entry_points= get_entry_points)
|
155
|
-
entry_points.reduce([]) do |result,(
|
156
|
-
text.scan(LIQUID_REGEXP).flatten.map{|t| t.strip}.each do |a|
|
143
|
+
def keys_from_entry_points(entry_points = get_entry_points)
|
144
|
+
entry_points.reduce([]) do |result, (_m, text)|
|
145
|
+
text.scan(LIQUID_REGEXP).flatten.map { |t| t.strip }.each do |a|
|
157
146
|
result << a
|
158
147
|
end
|
159
148
|
result.uniq
|
160
149
|
end
|
161
150
|
end
|
162
151
|
|
163
|
-
def keys_to_h(keys= @placeholder_keys)
|
164
|
-
keys.each_with_object({}) do |k,h|
|
152
|
+
def keys_to_h(keys = @placeholder_keys)
|
153
|
+
keys.each_with_object({}) do |k, h|
|
165
154
|
h[k] = ""
|
166
155
|
end
|
167
156
|
end
|
168
|
-
|
169
|
-
|
170
157
|
end
|
171
|
-
|
172
158
|
end
|
@@ -1,7 +1,5 @@
|
|
1
1
|
module Microstation
|
2
|
-
|
3
2
|
class TemplateRunner
|
4
|
-
|
5
3
|
attr_reader :file, :template_hash
|
6
4
|
|
7
5
|
def initialize(file)
|
@@ -11,18 +9,16 @@ module Microstation
|
|
11
9
|
end
|
12
10
|
|
13
11
|
def load(file)
|
14
|
-
|
15
|
-
|
16
|
-
YAML.load(f)
|
17
|
-
end
|
18
|
-
rescue => e
|
19
|
-
binding.pry
|
20
|
-
puts "Could not parse YAML: #{e.message}"
|
12
|
+
File.open(file) do |f|
|
13
|
+
YAML.load(f)
|
21
14
|
end
|
15
|
+
rescue => e
|
16
|
+
binding.pry
|
17
|
+
puts "Could not parse YAML: #{e.message}"
|
22
18
|
end
|
23
19
|
|
24
20
|
def name
|
25
|
-
template_hash[:name] || Pathname(template).basename.ext(
|
21
|
+
template_hash[:name] || Pathname(template).basename.ext(".dgn")
|
26
22
|
end
|
27
23
|
|
28
24
|
def locals
|
@@ -41,25 +37,21 @@ module Microstation
|
|
41
37
|
template_hash[:template]
|
42
38
|
end
|
43
39
|
|
44
|
-
def run_with_app(app,options = {})
|
45
|
-
run_options = {
|
40
|
+
def run_with_app(app, options = {})
|
41
|
+
run_options = {app: app}.merge(options)
|
46
42
|
run(run_options)
|
47
43
|
end
|
48
44
|
|
49
45
|
def run(options = {})
|
50
|
-
begin
|
51
46
|
the_template = Template.new(template)
|
52
|
-
template_options = {
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
}
|
47
|
+
template_options = {output_dir: output_dir,
|
48
|
+
locals: locals,
|
49
|
+
name: name,
|
50
|
+
tagsets: tagsets}
|
57
51
|
run_options = template_options.merge(options)
|
58
52
|
the_template.render(run_options)
|
59
|
-
|
60
|
-
|
61
|
-
end
|
53
|
+
rescue
|
54
|
+
binding.pry
|
62
55
|
end
|
63
|
-
|
64
56
|
end
|
65
57
|
end
|
data/lib/microstation/text.rb
CHANGED
@@ -1,11 +1,8 @@
|
|
1
|
-
require
|
1
|
+
require "microstation/element"
|
2
2
|
|
3
3
|
module Microstation
|
4
|
-
|
5
4
|
class Text < Element
|
6
|
-
|
7
|
-
|
8
|
-
def read_ole(ole)
|
5
|
+
def read_ole(_ole)
|
9
6
|
ole_obj.Text
|
10
7
|
end
|
11
8
|
|
@@ -21,7 +18,6 @@ module Microstation
|
|
21
18
|
@original =~ reg
|
22
19
|
end
|
23
20
|
|
24
|
-
|
25
21
|
# def microstation_id
|
26
22
|
# @ole_obj.Id || @ole_obj.ID64
|
27
23
|
# end
|
@@ -40,27 +36,31 @@ module Microstation
|
|
40
36
|
def bounds
|
41
37
|
binding.pry
|
42
38
|
rotation = ole_obj.Rotation
|
43
|
-
inverse_rotation =
|
44
|
-
|
39
|
+
inverse_rotation = begin
|
40
|
+
app_ole_obj.Matrix3dInverse(rotation)
|
41
|
+
rescue
|
42
|
+
pry
|
43
|
+
end
|
44
|
+
transform = app_ole_obj.Transform3dFromMatrix3dandFixedPoint3d(app_ole_obj.Matrix3dInverse(rotation),
|
45
|
+
ole_obj.origin)
|
45
46
|
ole_obj.transform transform
|
46
47
|
pts = []
|
47
48
|
|
48
|
-
0.upto(4)
|
49
|
+
0.upto(4) do |i|
|
49
50
|
points[i] = ole_obj.Boundary.Low
|
50
51
|
end
|
51
52
|
points[2] = self.Boundary.High
|
52
53
|
points[1].X = points[2].x
|
53
54
|
points[3].y = points[2].Y
|
54
|
-
|
55
55
|
end
|
56
56
|
|
57
|
-
def method_missing(meth
|
58
|
-
if
|
59
|
-
ole_obj.send(meth
|
57
|
+
def method_missing(meth, *args, &block)
|
58
|
+
if /^[A-Z]/.match?(meth)
|
59
|
+
ole_obj.send(meth, *args)
|
60
60
|
else
|
61
61
|
dup = @original.dup
|
62
|
-
result = dup.send(meth
|
63
|
-
update(result)
|
62
|
+
result = dup.send(meth, *args, &block)
|
63
|
+
update(result)
|
64
64
|
result
|
65
65
|
end
|
66
66
|
end
|
@@ -71,9 +71,5 @@ module Microstation
|
|
71
71
|
# _update(dup) unless dup == @original_text
|
72
72
|
# result
|
73
73
|
# end
|
74
|
-
|
75
|
-
|
76
|
-
|
77
74
|
end
|
78
|
-
|
79
75
|
end
|
@@ -1,15 +1,11 @@
|
|
1
1
|
module Microstation
|
2
|
-
|
3
2
|
class TextNode < Element
|
4
|
-
|
5
3
|
attr_reader :original, :ole_obj
|
6
4
|
|
7
|
-
|
8
5
|
def to_regexp
|
9
6
|
Regexp.new(original.to_s)
|
10
7
|
end
|
11
8
|
|
12
|
-
|
13
9
|
def empty?
|
14
10
|
ole_obj.TextLinesCount == 0
|
15
11
|
end
|
@@ -22,7 +18,6 @@ module Microstation
|
|
22
18
|
ole_obj.TextLinesCount
|
23
19
|
end
|
24
20
|
|
25
|
-
|
26
21
|
def read_ole(ole)
|
27
22
|
count = ole.TextLinesCount
|
28
23
|
# debugger if count > 0
|
@@ -54,17 +49,15 @@ module Microstation
|
|
54
49
|
end
|
55
50
|
|
56
51
|
def write_ole_in_cell(text)
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
new_text_ole.AddTextLine(line)
|
63
|
-
end
|
64
|
-
@ole_obj = new_text_ole
|
65
|
-
rescue => e
|
66
|
-
@ole_obj = orig_ole
|
52
|
+
orig_ole = ole_obj
|
53
|
+
new_text_ole = ole_obj.Clone
|
54
|
+
new_text_ole.DeleteAllTextLines
|
55
|
+
text.each_line do |line|
|
56
|
+
new_text_ole.AddTextLine(line)
|
67
57
|
end
|
58
|
+
@ole_obj = new_text_ole
|
59
|
+
rescue => e
|
60
|
+
@ole_obj = orig_ole
|
68
61
|
end
|
69
62
|
|
70
63
|
def update_ole!(text)
|
@@ -81,33 +74,33 @@ module Microstation
|
|
81
74
|
end
|
82
75
|
|
83
76
|
def =~(reg)
|
84
|
-
@original =~ reg
|
77
|
+
@original =~ reg
|
85
78
|
end
|
86
79
|
|
87
80
|
def template?
|
88
81
|
!!(@original =~ /{{.+}}/)
|
89
82
|
end
|
90
83
|
|
91
|
-
def render(h={})
|
92
|
-
return self unless
|
93
|
-
|
84
|
+
def render(h = {})
|
85
|
+
return self unless template?
|
86
|
+
|
87
|
+
template = Liquid::Template.parse(to_s)
|
94
88
|
result = template.render(h)
|
95
89
|
update(result) unless result == @original
|
96
90
|
self
|
97
91
|
end
|
98
92
|
|
99
|
-
def method_missing(meth
|
100
|
-
if
|
101
|
-
ole_obj.send(meth
|
93
|
+
def method_missing(meth, *args, &block)
|
94
|
+
if /^[A-Z]/.match?(meth)
|
95
|
+
ole_obj.send(meth, *args)
|
102
96
|
else
|
103
97
|
copy = @original.dup
|
104
|
-
result = copy.send(meth
|
98
|
+
result = copy.send(meth, *args, &block)
|
105
99
|
update(result) unless copy == @original
|
106
100
|
result
|
107
101
|
end
|
108
102
|
end
|
109
103
|
|
110
|
-
|
111
104
|
# def method_missing2(meth,*args,&block)
|
112
105
|
# if meth.to_s =~ /^[A-Z]/
|
113
106
|
# ole_obj.send(meth,*args)
|
@@ -118,7 +111,5 @@ module Microstation
|
|
118
111
|
# result
|
119
112
|
# end
|
120
113
|
# end
|
121
|
-
|
122
114
|
end
|
123
|
-
|
124
115
|
end
|
@@ -1,9 +1,6 @@
|
|
1
1
|
module Microstation
|
2
|
-
|
3
2
|
module TS
|
4
|
-
|
5
3
|
class Attribute
|
6
|
-
|
7
4
|
attr_reader :ole_obj
|
8
5
|
|
9
6
|
# msdTagTypeCharacter 1 (&H1)
|
@@ -16,26 +13,26 @@ module Microstation
|
|
16
13
|
1 => String,
|
17
14
|
2 => Integer,
|
18
15
|
3 => Integer,
|
19
|
-
4 => Float
|
16
|
+
4 => Float
|
20
17
|
# 5 => Binary
|
21
18
|
}
|
22
19
|
|
23
20
|
RUBY_TO_MS = TYPES.invert
|
24
21
|
|
25
22
|
def self.tag_type(type)
|
26
|
-
if type.
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
23
|
+
ruby_type = if type.instance_of?(Symbol)
|
24
|
+
case type
|
25
|
+
when :char
|
26
|
+
String
|
27
|
+
when :int
|
28
|
+
Integer
|
29
|
+
when :float
|
30
|
+
Float
|
31
|
+
else
|
32
|
+
:char
|
33
|
+
end
|
37
34
|
else
|
38
|
-
|
35
|
+
type
|
39
36
|
end
|
40
37
|
|
41
38
|
RUBY_TO_MS[ruby_type]
|
@@ -104,9 +101,10 @@ module Microstation
|
|
104
101
|
end
|
105
102
|
|
106
103
|
def hidden=(hidden)
|
107
|
-
bool =
|
104
|
+
bool = hidden ? true : false
|
108
105
|
@ole_obj.IsHidden = bool
|
109
106
|
end
|
107
|
+
|
110
108
|
def prompt
|
111
109
|
@ole_obj.Prompt
|
112
110
|
end
|
@@ -131,10 +129,8 @@ module Microstation
|
|
131
129
|
end
|
132
130
|
|
133
131
|
def ==(other)
|
134
|
-
@ole_obj.Name == other.ole_obj.Name
|
132
|
+
@ole_obj.Name == other.ole_obj.Name && @ole_obj.TagSetName == other.ole_obj.TagSetName && @ole_obj.TagType == other.ole_obj.TagType
|
135
133
|
end
|
136
|
-
|
137
134
|
end
|
138
|
-
|
139
135
|
end
|
140
136
|
end
|