Class: Microstation::Element
- Inherits:
-
Object
- Object
- Microstation::Element
show all
- Includes:
- ElementTrait
- Defined in:
- lib/microstation/element.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#cell?, #complex?, #graphical?, #has_tags?, #id_from_record, #line?, #microstation_id, #microstation_type, #model, #parent, #select, #text?, #text_node?, #textual?, #to_ole
Constructor Details
#initialize(ole, app, cell = nil) ⇒ Element
Returns a new instance of Element.
144
145
146
147
148
149
|
# File 'lib/microstation/element.rb', line 144
def initialize(ole,app, cell = nil)
@ole_obj = ole
@original = read_ole(ole)
@app = app
@cell = cell
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
163
164
165
166
167
168
169
170
|
# File 'lib/microstation/element.rb', line 163
def method_missing(meth,*args,&block)
if meth.to_s =~ /^[A-Z]/
result = ole_obj.send(meth,*args,&block)
Element.convert_item(result,app)
else
super(meth,*args,&block)
end
end
|
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
142
143
144
|
# File 'lib/microstation/element.rb', line 142
def app
@app
end
|
#ole_obj ⇒ Object
Returns the value of attribute ole_obj.
142
143
144
|
# File 'lib/microstation/element.rb', line 142
def ole_obj
@ole_obj
end
|
#original ⇒ Object
Returns the value of attribute original.
142
143
144
|
# File 'lib/microstation/element.rb', line 142
def original
@original
end
|
Class Method Details
.convert_item(ole, app, cell = nil) ⇒ Object
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
# File 'lib/microstation/element.rb', line 107
def self.convert_item(ole,app, cell=nil)
return Point3d.from_ole(ole) if ole.class == WIN32OLE_RECORD && ole.typename == 'Point3d'
return ole unless ole.class == WIN32OLE
case ole.Type
when ::Microstation::MSD::MsdElementTypeText
::Microstation::Text.new(ole,app,cell)
when ::Microstation::MSD::MsdElementTypeLine
::Microstation::Line.new(ole,app,cell)
when ::Microstation::MSD::MsdElementTypeTextNode
::Microstation::TextNode.new(ole,app,cell)
when ::Microstation::MSD::MsdElementTypeTag
::Microstation::Tag.new(ole,app,cell)
when ::Microstation::MSD::MsdElementTypeCellHeader
::Microstation::Cell.new(ole,app,cell)
when ::Microstation::MSD::MsdElementTypeSharedCell
::Microstation::Cell.new(ole,app,cell)
when ::Microstation::MSD::MsdElementTypeArc
::Microstation::Arc.new(ole,app,cell)
when ::Microstation::MSD::MsdElementTypeEllipse
::Microstation::Ellipse.new(ole,app,cell)
when ::Microstation::MSD::MsdElementTypeBsplineSurface
::Microstation::BSplineSurface.new(ole,app,cell)
when ::Microstation::MSD::MsdElementTypeBsplineCurve
::Microstation::BSplineCurve.new(ole,app,cell)
else
new(ole,app,cell)
end
end
|
.ole_object? ⇒ Boolean
137
138
139
|
# File 'lib/microstation/element.rb', line 137
def self.ole_object?
ole.class == WIN32OLE
end
|
Instance Method Details
#[](name) ⇒ Object
182
183
184
|
# File 'lib/microstation/element.rb', line 182
def [](name)
property_handler[name]
end
|
#app_ole_obj ⇒ Object
226
227
228
|
# File 'lib/microstation/element.rb', line 226
def app_ole_obj
app.ole_obj
end
|
#do_update(value) ⇒ Object
187
188
189
190
191
192
193
194
195
196
197
198
199
|
# File 'lib/microstation/element.rb', line 187
def do_update(value)
return false if value == original
saved_original = original
begin
write_ole(value)
@original = read_ole(ole_obj)
return true
rescue => e
@original = saved_original
false
end
end
|
#each(ole = ole_obj, &block) ⇒ Object
251
252
253
254
255
256
257
258
259
|
# File 'lib/microstation/element.rb', line 251
def each(ole = ole_obj,&block)
return unless ole.IsComplexElement
return to_enum(:each) unless block_given?
if ole.IsCellElement
each_cell(ole,&block)
else
each_complex(ole,&block)
end
end
|
#each_cell(ole, &block) ⇒ Object
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
|
# File 'lib/microstation/element.rb', line 234
def each_cell(ole,&block)
cell = ole if ole_cell(ole)
ole.ResetElementEnumeration rescue binding.pry
while ole.MoveToNextElement
component = ole.CopyCurrentElement
if component.IsTextNodeElement
yield Microstation::Wrap.wrap(component.AsTextNodeElement,app,cell)
elsif component.IsTextElement
yield Microstation::Wrap.wrap(component.AsTextElement,app,cell)
elsif component.IsComplexElement
each(component)
else
yield Microstation::Wrap.wrap(component,app,cell)
end
end
end
|
#each_complex(ole, &block) ⇒ Object
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
# File 'lib/microstation/element.rb', line 261
def each_complex(ole,&block)
cell = nil
components = ole.GetSubElements
while components.MoveNext
component = components.Current
if component.IsTextNodeElement
yield Microstation::Wrap.wrap(component.AsTextNodeElement,app,cell)
elsif component.IsTextElement
yield Microstation::Wrap.wrap(component.AsTextElement,app,cell)
elsif component.IsComplexElement
each(component,&block)
else
yield Microstation::Wrap.wrap(component,app,cell)
end
end
end
|
#get_property_handler ⇒ Object
173
174
175
176
|
# File 'lib/microstation/element.rb', line 173
def get_property_handler
ph_ole = app_ole_obj.CreatePropertyHandler(ole_obj)
PropertyHandler.new(ph_ole)
end
|
#in_cell? ⇒ Boolean
151
152
153
|
# File 'lib/microstation/element.rb', line 151
def in_cell?
!!@cell
end
|
#ole_cell(ole) ⇒ Object
230
231
232
|
# File 'lib/microstation/element.rb', line 230
def ole_cell(ole)
ole.IsCellElement || ole.IsSharedCellElement
end
|
#property_handler ⇒ Object
178
179
180
|
# File 'lib/microstation/element.rb', line 178
def property_handler
@property_handler ||= get_property_handler
end
|
#read_ole(ole) ⇒ Object
155
156
157
|
# File 'lib/microstation/element.rb', line 155
def read_ole(ole)
end
|
#redraw(el = ole_obj) ⇒ Object
221
222
223
224
|
# File 'lib/microstation/element.rb', line 221
def redraw(el = ole_obj)
el.Redraw ::Microstation::MSD::MsdDrawingModeNormal
el.Rewrite
end
|
#update(value) ⇒ Object
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
# File 'lib/microstation/element.rb', line 201
def update(value)
redraw_el = ole_obj
if do_update(value)
if in_cell?
@cell.ReplaceCurrentElement @ole_obj
redraw_el = @cell
end
redraw(redraw_el)
@updated = true
true
else
@updated = false
false
end
end
|
#updated? ⇒ Boolean
217
218
219
|
# File 'lib/microstation/element.rb', line 217
def updated?
@updated
end
|
#write_ole(value) ⇒ Object
159
160
161
|
# File 'lib/microstation/element.rb', line 159
def write_ole(value)
end
|