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
|
2019-03-01 13:36:53 +00:00
|
|
|
* Copyright (C) 2018-2019 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
|
|
|
|
*/
|
|
|
|
|
2019-01-11 13:21:38 +00:00
|
|
|
#include "drc_marker_factory.h"
|
2011-09-23 20:00:30 +00:00
|
|
|
|
2018-02-02 20:57:12 +00:00
|
|
|
#include <board_design_settings.h>
|
2019-01-11 13:21:38 +00:00
|
|
|
#include <class_board_item.h>
|
|
|
|
#include <class_edge_mod.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_marker_pcb.h>
|
2019-01-11 13:21:38 +00:00
|
|
|
#include <class_pad.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>
|
2019-01-11 13:21:38 +00:00
|
|
|
#include <class_track.h>
|
|
|
|
#include <class_zone.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <drc.h>
|
|
|
|
#include <fctsys.h>
|
|
|
|
#include <geometry/geometry_utils.h>
|
|
|
|
#include <pcb_edit_frame.h>
|
|
|
|
#include <pcbnew.h>
|
2011-09-23 20:00:30 +00:00
|
|
|
|
|
|
|
|
2018-08-27 13:50:50 +00:00
|
|
|
const int EPSILON = Mils2iu( 5 );
|
|
|
|
|
|
|
|
|
2019-01-11 13:21:38 +00:00
|
|
|
DRC_MARKER_FACTORY::DRC_MARKER_FACTORY()
|
|
|
|
{
|
|
|
|
SetUnits( EDA_UNITS_T::MILLIMETRES );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DRC_MARKER_FACTORY::SetUnitsProvider( UNITS_PROVIDER aUnitsProvider )
|
|
|
|
{
|
|
|
|
m_units_provider = aUnitsProvider;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DRC_MARKER_FACTORY::SetUnits( EDA_UNITS_T aUnits )
|
|
|
|
{
|
|
|
|
m_units_provider = [=]() { return aUnits; };
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MARKER_PCB* DRC_MARKER_FACTORY::NewMarker(
|
|
|
|
TRACK* aTrack, ZONE_CONTAINER* aConflictZone, int aErrorCode ) const
|
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
|
|
|
|
2019-01-11 13:21:38 +00:00
|
|
|
return new MARKER_PCB( getCurrentUnits(), aErrorCode, markerPos, aTrack, aTrack->GetPosition(),
|
|
|
|
aConflictZone, aConflictZone->GetPosition() );
|
2011-09-23 20:00:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-11 13:21:38 +00:00
|
|
|
MARKER_PCB* DRC_MARKER_FACTORY::NewMarker(
|
|
|
|
TRACK* aTrack, BOARD_ITEM* aConflitItem, const SEG& aConflictSeg, int aErrorCode ) const
|
2011-09-23 20:00:30 +00:00
|
|
|
{
|
2019-01-11 13:21:38 +00:00
|
|
|
wxPoint markerPos;
|
2018-08-27 13:50:50 +00:00
|
|
|
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
|
|
|
|
2019-01-11 13:21:38 +00:00
|
|
|
return new MARKER_PCB( getCurrentUnits(), aErrorCode, markerPos, aTrack, aTrack->GetPosition(),
|
|
|
|
aConflitItem, aConflitItem->GetPosition() );
|
2011-09-23 20:00:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-11 13:21:38 +00:00
|
|
|
MARKER_PCB* DRC_MARKER_FACTORY::NewMarker(
|
|
|
|
D_PAD* aPad, BOARD_ITEM* aConflictItem, int aErrorCode ) const
|
2011-09-23 20:00:30 +00:00
|
|
|
{
|
2019-01-11 13:21:38 +00:00
|
|
|
return new MARKER_PCB( getCurrentUnits(), aErrorCode, aPad->GetPosition(), aPad,
|
|
|
|
aPad->GetPosition(), aConflictItem, aConflictItem->GetPosition() );
|
2011-09-23 20:00:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-11 13:21:38 +00:00
|
|
|
MARKER_PCB* DRC_MARKER_FACTORY::NewMarker(
|
|
|
|
const wxPoint& aPos, BOARD_ITEM* aItem, int aErrorCode ) const
|
2011-09-23 20:00:30 +00:00
|
|
|
{
|
2019-01-11 13:21:38 +00:00
|
|
|
return new MARKER_PCB(
|
2019-03-01 13:36:53 +00:00
|
|
|
getCurrentUnits(), aErrorCode, aPos, aItem, aPos, nullptr, wxPoint() );
|
2018-08-27 13:50:50 +00:00
|
|
|
}
|
2018-08-23 22:41:57 +00:00
|
|
|
|
2011-09-23 20:00:30 +00:00
|
|
|
|
2019-01-11 13:21:38 +00:00
|
|
|
MARKER_PCB* DRC_MARKER_FACTORY::NewMarker(
|
|
|
|
const wxPoint& aPos, BOARD_ITEM* aItem, BOARD_ITEM* bItem, int aErrorCode ) const
|
2018-08-27 13:50:50 +00:00
|
|
|
{
|
2019-01-11 13:21:38 +00:00
|
|
|
return new MARKER_PCB( getCurrentUnits(), aErrorCode, aPos, aItem, aItem->GetPosition(), bItem,
|
|
|
|
bItem->GetPosition() );
|
2011-09-23 20:00:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-11 13:21:38 +00:00
|
|
|
MARKER_PCB* DRC_MARKER_FACTORY::NewMarker( int aErrorCode, const wxString& aMessage ) const
|
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
|
|
|
}
|