29 #include <Inventor/SbVec3f.h>
30 #include <Inventor/SbRotation.h>
31 #include <Inventor/nodes/SoSeparator.h>
32 #include <Inventor/nodes/SoCone.h>
33 #include <Inventor/nodes/SoMaterial.h>
41 Operation(operation.getMemoryXController(), operation.getScene()),
42 objectName(operation.objectName),
43 objectCollection(operation.objectCollection),
44 objectPosition(operation.objectPosition),
45 objectRotation(operation.objectRotation)
53 controller::AddOperation::AddOperation(
const std::shared_ptr<memoryxcontroller::MemoryXController>& memoryXController,
const std::shared_ptr<scene3D::Scene>& scene,
const std::string& objectName,
const std::string& objectCollection,
const SbVec3f& objectPosition,
const SbRotation& objectRotation,
const std::string& objectId) :
54 Operation(memoryXController, scene, objectId),
55 objectName(objectName),
56 objectCollection(objectCollection),
57 objectPosition(objectPosition),
58 objectRotation(objectRotation)
63 controller::AddOperation::AddOperation(
const std::shared_ptr<memoryxcontroller::MemoryXController>& memoryXController,
const std::shared_ptr<scene3D::Scene>& scene,
const std::string& objectName,
const std::string& objectCollection,
const SbVec3f& objectPosition,
const SbRotation& objectRotation) :
65 objectName(objectName),
66 objectCollection(objectCollection),
67 objectPosition(objectPosition),
68 objectRotation(objectRotation)
73 controller::AddOperation::AddOperation(
const std::shared_ptr<memoryxcontroller::MemoryXController>& memoryXController,
const std::shared_ptr<scene3D::Scene>& scene,
const std::string& objectName,
const std::string& objectCollection) :
75 objectName(objectName),
76 objectCollection(objectCollection),
77 objectPosition(0, 0, 0),
78 objectRotation(SbVec3f(1, 0, 0), 0)
83 void controller::AddOperation::createRandomId()
85 static const char chars[] =
86 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
87 const int length = 20;
89 std::shared_ptr<scene3D::Scene> scene = getScene();
90 char random[length + 1];
94 for (
int i = 0; i < length; ++i)
96 random[i] = chars[rand() % (
sizeof(chars) - 1)];
101 while (scene->getObjectManager()->getObjectById(random));
103 std::string
id = random;
109 std::shared_ptr<controller::Operation> inverseOperation(
new controller::RemoveOperation(getMemoryXController(), getScene(), objectName, objectCollection, objectPosition, objectRotation, getObjectId()));
110 return inverseOperation;
120 memoryx::ObjectClassPtr objectClass = memoryXController->getPriorKnowlegdeController()->getObjectClassPtr(objectName, objectCollection);
124 std::string newObjectId = memoryXController->getWorkingMemoryController()->addObjectInstance(objectName, objectClass);
125 setObjectId(newObjectId);
128 getMemoryXController()->getWorkingMemoryController()->rotateTranslateObject(newObjectId, objectRotation, objectPosition);
133 std::shared_ptr<scene3D::Scene> scene = getScene();
135 memoryx::ObjectClassPtr objectClass = priorKnowledgeController->getObjectClassPtr(objectName, objectCollection);
136 SoNode* geometryNode = priorKnowledgeController->getCoinVisualisation(objectClass,
false);
137 SoNode* collisionNode = priorKnowledgeController->getCoinVisualisation(objectClass,
true);
141 ARMARX_WARNING_S <<
"object \"" << objectName <<
"\" has no collison model";
142 collisionNode =
new SoSeparator;
143 SoMaterial* material =
new SoMaterial;
144 material->ambientColor.setValue(1.0f, 0.0f, 0.0f);
145 material->diffuseColor.setValue(1.0f, 0.0f, 0.0f);
146 SoCone* cone =
new SoCone;
147 cone->bottomRadius.setValue(0.03);
148 cone->height.setValue(0.3);
149 ((SoSeparator*)collisionNode)->addChild(material);
150 ((SoSeparator*)collisionNode)->addChild(cone);
155 ARMARX_WARNING_S <<
"object \"" << objectName <<
"\" has no visualisation model";
156 geometryNode =
new SoSeparator;
157 SoMaterial* material =
new SoMaterial;
158 material->ambientColor.setValue(1.0f, 0.0f, 0.0f);
159 material->diffuseColor.setValue(1.0f, 0.0f, 0.0f);
160 SoCone* cone =
new SoCone;
161 cone->bottomRadius.setValue(0.03);
162 cone->height.setValue(0.3);
163 ((SoSeparator*)geometryNode)->addChild(material);
164 ((SoSeparator*)geometryNode)->addChild(cone);
167 SoSeparator* geometry =
new SoSeparator();
168 geometry->addChild(geometryNode);
169 SoSeparator* collision =
new SoSeparator();
170 collision->addChild(collisionNode);
173 object->setRotation(objectRotation);
174 object->setTranslation(objectPosition);
175 scene->getObjectManager()->addObject(
object);