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 
89  ScenarioStartModes mode, Exec::ExecutorPtr executor, IceGrid::AdminPrx iceAdmin);
90 
91  signals:
92  /**
93  * Gets emitted after changes have been made to the data structure. Other controllers should update their models.
94  */
95  void updated();
96 
97  /**
98  * Gets emitted after changes have been made to the States of the Applications. The DetailedApplicationView should update.
99  */
100  void statusUpdated();
102 
103  /**
104  * Gets emitted after an ApplicationInstance has been clicked.
105  * @param scenario clicked ApplicationInstance
106  */
108 
109  /**
110  * Gets emitted after a Scenario has been clicked.
111  * @param scenario clicked Scenario
112  */
114 
116 
117  public slots:
118  /**
119  * Shows a view that allows the user to create a new Scenario. This scenario will then be added
120  * to the data structure and models.
121  */
122  void createScenario();
123 
124  /**
125  * Updates the model by reloading all scenarios and applications.
126  */
127  void updateModel();
128 
129  /**
130  * Updates the statuses of all Applications and Scenarios.
131  */
132  void updateStati();
134 
135 
136  /**
137  * Removes an item from the model. Can either be an ApplicationInstance or an Scenario
138  * @param index of the model to be removed
139  */
140  void removeItem(QModelIndex item);
141 
142  /**
143  * Creates a new scenario in the package.
144  * @param name name of the new scenario
145  * @param package name of the package
146  */
147  void createdScenario(std::string name, std::string package);
148 
149  /**
150  * Starts or stops the object in the specified location.
151  * @param row row the object is in
152  * @param column column the object is in
153  * @param parent parent of the object. Needed to differentiate between scenarios and applications.
154  */
155  void start(int row, int column, QModelIndex parent, ScenarioStartModes mode);
156  void stop(int row, int column, QModelIndex parent);
157  void stopUpdateTask();
158 
159  /**
160  * Restarts the object in the specified location.
161  * @param row row the object is in
162  * @param column column the object is in
163  * @param parent parent of the object. Needed to differentiate between scenarios and applications.
164  * @see start_stop(int row, int column, QModelIndex parent);
165  */
166  void restart(int row, int column, QModelIndex parent);
167 
168  /**
169  * Adds applications to a scenario.
170  * @param applications list of applications to be added
171  * @param row
172  * @param parent model-index of the scenario
173  */
174  void addApplicationsToScenario(QList<QPair<QString, ScenarioManager::Data_Structure::Application*> > applications,
175  int row, const QModelIndex& parent);
176 
177  /**
178  * Calculates the object at the given index and signals to show it.
179  * @param index index of the object
180  */
181  void showApplication(const QModelIndex& index);
182 
184 
185  /**
186  * @brief Set an IceAdmin for the controller. Needet to start an application via ice
187  * @param IceGrid::AdminPrx
188  */
189  void setIceAdmin(IceGrid::AdminPrx iceAdmin);
190 
191  private:
192  void startScenario(ScenarioItem* scenarioItem, ScenarioStartModes mode);
193  int findScenario(ScenarioItem* rootItem, std::string name, std::string packageName);
194  QModelIndex findSubScenarioModelIndex(std::string scenarioName, std::string packageName);
195  QModelIndex findApplicationModelIndex(ScenarioManager::Data_Structure::ApplicationInstancePtr application);
196  QModelIndex findSubScenarioModelIndexByScenarioIndex(QModelIndex scenarioIndex, std::string packageName);
197 
198  static void ShowWarningDialog(QString message, bool showOnce = false, QString messageId = "");
199 
200  private:
201  ScenarioModel treemodel;
204  // used for fetching application stati, list set before every update by gui thread
205  std::vector<ApplicationInstancePtr> applicationInstances;
206  std::mutex applicationInstanceMutex;
208  Exec::ExecutorPtr executor;
209  IceGrid::AdminPrx iceAdmin;
210  CreateScenarioView createScenarioView;
211 
212  };
213 }
214 
215 
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
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:95
ScenarioManager::Controller::ScenarioListController::setIceAdmin
void setIceAdmin(IceGrid::AdminPrx iceAdmin)
Set an IceAdmin for the controller.
Definition: ScenarioListController.cpp:1029
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:171
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.
ScenarioManager::Controller::ScenarioListController::StartScenario
static bool StartScenario(ScenarioManager::Data_Structure::ScenarioPtr scenario, ScenarioStartModes mode, Exec::ExecutorPtr executor, IceGrid::AdminPrx iceAdmin)
Definition: ScenarioListController.cpp:858
ScenarioManager::Controller::ScenarioListController::start
void start(int row, int column, QModelIndex parent, ScenarioStartModes mode)
Starts or stops the object in the specified location.
Definition: ScenarioListController.cpp:146
Package.h
ScenarioManager::Controller::ScenarioListController::createdScenario
void createdScenario(std::string name, std::string package)
Creates a new scenario in the package.
Definition: ScenarioListController.cpp:557
ScenarioManager::Controller::ScenarioListController::restart
void restart(int row, int column, QModelIndex parent)
Restarts the object in the specified location.
Definition: ScenarioListController.cpp:245
ScenarioStartModes
ScenarioStartModes
Definition: scenariolistview.h:44
Executor.h
ScenarioManager::Controller::ScenarioListController::stopUpdateTask
void stopUpdateTask()
Definition: ScenarioListController.cpp:141
FilterableTreeModelSortFilterProxyModelPtr
std::shared_ptr< FilterableTreeModelSortFilterProxyModel > FilterableTreeModelSortFilterProxyModelPtr
Definition: filterabletreemodelsortfilterproxymodel.h:65
ScenarioManager::Controller::ScenarioListController::~ScenarioListController
~ScenarioListController() override
Destructor.
Definition: ScenarioListController.cpp:85
IceManager.h
IceGridAdmin.h
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:613
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:55
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:283
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:965
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:1010
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:533
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:456
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:834
ScenarioManager::Controller::ScenarioListController::getTreeModel
FilterableTreeModelSortFilterProxyModelPtr getTreeModel()
Returns the model used by the ScenarioListView and managed by this controller.
Definition: ScenarioListController.cpp:90
ScenarioManager::Controller::ScenarioListController::updateModel
void updateModel()
Updates the model by reloading all scenarios and applications.
Definition: ScenarioListController.cpp:654
armarx::SimplePeriodicTask
Usage:
Definition: ApplicationNetworkStats.h:32