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) 2017 KiCad Developers, see change_log.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>
39 
40 #include <drc_stuff.h>
41 #include <class_pad.h>
42 #include <class_track.h>
43 #include <class_zone.h>
44 #include <class_zone.h>
45 #include <class_marker_pcb.h>
46 #include <class_pcb_text.h>
47 
48 
49 MARKER_PCB* DRC::fillMarker( const TRACK* aTrack, BOARD_ITEM* aItem, int aErrorCode,
50  MARKER_PCB* fillMe )
51 {
52  wxString textA = aTrack->GetSelectMenuText();
53  wxString textB;
54 
55  wxPoint position;
56  wxPoint posB;
57 
58  if( aItem ) // aItem might be NULL
59  {
60  textB = aItem->GetSelectMenuText();
61 
62  if( aItem->Type() == PCB_PAD_T )
63  {
64  posB = position = ((D_PAD*)aItem)->GetPosition();
65  }
66  else if( aItem->Type() == PCB_VIA_T )
67  {
68  posB = position = ((VIA*)aItem)->GetPosition();
69  }
70  else if( aItem->Type() == PCB_TRACE_T )
71  {
72  TRACK* track = (TRACK*) aItem;
73 
74  posB = track->GetPosition();
75 
76  wxPoint endPos = track->GetEnd();
77 
78  // either of aItem's start or end will be used for the marker position
79  // first assume start, then switch at end if needed. decision made on
80  // distance from end of aTrack.
81  position = track->GetStart();
82 
83  double dToEnd = GetLineLength( endPos, aTrack->GetEnd() );
84  double dToStart = GetLineLength( position, aTrack->GetEnd() );
85 
86  if( dToEnd < dToStart )
87  position = endPos;
88  }
89  else if( aItem->Type() == PCB_TEXT_T )
90  {
91  position = aTrack->GetPosition();
92  posB = ((TEXTE_PCB*) aItem)->GetPosition();
93  }
94  }
95  else
96  position = aTrack->GetPosition();
97 
98  if( fillMe )
99  {
100  if( aItem )
101  fillMe->SetData( aErrorCode, position,
102  textA, aTrack->GetPosition(),
103  textB, posB );
104  else
105  fillMe->SetData( aErrorCode, position,
106  textA, aTrack->GetPosition() );
107  }
108  else
109  {
110  if( aItem )
111  {
112  fillMe = new MARKER_PCB( aErrorCode, position,
113  textA, aTrack->GetPosition(),
114  textB, posB );
115  fillMe->SetItem( aItem );
116  }
117  else
118  {
119  fillMe = new MARKER_PCB( aErrorCode, position,
120  textA, aTrack->GetPosition() );
121  }
122  }
123 
124  return fillMe;
125 }
126 
127 
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  wxPoint posB;
135 
136  if( aItem )
137  {
138  textB = aItem->GetSelectMenuText();
139 
140  switch( aItem->Type() )
141  {
142  case PCB_PAD_T:
143  posB = ((D_PAD*)aItem)->GetPosition();
144  break;
145 
146  case PCB_TEXT_T:
147  posB = ((TEXTE_PCB*)aItem)->GetPosition();
148  break;
149 
150  default:
151  wxLogDebug( wxT("fillMarker: unsupported item") );
152  break;
153  }
154  }
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  fillMe->SetItem( aPad ); // TODO it has to be checked
164  }
165 
166  return fillMe;
167 }
168 
169 
170 MARKER_PCB* DRC::fillMarker( ZONE_CONTAINER* aArea, int aErrorCode, MARKER_PCB* fillMe )
171 {
172  wxString textA = aArea->GetSelectMenuText();
173 
174  wxPoint posA = aArea->GetPosition();
175 
176  if( fillMe )
177  {
178  fillMe->SetData( aErrorCode, posA, textA, posA );
179  }
180  else
181  {
182  fillMe = new MARKER_PCB( aErrorCode, posA, textA, posA );
183  fillMe->SetItem( aArea );
184  }
185 
186  return fillMe;
187 }
188 
189 
191  const wxPoint& aPos,
192  int aErrorCode,
193  MARKER_PCB* fillMe )
194 {
195  wxString textA = aArea->GetSelectMenuText();
196 
197  wxPoint posA = aPos;
198 
199  if( fillMe )
200  {
201  fillMe->SetData( aErrorCode, posA, textA, posA );
202  }
203  else
204  {
205  fillMe = new MARKER_PCB( aErrorCode, posA, textA, posA );
206  fillMe->SetItem( aArea );
207  }
208 
209  return fillMe;
210 }
211 
212 
213 MARKER_PCB* DRC::fillMarker( int aErrorCode, const wxString& aMessage, MARKER_PCB* fillMe )
214 {
215  wxPoint posA; // not displayed
216 
217  if( fillMe )
218  fillMe->SetData( aErrorCode, posA, aMessage, posA );
219  else
220  fillMe = new MARKER_PCB( aErrorCode, posA, aMessage, posA );
221 
222  fillMe->SetShowNoCoordinate();
223 
224  return fillMe;
225 }
226 
227 
228 MARKER_PCB* DRC::fillMarker( const wxPoint& aPos, int aErrorCode, const wxString& aMessage, MARKER_PCB* fillMe )
229 {
230  wxPoint posA = aPos;
231 
232  if( fillMe )
233  fillMe->SetData( aErrorCode, posA, aMessage, posA );
234  else
235  fillMe = new MARKER_PCB( aErrorCode, posA, aMessage, posA );
236 
237  return fillMe;
238 }
239 
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:78
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
wxString GetSelectMenuText() const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: class_pad.cpp:1179
wxString GetSelectMenuText() const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
TEXTE_PCB class definition.
MARKER_PCB * fillMarker(const TRACK *aTrack, BOARD_ITEM *aItem, int aErrorCode, MARKER_PCB *fillMe)
Function fillMarker optionally creates a marker and fills it in with information, but does not add it...
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
void SetShowNoCoordinate()
class TEXTE_PCB, text on a layer
Definition: typeinfo.h:104
Classes to handle copper zones.
class D_PAD, a pad in a footprint
Definition: typeinfo.h:102
virtual wxString GetSelectMenuText() const
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
const wxPoint & GetEnd() const
Definition: class_track.h:118
void SetData(int aErrorCode, const wxPoint &aMarkerPos, const wxString &aText, const wxPoint &aPos, const wxString &bText, const wxPoint &bPos)
Function SetData fills in all the reportable data associated with a MARKER.
Functions relatives to tracks, vias and segments used to fill zones.
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:107
void SetItem(const BOARD_ITEM *aItem)
const wxPoint & GetPosition() const override
Definition: class_track.h:112
Markers used to show a drc problem on boards.
const wxPoint & GetStart() const
Definition: class_track.h:121
const wxPoint & GetPosition() const override
Definition: class_pad.h:220
virtual wxString GetSelectMenuText() const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Pad object description.
const wxPoint & GetPosition() const override
Function GetPosition.
Definition: class_zone.cpp:170
The common library.
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:108