Mercurial > lcfOS
changeset 82:a47f6fec5435
Added some sort of auto routing
author | windel |
---|---|
date | Sun, 18 Nov 2012 13:09:10 +0100 |
parents | 49161141d765 |
children | 762721284ec2 |
files | python/apps/diagrameditor.py |
diffstat | 1 files changed, 24 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/python/apps/diagrameditor.py Fri Nov 16 12:10:34 2012 +0100 +++ b/python/apps/diagrameditor.py Sun Nov 18 13:09:10 2012 +0100 @@ -56,9 +56,7 @@ d['toBlock'] = self.toPort.block.name d['toPort'] = self.toPort.name return d - def setDict(self, d): - print(d) - Dict = property(getDict, setDict) + Dict = property(getDict) def myDelete(self): scene = self.scene() if scene: @@ -102,15 +100,30 @@ TODO: implement nice automatic line router """ pos1 = self.getPos1() - if pos1 is None or self.pos2 is None: + pos2 = self.pos2 + if pos1 is None or pos2 is None: return - pts = [pos1] + [v.pos() for v in self.vias] + [self.pos2] - self.arrowhead.setPos(self.pos2) - if pts[-1].x() < pts[-2].x(): - self.arrowhead.setRotation(-90) - else: - self.arrowhead.setRotation(90) - self.setPath(buildPath(pts)) + scene = self.scene() + vias = [pos1 + QPointF(20, 0)] + self.vias + [pos2 + QPointF(-20, 0)] + if scene: + litem = QGraphicsLineItem() + litem.setFlags(self.ItemIsSelectable) + scene.addItem(litem) + for p1, p2 in zip(vias[:-1], vias[1:]): + line = QLineF(p1, p2) + litem.setLine(line) + citems = scene.collidingItems(litem) + citems = [i for i in citems if type(i) is BlockItem] + print(citems) + scene.removeItem(litem) + pts = [pos1] + vias + [pos2] + self.arrowhead.setPos(pos2) + self.arrowhead.setRotation(90) + p = buildPath(pts) + pps = QPainterPathStroker() + pps.setWidth(3) + p = pps.createStroke(p).simplified() + self.setPath(p) """ Create a shape outline using the path stroker """ s = super(Connection, self).shape() pps = QPainterPathStroker()