void ManualAlignment::probePickedCallback(void * ud, SoEventCallback * n) { Gui::View3DInventorViewer* view = reinterpret_cast<Gui::View3DInventorViewer*>(n->getUserData()); const SoEvent* ev = n->getEvent(); if (ev->getTypeId() == SoMouseButtonEvent::getClassTypeId()) { // set as handled n->getAction()->setHandled(); n->setHandled(); const SoMouseButtonEvent * mbe = static_cast<const SoMouseButtonEvent *>(ev); if (mbe->getButton() == SoMouseButtonEvent::BUTTON1 && mbe->getState() == SoButtonEvent::DOWN) { // if we are in 'align' mode then handle the click event ManualAlignment* self = ManualAlignment::instance(); // Get the closest point to the camera of the whole scene. // This point doesn't need to be part of this view provider. Gui::WaitCursor wc; const SoPickedPoint * point = view->getPickedPoint(n); if (point) { Gui::ViewProvider* vp = static_cast<Gui::ViewProvider*>(view->getViewProviderByPath(point->getPath())); if (vp && vp->getTypeId().isDerivedFrom(Gui::ViewProviderDocumentObject::getClassTypeId())) { Gui::ViewProviderDocumentObject* that = static_cast<Gui::ViewProviderDocumentObject*>(vp); if (self->applyPickedProbe(that, point)) { const SbVec3f& vec = point->getPoint(); Gui::getMainWindow()->showMessage( tr("Point picked at (%1,%2,%3)") .arg(vec[0]).arg(vec[1]).arg(vec[2])); } else { Gui::getMainWindow()->showMessage( tr("No point was found on model")); } } } else { Gui::getMainWindow()->showMessage( tr("No point was picked")); } } else if (mbe->getButton() == SoMouseButtonEvent::BUTTON2 && mbe->getState() == SoButtonEvent::UP) { ManualAlignment* self = ManualAlignment::instance(); if (self->myAlignModel.isEmpty() || self->myFixedGroup.isEmpty()) return; self->showInstructions(); int nPoints; if (view == self->myViewer->getViewer(0)) nPoints = self->myAlignModel.activeGroup().countPoints(); else nPoints = self->myFixedGroup.countPoints(); QMenu menu; QAction* fi = menu.addAction(QLatin1String("&Align")); QAction* rem = menu.addAction(QLatin1String("&Remove last point")); //QAction* cl = menu.addAction("C&lear"); QAction* ca = menu.addAction(QLatin1String("&Cancel")); fi->setEnabled(self->canAlign()); rem->setEnabled(nPoints > 0); menu.addSeparator(); QAction* sync = menu.addAction(QLatin1String("&Synchronize views")); sync->setCheckable(true); if (self->d->sensorCam1->getAttachedNode()) sync->setChecked(true); QAction* id = menu.exec(QCursor::pos()); if (id == fi) { // call align->align(); QTimer::singleShot(300, self, SLOT(onAlign())); } else if ((id == rem) && (view == self->myViewer->getViewer(0))) { QTimer::singleShot(300, self, SLOT(onRemoveLastPointMoveable())); } else if ((id == rem) && (view == self->myViewer->getViewer(1))) { QTimer::singleShot(300, self, SLOT(onRemoveLastPointFixed())); } //else if (id == cl) { // // call align->clear(); // QTimer::singleShot(300, self, SLOT(onClear())); //} else if (id == ca) { // call align->cancel(); QTimer::singleShot(300, self, SLOT(onCancel())); } else if (id == sync) { // setup sensor connection if (sync->isChecked()) { SoCamera* cam1 = self->myViewer->getViewer(0)->getSoRenderManager()->getCamera(); SoCamera* cam2 = self->myViewer->getViewer(1)->getSoRenderManager()->getCamera(); if (cam1 && cam2) { self->d->sensorCam1->attach(cam1); self->d->rot_cam1 = cam1->orientation.getValue(); self->d->pos_cam1 = cam1->position.getValue(); self->d->sensorCam2->attach(cam2); self->d->rot_cam2 = cam2->orientation.getValue(); self->d->pos_cam2 = cam2->position.getValue(); } } else { self->d->sensorCam1->detach(); self->d->sensorCam2->detach(); } } } } }