From 1ad5da888b7772957d93cef8a34416efff2d31e6 Mon Sep 17 00:00:00 2001 From: Armin <21990230+GODrums@users.noreply.github.com> Date: Thu, 26 Oct 2023 14:21:52 +0200 Subject: [PATCH] Support for subsystems in component diagrams (#291) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Alexander Görtzen <40467337+AlexanderG2207@users.noreply.github.com> Co-authored-by: Matthias Lehner <143808484+matthiaslehnertum@users.noreply.github.com> --- src/main/i18n/de.json | 1 + src/main/i18n/en.json | 1 + .../uml-component/uml-component-component.tsx | 13 +++-- .../common/uml-component/uml-component.ts | 8 +++- src/main/packages/components.ts | 2 + src/main/packages/popups.ts | 1 + .../component-preview.ts | 12 ++++- .../packages/uml-component-diagram/index.ts | 1 + .../uml-component-subsystem-component.tsx | 48 +++++++++++++++++++ .../uml-component-subsystem.ts | 16 +++++++ src/main/packages/uml-elements.ts | 2 + .../uml-component-component-test.tsx.snap | 34 +++++++++---- 12 files changed, 124 insertions(+), 15 deletions(-) create mode 100644 src/main/packages/uml-component-diagram/uml-component-subsystem/uml-component-subsystem-component.tsx create mode 100644 src/main/packages/uml-component-diagram/uml-component-subsystem/uml-component-subsystem.ts diff --git a/src/main/i18n/de.json b/src/main/i18n/de.json index f6e018b2b..a3e2ef354 100644 --- a/src/main/i18n/de.json +++ b/src/main/i18n/de.json @@ -79,6 +79,7 @@ }, "ComponentDiagram": { "Component": "Komponente", + "Subsystem": "Teilsystem", "ComponentDependency": "Abhängigkeit", "ComponentInterface": "Schnittstelle", "ComponentInterfaceProvided": "Bereitgestellte Schnittstelle", diff --git a/src/main/i18n/en.json b/src/main/i18n/en.json index 25d8cf30c..b5ebf7caf 100644 --- a/src/main/i18n/en.json +++ b/src/main/i18n/en.json @@ -79,6 +79,7 @@ }, "ComponentDiagram": { "Component": "Component", + "Subsystem": "Subsystem", "ComponentDependency": "Dependency", "ComponentInterface": "Interface", "ComponentInterfaceProvided": "Provided Interface", diff --git a/src/main/packages/common/uml-component/uml-component-component.tsx b/src/main/packages/common/uml-component/uml-component-component.tsx index b8dff7065..475ef2121 100644 --- a/src/main/packages/common/uml-component/uml-component-component.tsx +++ b/src/main/packages/common/uml-component/uml-component-component.tsx @@ -11,9 +11,6 @@ export const UMLComponentComponent: FunctionComponent = ({ element, child strokeColor={element.strokeColor} fillColor={fillColor || element.fillColor} /> - - {element.name} - = ({ element, child strokeMiterlimit="10" /> + + {element.stereotype && ( + + {`«${element.stereotype}»`} + + )} + + {element.name} + + {children} ); diff --git a/src/main/packages/common/uml-component/uml-component.ts b/src/main/packages/common/uml-component/uml-component.ts index 008bf3345..bd1cbbbea 100644 --- a/src/main/packages/common/uml-component/uml-component.ts +++ b/src/main/packages/common/uml-component/uml-component.ts @@ -1,3 +1,9 @@ import { UMLPackage } from '../uml-package/uml-package'; -export abstract class UMLComponent extends UMLPackage {} +export interface IUMLComponent { + stereotype: string; +} + +export abstract class UMLComponent extends UMLPackage implements IUMLComponent { + stereotype = 'component'; +} diff --git a/src/main/packages/components.ts b/src/main/packages/components.ts index 822dbae96..5d7fad874 100644 --- a/src/main/packages/components.ts +++ b/src/main/packages/components.ts @@ -37,6 +37,7 @@ import { UMLPetriNetArcComponent } from './uml-petri-net/uml-petri-net-arc/uml-p import { UMLReachabilityGraphArcComponent } from './uml-reachability-graph/uml-reachability-graph-arc/uml-reachability-graph-arc-component'; import { UMLReachabilityGraphMarkingComponent } from './uml-reachability-graph/uml-reachability-graph-marking/uml-reachability-graph-marking-component'; import { UMLComponentComponent } from './common/uml-component/uml-component-component'; +import { UMLComponentSubsystem } from './uml-component-diagram/uml-component-subsystem/uml-component-subsystem-component'; import { SyntaxTreeTerminalComponent } from './syntax-tree/syntax-tree-terminal/syntax-tree-terminal-component'; import { SyntaxTreeNonterminalComponent } from './syntax-tree/syntax-tree-nonterminal/syntax-tree-nonterminal-component'; import { SyntaxTreeLinkComponent } from './syntax-tree/syntax-tree-link/syntax-tree-link-component'; @@ -86,6 +87,7 @@ export const Components: { [UMLElementType.UseCaseActor]: UMLUseCaseActorComponent, [UMLElementType.UseCaseSystem]: UMLUseCaseSystemComponent, [UMLElementType.Component]: UMLComponentComponent, + [UMLElementType.Subsystem]: UMLComponentSubsystem, [UMLElementType.ComponentInterface]: UMLInterfaceComponent, [UMLElementType.DeploymentNode]: UMLDeploymentNodeComponent, [UMLElementType.DeploymentComponent]: UMLComponentComponent, diff --git a/src/main/packages/popups.ts b/src/main/packages/popups.ts index d8269d9da..0716c1351 100644 --- a/src/main/packages/popups.ts +++ b/src/main/packages/popups.ts @@ -55,6 +55,7 @@ export const Popups: { [key in UMLElementType | UMLRelationshipType]: ComponentT [UMLElementType.UseCaseActor]: DefaultPopup, [UMLElementType.UseCaseSystem]: DefaultPopup, [UMLElementType.Component]: DefaultPopup, + [UMLElementType.Subsystem]: DefaultPopup, [UMLElementType.ComponentInterface]: DefaultPopup, [UMLElementType.DeploymentNode]: UMLDeploymentNodeUpdate, [UMLElementType.DeploymentComponent]: DefaultPopup, diff --git a/src/main/packages/uml-component-diagram/component-preview.ts b/src/main/packages/uml-component-diagram/component-preview.ts index c763322cc..f931e8d1d 100644 --- a/src/main/packages/uml-component-diagram/component-preview.ts +++ b/src/main/packages/uml-component-diagram/component-preview.ts @@ -3,6 +3,7 @@ import { UMLElement } from '../../services/uml-element/uml-element'; import { ComposePreview } from '../compose-preview'; import { UMLComponentInterface } from './uml-component-interface/uml-component-interface'; import { UMLComponentComponent } from './uml-component/uml-component-component'; +import { UMLSubsystem } from './uml-component-subsystem/uml-component-subsystem'; export const composeComponentPreview: ComposePreview = ( layer: ILayer, @@ -19,7 +20,16 @@ export const composeComponentPreview: ComposePreview = ( }; elements.push(umlComponent); - // UML Deployment Artifact + // UML Subsystem + const umlSubsystem = new UMLSubsystem({ name: translate('packages.ComponentDiagram.Subsystem') }); + umlSubsystem.bounds = { + ...umlSubsystem.bounds, + width: umlSubsystem.bounds.width, + height: umlSubsystem.bounds.height, + }; + elements.push(umlSubsystem); + + // UML Component Interface const umlComponentInterface = new UMLComponentInterface({ name: translate('packages.ComponentDiagram.ComponentInterface'), }); diff --git a/src/main/packages/uml-component-diagram/index.ts b/src/main/packages/uml-component-diagram/index.ts index fd041b35e..e32b66059 100644 --- a/src/main/packages/uml-component-diagram/index.ts +++ b/src/main/packages/uml-component-diagram/index.ts @@ -1,5 +1,6 @@ export const ComponentElementType = { Component: 'Component', + Subsystem: 'Subsystem', ComponentInterface: 'ComponentInterface', } as const; diff --git a/src/main/packages/uml-component-diagram/uml-component-subsystem/uml-component-subsystem-component.tsx b/src/main/packages/uml-component-diagram/uml-component-subsystem/uml-component-subsystem-component.tsx new file mode 100644 index 000000000..d717de65d --- /dev/null +++ b/src/main/packages/uml-component-diagram/uml-component-subsystem/uml-component-subsystem-component.tsx @@ -0,0 +1,48 @@ +import React, { FunctionComponent } from 'react'; +import { Text } from '../../../components/controls/text/text'; +import { UMLSubsystem } from './uml-component-subsystem'; +import { ThemedPath, ThemedRect } from '../../../components/theme/themedComponents'; + +export const UMLComponentSubsystem: FunctionComponent = ({ element, children, fillColor }) => ( + + + + + + + + {element.stereotype && ( + + {`«${element.stereotype}»`} + + )} + + {element.name} + + + {children} + +); + +interface Props { + element: UMLSubsystem; + fillColor?: string; + children?: React.ReactNode; +} diff --git a/src/main/packages/uml-component-diagram/uml-component-subsystem/uml-component-subsystem.ts b/src/main/packages/uml-component-diagram/uml-component-subsystem/uml-component-subsystem.ts new file mode 100644 index 000000000..0abb1b793 --- /dev/null +++ b/src/main/packages/uml-component-diagram/uml-component-subsystem/uml-component-subsystem.ts @@ -0,0 +1,16 @@ +import { UMLPackage } from '../../common/uml-package/uml-package'; +import { ComponentElementType, ComponentRelationshipType } from '..'; + +export interface IUMLSubsystem { + stereotype: string; +} + +export class UMLSubsystem extends UMLPackage implements IUMLSubsystem { + static supportedRelationships = [ + ComponentRelationshipType.ComponentDependency, + ComponentRelationshipType.ComponentInterfaceProvided, + ComponentRelationshipType.ComponentInterfaceRequired, + ]; + stereotype = 'subsystem'; + type = ComponentElementType.Subsystem; +} diff --git a/src/main/packages/uml-elements.ts b/src/main/packages/uml-elements.ts index f6c8cc6be..f06af75e3 100644 --- a/src/main/packages/uml-elements.ts +++ b/src/main/packages/uml-elements.ts @@ -30,6 +30,7 @@ import { UMLReachabilityGraphMarking } from './uml-reachability-graph/uml-reacha import { CommunicationLinkMessage } from './uml-communication-diagram/uml-communication-link/uml-communiction-link-message'; import { UMLDeploymentComponent } from './uml-deployment-diagram/uml-deployment-component/uml-component'; import { UMLComponentComponent } from './uml-component-diagram/uml-component/uml-component-component'; +import { UMLSubsystem } from './uml-component-diagram/uml-component-subsystem/uml-component-subsystem'; import { SyntaxTreeTerminal } from './syntax-tree/syntax-tree-terminal/syntax-tree-terminal'; import { SyntaxTreeNonterminal } from './syntax-tree/syntax-tree-nonterminal/syntax-tree-nonterminal'; import { FlowchartTerminal } from './flowchart/flowchart-terminal/flowchart-terminal'; @@ -72,6 +73,7 @@ export const UMLElements = { [UMLElementType.UseCaseActor]: UMLUseCaseActor, [UMLElementType.UseCaseSystem]: UMLUseCaseSystem, [UMLElementType.Component]: UMLComponentComponent, + [UMLElementType.Subsystem]: UMLSubsystem, [UMLElementType.ComponentInterface]: UMLComponentInterface, [UMLElementType.DeploymentNode]: UMLDeploymentNode, [UMLElementType.DeploymentComponent]: UMLDeploymentComponent, diff --git a/src/tests/unit/packages/uml-component-diagram/uml-component/__snapshots__/uml-component-component-test.tsx.snap b/src/tests/unit/packages/uml-component-diagram/uml-component/__snapshots__/uml-component-component-test.tsx.snap index d8d80fd3f..41fecd199 100644 --- a/src/tests/unit/packages/uml-component-diagram/uml-component/__snapshots__/uml-component-component-test.tsx.snap +++ b/src/tests/unit/packages/uml-component-diagram/uml-component/__snapshots__/uml-component-component-test.tsx.snap @@ -14,16 +14,6 @@ exports[`render the uml-component-component 1`] = ` stroke="black" width="100%" /> - - TestComponentComponent - @@ -44,6 +34,30 @@ exports[`render the uml-component-component 1`] = ` stroke-width="1.2" /> + + + «component» + + + TestComponentComponent + +