RemoveOperation.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 // std
25 #include <stdexcept>
26 #include <string>
27 
28 // scene3D
29 #include <QtCore/qstatemachine.h>
30 
31 #include <Inventor/SbRotation.h>
32 #include <Inventor/SbVec3f.h>
33 
34 // local
35 #include "RemoveOperation.h"
36 
38  const std::shared_ptr<memoryxcontroller::MemoryXController>& memoryXController,
39  const std::shared_ptr<scene3D::Scene>& scene,
40  const std::string& objectName,
41  const std::string& objectCollection,
42  const SbVec3f& objectPosition,
43  const SbRotation& objectRotation,
44  const std::string& objectId) :
45  Operation(memoryXController, scene, objectId),
46  objectName(objectName),
47  objectCollection(objectCollection),
48  objectPosition(objectPosition),
49  objectRotation(objectRotation)
50 {
51 }
52 
54  const std::shared_ptr<memoryxcontroller::MemoryXController>& memoryXController,
55  const std::shared_ptr<scene3D::Scene>& scene,
56  const std::string& objectId) :
57  Operation(memoryXController, scene, objectId),
58  objectName(),
59  objectCollection(),
60  objectPosition(),
61  objectRotation()
62 {
63 }
64 
67 {
68  if (!(objectName.empty() || objectCollection.empty()))
69  {
70  std::shared_ptr<controller::Operation> inverseOperation(
71  new controller::AddOperation(getMemoryXController(),
72  getScene(),
73  objectName,
74  objectCollection,
75  objectPosition,
76  objectRotation,
77  getObjectId()));
78  return inverseOperation;
79  }
80  else
81  {
82  throw std::runtime_error("Not yet executed");
83  }
84 }
85 
86 void
88 {
89  memoryxcontroller::MemoryXControllerPtr memoryXController = getMemoryXController();
90  /* currently we can not get these informations here; we should not need it, because we get them from the local scene
91  if(!(objectName.empty() || objectCollection.empty()))
92  {
93  objectName = "";
94  objectCollection = "";
95  objectPosition = "";
96  objectRotation = "";
97  }
98  */
99  memoryXController->getWorkingMemoryController()->removeObjectInstance(getObjectId());
100 }
101 
102 void
104 {
105  std::shared_ptr<scene3D::Scene> scene = getScene();
106  scene3D::SceneObjectPtr object = scene->getObjectManager()->getObjectById(getObjectId());
107 
108  if (!object)
109  {
110  throw std::logic_error("Object does not exist");
111  }
112 
113  objectName = object->getClassId();
114  objectCollection = object->getCollection();
115  objectPosition = object->getTranslation();
116  objectRotation = object->getRotation();
117  scene->getObjectManager()->removeObject(object);
118 }
119 
120 bool
122 {
123  std::shared_ptr<scene3D::Scene> scene = getScene();
124  scene3D::SceneObjectPtr object = scene->getObjectManager()->getObjectById(getObjectId());
125 
126  if (!object)
127  {
128  return true;
129  }
130 
131  return object->isMutable();
132 }
RemoveOperation.h
controller::RemoveOperation::executeOnScene
void executeOnScene() override
Removes the object from the local Scene.
Definition: RemoveOperation.cpp:103
controller::RemoveOperation::isExecuteable
bool isExecuteable() override
Returns true, if the SceneObject is mutable.
Definition: RemoveOperation.cpp:121
controller::RemoveOperation::createInverseOperation
const OperationPtr createInverseOperation() const override
Returns a new operation which adds the object again.
Definition: RemoveOperation.cpp:66
controller::RemoveOperation::executeOnWorkingMemory
void executeOnWorkingMemory() override
Removes the object from the WorkingMemory.
Definition: RemoveOperation.cpp:87
controller::OperationPtr
std::shared_ptr< Operation > OperationPtr
Definition: ClassDefinitions.h:54
scene3D::SceneObjectPtr
boost::intrusive_ptr< SceneObject > SceneObjectPtr
Definition: PointerDefinitions.h:40
controller::RemoveOperation::RemoveOperation
RemoveOperation(const std::shared_ptr< memoryxcontroller::MemoryXController > &memoryXController, const std::shared_ptr< scene3D::Scene > &scene, const std::string &objectId)
Creates a new operation, which removes a object.
Definition: RemoveOperation.cpp:53
controller::AddOperation
A Operation to create a new object in the scene and the WorkingMemory.
Definition: AddOperation.h:46
controller::Operation
An abstract class, which offers methods to run operations on the WorkingMemory and the Scene.
Definition: Operation.h:44
memoryxcontroller::MemoryXControllerPtr
std::shared_ptr< MemoryXController > MemoryXControllerPtr
Definition: MemoryXController.h:149