KiCad PCB EDA Suite
pcbnew_scripting_helpers.cpp
Go to the documentation of this file.
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 
30 #include <Python.h>
31 
33 #include <pcbnew.h>
34 #include <pcbnew_id.h>
35 #include <build_version.h>
36 #include <class_board.h>
37 #include <class_drawpanel.h>
38 #include <kicad_string.h>
39 #include <io_mgr.h>
40 #include <macros.h>
41 #include <stdlib.h>
42 
44 
46 {
47  if( PcbEditFrame )
48  return PcbEditFrame->GetBoard();
49  else
50  return NULL;
51 }
52 
53 
55 {
56  PcbEditFrame = aPCBEdaFrame;
57 }
58 
59 
60 BOARD* LoadBoard( wxString& aFileName )
61 {
62  if( aFileName.EndsWith( wxT( ".kicad_pcb" ) ) )
63  return LoadBoard( aFileName, IO_MGR::KICAD );
64 
65  else if( aFileName.EndsWith( wxT( ".brd" ) ) )
66  return LoadBoard( aFileName, IO_MGR::LEGACY );
67 
68  // as fall back for any other kind use the legacy format
69  return LoadBoard( aFileName, IO_MGR::LEGACY );
70 }
71 
72 
73 BOARD* LoadBoard( wxString& aFileName, IO_MGR::PCB_FILE_T aFormat )
74 {
75  return IO_MGR::Load( aFormat, aFileName );
76 }
77 
78 
79 bool SaveBoard( wxString& aFilename, BOARD* aBoard )
80 {
81  return SaveBoard( aFilename, aBoard, IO_MGR::KICAD );
82 }
83 
84 
85 bool SaveBoard( wxString& aFileName, BOARD* aBoard,
86  IO_MGR::PCB_FILE_T aFormat )
87 {
88  aBoard->m_Status_Pcb &= ~CONNEXION_OK;
91 
92 #if 0
93  wxString header;
94  PROPERTIES props;
95 
96  if( aFormat == IO_MGR::LEGACY )
97  {
98  header = wxString::Format(
99  wxT( "PCBNEW-BOARD Version %d date %s\n\n# Created by Pcbnew%s scripting\n\n" ),
100  LEGACY_BOARD_FILE_VERSION, DateAndTime().GetData(),
101  GetBuildVersion().GetData() );
102  props["header"] = header;
103  }
104 
105  IO_MGR::Save( aFormat, aFileName, aBoard, &props );
106 #else
107  IO_MGR::Save( aFormat, aFileName, aBoard, NULL );
108 #endif
109  return true;
110 }
111 
112 
113 void Refresh()
114 {
115  // first argument is erase background, second is a wxRect
116  PcbEditFrame->GetCanvas()->Refresh( true, NULL );
117 }
118 
119 
120 void WindowZoom( int xl, int yl, int width, int height )
121 {
122  EDA_RECT Rect( wxPoint( xl, yl ), wxSize( width, height )) ;
123  PcbEditFrame->Window_Zoom( Rect );
124 }
BOARD * LoadBoard(wxString &aFileName)
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL) override
Definition: draw_panel.cpp:326
void ScriptingSetPcbEditFrame(PCB_EDIT_FRAME *aPCBEdaFrame)
EDA_DRAW_PANEL * GetCanvas()
Definition: draw_frame.h:299
Class BOARD to handle a board.
BOARD * GetBoard() const
Class PROPERTIES is a name/value tuple with unique names and optional values.
Definition: properties.h:34
This file contains miscellaneous commonly used macros and functions.
static PCB_EDIT_FRAME * PcbEditFrame
void SynchronizeNetsAndNetClasses()
Function SynchronizeNetsAndNetClasses copies NETCLASS info to each NET, based on NET membership in a ...
void Refresh()
wxString GetBuildVersion()
Function GetBuildVersion Return the build version string.
static const char Default[]
the name of the default NETCLASS
S-expression Pcbnew file format.
Definition: io_mgr.h:54
static BOARD * Load(PCB_FILE_T aFileType, const wxString &aFileName, BOARD *aAppendToMe=NULL, const PROPERTIES *aProperties=NULL)
Function Load finds the requested PLUGIN and if found, calls the PLUGIN->Load(..) funtion on it using...
Definition: io_mgr.cpp:229
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:530
bool SaveBoard(wxString &aFilename, BOARD *aBoard)
BOARD * GetBoard()
static void Save(PCB_FILE_T aFileType, const wxString &aFileName, BOARD *aBoard, const PROPERTIES *aProperties=NULL)
Function Save will write either a full aBoard to a storage file in a format that this implementation ...
Definition: io_mgr.cpp:244
bool SetCurrentNetClass(const wxString &aNetClassName)
Function SetCurrentNetClass Must be called after a netclass selection (or after a netclass parameter ...
Legacy Pcbnew file formats prior to s-expression.
Definition: io_mgr.h:53
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:166
Class EDA_RECT handles the component boundary box.
void Window_Zoom(EDA_RECT &Rect)
Compute the zoom factor and the new draw offset to draw the selected area (Rect) in full window scree...
Definition: zoom.cpp:103
void WindowZoom(int xl, int yl, int width, int height)
PCB_FILE_T
Enum PCB_FILE_T is a set of file types that the IO_MGR knows about, and for which there has been a pl...
Definition: io_mgr.h:51
wxString DateAndTime()
Function DateAndTime.
Definition: string.cpp:229
int m_Status_Pcb
Flags used in ratsnest calculation and update.
Definition: class_board.h:240