source: anr/gantt.l @ 279

Last change on this file since 279 was 279, checked in by coach, 14 years ago

1) Fixed problems with the \CoutHorsD macro.
2) Renamed as \OtherPartner?{debu}{fin}{partener}{moyen-an-1:moyen-an-2:moyen-an-3}.
3) Updated document for using it.
4) Changed the "model use" delivrable.

  • Property svn:keywords set to Revision HeadURL Id
File size: 32.9 KB
Line 
1%{
2#define COLOR_Milestone  "gtcMilestone"
3#define COLOR_BOX_HEAVY "gtcBoxHeavy"
4#define COLOR_BOX_LIGHT "gtcBoxLight"
5
6#define PICT_TOPSEP   0.0
7#define PICT_BOTSEP   3.0
8#define PICT_LEFTSEP  2.0
9#define PICT_RIGHTSEP 3.0
10#define PICT_VSEP     2.0
11#define PICT_HSEP     2.0
12
13#define PICT_MONTHHEIGHT 5  // police height
14#define PICT_MONTHWIDTH  (10./3.)
15
16#define TASK_VSEP  2
17#define TASK_BGC0       "gtcTaskBG0"
18#define TASK_BGC1       "gtcTaskBG1"
19#define TASK_TITLEHEIGHT 6.
20#define TASK_TITLEFONTHEIGHT 2.
21
22#define DELIVRABLE_VSEP   1
23#define DELIVRABLE_HEIGHT 3
24#define DELIVRABLE_LABELWIDTH  7.5
25#define DELIVRABLE_LABELHEIGHT DELIVRABLE_HEIGHT
26#define DELIVRABLE_TITLEWIDTH  38
27#define DELIVRABLE_TITLEHEIGHT DELIVRABLE_HEIGHT
28#define DELIVRABLE_BOXHEIGHT   (DELIVRABLE_HEIGHT)
29
30char* task_names[] = {
31    0,
32    "Project management",
33    "Backbone infrastructure",
34    "System generation",
35    "HAS front-end",
36    "HAS back-end",
37    "PC/FPGA communication middleware",
38    "Industrial demonstrators",
39    "Dissemination",
40    0
41};
42struct partner_def { char *key, *name, *fnfull, *fnshort; } partner_table[] = {
43    { "UNKNOW" ,"relax"  ,0                             ,0                        },
44    { "irisa"  ,"irisa"  ,"table_inria_cairn_full.tex"  ,"table_inria_cairn_short.tex"  },
45    { "lip"    ,"lip"    ,"table_inria_compsys_full.tex","table_inria_compsys_short.tex"    },
46    { "tima"   ,"tima"   ,"table_tima_full.tex"         ,"table_tima_short.tex"   },
47    { "ubs"    ,"ubs"    ,"table_ubs_full.tex"          ,"table_ubs_short.tex"    },
48    { "upmc"   ,"upmc"   ,"table_upmc_full.tex"         ,"table_upmc_short.tex"   },
49    { "bull"   ,"bull"   ,"table_bull_full.tex"         ,"table_bull_short.tex"   },
50    { "thales" ,"thales" ,"table_thales_full.tex"       ,"table_thales_short.tex" },
51    { "mds"    ,"mds"    ,"table_mds_full.tex"          ,"table_mds_short.tex"   },
52    { 0        ,0        ,0                             ,0                        },
53};
54
55typedef struct _Tlivrable {
56    char v;            // 0, 1, 2, ..., F
57    char* kind;
58    char* title;
59    int   bm,em;       // mois de bebut et de fin
60    double hman[3];    // nombre de mh par an
61    int tn,stn,dn,vn;  // task, sub-task, number
62    int    leader;     // 1: the partner leads this livrable
63                       // 0: the partner helps for this livrable
64    int    partner;    // index dans partner_table
65    // these fields are filled by the program for data[tn][0][0][0]
66    double task_y;           // top of task
67    double task_dy;          // bot of task is task_y+task_dy
68    double task_y_del;       // delivrables start at task_y+task_y_del
69    double nbma[3];          // durée en mois par annee
70    // these fields are filled by the program for data[tn][stn][dn][0]
71    struct _Tlivrable // versions of the livrable
72            **vers; // null termiated (vers[i] = data[tn][stn][dn][j])
73                    // this->leader == 1
74                    // vers[0] = this
75                    // vers[i]->leadaer == this->leader
76                    // vers[i]->partner == this->partner
77    int    nbvers;  // nombre de vers
78    double height;     // height of livrable
79    // int del_bm,del_em;    // mois de bebut et de fin cummule
80    // these fields are filled by the program for all elements
81    int   nbTitleLines;
82    char* titleLines[5]; // null termiated
83    struct _Tlivrable // participant to the livrable
84            **part; // null termiated (vers[i] = data[tn][stn][dn][j])
85                    // this->leader == 1
86                    // vers[i] != this
87                    // vers[i]->leader ==  0
88                    // vers[i]->partner != this->partner
89    int    nbpart;  // nombre de vers
90} Tlivrable;
91
92#define T_MAX 10
93#define S_MAX 10
94#define D_MAX 10
95#define V_MAX 10
96typedef struct _Tdata {
97    FILE*      os;
98    Tlivrable* ls[T_MAX][S_MAX][D_MAX][V_MAX];
99} Tdata;
100Tdata  data_org;
101Tdata* curr;
102
103Tdata* data_new(int *tnplus, int *tnmoins)
104{
105    int i,skip;
106    int tn,stn,dn,v;
107    Tdata* data = malloc(sizeof(*data));
108    memset(data,0,sizeof(*data));
109    for (tn=0 ; tn<T_MAX ; tn++)
110    for (stn=0; stn<S_MAX; stn++)
111    for (dn=0; dn<D_MAX; dn++)
112    for (v=0; v<V_MAX; v++) {
113        if ( data_org.ls[tn][stn][dn][v]==0 ) continue;
114        // tnplus treatment
115        skip = 0;
116        if (tnplus!=0) {
117            skip=1;
118            for (i=0 ; tnplus[i]!=-1 ; i++) {
119                if ( tnplus[i]==data_org.ls[tn][stn][dn][v]->tn ) {
120                    skip=0;
121                    break;
122        }   }   }
123        if (skip) continue;
124        // tnmoins treatment
125        skip = 0;
126        if (tnmoins!=0) {
127            for (i=0 ; tnmoins[i]!=-1 ; i++) {
128//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]);
129                if ( tnmoins[i]==data_org.ls[tn][stn][dn][v]->tn ) {
130                    skip=1;
131                    break;
132        }   }   }
133//fprintf(stderr,"selected: [tn][stn][dn][v]=%d,%d,%d,%d skip=%d\n",tn,stn,dn,v,skip);
134        if (skip) continue;
135        Tlivrable* l=malloc(sizeof(*l));
136        *l = *data_org.ls[tn][stn][dn][v];
137        data->ls[tn][stn][dn][v] = l;
138//fprintf(stderr,"selected: [tn][stn][dn][v]=%d,%d,%d,%d\n",tn,stn,dn,v);
139    }
140    return data;
141}
142
143int milestones[100];
144
145char* gen_label_base(char* buf,Tlivrable*p)
146    { if (p->dn >=0) sprintf(buf,"D%d%d%d",p->tn,p->stn,p->dn); else sprintf(buf,""); return buf; }
147char* gen_label_vers(char* buf,Tlivrable*p)
148    { if (p->nbvers<=1) strcpy(buf,""); else sprintf(buf,"V%c",p->v); return buf; }
149char* gen_label_full(char* buf,Tlivrable*p)
150    { char b[100],v[100]; gen_label_base(b,p); gen_label_vers(v,p);
151      sprintf(buf,"%s%s%s",b,*v?"-":"",v); return buf; }
152
153void print_put(double x,double y, const char* object)
154    { fprintf(curr->os,"\\put(%.2f,%.2f){%s}\n",x,y,object); }
155void print_hline(double x,double y, double len, const char* color)
156{
157    char object[1024];
158    if (color!=0) { fprintf(curr->os,"\\bgroup\\color{%s}\n",color); }
159    sprintf(object,"\\line(1,0){%.2f}",len);
160    print_put(x,y,object);
161    if (color!=0) { fprintf(curr->os,"\\egroup\n"); }
162}
163void print_vline(double x,double y, double len, const char* color)
164{
165    char object[1024];
166    if (color!=0) { fprintf(curr->os,"\\bgroup\\color{%s}\n",color); }
167    sprintf(object,"\\line(0,1){%.2f}",len);
168    print_put(x,y,object);
169    if (color!=0) { fprintf(curr->os,"\\egroup\n"); }
170}
171void print_box(
172    int filled, char* vers, // vers may be 0,
173    double x,double y, double dx, double dy,
174    const char* boxcolor,  // may be 0 (default COLOR_BOX_HEAVY)
175    const char* bgcolor,   // may be 0 (not set)
176    const char* textcolor //  may be 0 (black)
177){
178    double tn=.4;
179    char object[1024];
180    if ( boxcolor==0 ) boxcolor = COLOR_BOX_HEAVY;
181    if ( filled==1 ) {
182        sprintf(object,
183            "\\fcolorbox{black}{%s}{\\makebox(%.2f,%.2f){}}",
184                boxcolor,dx-2-tn,dy-2-tn);
185        print_put(x,y+1,object);
186    } else {
187        double tn2=tn/2;
188        double e=.1;
189        fprintf(curr->os,"\\bgroup\\color{%s}\n",boxcolor);
190        fprintf(curr->os,"\\linethickness{%.2fmm}\n",tn);
191        print_hline(x+tn2-e ,y,    dx     ,0);
192        print_hline(x+tn2-e ,y+dy, dx     ,0);
193        print_vline(x+tn-e  ,y+e,  dy-2*e ,0);
194        print_vline(x+dx-2*e,y+e,  dy-2*e ,0);
195        fprintf(curr->os,"\\egroup\n");
196    }
197    if (vers) {
198        sprintf(object,"\\begin{tiny}\\textbf{%s}\\end{tiny}",vers);
199        print_put(x+1,y+.5,object);
200    }
201}
202
203void gen_titleLines(Tlivrable*p)
204{
205    const char* macro="\\ganttlf";
206    char* pc = p->title;
207    char* pc2;
208
209    if (pc==0) return;
210   
211    while ( (pc2=strstr(pc,macro))!=0 ) {
212        char c = *pc2;
213        *pc2 = 0;
214        p->titleLines[p->nbTitleLines]=strdup(pc);
215        p->nbTitleLines+=1;
216        *pc2=c;
217        pc=pc2+strlen(macro);
218    }
219    p->titleLines[p->nbTitleLines]=strdup(pc);
220    p->nbTitleLines+=1;
221}
222%}
223
224%option noyywrap
225
226%%
227 int tn,stn,dn,v,bm,em; char* title; char* kind;
228 double an[3];
229 char*  an_comment;
230 int    leader;
231 int    partner;
232#.*\n   ;
233L=1       { leader=1; }
234L=0       { leader=0; }
235T=[0-9]+  { tn=atoi(yytext+2); }
236S=[0-9]+  { stn=atoi(yytext+2); }
237D=[0-9]+  { dn=atoi(yytext+2); }
238V=V[1-8F] { v=yytext[3]; }
239ML=[0-9]+ {
240        int i;
241        for (i=0 ; milestones[i]!=0 ; i++);
242        milestones[i] = atoi(yytext+3);
243    }
244BM=[0-9]+ { bm=atoi(yytext+3); }
245EM=[0-9]+ { em=atoi(yytext+3); }
246R=none    { an[0]=0; an[1]=0; an[2]=0; an_comment=0; }
247R=[0-9:.]+ {
248        char tmp[1000];
249        int status = sscanf(yytext+2,"%lf:%lf:%lf:%s",an+0,an+1,an+2,tmp);
250        if (status<3) {
251            fprintf(stderr,
252                "%s: is not resource definition, expected format \"N:N:N\" (near D%d%d%d-V%c)\n",
253               yytext+2,tn,stn,dn,v);
254            an[0]=0; an[1]=0; an[2]=0; an_comment=0;
255        } else if (status==3) {
256            an_comment = 0;
257        } else
258            an_comment = strdup(tmp);
259    }
260PART="{"[^}]+"}"  {
261        int i;
262        partner=-1;
263        for (i=0; partner_table[i].key!=0 ; i++) {
264            if (strstr(yytext,partner_table[i].key)!=0 ) {
265                partner=i;
266                break;
267            }
268        }
269        if ( partner==-1 ) {
270            fprintf(stderr,"%s: does not contains a partner key (near D%d%d%d-V%c)\n",
271               yytext+5,tn,stn,dn,v);
272            partner=0;
273        }
274    }
275KIND="{"[^}]+"}"  {
276        yytext[yyleng-1]=0;
277        kind= strdup(yytext+6);
278        if ( strcmp(kind,"x")!=0 && strcmp(kind,"d")!=0 && strcmp(kind,"h")!=0 &&
279             strcmp(kind,"d+x")!=0 )
280          fprintf(stderr,"ERROR:D%d%d%d invalid KIND: %s\n",tn,stn,dn,kind);
281    }
282KIND="{}"  {
283        yytext[yyleng-1]=0;
284        kind= strdup(yytext+6);
285    }
286TITLE=.*\n {
287        char* pc=yytext+6;
288        yytext[yyleng-1]=0;
289        while ( *pc==' ' || *pc=='\t' ) pc+=1;
290        title=strdup(pc);
291        Tlivrable* p= (Tlivrable*) calloc(sizeof(*p),1);
292        p->tn = tn;
293        p->stn = stn;
294        p->dn = dn;
295        p->v  = v;
296        p->hman[0] = an[0];
297        p->hman[1] = an[1];
298        p->hman[2] = an[2];
299        p->leader = leader;
300        p->partner = partner;
301        p->title = title;
302        p->bm = bm;
303        p->em = em;
304        p->kind = kind;
305        gen_titleLines(p);
306
307        for (v=0; data_org.ls[tn][stn][dn][v]!=0 ; v++);
308        data_org.ls[tn][stn][dn][v] = p;
309//fprintf(stderr,"ADDED: %d %d %d %d\n",tn,stn,dn,v);
310        tn=stn=dn=v=bm=em=0;
311        title=kind=0;
312        an[0]= an[1]=an[1]=0;
313        an_comment=0;
314        partner=0;
315        leader=0;
316    }
317[ \t\n] ;
318.   { fprintf(stderr,"%c: unexpected value in anr.gantt file (near D%d%d%d-V%c)\n",
319        *yytext,tn,stn,dn,v); }
320%%
321
322void prepare0(Tdata* data)
323{
324int tn,stn,v;
325int i0,i1,i;
326    for (tn=0 ; tn<T_MAX ; tn++)
327    for (stn=0; stn<S_MAX; stn++) {
328//fprintf(stderr,"AVANT:t=%d:%d:: ",tn,stn); for (i=0; i<D_MAX ; i++)
329//fprintf(stderr,"%d:%p ",i,data->ls[tn][stn][i][0]); fprintf(stderr,"\n");
330        while (1) {
331            for (i0=0 ; i0<D_MAX ; i0++)
332                if (data->ls[tn][stn][i0][0] == 0) break;
333            for (i1=i0+1 ; i1<D_MAX ; i1++)
334                if (data->ls[tn][stn][i1][0] != 0) break;
335            if (i1>=D_MAX) break;
336            // shift
337            for (i=0 ; (i1+i)<D_MAX ; i++)
338                for (v=0;v<V_MAX;v+=1) {
339                    data->ls[tn][stn][i0+i][v] = data->ls[tn][stn][i1+i][v];
340                    data->ls[tn][stn][i1+i][v] = 0;
341                }
342        }
343//fprintf(stderr,"AVANT:t=%d:%d:: ",tn,stn); for (i=0; i<D_MAX ; i++)
344//fprintf(stderr,"%d:%p ",i,data->ls[tn][stn][i][0]); fprintf(stderr,"\n");
345    }
346}
347void prepare1(Tdata* data)
348{
349int tn,dn,v;
350int i0,i1,i;
351    for (tn=0 ; tn<T_MAX ; tn++) {
352//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");
353        while (1) {
354            for (i0=0 ; i0<S_MAX ; i0++)
355                if (data->ls[tn][i0][0][0] == 0) break;
356            for (i1=i0+1 ; i1<S_MAX ; i1++)
357                if (data->ls[tn][i1][0][0] != 0) break;
358//fprintf(stderr,"%d %d %d\n",tn,i0,i1);
359            if (i1>=S_MAX) break;
360            // shift
361            for (i=0 ; (i1+i)<S_MAX ; i++)
362                for (dn=0;dn<D_MAX;dn+=1)
363                    for (v=0;v<V_MAX;v+=1) {
364                        data->ls[tn][i0+i][dn][v] = data->ls[tn][i1+i][dn][v];
365                        data->ls[tn][i1+i][dn][v] = 0;
366                    }
367        }
368//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");
369    }
370}
371void prepare2(Tdata* data)
372{
373int tn0,tn1,stn,dn,vn;
374int moved=1;
375    while (moved) {
376        moved=0;
377        for (tn0=0 ; tn0<T_MAX ; tn0++)
378            if (data->ls[tn0][0][0][0] == 0) break;
379        for (tn1=tn0+1 ; tn1<T_MAX ; tn1++)
380            if (data->ls[tn1][0][0][0] != 0) break;
381        if (tn1==T_MAX) break;
382        for (stn=0 ; stn<S_MAX ; stn++)
383            for (dn=0;dn<D_MAX;dn+=1)
384                for (vn=0;vn<V_MAX;vn+=1) {
385                    data->ls[tn0][stn][dn][vn] = data->ls[tn1][stn][dn][vn];
386                    data->ls[tn1][stn][dn][vn] = 0;
387                }
388        moved=1;
389    }
390}
391
392void prepare3(Tdata* data)
393{
394int tn,stn,dn,vn,cnt;
395Tlivrable* tmp;
396    for (tn=0 ; tn<T_MAX ; tn++)
397    for (stn=0; stn<S_MAX; stn++)
398    for (dn=0; dn<D_MAX; dn++) {
399        Tlivrable* p = data->ls[tn][stn][dn][0];
400        if (p==0) continue;
401        p->nbvers=0 ;
402        p->nbpart=0 ;
403        for (vn=0 ; vn<V_MAX ; vn+=1) {
404            tmp = data->ls[tn][stn][dn][vn];
405            if (tmp==0) continue;
406            if (tmp->leader==0)
407               p->nbpart+=1;
408            else
409                p->nbvers+=1;
410        }
411        p->vers=(Tlivrable**)malloc(sizeof(*p->vers)*(p->nbvers+1));
412        for (vn=0,cnt=0 ; vn<V_MAX ; vn+=1) {
413            tmp = data->ls[tn][stn][dn][vn];
414            if (tmp!=0 && tmp->leader==1) {
415                p->vers[cnt++] = tmp;
416                tmp->nbvers = p->nbvers;
417             }
418        }
419        p->vers[cnt] = 0;
420        if (p->nbpart!=0) {
421            p->part=(Tlivrable**)malloc(sizeof(*p->part)*(p->nbpart+1));
422            for (vn=0,cnt=0 ; vn<V_MAX ; vn+=1) {
423                tmp = data->ls[tn][stn][dn][vn];
424                if (tmp!=0 && tmp->leader==0) {
425                    p->part[cnt++] = tmp;
426                 }
427            }
428            p->part[cnt] = 0;
429        }
430
431        p->height = 1.0*DELIVRABLE_HEIGHT;
432        if (p->nbTitleLines>=1) {
433            double h=0;
434            h += p->vers[p->nbvers-1]->nbTitleLines*DELIVRABLE_TITLEHEIGHT;
435            h += (p->vers[p->nbvers-1]->nbTitleLines-1)*(DELIVRABLE_TITLEHEIGHT/5.);
436            if ( h>p->height) p->height=h;
437        }
438        Tlivrable* lu= p->vers[p->nbvers-1];
439        int i;
440//fprintf(stderr,"--------------------\n");
441        for (i=0 ; i<p->nbvers ; i++) {
442            Tlivrable* l= p->vers[i];
443            double bm= l->bm;
444            double em= l->em;
445//fprintf(stderr,"  %d%d%d-V%c: bm=%2.f em=%2.f --> %2.1f %2.1f %2.1f\n",l->tn,l->stn,l->dn,l->v,bm,em, lu->nbma[0],lu->nbma[1],lu->nbma[2]);
446            if (bm<12 && em>0) {
447                lu->nbma[0] += (em>12?12:em)-bm;
448                bm=12;
449            }
450            if (bm<24 && em>12) {
451                lu->nbma[1] += (em>24?24:em)-bm;
452                bm=24;
453            }
454            if (bm<36 && em>24) {
455                lu->nbma[2] += em-bm;
456            }
457//fprintf(stderr,"  %d%d%d-V%c: bm=%2.f em=%2.f --> %2.1f %2.1f %2.1f %p\n",l->tn,l->stn,l->dn,l->v,bm,em, lu->nbma[0],lu->nbma[1],lu->nbma[2], lu);
458        }
459    }
460}
461
462double task_livrable_height(int tn, double* delivrable_y)
463{
464int    stn,dn,nblivrables=0;
465double height=0;
466    height += TASK_TITLEHEIGHT ;
467    *delivrable_y = height;
468    for (stn=0 ; curr->ls[tn][stn][0][0]!=0 ; stn++)
469        for (dn=0 ; curr->ls[tn][stn][dn][0]!=0 ; dn++) {
470            if ( curr->ls[tn][stn][dn][0]->leader==0 ) continue;
471            nblivrables += 1;
472            height+=curr->ls[tn][stn][dn][0]->height;
473        }
474        height += DELIVRABLE_VSEP/2;
475        height += (nblivrables-1)*DELIVRABLE_VSEP;
476        height += DELIVRABLE_VSEP/2;
477    return height;
478}
479
480void  task_box(double pictwidth)
481{
482    int tn;
483    for ( tn=0 ; curr->ls[tn][0][0][0]!=0 ; tn++ ) {
484        const char* color= (tn%2)!=0 ? TASK_BGC1 : TASK_BGC0 ;
485        fprintf(curr->os,
486            "\\put(%.2f,%.2f){\\fcolorbox{black}{%s}{\\makebox(%5.2f,%5.2f){}}}\n",
487            0.0,curr->ls[tn][0][0][0]->task_y,
488            color,
489            pictwidth,curr->ls[tn][0][0][0]->task_dy
490        );
491    }
492}
493
494void  month_grid(double x, double y, double dx, double dy)
495{
496    int i;
497    for (i=0 ;  i<=36 ; i+=1,x+=PICT_MONTHWIDTH) {
498        if ( (i%3)!=0 ) continue;
499        fprintf(curr->os,
500            "\\put(%5.1f,%5.1f){\\line(0,1){%5.1f}}\\put(%5.1f,%5.1f){%d}\n",
501            x,y,dy-PICT_MONTHWIDTH-PICT_VSEP,
502            x-2,y+dy-PICT_MONTHHEIGHT,
503            i
504        );
505    }
506}
507
508void  print_milestones(double x, double y, double dx, double dy)
509{
510    int i;
511    double tn=.3;
512    //x=x-tn/2;
513    fprintf(curr->os,"\\bgroup\n");
514    fprintf(curr->os,"\\color{red}\n");
515    fprintf(curr->os,"\\linethickness{%.2fmm}\n",tn);
516    for (i=0 ;  milestones[i]!=0 ; i+=1) {
517        double xx= x + milestones[i]*PICT_MONTHWIDTH;
518        print_vline(xx,y,dy-PICT_MONTHWIDTH-PICT_VSEP,0);
519        char tmp[100];
520        sprintf(tmp,"M%d",i+1);
521        print_put(xx-2,y-3,tmp);
522    }
523    fprintf(curr->os,"\\egroup\n");
524}
525
526double delivrable(
527    double label_x, double box_x, double title_x,
528    double y,
529    int tn, int stn, int dn)
530{
531    Tlivrable* top=curr->ls[tn][stn][dn][0];
532    Tlivrable* last=curr->ls[tn][stn][dn][top->nbvers-1];
533    char tmp[1000],label[1000],title[1000];
534    double y0;
535    int v;
536    double label_dx = DELIVRABLE_LABELWIDTH ;
537    double label_dy = DELIVRABLE_LABELHEIGHT ;
538    double boxx,box_dx;
539    double box_dy = DELIVRABLE_BOXHEIGHT ;
540    double title_dx = DELIVRABLE_TITLEWIDTH ;
541    double title_dy = DELIVRABLE_TITLEHEIGHT ;
542   
543//print_hline(0,y,180,0);
544    gen_label_base(label,top);
545    // y -= DELIVRABLE_HEIGHT;
546    y -= top->height ;
547//print_hline(0,y,180,0);
548    fprintf(curr->os,"%% Delivrable %s (tn=%d stn=%d dn=%d\n",label,tn,stn,dn);
549
550    // print label
551    //y0 = (DELIVRABLE_HEIGHT-DELIVRABLE_LABELHEIGHT)/2;
552    y0 = (top->height-DELIVRABLE_LABELHEIGHT)/2;
553    sprintf(tmp,"\\ganttlabelstyle{%s}",label);
554    print_put(label_x,y+y0,tmp);
555    // print title
556    if (last->nbTitleLines==1) {
557        y0  = (DELIVRABLE_HEIGHT-DELIVRABLE_TITLEHEIGHT)/2;
558        y0 += DELIVRABLE_TITLEHEIGHT/5. ;
559        sprintf(tmp,"\\gantttitlestyle{%s}",last->title);
560        print_put(title_x,y+y0,tmp);
561    } else if (last->nbTitleLines>1) {
562        int i;
563        // y0 = (DELIVRABLE_HEIGHT-DELIVRABLE_TITLEHEIGHT)/2;
564        y0=DELIVRABLE_TITLEHEIGHT/5.;
565        sprintf(tmp,"\\gantttitlestyle{\\shortstack[l]{%s",last->titleLines[0]);
566        for (i=1 ; i<last->nbTitleLines ; i+=1) {
567            strcat(tmp,"\\\\");
568            strcat(tmp,last->titleLines[i]);
569        }
570        strcat(tmp,"}}");
571        print_put(title_x,y+y0,tmp);
572    }
573       
574    // print box
575    //y0 = (DELIVRABLE_HEIGHT-DELIVRABLE_BOXHEIGHT)/2;
576    y0 = (top->height-DELIVRABLE_BOXHEIGHT)/2;
577    if ( last==top ) {
578        Tlivrable* l=top;
579        boxx = box_x + l->bm*PICT_MONTHWIDTH ;
580        box_dx  = (l->em - l->bm) * PICT_MONTHWIDTH;
581        print_box(1,0,boxx,y+y0,box_dx,box_dy,COLOR_BOX_LIGHT,0,0);
582        print_box(0,0,boxx,y+y0,box_dx,box_dy,0,0,0);
583    } else for (v=0 ; v<top->nbvers ; v+=1) {
584        Tlivrable* l=curr->ls[tn][stn][dn][v] ;
585        gen_label_vers(tmp,l);
586        boxx = box_x + l->bm*PICT_MONTHWIDTH ;
587        box_dx  = (l->em - l->bm) * PICT_MONTHWIDTH;
588        print_box(1,0,boxx,y+y0,box_dx,box_dy,COLOR_BOX_LIGHT,0,0);
589        print_box(0,tmp,boxx,y+y0,box_dx,box_dy,0,0,0);
590    }
591    y -= DELIVRABLE_VSEP;
592    return y;
593}
594
595void task_delivrable(double label_x, double box_x, double title_x, int tn)
596{
597int stn,dn;
598Tlivrable* task=curr->ls[tn][0][0][0];
599double y = task->task_y+task->task_dy-task->task_y_del;
600    char tmp[1000];
601    sprintf(tmp,"\\textbf{Task-%d \\textit{%s}}",task->tn,task_names[task->tn]);
602    print_put(label_x/2,y+(TASK_TITLEHEIGHT-TASK_TITLEFONTHEIGHT)/2,tmp);
603
604    //y += DELIVRABLE_VSEP/2. ;
605    for (stn=0 ; curr->ls[tn][stn][0][0]!=0 ; stn++)
606        for (dn=0 ; curr->ls[tn][stn][dn][0]!=0 ; dn++) {
607                        if (curr->ls[tn][stn][dn][0]->dn >=0)
608                                y=delivrable(label_x,box_x,title_x,y,tn,stn,dn);
609        }
610}
611
612void do_gantt(const char* fn, int* tnplus, int* tnmoins)
613{
614    int tn;
615    double pictwidth, pictheight;
616    double gantt_x,gantt_y;
617    double gantt_dx,gantt_dy;
618
619    double label_x,title_x;
620    curr = data_new(tnplus,tnmoins);
621    if ( (curr->os=fopen(fn,"w"))==0 ) {
622        fprintf(stderr,"can not open %s file for writing.\n",fn);
623        fprintf(stderr,"generation of %s graph is skipped.\n",fn);
624        return;
625    }
626    prepare0(curr);
627    prepare1(curr);
628    prepare2(curr);
629    prepare3(curr);
630
631    pictheight=0 ;
632    pictheight += PICT_BOTSEP ;
633    for ( tn=0 ; curr->ls[tn][0][0][0]!=0 ; tn++ );
634    for ( tn=tn-1 ; tn>=0 ; tn-- ) {
635        double offset;
636        curr->ls[tn][0][0][0]->task_y     = pictheight;
637        curr->ls[tn][0][0][0]->task_dy    = task_livrable_height(tn,&offset);
638        curr->ls[tn][0][0][0]->task_y_del = offset;
639        pictheight += curr->ls[tn][0][0][0]->task_dy;
640        pictheight += TASK_VSEP;
641    }
642    pictheight += PICT_MONTHHEIGHT;
643    pictheight += PICT_TOPSEP ;
644    gantt_y  = PICT_BOTSEP ;
645    gantt_dy = pictheight-PICT_TOPSEP-PICT_BOTSEP ;
646
647    pictwidth=0;
648    pictwidth += PICT_LEFTSEP;
649    label_x    = pictwidth;
650    pictwidth += DELIVRABLE_LABELWIDTH;
651    pictwidth += PICT_HSEP;
652    gantt_x    = pictwidth ;
653    gantt_dx   = 36*PICT_MONTHWIDTH ;
654    pictwidth += gantt_dx ;
655    pictwidth += PICT_HSEP;
656    title_x    = pictwidth;
657    pictwidth += DELIVRABLE_TITLEWIDTH;
658    pictwidth += PICT_RIGHTSEP;
659   
660    fprintf(curr->os,"\\setlength{\\unitlength}{1.0mm}\n");
661    fprintf(curr->os,"\\begin{picture}(%.1f,%.1f)\n",pictwidth,pictheight);
662    //print_hline(0,0,pictwidth,0);
663    //print_hline(0,pictheight,pictwidth,0);
664    task_box(pictwidth);
665    month_grid(gantt_x,gantt_y,gantt_dx,gantt_dy);
666    for ( tn=0 ; curr->ls[tn][0][0][0]!=0 ; tn++ ) {
667        task_delivrable(label_x,gantt_x,title_x,tn);
668    }
669
670    print_milestones(gantt_x,0,gantt_dx,gantt_dy+gantt_y);
671    fprintf(curr->os,"\\end{picture}\n");
672    fclose(curr->os);
673    curr->os=0;
674}
675
676Tlivrable* do_partner_table_getLivrable(Tlivrable** leader, Tlivrable* top, int partner)
677{
678    int i;
679    Tlivrable* ret;
680    *leader=top->vers[top->nbvers-1];
681    if (leader[0]->partner==partner)
682        return *leader;
683    for (i=0; i<top->nbpart ; i+=1) {
684        ret= top->part[i];
685        if ( ret->partner==partner )
686                return ret;
687    }
688    return 0;
689}
690
691void do_partner_table_full(int partner)
692{
693    struct partner_def* part = partner_table+partner;
694    if ( (curr->os=fopen(part->fnfull,"w"))==0 ) {
695        fprintf(stderr,"can not open %s file for writing.\n",part->fnfull);
696        fprintf(stderr,"generation of %s partner table is skipped.\n",part->fnfull);
697        return;
698    }
699    fprintf(curr->os,"\\begin{tabular}{|c|l||r|r|r||r|}\\hline\n");
700    fprintf(curr->os,
701        "number & \\multicolumn{1}{c||}{title} & \\multicolumn{3}{c||}{years } & total \\\\\\cline{3-5}\n");
702    fprintf(curr->os,
703        " & & \\multicolumn{1}{c|}{1} & \\multicolumn{1}{c|}{2} & "
704        "\\multicolumn{1}{c||}{3} &  \\\\\\hline\\hline\n");
705    int tn,stn,dn,v=0;
706    double an1=0,an2=0,an3=0,an=0;
707    double tsk1,tsk2,tsk3,tsk;
708    int newlineadded=1;
709    for (tn=0 ; tn<T_MAX ; tn++) {
710        if (curr->ls[tn][0][0][0]==0) break;
711        if (tn!=0 && newlineadded==0 ) {
712            newlineadded = 1;
713            fprintf(curr->os,"\\hline ");
714        }
715                tsk1=tsk2=tsk3=tsk=0;
716        for (stn=0; stn<S_MAX; stn++) {
717            for (dn=0; dn<D_MAX; dn++) {
718                Tlivrable *lcurr,*leader;
719                Tlivrable* top=curr->ls[tn][stn][dn][v];
720                if (top==0) continue;
721                if ( (lcurr=do_partner_table_getLivrable(&leader,top,partner))==0 )
722                    continue;
723                double sum1,sum2,sum3,sum=0;
724                sum1 = lcurr->hman[0]; sum +=sum1;
725                sum2 = lcurr->hman[1]; sum +=sum2;
726                sum3 = lcurr->hman[2]; sum +=sum3;
727                char label[1000],title[1000];
728                gen_label_base(label,leader);
729                sprintf(title,"\\resstablestyletitle{%s}",leader->title);
730                fprintf(curr->os,"%s & %s & %2.1f & %2.1f & %2.1f & %2.1f \\\\\\hline\n",
731                   label,title,sum1,sum2,sum3,sum);
732                an1 += sum1 ; tsk1 += sum1 ;
733                an2 += sum2 ; tsk2 += sum2 ;
734                an3 += sum3 ; tsk3 += sum3 ;
735                an  += sum  ; tsk  += sum  ;
736                newlineadded=0;
737                if ( sum1==0 && leader->nbma[0]!=0)
738                    fprintf(stderr,"ERROR:   %-10s:%s probleme sur l'an 1 (in table=%2.1f, in gantt=%2.1f\n",
739                        part->name,label,sum1,leader->nbma[0]);
740                else if (sum1!=0 && leader->nbma[0]==0 )
741                    fprintf(stderr,"ERROR:   %-10s:%s probleme sur l'an 1 (in table=%2.1f, in gantt=%2.1f\n",
742                        part->name,label,sum1,leader->nbma[0]);
743                else if (sum1!=0 && sum1>leader->nbma[0] )
744                    fprintf(stderr,"WARNING: %-10s:%s probleme sur l'an 1 (in table=%2.1f, in gantt=%2.1f\n",
745                        part->name,label,sum1,leader->nbma[0]);
746                if ( sum2==0 && leader->nbma[1]!=0)
747                    fprintf(stderr,"ERROR:   %-10s:%s probleme sur l'an 2 (in table=%2.1f, in gantt=%2.1f\n",
748                        part->name,label,sum2,leader->nbma[1]);
749                else if ( sum2!=0 && leader->nbma[1]==0)
750                    fprintf(stderr,"ERROR:   %-10s:%s probleme sur l'an 2 (in table=%2.1f, in gantt=%2.1f\n",
751                        part->name,label,sum2,leader->nbma[1]);
752                else if (sum2!=0 && sum2>leader->nbma[1])
753                    fprintf(stderr,"WARNING: %-10s:%s probleme sur l'an 2 (in table=%2.1f, in gantt=%2.1f\n",
754                        part->name,label,sum2,leader->nbma[1]);
755                if ( sum3==0 && leader->nbma[2]!=0)
756                    fprintf(stderr,"ERROR:   %-10s:%s probleme sur l'an 3 (in table=%2.1f, in gantt=%2.1f\n",
757                        part->name,label,sum3,leader->nbma[2]);
758                else if ( sum3!=0 && leader->nbma[2]==0)
759                    fprintf(stderr,"ERROR:   %-10s:%s probleme sur l'an 3 (in table=%2.1f, in gantt=%2.1f\n",
760                        part->name,label,sum3,leader->nbma[2]);
761                else if (sum3!=0 && sum3>leader->nbma[2])
762                    fprintf(stderr,"WARNING: %-10s:%s probleme sur l'an 3 (in table=%2.1f, in gantt=%2.1f\n",
763                        part->name,label,sum3,leader->nbma[2]);
764            }
765        }
766                if (tsk!=0)
767        fprintf(curr->os,"%s & total Task-%d & %2.1f & %2.1f & %2.1f & %2.1f \\\\\\hline\n",
768            "",curr->ls[tn][0][0][0]->tn,tsk1,tsk2,tsk3,tsk);
769               
770    }
771    if ( an!=(an1+an2+an3) ) {
772        fprintf(stderr,"bad computation in %s table.\n",part->fnfull);
773    }
774    fprintf(curr->os,"\\hline\n");
775    fprintf(curr->os,"%s & %s & %2.1f & %2.1f & %2.1f & %2.1f \\\\\\hline\n",
776            "","total",an1,an2,an3,an);
777
778    fprintf(curr->os,"\\end{tabular}\n");
779    fclose(curr->os);
780    curr->os=0;
781}
782
783void do_partner_table_short(int partner)
784{
785    struct partner_def* part = partner_table+partner;
786    if ( (curr->os=fopen(part->fnshort,"w"))==0 ) {
787        fprintf(stderr,"can not open %s file for writing.\n",part->fnshort);
788        fprintf(stderr,"generation of %s partner table is skipped.\n",part->fnshort);
789        return;
790    }
791    fprintf(curr->os,"\\begin{center}\\begin{small}\\begin{tabular}{|c|l||r|r|r||r|}\\hline\n");
792    fprintf(curr->os,
793        " & title & \\multicolumn{3}{c||}{years } & total \\\\\\cline{3-5}\n");
794    fprintf(curr->os,
795        " &       & \\multicolumn{1}{c|}{1} & \\multicolumn{1}{c|}{2} & "
796                    "\\multicolumn{1}{c||}{3} &  \\\\\\hline\\hline\n");
797    int tn,stn,dn,v=0;
798    double an1=0,an2=0,an3=0,an=0;
799    double tsk1,tsk2,tsk3,tsk;
800    int newlineadded=1;
801    for (tn=0 ; tn<T_MAX ; tn++) {
802        if (curr->ls[tn][0][0][0]==0) break;
803                tsk1=tsk2=tsk3=tsk=0;
804        for (stn=0; stn<S_MAX; stn++) {
805            for (dn=0; dn<D_MAX; dn++) {
806                Tlivrable *lcurr,*leader;
807                Tlivrable* top=curr->ls[tn][stn][dn][v];
808                if (top==0) continue;
809                if ( (lcurr=do_partner_table_getLivrable(&leader,top,partner))==0 )
810                    continue;
811                double sum1,sum2,sum3,sum=0;
812                sum1 = lcurr->hman[0]; sum +=sum1;
813                sum2 = lcurr->hman[1]; sum +=sum2;
814                sum3 = lcurr->hman[2]; sum +=sum3;
815                an1 += sum1 ; tsk1 += sum1 ;
816                an2 += sum2 ; tsk2 += sum2 ;
817                an3 += sum3 ; tsk3 += sum3 ;
818                an  += sum  ; tsk  += sum  ;
819                newlineadded=0;
820                char label[1000];
821                gen_label_base(label,leader);
822            }
823        }
824                if (tsk!=0)
825        fprintf(curr->os,"Task-%d & %s & %2.1f & %2.1f & %2.1f & %2.1f \\\\\\hline\n",
826            curr->ls[tn][0][0][0]->tn,
827            task_names[curr->ls[tn][0][0][0]->tn],tsk1,tsk2,tsk3,tsk);
828               
829    }
830    if ( an!=(an1+an2+an3) ) {
831        fprintf(stderr,"bad computation in %s table.\n",part->fnshort);
832    }
833    fprintf(curr->os,"\\hline\n");
834    fprintf(curr->os," & %s &  %2.1f & %2.1f & %2.1f & %2.1f \\\\\\hline\n",
835            "total",an1,an2,an3,an);
836
837    fprintf(curr->os,"\\end{tabular}\\end{small}\\end{center}\n");
838    fclose(curr->os);
839    curr->os=0;
840}
841
842void do_livrable_tables_open(int tablenum, int last)
843{
844    char fn[1024];
845
846    if (curr->os!=0) {
847        fprintf(curr->os,"\\end{tabular}\n");
848        fclose(curr->os);
849        curr->os = 0;
850    }
851
852    if ( last )
853        return;
854
855    sprintf(fn,"table_livrable_%02d.tex",tablenum);
856    if ( (curr->os=fopen(fn,"w"))==0 ) {
857        fprintf(stderr,"FATAL: can not open %s file for writing.\n",fn);
858        exit(1);
859    }
860    fprintf(curr->os,"\\begin{tabular}[t]{|l|c|c|c|p{\\desclen}|}\\hline\n");
861    fprintf(curr->os,"number");
862    fprintf(curr->os," & resp.");
863    fprintf(curr->os," & \\makebox[2mm]{T0+}");
864    fprintf(curr->os," & \\makebox[2mm]{kind}");
865    fprintf(curr->os," & description\\\\\\hline\\hline\n");
866}
867
868void do_livrable_tables(int maxlines)
869{
870    int nblines=maxlines;
871    int nbfile=1;
872    int tn,stn,dn,v;
873    do_livrable_tables_open(nbfile,0); nbfile +=1 ;
874    for (tn=0 ; tn<T_MAX ; tn++)  { if ( curr->ls[tn][0][0][0]==0 ) break;
875    for (stn=0; stn<S_MAX; stn++) { if ( curr->ls[tn][stn][0][0]==0 ) break;
876    for (dn=0; dn<D_MAX; dn++)    {
877        Tlivrable* top = curr->ls[tn][stn][dn][0];
878        if ( top==0 ) break;
879        Tlivrable* last=top->vers[top->nbvers-1];
880        if ( (nblines-top->nbvers) <= 0 ) {
881            do_livrable_tables_open(nbfile,0); nbfile +=1 ;
882            nblines = maxlines;
883        }
884        for (v=0; v<V_MAX; v++) {
885            Tlivrable* l = curr->ls[tn][stn][dn][v];
886            if ( l==0 ) break;
887            if ( l->leader==0 ) continue;
888            char label[1000],resp[100],date[100],kind[100],desc[1000];
889            gen_label_full(label,l);
890            sprintf(resp,"\\S%s",partner_table[l->partner].key);
891            sprintf(date,"\\makebox[2mm][r]{%d}",l->em);
892            sprintf(kind,"\\makebox[1mm]{%s}",l->kind);
893            if ( top->nbvers == 1 )
894                sprintf(desc,"%s \\\\\\hline\n",last->title);
895             else if ( v==(top->nbvers-1) )
896                sprintf(desc,
897                  "\\multirow{-%d}{\\desclen}{%s}\\\\\\hline\n",
898                  top->nbvers,last->title);
899             //else if ( v==(top->nbvers-1) )
900             //   sprintf(desc, "\\\\\\hline\n");
901             else
902                sprintf(desc, "\\\\\\cline{1-4}\n");
903
904             fprintf(curr->os,"%-15s", label);
905             fprintf(curr->os," & %-10s", resp);
906             fprintf(curr->os," & %-30s", date);
907             fprintf(curr->os," & %-30s", kind);
908             fprintf(curr->os," & %s", desc);
909             nblines -= 1;
910        }
911    }}}
912    do_livrable_tables_open(nbfile,1);
913}
914
915int main()
916{
917    int tnplus[10] =  { 1, 2, 3, 4, 5, 6, -1 };
918    int tnmoins[10] = { 1, 2, 3, 4, 5, 6, -1 };
919
920    yylex();
921    do_gantt("gantt.tex",0,0);
922    do_gantt("gantt1.tex",tnplus,0);
923    do_gantt("gantt2.tex",0,tnmoins);
924
925    curr = data_new(0,0);
926    prepare0(curr);
927    prepare1(curr);
928    prepare2(curr);
929    prepare3(curr);
930    do_partner_table_full(1);  do_partner_table_short(1);
931    do_partner_table_full(2);  do_partner_table_short(2);
932    do_partner_table_full(3);  do_partner_table_short(3);
933    do_partner_table_full(4);  do_partner_table_short(4);
934    do_partner_table_full(5);  do_partner_table_short(5);
935    do_partner_table_full(6);  do_partner_table_short(6);
936    do_partner_table_full(7);  do_partner_table_short(7);
937    do_partner_table_full(8);  do_partner_table_short(8);
938
939    curr = data_new(0,0);
940    prepare0(curr);
941    prepare1(curr);
942    prepare2(curr);
943    prepare3(curr);
944    do_livrable_tables(40);
945    return 0;
946}
Note: See TracBrowser for help on using the repository browser.