Add Button to FEM Toolbar Tutorial

Notes: Work In Progress

FEM workbench has toolbars and menus. This tutorial shows how to add a button onto the toolbars. It also shows how to add a menuitem into the menu.

The task can be split into four parts:
 * Create a new icon file.
 * Register the new icon file. Make change at src/Mod/Fem//Gui/Resources/Fem.qrc
 * Create a new command. Make change at src/Mod/Fem/femcommands/commands.py
 * Add the new command onto the workbench. Make change at src/Mod/Fem/Gui/Workbench.cpp

Create a new icon file
For a button, We need a icon file. You can use any of your favorite tools to create it, but it must be in SVG format. Here we use FEM_testButton.svg as an example. It has to be put into.

Register the new icon file
The new icon SVG file has to be registered for the GUI-button with in  (in ).

Create a new command
A new command class has to be added to the module.

Just copy an existing command and adjust the icon, menu text and tool-tip in __init__(self). class _testButton(CommandManager): "The FEM_testButton command definition"

def __init__(self): super(_testButton, self).__init__ self.menuetext = "test Button" self.tooltip = "This is a test button" self.is_active = "always" #self.do_activated = "add_obj_on_gui_selobj_noset_edit" Don't forget to register the command at the bottom of the module file by using the addCommand(...) method.

FreeCADGui.addCommand(   "FEM_testButton",    _testButton ) Please see the discussion in the forum at https://forum.freecadweb.org/viewtopic.php?f=18&t=46693&start=10#p402004 if icons are involved.

Add the new command onto the workbench
The FEM workbench has several toolbars and menus. We will add the new command on to both the solve toolbar and the solve menu.

To add it to the solve toolbar, search for the following code snippet in and add the new command to the rest of the equation commands. Gui::ToolBarItem* solve = new Gui::ToolBarItem(root); solve->setCommand("Solve"); *solve << "FEM_SolverCalculixCxxtools" << "FEM_SolverCalculiX" << "FEM_SolverElmer" << "Separator" << "FEM_EquationElasticity" << "FEM_EquationElectrostatic" +         << "FEM_EquationFlow" << "FEM_EquationFluxsolver" << "FEM_EquationElectricforce" << "FEM_EquationHeat" << "Separator" << "FEM_SolverControl" << "FEM_SolverRun";

To add the flow equation command to the solve menu of the FEM workbench, search for the following code snippet in. Gui::MenuItem* solve = new Gui::MenuItem; root->insertItem(item, solve); solve->setCommand("&Solve"); *solve << "FEM_SolverCalculixCxxtools" << "FEM_SolverCalculiX" << "FEM_SolverElmer" << "FEM_SolverZ88" << "Separator" << "FEM_EquationElasticity" << "FEM_EquationElectrostatic" +         << "FEM_EquationFlow" << "FEM_EquationFluxsolver" << "FEM_EquationElectricforce" << "FEM_EquationHeat" << "Separator" << "FEM_SolverControl" << "FEM_SolverRun";