Changeset 36 for anr/gantt.l


Ignore:
Timestamp:
Jan 18, 2010, 9:31:49 AM (14 years ago)
Author:
coach
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • anr/gantt.l

    r34 r36  
    11%{
     2#define COLOR_Milestone  "gtcMilestone"
     3#define COLOR_BOX_HEAVY "gtcBoxHeavy"
     4#define COLOR_BOX_LIGHT "gtcBoxLight"
    25
    36#define PICT_TOPSEP   3
     
    1215
    1316#define TASK_VSEP  2
    14 #define TASK_BGC0 "red"
    15 #define TASK_BGC1 "yellow"
     17#define TASK_BGC0       "gtcTaskBG0"
     18#define TASK_BGC1       "gtcTaskBG1"
    1619
    1720#define DELIVRABLE_VSEP   1
    1821#define DELIVRABLE_HEIGHT 3
    19 #define DELIVRABLE_LABELWIDTH  15
     22#define DELIVRABLE_LABELWIDTH  10
    2023#define DELIVRABLE_LABELHEIGHT DELIVRABLE_HEIGHT
    21 #define DELIVRABLE_TITLEWIDTH  25
     24#define DELIVRABLE_TITLEWIDTH  35
    2225#define DELIVRABLE_TITLEHEIGHT DELIVRABLE_HEIGHT
    23 #define DELIVRABLE_BOXHEIGHT   (DELIVRABLE_HEIGHT-2)
     26#define DELIVRABLE_BOXHEIGHT   (DELIVRABLE_HEIGHT)
    2427
    2528typedef struct _Tlivrable {
    26     int tn,stn,dn;  // task, sub-task, number
    27     char v;         // 0, 1, 2, ..., F
     29    int tn,stn,dn,vn;  // task, sub-task, number
     30    char v;            // 0, 1, 2, ..., F
    2831    char* title;
    2932    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]
    3234    double task_y;           // top of task
    3335    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
    3645} Tlivrable;
    3746
     
    4150#define V_MAX 10
    4251Tlivrable* data[T_MAX][S_MAX][D_MAX][V_MAX];
     52
     53int milestones[100];
     54
     55char* gen_label_base(char* buf,Tlivrable*p)
     56    { sprintf(buf,"D%d%d%d",p->tn,p->stn,p->dn); return buf; }
     57char* gen_label_vers(char* buf,Tlivrable*p)
     58    { if (p->nbvers<=1) sprintf(buf,""); else sprintf(buf,"V%c",p->v); return buf; }
     59char* 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
     63void print_put(double x,double y, const char* object)
     64    { printf("\\put(%.2f,%.2f){%s}\n",x,y,object); }
     65void 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}
     73void 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}
     81void 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
     113void 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}
    43132%}
    44133
     
    53142D=[0-9]+ { dn=atoi(yytext+2); }
    54143V=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]; }
     144V=       { v='F'; }
     145ML=[0-9]+ {
     146        int i;
     147        for (i=0 ; milestones[i]!=0 ; i++);
     148        milestones[i] = atoi(yytext+3);
     149    }
    59150
    60151BM=[0-9]+ { bm=atoi(yytext+3); }
     
    62153TITLE=.*\n {
    63154        char* pc=yytext+6;
     155        yytext[yyleng-1]=0;
    64156        while ( *pc==' ' || *pc=='\t' ) pc+=1;
    65157        title=strdup(pc);
     
    72164        p->bm = bm;
    73165        p->em = em;
     166        gen_titleLines(p);
    74167
    75168        for (v=0; data[tn][stn][dn][v]!=0 ; v++);
    76169        data[tn][stn][dn][v] = p;
    77170fprintf(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"); }
    79172    }
    80173.|\n ;
     
    87180    for (tn=0 ; tn<T_MAX ; tn++)
    88181    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");
    91184        while (1) {
    92185            for (i0=0 ; i0<D_MAX ; i0++)
     
    102195                }
    103196        }
    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");
    106199    }
    107200}
     
    111204int i0,i1,i;
    112205    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");
    114207        while (1) {
    115208            for (i0=0 ; i0<S_MAX ; i0++)
     
    117210            for (i1=i0+1 ; i1<S_MAX ; i1++)
    118211                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);
    120213            if (i1>=S_MAX) break;
    121214            // shift
     
    127220                    }
    128221        }
    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}
     225void prepare2()
     226{
     227int 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
     252double task_livrable_height(int tn)
     253{
     254int    stn,dn,nblivrables=0;
     255double height=0;
    137256    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;
    142265}
    143266
     
    148271        const char* color= (tn%2)!=0 ? TASK_BGC1 : TASK_BGC0 ;
    149272        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",
    151274            0.0,data[tn][0][0][0]->task_y,
    152275            color,
     
    170293}
    171294
     295void  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
    172310double delivrable(
    173311    double label_x, double box_x, double title_x,
     
    175313    int tn, int stn, int dn)
    176314{
     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];
    177318    double y0;
    178319    int v;
     
    183324    double title_dx = DELIVRABLE_LABELWIDTH ;
    184325    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;
    195363        boxx = box_x + l->bm*PICT_MONTHWIDTH ;
    196364        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;
    206376    return y;
    207377}
     
    211381int stn,dn;
    212382double y = data[tn][0][0][0]->task_y+data[tn][0][0][0]->task_dy;
     383    //y += DELIVRABLE_VSEP/2. ;
    213384    for (stn=0 ; data[tn][stn][0][0]!=0 ; stn++)
    214385        for (dn=0 ; data[tn][stn][dn][0]!=0 ; dn++) {
    215386            y=delivrable(label_x,box_x,title_x,y,tn,stn,dn);
    216     }
     387        }
    217388}
    218389
     
    229400    prepare0();
    230401    prepare1();
     402    prepare2();
    231403
    232404    pictheight=0 ;
     
    234406    for ( tn=0 ; data[tn][0][0][0]!=0 ; tn++ );
    235407    for ( tn=tn-1 ; tn>=0 ; tn-- ) {
    236         int nblines= task_line(tn);
    237408        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);
    242410        pictheight += data[tn][0][0][0]->task_dy;
    243411        pictheight += TASK_VSEP;
     
    268436        task_delivrable(label_x,gantt_x,title_x,tn);
    269437      }
     438
     439    print_milestones(gantt_x,0,gantt_dx,gantt_dy+gantt_y);
    270440    printf("\\end{picture}\n");
    271441
Note: See TracChangeset for help on using the changeset viewer.