bool AbstractTaskFactory::Replace(const OrderedTaskPoint &new_tp, const unsigned position, const bool auto_mutate) { if (auto_mutate) { if (IsValidType(new_tp, position)) // ok to replace directly return task.Replace(new_tp, position); // will need to convert type of candidate OrderedTaskPoint *tp; if (position == 0) { // candidate must be transformed into a startpoint tp = CreateStart(new_tp.GetWaypoint()); } else if (IsPositionFinish(position) && position + 1 == task.TaskSize()) { // this point must be mutated into a finish tp = CreateFinish(new_tp.GetWaypoint()); } else { // this point must be mutated into an intermediate tp = CreateIntermediate(new_tp.GetWaypoint()); } bool success = task.Replace(*tp, position); delete tp; return success; } return task.Replace(new_tp, position); }
void onClick( Control* sender ) { String name = sender->getName(); if ( name == "start" ) { CreateStart(); } else if ( name == "setting" ) { CreateSetting(); } else if ( name == "credits" ) { CreateCredits(); } else if ( name == "exit" ) { RequestExit(); } else if ( name == "return" ) { CreateMenu(); } else if ( name == "accept" ) { exit( 0 ); } else if ( name == "cancel" ) { CreateMenu(); } }
bool AbstractTaskFactory::AppendOptionalStart(const OrderedTaskPoint &new_tp, const bool auto_mutate) { if (auto_mutate && !IsValidType(new_tp, 0)) { // candidate must be transformed into a startpoint of appropriate type StartPoint* sp = CreateStart(new_tp.GetWaypoint()); bool success = task.AppendOptionalStart(*sp); delete sp; return success; } // ok to add directly return task.AppendOptionalStart(new_tp); }
bool AbstractTaskFactory::AppendOptionalStart(const Waypoint& wp) { OrderedTaskPoint* tp = NULL; if (task.TaskSize()) tp = task.GetPoint(0).Clone(behaviour, GetOrderedTaskSettings(), &wp); else tp = CreateStart(wp); if (!tp) return false; // should never happen bool success = task.AppendOptionalStart(*tp); delete tp; return success; }
bool AbstractTaskFactory::Append(const OrderedTaskPoint &new_tp, const bool auto_mutate) { if (task.IsFull()) return false; if (auto_mutate) { if (!task.TaskSize()) { // empty task, so add as a start point if (IsValidType(new_tp, task.TaskSize())) { // candidate is ok, so add it return task.Append(new_tp); } else { // candidate must be transformed into a startpoint StartPoint* sp = CreateStart(new_tp.GetWaypoint()); bool success = task.Append(*sp); delete sp; return success; } } // non-empty task if (task.HasFinish()) { // old finish must be mutated into an intermediate point IntermediateTaskPoint* sp = CreateIntermediate(task.GetTaskPoint(task.TaskSize() - 1).GetWaypoint()); task.Replace(*sp, task.TaskSize()-1); delete sp; } if (IsValidType(new_tp, task.TaskSize())) // ok to append directly return task.Append(new_tp); // this point must be mutated into a finish FinishPoint* sp = CreateFinish(new_tp.GetWaypoint()); bool success = task.Append(*sp); delete sp; return success; } return task.Append(new_tp); }
bool AbstractTaskFactory::Insert(const OrderedTaskPoint &new_tp, const unsigned position, const bool auto_mutate) { if (position >= task.TaskSize()) return Append(new_tp, auto_mutate); if (auto_mutate) { if (position == 0) { if (task.HasStart()) { // old start must be mutated into an intermediate point IntermediateTaskPoint* sp = CreateIntermediate(task.GetTaskPoint(0).GetWaypoint()); task.Replace(*sp, 0); delete sp; } if (IsValidType(new_tp, 0)) { return task.Insert(new_tp, 0); } else { // candidate must be transformed into a startpoint StartPoint* sp = CreateStart(new_tp.GetWaypoint()); bool success = task.Insert(*sp, 0); delete sp; return success; } } else { if (new_tp.IsIntermediatePoint()) { // candidate ok for direct insertion return task.Insert(new_tp, position); } else { // candidate must be transformed into a intermediatepoint IntermediateTaskPoint* sp = CreateIntermediate(new_tp.GetWaypoint()); bool success = task.Insert(*sp, position); delete sp; return success; } } } return task.Insert(new_tp, position); }
bool AbstractTaskFactory::Remove(const unsigned position, const bool auto_mutate) { if (position >= task.TaskSize()) return false; if (auto_mutate) { if (position == 0) { // special case, remove start point.. if (task.TaskSize() == 1) { return task.Remove(0); } else { // create new start point from next point StartPoint* sp = CreateStart(task.GetTaskPoint(1).GetWaypoint()); bool success = task.Remove(0) && task.Replace(*sp, 0); delete sp; return success; } } else if (IsPositionFinish(position - 1) && position + 1 == task.TaskSize()) { // create new finish from previous point FinishPoint *sp = CreateFinish(task.GetTaskPoint(position - 1).GetWaypoint()); bool success = task.Remove(position) && task.Replace(*sp, position - 1); delete sp; return success; } else { // intermediate point deleted, nothing special to do return task.Remove(position); } } return task.Remove(position); }
OrderedTaskPoint* AbstractTaskFactory::CreatePoint(const TaskPointFactoryType type, const Waypoint &wp, fixed start_radius, fixed turnpoint_radius, fixed finish_radius) const { GetPointDefaultSizes(type, start_radius, turnpoint_radius, finish_radius); switch (type) { case TaskPointFactoryType::START_SECTOR: return CreateStart(SymmetricSectorZone::CreateFAISectorZone(wp.location, false), wp); case TaskPointFactoryType::START_LINE: return CreateStart(new LineSectorZone(wp.location, start_radius), wp); case TaskPointFactoryType::START_CYLINDER: return CreateStart(new CylinderZone(wp.location, start_radius), wp); case TaskPointFactoryType::START_BGA: return CreateStart(KeyholeZone::CreateBGAStartSectorZone(wp.location), wp); case TaskPointFactoryType::FAI_SECTOR: return CreateASTPoint(SymmetricSectorZone::CreateFAISectorZone(wp.location, true), wp); case TaskPointFactoryType::SYMMETRIC_QUADRANT: return CreateASTPoint(new SymmetricSectorZone(wp.location, turnpoint_radius), wp); case TaskPointFactoryType::KEYHOLE_SECTOR: return CreateASTPoint(KeyholeZone::CreateDAeCKeyholeZone(wp.location), wp); case TaskPointFactoryType::BGAFIXEDCOURSE_SECTOR: return CreateASTPoint(KeyholeZone::CreateBGAFixedCourseZone(wp.location), wp); case TaskPointFactoryType::BGAENHANCEDOPTION_SECTOR: return CreateASTPoint(KeyholeZone::CreateBGAEnhancedOptionZone(wp.location), wp); case TaskPointFactoryType::AST_CYLINDER: return CreateASTPoint(new CylinderZone(wp.location, turnpoint_radius), wp); case TaskPointFactoryType::MAT_CYLINDER: return CreateAATPoint(CylinderZone::CreateMatCylinderZone(wp.location), wp); case TaskPointFactoryType::AAT_CYLINDER: return CreateAATPoint(new CylinderZone(wp.location, turnpoint_radius), wp); case TaskPointFactoryType::AAT_SEGMENT: return CreateAATPoint(new SectorZone(wp.location, turnpoint_radius), wp); case TaskPointFactoryType::AAT_ANNULAR_SECTOR: return CreateAATPoint(new AnnularSectorZone(wp.location, turnpoint_radius), wp); case TaskPointFactoryType::AAT_KEYHOLE: return CreateAATPoint(KeyholeZone::CreateCustomKeyholeZone(wp.location, turnpoint_radius, Angle::QuarterCircle()), wp); case TaskPointFactoryType::FINISH_SECTOR: return CreateFinish(SymmetricSectorZone::CreateFAISectorZone(wp.location, false), wp); case TaskPointFactoryType::FINISH_LINE: return CreateFinish(new LineSectorZone(wp.location, finish_radius), wp); case TaskPointFactoryType::FINISH_CYLINDER: return CreateFinish(new CylinderZone(wp.location, finish_radius), wp); case TaskPointFactoryType::COUNT: gcc_unreachable(); } gcc_unreachable(); }
StartPoint* AbstractTaskFactory::CreateStart(const Waypoint &wp) const { return CreateStart(GetDefaultStartType(), wp); }