FreeCAD
120 строк · 4.7 Кб
1/***************************************************************************
2* Copyright (c) 2011 Werner Mayer <wmayer[at]users.sourceforge.net> *
3* *
4* This file is part of the FreeCAD CAx development system. *
5* *
6* This library is free software; you can redistribute it and/or *
7* modify it under the terms of the GNU Library General Public *
8* License as published by the Free Software Foundation; either *
9* version 2 of the License, or (at your option) any later version. *
10* *
11* This library is distributed in the hope that it will be useful, *
12* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14* GNU Library General Public License for more details. *
15* *
16* You should have received a copy of the GNU Library General Public *
17* License along with this library; see the file COPYING.LIB. If not, *
18* write to the Free Software Foundation, Inc., 59 Temple Place, *
19* Suite 330, Boston, MA 02111-1307, USA *
20* *
21***************************************************************************/
22
23#include "PreCompiled.h"24#ifndef _PreComp_25#include <Inventor/events/SoButtonEvent.h>26#endif27
28#include <App/Document.h>29#include <Gui/Application.h>30#include <Gui/BitmapFactory.h>31#include <Gui/Command.h>32#include <Gui/Document.h>33#include <Gui/MainWindow.h>34#include <Gui/View3DInventor.h>35#include <Gui/View3DInventorViewer.h>36#include <Mod/Inspection/App/InspectionFeature.h>37
38#include "ViewProviderInspection.h"39#include "VisualInspection.h"40
41
42DEF_STD_CMD_A(CmdVisualInspection)43
44CmdVisualInspection::CmdVisualInspection()45: Command("Inspection_VisualInspection")46{
47sAppModule = "Inspection";48sGroup = QT_TR_NOOP("Inspection");49sMenuText = QT_TR_NOOP("Visual inspection...");50sToolTipText = QT_TR_NOOP("Visual inspection");51sStatusTip = QT_TR_NOOP("Visual inspection");52sWhatsThis = "Inspection_VisualInspection";53}
54
55void CmdVisualInspection::activated(int)56{
57InspectionGui::VisualInspection dlg(Gui::getMainWindow());58dlg.exec();59}
60
61bool CmdVisualInspection::isActive()62{
63return App::GetApplication().getActiveDocument();64}
65
66//--------------------------------------------------------------------------------------
67
68DEF_STD_CMD_A(CmdInspectElement)69
70CmdInspectElement::CmdInspectElement()71: Command("Inspection_InspectElement")72{
73sAppModule = "Inspection";74sGroup = QT_TR_NOOP("Inspection");75sMenuText = QT_TR_NOOP("Inspection...");76sToolTipText = QT_TR_NOOP("Get distance information");77sWhatsThis = "Inspection_InspectElement";78sStatusTip = sToolTipText;79sPixmap = "inspect_pipette";80}
81
82void CmdInspectElement::activated(int)83{
84Gui::Document* doc = Gui::Application::Instance->activeDocument();85Gui::View3DInventor* view = static_cast<Gui::View3DInventor*>(doc->getActiveView());86if (view) {87Gui::View3DInventorViewer* viewer = view->getViewer();88viewer->setEditing(true);89viewer->setRedirectToSceneGraphEnabled(true);90viewer->setRedirectToSceneGraph(true);91viewer->setSelectionEnabled(false);92viewer->setEditingCursor(93QCursor(Gui::BitmapFactory().pixmapFromSvg("inspect_pipette", QSize(32, 32)), 4, 29));94viewer->addEventCallback(SoButtonEvent::getClassTypeId(),95InspectionGui::ViewProviderInspection::inspectCallback);96}97}
98
99bool CmdInspectElement::isActive()100{
101App::Document* doc = App::GetApplication().getActiveDocument();102if (!doc || doc->countObjectsOfType(Inspection::Feature::getClassTypeId()) == 0) {103return false;104}105
106Gui::MDIView* view = Gui::getMainWindow()->activeWindow();107if (view && view->isDerivedFrom(Gui::View3DInventor::getClassTypeId())) {108Gui::View3DInventorViewer* viewer = static_cast<Gui::View3DInventor*>(view)->getViewer();109return !viewer->isEditing();110}111
112return false;113}
114
115void CreateInspectionCommands()116{
117Gui::CommandManager& rcCmdMgr = Gui::Application::Instance->commandManager();118rcCmdMgr.addCommand(new CmdVisualInspection());119rcCmdMgr.addCommand(new CmdInspectElement());120}
121