RotateTranslateOperation.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 <Inventor/SbRotation.h>
30#include <Inventor/SbVec3f.h>
31
32// local
34
36 const std::shared_ptr<memoryxcontroller::MemoryXController>& memoryXController,
37 const std::shared_ptr<scene3D::Scene>& scene,
38 const std::string& objectId,
39 const SbRotation& oldRotation,
40 const SbRotation& newRotation,
41 const SbVec3f& oldPosition,
42 const SbVec3f& newPosition) :
43 Operation(memoryXController, scene, objectId),
44 oldRotation(oldRotation),
45 newRotation(newRotation),
46 oldPosition(oldPosition),
47 newPosition(newPosition)
48{
49}
50
53{
54 std::shared_ptr<controller::Operation> inverseOperation(
56 getScene(),
58 newRotation,
59 oldRotation,
60 newPosition,
61 oldPosition));
62 return inverseOperation;
63}
64
65void
67{
68 getMemoryXController()->getWorkingMemoryController()->rotateTranslateObject(
69 getObjectId(), newRotation, newPosition);
70}
71
72void
74{
75 std::shared_ptr<scene3D::Scene> scene = getScene();
76 scene3D::SceneObjectPtr object = scene->getObjectManager()->getObjectById(getObjectId());
77
78 if (!object)
79 {
80 throw std::logic_error("Object does not exist");
81 }
82
83 object->setRotation(newRotation);
84 object->setTranslation(newPosition);
85
86 //Reset manipulator to apply new position and translation
87 scene->getManipulatorManager()->applyManipulator(object);
88
89 if (scene->getSelectionManager()->isSelected(object))
90 {
91 scene->getManipulatorManager()->addManipulator(object);
92 }
93}
94
95bool
97{
98 std::shared_ptr<scene3D::Scene> scene = getScene();
99 scene3D::SceneObjectPtr object = scene->getObjectManager()->getObjectById(getObjectId());
100
101 if (!object)
102 {
103 return true;
104 }
105
106 return object->isMutable();
107}
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
A operation to rotate and translate a object.
bool isExecuteable() override
Returns true, if the SceneObject is mutable.
const OperationPtr createInverseOperation() const override
Returns a new operation, which reverts the rotation and translatioon of the object.
void executeOnScene() override
Rotates and translates the object in the Scene.
RotateTranslateOperation(const std::shared_ptr< memoryxcontroller::MemoryXController > &memoryXController, const std::shared_ptr< scene3D::Scene > &scene, const std::string &objectId, const SbRotation &oldRotation, const SbRotation &newRotation, const SbVec3f &oldPosition, const SbVec3f &newPosition)
Creates a new operation, which rotates and translates a object.
void executeOnWorkingMemory() override
Rotates and translates the object in the WorkingMemory.
std::shared_ptr< Operation > OperationPtr
boost::intrusive_ptr< SceneObject > SceneObjectPtr