CommandFeat.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2002 Jürgen Riegel <juergen.riegel@web.de>              *
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 
00026 #include <App/DocumentObject.h>
00027 
00028 #include "Application.h"
00029 #include "Command.h"
00030 #include "Document.h"
00031 #include "Selection.h"
00032 #include "ViewProvider.h"
00033 #include "ViewProviderDocumentObject.h"
00034 
00035 using namespace Gui;
00036 
00037 
00038 
00039 //===========================================================================
00040 // Std_Recompute
00041 //===========================================================================
00042 
00043 DEF_STD_CMD(StdCmdFeatRecompute);
00044 
00045 StdCmdFeatRecompute::StdCmdFeatRecompute()
00046   :Command("Std_Recompute")
00047 {
00048     // seting the
00049     sGroup        = QT_TR_NOOP("File");
00050     sMenuText     = QT_TR_NOOP("&Recompute");
00051     sToolTipText  = QT_TR_NOOP("Recompute feature or document");
00052     sWhatsThis    = QT_TR_NOOP("Recompute feature or document");
00053     sStatusTip    = QT_TR_NOOP("Recompute feature or document");
00054     sPixmap       = "view-refresh";
00055     sAccel        = "Ctrl+R";
00056 }
00057 
00058 void StdCmdFeatRecompute::activated(int iMsg)
00059 {
00060 }
00061 
00062 //===========================================================================
00063 // Std_RandomColor
00064 //===========================================================================
00065 
00066 DEF_STD_CMD_A(StdCmdRandomColor);
00067 
00068 StdCmdRandomColor::StdCmdRandomColor()
00069   :Command("Std_RandomColor")
00070 {
00071     sGroup        = QT_TR_NOOP("File");
00072     sMenuText     = QT_TR_NOOP("Random color");
00073     sToolTipText  = QT_TR_NOOP("Random color");
00074     sWhatsThis    = QT_TR_NOOP("Random color");
00075     sStatusTip    = QT_TR_NOOP("Random color");
00076 }
00077 
00078 void StdCmdRandomColor::activated(int iMsg)
00079 {
00080     // get the complete selection
00081     std::vector<SelectionSingleton::SelObj> sel = Selection().getCompleteSelection();
00082     for (std::vector<SelectionSingleton::SelObj>::iterator it = sel.begin(); it != sel.end(); ++it) {
00083         float fMax = (float)RAND_MAX;
00084         float fRed = (float)rand()/fMax;
00085         float fGrn = (float)rand()/fMax;
00086         float fBlu = (float)rand()/fMax;
00087 
00088         ViewProvider* view = Application::Instance->getDocument(it->pDoc)->getViewProvider(it->pObject);
00089         App::Property* color = view->getPropertyByName("ShapeColor");
00090         if (color && color->getTypeId() == App::PropertyColor::getClassTypeId()) {
00091             // get the view provider of the selected object and set the shape color
00092             doCommand(Gui, "Gui.getDocument(\"%s\").getObject(\"%s\").ShapeColor=(%.2f,%.2f,%.2f)"
00093                          , it->DocName, it->FeatName, fRed, fGrn, fBlu);
00094         }
00095     }
00096 }
00097 
00098 bool StdCmdRandomColor::isActive(void)
00099 {
00100     return (Gui::Selection().size() != 0);
00101 }
00102 
00103 
00104 namespace Gui {
00105 
00106 void CreateFeatCommands(void)
00107 {
00108     CommandManager &rcCmdMgr = Application::Instance->commandManager();
00109 
00110     rcCmdMgr.addCommand(new StdCmdFeatRecompute());
00111     rcCmdMgr.addCommand(new StdCmdRandomColor());
00112 }
00113 
00114 } // namespace Gui

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