Command.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef GUI_COMMAND_H
00025 #define GUI_COMMAND_H
00026
00027
00028 #include <list>
00029 #include <map>
00030 #include <string>
00031 #include <vector>
00032
00033 #include <Base/Type.h>
00034
00035 class QWidget;
00036 typedef struct _object PyObject;
00037
00038 namespace App
00039 {
00040 class Document;
00041 class DocumentObject;
00042 }
00043
00044 namespace Gui {
00045
00046 class Action;
00047 class Application;
00048 class CommandManager;
00049 class Command;
00050 class ActionGroup;
00051 class Document;
00052 class SelectionSingleton;
00053 class MDIView;
00054
00055
00056 void CreateStdCommands(void);
00057 void CreateDocCommands(void);
00058 void CreateFeatCommands(void);
00059 void CreateMacroCommands(void);
00060 void CreateViewStdCommands(void);
00061 void CreateWindowStdCommands(void);
00062 void CreateTestCommands(void);
00063
00064
00070 class GuiExport CommandBase
00071 {
00072 public:
00073 CommandBase(const char* sMenu, const char* sToolTip=0, const char* sWhat=0,
00074 const char* sStatus=0, const char* sPixmap=0, const char* sAccel=0);
00075 virtual ~CommandBase();
00076
00080 Action* getAction() const;
00081
00084 protected:
00086 virtual Action * createAction(void);
00087 public:
00089 virtual void languageChange() = 0;
00091 virtual const char* className() const = 0;
00093
00096 virtual const char* getMenuText () const { return sMenuText; }
00097 virtual const char* getToolTipText() const { return sToolTipText; }
00098 virtual const char* getStatusTip () const { return sStatusTip; }
00099 virtual const char* getWhatsThis () const { return sWhatsThis; }
00100 virtual const char* getPixmap () const { return sPixmap; }
00101 virtual const char* getAccel () const { return sAccel; }
00103
00106 void setWhatsThis (const char*);
00107 void setMenuText (const char*);
00108 void setToolTipText(const char*);
00109 void setStatusTip (const char*);
00110 void setPixmap (const char*);
00111 void setAccel (const char*);
00113
00114 protected:
00122 const char* sMenuText;
00123 const char* sToolTipText;
00124 const char* sWhatsThis;
00125 const char* sStatusTip;
00126 const char* sPixmap;
00127 const char* sAccel;
00129 protected:
00130 Action *_pcAction;
00131 };
00132
00146 class GuiExport Command : public CommandBase
00147 {
00148 public:
00149 Command(const char* name);
00150 virtual ~Command();
00151
00152 protected:
00156
00157 virtual void activated(int iMsg)=0;
00159 virtual bool isActive(void){return true;}
00161 virtual Action * createAction(void);
00163 void applyCommandData(Action* );
00164 const char* keySequenceToAccel(int) const;
00165 void adjustCameraPosition();
00167
00168 public:
00171
00172 friend class CommandManager;
00174 void testActive(void);
00176 void invoke (int);
00178 void addTo(QWidget *);
00180
00181
00184
00185 static Application* getGuiApplication(void);
00187 Gui::SelectionSingleton& getSelection(void);
00189 Gui::Document* getActiveGuiDocument(void) const;
00195 App::Document* getDocument(const char* Name=0) const;
00197 bool isViewOfType(Base::Type t) const;
00199 App::DocumentObject* getObject(const char* Name) const;
00201 std::string getUniqueObjectName(const char *BaseName) const;
00203
00206
00207 static void openCommand(const char* sName=0);
00209 static void commitCommand(void);
00211 static void abortCommand(void);
00213 static void updateActive(void);
00215 static void updateAll(std::list<Gui::Document*> cList);
00217 static bool isActiveObjectValid(void);
00219 void languageChange();
00221
00224
00225 enum DoCmd_Type {
00227 Doc,
00229 App,
00231 Gui
00232 };
00234 static void blockCommand(bool);
00236 static void doCommand(DoCmd_Type eType,const char* sCmd,...);
00237 static void copyVisual(const char* to, const char* attr, const char* from);
00238 static void copyVisual(const char* to, const char* attr_to, const char* from, const char* attr_from);
00240
00242 const std::string strToPython(const char* Str);
00243 const std::string strToPython(const std::string &Str){return strToPython(Str.c_str());};
00245
00248
00249 const char * beginCmdHelp(void);
00251 const char * endCmdHelp(void);
00253 virtual const char* getHelpUrl(void) const { return sHelpUrl; }
00255
00258
00259 bool hasActiveDocument(void) const;
00261 bool hasObject(const char* Name);
00263
00266
00267 const char* getAppModuleName(void) const {return sAppModule;}
00269 const char* getName() const { return sName; }
00271 const char* getGroupName() const { return sGroup; }
00273
00274 protected:
00275 enum CmdType {
00276 AlterDoc = 1,
00277 Alter3DView = 2,
00278 AlterSelection = 4,
00279 ForEdit = 8
00280 };
00281
00288 const char* sAppModule;
00289 const char* sGroup;
00290 const char* sName;
00291 const char* sHelpUrl;
00292 int eType;
00294 private:
00295 static bool _blockCmd;
00296 };
00297
00307 class PythonCommand: public Command
00308 {
00309 public:
00310 PythonCommand(const char* name,PyObject * pcPyCommand, const char* pActivationString);
00311 virtual ~PythonCommand() {}
00312
00313 protected:
00316
00317 virtual void activated(int iMsg);
00319 virtual bool isActive(void);
00321 const char* getHelpUrl(void);
00323 virtual Action * createAction(void);
00325
00326 public:
00329
00330 void languageChange();
00331 const char* className() const
00332 { return "PythonCommand"; }
00333 const char* getWhatsThis () const;
00334 const char* getMenuText () const;
00335 const char* getToolTipText() const;
00336 const char* getStatusTip () const;
00337 const char* getPixmap () const;
00338 const char* getAccel () const;
00340
00341 protected:
00343 const char* getResource(const char* sName) const;
00345 PyObject * _pcPyCommand;
00347 PyObject * _pcPyResourceDict;
00349 std::string Activation;
00350 };
00351
00352
00362 class MacroCommand: public Command
00363 {
00364 public:
00365 MacroCommand(const char* name);
00366 virtual ~MacroCommand() {}
00367
00368 protected:
00371
00372 void activated(int iMsg);
00374 Action * createAction(void);
00376
00377 public:
00379 const char* getScriptName () const { return sScriptName; }
00381 void languageChange() {}
00382 const char* className() const
00383 { return "Gui::MacroCommand"; }
00384
00387
00388 void setScriptName ( const char* );
00390
00394 static void load();
00396 static void save();
00398
00399 protected:
00400 const char* sScriptName;
00401 };
00402
00412 class GuiExport CommandManager
00413 {
00414 public:
00416 CommandManager();
00418 ~CommandManager();
00420 void addCommand(Command* pCom);
00422 void removeCommand(Command* pCom);
00423
00425 bool addTo(const char* Name, QWidget* pcWidget);
00426
00432 std::vector <Command*> getModuleCommands(const char *sModName) const;
00433
00439 std::vector <Command*> getAllCommands(void) const;
00440
00444 std::vector <Command*> getGroupCommands(const char *sGrpName) const;
00445
00450 Command* getCommandByName(const char* sName) const;
00451
00455 void runCommandByName (const char* sName) const;
00456
00458 const std::map<std::string, Command*>& getCommands() const { return _sCommands; }
00460 void testActive(void);
00461 private:
00463 void clearCommands();
00464 std::map<std::string,Command*> _sCommands;
00465 };
00466
00467 }
00468
00469
00475 #define DEF_STD_CMD(X) class X : public Gui::Command \
00476 {\
00477 public:\
00478 X();\
00479 virtual const char* className() const\
00480 { return #X; }\
00481 protected: \
00482 virtual void activated(int iMsg);\
00483 };
00484
00490 #define DEF_STD_CMD_A(X) class X : public Gui::Command \
00491 {\
00492 public:\
00493 X();\
00494 virtual ~X(){}\
00495 virtual const char* className() const\
00496 { return #X; }\
00497 protected: \
00498 virtual void activated(int iMsg);\
00499 virtual bool isActive(void);\
00500 };
00501
00507 #define DEF_STD_CMD_C(X) class X : public Gui::Command \
00508 {\
00509 public:\
00510 X();\
00511 virtual ~X(){}\
00512 virtual const char* className() const\
00513 { return #X; }\
00514 protected: \
00515 virtual void activated(int iMsg);\
00516 virtual Gui::Action * createAction(void);\
00517 };
00518
00524 #define DEF_STD_CMD_AC(X) class X : public Gui::Command \
00525 {\
00526 public:\
00527 X();\
00528 virtual ~X(){}\
00529 virtual const char* className() const\
00530 { return #X; }\
00531 protected: \
00532 virtual void activated(int iMsg);\
00533 virtual bool isActive(void);\
00534 virtual Gui::Action * createAction(void);\
00535 };
00536
00543 #define DEF_STD_CMD_ACL(X) class X : public Gui::Command \
00544 {\
00545 public:\
00546 X();\
00547 virtual ~X(){}\
00548 virtual void languageChange(); \
00549 virtual const char* className() const\
00550 { return #X; }\
00551 protected: \
00552 virtual void activated(int iMsg);\
00553 virtual bool isActive(void);\
00554 virtual Gui::Action * createAction(void);\
00555 };
00556
00563 #define DEF_3DV_CMD(X) class X : public Gui::Command \
00564 {\
00565 public:\
00566 X();\
00567 virtual ~X(){}\
00568 virtual const char* className() const\
00569 { return #X; }\
00570 protected: \
00571 virtual void activated(int iMsg);\
00572 virtual bool isActive(void)\
00573 {\
00574 Gui::MDIView* view = Gui::getMainWindow()->activeWindow();\
00575 return view && view->isDerivedFrom(Gui::View3DInventor::getClassTypeId());\
00576 }\
00577 };
00578
00579 #endif // GUI_COMMAND_H