ScenarioListController.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package ArmarXCore::core
19 * @author Cedric Seehausen (usdnr at kit dot edu)
20 * @date 2016
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
25
26#pragma once
27
28#include <chrono>
29#include <memory>
30#include <mutex>
31#include <vector>
32
33#include <QObject>
34
42
47
49{
50 using ApplicationInstanceStatusMap = std::map<ApplicationInstancePtr, std::string>;
51
52 /**
53 * @class ScenarioListController
54 * @ingroup controller
55 * @brief Manages the signals and model of the ScenarioListView.
56 * All signals emitted by the ScenarioListView need to be connected to their corresponding slots in this
57 * controller. This controller periodically refreshes the status of the Applications and Scenarios
58 * displayed in the ScenarioListView.
59 */
60 class ScenarioListController : public QObject, public armarx::Logging
61 {
62 Q_OBJECT
63
64 public:
65 /**
66 * Constructor which sets the data structure, the executor and optionally the parent object.
67 * @param packages list of packages. Need to contain the Scenarios and Applications displayed in the ScenarioListView.
68 * @param executor executor used to start, stop and update status of the Applications and Scenarios.
69 * @param parent standard QT option to specify a parent
70 */
72 Exec::ExecutorPtr executor,
73 QObject* parent = 0);
74
75 /**
76 * Destructor.
77 */
78 ~ScenarioListController() override;
79
80 /**
81 * Returns the model used by the ScenarioListView and managed by this controller.
82 * @return managed model
83 */
85
86 /**
87 * @brief fetches application stati over their designated strategy.
88 * This is potentially slow and should not be done in the GUI thread.
89 */
90 void fetchStati();
91
93 Exec::ExecutorPtr executor,
94 IceGrid::AdminPrx iceAdmin);
95
96 signals:
97 /**
98 * Gets emitted after changes have been made to the data structure. Other controllers should update their models.
99 */
100 void updated();
101
102 /**
103 * Gets emitted after changes have been made to the States of the Applications. The DetailedApplicationView should update.
104 */
107
108 /**
109 * Gets emitted after an ApplicationInstance has been clicked.
110 * @param scenario clicked ApplicationInstance
111 */
113 ScenarioItem* item);
114
115 /**
116 * Gets emitted after a Scenario has been clicked.
117 * @param scenario clicked Scenario
118 */
120
122
123 public slots:
124 /**
125 * Shows a view that allows the user to create a new Scenario. This scenario will then be added
126 * to the data structure and models.
127 */
128 void createScenario();
129
130 /**
131 * Updates the model by reloading all scenarios and applications.
132 */
133 void updateModel();
134
135 /**
136 * Updates the statuses of all Applications and Scenarios.
137 */
138 void updateStati();
140
141
142 /**
143 * Removes an item from the model. Can either be an ApplicationInstance or an Scenario
144 * @param index of the model to be removed
145 */
146 void removeItem(QModelIndex item);
147
148 /**
149 * Creates a new scenario in the package.
150 * @param name name of the new scenario
151 * @param package name of the package
152 */
153 void createdScenario(std::string name, std::string package);
154
155 /**
156 * Starts or stops the object in the specified location.
157 * @param row row the object is in
158 * @param column column the object is in
159 * @param parent parent of the object. Needed to differentiate between scenarios and applications.
160 */
161 void start(int row, int column, QModelIndex parent);
162
163 /**
164 * Rebuilds the tree straight away instead of waiting for the next status poll, so that the
165 * button of a just requested operation greys out on this event loop turn.
166 */
167 void refreshNow();
168
169 void stop(int row, int column, QModelIndex parent);
170 void stopUpdateTask();
171
172 /**
173 * Restarts the object in the specified location.
174 * @param row row the object is in
175 * @param column column the object is in
176 * @param parent parent of the object. Needed to differentiate between scenarios and applications.
177 * @see start_stop(int row, int column, QModelIndex parent);
178 */
179 void restart(int row, int column, QModelIndex parent);
180
181 /**
182 * Adds applications to a scenario.
183 * @param applications list of applications to be added
184 * @param row
185 * @param parent model-index of the scenario
186 */
188 QList<QPair<QString, ScenarioManager::Data_Structure::Application*>> applications,
189 int row,
190 const QModelIndex& parent);
191
192 /**
193 * Calculates the object at the given index and signals to show it.
194 * @param index index of the object
195 */
196 void showApplication(const QModelIndex& index);
197
199
200 /**
201 * @brief Set an IceAdmin for the controller. Needet to start an application via ice
202 * @param IceGrid::AdminPrx
203 */
204 void setIceAdmin(IceGrid::AdminPrx iceAdmin);
205
206 private:
207 void startScenario(ScenarioItem* scenarioItem);
208 int findScenario(ScenarioItem* rootItem, std::string name, std::string packageName);
209 QModelIndex findSubScenarioModelIndex(std::string scenarioName, std::string packageName);
210 QModelIndex findApplicationModelIndex(
212 QModelIndex findSubScenarioModelIndexByScenarioIndex(QModelIndex scenarioIndex,
213 std::string packageName);
214
215 static void
216 ShowWarningDialog(QString message, bool showOnce = false, QString messageId = "");
217
218 private:
219 ScenarioModel treemodel;
222 // used for fetching application stati, list set before every update by gui thread
223 std::vector<ApplicationInstancePtr> applicationInstances;
224 std::mutex applicationInstanceMutex;
225 /// How often fetchStati() refreshes the cached "binary exists" flag of the applications.
226 static constexpr std::chrono::seconds FoundUpdateInterval{5};
227 std::chrono::steady_clock::time_point lastFoundUpdate;
229 Exec::ExecutorPtr executor;
230 IceGrid::AdminPrx iceAdmin;
231 CreateScenarioView createScenarioView;
232 };
233} // namespace ScenarioManager::Controller
uint8_t index
View that allows user to create a new scenario.
TreeItem representing data contained in a Scenario or an Application.
void saveScenario(ScenarioManager::Data_Structure::ApplicationInstancePtr application)
void restart(int row, int column, QModelIndex parent)
Restarts the object in the specified location.
static bool StartScenario(ScenarioManager::Data_Structure::ScenarioPtr scenario, Exec::ExecutorPtr executor, IceGrid::AdminPrx iceAdmin)
void updated()
Gets emitted after changes have been made to the data structure.
void applicationInstanceClicked(Data_Structure::ApplicationInstancePtr appInstance, ScenarioItem *item)
Gets emitted after an ApplicationInstance has been clicked.
void start(int row, int column, QModelIndex parent)
Starts or stops the object in the specified location.
void stop(int row, int column, QModelIndex parent)
void setIceAdmin(IceGrid::AdminPrx iceAdmin)
Set an IceAdmin for the controller.
void modelUpdated(FilterableTreeModelSortFilterProxyModelPtr model)
void updateModel()
Updates the model by reloading all scenarios and applications.
void createScenario()
Shows a view that allows the user to create a new Scenario.
void scenarioClicked(Data_Structure::ScenarioPtr scenario)
Gets emitted after a Scenario has been clicked.
void addApplicationsToScenario(QList< QPair< QString, ScenarioManager::Data_Structure::Application * > > applications, int row, const QModelIndex &parent)
Adds applications to a scenario.
void fetchStati()
fetches application stati over their designated strategy.
void createdScenario(std::string name, std::string package)
Creates a new scenario in the package.
FilterableTreeModelSortFilterProxyModelPtr getTreeModel()
Returns the model used by the ScenarioListView and managed by this controller.
ScenarioListController(Data_Structure::PackageVectorPtr packages, Exec::ExecutorPtr executor, QObject *parent=0)
Constructor which sets the data structure, the executor and optionally the parent object.
void removeItem(QModelIndex item)
Removes an item from the model.
void refreshNow()
Rebuilds the tree straight away instead of waiting for the next status poll, so that the button of a ...
void updateStati()
Updates the statuses of all Applications and Scenarios.
void statusFetched(ApplicationInstanceStatusMap stati)
void statusUpdated()
Gets emitted after changes have been made to the States of the Applications.
void showApplication(const QModelIndex &index)
Calculates the object at the given index and signals to show it.
Model defining how a Scenario gets displayed in the TreeView.
Base Class for all Logging classes.
Definition Logging.h:238
IceUtil::Handle< PeriodicTask< T > > pointer_type
Shared pointer type for convenience.
std::shared_ptr< FilterableTreeModelSortFilterProxyModel > FilterableTreeModelSortFilterProxyModelPtr
std::map< ApplicationInstancePtr, std::string > ApplicationInstanceStatusMap
std::shared_ptr< Scenario > ScenarioPtr
Definition Scenario.h:35
std::shared_ptr< std::vector< ScenarioManager::Data_Structure::PackagePtr > > PackageVectorPtr
Definition Package.h:123
std::shared_ptr< ApplicationInstance > ApplicationInstancePtr
std::shared_ptr< Executor > ExecutorPtr
Definition Executor.h:210