SnapshotControlWidgetController.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2012-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 MemoryX::gui-plugins::SnapshotControlWidgetController
19  * @author Manfred Kroehnert ( Manfred dot Kroehnert at kit dot edu )
20  * @date 2014
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
26 
27 #include <SimoxUtility/algorithm/string/string_tools.h>
28 
29 namespace armarx
30 {
32  LONGTERM_SNAPSHOT_PREFIX("Snapshot_")
33  {
34  widget.setupUi(getWidget());
35  connectSlots();
36  getWidget()->setEnabled(false);
37  }
38 
40  {
41  }
42 
43  void
45  {
46  }
47 
48  void
50  {
51  }
52 
53  void
55  {
56  usingProxy("WorkingMemory");
57  usingProxy("LongtermMemory");
58  }
59 
60  void
62  {
63  workingMemoryPrx = getProxy<memoryx::WorkingMemoryInterfacePrx>("WorkingMemory");
64  longtermMemoryPrx = getProxy<memoryx::LongtermMemoryInterfacePrx>("LongtermMemory");
67  }
68 
69  void
71  {
72  enableMainWidgetAsync(false);
73  }
74 
75  void
76  SnapshotControlWidgetController::connectSlots()
77  {
78  connect(widget.loadSnapshotButton, SIGNAL(clicked()), this, SLOT(loadSnapshot()));
79  connect(widget.removeSnapshotButton, SIGNAL(clicked()), this, SLOT(removeSnapshot()));
80  connect(widget.saveSnapshotButton, SIGNAL(clicked()), this, SLOT(saveSnapshot()));
81  connect(widget.snapshotName,
82  SIGNAL(textChanged(QString)),
83  this,
84  SLOT(snapshotNameChanged(QString)));
85  widget.loadSnapshotButton->setEnabled(false);
86  widget.removeSnapshotButton->setEnabled(false);
87  widget.saveSnapshotButton->setEnabled(false);
88  }
89 
90  void
91  SnapshotControlWidgetController::snapshotNameChanged(const QString& snapshotName)
92  {
93  widget.saveSnapshotButton->setEnabled(!snapshotName.isEmpty());
94  }
95 
96  void
98  {
99  NameList snapshotNames = longtermMemoryPrx->getSnapshotNames();
100  widget.availableSnapshotsList->clear();
101 
102  for (auto snapshotName : snapshotNames)
103  {
104  widget.availableSnapshotsList->addItem(QString::fromStdString(snapshotName));
105  }
106 
107  if (!snapshotNames.empty())
108  {
109  widget.loadSnapshotButton->setEnabled(true);
110  widget.removeSnapshotButton->setEnabled(true);
111  }
112  }
113 
114  void
116  {
117  const std::string snapshotName = widget.availableSnapshotsList->currentText().toStdString();
118 
119  if (snapshotName.empty())
120  {
121  return;
122  }
123 
124  try
125  {
126  ARMARX_INFO << "Loading Snapshot with Name: " << snapshotName;
127  longtermMemoryPrx->loadWorkingMemorySnapshot(snapshotName, workingMemoryPrx);
128  ARMARX_INFO << "Snapshot succcessfully loaded: " << snapshotName;
129  }
130  catch (const armarx::LocalException& e)
131  {
132  ARMARX_ERROR << "SnapshotName could not be loaded: " << snapshotName;
133  }
134 
136  }
137 
138  void
140  {
141  const std::string snapshotName = widget.availableSnapshotsList->currentText().toStdString();
142 
143  if (snapshotName.empty())
144  {
145  return;
146  }
147 
148  try
149  {
150  ARMARX_INFO << "Removing Snapshot with Name: " << snapshotName;
151  longtermMemoryPrx->removeWorkingMemorySnapshot(snapshotName);
152  ARMARX_INFO << "Snapshot succcessfully removed: " << snapshotName;
153  }
154  catch (const armarx::LocalException& e)
155  {
156  ARMARX_ERROR << "SnapshotName could not be removed: " << snapshotName;
157  }
158 
160  }
161 
162  void
164  {
165  std::string snapshotName = widget.snapshotName->text().toStdString();
166 
167  if (snapshotName.empty())
168  {
169  return;
170  }
171 
172  if (!simox::alg::starts_with(snapshotName, LONGTERM_SNAPSHOT_PREFIX))
173  {
174  snapshotName = std::string(LONGTERM_SNAPSHOT_PREFIX) + snapshotName;
175  ARMARX_WARNING << "Snapshot name must start with <" << LONGTERM_SNAPSHOT_PREFIX
176  << ">. Changing to " << snapshotName;
177  }
178 
179  ARMARX_LOG << "Saving snapshot: " << snapshotName;
180  longtermMemoryPrx->saveWorkingMemorySnapshot(snapshotName, workingMemoryPrx);
182  }
183 } // namespace armarx
armarx::SnapshotControlWidgetController::SnapshotControlWidgetController
SnapshotControlWidgetController()
Controller Constructor.
Definition: SnapshotControlWidgetController.cpp:31
armarx::SnapshotControlWidgetController::removeSnapshot
void removeSnapshot()
removeSnapshot removes the Snapshot currently selected in the dropdown list from LongtermMemory
Definition: SnapshotControlWidgetController.cpp:139
armarx::SnapshotControlWidgetController::saveSnapshot
void saveSnapshot()
saveSnapshot saves the current content of WorkingMemory in LongtermMemory under the name provided in ...
Definition: SnapshotControlWidgetController.cpp:163
armarx::SnapshotControlWidgetController::loadSnapshotNames
void loadSnapshotNames()
loadSnapshotNames fetches the list of available Snapshot names from LongtermMemory
Definition: SnapshotControlWidgetController.cpp:97
armarx::SnapshotControlWidgetController::onConnectComponent
void onConnectComponent() override
Definition: SnapshotControlWidgetController.cpp:61
armarx::SnapshotControlWidgetController::loadSettings
void loadSettings(QSettings *settings) override
Definition: SnapshotControlWidgetController.cpp:44
armarx::starts_with
bool starts_with(const std::string &haystack, const std::string &needle)
Definition: StringHelpers.cpp:47
SnapshotControlWidgetController.h
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:196
armarx::SnapshotControlWidgetController::onInitComponent
void onInitComponent() override
Definition: SnapshotControlWidgetController.cpp:54
ARMARX_LOG
#define ARMARX_LOG
Definition: Logging.h:165
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
armarx::ArmarXWidgetController::enableMainWidgetAsync
void enableMainWidgetAsync(bool enable)
This function enables/disables the main widget asynchronously (if called from a non qt thread).
Definition: ArmarXWidgetController.cpp:191
armarx::SnapshotControlWidgetController::~SnapshotControlWidgetController
~SnapshotControlWidgetController() override
Controller destructor.
Definition: SnapshotControlWidgetController.cpp:39
armarx::SnapshotControlWidgetController::onDisconnectComponent
void onDisconnectComponent() override
Definition: SnapshotControlWidgetController.cpp:70
armarx::ArmarXWidgetController::getWidget
virtual QPointer< QWidget > getWidget()
getWidget returns a pointer to the a widget of this controller.
Definition: ArmarXWidgetController.cpp:54
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:193
armarx::SnapshotControlWidgetController::loadSnapshot
void loadSnapshot()
loadSnapshot loads the Snapshot currently selected in the dropdown list into WorkingMemory
Definition: SnapshotControlWidgetController.cpp:115
armarx::ManagedIceObject::usingProxy
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Definition: ManagedIceObject.cpp:154
armarx::SnapshotControlWidgetController::saveSettings
void saveSettings(QSettings *settings) override
Definition: SnapshotControlWidgetController.cpp:49
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27