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 (C) 2023 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, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
26
27#include <pad.h>
28#include <pcb_shape.h>
30
32#include <router/pns_solid.h>
33#include <router/pns_router.h>
34
35
37{
38public:
39 void SetHostTool( PCB_TOOL_BASE* aTool ) override
40 {
41 m_tool = aTool;
42 m_commit = nullptr;
43
45 }
46
47 void Commit() override
48 { //
49 m_changes.emplace_back();
50 }
51
53 {
54 m_changes.clear();
55 m_changes.emplace_back();
56 }
57
58 void AddItem( PNS::ITEM* aItem ) override
59 {
60 BOARD_ITEM* brdItem = createBoardItem( aItem );
61
62 if( brdItem )
63 {
64 aItem->SetParent( brdItem );
65 brdItem->ClearFlags();
66
67 m_changes.back().addedItems.emplace( brdItem );
68 }
69 }
70
71 void UpdateItem( PNS::ITEM* aItem ) override
72 { //
73 modifyBoardItem( aItem );
74 }
75
76 void RemoveItem( PNS::ITEM* aItem ) override
77 {
78 BOARD_ITEM* parent = aItem->Parent();
79
80 if( aItem->OfKind( PNS::ITEM::SOLID_T ) )
81 {
82 PAD* pad = static_cast<PAD*>( parent );
83 VECTOR2I pos = static_cast<PNS::SOLID*>( aItem )->Pos();
84
85 m_fpOffsets[pad].p_old = pos;
86 return;
87 }
88
89 if( parent )
90 {
91 m_changes.back().removedItems.emplace( parent );
92 }
93 }
94
95 std::vector<GENERATOR_PNS_CHANGES>& Changes() { return m_changes; };
96
97private:
98 std::vector<GENERATOR_PNS_CHANGES> m_changes;
99};
100
101
103{
104 static_cast<PNS_KICAD_IFACE_GENERATOR*>( GetInterface() )->ClearCommits();
105}
106
107
108const std::vector<GENERATOR_PNS_CHANGES>& GENERATOR_TOOL_PNS_PROXY::GetRouterChanges()
109{
110 return static_cast<PNS_KICAD_IFACE_GENERATOR*>( GetInterface() )->Changes();
111}
112
113
115 PNS::TOOL_BASE( aToolName )
116{
117}
118
119
121{
122}
123
124
126{
127 delete m_gridHelper;
128 delete m_router;
129 delete m_iface; // Delete after m_router because PNS::NODE dtor needs m_ruleResolver
130
131 if( aReason == RESET_REASON::SHUTDOWN )
132 {
133 m_iface = nullptr;
134 m_router = nullptr;
135 m_gridHelper = nullptr;
136 return;
137 }
138
140 m_iface->SetBoard( board() );
141 m_iface->SetView( getView() );
142 m_iface->SetHostTool( this );
143
144 m_router = new PNS::ROUTER;
148
150
151 PCBNEW_SETTINGS* settings = frame()->GetPcbNewSettings();
152
153 if( !settings->m_PnsSettings )
154 settings->m_PnsSettings = std::make_unique<PNS::ROUTING_SETTINGS>( settings, "tools.pns" );
155
156 m_router->LoadSettings( settings->m_PnsSettings.get() );
157
158 m_gridHelper = new PCB_GRID_HELPER( m_toolMgr, frame()->GetMagneticItemsSettings() );
159}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:79
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: eda_item.h:129
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:54
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:97
BOARD_ITEM * Parent() const
Definition: pns_item.h:189
void SetParent(BOARD_ITEM *aParent)
Definition: pns_item.h:188
bool OfKind(int aKindMask) const
Definition: pns_item.h:178
void ClearWorld()
Definition: pns_router.cpp:105
void UpdateSizes(const SIZES_SETTINGS &aSizes)
Applies stored settings.
Definition: pns_router.cpp:742
void LoadSettings(ROUTING_SETTINGS *aSettings)
Changes routing settings to ones passed in the parameter.
Definition: pns_router.h:211
void SetInterface(ROUTER_IFACE *aIface)
void SyncWorld()
Definition: pns_router.cpp:95
PNS_KICAD_IFACE * GetInterface() const
SIZES_SETTINGS m_savedSizes
Definition: pns_tool_base.h:70
PNS_KICAD_IFACE * m_iface
Definition: pns_tool_base.h:79
ROUTER * m_router
Definition: pns_tool_base.h:80
PCB_GRID_HELPER * m_gridHelper
Definition: pns_tool_base.h:78
void SetBoard(BOARD *aBoard)
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()
void SetView(KIGFX::VIEW *aView)
std::map< PAD *, OFFSET > m_fpOffsets
virtual void SetHostTool(PCB_TOOL_BASE *aTool)
std::unique_ptr< BOARD_COMMIT > m_commit
BOARD_CONNECTED_ITEM * createBoardItem(PNS::ITEM *aItem)
PCB_TOOL_BASE * m_tool
void modifyBoardItem(PNS::ITEM *aItem)
Base abstract interface for all kinds of tools.
Definition: tool_base.h:66
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:218
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:36
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:78
@ SHUTDOWN
Tool is being shut down.
Definition: tool_base.h:84
Push and Shove diff pair dimensions (gap) settings dialog.