FreeCAD C++
Protected Types | List of all members
Gui::Command Class Referenceabstract

#include <Gui/Command.h>

Detailed Description

The Command class.

This class is mostly used for commands implemented directly in C++ (see PythonCommand). It contains also a lot of helper methods to make implementing commands for FreeCAD as easy as possible.

Note
This class is intended to handle the GUI interaction like:
  • starting a dialog
  • doing view and window stuff
  • anything else, especially altering the document must be done on application level. See doCommand() for details.
See also
CommandManager
Author
Jürgen Riegel

Public Member Functions

Helper methods to generate help pages
const char * beginCmdHelp (void)
 returns the begin of a online help page
 
const char * endCmdHelp (void)
 returns the end of a online help page
 
virtual const char * getHelpUrl (void) const
 Get the help URL.
 
Helper methods for the Active tests
bool hasActiveDocument (void) const
 true when there is a document
 
bool hasObject (const char *Name)
 true when there is a document and a Feature with Name
 
checking of internal state
const char * getAppModuleName (void) const
 returns the name to which the command belongs
 
void setAppModuleName (const char *)
 
const char * getName () const
 Get the command name.
 
const char * getGroupName () const
 Get the name of the grouping of the command.
 
void setGroupName (const char *)
 
arbitrary helper methods
void adjustCameraPosition ()
 
- Public Member Functions inherited from Gui::CommandBase
ActiongetAction () const
 
virtual const char * getMenuText () const
 
virtual const char * getToolTipText () const
 
virtual const char * getStatusTip () const
 
virtual const char * getWhatsThis () const
 
virtual const char * getPixmap () const
 
virtual const char * getAccel () const
 
void setWhatsThis (const char *)
 
void setMenuText (const char *)
 
void setToolTipText (const char *)
 
void setStatusTip (const char *)
 
void setPixmap (const char *)
 
void setAccel (const char *)
 
virtual const char * className () const =0
 The C++ class name is needed as context for the translation framework.
 

Protected Types

enum  CmdType { AlterDoc = 1, Alter3DView = 2, AlterSelection = 4, ForEdit = 8 }
 

Protected Member Functions

Methods to override when creating a new command
virtual void activated (int iMsg)=0
 Methods which gets called when activated, needs to be reimplemented!
 
virtual bool isActive (void)
 Override this method if your Cmd is not always active.
 
virtual ActioncreateAction (void)
 Creates the used Action.
 
void applyCommandData (const char *context, Action *)
 Applies the menu text, tool and status tip to the passed action object.
 
const char * keySequenceToAccel (int) const
 
- Protected Member Functions inherited from Gui::CommandBase

Protected Attributes

Attributes

Set by the inherited constructor to set up the most important properties of the command. In the Command constructor are set default values! The real values should be set in the constructor of the inhereting class.

const char * sAppModule
 
const char * sGroup
 
const char * sName
 
const char * sHelpUrl
 
int eType
 
- Protected Attributes inherited from Gui::CommandBase
Action_pcAction
 
const char * sMenuText
 
const char * sToolTipText
 
const char * sWhatsThis
 
const char * sStatusTip
 
const char * sPixmap
 
const char * sAccel
 

interface used by the CommandManager and the Action

void testActive (void)
 Get somtile called to check the state of the command.
 
void setEnabled (bool)
 Enables or disables the command.
 
void invoke (int)
 get called by the QAction
 
void addTo (QWidget *)
 adds this command to arbitrary widgets
 
void addToGroup (ActionGroup *, bool checkable)
 

Helper methods to get important classes

Gui::DocumentgetActiveGuiDocument (void) const
 Get pointer to the active gui document.
 
App::DocumentgetDocument (const char *Name=0) const
 
bool isViewOfType (Base::Type t) const
 checks if the active view is of a special type or derived
 
App::DocumentObjectgetObject (const char *Name) const
 returns the named feature or the active one from the active document or NULL
 
std::string getUniqueObjectName (const char *BaseName) const
 Get unique Feature name from the active document.
 
static ApplicationgetGuiApplication (void)
 Get pointer to the Application Window.
 
static Gui::SelectionSingletongetSelection (void)
 Get a reference to the selection.
 

Helper methods for the Undo/Redo and Update handling

void languageChange ()
 Translate command.
 
void updateAction (int mode)
 Updates the QAction with respect to the passed mode.
 
static void openCommand (const char *sName=0)
 Open a new Undo transaction on the active document.
 
static void commitCommand (void)
 Commit the Undo transaction on the active document.
 
static void abortCommand (void)
 Abort the Undo transaction on the active document.
 
static bool hasPendingCommand (void)
 Check if an Undo transaction is open on the active document.
 
static void updateActive (void)
 Updates the (active) document (propagate changes)
 
static void updateAll (std::list< Gui::Document * > cList)
 Updates the (all or listed) documents (propagate changes)
 
static bool isActiveObjectValid (void)
 Checks if the active object of the active document is valid.
 

Helper methods for issuing commands to the Python interpreter

enum  DoCmd_Type { Doc, App, Gui }
 types of application level actions for DoCommand() More...
 
const std::string strToPython (const char *Str)
 translate a string to a python string literal (needed e.g. in file names for windows...)
 
const std::string strToPython (const std::string &Str)
 
static void blockCommand (bool)
 Blocks all command objects.
 
static void doCommand (DoCmd_Type eType, const char *sCmd,...)
 Run a App level Action.
 
static void runCommand (DoCmd_Type eType, const char *sCmd)
 
static void runCommand (DoCmd_Type eType, const QByteArray &sCmd)
 
static void addModule (DoCmd_Type eType, const char *sModuleName)
 import an external (or own) module only once
 
static std::string assureWorkbench (const char *sName)
 assures the switch to a certain workbench, if already in the workbench, does nothing.
 
static void copyVisual (const char *to, const char *attr, const char *from)
 
static void copyVisual (const char *to, const char *attr_to, const char *from, const char *attr_from)
 
static std::string getPythonTuple (const std::string &name, const std::vector< std::string > &subnames)
 Get Python tuple from object and sub-elements.
 

Member Enumeration Documentation

◆ CmdType

enum Gui::Command::CmdType
protected
Enumerator
AlterDoc 

Command change the Document

Alter3DView 

Command change the Gui

AlterSelection 

Command change the Selection

ForEdit 

Command is in a special edit mode active

◆ DoCmd_Type

types of application level actions for DoCommand()

Enumerator
Doc 

Action alters the document.

App 

Action alters only the application.

Gui 

Action alters only the Gui.

Member Function Documentation

◆ getDocument()

App::Document* Gui::Command::getDocument ( const char *  Name = 0) const

Get pointer to the named or active App document Returns a pointer to the named document or the active document when no name is given. NULL is returned when the name does not exist or no document is active!