← Back to team overview

kicad-developers team mailing list archive

Re: GAL PPA, scripting PPA

 

On 04/12/2013 02:26 PM, Adam Wolf wrote:

CERN folks, I'd be glad to talk about #7 on your roadmap and see if
there's anything I/Wayne and Layne can do to help the situation.

Hi Adam,

This is great news!

The proposal we discussed with the main devs some time ago is to first turn Kicad apps into DLLs, adding an API that will allow for inter-app communication and at some point in the future, embedding pcbnew/eeschema/gerbview windows into tabs. The second stage (to be discussed yet) is about refactoring all optional stuff into plugins: - writing a global plugin manager (most likely an extension of IO_MGR) that can enumerate and load both built-in and DLL plugins - moving import/export of schematics, 3D models, graphics and non-native libraries into DLL plugins. Probably the easiest one is 3D model import, with DLLs one can easily bring native STEP/IGES support without having to directly link pcbnew against OpenCascade libraries.
- much later (when #5 is done), adding tool plugins.

I did a quick hack for eeschema & pcbnew DLLs (see attachment), but it's incomplete and I'm afraid I won't have time to work on it anytime soon. Any help is more than welcome :)


Regards,
Tom

=== modified file 'CMakeLists.txt'
--- CMakeLists.txt	2013-02-27 07:19:42 +0000
+++ CMakeLists.txt	2013-03-21 15:58:58 +0000
@@ -151,8 +151,8 @@
         set(CMAKE_EXE_LINKER_FLAGS_RELEASE "-s")
 
         # Set default flags for Debug build.
-        set(CMAKE_C_FLAGS_DEBUG "${KICAD_GCC_DEBUG_BUILD_FLAGS} -Wall  -g3 -ggdb3 -DDEBUG")
-        set(CMAKE_CXX_FLAGS_DEBUG "${KICAD_GCC_DEBUG_BUILD_FLAGS} -Wall -g3 -ggdb3 -DDEBUG")
+        set(CMAKE_C_FLAGS_DEBUG "${KICAD_GCC_DEBUG_BUILD_FLAGS} -Wall  -g3 -ggdb3 -DDEBUG -fvisibility=hidden")
+        set(CMAKE_CXX_FLAGS_DEBUG "${KICAD_GCC_DEBUG_BUILD_FLAGS} -Wall -g3 -ggdb3 -DDEBUG -fvisibility=hidden")
     endif()
 
 endif(CMAKE_COMPILER_IS_GNUCXX)
@@ -374,6 +374,7 @@
 add_subdirectory(bitmap2component)
 add_subdirectory(pcb_calculator)
 add_subdirectory(tools)
+add_subdirectory(dll)
 #add_subdirectory(new)
 
 

=== added directory 'dll'
=== added file 'dll/CMakeLists.txt'
--- dll/CMakeLists.txt	1970-01-01 00:00:00 +0000
+++ dll/CMakeLists.txt	2013-03-21 17:19:56 +0000
@@ -0,0 +1,19 @@
+
+add_executable( dll_launcher dll_launcher.cpp )
+add_executable( lib_class_test lib_class_test.cpp )
+
+include_directories ( ../eeschema ../pcbnew ../common ../include ../)
+
+target_link_libraries( dll_launcher 
+											 -L.
+											 pcbnew_d
+											 eschema_d
+											 ${wxWidgets_LIBRARIES} )
+
+
+target_link_libraries( lib_class_test 
+											 -L.
+											 pcbnew_d
+											 eschema_d
+											 ${wxWidgets_LIBRARIES} )
+

=== added file 'dll/README'
--- dll/README	1970-01-01 00:00:00 +0000
+++ dll/README	2013-03-21 17:53:45 +0000
@@ -0,0 +1,6 @@
+Tom's DLL hacks. 
+
+This is just a dummy test, nothing to be pushed (yet) to "normal" Kicad. It's buggy.
+- dll_launcher loads either pcbnew or eeschema and launches it from a DLL.
+- lib_class_test loads links to both eeschema and PCBnew and allows browsing SCH/PCB libraries from
+  the same application, a functionality that we need for integrated library browser.
\ No newline at end of file

=== added file 'dll/dll_launcher.cpp'
--- dll/dll_launcher.cpp	1970-01-01 00:00:00 +0000
+++ dll/dll_launcher.cpp	2013-03-21 14:07:03 +0000
@@ -0,0 +1,45 @@
+#include <cstdio>
+#include <string>
+#include <stdexcept>
+
+#include <wx/app.h>
+
+using namespace std;
+
+wxApp* CreatePcbnewApp();
+wxApp* CreateEeschemaApp();
+
+main(int argc, char *argv[])
+{
+	wxApp *app = NULL;
+	
+	if(argc >= 2)
+	{
+		string appname = argv[1];
+		
+		if(appname == "pcbnew")
+			app =  CreatePcbnewApp();
+		
+		if (appname == "eeschema")
+			app =  CreateEeschemaApp();
+		
+		
+		if(!app)
+		{
+			printf("Unknown app :(\n");
+			return -1;
+		}
+	} else {
+		printf("usage: %s <application>\n", argv[0]);
+		return -1;
+	}
+	
+	wxApp::SetInstance( app );
+	wxEntryStart( argc, argv );
+	app->OnInit();
+	app->OnRun();
+	app->OnExit();
+	wxEntryCleanup();
+
+	return 0;
+}

=== added file 'dll/eeschema'
--- dll/eeschema	1970-01-01 00:00:00 +0000
+++ dll/eeschema	2013-03-21 17:25:16 +0000
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+LD_LIBRARY_PATH="." ./dll_launcher eeschema
\ No newline at end of file

=== added file 'dll/lib_class_test.cpp'
--- dll/lib_class_test.cpp	1970-01-01 00:00:00 +0000
+++ dll/lib_class_test.cpp	2013-03-21 17:33:23 +0000
@@ -0,0 +1,81 @@
+#include <cstdio>
+#include <string>
+#include <stdexcept>
+
+#include <wxstruct.h>
+
+#include <class_libentry.h>
+#include <class_library.h>
+#include <class_module.h>
+
+#include <io_mgr.h>
+
+#include <wx/string.h>
+
+using namespace std;
+
+void DumpSchematicLibrary(const string& filename)
+{
+	wxString errMsg;
+	wxFileName fname =  wxString(filename.c_str(), wxConvLibc);
+
+	auto_ptr<CMP_LIBRARY> myLib (new CMP_LIBRARY( LIBRARY_TYPE_EESCHEMA, fname ) );
+
+	myLib->Load(errMsg);
+	printf("Component library %s: %d entries\n", filename.c_str(), myLib->GetCount());
+    
+    for(LIB_ALIAS* ent = myLib->GetFirstEntry();;)
+    {
+    	LIB_PINS pins;
+    	ent->GetComponent()->GetPins(pins);
+    	printf("Component: %s, pins : %d\n", (const char *)ent->GetName().mb_str(), pins.size());
+		ent = myLib->GetNextEntry(ent->GetName());
+
+    	if(ent == myLib->GetFirstEntry())
+    		break;
+    }
+
+}
+
+void DumpFootprintLibrary(const string& filename)
+{
+	/* cool stuff :) */
+    PLUGIN::RELEASER pi( IO_MGR::PluginFind( IO_MGR::LEGACY ) );
+    wxArrayString fps;
+    wxString path (filename.c_str(), wxConvLibc);
+	
+	fps = pi->FootprintEnumerate(path);
+
+	printf("Footprint library %s: %d entries\n", filename.c_str(), fps.GetCount());
+
+	for(int i = 0; i < fps.GetCount(); i++)
+	{
+    	auto_ptr<MODULE> mod( pi->FootprintLoad( path, fps[i] ) );
+
+    	printf("Module: %s, pads: %d\n", (const char *) mod->GetLibRef().mb_str(), mod->GetPadCount());
+	}
+
+}
+
+main(int argc, char *argv[])
+{
+
+	if(argc < 3)
+	{
+		printf("usage: %s <component/footprint> <library file>\n", argv[0]);
+		return -1;
+	}
+
+	string mode (argv[1]);
+	
+	if(mode == "component")
+		DumpSchematicLibrary(argv[2]);
+	else if (mode == "footprint")
+		DumpFootprintLibrary(argv[2]);
+	else {
+		printf("Invalid parameter '%s'\n", argv[1]);
+		return -1;
+	}
+
+	return 0;
+}

=== added file 'dll/links.sh'
--- dll/links.sh	1970-01-01 00:00:00 +0000
+++ dll/links.sh	2013-03-21 14:36:12 +0000
@@ -0,0 +1,2 @@
+ln -sf ../pcbnew/libpcbnew_d.so .
+ln -sf ../eeschema/libeschema_d.so .
\ No newline at end of file

=== added file 'dll/pcbnew'
--- dll/pcbnew	1970-01-01 00:00:00 +0000
+++ dll/pcbnew	2013-03-21 17:25:21 +0000
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+LD_LIBRARY_PATH="." ./dll_launcher pcbnew
\ No newline at end of file

=== modified file 'eeschema/CMakeLists.txt'
--- eeschema/CMakeLists.txt	2012-12-16 11:36:18 +0000
+++ eeschema/CMakeLists.txt	2013-03-21 14:52:37 +0000
@@ -208,6 +208,13 @@
     ${EESCHEMA_SRCS}
     ${EESCHEMA_COMMON_SRCS}
     ${EESCHEMA_RESOURCES}
+   )
+
+
+add_library(eschema_d SHARED
+    ${EESCHEMA_SRCS}
+    ${EESCHEMA_COMMON_SRCS}
+    ${EESCHEMA_RESOURCES}
     )
 
 if(APPLE)
@@ -215,6 +222,8 @@
         ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist)
 endif(APPLE)
 
+
+
 target_link_libraries(eeschema
     common
     bitmaps
@@ -223,6 +232,14 @@
     ${GDI_PLUS_LIBRARIES}
     )
 
+target_link_libraries(eschema_d
+    common
+    bitmaps
+    polygon
+    ${wxWidgets_LIBRARIES}
+    ${GDI_PLUS_LIBRARIES}
+    )
+
 install(TARGETS eeschema
         DESTINATION ${KICAD_BIN}
         COMPONENT binary)

=== modified file 'eeschema/class_libentry.h'
--- eeschema/class_libentry.h	2012-09-02 16:38:52 +0000
+++ eeschema/class_libentry.h	2013-03-21 16:17:38 +0000
@@ -78,7 +78,7 @@
  * method to create components that have the same physical layout with different names
  * such as 74LS00, 74HC00 ... and many op amps.
  */
-class LIB_ALIAS : public EDA_ITEM
+class DLL_PUBLIC LIB_ALIAS : public EDA_ITEM
 {
     /**
      * The actual component of the alias.
@@ -185,7 +185,7 @@
  * A library component object is typically saved and loaded in a component library file (.lib).
  * Library components are different from schematic components.
  */
-class LIB_COMPONENT : public EDA_ITEM
+class DLL_PUBLIC LIB_COMPONENT : public EDA_ITEM
 {
     wxString           m_name;
     int                m_pinNameOffset;  ///< The offset in mils to draw the pin name.  Set to 0

=== modified file 'eeschema/class_library.h'
--- eeschema/class_library.h	2013-03-19 01:25:19 +0000
+++ eeschema/class_library.h	2013-03-21 17:34:22 +0000
@@ -87,7 +87,7 @@
  * is used to load, save, search, and otherwise manipulate
  * component library files.
  */
-class CMP_LIBRARY
+class DLL_PUBLIC CMP_LIBRARY
 {
     int                type;            ///< Library type indicator.
     wxFileName         fileName;        ///< Library file name.

=== modified file 'eeschema/eeschema.cpp'
--- eeschema/eeschema.cpp	2013-01-04 12:06:50 +0000
+++ eeschema/eeschema.cpp	2013-03-21 15:00:16 +0000
@@ -65,8 +65,14 @@
 // static object for many reasons) and also declares the accessor function
 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
 // not wxApp)
+
 IMPLEMENT_APP( EDA_APP )
 
+DLL_PUBLIC EDA_APP *CreateEeschemaApp()
+{
+    return new EDA_APP();
+}
+
 /* MacOSX: Needed for file association
  * http://wiki.wxwidgets.org/WxMac-specific_topics
  */

=== modified file 'eeschema/lib_pin.h'
--- eeschema/lib_pin.h	2013-02-20 11:46:38 +0000
+++ eeschema/lib_pin.h	2013-03-21 16:23:36 +0000
@@ -29,6 +29,7 @@
 #ifndef CLASS_PIN_H
 #define CLASS_PIN_H
 
+#include <common.h>
 #include <lib_draw_item.h>
 
 
@@ -95,7 +96,7 @@
 };
 
 
-class LIB_PIN : public LIB_ITEM
+class DLL_PUBLIC LIB_PIN : public LIB_ITEM
 {
     wxPoint  m_position;     ///< Position of the pin.
     int      m_length;       ///< Length of the pin.

=== modified file 'include/class_board_item.h'
--- include/class_board_item.h	2012-09-01 13:38:27 +0000
+++ include/class_board_item.h	2013-03-21 15:09:37 +0000
@@ -33,6 +33,7 @@
 
 #include <base_struct.h>
 #include <gr_basic.h>
+#include <common.h>
 #include <boost/ptr_container/ptr_vector.hpp>
 
 
@@ -68,7 +69,7 @@
  * found in Pcbnew or other programs that use class BOARD and its contents.
  * The corresponding class in Eeschema is SCH_ITEM.
  */
-class BOARD_ITEM : public EDA_ITEM
+class DLL_PUBLIC BOARD_ITEM : public EDA_ITEM
 {
     // These are made private here so they may not be used.
     // Instead everything derived from BOARD_ITEM is handled via DLIST<>'s

=== modified file 'include/common.h'
--- include/common.h	2013-01-18 10:42:23 +0000
+++ include/common.h	2013-03-21 14:38:37 +0000
@@ -42,6 +42,8 @@
 #include <convert_to_biu.h>
 #include <colors.h>
 
+#define DLL_PUBLIC __attribute__ ((visibility ("default")))
+
 #if !wxUSE_PRINTING_ARCHITECTURE && !SWIG
 #   error "You must use '--enable-printarch' in your wx library configuration."
 #endif

=== modified file 'include/wxBasePcbFrame.h'
--- include/wxBasePcbFrame.h	2012-10-07 15:37:25 +0000
+++ include/wxBasePcbFrame.h	2013-03-21 15:42:49 +0000
@@ -60,7 +60,7 @@
  * class PCB_BASE_FRAME
  * basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
  */
-class PCB_BASE_FRAME : public EDA_DRAW_FRAME
+class DLL_PUBLIC PCB_BASE_FRAME : public EDA_DRAW_FRAME
 {
 public:
     bool m_DisplayPadFill;          // How show pads

=== modified file 'pcbnew/CMakeLists.txt'
--- pcbnew/CMakeLists.txt	2013-03-18 19:36:07 +0000
+++ pcbnew/CMakeLists.txt	2013-03-21 17:51:05 +0000
@@ -401,6 +401,13 @@
     ${PCBNEW_RESOURCES}
     )
 
+add_library(pcbnew_d SHARED 
+    ${PCBNEW_SRCS}
+    ${PCBNEW_COMMON_SRCS}
+    ${PCBNEW_SCRIPTING_SRCS}
+    ${PCBNEW_RESOURCES}
+    )
+
 ###
 # Set properties for APPLE on pcbnew target
 ###
@@ -426,6 +433,20 @@
     ${PCBNEW_EXTRA_LIBS}
     )
 
+target_link_libraries(pcbnew_d
+    3d-viewer
+    pcbcommon
+    common
+    pcad2kicadpcb
+    polygon
+    bitmaps
+    ${wxWidgets_LIBRARIES}
+    ${OPENGL_LIBRARIES}
+    ${GDI_PLUS_LIBRARIES}
+    ${PYTHON_LIBRARIES}
+    ${PCBNEW_EXTRA_LIBS}
+    )
+
 ###
 # Add pcbnew as install target
 ###

=== modified file 'pcbnew/class_board.h'
--- pcbnew/class_board.h	2013-03-20 14:50:12 +0000
+++ pcbnew/class_board.h	2013-03-21 17:34:22 +0000
@@ -168,7 +168,7 @@
  * Class BOARD
  * holds information pertinent to a Pcbnew printed circuit board.
  */
-class BOARD : public BOARD_ITEM
+class DLL_PUBLIC BOARD : public BOARD_ITEM
 {
     friend class PCB_EDIT_FRAME;
 

=== modified file 'pcbnew/class_module.h'
--- pcbnew/class_module.h	2013-03-18 19:36:07 +0000
+++ pcbnew/class_module.h	2013-03-21 17:34:22 +0000
@@ -64,7 +64,7 @@
 };
 
 
-class MODULE : public BOARD_ITEM
+class DLL_PUBLIC MODULE : public BOARD_ITEM
 {
 public:
     MODULE( BOARD* parent );

=== modified file 'pcbnew/class_pad.h'
--- pcbnew/class_pad.h	2013-02-13 01:01:22 +0000
+++ pcbnew/class_pad.h	2013-03-21 15:06:02 +0000
@@ -92,7 +92,7 @@
 };
 
 
-class D_PAD : public BOARD_CONNECTED_ITEM
+class DLL_PUBLIC D_PAD : public BOARD_CONNECTED_ITEM
 {
 public:
     static int  m_PadSketchModePenSize; ///< Pen size used to draw pads in sketch mode

=== modified file 'pcbnew/io_mgr.h'
--- pcbnew/io_mgr.h	2013-01-21 03:27:01 +0000
+++ pcbnew/io_mgr.h	2013-03-21 15:44:58 +0000
@@ -26,6 +26,7 @@
  */
 
 #include <richio.h>
+#include <common.h>
 #include <hashtables.h>
 
 class BOARD;
@@ -37,7 +38,7 @@
  * Class IO_MGR
  * is a factory which returns an instance of a PLUGIN.
  */
-class IO_MGR
+class DLL_PUBLIC IO_MGR
 {
 public:
 

=== modified file 'pcbnew/pcbnew.cpp'
--- pcbnew/pcbnew.cpp	2013-03-11 19:30:58 +0000
+++ pcbnew/pcbnew.cpp	2013-03-21 17:34:22 +0000
@@ -86,6 +86,12 @@
 
 IMPLEMENT_APP( EDA_APP )
 
+DLL_PUBLIC EDA_APP *CreatePcbnewApp()
+{
+    return new EDA_APP();
+}
+
+
 
 /* MacOSX: Needed for file association
  * http://wiki.wxwidgets.org/WxMac-specific_topics
@@ -137,11 +143,13 @@
             wxMessageBox( msg );
         }
 
+#if 0
         if( !wxGetApp().LockFile( fn.GetFullPath() ) )
         {
             DisplayError( NULL, _( "This file is already open." ) );
             return false;
         }
+#endif
     }
 
     if( m_Checker && m_Checker->IsAnotherRunning() )


Follow ups

References