24 #include <ArmarXGui/applications/ArmarXGui/ui_ViewerWidget.h>
25 #include <ArmarXGui/applications/ArmarXGui/ui_ViewerWidgetConfigDialog.h>
28 #include <Inventor/nodes/SoNode.h>
29 #include <Inventor/nodes/SoSeparator.h>
30 #include <Inventor/nodes/SoCamera.h>
31 #include <Inventor/actions/SoLineHighlightRenderAction.h>
32 #include <Inventor/actions/SoSearchAction.h>
34 #include "../ArmarXMainWindow.h"
36 #include <QGridLayout>
41 #include <QColorDialog>
42 #include <QPushButton>
43 #include <QDialogButtonBox>
49 #define ARMARX_ORGANIZATION "KIT"
50 #define ARMARX_GUI_APPLICATION_NAME "ArmarXGUI"
52 #define VIEWER_SETTINGS_AA "AntiAliasing"
53 #define VIEWER_SETTINGS_BACKGROUND_COLOR "BackgroundColor"
54 #define VIEWER_SETTINGS_TRANSPARENCY_TYPE "TransparencyType"
57 ui(new Ui_Viewer3DWidget),
60 settings(QString(settingsFile.c_str()), QSettings::NativeFormat),
61 viewingModeAction(NULL)
63 configDialog =
nullptr;
64 configDialogUi =
nullptr;
72 delete configDialogUi;
83 auto l =
viewer->getScopedLock();
95 SoNode* node = sceneMap[sceneName].node;
96 bool initializeView = find(selectedViews.begin(), selectedViews.end(), node) == selectedViews.end();
97 viewer->setSceneGraph(node);
101 if (initialCameraPoses.find(sceneName) != initialCameraPoses.end())
114 selectedViews.push_back(node);
121 std::set<QString> sceneNames;
122 for (
auto& key : settings->allKeys())
124 if (key.startsWith(
"camera."))
126 sceneNames.insert(key.split(
'.').at(1));
130 for (
auto& scene : sceneNames)
134 p.
position[0] = settings->value(
"camera." + scene +
".pos_x").toFloat();
135 p.
position[1] = settings->value(
"camera." + scene +
".pos_y").toFloat();
136 p.
position[2] = settings->value(
"camera." + scene +
".pos_z").toFloat();
138 p.
orientation[0] = settings->value(
"camera." + scene +
".ori_q1").toFloat();
139 p.
orientation[1] = settings->value(
"camera." + scene +
".ori_q2").toFloat();
140 p.
orientation[2] = settings->value(
"camera." + scene +
".ori_q3").toFloat();
141 p.
orientation[3] = settings->value(
"camera." + scene +
".ori_q4").toFloat();
143 p.
focalDistance = settings->value(
"camera." + scene +
".focalDistance").toFloat();
145 initialCameraPoses[scene] = p;
151 auto l =
viewer->getScopedLock();
153 selectedViews.clear();
160 for (
auto& scene : sceneMap.toStdMap())
163 a.setType(SoCamera::getClassTypeId(),
true);
164 a.setInterest(SoSearchAction::FIRST);
165 a.apply(scene.second.node);
172 SoCamera* cameraNode = (SoCamera*)
a.getPath()->getTail();
173 QString sceneName = scene.first;
175 settings->setValue(
"camera." + sceneName +
".pos_x", cameraNode->position.getValue().getValue()[0]);
176 settings->setValue(
"camera." + sceneName +
".pos_y", cameraNode->position.getValue().getValue()[1]);
177 settings->setValue(
"camera." + sceneName +
".pos_z", cameraNode->position.getValue().getValue()[2]);
179 settings->setValue(
"camera." + sceneName +
".ori_q1", cameraNode->orientation.getValue().getValue()[0]);
180 settings->setValue(
"camera." + sceneName +
".ori_q2", cameraNode->orientation.getValue().getValue()[1]);
181 settings->setValue(
"camera." + sceneName +
".ori_q3", cameraNode->orientation.getValue().getValue()[2]);
182 settings->setValue(
"camera." + sceneName +
".ori_q4", cameraNode->orientation.getValue().getValue()[3]);
184 settings->setValue(
"camera." + sceneName +
".focalDistance", cameraNode->focalDistance.getValue());
192 connect(guiMainWindow, SIGNAL(updateSceneList(QMap<QString, Viewer3DInfo>)),
this, SLOT(
sceneListUpdated(QMap<QString, Viewer3DInfo>)));
199 getWidget()->setContentsMargins(1, 1, 1, 1);
200 getWidget()->setFocusPolicy(Qt::WheelFocus);
202 QGridLayout* grid =
new QGridLayout();
203 grid->setContentsMargins(0, 0, 0, 0);
205 getWidget()->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
207 QWidget* view1 =
new QWidget(
getWidget());
208 view1->setMinimumSize(100, 100);
209 view1->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
211 viewer.reset(
new CoinViewer(view1,
"", TRUE, SoQtExaminerViewer::BUILD_POPUP));
218 viewer->setBackgroundColor(SbColor(1.0f, 1.0f, 1.0f));
219 viewer->setAccumulationBuffer(
false);
225 viewer->setFeedbackVisibility(
true);
226 viewer->setGLRenderAction(
new SoLineHighlightRenderAction());
233 label =
new QLabel(
"Scene:");
236 grid->addWidget(view1, 0, 0, 1, 3);
237 grid->addWidget(
label, 1, 0);
240 grid->setColumnMinimumWidth(2, 20);
247 if (
index >= 0 && index < cb3DViewers->count())
250 auto sceneConfigDialog = sceneMap[sceneName].sceneConfigDialog;
252 if (sceneConfigDialog)
254 sceneConfigDialog->open();
261 configDialogUi =
new Ui_ViewerWidgetConfigDialog;
262 configDialogUi->setupUi(configDialog);
265 connect(configDialogUi->buttonBox->button(QDialogButtonBox::Save), SIGNAL(clicked()),
this, SLOT(
configDialogSaveSettings()));
266 connect(configDialogUi->pushButtonPickColor, SIGNAL(pressed()),
this, SLOT(
configDialogPickColor()));
292 if (parent != customToolbar->parent())
294 customToolbar->setParent(parent);
297 return customToolbar;
300 customToolbar =
new QToolBar(parent);
301 customToolbar->setIconSize(QSize(16, 16));
302 customToolbar->addAction(QIcon(
":/icons/configure-3.png"),
"Configure",
this, SLOT(
configDialogOpen()));
304 viewingModeAction = customToolbar->addAction(QIcon(
":/icons/hand.svg"),
"Viewing Mode (V)",
this, SLOT(
toggleViewingMode()));
305 viewingModeAction->setShortcut(QKeySequence(Qt::Key_V));
306 viewingModeAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
307 getWidget()->addAction(viewingModeAction);
308 viewingModeAction->setCheckable(
true);
309 viewingModeAction->setChecked(
true);
311 QAction* viewAllAction =
new QAction(QIcon(
":icons/zoom-original-2.png"),
"View All (A)",
getWidget());
312 customToolbar->addAction(viewAllAction);
313 viewAllAction->setShortcut(QKeySequence(tr(
"A")));
314 viewAllAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
315 connect(viewAllAction, SIGNAL(triggered()),
this, SLOT(
viewAll()));
318 return customToolbar;
324 if (
index >= 0 && index < cb3DViewers->count())
327 auto sceneConfigDialog = sceneMap[sceneName].sceneConfigDialog;
345 auto l =
viewer->getScopedLock();
347 this->sceneMap = sceneMap;
356 QMap<QString, Viewer3DInfo> ::iterator it = sceneMap.begin();
357 std::vector<SoNode*> newSelectedList;
359 for (; it != sceneMap.end(); it++)
363 if (find(selectedViews.begin(), selectedViews.end(), it.value().node) != selectedViews.end())
365 newSelectedList.push_back(it.value().node);
369 selectedViews = newSelectedList;
371 if (oldIndex < cb3DViewers->count())
382 if (!color.isValid())
390 p.setColor(QPalette::Button, color);
391 configDialogUi->pushButtonPickColor->setPalette(p);
398 viewingModeAction->setChecked(
viewer->isViewing());
400 ARMARX_INFO <<
"Viewing mode " << (
viewer->isViewing() ?
"enabled" :
"disabled");
413 SbColor
c =
viewer->getBackgroundColor();
416 configDialog->show();
423 if (configDialogUi->checkBoxMultipass->isChecked())
425 numPasses = pow(2, (configDialogUi->comboBoxMultipass->currentIndex() + 1));
427 viewer->setAccumulationBuffer(
false);
428 viewer->setAntialiasing((numPasses > 0), numPasses);
429 ARMARX_INFO <<
"Multipass Anti Aliasing: " << numPasses <<
"x";
431 QColor color = configDialogUi->pushButtonPickColor->palette().color(QPalette::Button);
432 viewer->setBackgroundColor(SbColor(color.red() / 255.0, color.green() / 255.0, color.blue() / 255.0));
433 ARMARX_INFO <<
"Background Color: (" << color.red() <<
", " << color.green() <<
", " << color.blue() <<
")";
435 if (configDialogUi->checkBoxTransparency->isChecked())
437 switch (configDialogUi->comboBoxTransparencyType->currentIndex())
440 viewer->setTransparencyType(SoGLRenderAction::BLEND);
444 viewer->setTransparencyType(SoGLRenderAction::SORTED_OBJECT_BLEND);
448 viewer->setTransparencyType(SoGLRenderAction::SORTED_LAYERS_BLEND);
458 viewer->setAlphaChannel(
false);
466 if (!configDialogUi->checkBoxTransparency->isChecked())
475 if (!configDialogUi->checkBoxMultipass->isChecked())
481 settings.setValue(
VIEWER_SETTINGS_AA, configDialogUi->comboBoxMultipass->currentIndex());
490 configDialogUi->checkBoxTransparency->setChecked(transparencyType != -1);
491 configDialogUi->comboBoxTransparencyType->setCurrentIndex(transparencyType);
494 configDialogUi->checkBoxMultipass->setChecked(antiAliasing != -1);
495 configDialogUi->comboBoxMultipass->setCurrentIndex(antiAliasing);
498 if (backgroundColor.isValid())
501 p.setColor(QPalette::Button, backgroundColor);
502 configDialogUi->pushButtonPickColor->setPalette(p);
519 label->setVisible(
false);
526 label->setVisible(
true);