VectorProcessing/splitLineDialog/splitlinedialog.cpp

Go to the documentation of this file.
00001 #include <QtGui>
00002 #include "splitlinedialog.h"
00003 #include "../../pihmLIBS/helpDialog/helpdialog.h"
00004 #include "../../pihmLIBS/splitLineAtVertices.h"
00005 #include "../../pihmLIBS/shapefil.h"
00006 
00007 #include <fstream>
00008 using namespace std;
00009 
00010 splitLineDialogDlg::splitLineDialogDlg(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 splitLineDialogDlg::addBrowse()
00022 {
00023         QStringList temp = QFileDialog::getOpenFileNames(this, "Choose File", "~/","Shape Files(*.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                         //std::cout<<"\n"<<temp[i].ascii();
00034                         str = temp[i];
00035                         str1 = temp[i];
00036                         str1.truncate(str1.length()-4);
00037                         str1.append("_Split.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 splitLineDialogDlg::removeBrowse()
00047 {
00048         int tmp = inputOutputTable->numRows();
00049                 //qWarning("\n %d",tmp);
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 splitLineDialogDlg::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 splitLineDialogDlg::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         if(inputOutputTable->numRows() < 1){
00086                 log.open(logFileName.ascii(), ios::app);
00087                 log<<"<p><font size=3 color=red> First Please input Files</p>";
00088                 log.close();
00089                 MessageLog->reload();
00090                 QApplication::processEvents();
00091         }
00092         else{
00093                 int rows = inputOutputTable->numRows();
00094                 QString shpFileName, dbfFileName, shpFileNameSplit, dbfFileNameSplit;
00095                 for(int i=0; i<rows; i++){
00096                         shpFileName = inputOutputTable->text(i, 0);
00097                         dbfFileName = shpFileName;
00098                         dbfFileName.truncate(dbfFileName.length()-3);
00099                         dbfFileName.append("dbf");
00100 
00101                         shpFileNameSplit = inputOutputTable->text(i, 1);
00102                         dbfFileNameSplit = shpFileNameSplit;
00103                         dbfFileNameSplit.truncate(dbfFileNameSplit.length()-3);
00104                         dbfFileNameSplit.append("dbf");
00105                 
00106                         ifstream in;
00107                         in.open(shpFileName.ascii());
00108                         ofstream out;
00109                         out.open(shpFileNameSplit.ascii());
00110                         
00111                         int runFlag = 1;
00112                         log.open(logFileName.ascii(), ios::app);
00113                         log<<"<p>Checking... "<<shpFileName.ascii()<<"... ";
00114                         if(in == NULL){
00115                                 log<<"<font size=3 color=red> Error!</p>";
00116                                 runFlag = 0;
00117                                 qWarning("\n %s doesn't exist!", shpFileName.ascii());                        
00118                         }
00119                         else
00120                                 log<<"Done!</p>";
00121                         log<<"<p>Checking... "<<shpFileNameSplit.ascii()<<"... ";               
00122                         if(out == NULL){
00123                                 log<<"<font size=3 color=red> Error!</p>";
00124                                 runFlag = 0;
00125                                 qWarning("\n %s doesn't exist!", shpFileNameSplit.ascii());
00126                         }
00127                         else
00128                                 log<<"Done!</p>";
00129                         log.close();
00130                         MessageLog->reload();
00131                         QApplication::processEvents();
00132 
00133                         if(runFlag == 1){
00134                                 log.open(logFileName.ascii(), ios::app);
00135                                 log<<"<p>Running... "<<shpFileName.ascii();
00136                                 log.close();
00137                                 MessageLog->reload();
00138                                 QApplication::processEvents();
00139 
00140                                 splitLineAtVertices(shpFileName.ascii(), dbfFileName.ascii(), shpFileNameSplit.ascii(), dbfFileNameSplit.ascii());
00141                                 log.open(logFileName.ascii(), ios::app);
00142                                 log<<" Done!</p>";
00143                                 log.close();
00144                                 MessageLog->reload();
00145                                 QApplication::processEvents();
00146                         }
00147                         in.close();
00148                         out.close();
00149                 }
00150         }
00151 }
00152 
00153 void splitLineDialogDlg::help()
00154 {
00155         helpDialog* hlpDlg = new helpDialog(this, "Split Line", 1, "helpFiles/splitLineDialog.html", "Help :: Split Line");
00156         hlpDlg->show(); 
00157 }

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