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(
55  new controller::RotateTranslateOperation(getMemoryXController(),
56  getScene(),
57  getObjectId(),
58  newRotation,
59  oldRotation,
60  newPosition,
61  oldPosition));
62  return inverseOperation;
63 }
64 
65 void
67 {
68  getMemoryXController()->getWorkingMemoryController()->rotateTranslateObject(
69  getObjectId(), newRotation, newPosition);
70 }
71 
72 void
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 
95 bool
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 }
controller::RotateTranslateOperation::isExecuteable
bool isExecuteable() override
Returns true, if the SceneObject is mutable.
Definition: RotateTranslateOperation.cpp:96
controller::RotateTranslateOperation::createInverseOperation
const OperationPtr createInverseOperation() const override
Returns a new operation, which reverts the rotation and translatioon of the object.
Definition: RotateTranslateOperation.cpp:52
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:73
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:66
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