Class: Microstation::Element

Inherits:
Object
  • Object
show all
Includes:
ElementTrait
Defined in:
lib/microstation/element.rb

Direct Known Subclasses

Arc, BSplineCurve, BSplineSurface, Cell, Ellipse, Line, Tag, Text, TextNode

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ElementTrait

#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.



137
138
139
140
141
142
# File 'lib/microstation/element.rb', line 137

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



154
155
156
157
158
159
160
161
# File 'lib/microstation/element.rb', line 154

def method_missing(meth, *args, &block)
  if /^[A-Z]/.match?(meth.to_s)
    result = ole_obj.send(meth, *args, &block)
    Element.convert_item(result, app)
  else
    super(meth, *args, &block)
  end
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



135
136
137
# File 'lib/microstation/element.rb', line 135

def app
  @app
end

#ole_objObject (readonly)

Returns the value of attribute ole_obj.



135
136
137
# File 'lib/microstation/element.rb', line 135

def ole_obj
  @ole_obj
end

#originalObject (readonly)

Returns the value of attribute original.



135
136
137
# File 'lib/microstation/element.rb', line 135

def original
  @original
end

Class Method Details

.convert_item(ole, app, cell = nil) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/microstation/element.rb', line 100

def self.convert_item(ole, app, cell = nil)
  return Point3d.from_ole(ole) if ole.instance_of?(WIN32OLE_RECORD) && ole.typename == "Point3d"
  return ole unless ole.instance_of?(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

Returns:

  • (Boolean)


131
132
133
# File 'lib/microstation/element.rb', line 131

def self.ole_object?
  ole.instance_of?(WIN32OLE)
end

Instance Method Details

#[](name) ⇒ Object



172
173
174
# File 'lib/microstation/element.rb', line 172

def [](name)
  property_handler[name]
end

#app_ole_objObject



215
216
217
# File 'lib/microstation/element.rb', line 215

def app_ole_obj
  app.ole_obj
end

#do_update(value) ⇒ Object



176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/microstation/element.rb', line 176

def do_update(value)
  return false if value == original

  saved_original = original
  begin
    write_ole(value)
    @original = read_ole(ole_obj)
    true
  rescue => e
    @original = saved_original
    false
  end
end

#each(ole = ole_obj, &block) ⇒ Object



244
245
246
247
248
249
250
251
252
253
# File 'lib/microstation/element.rb', line 244

def each(ole = ole_obj, &block)
  return unless ole.IsComplexElement
  return to_enum(:each) unless block

  if ole.IsCellElement
    each_cell(ole, &block)
  else
    each_complex(ole, &block)
  end
end

#each_cell(ole, &block) ⇒ Object



223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/microstation/element.rb', line 223

def each_cell(ole, &block)
  cell = ole if ole_cell(ole)
  begin
    ole.ResetElementEnumeration
  rescue
    binding.pry
  end
  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



255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/microstation/element.rb', line 255

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_handlerObject



163
164
165
166
# File 'lib/microstation/element.rb', line 163

def get_property_handler
  ph_ole = app_ole_obj.CreatePropertyHandler(ole_obj)
  PropertyHandler.new(ph_ole)
end

#in_cell?Boolean

Returns:

  • (Boolean)


144
145
146
# File 'lib/microstation/element.rb', line 144

def in_cell?
  !!@cell
end

#ole_cell(ole) ⇒ Object



219
220
221
# File 'lib/microstation/element.rb', line 219

def ole_cell(ole)
  ole.IsCellElement || ole.IsSharedCellElement
end

#property_handlerObject



168
169
170
# File 'lib/microstation/element.rb', line 168

def property_handler
  @property_handler ||= get_property_handler
end

#read_ole(ole) ⇒ Object



148
149
# File 'lib/microstation/element.rb', line 148

def read_ole(ole)
end

#redraw(el = ole_obj) ⇒ Object



210
211
212
213
# File 'lib/microstation/element.rb', line 210

def redraw(el = ole_obj)
  el.Redraw ::Microstation::MSD::MsdDrawingModeNormal
  el.Rewrite
end

#update(value) ⇒ Object



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/microstation/element.rb', line 190

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

Returns:

  • (Boolean)


206
207
208
# File 'lib/microstation/element.rb', line 206

def updated?
  @updated
end

#write_ole(value) ⇒ Object



151
152
# File 'lib/microstation/element.rb', line 151

def write_ole(value)
end