CommandMacro.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2010 Werner Mayer <wmayer[at]users.sourceforge.net>     *
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 "Command.h"
00029 #include "Application.h"
00030 #include "MainWindow.h"
00031 #include "DlgMacroExecuteImp.h"
00032 #include "DlgMacroRecordImp.h"
00033 #include "Macro.h"
00034 #include "PythonDebugger.h"
00035 
00036 using namespace Gui;
00037 
00038 
00039 //===========================================================================
00040 // Std_DlgMacroRecord
00041 //===========================================================================
00042 DEF_STD_CMD_A(StdCmdDlgMacroRecord);
00043 
00044 StdCmdDlgMacroRecord::StdCmdDlgMacroRecord()
00045   : Command("Std_DlgMacroRecord")
00046 {
00047     sGroup        = QT_TR_NOOP("Macro");
00048     sMenuText     = QT_TR_NOOP("&Macro recording ...");
00049     sToolTipText  = QT_TR_NOOP("Opens a dialog to record a macro");
00050     sWhatsThis    = "Std_DlgMacroRecord";
00051     sStatusTip    = QT_TR_NOOP("Opens a dialog to record a macro");
00052     sPixmap       = "macro-record";
00053     eType         = 0;
00054 }
00055 
00056 void StdCmdDlgMacroRecord::activated(int iMsg)
00057 {
00058     Gui::Dialog::DlgMacroRecordImp cDlg(getMainWindow());
00059     cDlg.exec();
00060 }
00061 
00062 bool StdCmdDlgMacroRecord::isActive(void)
00063 {
00064     return ! (getGuiApplication()->macroManager()->isOpen());
00065 }
00066 
00067 //===========================================================================
00068 // Std_MacroStopRecord
00069 //===========================================================================
00070 DEF_STD_CMD_A(StdCmdMacroStopRecord);
00071 
00072 StdCmdMacroStopRecord::StdCmdMacroStopRecord()
00073   : Command("Std_MacroStopRecord")
00074 {
00075     sGroup        = QT_TR_NOOP("Macro");
00076     sMenuText     = QT_TR_NOOP("S&top macro recording");
00077     sToolTipText  = QT_TR_NOOP("Stop the macro recording session");
00078     sWhatsThis    = "Std_MacroStopRecord";
00079     sStatusTip    = QT_TR_NOOP("Stop the macro recording session");
00080     sPixmap       = "macro-stop";
00081     eType         = 0;
00082 }
00083 
00084 void StdCmdMacroStopRecord::activated(int iMsg)
00085 {
00086     getGuiApplication()->macroManager()->commit();
00087 }
00088 
00089 bool StdCmdMacroStopRecord::isActive(void)
00090 {
00091     return getGuiApplication()->macroManager()->isOpen();
00092 }
00093 
00094 //===========================================================================
00095 // Std_DlgMacroExecute
00096 //===========================================================================
00097 DEF_STD_CMD_A(StdCmdDlgMacroExecute);
00098 
00099 StdCmdDlgMacroExecute::StdCmdDlgMacroExecute()
00100   : Command("Std_DlgMacroExecute")
00101 {
00102     sGroup        = QT_TR_NOOP("Macro");
00103     sMenuText     = QT_TR_NOOP("Macros ...");
00104     sToolTipText  = QT_TR_NOOP("Opens a dialog to let you execute a recorded macro");
00105     sWhatsThis    = "Std_DlgMacroExecute";
00106     sStatusTip    = QT_TR_NOOP("Opens a dialog to let you execute a recorded macro");
00107     sPixmap       = "accessories-text-editor";
00108     eType         = 0;
00109 }
00110 
00111 void StdCmdDlgMacroExecute::activated(int iMsg)
00112 {
00113     Gui::Dialog::DlgMacroExecuteImp cDlg(getMainWindow());
00114     cDlg.exec();
00115 }
00116 
00117 bool StdCmdDlgMacroExecute::isActive(void)
00118 {
00119     return ! (getGuiApplication()->macroManager()->isOpen());
00120 }
00121 
00122 //===========================================================================
00123 // Std_DlgMacroExecuteDirect
00124 //===========================================================================
00125 DEF_STD_CMD_A(StdCmdDlgMacroExecuteDirect);
00126 
00127 StdCmdDlgMacroExecuteDirect::StdCmdDlgMacroExecuteDirect()
00128   : Command("Std_DlgMacroExecuteDirect")
00129 {
00130     sGroup        = QT_TR_NOOP("Macro");
00131     sMenuText     = QT_TR_NOOP("Execute macro");
00132     sToolTipText  = QT_TR_NOOP("Execute the macro in the editor");
00133     sWhatsThis    = "Std_DlgMacroExecuteDirect";
00134     sStatusTip    = QT_TR_NOOP("Execute the macro in the editor");
00135     sPixmap       = "macro-execute";
00136     sAccel        = "Ctrl+F6";
00137     eType         = 0;
00138 }
00139 
00140 void StdCmdDlgMacroExecuteDirect::activated(int iMsg)
00141 {
00142     doCommand(Command::Gui,"Gui.SendMsgToActiveView(\"Run\")");
00143 }
00144 
00145 bool StdCmdDlgMacroExecuteDirect::isActive(void)
00146 {
00147     return getGuiApplication()->sendHasMsgToActiveView("Run");
00148 }
00149 
00150 DEF_STD_CMD_A(StdCmdMacroStartDebug);
00151 
00152 StdCmdMacroStartDebug::StdCmdMacroStartDebug()
00153   : Command("Std_MacroStartDebug")
00154 {
00155     sGroup        = QT_TR_NOOP("Macro");
00156     sMenuText     = QT_TR_NOOP("Debug macro");
00157     sToolTipText  = QT_TR_NOOP("Start debugging of macro");
00158     sWhatsThis    = "Std_MacroStartDebug";
00159     sStatusTip    = QT_TR_NOOP("Start debugging of macro");
00160     sPixmap       = "debug-start";
00161     sAccel        = "F6";
00162     eType         = 0;
00163 }
00164 
00165 void StdCmdMacroStartDebug::activated(int iMsg)
00166 {
00167     doCommand(Command::Gui,"Gui.SendMsgToActiveView(\"StartDebug\")");
00168 }
00169 
00170 bool StdCmdMacroStartDebug::isActive(void)
00171 {
00172     static PythonDebugger* dbg = Application::Instance->macroManager()->debugger();
00173     return (!dbg->isRunning() &&
00174             getGuiApplication()->sendHasMsgToActiveView("StartDebug"));
00175 }
00176 
00177 DEF_STD_CMD_A(StdCmdMacroStopDebug);
00178 
00179 StdCmdMacroStopDebug::StdCmdMacroStopDebug()
00180   : Command("Std_MacroStopDebug")
00181 {
00182     sGroup        = QT_TR_NOOP("Macro");
00183     sMenuText     = QT_TR_NOOP("Stop debugging");
00184     sToolTipText  = QT_TR_NOOP("Stop debugging of macro");
00185     sWhatsThis    = "Std_MacroStopDebug";
00186     sStatusTip    = QT_TR_NOOP("Stop debugging of macro");
00187     sPixmap       = "debug-stop";
00188     sAccel        = "Shift+F6";
00189     eType         = 0;
00190 }
00191 
00192 void StdCmdMacroStopDebug::activated(int iMsg)
00193 {
00194     Application::Instance->macroManager()->debugger()->tryStop();
00195 }
00196 
00197 bool StdCmdMacroStopDebug::isActive(void)
00198 {
00199     static PythonDebugger* dbg = Application::Instance->macroManager()->debugger();
00200     return dbg->isRunning();
00201 }
00202 
00203 DEF_STD_CMD_A(StdCmdMacroStepOver);
00204 
00205 StdCmdMacroStepOver::StdCmdMacroStepOver()
00206   : Command("Std_MacroStepOver")
00207 {
00208     sGroup        = QT_TR_NOOP("Macro");
00209     sMenuText     = QT_TR_NOOP("Step over");
00210     sToolTipText  = QT_TR_NOOP("Step over");
00211     sWhatsThis    = "Std_MacroStepOver";
00212     sStatusTip    = QT_TR_NOOP("Step over");
00213     sPixmap       = 0;
00214     sAccel        = "F10";
00215     eType         = 0;
00216 }
00217 
00218 void StdCmdMacroStepOver::activated(int iMsg)
00219 {
00220     Application::Instance->macroManager()->debugger()->stepOver();
00221 }
00222 
00223 bool StdCmdMacroStepOver::isActive(void)
00224 {
00225     static PythonDebugger* dbg = Application::Instance->macroManager()->debugger();
00226     return dbg->isRunning();
00227 }
00228 
00229 DEF_STD_CMD_A(StdCmdToggleBreakpoint);
00230 
00231 StdCmdToggleBreakpoint::StdCmdToggleBreakpoint()
00232   : Command("Std_ToggleBreakpoint")
00233 {
00234     sGroup        = QT_TR_NOOP("Macro");
00235     sMenuText     = QT_TR_NOOP("Toggle breakpoint");
00236     sToolTipText  = QT_TR_NOOP("Toggle breakpoint");
00237     sWhatsThis    = "Std_ToggleBreakpoint";
00238     sStatusTip    = QT_TR_NOOP("Toggle breakpoint");
00239     sPixmap       = 0;
00240     sAccel        = "F9";
00241     eType         = 0;
00242 }
00243 
00244 void StdCmdToggleBreakpoint::activated(int iMsg)
00245 {
00246     doCommand(Command::Gui,"Gui.SendMsgToActiveView(\"ToggleBreakpoint\")");
00247 }
00248 
00249 bool StdCmdToggleBreakpoint::isActive(void)
00250 {
00251     return getGuiApplication()->sendHasMsgToActiveView("ToggleBreakpoint");
00252 }
00253 
00254 namespace Gui {
00255 
00256 void CreateMacroCommands(void)
00257 {
00258     CommandManager &rcCmdMgr = Application::Instance->commandManager();
00259     rcCmdMgr.addCommand(new StdCmdDlgMacroRecord());
00260     rcCmdMgr.addCommand(new StdCmdMacroStopRecord());
00261     rcCmdMgr.addCommand(new StdCmdDlgMacroExecute());
00262     rcCmdMgr.addCommand(new StdCmdDlgMacroExecuteDirect());
00263     rcCmdMgr.addCommand(new StdCmdMacroStartDebug());
00264     rcCmdMgr.addCommand(new StdCmdMacroStopDebug());
00265     rcCmdMgr.addCommand(new StdCmdMacroStepOver());
00266     rcCmdMgr.addCommand(new StdCmdToggleBreakpoint());
00267 }
00268 
00269 } // namespace Gui

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