Module Creation/ro

Adăugarea de noi module și ateliere de lucru în FreeCAD este foarte ușoară. Un modul este orice extensie a FreeCAD, în timp ce un aelier de lucru este un GUI de configurare special care grupează câteva bare de instrumente și meniuri. De obicei, creați un nou modul care conține propriul atelier de lucru.

Modulele pot fi programate în C ++ sau în Python sau într-un mix de ambele, dar fișierele init module trebuie să fie în Python. Configurarea unui nou modul cu aceste fișiere este ușoară și se poate face manual cu instrumentul de construire FreeCAD.

Using the FreeCAD Build tool
Creating a new application module în FreeCAD este destul de simplă. The FreeCAD Build Tool (fcbt)face cea mai mare parte a muncii grele în locul tău. It is a Python script care poate fi găsit în arborele de dezvoltare FreeCAD sub: trunk/src/Tools/fcbt.py Atunci când interpretul dvs. python este instalat corect, puteți executa scriptul dintr-o linie de comandă cu python fcbt.py Va afișa următorul meniu: FreeCAD Build Tool Usage: fcbt [command parameter] possible commands are: - DistSrc        (DS)   Build a source Distr. of the current source tree - DistBin        (DB)   Build a binary Distr. of the current source tree - DistSetup      (DI)   Build a Setup Distr. of the current source tree - DistSetup      (DUI)  Build a User Setup Distr. of the current source tree - DistAll        (DA)   Run all three above modules - NextBuildNumber (NBN) Increase the Build Number of this Version - CreateModule   (CM)   Insert a new FreeCAD Module in the module directory - CreatePyModule (CP)   Insert a new FreeCAD Python Module in the module directory

For help on the modules type: fcbt ? La promptul de comandă introduceți "CM" pentru a începe crearea unui modul: Insert command: CM Acum vi se cere să specificați un nume pentru noul modul. Permiteți să-l numiți "TestMod" pentru acest exemplu: Please enter a name for your application: TestMod După ce apăsați Enter, fcbt începe să copieze toate fișierele necesare pentru modulul dvs. într-un nou dosar situat la trunk/src/Mod/TestMod/ Then all files are modified with your new module name. The only thing you need to do now is to add the two new projects "appTestMod" and "appTestModGui" to your workspace (on Windows) or to your makefile targets (unix). Thats it!

Setting up a new module manually
You need two things to create a new module:


 * A new folder in the FreeCAD Mod folder (either in InstalledPath/FreeCAD/Mod or in UserPath/.FreeCAD/Mod). You can name it as you like.
 * Inside that folder, an InitGui.py file. That file will be executed automatically on FreeCAD start (it can be empty, but just to test it,, put a print("hello world") inside)

Additionally, you can also add an Init.py file. InitGui.py file is loaded only when FreeCAD runs in GUI mode, whereas the Init.py file is always loaded. Since we're creating a workbench, however, we'll put our code in InitGui.py, since workbenches are GUI-only tools.

Creating a new workbench
Inside the InitGui.py file, the first thing you will want to do is define a workbench. You can use the following example as a template: The workbench must have all these attributes defined:
 * Icon - An XPM image. Most image software (like GIMP) can convert an image into xpm format, which is a text file. You can then paste the contents here.
 * MenuText - The workbench name as it appears in the workbenches list
 * Tooltip - Defines the tooltip text
 * Initialize - Executed when FreeCAD loads and creates all menus and toolbars that the workbench will use. If you are going to make your module in C++, you can also define your menus and toolbars inside the C++ module rather than the InitGui.py file. The important thing is that they are created now, before the module is activated.
 * Activated - Executed when the user switches to your workbench
 * Deactivated - Executed when the user switches away to another workbench or leaves FreeCAD

Creating FreeCAD commands in Python
Usually you define all your tools (called Commands in FreeCAD) in another module, then import that module before creating the toolbars and menus. Here is a simple example that can be used as a template: Note there are three methods defined:
 * GetResources - Returns a dictionary with the visual attributes of your tool. The Accel parameter defines an optional shortcut key.
 * IsActive - Determines whether or not the command is active. Inactive commands are indicated by a greyed-out icon in the menus and toolbars.
 * Activated - Executed when the Command is called, whether through a toolbar button, menu or script API call.

Creating FreeCAD Commands in C++
To Be Documented

Links

 * Some examples how power users have extended FreeCAD with various custom external workbenches are collected in External workbenches
 * Other example in Power user hub Workbench creation
 * Creating Commands Command