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 #include <MemoryX/gui-plugins/SceneEditor/ui_LoadSnapshotDialog.h>
26 
27 #include "../../controller/CreateGroupOperation.h"
28 #include "../../controller/AddToGroupOperation.h"
29 
31  QDialog(parent),
32  ui(new Ui::LoadSnapshotDialog),
34 {
35  ui->setupUi(this);
36  connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accepted()));
37 }
38 
40 {
41  delete ui;
42 }
43 
44 void gui::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 = controller->getMemoryXController()->loadSnapshot(snapshotName.toStdString());
55 
56  while (controller->getScene()->getGroupManager()->getGroupById(groupName + std::to_string(suffix)) != NULL)
57  {
58  ++suffix;
59  }
60 
61  groupName = groupName + std::to_string(suffix);
62  std::shared_ptr<std::vector<controller::OperationPtr> > operations(new std::vector<controller::OperationPtr>());
63  controller::OperationPtr operation(new controller::CreateGroupOperation(controller->getMemoryXController(),
64  controller->getScene(),
65  groupName));
66  operations->push_back(operation);
67 
68  for (std::vector<std::string>::iterator it = allIds.begin(); it != allIds.end(); ++it)
69  {
70  std::string objectId = *it;
71  controller::OperationPtr operation(new controller::AddToGroupOperation(controller->getMemoryXController(),
72  controller->getScene(),
73  groupName,
74  objectId));
75  operations->push_back(operation);
76  }
77 
79  }
80  }
81 }
82 
83 void gui::dialog::LoadSnapshotDialog::showEvent(QShowEvent*)
84 {
86  {
87  ui->comboBoxSnapshots->clear();
88  std::vector<std::string> allSnapshotsVector = controller->getMemoryXController()->getAllSnapshots();
89 
90  for (std::vector<std::string>::iterator it = allSnapshotsVector.begin(); it != allSnapshotsVector.end(); ++it)
91  {
92  ui->comboBoxSnapshots->insertItem(ui->comboBoxSnapshots->count(), QString::fromStdString(*it));
93  }
94  }
95 }
96 
98 {
99  this->ui->retranslateUi(this);
100 }
gui::dialog::LoadSnapshotDialog::retranslate
void retranslate()
Translates all translatable strings in this dialog.
Definition: LoadSnapshotDialog.cpp:97
gui::dialog::LoadSnapshotDialog
Definition: LoadSnapshotDialog.h:37
gui::dialog::LoadSnapshotDialog::~LoadSnapshotDialog
~LoadSnapshotDialog() override
Destructor.
Definition: LoadSnapshotDialog.cpp:39
controller::Controller::EXECUTE_ON_SCENE
static const int EXECUTE_ON_SCENE
A flag to execute operations on the Scene.
Definition: Controller.h:73
LoadSnapshotDialog.h
controller::Controller::UNDOABLE
static const int UNDOABLE
A flag to save the executed operations to the history.
Definition: Controller.h:80
controller
Definition: AddOperation.h:39
Ui
ArmarX Headers.
Definition: ArmarXMainWindow.h:54
controller::ControllerPtr
std::shared_ptr< Controller > ControllerPtr
Definition: ClassDefinitions.h:41
gui::dialog::LoadSnapshotDialog::LoadSnapshotDialog
LoadSnapshotDialog(controller::ControllerPtr control, QWidget *parent=0)
Constructor.
Definition: LoadSnapshotDialog.cpp:30
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:40
controller::CreateGroupOperation
A operation to create a new group.
Definition: CreateGroupOperation.h:41
controller::AddToGroupOperation
A operation to add a object to a existing group.
Definition: AddToGroupOperation.h:41
controller::OperationPtr
std::shared_ptr< Operation > OperationPtr
Definition: ClassDefinitions.h:54
control
This file is part of ArmarX.