Skip to content

Commit

Permalink
<Defect>[OglLinks]: <Create specific type of link>
Browse files Browse the repository at this point in the history
[Include unit test, Update version]

[optional footer(s)]
  • Loading branch information
Humberto Sanchez II committed Jul 18, 2022
1 parent a4ee8cd commit 91c45ad
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 4 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

setup(
name="untanglepyut",
version="0.2.0",
version="0.2.5",
author_email='[email protected]',
description='XML to Ogl Object Model',
long_description=README,
Expand Down
14 changes: 14 additions & 0 deletions tests/resources/SimpleInheritance.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<PyutProject version="10" CodePath="">
<PyutDocument type="CLASS_DIAGRAM" title="Simple" scrollPositionX="0" scrollPositionY="0" pixelsPerUnitX="20" pixelsPerUnitY="20">
<GraphicClass width="167" height="69" x="50" y="50">
<Class id="7" name="BaseClass" filename="" description="" showMethods="True" showFields="True" showStereotype="True" displayParameters="Unspecified"/>
</GraphicClass>
<GraphicClass width="161" height="69" x="50" y="275">
<Class id="8" name="SubClass" filename="" description="" showMethods="True" showFields="True" showStereotype="True" displayParameters="Unspecified"/>
</GraphicClass>
<GraphicLink srcX="130" srcY="275" dstX="130" dstY="118" spline="False">
<Link name="" type="INHERITANCE" cardSrc="" cardDestination="" bidir="False" sourceId="8" destId="7"/>
</GraphicLink>
</PyutDocument>
</PyutProject>
21 changes: 20 additions & 1 deletion tests/untanglepyut/TestUnTangler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from unittest import TestSuite
from unittest import main as unitTestMain

from ogl.OglInheritance import OglInheritance
from pkg_resources import resource_filename

from miniogl.ControlPoint import ControlPoint
Expand Down Expand Up @@ -40,7 +41,9 @@
DIAGRAM_NAME_1: DocumentTitle = DocumentTitle('Diagram-1')
DIAGRAM_NAME_2: DocumentTitle = DocumentTitle('Diagram-2')

ATM_DIAGRAM_NAME: DocumentTitle = DocumentTitle('Class Diagram')
ATM_DIAGRAM_NAME: DocumentTitle = DocumentTitle('Class Diagram')
SIMPLE_DIAGRAM_NAME: DocumentTitle = DocumentTitle('Simple')

TEST_XML_FILENAME: str = 'MultiDocumentProject.xml'


Expand Down Expand Up @@ -127,6 +130,22 @@ def testControlPointsGenerated(self):
controlPoint=oglLink.GetControlPoints()[0],
objectName=linkName)

def testSimpleInheritance(self):

fqFileName = resource_filename(TestBase.RESOURCES_PACKAGE_NAME, 'SimpleInheritance.xml')

untangler: UnTangler = UnTangler(fqFileName=fqFileName)

untangler.untangle()

singleDocument: Document = untangler.documents[SIMPLE_DIAGRAM_NAME]
oglLinks: UntangledOglLinks = singleDocument.oglLinks
self.assertEqual(1, len(oglLinks), 'There can be only one.')
self.assertTrue(isinstance(oglLinks[0], OglInheritance), 'Must be inheritance')
for oglLink in oglLinks:
self.logger.debug(f'{oglLink}')
self.assertEqual(PyutLinkType.INHERITANCE, oglLink.pyutObject.linkType)

def testCreateOglClassesForDiagram1(self):

self._testCreateClassesForDiagram(DIAGRAM_NAME_1, expectedCount=4)
Expand Down
54 changes: 52 additions & 2 deletions untanglepyut/UnTangler.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@
from miniogl.AttachmentLocation import AttachmentLocation
from miniogl.ControlPoint import ControlPoint
from miniogl.SelectAnchorPoint import SelectAnchorPoint
from ogl.OglAggregation import OglAggregation
from ogl.OglAssociation import OglAssociation

from ogl.OglClass import OglClass
from ogl.OglComposition import OglComposition
from ogl.OglInheritance import OglInheritance
from ogl.OglInterface import OglInterface
from ogl.OglInterface2 import OglInterface2
from ogl.OglLink import OglLink
from ogl.OglNoteLink import OglNoteLink

from pyutmodel.PyutClass import PyutClass
from pyutmodel.PyutDisplayParameters import PyutDisplayParameters
Expand Down Expand Up @@ -285,8 +291,12 @@ def _graphicLinkToOglLink(self, graphicLink: Element, oglClassDictionary: OglCla
assert dstShape is not None, 'Missing destination shape, invalid XML'

pyutLink: PyutLink = self._linkToPyutLink(singleLink, source=srcShape.pyutObject, destination=dstShape.pyutObject)
oglLink: OglLink = OglLink(srcShape=srcShape, pyutLink=pyutLink, dstShape=dstShape, srcPos=(srcX, srcY), dstPos=(dstX, dstY))

# oglLink: OglLink = OglLink(srcShape=srcShape, pyutLink=pyutLink, dstShape=dstShape, srcPos=(srcX, srcY), dstPos=(dstX, dstY))
oglLink: OglLink = self._createOglLink(srcShape=srcShape, pyutLink=pyutLink, destShape=dstShape,
linkType=pyutLink.linkType,
srcPos=(srcX, srcY),
dstPos=(dstX, dstY)
)
controlPoints: UntangledControlPoints = self._generateControlPoints(graphicLink=graphicLink)

parent = oglLink.GetSource().GetParent()
Expand Down Expand Up @@ -427,6 +437,46 @@ def _buildOglClassDictionary(self, oglClasses: UntangledOglClasses):

return oglClassDictionary

# noinspection PyUnusedLocal
def _createOglLink(self, srcShape, pyutLink, destShape, linkType: PyutLinkType, srcPos=None, dstPos=None):
"""
Used to get a OglLink of the given linkType.
Args:
srcShape: Source shape
pyutLink: Conceptual links associated with the graphical links.
destShape: Destination shape
linkType: The linkType of the link (OGL_INHERITANCE, ...)
srcPos: source position
dstPos: destination position
Returns: The requested link
"""
if linkType == PyutLinkType.AGGREGATION:
return OglAggregation(srcShape, pyutLink, destShape)

elif linkType == PyutLinkType.COMPOSITION:
return OglComposition(srcShape, pyutLink, destShape)

elif linkType == PyutLinkType.INHERITANCE:
return OglInheritance(srcShape, pyutLink, destShape)

elif linkType == PyutLinkType.ASSOCIATION:
return OglAssociation(srcShape, pyutLink, destShape)

elif linkType == PyutLinkType.INTERFACE:
return OglInterface(srcShape, pyutLink, destShape)

elif linkType == PyutLinkType.NOTELINK:
return OglNoteLink(srcShape, pyutLink, destShape)

elif linkType == PyutLinkType.SD_MESSAGE:
assert False, 'Sequence Diagram Messages not supported'
# return OglSDMessage(srcShape=srcShape, pyutSDMessage=pyutLink, dstShape=destShape)
else:
self.logger.error(f"Unknown OglLinkType: {linkType}")
return None

def _str2bool(self, strValue: str) -> bool:
return strValue.lower() in ("yes", "true", "t", "1", 'True')

Expand Down

0 comments on commit 91c45ad

Please sign in to comment.