Skip to content

Commit

Permalink
<Release>[Hot Patch]: Version update for release
Browse files Browse the repository at this point in the history
MiniDomToOglV10 had bug when trying to interpret floats as integers
Need more organization

[#257]
  • Loading branch information
hasii2011 committed Jan 21, 2021
1 parent 7e2818e commit 98836f1
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 47 deletions.
21 changes: 21 additions & 0 deletions src/org/pyut/PyutUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,27 @@ def __init__(self):

PyutUtils.logger = getLogger(__name__)

@staticmethod
def strFloatToInt(floatValue: str) -> int:
"""
Args:
floatValue:
Returns: An integer value
"""
if floatValue is not None and floatValue != '':
try:
integerValue: int = int(float(floatValue))
except ValueError:
PyutUtils.clsLogger.warning(f'Bad float value: {floatValue}')
integerValue: int = 0
else:
integerValue: int = 0

return integerValue

@staticmethod
def extractFileName(fullPath: str) -> str:
"""
Expand Down
88 changes: 44 additions & 44 deletions src/org/pyut/persistence/converters/MiniDomToOglV10.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

from org.pyut.persistence.converters.PyutXmlConstants import PyutXmlConstants

from org.pyut.PyutUtils import PyutUtils
from org.pyut.PyutUtils import PyutUtils as PyU

from org.pyut.ui.UmlFrame import UmlFrame

Expand Down Expand Up @@ -105,8 +105,8 @@ def getOglClasses(self, xmlOglClasses: NodeList) -> OglClasses:
pyutClass: PyutClass = PyutClass()

# Some old files had float sizes and positions
height: int = int(float(xmlOglClass.getAttribute(PyutXmlConstants.ATTR_HEIGHT)))
width: int = int(float(xmlOglClass.getAttribute(PyutXmlConstants.ATTR_WIDTH)))
height: int = PyU.strFloatToInt(xmlOglClass.getAttribute(PyutXmlConstants.ATTR_HEIGHT))
width: int = PyU.strFloatToInt(xmlOglClass.getAttribute(PyutXmlConstants.ATTR_WIDTH))

oglClass: OglClass = OglClass(pyutClass, width, height)

Expand All @@ -119,11 +119,11 @@ def getOglClasses(self, xmlOglClasses: NodeList) -> OglClasses:
pyutClass.setStereotype(getPyutStereotype(xmlClass.getAttribute(PyutXmlConstants.ATTR_STEREOTYPE)))

# adding display properties (cd)
value = PyutUtils.secureBoolean(xmlClass.getAttribute(PyutXmlConstants.ATTR_SHOW_STEREOTYPE))
value = PyU.secureBoolean(xmlClass.getAttribute(PyutXmlConstants.ATTR_SHOW_STEREOTYPE))
pyutClass.setShowStereotype(value)
value = PyutUtils.secureBoolean(xmlClass.getAttribute(PyutXmlConstants.ATTR_SHOW_METHODS))
value = PyU.secureBoolean(xmlClass.getAttribute(PyutXmlConstants.ATTR_SHOW_METHODS))
pyutClass.showMethods = value
value = PyutUtils.secureBoolean(xmlClass.getAttribute(PyutXmlConstants.ATTR_SHOW_FIELDS))
value = PyU.secureBoolean(xmlClass.getAttribute(PyutXmlConstants.ATTR_SHOW_FIELDS))
pyutClass.showFields = value

displayParametersStr: str = xmlClass.getAttribute(PyutXmlConstants.ATTR_DISPLAY_PARAMETERS)
Expand All @@ -141,8 +141,8 @@ def getOglClasses(self, xmlOglClasses: NodeList) -> OglClasses:
pyutClass.fields = self._getFields(xmlClass)

# Adding properties necessary to place shape on a diagram frame
x = int(float(xmlOglClass.getAttribute(PyutXmlConstants.ATTR_X)))
y = int(float(xmlOglClass.getAttribute(PyutXmlConstants.ATTR_Y)))
x = PyU.strFloatToInt(xmlOglClass.getAttribute(PyutXmlConstants.ATTR_X))
y = PyU.strFloatToInt(xmlOglClass.getAttribute(PyutXmlConstants.ATTR_Y))

oglClass.SetPosition(x, y)

Expand Down Expand Up @@ -189,12 +189,12 @@ def getOglLinks(self, xmlOglLinks: NodeList, oglClasses: OglObjects) -> OglLinks
# src and dst anchor position
xmlLink: Element = cast(Element, xmlLink)

sx = PyutUtils.secureFloat(xmlLink.getAttribute(PyutXmlConstants.ATTR_LINK_SOURCE_ANCHOR_X))
sy = PyutUtils.secureFloat(xmlLink.getAttribute(PyutXmlConstants.ATTR_LINK_SOURCE_ANCHOR_Y))
dx = PyutUtils.secureFloat(xmlLink.getAttribute(PyutXmlConstants.ATTR_LINK_DESTINATION_ANCHOR_X))
dy = PyutUtils.secureFloat(xmlLink.getAttribute(PyutXmlConstants.ATTR_LINK_DESTINATION_ANCHOR_Y))
sx = PyU.strFloatToInt(xmlLink.getAttribute(PyutXmlConstants.ATTR_LINK_SOURCE_ANCHOR_X))
sy = PyU.strFloatToInt(xmlLink.getAttribute(PyutXmlConstants.ATTR_LINK_SOURCE_ANCHOR_Y))
dx = PyU.strFloatToInt(xmlLink.getAttribute(PyutXmlConstants.ATTR_LINK_DESTINATION_ANCHOR_X))
dy = PyU.strFloatToInt(xmlLink.getAttribute(PyutXmlConstants.ATTR_LINK_DESTINATION_ANCHOR_Y))

spline: bool = PyutUtils.secureBoolean(xmlLink.getAttribute(PyutXmlConstants.ATTR_SPLINE))
spline: bool = PyU.secureBoolean(xmlLink.getAttribute(PyutXmlConstants.ATTR_SPLINE))

# get the associated PyutLink
srcId, dstId, assocPyutLink = self._getPyutLink(xmlLink)
Expand Down Expand Up @@ -263,8 +263,8 @@ def getOglNotes(self, xmlOglNotes: NodeList) -> OglNotes:
pyutNote: PyutNote = PyutNote()

# Building OGL Note
height: int = int(xmlOglNote.getAttribute(PyutXmlConstants.ATTR_HEIGHT))
width: int = int(xmlOglNote.getAttribute(PyutXmlConstants.ATTR_WIDTH))
height: int = PyU.strFloatToInt(xmlOglNote.getAttribute(PyutXmlConstants.ATTR_HEIGHT))
width: int = PyU.strFloatToInt(xmlOglNote.getAttribute(PyutXmlConstants.ATTR_WIDTH))
oglNote = OglNote(pyutNote, width, height)

xmlNote: Element = xmlOglNote.getElementsByTagName(PyutXmlConstants.ELEMENT_MODEL_NOTE)[0]
Expand All @@ -279,8 +279,8 @@ def getOglNotes(self, xmlOglNotes: NodeList) -> OglNotes:
pyutNote.setFilename(xmlNote.getAttribute(PyutXmlConstants.ATTR_FILENAME))

# Adding properties necessary to place shape on a diagram frame
x: int = int(xmlOglNote.getAttribute(PyutXmlConstants.ATTR_X))
y: int = int(xmlOglNote.getAttribute(PyutXmlConstants.ATTR_Y))
x: int = PyU.strFloatToInt(xmlOglNote.getAttribute(PyutXmlConstants.ATTR_X))
y: int = PyU.strFloatToInt(xmlOglNote.getAttribute(PyutXmlConstants.ATTR_Y))

oglNote.SetPosition(x, y)
# Update the dictionary
Expand All @@ -306,19 +306,19 @@ def getOglTextShapes(self, xmlOglTextShapes: NodeList) -> OglTextShapes:
textSizeStr: str = xmlText.getAttribute(PyutXmlConstants.ATTR_TEXT_SIZE)
pyutText.textSize = int(textSizeStr)

value = PyutUtils.secureBoolean(xmlText.getAttribute(PyutXmlConstants.ATTR_IS_BOLD))
value = PyU.secureBoolean(xmlText.getAttribute(PyutXmlConstants.ATTR_IS_BOLD))
pyutText.isBold = value

value = PyutUtils.secureBoolean(xmlText.getAttribute(PyutXmlConstants.ATTR_IS_ITALICIZED))
value = PyU.secureBoolean(xmlText.getAttribute(PyutXmlConstants.ATTR_IS_ITALICIZED))
pyutText.isItalicized = value

width: int = int(xmlOglTextShape.getAttribute(PyutXmlConstants.ATTR_WIDTH))
height: int = int(xmlOglTextShape.getAttribute(PyutXmlConstants.ATTR_HEIGHT))
width: int = PyU.strFloatToInt(xmlOglTextShape.getAttribute(PyutXmlConstants.ATTR_WIDTH))
height: int = PyU.strFloatToInt(xmlOglTextShape.getAttribute(PyutXmlConstants.ATTR_HEIGHT))

oglText: OglText = OglText(pyutText=pyutText, width=width, height=height)

x: int = int(xmlOglTextShape.getAttribute(PyutXmlConstants.ATTR_X))
y: int = int(xmlOglTextShape.getAttribute(PyutXmlConstants.ATTR_Y))
x: int = PyU.strFloatToInt(xmlOglTextShape.getAttribute(PyutXmlConstants.ATTR_X))
y: int = PyU.strFloatToInt(xmlOglTextShape.getAttribute(PyutXmlConstants.ATTR_Y))

oglText.SetPosition(x=x, y=y)

Expand All @@ -342,8 +342,8 @@ def getOglActors(self, xmlOglActors: NodeList) -> OglActors:
pyutActor: PyutActor = PyutActor()

# Building OGL Actor
height: int = int(xmlOglActor.getAttribute(PyutXmlConstants.ATTR_HEIGHT))
width: int = int(xmlOglActor.getAttribute(PyutXmlConstants.ATTR_WIDTH))
height: int = PyU.strFloatToInt(xmlOglActor.getAttribute(PyutXmlConstants.ATTR_HEIGHT))
width: int = PyU.strFloatToInt(xmlOglActor.getAttribute(PyutXmlConstants.ATTR_WIDTH))
oglActor: OglActor = OglActor(pyutActor, width, height)

xmlActor: Element = xmlOglActor.getElementsByTagName(PyutXmlConstants.ELEMENT_MODEL_ACTOR)[0]
Expand All @@ -353,8 +353,8 @@ def getOglActors(self, xmlOglActors: NodeList) -> OglActors:
pyutActor.setFilename(xmlActor.getAttribute(PyutXmlConstants.ATTR_FILENAME))

# Adding properties necessary to place shape on a diagram frame
x = int(xmlOglActor.getAttribute(PyutXmlConstants.ATTR_X))
y = int(xmlOglActor.getAttribute(PyutXmlConstants.ATTR_Y))
x = PyU.strFloatToInt(xmlOglActor.getAttribute(PyutXmlConstants.ATTR_X))
y = PyU.strFloatToInt(xmlOglActor.getAttribute(PyutXmlConstants.ATTR_Y))
oglActor.SetPosition(x, y)

oglActors[pyutActor.getId()] = oglActor
Expand All @@ -378,8 +378,8 @@ def getOglUseCases(self, xmlOglUseCases: NodeList) -> OglUseCases:
pyutUseCase: PyutUseCase = PyutUseCase()

# Building OGL UseCase
height: int = int(xmlOglUseCase.getAttribute(PyutXmlConstants.ATTR_HEIGHT))
width: int = int(xmlOglUseCase.getAttribute(PyutXmlConstants.ATTR_WIDTH))
height: int = PyU.strFloatToInt(xmlOglUseCase.getAttribute(PyutXmlConstants.ATTR_HEIGHT))
width: int = PyU.strFloatToInt(xmlOglUseCase.getAttribute(PyutXmlConstants.ATTR_WIDTH))
oglUseCase = OglUseCase(pyutUseCase, width, height)

xmlUseCase: Element = xmlOglUseCase.getElementsByTagName(PyutXmlConstants.ELEMENT_MODEL_USE_CASE)[0]
Expand All @@ -388,8 +388,8 @@ def getOglUseCases(self, xmlOglUseCases: NodeList) -> OglUseCases:
pyutUseCase.setName(xmlUseCase.getAttribute(PyutXmlConstants.ATTR_NAME))
pyutUseCase.setFilename(xmlUseCase.getAttribute(PyutXmlConstants.ATTR_FILENAME))

x: int = int(xmlOglUseCase.getAttribute(PyutXmlConstants.ATTR_X))
y: int = int(xmlOglUseCase.getAttribute(PyutXmlConstants.ATTR_Y))
x: int = PyU.strFloatToInt(xmlOglUseCase.getAttribute(PyutXmlConstants.ATTR_X))
y: int = PyU.strFloatToInt(xmlOglUseCase.getAttribute(PyutXmlConstants.ATTR_Y))
oglUseCase.SetPosition(x, y)

oglUseCases[pyutUseCase.getId()] = oglUseCase
Expand Down Expand Up @@ -419,14 +419,14 @@ def getOglSDInstances(self, xmlOglSDInstances: NodeList, umlFrame: UmlFrame) ->
pyutSDInstance.setId(int(xmlSDInstance.getAttribute(PyutXmlConstants.ATTR_ID)))
pyutSDInstance.setInstanceName(xmlSDInstance.getAttribute(PyutXmlConstants.ATTR_INSTANCE_NAME))

lifeLineLength: int = PyutUtils.secureInteger(xmlSDInstance.getAttribute(PyutXmlConstants.ATTR_LIFE_LINE_LENGTH))
lifeLineLength: int = PyU.secureInteger(xmlSDInstance.getAttribute(PyutXmlConstants.ATTR_LIFE_LINE_LENGTH))
pyutSDInstance.setInstanceLifeLineLength(lifeLineLength)

# Adding OGL class to UML Frame
x: int = int(xmlOglSDInstance.getAttribute(PyutXmlConstants.ATTR_X))
y: int = int(xmlOglSDInstance.getAttribute(PyutXmlConstants.ATTR_Y))
w: int = int(xmlOglSDInstance.getAttribute(PyutXmlConstants.ATTR_WIDTH))
h: int = int(xmlOglSDInstance.getAttribute(PyutXmlConstants.ATTR_HEIGHT))
x: int = PyU.strFloatToInt(xmlOglSDInstance.getAttribute(PyutXmlConstants.ATTR_X))
y: int = PyU.strFloatToInt(xmlOglSDInstance.getAttribute(PyutXmlConstants.ATTR_Y))
w: int = PyU.strFloatToInt(xmlOglSDInstance.getAttribute(PyutXmlConstants.ATTR_WIDTH))
h: int = PyU.strFloatToInt(xmlOglSDInstance.getAttribute(PyutXmlConstants.ATTR_HEIGHT))
oglSDInstance.SetSize(w, h)
oglSDInstance.SetPosition(x, y)

Expand Down Expand Up @@ -457,8 +457,8 @@ def getOglSDMessages(self, xmlOglSDMessages: NodeList, oglSDInstances: OglSDInst

srcID: int = int(xmlPyutSDMessage.getAttribute(PyutXmlConstants.ATTR_SD_MESSAGE_SOURCE_ID))
dstID: int = int(xmlPyutSDMessage.getAttribute(PyutXmlConstants.ATTR_SD_MESSAGE_DESTINATION_ID))
srcTime: int = int(float(xmlPyutSDMessage.getAttribute(PyutXmlConstants.ATTR_SOURCE_TIME_LINE)))
dstTime: int = int(float(xmlPyutSDMessage.getAttribute(PyutXmlConstants.ATTR_DESTINATION_TIME_LINE)))
srcTime: int = PyU.strFloatToInt(xmlPyutSDMessage.getAttribute(PyutXmlConstants.ATTR_SOURCE_TIME_LINE))
dstTime: int = PyU.strFloatToInt(xmlPyutSDMessage.getAttribute(PyutXmlConstants.ATTR_DESTINATION_TIME_LINE))
srcOgl = oglSDInstances[srcID]
dstOgl = oglSDInstances[dstID]

Expand Down Expand Up @@ -593,8 +593,8 @@ def _generateControlPoints(self, link: Element) -> ControlPoints:
controlPoints: ControlPoints = cast(ControlPoints, [])

for controlPoint in link.getElementsByTagName(PyutXmlConstants.ELEMENT_MODEL_CONTROL_POINT):
x = PyutUtils.secureFloat(controlPoint.getAttribute(PyutXmlConstants.ATTR_X))
y = PyutUtils.secureFloat(controlPoint.getAttribute(PyutXmlConstants.ATTR_Y))
x = PyU.strFloatToInt(controlPoint.getAttribute(PyutXmlConstants.ATTR_X))
y = PyU.strFloatToInt(controlPoint.getAttribute(PyutXmlConstants.ATTR_Y))
controlPoints.append(ControlPoint(x, y))

return controlPoints
Expand Down Expand Up @@ -677,8 +677,8 @@ def __setAssociationLabelPosition(self, xmlLink: Element, tagName: str, associat
associationLabel:
"""
label: Element = xmlLink.getElementsByTagName(tagName)[0]
x = float(label.getAttribute(PyutXmlConstants.ATTR_X))
y = float(label.getAttribute(PyutXmlConstants.ATTR_Y))
x: int = PyU.strFloatToInt(label.getAttribute(PyutXmlConstants.ATTR_X))
y: int = PyU.strFloatToInt(label.getAttribute(PyutXmlConstants.ATTR_Y))

self.logger.debug(f'tagName: {tagName} `{associationLabel.text=}` pos: ({x:.2f},{y:.2f})')

Expand All @@ -691,8 +691,8 @@ def __getAttachmentPoint(self, xmlOglInterface: Element) -> SelectAnchorPoint:
xStr: str = xmlOglInterface.getAttribute(PyutXmlConstants.ATTR_X)
yStr: str = xmlOglInterface.getAttribute(PyutXmlConstants.ATTR_Y)

x: float = PyutUtils.secureFloat(xStr)
y: float = PyutUtils.secureFloat(yStr)
x: int = PyU.strFloatToInt(xStr)
y: int = PyU.strFloatToInt(yStr)

attachmentPoint: AttachmentPoint = AttachmentPoint.toEnum(attachmentPointStr)
anchorPoint: SelectAnchorPoint = SelectAnchorPoint(x=x, y=y, attachmentPoint=attachmentPoint)
Expand Down
4 changes: 2 additions & 2 deletions src/org/pyut/persistence/converters/OglToMiniDomV10.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,8 +646,8 @@ def __getSimpleCoordinates(self, x: int, y: int) -> Tuple[str, str]:
Simple formatted string versions of the above
"""
simpleX: str = str(x)
simpleY: str = str(y)
simpleX: str = str(int(x)) # some older files have float
simpleY: str = str(int(y)) # some older files have float

return simpleX, simpleY

Expand Down
2 changes: 1 addition & 1 deletion src/org/pyut/resources/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.3.5+.817
6.3.6+.820
17 changes: 17 additions & 0 deletions src/tests/org/pyut/TestPyutUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,23 @@ def testSnapCoordinatesToGridNoSnapping(self):
self.assertEqual(expectedX, snappedX, 'X coordinate not correctly snapped')
self.assertEqual(expectedY, snappedY, 'Y coordinate not correctly snapped')

def testStrFloatToInt(self):

retValue: int = PyutUtils.strFloatToInt('23.0')

self.assertEqual(23, retValue, 'Conversion failed')

def testStrIntLikeFloatToInt(self):

retValue: int = PyutUtils.strFloatToInt('23')

self.assertEqual(23, retValue, 'Conversion failed')

def testStrFloatToIntThrowsException(self):

retValue: int = PyutUtils.strFloatToInt('aa')
self.assertEqual(0, retValue, 'Bad Value should return 0')


def suite() -> TestSuite:

Expand Down

0 comments on commit 98836f1

Please sign in to comment.