def find_axis(top_line, bot_line): type, origin = top_line.intersect(bot_line) # Force angles into right half-plane regardless of click order top_angle = (top_line.angle() + 90) % 180 - 90 bot_angle = (bot_line.angle() + 90) % 180 - 90 xaxis = QLineF(origin, QPointF(0, 0)) # Need to make non-zero vector xaxis.setLength(100) xaxis.setAngle((top_angle + bot_angle) / 2) yaxis = QLineF(xaxis) yaxis.setAngle(xaxis.angle() + 90) return origin, xaxis, yaxis
def find_axis(top_line, bot_line): type, origin = top_line.intersect(bot_line) # Force angles into right half-plane regardless of click order top_angle = (top_line.angle() + 90)%180 - 90 bot_angle = (bot_line.angle() + 90)%180 - 90 xaxis = QLineF(origin, QPointF(0, 0)) # Need to make non-zero vector xaxis.setLength(100) xaxis.setAngle((top_angle + bot_angle)/2) yaxis = QLineF(xaxis) yaxis.setAngle(xaxis.angle() + 90) return origin, xaxis, yaxis
def renewplot(self): """ Do not layout anything, but redraw all lines""" scene = self.graphicsView.scene() self.roots = set() # scene.changed.disconnect(self.renewplot) for i in self.qLines: scene.removeItem(i) self.qLines = [] for edge in self.gv.edges_iter(): qnode1 = self.nodesToQNodes[edge[0]] qnode2 = self.nodesToQNodes[edge[1]] line = QLineF(qnode1.pos(), qnode2.pos()) line.setLength(line.length() - 40) end = line.p2() arrowLine1 = QLineF() arrowLine1.setP1(end) arrowLine1.setLength(10) arrowLine1.setAngle(line.angle() + 210) arrowLine2 = QLineF() arrowLine2.setP1(end) arrowLine2.setLength(10) arrowLine2.setAngle(line.angle() - 210) if edge.attr['color'] not in self.qpens: self.qpens[edge.attr['color']] = QPen( QColor(edge.attr['color'])) item = scene.addLine(line, self.qpens[edge.attr['color']]) item.setZValue(-1) item.setFlag(QGraphicsItem.ItemIsSelectable, True) self.qLines.append(item) item = scene.addLine(arrowLine1, self.qpens[edge.attr['color']]) self.qLines.append(item) item = scene.addLine(arrowLine2, self.qpens[edge.attr['color']]) self.qLines.append(item) self.roots.add(edge[0])
def updateLeader(self): """ TOWRITE """ arrowStyle = Closed # int # TODO: Make this customizable arrowStyleAngle = 15.0 # qreal # TODO: Make this customizable arrowStyleLength = 1.0 # qreal # TODO: Make this customizable self.lineStyleAngle = 45.0 # qreal # TODO: Make this customizable self.lineStyleLength = 1.0 # qreal # TODO: Make this customizable lyne = self.line() # QLineF angle = lyne.angle() # qreal ap0 = lyne.p1() # QPointF lp0 = lyne.p2() # QPointF # Arrow lynePerp = QLineF(lyne.pointAt(arrowStyleLength / lyne.length()), lp0) lynePerp.setAngle(angle + 90) lyne1 = QLineF(ap0, lp0) lyne2 = QLineF(ap0, lp0) lyne1.setAngle(angle + arrowStyleAngle) lyne2.setAngle(angle - arrowStyleAngle) # ap1 = QPointF() # ap2 = QPointF() _, ap1 = lynePerp.intersect(lyne1) _, ap2 = lynePerp.intersect(lyne2) # Math Diagram # .(ap1) .(lp1) # /| /| # / | / | # / | / | # / | / | # / | / | # / | / | # / | / | # / | / | # /+(aSA) | /+(lSA) | # (ap0)./__(aSL)__|__________(lp0)./__(lSL)__| # \ -(aSA) | \ -(lSA) | # \ | \ | # \ | \ | # \ | \ | # \ | \ | # \ | \ | # \ | \ | # \ | \ | # \ | \ | # \| \| # .(ap2) .(lp2) if arrowStyle == Open: arrowStylePath = QPainterPath() arrowStylePath.moveTo(ap1) arrowStylePath.lineTo(ap0) arrowStylePath.lineTo(ap2) arrowStylePath.lineTo(ap0) arrowStylePath.lineTo(ap1) elif arrowStyle == Closed: arrowStylePath = QPainterPath() arrowStylePath.moveTo(ap1) arrowStylePath.lineTo(ap0) arrowStylePath.lineTo(ap2) arrowStylePath.lineTo(ap1) elif arrowStyle == Dot: arrowStylePath = QPainterPath() arrowStylePath.addEllipse(ap0, arrowStyleLength, arrowStyleLength) elif arrowStyle == Box: arrowStylePath = QPainterPath() side = QLineF(ap1, ap2).length() # qreal ar0 = QRectF(0, 0, side, side) ar0.moveCenter(ap0) arrowStylePath.addRect(ar0) elif arrowStyle == Tick: pass #TODO/PORT# Is this supposed to be empty? lineStylePath = QPainterPath() lineStylePath.moveTo(ap0) lineStylePath.lineTo(lp0)
def updateRubber(self, painter=None): """ TOWRITE :param `painter`: TOWRITE :type `painter`: `QPainter`_ """ rubberMode = self.objectRubberMode() # int if rubberMode == OBJ_RUBBER_POLYGON: self.setObjectPos(self.objectRubberPoint("POLYGON_POINT_0")) ok = False # bool numStr = self.objectRubberText("POLYGON_NUM_POINTS") # QString if not numStr: return try: num = int(numStr) except ValueError: return appendStr = '' # QString rubberPath = QPainterPath() rubberPath.moveTo( self.mapFromScene(self.objectRubberPoint("POLYGON_POINT_0"))) for i in range(1, num): # for(int i = 1; i <= num; i++) appendStr = "POLYGON_POINT_" + '%s' % i # QString().setNum(i) appendPoint = self.mapFromScene( self.objectRubberPoint(appendStr)) # QPointF rubberPath.lineTo(appendPoint) ## rubberPath.lineTo(0,0) self.updatePath(rubberPath) # Ensure the path isn't updated until the number of points is changed again. self.setObjectRubberText("POLYGON_NUM_POINTS", '') elif rubberMode == OBJ_RUBBER_POLYGON_INSCRIBE: self.setObjectPos(self.objectRubberPoint("POLYGON_CENTER")) numSides = self.objectRubberPoint( "POLYGON_NUM_SIDES").x() # quint16 inscribePoint = self.mapFromScene( self.objectRubberPoint("POLYGON_INSCRIBE_POINT")) # QPointF inscribeLine = QLineF(QPointF(0, 0), inscribePoint) # QLineF inscribeAngle = inscribeLine.angle() # qreal inscribeInc = 360.0 / numSides # qreal if painter: self.drawRubberLine(inscribeLine, painter, "VIEW_COLOR_CROSSHAIR") inscribePath = QPainterPath() # First Point. inscribePath.moveTo(inscribePoint) # Remaining Points. for i in range(1, numSides): # for(int i = 1; i < numSides; i++) inscribeLine.setAngle(inscribeAngle + inscribeInc * i) inscribePath.lineTo(inscribeLine.p2()) self.updatePath(inscribePath) elif rubberMode == OBJ_RUBBER_POLYGON_CIRCUMSCRIBE: self.setObjectPos(self.objectRubberPoint("POLYGON_CENTER")) numSides = self.objectRubberPoint( "POLYGON_NUM_SIDES").x() # quint16 circumscribePoint = self.mapFromScene( self.objectRubberPoint( "POLYGON_CIRCUMSCRIBE_POINT")) # QPointF circumscribeLine = QLineF(QPointF(0, 0), circumscribePoint) # QLineF circumscribeAngle = circumscribeLine.angle() # qreal circumscribeInc = 360.0 / numSides # qreal if painter: self.drawRubberLine(circumscribeLine, painter, "VIEW_COLOR_CROSSHAIR") circumscribePath = QPainterPath() # First Point. prev = QLineF(circumscribeLine.p2(), QPointF(0, 0)) prev = prev.normalVector() circumscribeLine.setAngle(circumscribeAngle + circumscribeInc) perp = QLineF(circumscribeLine.p2(), QPointF(0, 0)) perp = perp.normalVector() # iPoint = QPointF() _, iPoint = perp.intersect(prev) circumscribePath.moveTo(iPoint) # Remaining Points. for i in range(2, numSides): # for(int i = 2; i <= numSides; i++) prev = perp circumscribeLine.setAngle(circumscribeAngle + circumscribeInc * i) perp = QLineF(circumscribeLine.p2(), QPointF(0, 0)) perp = perp.normalVector() perp.intersect(prev, iPoint) circumscribePath.lineTo(iPoint) self.updatePath(circumscribePath) elif rubberMode == OBJ_RUBBER_GRIP: if painter: elemCount = self.normalPath.elementCount() # int gripPoint = self.objectRubberPoint("GRIP_POINT") # QPointF if self.gripIndex == -1: self.gripIndex = self.findIndex(gripPoint) if self.gripIndex == -1: return m = 0 # int n = 0 # int if not self.gripIndex: m = elemCount - 1 n = 1 elif self.gripIndex == elemCount - 1: m = elemCount - 2 n = 0 else: m = self.gripIndex - 1 n = self.gripIndex + 1 em = self.normalPath.elementAt(m) # QPainterPath::Element en = self.normalPath.elementAt(n) # QPainterPath::Element emPoint = QPointF(em.x, em.y) # QPointF enPoint = QPointF(en.x, en.y) # QPointF painter.drawLine(emPoint, self.mapFromScene(self.objectRubberPoint(""))) painter.drawLine(enPoint, self.mapFromScene(self.objectRubberPoint(""))) rubLine = QLineF(self.mapFromScene(gripPoint), self.mapFromScene(self.objectRubberPoint(""))) self.drawRubberLine(rubLine, painter, "VIEW_COLOR_CROSSHAIR")
def updateRubber(self, painter=None): """ TOWRITE :param `painter`: TOWRITE :type `painter`: `QPainter`_ """ rubberMode = self.objectRubberMode() # int if rubberMode == OBJ_RUBBER_POLYGON: self.setObjectPos(self.objectRubberPoint("POLYGON_POINT_0")) ok = False # bool numStr = self.objectRubberText("POLYGON_NUM_POINTS") # QString if not numStr: return try: num = int(numStr) except ValueError: return appendStr = '' # QString rubberPath = QPainterPath() rubberPath.moveTo(self.mapFromScene(self.objectRubberPoint("POLYGON_POINT_0"))) for i in range(1, num): # for(int i = 1; i <= num; i++) appendStr = "POLYGON_POINT_" + '%s' % i # QString().setNum(i) appendPoint = self.mapFromScene(self.objectRubberPoint(appendStr)) # QPointF rubberPath.lineTo(appendPoint) ## rubberPath.lineTo(0,0) self.updatePath(rubberPath) # Ensure the path isn't updated until the number of points is changed again. self.setObjectRubberText("POLYGON_NUM_POINTS", '') elif rubberMode == OBJ_RUBBER_POLYGON_INSCRIBE: self.setObjectPos(self.objectRubberPoint("POLYGON_CENTER")) numSides = self.objectRubberPoint("POLYGON_NUM_SIDES").x() # quint16 inscribePoint = self.mapFromScene(self.objectRubberPoint("POLYGON_INSCRIBE_POINT")) # QPointF inscribeLine = QLineF(QPointF(0, 0), inscribePoint) # QLineF inscribeAngle = inscribeLine.angle() # qreal inscribeInc = 360.0 / numSides # qreal if painter: self.drawRubberLine(inscribeLine, painter, "VIEW_COLOR_CROSSHAIR") inscribePath = QPainterPath() # First Point. inscribePath.moveTo(inscribePoint) # Remaining Points. for i in range(1, numSides): # for(int i = 1; i < numSides; i++) inscribeLine.setAngle(inscribeAngle + inscribeInc * i) inscribePath.lineTo(inscribeLine.p2()) self.updatePath(inscribePath) elif rubberMode == OBJ_RUBBER_POLYGON_CIRCUMSCRIBE: self.setObjectPos(self.objectRubberPoint("POLYGON_CENTER")) numSides = self.objectRubberPoint("POLYGON_NUM_SIDES").x() # quint16 circumscribePoint = self.mapFromScene(self.objectRubberPoint("POLYGON_CIRCUMSCRIBE_POINT")) # QPointF circumscribeLine = QLineF(QPointF(0, 0), circumscribePoint) # QLineF circumscribeAngle = circumscribeLine.angle() # qreal circumscribeInc = 360.0 / numSides # qreal if painter: self.drawRubberLine(circumscribeLine, painter, "VIEW_COLOR_CROSSHAIR") circumscribePath = QPainterPath() # First Point. prev = QLineF(circumscribeLine.p2(), QPointF(0, 0)) prev = prev.normalVector() circumscribeLine.setAngle(circumscribeAngle + circumscribeInc) perp = QLineF(circumscribeLine.p2(), QPointF(0, 0)) perp = perp.normalVector() # iPoint = QPointF() _, iPoint = perp.intersect(prev) circumscribePath.moveTo(iPoint) # Remaining Points. for i in range(2, numSides): # for(int i = 2; i <= numSides; i++) prev = perp circumscribeLine.setAngle(circumscribeAngle + circumscribeInc * i) perp = QLineF(circumscribeLine.p2(), QPointF(0, 0)) perp = perp.normalVector() perp.intersect(prev, iPoint) circumscribePath.lineTo(iPoint) self.updatePath(circumscribePath) elif rubberMode == OBJ_RUBBER_GRIP: if painter: elemCount = self.normalPath.elementCount() # int gripPoint = self.objectRubberPoint("GRIP_POINT") # QPointF if self.gripIndex == -1: self.gripIndex = self.findIndex(gripPoint) if self.gripIndex == -1: return m = 0 # int n = 0 # int if not self.gripIndex: m = elemCount - 1 n = 1 elif self.gripIndex == elemCount - 1: m = elemCount - 2 n = 0 else: m = self.gripIndex - 1 n = self.gripIndex + 1 em = self.normalPath.elementAt(m) # QPainterPath::Element en = self.normalPath.elementAt(n) # QPainterPath::Element emPoint = QPointF(em.x, em.y) # QPointF enPoint = QPointF(en.x, en.y) # QPointF painter.drawLine(emPoint, self.mapFromScene(self.objectRubberPoint(""))) painter.drawLine(enPoint, self.mapFromScene(self.objectRubberPoint(""))) rubLine = QLineF(self.mapFromScene(gripPoint), self.mapFromScene(self.objectRubberPoint(""))) self.drawRubberLine(rubLine, painter, "VIEW_COLOR_CROSSHAIR")