Пример #1
0
    def export(self, htmlPath, openBrowser=False):
        """Do export.

    :param htmlPath: Output HTML file path.
    :type htmlPath: unicode
    :param openBrowser: If True, open the exported page using default web browser.
    :type openBrowser: bool

    :returns: Exporter.NO_ERROR if success. Otherwise returns error message.
    :rtype: None or unicode.
    """
        self.settings.setOutputFilename(htmlPath)

        # check validity of export settings
        err_msg = self.settings.checkValidity()
        if err_msg:
            return err_msg

        ret = exportToThreeJS(
            self.settings,
            self.iface.legendInterface() if self.iface else None)
        if not ret:
            return "Failed to export (Unknown error)"

        if openBrowser:
            qgis2threejstools.openHTMLFile(self.settings.htmlfilename)

        return Exporter.NO_ERROR
Пример #2
0
  def export(self, htmlPath, openBrowser=False):
    """Do export.

    :param htmlPath: Output HTML file path.
    :type htmlPath: unicode
    :param openBrowser: If True, open the exported page using default web browser.
    :type openBrowser: bool

    :returns: Exporter.NO_ERROR if success. Otherwise returns error message.
    :rtype: None or unicode.
    """
    self.settings.setOutputFilename(htmlPath)

    # check validity of export settings
    err_msg = self.settings.checkValidity()
    if err_msg:
      return err_msg

    ret = exportToThreeJS(self.settings, self.iface.legendInterface() if self.iface else None)
    if not ret:
      return "Failed to export (Unknown error)"

    if openBrowser:
      qgis2threejstools.openHTMLFile(self.settings.htmlfilename)

    return Exporter.NO_ERROR
Пример #3
0
    def run(self):
        self.endPointSelection()

        ui = self.ui
        filename = ui.lineEdit_OutputFilename.text()  # ""=Temporary file
        if filename and os.path.exists(filename):
            if (
                QMessageBox.question(
                    self,
                    "Qgis2threejs",
                    "Output file already exists. Overwrite it?",
                    QMessageBox.Ok | QMessageBox.Cancel,
                )
                != QMessageBox.Ok
            ):
                return

        # export to web (three.js)
        canvas = self.iface.mapCanvas()
        export_settings = ExportSettings(self.settings(), canvas, self.pluginManager, self.localBrowsingMode)

        valid, err_msg = export_settings.checkValidity()
        if not valid:
            QMessageBox.warning(self, "Qgis2threejs", err_msg or "Invalid settings")
            return

        ui.pushButton_Run.setEnabled(False)
        ui.toolButton_Settings.setVisible(False)
        self.clearMessageBar()
        self.progress(0)

        if export_settings.exportMode == ExportSettings.PLAIN_MULTI_RES:
            # update quads and point on map canvas
            self.createRubberBands(export_settings.baseExtent, export_settings.quadtree)

        # export
        ret = exportToThreeJS(export_settings, self.iface.legendInterface(), self.objectTypeManager, self.progress)

        self.progress(100)
        ui.pushButton_Run.setEnabled(True)

        if not ret:
            ui.toolButton_Settings.setVisible(True)
            return

        self.clearRubberBands()

        # store last selections
        settings = QSettings()
        settings.setValue("/Qgis2threejs/lastTemplate", export_settings.templateName)
        settings.setValue("/Qgis2threejs/lastControls", export_settings.controls)

        # open web browser
        if not tools.openHTMLFile(export_settings.htmlfilename):
            ui.toolButton_Settings.setVisible(True)
            return

        # close dialog
        QDialog.accept(self)
Пример #4
0
    def run(self):
        ui = self.ui
        filename = ui.lineEdit_OutputFilename.text()  # ""=Temporary file
        if filename != "" and QFileInfo(
                filename).exists() and QMessageBox.question(
                    None, "Qgis2threejs",
                    "Output file already exists. Overwrite it?",
                    QMessageBox.Ok | QMessageBox.Cancel) != QMessageBox.Ok:
            return
        self.endPointSelection()

        item = ui.treeWidget_VectorLayers.currentItem()
        if item:
            self.saveVectorProperties(item.data(0, Qt.UserRole))

        ui.pushButton_Run.setEnabled(False)
        self.progress(0)

        canvas = self.iface.mapCanvas()
        htmlfilename = ui.lineEdit_OutputFilename.text()
        demlayerid = ui.comboBox_DEMLayer.itemData(
            ui.comboBox_DEMLayer.currentIndex())
        mapTo3d = MapTo3D(canvas,
                          verticalExaggeration=float(
                              ui.lineEdit_zFactor.text()))
        if self.ui.radioButton_Simple.isChecked():
            dem_width = int(ui.lineEdit_Width.text())
            dem_height = int(ui.lineEdit_Height.text())
            context = OutputContext(mapTo3d, canvas, demlayerid,
                                    self.vectorPropertiesDict,
                                    self.objectTypeManager,
                                    self.localBrowsingMode, dem_width,
                                    dem_height)
            htmlfilename = runSimple(htmlfilename, context, self.progress)
        else:
            context = OutputContext(mapTo3d, canvas, demlayerid,
                                    self.vectorPropertiesDict,
                                    self.objectTypeManager,
                                    self.localBrowsingMode)
            htmlfilename = runAdvanced(htmlfilename, context, self,
                                       self.progress)
        self.progress(100)
        ui.pushButton_Run.setEnabled(True)
        if htmlfilename is None:
            return
        self.clearRubberBands()

        if not tools.openHTMLFile(htmlfilename):
            return
        QDialog.accept(self)
Пример #5
0
  def run(self):
    ui = self.ui
    filename = ui.lineEdit_OutputFilename.text()   # ""=Temporary file
    if filename != "" and QFileInfo(filename).exists() and QMessageBox.question(None, "Qgis2threejs", "Output file already exists. Overwrite it?", QMessageBox.Ok | QMessageBox.Cancel) != QMessageBox.Ok:
      return
    self.endPointSelection()

    # save properties of current object
    item = self.ui.treeWidget.currentItem()
    if item and self.currentPage:
      self.saveProperties(item, self.currentPage)

    ui.pushButton_Run.setEnabled(False)
    self.clearMessageBar()
    self.progress(0)

    canvas = self.iface.mapCanvas()
    cbox = self.ui.comboBox_Template
    templateName = cbox.currentText()
    templateType = cbox.itemData(cbox.currentIndex(), Qt.UserRole)
    htmlfilename = ui.lineEdit_OutputFilename.text()

    # world properties
    world = self.properties[ObjectTreeItem.ITEM_WORLD] or {}
    verticalExaggeration = world.get("lineEdit_zFactor", 1.5)
    verticalShift = world.get("lineEdit_zShift", 0)

    # export to javascript (three.js)
    mapTo3d = MapTo3D(canvas, verticalExaggeration=float(verticalExaggeration), verticalShift=float(verticalShift))
    context = OutputContext(templateName, templateType, mapTo3d, canvas, self.properties, self, self.objectTypeManager, self.localBrowsingMode)
    htmlfilename = exportToThreeJS(htmlfilename, context, self.progress)

    self.progress(100)
    ui.pushButton_Run.setEnabled(True)
    if htmlfilename is None:
      return
    self.clearRubberBands()

    # store last selections
    settings = QSettings()
    settings.setValue("/Qgis2threejs/lastTemplate", templateName)
    settings.setValue("/Qgis2threejs/lastControls", context.controls)

    # open browser
    if not tools.openHTMLFile(htmlfilename):
      return
    QDialog.accept(self)
Пример #6
0
  def run(self):
    ui = self.ui
    filename = ui.lineEdit_OutputFilename.text()   # ""=Temporary file
    if filename != "" and QFileInfo(filename).exists() and QMessageBox.question(None, "Qgis2threejs", "Output file already exists. Overwrite it?", QMessageBox.Ok | QMessageBox.Cancel) != QMessageBox.Ok:
      return
    self.endPointSelection()

    item = ui.treeWidget_VectorLayers.currentItem()
    if item:
      self.saveVectorProperties(item.data(0, Qt.UserRole))

    ui.pushButton_Run.setEnabled(False)
    self.progress(0)

    canvas = self.iface.mapCanvas()
    htmlfilename = ui.lineEdit_OutputFilename.text()
    demlayerid = ui.comboBox_DEMLayer.itemData(ui.comboBox_DEMLayer.currentIndex())
    mapTo3d = MapTo3D(canvas, verticalExaggeration=float(ui.lineEdit_zFactor.text()))
    if self.ui.radioButton_Simple.isChecked():
      dem_width = int(ui.lineEdit_Width.text())
      dem_height = int(ui.lineEdit_Height.text())
      context = OutputContext(mapTo3d, canvas, demlayerid, self.vectorPropertiesDict, self.objectTypeManager, self.localBrowsingMode,
                              dem_width, dem_height)
      htmlfilename = runSimple(htmlfilename, context, self.progress)
    else:
      context = OutputContext(mapTo3d, canvas, demlayerid, self.vectorPropertiesDict, self.objectTypeManager, self.localBrowsingMode)
      htmlfilename = runAdvanced(htmlfilename, context, self, self.progress)
    self.progress(100)
    ui.pushButton_Run.setEnabled(True)
    if htmlfilename is None:
      return
    self.clearRubberBands()

    if not tools.openHTMLFile(htmlfilename):
      return
    QDialog.accept(self)
Пример #7
0
    def run(self):
        self.endPointSelection()

        ui = self.ui
        filename = ui.lineEdit_OutputFilename.text()  # ""=Temporary file
        if filename and os.path.exists(filename):
            if QMessageBox.question(
                    self, "Qgis2threejs",
                    "Output file already exists. Overwrite it?",
                    QMessageBox.Ok | QMessageBox.Cancel) != QMessageBox.Ok:
                return

        # export to web (three.js)
        export_settings = ExportSettings(self.pluginManager,
                                         self.localBrowsingMode)
        export_settings.loadSettings(self.settings())
        export_settings.setMapCanvas(self.iface.mapCanvas())

        err_msg = export_settings.checkValidity()
        if err_msg is not None:
            QMessageBox.warning(self, "Qgis2threejs", err_msg
                                or "Invalid settings")
            return

        ui.pushButton_Run.setEnabled(False)
        ui.toolButton_Settings.setVisible(False)
        self.clearMessageBar()
        self.progress(0)

        if export_settings.exportMode == ExportSettings.PLAIN_MULTI_RES:
            # update quads and point on map canvas
            self.createRubberBands(export_settings.baseExtent,
                                   export_settings.quadtree())

        # export
        ret = exportToThreeJS(export_settings, self.iface.legendInterface(),
                              self.objectTypeManager, self.progress)

        self.progress(100)
        ui.pushButton_Run.setEnabled(True)

        if not ret:
            ui.toolButton_Settings.setVisible(True)
            return

        self.clearRubberBands()

        # store last selections
        settings = QSettings()
        settings.setValue("/Qgis2threejs/lastTemplate",
                          export_settings.templatePath)
        settings.setValue("/Qgis2threejs/lastControls",
                          export_settings.controls)

        # open web browser
        if not tools.openHTMLFile(export_settings.htmlfilename):
            ui.toolButton_Settings.setVisible(True)
            return

        # close dialog
        QDialog.accept(self)