Learn Environment
task_manager.hpp
Go to the documentation of this file.
1 #ifndef TASKMANAGER_HPP
2 #define TASKMANAGER_HPP
3 
4 #include "common/task.hpp"
6 
7 #include <QObject>
8 #include <QVector>
9 #include <QSharedPointer>
10 
11 class TaskUI;
12 
20 class TaskManager : public QObject
21 {
22  Q_OBJECT
23 
24 public:
30  TaskManager(TaskUI *taskUI, QObject *parent = nullptr);
31 
37  void startStopSubtask(Subtask &subtask, bool startSolution = false);
38 
43  void toggleSolution(Subtask &subtask);
44 
45 public Q_SLOTS:
49  void nextTask();
50 
54  void previousTask();
55 
60  void selectTask(int index);
61 
66  void startStopSubtask(const Subtask &subtask);
67 
71  void forceResetRobot();
72 
73 private Q_SLOTS:
74 
78  void onTaskExecutionStarted();
79 
83  void onTaskExecutionFinished();
84 
89  void onTaskExecutionFailed(const QString &error);
90 
94  void onResetRobotStarted();
95 
99  void onResetRobotFinished();
100 
105  void onResetRobotFailed(const QString &error);
106 
107 private:
108  TaskUI *taskUI;
109  TaskExecutor *taskExecutor;
110  QVector<QSharedPointer<Task>> tasks;
111  QVector<Subtask*> queued_and_running_subtasks;
112  int currentQueueStartSolution = false;
113  int currentTaskIndex;
114  bool resetRobotInProgress = false;
115 
121  void startSubtask(Subtask &started_subtask, QSharedPointer<Task> &task, bool startSolution = false);
122 
126  void initiateFirstSubtask();
127 
131  void forceStop();
132 
137  void logWithHashes(const QString &message);
138 };
139 
140 #endif // TASKMANAGER_HPP
NotebookConverter
A class for converting Jupyter notebooks to Python scripts and processing task pools.
Definition: notebook_converter.hpp:23
QObject
TaskExecutor::resetRobotStarted
void resetRobotStarted()
Signal emitted when robot reset starts.
task.hpp
TaskManager
Manages tasks and their execution within the application.
Definition: task_manager.hpp:20
Subtask::status
SubtaskStatus status
The status of the subtask.
Definition: task.hpp:46
FolderStructureConstants::DIFFICULTY_LEVELS_DEFINITION_PATH
const QString DIFFICULTY_LEVELS_DEFINITION_PATH
Definition: folder_structure_constants.hpp:45
TaskUI::setTaskUI
void setTaskUI(int currentTaskIndex, const QVector< QSharedPointer< Task >> &tasks)
Sets the UI elements for the current task.
TaskExecutor::forceStop
void forceStop()
Forces the stop of all currently running tasks.
Definition: task_executor.cpp:62
task_executor.hpp
SubtaskStatus::Queued
@ Queued
The subtask is queued for execution.
Subtask::lastExecutionError
QString lastExecutionError
The error message from the last execution of the subtask.
Definition: task.hpp:50
folder_structure_constants.hpp
SubtaskStatus::Running
@ Running
The subtask is currently being executed.
TaskParser::loadTasks
QVector< QSharedPointer< Task > > loadTasks(const QString &taskPath, const QString &difficultyPath, const QString &topicPath)
Loads tasks with all configuration JSON files.
Definition: task_parser.cpp:33
TaskExecutor
Executes tasks and manages their execution state.
Definition: task_executor.hpp:19
TaskExecutor::resetRobotFinished
void resetRobotFinished()
Signal emitted when robot reset finishes.
Subtask::lastExecutionFailed
bool lastExecutionFailed
Whether the subtask has been executed at least once.
Definition: task.hpp:49
FolderStructureConstants::TOPIC_DEFINITIONS_PATH
const QString TOPIC_DEFINITIONS_PATH
Path to the topic definitions json.
Definition: folder_structure_constants.hpp:39
Subtask::solutionFilePath
QString solutionFilePath
The file path to the solution of the subtask.
Definition: task.hpp:36
TaskManager::selectTask
void selectTask(int index)
Selects a task by its index.
Definition: task_manager.cpp:88
TaskUI::updateSubtaskItemsUI
void updateSubtaskItemsUI()
Updates the UI elements for the subtasks.
SubtaskStatus::Inactive
@ Inactive
The subtask is inactive (state where it can't be executed).
TaskUI
Manages the user interface for tasks and subtasks.
Definition: task_ui.hpp:24
FolderStructureConstants::TASK_DEFINITIONS_PATH
const QString TASK_DEFINITIONS_PATH
Path to the task definitions json.
Definition: folder_structure_constants.hpp:33
Subtask::title
QString title
The title of the subtask.
Definition: task.hpp:32
TaskManager::forceResetRobot
void forceResetRobot()
Forces the reset of the robot to its initial state.
Definition: task_manager.cpp:170
TaskManager::TaskManager
TaskManager(TaskUI *taskUI, QObject *parent=nullptr)
Constructs a TaskManager object.
Definition: task_manager.cpp:11
TaskUI::finishedRobotResetUI
void finishedRobotResetUI()
Update the UI to show that the robot reset has finished.
TaskManager::toggleSolution
void toggleSolution(Subtask &subtask)
Show or hide the solution of a subtask.
Definition: task_manager.cpp:74
notebook_converter.hpp
TaskManager::nextTask
void nextTask()
Slot for changing to the next task.
Definition: task_manager.cpp:113
Subtask::parentTask
QWeakPointer< Task > parentTask
Weak pointer to the parent task.
Definition: task.hpp:45
TaskExecutor::taskExecutionFinished
void taskExecutionFinished()
Signal emitted when task execution finishes.
NotebookConverter::processTaskPool
void processTaskPool()
Modifies and copies all notebooks from task_pool to users workspace.
Definition: notebook_converter.cpp:95
TaskExecutor::taskExecutionStarted
void taskExecutionStarted()
Signal emitted when task execution starts.
Subtask::filePath
QString filePath
The file path of the subtask.
Definition: task.hpp:35
TaskParser
Parses tasks and subtasks from a JSON file.
Definition: task_parser.hpp:18
TaskUI::setTaskManager
void setTaskManager(TaskManager *manager)
Sets the TaskManager object.
TaskExecutor::executeTask
void executeTask(const Subtask &subtask, bool startSolution=false)
Executes a given subtask.
Definition: task_executor.cpp:10
task_parser.hpp
TaskExecutor::taskExecutionFailed
void taskExecutionFailed(const QString &error)
Signal emitted when task execution fails.
TaskExecutor::resetRobotFailed
void resetRobotFailed(const QString &error)
Signal emitted when robot reset fails.
TaskUI::startedRobotResetUI
void startedRobotResetUI(bool noSubtasksLeft)
Update the UI to show that the robot reset has been started.
TaskManager::startStopSubtask
void startStopSubtask(Subtask &subtask, bool startSolution=false)
Starts or stops a subtask.
Definition: task_manager.cpp:45
Subtask::reset_robot_before_executing
bool reset_robot_before_executing
Whether to reset the robot before executing the subtask.
Definition: task.hpp:42
SubtaskStatus::Ready
@ Ready
The subtask is ready to be executed.
task_manager.hpp
TaskManager::previousTask
void previousTask()
Slot for changing to the previous task.
Definition: task_manager.cpp:120
TaskUI::initializeUI
void initializeUI(const QVector< QSharedPointer< Task >> &tasks)
Initializes the UI with the loaded tasks.
NotebookConverter::toggleSolution
void toggleSolution(const QString &filePath, const QString &solutionFilePath)
Toggles the solution code in a Jupyter notebook.
Definition: notebook_converter.cpp:266
Subtask
Represents a subtask within a task.
Definition: task.hpp:31
TaskExecutor::resetRobot
void resetRobot()
Triggers python script to reset the robot to its initial state and removes all objects from the scene...
Definition: task_executor.cpp:68
TaskUI::failedRobotResetUI
void failedRobotResetUI(const QString &error)
Update the UI to show that the robot reset has failed.
task_ui.hpp