Fixed class movement in draw process

This commit is contained in:
Sven Heidemann 2022-01-18 20:02:39 +01:00
parent e5b3e80378
commit 2790dbfbab
3 changed files with 14 additions and 4 deletions

View File

@ -43,6 +43,12 @@ class UMLClass:
def dimension(self, value: int): def dimension(self, value: int):
self._dimension = value 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: def implementation_as_xml(self, base_class: 'UMLClass') -> str:
base_point = Position( base_point = Position(
base_class.position.x + int(base_class.dimension.width / 2), base_class.position.x + int(base_class.dimension.width / 2),

View File

@ -50,6 +50,7 @@ class ImplementationScannerService(ImplementationScannerABC):
implementation = self._get_implementation(name, sub, classes) implementation = self._get_implementation(name, sub, classes)
if implementation is not None: if implementation is not None:
implementation.is_first = False
implementations.append(implementation) implementations.append(implementation)
return implementations return implementations
return None return None

View File

@ -17,11 +17,11 @@ class UmletCreatorService(UmletCreatorABC):
UmletCreatorABC.__init__(self) UmletCreatorABC.__init__(self)
self._settings: UMLCreatorSettings = config.get_configuration(UMLCreatorSettings) self._settings: UMLCreatorSettings = config.get_configuration(UMLCreatorSettings)
self._moved_classes: list[UMLClass] = []
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]):
base_sub_map: dict[UMLClass, list[UMLClass]] = {} base_sub_map: dict[UMLClass, list[UMLClass]] = {}
moved_classes: list[UMLClass] = []
for implementation in implementations: for implementation in implementations:
sub_class: UMLClass = uml_classes.where(lambda u: u.cls == implementation.subclass).first() 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() 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: if base_class not in base_sub_map:
base_sub_map[base_class] = [] base_sub_map[base_class] = []
if sub_class in base_sub_map[base_class]:
continue
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)
@ -50,10 +52,11 @@ class UmletCreatorService(UmletCreatorABC):
sub_class.position.y = last_sub.y + self._padding * 2 sub_class.position.y = last_sub.y + self._padding * 2
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)
if sub_class.position.y + sub_class.dimension.height > highest_y: if sub_class.position.y + sub_class.dimension.height > highest_y:
highest_y = sub_class.position.y + sub_class.dimension.height highest_y = sub_class.position.y + sub_class.dimension.height
self._moved_classes.append(sub_class)
last_base.x = last_sub.x last_base.x = last_sub.x
if last_base.x <= self._settings.max_pixel_x: if last_base.x <= self._settings.max_pixel_x:
last_base.x += self._padding * 2 last_base.x += self._padding * 2
@ -61,10 +64,10 @@ class UmletCreatorService(UmletCreatorABC):
last_base.x = self._padding last_base.x = self._padding
last_base.y = highest_y + self._padding * 2 last_base.y = highest_y + self._padding * 2
moved_classes.append(base) self._moved_classes.append(base)
for cls in uml_classes: for cls in uml_classes:
if cls in moved_classes: if cls in self._moved_classes:
continue continue
if cls.position.y <= last_base.y: if cls.position.y <= last_base.y: