AddOperation.h
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#pragma once
25
26// std
27#include <exception>
28#include <string>
29
30// scene3D
31#include <Inventor/SbRotation.h>
32#include <Inventor/SbVec3f.h>
33
34// local
36#include "../scene3D/Scene.h"
37#include "Operation.h"
38
39namespace controller
40{
41 /**
42 * A Operation to create a new object in the scene and the WorkingMemory.
43 *
44 * @see controller::Operation
45 */
46 class AddOperation : public Operation
47 {
48 public:
49 /**
50 * Creates a new operation, which is a copy of the given operation, but has a new random ID.
51 *
52 * @param operation The operation to copy;
53 */
54 AddOperation(const AddOperation& operation);
55
56 /**
57 * Creates a new operation, which adds a new object.
58 *
59 * @param memoryXController The MemoryXController to add the object at.
60 * @param scene The scene to add the object at.
61 * @param objectName The name of the class of the object. This is used to identify the class in PriorKnowledge.
62 * @param objectCollection The name of the collection where the object is in. This is used to identify the class in PriorKnowledge.
63 * @param objectPosition The position where the object should be added.
64 * @param objectRotation The rotation to add the object with.
65 * @param objectId The object id to create the object with.
66 *
67 * @see controller::Operation::Operation
68 */
69 AddOperation(const std::shared_ptr<memoryxcontroller::MemoryXController>& memoryXController,
70 const std::shared_ptr<scene3D::Scene>& scene,
71 const std::string& objectName,
72 const std::string& objectCollection,
73 const SbVec3f& objectPosition,
74 const SbRotation& objectRotation,
75 const std::string& objectId);
76
77 /**
78 * Creates a new operation, which adds a new object.
79 * A new random object ID is created in this operation.
80 *
81 * @param memoryXController The MemoryXController to add the object at.
82 * @param scene The scene to add the object at.
83 * @param objectName The name of the class of the object. This is used to identify the class in PriorKnowledge.
84 * @param objectCollection The name of the collection where the object is in. This is used to identify the class in PriorKnowledge.
85 * @param objectPosition The position where the object should be added.
86 * @param objectRotation The rotation to add the object with.
87 *
88 * @see controller::Operation::Operation
89 */
90 AddOperation(const std::shared_ptr<memoryxcontroller::MemoryXController>& memoryXController,
91 const std::shared_ptr<scene3D::Scene>& scene,
92 const std::string& objectName,
93 const std::string& objectCollection,
94 const SbVec3f& objectPosition,
95 const SbRotation& objectRotation);
96
97 /**
98 * Creates a new operation, which adds a new object.
99 * A new random object ID is created in this operation.
100 * The object will be added at a default position with a default rotation.
101 *
102 * @param memoryXController The MemoryXController to add the object at.
103 * @param scene The scene to add the object at.
104 * @param objectName The name of the class of the object. This is used to identify the class in PriorKnowledge.
105 * @param objectCollection The name of the collection where the object is in. This is used to identify the class in PriorKnowledge.
106 *
107 * @see controller::Operation::Operation
108 */
109 AddOperation(const std::shared_ptr<memoryxcontroller::MemoryXController>& memoryXController,
110 const std::shared_ptr<scene3D::Scene>& scene,
111 const std::string& objectName,
112 const std::string& objectCollection);
113
114 /**
115 * Returns a new operation which removes the object, which will be added in this operation.
116 *
117 * @return The operation, which removes the object.
118 *
119 * @see controller::Operation::createInverseOperation
120 */
121 const OperationPtr createInverseOperation() const override;
122
123 protected:
124 /**
125 * Adds the object to the WorkingMemory.
126 *
127 * @see controller::Operation::executeOnWorkingMemory
128 */
129 void executeOnWorkingMemory() override;
130
131 /**
132 * Adds the object to the local Scene.
133 *
134 * @see controller::Operation::executeOnScene
135 */
136 void executeOnScene() override;
137
138 private:
139 void createRandomId();
140
141 std::string objectName;
142 std::string objectCollection;
143 SbVec3f objectPosition;
144 SbRotation objectRotation;
145 };
146} // namespace controller
const OperationPtr createInverseOperation() const override
Returns a new operation which removes the object, which will be added in this operation.
void executeOnScene() override
Adds the object to the local Scene.
AddOperation(const AddOperation &operation)
Creates a new operation, which is a copy of the given operation, but has a new random ID.
void executeOnWorkingMemory() override
Adds the object to the WorkingMemory.
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
std::shared_ptr< Operation > OperationPtr