SceneGroupManager.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 <algorithm>
25 
26 #include "SceneGroupManager.h"
27 
28 std::vector<scene3D::SceneGroupPtr> scene3D::SceneGroupManager::getAllGroups()
29 {
30  return sceneGroups;
31 }
32 
34 {
35  for (SceneGroupPtr group : sceneGroups)
36  {
37  if (group->getGroupId().compare(groupId) == 0)
38  {
39  return group;
40  }
41  }
42 
43  return scene3D::SceneGroupPtr();
44 }
45 
47 {
48  //Check whether an object with same ID already exists
49  if (this->getGroupById(group->getGroupId()) != NULL)
50  {
51  throw std::logic_error("Group already exists!");
52  }
53 
54  //Otherwise push object in our list
55  sceneGroups.push_back(group);
56 }
57 
59 {
60  if (group != NULL)
61  {
62  if (std::find(sceneGroups.begin(), sceneGroups.end(), group) != sceneGroups.end())
63  {
64  //Remove object from list
65  sceneGroups.erase(std::remove(sceneGroups.begin(), sceneGroups.end(), group), sceneGroups.end());
66  }
67  else
68  {
69  throw std::runtime_error("This group is not registered in the sceneGroupManager!");
70  }
71  }
72  else
73  {
74  throw std::runtime_error("Group is null!");
75  }
76 }
77 
79 {
80  if (this->getGroupById(newGroupId) != NULL)
81  {
82  throw std::invalid_argument("New ID of Group already exists!");
83  }
84 
85  //Otherwise change ID of group
86  group->setGroupId(newGroupId);
87 }
scene3D::SceneGroupManager::removeGroup
void removeGroup(scene3D::SceneGroupPtr group)
Removes a SceneGroup.
Definition: SceneGroupManager.cpp:58
scene3D::SceneGroupManager::getAllGroups
std::vector< scene3D::SceneGroupPtr > getAllGroups()
Returns all SceneGroups.
Definition: SceneGroupManager.cpp:28
SceneGroupManager.h
scene3D::SceneGroupManager::renameGroup
void renameGroup(scene3D::SceneGroupPtr group, std::string newGroupId)
Renames a SceneGroup.
Definition: SceneGroupManager.cpp:78
scene3D::SceneGroupManager::getGroupById
scene3D::SceneGroupPtr getGroupById(std::string groupId)
Returns a SceneGroup specified by an ID.
Definition: SceneGroupManager.cpp:33
scene3D::SceneGroupPtr
std::shared_ptr< SceneGroup > SceneGroupPtr
Definition: PointerDefinitions.h:53
scene3D::SceneGroupManager::addGroup
void addGroup(SceneGroupPtr group)
Adds a SceneGroup.
Definition: SceneGroupManager.cpp:46