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(
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
86void
88{
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
102void
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
120bool
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}
A Operation to create a new object in the scene and the WorkingMemory.
std::string getObjectId() const
Returns the ID of the object, this Operation is working on.
Definition Operation.cpp:54
const std::shared_ptr< memoryxcontroller::MemoryXController > getMemoryXController() const
Returns the the MemoryXController to execute the Operation at.
Definition Operation.cpp:48
const std::shared_ptr< scene3D::Scene > getScene() const
Returns the the Scene to execute the Operation at.
Definition Operation.cpp:42
Operation(const std::shared_ptr< memoryxcontroller::MemoryXController > &memoryXController, const std::shared_ptr< scene3D::Scene > &scene, const std::string &objectId)
A constructor.
Definition Operation.cpp:26
bool isExecuteable() override
Returns true, if the SceneObject is mutable.
const OperationPtr createInverseOperation() const override
Returns a new operation which adds the object again.
void executeOnScene() override
Removes the object from the local Scene.
void executeOnWorkingMemory() override
Removes the object from the WorkingMemory.
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.
std::shared_ptr< Operation > OperationPtr
std::shared_ptr< MemoryXController > MemoryXControllerPtr
boost::intrusive_ptr< SceneObject > SceneObjectPtr