source: anr/gantt.l @ 145

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

IA: fixed warning/error in table generation

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