Tutoriel Ajout d'un bouton dans la barre d'outils FEM
Tutorial |
Topic |
---|
FEM |
Level |
Avancé |
Time to complete |
60 min |
Authors |
JohnWang |
FreeCAD version |
0.19 |
Example files |
None |
See also |
None |
Introduction
L'atelier FEM dispose de barres d'outils et de menus. Ce tutoriel montre comment ajouter un bouton de test à une barre d'outils. Il montre également comment ajouter un élément de menu à un menu.
La tâche peut être divisée en quatre parties :
- Créer un nouveau fichier d'icône.
- Enregistrer le nouveau fichier d'icône. Modification nécessaire dans
src/Mod/Fem//Gui/Resources/Fem.qrc
- Créer une nouvelle classe de commande. Modification nécessaire dans
src/Mod/Fem/femcommands/commands.py
- Ajout d'une nouvelle commande à l'atelier. Modification nécessaire dans
src/Mod/Fem/Gui/Workbench.cpp
.
Créer un nouveau fichier d'icône
Pour le bouton, nous avons besoin d'un fichier d'icône. Vous pouvez utiliser n'importe lequel de vos outils préférés pour le créer, mais il doit être au format SVG. Nous utiliserons ici le fichier FEM_testButton.svg comme exemple.
Il doit être placé dans : src/Mod/Fem/Gui/Resources/icons/
.
Enregistrer le nouveau fichier d'icône
Le nouveau fichier icône SVG doit être enregistré pour le bouton GUI en l'insérant dans src/Mod/Fem/Gui/Resources/Fem.qrc
:
<file>icons/FEM_testButton.svg</file>
Créer une nouvelle classe de commande
Une nouvelle classe de commande doit être ajoutée au module src/Mod/Fem/femcommands/commands.py
.
Just copy/paste an existing command, then 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 with the addCommand(...)
method:
FreeCADGui.addCommand(
"FEM_testButton",
_testButton()
)
Note: Please see this discussion thread in the forum if icons are involved.
Add new command to workbench
We will add the new command to both the solve toolbar and the solve menu.
Search for the following code snippet in /Gui/Workbench.cpp
and add the new command:
Gui::ToolBarItem* solve = new Gui::ToolBarItem(root);
solve->setCommand("Solve");
*solve << "FEM_SolverCalculixCxxtools"
<< "FEM_SolverCalculiX"
<< "FEM_SolverElmer"
+ << "FEM_testButton"
<< "Separator"
To add the command to the solve menu of the FEM workbench, search for the following code snippet in Workbench.cpp
:
Gui::MenuItem* solve = new Gui::MenuItem;
root->insertItem(item, solve);
solve->setCommand("&Solve");
*solve << "FEM_SolverCalculixCxxtools"
<< "FEM_SolverCalculiX"
<< "FEM_SolverElmer"
<< "FEM_SolverZ88"
+ << "FEM_testButton"
<< "Separator"
Result: You should have just successfully added a test button to a FEM workbench toolbar and menu. Now, you can compile FreeCAD and test your new button.