26#include <boost/format.hpp>
29#include <Inventor/nodes/SoTransform.h>
36 SO_KIT_INIT_CLASS(
SceneObject, SoBaseKit,
"BaseKit");
39bool scene3D::SceneObject::isInitialized =
false;
43 std::string collection,
44 SoSeparator* geometry,
45 SoSeparator* collision) :
46 classId(classId), collection(collection), manipNode(nullptr), isManipulated(false)
49 if (!SceneObject::isInitialized)
52 SceneObject::isInitialized =
true;
57 SO_KIT_ADD_CATALOG_ENTRY(root, SoSeparator,
false,
this,
"", TRUE);
58 SO_KIT_ADD_CATALOG_ENTRY(transformManip, SoTransformManip, TRUE, root,
"", TRUE);
59 SO_KIT_ADD_CATALOG_ENTRY(transform, SoTransform, TRUE, root,
"", TRUE);
60 SO_KIT_ADD_CATALOG_ENTRY(modelswitch, SoSwitch, TRUE, root,
"", TRUE);
61 SO_KIT_ADD_CATALOG_ENTRY(visual, SoSeparator, TRUE, modelswitch,
"", TRUE);
62 SO_KIT_ADD_CATALOG_ENTRY(collision, SoSeparator, TRUE, modelswitch,
"", TRUE);
63 SO_KIT_INIT_INSTANCE();
69 this->setPart(
"root",
new SoSeparator);
72 this->transformNode =
new SoTransform;
73 this->setPart(
"transform", this->transformNode);
76 this->switchNode =
new SoSwitch;
77 this->setPart(
"modelswitch", this->switchNode);
79 this->switchNode->whichChild = 0;
82 this->setPart(
"visual", geometry);
85 this->setPart(
"collision", collision);
92 SO_KIT_ADD_CATALOG_ENTRY(root, SoSeparator,
false,
this,
"", TRUE);
93 SO_KIT_ADD_CATALOG_ENTRY(transform, SoTransform, TRUE,
this,
nullptr, TRUE);
94 SO_KIT_ADD_CATALOG_ENTRY(transformManip, SoTransformManip, TRUE, root,
"", TRUE);
95 SO_KIT_ADD_CATALOG_ENTRY(modelswitch, SoSwitch, TRUE,
this,
nullptr, TRUE);
96 SO_KIT_ADD_CATALOG_ENTRY(visual, SoSeparator, TRUE,
this, modelswitch, TRUE);
97 SO_KIT_ADD_CATALOG_ENTRY(collision, SoSeparator, TRUE,
this, modelswitch, TRUE);
98 SO_KIT_INIT_INSTANCE();
104 if (this->hasManipulator())
106 SoTransform* tempTransform =
new SoTransform;
107 tempTransform->ref();
109 tempTransform->combineRight(transformNode);
110 tempTransform->combineRight(manipNode);
112 SbVec3f result = tempTransform->translation.getValue();
113 tempTransform->unref();
117 return this->transformNode->translation.getValue();
123 this->transformNode->translation.setValue(translation);
126 if (this->hasManipulator())
128 this->manipNode->setToDefaults();
135 if (this->hasManipulator())
137 SoTransform* tempTransform =
new SoTransform;
138 tempTransform->ref();
140 tempTransform->combineRight(transformNode);
141 tempTransform->combineRight(manipNode);
144 SbRotation result = tempTransform->rotation.getValue();
145 tempTransform->unref();
149 return this->transformNode->rotation.getValue();
155 this->transformNode->rotation.setValue(rotation);
158 if (this->hasManipulator())
160 this->manipNode->setToDefaults();
167 this->switchNode->whichChild = show ? 1 : 0;
171scene3D::SceneObject::addManipulator(SoTransformManip* manip)
173 this->manipNode = manip;
174 this->setPart(
"transformManip", manipNode);
178scene3D::SceneObject::applyManipulator()
180 if (this->hasManipulator())
182 transformNode->combineRight(manipNode);
183 this->setPart(
"transformManip", NULL);
184 this->manipNode =
nullptr;
189scene3D::SceneObject::hasManipulator()
191 return this->manipNode !=
nullptr;
197 return this->objectId;
203 this->objectId = objectId;
215 this->classId = classId;
227 this->collection = collection;
230std::map<std::string, std::string>
233 std::map<std::string, std::string> allAttributes;
238 allAttributes.insert(std::pair<std::string, std::string>(
"Translation X", std::to_string(
x)));
239 allAttributes.insert(std::pair<std::string, std::string>(
"Translation Y", std::to_string(y)));
240 allAttributes.insert(std::pair<std::string, std::string>(
"Translation Z", std::to_string(z)));
243 float pw, px, py, pz;
245 allAttributes.insert(std::pair<std::string, std::string>(
"Rotation X", std::to_string(px)));
246 allAttributes.insert(std::pair<std::string, std::string>(
"Rotation Y", std::to_string(py)));
247 allAttributes.insert(std::pair<std::string, std::string>(
"Rotation Z", std::to_string(pz)));
248 allAttributes.insert(std::pair<std::string, std::string>(
"Angle", std::to_string(pw)));
256 for (
int i = 0; i < 4; i++)
258 out.append(boost::str(boost::format(
"%3.2g %3.2g %3.2g %3.2g") % matrix[i][0] %
259 matrix[i][1] % matrix[i][2] % matrix[i][3]));
267 allAttributes.insert(std::pair<std::string, std::string>(
"Matrix", out));
269 return allAttributes;
273scene3D::SceneObject::pushHistory()
275 this->lastRotation = this->getRotation();
276 this->lastTranslation = this->getTranslation();
280scene3D::SceneObject::getHistoryRotation()
282 return this->lastRotation;
286scene3D::SceneObject::getHistoryTranslation()
288 return lastTranslation;
292scene3D::SceneObject::trackThisTransformation(SoTransform* transformation)
294 this->manipNode->rotation.connectFrom(&transformation->rotation);
295 this->manipNode->translation.connectFrom(&transformation->translation);
299scene3D::SceneObject::untrackTransformations()
301 this->manipNode->rotation.disconnect();
302 this->manipNode->translation.disconnect();
308 return !isManipulated;
void setTranslation(SbVec3f translation)
Sets the Translation of the SceneObject.
std::string getObjectId() const
Returns the ObjectId of the SceneObject.
SbVec3f getTranslation()
Returns the Translation of the SceneObject.
std::string getClassId() const
Returns the ClassId of the SceneObject.
std::string getCollection() const
Returns the Collection of the SceneObject.
SceneObject(std::string objectId, std::string classId, std::string collection, SoSeparator *geometry, SoSeparator *collision)
std::map< std::string, std::string > getAllAttributes()
Returns all Attributes of the SceneObject as Map.
void showCollisionMesh(bool show)
Decides, whether CollisionMesh is beeing shown.
void setObjectId(std::string &objectId)
Sets the ObjectId of the SceneObject.
void setRotation(SbRotation rotation)
Sets the Rotation of the SceneObject.
bool isMutable()
Returns if you are allowed to change this object.
void setClassId(std::string &classId)
Sets the ClassId of the SceneObject.
static void initClass()
Initializes Class.
SbRotation getRotation()
Returns the Rotation of the SceneObject.
void setCollection(std::string &collection)
Sets the Collection of the SceneObject.
This file offers overloads of toIce() and fromIce() functions for STL container types.