@@ -13,14 +13,14 @@ def createLabel(self, text):
13
13
14
14
def updatePath (self ):
15
15
pass
16
-
16
+
17
17
def removeLabels (self ):
18
18
pass
19
-
19
+
20
20
def restoreLabels (self ):
21
21
pass
22
-
23
-
22
+
23
+
24
24
class AssociationConnectionItem (IConnectionItem ):
25
25
def __init__ (
26
26
self ,
@@ -31,23 +31,23 @@ def __init__(
31
31
parent = None
32
32
):
33
33
super ().__init__ (parent )
34
-
34
+
35
35
pen = QPen (QColor (0 , 255 , 0 ), 2 ) # Green color with 2-pixel thickness
36
36
self .setPen (pen )
37
-
37
+
38
38
self .setZValue (0 ) # Ensure connection items are behind rect items
39
-
39
+
40
40
self .showAssociationFlag = False
41
-
41
+
42
42
self .startItem = startItem
43
43
self .endItem = endItem
44
44
self .scene = scene
45
-
45
+
46
46
self .startItem .addConnection (self )
47
47
self .endItem .addConnection (self )
48
-
48
+
49
49
if self .startItem .assetType != 'Attacker' and self .endItem .assetType != 'Attacker' :
50
-
50
+
51
51
self .associationDetails = selectedAssociationText .split ("-->" )
52
52
assocLeftField = self .associationDetails [0 ]
53
53
assocMiddleName = self .associationDetails [1 ]
@@ -58,9 +58,9 @@ def __init__(
58
58
self .labelAssocLeftField = self .createLabel (assocLeftField .split ("." )[1 ])
59
59
self .labelAssocMiddleName = self .createLabel (assocMiddleName )
60
60
self .labelAssocRightField = self .createLabel (assocRightField .split ("." )[1 ])
61
-
61
+
62
62
else :
63
-
63
+
64
64
#Need to check who is attacker and get the name of target and attackStep Name
65
65
# Assumption is Both are not 'Attacker'
66
66
if self .startItem .assetType == 'Attacker' :
@@ -69,15 +69,15 @@ def __init__(
69
69
else :
70
70
attacker = self .endItem .attackerAttachment
71
71
target = str (self .startItem .assetName )
72
-
72
+
73
73
#selectedAssociationText is representing 'AttackStep' name
74
74
attacker .entry_points .append (target + ' -> ' + selectedAssociationText )
75
75
self .labelAssocLeftField = self .createLabel ("" )
76
76
self .labelAssocMiddleName = self .createLabel (selectedAssociationText )
77
77
self .labelAssocRightField = self .createLabel ("" )
78
-
79
-
80
-
78
+
79
+
80
+
81
81
self .updatePath ()
82
82
83
83
def createLabel (self , text ):
@@ -104,7 +104,7 @@ def updatePath(self):
104
104
self .startPos = self .startItem .sceneBoundingRect ().center ()
105
105
self .endPos = self .endItem .sceneBoundingRect ().center ()
106
106
self .setLine (QLineF (self .startPos , self .endPos ))
107
-
107
+
108
108
labelAssocLeftFieldPos = self .line ().pointAt (0.2 )
109
109
self .labelAssocLeftField .setPos (labelAssocLeftFieldPos - QPointF (self .labelAssocLeftField .boundingRect ().width () / 2 , self .labelAssocLeftField .boundingRect ().height () / 2 ))
110
110
@@ -113,9 +113,9 @@ def updatePath(self):
113
113
114
114
labelAssocRightFieldPos = self .line ().pointAt (0.8 )
115
115
self .labelAssocRightField .setPos (labelAssocRightFieldPos - QPointF (self .labelAssocRightField .boundingRect ().width () / 2 , self .labelAssocRightField .boundingRect ().height () / 2 ))
116
-
116
+
117
117
# print("isAssociationVisibilityChecked = "+ str(self.isAssociationVisibilityChecked))
118
-
118
+
119
119
self .labelAssocLeftField .setVisible (self .scene .getShowAssociationCheckBoxStatus ())
120
120
self .labelAssocRightField .setVisible (self .scene .getShowAssociationCheckBoxStatus ())
121
121
@@ -125,24 +125,24 @@ def calculateOffset(self, rect, label_pos, angle):
125
125
"""
126
126
offset_distance = 10 # Distance to move the label outside the rectangle
127
127
offset = QPointF ()
128
-
128
+
129
129
if angle < 90 or angle > 270 :
130
130
offset .setX (rect .width () / 2 + offset_distance )
131
131
else :
132
132
offset .setX (- (rect .width () / 2 + offset_distance ))
133
-
133
+
134
134
if angle < 180 :
135
135
offset .setY (rect .height () / 2 + offset_distance )
136
136
else :
137
137
offset .setY (- (rect .height () / 2 + offset_distance ))
138
-
138
+
139
139
return offset
140
-
140
+
141
141
def removeLabels (self ):
142
142
self .scene .removeItem (self .labelAssocLeftField )
143
143
self .scene .removeItem (self .labelAssocMiddleName )
144
144
self .scene .removeItem (self .labelAssocRightField )
145
-
145
+
146
146
def restoreLabels (self ):
147
147
self .scene .addItem (self .labelAssocLeftField )
148
148
self .scene .addItem (self .labelAssocMiddleName )
@@ -151,7 +151,6 @@ def restoreLabels(self):
151
151
def delete (self ):
152
152
self .removeLabels ()
153
153
self .scene .removeItem (self )
154
-
155
154
156
155
157
156
class EntrypointConnectionItem (IConnectionItem ):
@@ -193,8 +192,8 @@ def createLabel(self, text):
193
192
labelGroup = self .scene .createItemGroup ([labelBackground , label ])
194
193
labelGroup .setZValue (1 ) # Ensure labels are above the line
195
194
196
- return labelGroup
197
-
195
+ return labelGroup
196
+
198
197
def updatePath (self ):
199
198
"""
200
199
Draws a straight line from the start to end items and updates label positions.
0 commit comments