diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index bda556d348..e2d7f80496 100644 --- a/pcbnew/CMakeLists.txt +++ b/pcbnew/CMakeLists.txt @@ -1,6 +1,8 @@ add_definitions(-DPCBNEW) if (KICAD_SCRIPTING OR KICAD_SCRIPTING_MODULES) + + file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/scripting) FIND_PACKAGE(SWIG REQUIRED) INCLUDE(${SWIG_USE_FILE}) @@ -22,6 +24,7 @@ include_directories( ../polygon ../common/dialogs ./scripting + ../scripting ${INC_AFTER} ) @@ -230,9 +233,9 @@ set(PCBNEW_COMMON_SRCS if (KICAD_SCRIPTING) set(PCBNEW_SCRIPTING_PYTHON_HELPERS - scripting/wx_python_helpers.cpp + ../scripting/wx_python_helpers.cpp + ../scripting/python_scripting.cpp scripting/pcbnew_scripting_helpers.cpp - scripting/python_scripting.cpp ) set(PCBNEW_SCRIPTING_SRCS @@ -247,7 +250,7 @@ endif() if (KICAD_SCRIPTING OR KICAD_SCRIPTING_MODULES) - set(SWIG_FLAGS -I${CMAKE_CURRENT_SOURCE_DIR}/../.. -I${CMAKE_CURRENT_SOURCE_DIR} -I${CMAKE_CURRENT_SOURCE_DIR}/../include -DDEBUG) + set(SWIG_FLAGS -I${CMAKE_CURRENT_SOURCE_DIR}/../.. -I${CMAKE_CURRENT_SOURCE_DIR} -I${CMAKE_CURRENT_SOURCE_DIR}/../include -I${CMAKE_CURRENT_SOURCE_DIR}/../scripting -DDEBUG) # collect CFLAGS , and pass them to swig later diff --git a/pcbnew/pcbnew.cpp b/pcbnew/pcbnew.cpp index db36f29b9c..85e74642dc 100644 --- a/pcbnew/pcbnew.cpp +++ b/pcbnew/pcbnew.cpp @@ -48,8 +48,8 @@ #include #include -#include -#include +#include +#include // Colors for layers and items COLORS_DESIGN_SETTINGS g_ColorsSettings; diff --git a/pcbnew/scripting/kicad.i b/pcbnew/scripting/kicad.i deleted file mode 100644 index 77d9ab4731..0000000000 --- a/pcbnew/scripting/kicad.i +++ /dev/null @@ -1,51 +0,0 @@ -//%module kicad - -/* OFF NOW, it triggers an error with GCC 4.6 and swig-2.0.4 or trunk.. - http://sourceforge.net/tracker/index.php?func=detail&aid=3391906&group_id=1645&atid=101645 - - %include - %include -*/ -%nodefaultctor EDA_ITEM; - - -/* swig tries to wrap SetBack/SetNext on derived classes, but this method is - private for most childs, so if we don't ignore it it won't compile */ - -%ignore EDA_ITEM::SetBack; -%ignore EDA_ITEM::SetNext; - - -%ignore InitKiCadAbout; -%ignore GetCommandOptions; - -%{ - #include - #include - #include - #include - #include - #include - using namespace std; - #include - #include - -%} - -/* all the wx wrappers for wxString, wxPoint, wxRect, wxChar .. */ -%include - - -%include -%include -%include -%include -%include - - -/* -namespace std -{ - %template(intVector) vector; -} -*/ diff --git a/pcbnew/scripting/pcbnew.i b/pcbnew/scripting/pcbnew.i index 7ba2e627b4..bda640a789 100644 --- a/pcbnew/scripting/pcbnew.i +++ b/pcbnew/scripting/pcbnew.i @@ -1,3 +1,33 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2012 NBEE Embedded Systems, Miguel Angel Ajo + * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors. + * + * 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 pcbnew.i + * @brief Specific pcbnew wrappers + */ + + %module pcbnew %include "kicad.i" diff --git a/pcbnew/scripting/pcbnew_scripting_helpers.cpp b/pcbnew/scripting/pcbnew_scripting_helpers.cpp index ee2400903a..8315ff216d 100644 --- a/pcbnew/scripting/pcbnew_scripting_helpers.cpp +++ b/pcbnew/scripting/pcbnew_scripting_helpers.cpp @@ -1,3 +1,33 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2012 NBEE Embedded Systems, Miguel Angel Ajo + * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors. + * + * 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 pcbnew_scripting_helpers.cpp + * @brief Scripting helper functions for pcbnew functionality + */ + + #include #include #include diff --git a/pcbnew/scripting/tests/test1.py b/pcbnew/scripting/tests/test1.py index 6b50b24914..82d73dcd23 100644 --- a/pcbnew/scripting/tests/test1.py +++ b/pcbnew/scripting/tests/test1.py @@ -1,10 +1,10 @@ pcb = pcbnew.GetBoard() -m = pcb.m_Modules.item() +m = pcb.m_Modules while m: print m.GetPosition() - p = m.m_Pads.item() + p = m.m_Pads while p: print "p=>",p.GetPosition(),p.GetPadName() print p.GetPosition() diff --git a/pcbnew/scripting/tests/testLoadSave.py b/pcbnew/scripting/tests/testLoadSave.py new file mode 100644 index 0000000000..cabdacdef3 --- /dev/null +++ b/pcbnew/scripting/tests/testLoadSave.py @@ -0,0 +1,29 @@ +from pcbnew import * +import unittest + +class TestLoadSave(unittest.TestCase): + + def setUp(self): + self.TITLE="Test Board" + self.COMMENT1="For load/save test" + self.FILENAME="/tmp/test.brd" + + def test_00_save(self): + pcb = BOARD() + pcb.GetTitleBlock().SetTitle(self.TITLE) + pcb.GetTitleBlock().SetComment1(self.COMMENT1) + result = SaveBoard(self.FILENAME,pcb) + self.assertTrue(result) + + def test_01_load(self): + pcb2 = LoadBoard(self.FILENAME) + self.assertIsNotNone(pcb2) + + def test_02_titleblock_ok(self): + pcb2 = LoadBoard(self.FILENAME) + tb = pcb2.GetTitleBlock() + self.assertEqual(tb.GetTitle(),self.TITLE) + self.assertEqual(tb.GetComment1(),self.COMMENT1) + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/scripting/kicad.i b/scripting/kicad.i new file mode 100644 index 0000000000..5bd5dd11f7 --- /dev/null +++ b/scripting/kicad.i @@ -0,0 +1,79 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2012 NBEE Embedded Systems, Miguel Angel Ajo + * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors. + * + * 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.i + * @brief General wrappers for kicad / wx structures and classes + */ + + +/* OFF NOW, it triggers an error with GCC 4.6 and swig-2.0.4 or trunk.. + http://sourceforge.net/tracker/index.php?func=detail&aid=3391906&group_id=1645&atid=101645 + + %include + %include +*/ +%nodefaultctor EDA_ITEM; + + +/* swig tries to wrap SetBack/SetNext on derived classes, but this method is + private for most childs, so if we don't ignore it it won't compile */ + +%ignore EDA_ITEM::SetBack; +%ignore EDA_ITEM::SetNext; + + +%ignore InitKiCadAbout; +%ignore GetCommandOptions; + +%{ + #include + #include + #include + #include + #include + #include + using namespace std; + #include + #include + +%} + +/* all the wx wrappers for wxString, wxPoint, wxRect, wxChar .. */ +%include + + +%include +%include +%include +%include +%include + + +/* +namespace std +{ + %template(intVector) vector; +} +*/ diff --git a/pcbnew/scripting/python_scripting.cpp b/scripting/python_scripting.cpp similarity index 60% rename from pcbnew/scripting/python_scripting.cpp rename to scripting/python_scripting.cpp index 1a5bf7bc21..d8f07e67b3 100644 --- a/pcbnew/scripting/python_scripting.cpp +++ b/scripting/python_scripting.cpp @@ -1,3 +1,31 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2012 NBEE Embedded Systems, Miguel Angel Ajo + * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors. + * + * 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 python_scripting.cpp + * @brief methods to add scripting capabilities inside pcbnew + */ #include diff --git a/pcbnew/scripting/python_scripting.h b/scripting/python_scripting.h similarity index 100% rename from pcbnew/scripting/python_scripting.h rename to scripting/python_scripting.h diff --git a/pcbnew/scripting/wx.i b/scripting/wx.i similarity index 70% rename from pcbnew/scripting/wx.i rename to scripting/wx.i index 61f6c8ce38..2c5cfae95c 100644 --- a/pcbnew/scripting/wx.i +++ b/scripting/wx.i @@ -1,3 +1,31 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2012 Miguel Angel Ajo + * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors. + * + * 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 wx.i + * @brief wx wrappers for basic things, wxString, wxPoint, wxRect, etc.. + */ %{ #include diff --git a/pcbnew/scripting/wx_python_helpers.cpp b/scripting/wx_python_helpers.cpp similarity index 68% rename from pcbnew/scripting/wx_python_helpers.cpp rename to scripting/wx_python_helpers.cpp index aee5885019..a3c4848f93 100644 --- a/pcbnew/scripting/wx_python_helpers.cpp +++ b/scripting/wx_python_helpers.cpp @@ -1,3 +1,32 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2012 Miguel Angel Ajo + * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors. + * + * 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 wx_python_helpers.cpp + * @brief Python wrapping helpers for wx structures/objects + */ + #include #include #include diff --git a/pcbnew/scripting/wx_python_helpers.h b/scripting/wx_python_helpers.h similarity index 100% rename from pcbnew/scripting/wx_python_helpers.h rename to scripting/wx_python_helpers.h