source: anr/gantt.l @ 251

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

IA

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