KiCad PCB EDA Suite
dialog_update_pcb.cpp
Go to the documentation of this file.
1 
5 /*
6  * This program source code file is part of KiCad, a free EDA CAD application.
7  *
8  * Copyright (C) 1992-2016 KiCad Developers, see change_log.txt for contributors.
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, you may find one here:
22  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
23  * or you may search the http://www.gnu.org website for the version 2 license,
24  * or you may write to the Free Software Foundation, Inc.,
25  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26  */
27 
28 #include <common.h>
29 #include <wxPcbStruct.h>
30 #include <pcb_netlist.h>
31 #include <dialog_update_pcb.h>
32 #include <wx_html_report_panel.h>
33 #include <board_netlist_updater.h>
34 #include <tool/tool_manager.h>
35 #include <tools/pcb_actions.h>
36 #include <class_draw_panel_gal.h>
37 #include <class_drawpanel.h>
38 #include <class_board.h>
39 #include <ratsnest_data.h>
40 
41 #include <functional>
42 using namespace std::placeholders;
43 
45  DIALOG_UPDATE_PCB_BASE ( aParent ),
46  m_frame (aParent),
47  m_netlist (aNetlist)
48 {
49  m_messagePanel->SetLabel( _("Changes to be applied:") );
52  m_btnPerformUpdate->SetFocus();
53 
55 }
56 
57 
59 {
60 }
61 
62 
64 {
66 
67  REPORTER& reporter = m_messagePanel->Reporter();
68  TOOL_MANAGER* toolManager = m_frame->GetToolManager();
69  BOARD* board = m_frame->GetBoard();
70 
71  // keep trace of the initial baord area, if we want to place new footprints
72  // outside the existinag board
73  EDA_RECT bbox = board->GetBoundingBox();
74 
75  if( !aDryRun )
76  {
77 
78  // Clear selection, just in case a selected item has to be removed
79  toolManager->RunAction( PCB_ACTIONS::selectionClear, true );
80  }
81 
85 
86  try
87  {
88  m_frame->LoadFootprints( *m_netlist, &reporter );
89  }
90  catch( IO_ERROR &error )
91  {
92  wxString msg;
93 
94  reporter.Report( _( "Failed to load one or more footprints. Please add the missing libraries in PCBNew configuration. "
95  "The PCB will not update completely." ), REPORTER::RPT_ERROR );
96  reporter.Report( error.What(), REPORTER::RPT_INFO );
97  }
98 
100  updater.SetReporter ( &reporter );
101  updater.SetIsDryRun( aDryRun);
102  updater.SetLookupByTimestamp( m_matchByTimestamp->GetValue() );
103  updater.SetDeleteUnusedComponents ( true );
104  updater.SetReplaceFootprints( true );
105  updater.SetDeleteSinglePadNets( false );
106  updater.UpdateNetlist( *m_netlist );
107 
109 
110  if( aDryRun )
111  return;
112 
113  m_frame->SetCurItem( NULL );
114  m_frame->SetMsgPanel( board );
115 
116  std::vector<MODULE*> newFootprints = updater.GetAddedComponents();
117 
118  // Spread new footprints.
119  wxPoint areaPosition = m_frame->GetCrossHairPosition();
120 
121  if( !m_frame->IsGalCanvasActive() )
122  {
123  // In legacy mode place area to the left side of the board.
124  // if the board is empty, the bbox position is (0,0)
125  areaPosition.x = bbox.GetEnd().x + Millimeter2iu( 10 );
126  areaPosition.y = bbox.GetOrigin().y;
127  }
128 
129  m_frame->SpreadFootprints( &newFootprints, false, false, areaPosition, false );
130 
131  if( m_frame->IsGalCanvasActive() )
132  {
133  // Start move and place the new modules command
134  if( !newFootprints.empty() )
135  {
136  for( MODULE* footprint : newFootprints )
137  {
138  toolManager->RunAction( PCB_ACTIONS::selectItem, true, footprint );
139  }
140 
141  toolManager->InvokeTool( "pcbnew.InteractiveEdit" );
142  }
143  }
144  else // Legacy canvas
145  m_frame->GetCanvas()->Refresh();
146 
147  m_btnPerformUpdate->Enable( false );
148  m_btnPerformUpdate->SetLabel( _( "Update complete" ) );
149  m_btnCancel->SetLabel( _( "Close" ) );
150  m_btnCancel->SetFocus();
151 }
152 
153 
154 void DIALOG_UPDATE_PCB::OnMatchChange( wxCommandEvent& event )
155 {
156  PerformUpdate( true );
157 }
158 
159 
160 void DIALOG_UPDATE_PCB::OnUpdateClick( wxCommandEvent& event )
161 {
162  m_messagePanel->SetLabel( _( "Changes applied to the PCB:" ) );
163  PerformUpdate( false );
164  m_btnCancel->SetFocus();
165 }
void SetVisibleSeverities(int aSeverities)
Set the visible severity filter.
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:53
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes...
Definition: class_board.h:827
void SetLazyUpdate(bool aLazyUpdate)
Sets the lasy update.
wxRadioButton * m_matchByTimestamp
void SpreadFootprints(std::vector< MODULE * > *aFootprints, bool aMoveFootprintsOutsideBoardOnly, bool aCheckForBoardEdges, wxPoint aSpreadAreaPosition, bool aPrepareUndoCommand=true)
Function SpreadFootprints Footprints (after loaded by reading a netlist for instance) are moved to be...
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL) override
Definition: draw_panel.cpp:326
EDA_DRAW_PANEL * GetCanvas()
Definition: draw_frame.h:299
Class BOARD_NETLIST_UPDATER updates the BOARD with a new netlist.
Class BOARD to handle a board.
Class DIALOG_UPDATE_PCB_BASE.
Class that computes missing connections on a PCB.
void SetCurItem(BOARD_ITEM *aItem, bool aDisplayInfo=true)
Function SetCurItem sets the currently selected item and displays it in the MsgPanel.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
BOARD * GetBoard() const
BOARD_NETLIST_UPDATER class definition.
void SetFindByTimeStamp(bool aFindByTimeStamp)
Definition: pcb_netlist.h:302
void SetReporter(REPORTER *aReporter)
Sets the reporter object
Class REPORTER is a pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:61
bool InvokeTool(TOOL_ID aToolId)
Function InvokeTool() Calls a tool by sending a tool activation event to tool of given ID...
PCB_EDIT_FRAME * m_frame
void SortByReference()
const wxPoint & GetOrigin() const
Class TOOL_MANAGER.
Definition: tool_manager.h:49
virtual void OnUpdateClick(wxCommandEvent &event) override
void SetReplaceFootprints(bool aReplaceFootprints)
Definition: pcb_netlist.h:306
Class NETLIST stores all of information read from a netlist along with the flags used to update the N...
Definition: pcb_netlist.h:205
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Function SetMsgPanel clears the message panel and populates it with the contents of aList...
Definition: draw_frame.cpp:751
REPORTER & Reporter()
returns the reporter object that reports to this panel
bool IsGalCanvasActive() const
Function IsGalCanvasActive is used to check which canvas (GAL-based or standard) is currently in use...
Definition: draw_frame.h:795
const wxPoint GetEnd() const
WX_HTML_REPORT_PANEL * m_messagePanel
TOOL_MANAGER * GetToolManager() const
Function GetToolManager returns the tool manager instance, if any.
Definition: draw_frame.h:810
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
void LoadFootprints(NETLIST &aNetlist, REPORTER *aReporter)
Function loadFootprints loads the footprints for each COMPONENT in aNetlist from the list of librarie...
void Flush()
Forces updating the HTML page, after the report is built in lazy mode
void Clear()
clears the report panel
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:166
static TOOL_ACTION selectItem
Selects an item (specified as the event parameter).
Definition: pcb_actions.h:56
Class EDA_RECT handles the component boundary box.
The common library.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
void SetDeleteExtraFootprints(bool aDeleteExtraFootprints)
Definition: pcb_netlist.h:291
DIALOG_UPDATE_PCB(PCB_EDIT_FRAME *aParent, NETLIST *aNetlist)
void SetLabel(const wxString &aLabel) override
sets the frame label
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Function GetCrossHairPosition return the current cross hair position in logical (drawing) coordinates...
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:47
void PerformUpdate(bool aDryRun)
virtual void OnMatchChange(wxCommandEvent &event) override