def drawCell(self, p, x0, x1, y0, y1, subx, suby): w, h = x1 - x0, y1 - y0 rect = QtCore.QRectF(x0, y0, w, h) # rect: pp1 = QtGui.QPainterPath() pp1.addRect(rect) # busbars: # TODO: make width variable ... currently fixed to 1e-3 ps = QtGui.QPainterPath() for yi in subx: yi = y0 + yi * (y1 - y0) ps.addRect(QtCore.QRectF(x0, yi, w, 1e-3)) for xi in suby: xi = x0 + xi * (x1 - x0) ps.addRect(QtCore.QRectF(xi, y0, 1e-3, h)) if not self.circleOffs.isNull(): # intersect rect with ellipse to create pseudo rect shape: # scale rect: c = rect.center() esize = rect.size() * 2**0.5 - self.circleOffs esize.setWidth(max(rect.width(), esize.width())) esize.setHeight(max(rect.height(), esize.height())) rect.setSize(esize) rect.moveCenter(c) pp2 = QtGui.QPainterPath() pp2.addEllipse(rect) pp1 = pp2.intersected(pp1) ps = pp2.intersected(ps) p.addPath(ps) p.addPath(pp1)
def shape2(self): if self._shape is None: subx = self._genSublines(self.nSublines[1]) suby = self._genSublines(self.nSublines[0]) wx, wy = self.width[1] / \ self.nCells[1], self.width[0] / self.nCells[0] p = QtGui.QPainterPath() p.moveTo(0, 0) xx = np.linspace(0, 1, self.nCells[1] + 1) yy = np.linspace(0, 1, self.nCells[0] + 1) for i, (x0, x1) in enumerate(zip(xx[:-1], xx[1:])): for j, (y0, y1) in enumerate(zip(yy[:-1], yy[1:])): # set offset so, that boundary cells go till boundary # and offset only is between cells : if i == 0: # left wx0 = 0 wx1 = wx else: if i == self.nCells[1] - 1: # right wx1 = 0 wx0 = wx else: # middle wx1 = wx / 2 wx0 = wx / 2 if j == 0: # bottom wy0 = 0 wy1 = wy else: if j == self.nCells[0] - 1: # top wy1 = 0 wy0 = wy else: # middle wy1 = wy / 2 wy0 = wy / 2 self.drawCell(p, x0 + wx0, x1 - wx1, y0 + wy0, y1 - wy1, subx, suby) self._shape = p return self._shape