Esempio n. 1
0
bool 
OrderedTask::Replace(const OrderedTaskPoint &new_tp, const unsigned position)
{
  if (position >= task_points.size())
    return false;

  if (task_points[position]->equals(&new_tp))
    // nothing to do
    return true;

  /* is the new_tp allowed in this context? */
  if ((position > 0 && !new_tp.predecessor_allowed()) ||
      (position + 1 < task_points.size() && !new_tp.successor_allowed()))
    return false;

  delete task_points[position];
  task_points[position] = new_tp.clone(task_behaviour, m_ordered_behaviour);

  if (position)
    set_neighbours(position - 1);

  set_neighbours(position);
  if (position + 1 < task_points.size())
    set_neighbours(position + 1);

  update_geometry();
  return true;
}
Esempio n. 2
0
bool 
OrderedTask::Insert(const OrderedTaskPoint &new_tp, const unsigned position)
{
  if (position >= task_points.size())
    return Append(new_tp);

  if (/* is the new_tp allowed in this context? */
      (position > 0 && !new_tp.predecessor_allowed()) ||
      !new_tp.successor_allowed() ||
      /* can a tp be inserted at this position? */
      (position > 0 && !task_points[position - 1]->successor_allowed()) ||
      !task_points[position]->predecessor_allowed())
    return false;

  if (active_task_point >= position)
    active_task_point++;

  task_points.insert(task_points.begin() + position,
             new_tp.clone(task_behaviour, m_ordered_behaviour));

  if (position)
    set_neighbours(position - 1);

  set_neighbours(position);
  set_neighbours(position + 1);

  update_geometry();
  return true;
}