示例#1
0
    def outTIF(self, plotWidget, d_folder, name, title):
        if d_folder:
            fileName = os.path.join(d_folder, name + '.tif')
        else:
            if self.settings.value('lastOutputDir'):
                folder = self.settings.value('lastOutputDir')
            else:
                folder = self.settings.value('projFolder')

            fileName = QFileDialog.getSaveFileName(
                caption="Save Plot As .tif file",
                directory=folder,
                filter="Tagged Image File Format (*.tif;*.tiff)")
        fileName = toUnicode(fileName)

        if fileName:
            if not title:
                title = self.settings.value('figureTitle')
            plotWidget.setTitle(title)
            pix = QPixmap(QSize(600, 400))
            sh = QBrush(pix)
            sh.setColor(Qt.white)
            sh.setStyle(Qt.SolidPattern)
            painter = QPainter()
            painter.begin(pix)
            painter.setBrush(sh)
            painter.drawRect(0, 0, 600, 400)
            painter.end()

            legend = QwtLegend()
            plotWidget.insertLegend(legend)
            plotWidget.setAxisTitle(QwtPlot.xBottom,
                                    self.settings.value('xAxisTitle'))
            plotWidget.setAxisTitle(QwtPlot.yLeft,
                                    self.settings.value('yAxisTitle'))

            QSettings().setValue("lastOutputDir", os.path.dirname(fileName))
            filter = QwtPlotPrintFilter()
            filter.setOptions(QwtPlotPrintFilter.PrintAll
                              & ~QwtPlotPrintFilter.PrintBackground)
            plotWidget.print_(pix, filter)
            pix.save(fileName)
            plotWidget.insertLegend(None)
            plotWidget.setAxisTitle(QwtPlot.xBottom, None)
            plotWidget.setAxisTitle(QwtPlot.yLeft, None)
            plotWidget.setTitle(None)
示例#2
0
    def data(self, index, role=Qt.DisplayRole):
        column = index.column()

        if role == Qt.DisplayRole:
            field = self._mapping[index.row()]
            column_def = self.columns[column]
            value = field[column_def['name']]

            fieldType = column_def['type']
            if fieldType == QVariant.Type:
                if value == QVariant.Invalid:
                    return ''
                return self.fieldTypes[value]
            return value

        if role == Qt.EditRole:
            field = self._mapping[index.row()]
            column_def = self.columns[column]
            value = field[column_def['name']]
            return value

        if role == Qt.TextAlignmentRole:
            fieldType = self.columns[column]['type']
            if fieldType in [QVariant.Int]:
                hAlign = Qt.AlignRight
            else:
                hAlign = Qt.AlignLeft
            return hAlign + Qt.AlignVCenter

        if role == Qt.ForegroundRole:
            column_def = self.columns[column]
            if column_def['name'] == 'expression':
                brush = QBrush()
                if self._errors[index.row()]:
                    brush.setColor(Qt.red)
                else:
                    brush.setColor(Qt.black)
                return brush

        if role == Qt.ToolTipRole:
            column_def = self.columns[column]
            if column_def['name'] == 'expression':
                return self._errors[index.row()]
示例#3
0
    def data(self, index, role=Qt.DisplayRole):
        column = index.column()

        if role == Qt.DisplayRole:
            field = self._mapping[index.row()]
            column_def = self.columns[column]
            value = field[column_def['name']]

            fieldType = column_def['type']
            if fieldType == QVariant.Type:
                if value == QVariant.Invalid:
                    return ''
                return self.fieldTypes[value]
            return value

        if role == Qt.EditRole:
            field = self._mapping[index.row()]
            column_def = self.columns[column]
            value = field[column_def['name']]
            return value

        if role == Qt.TextAlignmentRole:
            fieldType = self.columns[column]['type']
            if fieldType in [QVariant.Int]:
                hAlign = Qt.AlignRight
            else:
                hAlign = Qt.AlignLeft
            return hAlign + Qt.AlignVCenter

        if role == Qt.ForegroundRole:
            column_def = self.columns[column]
            if column_def['name'] == 'expression':
                brush = QBrush()
                if self._errors[index.row()]:
                    brush.setColor(Qt.red)
                else:
                    brush.setColor(Qt.black)
                return brush

        if role == Qt.ToolTipRole:
            column_def = self.columns[column]
            if column_def['name'] == 'expression':
                return self._errors[index.row()]
示例#4
0
 def draw_background(self, painter, outline=True):
     old_pen = painter.pen()
     old_brush = painter.brush()
     p = QPen()
     b = QBrush()
     if self.__selected:
         p.setColor(QColor("#ffff99"))
         p.setWidth(2)
         b.setColor(QColor("#ffff66"))
         b.setStyle(Qt.SolidPattern)
     if self.__selected:
         painter.setBrush(b)
         painter.setPen(p)
         painter.drawRect(1, 0, self.boundingRect().width()-1, self.boundingRect().height()-1)
     if outline:
         painter.setBrush(QBrush())
         painter.setPen(QPen())
         painter.drawRect(0, 0, self.boundingRect().width(), self.boundingRect().height()-1)
     painter.setBrush(old_brush)
     painter.setPen(old_pen)
示例#5
0
class GPSMarker(QgsMapCanvasItem):
    def __init__(self, canvas):
        super(GPSMarker, self).__init__(canvas)
        self.canvas = canvas
        self._quaility = 0
        self._heading = 0
        self.size = roam.config.settings.get('gps', {}).get('marker_size', 24)
        self.red = Qt.darkRed
        self.blue = QColor(129, 173, 210)
        self.green = Qt.darkGreen
        self._gpsinfo = QgsGpsInformation()

        self.pointbrush = QBrush(self.red)
        self.pointpen = QPen(Qt.black)
        self.pointpen.setWidth(1)
        self.map_pos = QgsPoint(0.0, 0.0)
        self.gps = None

    def setgps(self, gps):
        self.gps = gps

    def setSize(self, size):
        self.size = size

    def paint(self, painter, xxx, xxx2):
        self.setPos(self.toCanvasCoordinates(self.map_pos))

        halfSize = self.size / 2.0
        rect = QRectF(0 - halfSize, 0 - halfSize, self.size, self.size)
        painter.setRenderHint(QPainter.Antialiasing)
        if self.quality == 0:
            color = self.red
        elif self.quality == 1:
            color = self.green
        elif self.quality >= 2:
            color = self.blue
        else:
            color = self.red

        self.pointpen.setColor(Qt.gray)
        self.pointpen.setWidth(2)
        self.pointbrush.setColor(color)

        painter.setBrush(self.pointbrush)
        painter.setPen(self.pointpen)
        y = 0 - halfSize
        x = rect.width() / 2 - halfSize
        line = QLine(x, y, x, rect.height() - halfSize)
        y = rect.height() / 2 - halfSize
        x = 0 - halfSize
        line2 = QLine(x, y, rect.width() - halfSize, y)

        # Arrow
        p = QPolygonF()
        p.append(QPoint(0 - halfSize, 0))
        p.append(QPoint(0, -self.size))
        x = rect.width() - halfSize
        p.append(QPoint(x, 0))
        p.append(QPoint(0, 0))

        offsetp = QPolygonF()
        offsetp.append(QPoint(0 - halfSize, 0))
        offsetp.append(QPoint(0, -self.size))
        x = rect.width() - halfSize
        offsetp.append(QPoint(x, 0))
        offsetp.append(QPoint(0, 0))

        waypoint = self.gps.waypoint
        if waypoint:
            az = self.map_pos.azimuth(waypoint)

            painter.save()
            painter.rotate(az)
            self.pointbrush.setColor(Qt.red)
            painter.setBrush(self.pointbrush)
            path = QPainterPath()
            path.addPolygon(offsetp)
            painter.drawPath(path)
            painter.restore()

        painter.save()
        painter.rotate(self._heading)
        path = QPainterPath()
        path.addPolygon(p)
        painter.drawPath(path)

        painter.restore()
        painter.drawEllipse(rect)
        painter.drawLine(line)
        painter.drawLine(line2)

    def boundingRect(self):
        halfSize = self.size / 2.0
        size = self.size * 2
        return QRectF(-size, -size, 2.0 * size, 2.0 * size)

    @property
    def quality(self):
        return self._gpsinfo.quality

    @quality.setter
    def quality(self, value):
        self._quaility = value
        self.update()

    def setCenter(self, map_pos, gpsinfo):
        self._heading = gpsinfo.direction
        self._gpsinfo = gpsinfo
        self.map_pos = QgsPointXY(map_pos)
        self.setPos(self.toCanvasCoordinates(self.map_pos))

    def updatePosition(self):
        self.setCenter(self.map_pos, self._gpsinfo)
示例#6
0
    def drawForeground(self, painter, rect):
        #print "BoreHoleScene.drawForeground"
        if self.__redraw:
            with self.__project.connect() as con:
                cur = con.cursor()
                self.__redraw = False
                self.clear()
                fm = painter.fontMetrics()

                if self.__id is None:
                    QGraphicsScene.drawForeground(self, painter, rect)
                    return

                cur.execute(
                    "SELECT geom FROM albion.hole WHERE id='{}'".format(
                        self.__id))
                res = cur.fetchone()

                if not res:
                    QGraphicsScene.drawForeground(self, painter, rect)
                    return

                hole = wkb.loads(bytes.fromhex(res[0]))
                line = [p[2] for p in hole.coords]
                tick_width = 20
                spacing = 5
                tick_text_offset = -10
                tabs = [50, 75, 150, 250, 350, 400, 500]
                zmin, zmax = min(line), max(line)
                zpmin, zpmax = 0, ((zmin - zmax) - 5) / self.m_per_pixel

                text = self.addText(self.__id)
                text.setPos(tabs[1], -5 * fm.height())

                label = 'Depth [m]'
                text = self.addText(label)
                text.setRotation(-90)
                text.setPos(0, 0)
                text = self.addText('Formation')
                text.setPos(tabs[1], -3 * fm.height())
                text = self.addText('Radiometry')
                text.setPos(tabs[2], -3 * fm.height())
                text = self.addText('Resistivity')
                text.setPos(tabs[3], -3 * fm.height())
                text = self.addText('Mineralization')
                text.setPos(tabs[4], -3 * fm.height())

                top = zpmin - 3 * fm.height()
                pen = QPen()
                pen.setWidth(3)
                for tab in [tabs[1], tabs[2], tabs[3], tabs[4], tabs[6]]:
                    self.addLine(tab, top, tab, zpmax, pen)
                self.addLine(tabs[1], zpmin, tabs[-1], zpmin, pen)
                self.addLine(tabs[1], zpmax, tabs[-1], zpmax, pen)
                self.addLine(tabs[1], top, tabs[-1], top, pen)

                # depth ticks
                for z in range(0, int(-(zmax - zmin) - 5), -10):
                    text = "% 4.0f" % (max(line) + z)
                    z /= self.m_per_pixel
                    width = fm.width(text)
                    text = self.addText(text)
                    text.setPos(tabs[0] - width - spacing,
                                tick_text_offset + int(z))
                    self.addLine(tabs[0], z, tabs[1], z)
                    self.addLine(tabs[2], z, tabs[4], z)

                #res = cur.execute("SELECT AsText(GEOMETRY), code FROM lithologies WHERE forage={}".format(self.__id)).fetchall()

                ## litho image
                #for geom, code in res:
                #    line = [(float(pt.split()[2])-z_tube+h_tube_sol)
                #            for pt in geom.replace('LINESTRING Z(','').replace(')','').split(',')]
                #    z_start = line[0]/self.m_per_pixel
                #    z_end = line[-1]/self.m_per_pixel
                #    brush = QBrush()
                #    brush.setTextureImage(self.texture(code))
                #    self.addRect(tabs[1], z_start, tabs[2]-tabs[1], z_end-z_start, brush=brush)

                ## bar diagram grid
                #for i in range(1, 10):
                #    pen.setWidth(1 if i != 5 else 2)
                #    x = tabs[3]+(tabs[4]-tabs[3])*float(i)/10
                #    self.addLine(x, zmin, x, zmax, pen)

                # formation color
                cur.execute(
                    "SELECT geom, code FROM albion.formation WHERE hole_id='{}'"
                    .format(self.__id))

                for geom, code in cur.fetchall():
                    line = [
                        p[2] for p in wkb.loads(bytes.fromhex(geom)).coords
                    ]
                    z_start = (line[0] - zmax) / self.m_per_pixel
                    z_end = (line[-1] - zmax) / self.m_per_pixel
                    brush = QBrush()
                    brush.setStyle(Qt.SolidPattern)
                    brush.setColor(self.formation_color(code))
                    self.addRect(tabs[1],
                                 z_start,
                                 tabs[2] - tabs[1],
                                 z_end - z_start,
                                 brush=brush)
                    #width = fm.width(code);
                    #text = self.addText(code)
                    #text.setPos(tabs[2]+spacing, tick_text_offset+int(.5*(z_start+z_end)))
                    self.addLine(tabs[2], z_start, tabs[2], z_start)
                    self.addLine(tabs[2], z_end, tabs[2], z_end)

                # radiometry diagram
                cur.execute(
                    "SELECT max(gamma) FROM albion.radiometry WHERE hole_id='{}'"
                    .format(self.__id))
                gamma_max = cur.fetchone()[0]
                cur.execute(
                    "SELECT geom, gamma FROM albion.radiometry WHERE hole_id='{}' AND gamma>=0"
                    .format(self.__id))
                for geom, gamma in cur.fetchall():
                    line = [
                        p[2] for p in wkb.loads(bytes.fromhex(geom)).coords
                    ]
                    z_start = (line[0] - zmax) / self.m_per_pixel
                    z_end = (line[-1] - zmax) / self.m_per_pixel
                    brush = QBrush()
                    brush.setStyle(Qt.SolidPattern)
                    brush.setColor(QColor(55, 51, 149))
                    self.addRect(tabs[2],
                                 z_start,
                                 (tabs[3] - tabs[2]) * gamma / gamma_max,
                                 z_end - z_start,
                                 pen=QPen(Qt.NoPen),
                                 brush=brush)

                # resistivity diagram
                cur.execute(
                    "SELECT max(rho) FROM albion.resistivity WHERE hole_id='{}'"
                    .format(self.__id))
                rho_max = cur.fetchone()[0]
                cur.execute(
                    "SELECT geom, rho FROM albion.resistivity WHERE hole_id='{}' AND rho>=0"
                    .format(self.__id))
                for geom, rho in cur.fetchall():
                    line = [
                        p[2] for p in wkb.loads(bytes.fromhex(geom)).coords
                    ]
                    z_start = (line[0] - zmax) / self.m_per_pixel
                    z_end = (line[-1] - zmax) / self.m_per_pixel
                    brush = QBrush()
                    brush.setStyle(Qt.SolidPattern)
                    brush.setColor(QColor(155, 51, 49))
                    self.addRect(tabs[3],
                                 z_start, (tabs[4] - tabs[3]) * rho / rho_max,
                                 z_end - z_start,
                                 pen=QPen(Qt.NoPen),
                                 brush=brush)

                # mineralization
                cur.execute(
                    "SELECT geom, oc, accu, grade FROM albion.mineralization WHERE hole_id='{}'"
                    .format(self.__id))

                for geom, oc, accu, grade in cur.fetchall():
                    line = [
                        p[2] for p in wkb.loads(bytes.fromhex(geom)).coords
                    ]
                    z_start = (line[0] - zmax) / self.m_per_pixel
                    z_end = (line[-1] - zmax) / self.m_per_pixel
                    brush = QBrush()
                    brush.setStyle(Qt.SolidPattern)
                    brush.setColor(QColor(250, 250, 50))
                    self.addRect(tabs[4],
                                 z_start,
                                 tabs[5] - tabs[4],
                                 z_end - z_start,
                                 brush=brush)
                    txt = "oc=" + str(oc) + "\naccu=" + str(
                        accu) + "\ngrade=" + str(grade)
                    width = fm.width(txt)
                    text = self.addText(txt)
                    text.setPos(
                        tabs[5] + spacing,
                        -int(1.5 * fm.height()) + int(.5 * (z_start + z_end)))
                    self.addLine(tabs[4], z_start, tabs[6], z_start)
                    self.addLine(tabs[4], z_end, tabs[6], z_end)

                self.setSceneRect(self.itemsBoundingRect())

        QGraphicsScene.drawForeground(self, painter, rect)