KiCad PCB EDA Suite
Loading...
Searching...
No Matches
generator_tool_pns_proxy.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) 2023 Alex Shvartzkop <[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, see <https://www.gnu.org/licenses/>.
19 */
20
22
23#include <pad.h>
24#include <pcb_shape.h>
26
28#include <router/pns_solid.h>
29#include <router/pns_router.h>
30
31
33{
34public:
35 void SetHostTool( PCB_TOOL_BASE* aTool ) override
36 {
37 m_tool = aTool;
38 m_commit = nullptr;
39
41 }
42
43 void Commit() override
44 { //
45 m_changes.emplace_back();
46 }
47
49 {
50 m_changes.clear();
51 m_changes.emplace_back();
52 }
53
54 void AddItem( PNS::ITEM* aItem ) override
55 {
56 BOARD_ITEM* brdItem = createBoardItem( aItem );
57
58 if( brdItem )
59 {
60 aItem->SetParent( brdItem );
61 brdItem->ClearFlags();
62
63 m_changes.back().addedItems.emplace( brdItem );
64 }
65 }
66
67 void UpdateItem( PNS::ITEM* aItem ) override
68 { //
69 modifyBoardItem( aItem );
70 }
71
72 void RemoveItem( PNS::ITEM* aItem ) override
73 {
74 BOARD_ITEM* parent = aItem->Parent();
75
76 if( aItem->OfKind( PNS::ITEM::SOLID_T ) )
77 {
78 PAD* pad = static_cast<PAD*>( parent );
79 VECTOR2I pos = static_cast<PNS::SOLID*>( aItem )->Pos();
80
81 m_fpOffsets[pad].p_old = pos;
82 return;
83 }
84
85 if( parent )
86 {
87 m_changes.back().removedItems.emplace( parent );
88 }
89 }
90
91 std::vector<GENERATOR_PNS_CHANGES>& Changes() { return m_changes; };
92
93private:
94 std::vector<GENERATOR_PNS_CHANGES> m_changes;
95};
96
97
99{
100 static_cast<PNS_KICAD_IFACE_GENERATOR*>( GetInterface() )->ClearCommits();
101}
102
103
104const std::vector<GENERATOR_PNS_CHANGES>& GENERATOR_TOOL_PNS_PROXY::GetRouterChanges()
105{
106 return static_cast<PNS_KICAD_IFACE_GENERATOR*>( GetInterface() )->Changes();
107}
108
109
111 PNS::TOOL_BASE( aToolName )
112{
113}
114
115
119
120
122{
123 delete m_gridHelper;
124 delete m_router;
125 delete m_iface; // Delete after m_router because PNS::NODE dtor needs m_ruleResolver
126
127 if( aReason == RESET_REASON::SHUTDOWN )
128 {
129 m_iface = nullptr;
130 m_router = nullptr;
131 m_gridHelper = nullptr;
132 return;
133 }
134
136 m_iface->SetBoard( board() );
137 m_iface->SetView( getView() );
138 m_iface->SetHostTool( this );
139
140 m_router = new PNS::ROUTER;
141 m_router->SetInterface( m_iface );
142 m_router->ClearWorld();
143 m_router->SyncWorld();
144
145 m_router->UpdateSizes( m_savedSizes );
146
147 PCBNEW_SETTINGS* settings = frame()->GetPcbNewSettings();
148
149 if( !settings->m_PnsSettings )
150 settings->m_PnsSettings = std::make_unique<PNS::ROUTING_SETTINGS>( settings, "tools.pns" );
151
152 m_router->LoadSettings( settings->m_PnsSettings.get() );
153
154 m_gridHelper = new PCB_GRID_HELPER( m_toolMgr, frame()->GetMagneticItemsSettings() );
155}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:81
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition eda_item.h:154
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
GENERATOR_TOOL_PNS_PROXY(const std::string &aToolName)
const std::vector< GENERATOR_PNS_CHANGES > & GetRouterChanges()
Definition pad.h:61
std::unique_ptr< PNS::ROUTING_SETTINGS > m_PnsSettings
T * frame() const
BOARD * board() const
Base class for PNS router board items.
Definition pns_item.h:98
BOARD_ITEM * Parent() const
Definition pns_item.h:199
void SetParent(BOARD_ITEM *aParent)
Definition pns_item.h:191
bool OfKind(int aKindMask) const
Definition pns_item.h:181
PNS_KICAD_IFACE * GetInterface() const
SIZES_SETTINGS m_savedSizes
PNS_KICAD_IFACE * m_iface
TOOL_BASE(const std::string &aToolName)
ROUTER * m_router
PCB_GRID_HELPER * m_gridHelper
std::vector< GENERATOR_PNS_CHANGES > m_changes
void SetHostTool(PCB_TOOL_BASE *aTool) override
void AddItem(PNS::ITEM *aItem) override
void UpdateItem(PNS::ITEM *aItem) override
void RemoveItem(PNS::ITEM *aItem) override
std::vector< GENERATOR_PNS_CHANGES > & Changes()
std::map< PAD *, OFFSET > m_fpOffsets
std::unique_ptr< BOARD_COMMIT > m_commit
BOARD_CONNECTED_ITEM * createBoardItem(PNS::ITEM *aItem)
PCB_TOOL_BASE * m_tool
void modifyBoardItem(PNS::ITEM *aItem)
TOOL_MANAGER * m_toolMgr
Definition tool_base.h:220
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition tool_base.cpp:34
RESET_REASON
Determine the reason of reset for a tool.
Definition tool_base.h:74
@ SHUTDOWN
Tool is being shut down.
Definition tool_base.h:80
Push and Shove diff pair dimensions (gap) settings dialog.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683