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 <Inventor/SbVec3f.h>
30 #include <Inventor/SbRotation.h>
31 #include <QtCore/qstatemachine.h>
32 
33 // local
34 #include "RemoveOperation.h"
35 
36 controller::RemoveOperation::RemoveOperation(const std::shared_ptr<memoryxcontroller::MemoryXController>& memoryXController, const std::shared_ptr<scene3D::Scene>& scene, const std::string& objectName, const std::string& objectCollection, const SbVec3f& objectPosition, const SbRotation& objectRotation, const std::string& objectId) :
37  Operation(memoryXController, scene, objectId),
38  objectName(objectName),
39  objectCollection(objectCollection),
40  objectPosition(objectPosition),
41  objectRotation(objectRotation)
42 {
43 }
44 
45 controller::RemoveOperation::RemoveOperation(const std::shared_ptr<memoryxcontroller::MemoryXController>& memoryXController, const std::shared_ptr<scene3D::Scene>& scene, const std::string& objectId) :
46  Operation(memoryXController, scene, objectId),
47  objectName(),
48  objectCollection(),
49  objectPosition(),
50  objectRotation()
51 {
52 }
53 
55 {
56  if (!(objectName.empty() || objectCollection.empty()))
57  {
58  std::shared_ptr<controller::Operation> inverseOperation(new controller::AddOperation(getMemoryXController(), getScene(), objectName, objectCollection, objectPosition, objectRotation, getObjectId()));
59  return inverseOperation;
60  }
61  else
62  {
63  throw std::runtime_error("Not yet executed");
64  }
65 }
66 
68 {
69  memoryxcontroller::MemoryXControllerPtr memoryXController = getMemoryXController();
70  /* currently we can not get these informations here; we should not need it, because we get them from the local scene
71  if(!(objectName.empty() || objectCollection.empty()))
72  {
73  objectName = "";
74  objectCollection = "";
75  objectPosition = "";
76  objectRotation = "";
77  }
78  */
79  memoryXController->getWorkingMemoryController()->removeObjectInstance(getObjectId());
80 }
81 
83 {
84  std::shared_ptr<scene3D::Scene> scene = getScene();
85  scene3D::SceneObjectPtr object = scene->getObjectManager()->getObjectById(getObjectId());
86 
87  if (!object)
88  {
89  throw std::logic_error("Object does not exist");
90  }
91 
92  objectName = object->getClassId();
93  objectCollection = object->getCollection();
94  objectPosition = object->getTranslation();
95  objectRotation = object->getRotation();
96  scene->getObjectManager()->removeObject(object);
97 }
98 
100 {
101  std::shared_ptr<scene3D::Scene> scene = getScene();
102  scene3D::SceneObjectPtr object = scene->getObjectManager()->getObjectById(getObjectId());
103 
104  if (!object)
105  {
106  return true;
107  }
108 
109  return object->isMutable();
110 }
RemoveOperation.h
controller::RemoveOperation::executeOnScene
void executeOnScene() override
Removes the object from the local Scene.
Definition: RemoveOperation.cpp:82
controller::RemoveOperation::isExecuteable
bool isExecuteable() override
Returns true, if the SceneObject is mutable.
Definition: RemoveOperation.cpp:99
controller::RemoveOperation::createInverseOperation
const OperationPtr createInverseOperation() const override
Returns a new operation which adds the object again.
Definition: RemoveOperation.cpp:54
controller::RemoveOperation::executeOnWorkingMemory
void executeOnWorkingMemory() override
Removes the object from the WorkingMemory.
Definition: RemoveOperation.cpp:67
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:45
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:146