Operation.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 #include <memory>
30 
31 // local
32 #include "ClassDefinitions.h"
33 #include "../scene3D/Scene.h"
34 #include "../memoryxcontroller/MemoryXController.h"
35 
36 namespace controller
37 {
38  /**
39  * An abstract class, which offers methods to run operations on the WorkingMemory and the Scene.
40  *
41  * @see scene3D::Scene
42  * @see memoryxcontroller::WorkingMemoryController
43  */
44  class Operation
45  {
46  friend class Controller;
47  friend class UndoRedoStack;
48 
49  public:
50  /**
51  * A constructor.
52  * Sets the Scene and WorkingMemory to execute the scene at.
53  *
54  * @param memoryXController the Controller for the WorkingMemory instance to run the Operation at
55  * @param scene the Scene to run the Operation at
56  * @param the ID of the object, which is affected by this operation
57  * @see scene3D::Scene
58  * @see memoryxcontroller::WorkingMemoryController
59  */
60  Operation(const std::shared_ptr<memoryxcontroller::MemoryXController>& memoryXController, const std::shared_ptr<scene3D::Scene>& scene, const std::string& objectId);
61 
62  /**
63  * A constructor.
64  * Sets the Scene and WorkingMemory to execute the scene at.
65  *
66  * @param memoryXController the Controller for the WorkingMemory instance to run the Operation at
67  * @param scene the Scene to run the Operation at
68  * @see scene3D::Scene
69  * @see memoryxcontroller::WorkingMemoryController
70  */
71  Operation(const std::shared_ptr<memoryxcontroller::MemoryXController>& memoryXController, const std::shared_ptr<scene3D::Scene>& scene);
72 
73  /**
74  * Returns a Operation, which reverts the changes done in this instance of the Operation.
75  *
76  * @return the inverse Operation
77  */
78  virtual const OperationPtr createInverseOperation() const = 0;
79 
80  /**
81  * Returns the ID of the object, this Operation is working on.
82  *
83  * @return the ID
84  */
85  std::string getObjectId() const;
86 
87  /**
88  * Return wehether the operation can be executed currently.
89  * If the Operation is never executeable this method return true.
90  *
91  * @return true, if the operation can be executed; false otherwise
92  */
93  virtual bool isExecuteable();
94 
95  protected:
96  /**
97  * Executes the Operation on the given WorkingMemory.
98  *
99  * @see memoryxcontroller::WorkingMemoryController
100  */
101  virtual void executeOnWorkingMemory() = 0;
102 
103  /**
104  * Executes the Operation on the given Scene.
105  *
106  * @see scene3D::Scene
107  */
108  virtual void executeOnScene() = 0;
109 
110  /**
111  * Returns the the Scene to execute the Operation at.
112  *
113  * @return the Scene
114  * @see scene3D::Scene
115  */
116  const std::shared_ptr<scene3D::Scene> getScene() const;
117 
118  /**
119  * Returns the the MemoryXController to execute the Operation at.
120  *
121  * @return the MemoryXController
122  * @see memoryxcontroller::MemoryXController
123  */
124  const std::shared_ptr<memoryxcontroller::MemoryXController> getMemoryXController() const;
125 
126  /**
127  * Sets the ID, this operation is working on.
128  *
129  * @param the new ID
130  */
131  void setObjectId(const std::string& objectId);
132 
133  private:
134  std::weak_ptr<scene3D::Scene> scene;
135  std::weak_ptr<memoryxcontroller::MemoryXController> memoryXController;
136  std::string objectId;
137  };
138 }
139 
controller::Operation::getObjectId
std::string getObjectId() const
Returns the ID of the object, this Operation is working on.
Definition: Operation.cpp:52
ClassDefinitions.h
controller::Operation::createInverseOperation
virtual const OperationPtr createInverseOperation() const =0
Returns a Operation, which reverts the changes done in this instance of the Operation.
controller::Operation::getScene
const std::shared_ptr< scene3D::Scene > getScene() const
Returns the the Scene to execute the Operation at.
Definition: Operation.cpp:42
controller::Operation::getMemoryXController
const std::shared_ptr< memoryxcontroller::MemoryXController > getMemoryXController() const
Returns the the MemoryXController to execute the Operation at.
Definition: Operation.cpp:47
controller
Definition: AddOperation.h:39
controller::UndoRedoStack
A Stack to save a history of Actions.
Definition: UndoRedoStack.h:44
controller::Operation::Operation
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
controller::Controller
A class to execute Operations, maintain the execution history and initialize Scene and MemoryXControl...
Definition: Controller.h:55
controller::Operation::isExecuteable
virtual bool isExecuteable()
Return wehether the operation can be executed currently.
Definition: Operation.cpp:62
controller::OperationPtr
std::shared_ptr< Operation > OperationPtr
Definition: ClassDefinitions.h:54
controller::Operation::executeOnScene
virtual void executeOnScene()=0
Executes the Operation on the given Scene.
controller::Operation::executeOnWorkingMemory
virtual void executeOnWorkingMemory()=0
Executes the Operation on the given WorkingMemory.
controller::Operation::setObjectId
void setObjectId(const std::string &objectId)
Sets the ID, this operation is working on.
Definition: Operation.cpp:57
controller::Operation
An abstract class, which offers methods to run operations on the WorkingMemory and the Scene.
Definition: Operation.h:44