void PropertyEnumAttacherItem::openTask()
{
    Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog();
    TaskDlgAttacher* task;
    task = qobject_cast<TaskDlgAttacher*>(dlg);

    if (dlg && !task) {
        // there is already another task dialog which must be closed first
        Gui::Control().showDialog(dlg);
        return;
    }
    if (!task) {
        const App::Property* prop = getFirstProperty();
        if (prop) {
            App::PropertyContainer* parent = prop->getContainer();

            if (parent->getTypeId().isDerivedFrom(App::DocumentObject::getClassTypeId())) {
                App::DocumentObject* obj = static_cast<App::DocumentObject*>(parent);
                Gui::ViewProvider* view = Gui::Application::Instance->getViewProvider(obj);

                if (view->getTypeId().isDerivedFrom(Gui::ViewProviderDocumentObject::getClassTypeId())) {
                    task = new TaskDlgAttacher(static_cast<Gui::ViewProviderDocumentObject*>(view));
                }
            }
        }
        if (!task) {
            return;
        }
    }
    
    Gui::Control().showDialog(task);
}
Example #2
0
void MeshSelection::pickFaceCallback(void * ud, SoEventCallback * n)
{
    // handle only mouse button events
    if (n->getEvent()->isOfType(SoMouseButtonEvent::getClassTypeId())) {
        const SoMouseButtonEvent * mbe = static_cast<const SoMouseButtonEvent*>(n->getEvent());
        Gui::View3DInventorViewer* view  = reinterpret_cast<Gui::View3DInventorViewer*>(n->getUserData());

        // Mark all incoming mouse button events as handled, especially, to deactivate the selection node
        n->getAction()->setHandled();
        if (mbe->getButton() == SoMouseButtonEvent::BUTTON1 && mbe->getState() == SoButtonEvent::DOWN) {
            const SoPickedPoint * point = n->getPickedPoint();
            if (point == NULL) {
                Base::Console().Message("No facet picked.\n");
                return;
            }

            n->setHandled();

            // By specifying the indexed mesh node 'pcFaceSet' we make sure that the picked point is
            // really from the mesh we render and not from any other geometry
            Gui::ViewProvider* vp = static_cast<Gui::ViewProvider*>(view->getViewProviderByPath(point->getPath()));
            if (!vp || !vp->getTypeId().isDerivedFrom(ViewProviderMesh::getClassTypeId()))
                return;
            ViewProviderMesh* mesh = static_cast<ViewProviderMesh*>(vp);
            MeshSelection* self = reinterpret_cast<MeshSelection*>(ud);
            std::list<ViewProviderMesh*> views = self->getViewProviders();
            if (std::find(views.begin(), views.end(), mesh) == views.end())
                return;
            const SoDetail* detail = point->getDetail(/*mesh->getShapeNode()*/);
            if (detail && detail->getTypeId() == SoFaceDetail::getClassTypeId()) {
                // get the boundary to the picked facet
                unsigned long uFacet = static_cast<const SoFaceDetail*>(detail)->getFaceIndex();
                if (self->addToSelection) {
                    if (self->addComponent)
                        mesh->selectComponent(uFacet);
                    else
                        mesh->selectFacet(uFacet);
                }
                else {
                    if (self->removeComponent)
                        mesh->deselectComponent(uFacet);
                    else
                        mesh->deselectFacet(uFacet);
                }
            }
        }
    }
}
Example #3
0
/**
 * Handle if the a view provider is about to being destroyed.
 */
void ManualAlignment::slotDeletedObject(const Gui::ViewProvider& Obj)
{
    // remove the view provider either from the left or the right view
    if (Obj.getTypeId().isDerivedFrom(Gui::ViewProviderDocumentObject::getClassTypeId())) {
        // remove the view provider immediately from the split window
        bool found = false;
        Gui::ViewProviderDocumentObject* vp = const_cast<Gui::ViewProviderDocumentObject*>
                                      (static_cast<const Gui::ViewProviderDocumentObject*>(&Obj));
        if (myAlignModel.activeGroup().hasView(vp)) {
            myViewer->getViewer(0)->removeViewProvider(vp);
            found = true;
        }
        if (myFixedGroup.hasView(vp)) {
            myViewer->getViewer(1)->removeViewProvider(vp);
            found = true;
        }

        if (found)
            cancel();
    }
}
void ViewProviderInspection::inspectCallback(void * ud, SoEventCallback * n)
{
    Gui::View3DInventorViewer* view  = reinterpret_cast<Gui::View3DInventorViewer*>(n->getUserData());
    const SoEvent* ev = n->getEvent();
    if (ev->getTypeId() == SoMouseButtonEvent::getClassTypeId()) {
        const SoMouseButtonEvent * mbe = static_cast<const SoMouseButtonEvent *>(ev);

        // Mark all incoming mouse button events as handled, especially, to deactivate the selection node
        n->getAction()->setHandled();
        n->setHandled();
        if (mbe->getButton() == SoMouseButtonEvent::BUTTON2 && mbe->getState() == SoButtonEvent::UP) {
            n->setHandled();
            // context-menu
            QMenu menu;
            QAction* fl = menu.addAction(QObject::tr("Annotation"));
            fl->setCheckable(true);
            fl->setChecked(addflag);
            QAction* cl = menu.addAction(QObject::tr("Leave info mode"));
            QAction* id = menu.exec(QCursor::pos());
            if (fl == id) {
                addflag = fl->isChecked();
            }
            else if (cl == id) {
                // post an event to a proxy object to make sure to avoid problems
                // when opening a modal dialog
                QApplication::postEvent(
                    new ViewProviderProxyObject(view->getGLWidget()),
                    new QEvent(QEvent::User));
                view->setEditing(false);
                view->getWidget()->setCursor(QCursor(Qt::ArrowCursor));
                view->setRedirectToSceneGraph(false);
                view->setRedirectToSceneGraphEnabled(false);
                view->removeEventCallback(SoButtonEvent::getClassTypeId(), inspectCallback);
            }
        }
        else if (mbe->getButton() == SoMouseButtonEvent::BUTTON1 && mbe->getState() == SoButtonEvent::UP) {
            const SoPickedPoint * point = n->getPickedPoint();
            if (point == NULL) {
                Base::Console().Message("No point picked.\n");
                return;
            }

            n->setHandled();

            // check if we have picked one a node of the view provider we are insterested in
            Gui::ViewProvider* vp = static_cast<Gui::ViewProvider*>(view->getViewProviderByPath(point->getPath()));
            if (vp && vp->getTypeId().isDerivedFrom(ViewProviderInspection::getClassTypeId())) {
                ViewProviderInspection* that = static_cast<ViewProviderInspection*>(vp);
                QString info = that->inspectDistance(point);
                Gui::getMainWindow()->setPaneText(1,info);
                if (addflag)
                    ViewProviderProxyObject::addFlag(view, info, point);
                else
                    Gui::ToolTip::showText(QCursor::pos(), info);
            }
            else {
                // the nearest picked point was not part of the view provider
                SoRayPickAction action(view->getViewportRegion());
                action.setPickAll(TRUE);
                action.setPoint(mbe->getPosition());
                action.apply(view->getSceneManager()->getSceneGraph());

                const SoPickedPointList& pps = action.getPickedPointList();
                for (int i=0; i<pps.getLength(); ++i) {
                    const SoPickedPoint * point = pps[i];
                    vp = static_cast<Gui::ViewProvider*>(view->getViewProviderByPath(point->getPath()));
                    if (vp && vp->getTypeId().isDerivedFrom(ViewProviderInspection::getClassTypeId())) {
                        ViewProviderInspection* that = static_cast<ViewProviderInspection*>(vp);
                        QString info = that->inspectDistance(point);
                        Gui::getMainWindow()->setPaneText(1,info);
                        if (addflag)
                            ViewProviderProxyObject::addFlag(view, info, point);
                        else
                            Gui::ToolTip::showText(QCursor::pos(), info);
                        break;
                    }
                }
            }
        }
    }
    // toggle between inspection and navigation mode
    else if (ev->getTypeId().isDerivedFrom(SoKeyboardEvent::getClassTypeId())) {
        const SoKeyboardEvent * const ke = static_cast<const SoKeyboardEvent *>(ev);
        if (ke->getState() == SoButtonEvent::DOWN &&
            ke->getKey() == SoKeyboardEvent::ESCAPE) {
            SbBool toggle = view->isRedirectedToSceneGraph();
            view->setRedirectToSceneGraph(!toggle);
            n->setHandled();
        }
    }
}
Example #5
0
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();
                }
            }
        }
    }
}