Class: Lutaml::Cli::Uml::DiagramCommand
- Inherits:
-
Object
- Object
- Lutaml::Cli::Uml::DiagramCommand
- Defined in:
- lib/lutaml/cli/uml/diagram_command.rb
Overview
CLI command for diagram rendering
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
-
.add_options_to(thor_class, _method_name) ⇒ Object
rubocop:disable Metrics/MethodLength.
Instance Method Summary collapse
-
#convert_diagram_to_rendering_format(diagram, repository) ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity.
- #determine_connector_type(connector) ⇒ Object
-
#determine_element_type(uml_element) ⇒ Object
rubocop:disable Metrics/MethodLength.
- #find_connector_by_xmi_id(xmi_id, repository) ⇒ Object
- #find_diagram_object_for_element(element_xmi_id, diagram) ⇒ Object
-
#find_uml_element_by_xmi_id(xmi_id, repository) ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity.
-
#initialize(options = {}) ⇒ DiagramCommand
constructor
A new instance of DiagramCommand.
- #run(action, *args) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ DiagramCommand
Returns a new instance of DiagramCommand.
12 13 14 |
# File 'lib/lutaml/cli/uml/diagram_command.rb', line 12 def initialize( = {}) @options = .transform_keys(&:to_sym) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
10 11 12 |
# File 'lib/lutaml/cli/uml/diagram_command.rb', line 10 def @options end |
Class Method Details
.add_options_to(thor_class, _method_name) ⇒ Object
rubocop:disable Metrics/MethodLength
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/lutaml/cli/uml/diagram_command.rb', line 16 def self.(thor_class, _method_name) # rubocop:disable Metrics/MethodLength thor_class.long_desc <<-DESC Render EA diagrams to SVG format. This command converts Enterprise Architect diagram data into clean, interactive SVG files suitable for web display. The diagrams can be rendered from LUR packages or directly from diagram data. The output SVG files include proper styling, interactive elements, and can be embedded in web applications or documentation. Examples: lutaml uml diagram render diagram001 -o diagram001.svg lutaml uml diagram render diagram001 -o diagram001.svg --interactive lutaml uml diagram list mymodel.lur DESC thor_class.option :output, aliases: "-o", type: :string, desc: "Output SVG file path" thor_class.option :format, type: :string, default: "svg", desc: "Output format (svg|png)" thor_class.option :interactive, type: :boolean, default: true, desc: "Include interactive elements" thor_class.option :width, type: :numeric, desc: "Diagram width" thor_class.option :height, type: :numeric, desc: "Diagram height" thor_class.option :padding, type: :numeric, default: 20, desc: "Padding around diagram" thor_class.option :background, type: :string, default: "#ffffff", desc: "Background color" thor_class.option :grid, type: :boolean, default: false, desc: "Show grid lines" end |
Instance Method Details
#convert_diagram_to_rendering_format(diagram, repository) ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 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 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/lutaml/cli/uml/diagram_command.rb', line 62 def convert_diagram_to_rendering_format(diagram, repository) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity elements = [] connectors = [] # Process diagram objects (visual elements) diagram.diagram_objects.each do |obj| # rubocop:disable Metrics/BlockLength # Find the actual UML element that this diagram object represents uml_element = find_uml_element_by_xmi_id(obj.object_xmi_id, repository) next unless uml_element # Convert to rendering format element_data = { id: obj.diagram_object_id || obj.object_xmi_id, type: determine_element_type(uml_element), name: uml_element.name, x: obj.left || 0, y: obj.top || 0, width: (obj.right - obj.left) || 120, height: (obj.bottom - obj.top) || 80, style: obj.style, } # Add stereotype if available if uml_element.respond_to?(:stereotype) && uml_element.stereotype element_data[:stereotype] = if uml_element.stereotype.is_a?(Array) uml_element.stereotype.first else uml_element.stereotype end end # Add attributes and operations for classes if uml_element.respond_to?(:attributes) && uml_element.attributes element_data[:attributes] = uml_element.attributes.map do |attr| { name: attr.name, type: attr.type, visibility: attr.visibility || "public", } end end if uml_element.respond_to?(:operations) && uml_element.operations element_data[:operations] = uml_element.operations.map do |op| { name: op.name, return_type: op.return_type, visibility: op.visibility || "public", parameters: op.parameters&.map do |p| { name: p.name, type: p.type } end || [], } end end elements << element_data end # Process diagram links (connectors/relationships) diagram.diagram_links.each do |link| # rubocop:disable Metrics/BlockLength # Find the actual connector that this diagram link represents connector = find_connector_by_xmi_id(link.connector_xmi_id, repository) next unless connector # Convert to rendering format connector_data = { id: link.connector_id || link.connector_xmi_id, type: determine_connector_type(connector), style: link.style, geometry: link.geometry, path: link.path, } # Add role and multiplicity information if available if connector.respond_to?(:owner_end_attribute_name) && connector.owner_end_attribute_name connector_data[:source_role] = connector.owner_end_attribute_name end if connector.respond_to?(:member_end_attribute_name) && connector.member_end_attribute_name connector_data[:target_role] = connector.member_end_attribute_name end if connector.respond_to?(:owner_end_cardinality) && connector.owner_end_cardinality connector_data[:source_multiplicity] = format_cardinality(connector.owner_end_cardinality) end if connector.respond_to?(:member_end_cardinality) && connector.member_end_cardinality connector_data[:target_multiplicity] = format_cardinality(connector.member_end_cardinality) end # Add source and target information if available if connector.respond_to?(:source) && connector.source source_obj = find_diagram_object_for_element( connector.source.xmi_id, diagram ) if source_obj connector_data[:source_x] = source_obj.left + ((source_obj.right - source_obj.left) / 2) connector_data[:source_y] = source_obj.top + ((source_obj.bottom - source_obj.top) / 2) end end if connector.respond_to?(:target) && connector.target target_obj = find_diagram_object_for_element( connector.target.xmi_id, diagram ) if target_obj connector_data[:target_x] = target_obj.left + ((target_obj.right - target_obj.left) / 2) connector_data[:target_y] = target_obj.top + ((target_obj.bottom - target_obj.top) / 2) end end connectors << connector_data end { elements: elements, connectors: connectors, } end |
#determine_connector_type(connector) ⇒ Object
228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/lutaml/cli/uml/diagram_command.rb', line 228 def determine_connector_type(connector) case connector when Lutaml::Uml::Association "association" when Lutaml::Uml::Generalization "generalization" when Lutaml::Uml::Dependency "dependency" else "connector" end end |
#determine_element_type(uml_element) ⇒ Object
rubocop:disable Metrics/MethodLength
213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/lutaml/cli/uml/diagram_command.rb', line 213 def determine_element_type(uml_element) # rubocop:disable Metrics/MethodLength case uml_element when Lutaml::Uml::Class "class" when Lutaml::Uml::Package "package" when Lutaml::Uml::DataType "datatype" when Lutaml::Uml::Enumeration "enumeration" else "unknown" end end |
#find_connector_by_xmi_id(xmi_id, repository) ⇒ Object
202 203 204 205 |
# File 'lib/lutaml/cli/uml/diagram_command.rb', line 202 def find_connector_by_xmi_id(xmi_id, repository) # Search through associations and other connectors repository.associations_index.find { |a| a.xmi_id == xmi_id } end |
#find_diagram_object_for_element(element_xmi_id, diagram) ⇒ Object
207 208 209 210 211 |
# File 'lib/lutaml/cli/uml/diagram_command.rb', line 207 def find_diagram_object_for_element(element_xmi_id, diagram) diagram.diagram_objects.find do |obj| obj.object_xmi_id == element_xmi_id end end |
#find_uml_element_by_xmi_id(xmi_id, repository) ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
194 195 196 197 198 199 200 |
# File 'lib/lutaml/cli/uml/diagram_command.rb', line 194 def find_uml_element_by_xmi_id(xmi_id, repository) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity # Search through all element types repository.classes_index.find { |c| c.xmi_id == xmi_id } || repository.packages_index.find { |p| p.xmi_id == xmi_id } || repository.data_types_index.find { |d| d.xmi_id == xmi_id } || repository.enums_index.find { |e| e.xmi_id == xmi_id } end |
#run(action, *args) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/lutaml/cli/uml/diagram_command.rb', line 49 def run(action, *args) case action when "render" render_diagram(args.first) when "list" list_diagrams(args.first) else puts "Unknown action: #{action}" puts "Available actions: render, list" raise Thor::Error, "Invalid action" end end |