KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_board_loader.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 modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * 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
21
22#include <board.h>
23#include <board_loader.h>
25#include <pcb_reference_image.h>
26#include <pcb_track.h>
27#include <pcb_io/pcb_io_mgr.h>
29#include <project.h>
31#include <wx/filename.h>
32
33
35{
36 PROJECT* loadProject( const wxString& aBoardName )
37 {
38 wxFileName projectFile( wxString::FromUTF8( KI_TEST::GetPcbnewTestDataDir() )
39 + aBoardName + ".kicad_pro" );
40
41 m_settingsManager.LoadProject( projectFile.GetFullPath() );
42
43 PROJECT* project = m_settingsManager.GetProject( projectFile.GetFullPath() );
44
45 BOOST_REQUIRE_MESSAGE( project, "Could not load project" );
46 return project;
47 }
48
49 wxString boardPath( const wxString& aBoardName ) const
50 {
51 return wxString::FromUTF8( KI_TEST::GetPcbnewTestDataDir() ) + aBoardName + ".kicad_pcb";
52 }
53
55};
56
57
59{
60 PROJECT* project = loadProject( "reference_images_load_save" );
61
62 std::unique_ptr<BOARD> board =
63 BOARD_LOADER::Load( boardPath( "reference_images_load_save" ),
65 project );
66
67 BOOST_REQUIRE( board );
68 BOOST_CHECK_EQUAL( board->GetProject(), project );
69 BOOST_CHECK( board->GetDesignSettings().m_DRCEngine );
70 BOOST_CHECK( board->GetConnectivity() );
71 BOOST_CHECK_GT( board->Drawings().size(), 0 );
72}
73
74
76{
77 PROJECT* project = loadProject( "reference_images_load_save" );
78
80 options.initialize_after_load = false;
81
82 std::unique_ptr<BOARD> board =
83 BOARD_LOADER::Load( boardPath( "reference_images_load_save" ),
85 project,
86 options );
87
88 BOOST_REQUIRE( board );
89 BOOST_CHECK_NE( board->GetProject(), project );
90 BOOST_CHECK( board->GetDesignSettings().m_DRCEngine == nullptr );
91}
92
93
94BOOST_AUTO_TEST_CASE( CollinearTrackArcLoadsAsTrack )
95{
96 const std::string path = KI_TEST::GetPcbnewTestDataDir()
97 + "plugins/allegro/boards/VCU118_REV2-0/8851_HW-U1-VCU118_REV2-0_071417.kicad_pcb";
98
99 std::unique_ptr<BOARD> board = KI_TEST::ReadBoardFromFileOrStream( path );
100
101 BOOST_REQUIRE( board );
102
103 // Collinear (arc ...) record in the file
104 BOARD_ITEM* item = board->ResolveItem( KIID( "945ee847-b394-409c-b580-2568b3573ad8" ) );
105
106 BOOST_REQUIRE( item );
108
109 PCB_TRACK* track = static_cast<PCB_TRACK*>( item );
110
111 BOOST_CHECK_EQUAL( track->GetStart(),
112 VECTOR2I( pcbIUScale.mmToIU( 81.471125 ), pcbIUScale.mmToIU( -136.690775 ) ) );
113 BOOST_CHECK_EQUAL( track->GetEnd(),
114 VECTOR2I( pcbIUScale.mmToIU( 81.476825 ), pcbIUScale.mmToIU( -136.685025 ) ) );
115 BOOST_CHECK_EQUAL( track->GetWidth(), pcbIUScale.mmToIU( 0.15 ) );
116 BOOST_CHECK_EQUAL( track->GetLayer(), In2_Cu );
117 BOOST_CHECK_EQUAL( track->GetNetname(), wxString( "FMCP_HSPC_DP11_C2M_N" ) );
118}
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
General utilities for PCB file IO for QA programs.
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:85
static std::unique_ptr< BOARD > Load(const wxString &aFileName, PCB_IO_MGR::PCB_FILE_T aFormat, PROJECT *aProject, const OPTIONS &aOptions)
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
Definition kiid.h:46
@ KICAD_SEXP
S-expression Pcbnew file format.
Definition pcb_io_mgr.h:54
const VECTOR2I & GetStart() const
Definition pcb_track.h:98
const VECTOR2I & GetEnd() const
Definition pcb_track.h:95
virtual int GetWidth() const
Definition pcb_track.h:92
Container for project specific data.
Definition project.h:63
@ In2_Cu
Definition layer_ids.h:63
std::string GetPcbnewTestDataDir()
Utility which returns a path to the data directory where the test board files are stored.
std::unique_ptr< BOARD > ReadBoardFromFileOrStream(const std::string &aFilename, std::istream &aFallback)
Read a board from a file, or another stream, as appropriate.
PROJECT * loadProject(const wxString &aBoardName)
wxString boardPath(const wxString &aBoardName) const
BOOST_FIXTURE_TEST_CASE(BoardLoaderWithInit, BOARD_LOADER_TEST_FIXTURE)
BOOST_AUTO_TEST_CASE(CollinearTrackArcLoadsAsTrack)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
std::string path
BOOST_CHECK_EQUAL(result, "25.4")
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition typeinfo.h:88
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708