2011-09-30 18:15:37 +00:00
|
|
|
/**
|
|
|
|
* @file drc_marker_functions.cpp
|
2011-09-23 20:00:30 +00:00
|
|
|
*/
|
2011-09-30 18:15:37 +00:00
|
|
|
|
2011-09-23 20:00:30 +00:00
|
|
|
/*
|
2011-09-30 18:15:37 +00:00
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
2011-09-23 20:00:30 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Dick Hollenbeck, dick@softplc.com
|
2017-03-16 17:09:33 +00:00
|
|
|
* Copyright (C) 2004-2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2018-01-28 21:02:31 +00:00
|
|
|
* Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-09-23 20:00:30 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/* Methods of class DRC to initialize drc markers with messages
|
2015-06-18 13:19:30 +00:00
|
|
|
* according to items and error code
|
2011-09-23 20:00:30 +00:00
|
|
|
*/
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <pcbnew.h>
|
2018-02-02 20:57:12 +00:00
|
|
|
#include <board_design_settings.h>
|
2018-08-27 13:50:50 +00:00
|
|
|
#include <geometry/geometry_utils.h>
|
2018-08-23 22:41:57 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2018-01-28 21:02:31 +00:00
|
|
|
#include <drc.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_pad.h>
|
|
|
|
#include <class_track.h>
|
|
|
|
#include <class_zone.h>
|
|
|
|
#include <class_marker_pcb.h>
|
2014-08-13 15:47:02 +00:00
|
|
|
#include <class_pcb_text.h>
|
2018-08-23 22:41:57 +00:00
|
|
|
#include <class_text_mod.h>
|
|
|
|
#include <class_edge_mod.h>
|
2018-01-28 09:35:33 +00:00
|
|
|
#include <class_board_item.h>
|
2011-09-23 20:00:30 +00:00
|
|
|
|
|
|
|
|
2018-08-27 13:50:50 +00:00
|
|
|
const int EPSILON = Mils2iu( 5 );
|
|
|
|
|
|
|
|
|
|
|
|
MARKER_PCB* DRC::newMarker( TRACK* aTrack, ZONE_CONTAINER* aConflictZone, int aErrorCode )
|
2011-09-23 20:00:30 +00:00
|
|
|
{
|
2018-09-11 23:26:48 +00:00
|
|
|
SHAPE_POLY_SET* conflictOutline;
|
|
|
|
|
|
|
|
if( aConflictZone->IsFilled() )
|
|
|
|
conflictOutline = const_cast<SHAPE_POLY_SET*>( &aConflictZone->GetFilledPolysList() );
|
|
|
|
else
|
|
|
|
conflictOutline = aConflictZone->Outline();
|
|
|
|
|
2018-08-27 13:50:50 +00:00
|
|
|
wxPoint markerPos;
|
|
|
|
wxPoint pt1 = aTrack->GetPosition();
|
|
|
|
wxPoint pt2 = aTrack->GetEnd();
|
2018-08-23 22:41:57 +00:00
|
|
|
|
2018-08-27 13:50:50 +00:00
|
|
|
// If the mid-point is in the zone, then that's a fine place for the marker
|
|
|
|
if( conflictOutline->Distance( ( pt1 + pt2 ) / 2 ) == 0 )
|
|
|
|
markerPos = ( pt1 + pt2 ) / 2;
|
2011-09-23 20:00:30 +00:00
|
|
|
|
2018-08-27 13:50:50 +00:00
|
|
|
// Otherwise do a binary search for a "good enough" marker location
|
|
|
|
else
|
2011-09-23 20:00:30 +00:00
|
|
|
{
|
2018-08-27 13:50:50 +00:00
|
|
|
while( GetLineLength( pt1, pt2 ) > EPSILON )
|
2011-09-23 20:00:30 +00:00
|
|
|
{
|
2018-08-27 13:50:50 +00:00
|
|
|
if( conflictOutline->Distance( pt1 ) < conflictOutline->Distance( pt2 ) )
|
|
|
|
pt2 = ( pt1 + pt2 ) / 2;
|
2018-08-23 22:41:57 +00:00
|
|
|
else
|
2018-08-27 13:50:50 +00:00
|
|
|
pt1 = ( pt1 + pt2 ) / 2;
|
2014-08-13 15:47:02 +00:00
|
|
|
}
|
2011-09-23 20:00:30 +00:00
|
|
|
|
2018-08-27 13:50:50 +00:00
|
|
|
// Once we're within EPSILON pt1 and pt2 are "equivalent"
|
|
|
|
markerPos = pt1;
|
|
|
|
}
|
2011-09-23 20:00:30 +00:00
|
|
|
|
2018-08-27 13:50:50 +00:00
|
|
|
return new MARKER_PCB( m_pcbEditorFrame->GetUserUnits(), aErrorCode, markerPos,
|
|
|
|
aTrack, aTrack->GetPosition(),
|
|
|
|
aConflictZone, aConflictZone->GetPosition() );
|
2011-09-23 20:00:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-27 13:50:50 +00:00
|
|
|
MARKER_PCB* DRC::newMarker( TRACK* aTrack, BOARD_ITEM* aConflitItem, const SEG& aConflictSeg,
|
|
|
|
int aErrorCode )
|
2011-09-23 20:00:30 +00:00
|
|
|
{
|
2018-08-27 13:50:50 +00:00
|
|
|
wxPoint markerPos;
|
|
|
|
wxPoint pt1 = aTrack->GetPosition();
|
|
|
|
wxPoint pt2 = aTrack->GetEnd();
|
2014-08-13 15:47:02 +00:00
|
|
|
|
2018-08-27 13:50:50 +00:00
|
|
|
// Do a binary search along the track for a "good enough" marker location
|
|
|
|
while( GetLineLength( pt1, pt2 ) > EPSILON )
|
2014-08-13 15:47:02 +00:00
|
|
|
{
|
2018-08-27 13:50:50 +00:00
|
|
|
if( aConflictSeg.Distance( pt1 ) < aConflictSeg.Distance( pt2 ) )
|
|
|
|
pt2 = ( pt1 + pt2 ) / 2;
|
|
|
|
else
|
|
|
|
pt1 = ( pt1 + pt2 ) / 2;
|
2014-08-13 15:47:02 +00:00
|
|
|
}
|
2011-09-23 20:00:30 +00:00
|
|
|
|
2018-08-27 13:50:50 +00:00
|
|
|
// Once we're within EPSILON pt1 and pt2 are "equivalent"
|
|
|
|
markerPos = pt1;
|
2011-09-23 20:00:30 +00:00
|
|
|
|
2018-08-27 13:50:50 +00:00
|
|
|
return new MARKER_PCB( m_pcbEditorFrame->GetUserUnits(), aErrorCode, markerPos,
|
|
|
|
aTrack, aTrack->GetPosition(),
|
|
|
|
aConflitItem, aConflitItem->GetPosition() );
|
2011-09-23 20:00:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-27 13:50:50 +00:00
|
|
|
MARKER_PCB* DRC::newMarker( D_PAD* aPad, BOARD_ITEM* aConflictItem, int aErrorCode )
|
2011-09-23 20:00:30 +00:00
|
|
|
{
|
2018-08-27 13:50:50 +00:00
|
|
|
return new MARKER_PCB( m_pcbEditorFrame->GetUserUnits(), aErrorCode, aPad->GetPosition(),
|
|
|
|
aPad, aPad->GetPosition(),
|
|
|
|
aConflictItem, aConflictItem->GetPosition() );
|
2011-09-23 20:00:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-27 13:50:50 +00:00
|
|
|
MARKER_PCB* DRC::newMarker(const wxPoint &aPos, BOARD_ITEM *aItem, int aErrorCode )
|
2011-09-23 20:00:30 +00:00
|
|
|
{
|
2018-08-27 13:50:50 +00:00
|
|
|
return new MARKER_PCB( m_pcbEditorFrame->GetUserUnits(), aErrorCode, aPos,
|
|
|
|
aItem, aItem->GetPosition(), nullptr, wxPoint() );
|
|
|
|
}
|
2018-08-23 22:41:57 +00:00
|
|
|
|
2011-09-23 20:00:30 +00:00
|
|
|
|
2018-08-27 13:50:50 +00:00
|
|
|
MARKER_PCB* DRC::newMarker( const wxPoint &aPos, BOARD_ITEM* aItem, BOARD_ITEM* bItem,
|
|
|
|
int aErrorCode )
|
|
|
|
{
|
|
|
|
return new MARKER_PCB( m_pcbEditorFrame->GetUserUnits(), aErrorCode, aPos,
|
|
|
|
aItem, aItem->GetPosition(), bItem, bItem->GetPosition() );
|
2011-09-23 20:00:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-27 13:50:50 +00:00
|
|
|
MARKER_PCB* DRC::newMarker( int aErrorCode, const wxString& aMessage )
|
2011-09-23 20:00:30 +00:00
|
|
|
{
|
2018-08-27 13:50:50 +00:00
|
|
|
MARKER_PCB* marker = new MARKER_PCB( aErrorCode, wxPoint(), aMessage, wxPoint() );
|
2011-09-23 20:00:30 +00:00
|
|
|
|
2018-08-27 13:50:50 +00:00
|
|
|
marker->SetShowNoCoordinate();
|
2011-09-23 20:00:30 +00:00
|
|
|
|
2018-08-27 13:50:50 +00:00
|
|
|
return marker;
|
2011-09-23 20:00:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-16 17:09:33 +00:00
|
|
|
|