bool
AbstractTaskFactory::is_homogeneous() const
{
  bool valid = true;

  const unsigned size = m_task.TaskSize();

  if (size > 2) {
    LegalPointType_t homogtype = getType(*m_task.get_tp(1));

    for (unsigned i = 2; i < size; i++) {
      OrderedTaskPoint *tp = m_task.get_tp(i);
      if ((tp->GetType() == TaskPoint::FINISH)) {
        ; // don't check a valid finish point
      } else {
        if (getType(*tp) != homogtype) {
          valid = false;
          break;
        }
      }
    }
  }

  return valid;
}
bool 
AbstractTaskFactory::validType(const OrderedTaskPoint &new_tp,
                               unsigned position) const
{
  switch (new_tp.GetType()) {
  case TaskPoint::START:
    return validAbstractType(POINT_START, position) &&
        validStartType(getType(new_tp));

  case TaskPoint::AST:
    return validAbstractType(POINT_AST, position) &&
        validIntermediateType(getType(new_tp));

  case TaskPoint::AAT:
    return validAbstractType(POINT_AAT, position)&&
        validIntermediateType(getType(new_tp));

  case TaskPoint::FINISH:
    return validAbstractType(POINT_FINISH, position)&&
        validFinishType(getType(new_tp));

  case TaskPoint::UNORDERED:
  case TaskPoint::ROUTE:
    /* obviously, when we check the type of an OrderedTaskPoint, we
       should never get type==UNORDERED or ROUTE */
    assert(false);
    break;
  }

  return false;
}
bool
AbstractTaskFactory::mutate_closed_finish_per_task_type()
{
  if (m_task.TaskSize() < 2)
    return false;

  if (!is_position_finish(m_task.TaskSize() - 1))
    return false;

  bool changed = false;

  if (get_ordered_task_behaviour().is_closed) {
    if (!is_closed()) {
      OrderedTaskPoint *tp = m_task.get_tp(m_task.TaskSize() - 1);
      assert(tp);
      if (tp->GetType() == TaskPoint::FINISH) {
        FinishPoint *fp = createFinish(m_task.get_tp(0)->GetWaypoint());
        assert(fp);
        remove(m_task.TaskSize() - 1, false);
        append(*fp, false);
        delete fp;
        changed = true;
      }
    }
  }
  return changed;
}
TaskPointFactoryType
AbstractTaskFactory::GetMutatedPointType(const OrderedTaskPoint &tp) const
{
  const TaskPointFactoryType oldtype = GetType(tp);
  TaskPointFactoryType newtype = oldtype;

  switch (tp.GetType()) {
  case TaskPointType::START:
    if (!IsValidStartType(newtype))
      newtype = GetDefaultStartType();
    break;

  case TaskPointType::AST:
  case TaskPointType::AAT:
    if (!IsValidIntermediateType(newtype))
      newtype = GetDefaultIntermediateType();
    break;

  case TaskPointType::FINISH:
    if (!IsValidFinishType(newtype))
      newtype = GetDefaultFinishType();
    break;

  case TaskPointType::UNORDERED:
    break;
  }
  return newtype;
}
bool 
AbstractTaskFactory::IsValidType(const OrderedTaskPoint &new_tp,
                               unsigned position) const
{
  switch (new_tp.GetType()) {
  case TaskPointType::START:
    return ValidAbstractType(POINT_START, position) &&
        IsValidStartType(GetType(new_tp));

  case TaskPointType::AST:
    return ValidAbstractType(POINT_AST, position) &&
        IsValidIntermediateType(GetType(new_tp));

  case TaskPointType::AAT:
    return ValidAbstractType(POINT_AAT, position)&&
        IsValidIntermediateType(GetType(new_tp));

  case TaskPointType::FINISH:
    return ValidAbstractType(POINT_FINISH, position)&&
        IsValidFinishType(GetType(new_tp));

  case TaskPointType::UNORDERED:
    /* obviously, when we check the type of an OrderedTaskPoint, we
       should never get type==UNORDERED */
    gcc_unreachable();
  }

  gcc_unreachable();
}
bool 
OrderedTaskPoint::Equals(const OrderedTaskPoint &other) const
{
  return GetWaypoint() == other.GetWaypoint() &&
    GetType() == other.GetType() &&
    GetObservationZone().Equals(other.GetObservationZone()) &&
    other.GetObservationZone().Equals(GetObservationZone());
}
static bool
IsTaskLegVisible(const OrderedTaskPoint &tp)
{
  switch (tp.GetType()) {
  case TaskPointType::START:
    return tp.HasExited();

  case TaskPointType::FINISH:
  case TaskPointType::AAT:
  case TaskPointType::AST:
    return tp.HasEntered();

  case TaskPointType::UNORDERED:
    break;
  }

  gcc_unreachable();
}
void
TaskPointRenderer::DrawOrdered(const OrderedTaskPoint &tp, Layer layer)
{
  int offset = index - active_index;

  if (offset == 0 && task_finished && tp.GetType() == TaskPointType::FINISH)
    /* if the task is finished, pretend the active_index is past the
       current index; we need this because XCSoar never moves
       active_index to one after the finish point, because that would
       point to an invalid task point index */
    offset = -1;

  switch (layer) {
  case LAYER_OZ_SHADE:
    if (tp.BoundingBoxOverlaps(bb_screen))
      // draw shaded part of observation zone
      DrawOZBackground(canvas, tp, offset);

    break;

  case LAYER_LEG:
    if (index > 0)
      DrawTaskLine(last_point, tp.GetLocationRemaining());

    last_point = tp.GetLocationRemaining();

    break;

  case LAYER_OZ_OUTLINE:
    if (tp.BoundingBoxOverlaps(bb_screen)) {
      if (mode_optional_start && offset == 0)
        /* render optional starts as deactivated */
        offset = -1;

      DrawOZForeground(tp, offset);
    }

    break;

  case LAYER_SYMBOLS:
    return;
  }
}
Exemple #9
0
static void
Serialise(WritableDataNode &node, const OrderedTaskPoint &data,
          const TCHAR *name)
{
  // do nothing
  std::unique_ptr<WritableDataNode> child(node.AppendChild(_T("Point")));
  child->SetAttribute(_T("type"), name);

  std::unique_ptr<WritableDataNode> wchild(child->AppendChild(_T("Waypoint")));
  Serialise(*wchild, data.GetWaypoint());

  std::unique_ptr<WritableDataNode> ochild(child->AppendChild(_T("ObservationZone")));
  Serialise(*ochild, data.GetObservationZone());

  if (data.GetType() == TaskPointType::AST) {
    const ASTPoint &ast = (const ASTPoint &)data;
    if (ast.GetScoreExit())
      child->SetAttribute(_T("score_exit"), true);
  }
}
Exemple #10
0
AbstractTaskFactory::LegalPointType_t
AbstractTaskFactory::getMutatedPointType(const OrderedTaskPoint &tp) const
{
  const LegalPointType_t oldtype = getType(tp);
  LegalPointType_t newtype = oldtype;

  switch (tp.GetType()) {
  case TaskPoint::START:
    if (!validStartType(newtype)) {
      newtype = m_behaviour.sector_defaults.start_type;
      if (!validStartType(newtype))
        newtype = *m_start_types.begin();
    }
    break;

  case TaskPoint::AST:
  case TaskPoint::AAT:
    if (!validIntermediateType(newtype)) {
      newtype = m_behaviour.sector_defaults.turnpoint_type;
      if (!validIntermediateType(newtype)) {
        newtype = *m_intermediate_types.begin();
      }
    }
    break;

  case TaskPoint::FINISH:
    if (!validFinishType(newtype)) {
      newtype = m_behaviour.sector_defaults.finish_type;
      if (!validFinishType(newtype))
        newtype = *m_finish_types.begin();
    }
    break;

  case TaskPoint::UNORDERED:
  case TaskPoint::ROUTE:
    break;
  }
  return newtype;
}
Exemple #11
0
AbstractTaskFactory::LegalPointType_t 
AbstractTaskFactory::getType(const OrderedTaskPoint &point) const
{
  const ObservationZonePoint* oz = point.get_oz();

  switch (point.GetType()) {
  case TaskPoint::START:
    switch (oz->shape) {
    case ObservationZonePoint::FAI_SECTOR:
      return START_SECTOR;

    case ObservationZonePoint::LINE:
      return START_LINE;

    case ObservationZonePoint::CYLINDER:
    case ObservationZonePoint::SECTOR:
    case ObservationZonePoint::KEYHOLE:
    case ObservationZonePoint::BGAFIXEDCOURSE:
    case ObservationZonePoint::BGAENHANCEDOPTION:
    case ObservationZonePoint::ANNULAR_SECTOR:
      return START_CYLINDER;

    case ObservationZonePoint::BGA_START:
      return START_BGA;
    }
    break;

  case TaskPoint::AAT:
    switch (oz->shape) {
    case ObservationZonePoint::SECTOR:
    case ObservationZonePoint::FAI_SECTOR:
    case ObservationZonePoint::KEYHOLE:
    case ObservationZonePoint::BGAFIXEDCOURSE:
    case ObservationZonePoint::BGAENHANCEDOPTION:
    case ObservationZonePoint::BGA_START:
    case ObservationZonePoint::LINE:
      return AAT_SEGMENT;
    case ObservationZonePoint::ANNULAR_SECTOR:
      return AAT_ANNULAR_SECTOR;
    case ObservationZonePoint::CYLINDER:
      return AAT_CYLINDER;
    }
    break;

  case TaskPoint::AST:
    switch (oz->shape) {
    case ObservationZonePoint::FAI_SECTOR:
      return FAI_SECTOR;

    case ObservationZonePoint::KEYHOLE:
      return KEYHOLE_SECTOR;

    case ObservationZonePoint::BGAFIXEDCOURSE:
      return BGAFIXEDCOURSE_SECTOR;

    case ObservationZonePoint::BGAENHANCEDOPTION:
      return BGAENHANCEDOPTION_SECTOR;

    case ObservationZonePoint::BGA_START:
    case ObservationZonePoint::CYLINDER:
    case ObservationZonePoint::SECTOR:
    case ObservationZonePoint::LINE:
    case ObservationZonePoint::ANNULAR_SECTOR:
      return AST_CYLINDER;
    }
    break;

  case TaskPoint::FINISH:
    switch (oz->shape) {
    case ObservationZonePoint::BGA_START:
    case ObservationZonePoint::FAI_SECTOR:
      return FINISH_SECTOR;

    case ObservationZonePoint::LINE:
      return FINISH_LINE;

    case ObservationZonePoint::CYLINDER:
    case ObservationZonePoint::SECTOR:
    case ObservationZonePoint::KEYHOLE:
    case ObservationZonePoint::BGAFIXEDCOURSE:
    case ObservationZonePoint::BGAENHANCEDOPTION:
    case ObservationZonePoint::ANNULAR_SECTOR:
      return FINISH_CYLINDER;
    }
    break;

  case TaskPoint::UNORDERED:
  case TaskPoint::ROUTE:
    /* obviously, when we check the type of an OrderedTaskPoint, we
       should never get type==UNORDERED or ROUTE. */
    assert(false);
    break;
  }

  // fail, should never get here
  assert(1);
  return START_LINE;
}
TaskPointFactoryType 
AbstractTaskFactory::GetType(const OrderedTaskPoint &point) const
{
  const ObservationZonePoint &oz = point.GetObservationZone();

  switch (point.GetType()) {
  case TaskPointType::START:
    switch (oz.GetShape()) {
    case ObservationZone::Shape::FAI_SECTOR:
    case ObservationZone::Shape::SYMMETRIC_QUADRANT:
      return TaskPointFactoryType::START_SECTOR;

    case ObservationZone::Shape::LINE:
      return TaskPointFactoryType::START_LINE;

    case ObservationZone::Shape::CYLINDER:
    case ObservationZone::Shape::MAT_CYLINDER:
    case ObservationZone::Shape::SECTOR:
    case ObservationZone::Shape::DAEC_KEYHOLE:
    case ObservationZone::Shape::CUSTOM_KEYHOLE:
    case ObservationZone::Shape::BGAFIXEDCOURSE:
    case ObservationZone::Shape::BGAENHANCEDOPTION:
    case ObservationZone::Shape::ANNULAR_SECTOR:
      return TaskPointFactoryType::START_CYLINDER;

    case ObservationZone::Shape::BGA_START:
      return TaskPointFactoryType::START_BGA;
    }
    break;

  case TaskPointType::AAT:
    switch (oz.GetShape()) {
    case ObservationZone::Shape::SECTOR:
    case ObservationZone::Shape::FAI_SECTOR:
    case ObservationZone::Shape::SYMMETRIC_QUADRANT:
    case ObservationZone::Shape::DAEC_KEYHOLE:
    case ObservationZone::Shape::BGAFIXEDCOURSE:
    case ObservationZone::Shape::BGAENHANCEDOPTION:
    case ObservationZone::Shape::BGA_START:
    case ObservationZone::Shape::LINE:
      return TaskPointFactoryType::AAT_SEGMENT;
    case ObservationZone::Shape::ANNULAR_SECTOR:
      return TaskPointFactoryType::AAT_ANNULAR_SECTOR;
    case ObservationZone::Shape::CYLINDER:
      return TaskPointFactoryType::AAT_CYLINDER;

    case ObservationZone::Shape::CUSTOM_KEYHOLE:
      return TaskPointFactoryType::AAT_KEYHOLE;

    case ObservationZone::Shape::MAT_CYLINDER:
      return TaskPointFactoryType::MAT_CYLINDER;
    }
    break;

  case TaskPointType::AST:
    switch (oz.GetShape()) {
    case ObservationZone::Shape::FAI_SECTOR:
      return TaskPointFactoryType::FAI_SECTOR;

    case ObservationZone::Shape::DAEC_KEYHOLE:
    case ObservationZone::Shape::CUSTOM_KEYHOLE:
      return TaskPointFactoryType::KEYHOLE_SECTOR;

    case ObservationZone::Shape::BGAFIXEDCOURSE:
      return TaskPointFactoryType::BGAFIXEDCOURSE_SECTOR;

    case ObservationZone::Shape::BGAENHANCEDOPTION:
      return TaskPointFactoryType::BGAENHANCEDOPTION_SECTOR;

    case ObservationZone::Shape::BGA_START:
    case ObservationZone::Shape::CYLINDER:
    case ObservationZone::Shape::MAT_CYLINDER:
    case ObservationZone::Shape::SECTOR:
    case ObservationZone::Shape::LINE:
    case ObservationZone::Shape::ANNULAR_SECTOR:
      return TaskPointFactoryType::AST_CYLINDER;

    case ObservationZone::Shape::SYMMETRIC_QUADRANT:
      return TaskPointFactoryType::SYMMETRIC_QUADRANT;
    }
    break;

  case TaskPointType::FINISH:
    switch (oz.GetShape()) {
    case ObservationZone::Shape::BGA_START:
    case ObservationZone::Shape::FAI_SECTOR:
    case ObservationZone::Shape::SYMMETRIC_QUADRANT:
      return TaskPointFactoryType::FINISH_SECTOR;

    case ObservationZone::Shape::LINE:
      return TaskPointFactoryType::FINISH_LINE;

    case ObservationZone::Shape::CYLINDER:
    case ObservationZone::Shape::MAT_CYLINDER:
    case ObservationZone::Shape::SECTOR:
    case ObservationZone::Shape::DAEC_KEYHOLE:
    case ObservationZone::Shape::CUSTOM_KEYHOLE:
    case ObservationZone::Shape::BGAFIXEDCOURSE:
    case ObservationZone::Shape::BGAENHANCEDOPTION:
    case ObservationZone::Shape::ANNULAR_SECTOR:
      return TaskPointFactoryType::FINISH_CYLINDER;
    }
    break;

  case TaskPointType::UNORDERED:
    /* obviously, when we check the type of an OrderedTaskPoint, we
       should never get type==UNORDERED */
    gcc_unreachable();
    break;
  }

  // fail, should never get here
  gcc_unreachable();
}
Exemple #13
0
static void
RefreshView()
{
  wTaskView->invalidate();

  OrderedTaskPoint* tp = ordered_task->get_tp(active_index);
  if (!tp)
    return;

  Refreshing = true; // tell onChange routines not to save form!

  ShowFormControl(*wf, _T("frmOZLine"), false);
  ShowFormControl(*wf, _T("frmOZSector"), false);
  ShowFormControl(*wf, _T("frmOZCylinder"), false);

  const ObservationZonePoint &oz = *tp->get_oz();

  switch (oz.shape) {
  case ObservationZonePoint::SECTOR:
  case ObservationZonePoint::ANNULAR_SECTOR:
    ShowFormControl(*wf, _T("frmOZSector"), true);

    LoadFormProperty(*wf, _T("prpOZSectorRadius"),
                     ugDistance, ((const SectorZone &)oz).getRadius());
    LoadFormProperty(*wf, _T("prpOZSectorStartRadial"),
                     ((const SectorZone &)oz).getStartRadial().value_degrees());
    LoadFormProperty(*wf, _T("prpOZSectorFinishRadial"),
                     ((const SectorZone &)oz).getEndRadial().value_degrees());

    if (oz.shape == ObservationZonePoint::ANNULAR_SECTOR) {
      LoadFormProperty(*wf, _T("prpOZSectorInnerRadius"),
                       ugDistance, ((const AnnularSectorZone &)oz).getInnerRadius());

      ShowFormControl(*wf, _T("prpOZSectorInnerRadius"), true);
    } else
      ShowFormControl(*wf, _T("prpOZSectorInnerRadius"), false);

    break;

  case ObservationZonePoint::LINE:
    ShowFormControl(*wf, _T("frmOZLine"), true);

    LoadFormProperty(*wf, _T("prpOZLineLength"), ugDistance,
                     ((const LineSectorZone &)oz).getLength());
    break;

  case ObservationZonePoint::CYLINDER:
    ShowFormControl(*wf, _T("frmOZCylinder"), true);

    LoadFormProperty(*wf, _T("prpOZCylinderRadius"), ugDistance,
                     ((const CylinderZone &)oz).getRadius());
    break;

  default:
    break;
  }

  WndFrame* wfrm = NULL;
  wfrm = ((WndFrame*)wf->FindByName(_T("lblType")));
  if (wfrm)
    wfrm->SetCaption(OrderedTaskPointName(ordered_task->get_factory().getType(*tp)));

  SetFormControlEnabled(*wf, _T("butPrevious"), active_index > 0);
  SetFormControlEnabled(*wf, _T("butNext"),
                        active_index < (ordered_task->TaskSize() - 1));

  WndButton* wb;
  wb = (WndButton*)wf->FindByName(_T("cmdOptionalStarts"));
  assert(wb);
  wb->set_visible(active_index == 0);
  if (ordered_task->optional_start_points_size() == 0)
    wb->SetCaption(_("Enable Alternate Starts"));
  else {
    TCHAR tmp[50];
    _stprintf(tmp, _T("%s (%d)"), _("Edit Alternates"),
        ordered_task->optional_start_points_size());
    wb->SetCaption(tmp);
  }

  EnableSizeEdit(ordered_task->get_factory_type() != TaskBehaviour::FACTORY_FAI_GENERAL);

  TCHAR bufType[100];
  TCHAR bufNamePrefix[100];

  switch (tp->GetType()) {
  case TaskPoint::START:
    _tcscpy(bufType, _T("Start point"));
    _tcscpy(bufNamePrefix, _T("Start: "));
    break;

  case TaskPoint::AST:
    _tcscpy(bufType, _T("Task point"));
    _stprintf(bufNamePrefix, _T("%d: "), active_index);
    break;

  case TaskPoint::AAT:
    _tcscpy(bufType, _T("Assigned area point"));
    _stprintf(bufNamePrefix, _T("%d: "), active_index);
    break;

  case TaskPoint::FINISH:
    _tcscpy(bufType, _T("Finish point"));
    _tcscpy(bufNamePrefix, _T("Finish: "));
    break;

  default:
    assert(true);
    break;
  }

  wf->SetCaption(bufType);

  wfrm = ((WndFrame*)wf->FindByName(_T("lblLocation")));
  if (wfrm) {
    TCHAR buff[100];
    _stprintf(buff, _T("%s %s"), bufNamePrefix, tp->GetWaypoint().name.c_str());
    wfrm->SetCaption(buff);
  }

  Refreshing = false; // reactivate onChange routines
}