Refactored to use new generic plugin base

This commit is contained in:
Cirilo Bernardo
2015-12-14 08:45:22 +11:00
parent 86042d86a6
commit 3ff8ca0caf
14 changed files with 1418 additions and 367 deletions
+96 -56
View File
@@ -30,69 +30,109 @@
#ifndef PLUGIN_3D_H
#define PLUGIN_3D_H
#include <wx/string.h>
//
// KICAD_PLUGIN CLASS INTERFACE
//
// WARNING: DO NOT EDIT THIS FILE OUTSIDE THE KICAD TREE
//
// Note: the plugin class name must match the name expected by the loader
#define KICAD_PLUGIN_CLASS "PLUGIN_3D"
#define MAJOR 1
#define MINOR 0
#define REVISION 0
#define PATCH 0
#include "../kicad_plugin.h"
KICAD_PLUGIN_EXPORT char const* GetKicadPluginClass( void )
{
return KICAD_PLUGIN_CLASS;
}
KICAD_PLUGIN_EXPORT void GetClassVersion( unsigned char* Major,
unsigned char* Minor, unsigned char* Revision, unsigned char* Patch )
{
if( Major )
*Major = MAJOR;
if( Minor )
*Minor = MINOR;
if( Revision )
*Revision = REVISION;
if( Patch )
*Patch = PATCH;
return;
}
KICAD_PLUGIN_EXPORT bool CheckClassVersion( unsigned char Major,
unsigned char Minor, unsigned char Revision, unsigned char Patch )
{
if( Major != MAJOR )
return false;
// at the moment there are no incompatibility rules other than the Major Version check
return true;
}
class SCENEGRAPH;
class S3D_PLUGIN
{
public:
virtual ~S3D_PLUGIN()
{
return;
}
/**
* Function GetNExtensions
*
* @return the number of extensions supported by the plugin
*/
KICAD_PLUGIN_EXPORT int GetNExtensions( void );
/**
* Function GetNExtensions
*
* @return the number of extensions supported by the plugin
*/
virtual int GetNExtensions( void ) const = 0;
/**
* Function GetModelExtension
*
* @param aIndex is the extension to return; valid values are
* 0 to GetNExtensions() - 1.
* @return the requested extension or a null string if aIndex
* was invalid.
*/
KICAD_PLUGIN_EXPORT char const* GetModelExtension( int aIndex );
/**
* Function GetModelExtension
*
* @param aIndex is the extension to return; valid values are
* 0 to GetNExtensions() - 1.
* @return the requested extension or a null string if aIndex
* was invalid.
*/
virtual const wxString GetModelExtension( int aIndex ) const = 0;
/**
* Function GetNFilters
* @returns the number of file filters
*/
KICAD_PLUGIN_EXPORT int GetNFilters( void );
/**
* Function GetNFilters
* @returns the number of file filters
*/
virtual int GetNFilters( void ) const = 0;
/**
* Function GetFileFilter
*
* @return the file filter string for the given index
*/
KICAD_PLUGIN_EXPORT char const* GetFileFilter( int aIndex );
/**
* Function GetFileFilter
*
* @return the file filter string for the given index
*/
virtual const wxString GetFileFilter( int aIndex ) const = 0;
/**
* Function CanRender
*
* @return true if the plugin can render a model, that is
* the Load() function is implemented
*/
KICAD_PLUGIN_EXPORT bool CanRender( void );
/**
* Function CanRender
*
* @return true if the plugin can render a model, that is
* the Load() function is implemented
*/
virtual bool CanRender( void ) const = 0;
/**
* Function Load
* reads the model file and creates a generic display structure
*
* @param aFileName is the full path of the model file
* @param aModel is a handle to a null pointer; on successful
* reading of the model data aModel will point to a representation
* for rendering
* @param returns true if the model was successfully loaded and false
* if there is no rendering support for the model or there were
* problems reading the model
*/
virtual SCENEGRAPH* Load( const wxString& aFileName ) = 0;
};
/**
* Function Load
* reads the model file and creates a generic display structure
*
* @param aFileName is the full path of the model file
* @param aModel is a handle to a null pointer; on successful
* reading of the model data aModel will point to a representation
* for rendering
* @param returns true if the model was successfully loaded and false
* if there is no rendering support for the model or there were
* problems reading the model
*/
KICAD_PLUGIN_EXPORT SCENEGRAPH* Load( char const* aFileName );
#endif // PLUGIN_3D_H
+112
View File
@@ -0,0 +1,112 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file kicad_plugin.h
* defines the most basic functions which all kicad plugins must implement.
* In the implementation the definitions must make use of the KICAD_PLUGIN_EXPORT
* to ensure symbol visibility.
*/
#ifndef KICAD_PLUGIN_H
#define KICAD_PLUGIN_H
#ifndef _WIN32
#ifndef KICAD_PLUGIN_EXPORT
#define KICAD_PLUGIN_EXPORT extern "C" __attribute__((__visibility__("default")))
#endif
#else
#include <cstdint>
#ifndef KICAD_PLUGIN_EXPORT
#define KICAD_PLUGIN_EXPORT extern "C" __declspec( dllexport )
#endif
#endif
/**
* Function GetKicadPluginClass
* returns the name of the implemented plugin class; for
* example 3DPLUGIN. This should be implemented in a source
* module which is compiled as part of every implementation
* of a specific plugin class.
*
* @return is the NULL-terminated UTF-8 string representing the
* plugin class
*/
KICAD_PLUGIN_EXPORT char const* GetKicadPluginClass( void );
/**
* Function GetClassVersion
* retrieves the version of the Plugin Class. This value is used to
* ensure API compatibility of a plugin as per typical practice. This must
* be implemented in a source module which is compiled as part of every
* implementation of a specific plugin class
*
* @param Major will hold the Plugin Class Major version
* @param Minor will hold the Plugin Class Minor version
* @param Revision will hold the Plugin Class Revision
* @param Patch will hold the Plugin Class Patch level
*/
KICAD_PLUGIN_EXPORT void GetClassVersion( unsigned char* Major,
unsigned char* Minor, unsigned char* Revision, unsigned char* Patch );
/**
* Function CheckClassVersion
* returns true if the class version reported by the Plugin Loader
* is compatible with the specific implementation of a plugin.
* This function must be defined by each specific plugin and it is
* the plugin developer's responsibility to ensure that the Plugin
* is in fact compatible with the Plugin Loader. The Plugin Loader
* shall reject any Plugin with a different Major number regardless
* of the return value of this function.
*/
KICAD_PLUGIN_EXPORT bool CheckClassVersion( unsigned char Major,
unsigned char Minor, unsigned char Revision, unsigned char Patch );
/**
* Function GetKicadPluginName
* returns the name of the plugin instance; for example IDFv3.
* This string may be used to check for name conflicts or to
* display informational messages about loaded plugins. This method
* must be implemented in specific instantiations of a plugin class.
*
* @return is the NULL-terminated UTF-8 string representing the
* plugin name
*/
KICAD_PLUGIN_EXPORT const char* GetKicadPluginName( void );
/**
* Function GetVersion
* retrieves the version of the instantiated plugin for informational
* purposes. Do not confuse this with GetAPIVersion which is used to
* determine API compatibility.
*
* @param Major will hold the Plugin Major version
* @param Minor will hold the Plugin Minor version
* @param Revision will hold the Plugin Revision
* @param Patch will hold the Plugin Patch level
*/
KICAD_PLUGIN_EXPORT void GetVersion( unsigned char* Major,
unsigned char* Minor, unsigned char* Revision, unsigned char* Patch );
#endif // KICAD_PLUGIN_H