KiCad PCB EDA Suite
pcb_legacy_draw_utils.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-2019 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 
27 #include <fctsys.h>
28 #include <pcb_edit_frame.h>
29 #include <base_units.h>
30 #include <class_board.h>
31 #include <class_module.h>
32 #include <class_track.h>
33 #include <class_zone.h>
34 #include <class_marker_pcb.h>
35 #include <pcbnew.h>
36 #include <footprint_edit_frame.h>
37 #include <pcbplot.h>
38 #include <wx/overlay.h>
39 
40 
41 // Local functions:
42 /* Trace the pads of a module in sketch mode.
43  * Used to display pads when when the module visibility is set to not visible
44  * and we want to see pad through.
45  * The pads must appear on the layers selected in LayerMask
46  */
47 static void Trace_Pads_Only( PCB_BASE_FRAME* aFrame, wxDC* DC, MODULE* Module,
48  int ox, int oy, LSET LayerMask );
49 
50 
51 // Redraw the BOARD items but not cursors, axis or grid
52 void BOARD::Print( PCB_BASE_FRAME* aFrame, wxDC* DC, const wxPoint& offset )
53 {
54  /* The order of drawing is flexible on some systems and not on others. For
55  * OSes which use OR to draw, the order is not important except for the
56  * effect of the highlight and its relationship to markers. See comment
57  * below.
58  * This order independence comes from the fact that a binary OR operation is
59  * commutative in nature.
60  * However on the OSX, the OR operation is not used, and so this sequence
61  * below is chosen to give MODULEs the highest visible priority.
62  */
63 
64  /* Draw all tracks and zones. As long as dark colors are used for the
65  * tracks, Then the OR draw mode should show tracks underneath other
66  * tracks. But a white track will cover any other color since it has
67  * more bits to OR in.
68  */
69  for( auto track : m_tracks )
70  {
71  if( track->IsMoving() )
72  continue;
73 
74  track->Print( aFrame, DC );
75  }
76 
77  // Draw areas (i.e. zones)
78  for( int ii = 0; ii < GetAreaCount(); ii++ )
79  {
80  ZONE_CONTAINER* zone = GetArea( ii );
81 
82  // Areas must be drawn here only if not moved or dragged,
83  // because these areas are drawn by ManageCursor() in a specific manner
84  if( ( zone->GetEditFlags() & (IN_EDIT | IS_DRAGGED | IS_MOVED) ) == 0 )
85  {
86  zone->Print( aFrame, DC );
87  zone->PrintFilledArea( aFrame, DC );
88  }
89  }
90 
91  // Draw the graphic items
92  for( auto item : m_drawings )
93  {
94  if( item->IsMoving() )
95  continue;
96 
97  switch( item->Type() )
98  {
99  case PCB_DIMENSION_T:
100  case PCB_TEXT_T:
101  case PCB_TARGET_T:
102  case PCB_LINE_T:
103  item->Print( aFrame, DC );
104  break;
105 
106  default:
107  break;
108  }
109  }
110 
111  LSET all_cu = LSET::AllCuMask();
112 
113  for( auto module : m_modules )
114  {
115  bool display = true;
116  LSET layerMask = all_cu;
117 
118  if( module->IsMoving() )
119  continue;
120 
122  {
123  if( module->GetLayer() == F_Cu )
124  display = false;
125 
126  layerMask.set( F_Cu, false );
127  }
128 
130  {
131  if( module->GetLayer() == B_Cu )
132  display = false;
133 
134  layerMask.set( B_Cu, false );
135  }
136 
137  if( display )
138  module->Print( aFrame, DC );
139  else
140  Trace_Pads_Only( aFrame, DC, module, 0, 0, layerMask );
141  }
142 
143  // draw the BOARD's markers last, otherwise the high light will erase any marker on a pad
144  for( unsigned i = 0; i < m_markers.size(); ++i )
145  {
146  m_markers[i]->Print( aFrame, DC );
147  }
148 }
149 
150 
151 /* Trace the pads of a module in sketch mode.
152  * Used to display pads when when the module visibility is set to not visible
153  * and we want to see pad through.
154  * The pads must appear on the layers selected in LayerMask
155  */
156 static void Trace_Pads_Only( PCB_BASE_FRAME* aFrame, wxDC* DC, MODULE* aModule,
157  int ox, int oy, LSET aLayerMask )
158 {
159  PCB_DISPLAY_OPTIONS displ_opts = aFrame->GetDisplayOptions();
160  int tmp = displ_opts.m_DisplayPadFill;
161 
162  displ_opts.m_DisplayPadFill = false;
163  aFrame->SetDisplayOptions( displ_opts );
164 
165  // Draw pads.
166  for( auto pad : aModule->Pads() )
167  {
168  if( (pad->GetLayerSet() & aLayerMask) == 0 )
169  continue;
170 
171  pad->Print( aFrame, DC, wxPoint( ox, oy ) );
172  }
173 
174  displ_opts.m_DisplayPadFill = tmp;
175  aFrame->SetDisplayOptions( displ_opts );
176 }
MODULES m_modules
MODULES for components on the board, owned by pointer.
Definition: class_board.h:175
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Function AllCuMask returns a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:686
ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
#define IN_EDIT
Item currently edited.
Definition: base_struct.h:118
Implementation of conversion functions that require both schematic and board internal units.
PADS & Pads()
Definition: class_module.h:173
class TEXTE_PCB, text on a layer
Definition: typeinfo.h:92
void SetDisplayOptions(const PCB_DISPLAY_OPTIONS &aOptions)
TRACKS m_tracks
TRACKS for traces on the board, owned by pointer.
Definition: class_board.h:178
const PCB_DISPLAY_OPTIONS & GetDisplayOptions() const
Function GetDisplayOptions returns the display options current in use Display options are relative to...
Definitions for tracks, vias and zones.
Board plot function definition file.
show modules on front
#define IS_DRAGGED
Item being dragged.
Definition: base_struct.h:122
Markers used to show a drc problem on boards.
PCB_DISPLAY_OPTIONS handles display options like enable/disable some optional drawings.
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:948
LSET is a set of PCB_LAYER_IDs.
void Print(PCB_BASE_FRAME *aFrame, wxDC *DC, const wxPoint &offset=ZeroOffset) override
Function Print Prints the zone outline.
Definition: class_zone.cpp:310
STATUS_FLAGS GetEditFlags() const
Definition: base_struct.h:260
MARKERS m_markers
MARKER_PCBs for clearance problems, owned by pointer.
Definition: class_board.h:169
static void Trace_Pads_Only(PCB_BASE_FRAME *aFrame, wxDC *DC, MODULE *Module, int ox, int oy, LSET LayerMask)
DRAWINGS m_drawings
BOARD_ITEMs for drawings on the board, owned by pointer.
Definition: class_board.h:172
class DIMENSION, a dimension (graphic item)
Definition: typeinfo.h:99
void Print(PCB_BASE_FRAME *aFrame, wxDC *aDC, const wxPoint &aOffset=ZeroOffset) override
Function Print.
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:100
bool IsElementVisible(GAL_LAYER_ID aLayer) const
Function IsElementVisible tests whether a given element category is visible.
void PrintFilledArea(PCB_BASE_FRAME *aFrame, wxDC *DC, const wxPoint &offset=ZeroOffset)
Function PrintFilledArea Draws the filled area for this zone (polygon list .m_FilledPolysList)
Definition: class_zone.cpp:422
Module description (excepted pads)
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:913
class DRAWSEGMENT, a segment not on copper layers
Definition: typeinfo.h:91
PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
#define IS_MOVED
Item being moved.
Definition: base_struct.h:119