Mod/Inspection/Gui/Command.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) YEAR YOUR NAME         <Your e-mail address>            *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 
00024 #include "PreCompiled.h"
00025 #ifndef _PreComp_
00026 #endif
00027 
00028 #include <Base/Console.h>
00029 #include <App/Document.h>
00030 #include <Gui/Application.h>
00031 #include <Gui/BitmapFactory.h>
00032 #include <Gui/Command.h>
00033 #include <Gui/Document.h>
00034 #include <Gui/MainWindow.h>
00035 #include <Gui/View3DInventor.h>
00036 #include <Gui/View3DInventorViewer.h>
00037 #include <Mod/Inspection/App/InspectionFeature.h>
00038 
00039 #include "VisualInspection.h"
00040 #include "ViewProviderInspection.h"
00041 
00042 
00043 DEF_STD_CMD_A(CmdVisualInspection);
00044 
00045 CmdVisualInspection::CmdVisualInspection()
00046   : Command("Inspection_VisualInspection")
00047 {
00048     sAppModule    = "Inspection";
00049     sGroup        = QT_TR_NOOP("Inspection");
00050     sMenuText     = QT_TR_NOOP("Visual inspection...");
00051     sToolTipText  = QT_TR_NOOP("Visual inspection");
00052     sStatusTip    = QT_TR_NOOP("Visual inspection");
00053     sWhatsThis    = "Inspection_VisualInspection";
00054 }
00055 
00056 void CmdVisualInspection::activated(int iMsg)
00057 {
00058     InspectionGui::VisualInspection dlg(Gui::getMainWindow());
00059     dlg.exec();
00060 }
00061 
00062 bool CmdVisualInspection::isActive(void)
00063 {
00064     return App::GetApplication().getActiveDocument();
00065 }
00066 
00067 //--------------------------------------------------------------------------------------
00068 
00069 DEF_STD_CMD_A(CmdInspectElement);
00070 
00071 CmdInspectElement::CmdInspectElement()
00072   : Command("Inspection_InspectElement")
00073 {
00074     sAppModule    = "Inspection";
00075     sGroup        = "Inspection";
00076     sMenuText     = "Inspection...";
00077     sToolTipText  = "Get distance information";
00078     sWhatsThis    = "Inspection_InspectElement";
00079     sStatusTip    = sToolTipText;
00080     sPixmap       = "mesh_pipette";
00081 }
00082 
00083 void CmdInspectElement::activated(int iMsg)
00084 {
00085     Gui::Document* doc = Gui::Application::Instance->activeDocument();
00086     Gui::View3DInventor* view = static_cast<Gui::View3DInventor*>(doc->getActiveView());
00087     if (view) {
00088         Gui::View3DInventorViewer* viewer = view->getViewer();
00089         viewer->setEditing(true);
00090         viewer->setRedirectToSceneGraph(true);
00091         viewer->setEditingCursor(QCursor(Gui::BitmapFactory().pixmap("mesh_pipette"),4,29));
00092         viewer->addEventCallback(SoButtonEvent::getClassTypeId(),
00093             InspectionGui::ViewProviderInspection::inspectCallback);
00094      }
00095 }
00096 
00097 bool CmdInspectElement::isActive(void)
00098 {
00099     App::Document* doc = App::GetApplication().getActiveDocument();
00100     if (!doc || doc->countObjectsOfType(Inspection::Feature::getClassTypeId()) == 0)
00101         return false;
00102 
00103     Gui::MDIView* view = Gui::getMainWindow()->activeWindow();
00104     if (view && view->isDerivedFrom(Gui::View3DInventor::getClassTypeId())) {
00105         Gui::View3DInventorViewer* viewer = static_cast<Gui::View3DInventor*>(view)->getViewer();
00106         return !viewer->isEditing();
00107     }
00108 
00109     return false;
00110 }
00111 
00112 void CreateInspectionCommands(void)
00113 {
00114     Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager();
00115     rcCmdMgr.addCommand(new CmdVisualInspection());
00116     rcCmdMgr.addCommand(new CmdInspectElement());
00117 }

Generated on Wed Nov 23 19:00:01 2011 for FreeCAD by  doxygen 1.6.1