kplato

kptschedule.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2005 Dag Andersen <danders@get2net.dk>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation;
00007    version 2 of the License.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017    Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #ifndef KPTSCHEDULE_H
00021 #define KPTSCHEDULE_H
00022 
00023 #include "kpteffortcostmap.h"
00024 #include "kptresource.h"
00025 
00026 #include <qintdict.h>
00027 #include <qptrlist.h>
00028 #include <qstring.h>
00029 
00030 class QDomElement;
00031 
00032 namespace KPlato
00033 {
00034 
00035 class Appointment;
00036 class DateTime;
00037 class Duration;
00038 class Node;
00039 class Task;
00040 
00053 class Schedule
00054 {
00055 public:
00056     //NOTE: Must match Effort::Use atm.
00057     enum Type { Expected=0, //Effort::Use_Expected
00058                 Optimistic=1, //Effort::Use_Optimistic
00059                 Pessimistic=2 //Effort::Use_Pessimistic
00060     };
00061     
00062     Schedule();
00063     Schedule(Schedule *parent);
00064     Schedule(QString name, Type type, long id);
00065     ~Schedule();
00066     
00067     QString name() const { return m_name; }
00068     void setName(QString name) { m_name = name; }
00069     Type type() const { return m_type; }
00070     void setType(Type type) { m_type = type; }
00071     void setType(QString type);
00072     QString typeToString(bool translate=false) const;
00073     long id() const { return m_id; }
00074     void setId(long id) { m_id = id; }
00075     void setParent(Schedule *parent);
00076     Schedule *parent() const { return m_parent; }
00077     virtual bool isDeleted() const;
00078     virtual void setDeleted(bool on);
00079     
00080     virtual Resource *resource() const { return 0; }
00081     virtual Node *node() const { return 0; }
00082     
00083     virtual bool loadXML(const QDomElement &element);
00084     virtual void saveXML(QDomElement &element) const;
00085     void saveCommonXML(QDomElement &element) const;
00086     void saveAppointments(QDomElement &element) const;
00087     
00089     QPtrList<Appointment> &appointments() { return m_appointments; }
00091     virtual bool add(Appointment *appointment);
00093     virtual void addAppointment(Schedule */*other*/, DateTime &/*start*/, DateTime &/*end*/, double /*load*/=100) {}
00095     void removeAppointment(Appointment *appointment);
00097     void takeAppointment(Appointment *appointment);
00098     Appointment *findAppointment(Schedule *resource, Schedule *node);
00099     
00100     Appointment appointmentIntervals() const;
00101     
00102     virtual bool isOverbooked() const { return false; }
00103     virtual bool isOverbooked(const DateTime &/*start*/, const DateTime &/*end*/) const { return false; }
00104 
00105     virtual EffortCostMap plannedEffortCostPrDay(const QDate &start, const QDate &end) const;
00106         
00108     virtual Duration plannedEffort() const;
00110     virtual Duration plannedEffort(const QDate &date) const;
00112     virtual Duration plannedEffortTo(const QDate &date) const;
00113     
00115     virtual Duration actualEffort() const;
00117     virtual Duration actualEffort(const QDate &date) const;
00119     virtual Duration actualEffortTo(const QDate &date) const;
00120     
00125     virtual double plannedCost() const; 
00126     
00128     virtual double plannedCost(const QDate &date) const;
00133     virtual double plannedCostTo(const QDate &date) const;
00138     virtual double actualCost() const;
00140     virtual double actualCost(const QDate &date) const;
00142     virtual double actualCostTo(const QDate &date) const;
00143     
00145     double effortPerformanceIndex(const QDate &/*date*/, bool */*error=0*/) { return 0.0; }
00147     double costPerformanceIndex(const QDate &/*date*/, bool */*error=0*/) { return 0.0; }
00148 
00149     virtual double normalRatePrHour() const { return 0.0; }
00150 
00151     void setEarliestStart(DateTime &dt) { earliestStart = dt; }
00152     void setLatestFinish(DateTime &dt) { latestFinish = dt; }
00153 
00154     virtual void initiateCalculation();
00155     virtual void calcResourceOverbooked();
00156 
00157     void setScheduled(bool on) { notScheduled = !on; }
00158     bool isScheduled() const { return !notScheduled; }
00159     
00160     DateTime start() const { return startTime; }
00161     DateTime end() const { return endTime; }
00162     
00163 protected:
00164     QString m_name;
00165     Type m_type;
00166     long m_id;
00167     bool m_deleted;
00168 
00169     QPtrList<Appointment> m_appointments;
00170     Schedule *m_parent;
00171     
00172     friend class Node;
00173     friend class Task;
00174     friend class Project;
00175     friend class Resource;
00181     DateTime earliestStart;
00187     DateTime latestFinish;
00192     DateTime startTime;
00198     DateTime endTime;
00203     Duration duration;
00204 
00206     bool resourceError;
00208     bool resourceOverbooked;
00210     bool resourceNotAvailable;
00212     bool schedulingError;
00214     bool notScheduled;
00215 
00216     DateTime workStartTime;
00217     DateTime workEndTime;
00218     bool inCriticalPath;
00219 
00220 
00221 #ifndef NDEBUG
00222 public:
00223     virtual void printDebug(QString ident);
00224 #endif
00225 };
00226 
00231 class NodeSchedule : public Schedule
00232 {
00233 public:
00234     NodeSchedule();
00235     NodeSchedule(Node *node, QString name, Schedule::Type type, long id);
00236     NodeSchedule(Schedule *parent, Node *node);
00237     ~NodeSchedule();
00238     
00239     virtual bool isDeleted() const 
00240         { return m_parent == 0 ? true : m_parent->isDeleted(); }
00241     void setDeleted(bool on);
00242     
00243     virtual bool loadXML(const QDomElement &element);
00244     virtual void saveXML(QDomElement &element) const;
00245 
00246 // tasks------------>
00247     virtual void addAppointment(Schedule *resource, DateTime &start, DateTime &end, double load=100);
00248     
00249     virtual Node *node() const { return m_node; }
00250     virtual void setNode(Node *n) { m_node = n; }
00251     
00252 protected:
00253     void init();
00254 
00255 private:
00256     Node *m_node;
00257     
00258 #ifndef NDEBUG
00259 public:
00260     virtual void printDebug(QString ident);
00261 #endif
00262 };
00263 
00268 class ResourceSchedule : public Schedule
00269 {
00270 public:
00271     ResourceSchedule();
00272     ResourceSchedule(Resource *Resource, QString name, Schedule::Type type, long id);
00273     ResourceSchedule(Schedule *parent, Resource *Resource);
00274     ~ResourceSchedule();
00275     
00276     virtual bool isDeleted() const 
00277         { return m_parent == 0 ? true : m_parent->isDeleted(); }
00278     virtual void addAppointment(Schedule *node, DateTime &start, DateTime &end, double load=100);
00279     
00280     virtual bool isOverbooked() const;
00281     virtual bool isOverbooked(const DateTime &start, const DateTime &end) const;
00282     Appointment appointmentIntervals() const;
00283     
00284     virtual Resource *resource() const { return m_resource; }
00285     virtual double normalRatePrHour() const;
00286     
00287 private:
00288     Resource *m_resource;
00289     Schedule *m_parent;
00290 
00291 #ifndef NDEBUG
00292 public:
00293     virtual void printDebug(QString ident);
00294 #endif
00295 };
00296 
00301 class MainSchedule : public NodeSchedule
00302 {
00303 public:
00304     MainSchedule();
00305     MainSchedule(Node *node, QString name, Schedule::Type type, long id);
00306     ~MainSchedule();
00307     virtual bool isDeleted() const { return m_deleted; }
00308 
00309     virtual bool loadXML(const QDomElement &element, Project &project);
00310     virtual void saveXML(QDomElement &element) const;
00311 
00312 private:
00313 
00314 #ifndef NDEBUG
00315 public:
00316     virtual void printDebug(QString ident);
00317 #endif
00318 };
00319 
00320 
00321 } //namespace KPlato
00322 
00323 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys