00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "smallmaps.h"
00022
00023 using namespace std;
00024
00025
00026 SmallMaps::SmallMaps( QWidget *parent, const char *name )
00027 : QWidget( parent, name )
00028 {
00029
00030
00031 QBoxLayout *topLayout = new QVBoxLayout( this, 5 );
00032
00033
00034 QMenuBar *menubar = new QMenuBar( this );
00035 menubar->setSeparator( QMenuBar::InWindowsStyle );
00036 QPopupMenu* popup;
00037 popup = new QPopupMenu( this );
00038 popup->insertItem( "&Quit", qApp, SLOT(quit()) );
00039 menubar->insertItem( "&File", popup );
00040
00041
00042 topLayout->setMenuBar( menubar );
00043
00044
00045 QBoxLayout *buttons = new QHBoxLayout( topLayout );
00046
00047 QPushButton* but1 = new QPushButton( this );
00048 QString s;
00049 s.sprintf( "Create Small Map ");
00050 but1->setText( s );
00051
00052
00053
00054
00055
00056 buttons->addWidget( but1, 10 );
00057
00058
00059
00060
00061
00062 QPushButton* but2 = new QPushButton( this );
00063 s.sprintf( "Create random Traffic ");
00064 but2->setText( s );
00065 buttons->addWidget( but2, 10 );
00066
00067
00068
00069
00070
00071
00072
00073
00074 const int labelCol = 0;
00075 const int linedCol = 1;
00076 const int multiCol = 2;
00077
00078
00079
00080 QGridLayout *grid = new QGridLayout( topLayout, 0, 0, 10 );
00081 int row=0;
00082
00083
00084 ed1 = new QLineEdit( this );
00085
00086 grid->addWidget( ed1, row, linedCol );
00087 ed1->setText("frida_bidi_plain.nod.xml");
00088
00089
00090 s.sprintf( "Original Map:" );
00091 QLabel *label1 = new QLabel( ed1, s, this );
00092
00093 grid->addWidget( label1, row, labelCol );
00094 row++;
00095
00096
00097 ed2 = new QLineEdit( this );
00098 grid->addWidget( ed2, row, linedCol );
00099 s.sprintf( "\tX1:" );
00100 QLabel *label2 = new QLabel( ed2, s, this );
00101 grid->addWidget( label2, row, labelCol );
00102 row++;
00103
00104
00105 ed3 = new QLineEdit( this );
00106 grid->addWidget( ed3, row, linedCol );
00107 s.sprintf( "\tX2:" );
00108 QLabel *label3 = new QLabel( ed3, s, this );
00109 grid->addWidget( label3, row, labelCol );
00110 row++;
00111
00112
00113 ed4 = new QLineEdit( this );
00114 grid->addWidget( ed4, row, linedCol );
00115 s.sprintf( "\tY1:" );
00116 QLabel *label4 = new QLabel( ed4, s, this );
00117 grid->addWidget( label4, row, labelCol );
00118 row++;
00119
00120
00121 ed5 = new QLineEdit( this );
00122 grid->addWidget( ed5, row, linedCol );
00123 s.sprintf( "\tY2:" );
00124 QLabel *label5 = new QLabel( ed5, s, this );
00125 grid->addWidget( label5, row, labelCol );
00126 row++;
00127
00128
00129
00130
00131
00132 med = new QTextView( this );
00133 grid->addMultiCellWidget( med, 0, -1, multiCol, multiCol );
00134
00135
00136
00137
00138 grid->setColStretch( linedCol, 10 );
00139 grid->setColStretch( multiCol, 20 );
00140
00141
00142 QLabel* sb = new QLabel( this );
00143 sb->setText( "Florides Andreas 2006 UCY" );
00144 sb->setFrameStyle( QFrame::Panel | QFrame::Sunken );
00145
00146
00147
00148 sb->setFixedHeight( sb->sizeHint().height() );
00149
00150 sb->setAlignment( AlignVCenter | AlignLeft );
00151 topLayout->addWidget( sb );
00152
00153 topLayout->activate();
00154
00155
00156 connect( but1, SIGNAL( clicked() ), SLOT( createmap() ) );
00157 connect( but2, SIGNAL( clicked() ), SLOT( createtraffic() ) );
00158 }
00159
00160 SmallMaps::~SmallMaps()
00161 {
00162
00163
00164 }
00165
00166 void
00167 SmallMaps::createmap()
00168 {
00169 char buffer[1024];
00170 FILE* fd ;
00171
00172 string fileName=ed1->text();
00173 int x1=atoi(ed2->text());
00174 int x2=atoi(ed3->text());
00175 int y1=atoi(ed4->text());
00176 int y2=atoi(ed5->text());
00177 char tempstring[500];
00178
00179 ifstream d_file;
00180 ofstream OUT ("smallfrida.nod.xml");
00181 string strb,temp;
00182 int x,y;
00183 char str[2000];
00184 int whereid,wherex,wherey,whereend;
00185
00186 d_file.open(ed1->text());
00187
00188 if (!d_file.is_open())
00189 {
00190
00191 med->append(tr("File"));
00192 med->append(ed1->text());
00193 med->append(tr("does not exist in the client's current directory\n "));
00194
00195 }
00196 else
00197 {
00198 sprintf(tempstring, "File OK. Start parsing with x:%d-%d and y:%d-%d",x1,x2,y1,y2);
00199 med->append(tempstring);
00200
00201 while(!d_file.eof())
00202 {
00203 d_file.getline(str,2000);
00204 strb=str;
00205 whereid=strb.find("id=",0);
00206 if (whereid != string::npos)
00207 {
00208 wherex=strb.find("x=",0);
00209 wherey=strb.find("y=",0);
00210 whereend=strb.find(">",0);
00211 x = atoi(strb.substr(wherex+3,wherey-12).c_str());
00212 if (x>x1&&x<x2)
00213 {
00214 y = atoi(strb.substr(wherey+3,whereend-2).c_str());
00215 if (y>y1&&y<y2) OUT << str << endl;
00216 }
00217
00218 }
00219 else OUT << str << endl;
00220 }
00221 d_file.close();
00222
00223 fd= popen("./netconvert --xml-node-files=smallfrida.nod.xml --xml-edge-files=frida_bidi_plain.edg.xml --output-file=smallfrida.net.xml --omit-corrupt-edges", "r");
00224 if (fd == NULL) {
00225 med->append( tr("Error executing netconvert, try manualy"));
00226 }
00227 while(fgets(buffer, sizeof(buffer), fd)!=NULL) {
00228 med->append(buffer);
00229 }
00230 pclose (fd);
00231
00232 }
00233 }
00234
00235 void
00236 SmallMaps::createtraffic()
00237 {
00238
00239 char buffer[1024];
00240 FILE* fd ;
00241
00242 med->append( tr("Creating random routes with jtrrouter...\n") );
00243
00244 fd= popen("export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/:/usr/lib/ ; jtrrouter --net=smallfrida.net.xml -R 2 --output-file=smallfrida.rou.xml -b 0 -e 100 --continue-on-unbuild ", "r");
00245 if (fd == NULL) {
00246 med->append( tr("Error executing jtrrouter, try manualy"));
00247 }
00248 while(fgets(buffer, sizeof(buffer), fd)!=NULL) {
00249 med->append(buffer);
00250 }
00251 pclose (fd);
00252
00253 }