Exemplo n.º 1
0
 def __init__(self, parent):
     QtOpenGL.QGLWidget.__init__(self, parent)
     self.scaleChanged.connect(self.updateGL)
     self.centerChanged.connect(self.updateGL)
     self.__scale = 1.0
     self.__center = QtCore.QPointF(0.0, 0.0)
     self.__bg_color = PolygonViewerImpl.__DEFAULT_CLEAR_COLOR
     self.__use_all_colors = True
     self.__polygon_painter = PolygonPainter([], [], None)
Exemplo n.º 2
0
class PolygonViewerImpl(QtOpenGL.QGLWidget):

    scaleChanged = QtCore.pyqtSignal(float)
    centerChanged = QtCore.pyqtSignal(QtCore.QPointF)

    __MAX_SCALE = 10.0
    __MIN_SCALE = 0.01
    # Default color is ocean-blue
    __DEFAULT_CLEAR_COLOR = QtGui.QColor(28, 107, 160)


    def __init__(self, parent):
        QtOpenGL.QGLWidget.__init__(self, parent)
        self.scaleChanged.connect(self.updateGL)
        self.centerChanged.connect(self.updateGL)
        self.__scale = 1.0
        self.__center = QtCore.QPointF(0.0, 0.0)
        self.__bg_color = PolygonViewerImpl.__DEFAULT_CLEAR_COLOR
        self.__use_all_colors = True
        self.__polygon_painter = PolygonPainter([], [], None)


    def __set_projection(self, w, h):
        # Set up projection
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        x = float(w) / 500
        y = float(h) / 500
        gluOrtho2D(-x, x, -y, y)
        # Scale
        glScalef(self.scale, self.scale, 1.0)
        # Translate
        glTranslatef(-self.center.x(), -self.center.y(), 0.0)


    def getScale(self):
        return self.__scale


    @QtCore.pyqtSlot(float)
    def setScale(self, new_scale):
        if new_scale < self.__MIN_SCALE:
            new_scale = self.__MIN_SCALE
        elif new_scale > self.__MAX_SCALE:
            new_scale = self.__MAX_SCALE

        self.__scale = new_scale
        self.makeCurrent()
        self.__set_projection(self.width(), self.height())
        self.scaleChanged.emit(self.__scale)


    scale = property(getScale, setScale)


    def getCenter(self):
        return self.__center


    @QtCore.pyqtSlot(QtCore.QPointF)
    def setCenter(self, pt):
        self.__center = pt
        self.centerChanged.emit(pt)
        self.makeCurrent()
        self.__set_projection(self.width(), self.height())


    center = property(getCenter, setCenter)


    def getBgColor(self):
        return self.__bg_color


    @QtCore.pyqtSlot(QtGui.QColor)
    def setBgColor(self, color):
        self.__bg_color = color
        self.updateGL()


    bgColor = property(getBgColor, setBgColor)


    @QtCore.pyqtSlot(bool)
    def setUseAllColorsMode(self, use_all_colors):
        if self.__use_all_colors == use_all_colors:
            return
        self.__use_all_colors = use_all_colors
        self.__polygon_painter.set_use_colors_from_coloring(not use_all_colors)
        self.updateGL()


    def getUseAllColorsMode(self):
        return self.__use_all_colors


    useAllColorsMode = property(getUseAllColorsMode, setUseAllColorsMode)


    def set_polygon_painter(self, painter):
        self.__polygon_painter = painter
        self.updateGL()


    def paintGL(self):
        # Use ocean blue as clear color
        self.qglClearColor(self.__bg_color)
        glClear(GL_COLOR_BUFFER_BIT)

        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()

        self.__polygon_painter.paint_vbo()


    def resizeGL(self, w, h):
        # Set up the viewport
        glViewport(0, 0, w, h)

        aspect = float(w) / h
        self.__set_projection(w, h)


    def initializeGL(self):
        self.__set_projection(self.width(), self.height())