Changeset 36 for anr/gantt.l
- Timestamp:
- Jan 18, 2010, 9:31:49 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anr/gantt.l
r34 r36 1 1 %{ 2 #define COLOR_Milestone "gtcMilestone" 3 #define COLOR_BOX_HEAVY "gtcBoxHeavy" 4 #define COLOR_BOX_LIGHT "gtcBoxLight" 2 5 3 6 #define PICT_TOPSEP 3 … … 12 15 13 16 #define TASK_VSEP 2 14 #define TASK_BGC0 "red"15 #define TASK_BGC1 "yellow"17 #define TASK_BGC0 "gtcTaskBG0" 18 #define TASK_BGC1 "gtcTaskBG1" 16 19 17 20 #define DELIVRABLE_VSEP 1 18 21 #define DELIVRABLE_HEIGHT 3 19 #define DELIVRABLE_LABELWIDTH 1 522 #define DELIVRABLE_LABELWIDTH 10 20 23 #define DELIVRABLE_LABELHEIGHT DELIVRABLE_HEIGHT 21 #define DELIVRABLE_TITLEWIDTH 2524 #define DELIVRABLE_TITLEWIDTH 35 22 25 #define DELIVRABLE_TITLEHEIGHT DELIVRABLE_HEIGHT 23 #define DELIVRABLE_BOXHEIGHT (DELIVRABLE_HEIGHT -2)26 #define DELIVRABLE_BOXHEIGHT (DELIVRABLE_HEIGHT) 24 27 25 28 typedef struct _Tlivrable { 26 int tn,stn,dn ; // task, sub-task, number27 char v; // 0, 1, 2, ..., F29 int tn,stn,dn,vn; // task, sub-task, number 30 char v; // 0, 1, 2, ..., F 28 31 char* title; 29 32 int bm,em; // mois de bebut et de fin 30 // this fields are filled by the program for data[tn][0][0][0] 31 int task_line; 33 // these fields are filled by the program for data[tn][0][0][0] 32 34 double task_y; // top of task 33 35 double task_dy; // bot of task is task_y+task_dy 34 // this fields are filled by the program for data[tn][stn][dn][0] 35 int del_bm,del_em; // mois de bebut et de fin cummule 36 // these fields are filled by the program for data[tn][stn][dn][0] 37 struct _Tlivrable 38 **vers; // null termiated (vers[i] = &data[tn][stn][dn][i]) 39 int nbvers; // nombre de vers 40 double height; // height of livrable 41 // int del_bm,del_em; // mois de bebut et de fin cummule 42 // these fields are filled by the program for all elements 43 int nbTitleLines; 44 char* titleLines[5]; // null termiated 36 45 } Tlivrable; 37 46 … … 41 50 #define V_MAX 10 42 51 Tlivrable* data[T_MAX][S_MAX][D_MAX][V_MAX]; 52 53 int milestones[100]; 54 55 char* gen_label_base(char* buf,Tlivrable*p) 56 { sprintf(buf,"D%d%d%d",p->tn,p->stn,p->dn); return buf; } 57 char* gen_label_vers(char* buf,Tlivrable*p) 58 { if (p->nbvers<=1) sprintf(buf,""); else sprintf(buf,"V%c",p->v); return buf; } 59 char* gen_label_full(char* buf,Tlivrable*p) 60 { char b[100],v[100]; gen_label_base(b,p); gen_label_vers(v,p); 61 sprintf(buf,"%s%s%s",b,*v?"-":"",v); return buf; } 62 63 void print_put(double x,double y, const char* object) 64 { printf("\\put(%.2f,%.2f){%s}\n",x,y,object); } 65 void print_hline(double x,double y, double len, const char* color) 66 { 67 char object[1024]; 68 if (color!=0) { printf("\\bgroup\\color{%s}\n",color); } 69 sprintf(object,"\\line(1,0){%.2f}",len); 70 print_put(x,y,object); 71 if (color!=0) { printf("\\egroup\n"); } 72 } 73 void print_vline(double x,double y, double len, const char* color) 74 { 75 char object[1024]; 76 if (color!=0) { printf("\\bgroup\\color{%s}\n",color); } 77 sprintf(object,"\\line(0,1){%.2f}",len); 78 print_put(x,y,object); 79 if (color!=0) { printf("\\egroup\n"); } 80 } 81 void print_box( 82 int filled, char* vers, // vers may be 0, 83 double x,double y, double dx, double dy, 84 const char* boxcolor, // may be 0 (default COLOR_BOX_HEAVY) 85 const char* bgcolor, // may be 0 (not set) 86 const char* textcolor // may be 0 (black) 87 ){ 88 double tn=.4; 89 char object[1024]; 90 if ( boxcolor==0 ) boxcolor = COLOR_BOX_HEAVY; 91 if ( filled==1 ) { 92 sprintf(object, 93 "\\fcolorbox{black}{%s}{\\makebox(%.2f,%.2f){}}", 94 boxcolor,dx-2-tn,dy-2-tn); 95 print_put(x,y+1,object); 96 } else { 97 double tn2=tn/2; 98 double e=.1; 99 printf("\\bgroup\\color{%s}\n",boxcolor); 100 printf("\\linethickness{%.2fmm}\n",tn); 101 print_hline(x+tn2-e ,y, dx ,0); 102 print_hline(x+tn2-e ,y+dy, dx ,0); 103 print_vline(x+tn-e ,y+e, dy-2*e ,0); 104 print_vline(x+dx-2*e,y+e, dy-2*e ,0); 105 printf("\\egroup\n"); 106 } 107 if (vers) { 108 sprintf(object,"\\begin{tiny}\\textbf{%s}\\end{tiny}",vers); 109 print_put(x+1,y+.5,object); 110 } 111 } 112 113 void gen_titleLines(Tlivrable*p) 114 { 115 const char* macro="\\ganttlf"; 116 char* pc = p->title; 117 char* pc2; 118 119 if (pc==0) return; 120 121 while ( (pc2=strstr(pc,macro))!=0 ) { 122 char c = *pc2; 123 *pc2 = 0; 124 p->titleLines[p->nbTitleLines]=strdup(pc); 125 p->nbTitleLines+=1; 126 *pc2=c; 127 pc=pc2+strlen(macro); 128 } 129 p->titleLines[p->nbTitleLines]=strdup(pc); 130 p->nbTitleLines+=1; 131 } 43 132 %} 44 133 … … 53 142 D=[0-9]+ { dn=atoi(yytext+2); } 54 143 V=V. { v=yytext[3]; } 55 DV=-VF { dn=0; v='F'; } 56 DV= { dn=0; v='F'; } 57 DV=-[0-9]-VF { dn=yytext[4]-'0'; v=yytext[yyleng-1]; } 58 DV=-[0-9]-V[0-9] { dn=yytext[4]-'0'; v=yytext[yyleng-1]; } 144 V= { v='F'; } 145 ML=[0-9]+ { 146 int i; 147 for (i=0 ; milestones[i]!=0 ; i++); 148 milestones[i] = atoi(yytext+3); 149 } 59 150 60 151 BM=[0-9]+ { bm=atoi(yytext+3); } … … 62 153 TITLE=.*\n { 63 154 char* pc=yytext+6; 155 yytext[yyleng-1]=0; 64 156 while ( *pc==' ' || *pc=='\t' ) pc+=1; 65 157 title=strdup(pc); … … 72 164 p->bm = bm; 73 165 p->em = em; 166 gen_titleLines(p); 74 167 75 168 for (v=0; data[tn][stn][dn][v]!=0 ; v++); 76 169 data[tn][stn][dn][v] = p; 77 170 fprintf(stderr,"ADDED: %d %d %d %d\n",tn,stn,dn,v); 78 {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"); }171 //{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"); } 79 172 } 80 173 .|\n ; … … 87 180 for (tn=0 ; tn<T_MAX ; tn++) 88 181 for (stn=0; stn<S_MAX; stn++) { 89 fprintf(stderr,"AVANT:t=%d:%d:: ",tn,stn); for (i=0; i<D_MAX ; i++)90 fprintf(stderr,"%d:%p ",i,data[tn][stn][i][0]); fprintf(stderr,"\n");182 //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"); 91 184 while (1) { 92 185 for (i0=0 ; i0<D_MAX ; i0++) … … 102 195 } 103 196 } 104 fprintf(stderr,"AVANT:t=%d:%d:: ",tn,stn); for (i=0; i<D_MAX ; i++)105 fprintf(stderr,"%d:%p ",i,data[tn][stn][i][0]); fprintf(stderr,"\n");197 //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"); 106 199 } 107 200 } … … 111 204 int i0,i1,i; 112 205 for (tn=0 ; tn<T_MAX ; tn++) { 113 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");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"); 114 207 while (1) { 115 208 for (i0=0 ; i0<S_MAX ; i0++) … … 117 210 for (i1=i0+1 ; i1<S_MAX ; i1++) 118 211 if (data[tn][i1][0][0] != 0) break; 119 fprintf(stderr,"%d %d %d\n",tn,i0,i1);212 //fprintf(stderr,"%d %d %d\n",tn,i0,i1); 120 213 if (i1>=S_MAX) break; 121 214 // shift … … 127 220 } 128 221 } 129 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"); 130 } 131 } 132 133 int task_line(int tn) 134 { 135 int stn,dn,v; 136 int nblignes=0; 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() 226 { 227 int tn,stn,dn,vn; 228 for (tn=0 ; tn<T_MAX ; tn++) 229 for (stn=0; stn<S_MAX; stn++) 230 for (dn=0; dn<D_MAX; dn++) { 231 Tlivrable* p = data[tn][stn][dn][0]; 232 if (p==0) continue; 233 p->nbvers=0 ; 234 for (vn=0 ; vn<V_MAX ; vn+=1) 235 if (data[tn][stn][dn][vn]!=0) p->nbvers+=1; 236 p->vers=(Tlivrable**)malloc(sizeof(*p->vers)*(p->nbvers+1)); 237 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; 240 } 241 p->vers[vn] = 0; 242 p->height = 1.0*DELIVRABLE_HEIGHT; 243 if (p->nbTitleLines>=1) { 244 double h=0; 245 h += p->vers[p->nbvers-1]->nbTitleLines*DELIVRABLE_TITLEHEIGHT; 246 h += (p->vers[p->nbvers-1]->nbTitleLines-1)*(DELIVRABLE_TITLEHEIGHT/5.); 247 if ( h>p->height) p->height=h; 248 } 249 } 250 } 251 252 double task_livrable_height(int tn) 253 { 254 int stn,dn,nblivrables=0; 255 double height=0; 137 256 for (stn=0 ; data[tn][stn][0][0]!=0 ; stn++) 138 for (dn=0 ; data[tn][stn][dn][0]!=0 ; dn++) 139 for (v=0 ; data[tn][stn][dn][v]!=0 ; v++) 140 nblignes+=1; 141 return nblignes; 257 for (dn=0 ; data[tn][stn][dn][0]!=0 ; dn++) { 258 nblivrables += 1; 259 height+=data[tn][stn][dn][0]->height; 260 } 261 height += DELIVRABLE_VSEP/2; 262 height += (nblivrables-1)*DELIVRABLE_VSEP; 263 height += DELIVRABLE_VSEP/2; 264 return height; 142 265 } 143 266 … … 148 271 const char* color= (tn%2)!=0 ? TASK_BGC1 : TASK_BGC0 ; 149 272 printf( 150 "\\put(%. 1f,%.1f){\\fcolorbox{black}{%s}{\\makebox(%5.1f,%5.1f){}}}\n",273 "\\put(%.2f,%.2f){\\fcolorbox{black}{%s}{\\makebox(%5.2f,%5.2f){}}}\n", 151 274 0.0,data[tn][0][0][0]->task_y, 152 275 color, … … 170 293 } 171 294 295 void print_milestones(double x, double y, double dx, double dy) 296 { 297 int i; 298 double tn=.3; 299 //x=x-tn/2; 300 printf("\\bgroup\n"); 301 printf("\\color{red}\n"); 302 printf("\\linethickness{%.2fmm}\n",tn); 303 for (i=0 ; milestones[i]!=0 ; i+=1) { 304 double xx= x + milestones[i]*PICT_MONTHWIDTH; 305 print_vline(xx,y,dy-PICT_MONTHWIDTH-PICT_VSEP,0); 306 } 307 printf("\\egroup\n"); 308 } 309 172 310 double delivrable( 173 311 double label_x, double box_x, double title_x, … … 175 313 int tn, int stn, int dn) 176 314 { 315 Tlivrable* top=data[tn][stn][dn][0]; 316 Tlivrable* last=data[tn][stn][dn][top->nbvers-1]; 317 char tmp[1000],label[1000],title[1000]; 177 318 double y0; 178 319 int v; … … 183 324 double title_dx = DELIVRABLE_LABELWIDTH ; 184 325 double title_dy = DELIVRABLE_TITLEHEIGHT ; 185 for (v=0 ; data[tn][stn][dn][v]!=0 ; v++) { 186 Tlivrable* l=data[tn][stn][dn][v] ; 187 y -= DELIVRABLE_HEIGHT; 188 char label[100]; sprintf(label,"D%d-%d-%d-V%c",tn,stn,dn,l->v); 189 printf("% Delivrable %d %d %d\n",tn,stn,dn); 190 y0 = (DELIVRABLE_HEIGHT-DELIVRABLE_LABELHEIGHT)/2; 191 printf("\\put(%.1f,%.1f)",label_x,y+y0); 192 printf("{\\makebox(%.1f,%.1f)[l]{\\ganttlabelstyle{%s}}}\n", 193 label_dx,label_dy,label); 194 y0 = (DELIVRABLE_HEIGHT-DELIVRABLE_BOXHEIGHT)/2; 326 327 //print_hline(0,y,180,0); 328 gen_label_base(label,top); 329 // y -= DELIVRABLE_HEIGHT; 330 y -= top->height ; 331 //print_hline(0,y,180,0); 332 printf("% Delivrable %s (tn=%d stn=%d dn=%d\n",label,tn,stn,dn); 333 334 // print label 335 //y0 = (DELIVRABLE_HEIGHT-DELIVRABLE_LABELHEIGHT)/2; 336 y0 = (top->height-DELIVRABLE_LABELHEIGHT)/2; 337 sprintf(tmp,"\\ganttlabelstyle{%s}",label); 338 print_put(label_x,y+y0,tmp); 339 // print title 340 if (last->nbTitleLines==1) { 341 y0 = (DELIVRABLE_HEIGHT-DELIVRABLE_TITLEHEIGHT)/2; 342 y0 += DELIVRABLE_TITLEHEIGHT/5. ; 343 sprintf(tmp,"\\gantttitlestyle{%s}",last->title); 344 print_put(title_x,y+y0,tmp); 345 } else if (last->nbTitleLines>1) { 346 int i; 347 // y0 = (DELIVRABLE_HEIGHT-DELIVRABLE_TITLEHEIGHT)/2; 348 y0=DELIVRABLE_TITLEHEIGHT/5.; 349 sprintf(tmp,"\\gantttitlestyle{\\shortstack[l]{%s",last->titleLines[0]); 350 for (i=1 ; i<last->nbTitleLines ; i+=1) { 351 strcat(tmp,"\\\\"); 352 strcat(tmp,last->titleLines[i]); 353 } 354 strcat(tmp,"}}"); 355 print_put(title_x,y+y0,tmp); 356 } 357 358 // print box 359 //y0 = (DELIVRABLE_HEIGHT-DELIVRABLE_BOXHEIGHT)/2; 360 y0 = (top->height-DELIVRABLE_BOXHEIGHT)/2; 361 if ( last==top ) { 362 Tlivrable* l=top; 195 363 boxx = box_x + l->bm*PICT_MONTHWIDTH ; 196 364 box_dx = (l->em - l->bm) * PICT_MONTHWIDTH; 197 printf("\\put(%.1f,%.1f)",boxx,y+y0); 198 printf("{\\fcolorbox{black}{blue}{\\makebox(%.1f,%.1f){}}}\n", 199 box_dx-2,box_dy); 200 y0 = (DELIVRABLE_HEIGHT-DELIVRABLE_TITLEHEIGHT)/2; 201 printf("\\put(%.1f,%.1f)",title_x,y+y0); 202 printf("{\\makebox(%.1f,%.1f)[l]{\\gantttitlestyle{%s}}}\n", 203 title_dx,title_dy,l->title); 204 y -= DELIVRABLE_VSEP; 205 } 365 print_box(1,0,boxx,y+y0,box_dx,box_dy,COLOR_BOX_LIGHT,0,0); 366 print_box(0,0,boxx,y+y0,box_dx,box_dy,0,0,0); 367 } else for (v=0 ; v<top->nbvers ; v+=1) { 368 Tlivrable* l=data[tn][stn][dn][v] ; 369 gen_label_vers(tmp,l); 370 boxx = box_x + l->bm*PICT_MONTHWIDTH ; 371 box_dx = (l->em - l->bm) * PICT_MONTHWIDTH; 372 print_box(1,0,boxx,y+y0,box_dx,box_dy,COLOR_BOX_LIGHT,0,0); 373 print_box(0,tmp,boxx,y+y0,box_dx,box_dy,0,0,0); 374 } 375 y -= DELIVRABLE_VSEP; 206 376 return y; 207 377 } … … 211 381 int stn,dn; 212 382 double y = data[tn][0][0][0]->task_y+data[tn][0][0][0]->task_dy; 383 //y += DELIVRABLE_VSEP/2. ; 213 384 for (stn=0 ; data[tn][stn][0][0]!=0 ; stn++) 214 385 for (dn=0 ; data[tn][stn][dn][0]!=0 ; dn++) { 215 386 y=delivrable(label_x,box_x,title_x,y,tn,stn,dn); 216 }387 } 217 388 } 218 389 … … 229 400 prepare0(); 230 401 prepare1(); 402 prepare2(); 231 403 232 404 pictheight=0 ; … … 234 406 for ( tn=0 ; data[tn][0][0][0]!=0 ; tn++ ); 235 407 for ( tn=tn-1 ; tn>=0 ; tn-- ) { 236 int nblines= task_line(tn);237 408 data[tn][0][0][0]->task_y = pictheight; 238 data[tn][0][0][0]->task_line = nblines; 239 data[tn][0][0][0]->task_dy = 0; 240 data[tn][0][0][0]->task_dy += nblines*DELIVRABLE_HEIGHT; 241 data[tn][0][0][0]->task_dy += (nblines-1)*DELIVRABLE_VSEP; 409 data[tn][0][0][0]->task_dy = task_livrable_height(tn); 242 410 pictheight += data[tn][0][0][0]->task_dy; 243 411 pictheight += TASK_VSEP; … … 268 436 task_delivrable(label_x,gantt_x,title_x,tn); 269 437 } 438 439 print_milestones(gantt_x,0,gantt_dx,gantt_dy+gantt_y); 270 440 printf("\\end{picture}\n"); 271 441
Note: See TracChangeset
for help on using the changeset viewer.