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
29namespace armarx
30{
32 LONGTERM_SNAPSHOT_PREFIX("Snapshot_")
33 {
34 widget.setupUi(getWidget());
35 connectSlots();
36 getWidget()->setEnabled(false);
37 }
38
42
43 void
45 {
46 }
47
48 void
50 {
51 }
52
53 void
55 {
56 usingProxy("WorkingMemory");
57 usingProxy("LongtermMemory");
58 }
59
60 void
68
69 void
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
virtual QPointer< QWidget > getWidget()
getWidget returns a pointer to the a widget of this controller.
void enableMainWidgetAsync(bool enable)
This function enables/disables the main widget asynchronously (if called from a non qt thread).
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
void removeSnapshot()
removeSnapshot removes the Snapshot currently selected in the dropdown list from LongtermMemory
~SnapshotControlWidgetController() override
Controller destructor.
void loadSnapshot()
loadSnapshot loads the Snapshot currently selected in the dropdown list into WorkingMemory
void loadSnapshotNames()
loadSnapshotNames fetches the list of available Snapshot names from LongtermMemory
void saveSnapshot()
saveSnapshot saves the current content of WorkingMemory in LongtermMemory under the name provided in ...
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:196
#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
This file offers overloads of toIce() and fromIce() functions for STL container types.