diff --git a/src/untanglepyut/UnTangleOglLinks.py b/src/untanglepyut/UnTangleOglLinks.py index 896bc76..7027e71 100644 --- a/src/untanglepyut/UnTangleOglLinks.py +++ b/src/untanglepyut/UnTangleOglLinks.py @@ -218,11 +218,8 @@ def _graphicLollipopToOglInterface(self, graphicLollipop: Element, linkableOglOb assert len(linkableOglObjects) != 0, 'Developer forgot to create dictionary' - # - # TODO: Do not use these x,y positions; They are diagram relative - # - # x: int = int(graphicLollipop['x']) - # y: int = int(graphicLollipop['y']) + x: int = int(graphicLollipop['x']) + y: int = int(graphicLollipop['y']) attachmentLocationStr: str = graphicLollipop['attachmentPoint'] attachmentSide: AttachmentSide = AttachmentSide.toEnum(attachmentLocationStr) @@ -231,13 +228,19 @@ def _graphicLollipopToOglInterface(self, graphicLollipop: Element, linkableOglOb pyutInterface: PyutInterface = self._untanglePyut.interfaceToPyutInterface(oglInterface2=graphicLollipop) - oglClass: OglClass = self._getOglClassFromName(pyutInterface.implementors[0], linkableOglObjects) + self.logger.debug(f'{pyutInterface.name} {pyutInterface.id=} {pyutInterface.implementors=}') + + # oglClass: OglClass = self._getOglClassFromName(pyutInterface.implementors[0], linkableOglObjects) + + oglClass: OglClass = self._determineAttachedToClass(x=x, y=y, linkableOglObjects=linkableOglObjects) oglPosition: OglPosition = self._determineAttachmentPoint(attachmentSide, oglClass) - self.logger.debug(f'{oglPosition.x=},{oglPosition.y=}') + + self.logger.debug(f'{oglClass.id=} {oglPosition.x=} {oglPosition.y=}') anchorPoint: SelectAnchorPoint = SelectAnchorPoint(x=oglPosition.x, y=oglPosition.y, attachmentSide=attachmentSide, parent=oglClass) oglInterface2: OglInterface2 = OglInterface2(pyutInterface=pyutInterface, destinationAnchor=anchorPoint) + self.logger.debug(f'{oglInterface2.id=} {oglInterface2.destinationAnchor=}') return oglInterface2 def _getOglClassFromName(self, className: str, linkableOglObjects: LinkableOglObjects) -> OglClass: @@ -377,3 +380,26 @@ def _createALabel(self, parentAssociation: OglAssociation, graphicLink: Element, oglAssociationLabel: OglAssociationLabel = OglAssociationLabel(x=x, y=y, text=updatedLabelText, parent=parentAssociation) return oglAssociationLabel + + def _determineAttachedToClass(self, x: int, y: int, linkableOglObjects: LinkableOglObjects) -> OglClass: + """ + I cannot store a pointer to the class the lollipop is attached to. However, I need to know the lollipop's + parent because of + Args: + x: + y: + linkableOglObjects: + + Returns: The OglClass that the lollipop is attached to + """ + + foundClass: OglClass = cast(OglClass, None) + + for linkableObject in linkableOglObjects.values(): + oglClass: OglClass = cast(OglClass, linkableObject) + if oglClass.Inside(x=x, y=y) is True: + foundClass = oglClass + break + + assert foundClass is not None, 'XML must be in error' + return foundClass diff --git a/tests/resources/v11/LollipopInterfaceMultiImplementor.xml b/tests/resources/v11/LollipopInterfaceMultiImplementor.xml new file mode 100644 index 0000000..f517a99 --- /dev/null +++ b/tests/resources/v11/LollipopInterfaceMultiImplementor.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/untanglepyut/TestUnTangler.py b/tests/untanglepyut/TestUnTangler.py new file mode 100644 index 0000000..ef6fdde --- /dev/null +++ b/tests/untanglepyut/TestUnTangler.py @@ -0,0 +1,80 @@ + +from typing import cast + +from unittest import TestSuite +from unittest import main as unitTestMain + +from codeallybasic.UnitTestBase import UnitTestBase + +from pyutmodelv2.PyutInterface import PyutInterface + +from ogl.OglInterface2 import OglInterface2 + +from untanglepyut.Types import Document +from untanglepyut.Types import DocumentTitle +from untanglepyut.Types import Documents +from untanglepyut.Types import UntangledOglLinks + +from untanglepyut.UnTangler import UnTangler +from untanglepyut.XmlVersion import XmlVersion + +from tests.ProjectTestBase import TestBase + + +class TestUnTangler(TestBase): + """ + Auto generated by the one and only: + Gato Malo – Humberto A. Sanchez II + Generated: 06 June 2024 + """ + + @classmethod + def setUpClass(cls): + super().setUpClass() + + def setUp(self): + super().setUp() + + def tearDown(self): + super().tearDown() + + def testLollipopInterfaceMultiImplementor(self): + + fqFileName: str = UnitTestBase.getFullyQualifiedResourceFileName(package=TestBase.V11_TEST_FILES_PACKAGE_NAME, + fileName='LollipopInterfaceMultiImplementor.xml') + untangler: UnTangler = UnTangler(xmlVersion=XmlVersion.V11) + + untangler.untangleFile(fqFileName=fqFileName) + + documents: Documents = untangler.documents + + self.assertTrue(len(documents) == 1, 'Should only have a single document') + + document: Document = documents[DocumentTitle('SampleIFace')] + + untangledOglLinks: UntangledOglLinks = document.oglLinks + + self.assertTrue(len(untangledOglLinks) == 2, 'Not enough lollipops') + + interface1: OglInterface2 = cast(OglInterface2, untangledOglLinks[0]) + interface2: OglInterface2 = cast(OglInterface2, untangledOglLinks[1]) + + pyutInterface1: PyutInterface = interface1.pyutInterface + pyutInterface2: PyutInterface = interface2.pyutInterface + + self.assertEqual(pyutInterface1.name, pyutInterface2.name, 'Names should match') + self.assertEqual(pyutInterface1.id, pyutInterface2.id, 'IDs should match') + + +def suite() -> TestSuite: + import unittest + + testSuite: TestSuite = TestSuite() + + testSuite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(testCaseClass=TestUnTangler)) + + return testSuite + + +if __name__ == '__main__': + unitTestMain()