25 #include <QGridLayout>
29 #include <VirtualRobot/MathTools.h>
32 #include <boost/format.hpp>
35 #include <ArmarXGui/libraries/qtpropertybrowser/src/QtProperty>
37 #include "../controller/RotateTranslateOperation.h"
50 connect(doubleManager, SIGNAL(valueChanged(
QtProperty*,
double)),
51 this, SLOT(valueChanged(
QtProperty*,
double)));
58 if (objectClass && collection.length() != 0)
60 this->setClassAttributes(objectClass, collection,
true);
61 this->setFactoryForManager(qobject_cast<QtDoublePropertyManager*>(doubleManager), qobject_cast<QtDoubleSpinBoxFactory*>(spinBoxFactory));
72 currentSceneObject = sceneObject;
73 this->setInstanceAttributes();
74 this->setFactoryForManager(qobject_cast<QtDoublePropertyManager*>(doubleManager), qobject_cast<QtDoubleSpinBoxFactory*>(spinBoxFactory));
79 void gui::PropertyBrowserWidget::valueChanged(
QtProperty* property,
double newValue)
82 if (!propertyToId.contains(property) || !currentSceneObject || propertyToValue[property] == newValue)
89 propertyToValue[property] = newValue;
90 std::shared_ptr<std::vector<controller::OperationPtr> > operations(
new std::vector<controller::OperationPtr>());
94 currentSceneObject->getObjectId(),
95 currentSceneObject->getRotation(),
96 this->createNewRotation(property, newValue),
97 currentSceneObject->getTranslation(),
98 this->createNewTranslation(property, newValue)));
99 operations->push_back(operation);
105 void gui::PropertyBrowserWidget::setInstanceAttributes()
107 QtProperty* instanceAttributes = groupManager->addProperty(tr(
"Instance Attributes"));
109 QtProperty* objectID = stringManager->addProperty(tr(
"Object ID"));
110 stringManager->setValue(objectID, QString::fromStdString(currentSceneObject->getObjectId()));
114 QtProperty* quaternion = groupManager->addProperty(tr(
"Rotation as Quaternion"));
116 float xQuat, yQuat, zQuat, wQuat;
117 currentSceneObject->getRotation().getValue(xQuat, yQuat, zQuat, wQuat);
119 QtProperty* quaternionX = doubleManager->addProperty(tr(
"x"));
120 QtProperty* quaternionY = doubleManager->addProperty(tr(
"y"));
121 QtProperty* quaternionZ = doubleManager->addProperty(tr(
"z"));
122 QtProperty* quaternionW = doubleManager->addProperty(tr(
"w"));
125 propertyToValue[quaternionX] = (double) xQuat;
126 propertyToValue[quaternionY] = (double) yQuat;
127 propertyToValue[quaternionZ] = (double) zQuat;
128 propertyToValue[quaternionW] = (double) wQuat;
130 doubleManager->setValue(quaternionX, (
double) xQuat);
131 doubleManager->setValue(quaternionY, (
double) yQuat);
132 doubleManager->setValue(quaternionZ, (
double) zQuat);
133 doubleManager->setValue(quaternionW, (
double) wQuat);
135 doubleManager->setSingleStep(quaternionW, 0.01);
136 doubleManager->setSingleStep(quaternionX, 0.01);
137 doubleManager->setSingleStep(quaternionY, 0.01);
138 doubleManager->setSingleStep(quaternionZ, 0.01);
146 QtProperty* rpy = groupManager->addProperty(tr(
"Roll-Pitch-Yaw"));
148 QtProperty* roll = doubleManager->addProperty(tr(
"Roll in deg"));
149 QtProperty* pitch = doubleManager->addProperty(tr(
"Pitch in deg"));
150 QtProperty* yaw = doubleManager->addProperty(tr(
"Yaw in deg"));
152 Eigen::Vector3f rpyVector;
153 VirtualRobot::MathTools::eigen4f2rpy(VirtualRobot::MathTools::quat2eigen4f(xQuat, yQuat, zQuat, wQuat), rpyVector);
155 float rollDeg, pitchDeg, yawDeg;
157 rollDeg = VirtualRobot::MathTools::rad2deg(rpyVector(0));
158 pitchDeg = VirtualRobot::MathTools::rad2deg(rpyVector(1));
159 yawDeg = VirtualRobot::MathTools::rad2deg(rpyVector(2));
161 propertyToValue[roll] = rollDeg;
162 propertyToValue[pitch] = pitchDeg;
163 propertyToValue[yaw] = yawDeg;
165 doubleManager->setValue(roll, rollDeg);
166 doubleManager->setValue(pitch, pitchDeg);
167 doubleManager->setValue(yaw, yawDeg);
169 doubleManager->setSingleStep(roll, 1);
170 doubleManager->setSingleStep(pitch, 1);
171 doubleManager->setSingleStep(yaw, 1);
178 QtProperty* translation = groupManager->addProperty(tr(
"Translation"));
180 float xPos, yPos, zPos;
181 currentSceneObject->getTranslation().getValue(xPos, yPos, zPos);
183 QtProperty* translationX = doubleManager->addProperty(tr(
"X Position"));
184 QtProperty* translationY = doubleManager->addProperty(tr(
"Y Position"));
185 QtProperty* translationZ = doubleManager->addProperty(tr(
"Z Position"));
188 propertyToValue[translationX] = (double) xPos;
189 propertyToValue[translationY] = (double) yPos;
190 propertyToValue[translationZ] = (double) zPos;
192 doubleManager->setValue(translationX, (
double) xPos);
193 doubleManager->setValue(translationY, (
double) yPos);
194 doubleManager->setValue(translationZ, (
double) zPos);
196 doubleManager->setSingleStep(translationX, 0.01);
197 doubleManager->setSingleStep(translationY, 0.01);
198 doubleManager->setSingleStep(translationZ, 0.01);
204 QtProperty* matrix = stringManager->addProperty(tr(
"Matrix"));
206 stringManager->setValue(matrix, QString::fromStdString(this->getMatrix()));
214 this->insertInMap(quaternionX,
"x");
215 this->insertInMap(quaternionY,
"y");
216 this->insertInMap(quaternionZ,
"z");
217 this->insertInMap(quaternionW,
"w");
218 this->insertInMap(roll,
"Roll in deg");
219 this->insertInMap(pitch,
"Pitch in deg");
220 this->insertInMap(yaw,
"Yaw in deg");
221 this->insertInMap(translationX,
"X Position");
222 this->insertInMap(translationY,
"Y Position");
223 this->insertInMap(translationZ,
"Z Position");
224 this->insertInMap(matrix,
"Matrix");
226 QtBrowserItem* instancesSection = this->addProperty(instanceAttributes);
227 setExpanded(instancesSection,
true);
229 std::string collection = currentSceneObject->getCollection();
230 std::string objectClass = currentSceneObject->getClassId();
234 this->setClassAttributes(
controller->getMemoryXController()->getPriorKnowlegdeController()->getObjectClassPtr(objectClass, collection), collection,
false);
238 void gui::PropertyBrowserWidget::setClassAttributes(
const memoryx::ObjectClassPtr& objectClass,
const std::string& collection,
bool expanded)
240 QtProperty* classAttributes = groupManager->addProperty(tr(
"Class Attributes"));
242 QtProperty* className = stringManager->addProperty(tr(
"Class Name"));
243 stringManager->setValue(className, QString::fromStdString(objectClass->getName()));
246 QtProperty* collectionName = stringManager->addProperty(tr(
"Collection"));
247 stringManager->setValue(collectionName, QString::fromStdString(collection));
250 QtProperty* objectClassID = stringManager->addProperty(tr(
"Object Class ID"));
251 stringManager->setValue(objectClassID, QString::fromStdString(objectClass->getId()));
254 std::map<std::string, std::string>::iterator iterator;
259 std::map<std::string, std::string> attributes =
controller->getMemoryXController()->getPriorKnowlegdeController()->getAllAttributes(objectClass);
261 for (iterator = attributes.begin(); iterator != attributes.end(); ++iterator)
263 QtProperty*
property = stringManager->addProperty(QString::fromStdString(iterator->first));
264 stringManager->setValue(property, QString::fromStdString(iterator->second));
269 QtBrowserItem* classesSection = this->addProperty(classAttributes);
271 setExpanded(classesSection, expanded);
274 void gui::PropertyBrowserWidget::clearAll()
277 groupManager->clear();
278 doubleManager->clear();
279 stringManager->clear();
280 propertyToId.clear();
281 idToProperty.clear();
282 propertyToValue.clear();
283 currentSceneObject = NULL;
288 if (!currentSceneObject || objectID != currentSceneObject->getObjectId())
294 float xQuat, yQuat, zQuat, wQuat;
295 currentSceneObject->getRotation().getValue(xQuat, yQuat, zQuat, wQuat);
298 propertyToValue[idToProperty[QString(
"x")]] = (double) xQuat;
299 propertyToValue[idToProperty[QString(
"y")]] = (double) yQuat;
300 propertyToValue[idToProperty[QString(
"z")]] = (double) zQuat;
301 propertyToValue[idToProperty[QString(
"w")]] = (double) wQuat;
303 doubleManager->setValue(idToProperty[QString(
"x")], (double) xQuat);
304 doubleManager->setValue(idToProperty[QString(
"y")], (double) yQuat);
305 doubleManager->setValue(idToProperty[QString(
"z")], (double) zQuat);
306 doubleManager->setValue(idToProperty[QString(
"w")], (double) wQuat);
308 Eigen::Vector3f rpyVector;
309 VirtualRobot::MathTools::eigen4f2rpy(VirtualRobot::MathTools::quat2eigen4f(xQuat, yQuat, zQuat, wQuat), rpyVector);
311 float rollDeg, pitchDeg, yawDeg;
313 rollDeg = VirtualRobot::MathTools::rad2deg(rpyVector(0));
314 pitchDeg = VirtualRobot::MathTools::rad2deg(rpyVector(1));
315 yawDeg = VirtualRobot::MathTools::rad2deg(rpyVector(2));
318 propertyToValue[idToProperty[QString(
"Roll in deg")]] = rollDeg;
319 propertyToValue[idToProperty[QString(
"Pitch in deg")]] = pitchDeg;
320 propertyToValue[idToProperty[QString(
"Yaw in deg")]] = yawDeg;
322 doubleManager->setValue(idToProperty[QString(
"Roll in deg")], rollDeg);
323 doubleManager->setValue(idToProperty[QString(
"Pitch in deg")], pitchDeg);
324 doubleManager->setValue(idToProperty[QString(
"Yaw in deg")], yawDeg);
327 float xPos, yPos, zPos;
328 currentSceneObject->getTranslation().getValue(xPos, yPos, zPos);
331 propertyToValue[idToProperty[QString(
"X Position")]] = (double) xPos;
332 propertyToValue[idToProperty[QString(
"Y Position")]] = (double) yPos;
333 propertyToValue[idToProperty[QString(
"Z Position")]] = (double) zPos;
335 doubleManager->setValue(idToProperty[QString(
"X Position")], (double) xPos);
336 doubleManager->setValue(idToProperty[QString(
"Y Position")], (double) yPos);
337 doubleManager->setValue(idToProperty[QString(
"Z Position")], (double) zPos);
341 stringManager->setValue(idToProperty[QString(
"Matrix")], QString::fromStdString(this->getMatrix()));
344 void gui::PropertyBrowserWidget::insertInMap(
QtProperty* property, QString
id)
346 propertyToId[property] = id;
347 idToProperty[id] = property;
351 SbRotation gui::PropertyBrowserWidget::createNewRotation(
QtProperty* property,
double val)
353 SbRotation newRotation = currentSceneObject->getRotation();
354 float xQuat, yQuat, zQuat, wQuat;
355 newRotation.getValue(xQuat, yQuat, zQuat, wQuat);
358 VirtualRobot::MathTools::eigen4f2rpy(VirtualRobot::MathTools::quat2eigen4f(xQuat, yQuat, zQuat, wQuat), rpy);
362 QString
id = propertyToId[property];
363 if (
id == QString(
"x") && !((
float) val == yQuat && yQuat == zQuat && zQuat == wQuat && wQuat == 0.0f))
365 newRotation = SbRotation((
float) val, yQuat, zQuat, wQuat);
367 else if (
id == QString(
"y") && !((
float) val == xQuat && xQuat == zQuat && zQuat == wQuat && wQuat == 0.0f))
369 newRotation = SbRotation(xQuat, (
float) val, zQuat, wQuat);
371 else if (
id == QString(
"z") && !((
float) val == xQuat && xQuat == yQuat && yQuat == wQuat && wQuat == 0.0f))
373 newRotation = SbRotation(xQuat, yQuat, (
float) val, wQuat);
375 else if (
id == QString(
"w") && !((
float) val == xQuat && xQuat == yQuat && yQuat == zQuat && zQuat == 0.0f))
377 newRotation = SbRotation(xQuat, yQuat, zQuat, (
float) val);
379 else if (
id == QString(
"Roll in deg"))
381 VirtualRobot::MathTools::rpy2eigen4f(VirtualRobot::MathTools::deg2rad((
float) val), rpy(1), rpy(2), rotationMatrix);
382 quaternion = VirtualRobot::MathTools::eigen4f2quat(rotationMatrix);
383 newRotation = SbRotation(quaternion.x, quaternion.y, quaternion.z, quaternion.w);
385 else if (
id == QString(
"Pitch in deg"))
387 VirtualRobot::MathTools::rpy2eigen4f(rpy(0), VirtualRobot::MathTools::deg2rad((
float) val), rpy(2), rotationMatrix);
388 quaternion = VirtualRobot::MathTools::eigen4f2quat(rotationMatrix);
389 newRotation = SbRotation(quaternion.x, quaternion.y, quaternion.z, quaternion.w);
391 else if (
id == QString(
"Yaw in deg"))
393 VirtualRobot::MathTools::rpy2eigen4f(rpy(0), rpy(1), VirtualRobot::MathTools::deg2rad((
float) val), rotationMatrix);
394 quaternion = VirtualRobot::MathTools::eigen4f2quat(rotationMatrix);
395 newRotation = SbRotation(quaternion.x, quaternion.y, quaternion.z, quaternion.w);
399 newRotation = currentSceneObject->getRotation();
404 newRotation.getValue(x, y, z, w);
406 VirtualRobot::MathTools::eigen4f2rpy(VirtualRobot::MathTools::quat2eigen4f(x, y, z, w), rot);
408 ARMARX_INFO_S <<
"Quat: \n" << x <<
", \n" << y <<
", \n" << z <<
", \n" << w;
414 SbVec3f gui::PropertyBrowserWidget::createNewTranslation(
QtProperty* property,
double val)
417 float xPos, yPos, zPos;
418 currentSceneObject->getTranslation().getValue(xPos, yPos, zPos);
420 QString
id = propertyToId[property];
422 if (
id == QString(
"X Position"))
424 newPosition = SbVec3f((
float) val, yPos, zPos);
426 else if (
id == QString(
"Y Position"))
428 newPosition = SbVec3f(xPos, (
float) val, zPos);
430 else if (
id == QString(
"Z Position"))
432 newPosition = SbVec3f(xPos, yPos, (
float) val);
436 newPosition = currentSceneObject->getTranslation();
443 std::string gui::PropertyBrowserWidget::getMatrix()
446 sbMatrix.setRotate(currentSceneObject->getRotation());
447 sbMatrix.setTranslate(currentSceneObject->getTranslation());
448 std::string matrixToString;
450 for (
int i = 0; i < 4; ++i)
452 matrixToString.append(
boost::str(boost::format(
"%3.2g %3.2g %3.2g %3.2g") %
453 sbMatrix[i][0] % sbMatrix[i][1] %
454 sbMatrix[i][2] % sbMatrix[i][3]));
458 matrixToString.append(
"\n");
462 return matrixToString;