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 <QObject>
00030 #include <QHash>
00031 #include <QRect>
00032 #include <QString>
00033
00034 class QDomElement;
00035
00036 namespace KPlato
00037 {
00038
00039 class Account;
00040 class Project;
00041 class Appointment;
00042 class ResourceGroup;
00043 class Resource;
00044 class ResourceGroupRequest;
00045 class Effort;
00046 class WBSDefinition;
00047 class EffortCostMap;
00048
00054 class Node : public QObject
00055 {
00056 Q_OBJECT
00057 public:
00058 enum ConstraintType { ASAP, ALAP, MustStartOn, MustFinishOn, StartNotEarlier, FinishNotLater, FixedInterval };
00059
00060 Node(Node *parent = 0);
00061 Node(Node &node, Node *parent = 0);
00062
00063
00064
00065 virtual ~Node() = 0;
00066
00067 bool setId(QString id);
00068 QString id() const { return m_id; }
00069
00070 enum NodeTypes {
00071 Type_Node = 0,
00072 Type_Project = 1,
00073 Type_Subproject = 2,
00074 Type_Task = 3,
00075 Type_Milestone = 4,
00076 Type_Periodic = 5,
00077 Type_Summarytask = 6
00078 };
00079
00080 virtual int type() const = 0;
00081
00082 QString typeToString( bool trans = false ) const;
00087 virtual Node *projectNode();
00088
00089
00090 virtual bool load(QDomElement &) { return true; }
00091 virtual bool load(QDomElement &, Project &) { return true; }
00092 virtual void save(QDomElement &element) const = 0;
00094 virtual void saveRelations(QDomElement &element) const;
00095
00096
00097
00098
00099
00100 Node *getParent() const { return m_parent; }
00101 void setParent( Node* newParent ) { m_parent = newParent;}
00102 const QList<Node*> &childNodeIterator() const { return m_nodes; }
00103 int numChildren() const { return m_nodes.count(); }
00104 virtual void addChildNode(Node *node, Node *after=0);
00105 virtual void insertChildNode(unsigned int index, Node *node);
00106 void takeChildNode(Node *node );
00107 void takeChildNode(int number );
00108 Node* childNode(int number) { return m_nodes.at(number); }
00109 const Node* childNode(int number) const;
00110 int findChildNode( Node* node );
00111 bool isChildOf( 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);
00131 void takeDependChildNode( Relation *rel );
00132 Relation *getDependChildNode( int number ) {
00133 return m_dependChildNodes.at(number);
00134 }
00135 QList<Relation*> &dependChildNodes() { return m_dependChildNodes; }
00136
00137 int numDependParentNodes() const { return m_dependParentNodes.count(); }
00139 virtual void addDependParentNode(Node *node, Relation::Type p=Relation::FinishStart);
00141 virtual void addDependParentNode( Node *node, Relation::Type p, Duration lag);
00143 virtual bool addDependParentNode( Relation *relation);
00145 virtual void insertDependParentNode( unsigned int index, Node *node, Relation::Type p=Relation::FinishStart);
00149 void takeDependParentNode( Relation *rel );
00150 Relation *getDependParentNode( int number ) {
00151 return m_dependParentNodes.at(number);
00152 }
00153 QList<Relation*> &dependParentNodes() { return m_dependParentNodes; }
00154
00155 bool isParentOf(Node *node);
00156 bool isDependChildOf(Node *node);
00157
00158 Relation *findParentRelation(Node *node);
00159 Relation *findChildRelation(Node *node);
00160 Relation *findRelation(Node *node);
00161
00162 void setStartTime(DateTime startTime);
00164 virtual DateTime startTime() const
00165 { return m_currentSchedule ? m_currentSchedule->startTime : DateTime(); }
00166 const QDate &startDate() const { return m_dateOnlyStartDate; }
00167 void setEndTime(DateTime endTime);
00169 virtual DateTime endTime() const
00170 { return m_currentSchedule ? m_currentSchedule->endTime : DateTime(); }
00171 const QDate &endDate() const { return m_dateOnlyEndDate; }
00172
00173 void setEffort(Effort* e) { m_effort = e; }
00174 Effort* effort() const { return m_effort; }
00175
00179 virtual Duration *getExpectedDuration() = 0;
00180
00186 virtual Duration *getRandomDuration() = 0;
00187
00192 Duration *getDelay();
00193
00199 DateTime getEarliestStart() const
00200 { return m_currentSchedule ? m_currentSchedule->earliestStart : DateTime(); }
00205 void setEarliestStart(const DateTime &dt)
00206 { if (m_currentSchedule) m_currentSchedule->earliestStart = dt; }
00211 DateTime getLatestFinish() const
00212 { return m_currentSchedule ? m_currentSchedule->latestFinish : DateTime(); }
00218 void setLatestFinish(const DateTime &dt)
00219 { if (m_currentSchedule) m_currentSchedule->latestFinish = dt; }
00220
00221 QString &name() { return m_name; }
00222 QString &leader() { return m_leader; }
00223 QString &description() { return m_description; }
00224 const QString &name() const { return m_name; }
00225 const QString &leader() const { return m_leader; }
00226 const QString &description() const { return m_description; }
00227 void setName(const QString &n);
00228 void setLeader(const QString &l);
00229 void setDescription(const QString &d);
00230
00231 void setConstraint(Node::ConstraintType type);
00232 void setConstraint(QString &type);
00233 int constraint() const { return m_constraint; }
00234 QString constraintToString( bool trans=false ) const;
00235 static QStringList constraintList( bool trans );
00236
00237 virtual void setConstraintStartTime(QDateTime time)
00238 { m_constraintStartTime = time; changed( this ); }
00239 virtual void setConstraintEndTime(QDateTime time)
00240 { m_constraintEndTime = time; changed( this ); }
00241
00242 virtual DateTime constraintStartTime() const { return m_constraintStartTime; }
00243 virtual DateTime constraintEndTime() const { return m_constraintEndTime; }
00244 virtual DateTime startNotEarlier() const { return m_constraintStartTime; }
00245 virtual DateTime finishNotLater() const { return m_constraintEndTime; }
00246 virtual DateTime mustStartOn() const { return m_constraintStartTime; }
00247 virtual DateTime mustFinishOn() const { return m_constraintEndTime; }
00248
00249 virtual ResourceGroupRequest *resourceRequest(ResourceGroup *) const { return 0; }
00250 virtual void makeAppointments();
00251
00253 bool resourceError() const
00254 { return m_currentSchedule ? m_currentSchedule->resourceError : false; }
00256 virtual bool resourceOverbooked() const
00257 { return m_currentSchedule ? m_currentSchedule->resourceOverbooked : false; }
00260 virtual void calcResourceOverbooked();
00262 bool resourceNotAvailable() const
00263 { return m_currentSchedule ? m_currentSchedule->resourceNotAvailable : false; }
00265 virtual bool schedulingError() const
00266 { return m_currentSchedule ? m_currentSchedule->schedulingError : false; }
00268 bool notScheduled() const
00269 { return m_currentSchedule == 0 || m_currentSchedule->isDeleted() || m_currentSchedule->notScheduled; }
00271 virtual QStringList overbookedResources() const;
00272
00273 virtual EffortCostMap plannedEffortCostPrDay(const QDate &start, const QDate &end) const=0;
00274
00276 virtual Duration plannedEffort() { return Duration::zeroDuration; }
00278 virtual Duration plannedEffort(const QDate &) { return Duration::zeroDuration; }
00280 virtual Duration plannedEffortTo(const QDate &) { return Duration::zeroDuration; }
00281
00283 virtual Duration actualEffort() { return Duration::zeroDuration; }
00285 virtual Duration actualEffort(const QDate &) { return Duration::zeroDuration; }
00287 virtual Duration actualEffortTo(const QDate &) { return Duration::zeroDuration; }
00288
00293 virtual double plannedCost() { return 0; }
00294
00296 virtual double plannedCost(const QDate &) { return 0; }
00301 virtual double plannedCostTo(const QDate &) { return 0; }
00306 virtual double actualCost() { return 0; }
00308 virtual double actualCost(const QDate &) { return 0; }
00310 virtual double actualCostTo(const QDate &) { return 0; }
00311
00313 double effortPerformanceIndex(const QDate &, bool *) { return 0.0; }
00315 double costPerformanceIndex(const QDate &, bool *) { return 0.0; }
00316
00317 virtual void initiateCalculationLists(QList<Node*> &startnodes, QList<Node*> &endnodes, QList<Node*> &summarytasks) = 0;
00318 virtual DateTime calculateForward(int ) = 0;
00319 virtual DateTime calculateBackward(int ) = 0;
00320 virtual DateTime scheduleForward(const DateTime &, int ) = 0;
00321 virtual DateTime scheduleBackward(const DateTime &, int ) = 0;
00322 virtual void adjustSummarytask() = 0;
00323
00324 virtual void initiateCalculation(Schedule &sch);
00325 virtual void resetVisited();
00326 void propagateEarliestStart(DateTime &time);
00327 void propagateLatestFinish(DateTime &time);
00328 void moveEarliestStart(DateTime &time);
00329 void moveLatestFinish(DateTime &time);
00330
00331 virtual Duration summarytaskDurationForward(const DateTime &)
00332 { return Duration::zeroDuration; }
00333
00334 virtual DateTime summarytaskEarliestStart()
00335 { return DateTime(); }
00336
00337 virtual Duration summarytaskDurationBackward(const DateTime &)
00338 { return Duration::zeroDuration; }
00339
00340 virtual DateTime summarytaskLatestFinish()
00341 { return DateTime(); }
00342
00343 const Duration &duration()
00344 { return m_currentSchedule ? m_currentSchedule->duration : Duration::zeroDuration; }
00353 Duration duration(const DateTime &time, int use, bool backward);
00354
00355 virtual Duration calcDuration(const DateTime &, const Duration &, bool ) { return Duration::zeroDuration;}
00356
00357 Node *siblingBefore();
00358 Node *childBefore(Node *node);
00359 Node *siblingAfter();
00360 Node *childAfter(Node *node);
00361 bool moveChildUp(Node *node);
00362 bool moveChildDown(Node *node);
00363
00365 bool legalToLink(Node *node);
00367 virtual bool legalToLink(Node *, Node *) { return false; }
00369 virtual bool isEndNode() const;
00371 virtual bool isStartNode() const;
00372 virtual void clearProxyRelations() {}
00373 virtual void addParentProxyRelations(QList<Relation*> &) {}
00374 virtual void addChildProxyRelations(QList<Relation*> &) {}
00375 virtual void addParentProxyRelation(Node *, const Relation *) {}
00376 virtual void addChildProxyRelation(Node *, const Relation *) {}
00377
00379 virtual void saveAppointments(QDomElement &element, long id) const;
00381 QList<Appointment*> appointments();
00383
00385 virtual bool addAppointment(Appointment *appointment);
00387 virtual bool addAppointment(Appointment *appointment, Schedule &main);
00389 virtual void addAppointment(ResourceSchedule *resource, DateTime &start, DateTime &end, double load=100);
00390
00392 virtual Node *findNode() const { return findNode(m_id); }
00394 virtual Node *findNode(const QString &id) const
00395 { return (m_parent ? m_parent->findNode(id) : 0); }
00397 virtual bool removeId() { return removeId(m_id); }
00399 virtual bool removeId(const QString &id)
00400 { return (m_parent ? m_parent->removeId(id) : false); }
00402 virtual void insertId(const QString &id) { insertId(id, this); }
00404 virtual void insertId(const QString &id, Node *node)
00405 { if (m_parent) m_parent->insertId(id, node); }
00406
00412 virtual DateTime workStartTime() const
00413 { return m_currentSchedule ? m_currentSchedule->workStartTime : DateTime(); }
00414 void setWorkStartTime(const DateTime &dt)
00415 { if (m_currentSchedule) m_currentSchedule->workStartTime = dt; }
00416
00422 virtual DateTime workEndTime() const
00423 { return m_currentSchedule ? m_currentSchedule->workEndTime : DateTime(); }
00424 void setWorkEndTime(const DateTime &dt)
00425 { if (m_currentSchedule) m_currentSchedule->workEndTime = dt; }
00426
00427 virtual bool isCritical() const { return false; }
00428 virtual bool inCriticalPath() const
00429 { return m_currentSchedule ? m_currentSchedule->inCriticalPath : false; }
00430 virtual bool calcCriticalPath(bool fromEnd);
00431
00433 virtual int level();
00435 virtual void generateWBS(int count, WBSDefinition &def, QString wbs=QString());
00436 QString wbs() const { return m_wbs; }
00437
00438 double startupCost() const { return m_startupCost; }
00439 void setStartupCost(double cost) { m_startupCost = cost; }
00440
00441 Account *startupAccount() const { return m_startupAccount; }
00442 void setStartupAccount(Account *acc) { m_startupAccount = acc; }
00443
00444 double shutdownCost() const { return m_shutdownCost; }
00445 void setShutdownCost(double cost) { m_shutdownCost = cost; }
00446
00447 Account *shutdownAccount() const { return m_shutdownAccount; }
00448 void setShutdownAccount(Account *acc) { m_shutdownAccount = acc; }
00449
00450 Account *runningAccount() const { return m_runningAccount; }
00451 void setRunningAccount(Account *acc) { m_runningAccount = acc; }
00452
00453 Schedule *currentSchedule() const { return m_currentSchedule; }
00455 virtual void setCurrentSchedule(long id);
00456
00457 void setCurrentSchedulePtr(Schedule *schedule) { m_currentSchedule = schedule; }
00458
00459 QHash<long, Schedule*> &schedules() { return m_schedules; }
00461 Schedule *findSchedule(const QString name, const Schedule::Type type);
00463 Schedule *findSchedule(const Schedule::Type type);
00465 Schedule *findSchedule(long id) const {
00466 return m_schedules.contains(id) ? m_schedules[id] : 0;
00467 }
00469 void takeSchedule(const Schedule *schedule);
00471 void addSchedule(Schedule *schedule);
00473 Schedule *createSchedule(QString name, Schedule::Type type, long id);
00475 Schedule *createSchedule(Schedule *parent);
00476
00478 void setScheduleDeleted(long id, bool onoff);
00480 virtual void setParentSchedule(Schedule *sch);
00481
00482 DateTime startTime()
00483 { return m_currentSchedule ? m_currentSchedule->startTime : DateTime(); }
00484 DateTime endTime()
00485 { return m_currentSchedule ? m_currentSchedule->endTime : DateTime(); }
00486
00487 protected:
00488 virtual void changed(Node *node);
00489
00490 QList<Node*> m_nodes;
00491 QList<Relation*> m_dependChildNodes;
00492 QList<Relation*> m_dependParentNodes;
00493 Node *m_parent;
00494
00495 QString m_id;
00496 QString m_name;
00497 QString m_leader;
00498 QString m_description;
00499
00500 Effort* m_effort;
00501
00502
00503 ConstraintType m_constraint;
00504
00509 DateTime m_constraintStartTime;
00514 DateTime m_constraintEndTime;
00515
00516 bool m_visitedForward;
00517 bool m_visitedBackward;
00518 Duration m_durationForward;
00519 Duration m_durationBackward;
00520
00521 QDate m_dateOnlyStartDate;
00522 QDate m_dateOnlyEndDate;
00523 Duration m_dateOnlyDuration;
00524
00525 QHash<long, Schedule*> m_schedules;
00526 Schedule *m_currentSchedule;
00527
00528 QString m_wbs;
00529
00530 double m_startupCost;
00531 Account *m_startupAccount;
00532 double m_shutdownCost;
00533 Account *m_shutdownAccount;
00534 Account *m_runningAccount;
00535
00536 private:
00537 void init();
00538
00539 #ifndef NDEBUG
00540 public:
00541 virtual void printDebug(bool children, QByteArray indent);
00542 #endif
00543
00544 };
00545
00547
00553 class Effort {
00554 public:
00555 Effort ( Duration e = Duration::zeroDuration, Duration p = Duration::zeroDuration,
00556 Duration o = Duration::zeroDuration );
00557
00558 Effort ( double e, double p = 0, double o = 0);
00559
00560 Effort (const Effort &effort);
00561 ~Effort();
00562
00563 enum Type { Type_Effort = 0,
00564 Type_FixedDuration = 1
00565 };
00566 Type type() const { return m_type; }
00567 void setType(Type type) { m_type = type; }
00568 void setType(QString type);
00569 QString typeToString( bool trans=false ) const;
00570 static QStringList typeToStringList( bool trans=false );
00571
00572 enum Risktype { Risk_None, Risk_Low, Risk_High };
00573 Risktype risktype() const { return m_risktype; }
00574 void setRisktype(Risktype type) { m_risktype = type; }
00575 void setRisktype(QString type);
00576 QString risktypeToString( bool trans=false ) const;
00577 static QStringList risktypeToStringList( bool trans=false );
00578
00579 enum Use { Use_Expected=0, Use_Optimistic=1, Use_Pessimistic=2 };
00580 Duration effort(int use) const;
00581 const Duration& optimistic() const {return m_optimisticEffort;}
00582 const Duration& pessimistic() const {return m_pessimisticEffort;}
00583 const Duration& expected() const {return m_expectedEffort;}
00584
00585 void set( Duration e, Duration p = Duration::zeroDuration, Duration o = Duration::zeroDuration );
00586 void set( int e, int p = -1, int o = -1 );
00587 void set(unsigned days, unsigned hours, unsigned minutes);
00588 void expectedEffort(unsigned *days, unsigned *hours, unsigned *minutes);
00589
00590 bool load(QDomElement &element);
00591 void save(QDomElement &element) const;
00592
00597 void setOptimisticRatio(int percent);
00602 int optimisticRatio() const;
00607 void setPessimisticRatio(int percent);
00612 int pessimisticRatio() const;
00613
00617 static const Effort zeroEffort;
00618
00619 Duration variance() const;
00620 Duration pertExpected() const;
00621 Duration pertOptimistic() const;
00622 Duration pertPessimistic() const;
00623
00624 private:
00625 Duration m_optimisticEffort;
00626 Duration m_pessimisticEffort;
00627 Duration m_expectedEffort;
00628
00629 Type m_type;
00630 Risktype m_risktype;
00631
00632 #ifndef NDEBUG
00633 public:
00634 void printDebug(QByteArray indent);
00635 #endif
00636
00637 };
00638
00639 }
00640
00641 #endif