/* * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2023 Alex Shvartzkop * Copyright (C) 2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, you may find one here: * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * or you may search the http://www.gnu.org website for the version 2 license, * or you may write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ #include "generator_tool_pns_proxy.h" #include #include #include #include #include #include class PNS_KICAD_IFACE_GENERATOR : public PNS_KICAD_IFACE { public: void Commit() override {} void SetHostTool( PCB_TOOL_BASE* aTool ) override { m_tool = aTool; m_commit = nullptr; m_addedItems.clear(); m_removedItems.clear(); } void AddItem( PNS::ITEM* aItem ) override { BOARD_ITEM* brdItem = createBoardItem( aItem ); m_addedItems.emplace( brdItem ); } void UpdateItem( PNS::ITEM* aItem ) override { // modifyBoardItem( aItem ); } void RemoveItem( PNS::ITEM* aItem ) override { BOARD_ITEM* parent = aItem->Parent(); if( aItem->OfKind( PNS::ITEM::SOLID_T ) ) { PAD* pad = static_cast( parent ); VECTOR2I pos = static_cast( aItem )->Pos(); m_fpOffsets[pad].p_old = pos; return; } if( parent ) { m_removedItems.emplace( parent ); } } std::set& AddedItems() { return m_addedItems; } std::set& RemovedItems() { return m_removedItems; } private: std::set m_addedItems; std::set m_removedItems; }; void GENERATOR_TOOL_PNS_PROXY::ClearRouterCommit() { static_cast( GetInterface() )->AddedItems().clear(); static_cast( GetInterface() )->RemovedItems().clear(); } const std::set& GENERATOR_TOOL_PNS_PROXY::GetRouterCommitAddedItems() { return static_cast( GetInterface() )->AddedItems(); } const std::set& GENERATOR_TOOL_PNS_PROXY::GetRouterCommitRemovedItems() { return static_cast( GetInterface() )->RemovedItems(); } GENERATOR_TOOL_PNS_PROXY::GENERATOR_TOOL_PNS_PROXY( const std::string& aToolName ) : PNS::TOOL_BASE( aToolName ) { } GENERATOR_TOOL_PNS_PROXY::~GENERATOR_TOOL_PNS_PROXY() { } void GENERATOR_TOOL_PNS_PROXY::Reset( RESET_REASON aReason ) { delete m_gridHelper; delete m_router; delete m_iface; // Delete after m_router because PNS::NODE dtor needs m_ruleResolver m_iface = new PNS_KICAD_IFACE_GENERATOR; m_iface->SetBoard( board() ); m_iface->SetView( getView() ); m_iface->SetHostTool( this ); m_router = new PNS::ROUTER; m_router->SetInterface( m_iface ); m_router->ClearWorld(); m_router->SyncWorld(); m_router->UpdateSizes( m_savedSizes ); PCBNEW_SETTINGS* settings = frame()->GetPcbNewSettings(); if( !settings->m_PnsSettings ) settings->m_PnsSettings = std::make_unique( settings, "tools.pns" ); m_router->LoadSettings( settings->m_PnsSettings.get() ); m_gridHelper = new PCB_GRID_HELPER( m_toolMgr, frame()->GetMagneticItemsSettings() ); }