Skip to content

Commit

Permalink
<Bug>[OglInterface2]: <Not yet fixed>
Browse files Browse the repository at this point in the history
[Added debug; renamed enum for clarity]

[#60]
  • Loading branch information
Humberto Sanchez II committed Feb 21, 2023
1 parent c8a1dc3 commit 681e685
Show file tree
Hide file tree
Showing 15 changed files with 267 additions and 65 deletions.
14 changes: 7 additions & 7 deletions miniogl/AttachmentLocation.py → miniogl/AttachmentSide.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from enum import Enum


class AttachmentLocation(Enum):
class AttachmentSide(Enum):
"""
Cardinal points, taken to correspond to the attachment points of the OglClass
"""
Expand All @@ -15,7 +15,7 @@ def __str__(self):
return str(self.name)

@staticmethod
def toEnum(strValue: str) -> 'AttachmentLocation':
def toEnum(strValue: str) -> 'AttachmentSide':
"""
Converts the input string to the attachment location
Args:
Expand All @@ -26,13 +26,13 @@ def toEnum(strValue: str) -> 'AttachmentLocation':
canonicalStr: str = strValue.strip(' ')

if canonicalStr == 'NORTH':
return AttachmentLocation.NORTH
return AttachmentSide.NORTH
elif canonicalStr == 'EAST':
return AttachmentLocation.EAST
return AttachmentSide.EAST
elif canonicalStr == 'WEST':
return AttachmentLocation.WEST
return AttachmentSide.WEST
elif canonicalStr == 'SOUTH':
return AttachmentLocation.SOUTH
return AttachmentSide.SOUTH
else:
print(f'Warning: did not recognize this attachment point: {canonicalStr}')
return AttachmentLocation.NORTH
return AttachmentSide.NORTH
18 changes: 9 additions & 9 deletions miniogl/LollipopLine.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from wx import RED_PEN
from wx import DC

from miniogl.AttachmentLocation import AttachmentLocation
from miniogl.AttachmentSide import AttachmentSide
from miniogl.Common import CommonLine
from miniogl.Common import CommonPoint

Expand All @@ -24,7 +24,7 @@ def __init__(self, destinationAnchor: SelectAnchorPoint):

super().__init__()

self.logger: Logger = getLogger(__name__)
self.lollipopLogger: Logger = getLogger(__name__)
self._destinationAnchor: SelectAnchorPoint = cast(SelectAnchorPoint, None)

if destinationAnchor is not None:
Expand All @@ -41,7 +41,7 @@ def destinationAnchor(self, theNewValue: SelectAnchorPoint):

def lineCoordinates(self) -> CommonLine:

attachmentPoint: AttachmentLocation = self._destinationAnchor.attachmentPoint
attachmentPoint: AttachmentSide = self._destinationAnchor.attachmentPoint

xDest, yDest = self._destinationAnchor.GetPosition()
circleX, circleY, xSrc, ySrc = self._calculateWhereToDrawLollipop(attachmentPoint, xDest, yDest)
Expand All @@ -56,11 +56,11 @@ def Draw(self, dc: DC, withChildren: bool = True):
dc.SetPen(BLACK_PEN)

xDest, yDest = self._destinationAnchor.GetPosition()
attachmentPoint: AttachmentLocation = self._destinationAnchor.attachmentPoint
attachmentPoint: AttachmentSide = self._destinationAnchor.attachmentPoint

circleX, circleY, xSrc, ySrc = self._calculateWhereToDrawLollipop(attachmentPoint, xDest, yDest)

self.logger.debug(f'Source: ({xSrc},{ySrc}) - Dest ({xDest},{yDest})')
self.lollipopLogger.debug(f'Source: ({xSrc},{ySrc}) - Dest ({xDest},{yDest})')
dc.DrawLine(xSrc, ySrc, xDest, yDest)
dc.DrawCircle(circleX, circleY, LollipopLine.LOLLIPOP_CIRCLE_RADIUS)

Expand All @@ -81,19 +81,19 @@ def _calculateWhereToDrawLollipop(self, attachmentPoint, xDest, yDest):
ratio = panel.currentZoom

lollipopLength: int = LollipopLine.LOLLIPOP_LINE_LENGTH * ratio
self.logger.debug(f'{lollipopLength}')
self.lollipopLogger.debug(f'({xDest},{yDest}) {lollipopLength=}')

if attachmentPoint == AttachmentLocation.EAST:
if attachmentPoint == AttachmentSide.EAST:
xSrc: int = int(xDest + lollipopLength)
ySrc: int = int(yDest)
circleX: int = int(xDest + lollipopLength)
circleY: int = int(yDest)
elif attachmentPoint == AttachmentLocation.WEST:
elif attachmentPoint == AttachmentSide.WEST:
xSrc = int(xDest - lollipopLength)
ySrc = int(yDest)
circleX = int(xDest - lollipopLength)
circleY = int(yDest)
elif attachmentPoint == AttachmentLocation.NORTH:
elif attachmentPoint == AttachmentSide.NORTH:
xSrc = int(xDest)
ySrc = int(yDest - lollipopLength)
circleX = int(xDest)
Expand Down
18 changes: 10 additions & 8 deletions miniogl/SelectAnchorPoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from miniogl.AnchorPoint import AnchorPoint
from miniogl.ShapeEventHandler import ShapeEventHandler

from miniogl.AttachmentLocation import AttachmentLocation
from miniogl.AttachmentSide import AttachmentSide


class SelectAnchorPoint(AnchorPoint, ShapeEventHandler):
Expand All @@ -22,7 +22,7 @@ class SelectAnchorPoint(AnchorPoint, ShapeEventHandler):
to attach something
"""
def __init__(self, x: int, y: int, attachmentPoint: AttachmentLocation, parent: Shape | None):
def __init__(self, x: int, y: int, attachmentSide: AttachmentSide, parent: Shape | None):
"""
Args:
Expand All @@ -33,17 +33,19 @@ def __init__(self, x: int, y: int, attachmentPoint: AttachmentLocation, parent:
super().__init__(x, y, parent)

self.logger: Logger = getLogger(__name__)
self._attachmentPoint: AttachmentLocation = attachmentPoint
self._attachmentSide: AttachmentSide = attachmentSide
self._pen: Pen = RED_PEN
self.SetDraggable(True) # So it sticks on OglClass resize; But now the user can move it !!
self.SetStayInside(True)
self.SetDraggable(False) # So it sticks on OglClass resize; But now the user can move it !!
self.SetStayOnBorder(True)

@property
def attachmentPoint(self) -> AttachmentLocation:
return self._attachmentPoint
def attachmentPoint(self) -> AttachmentSide:
return self._attachmentSide

@attachmentPoint.setter
def attachmentPoint(self, newValue: AttachmentLocation):
self._attachmentPoint = newValue
def attachmentPoint(self, newValue: AttachmentSide):
self._attachmentSide = newValue

def setYouAreTheSelectedAnchor(self):
self._pen = BLACK_PEN
Expand Down
12 changes: 6 additions & 6 deletions ogl/OglInterface2.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from wx import Font

from miniogl.Common import Common
from miniogl.AttachmentLocation import AttachmentLocation
from miniogl.AttachmentSide import AttachmentSide
from miniogl.SelectAnchorPoint import SelectAnchorPoint
from miniogl.LollipopLine import LollipopLine

Expand Down Expand Up @@ -154,26 +154,26 @@ def _isSameId(self, other):
def _determineInterfaceNamePosition(self, destinationAnchor: SelectAnchorPoint, pixelSize: Tuple[int, int], textSize: Tuple[int, int]) -> OglPosition:

oglPosition: OglPosition = OglPosition()
attachmentPoint: AttachmentLocation = destinationAnchor.attachmentPoint
attachmentPoint: AttachmentSide = destinationAnchor.attachmentPoint

x, y = destinationAnchor.GetPosition()

fWidth, fHeight = pixelSize
tWidth, tHeight = textSize

if attachmentPoint == AttachmentLocation.NORTH:
if attachmentPoint == AttachmentSide.NORTH:
y -= (LollipopLine.LOLLIPOP_LINE_LENGTH + (LollipopLine.LOLLIPOP_CIRCLE_RADIUS * 2) + OglInterface2.ADJUST_AWAY_FROM_IMPLEMENTOR)
x -= (tWidth // 2)
oglPosition.x = x
oglPosition.y = y

elif attachmentPoint == AttachmentLocation.SOUTH:
elif attachmentPoint == AttachmentSide.SOUTH:
y += (LollipopLine.LOLLIPOP_LINE_LENGTH + LollipopLine.LOLLIPOP_CIRCLE_RADIUS + OglInterface2.ADJUST_AWAY_FROM_IMPLEMENTOR)
x -= (tWidth // 2)
oglPosition.x = x
oglPosition.y = y

elif attachmentPoint == AttachmentLocation.WEST:
elif attachmentPoint == AttachmentSide.WEST:
y = y - (fHeight * 2)
originalX: int = x
x = x - LollipopLine.LOLLIPOP_LINE_LENGTH - (tWidth // 2)
Expand All @@ -182,7 +182,7 @@ def _determineInterfaceNamePosition(self, destinationAnchor: SelectAnchorPoint,
oglPosition.x = x
oglPosition.y = y

elif attachmentPoint == AttachmentLocation.EAST:
elif attachmentPoint == AttachmentSide.EAST:
y = y - (fHeight * 2)
x = x + round(LollipopLine.LOLLIPOP_LINE_LENGTH * 0.8)
oglPosition.x = x
Expand Down
24 changes: 12 additions & 12 deletions ogl/OglLink.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from miniogl.LineShape import LineShape
from miniogl.Shape import Shape
from miniogl.ShapeEventHandler import ShapeEventHandler
from miniogl.AttachmentLocation import AttachmentLocation
from miniogl.AttachmentSide import AttachmentSide

from ogl.OglPosition import OglPosition

Expand Down Expand Up @@ -83,16 +83,16 @@ def __init__(self, srcShape, pyutLink, dstShape, srcPos=None, dstPos=None):

sw, sh = self._srcShape.GetSize()
dw, dh = self._destShape.GetSize()
if orient == AttachmentLocation.NORTH:
if orient == AttachmentSide.NORTH:
srcX, srcY = sw//2, 0
dstX, dstY = dw//2, dh
elif orient == AttachmentLocation.SOUTH:
elif orient == AttachmentSide.SOUTH:
srcX, srcY = sw//2, sh
dstX, dstY = dw//2, 0
elif orient == AttachmentLocation.EAST:
elif orient == AttachmentSide.EAST:
srcX, srcY = sw, sh//2
dstX, dstY = 0, dh//2
elif orient == AttachmentLocation.WEST:
elif orient == AttachmentSide.WEST:
srcX, srcY = 0, sh//2
dstX, dstY = dw, dh//2

Expand Down Expand Up @@ -142,7 +142,7 @@ def __init__(self, srcShape, pyutLink, dstShape, srcPos=None, dstPos=None):
self._link = PyutLink()

@staticmethod
def getOrient(srcX, srcY, destX, destY) -> AttachmentLocation:
def getOrient(srcX, srcY, destX, destY) -> AttachmentSide:
"""
Giving a source and destination, returns where the destination
is located according to the source.
Expand All @@ -156,18 +156,18 @@ def getOrient(srcX, srcY, destX, destY) -> AttachmentLocation:
deltaY = srcY - destY
if deltaX > 0: # dest is not east
if deltaX > abs(deltaY): # dest is west
return AttachmentLocation.WEST
return AttachmentSide.WEST
elif deltaY > 0:
return AttachmentLocation.NORTH
return AttachmentSide.NORTH
else:
return AttachmentLocation.SOUTH
return AttachmentSide.SOUTH
else: # dest is not west
if -deltaX > abs(deltaY): # dest is east
return AttachmentLocation.EAST
return AttachmentSide.EAST
elif deltaY > 0:
return AttachmentLocation.NORTH
return AttachmentSide.NORTH
else:
return AttachmentLocation.SOUTH
return AttachmentSide.SOUTH

@property
def sourceShape(self):
Expand Down
2 changes: 1 addition & 1 deletion ogl/ui/DiagramPreferencesPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def _onCenterDiagramViewChanged(self, event: CommandEvent):
def _onShowParametersChanged(self, event: CommandEvent):
newValue: bool = event.IsChecked()
self._preferences.showParameters = newValue

def _onGridLineColorSelectionChanged(self, event: CommandEvent):

colorValue: str = event.GetString()
Expand Down
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="ogl",
version="0.70.0",
version="0.70.10",
author='Humberto A. Sanchez II',
author_email='[email protected]',
maintainer='Humberto A. Sanchez II',
Expand Down
48 changes: 48 additions & 0 deletions tests/demo/DemoEventEngine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

from typing import Callable

from logging import Logger
from logging import getLogger

from enum import Enum

from wx import PostEvent
from wx import PyEventBinder
from wx import Window

from wx.lib.newevent import NewEvent


SetStatusTextEvent, EVT_SET_STATUS_TEXT = NewEvent()


class DemoEventType(Enum):
SET_STATUS_TEXT = 'SetStatusText'


class DemoEventEngine:
def __init__(self, listeningWindow: Window):

self._listeningWindow: Window = listeningWindow
self.logger: Logger = getLogger(__name__)

def registerListener(self, event: PyEventBinder, callback: Callable):
self._listeningWindow.Bind(event, callback)

def sendEvent(self, eventType: DemoEventType, **kwargs):
"""
Args:
eventType:
**kwargs:
"""
match eventType:
case DemoEventType.SET_STATUS_TEXT:
self._sendSetStatusTextEvent(**kwargs)
case _:
self.logger.warning(f'Unknown Demo Event Type: {eventType}')

def _sendSetStatusTextEvent(self, **kwargs):

statusMessage: str = kwargs['statusMessage']
eventToPost: SetStatusTextEvent = SetStatusTextEvent(statusMessage=statusMessage) # type: ignore
PostEvent(dest=self._listeningWindow, event=eventToPost)
Loading

0 comments on commit 681e685

Please sign in to comment.