Class: Ea::Sources::Xmi::DiagramBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/ea/sources/xmi/diagram_builder.rb

Overview

Translates EA diagrams from the XMI source into Ea::Model instances. Uses the rich placement data inside the xmi:Extension block (Left/Top/Right/Bottom, BCol, font, SOID/EOID, EDGE, label boxes) when present. Falls back to the UML-DI owned_element bounds otherwise.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ DiagramBuilder

Returns a new instance of DiagramBuilder.



14
15
16
# File 'lib/ea/sources/xmi/diagram_builder.rb', line 14

def initialize(root)
  @root = root
end

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



12
13
14
# File 'lib/ea/sources/xmi/diagram_builder.rb', line 12

def root
  @root
end

Instance Method Details

#build_allObject



18
19
20
21
22
23
# File 'lib/ea/sources/xmi/diagram_builder.rb', line 18

def build_all
  ext_diagrams = extension_diagrams
  return [] if ext_diagrams.empty?

  ext_diagrams.map { |d| build_one(d) }
end

#build_one(ext_diagram) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ea/sources/xmi/diagram_builder.rb', line 39

def build_one(ext_diagram)
  id = IdNormalizer.from_xmi_id(ext_diagram.id)
  ext_elements = ExtensionElements.new(ext_diagram)
  placed_elements = ext_elements.placed_elements
  placed_connectors = ext_elements.placed_connectors
  props = ext_diagram.properties

  Ea::Model::Diagram.new(
    id: id,
    name: props&.name || ext_diagram.id,
    package_id: ext_diagram.model&.package,
    diagram_type: props&.type&.split(":")&.last&.downcase,
    bounds: canvas_bounds(placed_elements),
    elements: build_elements(placed_elements, id),
    connectors: build_connectors(placed_connectors,
                                  placed_elements, id),
    annotations: []
  )
end

#extension_diagramsObject

The XMI stores diagrams in two places:

  • root.model.diagram — UML-DI shape (often just one or none)
  • root.extension.diagrams.diagram — the rich EA extension block with placement/style/connector data (the source of truth for rendering). We use the extension block when present; fall back to UML-DI otherwise.


32
33
34
35
36
37
# File 'lib/ea/sources/xmi/diagram_builder.rb', line 32

def extension_diagrams
  ext = root.extension
  return [] unless ext&.diagrams

  ext.diagrams.diagram.to_a
end