highlight.cpp 5.53 KB
Newer Older
1 2 3
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
4 5 6
 * Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
 * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
 * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you may find one here:
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * or you may search the http://www.gnu.org website for the version 2 license,
 * or you may write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

26
/**
27
 * @file highlight.cpp
28 29
 * @brief Highlight nets.
 */
30

31 32 33 34 35 36
#include <fctsys.h>
#include <class_drawpanel.h>
#include <kicad_string.h>
#include <wxPcbStruct.h>
#include <kicad_device_context.h>
#include <macros.h>
37

38 39 40
#include <class_board.h>
#include <class_track.h>
#include <class_zone.h>
41

42 43
#include <pcbnew.h>
#include <collectors.h>
44

45

46
#define Pad_fill ( Pad_Fill_Item.State == RUN )
47 48


49
void PCB_EDIT_FRAME::ListNetsAndSelect( wxCommandEvent& event )
50
{
51 52
    NETINFO_ITEM* net;
    wxString      netFilter;
53
    wxArrayString list;
54 55

    netFilter = wxT( "*" );
56 57
    wxTextEntryDialog dlg( this, _( "Filter Net Names" ), _( "Net Filter" ), netFilter );

58 59 60 61
    if( dlg.ShowModal() != wxID_OK )
        return; // cancelled by user

    netFilter = dlg.GetValue( );
62

63
    if( netFilter.IsEmpty() )
64 65
        return;

66
    wxString Line;
67
    for( unsigned ii = 0; ii < GetBoard()->GetNetCount(); ii++ )
68
    {
69
        net = GetBoard()->m_NetInfo.GetNetItem( ii );
70

71
        if( !WildCompareString( netFilter, net->GetNetname(), false ) )
72 73
            continue;

74
        Line.Printf( wxT( "net %3.3d:  %s" ), net->GetNet(),
75
                     GetChars( net->GetNetname() ) );
76
        list.Add( Line );
77 78
    }

79 80 81 82 83
#if wxCHECK_VERSION( 2, 9, 4 )
    wxSingleChoiceDialog choiceDlg( this, wxEmptyString, _( "Select Net" ), list, (void**) NULL );
#else
    wxSingleChoiceDialog choiceDlg( this, wxEmptyString, _( "Select Net" ), list, (char**) NULL );
#endif
dickelbeck's avatar
dickelbeck committed
84

85
    if( (choiceDlg.ShowModal() == wxID_CANCEL) || (choiceDlg.GetSelection() == wxNOT_FOUND) )
86 87
        return;

88
    bool     found   = false;
89
    unsigned netcode = (unsigned) choiceDlg.GetSelection();
90 91

    // Search for the net selected.
92
    for( unsigned ii = 0; ii < GetBoard()->GetNetCount(); ii++ )
93
    {
94
        net = GetBoard()->FindNet( ii );
95

96
        if( !WildCompareString( netFilter, net->GetNetname(), false ) )
97
            continue;
dickelbeck's avatar
dickelbeck committed
98

99
        if( ii == netcode )
100
        {
101 102
            netcode = net->GetNet();
            found   = true;
103 104 105 106
            break;
        }
    }

107 108
    if( found )
    {
109
        INSTALL_UNBUFFERED_DC( dc, m_canvas );
110

111
        if( GetBoard()->IsHighLightNetON() )
112
            HighLight( &dc );
dickelbeck's avatar
dickelbeck committed
113

114
        GetBoard()->SetHighLightNet( netcode );
115
        HighLight( &dc );
116
    }
117 118 119
}


120
int PCB_EDIT_FRAME::SelectHighLight( wxDC* DC )
121
{
122
    int netcode = -1;
123 124

    if( GetBoard()->IsHighLightNetON() )
125
        HighLight( DC );
dickelbeck's avatar
dickelbeck committed
126

127
    // use this scheme because a pad is a higher priority than a track in the
128
    // search, and finding a pad, instead of a track on a pad,
129
    // allows us to fire a message to Eeschema.
130 131 132

    GENERAL_COLLECTORS_GUIDE guide = GetCollectorsGuide();

133
    // optionally, modify the "guide" here as needed using its member functions
dickelbeck's avatar
dickelbeck committed
134

135
    m_Collector->Collect( GetBoard(), GENERAL_COLLECTOR::PadsTracksOrZones,
136
                          RefPos( true ), guide );
137 138

    BOARD_ITEM* item = (*m_Collector)[0];
dickelbeck's avatar
dickelbeck committed
139

140
    if( item )
141
    {
142
        switch( item->Type() )
143
        {
144
        case PCB_PAD_T:
145
            netcode = ( (D_PAD*) item )->GetNetCode();
146
            SendMessageToEESCHEMA( item );
147
            break;
dickelbeck's avatar
dickelbeck committed
148

149 150 151
        case PCB_TRACE_T:
        case PCB_VIA_T:
        case PCB_ZONE_T:
152 153
            // since these classes are all derived from TRACK, use a common
            // GetNet() function:
154
            netcode = ( (TRACK*) item )->GetNetCode();
155
            break;
dickelbeck's avatar
dickelbeck committed
156

157
        case PCB_ZONE_AREA_T:
158
            netcode = ( (ZONE_CONTAINER*) item )->GetNetCode();
159
            break;
dickelbeck's avatar
dickelbeck committed
160

161 162 163
        default:
            ;   // until somebody changes GENERAL_COLLECTOR::PadsOrTracks,
                // this should not happen.
164 165
        }
    }
166

167 168
    if( netcode >= 0 )
    {
169
        GetBoard()->SetHighLightNet( netcode );
170
        HighLight( DC );
171 172 173
    }

    return netcode;      // HitTest() failed.
174 175 176
}


177
void PCB_EDIT_FRAME::HighLight( wxDC* DC )
178
{
179 180
    if( GetBoard()->IsHighLightNetON() )
        GetBoard()->HighLightOFF();
181
    else
182
        GetBoard()->HighLightON();
dickelbeck's avatar
dickelbeck committed
183

184
    GetBoard()->DrawHighLight( m_canvas, DC, GetBoard()->GetHighLightNetCode() );
185
}
186 187 188 189 190 191 192 193 194 195 196 197 198 199

void PCB_EDIT_FRAME::HighlightUnconnectedPads( wxDC* DC )
{
    for( unsigned ii = 0; ii < GetBoard()->GetRatsnestsCount(); ii++ )
    {
        RATSNEST_ITEM* net = &GetBoard()->m_FullRatsnest[ii];

        if( (net->m_Status & CH_ACTIF) == 0 )
            continue;

        net->m_PadStart->Draw( m_canvas, DC, GR_OR | GR_HIGHLIGHT );
        net->m_PadEnd->Draw( m_canvas, DC, GR_OR | GR_HIGHLIGHT );
    }
}