Commit dead896b authored by Michael Büsch's avatar Michael Büsch

gui/fup: Draw branch circles

Signed-off-by: Michael Büsch's avatarMichael Buesch <>
parent 4c9265a3
...@@ -86,7 +86,7 @@ class FupWire(FupBaseClass): ...@@ -86,7 +86,7 @@ class FupWire(FupBaseClass):
self.__wirePen = QPen(QColor("#000000")) self.__wirePen = QPen(QColor("#000000"))
self.__wirePen.setWidth(2) self.__wirePen.setWidth(2)
self.__wireCollidingPen = QPen(QColor("#000000")) self.__wireCollidingPen = QPen(QColor("#C02020"))
self.__wireCollidingPen.setWidth(2) self.__wireCollidingPen.setWidth(2)
self.__wireBranchPen = QPen(QColor("#000000")) self.__wireBranchPen = QPen(QColor("#000000"))
self.__wireBranchPen.setWidth(1) self.__wireBranchPen.setWidth(1)
...@@ -130,16 +130,24 @@ class FupWire(FupBaseClass): ...@@ -130,16 +130,24 @@ class FupWire(FupBaseClass):
if not self.connections and not self.outConn: if not self.connections and not self.outConn:
self.grid.removeWire(self) self.grid.removeWire(self)
class DrawInfo(object):
__slots__ = ("segStart", "segments", "segDirect")
def __init__(self, segStart, segments, segDirect):
self.segStart = segStart
self.segments = segments
self.segDirect = segDirect
def draw(self, painter): def draw(self, painter):
if self.outConn is None: if self.outConn is None:
return # Only inputs. Do not draw. return # Only inputs. Do not draw.
grid = self.grid grid = self.grid
# Branch circles diameter # Branch circles diameter
r, d = self.BRANCH_DIA // 2, self.BRANCH_DIA branchR, branchD = self.BRANCH_DIA // 2, self.BRANCH_DIA
painter.setBrush(self.__wireBranchBrush) painter.setBrush(self.__wireBranchBrush)
# Draw wire from output to all inputs # Calculate the coordinates of all wire lines.
wireLines = [] # List of DrawInfo()s
xAbs0, yAbs0 = self.outConn.pixCoords xAbs0, yAbs0 = self.outConn.pixCoords
cellPixWidth = self.grid.cellPixWidth cellPixWidth = self.grid.cellPixWidth
for inConn in self.connections: for inConn in self.connections:
...@@ -147,27 +155,47 @@ class FupWire(FupBaseClass): ...@@ -147,27 +155,47 @@ class FupWire(FupBaseClass):
continue continue
assert(inConn.IN) assert(inConn.IN)
# Draw the wire from out to in # Construct line segments to draw the wire from out to in.
xAbs1, yAbs1 = inConn.pixCoords xAbs1, yAbs1 = inConn.pixCoords
x = (xAbs0 // cellPixWidth) * cellPixWidth + cellPixWidth x = (xAbs0 // cellPixWidth) * cellPixWidth + cellPixWidth
seg0 = LineSeg2D.fromCoords(xAbs0, yAbs0, x, yAbs0) segStart = LineSeg2D.fromCoords(xAbs0, yAbs0, x, yAbs0)
seg1 = LineSeg2D.fromCoords(x, yAbs0, x, yAbs1) seg0 = LineSeg2D.fromCoords(x, yAbs0, x, yAbs1)
seg2 = LineSeg2D.fromCoords(x, yAbs1, xAbs1, yAbs1) seg1 = LineSeg2D.fromCoords(x, yAbs1, xAbs1, yAbs1)
segDirect = LineSeg2D.fromCoords(x, yAbs0, xAbs1, yAbs1) segDirect = LineSeg2D.fromCoords(x, yAbs0, xAbs1, yAbs1)
grid.drawWireLine(painter, self, seg0) wireLines.append(self.DrawInfo(segStart,
if not grid.checkWireLine(painter, {self}, seg1) and\ (seg0, seg1),
not grid.checkWireLine(painter, {self}, seg2): segDirect))
grid.drawWireLine(painter, self, seg1)
grid.drawWireLine(painter, self, seg2)
grid.drawWireLine(painter, self, segDirect)
# Draw the branch circles def drawBranch(x, y):
painter.setPen(self.__wireBranchPen) painter.setPen(self.__wireBranchPen)
painter.drawEllipse(xAbs0 - r, yAbs0 - r, d, d) painter.drawEllipse(x - branchR, y - branchR,
painter.drawEllipse(xAbs1 - r, yAbs1 - r, d, d) branchD, branchD)
def drawSeg(seg, handleBranches=True, pen=self.__wirePen):
grid.drawWireLine(painter, self, seg)
if not handleBranches:
for otherDrawInfo in wireLines:
if drawInfo is otherDrawInfo:
for otherSeg in otherDrawInfo.segments:
inter = seg.intersection(otherSeg)
if not inter.intersects:
drawBranch(inter.pointA.x, inter.pointA.y)
drawBranch(inter.pointB.x, inter.pointB.y)
# Draw wire from output to all inputs
for drawInfo in wireLines:
drawSeg(drawInfo.segStart, handleBranches=False)
if all(not grid.checkWireLine(painter, {self}, seg)
for seg in drawInfo.segments):
for seg in drawInfo.segments:
drawSeg(drawInfo.segDirect, handleBranches=False,
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment