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 namespace frepple
00030 {
00031
00032
00033 DECLARE_EXPORT FlowPlan::FlowPlan (OperationPlan *opplan, const Flow *f)
00034 {
00035 assert(opplan && f);
00036 fl = const_cast<Flow*>(f);
00037
00038
00039 oper = opplan;
00040 nextFlowPlan = opplan->firstflowplan;
00041 opplan->firstflowplan = this;
00042
00043
00044 fl->getBuffer()->flowplans.insert(
00045 this,
00046 fl->getFlowplanQuantity(this),
00047 fl->getFlowplanDate(this)
00048 );
00049
00050
00051
00052 fl->getBuffer()->setChanged();
00053 fl->getOperation()->setChanged();
00054 }
00055
00056
00057 DECLARE_EXPORT void FlowPlan::update()
00058 {
00059
00060 fl->getBuffer()->flowplans.update(
00061 this,
00062 fl->getFlowplanQuantity(this),
00063 fl->getFlowplanDate(this)
00064 );
00065
00066
00067
00068 fl->getBuffer()->setChanged();
00069 fl->getOperation()->setChanged();
00070 }
00071
00072
00073
00074
00075 DECLARE_EXPORT void FlowPlan::writeElement(XMLOutput *o, const Keyword& tag, mode m) const
00076 {
00077 o->BeginObject(tag);
00078 o->writeElement(Tags::tag_date, getDate());
00079 o->writeElement(Tags::tag_quantity, getQuantity());
00080 o->writeElement(Tags::tag_onhand, getOnhand());
00081 o->writeElement(Tags::tag_minimum, getMin());
00082 o->writeElement(Tags::tag_maximum, getMax());
00083 if (!dynamic_cast<OperationPlan*>(o->getCurrentObject()))
00084 o->writeElement(Tags::tag_operationplan, &*getOperationPlan());
00085
00086
00087 if (o->getContentType() == XMLOutput::PLANDETAIL)
00088 {
00089
00090 PeggingIterator k(this, false);
00091 if (k) --k;
00092 for (; k; --k)
00093 {
00094 o->BeginObject(Tags::tag_pegging, Tags::tag_level, k.getLevel());
00095 o->writeElement(Tags::tag_quantity, k.getQuantityDemand());
00096 o->writeElement(Tags::tag_factor, k.getFactor());
00097 if (!k.getPegged()) o->writeElement(Tags::tag_id, "unpegged");
00098 o->writeElement(Tags::tag_buffer, Tags::tag_name, k.getBuffer()->getName());
00099 if (k.getConsumingOperationplan())
00100 o->writeElement(Tags::tag_consuming,
00101 Tags::tag_id, k.getConsumingOperationplan()->getIdentifier(),
00102 Tags::tag_operation, k.getConsumingOperationplan()->getOperation()->getName());
00103 if (k.getProducingOperationplan())
00104 o->writeElement(Tags::tag_producing,
00105 Tags::tag_id, k.getProducingOperationplan()->getIdentifier(),
00106 Tags::tag_operation, k.getProducingOperationplan()->getOperation()->getName());
00107 o->writeElement(Tags::tag_dates, DateRange(k.getProducingDate(),k.getConsumingDate()));
00108 o->EndObject(Tags::tag_pegging);
00109 }
00110
00111
00112 PeggingIterator l(this, true);
00113 if (l) ++l;
00114 for (; l; ++l)
00115 {
00116 o->BeginObject(Tags::tag_pegging, Tags::tag_level, l.getLevel());
00117 o->writeElement(Tags::tag_quantity, l.getQuantityDemand());
00118 o->writeElement(Tags::tag_factor, l.getFactor());
00119 if (!l.getPegged()) o->writeElement(Tags::tag_id, "unpegged");
00120 o->writeElement(Tags::tag_buffer, Tags::tag_name, l.getBuffer()->getName());
00121 if (l.getConsumingOperationplan())
00122 o->writeElement(Tags::tag_consuming,
00123 Tags::tag_id, l.getConsumingOperationplan()->getIdentifier(),
00124 Tags::tag_operation, l.getConsumingOperationplan()->getOperation()->getName());
00125 if (l.getProducingOperationplan())
00126 o->writeElement(Tags::tag_producing,
00127 Tags::tag_id, l.getProducingOperationplan()->getIdentifier(),
00128 Tags::tag_operation, l.getProducingOperationplan()->getOperation()->getName());
00129 o->writeElement(Tags::tag_dates, DateRange(l.getProducingDate(),l.getConsumingDate()));
00130 o->EndObject(Tags::tag_pegging);
00131 }
00132 }
00133
00134 o->EndObject(tag);
00135 }
00136
00137
00138 int PythonFlowPlan::initialize(PyObject* m)
00139 {
00140
00141 PythonType& x = getType();
00142 x.setName("flowplan");
00143 x.setDoc("frePPLe flowplan");
00144 x.supportgetattro();
00145 return x.typeReady(m);
00146 }
00147
00148
00149 PyObject* PythonFlowPlan::getattro(const Attribute& attr)
00150 {
00151 if (!fl) return Py_BuildValue("");
00152 if (attr.isA(Tags::tag_operationplan))
00153 return PythonObject(fl->getOperationPlan());
00154 if (attr.isA(Tags::tag_quantity))
00155 return PythonObject(fl->getQuantity());
00156 if (attr.isA(Tags::tag_date))
00157 return PythonObject(fl->getDate());
00158 if (attr.isA(Tags::tag_onhand))
00159 return PythonObject(fl->getOnhand());
00160 if (attr.isA(Tags::tag_buffer))
00161 return PythonObject(fl->getFlow()->getBuffer());
00162 return NULL;
00163 }
00164
00165
00166 int PythonFlowPlanIterator::initialize(PyObject* m)
00167 {
00168
00169 PythonType& x = PythonExtension<PythonFlowPlanIterator>::getType();
00170 x.setName("flowplanIterator");
00171 x.setDoc("frePPLe iterator for flowplan");
00172 x.supportiter();
00173 return x.typeReady(m);
00174 }
00175
00176
00177 PyObject* PythonFlowPlanIterator::iternext()
00178 {
00179
00180 while (i != buf->getFlowPlans().end() && i->getQuantity()==0.0)
00181 ++i;
00182 if (i == buf->getFlowPlans().end()) return NULL;
00183
00184
00185 return new PythonFlowPlan(const_cast<FlowPlan*>(dynamic_cast<const FlowPlan*>(&*(i++))));
00186 }
00187
00188 }