Added logic to draw on x to given max point
This commit is contained in:
parent
318a8362ca
commit
f7b88fe127
@ -7,7 +7,9 @@
|
|||||||
},
|
},
|
||||||
"Scripts": {
|
"Scripts": {
|
||||||
"build-start": "cpl build; cd dist/py_to_uxf/build/py_to_uxf; echo \"Starting:\"; bash py_to_uxf -p ./ -o uml.uxf",
|
"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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,6 +6,6 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"UMLCreator": {
|
"UMLCreator": {
|
||||||
"MaxPixelX": 1500
|
"MaxPixelX": 2000
|
||||||
}
|
}
|
||||||
}
|
}
|
23
src/py_to_uxf_core/configuration/uml_creator_settings.py
Normal file
23
src/py_to_uxf_core/configuration/uml_creator_settings.py
Normal file
@ -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()}')
|
@ -1,7 +1,9 @@
|
|||||||
|
from cpl_core.configuration import ConfigurationABC
|
||||||
from cpl_core.console import Console
|
from cpl_core.console import Console
|
||||||
from cpl_query.extension import List
|
from cpl_query.extension import List
|
||||||
|
|
||||||
from py_to_uxf_core.abc.umlet_creator_abc import UmletCreatorABC
|
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.class_implementation import ClassImplementation
|
||||||
from py_to_uxf_core.model.dimension import Dimension
|
from py_to_uxf_core.model.dimension import Dimension
|
||||||
from py_to_uxf_core.model.position import Position
|
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):
|
class UmletCreatorService(UmletCreatorABC):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, config: ConfigurationABC):
|
||||||
UmletCreatorABC.__init__(self)
|
UmletCreatorABC.__init__(self)
|
||||||
|
|
||||||
|
self._settings: UMLCreatorSettings = config.get_configuration(UMLCreatorSettings)
|
||||||
self._padding = 30
|
self._padding = 30
|
||||||
|
|
||||||
def _sort_by_implementation(self, uml_classes: List[UMLClass], implementations: List[ClassImplementation]):
|
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)
|
base_sub_map[base_class].append(sub_class)
|
||||||
|
|
||||||
last_base = Position(self._padding, self._padding)
|
last_base = Position(self._padding, self._padding)
|
||||||
|
highest_y = 0
|
||||||
for base in base_sub_map:
|
for base in base_sub_map:
|
||||||
subclasses = base_sub_map[base]
|
subclasses = base_sub_map[base]
|
||||||
|
|
||||||
base.position.x = last_base.x
|
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)
|
last_sub = Position(base.position.x, base.position.y + base.dimension.height)
|
||||||
for sub_class in subclasses:
|
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
|
last_sub.x = sub_class.position.x + sub_class.dimension.width + self._padding
|
||||||
moved_classes.append(sub_class)
|
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)
|
moved_classes.append(base)
|
||||||
|
|
||||||
for cls in uml_classes:
|
for cls in uml_classes:
|
||||||
if cls in moved_classes:
|
if cls in moved_classes:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
cls.position.x = last_base.x + self._padding
|
if cls.position.y <= last_base.y:
|
||||||
last_base.x = cls.position.x + cls.dimension.width
|
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:
|
def generate_xml(self, classes: List[PythonClass], implementations: List[ClassImplementation]) -> str:
|
||||||
uml_classes = List(UMLClass)
|
uml_classes = List(UMLClass)
|
||||||
|
Loading…
Reference in New Issue
Block a user