KiCad PCB EDA Suite
move_and_route_event_functions.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) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
5  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
6  * Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
7  *
8  * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.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 
33 #include <algorithm>
34 
35 #include <fctsys.h>
36 #include <class_drawpanel.h>
37 #include <confirm.h>
38 #include <kicad_string.h>
39 #include <pcbnew.h>
40 #include <wxPcbStruct.h>
41 #include <kicad_device_context.h>
42 
43 #include <autorout.h>
44 #include <cell.h>
45 #include <pcbnew_id.h>
46 #include <class_board.h>
47 #include <class_module.h>
48 
49 
50 typedef enum {
56 
57 
58 
59 wxString ModulesMaskSelection = wxT( "*" );
60 
61 
62 /* Called on events (popup menus) relative to automove and autoplace footprints
63  */
64 void PCB_EDIT_FRAME::OnPlaceOrRouteFootprints( wxCommandEvent& event )
65 {
66  int id = event.GetId();
67 
68  if( m_mainToolBar == NULL )
69  return;
70 
72 
73  switch( id )
74  {
76  return;
77 
79  LockModule( (MODULE*) GetScreen()->GetCurItem(), true );
80  return;
81 
83  LockModule( (MODULE*) GetScreen()->GetCurItem(), false );
84  return;
85 
87  LockModule( NULL, false );
88  return;
89 
91  LockModule( NULL, true );
92  return;
93 
95  if( m_canvas->IsMouseCaptured() )
96  {
98  }
99 
100  break;
101 
102  default: // Abort a current command (if any)
104  break;
105  }
106 
107  // Erase ratsnest if needed
109  DrawGeneralRatsnest( &dc );
110 
112 
113  switch( id )
114  {
117  break;
118 
120  AutoPlaceModule( NULL, PLACE_ALL, &dc );
121  break;
122 
124  AutoPlaceModule( NULL, PLACE_OUT_OF_BOARD, &dc );
125  break;
126 
128  AutoPlaceModule( NULL, PLACE_INCREMENTAL, &dc );
129  break;
130 
132  if( !IsOK( this,
133  _("Not locked footprints inside the board will be moved. OK?") ) )
134  break;
135  // Fall through
137  if( GetBoard()->m_Modules == NULL )
138  {
139  DisplayError( this, _( "No footprint found!" ) );
140  return;
141  }
142  else
143  {
144  MODULE* footprint = GetBoard()->m_Modules;
145  std::vector<MODULE*> footprintList;
146  for( ; footprint != NULL; footprint = footprint->Next() )
147  footprintList.push_back( footprint );
148 
149  SpreadFootprints( &footprintList, id == ID_POPUP_PCB_SPREAD_NEW_MODULES,
150  true, GetCrossHairPosition() );
151  }
152  break;
153 
155  Autoroute( &dc, ROUTE_ALL );
156  break;
157 
159  Autoroute( &dc, ROUTE_MODULE );
160  break;
161 
163  Autoroute( &dc, ROUTE_PAD );
164  break;
165 
167  Autoroute( &dc, ROUTE_NET );
168  break;
169 
171  Reset_Noroutable( &dc );
172  break;
173 
174  default:
175  wxMessageBox( wxT( "OnPlaceOrRouteFootprints command error" ) );
176  break;
177  }
178 
180  Compile_Ratsnest( &dc, true );
181 }
182 
183 
184 /* Set or reset (true or false) Lock attribute of aModule or all modules if aModule == NULL
185  */
186 void PCB_EDIT_FRAME::LockModule( MODULE* aModule, bool aLocked )
187 {
188  if( aModule )
189  {
190  aModule->SetLocked( aLocked );
191  SetMsgPanel( aModule );
192  OnModify();
193  }
194  else
195  {
196  aModule = GetBoard()->m_Modules;
197 
198  for( ; aModule != NULL; aModule = aModule->Next() )
199  {
201  {
202  aModule->SetLocked( aLocked );
203  OnModify();
204  }
205  }
206  }
207 }
208 
virtual void OnModify() override
Function OnModify must be called after a board change to set the modified flag.
Definition: pcbframe.cpp:996
bool IsElementVisible(GAL_LAYER_ID LAYER_aPCB) const
Function IsElementVisible tests whether a given element category is visible.
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...
void AutoPlaceModule(MODULE *Module, int place_mode, wxDC *DC)
Function AutoPlaceModule automatically places footprints within the confines of the PCB edges...
void OnPlaceOrRouteFootprints(wxCommandEvent &event)
void LockModule(MODULE *aModule, bool aLocked)
This file is part of the common library.
Class BOARD to handle a board.
MODULE * Next() const
Definition: class_module.h:99
void EndMouseCapture(int aId=-1, int aCursorId=-1, const wxString &aTitle=wxEmptyString, bool aCallEndFunc=true)
Function EndMouseCapture ends mouse a capture.
BOARD * GetBoard() const
void CallEndMouseCapture(wxDC *aDC)
Function CallEndMouseCapture calls the end mouse capture callback.
wxString ModulesMaskSelection
a helper to handle the real device context used in KiCad
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:754
bool IsMouseCaptured() const
bool WildCompareString(const wxString &pattern, const wxString &string_to_tst, bool case_sensitive)
Function WildCompareString compares a string against wild card (* and ?) pattern using the usual rule...
Definition: string.cpp:305
void DrawGeneralRatsnest(wxDC *aDC, int aNetcode=0)
function Displays the general ratsnest Only ratsnest with the status bit CH_VISIBLE is set are displa...
Definition: ratsnest.cpp:300
void Reset_Noroutable(wxDC *DC)
Definition: autorout.cpp:210
wxAuiToolBar * m_mainToolBar
Standard horizontal Toolbar.
Definition: wxstruct.h:135
void Autoroute(wxDC *DC, int mode)
Definition: autorout.cpp:54
void Compile_Ratsnest(wxDC *aDC, bool aDisplayStatus)
Function Compile_Ratsnest Create the entire board ratsnest.
Definition: ratsnest.cpp:165
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:92
void SetLocked(bool isLocked) override
Function SetLocked sets the MODULE_is_LOCKED bit in the m_ModuleStatus.
Definition: class_module.h:233
const wxString & GetReference() const
Function GetReference.
Definition: class_module.h:411
DLIST< MODULE > m_Modules
Definition: class_board.h:243
#define INSTALL_UNBUFFERED_DC(name, parent)
PCB_SCREEN * GetScreen() const override
Function GetScreen returns a pointer to a BASE_SCREEN or one of its derivatives.
Module description (excepted pads)
int GetDefaultCursor() const
Function GetDefaultCursor return the default cursor shape.
BOARD_ITEM * GetCurItem()
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:69
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Function GetCrossHairPosition return the current cross hair position in logical (drawing) coordinates...
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Function IsOK displays a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:111
int m_Status_Pcb
Flags used in ratsnest calculation and update.
Definition: class_board.h:240