RasterProcessing/CatchmentGrid/catchmentgrid.cpp

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

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