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