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
69
70
71
|
# File 'lib/microstation/model_trait.rb', line 69
def activate
ole_obj.Activate
end
|
#active? ⇒ Boolean
22
23
24
|
# File 'lib/microstation/model_trait.rb', line 22
def active?
ole_obj.IsActive
end
|
#add_element(el) ⇒ Object
82
83
84
85
86
87
88
|
# File 'lib/microstation/model_trait.rb', line 82
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
49
50
51
52
53
54
55
|
# File 'lib/microstation/model_trait.rb', line 49
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
16
17
18
19
20
|
# File 'lib/microstation/model_trait.rb', line 16
def find_by_id(id)
ele = ole_obj.GetElementById64(id) rescue nil
return nil unless ele
app.ole_to_ruby(ele)
end
|
#get_matching_text(re) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/microstation/model_trait.rb', line 34
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
26
27
28
|
# File 'lib/microstation/model_trait.rb', line 26
def get_selected_elements
Enumerator.new(ole_obj.GetSelectedElements,app)
end
|
#get_selected_text ⇒ Object
30
31
32
|
# File 'lib/microstation/model_trait.rb', line 30
def get_selected_text
get_selected_elements.select{|t| t.textual?}
end
|
125
126
127
128
|
# File 'lib/microstation/model_trait.rb', line 125
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
|
130
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 130
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
73
74
75
|
# File 'lib/microstation/model_trait.rb', line 73
def locked?
ole_obj.IsLocked?
end
|
#name ⇒ Object
12
13
14
|
# File 'lib/microstation/model_trait.rb', line 12
def name
ole_obj.name
end
|
#readonly? ⇒ Boolean
65
66
67
|
# File 'lib/microstation/model_trait.rb', line 65
def readonly?
ole_obj.IsReadOnly
end
|
#scan_model(criteria = nil) { ... } ⇒ Object
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
# File 'lib/microstation/model_trait.rb', line 157
def scan_model(criteria=nil)
criteria = 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
|
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/microstation/model_trait.rb', line 94
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
61
62
63
|
# File 'lib/microstation/model_trait.rb', line 61
def select_element(el)
ole_obj.SelectElement(el.ole_obj)
end
|
90
91
92
|
# File 'lib/microstation/model_trait.rb', line 90
def select_tagset_instances
end
|
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/microstation/model_trait.rb', line 108
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
77
78
79
|
# File 'lib/microstation/model_trait.rb', line 77
def to_s
"Microstation::Model-#{name}"
end
|
#unselect_element(el) ⇒ Object
57
58
59
|
# File 'lib/microstation/model_trait.rb', line 57
def unselect_element(el)
ole_obj.UnselectElement(el.ole_obj)
end
|