/* This file is part of the KDE project Copyright (C) 2005 Dag Andersen This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; version 2 of the License. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kptschedule.h" #include "kptappointment.h" #include "kptdatetime.h" #include "kptduration.h" #include "kptnode.h" #include #include #include #include #include namespace KPlato { Schedule::Schedule() : m_type(Expected), m_id(0), m_deleted(false), m_parent(0) { } Schedule::Schedule(Schedule *parent) : m_type(Expected), m_id(0), m_deleted(false), m_appointments(), m_parent(parent) { if (parent) { m_name = parent->name(); m_type = parent->type(); m_id = parent->id(); } m_appointments.setAutoDelete(true); //kdDebug()< it = m_appointments; for (; it.current(); ++it) { if (it.current()->resource()->isOverbooked(startTime, endTime)) { resourceOverbooked = true; break; } } } TQStringList Schedule::overbookedResources() const { TQStringList rl; TQPtrListIterator it = m_appointments; for (; it.current(); ++it) { if (it.current()->resource()->isOverbooked(it.current()->startTime(), it.current()->endTime())) { rl += it.current()->resource()->resource()->name(); } } return rl; } bool Schedule::loadXML(const TQDomElement &sch) { m_name = sch.attribute("name"); setType(sch.attribute("type")); m_id = sch.attribute("id").toLong(); return true; } void Schedule::saveXML(TQDomElement &element) const { TQDomElement sch = element.ownerDocument().createElement("schedule"); element.appendChild(sch); saveCommonXML(sch); } void Schedule::saveCommonXML(TQDomElement &element) const { //kdDebug()< it = m_appointments; for (; it.current(); ++it) { it.current()->saveXML(element); } } bool Schedule::add(Appointment *appointment) { if (m_appointments.findRef(appointment) != -1) { kdError()<name()<<"'"<name()<<"'"<node()) appointment->node()->takeAppointment(appointment); } else { //kdDebug()< it = m_appointments; for (; it.current(); ++it) { if (it.current()->node() == node && it.current()->resource() == resource) return it.current(); } return 0; } EffortCostMap Schedule::plannedEffortCostPrDay(const TQDate &start, const TQDate &end) const { //kdDebug()< it(m_appointments); for (; it.current(); ++it) { //kdDebug()<plannedPrDay(start, end); } return ec; } Duration Schedule::plannedEffort() const { //kdDebug()< it(m_appointments); for (; it.current(); ++it) { eff += it.current()->plannedEffort(); } return eff; } Duration Schedule::plannedEffort(const TQDate &date) const { //kdDebug()< it(m_appointments); for (; it.current(); ++it) { eff += it.current()->plannedEffort(date); } return eff; } Duration Schedule::plannedEffortTo(const TQDate &date) const { //kdDebug()< it(m_appointments); for (; it.current(); ++it) { eff += it.current()->plannedEffortTo(date); } return eff; } Duration Schedule::actualEffort() const { //kdDebug()< it(m_appointments); for (; it.current(); ++it) { eff += it.current()->actualEffort(); } return eff; } Duration Schedule::actualEffort(const TQDate &date) const { //kdDebug()< it(m_appointments); for (; it.current(); ++it) { eff += it.current()->actualEffort(date); } return eff; } Duration Schedule::actualEffortTo(const TQDate &date) const { //kdDebug()< it(m_appointments); for (; it.current(); ++it) { eff += it.current()->actualEffortTo(date); } return eff; } double Schedule::plannedCost() const { //kdDebug()< it(m_appointments); for (; it.current(); ++it) { c += it.current()->plannedCost(); } return c; } double Schedule::plannedCost(const TQDate &date) const { //kdDebug()< it(m_appointments); for (; it.current(); ++it) { c += it.current()->plannedCost(date); } return c; } double Schedule::plannedCostTo(const TQDate &date) const { //kdDebug()< it(m_appointments); for (; it.current(); ++it) { c += it.current()->plannedCostTo(date); } return c; } double Schedule::actualCost() const { //kdDebug()< it(m_appointments); for (; it.current(); ++it) { c += it.current()->actualCost(); } return c; } double Schedule::actualCost(const TQDate &date) const { //kdDebug()< it(m_appointments); for (; it.current(); ++it) { c += it.current()->actualCost(date); } return c; } double Schedule::actualCostTo(const TQDate &date) const { //kdDebug()< it(m_appointments); for (; it.current(); ++it) { c += it.current()->actualCostTo(date); } return c; } //------------------------------------------------- NodeSchedule::NodeSchedule() : Schedule(), m_node(0) { //kdDebug()<name()<name()<addInterval(start, end, load); return; } a = new Appointment(resource, this, start, end, load); if (!add(a)) { delete a; } if (!resource->add(a)) { delete a; } } //----------------------------------------------- ResourceSchedule::ResourceSchedule() : Schedule(), m_resource(0) { //kdDebug()<name()<name()<addInterval(start, end, load); return; } a = new Appointment(this, node, start, end, load); if (!add(a)) { delete a; } if (!node->add(a)) { delete a; } } bool ResourceSchedule::isOverbooked() const { return false; } bool ResourceSchedule::isOverbooked(const DateTime &start, const DateTime &end) const { if (m_resource == 0) return false; //kdDebug()< it = a.intervals(); for (; it.current(); ++it) { if ((!end.isValid() || it.current()->startTime() < end) && (!start.isValid() || it.current()->endTime() > start)) { if (it.current()->load() > m_resource->units()) { //kdDebug()<startTime() >= end) break; } //kdDebug()< it = m_appointments; for (; it.current(); ++it) { a += *(it.current()); } return a; } double ResourceSchedule::normalRatePrHour() const { return m_resource ? m_resource->normalRate() : 0.0; } //-------------------------------------- MainSchedule::MainSchedule() : NodeSchedule() { //kdDebug()<name()<loadXML(app, project, *this)) { // TODO: Complain about this kdError()<name()< it = m_appointments; for (; it.current(); ++it) { it.current()->printDebug(indent + " "); } } void ResourceSchedule::printDebug(TQString indent) { Schedule::printDebug(indent); indent += "! "; if (m_parent == 0) kdDebug()<name()<name()< it = m_appointments; for (; it.current(); ++it) { it.current()->printDebug(indent + " "); } } #endif } //namespace KPlato