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, 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
37#include <cerrno>
38#include <wx/string.h>
39#include <wx/filename.h>
40#include <wx/xml/xml.h>
41
42using namespace PCAD2KICAD;
43
44
45PCB_IO_PCAD::PCB_IO_PCAD() : PCB_IO( wxS( "P-Cad" ) )
46{
47}
48
49
51{
52}
53
54
55bool PCB_IO_PCAD::CanReadBoard( const wxString& aFileName ) const
56{
57 if( !PCB_IO::CanReadBoard( aFileName ) )
58 return false;
59
60 return IO_UTILS::fileStartsWithPrefix( aFileName, wxT( "ACCEL_ASCII" ), false );
61}
62
63
64BOARD* PCB_IO_PCAD::LoadBoard( const wxString& aFileName, BOARD* aAppendToMe,
65 const std::map<std::string, UTF8>* aProperties, PROJECT* aProject )
66{
67 wxXmlDocument xmlDoc;
68
69 m_props = aProperties;
70
71 m_board = aAppendToMe ? aAppendToMe : new BOARD();
72
73 // Give the filename to the board if it's new
74 if( !aAppendToMe )
75 m_board->SetFileName( aFileName );
76
77 PCAD_PCB pcb( m_board );
78
79 LoadInputFile( aFileName, &xmlDoc );
80 pcb.ParseBoard( nullptr, &xmlDoc, wxT( "PCB" ) );
81 pcb.AddToBoard();
82
83 return m_board;
84}
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:317
void SetFileName(const wxString &aFileName)
Definition: board.h:352
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:64
bool CanReadBoard(const wxString &aFileName) const override
Checks if this PCB_IO can read the specified board file.
Definition: pcb_io_pcad.cpp:55
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:324
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:327
Container for project specific data.
Definition: project.h:65
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)