You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: technical/CreatePythonBindingForCpp.md
+17-15Lines changed: 17 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,10 @@
1
-
# Background
1
+
---
2
+
layout: default
3
+
---
4
+
5
+
# Create a Python Binding for C++
6
+
7
+
## Background
2
8
3
9
It becomes necessary at times to expand the FreeCAD API further by exposing functions that are available in the source code in c++ to the python. This process is generally referred to as creating a binding.
4
10
@@ -18,7 +24,7 @@ The XML file YourClassPy.xml provides information about the functions and attrib
18
24
19
25
For this example, we will look at the wrapper for the Base::Axis C++ class. The XML description file begins with:
@@ -42,7 +48,7 @@ For this example, we will look at the wrapper for the Base::Axis C++ class. The
42
48
43
49
Following this preamble, a list of methods and attributes is given. The format of a method is:
44
50
45
-
```XML
51
+
```xml
46
52
<Methode Name##"move">
47
53
<Documentation>
48
54
<UserDocu>
@@ -55,7 +61,7 @@ Following this preamble, a list of methods and attributes is given. The format o
55
61
56
62
The format of an attribute is:
57
63
58
-
```XML
64
+
```xml
59
65
<Attribute Name##"Direction" ReadOnly##"false">
60
66
<Documentation>
61
67
<UserDocu>Direction vector of the Axis</UserDocu>
@@ -66,24 +72,25 @@ The format of an attribute is:
66
72
67
73
For an attribute, if "ReadOnly" is false, you will provide both a getter and a setter function. If it is true, only a getter is allowed. In this case we will be required to provide two functions in the implementation C++ file:
68
74
69
-
```C++
75
+
```cpp
70
76
Py::Object AxisPy::getDirection(void) const
77
+
````
71
78
72
79
and:
73
80
81
+
```cpp
74
82
void AxisPy::setDirection(Py::Object arg)
75
83
```
76
84
85
+
## Implementation C++ File
77
86
78
-
## Implementation Cplusplus File
79
-
80
-
The implementation C++ file YourClassPyImp.cpp provides the "glue" that connects the C++ and Python structures together, effectively translating from one language to the other. The FreeCAD C++-to-Python system provides a number of C++ classes that map to their corresponding Python type. The most fundamental of these is the incode|Py::Object class -- rarely created directly, this class provides the base of the inheritance tree, and is used as the return type for any function that is returning Python data.
87
+
The implementation C++ file `YourClassPyImp.cpp` provides the "glue" that connects the C++ and Python structures together, effectively translating from one language to the other. The FreeCAD C++-to-Python system provides a number of C++ classes that map to their corresponding Python type. The most fundamental of these is the incode `Py::Object` class - rarely created directly, this class provides the base of the inheritance tree, and is used as the return type for any function that is returning Python data.
81
88
82
89
### Include Files
83
90
84
91
Your C++ implementation file will include the following files:
85
92
86
-
```C++
93
+
```cpp
87
94
#include "PreCompiled.h"
88
95
89
96
#include "YourClass.h"
@@ -99,7 +106,7 @@ Of course, you may include whatever other C++ headers your code requires to func
99
106
100
107
Your C++ implementation must contain the definition of the PyInit function: for example, for the Axis class wrapper, this is
101
108
102
-
```C++
109
+
```cpp
103
110
int AxisPy::PyInit(PyObject* args, PyObject* /*kwd*/)
104
111
105
112
//Within this function you will most likely need to parse incoming arguments to the constructor: the most important function for this purpose is the Python-provided incode|PyArg_ParseTuple. It takes in the
@@ -123,7 +130,6 @@ For a complete list of format specifiers see [https://docs.python.org/3/c-api/ar
The basic structure of a program to expose functionality to Python is something like this:
@@ -147,14 +153,10 @@ There is a convention for return values from our C++/Python connections:
147
153
* xxxxxPyImp routines return a PyObject* pointer (see TopoShapePyImp.cpp)
148
154
* AppmyModulePy.cpp routines return a Py::Object (see https://github.com/FreeCAD/FreeCAD/blob/master/src/Mod/Part/App/AppPartPy.cpp and FreeCAD/src/Mod/Part/AppPartPy.cpp.
Copy file name to clipboardExpand all lines: technical/TheApplicationModule.md
+4-5Lines changed: 4 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,14 @@
1
1
---
2
2
layout: default
3
-
mermaid: true
4
3
---
5
4
6
-
# "The Application Module"
5
+
# The Application Module
7
6
8
-
"An overview of application module structure."
7
+
An overview of application module structure.
9
8
10
-
The functionality of FreeCAD is separated into Modules. Some Modules are built into FreeCAD and some are Extension Modules (a form of plug-in). Once installed, Extension Modules behave exactly as built-in Modules.
9
+
The functionality of FreeCAD is separated into Modules. Some Modules are built into FreeCAD and some are Extension Modules (a form of plug-in). Once installed, Extension Modules behave exactly as built-in Modules.
11
10
12
-
Application Modules provide specialized functions and may store specialized data. Examples of Application Modules are Arch (for buildings) and Sketcher (for drawing Sketches).
11
+
Application Modules provide specialized functions and may store specialized data. Examples of Application Modules are Arch (for buildings) and Sketcher (for drawing Sketches).
13
12
14
13
Application Modules are almost always divided into two parts: App which manages the relevant document objects and operations on them, and Gui which handles the display.
Copy file name to clipboardExpand all lines: technical/developerglossary.md
+3-6Lines changed: 3 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,12 @@
1
1
---
2
2
layout: default
3
3
---
4
-
# "Developer's Glossary"
5
4
6
-
"Some terms that a developer may run across."
5
+
# Developer's Glossary
7
6
8
-
Note that there may be subtle differences in how some terms are used by developers vs how they are used by users.
7
+
Some terms that a developer may run across.
9
8
9
+
Note that there may be subtle differences in how some terms are used by developers vs how they are used by users.
10
10
11
11
* Binding: the mechanism for linking C++ functionality to and from Python.
12
12
* CI (Continuous Integration): the mechanism by which Pull Requests are automatically built and unit tested.
@@ -17,9 +17,6 @@ Note that there may be subtle differences in how some terms are used by develope
17
17
* Pull Request: how a contributor indicates that they have a change to be merged
18
18
* ViewProvider: an object that provides painting services for a Feature. The ViewProvider is notified of changes in a Features properties and, if the change affects the visual representation of the Feature, updates the display. Note that in some modules (ex TechDraw with the Qt GraphicsFramework) there is another layer of functionality that manages the painting.
19
19
20
-
21
-
22
-
23
20
## See Also
24
21
25
22
*[FreeCAD glossary wiki entry](https://wiki.freecad.org/Glossary)
@@ -19,8 +20,8 @@ Technical information of interest to Contributors.
19
20
-[Coin3d](https://www.coin3d.org/): a [scenegraph](https://wiki.freecad.org/Scenegraph) manager based on OpenInventor that handles drawing in the 3d window.
20
21
-[Pivy](https://wiki.freecad.org/Pivy): a Python binding for Coin3d
21
22
22
-
23
23
## Modifying FreeCAD
24
+
24
25
- Contributing to FreeCAD
25
26
- The process for submitting changes to FreeCAD is described in the [CONTRIBUTING.md](https://github.com/FreeCAD/FreeCAD/blob/master/CONTRIBUTING.md)
26
27
file in the root of the source tree.
@@ -30,11 +31,8 @@ Technical information of interest to Contributors.
30
31
-[Create a Python Binding for C++ Class](./CreatePythonBindingForCpp.md)
31
32
-[Checklist for Adding a Feature to a Workbench in C++](./ChecklistForNewFeatureC++.md)
0 commit comments