Changeset 51 for anr/gantt.l
- Timestamp:
- Jan 31, 2010, 12:53:01 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anr/gantt.l
r36 r51 4 4 #define COLOR_BOX_LIGHT "gtcBoxLight" 5 5 6 #define PICT_TOPSEP 37 #define PICT_BOTSEP 3 8 #define PICT_LEFTSEP 3 9 #define PICT_RIGHTSEP 3 10 #define PICT_VSEP 2 11 #define PICT_HSEP 2 6 #define PICT_TOPSEP 0.0 7 #define PICT_BOTSEP 3.0 8 #define PICT_LEFTSEP 3.0 9 #define PICT_RIGHTSEP 3.0 10 #define PICT_VSEP 2.0 11 #define PICT_HSEP 2.0 12 12 13 13 #define PICT_MONTHHEIGHT 5 // police height … … 17 17 #define TASK_BGC0 "gtcTaskBG0" 18 18 #define TASK_BGC1 "gtcTaskBG1" 19 #define TASK_TITLEHEIGHT 6. 20 #define TASK_TITLEFONTHEIGHT 2. 19 21 20 22 #define DELIVRABLE_VSEP 1 … … 25 27 #define DELIVRABLE_TITLEHEIGHT DELIVRABLE_HEIGHT 26 28 #define DELIVRABLE_BOXHEIGHT (DELIVRABLE_HEIGHT) 29 30 char* task_names[] = { 31 "Project management", 32 "Backbone infrastructure", 33 "System generation", 34 "HAS front-end", 35 "HAS back-end", 36 "PC/FPGA communication middleware", 37 "Industrial demonstrators", 38 "Dissemination", 39 0 40 }; 27 41 28 42 typedef struct _Tlivrable { … … 34 48 double task_y; // top of task 35 49 double task_dy; // bot of task is task_y+task_dy 50 double task_y_del; // delivrables start at task_y+task_y_del 36 51 // these fields are filled by the program for data[tn][stn][dn][0] 37 52 struct _Tlivrable … … 49 64 #define D_MAX 10 50 65 #define V_MAX 10 51 Tlivrable* data[T_MAX][S_MAX][D_MAX][V_MAX]; 66 typedef struct _Tdata { 67 FILE* os; 68 Tlivrable* ls[T_MAX][S_MAX][D_MAX][V_MAX]; 69 } Tdata; 70 Tdata data_org; 71 Tdata* curr; 72 73 Tdata* data_new(int *tnplus, int *tnmoins) 74 { 75 int i,skip; 76 int tn,stn,dn,v; 77 Tdata* data = malloc(sizeof(*data)); 78 memset(data,0,sizeof(*data)); 79 for (tn=0 ; tn<T_MAX ; tn++) 80 for (stn=0; stn<S_MAX; stn++) 81 for (dn=0; dn<D_MAX; dn++) 82 for (v=0; v<V_MAX; v++) { 83 if ( data_org.ls[tn][stn][dn][v]==0 ) continue; 84 // tnplus treatment 85 skip = 0; 86 if (tnplus!=0) { 87 skip=1; 88 for (i=0 ; tnplus[i]!=-1 ; i++) { 89 if ( tnplus[i]==data_org.ls[tn][stn][dn][v]->tn ) { 90 skip=0; 91 break; 92 } } } 93 if (skip) continue; 94 // tnmoins treatment 95 skip = 0; 96 if (tnmoins!=0) { 97 for (i=0 ; tnmoins[i]!=-1 ; i++) { 98 //fprintf(stderr,"i=%d data_org.ls[tn][stn][dn][v]->tn=%d tnmoins[i]=%d\n",i,data_org.ls[tn][stn][dn][v]->tn,tnmoins[i]); 99 if ( tnmoins[i]==data_org.ls[tn][stn][dn][v]->tn ) { 100 skip=1; 101 break; 102 } } } 103 //fprintf(stderr,"selected: [tn][stn][dn][v]=%d,%d,%d,%d skip=%d\n",tn,stn,dn,v,skip); 104 if (skip) continue; 105 Tlivrable* l=malloc(sizeof(*l)); 106 *l = *data_org.ls[tn][stn][dn][v]; 107 data->ls[tn][stn][dn][v] = l; 108 fprintf(stderr,"selected: [tn][stn][dn][v]=%d,%d,%d,%d\n",tn,stn,dn,v); 109 } 110 return data; 111 } 52 112 53 113 int milestones[100]; … … 56 116 { sprintf(buf,"D%d%d%d",p->tn,p->stn,p->dn); return buf; } 57 117 char* gen_label_vers(char* buf,Tlivrable*p) 58 { if (p->nbvers<=1) s printf(buf,""); else sprintf(buf,"V%c",p->v); return buf; }118 { if (p->nbvers<=1) strcpy(buf,""); else sprintf(buf,"V%c",p->v); return buf; } 59 119 char* gen_label_full(char* buf,Tlivrable*p) 60 120 { char b[100],v[100]; gen_label_base(b,p); gen_label_vers(v,p); … … 62 122 63 123 void print_put(double x,double y, const char* object) 64 { printf("\\put(%.2f,%.2f){%s}\n",x,y,object); }124 { fprintf(curr->os,"\\put(%.2f,%.2f){%s}\n",x,y,object); } 65 125 void print_hline(double x,double y, double len, const char* color) 66 126 { 67 127 char object[1024]; 68 if (color!=0) { printf("\\bgroup\\color{%s}\n",color); }128 if (color!=0) { fprintf(curr->os,"\\bgroup\\color{%s}\n",color); } 69 129 sprintf(object,"\\line(1,0){%.2f}",len); 70 130 print_put(x,y,object); 71 if (color!=0) { printf("\\egroup\n"); }131 if (color!=0) { fprintf(curr->os,"\\egroup\n"); } 72 132 } 73 133 void print_vline(double x,double y, double len, const char* color) 74 134 { 75 135 char object[1024]; 76 if (color!=0) { printf("\\bgroup\\color{%s}\n",color); }136 if (color!=0) { fprintf(curr->os,"\\bgroup\\color{%s}\n",color); } 77 137 sprintf(object,"\\line(0,1){%.2f}",len); 78 138 print_put(x,y,object); 79 if (color!=0) { printf("\\egroup\n"); }139 if (color!=0) { fprintf(curr->os,"\\egroup\n"); } 80 140 } 81 141 void print_box( … … 97 157 double tn2=tn/2; 98 158 double e=.1; 99 printf("\\bgroup\\color{%s}\n",boxcolor);100 printf("\\linethickness{%.2fmm}\n",tn);159 fprintf(curr->os,"\\bgroup\\color{%s}\n",boxcolor); 160 fprintf(curr->os,"\\linethickness{%.2fmm}\n",tn); 101 161 print_hline(x+tn2-e ,y, dx ,0); 102 162 print_hline(x+tn2-e ,y+dy, dx ,0); 103 163 print_vline(x+tn-e ,y+e, dy-2*e ,0); 104 164 print_vline(x+dx-2*e,y+e, dy-2*e ,0); 105 printf("\\egroup\n");165 fprintf(curr->os,"\\egroup\n"); 106 166 } 107 167 if (vers) { … … 166 226 gen_titleLines(p); 167 227 168 for (v=0; data [tn][stn][dn][v]!=0 ; v++);169 data [tn][stn][dn][v] = p;228 for (v=0; data_org.ls[tn][stn][dn][v]!=0 ; v++); 229 data_org.ls[tn][stn][dn][v] = p; 170 230 fprintf(stderr,"ADDED: %d %d %d %d\n",tn,stn,dn,v); 171 231 //{int i,tn=0; fprintf(stderr,"CURR:t=%d:: ",tn); for (i=0; i<S_MAX ; i++) fprintf(stderr,"%d:%p ",i,data[tn][i][0][0]); fprintf(stderr,"\n"); } … … 174 234 %% 175 235 176 void prepare0( )177 { 178 int tn,stn, dn,v;236 void prepare0(Tdata* data) 237 { 238 int tn,stn,v; 179 239 int i0,i1,i; 180 240 for (tn=0 ; tn<T_MAX ; tn++) 181 241 for (stn=0; stn<S_MAX; stn++) { 182 242 //fprintf(stderr,"AVANT:t=%d:%d:: ",tn,stn); for (i=0; i<D_MAX ; i++) 183 //fprintf(stderr,"%d:%p ",i,data [tn][stn][i][0]); fprintf(stderr,"\n");243 //fprintf(stderr,"%d:%p ",i,data->ls[tn][stn][i][0]); fprintf(stderr,"\n"); 184 244 while (1) { 185 245 for (i0=0 ; i0<D_MAX ; i0++) 186 if (data [tn][stn][i0][0] == 0) break;246 if (data->ls[tn][stn][i0][0] == 0) break; 187 247 for (i1=i0+1 ; i1<D_MAX ; i1++) 188 if (data [tn][stn][i1][0] != 0) break;248 if (data->ls[tn][stn][i1][0] != 0) break; 189 249 if (i1>=D_MAX) break; 190 250 // shift 191 251 for (i=0 ; (i1+i)<D_MAX ; i++) 192 252 for (v=0;v<V_MAX;v+=1) { 193 data [tn][stn][i0+i][v] = data[tn][stn][i1+i][v];194 data [tn][stn][i1+i][v] = 0;253 data->ls[tn][stn][i0+i][v] = data->ls[tn][stn][i1+i][v]; 254 data->ls[tn][stn][i1+i][v] = 0; 195 255 } 196 256 } 197 257 //fprintf(stderr,"AVANT:t=%d:%d:: ",tn,stn); for (i=0; i<D_MAX ; i++) 198 //fprintf(stderr,"%d:%p ",i,data [tn][stn][i][0]); fprintf(stderr,"\n");199 } 200 } 201 void prepare1( )202 { 203 int tn, stn,dn,v;258 //fprintf(stderr,"%d:%p ",i,data->ls[tn][stn][i][0]); fprintf(stderr,"\n"); 259 } 260 } 261 void prepare1(Tdata* data) 262 { 263 int tn,dn,v; 204 264 int i0,i1,i; 205 265 for (tn=0 ; tn<T_MAX ; tn++) { 206 //fprintf(stderr,"AVANT:t=%d:: ",tn,i0,i1); for (i=0; i<S_MAX ; i++) fprintf(stderr,"%d:%p ",i,data [tn][i][0][0]); fprintf(stderr,"\n");266 //fprintf(stderr,"AVANT:t=%d:: ",tn,i0,i1); for (i=0; i<S_MAX ; i++) fprintf(stderr,"%d:%p ",i,data->ls[tn][i][0][0]); fprintf(stderr,"\n"); 207 267 while (1) { 208 268 for (i0=0 ; i0<S_MAX ; i0++) 209 if (data [tn][i0][0][0] == 0) break;269 if (data->ls[tn][i0][0][0] == 0) break; 210 270 for (i1=i0+1 ; i1<S_MAX ; i1++) 211 if (data [tn][i1][0][0] != 0) break;271 if (data->ls[tn][i1][0][0] != 0) break; 212 272 //fprintf(stderr,"%d %d %d\n",tn,i0,i1); 213 273 if (i1>=S_MAX) break; … … 216 276 for (dn=0;dn<D_MAX;dn+=1) 217 277 for (v=0;v<V_MAX;v+=1) { 218 data [tn][i0+i][dn][v] = data[tn][i1+i][dn][v];219 data [tn][i1+i][dn][v] = 0;278 data->ls[tn][i0+i][dn][v] = data->ls[tn][i1+i][dn][v]; 279 data->ls[tn][i1+i][dn][v] = 0; 220 280 } 221 281 } 222 //fprintf(stderr,"APRES:t=%d:: ",tn,i0,i1); for (i=0; i<S_MAX ; i++) fprintf(stderr,"%d:%p ",i,data[tn][i][0][0]); fprintf(stderr,"\n"); 223 } 224 } 225 void prepare2() 282 //fprintf(stderr,"APRES:t=%d:: ",tn,i0,i1); for (i=0; i<S_MAX ; i++) fprintf(stderr,"%d:%p ",i,data->ls[tn][i][0][0]); fprintf(stderr,"\n"); 283 } 284 } 285 void prepare2(Tdata* data) 286 { 287 int tn0,tn1,stn,dn,vn; 288 int moved=1; 289 while (moved) { 290 moved=0; 291 for (tn0=0 ; tn0<T_MAX ; tn0++) 292 if (data->ls[tn0][0][0][0] == 0) break; 293 for (tn1=tn0+1 ; tn1<T_MAX ; tn1++) 294 if (data->ls[tn1][0][0][0] != 0) break; 295 if (tn1==T_MAX) break; 296 for (stn=0 ; stn<S_MAX ; stn++) 297 for (dn=0;dn<D_MAX;dn+=1) 298 for (vn=0;vn<V_MAX;vn+=1) { 299 data->ls[tn0][stn][dn][vn] = data->ls[tn1][stn][dn][vn]; 300 data->ls[tn1][stn][dn][vn] = 0; 301 } 302 moved=1; 303 } 304 } 305 306 void prepare3(Tdata* data) 226 307 { 227 308 int tn,stn,dn,vn; … … 229 310 for (stn=0; stn<S_MAX; stn++) 230 311 for (dn=0; dn<D_MAX; dn++) { 231 Tlivrable* p = data [tn][stn][dn][0];312 Tlivrable* p = data->ls[tn][stn][dn][0]; 232 313 if (p==0) continue; 233 314 p->nbvers=0 ; 234 315 for (vn=0 ; vn<V_MAX ; vn+=1) 235 if (data [tn][stn][dn][vn]!=0) p->nbvers+=1;316 if (data->ls[tn][stn][dn][vn]!=0) p->nbvers+=1; 236 317 p->vers=(Tlivrable**)malloc(sizeof(*p->vers)*(p->nbvers+1)); 237 318 for (vn=0 ; vn<p->nbvers ; vn+=1) { 238 p->vers[vn] = data [tn][stn][dn][vn];239 data [tn][stn][dn][vn]->nbvers = p->nbvers;319 p->vers[vn] = data->ls[tn][stn][dn][vn]; 320 data->ls[tn][stn][dn][vn]->nbvers = p->nbvers; 240 321 } 241 322 p->vers[vn] = 0; … … 250 331 } 251 332 252 double task_livrable_height(int tn )333 double task_livrable_height(int tn, double* delivrable_y) 253 334 { 254 335 int stn,dn,nblivrables=0; 255 336 double height=0; 256 for (stn=0 ; data[tn][stn][0][0]!=0 ; stn++) 257 for (dn=0 ; data[tn][stn][dn][0]!=0 ; dn++) { 337 height += TASK_TITLEHEIGHT ; 338 *delivrable_y = height; 339 for (stn=0 ; curr->ls[tn][stn][0][0]!=0 ; stn++) 340 for (dn=0 ; curr->ls[tn][stn][dn][0]!=0 ; dn++) { 258 341 nblivrables += 1; 259 height+= data[tn][stn][dn][0]->height;342 height+=curr->ls[tn][stn][dn][0]->height; 260 343 } 261 344 height += DELIVRABLE_VSEP/2; … … 268 351 { 269 352 int tn; 270 for ( tn=0 ; data[tn][0][0][0]!=0 ; tn++ ) {353 for ( tn=0 ; curr->ls[tn][0][0][0]!=0 ; tn++ ) { 271 354 const char* color= (tn%2)!=0 ? TASK_BGC1 : TASK_BGC0 ; 272 printf(355 fprintf(curr->os, 273 356 "\\put(%.2f,%.2f){\\fcolorbox{black}{%s}{\\makebox(%5.2f,%5.2f){}}}\n", 274 0.0, data[tn][0][0][0]->task_y,357 0.0,curr->ls[tn][0][0][0]->task_y, 275 358 color, 276 pictwidth, data[tn][0][0][0]->task_dy359 pictwidth,curr->ls[tn][0][0][0]->task_dy 277 360 ); 278 361 } … … 284 367 for (i=0 ; i<=36 ; i+=1,x+=PICT_MONTHWIDTH) { 285 368 if ( (i%3)!=0 ) continue; 286 printf(369 fprintf(curr->os, 287 370 "\\put(%5.1f,%5.1f){\\line(0,1){%5.1f}}\\put(%5.1f,%5.1f){%d}\n", 288 371 x,y,dy-PICT_MONTHWIDTH-PICT_VSEP, … … 298 381 double tn=.3; 299 382 //x=x-tn/2; 300 printf("\\bgroup\n");301 printf("\\color{red}\n");302 printf("\\linethickness{%.2fmm}\n",tn);383 fprintf(curr->os,"\\bgroup\n"); 384 fprintf(curr->os,"\\color{red}\n"); 385 fprintf(curr->os,"\\linethickness{%.2fmm}\n",tn); 303 386 for (i=0 ; milestones[i]!=0 ; i+=1) { 304 387 double xx= x + milestones[i]*PICT_MONTHWIDTH; 305 388 print_vline(xx,y,dy-PICT_MONTHWIDTH-PICT_VSEP,0); 306 389 } 307 printf("\\egroup\n");390 fprintf(curr->os,"\\egroup\n"); 308 391 } 309 392 … … 313 396 int tn, int stn, int dn) 314 397 { 315 Tlivrable* top= data[tn][stn][dn][0];316 Tlivrable* last= data[tn][stn][dn][top->nbvers-1];398 Tlivrable* top=curr->ls[tn][stn][dn][0]; 399 Tlivrable* last=curr->ls[tn][stn][dn][top->nbvers-1]; 317 400 char tmp[1000],label[1000],title[1000]; 318 401 double y0; … … 330 413 y -= top->height ; 331 414 //print_hline(0,y,180,0); 332 printf("% Delivrable %s (tn=%d stn=%d dn=%d\n",label,tn,stn,dn);415 fprintf(curr->os,"%% Delivrable %s (tn=%d stn=%d dn=%d\n",label,tn,stn,dn); 333 416 334 417 // print label … … 366 449 print_box(0,0,boxx,y+y0,box_dx,box_dy,0,0,0); 367 450 } else for (v=0 ; v<top->nbvers ; v+=1) { 368 Tlivrable* l= data[tn][stn][dn][v] ;451 Tlivrable* l=curr->ls[tn][stn][dn][v] ; 369 452 gen_label_vers(tmp,l); 370 453 boxx = box_x + l->bm*PICT_MONTHWIDTH ; … … 380 463 { 381 464 int stn,dn; 382 double y = data[tn][0][0][0]->task_y+data[tn][0][0][0]->task_dy; 465 Tlivrable* task=curr->ls[tn][0][0][0]; 466 double y = task->task_y+task->task_dy-task->task_y_del; 467 char tmp[1000]; 468 sprintf(tmp,"\\textbf{Task-%d \\textit{%s}}",task->tn,task_names[task->tn]); 469 print_put(label_x/2,y+(TASK_TITLEHEIGHT-TASK_TITLEFONTHEIGHT)/2,tmp); 470 383 471 //y += DELIVRABLE_VSEP/2. ; 384 for (stn=0 ; data[tn][stn][0][0]!=0 ; stn++)385 for (dn=0 ; data[tn][stn][dn][0]!=0 ; dn++) {472 for (stn=0 ; curr->ls[tn][stn][0][0]!=0 ; stn++) 473 for (dn=0 ; curr->ls[tn][stn][dn][0]!=0 ; dn++) { 386 474 y=delivrable(label_x,box_x,title_x,y,tn,stn,dn); 387 475 } 388 476 } 389 477 390 int main()478 void do_gantt(const char* fn, int* tnplus, int* tnmoins) 391 479 { 392 480 int tn; … … 396 484 397 485 double label_x,title_x; 398 399 yylex(); 400 prepare0(); 401 prepare1(); 402 prepare2(); 486 curr = data_new(tnplus,tnmoins); 487 if ( (curr->os=fopen(fn,"w"))==0 ) { 488 fprintf(stderr,"can not open %s file for writing.\n",fn); 489 fprintf(stderr,"generation of %s graph is skipped.\n",fn); 490 return; 491 } 492 prepare0(curr); 493 prepare1(curr); 494 prepare2(curr); 495 prepare3(curr); 403 496 404 497 pictheight=0 ; 405 498 pictheight += PICT_BOTSEP ; 406 for ( tn=0 ; data[tn][0][0][0]!=0 ; tn++ );499 for ( tn=0 ; curr->ls[tn][0][0][0]!=0 ; tn++ ); 407 500 for ( tn=tn-1 ; tn>=0 ; tn-- ) { 408 data[tn][0][0][0]->task_y = pictheight; 409 data[tn][0][0][0]->task_dy = task_livrable_height(tn); 410 pictheight += data[tn][0][0][0]->task_dy; 501 double offset; 502 curr->ls[tn][0][0][0]->task_y = pictheight; 503 curr->ls[tn][0][0][0]->task_dy = task_livrable_height(tn,&offset); 504 curr->ls[tn][0][0][0]->task_y_del = offset; 505 pictheight += curr->ls[tn][0][0][0]->task_dy; 411 506 pictheight += TASK_VSEP; 412 507 } … … 429 524 pictwidth += PICT_RIGHTSEP; 430 525 431 printf("\\setlength{\\unitlength}{1.0mm}\n"); 432 printf("\\begin{picture}(%.1f,%.1f)\n",pictwidth,pictheight); 433 task_box(pictwidth); 434 month_grid(gantt_x,gantt_y,gantt_dx,gantt_dy); 435 for ( tn=0 ; data[tn][0][0][0]!=0 ; tn++ ) { 526 fprintf(curr->os,"\\setlength{\\unitlength}{1.0mm}\n"); 527 fprintf(curr->os,"\\begin{picture}(%.1f,%.1f)\n",pictwidth,pictheight); 528 //print_hline(0,0,pictwidth,0); 529 //print_hline(0,pictheight,pictwidth,0); 530 task_box(pictwidth); 531 month_grid(gantt_x,gantt_y,gantt_dx,gantt_dy); 532 for ( tn=0 ; curr->ls[tn][0][0][0]!=0 ; tn++ ) { 436 533 task_delivrable(label_x,gantt_x,title_x,tn); 437 534 } 438 535 439 536 print_milestones(gantt_x,0,gantt_dx,gantt_dy+gantt_y); 440 printf("\\end{picture}\n"); 537 fprintf(curr->os,"\\end{picture}\n"); 538 } 539 540 int main() 541 { 542 int tnplus[10] = { 0, 6, 7, -1 }; 543 int tnmoins[10] = { 0, 6, 7, -1 }; 544 545 yylex(); 546 do_gantt("gantt.tex",0,0); 547 do_gantt("gantt1.tex",tnplus,0); 548 do_gantt("gantt2.tex",0,tnmoins); 441 549 442 550 return 0;
Note: See TracChangeset
for help on using the changeset viewer.