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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include <pcb_edit_frame.h>
25#include <pcbnew_settings.h>
26#include <dialog_update_pcb.h>
31#include <pcb_group.h>
32#include <tool/tool_manager.h>
33#include <tools/pcb_actions.h>
35#include <view/view_controls.h>
36#include <kiface_base.h>
37#include <kiplatform/ui.h>
38
39
41 DIALOG_UPDATE_PCB_BASE( aParent ),
42 m_frame( aParent ),
43 m_netlist( aNetlist ),
44 m_initialized( false )
45{
46 m_messagePanel->SetLabel( _("Changes to Be Applied") );
47 m_messagePanel->SetFileName( Prj().GetProjectPath() + wxT( "report.txt" ) );
48 m_messagePanel->SetLazyUpdate( true );
49 m_netlist->SortByReference();
50
51 m_messagePanel->GetSizer()->SetSizeHints( this );
52 m_messagePanel->Layout();
53
54 SetupStandardButtons( { { wxID_OK, _( "Update PCB" ) },
55 { wxID_CANCEL, _( "Close" ) } } );
56
58
60
61 m_initialized = true;
62}
63
64
66{
68 {
69 PCB_SELECTION_TOOL* selTool = m_frame->GetToolManager()->GetTool<PCB_SELECTION_TOOL>();
70 PCB_SELECTION& selection = selTool->GetSelection();
71
72 // Set the reference point to (0,0) where the new footprints were spread. This ensures
73 // the move tool knows where the items are located, preventing an offset when the "warp
74 // cursor to origin of moved object" preference is disabled.
75 if( selection.Size() > 0 )
76 selection.SetReferencePoint( VECTOR2I( 0, 0 ) );
77
78 KIGFX::VIEW_CONTROLS* controls = m_frame->GetCanvas()->GetViewControls();
79 controls->SetCursorPosition( controls->GetMousePosition() );
80 m_frame->GetToolManager()->RunAction( PCB_ACTIONS::move );
81 }
82}
83
84
86{
87 m_messagePanel->Clear();
88
89 REPORTER& reporter = m_messagePanel->Reporter();
90
91 m_runDragCommand = false;
92
93 m_netlist->SetFindByTimeStamp( !m_cbRelinkFootprints->GetValue() );
94 m_netlist->SetReplaceFootprints( m_cbUpdateFootprints->GetValue() );
95
96 if( !aDryRun )
97 {
98 m_frame->GetToolManager()->DeactivateTool();
99 m_frame->GetToolManager()->RunAction( ACTIONS::selectionClear );
100 }
101
102 BOARD_NETLIST_UPDATER updater( m_frame, m_frame->GetBoard() );
103 updater.SetReporter ( &reporter );
104 updater.SetIsDryRun( aDryRun );
105 updater.SetLookupByTimestamp( !m_cbRelinkFootprints->GetValue() );
107 updater.SetReplaceFootprints( m_cbUpdateFootprints->GetValue() );
108 updater.SetTransferGroups( m_cbTransferGroups->GetValue() );
110 updater.SetOverrideLocks( m_cbOverrideLocks->GetValue() );
111 updater.SetUpdateFields( m_cbUpdateFields->GetValue() );
112 updater.SetRemoveExtraFields( m_cbRemoveExtraFields->GetValue() );
113 updater.UpdateNetlist( *m_netlist );
114
115 m_messagePanel->Flush( true );
116
117 if( aDryRun )
118 return;
119
120 m_frame->OnNetlistChanged( updater, &m_runDragCommand );
121
122 if( m_cbApplyDesignBlockLayouts->GetValue() )
123 {
124 TOOL_MANAGER* toolMgr = m_frame->GetToolManager();
125 PCB_SELECTION_TOOL* selTool = toolMgr->GetTool<PCB_SELECTION_TOOL>();
126
127 for( PCB_GROUP* group : updater.GetAddedGroups() )
128 {
129 if( !group->HasDesignBlockLink() )
130 continue;
131
133 selTool->select( group );
135 }
136
138 }
139}
140
141
143{
144 m_cbApplyDesignBlockLayouts->Enable( m_cbTransferGroups->GetValue() );
145
146 PerformUpdate( true );
147
148 return true;
149}
150
151
152void DIALOG_UPDATE_PCB::OnOptionChanged( wxCommandEvent& event )
153{
154 bool transferGroups = m_cbTransferGroups->GetValue();
155
156 if( !transferGroups )
157 m_cbApplyDesignBlockLayouts->SetValue( false );
158
159 m_cbApplyDesignBlockLayouts->Enable( transferGroups );
160
161 if( m_initialized )
162 {
163 PerformUpdate( true );
164 m_sdbSizer1OK->Enable( true );
165 m_sdbSizer1OK->SetDefault();
166 }
167}
168
169
170void DIALOG_UPDATE_PCB::OnUpdateClick( wxCommandEvent& event )
171{
172 m_messagePanel->SetLabel( _( "Changes Applied to PCB" ) );
173 PerformUpdate( false );
174
175 m_sdbSizer1Cancel->SetDefault();
176 // wxWidgets has a tendency to keep both buttons highlighted without the following:
177 m_sdbSizer1OK->Enable( false );
178}
static TOOL_ACTION selectionClear
Clear the current selection.
Definition actions.h:224
Update the BOARD with a new netlist.
void SetRemoveExtraFields(bool aEnabled)
void SetReporter(REPORTER *aReporter)
Enable dry run mode (just report, no changes to PCB).
bool UpdateNetlist(NETLIST &aNetlist)
Update the board's components according to the new netlist.
void SetIsDryRun(bool aEnabled)
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:53
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:75
void SetReferencePoint(const VECTOR2I &aP)
Master controller class:
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:687