KiCad PCB EDA Suite
drc_marker_functions.cpp
Go to the documentation of this file.
1 
5 /*
6  * This program source code file is part of KiCad, a free EDA CAD application.
7  *
8  * Copyright (C) 2010 Dick Hollenbeck, dick@softplc.com
9  * Copyright (C) 2004-2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
10  * Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors.
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, you may find one here:
24  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
25  * or you may search the http://www.gnu.org website for the version 2 license,
26  * or you may write to the Free Software Foundation, Inc.,
27  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
28  */
29 
30 
31 /* Methods of class DRC to initialize drc markers with messages
32  * according to items and error code
33 */
34 
35 #include <fctsys.h>
36 #include <common.h>
37 #include <pcbnew.h>
38 #include <board_design_settings.h>
40 #include <pcb_edit_frame.h>
41 #include <drc.h>
42 #include <class_pad.h>
43 #include <class_track.h>
44 #include <class_zone.h>
45 #include <class_marker_pcb.h>
46 #include <class_pcb_text.h>
47 #include <class_text_mod.h>
48 #include <class_edge_mod.h>
49 #include <class_board_item.h>
50 
51 
52 const int EPSILON = Mils2iu( 5 );
53 
54 
55 MARKER_PCB* DRC::newMarker( TRACK* aTrack, ZONE_CONTAINER* aConflictZone, int aErrorCode )
56 {
57  SHAPE_POLY_SET* conflictOutline;
58 
59  if( aConflictZone->IsFilled() )
60  conflictOutline = const_cast<SHAPE_POLY_SET*>( &aConflictZone->GetFilledPolysList() );
61  else
62  conflictOutline = aConflictZone->Outline();
63 
64  wxPoint markerPos;
65  wxPoint pt1 = aTrack->GetPosition();
66  wxPoint pt2 = aTrack->GetEnd();
67 
68  // If the mid-point is in the zone, then that's a fine place for the marker
69  if( conflictOutline->Distance( ( pt1 + pt2 ) / 2 ) == 0 )
70  markerPos = ( pt1 + pt2 ) / 2;
71 
72  // Otherwise do a binary search for a "good enough" marker location
73  else
74  {
75  while( GetLineLength( pt1, pt2 ) > EPSILON )
76  {
77  if( conflictOutline->Distance( pt1 ) < conflictOutline->Distance( pt2 ) )
78  pt2 = ( pt1 + pt2 ) / 2;
79  else
80  pt1 = ( pt1 + pt2 ) / 2;
81  }
82 
83  // Once we're within EPSILON pt1 and pt2 are "equivalent"
84  markerPos = pt1;
85  }
86 
87  return new MARKER_PCB( m_pcbEditorFrame->GetUserUnits(), aErrorCode, markerPos,
88  aTrack, aTrack->GetPosition(),
89  aConflictZone, aConflictZone->GetPosition() );
90 }
91 
92 
93 MARKER_PCB* DRC::newMarker( TRACK* aTrack, BOARD_ITEM* aConflitItem, const SEG& aConflictSeg,
94  int aErrorCode )
95 {
96  wxPoint markerPos;
97  wxPoint pt1 = aTrack->GetPosition();
98  wxPoint pt2 = aTrack->GetEnd();
99 
100  // Do a binary search along the track for a "good enough" marker location
101  while( GetLineLength( pt1, pt2 ) > EPSILON )
102  {
103  if( aConflictSeg.Distance( pt1 ) < aConflictSeg.Distance( pt2 ) )
104  pt2 = ( pt1 + pt2 ) / 2;
105  else
106  pt1 = ( pt1 + pt2 ) / 2;
107  }
108 
109  // Once we're within EPSILON pt1 and pt2 are "equivalent"
110  markerPos = pt1;
111 
112  return new MARKER_PCB( m_pcbEditorFrame->GetUserUnits(), aErrorCode, markerPos,
113  aTrack, aTrack->GetPosition(),
114  aConflitItem, aConflitItem->GetPosition() );
115 }
116 
117 
118 MARKER_PCB* DRC::newMarker( D_PAD* aPad, BOARD_ITEM* aConflictItem, int aErrorCode )
119 {
120  return new MARKER_PCB( m_pcbEditorFrame->GetUserUnits(), aErrorCode, aPad->GetPosition(),
121  aPad, aPad->GetPosition(),
122  aConflictItem, aConflictItem->GetPosition() );
123 }
124 
125 
126 MARKER_PCB* DRC::newMarker(const wxPoint &aPos, BOARD_ITEM *aItem, int aErrorCode )
127 {
128  return new MARKER_PCB( m_pcbEditorFrame->GetUserUnits(), aErrorCode, aPos,
129  aItem, aItem->GetPosition(), nullptr, wxPoint() );
130 }
131 
132 
133 MARKER_PCB* DRC::newMarker( const wxPoint &aPos, BOARD_ITEM* aItem, BOARD_ITEM* bItem,
134  int aErrorCode )
135 {
136  return new MARKER_PCB( m_pcbEditorFrame->GetUserUnits(), aErrorCode, aPos,
137  aItem, aItem->GetPosition(), bItem, bItem->GetPosition() );
138 }
139 
140 
141 MARKER_PCB* DRC::newMarker( int aErrorCode, const wxString& aMessage )
142 {
143  MARKER_PCB* marker = new MARKER_PCB( aErrorCode, wxPoint(), aMessage, wxPoint() );
144 
145  marker->SetShowNoCoordinate();
146 
147  return marker;
148 }
149 
150 
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
double GetLineLength(const wxPoint &aPointA, const wxPoint &aPointB)
Function GetLineLength returns the length of a line segment defined by aPointA and aPointB...
Definition: trigo.h:191
TEXTE_PCB class definition.
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
Classes BOARD_ITEM and BOARD_CONNECTED_ITEM.
void SetShowNoCoordinate()
Definition: marker_base.h:209
bool IsFilled() const
Definition: class_zone.h:195
SHAPE_POLY_SET * Outline()
Definition: class_zone.h:242
Classes to handle copper zones.
const wxPoint GetPosition() const override
Function GetPosition.
Definition: class_zone.cpp:169
const wxPoint & GetEnd() const
Definition: class_track.h:119
Functions relatives to tracks, vias and segments used to fill zones.
const int EPSILON
Markers used to show a drc problem on boards.
Footprint text class description.
const wxPoint GetPosition() const override
Definition: class_track.h:113
Class SHAPE_POLY_SET.
EDA_UNITS_T GetUserUnits() const override
Return the user units currently in use.
Definition: draw_frame.h:284
MARKER_PCB * newMarker(TRACK *aTrack, BOARD_ITEM *aConflitItem, const SEG &aConflictSeg, int aErrorCode)
Function newMarker Creates a marker on a track, via or pad.
a few functions useful in geometry calculations.
PCB_EDIT_FRAME * m_pcbEditorFrame
The pcb frame editor which owns the board.
Definition: drc.h:221
const SHAPE_POLY_SET & GetFilledPolysList() const
Function GetFilledPolysList returns a reference to the list of filled polygons.
Definition: class_zone.h:555
Pad object description.
virtual const wxPoint GetPosition() const =0
Definition: seg.h:36
int Distance(VECTOR2I aPoint)
Function DistanceToPolygon computes the minimum distance between aPoint and all the polygons in the s...
The common library.
const wxPoint GetPosition() const override
Definition: class_pad.h:220
EDGE_MODULE class definition.
int Distance(const SEG &aSeg) const
Function Distance()
Definition: seg.h:195