Add Button to FEM Toolbar Tutorial/de: Difference between revisions
(Created page with "{{TutorialInfo/de |Topic=FEM |Level=Fortgeschritten |Time=60 min |Author=JohnWang |FCVersion=0.19 }}") |
(Updating to match new version of source page) |
||
(10 intermediate revisions by one other user not shown) | |||
Line 9: | Line 9: | ||
}} |
}} |
||
= |
<span id="Introduction"></span> |
||
== Einleitung == |
|||
Der Arbeitsbereich FEM enthält Symbolleisten und Menüs. Diese Anleitung zeigt, wie eine Test-Schaltfläche zu einer Symbolleiste hinzugefügt wird. Sie zeigt auch, wie einem Menü ein Menüeintrag hinzugefügt wird. |
|||
The FEM workbench has toolbars and menus. This tutorial shows how to add a test button to a toolbar. It also shows how to add a menuitem to a menu. |
|||
Die Aufgabe lässt sich in vier Teile aufteilen: |
|||
The task can be split into four parts: |
|||
* ''' |
* '''Eine neue Symboldatei erstellen'''. |
||
* ''' |
* '''Die neue Symboldatei registrieren'''. {{incode|src/Mod/Fem/Gui/Resources/Fem.qrc}} muss geändert werden. |
||
* ''' |
* '''Eine neue Befehlsklasse erstellen'''. {{incode|src/Mod/Fem/femcommands/commands.py}} muss geändert werden |
||
* ''' |
* '''Einem Arbeitsbereich einen neuen Befehl hinzufügen'''. {{incode|src/Mod/Fem/Gui/Workbench.cpp}} muss geändert werden. |
||
<span id="Create_a_new_icon_file"></span> |
|||
== Create a new icon file == |
|||
==Eine neue Symboldatei erstellen== |
|||
Für die Schaltfläche brauchen wir eine Symboldatei. Sie kann mit jedem deiner Lieblingswerkzeuge erstellt werden, muss aber im SVG-Format gespeichert werden. Wir verwenden als Beispiel {{FileName|FEM_testButton.svg}} |
|||
Sie muss hier abgelegt werden: {{incode|src/Mod/Fem/Gui/Resources/icons/}}. |
|||
<span id="Register_the_new_icon_file"></span> |
|||
== Register the new icon file == |
|||
==Die neue Symboldatei registrieren== |
|||
The new SVG icon file has to be registered for the GUI |
The new SVG icon file has to be registered for the GUI button by inserting it in {{incode|src/Mod/Fem/Gui/Resources/Fem.qrc}}: |
||
{{code|code= |
{{code|code= |
||
Line 33: | Line 36: | ||
}} |
}} |
||
<span id="Create_a_new_command_class"></span> |
|||
== Create a new command class == |
|||
==Eine neue Befehlsklasse erstellen== |
|||
A new command class has to be added to the {{incode|src/Mod/Fem/femcommands/commands.py}} module. |
A new command class has to be added to the {{incode|src/Mod/Fem/femcommands/commands.py}} module. |
||
Line 62: | Line 66: | ||
'''Note''': Please see this [https://forum.freecadweb.org/viewtopic.php?f=18&t=46693&start=10#p402004 discussion thread] in the forum if icons are involved. |
'''Note''': Please see this [https://forum.freecadweb.org/viewtopic.php?f=18&t=46693&start=10#p402004 discussion thread] in the forum if icons are involved. |
||
<span id="Add_new_command_to_workbench"></span> |
|||
== Add new command to workbench == |
|||
==Einem Arbeitsbereich einen neuen Befehl hinzufügen== |
|||
We will add the new command to both the '''solve''' toolbar and the '''solve''' menu. |
We will add the new command to both the '''solve''' toolbar and the '''solve''' menu. |
Latest revision as of 10:03, 13 January 2024
Tutorium |
Thema |
---|
FEM |
Niveau |
Fortgeschritten |
Zeit zum Abschluss |
60 min |
Autoren |
JohnWang |
FreeCAD-Version |
0.19 |
Beispieldateien |
None |
Siehe auch |
None |
Einleitung
Der Arbeitsbereich FEM enthält Symbolleisten und Menüs. Diese Anleitung zeigt, wie eine Test-Schaltfläche zu einer Symbolleiste hinzugefügt wird. Sie zeigt auch, wie einem Menü ein Menüeintrag hinzugefügt wird.
Die Aufgabe lässt sich in vier Teile aufteilen:
- Eine neue Symboldatei erstellen.
- Die neue Symboldatei registrieren.
src/Mod/Fem/Gui/Resources/Fem.qrc
muss geändert werden. - Eine neue Befehlsklasse erstellen.
src/Mod/Fem/femcommands/commands.py
muss geändert werden - Einem Arbeitsbereich einen neuen Befehl hinzufügen.
src/Mod/Fem/Gui/Workbench.cpp
muss geändert werden.
Eine neue Symboldatei erstellen
Für die Schaltfläche brauchen wir eine Symboldatei. Sie kann mit jedem deiner Lieblingswerkzeuge erstellt werden, muss aber im SVG-Format gespeichert werden. Wir verwenden als Beispiel FEM_testButton.svg
Sie muss hier abgelegt werden: src/Mod/Fem/Gui/Resources/icons/
.
Die neue Symboldatei registrieren
The new SVG icon file has to be registered for the GUI button by inserting it in src/Mod/Fem/Gui/Resources/Fem.qrc
:
<file>icons/FEM_testButton.svg</file>
Eine neue Befehlsklasse erstellen
A new command class has to be added to the src/Mod/Fem/femcommands/commands.py
module.
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.
Einem Arbeitsbereich einen neuen Befehl hinzufügen
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.