Improved sort criteria

This commit is contained in:
Sven Heidemann 2022-01-18 21:54:55 +01:00
parent 405dded626
commit 83f666353f
3 changed files with 15 additions and 12 deletions

View File

@ -6,6 +6,7 @@ class ClassImplementation:
def __init__(self, base: PythonClass, subclass: PythonClass): def __init__(self, base: PythonClass, subclass: PythonClass):
self._base = base self._base = base
self._subclass = subclass self._subclass = subclass
self.is_first = True
@property @property
def base(self) -> PythonClass: def base(self) -> PythonClass:
@ -16,7 +17,7 @@ class ClassImplementation:
return self._subclass return self._subclass
def __str__(self): def __str__(self):
return f'<{self._subclass.name} -> {self._base.name}>' return f'<{type(self).__name__} {self.is_first} {self._subclass.name} -> {self._base.name}>'
def __repr__(self): def __repr__(self):
return f'<{self._subclass.name} -> {self._base.name}>' return f'<{type(self).__name__} {self.is_first} {self._subclass.name} -> {self._base.name}>'

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

@ -34,7 +34,8 @@ 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 highest_y = self._padding
for base in base_sub_map: for base in base_sub_map:
subclasses = base_sub_map[base] subclasses = base_sub_map[base]
@ -43,6 +44,7 @@ class UmletCreatorService(UmletCreatorABC):
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:
if sub_class not in self._moved_classes:
sub_class.position.x = base.position.x sub_class.position.x = base.position.x
sub_class.position.y = base.position.y sub_class.position.y = base.position.y
@ -70,16 +72,15 @@ class UmletCreatorService(UmletCreatorABC):
if cls in self._moved_classes: if cls in self._moved_classes:
continue continue
if cls.position.y <= last_base.y: new_x = last_base.x
cls.position.y = last_base.y
new_x = last_base.x + self._padding
if new_x <= self._settings.max_pixel_x: if new_x <= self._settings.max_pixel_x:
cls.position.x = new_x cls.position.x = new_x
last_base.x = cls.position.x + cls.dimension.width last_base.x = new_x + cls.dimension.width + self._padding
cls.position.y = last_base.y
else: else:
last_base.x = self._padding cls.position.x = self._padding
last_base.y = highest_y + self._padding * 2 cls.position.y = highest_y + self._padding * 2
last_base = cls.position
if cls.position.y + cls.dimension.height > highest_y: if cls.position.y + cls.dimension.height > highest_y:
highest_y = cls.position.y + cls.dimension.height highest_y = cls.position.y + cls.dimension.height