00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <cstdarg>
00019
00020 using namespace std;
00021
00022 #include "task.h"
00023 #include "projectExceptions.h"
00024
00025 TASK::TASK(char *id, char *name, int duration):
00026 NAMED_ID(id, name)
00027 {
00028 mDesc = NULL;
00029 mOverrun = NULL;
00030 mDuration = duration;
00031 mFullduration = duration;
00032 remaining = -1;
00033 rremaining = -1;
00034 mAssigned = NULL;
00035 mStart = INVALIDDAYNO;
00036 mFinish = INVALIDDAYNO;
00037 mLstart = INVALIDDAYNO;
00038 mLfinish = INVALIDDAYNO;
00039 mSlack = 0;
00040 mAstart = INVALIDDAYNO;
00041 mAfinish = INVALIDDAYNO;
00042 mBstart = INVALIDDAYNO;
00043 mBfinish = INVALIDDAYNO;
00044 mChildren = 0;
00045 mBlock = false;
00046 scheduled = 0;
00047 rscheduled = 0;
00048 x1 = x2 = y1 = y2 = 0;
00049 nx = ny = -1;
00050 mnDays = 0;
00051 mParents = 0;
00052 mPercentComplete = 0.0;
00053 }
00054
00055
00056 void TASK::Error(char *fmt, ...)
00057 {
00058 char buf[1024];
00059 va_list args;
00060
00061 va_start(args, fmt);
00062 vsprintf(buf, fmt, args);
00063 va_end(args);
00064
00065 string sid = id();
00066 throw TASKException( sid, buf );
00067 }
00068
00069
00070 void TASK::setDaysDone(int days)
00071 {
00072 mnDays = days;
00073 }
00074
00075
00076 void TASK::Blockify()
00077 {
00078 mBlock = true;
00079 }
00080
00081
00082 void TASK::setDesc( char * desc )
00083 {
00084 mDesc = strdup(desc);
00085 }
00086
00087 void TASK::setPercentComplete( double c )
00088 {
00089 if( c < 0.0 || c > 100.0 )
00090 Error("Invalid completion (should be 0<=%s<=100)", c);
00091 mPercentComplete = c;
00092 }
00093
00094
00095 void TASK::AddNote(const string & note)
00096 {
00097 mNotes.push_back(note);
00098 }
00099
00100
00101 void TASK::addDepends( TASK * depends )
00102 {
00103 mDepends.push_back( depends );
00104 ++depends->mChildren;
00105 };
00106
00107
00108 void TASK::addFollows( TASK * follows )
00109 {
00110 mFollows.push_back( follows );
00111 ++follows->mParents;
00112 }
00113
00114
00115 void TASK::addTimeBlock(RESOURCE *r, int start, int finish, TimeBlock::Type type)
00116 {
00117 mWhen.push_back(TaskTimeBlock(r, start, finish, type));
00118 }
00119
00120
00121 void TASK::addReverseTimeBlock(RESOURCE *r, int start, int finish, TimeBlock::Type type)
00122 {
00123 mRwhen.push_back(TaskTimeBlock(r, start, finish, type));
00124 }
00125
00126
00127 void TASK::copyWhenToReverseWhen()
00128 {
00129 mRwhen = mWhen;
00130 }
00131
00132
00133 bool TASK::DayBooked( int dayNo )
00134 {
00135 for ( TaskTimeBlockIterator tb = mWhen.begin(); tb != mWhen.end() ; tb++ )
00136 if ( tb->start() <= dayNo && tb->finish() >= dayNo )
00137 return true;
00138 return false;
00139 }
00140
00141
00142 bool TASK::overlap(int start, int finish)
00143 {
00144 for ( TaskTimeBlockIterator tb = mWhen.begin(); tb != mWhen.end(); tb++ )
00145 if ( tb->overlap(start, finish) )
00146 return true;
00147 return false;
00148 }
00149
00150
00151 bool TASK::isActiveDuring(int start, int finish)
00152 {
00153 if ( start <= mStart && mStart <= finish )
00154 return true;
00155 if ( start <= mFinish && mFinish <= finish )
00156 return true;
00157 if ( mStart <= start && start <= mFinish )
00158 return true;
00159 if ( mStart <= finish && finish <= mFinish )
00160 return true;
00161 return false;
00162 }
00163
00164
00165 void TASK::addCandidate(RESOURCE *res)
00166 {
00167 mCando.push_back(res);
00168 }
00169
00170 double TASK::timeCost()
00171 {
00172 return mAssigned->rate() * mDuration;
00173 }
00174
00175
00176 double TASK::itemCost()
00177 {
00178 double value = 0.0;
00179 for ( ITEM::PTRLIST::const_iterator ip = mItems.begin() ; ip != mItems.end() ; ip++)
00180 value += (*ip)->cost();
00181
00182 return value;
00183 }
00184
00185
00186 bool CompareTaskResources::operator()(const TASK * t1, const TASK * t2) const
00187 {
00188 int deltar = strcmp(t1->assigned()->id(), t2->assigned()->id());
00189 if ( deltar != 0 )
00190 return deltar < 0;
00191
00192 return t1->start() < t2->start();
00193 }
00194
00195
00196