You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

146 lines
3.8 KiB

12 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2012 NBEE Embedded Systems, Miguel Angel Ajo <miguelangel@nbee.es>
  5. * Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. /**
  25. * @file pcbnew_scripting_helpers.cpp
  26. * @brief Scripting helper functions for pcbnew functionality
  27. */
  28. #include <Python.h>
  29. #include <pcbnew_scripting_helpers.h>
  30. #include <pcbnew.h>
  31. #include <pcbnew_id.h>
  32. #include <build_version.h>
  33. #include <class_board.h>
  34. #include <class_drawpanel.h>
  35. #include <kicad_string.h>
  36. #include <io_mgr.h>
  37. #include <macros.h>
  38. #include <stdlib.h>
  39. #include <pcb_draw_panel_gal.h>
  40. #include <action_plugin.h>
  41. static PCB_EDIT_FRAME* s_PcbEditFrame = NULL;
  42. BOARD* GetBoard()
  43. {
  44. if( s_PcbEditFrame )
  45. return s_PcbEditFrame->GetBoard();
  46. else
  47. return NULL;
  48. }
  49. void ScriptingSetPcbEditFrame( PCB_EDIT_FRAME* aPcbEditFrame )
  50. {
  51. s_PcbEditFrame = aPcbEditFrame;
  52. }
  53. BOARD* LoadBoard( wxString& aFileName )
  54. {
  55. if( aFileName.EndsWith( wxT( ".kicad_pcb" ) ) )
  56. return LoadBoard( aFileName, IO_MGR::KICAD_SEXP );
  57. else if( aFileName.EndsWith( wxT( ".brd" ) ) )
  58. return LoadBoard( aFileName, IO_MGR::LEGACY );
  59. // as fall back for any other kind use the legacy format
  60. return LoadBoard( aFileName, IO_MGR::LEGACY );
  61. }
  62. BOARD* LoadBoard( wxString& aFileName, IO_MGR::PCB_FILE_T aFormat )
  63. {
  64. BOARD* brd = IO_MGR::Load( aFormat, aFileName );
  65. if( brd )
  66. brd->BuildConnectivity();
  67. return brd;
  68. }
  69. bool SaveBoard( wxString& aFileName, BOARD* aBoard, IO_MGR::PCB_FILE_T aFormat )
  70. {
  71. aBoard->BuildConnectivity();
  72. aBoard->SynchronizeNetsAndNetClasses();
  73. aBoard->GetDesignSettings().SetCurrentNetClass( NETCLASS::Default );
  74. IO_MGR::Save( aFormat, aFileName, aBoard, NULL );
  75. return true;
  76. }
  77. bool SaveBoard( wxString& aFileName, BOARD* aBoard )
  78. {
  79. return SaveBoard( aFileName, aBoard, IO_MGR::KICAD_SEXP );
  80. }
  81. void Refresh()
  82. {
  83. if( s_PcbEditFrame )
  84. {
  85. auto board = s_PcbEditFrame->GetBoard();
  86. board->BuildConnectivity();
  87. if( s_PcbEditFrame->IsGalCanvasActive() )
  88. {
  89. auto gal_canvas = static_cast<PCB_DRAW_PANEL_GAL*>( s_PcbEditFrame->GetGalCanvas() );
  90. // Reinit everything: this is the easy way to do that
  91. s_PcbEditFrame->UseGalCanvas( true );
  92. gal_canvas->Refresh();
  93. }
  94. else
  95. // first argument is erase background, second is a wxRect that
  96. // defines a reftresh area (all canvas if null)
  97. s_PcbEditFrame->GetCanvas()->Refresh( true, NULL );
  98. }
  99. }
  100. void WindowZoom( int xl, int yl, int width, int height )
  101. {
  102. EDA_RECT Rect( wxPoint( xl, yl ), wxSize( width, height ) );
  103. if( s_PcbEditFrame )
  104. s_PcbEditFrame->Window_Zoom( Rect );
  105. }
  106. void UpdateUserInterface()
  107. {
  108. if( s_PcbEditFrame )
  109. s_PcbEditFrame->UpdateUserInterface();
  110. }
  111. bool IsActionRunning()
  112. {
  113. return ACTION_PLUGINS::IsActionRunning();
  114. }