Application Programming Interface (API)

Plugins are implemented via Application Programming Interface (API) implementations. Each Plugin Class has its specific API and in the 3D Plugin tutorials we have seen examples of the implementation of the 3D Plugin API as declared by the header 3d_plugin.h. Plugins may also rely on other APIs defined within the KiCad source tree; in the case of 3D plugins, all plugins which support visualization of models must interact with the Scene Graph API as declared in the header ifsg_all.h and its included headers.

This section describes the details of available Plugin Class APIs and other KiCad APIs which may be required for implementations of plugin classes.

Plugin Class APIs

There is currently only one plugin class declared for KiCad: the 3D Plugin Class. All KiCad plugin classes must implement a basic set of functions declared in the header file kicad_plugin.h; these declarations are referred to as the Base Kicad Plugin Class. No implementation of the Base Kicad Plugin Class exists; the header file exists purely to ensure that plugin developers implement these defined functions in each plugin implementation.

Within KiCad, each instance of a Plugin Loader implements the API presented by a plugin as though the Plugin Loader is a class providing the plugin’s services. This is achieved by the Plugin Loader class providing a public interface containing function names which are similar to those implemented by the plugin; the argument lists may vary to accommodate the need to inform the user of any problems which may be encountered if, for example, no plugin is loaded. Internally the Plugin Loader uses a stored pointer to each API function to invoke each function on behalf of the user.

API: Base Kicad Plugin Class

The Base Kicad Plugin Class is defined by the header file kicad_plugin.h. This header must be included in the declaration of all other plugin classes; for an example see the 3D Plugin Class declaration in the header file 3d_plugin.h. The prototypes for these functions were briefly described in Plugin Classes. The API is implemented by the base plugin loader as defined in pluginldr.cpp.

To help make sense of the functions required by the base KiCad plugin header we must look at what happens in the base Plugin Loader class. The Plugin Loader class declares a virtual function Open() which takes the full path to the plugin to be loaded. The implementation of the Open() function within a specific plugin class loader will initially invoke the protected open() function of the base plugin loader; this base open() function attempts to find the address of each of the required basic plugin functions; once the addresses of each function have been retrieved, a number of checks are enforced:

  1. Plugin GetKicadPluginClass() is invoked and the result is compared to the Plugin Class string provided by the Plugin Loader implementation; if these strings do not match then the opened plugin is not intended for the Plugin Loader instance.

  2. Plugin GetClassVersion() is invoked to retrieve the Plugin Class API Version implemented by the plugin.

  3. Plugin Loader virtual GetLoaderVersion() function is invoked to retrieve the Plugin Class API Version implemented by the loader.

  4. The Plugin Class API Version reported by the plugin and the loader are required to have the same Major Version number, otherwise they are considered incompatible. This is the most basic version test and it is enforced by the base plugin loader.

  5. Plugin CheckClassVersion() is invoked with the Plugin Class API Version information of the Plugin Loader; if the Plugin supports the given version then it returns true to indicate success. If successful the loader creates a PluginInfo string based on the results of GetKicadPluginName() and GetPluginVersion(), and the plugin loading procedure continues within the Plugin Loader’s Open() implementation.

API: 3D Plugin Class

The 3D Plugin Class is declared by the header file 3d_plugin.h and it extends the required plugin functions as described in Plugin Class: PLUGIN_3D. The corresponding Plugin Loader is defined in pluginldr3D.cpp and the loader implements the following public functions in addition to the required API functions:

  1. /* Open the plugin specified by the full path "aFullFileName" */
  2. bool Open( const wxString& aFullFileName );
  3. /* Close the currently opened plugin */
  4. void Close( void );
  5. /* Retrieve the Plugin Class API Version implemented by this Plugin Loader */
  6. void GetLoaderVersion( unsigned char* Major, unsigned char* Minor,
  7. unsigned char* Revision, unsigned char* Patch ) const;

The required 3D Plugin Class functions are exposed via the following functions:

  1. /* returns the Plugin Class or NULL if no plugin loaded */
  2. char const* GetKicadPluginClass( void );
  3. /* returns false if no plugin loaded */
  4. bool GetClassVersion( unsigned char* Major, unsigned char* Minor,
  5. unsigned char* Patch, unsigned char* Revision );
  6. /* returns false if the class version check fails or no plugin is loaded */
  7. bool CheckClassVersion( unsigned char Major, unsigned char Minor,
  8. unsigned char Patch, unsigned char Revision );
  9. /* returns the Plugin Name or NULL if no plugin loaded */
  10. const char* GetKicadPluginName( void );
  11. /*
  12. returns false if no plugin is loaded, otherwise the arguments
  13. contain the result of GetPluginVersion()
  14. */
  15. bool GetVersion( unsigned char* Major, unsigned char* Minor,
  16. unsigned char* Patch, unsigned char* Revision );
  17. /*
  18. sets aPluginInfo to an empty string if no plugin is loaded,
  19. otherwise aPluginInfo is set to a string of the form:
  20. [NAME]:[MAJOR].[MINOR].[PATCH].[REVISION] where
  21. NAME = name provided by GetKicadPluginClass()
  22. MAJOR, MINOR, PATCH, REVISION = version information from
  23. GetPluginVersion()
  24. */
  25. void GetPluginInfo( std::string& aPluginInfo );

In typical situations, the user would do the following:

  1. Create an instance of KICAD_PLUGIN_LDR_3D.

  2. Invoke Open( "/path/to/myplugin.so" ) to open a specific plugin. The return value must be checked to ensure that the plugin loaded as desired.

  3. Invoke any of the 3D Plugin Class calls as exposed by KICAD_PLUGIN_LDR_3D.

  4. Invoke Close() to close (unlink) the plugin.

  5. Destroy the KICAD_PLUGIN_LDR_3D instance.

Scenegraph Class APIs

The Scenegraph Class API is defined by the header ifsg_all.h and its included headers. The API consists of a number of helper routines with the namespace S3D as defined in ifsg_api.h and wrapper classes defined by the various ifsg_*.h headers; the wrappers support the underlying scene graph classes which, taken together, form a scene graph structure which is compatible with VRML2.0 static scene graphs. The headers, structures, classes and their public functions are as follows:

sg_version.h

  1. /*
  2. Defines version information of the SceneGraph Classes.
  3. All plugins which use the scenegraph class should include this header
  4. and check the version information against the version reported by
  5. S3D::GetLibVersion() to ensure compatibility
  6. */
  7. #define KICADSG_VERSION_MAJOR 2
  8. #define KICADSG_VERSION_MINOR 0
  9. #define KICADSG_VERSION_PATCH 0
  10. #define KICADSG_VERSION_REVISION 0

sg_types.h

  1. /*
  2. Defines the SceneGraph Class Types; these types
  3. are closely related to VRML2.0 node types.
  4. */
  5. namespace S3D
  6. {
  7. enum SGTYPES
  8. {
  9. SGTYPE_TRANSFORM = 0,
  10. SGTYPE_APPEARANCE,
  11. SGTYPE_COLORS,
  12. SGTYPE_COLORINDEX,
  13. SGTYPE_FACESET,
  14. SGTYPE_COORDS,
  15. SGTYPE_COORDINDEX,
  16. SGTYPE_NORMALS,
  17. SGTYPE_SHAPE,
  18. SGTYPE_END
  19. };
  20. };

The sg_base.h header contains declarations of basic data types used by the scenegraph classes.

sg_base.h

  1. /*
  2. This is an RGB color model equivalent to the VRML2.0
  3. RGB model where each color may have a value within the
  4. range [0..1].
  5. */
  6. class SGCOLOR
  7. {
  8. public:
  9. SGCOLOR();
  10. SGCOLOR( float aRVal, float aGVal, float aBVal );
  11. void GetColor( float& aRedVal, float& aGreenVal, float& aBlueVal ) const;
  12. void GetColor( SGCOLOR& aColor ) const;
  13. void GetColor( SGCOLOR* aColor ) const;
  14. bool SetColor( float aRedVal, float aGreenVal, float aBlueVal );
  15. bool SetColor( const SGCOLOR& aColor );
  16. bool SetColor( const SGCOLOR* aColor );
  17. };
  18. class SGPOINT
  19. {
  20. public:
  21. double x;
  22. double y;
  23. double z;
  24. public:
  25. SGPOINT();
  26. SGPOINT( double aXVal, double aYVal, double aZVal );
  27. void GetPoint( double& aXVal, double& aYVal, double& aZVal );
  28. void GetPoint( SGPOINT& aPoint );
  29. void GetPoint( SGPOINT* aPoint );
  30. void SetPoint( double aXVal, double aYVal, double aZVal );
  31. void SetPoint( const SGPOINT& aPoint );
  32. };
  33. /*
  34. A SGVECTOR has 3 components (x,y,z) similar to a point; however
  35. a vector ensures that the stored values are normalized and
  36. prevents direct manipulation of the component variables.
  37. */
  38. class SGVECTOR
  39. {
  40. public:
  41. SGVECTOR();
  42. SGVECTOR( double aXVal, double aYVal, double aZVal );
  43. void GetVector( double& aXVal, double& aYVal, double& aZVal ) const;
  44. void SetVector( double aXVal, double aYVal, double aZVal );
  45. void SetVector( const SGVECTOR& aVector );
  46. SGVECTOR& operator=( const SGVECTOR& source );
  47. };

The IFSG_NODE class is the base class for all scenegraph nodes. All scenegraph objects implement the public functions of this class but in some cases a particular function may have no meaning for a specific class.

ifsg_node.h

  1. class IFSG_NODE
  2. {
  3. public:
  4. IFSG_NODE();
  5. virtual ~IFSG_NODE();
  6. /**
  7. * Function Destroy
  8. * deletes the scenegraph object held by this wrapper
  9. */
  10. void Destroy( void );
  11. /**
  12. * Function Attach
  13. * associates a given SGNODE* with this wrapper
  14. */
  15. virtual bool Attach( SGNODE* aNode ) = 0;
  16. /**
  17. * Function NewNode
  18. * creates a new node to associate with this wrapper
  19. */
  20. virtual bool NewNode( SGNODE* aParent ) = 0;
  21. virtual bool NewNode( IFSG_NODE& aParent ) = 0;
  22. /**
  23. * Function GetRawPtr()
  24. * returns the raw internal SGNODE pointer
  25. */
  26. SGNODE* GetRawPtr( void );
  27. /**
  28. * Function GetNodeType
  29. * returns the type of this node instance
  30. */
  31. S3D::SGTYPES GetNodeType( void ) const;
  32. /**
  33. * Function GetParent
  34. * returns a pointer to the parent SGNODE of this object
  35. * or NULL if the object has no parent (ie. top level transform)
  36. * or if the wrapper is not currently associated with an SGNODE.
  37. */
  38. SGNODE* GetParent( void ) const;
  39. /**
  40. * Function SetParent
  41. * sets the parent SGNODE of this object.
  42. *
  43. * @param aParent [in] is the desired parent node
  44. * @return true if the operation succeeds; false if
  45. * the given node is not allowed to be a parent to
  46. * the derived object.
  47. */
  48. bool SetParent( SGNODE* aParent );
  49. /**
  50. * Function GetNodeTypeName
  51. * returns the text representation of the node type
  52. * or NULL if the node somehow has an invalid type
  53. */
  54. const char * GetNodeTypeName( S3D::SGTYPES aNodeType ) const;
  55. /**
  56. * Function AddRefNode
  57. * adds a reference to an existing node which is not owned by
  58. * (not a child of) this node.
  59. *
  60. * @return true on success
  61. */
  62. bool AddRefNode( SGNODE* aNode );
  63. bool AddRefNode( IFSG_NODE& aNode );
  64. /**
  65. * Function AddChildNode
  66. * adds a node as a child owned by this node.
  67. *
  68. * @return true on success
  69. */
  70. bool AddChildNode( SGNODE* aNode );
  71. bool AddChildNode( IFSG_NODE& aNode );
  72. };

IFSG_TRANSFORM is similar to a VRML2.0 Transform node; it may contain any number of child IFSG_SHAPE and IFSG_TRANSFORM nodes and any number of referenced IFSG_SHAPE and IFSG_TRANSFORM nodes. A valid scenegraph must have a single IFSG_TRANSFORM object as a root.

ifsg_transform.h

  1. /**
  2. * Class IFSG_TRANSFORM
  3. * is the wrapper for the VRML compatible TRANSFORM block class SCENEGRAPH
  4. */
  5. class IFSG_TRANSFORM : public IFSG_NODE
  6. {
  7. public:
  8. IFSG_TRANSFORM( bool create );
  9. IFSG_TRANSFORM( SGNODE* aParent );
  10. bool SetScaleOrientation( const SGVECTOR& aScaleAxis, double aAngle );
  11. bool SetRotation( const SGVECTOR& aRotationAxis, double aAngle );
  12. bool SetScale( const SGPOINT& aScale );
  13. bool SetScale( double aScale );
  14. bool SetCenter( const SGPOINT& aCenter );
  15. bool SetTranslation( const SGPOINT& aTranslation );
  16. /* various base class functions not shown here */
  17. };

IFSG_SHAPE is similar to a VRML2.0 Shape node; it must contain a single child or reference FACESET node and may contain a single child or reference APPEARANCE node.

ifsg_shape.h

  1. /**
  2. * Class IFSG_SHAPE
  3. * is the wrapper for the SGSHAPE class
  4. */
  5. class IFSG_SHAPE : public IFSG_NODE
  6. {
  7. public:
  8. IFSG_SHAPE( bool create );
  9. IFSG_SHAPE( SGNODE* aParent );
  10. IFSG_SHAPE( IFSG_NODE& aParent );
  11. /* various base class functions not shown here */
  12. };

IFSG_APPEARANCE is similar to a VRML2.0 Appearance node, however, at the moment it only represents the equivalent of an Appearance node containing a Material node.

ifsg_appearance.h

  1. class IFSG_APPEARANCE : public IFSG_NODE
  2. {
  3. public:
  4. IFSG_APPEARANCE( bool create );
  5. IFSG_APPEARANCE( SGNODE* aParent );
  6. IFSG_APPEARANCE( IFSG_NODE& aParent );
  7. bool SetEmissive( float aRVal, float aGVal, float aBVal );
  8. bool SetEmissive( const SGCOLOR* aRGBColor );
  9. bool SetEmissive( const SGCOLOR& aRGBColor );
  10. bool SetDiffuse( float aRVal, float aGVal, float aBVal );
  11. bool SetDiffuse( const SGCOLOR* aRGBColor );
  12. bool SetDiffuse( const SGCOLOR& aRGBColor );
  13. bool SetSpecular( float aRVal, float aGVal, float aBVal );
  14. bool SetSpecular( const SGCOLOR* aRGBColor );
  15. bool SetSpecular( const SGCOLOR& aRGBColor );
  16. bool SetAmbient( float aRVal, float aGVal, float aBVal );
  17. bool SetAmbient( const SGCOLOR* aRGBColor );
  18. bool SetAmbient( const SGCOLOR& aRGBColor );
  19. bool SetShininess( float aShininess );
  20. bool SetTransparency( float aTransparency );
  21. /* various base class functions not shown here */
  22. /* the following functions make no sense within an
  23. appearance node and always return a failure code
  24. bool AddRefNode( SGNODE* aNode );
  25. bool AddRefNode( IFSG_NODE& aNode );
  26. bool AddChildNode( SGNODE* aNode );
  27. bool AddChildNode( IFSG_NODE& aNode );
  28. */
  29. };

IFSG_FACESET is similar to a VRML2.0 Geometry node which contains an IndexedFaceSet node. It must contain a single child or reference COORDS node, a single child COORDINDEX node, and a single child or reference NORMALS node; in addition there may be a single child or reference COLORS node. A simplistic normals calculation function is provided to aid the user in assigning normal values to surfaces. The deviations from the VRML2.0 analogue are as follows:

  1. Normals are always per-vertex.

  2. Colors are always per vertex.

  3. The coordinate index set must describe triangular faces only.

ifsg_faceset.h

  1. /**
  2. * Class IFSG_FACESET
  3. * is the wrapper for the SGFACESET class
  4. */
  5. class IFSG_FACESET : public IFSG_NODE
  6. {
  7. public:
  8. IFSG_FACESET( bool create );
  9. IFSG_FACESET( SGNODE* aParent );
  10. IFSG_FACESET( IFSG_NODE& aParent );
  11. bool CalcNormals( SGNODE** aPtr );
  12. /* various base class functions not shown here */
  13. };

ifsg_coords.h

  1. /**
  2. * Class IFSG_COORDS
  3. * is the wrapper for SGCOORDS
  4. */
  5. class IFSG_COORDS : public IFSG_NODE
  6. {
  7. public:
  8. IFSG_COORDS( bool create );
  9. IFSG_COORDS( SGNODE* aParent );
  10. IFSG_COORDS( IFSG_NODE& aParent );
  11. bool GetCoordsList( size_t& aListSize, SGPOINT*& aCoordsList );
  12. bool SetCoordsList( size_t aListSize, const SGPOINT* aCoordsList );
  13. bool AddCoord( double aXValue, double aYValue, double aZValue );
  14. bool AddCoord( const SGPOINT& aPoint );
  15. /* various base class functions not shown here */
  16. /* the following functions make no sense within a
  17. coords node and always return a failure code
  18. bool AddRefNode( SGNODE* aNode );
  19. bool AddRefNode( IFSG_NODE& aNode );
  20. bool AddChildNode( SGNODE* aNode );
  21. bool AddChildNode( IFSG_NODE& aNode );
  22. */
  23. };

IFSG_COORDINDEX is similar to a VRML2.0 coordIdx[] set except it must exclusively describe triangular faces, which implies that the total number of indices is divisible by 3.

ifsg_coordindex.h

  1. /**
  2. * Class IFSG_COORDINDEX
  3. * is the wrapper for SGCOORDINDEX
  4. */
  5. class IFSG_COORDINDEX : public IFSG_INDEX
  6. {
  7. public:
  8. IFSG_COORDINDEX( bool create );
  9. IFSG_COORDINDEX( SGNODE* aParent );
  10. IFSG_COORDINDEX( IFSG_NODE& aParent );
  11. bool GetIndices( size_t& nIndices, int*& aIndexList );
  12. bool SetIndices( size_t nIndices, int* aIndexList );
  13. bool AddIndex( int aIndex );
  14. /* various base class functions not shown here */
  15. /* the following functions make no sense within a
  16. coordindex node and always return a failure code
  17. bool AddRefNode( SGNODE* aNode );
  18. bool AddRefNode( IFSG_NODE& aNode );
  19. bool AddChildNode( SGNODE* aNode );
  20. bool AddChildNode( IFSG_NODE& aNode );
  21. */
  22. };

IFSG_NORMALS is equivalent to a VRML2.0 Normals node.

ifsg_normals.h

  1. /**
  2. * Class IFSG_NORMALS
  3. * is the wrapper for the SGNORMALS class
  4. */
  5. class IFSG_NORMALS : public IFSG_NODE
  6. {
  7. public:
  8. IFSG_NORMALS( bool create );
  9. IFSG_NORMALS( SGNODE* aParent );
  10. IFSG_NORMALS( IFSG_NODE& aParent );
  11. bool GetNormalList( size_t& aListSize, SGVECTOR*& aNormalList );
  12. bool SetNormalList( size_t aListSize, const SGVECTOR* aNormalList );
  13. bool AddNormal( double aXValue, double aYValue, double aZValue );
  14. bool AddNormal( const SGVECTOR& aNormal );
  15. /* various base class functions not shown here */
  16. /* the following functions make no sense within a
  17. normals node and always return a failure code
  18. bool AddRefNode( SGNODE* aNode );
  19. bool AddRefNode( IFSG_NODE& aNode );
  20. bool AddChildNode( SGNODE* aNode );
  21. bool AddChildNode( IFSG_NODE& aNode );
  22. */
  23. };

IFSG_COLORS is similar to a VRML2.0 colors[] set.

ifsg_colors.h

  1. /**
  2. * Class IFSG_COLORS
  3. * is the wrapper for SGCOLORS
  4. */
  5. class IFSG_COLORS : public IFSG_NODE
  6. {
  7. public:
  8. IFSG_COLORS( bool create );
  9. IFSG_COLORS( SGNODE* aParent );
  10. IFSG_COLORS( IFSG_NODE& aParent );
  11. bool GetColorList( size_t& aListSize, SGCOLOR*& aColorList );
  12. bool SetColorList( size_t aListSize, const SGCOLOR* aColorList );
  13. bool AddColor( double aRedValue, double aGreenValue, double aBlueValue );
  14. bool AddColor( const SGCOLOR& aColor );
  15. /* various base class functions not shown here */
  16. /* the following functions make no sense within a
  17. normals node and always return a failure code
  18. bool AddRefNode( SGNODE* aNode );
  19. bool AddRefNode( IFSG_NODE& aNode );
  20. bool AddChildNode( SGNODE* aNode );
  21. bool AddChildNode( IFSG_NODE& aNode );
  22. */
  23. };

The remaining API functions are defined in ifsg_api.h as follows:

ifsg_api.h

  1. namespace S3D
  2. {
  3. /**
  4. * Function GetLibVersion retrieves version information of the
  5. * kicad_3dsg library
  6. */
  7. SGLIB_API void GetLibVersion( unsigned char* Major, unsigned char* Minor,
  8. unsigned char* Patch, unsigned char* Revision );
  9. // functions to extract information from SGNODE pointers
  10. SGLIB_API S3D::SGTYPES GetSGNodeType( SGNODE* aNode );
  11. SGLIB_API SGNODE* GetSGNodeParent( SGNODE* aNode );
  12. SGLIB_API bool AddSGNodeRef( SGNODE* aParent, SGNODE* aChild );
  13. SGLIB_API bool AddSGNodeChild( SGNODE* aParent, SGNODE* aChild );
  14. SGLIB_API void AssociateSGNodeWrapper( SGNODE* aObject, SGNODE** aRefPtr );
  15. /**
  16. * Function CalcTriNorm
  17. * returns the normal vector of a triangle described by vertices p1, p2, p3
  18. */
  19. SGLIB_API SGVECTOR CalcTriNorm( const SGPOINT& p1, const SGPOINT& p2, const SGPOINT& p3 );
  20. /**
  21. * Function WriteCache
  22. * writes the SGNODE tree to a binary cache file
  23. *
  24. * @param aFileName is the name of the file to write
  25. * @param overwrite must be set to true to overwrite an existing file
  26. * @param aNode is any node within the node tree which is to be written
  27. * @return true on success
  28. */
  29. SGLIB_API bool WriteCache( const char* aFileName, bool overwrite, SGNODE* aNode,
  30. const char* aPluginInfo );
  31. /**
  32. * Function ReadCache
  33. * reads a binary cache file and creates an SGNODE tree
  34. *
  35. * @param aFileName is the name of the binary cache file to be read
  36. * @return NULL on failure, on success a pointer to the top level SCENEGRAPH node;
  37. * if desired this node can be associated with an IFSG_TRANSFORM wrapper via
  38. * the IFSG_TRANSFORM::Attach() function.
  39. */
  40. SGLIB_API SGNODE* ReadCache( const char* aFileName, void* aPluginMgr,
  41. bool (*aTagCheck)( const char*, void* ) );
  42. /**
  43. * Function WriteVRML
  44. * writes out the given node and its subnodes to a VRML2 file
  45. *
  46. * @param filename is the name of the output file
  47. * @param overwrite should be set to true to overwrite an existing VRML file
  48. * @param aTopNode is a pointer to a SCENEGRAPH object representing the VRML scene
  49. * @param reuse should be set to true to make use of VRML DEF/USE features
  50. * @return true on success
  51. */
  52. SGLIB_API bool WriteVRML( const char* filename, bool overwrite, SGNODE* aTopNode,
  53. bool reuse, bool renameNodes );
  54. // NOTE: The following functions are used in combination to create a VRML
  55. // assembly which may use various instances of each SG* representation of a module.
  56. // A typical use case would be:
  57. // 1. invoke 'ResetNodeIndex()' to reset the global node name indices
  58. // 2. for each model pointer provided by 'S3DCACHE->Load()', invoke 'RenameNodes()' once;
  59. // this ensures that all nodes have a unique name to present to the final output file.
  60. // Internally, RenameNodes() will only rename the given node and all Child subnodes;
  61. // nodes which are only referenced will not be renamed. Using the pointer supplied
  62. // by 'S3DCACHE->Load()' ensures that all nodes but the returned node (top node) are
  63. // children of at least one node, so all nodes are given unique names.
  64. // 3. if SG* trees are created independently of S3DCACHE->Load() the user must invoke
  65. // RenameNodes() as appropriate to ensure that all nodes have a unique name
  66. // 4. create an assembly structure by creating new IFSG_TRANSFORM nodes as appropriate
  67. // for each instance of a component; the component base model as returned by
  68. // S3DCACHE->Load() may be added to these IFSG_TRANSFORM nodes via 'AddRefNode()';
  69. // set the offset, rotation, etc of the IFSG_TRANSFORM node to ensure correct
  70. // 5. Ensure that all new IFSG_TRANSFORM nodes are placed as child nodes within a
  71. // top level IFSG_TRANSFORM node in preparation for final node naming and output
  72. // 6. Invoke RenameNodes() on the top level assembly node
  73. // 7. Invoke WriteVRML() as normal, with renameNodes = false, to write the entire assembly
  74. // structure to a single VRML file
  75. // 8. Clean up by deleting any extra IFSG_TRANSFORM wrappers and their underlying SG*
  76. // classes which have been created solely for the assembly output
  77. /**
  78. * Function ResetNodeIndex
  79. * resets the global SG* class indices
  80. *
  81. * @param aNode may be any valid SGNODE
  82. */
  83. SGLIB_API void ResetNodeIndex( SGNODE* aNode );
  84. /**
  85. * Function RenameNodes
  86. * renames a node and all children nodes based on the current
  87. * values of the global SG* class indices
  88. *
  89. * @param aNode is a top level node
  90. */
  91. SGLIB_API void RenameNodes( SGNODE* aNode );
  92. /**
  93. * Function DestroyNode
  94. * deletes the given SG* class node. This function makes it possible
  95. * to safely delete an SG* node without associating the node with
  96. * its corresponding IFSG* wrapper.
  97. */
  98. SGLIB_API void DestroyNode( SGNODE* aNode );
  99. // NOTE: The following functions facilitate the creation and destruction
  100. // of data structures for rendering
  101. /**
  102. * Function GetModel
  103. * creates an S3DMODEL representation of aNode (raw data, no transforms)
  104. *
  105. * @param aNode is the node to be transcribed into an S3DMODEL representation
  106. * @return an S3DMODEL representation of aNode on success, otherwise NULL
  107. */
  108. SGLIB_API S3DMODEL* GetModel( SCENEGRAPH* aNode );
  109. /**
  110. * Function Destroy3DModel
  111. * frees memory used by an S3DMODEL structure and sets the pointer to
  112. * the structure to NULL
  113. */
  114. SGLIB_API void Destroy3DModel( S3DMODEL** aModel );
  115. /**
  116. * Function Free3DModel
  117. * frees memory used internally by an S3DMODEL structure
  118. */
  119. SGLIB_API void Free3DModel( S3DMODEL& aModel );
  120. /**
  121. * Function Free3DMesh
  122. * frees memory used internally by an SMESH structure
  123. */
  124. SGLIB_API void Free3DMesh( SMESH& aMesh );
  125. /**
  126. * Function New3DModel
  127. * creates and initializes an S3DMODEL struct
  128. */
  129. SGLIB_API S3DMODEL* New3DModel( void );
  130. /**
  131. * Function Init3DMaterial
  132. * initializes an SMATERIAL struct
  133. */
  134. SGLIB_API void Init3DMaterial( SMATERIAL& aMat );
  135. /**
  136. * Function Init3DMesh
  137. * creates and initializes an SMESH struct
  138. */
  139. SGLIB_API void Init3DMesh( SMESH& aMesh );
  140. };

For actual usage examples of the Scenegraph API see the Advanced 3D Plugin tutorial above and the KiCad VRML1, VRML2, and X3D parsers.