microstation 0.4.1 → 0.8.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.autotest +23 -23
- data/.rspec +2 -2
- data/Gemfile +29 -10
- data/History.txt +6 -6
- data/LICENSE.adoc +22 -0
- data/Manifest.txt +91 -60
- data/README.adoc +131 -0
- data/Rakefile +72 -30
- data/bin/dgn2pdf +36 -37
- data/bin/dgn_template +107 -0
- data/bin/pw_print +35 -0
- data/cad_files/drawing_faatitle_in_non_default_model.dgn +0 -0
- 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/cad_files/seed2d.dgn +0 -0
- data/cad_files/seed3d.dgn +0 -0
- data/lib/microstation/app.rb +781 -286
- data/lib/microstation/cad_input_queue.rb +100 -25
- data/lib/microstation/cell.rb +191 -0
- data/lib/microstation/changer.rb +70 -0
- data/lib/microstation/configuration.rb +193 -57
- data/lib/microstation/criteria_creation_t.rb +23 -0
- data/lib/microstation/dir.rb +252 -252
- data/lib/microstation/directory.rb +46 -0
- data/lib/microstation/drawing.rb +686 -189
- data/lib/microstation/element.rb +311 -0
- data/lib/microstation/enumerator.rb +32 -29
- data/lib/microstation/errors.rb +17 -0
- data/lib/microstation/event_handler.rb +28 -0
- data/lib/microstation/ext/pathname.rb +23 -25
- data/lib/microstation/ext/win32ole.rb +7 -0
- data/lib/microstation/extensions/faa.rb +124 -0
- data/lib/microstation/file_tests.rb +68 -0
- data/lib/microstation/functions.rb +60 -0
- data/lib/microstation/graphics.rb +35 -0
- data/lib/microstation/line.rb +19 -0
- data/lib/microstation/model.rb +45 -0
- data/lib/microstation/model_trait.rb +189 -0
- data/lib/microstation/ole_cad_input_message.rb +101 -0
- data/lib/microstation/ole_helper.rb +152 -0
- data/lib/microstation/pdf_support.rb +40 -40
- data/lib/microstation/point3d.rb +71 -0
- data/lib/microstation/primitive_command_interface.rb +66 -0
- data/lib/microstation/properties.rb +61 -57
- data/lib/microstation/property_handler.rb +48 -0
- data/lib/microstation/scan/color.rb +38 -38
- data/lib/microstation/scan/criteria.rb +89 -85
- data/lib/microstation/scan/klass.rb +43 -43
- data/lib/microstation/scan/level.rb +38 -38
- data/lib/microstation/scan/line_style.rb +45 -45
- data/lib/microstation/scan/line_weight.rb +33 -33
- data/lib/microstation/scan/range.rb +19 -0
- data/lib/microstation/scan/scan_trait.rb +51 -0
- data/lib/microstation/scan/subtype.rb +40 -40
- data/lib/microstation/scan/type.rb +134 -109
- data/lib/microstation/scan_trait.rb +62 -0
- data/lib/microstation/scanner.rb +24 -24
- data/lib/microstation/tag.rb +87 -58
- data/lib/microstation/tag_set.rb +385 -280
- data/lib/microstation/tag_set_trait.rb +51 -0
- data/lib/microstation/tagged_element.rb +105 -0
- data/lib/microstation/template.rb +90 -84
- data/lib/microstation/template_info.rb +172 -0
- data/lib/microstation/template_runner.rb +65 -0
- data/lib/microstation/text.rb +79 -54
- data/lib/microstation/text_node.rb +124 -74
- data/lib/microstation/ts/attribute.rb +140 -139
- data/lib/microstation/ts/instance.rb +146 -112
- data/lib/microstation/ts/tagset_trait.rb +49 -0
- data/lib/microstation/types.rb +91 -91
- data/lib/microstation/version.rb +5 -0
- data/lib/microstation/wrap.rb +28 -214
- data/lib/microstation.rb +252 -88
- data/plot/pdf-bw.plt +164 -164
- data/plot/pdf.plt +163 -163
- data/plot/png.plt +383 -383
- data/plot/tiff.plt +384 -384
- data/plot/wmbw.tbl +324 -66
- data/plot/wmcolor.tbl +62 -62
- data/spec/microstation/app_spec.rb +184 -0
- data/spec/microstation/configuration_spec.rb +131 -0
- data/spec/microstation/drawing_spec.rb +245 -0
- data/spec/microstation/functions_spec.rb +36 -0
- data/spec/microstation/tag_set_spec.rb +159 -0
- data/spec/microstation/template_spec.rb +159 -0
- data/spec/microstation/text_node_spec.rb +67 -0
- data/spec/microstation/text_spec.rb +42 -0
- data/spec/microstation_spec.rb +47 -36
- data/spec/spec_helper.rb +97 -31
- metadata +308 -84
- data/.gemtest +0 -0
- data/README.txt +0 -75
- data/lib/microstation/attributes.rb +0 -35
- data/lib/microstation/extensions/hash.rb +0 -27
- data/spec/app_spec.rb +0 -267
- data/spec/configuration_spec.rb +0 -122
- data/spec/drawing_spec.rb +0 -247
- 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 +0 -60
- data/spec/scanner_spec.rb +0 -155
- data/spec/spec_app.rb +0 -11
- data/spec/tag_set_spec.rb +0 -123
- data/spec/text_node_spec.rb +0 -92
- data/spec/text_spec.rb +0 -62
@@ -0,0 +1,51 @@
|
|
1
|
+
module Microstation
|
2
|
+
|
3
|
+
module TagSetTrait
|
4
|
+
|
5
|
+
def tagsets
|
6
|
+
@tagsets ||= TagSets.new(self,ole_obj_tagsets)
|
7
|
+
end
|
8
|
+
|
9
|
+
def tagset_names
|
10
|
+
tagsets.map{|ts| ts.name}
|
11
|
+
end
|
12
|
+
|
13
|
+
def reset_tagsets
|
14
|
+
@tagsets = nil
|
15
|
+
tagsets
|
16
|
+
end
|
17
|
+
|
18
|
+
def create_tagset(name,&block)
|
19
|
+
ts = tagsets.create(name)
|
20
|
+
reset_tagsets
|
21
|
+
block.call ts if block
|
22
|
+
ts
|
23
|
+
end
|
24
|
+
|
25
|
+
def create_tagset!(name,&block)
|
26
|
+
remove_tagset(name)
|
27
|
+
create_tagset(name,&block)
|
28
|
+
end
|
29
|
+
|
30
|
+
def remove_tagset(name)
|
31
|
+
tagsets.remove(name)
|
32
|
+
reset_tagsets
|
33
|
+
end
|
34
|
+
|
35
|
+
def find_tagset(name)
|
36
|
+
tagsets[name]
|
37
|
+
end
|
38
|
+
|
39
|
+
protected
|
40
|
+
|
41
|
+
def ole_obj_tagsets
|
42
|
+
@ole_obj.TagSets
|
43
|
+
end
|
44
|
+
|
45
|
+
def ensure_tags(tags)
|
46
|
+
tags.map{|t| t.class == WIN32OLE ? app.ole_to_ruby(t) : t }
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
module Microstation
|
2
|
+
|
3
|
+
class TaggedElement
|
4
|
+
|
5
|
+
class Set
|
6
|
+
|
7
|
+
attr_reader :element
|
8
|
+
|
9
|
+
def initialize(name,element)
|
10
|
+
@name = name
|
11
|
+
@element = element
|
12
|
+
end
|
13
|
+
|
14
|
+
def name
|
15
|
+
@name
|
16
|
+
end
|
17
|
+
|
18
|
+
def elements=(elements)
|
19
|
+
elements.each do |ele|
|
20
|
+
ele.base_element = @element
|
21
|
+
end
|
22
|
+
@elements = elements
|
23
|
+
end
|
24
|
+
|
25
|
+
def find_attribute(name)
|
26
|
+
@elements.find{|a| a.name == name.to_s}
|
27
|
+
end
|
28
|
+
|
29
|
+
def [](name)
|
30
|
+
find_attribute(name)
|
31
|
+
end
|
32
|
+
|
33
|
+
def attributes
|
34
|
+
@elements.map{|e| e.name}
|
35
|
+
end
|
36
|
+
|
37
|
+
def update_element(name,value)
|
38
|
+
find_attribute(name)._update(value)
|
39
|
+
end
|
40
|
+
|
41
|
+
def element_value(name)
|
42
|
+
find_attribute(name).value
|
43
|
+
end
|
44
|
+
|
45
|
+
def to_hash
|
46
|
+
result = {}
|
47
|
+
@elements.each do |ele|
|
48
|
+
result[ele.name] = ele.value unless (ele.value == "" || ele.value.nil?)
|
49
|
+
end
|
50
|
+
result
|
51
|
+
end
|
52
|
+
|
53
|
+
def stringify_keys(hash)
|
54
|
+
result = {}
|
55
|
+
hash.each do |key,value|
|
56
|
+
result[key.to_s] = value
|
57
|
+
end
|
58
|
+
result
|
59
|
+
end
|
60
|
+
|
61
|
+
def update(value_hash)
|
62
|
+
value_hash = stringify_keys(value_hash)
|
63
|
+
valid_atts = attributes & value_hash.keys
|
64
|
+
valid_atts.each do |att|
|
65
|
+
update_element(att,value_hash[att])
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def method_missing(meth,*args,&block)
|
70
|
+
# binding.pry
|
71
|
+
base = meth.to_s.sub("=", "")
|
72
|
+
if attributes.include?(base)
|
73
|
+
if meth.match /(=)/
|
74
|
+
update_element(base,*args)
|
75
|
+
else
|
76
|
+
element_value(base.to_s)
|
77
|
+
end
|
78
|
+
else
|
79
|
+
super(meth,*args,&block)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
def initialize(ole=nil)
|
86
|
+
@ole_obj = ole
|
87
|
+
@tag_sets = []
|
88
|
+
end
|
89
|
+
|
90
|
+
def add_tagset(name,elements)
|
91
|
+
ts = TaggedElement::Set.new(name,self)
|
92
|
+
ts.elements = elements
|
93
|
+
@tag_sets << ts
|
94
|
+
ts
|
95
|
+
end
|
96
|
+
|
97
|
+
def get_tagset(name)
|
98
|
+
@tagsets.find{|ts| ts.name == name}
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
end
|
@@ -1,84 +1,90 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require '
|
4
|
-
require
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
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
|
+
|
12
|
+
module Microstation
|
13
|
+
class Template
|
14
|
+
EMPTY_ARRAY = [].freeze
|
15
|
+
EMPTY_HASH = {}.freeze
|
16
|
+
def initialize(template, output_dir: nil, app: nil, name: nil)
|
17
|
+
@changer = Changer.new(template, output_dir: output_dir, app: app, name: name)
|
18
|
+
end
|
19
|
+
|
20
|
+
def template
|
21
|
+
@changer.template
|
22
|
+
end
|
23
|
+
|
24
|
+
def render(name: nil, output_dir: nil, locals: EMPTY_HASH, tagsets: EMPTY_ARRAY)
|
25
|
+
return if locals == EMPTY_HASH && tagsets == EMPTY_ARRAY
|
26
|
+
@changer.run(name: name, output_dir: output_dir) do |drawing|
|
27
|
+
locals = normalize_hash(locals)
|
28
|
+
update_text(drawing, locals)
|
29
|
+
update_tagsets(drawing, tagsets)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def run(update = {})
|
34
|
+
@changer.run do |drawing|
|
35
|
+
locals = normalize_hash(update)
|
36
|
+
return if locals == {}
|
37
|
+
|
38
|
+
update_text(drawing, locals)
|
39
|
+
update_tagsets(drawing, tagsets)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def update_text(drawing, locals = {})
|
44
|
+
change_template_text_normal(drawing, locals)
|
45
|
+
change_template_text_in_cells(drawing, locals)
|
46
|
+
end
|
47
|
+
|
48
|
+
def change_template_text_normal(drawing, locals = {})
|
49
|
+
drawing.scan_text do |text|
|
50
|
+
new_text = update_liquid_text(text, locals)
|
51
|
+
text.replace new_text if new_text != text.to_s
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def change_template_text_in_cells(drawing, locals = {})
|
56
|
+
drawing.scan_cells do |c|
|
57
|
+
c.text_elements do |text|
|
58
|
+
new_text = update_liquid_text(text, locals)
|
59
|
+
text.replace new_text if new_text != text.to_s
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def update_liquid_text(text, locals)
|
65
|
+
update_hash = normalize_hash(locals)
|
66
|
+
compiled = ::Liquid::Template.parse(text.to_s)
|
67
|
+
new_text = begin
|
68
|
+
compiled.render(update_hash)
|
69
|
+
rescue StandardError
|
70
|
+
text
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def normalize_hash(scope)
|
75
|
+
scope = scope.to_h if scope.respond_to?(:to_h)
|
76
|
+
scope = scope.transform_keys(&:to_s) if scope.is_a? Hash
|
77
|
+
scope
|
78
|
+
end
|
79
|
+
|
80
|
+
def update_tagsets(drawing, ts_arg)
|
81
|
+
return if ts_arg == []
|
82
|
+
return if ts_arg == {}
|
83
|
+
|
84
|
+
ts_arg = [ts_arg] if ts_arg.instance_of?(Hash)
|
85
|
+
ts_arg.each do |hash_pair|
|
86
|
+
drawing.update_tagset(hash_pair.keys[0], hash_pair.values[0])
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,172 @@
|
|
1
|
+
module Microstation
|
2
|
+
|
3
|
+
class TemplateInfo
|
4
|
+
|
5
|
+
class TagSetMap
|
6
|
+
|
7
|
+
def initialize(filter,block)
|
8
|
+
@filter = filter
|
9
|
+
@block = block
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(tagsets)
|
13
|
+
instances = tagsets.select(&filter)
|
14
|
+
instances.map{ |ti| block.call(ti)}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
LIQUID_REGEXP = /{{([^}}]+)}}/
|
21
|
+
|
22
|
+
|
23
|
+
attr_reader :drawing,:placeholder_keys, :template, :tagsets,:locals,:drawing_path, :tagset_filter,:tagset_map
|
24
|
+
|
25
|
+
def initialize(drawing, tagset_filter: nil, tagset_map: faa_map, visible: false)
|
26
|
+
case drawing
|
27
|
+
when ::Microstation::Drawing
|
28
|
+
initialize_attributes(drawing)
|
29
|
+
return
|
30
|
+
when String,Pathname
|
31
|
+
drawing_path = drawing
|
32
|
+
else
|
33
|
+
drawing_path = drawing.to_path
|
34
|
+
end
|
35
|
+
binding.pry
|
36
|
+
::Microstation::App.run(visible: visible) do |app|
|
37
|
+
app.open_drawing(drawing_path) do |d|
|
38
|
+
initialize_attributes(d)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
@tagset_filter = tagset_filter
|
42
|
+
@tagset_map = tagset_map
|
43
|
+
return self
|
44
|
+
end
|
45
|
+
|
46
|
+
def initialize_attributes(drawing)
|
47
|
+
@drawing_path = drawing.path
|
48
|
+
entry_points = get_entry_points(drawing)
|
49
|
+
@placeholder_keys = keys_from_entry_points(entry_points)
|
50
|
+
@locals = keys_to_h(@placeholder_keys)
|
51
|
+
@template = @drawing_path.to_s
|
52
|
+
@tagsets = drawing_tagsets(drawing)
|
53
|
+
@output_dir = output_dir(@drawing_path)
|
54
|
+
end
|
55
|
+
|
56
|
+
def drawing_tagsets(drawing)
|
57
|
+
#drawing.tagsets_in_drawing_to_hash
|
58
|
+
drawing.tagsets_in_drawing_to_hash
|
59
|
+
end
|
60
|
+
|
61
|
+
def output_dir(l_drawing_path = @drawing_path)
|
62
|
+
l_drawing_path.parent.to_s
|
63
|
+
end
|
64
|
+
|
65
|
+
def to_h
|
66
|
+
if tagset_filter
|
67
|
+
filtered = tagsets.select{|ts| tagset_filter.call(ts)}
|
68
|
+
else
|
69
|
+
filtered = tagsets.dup
|
70
|
+
end
|
71
|
+
mapped_tsets = filtered.map{|ts| tagset_map.call(ts)}
|
72
|
+
{ template: template,
|
73
|
+
output_dir: output_dir,
|
74
|
+
name: drawing_name,
|
75
|
+
locals: locals,
|
76
|
+
tagsets: mapped_tsets
|
77
|
+
}
|
78
|
+
end
|
79
|
+
|
80
|
+
def default_filter
|
81
|
+
->(ts){ ts.name == 'faatitle'}
|
82
|
+
end
|
83
|
+
|
84
|
+
def before_locals(locals)
|
85
|
+
locals
|
86
|
+
end
|
87
|
+
|
88
|
+
def map_tagset(mapname: , filter: tagset_name_filter, &block)
|
89
|
+
@tagset_mappings[tname] = TagSetMap.new(filter, block)
|
90
|
+
end
|
91
|
+
|
92
|
+
def do_tagset_mappings
|
93
|
+
@tagset_mappings.each do |ts_mapper|
|
94
|
+
ts_mapper.call(tagsets)
|
95
|
+
ti_instances = tagsets.select{|ts| ts['tag_name'] == k}
|
96
|
+
ti_instances.each do |ti|
|
97
|
+
ti.attributes.map
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def faa_map
|
103
|
+
->(ts){
|
104
|
+
if ts['tagset_name'] == 'faatitle'
|
105
|
+
atts = ts['attributes']
|
106
|
+
new_atts = atts.keep_if{|k,v| faa_title_keys.include? k}
|
107
|
+
ts['attributes']= new_atts
|
108
|
+
ts
|
109
|
+
else
|
110
|
+
ts
|
111
|
+
end
|
112
|
+
}
|
113
|
+
end
|
114
|
+
|
115
|
+
def faa_title_keys
|
116
|
+
%w(microstation_id fac title1 title2 title3 subnam subttle appname appttl file dnnew jcnno city state)
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
def drawing_name
|
121
|
+
drawing_path.basename.to_s
|
122
|
+
end
|
123
|
+
|
124
|
+
def yaml_filename
|
125
|
+
drawing_path.basename.ext('yaml')
|
126
|
+
end
|
127
|
+
|
128
|
+
def dump(dir = output_dir)
|
129
|
+
dir = Pathname(dir)
|
130
|
+
File.open(dir + yaml_filename, 'w'){|f| f.puts self.to_yaml}
|
131
|
+
end
|
132
|
+
|
133
|
+
def to_yaml
|
134
|
+
to_h.to_yaml
|
135
|
+
end
|
136
|
+
|
137
|
+
protected
|
138
|
+
|
139
|
+
def entry_points(drawing)
|
140
|
+
@entry_points ||= get_entry_points
|
141
|
+
end
|
142
|
+
|
143
|
+
def get_entry_points(drawing)
|
144
|
+
result = []
|
145
|
+
drawing.scan_all_text do |m,text|
|
146
|
+
binding.pry if text =~ /txt1/
|
147
|
+
|
148
|
+
result << [m, text.to_s] if text.to_s =~ /{{([^}}])+}}/
|
149
|
+
end
|
150
|
+
binding.pry
|
151
|
+
result
|
152
|
+
end
|
153
|
+
|
154
|
+
def keys_from_entry_points(entry_points= get_entry_points)
|
155
|
+
entry_points.reduce([]) do |result,(m,text)|
|
156
|
+
text.scan(LIQUID_REGEXP).flatten.map{|t| t.strip}.each do |a|
|
157
|
+
result << a
|
158
|
+
end
|
159
|
+
result.uniq
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
def keys_to_h(keys= @placeholder_keys)
|
164
|
+
keys.each_with_object({}) do |k,h|
|
165
|
+
h[k] = ""
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Microstation
|
2
|
+
|
3
|
+
class TemplateRunner
|
4
|
+
|
5
|
+
attr_reader :file, :template_hash
|
6
|
+
|
7
|
+
def initialize(file)
|
8
|
+
puts "running #{file}"
|
9
|
+
@file = file
|
10
|
+
@template_hash = load(file)
|
11
|
+
end
|
12
|
+
|
13
|
+
def load(file)
|
14
|
+
begin
|
15
|
+
File.open(file) do |f|
|
16
|
+
YAML.load(f)
|
17
|
+
end
|
18
|
+
rescue => e
|
19
|
+
binding.pry
|
20
|
+
puts "Could not parse YAML: #{e.message}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def name
|
25
|
+
template_hash[:name] || Pathname(template).basename.ext('.dgn')
|
26
|
+
end
|
27
|
+
|
28
|
+
def locals
|
29
|
+
template_hash[:locals]
|
30
|
+
end
|
31
|
+
|
32
|
+
def tagsets
|
33
|
+
template_hash[:tagsets]
|
34
|
+
end
|
35
|
+
|
36
|
+
def output_dir
|
37
|
+
template_hash[:output_dir]
|
38
|
+
end
|
39
|
+
|
40
|
+
def template
|
41
|
+
template_hash[:template]
|
42
|
+
end
|
43
|
+
|
44
|
+
def run_with_app(app,options = {})
|
45
|
+
run_options = { app: app}.merge(options)
|
46
|
+
run(run_options)
|
47
|
+
end
|
48
|
+
|
49
|
+
def run(options = {})
|
50
|
+
begin
|
51
|
+
the_template = Template.new(template)
|
52
|
+
template_options = { output_dir: output_dir,
|
53
|
+
locals: locals,
|
54
|
+
name: name,
|
55
|
+
tagsets: tagsets
|
56
|
+
}
|
57
|
+
run_options = template_options.merge(options)
|
58
|
+
the_template.render(run_options)
|
59
|
+
rescue
|
60
|
+
binding.pry
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
data/lib/microstation/text.rb
CHANGED
@@ -1,54 +1,79 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
def
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
def
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
1
|
+
require 'microstation/element'
|
2
|
+
|
3
|
+
module Microstation
|
4
|
+
|
5
|
+
class Text < Element
|
6
|
+
|
7
|
+
|
8
|
+
def read_ole(ole)
|
9
|
+
ole_obj.Text
|
10
|
+
end
|
11
|
+
|
12
|
+
def write_ole(text)
|
13
|
+
ole_obj.Text = text
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_regexp
|
17
|
+
Regexp.new(read_ole.to_s)
|
18
|
+
end
|
19
|
+
|
20
|
+
def =~(reg)
|
21
|
+
@original =~ reg
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
# def microstation_id
|
26
|
+
# @ole_obj.Id || @ole_obj.ID64
|
27
|
+
# end
|
28
|
+
# def text?
|
29
|
+
# true
|
30
|
+
# end
|
31
|
+
|
32
|
+
# def text_node?
|
33
|
+
# false
|
34
|
+
# end
|
35
|
+
|
36
|
+
def to_s
|
37
|
+
original.to_s
|
38
|
+
end
|
39
|
+
|
40
|
+
def bounds
|
41
|
+
binding.pry
|
42
|
+
rotation = ole_obj.Rotation
|
43
|
+
inverse_rotation = app_ole_obj.Matrix3dInverse(rotation) rescue pry
|
44
|
+
transform = app_ole_obj.Transform3dFromMatrix3dandFixedPoint3d(app_ole_obj.Matrix3dInverse(rotation), ole_obj.origin)
|
45
|
+
ole_obj.transform transform
|
46
|
+
pts = []
|
47
|
+
|
48
|
+
0.upto(4) do |i|
|
49
|
+
points[i] = ole_obj.Boundary.Low
|
50
|
+
end
|
51
|
+
points[2] = self.Boundary.High
|
52
|
+
points[1].X = points[2].x
|
53
|
+
points[3].y = points[2].Y
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
def method_missing(meth,*args, &block)
|
58
|
+
if meth =~ /^[A-Z]/
|
59
|
+
ole_obj.send(meth,*args)
|
60
|
+
else
|
61
|
+
dup = @original.dup
|
62
|
+
result = dup.send(meth,*args, &block)
|
63
|
+
update(result)
|
64
|
+
result
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# def method_missing(meth,*args,&block)
|
69
|
+
# dup = @original_text.dup
|
70
|
+
# result = dup.send(meth,*args, &block)
|
71
|
+
# _update(dup) unless dup == @original_text
|
72
|
+
# result
|
73
|
+
# end
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|