Example #1
0
    def draw(self, p, rect):
        if not self._map():
            return

        #self._setupPainter(p)

        zoomFactor = self.edgeOverlay._zoom

        #p.drawPolygon(self._qpointarray, True, s, e-s)

        r = p.clipRegion().boundingRect()
        bbox = BoundingBox((r.left() / zoomFactor - 0.5,
                            r.top() / zoomFactor - 0.5),
                           (r.right() / zoomFactor + 0.5,
                            r.bottom() / zoomFactor + 0.5))
        map = self._map()
        if self.colors:
            try:
                for edge in map.edgeIter():
                    edgeColor = self.colors[edge.label()]
                    if edgeColor and bbox.intersects(edge.boundingBox()):
                        p.setPen(QtGui.QPen(edgeColor, self.width))
                        p.drawPolyline(self._getZoomedEdge(edge))
            except IndexError, e:
                print e #"IndexError: %d > %d (maxEdgeLabel: %d)!" % (
Example #2
0
    def addClippedPoly(self, polygon, **attr):
        """fe.addClippedPoly(polygon, ...)

        Adds and returns exactly fig.Polygon objects for each part of
        the given polygon which is in the clipping range.  Again, note
        the possibility of setting properties (depth, penColor,
        lineStyle, lineWidth, ...) on all resulting objects via
        keyword arguments (cf. documentation of the FigExporter
        class).

        If simplifyEpsilon (default: 0.5) is not None, simplifyPolygon
        is called on the *scaled* polygon (i.e. the default is to
        simplify the polygon to 0.5 fig units, which are integer
        anyways)."""

        if "fillColor" in attr and not "fillStyle" in attr:
            attr["fillStyle"] = fig.FillStyle.Solid

        # no ROI to clip to?
        if not self.roi:
            return [self.addEdge(polygon, **attr)]

        if type(polygon) != Polygon:
            if not isinstance(polygon, list):
                polygon = Polygon(list(polygon))
            else:
                polygon = Polygon(polygon)

        clipRect = BoundingBox(self.roi)
        o = self.offset + attr.get('offset', (0, 0))
        clipRect.moveBy(-o)

        # handle all-or-none cases:
        if not clipRect.intersects(polygon.boundingBox()):
            return []
        if clipRect.contains(polygon.boundingBox()):
            return [self.addEdge(polygon, **attr)]

        # general case: perform clipping, add parts one-by-one:
        result = []  # fig.Compound(container) - I dont't dare grouping here..
        closeAtBorder = (attr.get("fillStyle", fig.FillStyle.None) !=
                         fig.FillStyle.None)
        for part in clipPoly(polygon, clipRect, closeAtBorder):
            if part.length():  # don't add zero-length polygons
                result.append(self.addEdge(part, **attr))
        return result
Example #3
0
    def addClippedPoly(self, polygon, **attr):
        """fe.addClippedPoly(polygon, ...)

        Adds and returns exactly fig.Polygon objects for each part of
        the given polygon which is in the clipping range.  Again, note
        the possibility of setting properties (depth, penColor,
        lineStyle, lineWidth, ...) on all resulting objects via
        keyword arguments (cf. documentation of the FigExporter
        class).

        If simplifyEpsilon (default: 0.5) is not None, simplifyPolygon
        is called on the *scaled* polygon (i.e. the default is to
        simplify the polygon to 0.5 fig units, which are integer
        anyways)."""

        if "fillColor" in attr and not "fillStyle" in attr:
            attr["fillStyle"] = fig.FillStyle.Solid

        # no ROI to clip to?
        if not self.roi:
            return [self.addEdge(polygon, **attr)]

        if type(polygon) != Polygon:
            if not isinstance(polygon, list):
                polygon = Polygon(list(polygon))
            else:
                polygon = Polygon(polygon)

        clipRect = BoundingBox(self.roi)
        o = self.offset + attr.get('offset', (0,0))
        clipRect.moveBy(-o)

        # handle all-or-none cases:
        if not clipRect.intersects(polygon.boundingBox()):
            return []
        if clipRect.contains(polygon.boundingBox()):
            return [self.addEdge(polygon, **attr)]

        # general case: perform clipping, add parts one-by-one:
        result = [] # fig.Compound(container) - I dont't dare grouping here..
        closeAtBorder = (
            attr.get("fillStyle", fig.FillStyle.None) != fig.FillStyle.None)
        for part in clipPoly(polygon, clipRect, closeAtBorder):
            if part.length(): # don't add zero-length polygons
                result.append(self.addEdge(part, **attr))
        return result
Example #4
0
    def draw(self, p, rect=None):
        if not self._map():
            return

        #self._setupPainter(p)

        r = p.clipRegion().boundingRect()
        bbox = BoundingBox(
            (r.left() / self._zoom - 0.5, r.top() / self._zoom - 0.5),
            (r.right() / self._zoom + 0.5, r.bottom() / self._zoom + 0.5))
        map = self._map()

        if self.colors:
            try:
                for edge in map.edgeIter():
                    edgeColor = self.colors[edge.label()]
                    if edgeColor and bbox.intersects(edge.boundingBox()):
                        p.setPen(QtGui.QPen(edgeColor, self.width))
                        p.drawPolyline(self._getZoomedEdge(edge))
            except IndexError, e:
                print e  #"IndexError: %d > %d (maxEdgeLabel: %d)!" % (