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 <Inventor/nodes/SoSwitch.h>
27 #include <Inventor/nodes/SoTransform.h>
28 #include <Inventor/nodes/SoSeparator.h>
29 #include <Inventor/nodekits/SoBaseKit.h>
30 #include <Inventor/SbRotation.h>
31 #include <Inventor/manips/SoTransformManip.h>
32 
33 #include <string>
34 #include <map>
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, std::string classId, std::string collection, SoSeparator* geometry, SoSeparator* collision);
68 
69  /**
70  * Returns the Translation of the SceneObject.
71  *
72  * @return SbVec3f Translation of SceneObject
73  */
74  SbVec3f getTranslation();
75 
76  /**
77  * Sets the Translation of the SceneObject.
78  *
79  * @param translation Translation of SceneObject
80  */
81  void setTranslation(SbVec3f translation);
82 
83  /**
84  * Returns the Rotation of the SceneObject.
85  *
86  * @return SbRotation Rotation of SceneObject
87  */
88  SbRotation getRotation();
89 
90  /**
91  * Sets the Rotation of the SceneObject.
92  *
93  * @param rotation Rotation of SceneObject
94  */
95  void setRotation(SbRotation rotation);
96 
97  /**
98  * Decides, whether CollisionMesh is beeing shown.
99  *
100  * @param show Show Collision Mesh
101  */
102  void showCollisionMesh(bool show);
103 
104  /**
105  * Initializes Class.
106  *
107  */
108  static void initClass();
109 
110  /**
111  * Returns the ObjectId of the SceneObject.
112  *
113  * @return std::string ObjectId of the SceneObject
114  */
115  std::string getObjectId() const;
116  /**
117  * Sets the ObjectId of the SceneObject.
118  *
119  * @param objectId ObjectId of the SceneObject
120  */
121  void setObjectId(std::string& objectId);
122  /**
123  * Returns the ClassId of the SceneObject.
124  *
125  * @return std::string ClassId of the SceneObject
126  */
127  std::string getClassId() const;
128  /**
129  * Sets the ClassId of the SceneObject.
130  *
131  * @param classId ClassId of the SceneObject
132  */
133  void setClassId(std::string& classId);
134  /**
135  * Returns the Collection of the SceneObject.
136  *
137  * @return std::string Collection of the SceneObject
138  */
139  std::string getCollection() const;
140  /**
141  * Sets the Collection of the SceneObject.
142  *
143  * @param collection Collection of the SceneObject
144  */
145  void setCollection(std::string& collection);
146 
147  /**
148  * Returns all Attributes of the SceneObject as Map.
149  *
150  * @return std::map<std::string, std::string> All Attributes as Map
151  */
152  std::map<std::string, std::string> getAllAttributes();
153 
154  /**
155  * Returns if you are allowed to change this object.
156  *
157  * @return true, if you are allowed; false otherwise
158  */
159  bool isMutable();
160 
161  private:
162  static bool isInitialized;
163  std::string classId;
164  std::string collection;
165  std::string objectId;
166 
167  SceneObject();
168 
169  void addManipulator(SoTransformManip* manip);
170 
171  void applyManipulator();
172 
173  bool hasManipulator();
174 
175  void trackThisTransformation(SoTransform* transformation);
176  void untrackTransformations();
177 
178  SbVec3f lastTranslation;
179  SbRotation lastRotation;
180  void pushHistory();
181 
182  SbRotation getHistoryRotation();
183  SbVec3f getHistoryTranslation();
184 
185  SoTransformManip* manipNode;
186  SoTransform* transformNode;
187  SoSwitch* switchNode;
188 
189  bool isManipulated;
190  };
191 }
192 
scene3D::SceneObject::setTranslation
void setTranslation(SbVec3f translation)
Sets the Translation of the SceneObject.
Definition: SceneObject.cpp:122
scene3D::SceneObject::showCollisionMesh
void showCollisionMesh(bool show)
Decides, whether CollisionMesh is beeing shown.
Definition: SceneObject.cpp:163
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:214
scene3D::SceneObject::setObjectId
void setObjectId(std::string &objectId)
Sets the ObjectId of the SceneObject.
Definition: SceneObject.cpp:194
scene3D::SceneObject
Definition: SceneObject.h:43
scene3D::SceneObject::getCollection
std::string getCollection() const
Returns the Collection of the SceneObject.
Definition: SceneObject.cpp:209
scene3D::SceneObject::setClassId
void setClassId(std::string &classId)
Sets the ClassId of the SceneObject.
Definition: SceneObject.cpp:204
scene3D::SceneObject::getTranslation
SbVec3f getTranslation()
Returns the Translation of the SceneObject.
Definition: SceneObject.cpp:104
scene3D::SceneObject::isMutable
bool isMutable()
Returns if you are allowed to change this object.
Definition: SceneObject.cpp:288
scene3D::SceneObject::getClassId
std::string getClassId() const
Returns the ClassId of the SceneObject.
Definition: SceneObject.cpp:199
scene3D::SceneObject::setRotation
void setRotation(SbRotation rotation)
Sets the Rotation of the SceneObject.
Definition: SceneObject.cpp:152
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:315
scene3D::SceneObject::getAllAttributes
std::map< std::string, std::string > getAllAttributes()
Returns all Attributes of the SceneObject as Map.
Definition: SceneObject.cpp:219
scene3D::SceneManipulatorManager
Definition: SceneManipulatorManager.h:34
scene3D::SceneObject::initClass
static void initClass()
Initializes Class.
Definition: SceneObject.cpp:31
scene3D::SceneObject::getObjectId
std::string getObjectId() const
Returns the ObjectId of the SceneObject.
Definition: SceneObject.cpp:189