LoadSnapshotDialog.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::SceneEditor
19 * @date 2015
20 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
21 * GNU General Public License
22 */
23
24#include "LoadSnapshotDialog.h"
25
28#include <MemoryX/gui-plugins/SceneEditor/ui_LoadSnapshotDialog.h>
29
31 QWidget* parent) :
32 QDialog(parent), ui(new Ui::LoadSnapshotDialog), control(control)
33{
34 ui->setupUi(this);
35 connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accepted()));
36}
37
42
43void
44gui::dialog::LoadSnapshotDialog::accepted()
45{
47 {
48 QString snapshotName = ui->comboBoxSnapshots->currentText();
49
50 if (snapshotName != "")
51 {
52 std::string groupName = snapshotName.toStdString();
53 int suffix = 1;
54 std::vector<std::string> allIds =
55 controller->getMemoryXController()->loadSnapshot(snapshotName.toStdString());
56
57 while (controller->getScene()->getGroupManager()->getGroupById(
58 groupName + std::to_string(suffix)) != NULL)
59 {
60 ++suffix;
61 }
62
63 groupName = groupName + std::to_string(suffix);
64 std::shared_ptr<std::vector<controller::OperationPtr>> operations(
65 new std::vector<controller::OperationPtr>());
67 controller->getMemoryXController(), controller->getScene(), groupName));
68 operations->push_back(operation);
69
70 for (std::vector<std::string>::iterator it = allIds.begin(); it != allIds.end(); ++it)
71 {
72 std::string objectId = *it;
74 new controller::AddToGroupOperation(controller->getMemoryXController(),
75 controller->getScene(),
76 groupName,
77 objectId));
78 operations->push_back(operation);
79 }
80
83 operations);
84 }
85 }
86}
87
88void
89gui::dialog::LoadSnapshotDialog::showEvent(QShowEvent*)
90{
91 if (controller::ControllerPtr controller = control.lock())
92 {
93 ui->comboBoxSnapshots->clear();
94 std::vector<std::string> allSnapshotsVector =
95 controller->getMemoryXController()->getAllSnapshots();
96
97 for (std::vector<std::string>::iterator it = allSnapshotsVector.begin();
98 it != allSnapshotsVector.end();
99 ++it)
100 {
101 ui->comboBoxSnapshots->insertItem(ui->comboBoxSnapshots->count(),
102 QString::fromStdString(*it));
103 }
104 }
105}
106
107void
109{
110 this->ui->retranslateUi(this);
111}
A operation to add a object to a existing group.
static const int UNDOABLE
A flag to save the executed operations to the history.
Definition Controller.h:80
static const int EXECUTE_ON_SCENE
A flag to execute operations on the Scene.
Definition Controller.h:73
A operation to create a new group.
LoadSnapshotDialog(controller::ControllerPtr control, QWidget *parent=0)
Constructor.
~LoadSnapshotDialog() override
Destructor.
void retranslate()
Translates all translatable strings in this dialog.
ArmarX Headers.
This file is part of ArmarX.
std::shared_ptr< Controller > ControllerPtr
std::shared_ptr< Operation > OperationPtr