00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef KPTNODE_H
00022 #define KPTNODE_H
00023
00024 #include "kptrelation.h"
00025 #include "kptduration.h"
00026 #include "kptdatetime.h"
00027 #include "kptschedule.h"
00028
00029 #include <qintdict.h>
00030 #include <qrect.h>
00031 #include <qptrlist.h>
00032 #include <qstring.h>
00033 #include <qcanvas.h>
00034
00035 #include <vector>
00036
00037 class QDomElement;
00038
00039 namespace KPlato
00040 {
00041
00042 class Account;
00043 class Project;
00044 class Appointment;
00045 class ResourceGroup;
00046 class Resource;
00047 class ResourceGroupRequest;
00048 class Effort;
00049 class WBSDefinition;
00050 class EffortCostMap;
00051
00057 class Node {
00058
00059 public:
00060 enum ConstraintType { ASAP, ALAP, MustStartOn, MustFinishOn, StartNotEarlier, FinishNotLater, FixedInterval };
00061
00062 Node(Node *parent = 0);
00063 Node(Node &node, Node *parent = 0);
00064
00065
00066
00067 virtual ~Node() = 0;
00068
00069 bool setId(QString id);
00070 QString id() const { return m_id; }
00071
00072 enum NodeTypes {
00073 Type_Node = 0,
00074 Type_Project = 1,
00075 Type_Subproject = 2,
00076 Type_Task = 3,
00077 Type_Milestone = 4,
00078 Type_Periodic = 5,
00079 Type_Summarytask = 6
00080 };
00081
00082 virtual int type() const = 0;
00083
00088 virtual Node *projectNode();
00089
00090
00091 virtual bool load(QDomElement &) { return true; }
00092 virtual bool load(QDomElement &, Project &) { return true; }
00093 virtual void save(QDomElement &element) const = 0;
00095 virtual void saveRelations(QDomElement &element) const;
00096
00097
00098
00099
00100
00101 Node *getParent() const { return m_parent; }
00102 void setParent( Node* newParent ) { m_parent = newParent;}
00103 const QPtrList<Node> &childNodeIterator() const { return m_nodes; }
00104 int numChildren() const { return m_nodes.count(); }
00105 virtual void addChildNode(Node *node, Node *after=0);
00106 virtual void insertChildNode(unsigned int index, Node *node);
00107 void delChildNode(Node *node, bool remove=true);
00108 void delChildNode(int number, bool remove=true);
00109 Node* getChildNode(int number) { return m_nodes.at(number); }
00110 const Node* getChildNode(int number) const;
00111 int findChildNode( Node* node );
00112
00113
00114
00115
00116
00117
00118
00119 int numDependChildNodes() const { return m_dependChildNodes.count(); }
00121 virtual void addDependChildNode( Node *node, Relation::Type p=Relation::FinishStart);
00123 virtual void addDependChildNode( Node *node, Relation::Type p, Duration lag);
00125 virtual bool addDependChildNode( Relation *relation);
00127 virtual void insertDependChildNode( unsigned int index, Node *node, Relation::Type p=Relation::FinishStart);
00128 void delDependChildNode( Node *node, bool remove=false);
00129 void delDependChildNode( Relation *rel, bool remove=false);
00130 void delDependChildNode( int number, bool remove=false);
00131 Relation *getDependChildNode( int number) {
00132 return m_dependChildNodes.at(number);
00133 }
00134 QPtrList<Relation> &dependChildNodes() { return m_dependChildNodes; }
00135
00140 void takeDependChildNode(Relation *rel);
00141
00142 int numDependParentNodes() const { return m_dependParentNodes.count(); }
00144 virtual void addDependParentNode(Node *node, Relation::Type p=Relation::FinishStart);
00146 virtual void addDependParentNode( Node *node, Relation::Type p, Duration lag);
00148 virtual bool addDependParentNode( Relation *relation);
00150 virtual void insertDependParentNode( unsigned int index, Node *node, Relation::Type p=Relation::FinishStart);
00151 void delDependParentNode( Node *node, bool remove=false);
00152 void delDependParentNode( Relation *rel, bool remove=false);
00153 void delDependParentNode( int number, bool remove=false);
00154 Relation *getDependParentNode( int number) {
00155 return m_dependParentNodes.at(number);
00156 }
00157 QPtrList<Relation> &dependParentNodes() { return m_dependParentNodes; }
00158
00163 void takeDependParentNode(Relation *rel);
00164
00165 bool isParentOf(Node *node);
00166 bool isDependChildOf(Node *node);
00167
00168 Relation *findParentRelation(Node *node);
00169 Relation *findChildRelation(Node *node);
00170 Relation *findRelation(Node *node);
00171
00172 void setStartTime(DateTime startTime);
00174 virtual DateTime startTime() const
00175 { return m_currentSchedule ? m_currentSchedule->startTime : DateTime(); }
00176 const QDate &startDate() const { return m_dateOnlyStartDate; }
00177 void setEndTime(DateTime endTime);
00179 virtual DateTime endTime() const
00180 { return m_currentSchedule ? m_currentSchedule->endTime : DateTime(); }
00181 const QDate &endDate() const { return m_dateOnlyEndDate; }
00182
00183 void setEffort(Effort* e) { m_effort = e; }
00184 Effort* effort() const { return m_effort; }
00185
00189 virtual Duration *getExpectedDuration() = 0;
00190
00196 virtual Duration *getRandomDuration() = 0;
00197
00202 Duration *getDelay();
00203
00209 DateTime getEarliestStart() const
00210 { return m_currentSchedule ? m_currentSchedule->earliestStart : DateTime(); }
00215 void setEarliestStart(const DateTime &dt)
00216 { if (m_currentSchedule) m_currentSchedule->earliestStart = dt; }
00221 DateTime getLatestFinish() const
00222 { return m_currentSchedule ? m_currentSchedule->latestFinish : DateTime(); }
00228 void setLatestFinish(const DateTime &dt)
00229 { if (m_currentSchedule) m_currentSchedule->latestFinish = dt; }
00230
00231 QString &name() { return m_name; }
00232 QString &leader() { return m_leader; }
00233 QString &description() { return m_description; }
00234 const QString &name() const { return m_name; }
00235 const QString &leader() const { return m_leader; }
00236 const QString &description() const { return m_description; }
00237 void setName(const QString &n) { m_name = n; }
00238 void setLeader(const QString &l) { m_leader = l; }
00239 void setDescription(const QString &d) { m_description = d; }
00240
00241 virtual void setConstraint(Node::ConstraintType type) { m_constraint = type; }
00242 void setConstraint(QString &type);
00243 int constraint() const { return m_constraint; }
00244 QString constraintToString() const;
00245
00246 virtual void setConstraintStartTime(QDateTime time) { m_constraintStartTime = time; }
00247 virtual void setConstraintEndTime(QDateTime time) { m_constraintEndTime = time; }
00248
00249 virtual DateTime constraintStartTime() const { return m_constraintStartTime; }
00250 virtual DateTime constraintEndTime() const { return m_constraintEndTime; }
00251 virtual DateTime startNotEarlier() const { return m_constraintStartTime; }
00252 virtual DateTime finishNotLater() const { return m_constraintEndTime; }
00253 virtual DateTime mustStartOn() const { return m_constraintStartTime; }
00254 virtual DateTime mustFinishOn() const { return m_constraintEndTime; }
00255
00256 virtual ResourceGroupRequest *resourceRequest(ResourceGroup *) const { return 0; }
00257 virtual void makeAppointments();
00258
00260 bool resourceError() const
00261 { return m_currentSchedule ? m_currentSchedule->resourceError : false; }
00263 virtual bool resourceOverbooked() const
00264 { return m_currentSchedule ? m_currentSchedule->resourceOverbooked : false; }
00266 virtual QStringList overbookedResources() const;
00269 virtual void calcResourceOverbooked();
00271 bool resourceNotAvailable() const
00272 { return m_currentSchedule ? m_currentSchedule->resourceNotAvailable : false; }
00274 virtual bool schedulingError() const
00275 { return m_currentSchedule ? m_currentSchedule->schedulingError : false; }
00277 bool notScheduled() const
00278 { return m_currentSchedule == 0 || m_currentSchedule->isDeleted() || m_currentSchedule->notScheduled; }
00279
00280 virtual EffortCostMap plannedEffortCostPrDay(const QDate &start, const QDate &end) const=0;
00281
00283 virtual Duration plannedEffort() { return Duration::zeroDuration; }
00285 virtual Duration plannedEffort(const QDate &) { return Duration::zeroDuration; }
00287 virtual Duration plannedEffortTo(const QDate &) { return Duration::zeroDuration; }
00288
00290 virtual Duration actualEffort() { return Duration::zeroDuration; }
00292 virtual Duration actualEffort(const QDate &) { return Duration::zeroDuration; }
00294 virtual Duration actualEffortTo(const QDate &) { return Duration::zeroDuration; }
00295
00300 virtual double plannedCost() { return 0; }
00301
00303 virtual double plannedCost(const QDate &) { return 0; }
00308 virtual double plannedCostTo(const QDate &) { return 0; }
00313 virtual double actualCost() { return 0; }
00315 virtual double actualCost(const QDate &) { return 0; }
00317 virtual double actualCostTo(const QDate &) { return 0; }
00318
00320 double effortPerformanceIndex(const QDate &, bool *) { return 0.0; }
00322 double costPerformanceIndex(const QDate &, bool *) { return 0.0; }
00323
00324 virtual void initiateCalculationLists(QPtrList<Node> &startnodes, QPtrList<Node> &endnodes, QPtrList<Node> &summarytasks) = 0;
00325 virtual DateTime calculateForward(int ) = 0;
00326 virtual DateTime calculateBackward(int ) = 0;
00327 virtual DateTime scheduleForward(const DateTime &, int ) = 0;
00328 virtual DateTime scheduleBackward(const DateTime &, int ) = 0;
00329 virtual void adjustSummarytask() = 0;
00330
00331 virtual void initiateCalculation(Schedule &sch);
00332 virtual void resetVisited();
00333 void propagateEarliestStart(DateTime &time);
00334 void propagateLatestFinish(DateTime &time);
00335 void moveEarliestStart(DateTime &time);
00336 void moveLatestFinish(DateTime &time);
00337
00338 virtual Duration summarytaskDurationForward(const DateTime &)
00339 { return Duration::zeroDuration; }
00340
00341 virtual DateTime summarytaskEarliestStart()
00342 { return DateTime(); }
00343
00344 virtual Duration summarytaskDurationBackward(const DateTime &)
00345 { return Duration::zeroDuration; }
00346
00347 virtual DateTime summarytaskLatestFinish()
00348 { return DateTime(); }
00349
00350 const Duration &duration()
00351 { return m_currentSchedule ? m_currentSchedule->duration : Duration::zeroDuration; }
00360 Duration duration(const DateTime &time, int use, bool backward);
00361
00362 virtual Duration calcDuration(const DateTime &, const Duration &, bool ) { return Duration::zeroDuration;}
00363
00364 Node *siblingBefore();
00365 Node *childBefore(Node *node);
00366 Node *siblingAfter();
00367 Node *childAfter(Node *node);
00368 bool moveChildUp(Node *node);
00369 bool moveChildDown(Node *node);
00370
00372 bool legalToLink(Node *node);
00374 virtual bool legalToLink(Node *, Node *) { return false; }
00376 virtual bool isEndNode() const;
00378 virtual bool isStartNode() const;
00379 virtual void clearProxyRelations() {}
00380 virtual void addParentProxyRelations(QPtrList<Relation> &) {}
00381 virtual void addChildProxyRelations(QPtrList<Relation> &) {}
00382 virtual void addParentProxyRelation(Node *, const Relation *) {}
00383 virtual void addChildProxyRelation(Node *, const Relation *) {}
00384
00386 virtual void saveAppointments(QDomElement &element, long id) const;
00388 QPtrList<Appointment> appointments();
00390
00392 virtual bool addAppointment(Appointment *appointment);
00394 virtual bool addAppointment(Appointment *appointment, Schedule &main);
00396 virtual void addAppointment(ResourceSchedule *resource, DateTime &start, DateTime &end, double load=100);
00397
00399 virtual Node *findNode() const { return findNode(m_id); }
00401 virtual Node *findNode(const QString &id) const
00402 { return (m_parent ? m_parent->findNode(id) : 0); }
00404 virtual bool removeId() { return removeId(m_id); }
00406 virtual bool removeId(const QString &id)
00407 { return (m_parent ? m_parent->removeId(id) : false); }
00409 virtual void insertId(const QString &id) { insertId(id, this); }
00411 virtual void insertId(const QString &id, const Node *node)
00412 { if (m_parent) m_parent->insertId(id, node); }
00413
00419 virtual DateTime workStartTime() const
00420 { return m_currentSchedule ? m_currentSchedule->workStartTime : DateTime(); }
00421 void setWorkStartTime(const DateTime &dt)
00422 { if (m_currentSchedule) m_currentSchedule->workStartTime = dt; }
00423
00429 virtual DateTime workEndTime() const
00430 { return m_currentSchedule ? m_currentSchedule->workEndTime : DateTime(); }
00431 void setWorkEndTime(const DateTime &dt)
00432 { if (m_currentSchedule) m_currentSchedule->workEndTime = dt; }
00433
00434 virtual bool isCritical() const { return false; }
00435 virtual bool inCriticalPath() const
00436 { return m_currentSchedule ? m_currentSchedule->inCriticalPath : false; }
00437 virtual bool calcCriticalPath(bool fromEnd);
00438
00440 virtual int level();
00442 virtual void generateWBS(int count, WBSDefinition &def, QString wbs=QString());
00443 QString wbs() const { return m_wbs; }
00444
00445 double startupCost() const { return m_startupCost; }
00446 void setStartupCost(double cost) { m_startupCost = cost; }
00447
00448 Account *startupAccount() const { return m_startupAccount; }
00449 void setStartupAccount(Account *acc) { m_startupAccount = acc; }
00450
00451 double shutdownCost() const { return m_shutdownCost; }
00452 void setShutdownCost(double cost) { m_shutdownCost = cost; }
00453
00454 Account *shutdownAccount() const { return m_shutdownAccount; }
00455 void setShutdownAccount(Account *acc) { m_shutdownAccount = acc; }
00456
00457 Account *runningAccount() const { return m_runningAccount; }
00458 void setRunningAccount(Account *acc) { m_runningAccount = acc; }
00459
00460 Schedule *currentSchedule() const { return m_currentSchedule; }
00462 virtual void setCurrentSchedule(long id);
00463
00464 void setCurrentSchedulePtr(Schedule *schedule) { m_currentSchedule = schedule; }
00465
00466 QIntDict<Schedule> &schedules() { return m_schedules; }
00468 Schedule *findSchedule(const QString name, const Schedule::Type type) const;
00470 Schedule *findSchedule(const Schedule::Type type) const;
00472 Schedule *findSchedule(long id) const { return m_schedules[id]; }
00474 void takeSchedule(const Schedule *schedule);
00476 void addSchedule(Schedule *schedule);
00478 Schedule *createSchedule(QString name, Schedule::Type type, long id);
00480 Schedule *createSchedule(Schedule *parent);
00481
00483 void setScheduleDeleted(long id, bool onoff);
00485 virtual void setParentSchedule(Schedule *sch);
00486
00487 DateTime startTime()
00488 { return m_currentSchedule ? m_currentSchedule->startTime : DateTime(); }
00489 DateTime endTime()
00490 { return m_currentSchedule ? m_currentSchedule->endTime : DateTime(); }
00491
00492 protected:
00493 QPtrList<Node> m_nodes;
00494 QPtrList<Relation> m_dependChildNodes;
00495 QPtrList<Relation> m_dependParentNodes;
00496 Node *m_parent;
00497
00498 QString m_id;
00499 QString m_name;
00500 QString m_leader;
00501 QString m_description;
00502
00503 Effort* m_effort;
00504
00505
00506 ConstraintType m_constraint;
00507
00512 DateTime m_constraintStartTime;
00517 DateTime m_constraintEndTime;
00518
00519 bool m_visitedForward;
00520 bool m_visitedBackward;
00521 Duration m_durationForward;
00522 Duration m_durationBackward;
00523
00524 QDate m_dateOnlyStartDate;
00525 QDate m_dateOnlyEndDate;
00526 Duration m_dateOnlyDuration;
00527
00528 QIntDict<Schedule> m_schedules;
00529 Schedule *m_currentSchedule;
00530
00531 QString m_wbs;
00532
00533 double m_startupCost;
00534 Account *m_startupAccount;
00535 double m_shutdownCost;
00536 Account *m_shutdownAccount;
00537 Account *m_runningAccount;
00538
00539 private:
00540 void init();
00541
00542 #ifndef NDEBUG
00543 public:
00544 virtual void printDebug(bool children, QCString indent);
00545 #endif
00546
00547 };
00548
00550
00556 class Effort {
00557 public:
00558 Effort ( Duration e = Duration::zeroDuration, Duration p = Duration::zeroDuration,
00559 Duration o = Duration::zeroDuration );
00560
00561 Effort ( double e, double p = 0, double o = 0);
00562
00563 Effort (const Effort &effort);
00564 ~Effort();
00565
00566 enum Type { Type_Effort = 0,
00567 Type_FixedDuration = 1
00568 };
00569 Type type() const { return m_type; }
00570 void setType(Type type) { m_type = type; }
00571 void setType(QString type);
00572 QString typeToString() const;
00573
00574 enum Risktype { Risk_None, Risk_Low, Risk_High };
00575 Risktype risktype() const { return m_risktype; }
00576 void setRisktype(Risktype type) { m_risktype = type; }
00577 void setRisktype(QString type);
00578 QString risktypeToString() const;
00579
00580 enum Use { Use_Expected=0, Use_Optimistic=1, Use_Pessimistic=2 };
00581 Duration effort(int use) const;
00582 const Duration& optimistic() const {return m_optimisticEffort;}
00583 const Duration& pessimistic() const {return m_pessimisticEffort;}
00584 const Duration& expected() const {return m_expectedEffort;}
00585
00586 void set( Duration e, Duration p = Duration::zeroDuration, Duration o = Duration::zeroDuration );
00587 void set( int e, int p = -1, int o = -1 );
00588 void set(unsigned days, unsigned hours, unsigned minutes);
00589 void expectedEffort(unsigned *days, unsigned *hours, unsigned *minutes);
00590
00591 bool load(QDomElement &element);
00592 void save(QDomElement &element) const;
00593
00598 void setOptimisticRatio(int percent);
00603 int optimisticRatio() const;
00608 void setPessimisticRatio(int percent);
00613 int pessimisticRatio() const;
00614
00618 static const Effort zeroEffort;
00619
00620 Duration variance() const;
00621 Duration pertExpected() const;
00622 Duration pertOptimistic() const;
00623 Duration pertPessimistic() const;
00624
00625 private:
00626 Duration m_optimisticEffort;
00627 Duration m_pessimisticEffort;
00628 Duration m_expectedEffort;
00629
00630 Type m_type;
00631 Risktype m_risktype;
00632
00633 #ifndef NDEBUG
00634 public:
00635 void printDebug(QCString indent);
00636 #endif
00637
00638 };
00639
00640 }
00641
00642 #endif