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
- #add_association_metadata(data, connector) ⇒ Object
- #add_classifier_members(data, uml_element) ⇒ Object
- #add_connector_coordinates(data, connector, diagram) ⇒ Object
- #add_element_stereotype(data, uml_element) ⇒ Object
- #add_endpoint_coords(data, xmi_id, diagram, x_key, y_key) ⇒ Object
- #base_element_data(obj, uml_element) ⇒ Object
- #build_connector_data(link, connector, diagram) ⇒ Object
- #build_element_data(obj, uml_element) ⇒ Object
- #convert_diagram_to_rendering_format(diagram, repository) ⇒ Object
- #determine_connector_type(connector) ⇒ Object
-
#determine_element_type(uml_element) ⇒ Object
rubocop:disable Metrics/MethodLength.
- #extract_diagram_connectors(diagram, repository) ⇒ Object
- #extract_diagram_elements(diagram, repository) ⇒ Object
- #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
- #serialize_element_attributes(attributes) ⇒ Object
- #serialize_element_operations(operations) ⇒ 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
#add_association_metadata(data, connector) ⇒ Object
200 201 202 203 204 205 206 207 |
# File 'lib/lutaml/cli/uml/diagram_command.rb', line 200 def (data, connector) return unless connector.is_a?(Lutaml::Uml::Association) data[:source_role] = connector.owner_end_attribute_name if connector.owner_end_attribute_name data[:target_role] = connector.member_end_attribute_name if connector.member_end_attribute_name data[:source_multiplicity] = format_cardinality(connector.owner_end_cardinality) if connector.owner_end_cardinality data[:target_multiplicity] = format_cardinality(connector.member_end_cardinality) if connector.member_end_cardinality end |
#add_classifier_members(data, uml_element) ⇒ Object
153 154 155 156 157 158 |
# File 'lib/lutaml/cli/uml/diagram_command.rb', line 153 def add_classifier_members(data, uml_element) return unless uml_element.is_a?(Lutaml::Uml::Classifier) data[:attributes] = serialize_element_attributes(uml_element.attributes) if uml_element.attributes data[:operations] = serialize_element_operations(uml_element.operations) if uml_element.operations end |
#add_connector_coordinates(data, connector, diagram) ⇒ Object
209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/lutaml/cli/uml/diagram_command.rb', line 209 def add_connector_coordinates(data, connector, diagram) return unless connector.is_a?(Lutaml::Uml::Association) if connector.owner_end && connector.source add_endpoint_coords(data, connector.source.xmi_id, diagram, :source_x, :source_y) end return unless connector.member_end && connector.target add_endpoint_coords(data, connector.target.xmi_id, diagram, :target_x, :target_y) end |
#add_element_stereotype(data, uml_element) ⇒ Object
146 147 148 149 150 151 |
# File 'lib/lutaml/cli/uml/diagram_command.rb', line 146 def add_element_stereotype(data, uml_element) return unless uml_element.is_a?(Lutaml::Uml::TopElement) return unless uml_element.stereotype && !uml_element.stereotype.empty? data[:stereotype] = uml_element.stereotype.first end |
#add_endpoint_coords(data, xmi_id, diagram, x_key, y_key) ⇒ Object
223 224 225 226 227 228 229 |
# File 'lib/lutaml/cli/uml/diagram_command.rb', line 223 def add_endpoint_coords(data, xmi_id, diagram, x_key, y_key) obj = find_diagram_object_for_element(xmi_id, diagram) return unless obj data[x_key] = obj.left + ((obj.right - obj.left) / 2) data[y_key] = obj.top + ((obj.bottom - obj.top) / 2) end |
#base_element_data(obj, uml_element) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/lutaml/cli/uml/diagram_command.rb', line 133 def base_element_data(obj, uml_element) { 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, } end |
#build_connector_data(link, connector, diagram) ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/lutaml/cli/uml/diagram_command.rb', line 185 def build_connector_data(link, connector, diagram) data = { id: link.connector_id || link.connector_xmi_id, type: determine_connector_type(connector), style: link.style, geometry: link.geometry, path: link.path, } (data, connector) add_connector_coordinates(data, connector, diagram) data end |
#build_element_data(obj, uml_element) ⇒ Object
126 127 128 129 130 131 |
# File 'lib/lutaml/cli/uml/diagram_command.rb', line 126 def build_element_data(obj, uml_element) data = base_element_data(obj, uml_element) add_element_stereotype(data, uml_element) add_classifier_members(data, uml_element) data end |
#convert_diagram_to_rendering_format(diagram, repository) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/lutaml/cli/uml/diagram_command.rb', line 62 def convert_diagram_to_rendering_format(diagram, repository) elements = extract_diagram_elements(diagram, repository) connectors = extract_diagram_connectors(diagram, repository) { elements: elements, connectors: connectors } end |
#determine_connector_type(connector) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/lutaml/cli/uml/diagram_command.rb', line 103 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
88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/lutaml/cli/uml/diagram_command.rb', line 88 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 |
#extract_diagram_connectors(diagram, repository) ⇒ Object
175 176 177 178 179 180 181 182 183 |
# File 'lib/lutaml/cli/uml/diagram_command.rb', line 175 def extract_diagram_connectors(diagram, repository) diagram.diagram_links.filter_map do |link| connector = find_connector_by_xmi_id(link.connector_xmi_id, repository) next unless connector build_connector_data(link, connector, diagram) end end |
#extract_diagram_elements(diagram, repository) ⇒ Object
116 117 118 119 120 121 122 123 124 |
# File 'lib/lutaml/cli/uml/diagram_command.rb', line 116 def extract_diagram_elements(diagram, repository) diagram.diagram_objects.filter_map do |obj| uml_element = find_uml_element_by_xmi_id(obj.object_xmi_id, repository) next unless uml_element build_element_data(obj, uml_element) end end |
#find_connector_by_xmi_id(xmi_id, repository) ⇒ Object
77 78 79 80 |
# File 'lib/lutaml/cli/uml/diagram_command.rb', line 77 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
82 83 84 85 86 |
# File 'lib/lutaml/cli/uml/diagram_command.rb', line 82 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
69 70 71 72 73 74 75 |
# File 'lib/lutaml/cli/uml/diagram_command.rb', line 69 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 |
#serialize_element_attributes(attributes) ⇒ Object
160 161 162 163 164 165 |
# File 'lib/lutaml/cli/uml/diagram_command.rb', line 160 def serialize_element_attributes(attributes) attributes.map do |attr| { name: attr.name, type: attr.type, visibility: attr.visibility || "public" } end end |
#serialize_element_operations(operations) ⇒ Object
167 168 169 170 171 172 173 |
# File 'lib/lutaml/cli/uml/diagram_command.rb', line 167 def serialize_element_operations(operations) operations.map do |op| { name: op.name, return_type: op.return_type, visibility: op.visibility || "public", parameters: op.parameters&.map { |p| { name: p.name, type: p.type } } || [] } end end |