Esempio n. 1
0
class tuflowqgis_import_check_dialog(QDialog, Ui_tuflowqgis_import_check):
    def __init__(self, iface, project):
        QDialog.__init__(self)
        self.iface = iface
        self.setupUi(self)
        self.tfsettings = TF_Settings()

        # load stored settings
        self.last_chk_folder = self.tfsettings.get_last_chk_folder()
        error, message = self.tfsettings.Load()  # exe, tuflow dircetory and projection
        if error:
            QMessageBox.information(self.iface.mainWindow(), "Error", "Error Loading Settings: " + message)

        QObject.connect(self.browsedir, SIGNAL("clicked()"), self.browse_empty_dir)
        QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), self.run)

        if self.last_chk_folder == "Undefined":
            if self.tfsettings.combined.base_dir:
                self.last_chk_folder = os.path.join(self.tfsettings.combined.base_dir, "TUFLOW", "Check")
                self.emptydir.setText(self.last_chk_folder)
                # 	self.emptydir.setText(self.tfsettings.combined.base_dir+"\\TUFLOW\\check")
        else:
            self.emptydir.setText(self.last_chk_folder)
            # self.emptydir.setText = self.tfsettings.get_last_mi_folder()

    def browse_empty_dir(self):
        newname = QFileDialog.getExistingDirectory(None, "Output Directory", self.last_chk_folder)
        if newname != None:
            try:
                self.emptydir.setText(newname)
                self.tfsettings.save_last_chk_folder(newname)
            except:
                self.emptydir.setText("Problem Saving Settings")

    def run(self):
        runID = unicode(self.txtRunID.displayText()).strip()
        basedir = unicode(self.emptydir.displayText()).strip()
        showchecks = self.showchecks.isChecked()

        # run create dir script
        # message = tuflowqgis_import_check_tf(self.iface, basedir, runID, empty_types, points, lines, regions)
        message = tuflowqgis_import_check_tf(self.iface, basedir, runID, showchecks)
        # message = tuflowqgis_create_tf_dir(self.iface, crs, basedir)
        if message <> None:
            QMessageBox.critical(self.iface.mainWindow(), "Importing TUFLOW Empty File(s)", message)
Esempio n. 2
0
    def __init__(self, iface):
        QDialog.__init__(self)
        self.iface = iface
        self.setupUi(self)
        self.tfsettings = TF_Settings()
        self.last_mi = self.tfsettings.get_last_mi_folder()

        QObject.connect(self.browseoutfile, SIGNAL("clicked()"), self.browse_outdir)
        QObject.connect(self.buttonBox, SIGNAL("accepted()"), self.run)
Esempio n. 3
0
class tuflowqgis_splitMI_folder_dialog(QDialog, Ui_tuflowqgis_splitMI_folder):
    def __init__(self, iface):
        QDialog.__init__(self)
        self.iface = iface
        self.setupUi(self)
        self.tfsettings = TF_Settings()
        self.last_mi = self.tfsettings.get_last_mi_folder()

        QObject.connect(self.browseoutfile, SIGNAL("clicked()"), self.browse_outdir)
        QObject.connect(self.buttonBox, SIGNAL("accepted()"), self.run)

    def browse_outdir(self):
        # newname = QFileDialog.getExistingDirectory(None, "Output Directory")
        newname = QFileDialog.getExistingDirectory(None, "Output Directory", self.last_mi)
        if newname != None:
            self.outfolder.setText(newname)
            self.tfsettings.save_last_mi_folder(newname)

    def run(self):
        QMessageBox.information(self.iface.mainWindow(), "debug", "run")
        folder = unicode(self.outfolder.displayText()).strip()
        QMessageBox.information(self.iface.mainWindow(), "debug", "Folder: \n" + folder)

        mif_files = []
        if self.cbRecursive.isChecked():  # look in subfolders:
            for root, dirnames, filenames in os.walk(folder):
                for filename in fnmatch.filter(filenames, "*.mif"):
                    mif_files.append(os.path.join(root, filename))
        else:  # only specified folder
            filenames = os.listdir(folder)
            for filename in fnmatch.filter(filenames, "*.mif"):
                mif_files.append(os.path.join(folder, filename))

        nF = len(mif_files)
        # QMessageBox.information( self.iface.mainWindow(),"debug", "Number of mif files = :"+str(nF))

        for mif_file in mif_files:
            message, fname_P, fname_L, fname_R, npts, nln, nrg = split_MI_util2(mif_file)

            if message <> None:
                QMessageBox.information(self.iface.mainWindow(), "ERROR", message)
                QMessageBox.information(self.iface.mainWindow(), "point file", fname_P)
            else:
                QMessageBox.information(self.iface.mainWindow(), "ERROR", "Success")
Esempio n. 4
0
    def __init__(self, iface, project):
        QDialog.__init__(self)
        self.iface = iface
        self.setupUi(self)
        self.tfsettings = TF_Settings()
        project_loaded = False

        # load stored settings
        error, message = self.tfsettings.Load()
        if error:
            QMessageBox.information(self.iface.mainWindow(), "Error", "Error Loading Settings: " + message)

        if self.tfsettings.combined.tf_exe:
            tfexe = self.tfsettings.combined.tf_exe
            self.exefolder, dum = os.path.split(tfexe)
            project_loaded = True
        else:  # load last used exe
            tfexe = self.tfsettings.get_last_exe()
        if self.tfsettings.combined.base_dir:
            self.tffolder = self.tfsettings.combined.base_dir
            self.runfolder = os.path.join(self.tffolder, "TUFLOW", "runs")
            project_loaded = True
        else:  # load last used directory
            self.runfolder = self.tfsettings.get_last_run_folder()
        if not project_loaded:
            QMessageBox.information(
                self.iface.mainWindow(), "Information", "Project not loaded using last saved location."
            )

        self.TUFLOW_exe.setText(tfexe)

        QObject.connect(self.browsetcffile, SIGNAL("clicked()"), self.browse_tcf)
        QObject.connect(self.browseexe, SIGNAL("clicked()"), self.browse_exe)
        QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), self.run)

        files = glob.glob(unicode(self.runfolder) + os.path.sep + "*.tcf")
        self.tcfin = ""
        if len(files) > 0:
            files.sort(key=os.path.getmtime, reverse=True)
            self.tcfin = files[0]
        if len(self.tcfin) > 3:
            self.tcf.setText(self.tcfin)
Esempio n. 5
0
    def __init__(self, iface, project):
        QDialog.__init__(self)
        self.iface = iface
        self.setupUi(self)
        self.tfsettings = TF_Settings()

        # load stored settings
        self.last_chk_folder = self.tfsettings.get_last_chk_folder()
        error, message = self.tfsettings.Load()  # exe, tuflow dircetory and projection
        if error:
            QMessageBox.information(self.iface.mainWindow(), "Error", "Error Loading Settings: " + message)

        QObject.connect(self.browsedir, SIGNAL("clicked()"), self.browse_empty_dir)
        QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), self.run)

        if self.last_chk_folder == "Undefined":
            if self.tfsettings.combined.base_dir:
                self.last_chk_folder = os.path.join(self.tfsettings.combined.base_dir, "TUFLOW", "Check")
                self.emptydir.setText(self.last_chk_folder)
                # 	self.emptydir.setText(self.tfsettings.combined.base_dir+"\\TUFLOW\\check")
        else:
            self.emptydir.setText(self.last_chk_folder)
Esempio n. 6
0
    def __init__(self, iface, project):
        QDialog.__init__(self)
        self.iface = iface
        self.setupUi(self)
        self.canvas = self.iface.mapCanvas()
        # self.project = project
        cLayer = self.canvas.currentLayer()
        self.tfsettings = TF_Settings()
        self.crs = None
        fname = ""
        # message, tffolder, tfexe, tf_prj = load_project(self.project)
        # dont give error here as it may be the first occurence
        # if message != None:
        # 	QMessageBox.critical( self.iface.mainWindow(),"Error", message)

        # load global tfsettings
        # QMessageBox.information( self.iface.mainWindow(),"debug", "loading gloabal settings")
        error, message = self.tfsettings.Load()
        if error:
            QMessageBox.information(self.iface.mainWindow(), "Error", "Error Loading Global Settings: " + message)

            # set fields
        if self.tfsettings.project_settings.base_dir:
            self.outdir.setText(self.tfsettings.project_settings.base_dir)
        elif self.tfsettings.global_settings.base_dir:
            self.outdir.setText(self.tfsettings.global_settings.base_dir)
        else:
            self.outdir.setText("Not Yet Set")

        if self.tfsettings.project_settings.tf_exe:
            self.TUFLOW_exe.setText(self.tfsettings.project_settings.tf_exe)
        elif self.tfsettings.global_settings.tf_exe:
            self.TUFLOW_exe.setText(self.tfsettings.global_settings.tf_exe)
        else:
            self.TUFLOW_exe.setText("Not Yet Set")

        if self.tfsettings.project_settings.CRS_ID:
            self.form_crsID.setText(self.tfsettings.project_settings.CRS_ID)
            self.crs = QgsCoordinateReferenceSystem()
            success = self.crs.createFromString(self.tfsettings.project_settings.CRS_ID)
            if success:
                self.crsDesc.setText(self.crs.description())
        elif self.tfsettings.global_settings.CRS_ID:
            self.form_crsID.setText(self.tfsettings.global_settings.CRS_ID)
            self.crs = QgsCoordinateReferenceSystem()
            success = self.crs.createFromString(self.tfsettings.global_settings.CRS_ID)
            if success:
                self.crsDesc.setText(self.crs.description())
        else:
            # self.form_crsID.setText("Not Yet Set")
            if cLayer:
                cName = cLayer.name()
                self.crs = cLayer.crs()
                self.form_crsID.setText(self.crs.authid())
                self.crsDesc.setText(self.crs.description())
            else:
                self.crsDesc.setText("Please select CRS")
                self.form_crsID.setText("Please select CRS")
                self.crs = None

        if self.crs:
            self.sourcelayer.addItem("Use saved projection")
            cLayer = False
            self.sourcelayer.setCurrentIndex(0)

            # add vector data as options in dropbox
        i = 0
        for name, layer in QgsMapLayerRegistry.instance().mapLayers().iteritems():
            if layer.type() == QgsMapLayer.VectorLayer:
                self.sourcelayer.addItem(layer.name())
                if cLayer:
                    if layer.name() == cName:
                        self.sourcelayer.setCurrentIndex(i)
                i = i + 1
        if i == 0:
            self.sourcelayer.addItem("No Vector Data Open - use Set CRS Below")

        QObject.connect(self.browseoutfile, SIGNAL("clicked()"), self.browse_outdir)
        QObject.connect(self.browseexe, SIGNAL("clicked()"), self.browse_exe)
        QObject.connect(self.pbSelectCRS, SIGNAL("clicked()"), self.select_CRS)
        QObject.connect(self.sourcelayer, SIGNAL("currentIndexChanged(int)"), self.layer_changed)
        QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), self.run)
Esempio n. 7
0
class tuflowqgis_configure_tf_dialog(QDialog, Ui_tuflowqgis_configure_tf):
    def __init__(self, iface, project):
        QDialog.__init__(self)
        self.iface = iface
        self.setupUi(self)
        self.canvas = self.iface.mapCanvas()
        # self.project = project
        cLayer = self.canvas.currentLayer()
        self.tfsettings = TF_Settings()
        self.crs = None
        fname = ""
        # message, tffolder, tfexe, tf_prj = load_project(self.project)
        # dont give error here as it may be the first occurence
        # if message != None:
        # 	QMessageBox.critical( self.iface.mainWindow(),"Error", message)

        # load global tfsettings
        # QMessageBox.information( self.iface.mainWindow(),"debug", "loading gloabal settings")
        error, message = self.tfsettings.Load()
        if error:
            QMessageBox.information(self.iface.mainWindow(), "Error", "Error Loading Global Settings: " + message)

            # set fields
        if self.tfsettings.project_settings.base_dir:
            self.outdir.setText(self.tfsettings.project_settings.base_dir)
        elif self.tfsettings.global_settings.base_dir:
            self.outdir.setText(self.tfsettings.global_settings.base_dir)
        else:
            self.outdir.setText("Not Yet Set")

        if self.tfsettings.project_settings.tf_exe:
            self.TUFLOW_exe.setText(self.tfsettings.project_settings.tf_exe)
        elif self.tfsettings.global_settings.tf_exe:
            self.TUFLOW_exe.setText(self.tfsettings.global_settings.tf_exe)
        else:
            self.TUFLOW_exe.setText("Not Yet Set")

        if self.tfsettings.project_settings.CRS_ID:
            self.form_crsID.setText(self.tfsettings.project_settings.CRS_ID)
            self.crs = QgsCoordinateReferenceSystem()
            success = self.crs.createFromString(self.tfsettings.project_settings.CRS_ID)
            if success:
                self.crsDesc.setText(self.crs.description())
        elif self.tfsettings.global_settings.CRS_ID:
            self.form_crsID.setText(self.tfsettings.global_settings.CRS_ID)
            self.crs = QgsCoordinateReferenceSystem()
            success = self.crs.createFromString(self.tfsettings.global_settings.CRS_ID)
            if success:
                self.crsDesc.setText(self.crs.description())
        else:
            # self.form_crsID.setText("Not Yet Set")
            if cLayer:
                cName = cLayer.name()
                self.crs = cLayer.crs()
                self.form_crsID.setText(self.crs.authid())
                self.crsDesc.setText(self.crs.description())
            else:
                self.crsDesc.setText("Please select CRS")
                self.form_crsID.setText("Please select CRS")
                self.crs = None

        if self.crs:
            self.sourcelayer.addItem("Use saved projection")
            cLayer = False
            self.sourcelayer.setCurrentIndex(0)

            # add vector data as options in dropbox
        i = 0
        for name, layer in QgsMapLayerRegistry.instance().mapLayers().iteritems():
            if layer.type() == QgsMapLayer.VectorLayer:
                self.sourcelayer.addItem(layer.name())
                if cLayer:
                    if layer.name() == cName:
                        self.sourcelayer.setCurrentIndex(i)
                i = i + 1
        if i == 0:
            self.sourcelayer.addItem("No Vector Data Open - use Set CRS Below")

        QObject.connect(self.browseoutfile, SIGNAL("clicked()"), self.browse_outdir)
        QObject.connect(self.browseexe, SIGNAL("clicked()"), self.browse_exe)
        QObject.connect(self.pbSelectCRS, SIGNAL("clicked()"), self.select_CRS)
        QObject.connect(self.sourcelayer, SIGNAL("currentIndexChanged(int)"), self.layer_changed)
        QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), self.run)

        # QMessageBox.critical(self.iface.mainWindow(), "Setting Projection", "No vector data open, a shapefile is required for setting the model projection. \nPlease open or create a file in the desired projection.")

    def browse_outdir(self):
        # newname = QFileDialog.getExistingDirectory(None, QString.fromLocal8Bit("Output Directory"))
        newname = QFileDialog.getExistingDirectory(None, "Output Directory")
        if newname != None:
            # self.outdir.setText(QString(newname))
            self.outdir.setText(newname)

    def select_CRS(self):
        projSelector = QgsGenericProjectionSelector()
        projSelector.exec_()
        try:
            authid = projSelector.selectedAuthId()
            self.crs = QgsCoordinateReferenceSystem()
            success = self.crs.createFromString(authid)
            if not success:
                self.crs = None
            else:
                self.crsDesc.setText(self.crs.description())
                self.form_crsID.setText(authid)
        except:
            self.crs = None

    def browse_exe(self):

        # get last used dir
        last_exe = self.tfsettings.get_last_exe()
        if last_exe:
            last_dir, tail = os.path.split(last_exe)
        else:
            last_dir = ""

            # Get the file name
        inFileName = QFileDialog.getOpenFileName(
            self.iface.mainWindow(), "Select TUFLOW exe", last_dir, "TUFLOW Executable (*.exe)"
        )
        inFileName = str(inFileName)
        if len(inFileName) == 0:  # If the length is 0 the user pressed cancel
            return
            # Store the exe location and path we just looked in
        self.TUFLOW_exe.setText(inFileName)
        self.tfsettings.save_last_exe(inFileName)

    def layer_changed(self):
        layername = unicode(self.sourcelayer.currentText())
        if layername != "Use saved projection":
            layer = tuflowqgis_find_layer(layername)
            if layer != None:
                self.crs = layer.crs()
                self.form_crsID.setText(self.crs.authid())
                self.crsDesc.setText(self.crs.description())

    def run(self):
        tf_prj = unicode(self.form_crsID.displayText()).strip()
        basedir = unicode(self.outdir.displayText()).strip()
        tfexe = unicode(self.TUFLOW_exe.displayText()).strip()

        # Save Project Settings
        self.tfsettings.project_settings.CRS_ID = tf_prj
        self.tfsettings.project_settings.tf_exe = tfexe
        self.tfsettings.project_settings.base_dir = basedir
        error, message = self.tfsettings.Save_Project()
        if error:
            QMessageBox.information(
                self.iface.mainWindow(), "Error", "Error Saving Project Settings. Message: " + message
            )
        else:
            QMessageBox.information(self.iface.mainWindow(), "Information", "Project Settings Saved")

            # Save Global Settings
        if self.cbGlobal.isChecked():
            self.tfsettings.global_settings.CRS_ID = tf_prj
            self.tfsettings.global_settings.tf_exe = tfexe
            self.tfsettings.global_settings.base_dir = basedir
            error, message = self.tfsettings.Save_Global()
            if error:
                QMessageBox.information(
                    self.iface.mainWindow(), "Error", "Error Saving Global Settings. Message: " + message
                )
            else:
                QMessageBox.information(self.iface.mainWindow(), "Information", "Global Settings Saved")

        if self.cbCreate.isChecked():
            crs = QgsCoordinateReferenceSystem()
            crs.createFromString(tf_prj)

            # QMessageBox.information( self.iface.mainWindow(),"Creating TUFLOW directory", basedir)
            message = tuflowqgis_create_tf_dir(self.iface, crs, basedir)
            if message <> None:
                QMessageBox.critical(self.iface.mainWindow(), "Creating TUFLOW Directory ", message)

        if self.cbRun.isChecked():
            # tcf = os.path.join(basedir+"\\TUFLOW\\runs\\Create_Empties.tcf")
            tcf = os.path.join(basedir, "TUFLOW", "runs", "Create_Empties.tcf")
            QMessageBox.information(
                self.iface.mainWindow(), "Running TUFLOW", "Starting simulation: " + tcf + "\n Executable: " + tfexe
            )
            message = run_tuflow(self.iface, tfexe, tcf)
            if message <> None:
                QMessageBox.critical(self.iface.mainWindow(), "Running TUFLOW ", message)
Esempio n. 8
0
class tuflowqgis_run_tf_simple_dialog(QDialog, Ui_tuflowqgis_run_tf_simple):
    def __init__(self, iface, project):
        QDialog.__init__(self)
        self.iface = iface
        self.setupUi(self)
        self.tfsettings = TF_Settings()
        project_loaded = False

        # load stored settings
        error, message = self.tfsettings.Load()
        if error:
            QMessageBox.information(self.iface.mainWindow(), "Error", "Error Loading Settings: " + message)

        if self.tfsettings.combined.tf_exe:
            tfexe = self.tfsettings.combined.tf_exe
            self.exefolder, dum = os.path.split(tfexe)
            project_loaded = True
        else:  # load last used exe
            tfexe = self.tfsettings.get_last_exe()
        if self.tfsettings.combined.base_dir:
            self.tffolder = self.tfsettings.combined.base_dir
            self.runfolder = os.path.join(self.tffolder, "TUFLOW", "runs")
            project_loaded = True
        else:  # load last used directory
            self.runfolder = self.tfsettings.get_last_run_folder()
        if not project_loaded:
            QMessageBox.information(
                self.iface.mainWindow(), "Information", "Project not loaded using last saved location."
            )

        self.TUFLOW_exe.setText(tfexe)

        QObject.connect(self.browsetcffile, SIGNAL("clicked()"), self.browse_tcf)
        QObject.connect(self.browseexe, SIGNAL("clicked()"), self.browse_exe)
        QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), self.run)

        files = glob.glob(unicode(self.runfolder) + os.path.sep + "*.tcf")
        self.tcfin = ""
        if len(files) > 0:
            files.sort(key=os.path.getmtime, reverse=True)
            self.tcfin = files[0]
        if len(self.tcfin) > 3:
            self.tcf.setText(self.tcfin)

    def browse_tcf(self):
        # Get the file name
        inFileName = QFileDialog.getOpenFileName(
            self.iface.mainWindow(), "Select TUFLOW Control File", self.runfolder, "TUFLOW Control File (*.tcf)"
        )
        inFileName = str(inFileName)
        if len(inFileName) == 0:  # If the length is 0 the user pressed cancel
            return
            # Store the exe location and path we just looked in
        self.tcfin = inFileName
        # self.tfsettings.save_last_exe(self,last_exe)("TUFLOW_Run_TUFLOW/tcf", inFileName)

        self.tcf.setText(inFileName)
        head, tail = os.path.split(inFileName)
        if head <> os.sep and head.lower() <> "c:\\" and head <> "":
            self.tfsettings.save_last_run_folder(head)
            # self.tfsettings.setValue("TUFLOW_Run_TUFLOW/tcfDir", head)

    def browse_exe(self):
        # Get the file name
        inFileName = QFileDialog.getOpenFileName(
            self.iface.mainWindow(), "Select TUFLOW exe", self.exefolder, "TUFLOW Executable (*.exe)"
        )
        inFileName = str(inFileName)
        if len(inFileName) == 0:  # If the length is 0 the user pressed cancel
            return
            # Store the exe location and path we just looked in
        self.tfsettings.save_last_exe(inFileName)
        self.exe = inFileName
        # self.tfsettings.setValue("TUFLOW_Run_TUFLOW/exe", inFileName)
        self.TUFLOW_exe.setText(inFileName)
        # head, tail = os.path.split(inFileName)
        # if head <> os.sep and head.lower() <> 'c:\\' and head <> '':
        # 	self.tfsettings.setValue("TUFLOW_Run_TUFLOW/exeDir", head)

    def run(self):
        tcf = unicode(self.tcf.displayText()).strip()
        tfexe = unicode(self.TUFLOW_exe.displayText()).strip()
        QMessageBox.information(
            self.iface.mainWindow(), "Running TUFLOW", "Starting simulation: " + tcf + "\n Executable: " + tfexe
        )
        message = run_tuflow(self.iface, tfexe, tcf)
        if message <> None:
            QMessageBox.critical(self.iface.mainWindow(), "Running TUFLOW", message)