From 2790dbfbab06223f4966c725cca84c65498803b9 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Tue, 18 Jan 2022 20:02:39 +0100 Subject: [PATCH] Fixed class movement in draw process --- src/py_to_uxf_core/model/uml_class.py | 6 ++++++ .../service/implementation_scanner_service.py | 1 + src/py_to_uxf_core/service/umlet_creator_service.py | 11 +++++++---- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/py_to_uxf_core/model/uml_class.py b/src/py_to_uxf_core/model/uml_class.py index 09339f3..09f39a7 100644 --- a/src/py_to_uxf_core/model/uml_class.py +++ b/src/py_to_uxf_core/model/uml_class.py @@ -43,6 +43,12 @@ class UMLClass: def dimension(self, value: int): self._dimension = value + def __str__(self): + return f'{self._cls}: {self._position} {self._dimension}' + + def __repr__(self): + return f'{self._cls}: {self._position} {self._dimension}' + def implementation_as_xml(self, base_class: 'UMLClass') -> str: base_point = Position( base_class.position.x + int(base_class.dimension.width / 2), diff --git a/src/py_to_uxf_core/service/implementation_scanner_service.py b/src/py_to_uxf_core/service/implementation_scanner_service.py index e48b630..e44b390 100644 --- a/src/py_to_uxf_core/service/implementation_scanner_service.py +++ b/src/py_to_uxf_core/service/implementation_scanner_service.py @@ -50,6 +50,7 @@ class ImplementationScannerService(ImplementationScannerABC): implementation = self._get_implementation(name, sub, classes) if implementation is not None: + implementation.is_first = False implementations.append(implementation) return implementations return None diff --git a/src/py_to_uxf_core/service/umlet_creator_service.py b/src/py_to_uxf_core/service/umlet_creator_service.py index 43a6d03..5d17294 100644 --- a/src/py_to_uxf_core/service/umlet_creator_service.py +++ b/src/py_to_uxf_core/service/umlet_creator_service.py @@ -17,11 +17,11 @@ class UmletCreatorService(UmletCreatorABC): UmletCreatorABC.__init__(self) self._settings: UMLCreatorSettings = config.get_configuration(UMLCreatorSettings) + self._moved_classes: list[UMLClass] = [] self._padding = 30 def _sort_by_implementation(self, uml_classes: List[UMLClass], implementations: List[ClassImplementation]): base_sub_map: dict[UMLClass, list[UMLClass]] = {} - moved_classes: list[UMLClass] = [] for implementation in implementations: sub_class: UMLClass = uml_classes.where(lambda u: u.cls == implementation.subclass).first() base_class: UMLClass = uml_classes.where(lambda u: u.cls == implementation.base).first() @@ -29,6 +29,8 @@ class UmletCreatorService(UmletCreatorABC): if base_class not in base_sub_map: base_sub_map[base_class] = [] + if sub_class in base_sub_map[base_class]: + continue base_sub_map[base_class].append(sub_class) last_base = Position(self._padding, self._padding) @@ -50,10 +52,11 @@ class UmletCreatorService(UmletCreatorABC): sub_class.position.y = last_sub.y + self._padding * 2 last_sub.x = sub_class.position.x + sub_class.dimension.width + self._padding - moved_classes.append(sub_class) if sub_class.position.y + sub_class.dimension.height > highest_y: highest_y = sub_class.position.y + sub_class.dimension.height + self._moved_classes.append(sub_class) + last_base.x = last_sub.x if last_base.x <= self._settings.max_pixel_x: last_base.x += self._padding * 2 @@ -61,10 +64,10 @@ class UmletCreatorService(UmletCreatorABC): last_base.x = self._padding last_base.y = highest_y + self._padding * 2 - moved_classes.append(base) + self._moved_classes.append(base) for cls in uml_classes: - if cls in moved_classes: + if cls in self._moved_classes: continue if cls.position.y <= last_base.y: