1
1
2
2
from typing import List
3
+ from typing import Tuple
4
+ from typing import cast
3
5
4
6
from logging import Logger
5
7
from logging import getLogger
6
8
9
+ from ogl .OglActor import OglActor
10
+ from pyutmodelv2 .PyutLink import PyutLink
7
11
from untangle import Element
8
12
9
13
from pyutmodelv2 .PyutSDInstance import PyutSDInstance
12
16
from ogl .sd .OglSDInstance import OglSDInstance
13
17
from ogl .sd .OglSDMessage import OglSDMessage
14
18
19
+ from ogl .OglAssociation import OglAssociation
20
+
15
21
from untanglepyut import XmlConstants
22
+ from untanglepyut .Types import Elements
23
+
16
24
from untanglepyut .Types import GraphicInformation
25
+ from untanglepyut .Types import GraphicLinkAttributes
26
+ from untanglepyut .Types import LinkableOglObject
27
+ from untanglepyut .Types import LinkableOglObjects
17
28
from untanglepyut .Types import OglSDInstances
18
29
from untanglepyut .Types import OglSDMessages
19
-
20
- from untanglepyut .BaseUnTangle import BaseUnTangle
30
+ from untanglepyut .Types import UntangledOglActors
31
+ from untanglepyut .Types import UntangledOglLinks
32
+ from untanglepyut .Types import createLinkableOglObjects
21
33
from untanglepyut .Types import createOglSDInstances
22
34
from untanglepyut .Types import createOglSDMessages
35
+ from untanglepyut .Types import createUntangledOglActors
36
+ from untanglepyut .Types import createUntangledOglLinks
37
+ from untanglepyut .UnTangleOglLinks import UnTangleOglLinks
38
+
23
39
from untanglepyut .UnTanglePyut import ConvolutedPyutSDMessageInformation
24
40
from untanglepyut .UnTanglePyut import UnTanglePyut
41
+ from untanglepyut .UnTangleUseCaseDiagram import UnTangleUseCaseDiagram
42
+
25
43
from untanglepyut .XmlVersion import XmlVersion
26
44
45
+ from untanglepyut .BaseUnTangle import BaseUnTangle
46
+
27
47
28
48
class UnTangleSequenceDiagram (BaseUnTangle ):
29
49
@@ -33,17 +53,33 @@ def __init__(self, xmlVersion: XmlVersion):
33
53
34
54
self .logger : Logger = getLogger (__name__ )
35
55
36
- self ._oglSDInstances : OglSDInstances = createOglSDInstances ()
37
- self ._oglSDMessages : OglSDMessages = createOglSDMessages ()
56
+ self ._oglSDInstances : OglSDInstances = createOglSDInstances ()
57
+ self ._oglSDMessages : OglSDMessages = createOglSDMessages ()
58
+ self ._oglActors : UntangledOglActors = createUntangledOglActors ()
59
+ self ._oglLinks : UntangledOglLinks = createUntangledOglLinks ()
38
60
39
61
self ._untanglePyut : UnTanglePyut = UnTanglePyut (xmlVersion = xmlVersion )
62
+ #
63
+ # Need some help
64
+ #
65
+ self ._untangleUseCaseStuff : UnTangleUseCaseDiagram = UnTangleUseCaseDiagram (xmlVersion = xmlVersion )
66
+ self ._untangleLinks : UnTangleOglLinks = UnTangleOglLinks (xmlVersion = xmlVersion )
40
67
41
68
if xmlVersion == XmlVersion .V10 :
42
- self ._elementInstance : str = XmlConstants .V10_ELEMENT_INSTANCE
43
- self ._elementMessage : str = XmlConstants .V10_ELEMENT_MESSAGE
69
+ self ._elementInstance : str = XmlConstants .V10_ELEMENT_INSTANCE
70
+ self ._elementMessage : str = XmlConstants .V10_ELEMENT_MESSAGE
71
+ self ._elementOglLink : str = XmlConstants .V10_ELEMENT_OGL_LINK
72
+ self ._elementLink : str = XmlConstants .V10_ELEMENT_LINK
73
+ self ._attrSourceId : str = XmlConstants .V10_ATTR_SOURCE_ID
74
+ self ._attrDestinationId : str = XmlConstants .V10_ATTR_DESTINATION_ID
75
+
44
76
else :
45
- self ._elementInstance = XmlConstants .V11_ELEMENT_INSTANCE
46
- self ._elementMessage = XmlConstants .V11_ELEMENT_MESSAGE
77
+ self ._elementInstance = XmlConstants .V11_ELEMENT_INSTANCE
78
+ self ._elementMessage = XmlConstants .V11_ELEMENT_MESSAGE
79
+ self ._elementOglLink = XmlConstants .V11_ELEMENT_OGL_LINK
80
+ self ._elementLink = XmlConstants .V11_ELEMENT_LINK
81
+ self ._attrSourceId = XmlConstants .V11_ATTR_SOURCE_ID
82
+ self ._attrDestinationId = XmlConstants .V11_ATTR_DESTINATION_ID
47
83
48
84
def unTangle (self , pyutDocument : Element ):
49
85
"""
@@ -54,6 +90,14 @@ def unTangle(self, pyutDocument: Element):
54
90
self ._oglSDInstances = self ._untangleSDInstances (pyutDocument = pyutDocument )
55
91
self ._oglSDMessages = self ._untangleSDMessages (pyutDocument = pyutDocument )
56
92
93
+ self ._untangleUseCaseStuff .unTangle (pyutDocument = pyutDocument )
94
+
95
+ self ._oglActors = self ._untangleUseCaseStuff .oglActors
96
+
97
+ linkableOglObjects : LinkableOglObjects = self ._buildLinkableObjects ()
98
+ # self._oglLinks = self._untangleLinks.unTangle(pyutDocument=pyutDocument, linkableOglObjects=linkableOglObjects)
99
+ self ._oglLinks = self ._connectActorsToSDInstances (pyutDocument = pyutDocument , linkableOglObjects = linkableOglObjects )
100
+
57
101
@property
58
102
def oglSDInstances (self ) -> OglSDInstances :
59
103
return self ._oglSDInstances
@@ -62,10 +106,18 @@ def oglSDInstances(self) -> OglSDInstances:
62
106
def oglSDMessages (self ) -> OglSDMessages :
63
107
return self ._oglSDMessages
64
108
109
+ @property
110
+ def oglActors (self ) -> UntangledOglActors :
111
+ return self ._oglActors
112
+
113
+ @property
114
+ def oglLinks (self ) -> UntangledOglLinks :
115
+ return self ._oglLinks
116
+
65
117
def _untangleSDInstances (self , pyutDocument : Element ) -> OglSDInstances :
66
118
67
119
oglSDInstances : OglSDInstances = createOglSDInstances ()
68
- graphicSDInstances : List [Element ] = pyutDocument .get_elements (self ._elementInstance )
120
+ graphicSDInstances : List [Element ] = pyutDocument .get_elements (self ._elementInstance )
69
121
70
122
for graphicSDInstance in graphicSDInstances :
71
123
self .logger .debug (f'{ graphicSDInstance = } ' )
@@ -103,3 +155,99 @@ def _untangleSDMessages(self, pyutDocument: Element) -> OglSDMessages:
103
155
oglSDMessages [pyutSDMessage .id ] = oglSDMessage
104
156
105
157
return oglSDMessages
158
+
159
+ def _connectActorsToSDInstances (self , pyutDocument : Element , linkableOglObjects : LinkableOglObjects ) -> UntangledOglLinks :
160
+
161
+ oglLinks : UntangledOglLinks = createUntangledOglLinks ()
162
+
163
+ # US Agency for International Development must go away
164
+
165
+ graphicLinks : Elements = cast (Elements , pyutDocument .get_elements (self ._elementOglLink ))
166
+ for graphicLink in graphicLinks :
167
+ oglAssociation : OglAssociation = self ._createActorLink (graphicLink = graphicLink , linkableOglObjects = linkableOglObjects )
168
+ oglLinks .append (oglAssociation )
169
+
170
+ return oglLinks
171
+
172
+ def _createActorLink (self , graphicLink : Element , linkableOglObjects : LinkableOglObjects ) -> OglAssociation :
173
+ """
174
+
175
+ Args:
176
+ graphicLink:
177
+ linkableOglObjects:
178
+
179
+ Returns:
180
+ """
181
+
182
+ links : Elements = cast (Elements , graphicLink .get_elements (self ._elementLink ))
183
+ assert len (links ) == 1 , 'Should only ever be one'
184
+
185
+ singleLink : Element = links [0 ]
186
+ sourceId , dstId = self ._linkIDs (singleLink = singleLink )
187
+ try :
188
+ srcShape : LinkableOglObject = linkableOglObjects [sourceId ]
189
+ dstShape : OglSDInstance = linkableOglObjects [dstId ] # type: ignore
190
+ except KeyError as ke :
191
+ self .logger .error (f'{ linkableOglObjects = } ' )
192
+ self .logger .error (f'Developer Error -- { singleLink = } ' )
193
+ self .logger .error (f'Developer Error -- { sourceId = } { dstId = } KeyError index: { ke } ' )
194
+ return cast (OglAssociation , None )
195
+
196
+ assert isinstance (srcShape , OglActor ), 'Developer Error'
197
+ assert isinstance (dstShape , OglSDInstance ), 'Developer Error'
198
+
199
+ pyutLink : PyutLink = self ._untanglePyut .linkToPyutLink (singleLink , source = srcShape .pyutObject , destination = dstShape .pyutSDInstance )
200
+ gla : GraphicLinkAttributes = GraphicLinkAttributes .fromGraphicLink (xmlVersion = self ._xmlVersion , graphicLink = graphicLink )
201
+
202
+ self .logger .debug (f'graphicLink= { gla .srcX = } { gla .srcY = } { gla .dstX = } { gla .dstY = } { gla .spline = } ' )
203
+
204
+ oglAssociation : OglAssociation = OglAssociation (srcShape = srcShape ,
205
+ pyutLink = pyutLink ,
206
+ dstShape = dstShape ,
207
+ srcPos = (gla .srcX , gla .srcY ),
208
+ dstPos = (gla .dstX , gla .dstY )
209
+ )
210
+ # put the anchors at the right position
211
+ srcAnchor = oglAssociation .sourceAnchor
212
+ dstAnchor = oglAssociation .destinationAnchor
213
+ srcAnchor .SetPosition (gla .srcX , gla .srcY )
214
+ dstAnchor .SetPosition (gla .dstX , gla .dstY )
215
+
216
+ srcModel = srcAnchor .model
217
+ srcModel .SetPosition (x = gla .srcX , y = gla .srcY )
218
+ dstModel = dstAnchor .model
219
+ dstModel .SetPosition (x = gla .dstX , y = gla .dstY )
220
+ #
221
+ # Do not create association labels
222
+ #
223
+ return oglAssociation
224
+
225
+ def _linkIDs (self , singleLink : Element ) -> Tuple [int , int ]:
226
+ """
227
+ Extracts the source and destination IDs
228
+ Args:
229
+ singleLink:
230
+
231
+ Returns: A tuple of sourceId,destinationId
232
+ """
233
+
234
+ sourceId : int = int (singleLink [self ._attrSourceId ])
235
+ dstId : int = int (singleLink [self ._attrDestinationId ])
236
+
237
+ return sourceId , dstId
238
+
239
+ def _buildLinkableObjects (self ) -> LinkableOglObjects :
240
+ """
241
+
242
+ Returns: Linkable Objects Dictionary
243
+ """
244
+
245
+ linkableOglObjects : LinkableOglObjects = createLinkableOglObjects ()
246
+
247
+ for oglActor in self .oglActors :
248
+ linkableOglObjects [oglActor .pyutObject .id ] = oglActor
249
+
250
+ for pyutID , oglSDInstance in self .oglSDInstances .items ():
251
+ linkableOglObjects [pyutID ] = oglSDInstance # type: ignore
252
+
253
+ return linkableOglObjects
0 commit comments