KiCad PCB EDA Suite
highlight.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) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
31 #include <fctsys.h>
32 #include <class_drawpanel.h>
33 #include <wxPcbStruct.h>
34 #include <kicad_device_context.h>
35 
36 #include <class_board.h>
37 #include <class_track.h>
38 #include <class_zone.h>
39 
40 #include <pcbnew.h>
41 #include <collectors.h>
42 
43 
45 {
46  int netcode = -1;
47 
48  if( GetBoard()->IsHighLightNetON() )
49  HighLight( DC );
50 
51  // use this scheme because a pad is a higher priority than a track in the
52  // search, and finding a pad, instead of a track on a pad,
53  // allows us to fire a message to Eeschema.
54 
56 
57  // optionally, modify the "guide" here as needed using its member functions
58 
60  RefPos( true ), guide );
61 
62  BOARD_ITEM* item = (*m_Collector)[0];
63 
64  if( item )
65  {
66  switch( item->Type() )
67  {
68  case PCB_PAD_T:
69  netcode = ( (D_PAD*) item )->GetNetCode();
70  SendMessageToEESCHEMA( item );
71  break;
72 
73  case PCB_TRACE_T:
74  case PCB_VIA_T:
75  case PCB_ZONE_T:
76  // since these classes are all derived from TRACK, use a common
77  // GetNet() function:
78  netcode = ( (TRACK*) item )->GetNetCode();
79  break;
80 
81  case PCB_ZONE_AREA_T:
82  netcode = ( (ZONE_CONTAINER*) item )->GetNetCode();
83  break;
84 
85  default:
86  ; // until somebody changes GENERAL_COLLECTOR::PadsOrTracks,
87  // this should not happen.
88  }
89  }
90 
91  if( netcode >= 0 )
92  {
93  GetBoard()->SetHighLightNet( netcode );
94  HighLight( DC );
95  }
96 
97  return netcode; // HitTest() failed.
98 }
99 
100 
102 {
103  if( GetBoard()->IsHighLightNetON() )
104  GetBoard()->HighLightOFF();
105  else
106  GetBoard()->HighLightON();
107 
108  GetBoard()->DrawHighLight( m_canvas, DC, GetBoard()->GetHighLightNetCode() );
109 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:78
static const KICAD_T PadsTracksOrZones[]
A scan list for PADs, TRACKs, VIAs, or ZONEs.
Definition: collectors.h:276
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
void Collect(BOARD_ITEM *aItem, const KICAD_T aScanList[], const wxPoint &aRefPos, const COLLECTORS_GUIDE &aGuide)
Function Collect scans a BOARD_ITEM using this class's Inspector method, which does the collection...
Definition: collectors.cpp:447
Class BOARD to handle a board.
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:114
void HighLightOFF()
Function HighLightOFF Disable highlight.
Definition: class_board.h:379
BOARD * GetBoard() const
Classes to handle copper zones.
class D_PAD, a pad in a footprint
Definition: typeinfo.h:102
Functions relatives to tracks, vias and segments used to fill zones.
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:107
GENERAL_COLLECTOR * m_Collector
GENERAL_COLLECTORS_GUIDE GetCollectorsGuide()
Function GetCollectorsGuide.
a helper to handle the real device context used in KiCad
void HighLight(wxDC *DC)
Function HighLight.
Definition: highlight.cpp:101
class SEGZONE, a segment used to fill a zone area (segment on a copper layer)
Definition: typeinfo.h:109
void HighLightON()
Function HighLightON Enable highlight.
Definition: class_board.h:386
void SetHighLightNet(int aNetCode)
Function SetHighLightNet.
Definition: class_board.h:364
wxPoint RefPos(bool useMouse) const
Function RefPos Return the reference position, coming from either the mouse position or the cursor po...
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:92
void SendMessageToEESCHEMA(BOARD_ITEM *objectToSync)
Function SendMessageToEESCHEMA sends a message to the schematic editor so that it may move its cursor...
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:108
Class GENERAL_COLLECTORS_GUIDE is a general implementation of a COLLECTORS_GUIDE. ...
Definition: collectors.h:378
void DrawHighLight(EDA_DRAW_PANEL *aDrawPanel, wxDC *aDC, int aNetCode)
Function DrawHighLight redraws the objects in the board that are associated with the given aNetCode a...
Definition: tracepcb.cpp:247
int SelectHighLight(wxDC *DC)
Locate track or pad and highlight the corresponding net.
Definition: highlight.cpp:44