KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_update_pcb.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#include <pcb_edit_frame.h>
21#include <pcbnew_settings.h>
22#include <dialog_update_pcb.h>
27#include <pcb_group.h>
28#include <tool/tool_manager.h>
29#include <tools/pcb_actions.h>
31#include <view/view_controls.h>
32#include <kiface_base.h>
33#include <kiplatform/ui.h>
34
35
37 DIALOG_UPDATE_PCB_BASE( aParent ),
38 m_frame( aParent ),
39 m_netlist( aNetlist ),
40 m_initialized( false )
41{
42 m_messagePanel->SetLabel( _("Changes to Be Applied") );
43 m_messagePanel->SetFileName( Prj().GetProjectPath() + wxT( "report.txt" ) );
44 m_messagePanel->SetLazyUpdate( true );
45 m_netlist->SortByReference();
46
47 m_messagePanel->GetSizer()->SetSizeHints( this );
48 m_messagePanel->Layout();
49
50 SetupStandardButtons( { { wxID_OK, _( "Update PCB" ) },
51 { wxID_CANCEL, _( "Close" ) } } );
52
54
56
57 m_initialized = true;
58}
59
60
62{
64 {
65 PCB_SELECTION_TOOL* selTool = m_frame->GetToolManager()->GetTool<PCB_SELECTION_TOOL>();
66 PCB_SELECTION& selection = selTool->GetSelection();
67
68 // Set the reference point to (0,0) where the new footprints were spread. This ensures
69 // the move tool knows where the items are located, preventing an offset when the "warp
70 // cursor to origin of moved object" preference is disabled.
71 if( selection.Size() > 0 )
72 selection.SetReferencePoint( VECTOR2I( 0, 0 ) );
73
74 KIGFX::VIEW_CONTROLS* controls = m_frame->GetCanvas()->GetViewControls();
75 controls->SetCursorPosition( controls->GetMousePosition() );
76 m_frame->GetToolManager()->RunAction( PCB_ACTIONS::move );
77 }
78}
79
80
82{
83 m_messagePanel->Clear();
84
85 REPORTER& reporter = m_messagePanel->Reporter();
86
87 m_runDragCommand = false;
88
89 m_netlist->SetFindByTimeStamp( !m_cbRelinkFootprints->GetValue() );
90 m_netlist->SetReplaceFootprints( m_cbUpdateFootprints->GetValue() );
91
92 if( !aDryRun )
93 {
94 m_frame->GetToolManager()->DeactivateTool();
95 m_frame->GetToolManager()->RunAction( ACTIONS::selectionClear );
96 }
97
98 BOARD_NETLIST_UPDATER updater( m_frame, m_frame->GetBoard() );
99 updater.SetReporter ( &reporter );
100 updater.SetIsDryRun( aDryRun );
101 updater.SetWillDrag( !aDryRun );
102 updater.SetLookupByTimestamp( !m_cbRelinkFootprints->GetValue() );
104 updater.SetReplaceFootprints( m_cbUpdateFootprints->GetValue() );
105 updater.SetTransferGroups( m_cbTransferGroups->GetValue() );
107 updater.SetOverrideLocks( m_cbOverrideLocks->GetValue() );
108 updater.SetUpdateFields( m_cbUpdateFields->GetValue() );
109 updater.SetRemoveExtraFields( m_cbRemoveExtraFields->GetValue() );
110 updater.UpdateNetlist( *m_netlist );
111
112 m_messagePanel->Flush( true );
113
114 if( aDryRun )
115 return;
116
117 m_frame->OnNetlistChanged( updater, &m_runDragCommand );
118
119 if( m_cbApplyDesignBlockLayouts->GetValue() )
120 {
121 TOOL_MANAGER* toolMgr = m_frame->GetToolManager();
122 PCB_SELECTION_TOOL* selTool = toolMgr->GetTool<PCB_SELECTION_TOOL>();
123
124 for( PCB_GROUP* group : updater.GetAddedGroups() )
125 {
126 if( !group->HasDesignBlockLink() )
127 continue;
128
130 selTool->select( group );
132 }
133
135 m_runDragCommand = false;
136 }
137}
138
139
141{
142 m_cbApplyDesignBlockLayouts->Enable( m_cbTransferGroups->GetValue() );
143
144 PerformUpdate( true );
145
146 return true;
147}
148
149
150void DIALOG_UPDATE_PCB::OnOptionChanged( wxCommandEvent& event )
151{
152 bool transferGroups = m_cbTransferGroups->GetValue();
153
154 if( !transferGroups )
155 m_cbApplyDesignBlockLayouts->SetValue( false );
156
157 m_cbApplyDesignBlockLayouts->Enable( transferGroups );
158
159 if( m_initialized )
160 {
161 PerformUpdate( true );
162 m_sdbSizer1OK->Enable( true );
163 m_sdbSizer1OK->SetDefault();
164 }
165}
166
167
168void DIALOG_UPDATE_PCB::OnUpdateClick( wxCommandEvent& event )
169{
170 m_messagePanel->SetLabel( _( "Changes Applied to PCB" ) );
171 PerformUpdate( false );
172
173 m_sdbSizer1Cancel->SetDefault();
174 // wxWidgets has a tendency to keep both buttons highlighted without the following:
175 m_sdbSizer1OK->Enable( false );
176}
static TOOL_ACTION selectionClear
Clear the current selection.
Definition actions.h:220
Update the BOARD with a new netlist.
void SetRemoveExtraFields(bool aEnabled)
void SetReporter(REPORTER *aReporter)
bool UpdateNetlist(NETLIST &aNetlist)
Update the board's components according to the new netlist.
void SetWillDrag(bool aWillDrag)
void SetIsDryRun(bool aEnabled)
Enable dry run mode (just report, no changes to PCB).
void SetDeleteUnusedFootprints(bool aEnabled)
void SetOverrideLocks(bool aOverride)
std::vector< PCB_GROUP * > GetAddedGroups() const
void SetApplyDesignBlockLayouts(bool aEnabled)
void SetReplaceFootprints(bool aEnabled)
void SetLookupByTimestamp(bool aEnabled)
void SetUpdateFields(bool aEnabled)
void SetTransferGroups(bool aEnabled)
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
WX_HTML_REPORT_PANEL * m_messagePanel
DIALOG_UPDATE_PCB_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Update PCB from Schematic"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
void PerformUpdate(bool aDryRun)
void OnOptionChanged(wxCommandEvent &event) override
bool TransferDataToWindow() override
void OnUpdateClick(wxCommandEvent &event) override
DIALOG_UPDATE_PCB(PCB_EDIT_FRAME *aParent, NETLIST *aNetlist)
PCB_EDIT_FRAME * m_frame
An interface for classes handling user events controlling the view behavior such as zooming,...
virtual VECTOR2D GetMousePosition(bool aWorldCoordinates=true) const =0
Return the current mouse pointer position.
virtual void SetCursorPosition(const VECTOR2D &aPosition, bool aWarpView=true, bool aTriggeredByArrows=false, long aArrowCommand=0)=0
Move cursor to the requested position expressed in world coordinates.
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
Store information read from a netlist along with the flags used to update the NETLIST in the BOARD.
static TOOL_ACTION applyDesignBlockLayout
static TOOL_ACTION move
move or drag an item
The main frame for Pcbnew.
A set of BOARD_ITEMs (i.e., without duplicates).
Definition pcb_group.h:51
The selection tool: currently supports:
void select(EDA_ITEM *aItem) override
Take necessary action mark an item as selected.
PCB_SELECTION & GetSelection()
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
void SetReferencePoint(const VECTOR2I &aP)
Master controller class:
T * GetTool()
Return the tool of given type or nullptr if there is no such tool registered.
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
#define _(s)
Class to handle a set of BOARD_ITEMs.
Class that computes missing connections on a PCB.
IbisParser parser & reporter
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708