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 
42 #include "../gui/createscenarioview.h"
43 #include "../gui/filterabletreemodelsortfilterproxymodel.h"
44 #include "../gui/scenariolistview.h"
45 #include "../gui/scenariomodel.h"
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  */
104  void statusUpdated();
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
ScenarioItem
TreeItem representing data contained in a Scenario or an Application.
Definition: scenarioitem.h:40
ScenarioManager::Controller::ApplicationInstanceStatusMap
std::map< ApplicationInstancePtr, std::string > ApplicationInstanceStatusMap
Definition: ScenarioListController.h:49
ScenarioManager::Data_Structure::ApplicationInstancePtr
std::shared_ptr< ApplicationInstance > ApplicationInstancePtr
Definition: ApplicationInstance.h:33
ScenarioManager::Data_Structure::ScenarioPtr
std::shared_ptr< Scenario > ScenarioPtr
Definition: Scenario.h:35
ScenarioManager::Controller::ScenarioListController
Manages the signals and model of the ScenarioListView. All signals emitted by the ScenarioListView ne...
Definition: ScenarioListController.h:59
ScenarioManager::Controller::ScenarioListController::StartScenario
static bool StartScenario(ScenarioManager::Data_Structure::ScenarioPtr scenario, Exec::ExecutorPtr executor, IceGrid::AdminPrx iceAdmin)
Definition: ScenarioListController.cpp:893
index
uint8_t index
Definition: EtherCATFrame.h:59
ScenarioManager::Controller
Definition: ApplicationDatabaseController.h:40
ScenarioModel
Model defining how a Scenario gets displayed in the TreeView.
Definition: scenariomodel.h:39
ScenarioManager::Controller::ScenarioListController::stop
void stop(int row, int column, QModelIndex parent)
Definition: ScenarioListController.cpp:116
ScenarioManager::Controller::ScenarioListController::setIceAdmin
void setIceAdmin(IceGrid::AdminPrx iceAdmin)
Set an IceAdmin for the controller.
Definition: ScenarioListController.cpp:993
message
message(STATUS "Boost-Library-Dir: " "${Boost_LIBRARY_DIRS}") message(STATUS "Boost-LIBRARIES
Definition: CMakeLists.txt:8
ScenarioManager::Exec::ExecutorPtr
std::shared_ptr< Executor > ExecutorPtr
Definition: Executor.h:175
ScenarioManager::Data_Structure::PackageVectorPtr
std::shared_ptr< std::vector< ScenarioManager::Data_Structure::PackagePtr > > PackageVectorPtr
Definition: Package.h:124
ScenarioManager::Controller::ScenarioListController::updated
void updated()
Gets emitted after changes have been made to the data structure.
ScenarioManager::Controller::ScenarioListController::scenarioClicked
void scenarioClicked(Data_Structure::ScenarioPtr scenario)
Gets emitted after a Scenario has been clicked.
Package.h
ScenarioManager::Controller::ScenarioListController::createdScenario
void createdScenario(std::string name, std::string package)
Creates a new scenario in the package.
Definition: ScenarioListController.cpp:564
ScenarioManager::Controller::ScenarioListController::restart
void restart(int row, int column, QModelIndex parent)
Restarts the object in the specified location.
Definition: ScenarioListController.cpp:228
Executor.h
ScenarioManager::Controller::ScenarioListController::stopUpdateTask
void stopUpdateTask()
Definition: ScenarioListController.cpp:155
FilterableTreeModelSortFilterProxyModelPtr
std::shared_ptr< FilterableTreeModelSortFilterProxyModel > FilterableTreeModelSortFilterProxyModelPtr
Definition: filterabletreemodelsortfilterproxymodel.h:68
ScenarioManager::Controller::ScenarioListController::~ScenarioListController
~ScenarioListController() override
Destructor.
Definition: ScenarioListController.cpp:104
IceManager.h
IceGridAdmin.h
ScenarioManager::Controller::ScenarioListController::start
void start(int row, int column, QModelIndex parent)
Starts or stops the object in the specified location.
Definition: ScenarioListController.cpp:161
TaskUtil.h
ScenarioManager::Controller::ScenarioListController::showApplication
void showApplication(const QModelIndex &index)
Calculates the object at the given index and signals to show it.
Definition: ScenarioListController.cpp:623
ApplicationInstance.h
ScenarioManager::Controller::ScenarioListController::ScenarioListController
ScenarioListController(Data_Structure::PackageVectorPtr packages, Exec::ExecutorPtr executor, QObject *parent=0)
Constructor which sets the data structure, the executor and optionally the parent object.
Definition: ScenarioListController.cpp:59
ScenarioManager::Controller::ScenarioListController::statusFetched
void statusFetched(ApplicationInstanceStatusMap stati)
ScenarioManager::Controller::ScenarioListController::updateStati
void updateStati()
Updates the statuses of all Applications and Scenarios.
Definition: ScenarioListController.cpp:923
armarx::Logging
Base Class for all Logging classes.
Definition: Logging.h:239
ScenarioManager::Controller::ScenarioListController::saveScenario
void saveScenario(ScenarioManager::Data_Structure::ApplicationInstancePtr application)
Definition: ScenarioListController.cpp:971
ScenarioManager::Controller::ScenarioListController::modelUpdated
void modelUpdated(FilterableTreeModelSortFilterProxyModelPtr model)
ScenarioManager::Controller::ScenarioListController::applicationInstanceClicked
void applicationInstanceClicked(Data_Structure::ApplicationInstancePtr appInstance, ScenarioItem *item)
Gets emitted after an ApplicationInstance has been clicked.
ScenarioManager::Controller::ScenarioListController::createScenario
void createScenario()
Shows a view that allows the user to create a new Scenario.
Definition: ScenarioListController.cpp:538
CreateScenarioView
View that allows user to create a new scenario.
Definition: createscenarioview.h:42
Logging.h
ScenarioManager::Controller::ScenarioListController::removeItem
void removeItem(QModelIndex item)
Removes an item from the model.
Definition: ScenarioListController.cpp:458
ScenarioManager::Controller::ScenarioListController::statusUpdated
void statusUpdated()
Gets emitted after changes have been made to the States of the Applications.
ScenarioManager::Controller::ScenarioListController::fetchStati
void fetchStati()
fetches application stati over their designated strategy.
Definition: ScenarioListController.cpp:868
ScenarioManager::Controller::ScenarioListController::addApplicationsToScenario
void addApplicationsToScenario(QList< QPair< QString, ScenarioManager::Data_Structure::Application * >> applications, int row, const QModelIndex &parent)
Adds applications to a scenario.
Definition: ScenarioListController.cpp:268
ScenarioManager::Controller::ScenarioListController::getTreeModel
FilterableTreeModelSortFilterProxyModelPtr getTreeModel()
Returns the model used by the ScenarioListView and managed by this controller.
Definition: ScenarioListController.cpp:110
ScenarioManager::Controller::ScenarioListController::updateModel
void updateModel()
Updates the model by reloading all scenarios and applications.
Definition: ScenarioListController.cpp:667
armarx::SimplePeriodicTask
Usage:
Definition: ApplicationNetworkStats.h:32