def Draw(self, dc: DC, withChildren: bool = True): """ Draw the text on the dc. Args: dc withChildren """ if self._visible: RectangleShape.Draw(self, dc, False) dc.SetTextForeground(self._color) dc.SetBackgroundMode(PENSTYLE_SOLID) dc.SetTextBackground(self._textBack) x, y = self.GetPosition() # to draw the text shape with its own font size saveFont: Font = dc.GetFont() if self.GetFont() is not None: dc.SetFont(self.GetFont()) dc.DrawText(self._text, x, y) dc.SetFont(saveFont) if withChildren: self.DrawChildren(dc)
def _drawSourceCardinality(self, dc: DC, sp: OglPosition, dp: OglPosition): dx, dy = self._computeDxDy(srcPosition=sp, destPosition=dp) linkLength: float = self._computeLinkLength(srcPosition=sp, destPosition=dp) srcLblX: int = round((20 * dx / linkLength - dx * 5 / linkLength) + sp.x) srcLblY: int = round((20 * dy / linkLength + dy * 5 / linkLength) + sp.y) if OglAssociation.clsLogger.isEnabledFor(INFO): info = (f'{sp=} ' f'{dp=} ' f'{dx=} ' f'{dy=} ' f'linkLength={linkLength:.2f} ' f'srcLblX={srcLblX:.2f} ' f'srcLblY={srcLblY:.2f}') OglAssociation.clsLogger.info(info) saveFont: Font = dc.GetFont() dc.SetFont(self._defaultFont) sourceCardinalityText: str = self._link.sourceCardinality dc.DrawText(sourceCardinalityText, srcLblX, srcLblY) dc.SetFont(saveFont) self._sourceCardinality = self.__updateAssociationLabel( self._sourceCardinality, x=srcLblX, y=srcLblY, text=sourceCardinalityText)
def _drawCenterLabel(self, dc: DC, sp: OglPosition, dp: OglPosition): midPoint: OglPosition = OglUtils.computeMidPoint(srcPosition=sp, destPosition=dp) saveFont: Font = dc.GetFont() dc.SetFont(self._defaultFont) centerText: str = self._link.getName() dc.DrawText(centerText, midPoint.x, midPoint.y) dc.SetFont(saveFont) self._centerLabel = self.__updateAssociationLabel(self._centerLabel, x=midPoint.x, y=midPoint.y, text=centerText)
def _drawDestinationCardinality(self, dc: DC, sp: OglPosition, dp: OglPosition): dx, dy = self._computeDxDy(srcPosition=sp, destPosition=dp) linkLength: float = self._computeLinkLength(srcPosition=sp, destPosition=dp) dstLblX: int = round((-20 * dx / linkLength + dy * 5 / linkLength) + dp.x) dstLblY: int = round((-20 * dy / linkLength - dy * 5 / linkLength) + dp.y) saveFont: Font = dc.GetFont() dc.SetFont(self._defaultFont) destinationCardinalityText: str = self._link.destinationCardinality dc.DrawText(destinationCardinalityText, dstLblX, dstLblY) self._destinationCardinality = self.__updateAssociationLabel( self._destinationCardinality, x=dstLblX, y=dstLblY, text=destinationCardinalityText) dc.SetFont(saveFont)