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 class QStringList;
00032 
00033 namespace KPlato
00034 {
00035 
00036 class Appointment;
00037 class DateTime;
00038 class Duration;
00039 class Node;
00040 class Task;
00041 
00054 class Schedule
00055 {
00056 public:
00057     //NOTE: Must match Effort::Use atm.
00058     enum Type { Expected=0, //Effort::Use_Expected
00059                 Optimistic=1, //Effort::Use_Optimistic
00060                 Pessimistic=2 //Effort::Use_Pessimistic
00061     };
00062     
00063     Schedule();
00064     Schedule(Schedule *parent);
00065     Schedule(QString name, Type type, long id);
00066     ~Schedule();
00067     
00068     QString name() const { return m_name; }
00069     void setName(QString name) { m_name = name; }
00070     Type type() const { return m_type; }
00071     void setType(Type type) { m_type = type; }
00072     void setType(QString type);
00073     QString typeToString(bool translate=false) const;
00074     long id() const { return m_id; }
00075     void setId(long id) { m_id = id; }
00076     void setParent(Schedule *parent);
00077     Schedule *parent() const { return m_parent; }
00078     virtual bool isDeleted() const;
00079     virtual void setDeleted(bool on);
00080     
00081     virtual Resource *resource() const { return 0; }
00082     virtual Node *node() const { return 0; }
00083     
00084     virtual bool loadXML(const QDomElement &element);
00085     virtual void saveXML(QDomElement &element) const;
00086     void saveCommonXML(QDomElement &element) const;
00087     void saveAppointments(QDomElement &element) const;
00088     
00090     QPtrList<Appointment> &appointments() { return m_appointments; }
00092     virtual bool add(Appointment *appointment);
00094     virtual void addAppointment(Schedule */*other*/, DateTime &/*start*/, DateTime &/*end*/, double /*load*/=100) {}
00096     void removeAppointment(Appointment *appointment);
00098     void takeAppointment(Appointment *appointment);
00099     Appointment *findAppointment(Schedule *resource, Schedule *node);
00100     
00101     Appointment appointmentIntervals() const;
00102     
00103     virtual bool isOverbooked() const { return false; }
00104     virtual bool isOverbooked(const DateTime &/*start*/, const DateTime &/*end*/) const { return false; }
00105     virtual QStringList overbookedResources() const;
00106     
00107     virtual EffortCostMap plannedEffortCostPrDay(const QDate &start, const QDate &end) const;
00108         
00110     virtual Duration plannedEffort() const;
00112     virtual Duration plannedEffort(const QDate &date) const;
00114     virtual Duration plannedEffortTo(const QDate &date) const;
00115     
00117     virtual Duration actualEffort() const;
00119     virtual Duration actualEffort(const QDate &date) const;
00121     virtual Duration actualEffortTo(const QDate &date) const;
00122     
00127     virtual double plannedCost() const; 
00128     
00130     virtual double plannedCost(const QDate &date) const;
00135     virtual double plannedCostTo(const QDate &date) const;
00140     virtual double actualCost() const;
00142     virtual double actualCost(const QDate &date) const;
00144     virtual double actualCostTo(const QDate &date) const;
00145     
00147     double effortPerformanceIndex(const QDate &/*date*/, bool */*error=0*/) { return 0.0; }
00149     double costPerformanceIndex(const QDate &/*date*/, bool */*error=0*/) { return 0.0; }
00150 
00151     virtual double normalRatePrHour() const { return 0.0; }
00152 
00153     void setEarliestStart(DateTime &dt) { earliestStart = dt; }
00154     void setLatestFinish(DateTime &dt) { latestFinish = dt; }
00155 
00156     virtual void initiateCalculation();
00157     virtual void calcResourceOverbooked();
00158 
00159     void setScheduled(bool on) { notScheduled = !on; }
00160     bool isScheduled() const { return !notScheduled; }
00161     
00162     DateTime start() const { return startTime; }
00163     DateTime end() const { return endTime; }
00164     
00165 protected:
00166     QString m_name;
00167     Type m_type;
00168     long m_id;
00169     bool m_deleted;
00170 
00171     QPtrList<Appointment> m_appointments;
00172     Schedule *m_parent;
00173     
00174     friend class Node;
00175     friend class Task;
00176     friend class Project;
00177     friend class Resource;
00178     friend class RecalculateProjectCmd;
00184     DateTime earliestStart;
00190     DateTime latestFinish;
00195     DateTime startTime;
00201     DateTime endTime;
00206     Duration duration;
00207 
00209     bool resourceError;
00211     bool resourceOverbooked;
00213     bool resourceNotAvailable;
00215     bool schedulingError;
00217     bool notScheduled;
00218 
00219     DateTime workStartTime;
00220     DateTime workEndTime;
00221     bool inCriticalPath;
00222 
00223 #ifndef NDEBUG
00224 public:
00225     virtual void printDebug(QString ident);
00226 #endif
00227 };
00228 
00233 class NodeSchedule : public Schedule
00234 {
00235 public:
00236     NodeSchedule();
00237     NodeSchedule(Node *node, QString name, Schedule::Type type, long id);
00238     NodeSchedule(Schedule *parent, Node *node);
00239     ~NodeSchedule();
00240     
00241     virtual bool isDeleted() const 
00242         { return m_parent == 0 ? true : m_parent->isDeleted(); }
00243     void setDeleted(bool on);
00244     
00245     virtual bool loadXML(const QDomElement &element);
00246     virtual void saveXML(QDomElement &element) const;
00247 
00248 // tasks------------>
00249     virtual void addAppointment(Schedule *resource, DateTime &start, DateTime &end, double load=100);
00250     
00251     virtual Node *node() const { return m_node; }
00252     virtual void setNode(Node *n) { m_node = n; }
00253     
00254 protected:
00255     void init();
00256 
00257 private:
00258     Node *m_node;
00259     
00260 #ifndef NDEBUG
00261 public:
00262     virtual void printDebug(QString ident);
00263 #endif
00264 };
00265 
00270 class ResourceSchedule : public Schedule
00271 {
00272 public:
00273     ResourceSchedule();
00274     ResourceSchedule(Resource *Resource, QString name, Schedule::Type type, long id);
00275     ResourceSchedule(Schedule *parent, Resource *Resource);
00276     ~ResourceSchedule();
00277     
00278     virtual bool isDeleted() const 
00279         { return m_parent == 0 ? true : m_parent->isDeleted(); }
00280     virtual void addAppointment(Schedule *node, DateTime &start, DateTime &end, double load=100);
00281     
00282     virtual bool isOverbooked() const;
00283     virtual bool isOverbooked(const DateTime &start, const DateTime &end) const;
00284     Appointment appointmentIntervals() const;
00285     
00286     virtual Resource *resource() const { return m_resource; }
00287     virtual double normalRatePrHour() const;
00288     
00289 private:
00290     Resource *m_resource;
00291     Schedule *m_parent;
00292 
00293 #ifndef NDEBUG
00294 public:
00295     virtual void printDebug(QString ident);
00296 #endif
00297 };
00298 
00303 class MainSchedule : public NodeSchedule
00304 {
00305 public:
00306     MainSchedule();
00307     MainSchedule(Node *node, QString name, Schedule::Type type, long id);
00308     ~MainSchedule();
00309     virtual bool isDeleted() const { return m_deleted; }
00310 
00311     virtual bool loadXML(const QDomElement &element, Project &project);
00312     virtual void saveXML(QDomElement &element) const;
00313 
00314 private:
00315 
00316 #ifndef NDEBUG
00317 public:
00318     virtual void printDebug(QString ident);
00319 #endif
00320 };
00321 
00322 
00323 } //namespace KPlato
00324 
00325 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys