SceneObject.h
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 #pragma once
25 
26 #include <map>
27 #include <string>
28 
29 #include <Inventor/SbRotation.h>
30 #include <Inventor/manips/SoTransformManip.h>
31 #include <Inventor/nodekits/SoBaseKit.h>
32 #include <Inventor/nodes/SoSeparator.h>
33 #include <Inventor/nodes/SoSwitch.h>
34 #include <Inventor/nodes/SoTransform.h>
35 
36 namespace scene3D
37 {
38  class SceneGroup;
39 }
40 
41 namespace scene3D
42 {
43  class SceneObject : public SoBaseKit
44  {
45 
47 
48  SO_KIT_HEADER(SceneObject);
49 
50  SO_KIT_CATALOG_ENTRY_HEADER(root);
51  SO_KIT_CATALOG_ENTRY_HEADER(transform);
52  SO_KIT_CATALOG_ENTRY_HEADER(transformManip);
53  SO_KIT_CATALOG_ENTRY_HEADER(modelswitch);
54  SO_KIT_CATALOG_ENTRY_HEADER(visual);
55  SO_KIT_CATALOG_ENTRY_HEADER(collision);
56 
57  public:
58  /**
59  * @brief
60  *
61  * @param objectId
62  * @param classId
63  * @param collection
64  * @param geometry
65  * @param collision
66  */
67  SceneObject(std::string objectId,
68  std::string classId,
69  std::string collection,
70  SoSeparator* geometry,
71  SoSeparator* collision);
72 
73  /**
74  * Returns the Translation of the SceneObject.
75  *
76  * @return SbVec3f Translation of SceneObject
77  */
78  SbVec3f getTranslation();
79 
80  /**
81  * Sets the Translation of the SceneObject.
82  *
83  * @param translation Translation of SceneObject
84  */
85  void setTranslation(SbVec3f translation);
86 
87  /**
88  * Returns the Rotation of the SceneObject.
89  *
90  * @return SbRotation Rotation of SceneObject
91  */
92  SbRotation getRotation();
93 
94  /**
95  * Sets the Rotation of the SceneObject.
96  *
97  * @param rotation Rotation of SceneObject
98  */
99  void setRotation(SbRotation rotation);
100 
101  /**
102  * Decides, whether CollisionMesh is beeing shown.
103  *
104  * @param show Show Collision Mesh
105  */
106  void showCollisionMesh(bool show);
107 
108  /**
109  * Initializes Class.
110  *
111  */
112  static void initClass();
113 
114  /**
115  * Returns the ObjectId of the SceneObject.
116  *
117  * @return std::string ObjectId of the SceneObject
118  */
119  std::string getObjectId() const;
120  /**
121  * Sets the ObjectId of the SceneObject.
122  *
123  * @param objectId ObjectId of the SceneObject
124  */
125  void setObjectId(std::string& objectId);
126  /**
127  * Returns the ClassId of the SceneObject.
128  *
129  * @return std::string ClassId of the SceneObject
130  */
131  std::string getClassId() const;
132  /**
133  * Sets the ClassId of the SceneObject.
134  *
135  * @param classId ClassId of the SceneObject
136  */
137  void setClassId(std::string& classId);
138  /**
139  * Returns the Collection of the SceneObject.
140  *
141  * @return std::string Collection of the SceneObject
142  */
143  std::string getCollection() const;
144  /**
145  * Sets the Collection of the SceneObject.
146  *
147  * @param collection Collection of the SceneObject
148  */
149  void setCollection(std::string& collection);
150 
151  /**
152  * Returns all Attributes of the SceneObject as Map.
153  *
154  * @return std::map<std::string, std::string> All Attributes as Map
155  */
156  std::map<std::string, std::string> getAllAttributes();
157 
158  /**
159  * Returns if you are allowed to change this object.
160  *
161  * @return true, if you are allowed; false otherwise
162  */
163  bool isMutable();
164 
165  private:
166  static bool isInitialized;
167  std::string classId;
168  std::string collection;
169  std::string objectId;
170 
171  SceneObject();
172 
173  void addManipulator(SoTransformManip* manip);
174 
175  void applyManipulator();
176 
177  bool hasManipulator();
178 
179  void trackThisTransformation(SoTransform* transformation);
180  void untrackTransformations();
181 
182  SbVec3f lastTranslation;
183  SbRotation lastRotation;
184  void pushHistory();
185 
186  SbRotation getHistoryRotation();
187  SbVec3f getHistoryTranslation();
188 
189  SoTransformManip* manipNode;
190  SoTransform* transformNode;
191  SoSwitch* switchNode;
192 
193  bool isManipulated;
194  };
195 } // namespace scene3D
scene3D::SceneObject::setTranslation
void setTranslation(SbVec3f translation)
Sets the Translation of the SceneObject.
Definition: SceneObject.cpp:121
scene3D::SceneObject::showCollisionMesh
void showCollisionMesh(bool show)
Decides, whether CollisionMesh is beeing shown.
Definition: SceneObject.cpp:165
scene3D::SceneObject::getRotation
SbRotation getRotation()
Returns the Rotation of the SceneObject.
Definition: SceneObject.cpp:133
scene3D::SceneObject::setCollection
void setCollection(std::string &collection)
Sets the Collection of the SceneObject.
Definition: SceneObject.cpp:225
scene3D::SceneObject::setObjectId
void setObjectId(std::string &objectId)
Sets the ObjectId of the SceneObject.
Definition: SceneObject.cpp:201
scene3D::SceneObject
Definition: SceneObject.h:43
scene3D::SceneObject::getCollection
std::string getCollection() const
Returns the Collection of the SceneObject.
Definition: SceneObject.cpp:219
scene3D::SceneObject::setClassId
void setClassId(std::string &classId)
Sets the ClassId of the SceneObject.
Definition: SceneObject.cpp:213
scene3D::SceneObject::getTranslation
SbVec3f getTranslation()
Returns the Translation of the SceneObject.
Definition: SceneObject.cpp:102
scene3D::SceneObject::isMutable
bool isMutable()
Returns if you are allowed to change this object.
Definition: SceneObject.cpp:306
scene3D::SceneObject::getClassId
std::string getClassId() const
Returns the ClassId of the SceneObject.
Definition: SceneObject.cpp:207
scene3D::SceneObject::setRotation
void setRotation(SbRotation rotation)
Sets the Rotation of the SceneObject.
Definition: SceneObject.cpp:153
scene3D
Definition: ManipulatorMode.h:26
armarx::transform
auto transform(const Container< InputT, Alloc > &in, OutputT(*func)(InputT const &)) -> Container< OutputT, typename std::allocator_traits< Alloc >::template rebind_alloc< OutputT >>
Convenience function (with less typing) to transform a container of type InputT into the same contain...
Definition: algorithm.h:351
scene3D::SceneObject::getAllAttributes
std::map< std::string, std::string > getAllAttributes()
Returns all Attributes of the SceneObject as Map.
Definition: SceneObject.cpp:231
scene3D::SceneManipulatorManager
Definition: SceneManipulatorManager.h:32
scene3D::SceneObject::initClass
static void initClass()
Initializes Class.
Definition: SceneObject.cpp:34
scene3D::SceneObject::getObjectId
std::string getObjectId() const
Returns the ObjectId of the SceneObject.
Definition: SceneObject.cpp:195