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