OSDN Git Service

Removing redundant error checking related to booking declaration.
[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 {
55 }
56
57 void
58 TaskScenario::calcCompletionDegree(time_t now)
59 {
60     if (now > end)
61     {
62         completionDegree = 100.0;
63         status = reportedCompletion >= 0 && reportedCompletion < 100 ?
64             Late : Finished;
65     }
66     else if (now <= start)
67     {
68         completionDegree = 0.0;
69         status = reportedCompletion > 0 ? InProgressEarly : NotStarted;
70     }
71     else
72     {
73         status = OnTime;
74         if (effort > 0.0)
75         {
76             completionDegree = (100.0 / effort) *
77                 task->getLoad(index, Interval(start, now));
78         }
79         else if (length > 0.0)
80         {
81             completionDegree = (100.0 /
82                 task->getProject()->calcWorkingDays(Interval(start, end))) *
83                 task->getProject()->calcWorkingDays(Interval(start, now));
84         }
85         else
86             completionDegree = (100.0 / (end - start + 1)) * (now - start);
87
88         if (reportedCompletion >= 0.0)
89         {
90             if (reportedCompletion < completionDegree)
91                 status = InProgressLate;
92             else if (reportedCompletion > completionDegree)
93                 status = InProgressEarly;
94         }
95     }
96 }
97
98 bool TaskScenario::isDutyOf(const Resource* r) const
99 {
100     for (ConstResourceTreeIterator rti(r); *rti; ++rti)
101         if (bookedResources.containsRef(*rti) > 0)
102             return true;
103
104     return false;
105 }