Skip to content

Commit 58240c3

Browse files
author
Humberto Sanchez II
committed
<type>[optional scope]: <Handle rest of Ogl Object>
[ * Text and Notes are important * Fix bug for Text IDs * OglText must untangle a PyutText not a PyutNote ] [#67]
1 parent b0760ff commit 58240c3

File tree

9 files changed

+359
-49
lines changed

9 files changed

+359
-49
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
2+
from typing import Dict
3+
from typing import cast
4+
5+
from unittest import TestSuite
6+
from unittest import main as unitTestMain
7+
8+
from untangle import Element
9+
from untangle import parse
10+
11+
from ogl.OglNote import OglNote
12+
13+
from untanglepyut.XmlVersion import XmlVersion
14+
15+
from untanglepyut.Types import UntangledOglNotes
16+
17+
from untanglepyut.UnTangleOglNotes import UnTangleOglNotes
18+
19+
20+
from tests.TestBase import TestBase
21+
22+
V11_MANY_NOTES_DOCUMENT: str = """
23+
<PyutDocument type="CLASS_DIAGRAM" title="Class Diagram" scrollPositionX="0" scrollPositionY="0" pixelsPerUnitX="20" pixelsPerUnitY="20">
24+
<OglNote width="100" height="50" x="231" y="191">
25+
<PyutNote id="1" content="I am note 1" filename="" />
26+
</OglNote>
27+
<OglNote width="100" height="50" x="563" y="296">
28+
<PyutNote id="2" content="I am note 2" filename="" />
29+
</OglNote>
30+
<OglNote width="100" height="50" x="196" y="483">
31+
<PyutNote id="3" content="I am note 3" filename="/tmp/Note3.txt" />
32+
</OglNote>
33+
</PyutDocument>
34+
"""
35+
36+
V10_MANY_NOTES_DOCUMENT: str = """
37+
<PyutDocument type="CLASS_DIAGRAM" title="Class Diagram" scrollPositionX="0" scrollPositionY="0" pixelsPerUnitX="20" pixelsPerUnitY="20">
38+
<GraphicNote width="123" height="56" x="75" y="75">
39+
<Note id="1" content="This is note 1" filename=""/>
40+
</GraphicNote>
41+
<GraphicNote width="128" height="57" x="250" y="75">
42+
<Note id="2" content="This is note 2" filename=""/>
43+
</GraphicNote>
44+
<GraphicNote width="211" height="53" x="100" y="175">
45+
<Note id="3" content="This is the note 3; I am fat note" filename="/tmp/Note3.txt"/>
46+
</GraphicNote>
47+
</PyutDocument>
48+
"""
49+
50+
51+
class TestUnTangleOglNotes(TestBase):
52+
"""
53+
"""
54+
@classmethod
55+
def setUpClass(cls):
56+
super().setUpClass()
57+
58+
def setUp(self):
59+
super().setUp()
60+
61+
def tearDown(self):
62+
super().tearDown()
63+
64+
def testUntangleV11Notes(self):
65+
self._runTest(V11_MANY_NOTES_DOCUMENT, XmlVersion.V11)
66+
67+
def testUntangleV10Notes(self):
68+
self._runTest(V10_MANY_NOTES_DOCUMENT, XmlVersion.V10)
69+
70+
def _runTest(self, pyutDocument: str, xmlVersion: XmlVersion):
71+
72+
root: Element = parse(pyutDocument)
73+
manyNotesDocument: Element = root.PyutDocument
74+
75+
unTangleOglNotes: UnTangleOglNotes = UnTangleOglNotes(xmlVersion=xmlVersion)
76+
77+
unTangledNotes: UntangledOglNotes = unTangleOglNotes.unTangle(pyutDocument=manyNotesDocument)
78+
79+
self.assertEqual(3, len(unTangledNotes), 'Note count mismatch')
80+
81+
noteDict: Dict[int, OglNote] = {}
82+
83+
for note in unTangledNotes:
84+
oglNote: OglNote = cast(OglNote, note)
85+
86+
noteDict[oglNote.pyutObject.id] = oglNote
87+
88+
noteWithFileName: OglNote = noteDict[3]
89+
90+
self.assertEqual('/tmp/Note3.txt', noteWithFileName.pyutObject.fileName)
91+
92+
93+
def suite() -> TestSuite:
94+
import unittest
95+
96+
testSuite: TestSuite = TestSuite()
97+
98+
testSuite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(testCaseClass=TestUnTangleOglNotes))
99+
100+
return testSuite
101+
102+
103+
if __name__ == '__main__':
104+
unitTestMain()
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
from typing import Dict
2+
from typing import cast
3+
from unittest import TestSuite
4+
from unittest import main as unitTestMain
5+
6+
from untangle import Element
7+
from untangle import parse
8+
9+
from ogl.OglText import OglText
10+
11+
from untanglepyut.Types import UntangledOglTexts
12+
from untanglepyut.UnTangleOglTexts import UnTangleOglTexts
13+
from untanglepyut.XmlVersion import XmlVersion
14+
15+
from tests.TestBase import TestBase
16+
17+
V10_MANY_TEXTS_DOCUMENT: str = """
18+
<PyutDocument type="CLASS_DIAGRAM" title="Lots Of Text" scrollPositionX="0" scrollPositionY="0" pixelsPerUnitX="20" pixelsPerUnitY="20">
19+
<GraphicText width="125" height="50" x="50" y="75" textSize="14" isBold="False" isItalicized="False" fontFamily="Swiss">
20+
<Text id="1" content="I am text 1"/>
21+
</GraphicText>
22+
<GraphicText width="125" height="50" x="75" y="150" textSize="14" isBold="False" isItalicized="False" fontFamily="Swiss">
23+
<Text id="2" content="I am text 2"/>
24+
</GraphicText>
25+
<GraphicText width="125" height="50" x="275" y="75" textSize="14" isBold="False" isItalicized="False" fontFamily="Swiss">
26+
<Text id="3" content="I am text 3"/>
27+
</GraphicText>
28+
</PyutDocument>
29+
"""
30+
31+
V11_MANY_TEXTS_DOCUMENT: str = """
32+
<PyutDocument type="CLASS_DIAGRAM" title="Class Diagram" scrollPositionX="0" scrollPositionY="0" pixelsPerUnitX="20" pixelsPerUnitY="20">
33+
<OglText width="125" height="50" x="50" y="25">
34+
<PyutText id="1" content="I am text 1" />
35+
</OglText>
36+
<OglText width="125" height="50" x="75" y="150">
37+
<PyutText id="2" content="I am text 2" />
38+
</OglText>
39+
<OglText width="125" height="50" x="150" y="250">
40+
<PyutText id="3" content="I am text 3" />
41+
</OglText>
42+
</PyutDocument>
43+
"""
44+
45+
46+
class TestUnTangleOglTexts(TestBase):
47+
"""
48+
"""
49+
50+
@classmethod
51+
def setUpClass(cls):
52+
super().setUpClass()
53+
54+
def setUp(self):
55+
super().setUp()
56+
57+
def tearDown(self):
58+
super().tearDown()
59+
60+
def testUntangleV10Texts(self):
61+
self._runTest(pyutDocument=V10_MANY_TEXTS_DOCUMENT, xmlVersion=XmlVersion.V10)
62+
63+
def testUntangleV11Texts(self):
64+
"""Another test"""
65+
pass
66+
self._runTest(pyutDocument=V11_MANY_TEXTS_DOCUMENT, xmlVersion=XmlVersion.V11)
67+
68+
def _runTest(self, pyutDocument: str, xmlVersion: XmlVersion):
69+
70+
root: Element = parse(pyutDocument)
71+
manyTextsDocument: Element = root.PyutDocument
72+
73+
unTangleOglTexts: UnTangleOglTexts = UnTangleOglTexts(xmlVersion=xmlVersion)
74+
unTangledTexts: UntangledOglTexts = unTangleOglTexts.unTangle(pyutDocument=manyTextsDocument)
75+
76+
self.assertEqual(3, len(unTangledTexts), 'Note count mismatch')
77+
78+
textDict: Dict[int, OglText] = {}
79+
80+
for text in unTangledTexts:
81+
oglText: OglText = cast(OglText, text)
82+
83+
textDict[oglText.pyutObject.id] = oglText
84+
85+
checkText: OglText = textDict[3]
86+
87+
self.assertEqual('I am text 3', checkText.pyutObject.content)
88+
89+
90+
def suite() -> TestSuite:
91+
92+
import unittest
93+
94+
testSuite: TestSuite = TestSuite()
95+
96+
testSuite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(testCaseClass=TestUnTangleOglTexts))
97+
98+
return testSuite
99+
100+
101+
if __name__ == '__main__':
102+
unitTestMain()

tests/untanglepyut/v11/TestUnTangleUseCaseDiagram.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
from unittest import TestSuite
33
from unittest import main as unitTestMain
44

5-
from ogl.OglActor import OglActor
6-
from ogl.OglUseCase import OglUseCase
75
from untangle import Element
86
from untangle import parse
97

8+
from ogl.OglActor import OglActor
9+
from ogl.OglUseCase import OglUseCase
10+
1011
from tests.TestBase import TestBase
12+
1113
from untanglepyut.Types import UntangledOglActors
1214
from untanglepyut.Types import UntangledOglUseCases
1315
from untanglepyut.XmlVersion import XmlVersion

untanglepyut/UnTangleOglNotes.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
2+
from logging import Logger
3+
from logging import getLogger
4+
5+
from untangle import Element
6+
7+
from pyutmodel.PyutNote import PyutNote
8+
9+
from ogl.OglNote import OglNote
10+
11+
from untanglepyut.BaseUnTangle import BaseUnTangle
12+
13+
from untanglepyut.Types import Elements
14+
from untanglepyut.Types import GraphicInformation
15+
from untanglepyut.Types import UntangledOglNotes
16+
from untanglepyut.Types import createUntangledOglNotes
17+
from untanglepyut.UnTanglePyut import UnTanglePyut
18+
19+
from untanglepyut import XmlConstants
20+
21+
from untanglepyut.XmlVersion import XmlVersion
22+
23+
24+
class UnTangleOglNotes(BaseUnTangle):
25+
def __init__(self, xmlVersion: XmlVersion):
26+
27+
super().__init__(xmlVersion=xmlVersion)
28+
29+
self.logger: Logger = getLogger(__name__)
30+
31+
self._untanglePyut: UnTanglePyut = UnTanglePyut(xmlVersion=xmlVersion)
32+
33+
if xmlVersion == XmlVersion.V10:
34+
self._elementOglNote: str = XmlConstants.V10_ELEMENT_NOTE
35+
else:
36+
self._elementOglNote = XmlConstants.V11_ELEMENT_NOTE
37+
38+
def unTangle(self, pyutDocument: Element) -> UntangledOglNotes:
39+
"""
40+
41+
Args:
42+
pyutDocument:
43+
44+
Returns: untangled OglNote objects if any exist, else an empty list
45+
"""
46+
47+
oglNotes: UntangledOglNotes = createUntangledOglNotes()
48+
graphicNotes: Elements = pyutDocument.get_elements(self._elementOglNote)
49+
50+
for graphicNote in graphicNotes:
51+
self.logger.debug(f'{graphicNote}')
52+
53+
graphicInformation: GraphicInformation = GraphicInformation.toGraphicInfo(graphicElement=graphicNote)
54+
oglNote: OglNote = OglNote(w=graphicInformation.width, h=graphicInformation.height)
55+
oglNote.SetPosition(x=graphicInformation.x, y=graphicInformation.y)
56+
self._updateModel(oglObject=oglNote, graphicInformation=graphicInformation)
57+
58+
pyutNote: PyutNote = self._untanglePyut.noteToPyutNote(graphicNote=graphicNote)
59+
oglNote.pyutObject = pyutNote
60+
oglNotes.append(oglNote)
61+
62+
return oglNotes

untanglepyut/UnTangleOglTexts.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
2+
from logging import Logger
3+
from logging import getLogger
4+
5+
from untangle import Element
6+
7+
from pyutmodel.PyutText import PyutText
8+
9+
from ogl.OglText import OglText
10+
11+
from untanglepyut import XmlConstants
12+
13+
from untanglepyut.BaseUnTangle import BaseUnTangle
14+
from untanglepyut.Types import GraphicInformation
15+
from untanglepyut.UnTanglePyut import UnTanglePyut
16+
17+
from untanglepyut.XmlVersion import XmlVersion
18+
19+
from untanglepyut.Types import Elements
20+
from untanglepyut.Types import UntangledOglTexts
21+
from untanglepyut.Types import createUntangledOglTexts
22+
23+
24+
class UnTangleOglTexts(BaseUnTangle):
25+
"""
26+
Yes, I know bad English
27+
"""
28+
def __init__(self, xmlVersion: XmlVersion):
29+
30+
super().__init__(xmlVersion=xmlVersion)
31+
32+
self.logger: Logger = getLogger(__name__)
33+
34+
self._untanglePyut: UnTanglePyut = UnTanglePyut(xmlVersion=xmlVersion)
35+
36+
if xmlVersion == XmlVersion.V10:
37+
self._elementOglText: str = XmlConstants.V10_ELEMENT_TEXT
38+
else:
39+
self._elementOglText = XmlConstants.V11_ELEMENT_TEXT
40+
41+
def unTangle(self, pyutDocument: Element) -> UntangledOglTexts:
42+
"""
43+
44+
Args:
45+
pyutDocument: The Element document
46+
47+
Returns: untangled OglText objects if any exist, else an empty list
48+
"""
49+
50+
oglTexts: UntangledOglTexts = createUntangledOglTexts()
51+
graphicTexts: Elements = pyutDocument.get_elements(self._elementOglText)
52+
53+
for graphicText in graphicTexts:
54+
self.logger.debug(f'{graphicText}')
55+
56+
graphicInformation: GraphicInformation = GraphicInformation.toGraphicInfo(graphicElement=graphicText)
57+
pyutText: PyutText = self._untanglePyut.textToPyutText(graphicText=graphicText)
58+
oglText: OglText = OglText(pyutText=pyutText, width=graphicInformation.width, height=graphicInformation.height)
59+
oglText.SetPosition(x=graphicInformation.x, y=graphicInformation.y)
60+
#
61+
# This is necessary if it is never added to a diagram
62+
# and immediately serialized
63+
#
64+
self._updateModel(oglObject=oglText, graphicInformation=graphicInformation)
65+
oglText.pyutText = pyutText
66+
oglTexts.append(oglText)
67+
68+
return oglTexts

untanglepyut/UnTanglePyut.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def textToPyutText(self, graphicText: Element) -> PyutText:
167167

168168
pyutText: PyutText = PyutText()
169169

170-
pyutText.id = textElement['id']
170+
pyutText.id = int(textElement[self._attrId])
171171

172172
rawContent: str = textElement['content']
173173
cleanContent: str = rawContent.replace(UnTanglePyut.END_OF_LINE_MARKER, osLineSep)
@@ -466,8 +466,8 @@ def _addPyutObjectAttributes(self, pyutElement: Element, pyutObject: PyutObject)
466466
Returns: The updated pyutObject as
467467
"""
468468

469-
pyutObject.id = int(pyutElement[self._attrId]) # TODO revisit this when we start using UUIDs
470-
pyutObject.name = pyutElement['name']
469+
pyutObject.id = int(pyutElement[self._attrId]) # TODO revisit this when we start using UUIDs
470+
pyutObject.name = pyutElement['name']
471471
pyutObject.fileName = pyutElement[self._attrFileName]
472472

473473
return pyutObject

0 commit comments

Comments
 (0)