kicad/pcbnew/drc.cpp

797 lines
24 KiB
C++
Raw Normal View History

2007-12-01 03:42:52 +00:00
/*
* This program source code file is part of KiCad, a free EDA CAD application.
2007-12-01 03:42:52 +00:00
*
* Copyright (C) 2004-2007 Jean-Pierre Charras, jean-pierre.charras@gipsa-lab.inpg.fr
2007-12-01 03:42:52 +00:00
* Copyright (C) 2007 Dick Hollenbeck, dick@softplc.com
* Copyright (C) 2007 KiCad Developers, see change_log.txt for contributors.
2007-12-01 03:42:52 +00:00
*
* 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
*/
2007-08-08 20:51:08 +00:00
/****************************/
/* DRC control */
2007-08-08 20:51:08 +00:00
/****************************/
#include <fctsys.h>
#include <wxPcbStruct.h>
#include <trigo.h>
#include <base_units.h>
#include <class_board_design_settings.h>
#include <class_module.h>
#include <class_track.h>
#include <class_pad.h>
#include <class_zone.h>
#include <class_draw_panel_gal.h>
2014-03-19 12:42:46 +00:00
#include <view/view.h>
#include <pcbnew.h>
#include <drc_stuff.h>
#include <dialog_drc.h>
#include <wx/progdlg.h>
2007-11-27 01:34:35 +00:00
2007-12-01 03:42:52 +00:00
void DRC::ShowDialog()
{
if( !m_ui )
{
m_ui = new DIALOG_DRC_CONTROL( this, m_mainWindow );
2007-12-04 18:23:38 +00:00
updatePointers();
2008-02-09 08:34:45 +00:00
2007-12-04 18:23:38 +00:00
// copy data retained in this DRC object into the m_ui DrcPanel:
2008-02-09 08:34:45 +00:00
PutValueInLocalUnits( *m_ui->m_SetTrackMinWidthCtrl,
m_pcb->GetDesignSettings().m_TrackMinWidth );
PutValueInLocalUnits( *m_ui->m_SetViaMinSizeCtrl,
m_pcb->GetDesignSettings().m_ViasMinSize );
PutValueInLocalUnits( *m_ui->m_SetMicroViakMinSizeCtrl,
m_pcb->GetDesignSettings().m_MicroViasMinSize );
2007-12-01 03:42:52 +00:00
2007-12-04 18:23:38 +00:00
m_ui->m_CreateRptCtrl->SetValue( m_doCreateRptFile );
m_ui->m_RptFilenameCtrl->SetValue( m_rptFilename );
}
else
updatePointers();
2008-02-09 08:34:45 +00:00
m_ui->Show( true );
2007-12-01 03:42:52 +00:00
}
2007-12-04 18:23:38 +00:00
void DRC::DestroyDialog( int aReason )
2007-12-01 03:42:52 +00:00
{
2007-12-03 05:14:51 +00:00
if( m_ui )
2007-12-01 03:42:52 +00:00
{
2007-12-04 18:23:38 +00:00
if( aReason == wxID_OK )
{
2008-02-09 08:34:45 +00:00
// if user clicked OK, save his choices in this DRC object.
m_doCreateRptFile = m_ui->m_CreateRptCtrl->GetValue();
m_rptFilename = m_ui->m_RptFilenameCtrl->GetValue();
2007-12-04 18:23:38 +00:00
}
2008-02-09 08:34:45 +00:00
2007-12-03 05:14:51 +00:00
m_ui->Destroy();
m_ui = 0;
2007-12-01 03:42:52 +00:00
}
}
2007-11-27 01:34:35 +00:00
DRC::DRC( PCB_EDIT_FRAME* aPcbWindow )
2007-12-01 03:42:52 +00:00
{
m_mainWindow = aPcbWindow;
m_pcb = aPcbWindow->GetBoard();
m_ui = 0;
2007-12-01 03:42:52 +00:00
2008-02-09 08:34:45 +00:00
// establish initial values for everything:
m_doPad2PadTest = true; // enable pad to pad clearance tests
m_doUnconnectedTest = true; // enable unconnected tests
m_doZonesTest = true; // enable zone to items clearance tests
2008-02-09 08:34:45 +00:00
m_doCreateRptFile = false;
2007-11-27 01:34:35 +00:00
2007-12-01 03:42:52 +00:00
// m_rptFilename set to empty by its constructor
m_currentMarker = NULL;
2008-02-09 08:34:45 +00:00
m_segmAngle = 0;
2007-12-01 03:42:52 +00:00
m_segmLength = 0;
2008-02-09 08:34:45 +00:00
2007-12-01 03:42:52 +00:00
m_xcliplo = 0;
m_ycliplo = 0;
m_xcliphi = 0;
m_ycliphi = 0;
}
2007-12-04 18:23:38 +00:00
DRC::~DRC()
{
2008-02-09 08:34:45 +00:00
// maybe someday look at pointainer.h <- google for "pointainer.h"
for( unsigned i = 0; i<m_unconnected.size(); ++i )
2007-12-04 18:23:38 +00:00
delete m_unconnected[i];
}
2007-12-01 03:42:52 +00:00
2007-12-01 03:42:52 +00:00
int DRC::Drc( TRACK* aRefSegm, TRACK* aList )
{
2007-12-01 03:42:52 +00:00
updatePointers();
2008-02-09 08:34:45 +00:00
if( !doTrackDrc( aRefSegm, aList, true ) )
2007-08-08 20:51:08 +00:00
{
2007-12-01 05:37:44 +00:00
wxASSERT( m_currentMarker );
2008-02-09 08:34:45 +00:00
m_mainWindow->SetMsgPanel( m_currentMarker );
2007-12-01 03:42:52 +00:00
return BAD_DRC;
2007-08-08 20:51:08 +00:00
}
2008-02-09 08:34:45 +00:00
if( !doTrackKeepoutDrc( aRefSegm ) )
{
wxASSERT( m_currentMarker );
m_mainWindow->SetMsgPanel( m_currentMarker );
return BAD_DRC;
}
2007-12-01 03:42:52 +00:00
return OK_DRC;
}
2007-08-08 20:51:08 +00:00
2010-12-29 17:47:32 +00:00
int DRC::Drc( ZONE_CONTAINER* aArea, int aCornerIndex )
{
updatePointers();
2008-02-09 08:34:45 +00:00
2010-12-29 17:47:32 +00:00
if( !doEdgeZoneDrc( aArea, aCornerIndex ) )
{
wxASSERT( m_currentMarker );
m_mainWindow->SetMsgPanel( m_currentMarker );
return BAD_DRC;
}
2008-02-09 08:34:45 +00:00
return OK_DRC;
}
void DRC::RunTests( wxTextCtrl* aMessages )
2007-12-01 03:42:52 +00:00
{
// Ensure ratsnest is up to date:
if( (m_pcb->m_Status_Pcb & LISTE_RATSNEST_ITEM_OK) == 0 )
{
2009-09-10 15:22:26 +00:00
if( aMessages )
{
aMessages->AppendText( _( "Compile ratsnest...\n" ) );
2009-09-10 15:22:26 +00:00
wxSafeYield();
}
m_mainWindow->Compile_Ratsnest( NULL, true );
}
2007-12-04 18:23:38 +00:00
// someone should have cleared the two lists before calling this.
2008-02-09 08:34:45 +00:00
2009-09-10 15:22:26 +00:00
if( !testNetClasses() )
{
// testing the netclasses is a special case because if the netclasses
2012-02-06 05:44:19 +00:00
// do not pass the BOARD_DESIGN_SETTINGS checks, then every member of a net
2009-09-10 15:22:26 +00:00
// class (a NET) will cause its items such as tracks, vias, and pads
// to also fail. So quit after *all* netclass errors have been reported.
if( aMessages )
aMessages->AppendText( _( "Aborting\n" ) );
2009-09-10 15:22:26 +00:00
// update the m_ui listboxes
updatePointers();
return;
}
2007-12-01 03:42:52 +00:00
// test pad to pad clearances, nothing to do with tracks, vias or zones.
if( m_doPad2PadTest )
{
2009-09-10 15:22:26 +00:00
if( aMessages )
{
aMessages->AppendText( _( "Pad clearances...\n" ) );
2009-09-10 15:22:26 +00:00
wxSafeYield();
}
2007-12-01 03:42:52 +00:00
testPad2Pad();
}
2007-12-01 03:42:52 +00:00
2007-12-01 05:37:44 +00:00
// test track and via clearances to other tracks, pads, and vias
2009-09-10 15:22:26 +00:00
if( aMessages )
{
aMessages->AppendText( _( "Track clearances...\n" ) );
2009-09-10 15:22:26 +00:00
wxSafeYield();
}
testTracks( true );
2007-12-01 03:42:52 +00:00
// Before testing segments and unconnected, refill all zones:
// this is a good caution, because filled areas can be outdated.
2009-09-10 15:22:26 +00:00
if( aMessages )
{
aMessages->AppendText( _( "Fill zones...\n" ) );
2009-09-10 15:22:26 +00:00
wxSafeYield();
}
m_mainWindow->Fill_All_Zones( aMessages ? aMessages->GetParent() : m_mainWindow,
false );
// test zone clearances to other zones
if( aMessages )
2009-09-10 15:22:26 +00:00
{
aMessages->AppendText( _( "Test zones...\n" ) );
2009-09-10 15:22:26 +00:00
wxSafeYield();
}
testZones();
2007-12-01 03:42:52 +00:00
2008-02-09 08:34:45 +00:00
// find and gather unconnected pads.
2007-12-01 03:42:52 +00:00
if( m_doUnconnectedTest )
{
2009-09-10 15:22:26 +00:00
if( aMessages )
{
aMessages->AppendText( _( "Unconnected pads...\n" ) );
aMessages->Refresh();
2009-09-10 15:22:26 +00:00
}
2007-12-01 03:42:52 +00:00
testUnconnected();
}
2008-02-09 08:34:45 +00:00
// find and gather vias, tracks, pads inside keepout areas.
if( m_doKeepoutTest )
{
if( aMessages )
{
aMessages->AppendText( _( "Keepout areas ...\n" ) );
aMessages->Refresh();
}
testKeepoutAreas();
}
2007-12-04 18:23:38 +00:00
// update the m_ui listboxes
2007-12-03 05:14:51 +00:00
updatePointers();
2009-09-10 15:22:26 +00:00
if( aMessages )
{
// no newline on this one because it is last, don't want the window
// to unnecessarily scroll.
aMessages->AppendText( _( "Finished" ) );
2009-09-10 15:22:26 +00:00
}
2007-12-03 05:14:51 +00:00
}
void DRC::ListUnconnectedPads()
{
testUnconnected();
2008-02-09 08:34:45 +00:00
2007-12-04 18:23:38 +00:00
// update the m_ui listboxes
updatePointers();
2007-12-01 03:42:52 +00:00
}
2007-12-03 05:14:51 +00:00
void DRC::updatePointers()
{
// update my pointers, m_mainWindow is the only unchangeable one
m_pcb = m_mainWindow->GetBoard();
2007-12-04 18:23:38 +00:00
if( m_ui ) // Use diag list boxes only in DRC dialog
2008-02-09 08:34:45 +00:00
{
m_ui->m_ClearanceListBox->SetList( new DRC_LIST_MARKERS( m_pcb ) );
m_ui->m_UnconnectedListBox->SetList( new DRC_LIST_UNCONNECTED( &m_unconnected ) );
}
2007-12-03 05:14:51 +00:00
}
2008-02-09 08:34:45 +00:00
2007-12-03 05:14:51 +00:00
bool DRC::doNetClass( NETCLASSPTR nc, wxString& msg )
2009-09-10 15:22:26 +00:00
{
bool ret = true;
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
const BOARD_DESIGN_SETTINGS& g = m_pcb->GetDesignSettings();
2009-09-10 15:22:26 +00:00
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
#define FmtVal( x ) GetChars( StringFromValue( g_UserUnit, x ) )
2009-09-10 15:22:26 +00:00
#if 0 // set to 1 when (if...) BOARD_DESIGN_SETTINGS has a m_MinClearance value
if( nc->GetClearance() < g.m_MinClearance )
2009-09-10 15:22:26 +00:00
{
msg.Printf( _( "NETCLASS: '%s' has Clearance:%s which is less than global:%s" ),
GetChars( nc->GetName() ),
FmtVal( nc->GetClearance() ),
FmtVal( g.m_TrackClearance )
);
2009-09-10 15:22:26 +00:00
m_currentMarker = fillMarker( DRCE_NETCLASS_CLEARANCE, msg, m_currentMarker );
m_pcb->Add( m_currentMarker );
2014-03-19 12:42:46 +00:00
m_mainWindow->GetGalCanvas()->GetView()->Add( m_currentMarker );
2009-09-10 15:22:26 +00:00
m_currentMarker = 0;
ret = false;
}
#endif
2009-09-10 15:22:26 +00:00
if( nc->GetTrackWidth() < g.m_TrackMinWidth )
2009-09-10 15:22:26 +00:00
{
msg.Printf( _( "NETCLASS: '%s' has TrackWidth:%s which is less than global:%s" ),
GetChars( nc->GetName() ),
FmtVal( nc->GetTrackWidth() ),
FmtVal( g.m_TrackMinWidth )
);
2009-09-10 15:22:26 +00:00
m_currentMarker = fillMarker( DRCE_NETCLASS_TRACKWIDTH, msg, m_currentMarker );
m_pcb->Add( m_currentMarker );
2014-03-19 12:42:46 +00:00
m_mainWindow->GetGalCanvas()->GetView()->Add( m_currentMarker );
2009-09-10 15:22:26 +00:00
m_currentMarker = 0;
ret = false;
}
if( nc->GetViaDiameter() < g.m_ViasMinSize )
2009-09-10 15:22:26 +00:00
{
msg.Printf( _( "NETCLASS: '%s' has Via Dia:%s which is less than global:%s" ),
GetChars( nc->GetName() ),
FmtVal( nc->GetViaDiameter() ),
FmtVal( g.m_ViasMinSize )
);
2009-09-10 15:22:26 +00:00
m_currentMarker = fillMarker( DRCE_NETCLASS_VIASIZE, msg, m_currentMarker );
m_pcb->Add( m_currentMarker );
2014-03-19 12:42:46 +00:00
m_mainWindow->GetGalCanvas()->GetView()->Add( m_currentMarker );
2009-09-10 15:22:26 +00:00
m_currentMarker = 0;
ret = false;
}
if( nc->GetViaDrill() < g.m_ViasMinDrill )
2009-09-10 15:22:26 +00:00
{
msg.Printf( _( "NETCLASS: '%s' has Via Drill:%s which is less than global:%s" ),
GetChars( nc->GetName() ),
FmtVal( nc->GetViaDrill() ),
FmtVal( g.m_ViasMinDrill )
);
2009-09-10 15:22:26 +00:00
m_currentMarker = fillMarker( DRCE_NETCLASS_VIADRILLSIZE, msg, m_currentMarker );
m_pcb->Add( m_currentMarker );
2014-03-19 12:42:46 +00:00
m_mainWindow->GetGalCanvas()->GetView()->Add( m_currentMarker );
2009-09-10 15:22:26 +00:00
m_currentMarker = 0;
ret = false;
}
if( nc->GetuViaDiameter() < g.m_MicroViasMinSize )
2009-09-10 15:22:26 +00:00
{
msg.Printf( _( "NETCLASS: '%s' has uVia Dia:%s which is less than global:%s" ),
GetChars( nc->GetName() ),
FmtVal( nc->GetuViaDiameter() ),
FmtVal( g.m_MicroViasMinSize )
);
2009-09-10 15:22:26 +00:00
m_currentMarker = fillMarker( DRCE_NETCLASS_uVIASIZE, msg, m_currentMarker );
m_pcb->Add( m_currentMarker );
2014-03-19 12:42:46 +00:00
m_mainWindow->GetGalCanvas()->GetView()->Add( m_currentMarker );
2009-09-10 15:22:26 +00:00
m_currentMarker = 0;
ret = false;
}
if( nc->GetuViaDrill() < g.m_MicroViasMinDrill )
2009-09-10 15:22:26 +00:00
{
msg.Printf( _( "NETCLASS: '%s' has uVia Drill:%s which is less than global:%s" ),
GetChars( nc->GetName() ),
FmtVal( nc->GetuViaDrill() ),
FmtVal( g.m_MicroViasMinDrill )
);
2009-09-10 15:22:26 +00:00
m_currentMarker = fillMarker( DRCE_NETCLASS_uVIADRILLSIZE, msg, m_currentMarker );
m_pcb->Add( m_currentMarker );
2014-03-19 12:42:46 +00:00
m_mainWindow->GetGalCanvas()->GetView()->Add( m_currentMarker );
2009-09-10 15:22:26 +00:00
m_currentMarker = 0;
ret = false;
}
return ret;
}
bool DRC::testNetClasses()
{
bool ret = true;
2009-09-10 15:22:26 +00:00
NETCLASSES& netclasses = m_pcb->GetDesignSettings().m_NetClasses;
2009-09-10 15:22:26 +00:00
wxString msg; // construct this only once here, not in a loop, since somewhat expensive.
if( !doNetClass( netclasses.GetDefault(), msg ) )
ret = false;
for( NETCLASSES::const_iterator i = netclasses.begin(); i != netclasses.end(); ++i )
{
NETCLASSPTR nc = i->second;
2009-09-10 15:22:26 +00:00
if( !doNetClass( nc, msg ) )
ret = false;
}
return ret;
}
2007-12-01 03:42:52 +00:00
void DRC::testPad2Pad()
{
2008-03-18 04:04:17 +00:00
std::vector<D_PAD*> sortedPads;
m_pcb->GetSortedPadListByXthenYCoord( sortedPads );
2007-12-01 03:42:52 +00:00
// find the max size of the pads (used to stop the test)
int max_size = 0;
2008-03-18 04:04:17 +00:00
for( unsigned i = 0; i < sortedPads.size(); ++i )
2007-12-01 03:42:52 +00:00
{
2008-03-18 04:04:17 +00:00
D_PAD* pad = sortedPads[i];
2012-02-19 04:02:19 +00:00
// GetBoundingRadius() is the radius of the minimum sized circle fully containing the pad
int radius = pad->GetBoundingRadius();
if( radius > max_size )
max_size = radius;
2007-12-01 03:42:52 +00:00
}
// Test the pads
2008-03-18 04:04:17 +00:00
D_PAD** listEnd = &sortedPads[ sortedPads.size() ];
for( unsigned i = 0; i< sortedPads.size(); ++i )
2007-12-01 03:42:52 +00:00
{
2008-03-18 04:04:17 +00:00
D_PAD* pad = sortedPads[i];
2008-02-09 08:34:45 +00:00
int x_limit = max_size + pad->GetClearance() +
2012-02-19 04:02:19 +00:00
pad->GetBoundingRadius() + pad->GetPosition().x;
2009-09-10 15:22:26 +00:00
if( !doPadToPadsDrc( pad, &sortedPads[i], listEnd, x_limit ) )
2007-11-27 01:34:35 +00:00
{
2007-12-01 03:42:52 +00:00
wxASSERT( m_currentMarker );
m_pcb->Add( m_currentMarker );
2014-03-19 12:42:46 +00:00
m_mainWindow->GetGalCanvas()->GetView()->Add( m_currentMarker );
2008-02-09 08:34:45 +00:00
m_currentMarker = 0;
2007-11-27 01:34:35 +00:00
}
2007-12-01 03:42:52 +00:00
}
}
2007-11-27 01:34:35 +00:00
void DRC::testTracks( bool aShowProgressBar )
{
wxProgressDialog * progressDialog = NULL;
const int delta = 500; // This is the number of tests between 2 calls to the
// progress bar
int count = 0;
for( TRACK* segm = m_pcb->m_Track; segm && segm->Next(); segm = segm->Next() )
count++;
int deltamax = count/delta;
if( aShowProgressBar && deltamax > 3 )
{
progressDialog = new wxProgressDialog( _( "Track clearances" ), wxEmptyString,
deltamax, m_mainWindow,
wxPD_AUTO_HIDE | wxPD_CAN_ABORT );
progressDialog->Update( 0, wxEmptyString );
}
int ii = 0;
count = 0;
for( TRACK* segm = m_pcb->m_Track; segm && segm->Next(); segm = segm->Next() )
{
if ( ii++ > delta )
{
ii = 0;
count++;
if( progressDialog )
{
if( !progressDialog->Update( count, wxEmptyString ) )
break; // Aborted by user
}
}
if( !doTrackDrc( segm, segm->Next(), true ) )
{
wxASSERT( m_currentMarker );
m_pcb->Add( m_currentMarker );
2014-03-19 12:42:46 +00:00
m_mainWindow->GetGalCanvas()->GetView()->Add( m_currentMarker );
m_currentMarker = 0;
}
}
if( progressDialog )
progressDialog->Destroy();
}
2007-12-01 03:42:52 +00:00
void DRC::testUnconnected()
{
if( (m_pcb->m_Status_Pcb & LISTE_RATSNEST_ITEM_OK) == 0 )
2007-12-01 03:42:52 +00:00
{
wxClientDC dc( m_mainWindow->GetCanvas() );
m_mainWindow->Compile_Ratsnest( &dc, true );
2007-12-01 03:42:52 +00:00
}
2008-02-09 08:34:45 +00:00
if( m_pcb->GetRatsnestsCount() == 0 )
2007-12-01 03:42:52 +00:00
return;
2007-11-27 01:34:35 +00:00
wxString msg;
for( unsigned ii = 0; ii < m_pcb->GetRatsnestsCount(); ++ii )
2007-12-01 03:42:52 +00:00
{
RATSNEST_ITEM& rat = m_pcb->m_FullRatsnest[ii];
if( (rat.m_Status & CH_ACTIF) == 0 )
2007-12-01 03:42:52 +00:00
continue;
2007-08-08 20:51:08 +00:00
D_PAD* padStart = rat.m_PadStart;
D_PAD* padEnd = rat.m_PadEnd;
2007-11-27 01:34:35 +00:00
msg = padStart->GetSelectMenuText() + wxT( " net " ) + padStart->GetNetname();
DRC_ITEM* uncItem = new DRC_ITEM( DRCE_UNCONNECTED_PADS,
msg,
padEnd->GetSelectMenuText(),
padStart->GetPosition(), padEnd->GetPosition() );
2008-02-09 08:34:45 +00:00
2007-12-04 18:23:38 +00:00
m_unconnected.push_back( uncItem );
2007-12-01 03:42:52 +00:00
}
}
2007-11-27 01:34:35 +00:00
void DRC::testZones()
2007-12-01 03:42:52 +00:00
{
// Test copper areas for valid netcodes
2008-02-09 08:34:45 +00:00
// if a netcode is < 0 the netname was not found when reading a netlist
// if a netcode is == 0 the netname is void, and the zone is not connected.
// This is allowed, but i am not sure this is a good idea
2008-02-09 08:34:45 +00:00
for( int ii = 0; ii < m_pcb->GetAreaCount(); ii++ )
{
ZONE_CONTAINER* test_area = m_pcb->GetArea( ii );
if( !test_area->IsOnCopperLayer() )
continue;
if( test_area->GetNetCode() < 0 )
2008-02-09 08:34:45 +00:00
{
m_currentMarker = fillMarker( test_area,
DRCE_NON_EXISTANT_NET_FOR_ZONE_OUTLINE, m_currentMarker );
2008-02-09 08:34:45 +00:00
m_pcb->Add( m_currentMarker );
2014-03-19 12:42:46 +00:00
m_mainWindow->GetGalCanvas()->GetView()->Add( m_currentMarker );
2008-02-09 08:34:45 +00:00
m_currentMarker = 0;
}
}
// Test copper areas outlines, and create markers when needed
m_pcb->Test_Drc_Areas_Outlines_To_Areas_Outlines( NULL, true );
2007-12-01 03:42:52 +00:00
}
2007-08-08 20:51:08 +00:00
2007-12-01 03:42:52 +00:00
void DRC::testKeepoutAreas()
{
// Test keepout areas for vias, tracks and pads inside keepout areas
for( int ii = 0; ii < m_pcb->GetAreaCount(); ii++ )
{
ZONE_CONTAINER* area = m_pcb->GetArea( ii );
if( !area->GetIsKeepout() )
continue;
for( TRACK* segm = m_pcb->m_Track; segm != NULL; segm = segm->Next() )
{
if( segm->Type() == PCB_TRACE_T )
{
if( ! area->GetDoNotAllowTracks() )
continue;
if( segm->GetLayer() != area->GetLayer() )
continue;
if( area->Outline()->Distance( segm->GetStart(), segm->GetEnd(),
segm->GetWidth() ) == 0 )
{
m_currentMarker = fillMarker( segm, NULL,
DRCE_TRACK_INSIDE_KEEPOUT, m_currentMarker );
m_pcb->Add( m_currentMarker );
2014-03-19 12:42:46 +00:00
m_mainWindow->GetGalCanvas()->GetView()->Add( m_currentMarker );
m_currentMarker = 0;
}
}
else if( segm->Type() == PCB_VIA_T )
{
if( ! area->GetDoNotAllowVias() )
continue;
if( ! ((VIA*)segm)->IsOnLayer( area->GetLayer() ) )
continue;
if( area->Outline()->Distance( segm->GetPosition() ) < segm->GetWidth()/2 )
{
m_currentMarker = fillMarker( segm, NULL,
DRCE_VIA_INSIDE_KEEPOUT, m_currentMarker );
m_pcb->Add( m_currentMarker );
2014-03-19 12:42:46 +00:00
m_mainWindow->GetGalCanvas()->GetView()->Add( m_currentMarker );
m_currentMarker = 0;
}
}
}
// Test pads: TODO
}
}
bool DRC::doTrackKeepoutDrc( TRACK* aRefSeg )
{
// Test keepout areas for vias, tracks and pads inside keepout areas
for( int ii = 0; ii < m_pcb->GetAreaCount(); ii++ )
{
ZONE_CONTAINER* area = m_pcb->GetArea( ii );
if( !area->GetIsKeepout() )
continue;
if( aRefSeg->Type() == PCB_TRACE_T )
{
if( ! area->GetDoNotAllowTracks() )
continue;
if( aRefSeg->GetLayer() != area->GetLayer() )
continue;
if( area->Outline()->Distance( aRefSeg->GetStart(), aRefSeg->GetEnd(),
aRefSeg->GetWidth() ) == 0 )
{
m_currentMarker = fillMarker( aRefSeg, NULL,
DRCE_TRACK_INSIDE_KEEPOUT, m_currentMarker );
return false;
}
}
else if( aRefSeg->Type() == PCB_VIA_T )
{
if( ! area->GetDoNotAllowVias() )
continue;
if( ! ((VIA*)aRefSeg)->IsOnLayer( area->GetLayer() ) )
continue;
if( area->Outline()->Distance( aRefSeg->GetPosition() ) < aRefSeg->GetWidth()/2 )
{
m_currentMarker = fillMarker( aRefSeg, NULL,
DRCE_VIA_INSIDE_KEEPOUT, m_currentMarker );
return false;
}
}
}
return true;
}
bool DRC::doPadToPadsDrc( D_PAD* aRefPad, D_PAD** aStart, D_PAD** aEnd, int x_limit )
2007-12-01 03:42:52 +00:00
{
LAYER_MSK layerMask = aRefPad->GetLayerMask() & ALL_CU_LAYERS;
/* used to test DRC pad to holes: this dummy pad has the size and shape of the hole
* to test pad to pad hole DRC, using the pad to pad DRC test function.
* Therefore, this dummy pad is a circle or an oval.
* A pad must have a parent because some functions expect a non null parent
* to find the parent board, and some other data
*/
MODULE dummymodule( m_pcb ); // Creates a dummy parent
D_PAD dummypad( &dummymodule );
2012-02-19 04:02:19 +00:00
// Ensure the hole is on all copper layers
dummypad.SetLayerMask( ALL_CU_LAYERS | dummypad.GetLayerMask() );
// Use the minimal local clearance value for the dummy pad.
// The clearance of the active pad will be used as minimum distance to a hole
// (a value = 0 means use netclass value)
dummypad.SetLocalClearance( 1 );
2008-02-09 08:34:45 +00:00
for( D_PAD** pad_list = aStart; pad_list<aEnd; ++pad_list )
2007-12-01 03:42:52 +00:00
{
D_PAD* pad = *pad_list;
2007-12-01 03:42:52 +00:00
if( pad == aRefPad )
continue;
2012-02-19 04:02:19 +00:00
// We can stop the test when pad->GetPosition().x > x_limit
2009-09-10 15:22:26 +00:00
// because the list is sorted by X values
2012-02-19 04:02:19 +00:00
if( pad->GetPosition().x > x_limit )
2007-12-01 03:42:52 +00:00
break;
2009-09-10 15:22:26 +00:00
// No problem if pads are on different copper layers,
// but their hole (if any ) can create DRC error because they are on all
2009-09-10 15:22:26 +00:00
// copper layers, so we test them
2012-02-19 04:02:19 +00:00
if( ( pad->GetLayerMask() & layerMask ) == 0 )
{
2009-09-10 15:22:26 +00:00
// if holes are in the same location and have the same size and shape,
// this can be accepted
if( pad->GetPosition() == aRefPad->GetPosition()
2012-02-19 04:02:19 +00:00
&& pad->GetDrillSize() == aRefPad->GetDrillSize()
&& pad->GetDrillShape() == aRefPad->GetDrillShape() )
{
if( aRefPad->GetDrillShape() == PAD_DRILL_CIRCLE )
continue;
// for oval holes: must also have the same orientation
2012-02-19 04:02:19 +00:00
if( pad->GetOrientation() == aRefPad->GetOrientation() )
continue;
}
/* Here, we must test clearance between holes and pads
* dummy pad size and shape is adjusted to pad drill size and shape
*/
2012-02-19 04:02:19 +00:00
if( pad->GetDrillSize().x )
{
// pad under testing has a hole, test this hole against pad reference
dummypad.SetPosition( pad->GetPosition() );
2012-02-19 04:02:19 +00:00
dummypad.SetSize( pad->GetDrillSize() );
dummypad.SetShape( pad->GetDrillShape() == PAD_DRILL_OBLONG ?
PAD_OVAL : PAD_CIRCLE );
2012-02-19 04:02:19 +00:00
dummypad.SetOrientation( pad->GetOrientation() );
2009-09-10 15:22:26 +00:00
if( !checkClearancePadToPad( aRefPad, &dummypad ) )
{
// here we have a drc error on pad!
m_currentMarker = fillMarker( pad, aRefPad,
DRCE_HOLE_NEAR_PAD, m_currentMarker );
return false;
}
}
2009-09-10 15:22:26 +00:00
2012-02-19 04:02:19 +00:00
if( aRefPad->GetDrillSize().x ) // pad reference has a hole
{
dummypad.SetPosition( aRefPad->GetPosition() );
2012-02-19 04:02:19 +00:00
dummypad.SetSize( aRefPad->GetDrillSize() );
dummypad.SetShape( aRefPad->GetDrillShape() == PAD_DRILL_OBLONG ?
PAD_OVAL : PAD_CIRCLE );
2012-02-19 04:02:19 +00:00
dummypad.SetOrientation( aRefPad->GetOrientation() );
2009-09-10 15:22:26 +00:00
if( !checkClearancePadToPad( pad, &dummypad ) )
{
// here we have a drc error on aRefPad!
m_currentMarker = fillMarker( aRefPad, pad,
DRCE_HOLE_NEAR_PAD, m_currentMarker );
return false;
}
}
2007-12-01 03:42:52 +00:00
continue;
}
2007-12-01 03:42:52 +00:00
2009-09-10 15:22:26 +00:00
// The pad must be in a net (i.e pt_pad->GetNet() != 0 ),
// But no problem if pads have the same netcode (same net)
if( pad->GetNetCode() && ( aRefPad->GetNetCode() == pad->GetNetCode() ) )
2007-12-01 03:42:52 +00:00
continue;
2009-09-10 15:22:26 +00:00
// if pads are from the same footprint
if( pad->GetParent() == aRefPad->GetParent() )
{
// and have the same pad number ( equivalent pads )
// one can argue that this 2nd test is not necessary, that any
// two pads from a single module are acceptable. This 2nd test
// should eventually be a configuration option.
2011-12-16 17:03:25 +00:00
if( pad->PadNameEqual( aRefPad ) )
2009-09-10 15:22:26 +00:00
continue;
}
2007-12-01 03:42:52 +00:00
2009-09-10 15:22:26 +00:00
if( !checkClearancePadToPad( aRefPad, pad ) )
2007-12-01 03:42:52 +00:00
{
// here we have a drc error!
m_currentMarker = fillMarker( aRefPad, pad, DRCE_PAD_NEAR_PAD1, m_currentMarker );
2007-12-01 03:42:52 +00:00
return false;
}
}
return true;
}