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 m_createdItems.clear();
53 }
54
55 void AddItem( PNS::ITEM* aItem ) override
56 {
57 BOARD_ITEM* brdItem = createBoardItem( aItem );
58
59 if( brdItem )
60 {
61 aItem->SetParent( brdItem );
62 brdItem->ClearFlags();
63
64 m_createdItems.insert( brdItem );
65 m_changes.back().addedItems.emplace( brdItem );
66 }
67 }
68
69 void UpdateItem( PNS::ITEM* aItem ) override
70 { //
71 modifyBoardItem( aItem );
72 }
73
74 void RemoveItem( PNS::ITEM* aItem ) override
75 {
76 BOARD_ITEM* parent = aItem->Parent();
77
78 if( aItem->OfKind( PNS::ITEM::SOLID_T ) )
79 {
80 PAD* pad = static_cast<PAD*>( parent );
81 VECTOR2I pos = static_cast<PNS::SOLID*>( aItem )->Pos();
82
83 m_fpOffsets[pad].p_old = pos;
84 return;
85 }
86
87 if( parent )
88 {
89 m_changes.back().removedItems.emplace( parent );
90 }
91 }
92
93 std::vector<GENERATOR_PNS_CHANGES>& Changes() { return m_changes; };
94
95 bool IsGeneratedItem( BOARD_ITEM* aItem ) const { return m_createdItems.contains( aItem ); }
96
97private:
98 std::set<BOARD_ITEM*> m_createdItems;
99
100 std::vector<GENERATOR_PNS_CHANGES> m_changes;
101};
102
103
105{
106 static_cast<PNS_KICAD_IFACE_GENERATOR*>( GetInterface() )->ClearCommits();
107}
108
109
110const std::vector<GENERATOR_PNS_CHANGES>& GENERATOR_TOOL_PNS_PROXY::GetRouterChanges()
111{
112 return static_cast<PNS_KICAD_IFACE_GENERATOR*>( GetInterface() )->Changes();
113}
114
115
117{
118 return static_cast<PNS_KICAD_IFACE_GENERATOR*>( GetInterface() )->IsGeneratedItem( aItem );
119}
120
121
123 PNS::TOOL_BASE( aToolName )
124{
125}
126
127
131
132
134{
135 delete m_gridHelper;
136 delete m_router;
137 delete m_iface; // Delete after m_router because PNS::NODE dtor needs m_ruleResolver
138
139 if( aReason == RESET_REASON::SHUTDOWN )
140 {
141 m_iface = nullptr;
142 m_router = nullptr;
143 m_gridHelper = nullptr;
144 return;
145 }
146
148 m_iface->SetBoard( board() );
149 m_iface->SetView( getView() );
150 m_iface->SetHostTool( this );
151
152 m_router = new PNS::ROUTER;
153 m_router->SetInterface( m_iface );
154 m_router->ClearWorld();
155 m_router->SyncWorld();
156
157 m_router->UpdateSizes( m_savedSizes );
158
159 PCBNEW_SETTINGS* settings = frame()->GetPcbNewSettings();
160
161 if( !settings->m_PnsSettings )
162 settings->m_PnsSettings = std::make_unique<PNS::ROUTING_SETTINGS>( settings, "tools.pns" );
163
164 m_router->LoadSettings( settings->m_PnsSettings.get() );
165
166 m_gridHelper = new PCB_GRID_HELPER( m_toolMgr, frame()->GetMagneticItemsSettings() );
167}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:84
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition eda_item.h:160
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()
bool ItemCreatedBySession(BOARD_ITEM *aItem) const
Returns true if the given board item was created by the router interface during the current generator...
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
std::set< BOARD_ITEM * > m_createdItems
void AddItem(PNS::ITEM *aItem) override
void UpdateItem(PNS::ITEM *aItem) override
void RemoveItem(PNS::ITEM *aItem) override
bool IsGeneratedItem(BOARD_ITEM *aItem) const
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