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 <memory>
29#include <mutex>
30#include <vector>
31
32#include <QObject>
33
41
46
48{
49 using ApplicationInstanceStatusMap = std::map<ApplicationInstancePtr, std::string>;
50
51 /**
52 * @class ScenarioListController
53 * @ingroup controller
54 * @brief Manages the signals and model of the ScenarioListView.
55 * All signals emitted by the ScenarioListView need to be connected to their corresponding slots in this
56 * controller. This controller periodically refreshes the status of the Applications and Scenarios
57 * displayed in the ScenarioListView.
58 */
59 class ScenarioListController : public QObject, public armarx::Logging
60 {
61 Q_OBJECT
62
63 public:
64 /**
65 * Constructor which sets the data structure, the executor and optionally the parent object.
66 * @param packages list of packages. Need to contain the Scenarios and Applications displayed in the ScenarioListView.
67 * @param executor executor used to start, stop and update status of the Applications and Scenarios.
68 * @param parent standard QT option to specify a parent
69 */
71 Exec::ExecutorPtr executor,
72 QObject* parent = 0);
73
74 /**
75 * Destructor.
76 */
77 ~ScenarioListController() override;
78
79 /**
80 * Returns the model used by the ScenarioListView and managed by this controller.
81 * @return managed model
82 */
84
85 /**
86 * @brief fetches application stati over their designated strategy.
87 * This is potentially slow and should not be done in the GUI thread.
88 */
89 void fetchStati();
90
92 Exec::ExecutorPtr executor,
93 IceGrid::AdminPrx iceAdmin);
94
95 signals:
96 /**
97 * Gets emitted after changes have been made to the data structure. Other controllers should update their models.
98 */
99 void updated();
100
101 /**
102 * Gets emitted after changes have been made to the States of the Applications. The DetailedApplicationView should update.
103 */
106
107 /**
108 * Gets emitted after an ApplicationInstance has been clicked.
109 * @param scenario clicked ApplicationInstance
110 */
112 ScenarioItem* item);
113
114 /**
115 * Gets emitted after a Scenario has been clicked.
116 * @param scenario clicked Scenario
117 */
119
121
122 public slots:
123 /**
124 * Shows a view that allows the user to create a new Scenario. This scenario will then be added
125 * to the data structure and models.
126 */
127 void createScenario();
128
129 /**
130 * Updates the model by reloading all scenarios and applications.
131 */
132 void updateModel();
133
134 /**
135 * Updates the statuses of all Applications and Scenarios.
136 */
137 void updateStati();
139
140
141 /**
142 * Removes an item from the model. Can either be an ApplicationInstance or an Scenario
143 * @param index of the model to be removed
144 */
145 void removeItem(QModelIndex item);
146
147 /**
148 * Creates a new scenario in the package.
149 * @param name name of the new scenario
150 * @param package name of the package
151 */
152 void createdScenario(std::string name, std::string package);
153
154 /**
155 * Starts or stops the object in the specified location.
156 * @param row row the object is in
157 * @param column column the object is in
158 * @param parent parent of the object. Needed to differentiate between scenarios and applications.
159 */
160 void start(int row, int column, QModelIndex parent);
161 void stop(int row, int column, QModelIndex parent);
162 void stopUpdateTask();
163
164 /**
165 * Restarts the object in the specified location.
166 * @param row row the object is in
167 * @param column column the object is in
168 * @param parent parent of the object. Needed to differentiate between scenarios and applications.
169 * @see start_stop(int row, int column, QModelIndex parent);
170 */
171 void restart(int row, int column, QModelIndex parent);
172
173 /**
174 * Adds applications to a scenario.
175 * @param applications list of applications to be added
176 * @param row
177 * @param parent model-index of the scenario
178 */
180 QList<QPair<QString, ScenarioManager::Data_Structure::Application*>> applications,
181 int row,
182 const QModelIndex& parent);
183
184 /**
185 * Calculates the object at the given index and signals to show it.
186 * @param index index of the object
187 */
188 void showApplication(const QModelIndex& index);
189
191
192 /**
193 * @brief Set an IceAdmin for the controller. Needet to start an application via ice
194 * @param IceGrid::AdminPrx
195 */
196 void setIceAdmin(IceGrid::AdminPrx iceAdmin);
197
198 private:
199 void startScenario(ScenarioItem* scenarioItem);
200 int findScenario(ScenarioItem* rootItem, std::string name, std::string packageName);
201 QModelIndex findSubScenarioModelIndex(std::string scenarioName, std::string packageName);
202 QModelIndex findApplicationModelIndex(
204 QModelIndex findSubScenarioModelIndexByScenarioIndex(QModelIndex scenarioIndex,
205 std::string packageName);
206
207 static void
208 ShowWarningDialog(QString message, bool showOnce = false, QString messageId = "");
209
210 private:
211 ScenarioModel treemodel;
214 // used for fetching application stati, list set before every update by gui thread
215 std::vector<ApplicationInstancePtr> applicationInstances;
216 std::mutex applicationInstanceMutex;
218 Exec::ExecutorPtr executor;
219 IceGrid::AdminPrx iceAdmin;
220 CreateScenarioView createScenarioView;
221 };
222} // 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 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:240
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:175