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 
30 namespace armarx
31 {
33  LONGTERM_SNAPSHOT_PREFIX("Snapshot_")
34  {
35  widget.setupUi(getWidget());
36  connectSlots();
37  getWidget()->setEnabled(false);
38  }
39 
40 
42  {
43 
44  }
45 
46 
48  {
49 
50  }
51 
52 
54  {
55 
56  }
57 
58 
60  {
61  usingProxy("WorkingMemory");
62  usingProxy("LongtermMemory");
63  }
64 
65 
67  {
68  workingMemoryPrx = getProxy<memoryx::WorkingMemoryInterfacePrx>("WorkingMemory");
69  longtermMemoryPrx = getProxy<memoryx::LongtermMemoryInterfacePrx>("LongtermMemory");
72  }
73 
74 
76  {
77  enableMainWidgetAsync(false);
78  }
79 
80 
81  void SnapshotControlWidgetController::connectSlots()
82  {
83  connect(widget.loadSnapshotButton, SIGNAL(clicked()), this, SLOT(loadSnapshot()));
84  connect(widget.removeSnapshotButton, SIGNAL(clicked()), this, SLOT(removeSnapshot()));
85  connect(widget.saveSnapshotButton, SIGNAL(clicked()), this, SLOT(saveSnapshot()));
86  connect(widget.snapshotName, SIGNAL(textChanged(QString)), this, SLOT(snapshotNameChanged(QString)));
87  widget.loadSnapshotButton->setEnabled(false);
88  widget.removeSnapshotButton->setEnabled(false);
89  widget.saveSnapshotButton->setEnabled(false);
90  }
91 
92 
93  void SnapshotControlWidgetController::snapshotNameChanged(const QString& snapshotName)
94  {
95  widget.saveSnapshotButton->setEnabled(!snapshotName.isEmpty());
96  }
97 
98 
100  {
101  NameList snapshotNames = longtermMemoryPrx->getSnapshotNames();
102  widget.availableSnapshotsList->clear();
103 
104  for (auto snapshotName : snapshotNames)
105  {
106  widget.availableSnapshotsList->addItem(QString::fromStdString(snapshotName));
107  }
108 
109  if (!snapshotNames.empty())
110  {
111  widget.loadSnapshotButton->setEnabled(true);
112  widget.removeSnapshotButton->setEnabled(true);
113  }
114  }
115 
116 
117 
119  {
120  const std::string snapshotName = widget.availableSnapshotsList->currentText().toStdString();
121 
122  if (snapshotName.empty())
123  {
124  return;
125  }
126 
127  try
128  {
129  ARMARX_INFO << "Loading Snapshot with Name: " << snapshotName;
130  longtermMemoryPrx->loadWorkingMemorySnapshot(snapshotName, workingMemoryPrx);
131  ARMARX_INFO << "Snapshot succcessfully loaded: " << snapshotName;
132  }
133  catch (const armarx::LocalException& e)
134  {
135  ARMARX_ERROR << "SnapshotName could not be loaded: " << snapshotName;
136  }
137 
139  }
140 
141 
143  {
144  const std::string snapshotName = widget.availableSnapshotsList->currentText().toStdString();
145 
146  if (snapshotName.empty())
147  {
148  return;
149  }
150 
151  try
152  {
153  ARMARX_INFO << "Removing Snapshot with Name: " << snapshotName;
154  longtermMemoryPrx->removeWorkingMemorySnapshot(snapshotName);
155  ARMARX_INFO << "Snapshot succcessfully removed: " << snapshotName;
156  }
157  catch (const armarx::LocalException& e)
158  {
159  ARMARX_ERROR << "SnapshotName could not be removed: " << snapshotName;
160  }
161 
163  }
164 
165 
167  {
168  std::string snapshotName = widget.snapshotName->text().toStdString();
169 
170  if (snapshotName.empty())
171  {
172  return;
173  }
174 
175  if (!simox::alg::starts_with(snapshotName, LONGTERM_SNAPSHOT_PREFIX))
176  {
177  snapshotName = std::string(LONGTERM_SNAPSHOT_PREFIX) + snapshotName;
178  ARMARX_WARNING << "Snapshot name must start with <" << LONGTERM_SNAPSHOT_PREFIX << ">. Changing to " << snapshotName;
179  }
180 
181  ARMARX_LOG << "Saving snapshot: " << snapshotName;
182  longtermMemoryPrx->saveWorkingMemorySnapshot(snapshotName, workingMemoryPrx);
184  }
185 }
armarx::SnapshotControlWidgetController::SnapshotControlWidgetController
SnapshotControlWidgetController()
Controller Constructor.
Definition: SnapshotControlWidgetController.cpp:32
armarx::SnapshotControlWidgetController::removeSnapshot
void removeSnapshot()
removeSnapshot removes the Snapshot currently selected in the dropdown list from LongtermMemory
Definition: SnapshotControlWidgetController.cpp:142
armarx::SnapshotControlWidgetController::saveSnapshot
void saveSnapshot()
saveSnapshot saves the current content of WorkingMemory in LongtermMemory under the name provided in ...
Definition: SnapshotControlWidgetController.cpp:166
armarx::SnapshotControlWidgetController::loadSnapshotNames
void loadSnapshotNames()
loadSnapshotNames fetches the list of available Snapshot names from LongtermMemory
Definition: SnapshotControlWidgetController.cpp:99
armarx::SnapshotControlWidgetController::onConnectComponent
void onConnectComponent() override
Definition: SnapshotControlWidgetController.cpp:66
armarx::SnapshotControlWidgetController::loadSettings
void loadSettings(QSettings *settings) override
Definition: SnapshotControlWidgetController.cpp:47
armarx::starts_with
bool starts_with(const std::string &haystack, const std::string &needle)
Definition: StringHelpers.cpp:43
SnapshotControlWidgetController.h
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:189
armarx::SnapshotControlWidgetController::onInitComponent
void onInitComponent() override
Definition: SnapshotControlWidgetController.cpp:59
ARMARX_LOG
#define ARMARX_LOG
Definition: Logging.h:163
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
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:174
armarx::SnapshotControlWidgetController::~SnapshotControlWidgetController
~SnapshotControlWidgetController() override
Controller destructor.
Definition: SnapshotControlWidgetController.cpp:41
armarx::SnapshotControlWidgetController::onDisconnectComponent
void onDisconnectComponent() override
Definition: SnapshotControlWidgetController.cpp:75
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:186
armarx::SnapshotControlWidgetController::loadSnapshot
void loadSnapshot()
loadSnapshot loads the Snapshot currently selected in the dropdown list into WorkingMemory
Definition: SnapshotControlWidgetController.cpp:118
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:151
armarx::SnapshotControlWidgetController::saveSettings
void saveSettings(QSettings *settings) override
Definition: SnapshotControlWidgetController.cpp:53
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28