SceneManipulatorManager.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 #include <Inventor/manips/SoTransformerManip.h>
25 
27 #include "../controller/RotateTranslateOperation.h"
28 
30 {
31  if (ScenePtr scene = this->scene.lock())
32  {
33  this->manipulatorMode = mode;
34 
35  for (SceneObjectPtr object : scene->getSelectionManager()->getAllSelected())
36  {
37  object->applyManipulator();
38  this->addManipulator(object);
39  }
40  }
41 }
42 
43 void scene3D::SceneManipulatorManager::manipulatorStartCallback(void* userdata, SoDragger* dragger)
44 {
45  std::pair<SceneObject*, Scene*>* data = (std::pair<SceneObject*, Scene*>*) userdata;
46  SceneObject* object = data->first;
47  Scene* scene = data->second;
48 
49  for (SceneObjectPtr sceneobject : scene->sceneSelectionManager->getAllSelected())
50  {
51  sceneobject->pushHistory();
52 
53  if (sceneobject != object)
54  {
55  sceneobject->trackThisTransformation(object->manipNode);
56  }
57 
58  sceneobject->isManipulated = true;
59  }
60 }
61 
62 void scene3D::SceneManipulatorManager::manipulatorValueChangedCallback(void* userdata, SoDragger* dragger)
63 {
64  std::pair<SceneObject*, Scene*>* data = (std::pair<SceneObject*, Scene*>*) userdata;
65  SceneObject* object = data->first;
66  Scene* scene = data->second;
67 
68  if (controller::ControllerPtr controller = scene->getController().lock())
69  {
70  std::vector<std::string> changed;
71  changed.push_back(object->getObjectId());
72  controller->triggerObjectsChanged(changed);
73  }
74 }
75 
76 void scene3D::SceneManipulatorManager::manipulatorFinishCallback(void* userdata, SoDragger* dragger)
77 {
78  Scene* scene = (Scene*)userdata;
79 
80  if (controller::ControllerPtr controller = scene->getController().lock())
81  {
82  std::shared_ptr<std::vector<controller::OperationPtr> > operations(new std::vector<controller::OperationPtr>());
83 
84  for (SceneObjectPtr sceneobject : scene->sceneSelectionManager->getAllSelected())
85  {
86 
88  controller->getMemoryXController(),
89  controller->getScene(), sceneobject->getObjectId(),
90  sceneobject->getHistoryRotation(), sceneobject->getRotation(),
91  sceneobject->getHistoryTranslation(), sceneobject->getTranslation()));
92 
93  operations->push_back(operation);
94 
95  sceneobject->untrackTransformations();
96  sceneobject->isManipulated = false;
97  }
98 
100  controller->executeQueuedOperations(false);
101  }
102 }
103 
105 {
106  this->manipulatorMode = ManipulatorMode::NONE;
107 }
108 
110 {
111  //Create new manipulator
112  SoTransformerManip* manip = new SoTransformerManip;
113  SoSeparator* nullSep = new SoSeparator;
114 
115  //Make all scale knobs disappear
116  manip->getDragger()->setPart("scale1", nullSep);
117  manip->getDragger()->setPart("scale2", nullSep);
118  manip->getDragger()->setPart("scale3", nullSep);
119  manip->getDragger()->setPart("scale4", nullSep);
120  manip->getDragger()->setPart("scale5", nullSep);
121  manip->getDragger()->setPart("scale6", nullSep);
122  manip->getDragger()->setPart("scale7", nullSep);
123  manip->getDragger()->setPart("scale8", nullSep);
124 
125 
126  if (this->manipulatorMode != ManipulatorMode::ALL)
127  {
128  if (this->manipulatorMode == ManipulatorMode::ROTATION
129  || this->manipulatorMode == ManipulatorMode::NONE)
130  {
131  //Make all translation knobs disappear
132  manip->getDragger()->setPart("translator1", nullSep);
133  manip->getDragger()->setPart("translator2", nullSep);
134  manip->getDragger()->setPart("translator3", nullSep);
135  manip->getDragger()->setPart("translator4", nullSep);
136  manip->getDragger()->setPart("translator5", nullSep);
137  manip->getDragger()->setPart("translator6", nullSep);
138  }
139 
140  if (this->manipulatorMode == ManipulatorMode::TRANSLATION
141  || this->manipulatorMode == ManipulatorMode::NONE)
142  {
143  //Make all translation knobs disappear
144  manip->getDragger()->setPart("rotator1", nullSep);
145  manip->getDragger()->setPart("rotator2", nullSep);
146  manip->getDragger()->setPart("rotator3", nullSep);
147  manip->getDragger()->setPart("rotator4", nullSep);
148  manip->getDragger()->setPart("rotator5", nullSep);
149  manip->getDragger()->setPart("rotator6", nullSep);
150  }
151  }
152 
153  if (ScenePtr scene = this->scene.lock())
154  {
155  manip->getDragger()->addStartCallback(manipulatorStartCallback, new std::pair<SceneObject*, Scene*>(object.get(), scene.get()));
156  manip->getDragger()->addValueChangedCallback(manipulatorValueChangedCallback, new std::pair<SceneObject*, Scene*>(object.get(), scene.get()));
157  manip->getDragger()->addFinishCallback(manipulatorFinishCallback, scene.get());
158  }
159 
160  object->addManipulator(manip);
161 }
162 
164 {
165  object->applyManipulator();
166 }
167 
169 {
170  return this->manipulatorMode;
171 }
scene3D::Scene
Definition: Scene.h:61
scene3D::ManipulatorMode
ManipulatorMode
Definition: ManipulatorMode.h:33
scene3D::ScenePtr
std::shared_ptr< Scene > ScenePtr
Definition: PointerDefinitions.h:36
SceneManipulatorManager.h
scene3D::SceneObject
Definition: SceneObject.h:43
controller::Controller::UNDOABLE
static const int UNDOABLE
A flag to save the executed operations to the history.
Definition: Controller.h:80
scene3D::ALL
@ ALL
Definition: ManipulatorMode.h:35
controller
Definition: AddOperation.h:39
controller::ControllerPtr
std::shared_ptr< Controller > ControllerPtr
Definition: ClassDefinitions.h:41
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
scene3D::SceneManipulatorManager::setManipulatorMode
void setManipulatorMode(scene3D::ManipulatorMode mode)
Sets a specific ManipulatorMode.
Definition: SceneManipulatorManager.cpp:29
scene3D::SceneManipulatorManager::getManipulatorMode
ManipulatorMode getManipulatorMode()
Returns the set ManipulatorMode.
Definition: SceneManipulatorManager.cpp:168
scene3D::SceneManipulatorManager::applyManipulator
void applyManipulator(SceneObjectPtr object)
Applys the selected Manipulator to a SceneObject.
Definition: SceneManipulatorManager.cpp:163
scene3D::TRANSLATION
@ TRANSLATION
Definition: ManipulatorMode.h:37
scene3D::SceneManipulatorManager::SceneManipulatorManager
SceneManipulatorManager(ScenePtr scene)
Constructor Creates an Instance of the Class.
Definition: SceneManipulatorManager.cpp:104
armarx::aron::similarity::FloatSimilarity::NONE
@ NONE
Definition: FloatSimilarity.h:11
controller::OperationPtr
std::shared_ptr< Operation > OperationPtr
Definition: ClassDefinitions.h:54
scene3D::SceneManipulatorManager::addManipulator
void addManipulator(SceneObjectPtr object)
Adds the selected Manipulator to a SceneObject.
Definition: SceneManipulatorManager.cpp:109
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::Controller::EXECUTE_ON_WM
static const int EXECUTE_ON_WM
A Flag to execute operations on the WorkingMemory.
Definition: Controller.h:66
scene3D::ROTATION
@ ROTATION
Definition: ManipulatorMode.h:36