drc_marker_functions.cpp 6.02 KB
Newer Older
1 2
/**
 * @file drc_marker_functions.cpp
3
 */
4

5
/*
6
 * This program source code file is part of KiCad, a free EDA CAD application.
7 8 9
 *
 * Copyright (C) 2010 Dick Hollenbeck, dick@softplc.com
 * Copyright (C) 2004-2010 Jean-Pierre Charras, jean-pierre.charras@gipsa-lab.inpg.fr
10
 * Copyright (C) 2007 KiCad Developers, see change_log.txt for contributors.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
 *
 * 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
 */


/* Methods of class DRC to initialize drc markers with messages
 * according to items and error ode
*/

35 36 37 38
#include <fctsys.h>
#include <common.h>
#include <pcbnew.h>
#include <class_board_design_settings.h>
39

40 41 42 43
#include <drc_stuff.h>
#include <class_pad.h>
#include <class_track.h>
#include <class_zone.h>
44
#include <class_zone.h>
45
#include <class_marker_pcb.h>
46
#include <class_pcb_text.h>
47 48


49 50
MARKER_PCB* DRC::fillMarker( const TRACK* aTrack, BOARD_ITEM* aItem, int aErrorCode,
                             MARKER_PCB* fillMe )
51 52 53 54 55 56 57 58 59 60 61
{
    wxString textA = aTrack->GetSelectMenuText();
    wxString textB;

    wxPoint  position;
    wxPoint  posB;

    if( aItem )     // aItem might be NULL
    {
        textB = aItem->GetSelectMenuText();

62 63
        if( aItem->Type() == PCB_PAD_T )
        {
Dick Hollenbeck's avatar
Dick Hollenbeck committed
64
            posB = position = ((D_PAD*)aItem)->GetPosition();
65 66 67
        }
        else if( aItem->Type() == PCB_VIA_T )
        {
68
            posB = position = ((VIA*)aItem)->GetPosition();
69 70
        }
        else if( aItem->Type() == PCB_TRACE_T )
71 72
        {
            TRACK*  track  = (TRACK*) aItem;
Dick Hollenbeck's avatar
Dick Hollenbeck committed
73 74 75

            posB = track->GetPosition();

76
            wxPoint endPos = track->GetEnd();
77 78 79 80

            // either of aItem's start or end will be used for the marker position
            // first assume start, then switch at end if needed.  decision made on
            // distance from end of aTrack.
81
            position = track->GetStart();
82

83 84
            double dToEnd = GetLineLength( endPos, aTrack->GetEnd() );
            double dToStart = GetLineLength( position, aTrack->GetEnd() );
85 86 87 88

            if( dToEnd < dToStart )
                position = endPos;
        }
89 90 91 92 93
        else if( aItem->Type() == PCB_TEXT_T )
        {
            position = aTrack->GetPosition();
            posB = ((TEXTE_PCB*) aItem)->GetPosition();
        }
94 95 96 97 98 99 100 101 102 103 104 105
    }
    else
        position = aTrack->GetPosition();

    if( fillMe )
    {
        if( aItem )
            fillMe->SetData( aErrorCode, position,
                             textA, aTrack->GetPosition(),
                             textB, posB );
        else
            fillMe->SetData( aErrorCode, position,
Dick Hollenbeck's avatar
Dick Hollenbeck committed
106
                             textA, aTrack->GetPosition() );
107 108 109 110
    }
    else
    {
        if( aItem )
111
        {
112 113 114
            fillMe = new MARKER_PCB( aErrorCode, position,
                                     textA, aTrack->GetPosition(),
                                     textB, posB );
115 116
            fillMe->SetItem( aItem );
        }
117
        else
118
        {
119
            fillMe = new MARKER_PCB( aErrorCode, position,
Dick Hollenbeck's avatar
Dick Hollenbeck committed
120
                                     textA, aTrack->GetPosition() );
121
        }
122 123 124 125 126 127
    }

    return fillMe;
}


128
MARKER_PCB* DRC::fillMarker( D_PAD* aPad, BOARD_ITEM* aItem, int aErrorCode, MARKER_PCB* fillMe )
129 130
{
    wxString textA = aPad->GetSelectMenuText();
131
    wxString textB;
132 133

    wxPoint  posA = aPad->GetPosition();
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
    wxPoint  posB;

    if( aItem )
    {
        textB = aItem->GetSelectMenuText();

        switch( aItem->Type() )
        {
        case PCB_PAD_T:
            posB = ((D_PAD*)aItem)->GetPosition();
            break;

        case PCB_TEXT_T:
            posB = ((TEXTE_PCB*)aItem)->GetPosition();
            break;

        default:
            wxLogDebug( wxT("fillMarker: unsupported item") );
            break;
        }
    }
155 156

    if( fillMe )
157
    {
158
        fillMe->SetData( aErrorCode, posA, textA, posA, textB, posB );
159
    }
160
    else
161
    {
162
        fillMe = new MARKER_PCB( aErrorCode, posA, textA, posA, textB, posB );
163 164
        fillMe->SetItem( aPad );    // TODO it has to be checked
    }
165 166 167 168 169 170 171 172 173 174 175 176

    return fillMe;
}


MARKER_PCB* DRC::fillMarker( ZONE_CONTAINER* aArea, int aErrorCode, MARKER_PCB* fillMe )
{
    wxString textA = aArea->GetSelectMenuText();

    wxPoint  posA = aArea->GetPosition();

    if( fillMe )
177
    {
178
        fillMe->SetData( aErrorCode, posA, textA, posA );
179
    }
180
    else
181
    {
182
        fillMe = new MARKER_PCB( aErrorCode, posA, textA, posA );
183 184
        fillMe->SetItem( aArea );
    }
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199

    return fillMe;
}


MARKER_PCB* DRC::fillMarker( const ZONE_CONTAINER* aArea,
                             const wxPoint&        aPos,
                             int                   aErrorCode,
                             MARKER_PCB*           fillMe )
{
    wxString textA = aArea->GetSelectMenuText();

    wxPoint  posA = aPos;

    if( fillMe )
200
    {
201
        fillMe->SetData( aErrorCode, posA, textA, posA );
202
    }
203
    else
204
    {
205
        fillMe = new MARKER_PCB( aErrorCode, posA, textA, posA );
206 207
        fillMe->SetItem( aArea );
    }
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226

    return fillMe;
}


MARKER_PCB* DRC::fillMarker( int aErrorCode, const wxString& aMessage, MARKER_PCB* fillMe )
{
    wxPoint posA;   // not displayed

    if( fillMe )
        fillMe->SetData( aErrorCode, posA, aMessage, posA );
    else
        fillMe = new MARKER_PCB( aErrorCode, posA, aMessage, posA );

    fillMe->SetShowNoCoordinate();

    return fillMe;
}