OSDN Git Service

adjust integer's signedness
[tjqt4port/tj2qt4.git] / taskjuggler / TaskScenario.cpp
1 /*
2  * TaskScenario.h - TaskJuggler
3  *
4  * Copyright (c) 2002 by Chris Schlaeger <cs@kde.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of version 2 of the GNU General Public License as
8  * published by the Free Software Foundation.
9  *
10  * $Id$
11  */
12
13 #include "TaskScenario.h"
14 #include "Resource.h"
15 #include "ResourceTreeIterator.h"
16 #include "Project.h"
17
18
19 TaskScenario::TaskScenario() :
20     task(0),
21     index(0),
22     specifiedStart(0),
23     specifiedEnd(0),
24     start(0),
25     end(0),
26     minStart(0),
27     maxStart(0),
28     minEnd(0),
29     maxEnd(0),
30     startBuffer(-1.0),
31     endBuffer(-1.0),
32     startBufferEnd(0),
33     endBufferStart(0),
34     duration(0.0),
35     length(0.0),
36     effort(0.0),
37     startCredit(-1.0),
38     endCredit(-1.0),
39     criticalness(0.0),
40     pathCriticalness(0.0),
41     isOnCriticalPath(false),
42     reportedCompletion(-1.0),
43     containerCompletion(-1.0),
44     completionDegree(0.0),
45     status(Undefined),
46     statusNote(),
47     specifiedScheduled(false),
48     scheduled(false),
49     startCanBeDetermined(false),
50     endCanBeDetermined(false),
51     specifiedBookedResources(),
52     bookedResources(),
53     criticalLinks(),
54     svgGanttReportIndex(-1)
55 {
56 }
57
58 void
59 TaskScenario::calcCompletionDegree(time_t now)
60 {
61     if (now > end)
62     {
63         completionDegree = 100.0;
64         status = reportedCompletion >= 0 && reportedCompletion < 100 ?
65             Late : Finished;
66     }
67     else if (now <= start)
68     {
69         completionDegree = 0.0;
70         status = reportedCompletion > 0 ? InProgressEarly : NotStarted;
71     }
72     else
73     {
74         status = OnTime;
75         if (effort > 0.0)
76         {
77             completionDegree = (100.0 / effort) *
78                 task->getLoad(index, Interval(start, now));
79         }
80         else if (length > 0.0)
81         {
82             completionDegree = (100.0 /
83                 task->getProject()->calcWorkingDays(Interval(start, end))) *
84                 task->getProject()->calcWorkingDays(Interval(start, now));
85         }
86         else
87             completionDegree = (100.0 / (end - start + 1)) * (now - start);
88
89         if (reportedCompletion >= 0.0)
90         {
91             if (reportedCompletion < completionDegree)
92                 status = InProgressLate;
93             else if (reportedCompletion > completionDegree)
94                 status = InProgressEarly;
95         }
96     }
97 }
98
99 bool TaskScenario::isDutyOf(const Resource* r) const
100 {
101     for (ConstResourceTreeIterator rti(r); *rti; ++rti)
102         if (bookedResources.containsRef(*rti) > 0)
103             return true;
104
105     return false;
106 }