# HG changeset patch # User windel # Date 1353240550 -3600 # Node ID a47f6fec54357535d658bfe1b3a2b53abd42b081 # Parent 49161141d7658bb703b649e985ca53b89ab8f4d6 Added some sort of auto routing diff -r 49161141d765 -r a47f6fec5435 python/apps/diagrameditor.py --- 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()