KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_io_pcad.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 Alexander Lunev <[email protected]>
5 * Copyright (C) 2012-2023 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 <pcad/pcb_io_pcad.h>
31#include <pcad/pcad_pcb.h>
32#include <pcad/s_expr_loader.h>
33#include <io/io_utils.h>
34
35#include <board.h>
36#include <locale_io.h>
37
38#include <cerrno>
39#include <wx/string.h>
40#include <wx/filename.h>
41#include <wx/xml/xml.h>
42
43using namespace PCAD2KICAD;
44
45
46PCB_IO_PCAD::PCB_IO_PCAD() : PCB_IO( wxS( "P-Cad" ) )
47{
48}
49
50
52{
53}
54
55
56bool PCB_IO_PCAD::CanReadBoard( const wxString& aFileName ) const
57{
58 if( !PCB_IO::CanReadBoard( aFileName ) )
59 return false;
60
61 return IO_UTILS::fileStartsWithPrefix( aFileName, wxT( "ACCEL_ASCII" ), false );
62}
63
64
65BOARD* PCB_IO_PCAD::LoadBoard( const wxString& aFileName, BOARD* aAppendToMe,
66 const std::map<std::string, UTF8>* aProperties, PROJECT* aProject )
67{
68 wxXmlDocument xmlDoc;
69
70 m_props = aProperties;
71
72 m_board = aAppendToMe ? aAppendToMe : new BOARD();
73
74 // Give the filename to the board if it's new
75 if( !aAppendToMe )
76 m_board->SetFileName( aFileName );
77
78 PCAD_PCB pcb( m_board );
79
80 LOCALE_IO toggle; // toggles on, then off, the C locale.
81
82 LoadInputFile( aFileName, &xmlDoc );
83 pcb.ParseBoard( nullptr, &xmlDoc, wxT( "PCB" ) );
84 pcb.AddToBoard();
85
86 return m_board;
87}
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:290
void SetFileName(const wxString &aFileName)
Definition: board.h:325
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:49
void ParseBoard(wxStatusBar *aStatusBar, wxXmlDocument *aXmlDoc, const wxString &aActualConversion)
Definition: pcad_pcb.cpp:673
void AddToBoard(FOOTPRINT *aFootprint=nullptr) override
Definition: pcad_pcb.cpp:941
BOARD * LoadBoard(const wxString &aFileName, BOARD *aAppendToMe, const std::map< std::string, UTF8 > *aProperties=nullptr, PROJECT *aProject=nullptr) override
Load information from some input file format that this PCB_IO implementation knows about into either ...
Definition: pcb_io_pcad.cpp:65
bool CanReadBoard(const wxString &aFileName) const override
Checks if this PCB_IO can read the specified board file.
Definition: pcb_io_pcad.cpp:56
A base class that BOARD loading and saving plugins should derive from.
Definition: pcb_io.h:71
BOARD * m_board
The board BOARD being worked on, no ownership here.
Definition: pcb_io.h:342
virtual bool CanReadBoard(const wxString &aFileName) const
Checks if this PCB_IO can read the specified board file.
Definition: pcb_io.cpp:42
const std::map< std::string, UTF8 > * m_props
Properties passed via Save() or Load(), no ownership, may be NULL.
Definition: pcb_io.h:345
Container for project specific data.
Definition: project.h:64
bool fileStartsWithPrefix(const wxString &aFilePath, const wxString &aPrefix, bool aIgnoreWhitespace)
Check if a file starts with a defined string.
Definition: io_utils.cpp:34
void LoadInputFile(const wxString &aFileName, wxXmlDocument *aXmlDoc)