KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_io_target3001.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
22
23#include <board.h>
24#include <footprint.h>
26#include <progress_reporter.h>
27
28
29PCB_IO_TARGET3001::PCB_IO_TARGET3001() : PCB_IO( wxS( "TARGET 3001!" ) )
30{
31}
32
33
34bool PCB_IO_TARGET3001::CanReadBoard( const wxString& aFileName ) const
35{
36 if( !PCB_IO::CanReadBoard( aFileName ) )
37 return false;
38
39 return TARGET3001::LooksLikeProject( aFileName );
40}
41
42
43void PCB_IO_TARGET3001::loadBoard( const wxString& aFileName, BOARD& aBoard, bool aIsNewLoad,
44 const std::map<std::string, UTF8>* aProperties, PROJECT* aProject )
45{
46 // The import sets up the board's stack and origin, which would disturb a board it is appended to
47 if( !aIsNewLoad )
48 THROW_IO_ERROR( _( "TARGET 3001! boards cannot be appended to an existing board." ) );
49
50 m_props = aProperties;
51 m_board = &aBoard;
53 m_libraryFootprints.clear();
54
56 {
57 m_progressReporter->Report( wxString::Format( _( "Loading %s..." ), aFileName ) );
58
59 if( !m_progressReporter->KeepRefreshing() )
61 }
62
64
66 builder.Build();
67
69
70 // One unrotated, front-side copy of each package seeds the project footprint library
71 for( FOOTPRINT* fp : m_board->Footprints() )
72 {
73 wxString name = fp->GetFPID().GetUniStringLibItemName();
74
75 if( m_libraryFootprints.count( name ) )
76 continue;
77
78 std::unique_ptr<FOOTPRINT> def( static_cast<FOOTPRINT*>( fp->Duplicate( false ) ) );
79 def->SetParent( nullptr );
80
81 if( def->IsFlipped() )
82 def->Flip( def->GetPosition(), FLIP_DIRECTION::LEFT_RIGHT );
83
84 def->SetOrientation( ANGLE_0 );
85 def->SetPosition( VECTOR2I( 0, 0 ) );
86 m_libraryFootprints.emplace( name, std::move( def ) );
87 }
88}
89
90
92{
93 std::vector<FOOTPRINT*> result;
94
95 for( const auto& [name, fp] : m_libraryFootprints )
96 result.push_back( static_cast<FOOTPRINT*>( fp->Clone() ) );
97
98 return result;
99}
const char * name
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
REPORTER * m_reporter
Reporter to log errors/warnings to, may be nullptr.
Definition io_base.h:242
PROGRESS_REPORTER * m_progressReporter
Progress reporter to track the progress of the operation, may be nullptr.
Definition io_base.h:245
bool CanReadBoard(const wxString &aFileName) const override
std::vector< FOOTPRINT * > GetImportedCachedLibraryFootprints() override
Return a container with the cached library footprints generated in the last call to Load.
std::map< wxString, std::unique_ptr< FOOTPRINT > > m_libraryFootprints
by package name
void loadBoard(const wxString &aFileName, BOARD &aBoard, bool aIsNewLoad, const std::map< std::string, UTF8 > *aProperties=nullptr, PROJECT *aProject=nullptr) override
Parse aFileName into aBoard.
BOARD * m_board
The board BOARD being worked on, no ownership here.
Definition pcb_io.h:404
virtual bool CanReadBoard(const wxString &aFileName) const
Definition pcb_io.cpp:40
PCB_IO(const wxString &aName)
Definition pcb_io.h:383
const std::map< std::string, UTF8 > * m_props
Properties passed via Save() or Load(), no ownership, may be NULL.
Definition pcb_io.h:407
Container for project specific data.
Definition project.h:63
Builds a KiCad board from a parsed TARGET 3001!
const wxString & DesignRules() const
Custom rules that carry what KiCad cannot store on the items themselves, empty when none apply.
#define _(s)
static constexpr EDA_ANGLE ANGLE_0
Definition eda_angle.h:448
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
#define THROW_IO_CANCELLED()
@ LEFT_RIGHT
Flip left to right (around the Y axis)
Definition mirror.h:24
PROJECT ParseFile(const wxString &aFileName)
Parse a complete .T3001 file.
bool LooksLikeProject(const wxString &aFileName)
Cheap check used by the plugin managers: the extension matches and the header is plausible.
wxString result
Test unit parsing edge cases and error handling.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708