Add Button to FEM Toolbar Tutorial/pl: Difference between revisions
(Created page with "Musi być umieszczony: {{incode|src/Mod/Fem/Gui/Resources/icons/}}.") |
(Created page with "== Zarejestruj plik nowej ikony ==") |
||
Line 28: | Line 28: | ||
Musi być umieszczony w: {{incode|src/Mod/Fem/Gui/Resources/icons/}}. |
Musi być umieszczony w: {{incode|src/Mod/Fem/Gui/Resources/icons/}}. |
||
<span id="Register_the_new_icon_file"></span> |
|||
== Register the new icon file == |
|||
== Zarejestruj plik nowej ikony == |
|||
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}}: |
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}}: |
Revision as of 17:20, 12 January 2024
Ćwiczenie |
Temat |
---|
MES |
Poziom trudności |
Zaawansowany |
Czas wykonania |
60 min |
Autorzy |
JohnWang |
Wersja FreeCAD |
0.19 |
Pliki z przykładami |
Zobacz również |
- |
Wprowadzenie
Środowisko pracy MES ma paski narzędzi i menu. Ten poradnik pokazuje jak dodać testowy przycisk do paska narzędzi. Przedstawia też dodawanie obiektu do menu.
Zadanie można podzielić na cztery części:
- Utwórz plik nowej ikony.
- Zarejestruj plik nowej ikony. Wymagana modyfikacja w
src/Mod/Fem/Gui/Resources/Fem.qrc
- Utwórz klasę nowego polecenia. Wymagana modyfikacja w
src/Mod/Fem/femcommands/commands.py
- Dodaj nowe polecenie do środowiska pracy MES. Wymagana modyfikacja w
src/Mod/Fem/Gui/Workbench.cpp
Utwórz plik nowej ikony
Potrzebujemy pliku ikony dla przycisku. Możesz skorzystać z dowolnego narzędzia aby go utworzyć, ale musi być zapisany w formacie SVG. W tym przykładzie skorzystamy z pliku FEM_testButton.svg.
Musi być umieszczony w: src/Mod/Fem/Gui/Resources/icons/
.
Zarejestruj plik nowej ikony
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>
Create a new command class
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.
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.