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 #include <ArmarXGui/gui-plugins/StatechartEventSenderPlugin/ui_EventSenderOverview.h>
25 
26 #include "EventSenderComponent.h"
27 
28 // ArmarX
30 
31 using namespace armarx;
32 
33 
35  ui(new Ui::EventSenderOverview())
36 
37 {
38  lastColumnInsertion = 0;
39  lastRowInsertion = 0;
40  ui->setupUi(getWidget());
41 
42  connect(ui->btnAddEventSender, SIGNAL(clicked()), this, SLOT(addEventSender()));
43 }
45 {
46  delete ui;
47 }
48 
49 void EventSenderOverview::loadSettings(QSettings* settings)
50 {
51  int size = settings->beginReadArray("EventSender");
52 
53  for (int i = 0; i < size; ++i)
54  {
55  settings->setArrayIndex(i);
56  EventSenderConfig config;
57  config.loadSettings(settings);
58  addEventSender(config);
59  }
60 
61  settings->endArray();
62 }
63 
64 void EventSenderOverview::saveSettings(QSettings* settings)
65 {
66 
67  settings->beginWriteArray("EventSender");
68  int size = ui->scrollAreaWidgetContents->children().size();
69  int settingsIndex = 0;
70 
71  for (int i = 0; i < size; ++i)
72  {
73  EventSenderComponent* comp = qobject_cast<EventSenderComponent*>(ui->scrollAreaWidgetContents->children().at(i));
74 
75  if (!comp)
76  {
77  continue;
78  }
79 
80  settings->setArrayIndex(settingsIndex);
81  comp->config.saveSettings(settings);
82  settingsIndex++;
83  }
84 
85  settings->endArray();
86 }
87 
89 {
90  int size = ui->scrollAreaWidgetContents->children().size();
91 
92  for (int i = 0; i < size; ++i)
93  {
94  EventSenderComponent* comp = qobject_cast<EventSenderComponent*>(ui->scrollAreaWidgetContents->children().at(i));
95 
96  if (!comp)
97  {
98  continue;
99  }
100 
101  comp->setIceManager(getIceManager());
102  }
103 }
104 
106 {
107  if (config.eventSenderName.length() == 0)
108  {
109  return NULL;
110  }
111 
112  // check if eventsender by this name exists
113  int size = ui->scrollAreaWidgetContents->children().size();
114 
115  for (int i = 0; i < size; ++i)
116  {
117  EventSenderComponent* comp = qobject_cast<EventSenderComponent*>(ui->scrollAreaWidgetContents->children().at(i));
118 
119  if (!comp)
120  {
121  continue;
122  }
123 
124  if (ui->edtEventSenderName->text() == comp->config.eventSenderName)
125  {
126  return NULL;
127  }
128  }
129 
130  ARMARX_LOG << "Adding EventSender " << config.eventSenderName.toStdString() << flush;
131  EventSenderComponent* comp = new EventSenderComponent(config.eventSenderName, ui->scrollAreaWidgetContents);
132  comp->setIceManager(getIceManager());
133  // comp->setAttribute(Qt::WA_DeleteOnClose,false);
134 
135  comp->setConfig(config);
136  ui->scrollAreaVerticalLayout->removeItem(ui->verticalSpacer);
137 
138  ui->scrollAreaVerticalLayout->addWidget(comp);
139  ui->scrollAreaVerticalLayout->addItem(ui->verticalSpacer);
140  connect(comp, SIGNAL(sendEvent(EventSenderConfig)), this, SLOT(sendEvent(EventSenderConfig)));
141  return comp;
142 }
143 
145 {
146  EventSenderConfig config;
147  config.eventSenderName = ui->edtEventSenderName->text();
148  addEventSender(config);
149 }
150 
152 {
153  try
154  {
155  RemoteStateOffererInterfacePrx statePrx;
156  statePrx = getProxy<RemoteStateOffererInterfacePrx>(config.componentName.toStdString());
157 
158  if (!statePrx)
159  {
160  ARMARX_WARNING << "Proxy is NULL" << flush;
161  return;
162  }
163 
164  statePrx->begin_issueEventWithGlobalIdStr(config.globalStateIdentifier, config.event);
165  ARMARX_INFO << "sent event " << config.event->eventName << " to state " << config.globalStateIdentifier << " in component " << config.componentName.toStdString() << flush;
166  ARMARX_INFO << "event parameter count: " << config.event->properties.size() << flush;
167  ARMARX_INFO << "Event dictionary: " << StateUtilFunctions::getDictionaryString(config.event->properties);
168  }
169  catch (Ice::NotRegisteredException& e)
170  {
171  ARMARX_WARNING << "Cannot send event - the entered component with name '" << config.componentName.toStdString() << "' was not found - maybe you forgot to start it?" << flush;
172  }
173  catch (armarx::UserException& e)
174  {
175  ARMARX_WARNING << "Cannot send event - Found component but cannot communicate correctly with component - probably it is a component of another type\nreason: " << e.reason << flush;
176  }
177  catch (LocalException& e)
178  {
179  ARMARX_WARNING << "Cannot send event - the entered component with name '" << config.componentName.toStdString() << "' was not found - maybe you forgot to start it?" << flush;
180  }
181  catch (std::exception& e)
182  {
183  ARMARX_WARNING << "Cannot send event - caught exception:\n" << e.what();
184  }
185 }
armarx::EventSenderComponent::config
EventSenderConfig config
Definition: EventSenderComponent.h:44
armarx::ManagedIceObject::getIceManager
IceManagerPtr getIceManager() const
Returns the IceManager.
Definition: ManagedIceObject.cpp:353
armarx::EventSenderConfig::loadSettings
void loadSettings(QSettings *settings)
Definition: EventSenderConfig.cpp:101
armarx::EventSenderConfig::componentName
QString componentName
Definition: EventSenderConfig.h:56
armarx::EventSenderComponent::setConfig
void setConfig(const EventSenderConfig &conf)
Definition: EventSenderComponent.cpp:126
armarx::EventSenderOverview::sendEvent
void sendEvent(const EventSenderConfig &config)
Definition: EventSenderOverview.cpp:151
armarx::EventSenderConfig::eventSenderName
QString eventSenderName
Definition: EventSenderConfig.h:54
armarx::EventSenderConfig::saveSettings
void saveSettings(QSettings *settings)
Definition: EventSenderConfig.cpp:72
armarx::EventSenderComponent::setIceManager
void setIceManager(IceManagerPtr iceMan)
Definition: EventSenderComponent.cpp:139
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:64
Statechart.h
EventSenderOverview.h
EventSenderComponent.h
armarx::EventSenderOverview::onInitComponent
void onInitComponent() override
Pure virtual hook for the subclass.
Definition: EventSenderOverview.cpp:88
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:144
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:49
ARMARX_LOG
#define ARMARX_LOG
Definition: Logging.h:163
armarx::StateUtilFunctions::getDictionaryString
std::string getDictionaryString(const StringVariantContainerBaseMap &mymap)
Converts the map into a string-representation.
Definition: StateUtilFunctions.cpp:232
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
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:186
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:28