KiCad PCB EDA Suite
tracepcb.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
5  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
6  * Copyright (C) 2012 Wayne Stambaugh <stambaughw@verizon.net>
7  * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, you may find one here:
21  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22  * or you may search the http://www.gnu.org website for the version 2 license,
23  * or you may write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26 
32 #include <fctsys.h>
33 #include <class_drawpanel.h>
34 #include <wxPcbStruct.h>
35 #include <base_units.h>
36 
37 #include <class_board.h>
38 #include <class_module.h>
39 #include <class_track.h>
40 #include <class_zone.h>
41 #include <class_marker_pcb.h>
42 
43 #include <pcbnew.h>
44 #include <module_editor_frame.h>
45 #include <pcbplot.h>
46 
47 #include <wx/overlay.h>
48 
49 
50 // Local functions:
51 /* Trace the pads of a module in sketch mode.
52  * Used to display pads when when the module visibility is set to not visible
53  * and we want to see pad through.
54  * The pads must appear on the layers selected in LayerMask
55  */
56 static void Trace_Pads_Only( EDA_DRAW_PANEL* panel, wxDC* DC, MODULE* Module,
57  int ox, int oy, LSET LayerMask, GR_DRAWMODE draw_mode );
58 
59 
60 void FOOTPRINT_EDIT_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
61 {
62  PCB_SCREEN* screen = GetScreen();
63 
64  if( !GetBoard() || !screen )
65  return;
66 
67  GRSetDrawMode( DC, GR_COPY );
68 
69  m_canvas->DrawBackGround( DC );
70  DrawWorkSheet( DC, screen, 0, IU_PER_MILS, wxEmptyString );
71 
72  // Redraw the footprints
73  for( MODULE* module = GetBoard()->m_Modules; module; module = module->Next() )
74  module->Draw( m_canvas, DC, GR_OR | GR_ALLOW_HIGHCONTRAST );
75 
76 #ifdef USE_WX_OVERLAY
77 
78  if( IsShown() )
79  {
80  m_overlay.Reset();
81  wxDCOverlay overlaydc( m_overlay, (wxWindowDC*) DC );
82  overlaydc.Clear();
83  }
84 
85 #endif
86 
87  if( m_canvas->IsMouseCaptured() )
88  m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
89 
90  // Redraw the cursor
91  m_canvas->DrawCrossHair( DC );
92 }
93 
94 
95 /* Draw the BOARD, and others elements : axis, grid ..
96  */
97 void PCB_EDIT_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
98 {
99  PCB_SCREEN* screen = GetScreen();
100 
101  if( !GetBoard() || !screen )
102  return;
103 
104  GRSetDrawMode( DC, GR_COPY );
105 
106  m_canvas->DrawBackGround( DC );
107 
109  IU_PER_MILS, GetBoard()->GetFileName() );
110 
112 
113  DrawGeneralRatsnest( DC );
114 
115 #ifdef USE_WX_OVERLAY
116 
117  if( IsShown() )
118  {
119  m_overlay.Reset();
120  wxDCOverlay overlaydc( m_overlay, (wxWindowDC*) DC );
121  overlaydc.Clear();
122  }
123 
124 #endif
125 
126  if( m_canvas->IsMouseCaptured() )
127  m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
128 
129  // Redraw the cursor
130  m_canvas->DrawCrossHair( DC );
131 }
132 
133 
134 // Redraw the BOARD items but not cursors, axis or grid
135 void BOARD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* DC, GR_DRAWMODE aDrawMode, const wxPoint& offset )
136 {
137  /* The order of drawing is flexible on some systems and not on others. For
138  * OSes which use OR to draw, the order is not important except for the
139  * effect of the highlight and its relationship to markers. See comment
140  * below.
141  * This order independence comes from the fact that a binary OR operation is
142  * commutative in nature.
143  * However on the OSX, the OR operation is not used, and so this sequence
144  * below is chosen to give MODULEs the highest visible priority.
145  */
146 
147  /* Draw all tracks and zones. As long as dark colors are used for the
148  * tracks, Then the OR draw mode should show tracks underneath other
149  * tracks. But a white track will cover any other color since it has
150  * more bits to OR in.
151  */
152  for( TRACK* track = m_Track; track; track = track->Next() )
153  {
154  if( track->IsMoving() )
155  continue;
156 
157  track->Draw( aPanel, DC, aDrawMode );
158  }
159 
160  // SEGZONE is outdated, only her for compatibility with
161  // very old designs
162  for( SEGZONE* zone = m_Zone; zone; zone = zone->Next() )
163  {
164  if( zone->IsMoving() )
165  continue;
166 
167  zone->Draw( aPanel, DC, aDrawMode );
168  }
169 
170  // Draw the graphic items
171  for( BOARD_ITEM* item = m_Drawings; item; item = item->Next() )
172  {
173  if( item->IsMoving() )
174  continue;
175 
176  switch( item->Type() )
177  {
178  case PCB_DIMENSION_T:
179  case PCB_TEXT_T:
180  case PCB_TARGET_T:
181  case PCB_LINE_T:
182  item->Draw( aPanel, DC, aDrawMode );
183  break;
184 
185  default:
186  break;
187  }
188  }
189 
190  // Draw areas (i.e. zones)
191  for( int ii = 0; ii < GetAreaCount(); ii++ )
192  {
193  ZONE_CONTAINER* zone = GetArea( ii );
194 
195  // Areas must be drawn here only if not moved or dragged,
196  // because these areas are drawn by ManageCursor() in a specific manner
197  if( ( zone->GetFlags() & (IN_EDIT | IS_DRAGGED | IS_MOVED) ) == 0 )
198  {
199  zone->Draw( aPanel, DC, aDrawMode );
200  zone->DrawFilledArea( aPanel, DC, aDrawMode );
201  }
202  }
203 
204  LSET all_cu = LSET::AllCuMask();
205 
206  for( MODULE* module = m_Modules; module; module = module->Next() )
207  {
208  bool display = true;
209  LSET layerMask = all_cu;
210 
211  if( module->IsMoving() )
212  continue;
213 
215  {
216  if( module->GetLayer() == F_Cu )
217  display = false;
218 
219  layerMask.set( F_Cu, false );
220  }
221 
223  {
224  if( module->GetLayer() == B_Cu )
225  display = false;
226 
227  layerMask.set( B_Cu, false );
228  }
229 
230  if( display )
231  module->Draw( aPanel, DC, aDrawMode );
232  else
233  Trace_Pads_Only( aPanel, DC, module, 0, 0, layerMask, aDrawMode );
234  }
235 
236  if( IsHighLightNetON() )
237  DrawHighLight( aPanel, DC, GetHighLightNetCode() );
238 
239  // draw the BOARD's markers last, otherwise the high light will erase any marker on a pad
240  for( unsigned i = 0; i < m_markers.size(); ++i )
241  {
242  m_markers[i]->Draw( aPanel, DC, aDrawMode );
243  }
244 }
245 
246 
247 void BOARD::DrawHighLight( EDA_DRAW_PANEL* am_canvas, wxDC* DC, int aNetCode )
248 {
249  GR_DRAWMODE draw_mode;
250 
251  if( IsHighLightNetON() )
252  draw_mode = GR_HIGHLIGHT | GR_OR;
253  else
254  draw_mode = GR_AND | GR_HIGHLIGHT;
255 
256  // Redraw zones
257  for( int ii = 0; ii < GetAreaCount(); ii++ )
258  {
259  ZONE_CONTAINER* zone = GetArea( ii );
260 
261  if( zone->GetNetCode() == aNetCode )
262  {
263  zone->Draw( am_canvas, DC, draw_mode );
264  }
265  }
266 
267  // Redraw any pads that have aNetCode
268  for( MODULE* module = m_Modules; module; module = module->Next() )
269  {
270  for( D_PAD* pad = module->Pads(); pad; pad = pad->Next() )
271  {
272  if( pad->GetNetCode() == aNetCode )
273  {
274  pad->Draw( am_canvas, DC, draw_mode );
275  }
276  }
277  }
278 
279  // Redraw track and vias that have aNetCode
280  for( TRACK* seg = m_Track; seg; seg = seg->Next() )
281  {
282  if( seg->GetNetCode() == aNetCode )
283  {
284  seg->Draw( am_canvas, DC, draw_mode );
285  }
286  }
287 }
288 
289 
290 /* Trace the pads of a module in sketch mode.
291  * Used to display pads when when the module visibility is set to not visible
292  * and we want to see pad through.
293  * The pads must appear on the layers selected in LayerMask
294  */
295 static void Trace_Pads_Only( EDA_DRAW_PANEL* panel, wxDC* DC, MODULE* aModule,
296  int ox, int oy, LSET aLayerMask, GR_DRAWMODE draw_mode )
297 {
298  DISPLAY_OPTIONS* displ_opts = (DISPLAY_OPTIONS*)panel->GetDisplayOptions();
299 
300  int tmp = displ_opts->m_DisplayPadFill;
301 
302  displ_opts->m_DisplayPadFill = false;
303 
304  // Draw pads.
305  for( D_PAD* pad = aModule->Pads(); pad; pad = pad->Next() )
306  {
307  if( (pad->GetLayerSet() & aLayerMask) == 0 )
308  continue;
309 
310  pad->Draw( panel, DC, draw_mode, wxPoint( ox, oy ) );
311  }
312 
313  displ_opts->m_DisplayPadFill = tmp;
314 }
show modules on front
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Function AllCuMask returns a mask holding the requested number of Cu LAYER_IDs.
Definition: lset.cpp:638
void Draw(EDA_DRAW_PANEL *panel, wxDC *DC, GR_DRAWMODE aDrawMode, const wxPoint &offset=ZeroOffset) override
Function Draw Draws the zone outline.
Definition: class_zone.cpp:179
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:78
Definition of class FOOTPRINT_EDIT_FRAME.
STATUS_FLAGS GetFlags() const
Definition: base_struct.h:255
#define IN_EDIT
Item currently edited.
Definition: base_struct.h:111
void GRSetDrawMode(wxDC *DC, GR_DRAWMODE draw_mode)
Definition: gr_basic.cpp:290
Implementation of conversion functions that require both schematic and board internal units...
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
Class BOARD to handle a board.
void DrawFilledArea(EDA_DRAW_PANEL *panel, wxDC *DC, GR_DRAWMODE aDrawMode, const wxPoint &offset=ZeroOffset)
Function DrawDrawFilledArea Draws the filled area for this zone (polygon list .m_FilledPolysList) ...
Definition: class_zone.cpp:240
void DrawCrossHair(wxDC *aDC, COLOR4D aColor=COLOR4D::WHITE)
Function DrawCrossHair draws the user cross hair.
Definition: draw_panel.cpp:216
MODULE * Next() const
Definition: class_module.h:99
class TEXTE_PCB, text on a layer
Definition: typeinfo.h:104
BOARD * GetBoard() const
Classes to handle copper zones.
DLIST< SEGZONE > m_Zone
Definition: class_board.h:245
Functions relatives to tracks, vias and segments used to fill zones.
SEGZONE * Next() const
Definition: class_track.h:362
Board plot function definition file.
BOARD_ITEM * Next() const
#define IS_DRAGGED
Item being dragged.
Definition: base_struct.h:115
Markers used to show a drc problem on boards.
Class LSET is a set of LAYER_IDs.
PCB_VISIBLE
Enum PCB_VISIBLE is a set of visible PCB elements.
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:41
bool IsMouseCaptured() const
void DrawGeneralRatsnest(wxDC *aDC, int aNetcode=0)
function Displays the general ratsnest Only ratsnest with the status bit CH_VISIBLE is set are displa...
Definition: ratsnest.cpp:300
void CallMouseCapture(wxDC *aDC, const wxPoint &aPosition, bool aErase)
Function CallMouseCapture calls the mouse capture callback.
D_PAD * Next() const
Definition: class_pad.h:106
DLIST< BOARD_ITEM > m_Drawings
Definition: class_board.h:242
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:1051
MARKERS m_markers
MARKER_PCBs for clearance problems, owned by pointer.
Definition: class_board.h:175
int g_DrawDefaultLineThickness
Default line thickness in internal units used to draw or plot items using a default thickness line va...
void RedrawActiveWindow(wxDC *DC, bool EraseBg) override
Function RedrawActiveWindoow draws the footprint editor BOARD, and others elements such as axis and g...
Definition: tracepcb.cpp:60
class DIMENSION, a dimension (graphic item)
Definition: typeinfo.h:112
void RedrawActiveWindow(wxDC *DC, bool EraseBg) override
Definition: tracepcb.cpp:97
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:113
Class DISPLAY_OPTIONS handles display options like enable/disable some optional drawings.
Definition: pcbstruct.h:62
Definition: gr_basic.h:42
int GetNetCode() const
Function GetNetCode.
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:92
bool m_DisplayPadFill
Definition: pcbstruct.h:65
TRACK * Next() const
Definition: class_track.h:97
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:1022
static void Trace_Pads_Only(EDA_DRAW_PANEL *panel, wxDC *DC, MODULE *Module, int ox, int oy, LSET LayerMask, GR_DRAWMODE draw_mode)
Definition: tracepcb.cpp:295
DLIST< MODULE > m_Modules
Definition: class_board.h:243
bool IsElementVisible(int aPCB_VISIBLE) const
Function IsElementVisible tests whether a given element category is visible.
PCB_SCREEN * GetScreen() const override
Function GetScreen returns a pointer to a BASE_SCREEN or one of its derivatives.
bool IsHighLightNetON() const
Function IsHighLightNetON.
Definition: class_board.h:370
void DrawBackGround(wxDC *DC)
Function DrawBackGround.
Definition: draw_panel.cpp:666
void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDC, GR_DRAWMODE aDrawMode, const wxPoint &aOffset=ZeroOffset) override
Function Draw.
Definition: tracepcb.cpp:135
DLIST< D_PAD > & Pads()
Definition: class_module.h:133
int GetHighLightNetCode() const
Function GetHighLightNetCode.
Definition: class_board.h:355
DLIST< TRACK > m_Track
Definition: class_board.h:244
void DrawWorkSheet(wxDC *aDC, BASE_SCREEN *aScreen, int aLineWidth, double aScale, const wxString &aFilename, const wxString &aSheetLayer=wxEmptyString)
Function DrawWorkSheet Draws on screen the page layout with the frame and the basic inscriptions...
Definition: worksheet.cpp:77
Module description (excepted pads)
void * GetDisplayOptions()
Function GetDisplayOptions A way to pass info to draw functions.
Definition: draw_panel.cpp:182
void DrawHighLight(EDA_DRAW_PANEL *aDrawPanel, wxDC *aDC, int aNetCode)
Function DrawHighLight redraws the objects in the board that are associated with the given aNetCode a...
Definition: tracepcb.cpp:247
class DRAWSEGMENT, a segment not on copper layers
Definition: typeinfo.h:103
#define IS_MOVED
Item being moved.
Definition: base_struct.h:112