Hopsan
|
The majority of the Hopsan component code is contained within the HopsanCore. When a new component is created, only the parts which make the new component unique needs to be specified. All other functionality is inherited from the base implementation in the HopsanCore. The code that is written for the new components must be compiled into a shared object file .dll (Windows), .so (UNIX) or .dynlib (MacOS) file. This file will contain the runtime executable code for the new components. While simulating, Hopsan will call functions in this file when the component is created, initialized, finalized and when it takes a simulation step.
The compiled library file can include one or several new components. It must also include two mandatory functions used by the HopsanCore to get information about and to register the contents of the library once it is loaded. A description of the library files is given in The Component Library Files
See the page_setupbuildenvironment or How to setup the component library development environment page for instructions on how to set up your development environment.
The documentation examples are based on the exampleComponentLibrary that is included in each Hopsan release. You can find it in your Hopsan installation directory, under componentLibraries/exampleComponentLib
. These documentation examples contain subsets of the original files, you should also look at the original files for their full content and additional comments. When creating a new component library, you can use the example files as a "getting started" template.
generateLibraryFiles.py:
If you end up building large component libraries, then this python script may come in handy. It can be used to automatically generate header and source include files as well as Qt project include files for the entire library tree recursively. See the defualtComponentLibrary that is included in each Hopsan release for an example.