From f7b88fe127b5ea086d8d9fda9c93c03a78fc4e2c Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Tue, 18 Jan 2022 17:54:58 +0100 Subject: [PATCH] Added logic to draw on x to given max point --- cpl-workspace.json | 4 ++- src/py_to_uxf/appsettings.json | 2 +- .../configuration/uml_creator_settings.py | 23 +++++++++++++ .../service/umlet_creator_service.py | 34 +++++++++++++++---- 4 files changed, 55 insertions(+), 8 deletions(-) create mode 100644 src/py_to_uxf_core/configuration/uml_creator_settings.py diff --git a/cpl-workspace.json b/cpl-workspace.json index 33a9cd7..3855f7e 100644 --- a/cpl-workspace.json +++ b/cpl-workspace.json @@ -7,7 +7,9 @@ }, "Scripts": { "build-start": "cpl build; cd dist/py_to_uxf/build/py_to_uxf; echo \"Starting:\"; bash py_to_uxf -p ./ -o uml.uxf", - "bs": "cpl build-start" + "build-start-test": "cpl build; cd dist/py_to_uxf/build/py_to_uxf; echo \"Starting:\"; bash py_to_uxf -p ../../../../sh_gismo/src -o gismo.uxf", + "bs": "cpl build-start", + "bst": "cpl build-start-test" } } } \ No newline at end of file diff --git a/src/py_to_uxf/appsettings.json b/src/py_to_uxf/appsettings.json index 92d85db..04c7f32 100644 --- a/src/py_to_uxf/appsettings.json +++ b/src/py_to_uxf/appsettings.json @@ -6,6 +6,6 @@ ] }, "UMLCreator": { - "MaxPixelX": 1500 + "MaxPixelX": 2000 } } \ No newline at end of file diff --git a/src/py_to_uxf_core/configuration/uml_creator_settings.py b/src/py_to_uxf_core/configuration/uml_creator_settings.py new file mode 100644 index 0000000..5ceadeb --- /dev/null +++ b/src/py_to_uxf_core/configuration/uml_creator_settings.py @@ -0,0 +1,23 @@ +import traceback + +from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC +from cpl_core.console import Console + + +class UMLCreatorSettings(ConfigurationModelABC): + + def __init__(self): + ConfigurationModelABC.__init__(self) + + self._max_pixel_x = 0 + + @property + def max_pixel_x(self) -> int: + return self._max_pixel_x + + def from_dict(self, settings: dict): + try: + self._max_pixel_x = settings['MaxPixelX'] + except Exception as e: + Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in {self.__name__} settings') + Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}') 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 4507e4e..43a6d03 100644 --- a/src/py_to_uxf_core/service/umlet_creator_service.py +++ b/src/py_to_uxf_core/service/umlet_creator_service.py @@ -1,7 +1,9 @@ +from cpl_core.configuration import ConfigurationABC from cpl_core.console import Console from cpl_query.extension import List from py_to_uxf_core.abc.umlet_creator_abc import UmletCreatorABC +from py_to_uxf_core.configuration.uml_creator_settings import UMLCreatorSettings from py_to_uxf_core.model.class_implementation import ClassImplementation from py_to_uxf_core.model.dimension import Dimension from py_to_uxf_core.model.position import Position @@ -11,9 +13,10 @@ from py_to_uxf_core.model.uml_class import UMLClass class UmletCreatorService(UmletCreatorABC): - def __init__(self): + def __init__(self, config: ConfigurationABC): UmletCreatorABC.__init__(self) + self._settings: UMLCreatorSettings = config.get_configuration(UMLCreatorSettings) self._padding = 30 def _sort_by_implementation(self, uml_classes: List[UMLClass], implementations: List[ClassImplementation]): @@ -29,11 +32,12 @@ class UmletCreatorService(UmletCreatorABC): base_sub_map[base_class].append(sub_class) last_base = Position(self._padding, self._padding) + highest_y = 0 for base in base_sub_map: subclasses = base_sub_map[base] base.position.x = last_base.x - base.position.y = self._padding + base.position.y = last_base.y last_sub = Position(base.position.x, base.position.y + base.dimension.height) for sub_class in subclasses: @@ -47,17 +51,35 @@ class UmletCreatorService(UmletCreatorABC): 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 + + last_base.x = last_sub.x + if last_base.x <= self._settings.max_pixel_x: + last_base.x += self._padding * 2 + else: + last_base.x = self._padding + last_base.y = highest_y + self._padding * 2 - last_base = last_sub - last_base.x += self._padding * 2 moved_classes.append(base) for cls in uml_classes: if cls in moved_classes: continue - cls.position.x = last_base.x + self._padding - last_base.x = cls.position.x + cls.dimension.width + if cls.position.y <= last_base.y: + cls.position.y = last_base.y + + new_x = last_base.x + self._padding + if new_x <= self._settings.max_pixel_x: + cls.position.x = new_x + last_base.x = cls.position.x + cls.dimension.width + else: + last_base.x = 0 + last_base.y = highest_y + self._padding * 2 + + if cls.position.y + cls.dimension.height > highest_y: + highest_y = cls.position.y + cls.dimension.height def generate_xml(self, classes: List[PythonClass], implementations: List[ClassImplementation]) -> str: uml_classes = List(UMLClass)