RasterProcessing/StreamGrid/streamgrid.cpp

Go to the documentation of this file.
00001 #include <QtGui>
00002 #include "streamgrid.h"
00003 #include "../../pihmRasterLIBS/lsm.h"
00004 #include "../../pihmRasterLIBS/flood.h"
00005 #include "../../pihmRasterLIBS/setdir.h"
00006 #include "../../pihmRasterLIBS/aread8.h"
00007 #include "../../pihmRasterLIBS/streamSegmentation.h"
00008 #include "../../pihmRasterLIBS/streamDefinition.h"
00009 
00010 #include "../../pihmLIBS/helpDialog/helpdialog.h"
00011 
00012 #include <fstream>
00013 using namespace std;
00014 
00015 
00016 StreamGridDlg::StreamGridDlg(QWidget *parent)
00017 {
00018         setupUi(this);
00019         connect(inputBrowseButton, SIGNAL(clicked()), this, SLOT(inputBrowse()));
00020         connect(outputBrowseButton, SIGNAL(clicked()), this, SLOT(outputBrowse()));
00021         connect(runButton, SIGNAL(clicked()), this, SLOT(run()));
00022         connect(helpButton, SIGNAL(clicked()), this, SLOT(help()));
00023         connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
00024 }
00025 
00026 void StreamGridDlg::inputBrowse()
00027 {
00028         QString str = QFileDialog::getOpenFileName(this, "Choose File", "~/","Flow Acc Grid File(*.adf *.asc)");
00029         inputFileLineEdit->setText(str);
00030 }
00031 
00032 
00033 void StreamGridDlg::outputBrowse()
00034 {
00035         QString temp = QFileDialog::getSaveFileName(this, "Choose File", "~/","Stream Grid File(*.adf *.asc)");
00036         QString tmp = temp;
00037         if(!(tmp.toLower()).endsWith(".asc")){
00038         tmp.append(".asc");
00039         temp = tmp;
00040         }
00041         
00042         outputFileLineEdit->setText(temp);
00043 }
00044 
00045 
00046 void StreamGridDlg::run()
00047 {
00048         QString logFileName("c:\log.html");
00049         ofstream log;
00050         log.open(logFileName.ascii());
00051         log<<"<html><body><font size=3 color=black><p> Verifying Files...</p></font></body></html>";
00052         log.close();
00053         messageLog->setSource(logFileName);
00054         messageLog->setFocus();
00055         messageLog->setModified(TRUE);  
00056 
00057         QString inputFileName((inputFileLineEdit->text()));
00058         QString outputFileName((outputFileLineEdit->text()));
00059         double thresh;
00060         thresh = (inputThreshLineEdit->text()).toDouble();
00061         
00062         ifstream inFile;      inFile.open((inputFileLineEdit->text()).ascii());
00063         ofstream outFile;    outFile.open((outputFileLineEdit->text()).ascii());
00064         int runFlag = 1;
00065 
00066         log.open(logFileName.ascii(), ios::app);
00067         if(inputFileName.length()==0){
00068                 log<<"<p><font size=3 color=red> Error! Please input Flow Acc. Grid Input File</p>";
00069                 runFlag = 0;
00070         }
00071         else{
00072                 log<<"<p>Checking... "<<inputFileName.ascii()<<"... ";
00073                 if(inFile == NULL){
00074                         log<<"<font size=3 color=red> Error!</p>";
00075                         qWarning("\n%s doesn't exist!", (inputFileLineEdit->text()).ascii());
00076                         runFlag = 0;
00077                 }
00078                 else
00079                         log<<"Done!</p>";
00080         }
00081         log.close();
00082         messageLog->reload();
00083         QApplication::processEvents();
00084 
00085         log.open(logFileName.ascii(), ios::app);
00086         if(outputFileName.length()==0){
00087                 log<<"<p><font size=3 color=red> Error! Please input Stream Grid Output File</p>";
00088                 runFlag = 0;
00089         }
00090         else{
00091                 log<<"<p>Checking... "<<outputFileName.ascii()<<"... ";
00092                 if(outFile == NULL){
00093                         log<<"<font size=3 color=red> Error!</p>";
00094                         qWarning("\nCan not open output file name");
00095                         runFlag = 0;
00096                 }
00097                 else
00098                         log<<"Done!</p>";
00099         }
00100         log.close();
00101         messageLog->reload();
00102         QApplication::processEvents();
00103 
00104         log.open(logFileName.ascii(), ios::app);
00105         if((inputThreshLineEdit->text()).length() == 0){
00106                 log<<"<p><font size=3 color=red> Error! Please input Threshold</p>";
00107                 runFlag = 0;
00108         }
00109         log.close();
00110         messageLog->reload();
00111         QApplication::processEvents();
00112 
00113         if(runFlag == 1){
00114                 log.open(logFileName.ascii(), ios::app);
00115                 log<<"<p>Running...";
00116                 log.close();
00117                 messageLog->reload();
00118                 QApplication::processEvents();
00119 
00120                 int err1 = streamDefinition((char *)inputFileName.ascii(), "dummy", (char *)outputFileName.ascii(), 1, thresh );
00121         
00122                 log.open(logFileName.ascii(), ios::app);
00123                 log<<" Done!</p>";
00124                 log.close();
00125                 messageLog->reload();
00126                 QApplication::processEvents();
00127 
00128                 if(showSG_DFrame->isChecked() == 1){
00129                         //QgsRasterLayer *tempLayer = new QgsRasterLayer("/backup/pihm/RasterProcessing/FillPits", "morgedem.asc");
00130                         applicationPointer->addRasterLayer(QStringList(outputFileName));
00131                 }
00132         }
00133 }
00134 
00135 void StreamGridDlg::help()
00136 {
00137         helpDialog* hlpDlg = new helpDialog(this, "Stream Grid", 1, "helpFiles/streamgrid.html", "Help :: Stream Grid");
00138         hlpDlg->show(); 
00139 
00140 }
00141 
00142 void StreamGridDlg::setApplicationPointer(QgisApp* appPtr){
00143     applicationPointer = appPtr;
00144 }

Generated on Sun Aug 5 17:34:00 2007 for PIHMgis by  doxygen 1.5.2