Module: Microstation::ModelTrait
Instance Method Summary
collapse
Methods included from ScanTrait
#cells_criteria, #create_scanner, #graphics_criteria, #lines_criteria, #scan, #scan_cell_with_name, #scan_cells, #scan_graphical, #scan_lines, #scan_tags, #scan_text, #tags_criteria, #text_criteria
Methods included from Graphics
#line, #line_from_pts
Instance Method Details
#activate ⇒ Object
72
73
74
|
# File 'lib/microstation/model_trait.rb', line 72
def activate
ole_obj.Activate
end
|
#active? ⇒ Boolean
25
26
27
|
# File 'lib/microstation/model_trait.rb', line 25
def active?
ole_obj.IsActive
end
|
#add_element(el) ⇒ Object
84
85
86
87
88
89
90
|
# File 'lib/microstation/model_trait.rb', line 84
def add_element(el)
if el.respond_to? :ole_obj
el = el.ole_obj
ole_obj.AddElement(el)
self
end
end
|
#change_text_suffix(reg, offset) ⇒ Object
52
53
54
55
56
57
58
|
# File 'lib/microstation/model_trait.rb', line 52
def change_text_suffix(reg, offset)
get_matching_text(reg) do |t, md|
pre = md[1]
suff = Integer(md[2]) + offset
t.replace "#{pre}#{suff}"
end
end
|
#find_by_id(id) ⇒ Object
15
16
17
18
19
20
21
22
23
|
# File 'lib/microstation/model_trait.rb', line 15
def find_by_id(id)
ele = begin
ole_obj.GetElementById64(id)
rescue
nil
end
return nil unless ele
app.ole_to_ruby(ele)
end
|
#get_matching_text(re) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/microstation/model_trait.rb', line 37
def get_matching_text(re)
result = []
get_selected_text.each do |t|
md = re.match(t)
if md
if block_given?
yield t, md
else
result << t
end
end
result
end
end
|
#get_selected_elements ⇒ Object
29
30
31
|
# File 'lib/microstation/model_trait.rb', line 29
def get_selected_elements
Enumerator.new(ole_obj.GetSelectedElements, app)
end
|
#get_selected_text ⇒ Object
33
34
35
|
# File 'lib/microstation/model_trait.rb', line 33
def get_selected_text
get_selected_elements.select { |t| t.textual? }
end
|
126
127
128
129
|
# File 'lib/microstation/model_trait.rb', line 126
def get_tagsets_in_model_hash(ts_name: nil, base_element_id: nil, &block)
tags = scan_tags_filtered(ts_name: ts_name, base_element_id: base_element_id)
tags_to_hash(tags, &block)
end
|
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
# File 'lib/microstation/model_trait.rb', line 131
def get_tagsets_in_model_hash_old
results = []
tsets = scan_tags.group_by { |t| t.tagset_name }
tsets.each do |tsname, tags|
elements = tags.group_by { |t| t.base_element_id }
elements.each do |id, tag_elts|
result_hash = {
name: tsname,
model: name,
tags: tag_elts,
base_element_id: id
}
if block_given?
yield result_hash
else
results << result_hash
end
end
results unless block_given?
end
end
|
#locked? ⇒ Boolean
76
77
78
|
# File 'lib/microstation/model_trait.rb', line 76
def locked?
ole_obj.IsLocked?
end
|
#name ⇒ Object
11
12
13
|
# File 'lib/microstation/model_trait.rb', line 11
def name
ole_obj.name
end
|
#readonly? ⇒ Boolean
68
69
70
|
# File 'lib/microstation/model_trait.rb', line 68
def readonly?
ole_obj.IsReadOnly
end
|
#scan_model(criteria = nil) { ... } ⇒ Object
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
# File 'lib/microstation/model_trait.rb', line 156
def scan_model(criteria = nil)
criteria ||= create_scanner(:nullscanner)
scan_result = ole_run_scan(criteria)
return [] unless scan_result
scan_enum = ::Microstation::Enumerator.new(scan_result, app)
result = []
if block_given?
scan_enum.each do |item|
yield item
end
else
scan_enum.each do |item|
result << item
end
end
return result unless block_given?
end
|
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/microstation/model_trait.rb', line 95
def scan_tags_filtered(ts_name: nil, base_element_id: nil, &block)
case [ts_name, base_element_id]
in [nil, nil]
scan_tags(&block)
in [String, nil]
scan_tags.select { |t| t.tagset_name == ts_name }
in [String, Numeric]
scan_tags.select { |t| t.tagset_name == ts_name && t.base_element_id == base_element_id }
in [nil, Numeric]
scan_tags.select { |t| t.base_element_id == base_element_id }
end
end
|
#select_element(el) ⇒ Object
64
65
66
|
# File 'lib/microstation/model_trait.rb', line 64
def select_element(el)
ole_obj.SelectElement(el.ole_obj)
end
|
92
93
|
# File 'lib/microstation/model_trait.rb', line 92
def select_tagset_instances
end
|
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/microstation/model_trait.rb', line 109
def tags_to_hash(tags)
return to_enum(__callee__, tags) unless block_given?
tsets = tags.group_by { |t| t.tagset_name }
tsets.each do |tsname, tags|
elements = tags.group_by { |t| t.base_element_id }
elements.each do |id, tag_elts|
result_hash = {
name: tsname,
model: name,
tags: tag_elts,
base_element_id: id
}
yield result_hash
end
end
end
|
#to_s ⇒ Object
80
81
82
|
# File 'lib/microstation/model_trait.rb', line 80
def to_s
"Microstation::Model-#{name}"
end
|
#unselect_element(el) ⇒ Object
60
61
62
|
# File 'lib/microstation/model_trait.rb', line 60
def unselect_element(el)
ole_obj.UnselectElement(el.ole_obj)
end
|