Source documentation: Difference between revisions

From FreeCAD Documentation
(Graphviz is also used by FreeCAD's dependency graph to show the relationships between different objects.)
(Updated Compile_on_Linux link.)
 
(21 intermediate revisions by 8 users not shown)
Line 1: Line 1:
<languages/>
<languages/>
<translate>
<translate>

<!--T:21-->
<!--T:21-->
{{Docnav
{{docnav|Extra python modules|List of Commands}}
|[[Extra_python_modules|Extra python modules]]
|[[Contributors|Contributors]]
}}


</translate>
<!--T:1-->
{{TOCright}}
The FreeCAD source code is commented to allow automatic HTML documentation generation using [http://www.doxygen.org Doxygen], a popular source code documentation system. Doxygen can document both the C++ and Python parts of FreeCAD.
<translate>

==Overview== <!--T:1-->
The FreeCAD source code is commented to allow automatic programming documentation generation using [[Doxygen|Doxygen]], a popular source code documentation system. Doxygen can document both the C++ and Python parts of FreeCAD, resulting in HTML pages with hyperlinks to each documented function and class.


<!--T:16-->
<!--T:16-->
The online source documentation is located at the [http://www.freecadweb.org/api/ FreeCAD API website]. Please note that this documentation is not always kept to date; if you have pressing questions about the code please ask in the developer section of the [https://forum.freecadweb.org/index.php FreeCAD forum].
The documentation is hosted online at the [https://freecad.github.io/SourceDoc/ FreeCAD API website]. Please note that this documentation may not always be up to date; if you need more details, download FreeCAD's latest source code and compile the documentation yourself. If you have pressing questions about the code please ask in the developer section of the [https://forum.freecadweb.org/index.php FreeCAD forum].

<!--T:31-->
Compiling the API documentation follows the same general steps as compiling the FreeCAD executable, as indicated in the [[Compile_on_Linux|Compile on Linux]] page.

<!--T:32-->
[[File:FreeCAD_documentation_compilation_workflow.svg|800px]]

<!--T:33-->
{{Caption|General workflow to compile FreeCAD's programming documentation. The Doxygen and Graphviz packages must be in the system, as well as the FreeCAD source code itself. CMake configures the system so that with a single make instruction the documentation for the the entire project is compiled into many HTML files with diagrams.}}


== Build source documentation == <!--T:4-->
== Build source documentation == <!--T:4-->

=== Complete documentation === <!--T:35-->


<!--T:5-->
<!--T:5-->
If you have Doxygen installed, it is very easy to build the documentation. Also install [https://www.graphviz.org/ Graphviz] to be able to produce diagrams showing the relationships between different classes and libraries in the FreeCAD code. Graphviz is also used by FreeCAD's [[Std DependencyGraph|dependency graph]] to show the relationships between different objects.
If you have Doxygen installed, it is very easy to build the documentation. Also install [https://www.graphviz.org/ Graphviz] to be able to produce diagrams showing the relationships between different classes and libraries in the FreeCAD code. Graphviz is also used by FreeCAD's [[Std_DependencyGraph|dependency graph]] to show the relationships between different objects.
</translate>
</translate>
{{Code|code=
{{Code|code=
Line 21: Line 40:


<!--T:23-->
<!--T:23-->
Then follow the same steps you would do to compile FreeCAD, as described on the [[CompileOnUnix|compile on Unix]] page, and summarized here for convenience.
Then follow the same steps you would do to compile FreeCAD, as described on the [[Compile_on_Linux|compile on Linux]] page, and summarized here for convenience.
* Get the source code of FreeCAD and place it in its own directory {{incode|freecad-source}}.
* Get the source code of FreeCAD and place it in its own directory {{incode|freecad-source}}.
* Create another directory {{incode|freecad-build}} in which you will compile FreeCAD and its documentation.
* Create another directory {{incode|freecad-build}} in which you will compile FreeCAD and its documentation.
Line 44: Line 63:
<!--T:6-->
<!--T:6-->
As mentioned in [[Compiling (Speeding up)|compiling (speeding up)]], the {{incode|-j}} option sets the number of CPU cores used for compilation. The resulting documentation files will appear in the directory
As mentioned in [[Compiling (Speeding up)|compiling (speeding up)]], the {{incode|-j}} option sets the number of CPU cores used for compilation. The resulting documentation files will appear in the directory
</translate>
{{Code|code=
{{Code|code=
freecad-build/doc/SourceDocu/html/
freecad-build/doc/SourceDocu/html/
}}
}}
<translate>


<!--T:25-->
<!--T:25-->
The point of entrance to the documentation is the {{incode|index.html}} file, which you can open with a web browser:
The point of entrance to the documentation is the {{incode|index.html}} file, which you can open with a web browser:
</translate>
{{Code|code=
{{Code|code=
xdg-open freecad-build/doc/SourceDocu/html/index.html
xdg-open freecad-build/doc/SourceDocu/html/index.html
}}
}}
<translate>


<!--T:17-->
<!--T:17-->
The {{incode|DevDoc}} target will generate a significant amount of data, around 5 GB of new files, particularly due to the diagrams created by Graphviz.
The {{incode|DevDoc}} target will generate a significant amount of data, around 5 GB of new files, particularly due to the diagrams created by Graphviz.

=== Reduced documentation === <!--T:36-->


<!--T:26-->
<!--T:26-->
An alternative, smaller version of the documentation which takes only around 600 MB can be generated with a different target. This is the version displayed on the [http://www.freecadweb.org/api/ FreeCAD API website].
The complete documentation uses around 3Gb of disk space. An alternative, smaller version of the documentation which takes only around 600 MB can be generated with a different target. This is the version displayed on the [https://freecad.github.io/SourceDoc/ FreeCAD API website].
</translate>
</translate>
{{Code|code=
{{Code|code=
Line 65: Line 90:
<translate>
<translate>


== Other versions == <!--T:8-->
<!--T:37-->
The documentation on the [https://freecad.github.io/SourceDoc/ FreeCAD API website] is produced automatically from https://github.com/FreeCAD/SourceDoc . Anyone can rebuild it and submit a pull request:
[http://free-cad.sf.net/SrcDocu/index.html FreeCAD 0.12] documentation hosted in Sourceforge.


<!--T:27-->
<!--T:38-->
* Fork the repo at https://github.com/FreeCAD/SourceDoc
[https://iesensor.com/FreeCADDoc/0.16-dev/ FreeCAD 0.16 development] documentation built by [http://forum.freecadweb.org/viewtopic.php?t=12613 qingfeng.xia].
* on your machine: clone the FreeCAD code (if you haven't yet), create a build dir for the doc, and clone the above SourceDoc repo inside. That SourceDoc will be updated when you rebuild the doc, and you'll be able to commit & push the results afterwards:
</translate>
{{Code|code=
git clone https://github.com/FreeCAD/FreeCAD
cd FreeCAD
mkdir build
cd build
mkdir -p doc/SourceDocu/html
cd doc/SourceDocu/html
git clone your-fork-url
cd ../../..
cmake -DBUILD_QT5=ON -DPYTHON_EXECUTABLE=/usr/bin/python3 ..
make WebDoc
cd doc/SourceDocu/html
git commit
git push
}}
<translate>
<!--T:39-->
* Go to your fork online, and create a pull request.


<!--T:15-->
== Other versions == <!--T:8-->
[https://iesensor.com/FreeCADDoc/0.19/ FreeCAD 0.19 development] documentation built by [http://forum.freecadweb.org/viewtopic.php?t=12613 qingfeng.xia].
[https://iesensor.com/FreeCADDoc/0.19/ FreeCAD 0.19 development] documentation built by [http://forum.freecadweb.org/viewtopic.php?t=12613 qingfeng.xia].


Line 87: Line 132:
If you don't install the documentation package for Coin, the links will be generated to access the online documentation at [https://coin3d.bitbucket.io/Coin/ BitBucket]. This will happen if a Doxygen tag file can be downloaded at configure time with {{incode|wget}}.
If you don't install the documentation package for Coin, the links will be generated to access the online documentation at [https://coin3d.bitbucket.io/Coin/ BitBucket]. This will happen if a Doxygen tag file can be downloaded at configure time with {{incode|wget}}.


== How to integrate doxygen in to the FreeCAD source code == <!--T:18-->
== Using Doxygen == <!--T:18-->
{{VeryImportantMessage|This is a work in progress. See [[Doxygen]]}}


<!--T:28-->
This section explains how to comment your source code so that it can be processed by Doxygen to automatically create the documentation.
See the [[Doxygen|Doxygen]] page for an extensive explanation on how to comment C++ and Python source code so that it can be processed by Doxygen to automatically create the documentation.


<!--T:34-->
This is an example of how source code is documented. It looks into the source code of VTK, a 3D visualization library used to present multi-physics simulation results.
Essentially, a comment block, starting with {{incode|/**}} or {{incode|///}} for C++, or {{incode|##}} for Python, needs to appear before every class or function definition, so that it is picked up by Doxygen. Many [[Doxygen#Doxygen markup|special commands]], which start with {{incode|\}} or {{incode|@}}, can be used to define parts of the code and format the output. [[Doxygen#Markdown support|Markdown syntax]] is also understood within the comment block, which makes it convenient to emphasize certain parts of the documentation.
</translate>
{{Code|code=
/**
* Returns the name of the workbench object.
*/
std::string name() const;


/**
A class to store a collection of coordinates is defined in a C++ header file. The top part of the file is commented, and a few keywords are used, like {{incode|@class}}, {{incode|@brief}}, {{incode|@sa}}, and {{incode|@par}} to indicate important parts. Inside the class, before a function is called, a block of commented text explains what the function does, and its arguments.
* Set the name to the workbench object.
*/
void setName(const std::string&);


/// remove the added TaskWatcher
<!--T:20-->
void removeTaskWatcher(void);
*Source code of [https://github.com/Kitware/VTK/blob/master/Common/Core/vtkArrayCoordinates.h vtkArrayCoordinates.h] defining the class
}}
*Doxygen produced documentation page for [http://www.vtk.org/doc/nightly/html/classvtkArrayCoordinates.html vtkArrayCoordinates class]
<translate>


<!--T:13-->
{{docnav|Extra python modules|List of Commands}}


<!--T:22-->
<!--T:13-->
{{Docnav
{{Userdocnavi}}
|[[Extra_python_modules|Extra python modules]]
|[[Contributors|Contributors]]
}}


<!--T:14-->
[[Category:Developer Documentation]]
</translate>
</translate>
{{Userdocnavi{{#translation:}}}}
[[Category:Developer Documentation{{#translation:}}]]
{{clear}}
{{clear}}

Latest revision as of 21:49, 12 November 2021

Overview

The FreeCAD source code is commented to allow automatic programming documentation generation using Doxygen, a popular source code documentation system. Doxygen can document both the C++ and Python parts of FreeCAD, resulting in HTML pages with hyperlinks to each documented function and class.

The documentation is hosted online at the FreeCAD API website. Please note that this documentation may not always be up to date; if you need more details, download FreeCAD's latest source code and compile the documentation yourself. If you have pressing questions about the code please ask in the developer section of the FreeCAD forum.

Compiling the API documentation follows the same general steps as compiling the FreeCAD executable, as indicated in the Compile on Linux page.

General workflow to compile FreeCAD's programming documentation. The Doxygen and Graphviz packages must be in the system, as well as the FreeCAD source code itself. CMake configures the system so that with a single make instruction the documentation for the the entire project is compiled into many HTML files with diagrams.

Build source documentation

Complete documentation

If you have Doxygen installed, it is very easy to build the documentation. Also install Graphviz to be able to produce diagrams showing the relationships between different classes and libraries in the FreeCAD code. Graphviz is also used by FreeCAD's dependency graph to show the relationships between different objects.

sudo apt install doxygen graphviz

Then follow the same steps you would do to compile FreeCAD, as described on the compile on Linux page, and summarized here for convenience.

  • Get the source code of FreeCAD and place it in its own directory freecad-source.
  • Create another directory freecad-build in which you will compile FreeCAD and its documentation.
  • Configure the sources with cmake, making sure you indicate the source directory, and specify the required options for your build.
  • Trigger the creation of the documentation using make.
git clone https://github.com/FreeCAD/FreeCAD.git freecad-source
mkdir freecad-build
cd freecad-build
cmake -DBUILD_QT5=ON -DPYTHON_EXECUTABLE=/usr/bin/python3 ../freecad-source

While you are inside the build directory issue the following instruction to create only the documentation.

make -j$(nproc --ignore=2) DevDoc

As mentioned in compiling (speeding up), the -j option sets the number of CPU cores used for compilation. The resulting documentation files will appear in the directory

freecad-build/doc/SourceDocu/html/

The point of entrance to the documentation is the index.html file, which you can open with a web browser:

xdg-open freecad-build/doc/SourceDocu/html/index.html

The DevDoc target will generate a significant amount of data, around 5 GB of new files, particularly due to the diagrams created by Graphviz.

Reduced documentation

The complete documentation uses around 3Gb of disk space. An alternative, smaller version of the documentation which takes only around 600 MB can be generated with a different target. This is the version displayed on the FreeCAD API website.

make -j$(nproc --ignore=2) WebDoc

The documentation on the FreeCAD API website is produced automatically from https://github.com/FreeCAD/SourceDoc . Anyone can rebuild it and submit a pull request:

  • Fork the repo at https://github.com/FreeCAD/SourceDoc
  • on your machine: clone the FreeCAD code (if you haven't yet), create a build dir for the doc, and clone the above SourceDoc repo inside. That SourceDoc will be updated when you rebuild the doc, and you'll be able to commit & push the results afterwards:
git clone https://github.com/FreeCAD/FreeCAD
cd FreeCAD
mkdir build
cd build
mkdir -p doc/SourceDocu/html
cd doc/SourceDocu/html
git clone your-fork-url
cd ../../..
cmake -DBUILD_QT5=ON -DPYTHON_EXECUTABLE=/usr/bin/python3 ..
make WebDoc
cd doc/SourceDocu/html
git commit
git push
  • Go to your fork online, and create a pull request.

Other versions

FreeCAD 0.19 development documentation built by qingfeng.xia.

Integrate Coin3D documentation

On Unix systems it is possible to link Coin3D source documentation with FreeCAD's. This allows for easier navigation and complete inheritance diagrams for Coin derived classes.

  • Install the libcoin-doc, libcoin80-doc, or similarly named package.
  • Unpack the archive coin.tar.gz located in /usr/share/doc/libcoin-doc/html; the files may be already unpacked in your system.
  • Generate again the source documentation.

If you don't install the documentation package for Coin, the links will be generated to access the online documentation at BitBucket. This will happen if a Doxygen tag file can be downloaded at configure time with wget.

Using Doxygen

See the Doxygen page for an extensive explanation on how to comment C++ and Python source code so that it can be processed by Doxygen to automatically create the documentation.

Essentially, a comment block, starting with /** or /// for C++, or ## for Python, needs to appear before every class or function definition, so that it is picked up by Doxygen. Many special commands, which start with \ or @, can be used to define parts of the code and format the output. Markdown syntax is also understood within the comment block, which makes it convenient to emphasize certain parts of the documentation.

/**
 * Returns the name of the workbench object.
 */
std::string name() const;

/**
 * Set the name to the workbench object.
 */
void setName(const std::string&);

/// remove the added TaskWatcher
void removeTaskWatcher(void);