Exemplo n.º 1
0
// For editing
bool OperationModel::setData( const QModelIndex &index, const QVariant &value, int role)
{
    qDebug() << "setData(), index" << index << "role" << role;

    if (index.isValid()) {
        int row = index.row();
        if (row >= 0 && row < m_items.count()) {
            Operation* item = m_items[row];
            if (role == SetIndexRole){
                 item->setIndex(value.toInt());
                 return true;
            } else if (role == SetNameRole) {
                item->setName(value.toString());
                return true;
            } else if (role == SetLastDateRole) {
                item->setLastDate(value.toDate());
                return true;
            } else if (role == SetBonsaiIdRole) {
                item->setBonsaiId(value.toInt());
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    } else {
        return false;
    }

    return false;
}
Exemplo n.º 2
0
DECLARE_EXPORT Operation* BufferProcure::getOperation() const
{
  if (!oper)
  {
    Operation *o = Operation::find(PURCHASE_OPERATION);
    if (!o)
    {
      // Create a new purchase operation
      o = new OperationFixedTime();
      o->setName(PURCHASE_OPERATION);
      static_cast<OperationFixedTime*>(o)->setDuration(leadtime);
      new FlowEnd(o, const_cast<BufferProcure*>(this), 1);
    }
    // Copy procurement parameters to the existing operation
    if (o->getType() == *OperationFixedTime::metadata)
      static_cast<OperationFixedTime*>(o)->setDuration(leadtime);
    const_cast<BufferProcure*>(this)->oper = o;
    o->setFence(getFence());
    o->setSizeMaximum(getSizeMaximum());
    o->setSizeMinimum(getSizeMinimum());
    o->setSizeMultiple(getSizeMultiple());
    if (!o->getLocation()) o->setLocation(getLocation());
    o->setSource(getSource());
  }
  return oper;
}
Exemplo n.º 3
0
DECLARE_EXPORT void Buffer::setOnHand(double f)
{
  // The dummy operation to model the inventory may need to be created
  Operation *o = Operation::find(INVENTORY_OPERATION);
  Flow *fl;
  if (!o)
  {
    // Create a fixed time operation with zero leadtime, hidden from the xml
    // output, hidden for the solver, and without problem detection.
    o = new OperationFixedTime();
    o->setName(INVENTORY_OPERATION);
    o->setHidden(true);
    o->setDetectProblems(false);
    fl = new FlowEnd(o, this, 1);
  }
  else
    // Find the flow of this operation
    fl = const_cast<Flow*>(&*(o->getFlows().begin()));

  // Check valid pointers
  if (!fl || !o)
    throw LogicException("Failed creating inventory operation for '"
        + getName() + "'");

  // Make sure the sign of the flow is correct: +1 or -1.
  fl->setQuantity(f>=0.0 ? 1.0 : -1.0);

  // Create a dummy operationplan on the inventory operation
  OperationPlan::iterator i(o);
  if (i == OperationPlan::end())
  {
    // No operationplan exists yet
    OperationPlan *opplan = o->createOperationPlan(
        fabs(f), Date::infinitePast, Date::infinitePast);
    opplan->setLocked(true);
    opplan->activate();
  }
  else
  {
    // Update the existing operationplan
    i->setLocked(false);
    i->setQuantity(fabs(f));
    i->setLocked(true);
  }
  setChanged();
}