Пример #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 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)
Пример #3
0
    def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.resize(
            QtCore.QSize(QtCore.QRect(0, 0, 440, 660).size()).expandedTo(
                Dialog.minimumSizeHint()))

        self.gridlayout = QGridLayout(Dialog)
        self.gridlayout.setObjectName("gridlayout")

        font = QFont()
        font.setPointSize(15)
        font.setWeight(50)
        font.setBold(True)

        self.label_2 = QLabel(Dialog)
        self.label_2.setFont(font)
        self.label_2.setTextFormat(QtCore.Qt.RichText)
        self.label_2.setObjectName("label_2")
        self.gridlayout.addWidget(self.label_2, 1, 1, 1, 2)

        self.textEdit = QTextEdit(Dialog)

        palette = QPalette()

        brush = QBrush(QColor(0, 0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QPalette.Active, QPalette.Base, brush)

        brush = QBrush(QColor(0, 0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QPalette.Inactive, QPalette.Base, brush)

        brush = QBrush(QColor(255, 255, 255))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QPalette.Disabled, QPalette.Base, brush)
        self.textEdit.setPalette(palette)
        self.textEdit.setAutoFillBackground(True)
        self.textEdit.width = 320
        self.textEdit.height = 360
        self.textEdit.setFrameShape(QFrame.NoFrame)
        self.textEdit.setFrameShadow(QFrame.Plain)
        self.textEdit.setReadOnly(True)
        self.textEdit.setObjectName("textEdit")
        self.textEdit.setTextInteractionFlags(QtCore.Qt.TextBrowserInteraction)

        self.gridlayout.addWidget(self.textEdit, 2, 1, 5, 2)

        self.pushButton = QPushButton(Dialog)
        self.pushButton.setObjectName("pushButton")
        self.gridlayout.addWidget(self.pushButton, 4, 2, 1, 1)

        spacerItem = QSpacerItem(20, 40, QSizePolicy.Minimum,
                                 QSizePolicy.Expanding)
        self.gridlayout.addItem(spacerItem, 3, 1, 1, 1)

        self.retranslateUi(Dialog)
        self.pushButton.clicked.connect(Dialog.reject)
        QtCore.QMetaObject.connectSlotsByName(Dialog)
Пример #4
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)