00001 /**************************************************************************** 00002 ** ui.h extension file, included from the uic-generated form implementation. 00003 ** 00004 ** If you want to add, delete, or rename functions or slots, use 00005 ** Qt Designer to update this file, preserving your code. 00006 ** 00007 ** You should not define a constructor or destructor in this file. 00008 ** Instead, write your code in functions called init() and destroy(). 00009 ** These will automatically be called by the form's constructor and 00010 ** destructor. 00011 *****************************************************************************/ 00012 00013 #include "Image/Image.H" 00014 #include "Image/Pixels.H" 00015 #include "Util/Timer.H" 00016 #include "Util/Types.H" 00017 #include "Util/log.H" 00018 00019 void BeoSubMappingQtMainForm::init() 00020 { 00021 prefix = "bottom"; // defalut 00022 setSave = false; 00023 startTimer(100); 00024 } 00025 void BeoSubMappingQtMainForm::change_bottom() 00026 { 00027 prefix = "bottom"; 00028 } 00029 void BeoSubMappingQtMainForm::change_front() 00030 { 00031 prefix = "front"; 00032 } 00033 void BeoSubMappingQtMainForm::change_top() 00034 { 00035 prefix = "top"; 00036 } 00037 void BeoSubMappingQtMainForm::camera_return() 00038 { 00039 00040 // char *a = camera->text().ascii(); 00041 // prefix = a; 00042 00043 } 00044 00045 void BeoSubMappingQtMainForm::displayFunc() 00046 { 00047 float fx, fy; 00048 if(List->currentItem()!= -1) 00049 poolImage->getRealPosition(List->currentItem(), fx, fy); 00050 else 00051 fx= fy = 0.0F; 00052 if(List->currentItem() == 0) 00053 displayCoord->setText(QString(sformat("x:%f y:%f", 0.0F, 0.0F))); 00054 else 00055 displayCoord->setText(QString(sformat("x:%f y:%f", fx, fy))); 00056 } 00057 00058 void BeoSubMappingQtMainForm::timerEvent( QTimerEvent *e ) 00059 { 00060 displayFunc(); 00061 } 00062 00063 void BeoSubMappingQtMainForm::displayLog() 00064 { 00065 // open the selected log file 00066 FILE *f; 00067 char stemp[20]; 00068 std::string s; 00069 QString qs; 00070 00071 poolImage->currentItem(List->currentItem()); 00072 f = fopen(List->currentText().ascii(), "r"); 00073 //can't open the file 00074 if (f == NULL) 00075 Log->setText(QString("can't find the file")); 00076 else 00077 { 00078 if (fscanf(f, "%s\t", stemp) != 1) LFATAL("fscanf() failed"); 00079 // change to the number of lines in the LOg 00080 for(int i=0 ; i<8 ; i++) 00081 { 00082 if (fscanf( f, "%s", stemp) != 1) LFATAL("fscanf() failed"); 00083 if(i%2 == 0) 00084 qs += QString(sformat( "%s\t", stemp)); 00085 else 00086 qs += QString(sformat( "%s\n", stemp)); 00087 } 00088 00089 Log->setText(qs); 00090 } 00091 fclose(f); 00092 00093 // show the image 00094 QString qs2 = List->currentText().replace(".txt", ".png"); 00095 img = Raster::ReadRGB( qs2 ); 00096 QPixmap qpixm = convertToQPixmap( img ); 00097 00098 QWMatrix m; 00099 m.rotate( -90 ); // rotate coordinate system 00100 QPixmap rpm =qpixm.xForm( m ); 00101 test->setPixmap(rpm); 00102 displayImage->setPixmap(qpixm); 00103 } 00104 00105 // read the file and parse the coordinate 00106 void BeoSubMappingQtMainForm::loadList() 00107 { 00108 int i, j; 00109 //int tempx, tempy; 00110 float tempx, tempy, glx, gly; 00111 char stemp[10][20]; 00112 FILE *f; 00113 // start to load the total txt file in the dir 00114 refreshImages(); 00115 // create the object in opengl 00116 poolImage->reset(); 00117 createIcon(); 00118 // setting the postition for each one 00119 00120 for(i=0 ; i<numItem ; i++) 00121 { 00122 f = fopen(List->text(i).ascii(), "r"); 00123 // add the coordinate for the icon on the panel and the real coordinate 00124 for(j=0 ; j<9 ; j++) 00125 if (fscanf( f, "%s\t", stemp[j]) != 1) LFATAL("fscanf() failed"); 00126 00127 if (fscanf(f, "%f %f", &tempx, &tempy) != 2) LFATAL("fscanf() failed"); 00128 if(tempx != -1000 && tempy!=-1000) 00129 { 00130 // FIXME it should be the real coord 00131 //poolImage->setCoord(i, tempx, tempy); 00132 poolImage->getGLPosition(tempx, tempy, glx, gly); 00133 poolImage->setCoordByGL(i, glx, gly); 00134 } 00135 fclose(f); 00136 } 00137 00138 } 00139 00140 00141 // insert items into the list 00142 void BeoSubMappingQtMainForm::refreshImages() 00143 { 00144 DIR *dir; 00145 struct dirent *entry; 00146 int size = 50; 00147 char buffer[size], fileName[20]; 00148 00149 numItem = 0; 00150 List->clear(); 00151 if (getcwd(buffer, size) == NULL) LFATAL("cannot getcwd"); 00152 if((dir = opendir(buffer)) == NULL) 00153 printf("open dir error"); 00154 else 00155 { 00156 00157 while((entry = readdir(dir)) !=NULL) 00158 { 00159 if(entry->d_name[0] != '.') 00160 { 00161 strcpy(fileName, entry->d_name); 00162 QString qs(fileName); 00163 if(prefix =="bottom") 00164 { 00165 if(qs.contains("taskGdown.txt") > 0) 00166 { 00167 numItem++; 00168 List->insertItem(qs, 0); 00169 } 00170 if(qs.contains("taskAdown.txt") > 0) 00171 { 00172 numItem++; 00173 List->insertItem(qs,1); 00174 } 00175 if(qs.contains("taskBdown.txt") > 0) 00176 { 00177 numItem++; 00178 List->insertItem(qs,2); 00179 } 00180 if(qs.contains("taskCdown.txt") > 0) 00181 { 00182 numItem++; 00183 List->insertItem(qs, 3); 00184 } 00185 00186 } 00187 else if(prefix == "front") 00188 { 00189 if(qs.contains("taskGfront.txt") > 0) 00190 { 00191 numItem++; 00192 List->insertItem(qs, 0); 00193 } 00194 if(qs.contains("taskAfront.txt") > 0) 00195 { 00196 numItem++; 00197 List->insertItem(qs,1); 00198 } 00199 if(qs.contains("taskBfront.txt") > 0) 00200 { 00201 numItem++; 00202 List->insertItem(qs,2); 00203 } 00204 if(prefix == "top") 00205 { 00206 numItem++; 00207 List->insertItem(qs, 3); 00208 } 00209 } 00210 else if(prefix =="top") 00211 { 00212 if(qs.contains("taskGup.txt") > 0) 00213 { 00214 numItem++; 00215 List->insertItem(qs, 0); 00216 } 00217 if(qs.contains("taskSup.txt") > 0) 00218 { 00219 numItem++; 00220 List->insertItem(qs,1); 00221 } 00222 if(qs.contains("taskCup.txt") > 0) 00223 { 00224 numItem++; 00225 List->insertItem(qs, 2); 00226 } 00227 00228 } 00229 00230 } 00231 } 00232 if((dir = opendir(buffer)) == NULL) 00233 printf("open dir error"); 00234 else 00235 { 00236 while((entry = readdir(dir)) !=NULL) 00237 { 00238 if(entry->d_name[0] != '.') 00239 { 00240 strcpy(fileName, entry->d_name); 00241 QString qs(fileName); 00242 if(qs.contains(".txt") > 0 &&qs.contains(prefix) > 0&& qs.contains("task") <= 0) 00243 { 00244 numItem++; 00245 List->insertItem(qs); // fix me 00246 } 00247 } 00248 } 00249 } 00250 } 00251 } 00252 00253 // recreate or create the item 00254 void BeoSubMappingQtMainForm::createIcon() 00255 { 00256 if(numItem != 0) 00257 poolImage->createIcon(numItem); 00258 } 00259 00260 void BeoSubMappingQtMainForm::saveiconList() 00261 { 00262 // iconImage *list = poolImage->getList(); 00263 FILE *f; 00264 int i, j; 00265 //int tempx, tempy; 00266 float tempx, tempy, rx, ry; 00267 char stemp[10][20]; 00268 00269 // get every thing 00270 for(i=0 ; i<numItem ; i++) 00271 { 00272 f = fopen(List->text(i).ascii(), "r"); 00273 // add the coordinate for the icon on the panel and the real coordinate 00274 for(j=0 ; j<9 ; j++) 00275 if (fscanf( f, "%s\t", stemp[j]) != 1) LFATAL("fscanf() failed"); 00276 //fscanf(f, "%d %d", &tempx, &tempy); 00277 if (fscanf(f, "%f %f", &tempx, &tempy) != 2) LFATAL("fscanf() failed"); 00278 fclose(f); 00279 f = fopen(List->text(i).ascii(), "w"); 00280 // delete the last 2 lines and then add the new one 00281 for(j = 0 ; j<9 ; j++) 00282 fprintf(f, "%s\t", stemp[j]); 00283 00284 poolImage->getRealPosition(i, rx, ry); 00285 fprintf(f, "%f %f", rx, ry); 00286 //fprintf(f, "%d %d", list[i].x, list[i].y); 00287 fclose(f); 00288 } 00289 } 00290 00291 void BeoSubMappingQtMainForm::LoadAngleScale() 00292 { 00293 FILE *f; 00294 //char stemp[10]; 00295 float angle; 00296 float scale; 00297 f = fopen("anglescale.as", "r"); 00298 if (fscanf(f,"%f %f", &angle, &scale) != 2) LFATAL("fscanf() failed"); 00299 poolImage->angle = angle; 00300 poolImage->scale = scale; 00301 00302 fclose(f); 00303 } 00304 00305 void BeoSubMappingQtMainForm::resetAllHeading() 00306 { 00307 // read the file and reset the information about heading to t-1000 00308 DIR *dir; 00309 FILE *f; 00310 struct dirent *entry; 00311 int i, size = 50; 00312 char buffer[size], fileName[20]; 00313 char stemp[12][20]; 00314 if (getcwd(buffer, size) == NULL) LFATAL("cannot getcwd"); 00315 if((dir = opendir(buffer)) == NULL) 00316 printf("open dir error"); 00317 else 00318 { 00319 00320 while((entry = readdir(dir)) !=NULL) 00321 { 00322 if(entry->d_name[0] != '.') 00323 { 00324 strcpy(fileName, entry->d_name); 00325 QString qs(fileName); 00326 if(qs.contains(".txt") > 0) 00327 { 00328 f = fopen(qs.ascii(), "r"); 00329 for(i=0 ; i<12 ;i++) 00330 { 00331 if(i<9 || i==10) 00332 if (fscanf( f, "%s\t", stemp[i]) != 1) LFATAL("fscanf() failed"); 00333 if(i == 9) 00334 if (fscanf(f, "%s ",stemp[i]) != 1) LFATAL("fscanf() failed"); 00335 if(i==11) 00336 if (fscanf(f, "%s", stemp[i]) != 1) LFATAL("fscanf() failed"); 00337 } 00338 00339 fclose(f); 00340 f = fopen(qs.ascii(), "w"); 00341 for(i= 0 ; i<12 ; i++) 00342 { 00343 if(i!=1 && (i<9 ||i==10)) 00344 fprintf(f, "%s\t", stemp[i]); 00345 else if(i==1) 00346 fprintf(f, "%s\t", sformat("%f", -1000.0).c_str()); 00347 else if(i==11) 00348 fprintf(f, "%s",stemp[i]); 00349 } 00350 fclose(f); 00351 } 00352 } 00353 } 00354 } 00355 } 00356 00357 void BeoSubMappingQtMainForm::changeTheHeading() 00358 { 00359 FILE *f; 00360 int i; 00361 char stemp[12][20]; 00362 f = fopen(List->currentText().ascii(), "r"); 00363 for(i=0 ; i<12 ;i++) 00364 { 00365 if(i<9 || i==10) 00366 if (fscanf( f, "%s\t", stemp[i]) != 1) LFATAL("fscanf() failed"); 00367 if(i == 9) 00368 if (fscanf(f, "%s ",stemp[i]) != 1) LFATAL("fscanf() failed"); 00369 if(i==11) 00370 if (fscanf(f, "%s", stemp[i]) != 1) LFATAL("fscanf() failed"); 00371 } 00372 00373 fclose(f); 00374 f = fopen(List->currentText().ascii(), "w"); 00375 for(i= 0 ; i<12 ; i++) 00376 { 00377 if(i!=1 && (i<9 ||i==10)) 00378 fprintf(f, "%s\t", stemp[i]); 00379 else if(i==1) 00380 fprintf(f, "%s\t", changeHeading->text().ascii()); 00381 else if(i==11) 00382 fprintf(f, "%s",stemp[i]); 00383 } 00384 fclose(f); 00385 displayLog(); 00386 }