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 <pcb_edit_frame.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  if( m_Collector->GetCount() == 0 )
64  RefPos( true ), guide );
65 
66  BOARD_ITEM* item = (*m_Collector)[0];
67 
68  if( item )
69  {
70  switch( item->Type() )
71  {
72  case PCB_PAD_T:
73  netcode = ( (D_PAD*) item )->GetNetCode();
74  SendMessageToEESCHEMA( item );
75  break;
76 
77  case PCB_TRACE_T:
78  case PCB_VIA_T:
79  // since these classes are all derived from TRACK, use a common
80  // GetNet() function:
81  netcode = ( (TRACK*) item )->GetNetCode();
82  break;
83 
84  case PCB_ZONE_AREA_T:
85  netcode = ( (ZONE_CONTAINER*) item )->GetNetCode();
86  break;
87 
88  default:
89  ; // until somebody changes GENERAL_COLLECTOR::PadsOrTracks,
90  // this should not happen.
91  }
92  }
93 
94  if( netcode >= 0 )
95  {
96  GetBoard()->SetHighLightNet( netcode );
97  HighLight( DC );
98  }
99 
100  return netcode; // HitTest() failed.
101 }
102 
103 
105 {
106  if( GetBoard()->IsHighLightNetON() )
107  GetBoard()->HighLightOFF();
108  else
109  GetBoard()->HighLightON();
110 
111  GetBoard()->DrawHighLight( m_canvas, DC, GetBoard()->GetHighLightNetCode() );
112 }
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:59
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)
Scan a BOARD_ITEM using this class's Inspector method, which does the collection.
Definition: collectors.cpp:473
Class BOARD to handle a board.
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:100
void HighLightOFF()
Function HighLightOFF Disable highlight.
Definition: class_board.h:389
Classes to handle copper zones.
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
static const KICAD_T PadsOrTracks[]
A scan list for PADs, TRACKs, or VIAs.
Definition: collectors.h:298
Functions relatives to tracks, vias and segments used to fill zones.
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
GENERAL_COLLECTOR * m_Collector
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:114
GENERAL_COLLECTORS_GUIDE GetCollectorsGuide()
Function GetCollectorsGuide.
a helper to handle the real device context used in KiCad
static const KICAD_T Zones[]
A scan list for zones outlines only.
Definition: collectors.h:277
void HighLight(wxDC *DC)
Function HighLight.
Definition: highlight.cpp:104
void HighLightON()
Function HighLightON Enable highlight.
Definition: class_board.h:396
void SetHighLightNet(int aNetCode)
Function SetHighLightNet.
Definition: class_board.h:374
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:128
void SendMessageToEESCHEMA(BOARD_ITEM *objectToSync)
Function SendMessageToEESCHEMA sends a message to the schematic editor so that it may move its cursor...
wxPoint RefPos(bool useMouse) const
Return the reference position, coming from either the mouse position or the cursor position.
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
BOARD * GetBoard() const
A general implementation of a COLLECTORS_GUIDE.
Definition: collectors.h:386
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...
int SelectHighLight(wxDC *DC)
Locate track or pad and highlight the corresponding net.
Definition: highlight.cpp:44
KICAD_T Type() const
Function Type()
Definition: base_struct.h:204