EventSenderOverview.cpp
Go to the documentation of this file.
1/*
2* This file is part of ArmarX.
3*
4* ArmarX is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License version 2 as
6* published by the Free Software Foundation.
7*
8* ArmarX is distributed in the hope that it will be useful, but
9* WITHOUT ANY WARRANTY; without even the implied warranty of
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* GNU General Public License for more details.
12*
13* You should have received a copy of the GNU General Public License
14* along with this program. If not, see <http://www.gnu.org/licenses/>.
15*
16* @package ArmarX::Gui
17* @author Mirko Waechter ( mirko.waechter at kit dot edu)
18* @date 2012
19* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20* GNU General Public License
21*/
22
23#include "EventSenderOverview.h"
24
25#include <ArmarXGui/gui-plugins/StatechartEventSenderPlugin/ui_EventSenderOverview.h>
26
28
29// ArmarX
31
32using namespace armarx;
33
35
36{
37 lastColumnInsertion = 0;
38 lastRowInsertion = 0;
39 ui->setupUi(getWidget());
40
41 connect(ui->btnAddEventSender, SIGNAL(clicked()), this, SLOT(addEventSender()));
42}
43
48
49void
51{
52 int size = settings->beginReadArray("EventSender");
53
54 for (int i = 0; i < size; ++i)
55 {
56 settings->setArrayIndex(i);
57 EventSenderConfig config;
58 config.loadSettings(settings);
59 addEventSender(config);
60 }
61
62 settings->endArray();
63}
64
65void
67{
68
69 settings->beginWriteArray("EventSender");
70 int size = ui->scrollAreaWidgetContents->children().size();
71 int settingsIndex = 0;
72
73 for (int i = 0; i < size; ++i)
74 {
76 qobject_cast<EventSenderComponent*>(ui->scrollAreaWidgetContents->children().at(i));
77
78 if (!comp)
79 {
80 continue;
81 }
82
83 settings->setArrayIndex(settingsIndex);
84 comp->config.saveSettings(settings);
85 settingsIndex++;
86 }
87
88 settings->endArray();
89}
90
91void
93{
94 int size = ui->scrollAreaWidgetContents->children().size();
95
96 for (int i = 0; i < size; ++i)
97 {
99 qobject_cast<EventSenderComponent*>(ui->scrollAreaWidgetContents->children().at(i));
100
101 if (!comp)
102 {
103 continue;
104 }
105
107 }
108}
109
112{
113 if (config.eventSenderName.length() == 0)
114 {
115 return NULL;
116 }
117
118 // check if eventsender by this name exists
119 int size = ui->scrollAreaWidgetContents->children().size();
120
121 for (int i = 0; i < size; ++i)
122 {
124 qobject_cast<EventSenderComponent*>(ui->scrollAreaWidgetContents->children().at(i));
125
126 if (!comp)
127 {
128 continue;
129 }
130
131 if (ui->edtEventSenderName->text() == comp->config.eventSenderName)
132 {
133 return NULL;
134 }
135 }
136
137 ARMARX_LOG << "Adding EventSender " << config.eventSenderName.toStdString() << flush;
139 new EventSenderComponent(config.eventSenderName, ui->scrollAreaWidgetContents);
141 // comp->setAttribute(Qt::WA_DeleteOnClose,false);
142
143 comp->setConfig(config);
144 ui->scrollAreaVerticalLayout->removeItem(ui->verticalSpacer);
145
146 ui->scrollAreaVerticalLayout->addWidget(comp);
147 ui->scrollAreaVerticalLayout->addItem(ui->verticalSpacer);
148 connect(comp, SIGNAL(sendEvent(EventSenderConfig)), this, SLOT(sendEvent(EventSenderConfig)));
149 return comp;
150}
151
152void
154{
155 EventSenderConfig config;
156 config.eventSenderName = ui->edtEventSenderName->text();
157 addEventSender(config);
158}
159
160void
162{
163 try
164 {
165 RemoteStateOffererInterfacePrx statePrx;
166 statePrx = getProxy<RemoteStateOffererInterfacePrx>(config.componentName.toStdString());
167
168 if (!statePrx)
169 {
170 ARMARX_WARNING << "Proxy is NULL" << flush;
171 return;
172 }
173
174 statePrx->begin_issueEventWithGlobalIdStr(config.globalStateIdentifier, config.event);
175 ARMARX_INFO << "sent event " << config.event->eventName << " to state "
176 << config.globalStateIdentifier << " in component "
177 << config.componentName.toStdString() << flush;
178 ARMARX_INFO << "event parameter count: " << config.event->properties.size() << flush;
179 ARMARX_INFO << "Event dictionary: "
180 << StateUtilFunctions::getDictionaryString(config.event->properties);
181 }
182 catch (Ice::NotRegisteredException& e)
183 {
184 ARMARX_WARNING << "Cannot send event - the entered component with name '"
185 << config.componentName.toStdString()
186 << "' was not found - maybe you forgot to start it?" << flush;
187 }
188 catch (armarx::UserException& e)
189 {
190 ARMARX_WARNING << "Cannot send event - Found component but cannot communicate correctly "
191 "with component - probably it is a component of another type\nreason: "
192 << e.reason << flush;
193 }
194 catch (LocalException& e)
195 {
196 ARMARX_WARNING << "Cannot send event - the entered component with name '"
197 << config.componentName.toStdString()
198 << "' was not found - maybe you forgot to start it?" << flush;
199 }
200 catch (std::exception& e)
201 {
202 ARMARX_WARNING << "Cannot send event - caught exception:\n" << e.what();
203 }
204}
virtual QPointer< QWidget > getWidget()
getWidget returns a pointer to the a widget of this controller.
void setConfig(const EventSenderConfig &conf)
void setIceManager(IceManagerPtr iceMan)
void onInitComponent() override
Pure virtual hook for the subclass.
void sendEvent(const EventSenderConfig &config)
void loadSettings(QSettings *settings) override
Implement to load the settings that are part of the GUI configuration.
void saveSettings(QSettings *settings) override
Implement to save the settings as part of the GUI configuration.
IceManagerPtr getIceManager() const
Returns the IceManager.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
#define ARMARX_LOG
Definition Logging.h:165
ArmarX Headers.
std::string getDictionaryString(const StringVariantContainerBaseMap &mymap)
Converts the map into a string-representation.
This file offers overloads of toIce() and fromIce() functions for STL container types.
const LogSender::manipulator flush
Definition LogSender.h:251
void saveSettings(QSettings *settings)
void loadSettings(QSettings *settings)