Class: Archimate::DataModel::ViewNode

Inherits:
Referenceable show all
Defined in:
lib/archimate/data_model/view_node.rb

Overview

Graphical node type. It can contain child node types. TODO: This is ViewNodeType in the v3 XSD

Direct Known Subclasses

Container, Label

Instance Attribute Summary

Attributes inherited from ArchimateNode

#parent_attribute_name, #struct_instance_variables

Instance Method Summary collapse

Methods inherited from ArchimateNode

#ancestors, #build_index, #clone, #compact!, #delete, #diff, #dup, #element_by_id, #id, #in_model, #in_model=, #initialize, #parent, #parent=, #path, #primitive?, #set, #with

Constructor Details

This class inherits a constructor from Archimate::DataModel::ArchimateNode

Instance Method Details

#absolute_positionObject

TODO: Is this true for all or only Archi models?



92
93
94
95
96
97
98
99
100
101
# File 'lib/archimate/data_model/view_node.rb', line 92

def absolute_position
  offset = bounds || Archimate::DataModel::Bounds.zero
  el = parent.parent
  while el.respond_to?(:bounds) && el.bounds
    bounds = el.bounds
    offset = offset.with(x: (offset.x || 0) + (bounds.x || 0), y: (offset.y || 0) + (bounds.y || 0))
    el = el.parent.parent
  end
  offset
end

#all_nodesObject



71
72
73
# File 'lib/archimate/data_model/view_node.rb', line 71

def all_nodes
  nodes.inject(Array.new(nodes)) { |child_ary, child| child_ary.concat(child.all_nodes) }
end

#child_id_hashObject



75
76
77
# File 'lib/archimate/data_model/view_node.rb', line 75

def child_id_hash
  nodes.each_with_object(id => self) { |i, a| a.merge!(i.child_id_hash) }
end

#descriptionObject



55
56
57
58
59
60
61
# File 'lib/archimate/data_model/view_node.rb', line 55

def description
  [
    name.nil? ? nil : name.to_s,
    element.nil? ? nil : element.name,
    element&.type.nil? ? nil : "(#{element.type})"
  ].compact.join(" ")
end

#elementObject



63
64
65
# File 'lib/archimate/data_model/view_node.rb', line 63

def element
  @element ||= in_model.lookup(archimate_element)
end

#in_diagramObject



87
88
89
# File 'lib/archimate/data_model/view_node.rb', line 87

def in_diagram
  @diagram ||= ->(node) { node = node.parent until node.nil? || node.is_a?(Diagram) }.call(self)
end

#model_elementObject



67
68
69
# File 'lib/archimate/data_model/view_node.rb', line 67

def model_element
  @model_element ||= in_model.lookup(model)
end

#referenced_identified_nodesObject



79
80
81
82
83
84
85
# File 'lib/archimate/data_model/view_node.rb', line 79

def referenced_identified_nodes
  (nodes + connections).reduce(
    (target_connections + [archimate_element]).compact
  ) do |a, e|
    a.concat(e.referenced_identified_nodes)
  end
end

#replace(entity, with_entity) ⇒ Object

it’s added under Real Element



40
41
42
43
44
45
46
47
48
49
# File 'lib/archimate/data_model/view_node.rb', line 40

def replace(entity, with_entity)
  if (archimate_element == entity.id)
    @archimate_element = with_entity.id
    @element = with_entity
  end
  if (model == entity.id)
    @model = with_entity.id
    @model_element = with_entity
  end
end

#to_sObject



51
52
53
# File 'lib/archimate/data_model/view_node.rb', line 51

def to_s
  "ViewNode[#{name || ''}](#{in_model.lookup(archimate_element) if archimate_element && in_model})"
end