00001 #include <QtGui>
00002 #include "polygontopolylinedialog.h"
00003 #include "../../pihmLIBS/helpDialog/helpdialog.h"
00004 #include "../../pihmLIBS/polygonToPolyline.h"
00005 #include "../../pihmLIBS/shapefil.h"
00006
00007 #include <fstream>
00008 using namespace std;
00009
00010 polygonToPolyLineDialogDlg::polygonToPolyLineDialogDlg(QWidget *parent)
00011 {
00012 setupUi(this);
00013 connect(addFileButton, SIGNAL(clicked()), this, SLOT(addBrowse()));
00014 connect(removeFileButton, SIGNAL(clicked()), this, SLOT(removeBrowse()));
00015 connect(removeAllButton, SIGNAL(clicked()), this, SLOT(removeAllBrowse()));
00016 connect(okButton, 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 polygonToPolyLineDialogDlg::addBrowse()
00022 {
00023 QStringList temp = QFileDialog::getOpenFileNames(this, "Choose File", "~/","Internal Bounds File(*.shp *.SHP)");
00024 QString str = "";
00025 QString str1 = "";
00026
00027 unsigned int i;
00028
00029 int rows = inputOutputTable->numRows();
00030
00031 for(i=0; i< temp.count();i++)
00032 {
00033
00034 str = temp[i];
00035 str1 = temp[i];
00036 str1.truncate(str1.length()-4);
00037 str1.append("_PolyLine.shp");
00038 inputOutputTable->insertRows(rows + i);
00039 Q3TableItem *tmpItem = new Q3TableItem(inputOutputTable, Q3TableItem::Always, str );
00040 inputOutputTable->setItem(rows+i,0,tmpItem);
00041 tmpItem = new Q3TableItem(inputOutputTable, Q3TableItem::Always, str1 );
00042 inputOutputTable->setItem(rows+i,1,tmpItem);
00043 }
00044 }
00045
00046 void polygonToPolyLineDialogDlg::removeBrowse()
00047 {
00048 int tmp = inputOutputTable->numRows();
00049
00050 Q3MemArray <int> rowArray(tmp);
00051 int j=0;
00052 for(int i=0; i<tmp;i++){
00053 if(inputOutputTable->isRowSelected(i))
00054 {
00055 rowArray[j]=i;
00056 qWarning("\n %d",rowArray[j]);
00057 j++;
00058 }
00059 }
00060 rowArray.truncate(j);
00061 inputOutputTable->removeRows(rowArray);
00062 }
00063
00064 void polygonToPolyLineDialogDlg::removeAllBrowse()
00065 {
00066 int tmp = inputOutputTable->numRows();
00067 for(int i=0; i<= tmp;i++){
00068 inputOutputTable->removeRow(0);
00069 }
00070 }
00071
00072
00073 void polygonToPolyLineDialogDlg::run()
00074 {
00075
00076 QString logFileName("c:\log.html");
00077 ofstream log;
00078 log.open(logFileName.ascii());
00079 log<<"<html><body><font size=3 color=black><p> Verifying Files...</p></font></body></html>";
00080 log.close();
00081 MessageLog->setSource(logFileName);
00082 MessageLog->setFocus();
00083 MessageLog->setModified(TRUE);
00084
00085 QString polygonFileShp, polygonFileDbf, polyLineFileShp, polyLineFileDbf;
00086
00087 if(inputOutputTable->numRows() < 1){
00088 log.open(logFileName.ascii(), ios::app);
00089 log<<"<p><font size=3 color=red> First Please input Files</p>";
00090 log.close();
00091 MessageLog->reload();
00092 QApplication::processEvents();
00093 }
00094 else{
00095 for(int i=0; i<inputOutputTable->numRows();i++){
00096 polygonFileShp = inputOutputTable->text(i,0);
00097 polygonFileDbf = inputOutputTable->text(i,0);
00098 polygonFileDbf.truncate(polygonFileDbf.length()-3);
00099 polygonFileDbf.append("dbf");
00100
00101 polyLineFileShp = inputOutputTable->text(i,1);
00102 polyLineFileDbf = inputOutputTable->text(i,1);
00103 polyLineFileDbf.truncate(polyLineFileDbf.length()-3);
00104 polyLineFileDbf.append("dbf");
00105
00106 ifstream in;
00107 in.open(polygonFileShp.ascii());
00108 ofstream out;
00109 out.open(polyLineFileShp.ascii());
00110
00111 int runFlag = 1;
00112 log.open(logFileName.ascii(), ios::app);
00113 log<<"<p>Checking... "<<polygonFileShp.ascii()<<"... ";
00114 if(in == NULL){
00115 log<<"<font size=3 color=red> Error!</p>";
00116 runFlag = 0;
00117 qWarning("\n %s doesn't exist!", polygonFileShp.ascii());
00118 }
00119 else
00120 log<<"Done!</p>";
00121
00122 log<<"<p>Checking... "<<polyLineFileShp.ascii()<<"... ";
00123 if(out == NULL){
00124 log<<"<font size=3 color=red> Error!</p>";
00125 runFlag = 0;
00126 qWarning("\n %s doesn't exist!", polygonFileShp.ascii());
00127 }
00128 else
00129 log<<"Done!</p>";
00130 log.close();
00131 MessageLog->reload();
00132 QApplication::processEvents();
00133
00134 if(runFlag == 1){
00135
00136 int entities[1], type[1];
00137 double minbound[10], maxbound[10];
00138 SHPHandle tempHandle = SHPOpen(polygonFileShp, "rb");
00139 SHPGetInfo(tempHandle, entities, type, minbound, maxbound);
00140 std::cout<<"type= "<<type[0]<<"\n";
00141 if(type[0] != 5){
00142 log.open(logFileName.ascii(), ios::app);
00143 log<<"<p><font size=3 color=red>"<<polygonFileShp.ascii()<<" is not a polygon type </p>";
00144 qWarning("\n %s is NOT a POLYGON file", polygonFileShp.ascii());
00145 log.close();
00146 MessageLog->reload();
00147 QApplication::processEvents();
00148 }
00149 else{
00150 log.open(logFileName.ascii(), ios::app);
00151 log<<"<p>Running...";
00152 log.close();
00153 MessageLog->reload();
00154 QApplication::processEvents();
00155
00156 polygonToPolyline(polygonFileShp, polygonFileDbf, polyLineFileShp, polyLineFileDbf);
00157
00158 log.open(logFileName.ascii(), ios::app);
00159 log<<" Done!</p>";
00160 log.close();
00161 MessageLog->reload();
00162 QApplication::processEvents();
00163 }
00164 }
00165 }
00166 }
00167 }
00168
00169 void polygonToPolyLineDialogDlg::help()
00170 {
00171 helpDialog* hlpDlg = new helpDialog(this, "Polygon To Polyline", 1, "helpFiles/polygonToPolyLineDialog.html", "Help :: Polygon To Polyline");
00172 hlpDlg->show();
00173 }