00001 #include <QtGui>
00002 #include "createtins.h"
00003
00004 #include "../../pihmLIBS/createTinShapeFile.h"
00005 #include "../../pihmLIBS/helpDialog/helpdialog.h"
00006
00007 #include <fstream>
00008 using namespace std;
00009
00010 createTINsDlg::createTINsDlg(QWidget *parent)
00011 {
00012 setupUi(this);
00013 connect(eleFileButton, SIGNAL(clicked()), this, SLOT(eleBrowse()));
00014 connect(nodeFileButton, SIGNAL(clicked()), this, SLOT(nodeBrowse()));
00015 connect(shpFileButton, SIGNAL(clicked()), this, SLOT(shpBrowse()));
00016 connect(runButton, SIGNAL(clicked()), this, SLOT(run()));
00017 connect(helpButton, SIGNAL(clicked()), this, SLOT(help()));
00018 connect(cancelButton, SIGNAL(clicked()), this, SLOT(close()));
00019 }
00020
00021 void createTINsDlg::eleBrowse()
00022 {
00023 QString str = QFileDialog::getOpenFileName(this, "Choose File", "~/","ele File(*.ele *.ELE)");
00024 eleFileLineEdit->setText(str);
00025 }
00026
00027 void createTINsDlg::nodeBrowse()
00028 {
00029 QString str = QFileDialog::getOpenFileName(this, "Choose File", "~/", "node File(*.node *.NODE)");
00030 nodeFileLineEdit->setText(str);
00031 }
00032
00033 void createTINsDlg::shpBrowse()
00034 {
00035 QString temp = QFileDialog::getSaveFileName(this, "Choose File", "~/","Shape File(*.shp *.SHP)");
00036 QString tmp = temp;
00037 if(!(tmp.toLower()).endsWith(".shp")){
00038 tmp.append(".shp");
00039 temp = tmp;
00040 }
00041
00042 shpFileLineEdit->setText(temp);
00043 }
00044
00045
00046 void createTINsDlg::run()
00047 {
00048
00049 QString logFileName("c:\log.html");
00050 ofstream log;
00051 log.open(logFileName.ascii());
00052 log<<"<html><body><font size=3 color=black><p> Verifying Files...</p></font></body></html>";
00053 log.close();
00054 MessageLog->setSource(logFileName);
00055 MessageLog->setFocus();
00056 MessageLog->setModified(TRUE);
00057
00058
00059 QString eleFileName((eleFileLineEdit->text()));
00060 QString nodeFileName((nodeFileLineEdit->text()));
00061 QString shpFileName((shpFileLineEdit->text()));
00062 QString dbfFileName(shpFileName);
00063 dbfFileName.truncate(dbfFileName.length()-3);
00064 dbfFileName.append("dbf");
00065
00066 int runFlag = 1;
00067 ifstream inEle(eleFileName.ascii());
00068 ifstream inNode(nodeFileName.ascii());
00069 ofstream outFile(shpFileName.ascii());
00070
00071 log.open(logFileName.ascii(), ios::app);
00072 if(eleFileName.length()==0){
00073 log<<"<p><font size=3 color=red> Error! Please input ele Input File</p>";
00074 runFlag = 0;
00075 }
00076 else{
00077 log<<"<p>Checking... "<<eleFileName.ascii()<<"... ";
00078 if(inEle == NULL){
00079 log<<"<font size=3 color=red> Error!</p>";
00080
00081 runFlag = 0;
00082 }
00083 else
00084 log<<"Done!</p>";
00085 }
00086 log.close();
00087 MessageLog->reload();
00088 QApplication::processEvents();
00089
00090
00091 log.open(logFileName.ascii(), ios::app);
00092 if(nodeFileName.length()==0){
00093 log<<"<p><font size=3 color=red> Error! Please input node Input File</p>";
00094 runFlag = 0;
00095 }
00096 else{
00097 log<<"<p>Checking... "<<nodeFileName.ascii()<<"... ";
00098 if(inNode == NULL){
00099 log<<"<font size=3 color=red> Error!</p>";
00100
00101 runFlag = 0;
00102 }
00103 else
00104 log<<"Done!</p>";
00105 }
00106 log.close();
00107 MessageLog->reload();
00108 QApplication::processEvents();
00109
00110
00111 log.open(logFileName.ascii(), ios::app);
00112 if(shpFileName.length()==0){
00113 log<<"<p><font size=3 color=red> Error! Please input Output Shape File</p>";
00114 runFlag = 0;
00115 }
00116 else{
00117 log<<"<p>Checking... "<<shpFileName.ascii()<<"... ";
00118 if(outFile == NULL){
00119 log<<"<font size=3 color=red> Error!</p>";
00120
00121 runFlag = 0;
00122 }
00123 else
00124 log<<"Done!</p>";
00125 }
00126 log.close();
00127 MessageLog->reload();
00128 QApplication::processEvents();
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143 if(runFlag == 1){
00144 log.open(logFileName.ascii(), ios::app);
00145 log<<"<p>Running TRINAGLE...";
00146 log.close();
00147 MessageLog->reload();
00148 QApplication::processEvents();
00149
00150 createTinShapeFile(eleFileName.ascii(), nodeFileName.ascii(), shpFileName.ascii(), dbfFileName.ascii(), "dummy");
00151
00152 log.open(logFileName.ascii(), ios::app);
00153 log<<" Done!</p>";
00154 log.close();
00155 MessageLog->reload();
00156 QApplication::processEvents();
00157 }
00158 }
00159
00160
00161
00162 void createTINsDlg::help()
00163 {
00164 helpDialog* hlpDlg = new helpDialog(this, "TIN Generation", 1, "helpFiles/tingeneration.html", "Help :: TIN Generation");
00165 hlpDlg->show();
00166
00167 }