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 
27 #include "EventSenderComponent.h"
28 
29 // ArmarX
31 
32 using 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 
45 {
46  delete ui;
47 }
48 
49 void
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 
65 void
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  {
75  EventSenderComponent* comp =
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 
91 void
93 {
94  int size = ui->scrollAreaWidgetContents->children().size();
95 
96  for (int i = 0; i < size; ++i)
97  {
98  EventSenderComponent* comp =
99  qobject_cast<EventSenderComponent*>(ui->scrollAreaWidgetContents->children().at(i));
100 
101  if (!comp)
102  {
103  continue;
104  }
105 
106  comp->setIceManager(getIceManager());
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  {
123  EventSenderComponent* comp =
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;
138  EventSenderComponent* comp =
139  new EventSenderComponent(config.eventSenderName, ui->scrollAreaWidgetContents);
140  comp->setIceManager(getIceManager());
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 
152 void
154 {
155  EventSenderConfig config;
156  config.eventSenderName = ui->edtEventSenderName->text();
157  addEventSender(config);
158 }
159 
160 void
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 }
armarx::EventSenderComponent::config
EventSenderConfig config
Definition: EventSenderComponent.h:42
armarx::ManagedIceObject::getIceManager
IceManagerPtr getIceManager() const
Returns the IceManager.
Definition: ManagedIceObject.cpp:366
armarx::EventSenderConfig::loadSettings
void loadSettings(QSettings *settings)
Definition: EventSenderConfig.cpp:103
armarx::EventSenderConfig::componentName
QString componentName
Definition: EventSenderConfig.h:56
armarx::EventSenderComponent::setConfig
void setConfig(const EventSenderConfig &conf)
Definition: EventSenderComponent.cpp:128
armarx::EventSenderOverview::sendEvent
void sendEvent(const EventSenderConfig &config)
Definition: EventSenderOverview.cpp:161
armarx::EventSenderConfig::eventSenderName
QString eventSenderName
Definition: EventSenderConfig.h:54
armarx::EventSenderConfig::saveSettings
void saveSettings(QSettings *settings)
Definition: EventSenderConfig.cpp:74
armarx::EventSenderComponent::setIceManager
void setIceManager(IceManagerPtr iceMan)
Definition: EventSenderComponent.cpp:141
armarx::EventSenderOverview::EventSenderOverview
EventSenderOverview()
Definition: EventSenderOverview.cpp:34
armarx::EventSenderConfig
Definition: EventSenderConfig.h:52
armarx::EventSenderComponent
Definition: EventSenderComponent.h:36
armarx::EventSenderOverview::saveSettings
void saveSettings(QSettings *settings) override
Implement to save the settings as part of the GUI configuration.
Definition: EventSenderOverview.cpp:66
Statechart.h
EventSenderOverview.h
EventSenderComponent.h
armarx::EventSenderOverview::onInitComponent
void onInitComponent() override
Pure virtual hook for the subclass.
Definition: EventSenderOverview.cpp:92
Ui
ArmarX Headers.
Definition: ArmarXMainWindow.h:54
armarx::EventSenderConfig::globalStateIdentifier
std::string globalStateIdentifier
Definition: EventSenderConfig.h:58
armarx::flush
const LogSender::manipulator flush
Definition: LogSender.h:251
armarx::EventSenderOverview::addEventSender
void addEventSender()
Definition: EventSenderOverview.cpp:153
armarx::EventSenderConfig::event
EventPtr event
Definition: EventSenderConfig.h:57
armarx::EventSenderOverview::loadSettings
void loadSettings(QSettings *settings) override
Implement to load the settings that are part of the GUI configuration.
Definition: EventSenderOverview.cpp:50
ARMARX_LOG
#define ARMARX_LOG
Definition: Logging.h:165
armarx::StateUtilFunctions::getDictionaryString
std::string getDictionaryString(const StringVariantContainerBaseMap &mymap)
Converts the map into a string-representation.
Definition: StateUtilFunctions.cpp:251
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
armarx::ArmarXWidgetController::getWidget
virtual QPointer< QWidget > getWidget()
getWidget returns a pointer to the a widget of this controller.
Definition: ArmarXWidgetController.cpp:54
armarx::EventSenderOverview
Definition: EventSenderOverview.h:128
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:193
armarx::EventSenderOverview::~EventSenderOverview
~EventSenderOverview() override
Definition: EventSenderOverview.cpp:44
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27