25 #include <ArmarXGui/applications/ArmarXGui/ui_ViewerWidget.h>
26 #include <ArmarXGui/applications/ArmarXGui/ui_ViewerWidgetConfigDialog.h>
30 #include <QColorDialog>
33 #include <QDialogButtonBox>
34 #include <QGridLayout>
36 #include <QPushButton>
40 #include "../ArmarXMainWindow.h"
41 #include <Inventor/actions/SoLineHighlightRenderAction.h>
42 #include <Inventor/actions/SoSearchAction.h>
43 #include <Inventor/nodes/SoCamera.h>
44 #include <Inventor/nodes/SoNode.h>
45 #include <Inventor/nodes/SoSeparator.h>
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),
61 settings(QString(settingsFile.c_str()), QSettings::NativeFormat),
62 viewingModeAction(NULL)
64 configDialog =
nullptr;
65 configDialogUi =
nullptr;
73 delete configDialogUi;
85 auto l =
viewer->getScopedLock();
97 SoNode* node = sceneMap[sceneName].node;
99 find(selectedViews.begin(), selectedViews.end(), node) == selectedViews.end();
100 viewer->setSceneGraph(node);
104 if (initialCameraPoses.find(sceneName) != initialCameraPoses.end())
108 viewer->getCamera()->position.setValue(
110 viewer->getCamera()->orientation.setValue(
119 selectedViews.push_back(node);
127 std::set<QString> sceneNames;
128 for (
auto& key : settings->allKeys())
130 if (key.startsWith(
"camera."))
132 sceneNames.insert(key.split(
'.').at(1));
136 for (
auto& scene : sceneNames)
140 p.
position[0] = settings->value(
"camera." + scene +
".pos_x").toFloat();
141 p.
position[1] = settings->value(
"camera." + scene +
".pos_y").toFloat();
142 p.
position[2] = settings->value(
"camera." + scene +
".pos_z").toFloat();
144 p.
orientation[0] = settings->value(
"camera." + scene +
".ori_q1").toFloat();
145 p.
orientation[1] = settings->value(
"camera." + scene +
".ori_q2").toFloat();
146 p.
orientation[2] = settings->value(
"camera." + scene +
".ori_q3").toFloat();
147 p.
orientation[3] = settings->value(
"camera." + scene +
".ori_q4").toFloat();
149 p.
focalDistance = settings->value(
"camera." + scene +
".focalDistance").toFloat();
151 initialCameraPoses[scene] = p;
157 auto l =
viewer->getScopedLock();
159 selectedViews.clear();
167 for (
auto& scene : sceneMap.toStdMap())
170 a.setType(SoCamera::getClassTypeId(),
true);
171 a.setInterest(SoSearchAction::FIRST);
172 a.apply(scene.second.node);
179 SoCamera* cameraNode = (SoCamera*)
a.getPath()->getTail();
180 QString sceneName = scene.first;
182 settings->setValue(
"camera." + sceneName +
".pos_x",
183 cameraNode->position.getValue().getValue()[0]);
184 settings->setValue(
"camera." + sceneName +
".pos_y",
185 cameraNode->position.getValue().getValue()[1]);
186 settings->setValue(
"camera." + sceneName +
".pos_z",
187 cameraNode->position.getValue().getValue()[2]);
189 settings->setValue(
"camera." + sceneName +
".ori_q1",
190 cameraNode->orientation.getValue().getValue()[0]);
191 settings->setValue(
"camera." + sceneName +
".ori_q2",
192 cameraNode->orientation.getValue().getValue()[1]);
193 settings->setValue(
"camera." + sceneName +
".ori_q3",
194 cameraNode->orientation.getValue().getValue()[2]);
195 settings->setValue(
"camera." + sceneName +
".ori_q4",
196 cameraNode->orientation.getValue().getValue()[3]);
198 settings->setValue(
"camera." + sceneName +
".focalDistance",
199 cameraNode->focalDistance.getValue());
208 connect(guiMainWindow,
209 SIGNAL(updateSceneList(QMap<QString, Viewer3DInfo>)),
219 getWidget()->setContentsMargins(1, 1, 1, 1);
220 getWidget()->setFocusPolicy(Qt::WheelFocus);
222 QGridLayout* grid =
new QGridLayout();
223 grid->setContentsMargins(0, 0, 0, 0);
225 getWidget()->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
227 QWidget* view1 =
new QWidget(
getWidget());
228 view1->setMinimumSize(100, 100);
229 view1->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
231 viewer.reset(
new CoinViewer(view1,
"", TRUE, SoQtExaminerViewer::BUILD_POPUP));
238 viewer->setBackgroundColor(SbColor(1.0f, 1.0f, 1.0f));
239 viewer->setAccumulationBuffer(
false);
245 viewer->setFeedbackVisibility(
true);
246 viewer->setGLRenderAction(
new SoLineHighlightRenderAction());
253 label =
new QLabel(
"Scene:");
255 new QPushButton(QIcon(
":/icons/configure-3.png"),
"",
getWidget());
257 grid->addWidget(view1, 0, 0, 1, 3);
258 grid->addWidget(
label, 1, 0);
261 grid->setColumnMinimumWidth(2, 20);
266 &QPushButton::pressed,
271 if (
index >= 0 && index < cb3DViewers->count())
274 auto sceneConfigDialog = sceneMap[sceneName].sceneConfigDialog;
276 if (sceneConfigDialog)
278 sceneConfigDialog->open();
285 configDialogUi =
new Ui_ViewerWidgetConfigDialog;
286 configDialogUi->setupUi(configDialog);
290 connect(configDialogUi->buttonBox->button(QDialogButtonBox::Save),
294 connect(configDialogUi->pushButtonPickColor,
326 if (parent != customToolbar->parent())
328 customToolbar->setParent(parent);
331 return customToolbar;
334 customToolbar =
new QToolBar(parent);
335 customToolbar->setIconSize(QSize(16, 16));
336 customToolbar->addAction(
337 QIcon(
":/icons/configure-3.png"),
"Configure",
this, SLOT(
configDialogOpen()));
339 viewingModeAction = customToolbar->addAction(
341 viewingModeAction->setShortcut(QKeySequence(Qt::Key_V));
342 viewingModeAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
343 getWidget()->addAction(viewingModeAction);
344 viewingModeAction->setCheckable(
true);
345 viewingModeAction->setChecked(
true);
347 QAction* viewAllAction =
348 new QAction(QIcon(
":icons/zoom-original-2.png"),
"View All (A)",
getWidget());
349 customToolbar->addAction(viewAllAction);
350 viewAllAction->setShortcut(QKeySequence(tr(
"A")));
351 viewAllAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
352 connect(viewAllAction, SIGNAL(triggered()),
this, SLOT(
viewAll()));
355 return customToolbar;
362 if (
index >= 0 && index < cb3DViewers->count())
365 auto sceneConfigDialog = sceneMap[sceneName].sceneConfigDialog;
384 auto l =
viewer->getScopedLock();
386 this->sceneMap = sceneMap;
395 QMap<QString, Viewer3DInfo>::iterator it = sceneMap.begin();
396 std::vector<SoNode*> newSelectedList;
398 for (; it != sceneMap.end(); it++)
402 if (find(selectedViews.begin(), selectedViews.end(), it.value().node) !=
405 newSelectedList.push_back(it.value().node);
409 selectedViews = newSelectedList;
411 if (oldIndex < cb3DViewers->count())
423 if (!color.isValid())
431 p.setColor(QPalette::Button, color);
432 configDialogUi->pushButtonPickColor->setPalette(p);
440 viewingModeAction->setChecked(
viewer->isViewing());
442 ARMARX_INFO <<
"Viewing mode " << (
viewer->isViewing() ?
"enabled" :
"disabled");
457 SbColor
c =
viewer->getBackgroundColor();
460 configDialog->show();
468 if (configDialogUi->checkBoxMultipass->isChecked())
470 numPasses = pow(2, (configDialogUi->comboBoxMultipass->currentIndex() + 1));
472 viewer->setAccumulationBuffer(
false);
473 viewer->setAntialiasing((numPasses > 0), numPasses);
474 ARMARX_INFO <<
"Multipass Anti Aliasing: " << numPasses <<
"x";
476 QColor color = configDialogUi->pushButtonPickColor->palette().color(QPalette::Button);
477 viewer->setBackgroundColor(
478 SbColor(color.red() / 255.0, color.green() / 255.0, color.blue() / 255.0));
479 ARMARX_INFO <<
"Background Color: (" << color.red() <<
", " << color.green() <<
", "
480 << color.blue() <<
")";
482 if (configDialogUi->checkBoxTransparency->isChecked())
484 switch (configDialogUi->comboBoxTransparencyType->currentIndex())
487 viewer->setTransparencyType(SoGLRenderAction::BLEND);
491 viewer->setTransparencyType(SoGLRenderAction::SORTED_OBJECT_BLEND);
495 viewer->setTransparencyType(SoGLRenderAction::SORTED_LAYERS_BLEND);
505 viewer->setAlphaChannel(
false);
514 if (!configDialogUi->checkBoxTransparency->isChecked())
521 configDialogUi->comboBoxTransparencyType->currentIndex());
524 if (!configDialogUi->checkBoxMultipass->isChecked())
531 configDialogUi->comboBoxMultipass->currentIndex());
535 configDialogUi->pushButtonPickColor->palette().color(QPalette::Button));
542 configDialogUi->checkBoxTransparency->setChecked(transparencyType != -1);
543 configDialogUi->comboBoxTransparencyType->setCurrentIndex(transparencyType);
546 configDialogUi->checkBoxMultipass->setChecked(antiAliasing != -1);
547 configDialogUi->comboBoxMultipass->setCurrentIndex(antiAliasing);
549 QColor backgroundColor =
551 if (backgroundColor.isValid())
554 p.setColor(QPalette::Button, backgroundColor);
555 configDialogUi->pushButtonPickColor->setPalette(p);
575 label->setVisible(
false);
583 label->setVisible(
true);