def __init__(
        self,
        iface,
        pointBuffer,
        picture_name,
        ParamPose,
        dem_box,
        cLayer,
        pathToData,
        crs,
        demName,
        isFrameBufferSupported,
    ):
        QtGui.QMainWindow.__init__(self)
        self.iface = iface
        self.cLayer = cLayer
        self.dem_box = dem_box
        self.ParamPose = ParamPose
        self.picture_name = picture_name
        self.pointBuffer = pointBuffer
        self.pathToData = pathToData
        self.crs = crs
        self.demName = demName
        self.isFrameBufferSupported = isFrameBufferSupported
        self.useOrthoImage = isinstance(self.pointBuffer.m_normal, int)
        self.haveMask = False
        self.polygonActivated = False

        self.ui = Ui_Monoplotter()
        self.qgl_window = QGLMonoplotter(pointBuffer, picture_name, ParamPose)

        img = QImage(picture_name)
        resolution = QDesktopWidget().screenGeometry()
        size = [0, 0]
        size[1] = resolution.height() / 2
        self.ratio = img.width() / float(img.height())
        size[0] = int(self.ratio * size[1])
        self.ui.setupUi(self, self.useOrthoImage)

        self.setCentralWidget(self.qgl_window)
        self.setFixedSize(size[0] + 200, size[1])

        self.ui.refreshButton.clicked.connect(self.refreshLayers)
        self.ui.saveButton.clicked.connect(self.saveImage)
        self.ui.spinBox.setValue(size[1])
        self.ui.spinBox.editingFinished.connect(self.resizeMonoplotter)
        self.ui.pushButton.clicked.connect(self.getOrtho)
        self.ui.buttonLabel.clicked.connect(self.openLabelSettings)
        self.ui.activatePolygon.clicked.connect(self.activatePolygonVisualization)

        if not self.useOrthoImage:
            self.ui.horizontalSlider.valueChanged.connect(self.changeTransparency)

        self.labelSetting = [QtGui.QColor(0, 0, 0), QFont(), 0, 0]
        self.ui.measure3D.toggled.connect(self.startMeasure3D)
        self.isMeasuring3D = False
class MonoplotterMainWindow(QtGui.QMainWindow):
    openOrtho = pyqtSignal()
    clearMapTool = pyqtSignal()
    closingMonoplot = pyqtSignal()

    def __init__(
        self,
        iface,
        pointBuffer,
        picture_name,
        ParamPose,
        dem_box,
        cLayer,
        pathToData,
        crs,
        demName,
        isFrameBufferSupported,
    ):
        QtGui.QMainWindow.__init__(self)
        self.iface = iface
        self.cLayer = cLayer
        self.dem_box = dem_box
        self.ParamPose = ParamPose
        self.picture_name = picture_name
        self.pointBuffer = pointBuffer
        self.pathToData = pathToData
        self.crs = crs
        self.demName = demName
        self.isFrameBufferSupported = isFrameBufferSupported
        self.useOrthoImage = isinstance(self.pointBuffer.m_normal, int)
        self.haveMask = False
        self.polygonActivated = False

        self.ui = Ui_Monoplotter()
        self.qgl_window = QGLMonoplotter(pointBuffer, picture_name, ParamPose)

        img = QImage(picture_name)
        resolution = QDesktopWidget().screenGeometry()
        size = [0, 0]
        size[1] = resolution.height() / 2
        self.ratio = img.width() / float(img.height())
        size[0] = int(self.ratio * size[1])
        self.ui.setupUi(self, self.useOrthoImage)

        self.setCentralWidget(self.qgl_window)
        self.setFixedSize(size[0] + 200, size[1])

        self.ui.refreshButton.clicked.connect(self.refreshLayers)
        self.ui.saveButton.clicked.connect(self.saveImage)
        self.ui.spinBox.setValue(size[1])
        self.ui.spinBox.editingFinished.connect(self.resizeMonoplotter)
        self.ui.pushButton.clicked.connect(self.getOrtho)
        self.ui.buttonLabel.clicked.connect(self.openLabelSettings)
        self.ui.activatePolygon.clicked.connect(self.activatePolygonVisualization)

        if not self.useOrthoImage:
            self.ui.horizontalSlider.valueChanged.connect(self.changeTransparency)

        self.labelSetting = [QtGui.QColor(0, 0, 0), QFont(), 0, 0]
        self.ui.measure3D.toggled.connect(self.startMeasure3D)
        self.isMeasuring3D = False

    def activatePolygonVisualization(self):
        if self.polygonActivated == False:
            self.polygonActivated = True
            self.qgl_window.polygonActivated = True
            self.ui.activatePolygon.setText("Disable Polygons")
        elif self.polygonActivated == True:
            self.polygonActivated = False
            self.qgl_window.polygonActivated = False
            self.ui.activatePolygon.setText("Enable Polygons")

    def changeTransparency(self, val):
        self.qgl_window.transparency = val * 50
        self.qgl_window.updateGL()

    def closeEvent(self, event):
        namePath = os.path.realpath(__file__)
        namePath = namePath.rsplit("\\", 3)
        path = namePath[0] + str("/plugins/Pic2Map/dustbin")
        folder = path.replace("\\", "/")
        self.qgl_window = None
        self.layerPolygonClipped = None
        self.closingMonoplot.emit()
        if os.path.isdir(folder):
            for the_file in os.listdir(folder):
                file_path = os.path.join(folder, the_file)
                file_path = file_path.replace("\\", "/")
                try:
                    if os.path.isfile(file_path):
                        os.unlink(file_path)
                except Exception, e:
                    print e