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/SbVec3f.h>
30 #include <Inventor/SbRotation.h>
31 
32 // local
34 
35 controller::RotateTranslateOperation::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) :
36  Operation(memoryXController, scene, objectId),
37  oldRotation(oldRotation),
38  newRotation(newRotation),
39  oldPosition(oldPosition),
40  newPosition(newPosition)
41 {
42 }
43 
45 {
46  std::shared_ptr<controller::Operation> inverseOperation(new controller::RotateTranslateOperation(getMemoryXController(), getScene(), getObjectId(), newRotation, oldRotation, newPosition, oldPosition));
47  return inverseOperation;
48 }
49 
51 {
52  getMemoryXController()->getWorkingMemoryController()->rotateTranslateObject(getObjectId(), newRotation, newPosition);
53 }
54 
56 {
57  std::shared_ptr<scene3D::Scene> scene = getScene();
58  scene3D::SceneObjectPtr object = scene->getObjectManager()->getObjectById(getObjectId());
59 
60  if (!object)
61  {
62  throw std::logic_error("Object does not exist");
63  }
64 
65  object->setRotation(newRotation);
66  object->setTranslation(newPosition);
67 
68  //Reset manipulator to apply new position and translation
69  scene->getManipulatorManager()->applyManipulator(object);
70 
71  if (scene->getSelectionManager()->isSelected(object))
72  {
73  scene->getManipulatorManager()->addManipulator(object);
74  }
75 }
76 
78 {
79  std::shared_ptr<scene3D::Scene> scene = getScene();
80  scene3D::SceneObjectPtr object = scene->getObjectManager()->getObjectById(getObjectId());
81 
82  if (!object)
83  {
84  return true;
85  }
86 
87  return object->isMutable();
88 }
controller::RotateTranslateOperation::isExecuteable
bool isExecuteable() override
Returns true, if the SceneObject is mutable.
Definition: RotateTranslateOperation.cpp:77
controller::RotateTranslateOperation::createInverseOperation
const OperationPtr createInverseOperation() const override
Returns a new operation, which reverts the rotation and translatioon of the object.
Definition: RotateTranslateOperation.cpp:44
controller::RotateTranslateOperation::RotateTranslateOperation
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.
Definition: RotateTranslateOperation.cpp:35
RotateTranslateOperation.h
controller::RotateTranslateOperation::executeOnScene
void executeOnScene() override
Rotates and translates the object in the Scene.
Definition: RotateTranslateOperation.cpp:55
controller::OperationPtr
std::shared_ptr< Operation > OperationPtr
Definition: ClassDefinitions.h:54
controller::RotateTranslateOperation::executeOnWorkingMemory
void executeOnWorkingMemory() override
Rotates and translates the object in the WorkingMemory.
Definition: RotateTranslateOperation.cpp:50
scene3D::SceneObjectPtr
boost::intrusive_ptr< SceneObject > SceneObjectPtr
Definition: PointerDefinitions.h:40
controller::RotateTranslateOperation
A operation to rotate and translate a object.
Definition: RotateTranslateOperation.h:46
controller::Operation
An abstract class, which offers methods to run operations on the WorkingMemory and the Scene.
Definition: Operation.h:44