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#include <pcbnew_settings.h>
33
34
36{
37public:
38 void SetHostTool( PCB_TOOL_BASE* aTool ) override
39 {
40 m_tool = aTool;
41 m_commit = nullptr;
42
44 }
45
46 void Commit() override
47 { //
48 m_changes.emplace_back();
49 }
50
52 {
53 m_changes.clear();
54 m_changes.emplace_back();
55 m_createdItems.clear();
56 }
57
58 // The base implementations build ROUTER_PREVIEW_ITEMs and touch the GAL view, which do
59 // not exist in headless sessions; skip display entirely there.
60 void DisplayItem( const PNS::ITEM* aItem, int aClearance, bool aEdit = false,
61 int aFlags = 0 ) override
62 {
63 if( !m_view )
64 return;
65
66 PNS_KICAD_IFACE::DisplayItem( aItem, aClearance, aEdit, aFlags );
67 }
68
69 void EraseView() override
70 {
71 if( !m_view )
72 return;
73
75 }
76
77 void HideItem( PNS::ITEM* aItem ) override
78 {
79 if( !m_view )
80 return;
81
83 }
84
85 void DisplayPathLine( const SHAPE_LINE_CHAIN& aLine, int aImportance ) override
86 {
87 if( !m_view )
88 return;
89
90 PNS_KICAD_IFACE::DisplayPathLine( aLine, aImportance );
91 }
92
93 void DisplayRatline( const SHAPE_LINE_CHAIN& aRatline, PNS::NET_HANDLE aNet ) override
94 {
95 if( !m_view )
96 return;
97
98 PNS_KICAD_IFACE::DisplayRatline( aRatline, aNet );
99 }
100
101 void AddItem( PNS::ITEM* aItem ) override
102 {
103 BOARD_ITEM* brdItem = createBoardItem( aItem );
104
105 if( brdItem )
106 {
107 aItem->SetParent( brdItem );
108 brdItem->ClearFlags();
109
110 m_createdItems.insert( brdItem );
111 m_changes.back().addedItems.emplace( brdItem );
112 }
113 }
114
115 void UpdateItem( PNS::ITEM* aItem ) override
116 {
117 wxCHECK_RET( m_generatorCommit, wxS( "Cannot update a generator route without a commit" ) );
119 }
120
121 void SetGeneratorCommit( BOARD_COMMIT* aCommit ) { m_generatorCommit = aCommit; }
122
123 void RemoveItem( PNS::ITEM* aItem ) override
124 {
125 BOARD_ITEM* parent = aItem->Parent();
126
127 if( aItem->OfKind( PNS::ITEM::SOLID_T ) )
128 {
129 PAD* pad = static_cast<PAD*>( parent );
130 VECTOR2I pos = static_cast<PNS::SOLID*>( aItem )->Pos();
131
132 m_fpOffsets[pad].p_old = pos;
133 return;
134 }
135
136 if( parent )
137 {
138 m_changes.back().removedItems.emplace( parent );
139 }
140 }
141
142 std::vector<GENERATOR_PNS_CHANGES>& Changes() { return m_changes; };
143
144 bool IsGeneratedItem( BOARD_ITEM* aItem ) const { return m_createdItems.contains( aItem ); }
145
146private:
148 std::set<BOARD_ITEM*> m_createdItems;
149
150 std::vector<GENERATOR_PNS_CHANGES> m_changes;
151};
152
153
155{
156 static_cast<PNS_KICAD_IFACE_GENERATOR*>( GetInterface() )->ClearCommits();
157}
158
159
160const std::vector<GENERATOR_PNS_CHANGES>& GENERATOR_TOOL_PNS_PROXY::GetRouterChanges()
161{
162 return static_cast<PNS_KICAD_IFACE_GENERATOR*>( GetInterface() )->Changes();
163}
164
165
167{
168 static_cast<PNS_KICAD_IFACE_GENERATOR*>( GetInterface() )->SetGeneratorCommit( aCommit );
169}
170
171
173{
174 return static_cast<PNS_KICAD_IFACE_GENERATOR*>( GetInterface() )->IsGeneratedItem( aItem );
175}
176
177
179 PNS::TOOL_BASE( aToolName )
180{
181}
182
183
187
188
190{
191 delete m_gridHelper;
192 delete m_router;
193 delete m_iface; // Delete after m_router because PNS::NODE dtor needs m_ruleResolver
194
195 if( aReason == RESET_REASON::SHUTDOWN )
196 {
197 m_iface = nullptr;
198 m_router = nullptr;
199 m_gridHelper = nullptr;
200 return;
201 }
202
204 m_iface->SetBoard( board() );
205 m_iface->SetView( getView() );
206 m_iface->SetHostTool( this );
207
208 m_router = new PNS::ROUTER;
209 m_router->SetInterface( m_iface );
210 m_router->ClearWorld();
211 m_router->SyncWorld();
212
213 m_router->UpdateSizes( m_savedSizes );
214
215 // Headless sessions (kicad-cli api-server) have no frame; fall back to the global
216 // settings store and default magnetic settings.
217 PCBNEW_SETTINGS* settings = GetAppSettings<PCBNEW_SETTINGS>( "pcbnew" );
218
219 if( !settings->m_PnsSettings )
220 settings->m_PnsSettings = std::make_unique<PNS::ROUTING_SETTINGS>( settings, "tools.pns" );
221
222 m_router->LoadSettings( settings->m_PnsSettings.get() );
223
224 // Only build the grid helper in GUI mode where a view exists
225 if( getView() )
226 {
227 static MAGNETIC_SETTINGS defaultMagnetic;
228 m_gridHelper = new PCB_GRID_HELPER( m_toolMgr, &defaultMagnetic );
229 }
230}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:85
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...
void SetRouterCommit(BOARD_COMMIT *aCommit)
Use the generator's commit for changes made to existing board items by PNS.
Definition pad.h:61
std::unique_ptr< PNS::ROUTING_SETTINGS > m_PnsSettings
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 SetGeneratorCommit(BOARD_COMMIT *aCommit)
void SetHostTool(PCB_TOOL_BASE *aTool) override
std::set< BOARD_ITEM * > m_createdItems
void DisplayPathLine(const SHAPE_LINE_CHAIN &aLine, int aImportance) override
void AddItem(PNS::ITEM *aItem) override
void DisplayItem(const PNS::ITEM *aItem, int aClearance, bool aEdit=false, int aFlags=0) override
void UpdateItem(PNS::ITEM *aItem) override
void HideItem(PNS::ITEM *aItem) override
void RemoveItem(PNS::ITEM *aItem) override
bool IsGeneratedItem(BOARD_ITEM *aItem) const
std::vector< GENERATOR_PNS_CHANGES > & Changes()
void DisplayRatline(const SHAPE_LINE_CHAIN &aRatline, PNS::NET_HANDLE aNet) override
std::map< PAD *, OFFSET > m_fpOffsets
void DisplayItem(const PNS::ITEM *aItem, int aClearance, bool aEdit=false, int aFlags=0) override
std::unique_ptr< BOARD_COMMIT > m_commit
void modifyBoardItem(PNS::ITEM *aItem, BOARD_COMMIT &aCommit)
void EraseView() override
void HideItem(PNS::ITEM *aItem) override
BOARD_CONNECTED_ITEM * createBoardItem(PNS::ITEM *aItem)
KIGFX::VIEW * m_view
void DisplayPathLine(const SHAPE_LINE_CHAIN &aLine, int aImportance) override
PCB_TOOL_BASE * m_tool
void DisplayRatline(const SHAPE_LINE_CHAIN &aRatline, PNS::NET_HANDLE aNet) override
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
TOOL_MANAGER * m_toolMgr
Definition tool_base.h:220
KIGFX::VIEW * getView() const
Return the instance of KIGFX::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.
void * NET_HANDLE
Definition pns_item.h:55
T * GetAppSettings(const char *aFilename)
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708