00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #define FREPPLE_CORE
00028 #include "frepple/model.h"
00029
00030 namespace frepple
00031 {
00032
00033
00034 DECLARE_EXPORT LoadPlan::LoadPlan (OperationPlan *o, const Load *r)
00035 {
00036 assert(o);
00037 ld = const_cast<Load*>(r);
00038 oper = o;
00039 start_or_end = START;
00040 nextLoadPlan = o->firstloadplan;
00041 o->firstloadplan = this;
00042 r->getResource()->loadplans.insert(
00043 this,
00044 ld->getLoadplanQuantity(this),
00045 ld->getLoadplanDate(this)
00046 );
00047
00048
00049 new LoadPlan(o, r, this);
00050
00051
00052
00053 r->getResource()->setChanged();
00054 r->getOperation()->setChanged();
00055 }
00056
00057
00058 DECLARE_EXPORT LoadPlan::LoadPlan (OperationPlan *o, const Load *r, LoadPlan *lp)
00059 {
00060 ld = const_cast<Load*>(r);
00061 oper = o;
00062 start_or_end = END;
00063 nextLoadPlan = o->firstloadplan;
00064 o->firstloadplan = this;
00065
00066 r->getResource()->loadplans.insert(
00067 this,
00068 ld->getLoadplanQuantity(this),
00069 ld->getLoadplanDate(this)
00070 );
00071 }
00072
00073
00074 DECLARE_EXPORT LoadPlan* LoadPlan::getOtherLoadPlan() const
00075 {
00076 for (LoadPlan *i = oper->firstloadplan; i; i = i->nextLoadPlan)
00077 if (i->ld == ld && i != this) return i;
00078 throw LogicException("No matching loadplan found");
00079 }
00080
00081
00082 DECLARE_EXPORT void LoadPlan::update()
00083 {
00084
00085 ld->getResource()->getLoadPlans().update(
00086 this,
00087 ld->getLoadplanQuantity(this),
00088 ld->getLoadplanDate(this)
00089 );
00090
00091
00092
00093 ld->getResource()->setChanged();
00094 ld->getOperation()->setChanged();
00095 }
00096
00097
00098 int PythonLoadPlan::initialize(PyObject* m)
00099 {
00100
00101 PythonType& x = getType();
00102 x.setName("loadplan");
00103 x.setDoc("frePPLe loadplan");
00104 x.supportgetattro();
00105 return x.typeReady(m);
00106 }
00107
00108
00109 PyObject* PythonLoadPlan::getattro(const Attribute& attr)
00110 {
00111 if (!fl) return Py_BuildValue("");
00112 if (attr.isA(Tags::tag_operationplan))
00113 return PythonObject(fl->getOperationPlan());
00114 if (attr.isA(Tags::tag_quantity))
00115 return PythonObject(fl->getQuantity());
00116 if (attr.isA(Tags::tag_startdate))
00117 return PythonObject(fl->getDate());
00118 if (attr.isA(Tags::tag_enddate))
00119 return PythonObject(fl->getOtherLoadPlan()->getDate());
00120 if (attr.isA(Tags::tag_resource))
00121 return PythonObject(fl->getLoad()->getResource());
00122 return NULL;
00123 }
00124
00125
00126 int PythonLoadPlanIterator::initialize(PyObject* m)
00127 {
00128
00129 PythonType& x = PythonExtension<PythonLoadPlanIterator>::getType();
00130 x.setName("loadplanIterator");
00131 x.setDoc("frePPLe iterator for loadplan");
00132 x.supportiter();
00133 return x.typeReady(m);
00134 }
00135
00136
00137 PyObject* PythonLoadPlanIterator::iternext()
00138 {
00139
00140 while (i != res->getLoadPlans().end() && i->getQuantity()<=0.0)
00141 ++i;
00142 if (i == res->getLoadPlans().end()) return NULL;
00143
00144
00145 return new PythonLoadPlan(const_cast<LoadPlan*>(dynamic_cast<const LoadPlan*>(&*(i++))));
00146 }
00147
00148 }