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 The 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, see <https://www.gnu.org/licenses/>.
19 */
20
25
26#include <pcad/pcb_io_pcad.h>
27#include <pcad/pcad_pcb.h>
28#include <pcad/s_expr_loader.h>
29#include <io/io_utils.h>
30
31#include <board.h>
32
33#include <cerrno>
34#include <wx/string.h>
35#include <wx/filename.h>
36#include <wx/xml/xml.h>
37
38using namespace PCAD2KICAD;
39
40
41PCB_IO_PCAD::PCB_IO_PCAD() : PCB_IO( wxS( "P-Cad" ) )
42{
43}
44
45
49
50
51bool PCB_IO_PCAD::CanReadBoard( const wxString& aFileName ) const
52{
53 if( !PCB_IO::CanReadBoard( aFileName ) )
54 return false;
55
56 return IO_UTILS::fileStartsWithPrefix( aFileName, wxT( "ACCEL_ASCII" ), false );
57}
58
59
60BOARD* PCB_IO_PCAD::LoadBoard( const wxString& aFileName, BOARD* aAppendToMe,
61 const std::map<std::string, UTF8>* aProperties, PROJECT* aProject )
62{
63 wxXmlDocument xmlDoc;
64
65 m_props = aProperties;
66
67 m_board = aAppendToMe ? aAppendToMe : new BOARD();
68
69 // Give the filename to the board if it's new
70 if( !aAppendToMe )
71 m_board->SetFileName( aFileName );
72
73 PCAD_PCB pcb( m_board );
74
75 LoadInputFile( aFileName, &xmlDoc );
76 pcb.ParseBoard( nullptr, &xmlDoc, wxT( "PCB" ) );
77 pcb.AddToBoard();
78
79 return m_board;
80}
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:372
void ParseBoard(wxStatusBar *aStatusBar, wxXmlDocument *aXmlDoc, const wxString &aActualConversion)
Definition pcad_pcb.cpp:893
void AddToBoard(FOOTPRINT *aFootprint=nullptr) override
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 ...
bool CanReadBoard(const wxString &aFileName) const override
Checks if this PCB_IO can read the specified board file.
BOARD * m_board
The board BOARD being worked on, no ownership here.
Definition pcb_io.h:349
virtual bool CanReadBoard(const wxString &aFileName) const
Checks if this PCB_IO can read the specified board file.
Definition pcb_io.cpp:38
PCB_IO(const wxString &aName)
Definition pcb_io.h:342
const std::map< std::string, UTF8 > * m_props
Properties passed via Save() or Load(), no ownership, may be NULL.
Definition pcb_io.h:352
Container for project specific data.
Definition project.h:62
bool fileStartsWithPrefix(const wxString &aFilePath, const wxString &aPrefix, bool aIgnoreWhitespace)
Check if a file starts with a defined string.
Definition io_utils.cpp:32
void LoadInputFile(const wxString &aFileName, wxXmlDocument *aXmlDoc)