File: Task.pm

package info (click to toggle)
taskjuggler 2.4.3-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 13,156 kB
  • ctags: 3,713
  • sloc: cpp: 37,683; sh: 13,617; xml: 6,021; perl: 5,207; lisp: 538; makefile: 283; python: 258
file content (423 lines) | stat: -rwxr-xr-x 8,391 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
######################################################################## 
# Copyright (c) 2002 by Philippe Midol-Monnet <philippe@midol-monnet.org>
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
#########################################################################

use strict;
use POSIX;

package Task;

# Parameters

my $task_width  = 4;      # 4cm
my $task_height = 1.5;    # 1,5 cm
my $cell_coef   = 1.3;

sub get_task_width {
    return $task_width;
}

sub get_task_height {
    return $task_height;
}

sub cell_coef {
    return $cell_coef;
}

sub new {
    my ( $class, $ref ) = @_;

    my $task = {
        Task => $ref,
        Col  => -1,
        Lin  => -1,
    };

    bless $task, $class;

    return $task;

}

sub get_id {
    my $self = shift;

    return $self->{Task}->{Id};

}

sub set_dep {
    my $self = shift;

    my $dep = shift;

    $self->{Dep} = $dep;
}

sub can_set_col {
    my $self = shift;

    my $task_dep;

    foreach $task_dep ( @{ $self->{Dep} } ) {
        return 0 if ( !$task_dep->col_is_set() );
    }

    return 1;

}

sub set_col {
    my $self = shift;

    my $column = -1;
    my $task_dep;
    my $col_task;

    foreach $task_dep ( @{ $self->{Dep} } ) {

        $col_task = $task_dep->get_max_col();
        $column = $col_task if ( $col_task > $column );
    }

    $column++;

    $self->{Col} = $column;

    return $column;
}

sub col_is_set {
    my $self = shift;

    return ( $self->{Col} != -1 );
}

sub get_col {
    my $self = shift;

    return $self->{Col};
}

sub get_min_col {
    my $self = shift;

    return $self->{Col};
}

sub get_max_col {
    my $self = shift;

    return $self->{Col};
}

sub calc_lin {
    my $self = shift;

    my $first_dep;
    my $line = 0;

    if ( $self->{Dep}[0] ) {
        $first_dep = $self->{Dep}[0];
        $line      = $first_dep->get_lin();
    }

    return $line;
}

sub set_lin {
    my $self = shift;
    my $line = shift;

    $self->{Lin} = $line;

    return;
}

sub add_lin {
    my $self = shift;
    my $line = shift;

    $self->{Lin} = $self->{Lin} + $line;

    return;
}

sub get_lin {
    my $self = shift;

    return $self->{Lin};
}

sub get_height {
    return 1;
}

sub set_abs_lin {
    my $self = shift;
    my $line = shift;

    $self->{Abs_Lin} = $line;

    return;
}


# return task dependencies
sub get_dep {
    my $self = shift;

    return $self->{Dep};
}

## return task dependencie id from xml
#sub get_dep_id
#  {
#    my $self = shift;

#    return $self->{Task}->{Depends}{TaskID};
#  }

# return task dependencie id from xml
sub get_previous_id {
    my $self = shift;

    return $self->{Task}->{Previous};
}

# return task dependencie id from xml
sub get_follower_id {
    my $self = shift;

    return $self->{Task}->{Followers};
}

sub is_container {
    my $self = shift;

    return 0;
}

sub get_parent {
    my $self = shift;

    return $self->{Task}->{ParentTask};

}

sub get_end {
    my $self = shift;

    if ($self->{Task}->{actualEnd}{content} != 0)
      {
	return $self->{Task}->{actualEnd}{content}
      }
    else 
      {
	return $self->{Task}->{planEnd}{content};
      }
}

sub get_start {
    my $self = shift;
    if ($self->{Task}->{actualStart}{content} != 0)
      {
	return $self->{Task}->{actualStart}{content}
      }
    else 
      {
        return $self->{Task}->{planStart}{content};
      }

}

sub draw {
    my $self   = shift;
    my $out_ps = shift;
    my $x_pos  = shift;
    my $y_pos  = shift;

    #  print $x_pos, " ",$y_pos, "\n";

    # blank zone
    $out_ps->setcolour("white");
    $out_ps->box( $x_pos, $y_pos, $x_pos + $task_width, $y_pos + $task_height,
        1 );

    # draw rectangle
    $out_ps->setcolour("black");
    $out_ps->box( $x_pos, $y_pos, $x_pos + $task_width, $y_pos + $task_height );

    my $x3          = $task_width / 3.0;
    my $y4          = $task_height / 4.0;
    my $text_margin = $y4 / 4.0;

    if ($self->{Task}->{Type} eq "Milestone" )
	{
	    $out_ps->box($x_pos + $x3, $y_pos + 3 * $y4, $x_pos + 2 * $x3, $y_pos + $task_height);
	}
	else
	{
    # draw each rectangle inside 
    $out_ps->line( $x_pos, $y_pos + $y4, $x_pos + $task_width, $y_pos + $y4 );
    $out_ps->line( $x_pos, $y_pos + 3 * $y4, $x_pos + $task_width,
        $y_pos + 3 * $y4 );
    $out_ps->line( $x_pos + $x3, $y_pos, $x_pos + $x3, $y_pos + $y4 );
    $out_ps->line( $x_pos + 2 * $x3, $y_pos, $x_pos + 2 * $x3, $y_pos + $y4 );
    $out_ps->line( $x_pos + $x3, $y_pos + 3 * $y4, $x_pos + $x3,
        $y_pos + $task_height );
    $out_ps->line(
        $x_pos + 2 * $x3, $y_pos + 3 * $y4,
        $x_pos + 2 * $x3, $y_pos + $task_height
    );
	}

    # draw progress bar (% complete)
    $out_ps->setcolour("grey80");
    $out_ps->box( $x_pos, 
		  $y_pos + $y4, 
		  $x_pos + $task_width * $self->{Task}->{complete} / 100.0,
		  $y_pos + 2 * $y4
		  ,1
		);
    $out_ps->setcolour("black");

    # write text
    # Task ID
    $out_ps->text(
        $x_pos + $task_width / 2.0, $y_pos + 2 * $y4 + $text_margin,
        $self->get_id(),            'centre'
    );

	
    # Start
    my $start_value;
    if ($self->{Task}->{actualStart}{content} != 0)
      {
	$start_value = $self->{Task}->{actualStart}{content}
      }
    else 
      {
	$start_value = $self->{Task}->{planStart}{content};
      }
    my $start = POSIX::strftime( "%x", localtime( $start_value ) );

   if ($self->{Task}->{Type} eq "Milestone" )
	{
    $out_ps->text(
        $x_pos + $x3 + $x3 / 2.0, $y_pos + 3 * $y4 + $text_margin,
        $start,             'centre'
    );
    }
    else
    {
    $out_ps->text(
        $x_pos + $x3 / 2.0, $y_pos + 3 * $y4 + $text_margin,
        $start,             'centre'
    );
    }
    # End

    my $end_value;
    if ($self->{Task}->{actualEnd}{content} != 0)
      {
	$end_value = $self->{Task}->{actualEnd}{content}
      }
    else 
      {
	$end_value = $self->{Task}->{planEnd}{content};
      }
    my $end = POSIX::strftime( "%x", localtime( $end_value ) );

   if ($self->{Task}->{Type} ne "Milestone" )
	{
    $out_ps->text( $x_pos + 2 * $x3 + $x3 / 2.0,
        $y_pos + 3 * $y4 + $text_margin, $end, 'centre' );
        }
}

# compute absolute Id from relative Id
sub id_to_abs {
    my $self   = shift;
    my $rel_id = shift;

    my $abs_id;
    my $task_id = $self->get_id;

    my @lst_sub_id = split /\./, $task_id;

    while ( $rel_id =~ s/^\!(.*)/$1/ ) {
        pop @lst_sub_id;
    }

    $abs_id = join '.', ( @lst_sub_id, $rel_id );
    return $abs_id;
}

#create dependencies (previous tasks) reference list
sub find_dep_lst {
    my $self     = shift;
    my $alltasks = shift;

    my $dep_ref;
    my $dep_id;
    my @lst_dep;
    my $abs_dep;

    if ( $self->get_previous_id ) {
        foreach $dep_id ( @{ $self->get_previous_id } ) {
            $dep_ref = $alltasks->find_id($dep_id);

            # Task depends of a TaskList then find last task from this list
            $dep_ref = $dep_ref->last_subtask if ($dep_ref->is_container());

            push @lst_dep, $dep_ref;
        }
    }

    return \@lst_dep;
}

#create back dependencies (follower tasks) reference list
sub find_follower_lst {
    my $self     = shift;
    my $alltasks = shift;

    my $dep_ref;
    my $dep_id;
    my @lst_dep;
    my $abs_dep;

    if ( $self->get_follower_id ) {
        foreach $dep_id ( @{ $self->get_follower_id } ) {
            $abs_dep = $self->id_to_abs($dep_id);
            $dep_ref = $alltasks->find_id($abs_dep);

            # not the best way but it works
            if ( $dep_ref->is_container() ) {
                $dep_ref = $dep_ref->last_sub_task;
            }
            push @lst_dep, $dep_ref;
        }
    }

    return \@lst_dep;
}

1;