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/SbVec3f.h>
32 #include <Inventor/SbRotation.h>
33 
34 // local
35 #include "../scene3D/Scene.h"
36 #include "Operation.h"
37 #include "../memoryxcontroller/MemoryXController.h"
38 
39 namespace 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, 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);
70 
71  /**
72  * Creates a new operation, which adds a new object.
73  * A new random object ID is created in this operation.
74  *
75  * @param memoryXController The MemoryXController to add the object at.
76  * @param scene The scene to add the object at.
77  * @param objectName The name of the class of the object. This is used to identify the class in PriorKnowledge.
78  * @param objectCollection The name of the collection where the object is in. This is used to identify the class in PriorKnowledge.
79  * @param objectPosition The position where the object should be added.
80  * @param objectRotation The rotation to add the object with.
81  *
82  * @see controller::Operation::Operation
83  */
84  AddOperation(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);
85 
86  /**
87  * Creates a new operation, which adds a new object.
88  * A new random object ID is created in this operation.
89  * The object will be added at a default position with a default rotation.
90  *
91  * @param memoryXController The MemoryXController to add the object at.
92  * @param scene The scene to add the object at.
93  * @param objectName The name of the class of the object. This is used to identify the class in PriorKnowledge.
94  * @param objectCollection The name of the collection where the object is in. This is used to identify the class in PriorKnowledge.
95  *
96  * @see controller::Operation::Operation
97  */
98  AddOperation(const std::shared_ptr<memoryxcontroller::MemoryXController>& memoryXController, const std::shared_ptr<scene3D::Scene>& scene, const std::string& objectName, const std::string& objectCollection);
99 
100  /**
101  * Returns a new operation which removes the object, which will be added in this operation.
102  *
103  * @return The operation, which removes the object.
104  *
105  * @see controller::Operation::createInverseOperation
106  */
107  const OperationPtr createInverseOperation() const override;
108 
109  protected:
110  /**
111  * Adds the object to the WorkingMemory.
112  *
113  * @see controller::Operation::executeOnWorkingMemory
114  */
115  void executeOnWorkingMemory() override;
116 
117  /**
118  * Adds the object to the local Scene.
119  *
120  * @see controller::Operation::executeOnScene
121  */
122  void executeOnScene() override;
123 
124  private:
125  void createRandomId();
126 
127  std::string objectName;
128  std::string objectCollection;
129  SbVec3f objectPosition;
130  SbRotation objectRotation;
131 
132  };
133 }
134 
controller::AddOperation::createInverseOperation
const OperationPtr createInverseOperation() const override
Returns a new operation which removes the object, which will be added in this operation.
Definition: AddOperation.cpp:107
Operation.h
controller::AddOperation::executeOnWorkingMemory
void executeOnWorkingMemory() override
Adds the object to the WorkingMemory.
Definition: AddOperation.cpp:113
controller::AddOperation::AddOperation
AddOperation(const AddOperation &operation)
Creates a new operation, which is a copy of the given operation, but has a new random ID.
Definition: AddOperation.cpp:40
controller
Definition: AddOperation.h:39
controller::AddOperation::executeOnScene
void executeOnScene() override
Adds the object to the local Scene.
Definition: AddOperation.cpp:131
controller::OperationPtr
std::shared_ptr< Operation > OperationPtr
Definition: ClassDefinitions.h:54
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