archimate 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +1 -1
  3. data/Gemfile +1 -0
  4. data/README.md +10 -55
  5. data/Rakefile +19 -1
  6. data/archimate.gemspec +16 -14
  7. data/bin/archimate +12 -0
  8. data/lib/archimate/cli/archi.rb +38 -19
  9. data/lib/archimate/cli/cleanup.rb +41 -25
  10. data/lib/archimate/cli/duper.rb +0 -1
  11. data/lib/archimate/cli/mapper.rb +53 -40
  12. data/lib/archimate/cli/svger.rb +33 -4
  13. data/lib/archimate/core_refinements.rb +41 -0
  14. data/lib/archimate/data_model/bounds.rb +14 -4
  15. data/lib/archimate/data_model/comparison.rb +3 -27
  16. data/lib/archimate/data_model/connection.rb +26 -11
  17. data/lib/archimate/data_model/diagram.rb +17 -10
  18. data/lib/archimate/data_model/element.rb +21 -9
  19. data/lib/archimate/data_model/elements.rb +24 -18
  20. data/lib/archimate/data_model/lang_string.rb +34 -10
  21. data/lib/archimate/data_model/layer.rb +6 -0
  22. data/lib/archimate/data_model/location.rb +10 -13
  23. data/lib/archimate/data_model/model.rb +55 -43
  24. data/lib/archimate/data_model/organization.rb +21 -5
  25. data/lib/archimate/data_model/property.rb +0 -6
  26. data/lib/archimate/data_model/referenceable.rb +29 -3
  27. data/lib/archimate/data_model/referenceable_list.rb +34 -14
  28. data/lib/archimate/data_model/relationship.rb +29 -8
  29. data/lib/archimate/data_model/relationship_references.rb +115 -6
  30. data/lib/archimate/data_model/relationships.rb +15 -0
  31. data/lib/archimate/data_model/view_node.rb +20 -13
  32. data/lib/archimate/data_model/viewpoint.rb +13 -1
  33. data/lib/archimate/data_model/viewpoints.rb +416 -0
  34. data/lib/archimate/data_model.rb +7 -1
  35. data/lib/archimate/derived_relations.rb +2 -11
  36. data/lib/archimate/export/cypher.rb +6 -5
  37. data/lib/archimate/file_format.rb +1 -0
  38. data/lib/archimate/file_formats/archi_file_reader.rb +11 -1
  39. data/lib/archimate/file_formats/archi_file_writer.rb +15 -46
  40. data/lib/archimate/file_formats/archi_file_writer_4.rb +14 -0
  41. data/lib/archimate/file_formats/model_exchange_file_reader.rb +2 -1
  42. data/lib/archimate/file_formats/model_exchange_file_writer_21.rb +1 -0
  43. data/lib/archimate/file_formats/sax/archi/diagram.rb +53 -13
  44. data/lib/archimate/file_formats/sax/archi/location.rb +1 -3
  45. data/lib/archimate/file_formats/sax/model_exchange_file/diagram.rb +13 -2
  46. data/lib/archimate/file_formats/sax.rb +1 -0
  47. data/lib/archimate/file_formats/serializer/archi/archi_file_writer.rb +63 -0
  48. data/lib/archimate/file_formats/serializer/archi/archi_file_writer_3.rb +18 -0
  49. data/lib/archimate/file_formats/serializer/archi/archi_file_writer_4.rb +18 -0
  50. data/lib/archimate/file_formats/serializer/archi/bounds.rb +2 -2
  51. data/lib/archimate/file_formats/serializer/archi/connection.rb +24 -13
  52. data/lib/archimate/file_formats/serializer/archi/diagram.rb +3 -3
  53. data/lib/archimate/file_formats/serializer/archi/element.rb +2 -2
  54. data/lib/archimate/file_formats/serializer/archi/organization.rb +1 -1
  55. data/lib/archimate/file_formats/serializer/archi/property.rb +1 -1
  56. data/lib/archimate/file_formats/serializer/archi/relationship.rb +2 -2
  57. data/lib/archimate/file_formats/serializer/archi/view_node.rb +20 -22
  58. data/lib/archimate/file_formats/serializer/archi/viewpoint3.rb +43 -0
  59. data/lib/archimate/file_formats/serializer/archi/viewpoint4.rb +41 -0
  60. data/lib/archimate/file_formats/serializer/model_exchange_file/style.rb +3 -7
  61. data/lib/archimate/file_formats/serializer/model_exchange_file/v21/diagram.rb +3 -3
  62. data/lib/archimate/file_formats/serializer/model_exchange_file/v21/model.rb +9 -2
  63. data/lib/archimate/file_formats/serializer/model_exchange_file/v21/view_node.rb +1 -1
  64. data/lib/archimate/file_formats/serializer/model_exchange_file/v21/viewpoint.rb +23 -0
  65. data/lib/archimate/file_formats/serializer/model_exchange_file/v30/diagram.rb +3 -3
  66. data/lib/archimate/file_formats/serializer/model_exchange_file/v30/model.rb +5 -7
  67. data/lib/archimate/file_formats/serializer/model_exchange_file/v30/view_node.rb +3 -3
  68. data/lib/archimate/file_formats/serializer/writer.rb +0 -5
  69. data/lib/archimate/file_formats/serializer.rb +6 -2
  70. data/lib/archimate/lint/duplicate_entities.rb +5 -5
  71. data/lib/archimate/lint/linter.rb +4 -4
  72. data/lib/archimate/maybe_io.rb +3 -2
  73. data/lib/archimate/svg/archimate.css +19 -21
  74. data/lib/archimate/svg/connection.rb +1 -1
  75. data/lib/archimate/svg/diagram.rb +1 -6
  76. data/lib/archimate/svg/entity/application_component.rb +9 -3
  77. data/lib/archimate/svg/entity/constraint.rb +0 -1
  78. data/lib/archimate/svg/entity/contract.rb +9 -0
  79. data/lib/archimate/svg/entity/data_entity.rb +1 -1
  80. data/lib/archimate/svg/entity/device.rb +1 -1
  81. data/lib/archimate/svg/entity/event_entity.rb +24 -7
  82. data/lib/archimate/svg/entity/group.rb +23 -4
  83. data/lib/archimate/svg/entity/grouping.rb +37 -0
  84. data/lib/archimate/svg/entity/interface_entity.rb +1 -1
  85. data/lib/archimate/svg/entity/node.rb +1 -1
  86. data/lib/archimate/svg/entity/outcome.rb +0 -1
  87. data/lib/archimate/svg/entity/principle.rb +0 -1
  88. data/lib/archimate/svg/entity/process_entity.rb +1 -1
  89. data/lib/archimate/svg/entity/requirement.rb +0 -1
  90. data/lib/archimate/svg/entity/service_entity.rb +6 -13
  91. data/lib/archimate/svg/entity.rb +1 -0
  92. data/lib/archimate/svg/entity_factory.rb +9 -5
  93. data/lib/archimate/svg/path.rb +57 -46
  94. data/lib/archimate/svg/point.rb +4 -0
  95. data/lib/archimate/svg/segment.rb +30 -0
  96. data/lib/archimate/svg/svg_template.svg.erb +11 -3
  97. data/lib/archimate/svg/view_node.rb +22 -0
  98. data/lib/archimate/version.rb +1 -1
  99. data/lib/archimate.rb +3 -2
  100. metadata +54 -54
  101. data/exe/archidiff +0 -7
  102. data/exe/archidiff-summary +0 -7
  103. data/exe/archimerge +0 -7
  104. data/exe/fmtxml +0 -7
  105. data/lib/archimate/data_model/viewpoint_type.rb +0 -389
  106. data/lib/archimate/file_formats/serializer/archi/location.rb +0 -26
  107. data/lib/archimate/file_formats/serializer/archi/viewpoint_type.rb +0 -45
  108. data/lib/archimate/svg/child.rb +0 -29
@@ -1,8 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ using Archimate::CoreRefinements
4
+
3
5
  module Archimate
4
6
  module Svg
5
7
  class Path
8
+ LINE_CURVE_RADIUS = 5
9
+
6
10
  attr_reader :connection
7
11
 
8
12
  def initialize(connection)
@@ -23,28 +27,42 @@ module Archimate
23
27
  # @return Point at the given percent along line between start and end
24
28
  def point(fraction)
25
29
  length_from_start = length * fraction
26
- segments.each do |a, b|
27
- seg_length = b - a
28
- if seg_length >= length_from_start
29
- pct = length_from_start / seg_length
30
- return Point.new(
31
- a.x + ((b.x - a.x) * pct),
32
- a.y + ((b.y - a.y) * pct)
33
- )
34
- else
35
- length_from_start -= seg_length
36
- end
30
+ segments.each do |segment|
31
+ return segment.from_start(length_from_start) if segment.length >= length_from_start
32
+ length_from_start -= segment.length
37
33
  end
38
34
  Point.new(0.0, 0.0)
39
35
  end
40
36
 
41
- # builds the line coordinates for the path
42
- # rough drawing is the point at center of first element, point of each bendpoint, and center of end element
43
- # First naive implementation
44
- # if left/right range of both overlap, use centerpoint of overlap range as x val
45
- # if top/bottom range of both overlap, use centerpoint of overlap range as y val
37
+ # New implementation of SVG d method for a set of points
38
+ # making smooth curves at each bendpoint
39
+ #
40
+ # Given three points: a, b, c
41
+ # The result should be:
42
+ # (a is already part of the path -> first point is a move_to command)
43
+ # line_to(segment(a-b) - curve_radius (from end))
44
+ # q_curve(b, segment(b-c) - curve_radius (from start))
45
+ #
46
+ # For cases with more bendpoints (with values d, e, ...)
47
+ # repeat the above section with c as the new a value (so then [c, d, e], [d, e, f], etc.)
46
48
  def d
47
- [move_to(points.first)].concat(points[1..-1].map { |pt| line_to(pt) }).join(" ")
49
+ [move_to(points.first)]
50
+ .concat(
51
+ points
52
+ .each_cons(3)
53
+ .flat_map { |a, b, c| curve_segment(a, b, c) }
54
+ )
55
+ .concat([line_to(points.last)])
56
+ .join(" ")
57
+ end
58
+
59
+ def curve_segment(a, b, c)
60
+ pt1 = Segment.new(a, b).from_end(LINE_CURVE_RADIUS)
61
+ pt2 = Segment.new(b, c).from_start(LINE_CURVE_RADIUS)
62
+ [
63
+ line_to(pt1),
64
+ q_curve(b, pt2)
65
+ ]
48
66
  end
49
67
 
50
68
  def points
@@ -52,37 +70,29 @@ module Archimate
52
70
  end
53
71
 
54
72
  def segments
55
- (0..points.length - 2).map { |i| [points[i], points[i + 1]] }
73
+ (0..points.length - 2).map { |i| Segment.new(points[i], points[i + 1]) }
56
74
  end
57
75
 
58
76
  # Returns the lengths of each segment of the line
59
77
  def segment_lengths
60
- segments.map { |a, b| b - a }
78
+ segments.map(&:length)
61
79
  end
62
80
 
63
81
  private
64
82
 
65
83
  def source_bounds
66
- @source_bounds ||= connection.source&.absolute_position || DataModel::Bounds.zero
84
+ @source_bounds ||= connection.source_bounds || DataModel::Bounds.zero
67
85
  end
68
86
 
69
87
  def target_bounds
70
- @target_bounds ||= connection.target&.absolute_position || DataModel::Bounds.zero
88
+ @target_bounds ||= connection.target_bounds || DataModel::Bounds.zero
71
89
  end
72
90
 
73
91
  def normalized_bend_points
74
- source_bounds_center = source_bounds.center
75
- bp_bounds = connection.bendpoints.map do |bp|
76
- DataModel::Bounds.new(
77
- x: source_bounds_center.x + (bp.x || 0),
78
- y: source_bounds_center.y + (bp.y || 0),
79
- width: 0,
80
- height: 0
81
- )
82
- end
83
- bp_bounds.reject do |bounds|
84
- bounds.inside?(source_bounds) || bounds.inside?(target_bounds)
85
- end
92
+ connection
93
+ .bendpoints
94
+ .reject { |bendpoint| [source_bounds, target_bounds].any? { |bounds| bendpoint.inside?(bounds) } }
95
+ .map { |bendpoint| DataModel::Bounds.from_location(bendpoint) }
86
96
  end
87
97
 
88
98
  def calc_points
@@ -98,17 +108,21 @@ module Archimate
98
108
  points.uniq
99
109
  end
100
110
 
101
- # a: Bounds
102
- # b: Bounds
111
+ # Takes the bounds of two objects and returns the optimal points
112
+ # between from the edge of `a` to the edge of `b`
113
+ # if left/right range of both overlap, use centerpoint of overlap range as x val
114
+ # if top/bottom range of both overlap, use centerpoint of overlap range as y val
115
+ # @param a [Bounds]
116
+ # @param b [Bounds]
103
117
  def bounds_to_points(a, b)
104
118
  ax_range = a.x_range
105
119
  bx_range = b.x_range
106
120
 
107
- overlap_x_center = ranges_overlap(ax_range, bx_range)
121
+ overlap_x_center = ax_range.overlap_midpoint(bx_range)
108
122
 
109
123
  if overlap_x_center
110
124
  ax = bx = overlap_x_center
111
- elsif b.is_right_of?(a)
125
+ elsif b.right_of?(a)
112
126
  ax = a.right
113
127
  bx = b.left
114
128
  else
@@ -119,11 +133,11 @@ module Archimate
119
133
  ay_range = a.y_range
120
134
  by_range = b.y_range
121
135
 
122
- overlap_y_center = ranges_overlap(ay_range, by_range)
136
+ overlap_y_center = ay_range.overlap_midpoint(by_range)
123
137
 
124
138
  if overlap_y_center
125
139
  ay = by = overlap_y_center
126
- elsif b.is_above?(a)
140
+ elsif b.above?(a)
127
141
  ay = a.top
128
142
  by = b.bottom
129
143
  else
@@ -135,18 +149,15 @@ module Archimate
135
149
  end
136
150
 
137
151
  def move_to(point)
138
- "M #{point.x} #{point.y}"
152
+ "M #{point}"
139
153
  end
140
154
 
141
155
  def line_to(point)
142
- "L #{point.x} #{point.y}"
156
+ "L #{point}"
143
157
  end
144
158
 
145
- def ranges_overlap(r1, r2)
146
- begin_max = [r1, r2].map(&:begin).max
147
- end_min = [r1, r2].map(&:end).min
148
- return nil if begin_max > end_min
149
- (begin_max + end_min) / 2.0
159
+ def q_curve(cp, pt)
160
+ "Q #{cp} #{pt}"
150
161
  end
151
162
  end
152
163
  end
@@ -9,6 +9,10 @@ module Archimate
9
9
  ((other.y - y)**2)
10
10
  )
11
11
  end
12
+
13
+ def to_s
14
+ [x, y].map(&:to_s).join(" ")
15
+ end
12
16
  end
13
17
  end
14
18
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Archimate
4
+ module Svg
5
+ Segment = Struct.new(:a, :b) do
6
+ def length
7
+ b - a
8
+ end
9
+
10
+ def from_end(dist)
11
+ length = b - a
12
+ from_start(length - dist)
13
+ end
14
+
15
+ def from_start(dist)
16
+ length = b - a
17
+ return a if dist.negative?
18
+ return b if length < dist
19
+ point_at_percent(dist / length)
20
+ end
21
+
22
+ def point_at_percent(pct)
23
+ Point.new(
24
+ a.x + ((b.x - a.x) * pct),
25
+ a.y + ((b.y - a.y) * pct)
26
+ )
27
+ end
28
+ end
29
+ end
30
+ end
@@ -80,8 +80,8 @@
80
80
  <symbol id="archimate-collaboration-badge" class="archimate-badge" viewBox="0 0 20 15" preserveAspectRatio="xMaxYMin meet">
81
81
  <path d="m7.5 14 a 6.5 6.5 0 0 1 0 -13 a 6.5 6.5 0 0 1 0 13 m 5 0 a 6.5 6.5 0 0 1 0 -13 a 6.5 6.5 0 0 1 0 13" style="fill:inherit;stroke:inherit"/>
82
82
  </symbol>
83
- <symbol id="archimate-communication-badge" class="archimate-badge" viewBox="0 0 20 15">
84
- <path d="m7.5 -1 l -6.5 6.5 l 6.5 6.5 m 5 -13 l 6.5 6.5 l -6.5 6.5 m -7 -6.5 h 3 m 3 0 h 3" style="fill:inherit;stroke:inherit"/>
83
+ <symbol id="archimate-communication-path-badge" class="archimate-badge" viewBox="0 0 20 15">
84
+ <path d="m7.5 -1 l -6.5 6.5 l 6.5 6.5 m 5 -13 l 6.5 6.5 l -6.5 6.5 m -7 -6.5 h 2 m 1.5 0 h 2 m 1.5 0 h 2" style="fill:inherit;stroke:inherit"/>
85
85
  </symbol>
86
86
  <symbol id="archimate-constraint-badge" class="archimate-badge" viewBox="0 0 20 15">
87
87
  <path d="m6 -1 h 13 l -5 10 h -13 z m 4 0 l -5 10" style="fill:inherit;stroke:inherit"/>
@@ -93,6 +93,9 @@
93
93
  <symbol id="archimate-driver-badge" class="archimate-badge" viewBox="0 0 20 15">
94
94
  <path d="m17.5 6.5 a 6.5 6.5 0 0 0 -13 0 a 6.5 6.5 0 0 0 13 0 m 2 0 h -17 m 8.5 -8.5 v 17 m -6.01 -2.49 l 12.02 -12.02 m 0 12.02 l -12.02 -12.02" style="fill:inherit;stroke:inherit"/>
95
95
  </symbol>
96
+ <symbol id="archimate-event-badge" class="archimate-badge" viewBox="0 0 20 20">
97
+ <path d="m1 1 a 8 6.5 0 0 1 0 12 h 12 a 6 5.5 0 0 0 0 -12 z" style="fill:inherit;stroke:inherit"/>
98
+ </symbol>
96
99
  <symbol id="archimate-function-badge" class="archimate-badge" viewBox="0 0 20 20" preserveAspectRatio="xMaxYMin meet">
97
100
  <path d="m7 15 l 0 -9 l 6 -5 l 6 5 l 0 9 l -6 -6 z" style="fill:none;stroke:inherit"/>
98
101
  </symbol>
@@ -117,6 +120,11 @@
117
120
  <symbol id="archimate-network-badge" class="archimate-badge" viewBox="0 0 20 15">
118
121
  <path d="m9 9.5 a 2.5 2.5 0 0 0 -5 0 a 2.5 2.5 0 0 0 5 0 m -2 -2.5 l 1 -3 m 0.5 0 a 2.5 2.5 0 0 0 0 -5 a 2.5 2.5 0 0 0 0 5 m 2 -2.5 h 3.5 a 2.5 2.5 0 0 0 5 0 a 2.5 2.5 0 0 0 -5 0 m 2 2.5 l -1 3 m -0.5 0 a 2.5 2.5 0 0 0 0 5 a 2.5 2.5 0 0 0 0 -5 m -2 2.5 h -3.5" style="fill:inherit;stroke:inherit"/>
119
122
  </symbol>
123
+ <symbol id="archimate-app-component-badge" class="archimate-badge" viewBox="0 0 20 20">
124
+ <path d="m6 4 v -3 h 12 v 17 h -12 v -3 m 0 -4 v -3" style="fill:inherit;stroke:inherit;"/>
125
+ <rect x="1" y="4" width="9" height="4" style="fill:inherit;stroke:inherit;"/>
126
+ <rect x="1" y="11" width="9" height="4" style="fill:inherit;stroke:inherit;"/>
127
+ </symbol>
120
128
  <symbol id="archimate-node-badge" class="archimate-badge" viewBox="0 0 20 20">
121
129
  <path d="M1 19 v -15 l 3 -3 h 15 v 15 l -3 3 z M 16 19 v -15 l 3 -3 m -3 3 h -15" style="fill:none;stroke:inherit;stroke-linejoin:miter;"/>
122
130
  </symbol>
@@ -143,7 +151,7 @@
143
151
  </symbol>
144
152
 
145
153
  <!-- Line Markers -->
146
- <marker id="archimate-dot-marker" viewBox="0 0 10 10" refX="0" refY="4" markerUnits="strokeWidth" markerWidth="10" markerHeight="10">
154
+ <marker id="archimate-dot-marker" viewBox="0 0 10 10" refX="4" refY="4" markerUnits="strokeWidth" markerWidth="10" markerHeight="10">
147
155
  <circle cx="4" cy="4" r="3" fill="black" stroke="black" />
148
156
  </marker>
149
157
  <marker id="archimate-used-by-arrow" viewBox="0 0 10 10" refX="9" refY="5" markerUnits="strokeWidth" markerWidth="8" markerHeight="8" orient="auto">
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Archimate
4
+ module Svg
5
+ class ViewNode
6
+ attr_reader :view_node
7
+
8
+ def initialize(view_node)
9
+ @view_node = view_node
10
+ end
11
+
12
+ # The info needed to render is contained in the view node with the exception of
13
+ # any offset needed. So this will need to be included in the recursive drawing of children
14
+ def render_elements(svg)
15
+ Nokogiri::XML::Builder.with(svg) do |xml|
16
+ EntityFactory.make_entity(view_node, nil).to_svg(xml)
17
+ end
18
+ svg
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Archimate
4
- VERSION = "2.0.2"
4
+ VERSION = "2.0.3"
5
5
  end
data/lib/archimate.rb CHANGED
@@ -35,7 +35,6 @@ module Archimate
35
35
  end
36
36
 
37
37
  module FileFormats
38
- autoload :ArchiFileFormat, 'archimate/file_formats/archi_file_format'
39
38
  autoload :ArchiFileReader, 'archimate/file_formats/archi_file_reader'
40
39
  autoload :ArchiFileWriter, 'archimate/file_formats/archi_file_writer'
41
40
  autoload :ModelExchangeFileReader, 'archimate/file_formats/model_exchange_file_reader'
@@ -51,7 +50,6 @@ module Archimate
51
50
  end
52
51
 
53
52
  module Svg
54
- autoload :Child, 'archimate/svg/child'
55
53
  autoload :CssStyle, 'archimate/svg/css_style'
56
54
  autoload :Connection, 'archimate/svg/connection'
57
55
  autoload :Diagram, 'archimate/svg/diagram'
@@ -60,7 +58,9 @@ module Archimate
60
58
  autoload :Extents, 'archimate/svg/extents'
61
59
  autoload :Path, 'archimate/svg/path'
62
60
  autoload :Point, 'archimate/svg/point'
61
+ autoload :Segment, 'archimate/svg/segment'
63
62
  autoload :SvgTemplate, 'archimate/svg/svg_template'
63
+ autoload :ViewNode, 'archimate/svg/view_node'
64
64
  end
65
65
 
66
66
  autoload :FileFormat, 'archimate/file_format'
@@ -69,6 +69,7 @@ module Archimate
69
69
  autoload :DerivedRelations, 'archimate/derived_relations'
70
70
 
71
71
  require "archimate/version"
72
+ require "archimate/core_refinements"
72
73
  require "archimate/config"
73
74
  require "archimate/logging"
74
75
  require "archimate/color"