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