Пример #1
0
    def __init__(self, iface=None, settingsPath=None):
        """ Constructor.

      :param iface: If specified, mapSettings attribute is initialized with the map settings of the map canvas.
                    The iface.legendInterface() is used to export vector layers in the same order as the legend.
      :type iface: QgisInterface
      :param settingsPath: Path to an existing settings file (.qto3settings).
      :type settingsPath: unicode
    """
        self.iface = iface
        self.mapSettings = None

        # create an export settings object
        self.settings = ExportSettings()
        if settingsPath:
            self.settings.loadSettingsFromFile(settingsPath)

        if iface:
            self.setMapSettings(iface.mapCanvas().mapSettings())
Пример #2
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)
Пример #3
0
  def __init__(self, iface=None, settingsPath=None):
    """ Constructor.

      :param iface: If specified, mapSettings attribute is initialized with the map settings of the map canvas.
                    The iface.legendInterface() is used to export vector layers in the same order as the legend.
      :type iface: QgisInterface
      :param settingsPath: Path to an existing settings file (.qto3settings).
      :type settingsPath: unicode
    """
    self.iface = iface
    self.mapSettings = None

    # create an export settings object
    self.settings = ExportSettings()
    if settingsPath:
      self.settings.loadSettingsFromFile(settingsPath)

    if iface:
      self.setMapSettings(iface.mapCanvas().mapSettings())
Пример #4
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)
Пример #5
0
class Exporter:
    """A convenient class to export the scenes to web programmatically
  """

    NO_ERROR = None

    def __init__(self, iface=None, settingsPath=None):
        """ Constructor.

      :param iface: If specified, mapSettings attribute is initialized with the map settings of the map canvas.
                    The iface.legendInterface() is used to export vector layers in the same order as the legend.
      :type iface: QgisInterface
      :param settingsPath: Path to an existing settings file (.qto3settings).
      :type settingsPath: unicode
    """
        self.iface = iface
        self.mapSettings = None

        # create an export settings object
        self.settings = ExportSettings()
        if settingsPath:
            self.settings.loadSettingsFromFile(settingsPath)

        if iface:
            self.setMapSettings(iface.mapCanvas().mapSettings())

    def setExtent(self, center, width, height, rotation=0):
        """ Set map extent to export settings.

    This is a convenience method to set map extent to export settings.
    Map settings should be set before this method is called.

    :param center: Center of the map extent in the map CRS.
    :type center: QgsPoint
    :param width: Width of the map extent in unit of the map CRS.
    :type width: float
    :param height: Height of the map extent in unit of the map CRS.
    :type height: float
    :param rotation: Rotation in degrees. Requires QGIS version 2.8 or later.
    :type rotation: float
    """
        if self.mapSettings is None:
            self.mapSettings = QgsMapSettings()

        if rotation:
            rect = RotatedRect(center, width, height, rotation)
            rect.toMapSettings(self.mapSettings)
        else:
            rect = QgsRectangle(center.x() - width / 2,
                                center.y() - height / 2,
                                center.x() + width / 2,
                                center.y() + height / 2)
            self.mapSettings.setExtent(rect)

        self.settings.setMapSettings(self.mapSettings)

    def setMapSettings(self, mapSettings):
        """Set map settings to export settings.

    Map settings is used to define base extent of the export and render a map canvas image.

    :param mapSettings: Map settings to be set.
    :type mapSettings: QgsMapSettings
    """
        self.mapSettings = mapSettings
        self.settings.setMapSettings(mapSettings)

    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
Пример #6
0
class Exporter:
  """A convenient class to export the scenes to web programmatically
  """

  NO_ERROR = None

  def __init__(self, iface=None, settingsPath=None):
    """ Constructor.

      :param iface: If specified, mapSettings attribute is initialized with the map settings of the map canvas.
                    The iface.legendInterface() is used to export vector layers in the same order as the legend.
      :type iface: QgisInterface
      :param settingsPath: Path to an existing settings file (.qto3settings).
      :type settingsPath: unicode
    """
    self.iface = iface
    self.mapSettings = None

    # create an export settings object
    self.settings = ExportSettings()
    if settingsPath:
      self.settings.loadSettingsFromFile(settingsPath)

    if iface:
      self.setMapSettings(iface.mapCanvas().mapSettings())

  def setExtent(self, center, width, height, rotation=0):
    """ Set map extent to export settings.

    This is a convenience method to set map extent to export settings.
    Map settings should be set before this method is called.

    :param center: Center of the map extent in the map CRS.
    :type center: QgsPoint
    :param width: Width of the map extent in unit of the map CRS.
    :type width: float
    :param height: Height of the map extent in unit of the map CRS.
    :type height: float
    :param rotation: Rotation in degrees. Requires QGIS version 2.8 or later.
    :type rotation: float
    """
    if self.mapSettings is None:
      self.mapSettings = QgsMapSettings()

    if rotation:
      rect = RotatedRect(center, width, height, rotation)
      rect.toMapSettings(self.mapSettings)
    else:
      rect = QgsRectangle(center.x() - width / 2, center.y() - height / 2,
                          center.x() + width / 2, center.y() + height / 2)
      self.mapSettings.setExtent(rect)

    self.settings.setMapSettings(self.mapSettings)

  def setMapSettings(self, mapSettings):
    """Set map settings to export settings.

    Map settings is used to define base extent of the export and render a map canvas image.

    :param mapSettings: Map settings to be set.
    :type mapSettings: QgsMapSettings
    """
    self.mapSettings = mapSettings
    self.settings.setMapSettings(mapSettings)

  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