scenarioitem.cpp
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#include "scenarioitem.h"
27
30
31using namespace armarx;
32using namespace ScenarioManager;
33using namespace Data_Structure;
34
35ScenarioItem::ScenarioItem(QList<QVariant> rootData)
36{
37 m_itemData = rootData.toVector();
38}
39
41{
42 this->scenario = scenario;
43
44 update();
45}
46
48{
49 this->application = application;
50 setEnabled(application->getEnabled());
51
52 update();
53}
54
55ScenarioItem::ScenarioItem(std::string name, std::vector<ApplicationInstancePtr> applications) :
56 applications(new std::vector<ApplicationInstancePtr>(applications))
57{
58 this->packageName = name;
59
60 for (const auto& appl : applications)
61 {
62 ScenarioItem* currentItem = new ScenarioItem(appl);
63 currentItem->setEnabled(appl->getEnabled());
64
65 this->appendChild(currentItem);
66 }
67
68 update();
69}
70
71void
73{
74 if (m_itemData.size() < 5)
75 {
76 m_itemData.resize(5);
77 m_itemData[1] = "Start";
78 m_itemData[2] = "Stop";
79 m_itemData[3] = "Restart";
80 }
81 if (scenario.get() != nullptr)
82 {
83 m_itemData[0] = scenario->getName().c_str();
84 m_itemData[4] = QString::fromStdString(scenario->getStatus());
85 }
86 else if (!packageName.empty())
87 {
88 m_itemData[0] = QString::fromStdString(packageName);
89
91 for (int i = 0; i < childCount(); i++)
92 {
94 auto item = dynamic_cast<ScenarioItem*>(child(i));
96 item->update();
97 if (!child(i)->isEnabled())
98 {
99 continue;
100 }
101 auto childState = child(i)->data(4).toString().toStdString();
103 {
105 }
107 childState == ApplicationStatus::Stopped)
108 {
110 }
112 childState == ApplicationStatus::Inactive)
113 {
115 }
117 childState == ApplicationStatus::Missing)
118 {
119 // Dont change scenario/package state if an app is missing
120 }
121 else if ((status == ApplicationStatus::Running &&
122 childState == ApplicationStatus::Stopped) ||
124 childState == ApplicationStatus::Running) ||
126 childState == ApplicationStatus::Inactive) ||
128 childState == ApplicationStatus::Inactive) ||
130 childState == ApplicationStatus::Running) ||
132 childState == ApplicationStatus::Stopped))
133 {
135 break;
136 }
137 else if (childState == ApplicationStatus::Waiting)
138 {
140 break;
141 }
142 }
143
144 m_itemData[4] = QString::fromStdString(status);
145 }
146 else
147 {
148 if (application->getInstanceName().empty())
149 {
150 m_itemData[0] = application->getName().c_str();
151 }
152 else
153 {
154 m_itemData[0] = (application->getInstanceName() + "." + application->getName()).c_str();
155 }
156
157 std::string status = application->getStatus();
158 if (!application->getFound())
159 {
160 // Status is shown as "Missing", no need for a warning, info is enough.
161 ARMARX_INFO << "Application '" + application->getExecutableAbsPath() + "' not found!";
162
163 m_itemData[4] = QVariant(QString::fromStdString(ApplicationStatus::Missing));
164 }
166 {
167 m_itemData[4] = QVariant(QString::fromStdString(ApplicationStatus::Running));
168 }
170 {
171 m_itemData[4] = QVariant(QString::fromStdString(ApplicationStatus::Stopped));
172 }
174 {
175 m_itemData[4] = QVariant(QString::fromStdString(ApplicationStatus::Inactive));
176 }
178 {
179 m_itemData[4] = QVariant(QString::fromStdString(ApplicationStatus::Waiting));
180 }
181 else
182 {
183 m_itemData[4] = QVariant(QString::fromStdString(ApplicationStatus::Unknown));
184 }
185
186 setEnabled(application->getEnabled());
187 }
188}
189
190std::string
192{
193 return packageName;
194}
195
198{
199 return scenario;
200}
201
204{
205 return application;
206}
207
210{
211 return applications;
212}
ScenarioManager::Data_Structure::ScenarioPtr getScenario()
If this item represents a Scenario, it is returned.
ScenarioManager::Data_Structure::ApplicationInstancePtr getApplicationInstance()
If this item represents an Application, it is returned.
std::string getPackageName()
ScenarioManager::Data_Structure::ApplicationInstanceVectorPtr getApplicationInstances()
void update()
Clears the item_data and parses the Scenario or Application for new data.
ScenarioItem(QList< QVariant > rootData)
Constructor that sets the data contained in this item.
int childCount() const
Definition treeitem.cpp:57
void appendChild(TreeItem *child)
Definition treeitem.cpp:44
virtual QVariant data(int column) const
Definition treeitem.cpp:69
void setEnabled(bool enabled)
Definition treeitem.cpp:92
bool isEnabled()
Definition treeitem.cpp:98
TreeItem * child(int row)
Definition treeitem.cpp:51
QVector< QVariant > m_itemData
Definition treeitem.h:75
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
std::shared_ptr< Scenario > ScenarioPtr
Definition Scenario.h:35
std::shared_ptr< ApplicationInstance > ApplicationInstancePtr
std::shared_ptr< std::vector< ApplicationInstancePtr > > ApplicationInstanceVectorPtr
This file offers overloads of toIce() and fromIce() functions for STL container types.