Class: Ea::Sources::Qea::DiagramBuilder

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

Overview

Translates EA t_diagram + t_diagramlinks + t_diagramobjects into Ea::Model::Diagram with placed DiagramElements and DiagramConnectors (including pixel coordinates and parsed styles).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(database) ⇒ DiagramBuilder

Returns a new instance of DiagramBuilder.



13
14
15
# File 'lib/ea/sources/qea/diagram_builder.rb', line 13

def initialize(database)
  @database = database
end

Instance Attribute Details

#databaseObject (readonly)

Returns the value of attribute database.



11
12
13
# File 'lib/ea/sources/qea/diagram_builder.rb', line 11

def database
  @database
end

Instance Method Details

#build_allObject



17
18
19
20
# File 'lib/ea/sources/qea/diagram_builder.rb', line 17

def build_all
  diagrams = database.collections[:diagrams] || []
  diagrams.map { |row| build_one(row) }
end

#build_one(diagram_row) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ea/sources/qea/diagram_builder.rb', line 22

def build_one(diagram_row)
  Ea::Model::Diagram.new(
    id: IdNormalizer.from_guid(diagram_row.ea_guid),
    name: diagram_row.name,
    package_id: package_id_for(diagram_row),
    diagram_type: diagram_row.diagram_type,
    bounds: bounds_for(diagram_row),
    style: diagram_row.pdata,
    style_ex: diagram_row.styleex,
    show_package_contents: package_contents_enabled?(diagram_row),
    hand_draw: hand_draw_enabled?(diagram_row),
    show_notes: show_notes_enabled?(diagram_row),
    show_parents: show_parents_enabled?(diagram_row),
    elements: build_elements(diagram_row),
    connectors: build_connectors(diagram_row),
    annotations: AnnotationBuilder.from_note(diagram_row.notes,
                                             diagram_row.ea_guid,
                                             kind: "documentation")
  )
end

#hand_draw_enabled?(diagram_row) ⇒ Boolean

HandDraw=1 in t_diagram.StyleEx triggers EA's wavy hand-drawn border style for every element on the diagram.

Returns:

  • (Boolean)


55
56
57
58
59
# File 'lib/ea/sources/qea/diagram_builder.rb', line 55

def hand_draw_enabled?(diagram_row)
  style_ex = diagram_row.styleex.to_s
  match = style_ex.match(/HandDraw=(\d)/)
  match && match[1] == "1"
end

#package_contents_enabled?(diagram_row) ⇒ Boolean

EA encodes "show package contents" as a non-zero integer in t_diagram.ShowPackageContents (1 in basic.qea, 255 in test.qea). When true, the package body lists its child classifiers/sub-packages as "+ Name" rows.

Returns:

  • (Boolean)


47
48
49
50
51
# File 'lib/ea/sources/qea/diagram_builder.rb', line 47

def package_contents_enabled?(diagram_row)
  return false if diagram_row.showpackagecontents.nil?

  diagram_row.showpackagecontents.to_i.nonzero?
end

#show_notes_enabled?(diagram_row) ⇒ Boolean

ShowNotes=1 in t_diagram.StyleEx renders the classifier's documentation note as wrapped text in the element body.

Returns:

  • (Boolean)


63
64
65
66
67
# File 'lib/ea/sources/qea/diagram_builder.rb', line 63

def show_notes_enabled?(diagram_row)
  style_ex = diagram_row.styleex.to_s
  match = style_ex.match(/ShowNotes=(\d)/)
  match && match[1] == "1"
end

#show_parents_enabled?(diagram_row) ⇒ Boolean

HideParents=1 in t_diagram.PDATA suppresses EA's "off-canvas parent class" ghost line — the italic parent name that EA normally prepends to a placed element's header when its generalization parent is not placed on the diagram.

Returns:

  • (Boolean)


73
74
75
76
77
# File 'lib/ea/sources/qea/diagram_builder.rb', line 73

def show_parents_enabled?(diagram_row)
  pdata = diagram_row.pdata.to_s
  match = pdata.match(/HideParents=(\d)/)
  match ? match[1] != "1" : true
end