KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_issue25900_delete_base_symbol.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
24
26
28#include <sch_io/sch_io.h>
29#include <sch_io/sch_io_mgr.h>
30#include <sch_screen.h>
31#include <lib_symbol.h>
32#include <wx/filename.h>
33
34BOOST_AUTO_TEST_SUITE( DeleteBaseSymbol )
35
36
37// Deleting 74LS02 with its derived symbols removed the unrelated 74469 and left 74LS02 behind
38BOOST_AUTO_TEST_CASE( DeleteBaseRemovesBaseAndDerived )
39{
40 wxFileName fn( KI_TEST::GetEeschemaTestDataDir(), wxS( "issue25900_74xx.kicad_sym" ) );
41
42 IO_RELEASER<SCH_IO> plugin( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) );
43 std::vector<LIB_SYMBOL*> originals;
44 plugin->EnumerateSymbolLib( originals, fn.GetFullPath() );
45
46 // Fill the buffer the way SYMBOL_LIBRARY_MANAGER does
47 LIB_BUFFER buf( wxS( "74xx" ) );
48
49 for( LIB_SYMBOL* symbol : originals )
50 {
51 auto copy = std::make_unique<LIB_SYMBOL>( *symbol );
52
53 if( symbol->IsDerived() )
54 {
55 LIB_SYMBOL* parent = buf.GetSymbol( symbol->GetParent().lock()->GetName() );
56
57 if( !parent )
58 {
59 auto newParent = std::make_unique<LIB_SYMBOL>( *symbol->GetParent().lock() );
60 parent = newParent.get();
61 buf.CreateBuffer( std::move( newParent ), std::make_unique<SCH_SCREEN>() );
62 }
63
64 copy->SetParent( parent );
65 }
66 else if( buf.GetSymbol( symbol->GetName() ) )
67 {
68 continue;
69 }
70
71 buf.CreateBuffer( std::move( copy ), std::make_unique<SCH_SCREEN>() );
72 }
73
74 BOOST_REQUIRE_EQUAL( buf.GetBuffers().size(), 8 );
75
76 std::shared_ptr<SYMBOL_BUFFER> base = buf.GetBuffer( wxS( "74LS02" ) );
77 BOOST_REQUIRE( base );
78
79 BOOST_CHECK( buf.DeleteBuffer( *base ) );
80
81 BOOST_REQUIRE_EQUAL( buf.GetBuffers().size(), 3 );
82 BOOST_CHECK( buf.GetSymbol( wxS( "74469" ) ) );
83 BOOST_CHECK( buf.GetSymbol( wxS( "74LS00" ) ) );
84 BOOST_CHECK( buf.GetSymbol( wxS( "7400" ) ) );
85}
86
87
Store a working copy of a library.
bool CreateBuffer(std::unique_ptr< LIB_SYMBOL > aCopy, std::unique_ptr< SCH_SCREEN > aScreen, bool aNew=false)
Create a new buffer to store a symbol. LIB_BUFFER takes ownership of aCopy.
bool DeleteBuffer(const SYMBOL_BUFFER &aSymbolBuf)
Delete the given symbol buffer from the library buffer.
const std::deque< std::shared_ptr< SYMBOL_BUFFER > > & GetBuffers() const
Return all buffered symbols.
std::shared_ptr< SYMBOL_BUFFER > GetBuffer(const wxString &aAlias) const
Return a symbol buffer with LIB_SYMBOL holding a symbolic alias.
LIB_SYMBOL * GetSymbol(const wxString &aAlias) const
Return the working copy of a LIB_SYMBOL root object with specified alias.
Define a library symbol object.
Definition lib_symbol.h:114
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
Definition io_mgr.h:33
std::string GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()