KiCad PCB EDA Suite
pcb_draw_panel_gal.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) 2014-2017 CERN
5  * @author Maciej Suminski <maciej.suminski@cern.ch>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #include "pcb_draw_panel_gal.h"
26 #include <view/view.h>
27 #include <view/wx_view_controls.h>
28 #include <pcb_painter.h>
29 #include <worksheet_viewitem.h>
30 #include <ratsnest_viewitem.h>
31 #include <ratsnest_data.h>
32 #include <connectivity.h>
33 
35 #include <class_board.h>
36 #include <class_module.h>
37 #include <class_track.h>
38 #include <wxBasePcbFrame.h>
39 
40 #include <functional>
41 using namespace std::placeholders;
42 
44 {
46  LAYER_DRC,
49 
52 
57 
60 
91 
94 
97 };
98 
99 
100 PCB_DRAW_PANEL_GAL::PCB_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWindowId,
101  const wxPoint& aPosition, const wxSize& aSize,
102  KIGFX::GAL_DISPLAY_OPTIONS& aOptions, GAL_TYPE aGalType ) :
103 EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalType )
104 {
107 
110 
111  // Load display options (such as filled/outline display of items).
112  // Can be made only if the parent window is an EDA_DRAW_FRAME (or a derived class)
113  // which is not always the case (namely when it is used from a wxDialog like the pad editor)
115 
116  if( frame )
117  {
118  DISPLAY_OPTIONS* displ_opts = (DISPLAY_OPTIONS*) frame->GetDisplayOptions();
119  static_cast<KIGFX::PCB_RENDER_SETTINGS*>( m_view->GetPainter()->GetSettings() )->LoadDisplayOptions( displ_opts );
120  }
121 }
122 
123 
125 {
126  delete m_painter;
127 }
128 
129 
131 {
132  m_view->Clear();
133 
134  // Load zones
135  for( int i = 0; i < aBoard->GetAreaCount(); ++i )
136  m_view->Add( (KIGFX::VIEW_ITEM*) ( aBoard->GetArea( i ) ) );
137 
138  // Load drawings
139  for( auto drawing : const_cast<BOARD*>(aBoard)->Drawings() )
140  m_view->Add( drawing );
141 
142  // Load tracks
143  for( TRACK* track = aBoard->m_Track; track; track = track->Next() )
144  m_view->Add( track );
145 
146  // Load modules and its additional elements
147  for( MODULE* module = aBoard->m_Modules; module; module = module->Next() )
148  {
149  module->RunOnChildren( std::bind( &KIGFX::VIEW::Add, m_view, _1, -1 ) );
150  m_view->Add( module );
151  }
152 
153  // Segzones (equivalent of ZONE_CONTAINER for legacy boards)
154  for( SEGZONE* zone = aBoard->m_Zone; zone; zone = zone->Next() )
155  m_view->Add( zone );
156 
157  // Ratsnest
158  m_ratsnest.reset( new KIGFX::RATSNEST_VIEWITEM( aBoard->GetConnectivity() ) );
159  m_view->Add( m_ratsnest.get() );
160 
161  // Display settings
162  UseColorScheme( aBoard->GetColorsSettings() );
163 }
164 
165 
167 {
168  m_worksheet.reset( aWorksheet );
169  m_view->Add( m_worksheet.get() );
170 }
171 
172 
174 {
176  rs = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( m_view->GetPainter()->GetSettings() );
177  rs->ImportLegacyColors( aSettings );
178 }
179 
180 
182 {
183  // Set display settings for high contrast mode
185 
186  SetTopLayer( aLayer );
187 
188  rSettings->ClearActiveLayers();
189  rSettings->SetActiveLayer( aLayer );
190 
191  if( IsCopperLayer( aLayer ) )
192  {
193  // Bring some other layers to the front in case of copper layers and make them colored
194  // fixme do not like the idea of storing the list of layers here,
195  // should be done in some other way I guess..
196  LAYER_NUM layers[] = {
197  GetNetnameLayer( aLayer ),
201  };
202 
203  for( unsigned int i = 0; i < sizeof( layers ) / sizeof( LAYER_NUM ); ++i )
204  rSettings->SetActiveLayer( layers[i] );
205 
206  // Pads should be shown too
207  if( aLayer == B_Cu )
208  {
209  rSettings->SetActiveLayer( LAYER_PAD_BK );
210  rSettings->SetActiveLayer( LAYER_MOD_BK );
212  }
213  else if( aLayer == F_Cu )
214  {
215  rSettings->SetActiveLayer( LAYER_PAD_FR );
216  rSettings->SetActiveLayer( LAYER_MOD_FR );
218  }
219  }
220 
222 }
223 
224 
226 {
229  m_view->SetTopLayer( aLayer );
230 
231  // Layers that should always have on-top attribute enabled
232  const LAYER_NUM layers[] = {
236  LAYER_DRC
237  };
238 
239  for( unsigned int i = 0; i < sizeof( layers ) / sizeof( LAYER_NUM ); ++i )
240  m_view->SetTopLayer( layers[i] );
241 
242  // Extra layers that are brought to the top if a F.* or B.* is selected
243  const LAYER_NUM frontLayers[] = {
246  };
247 
248  const LAYER_NUM backLayers[] = {
251  };
252 
253  const LAYER_NUM* extraLayers = NULL;
254 
255  // Bring a few more extra layers to the top depending on the selected board side
256  if( IsFrontLayer( aLayer ) )
257  extraLayers = frontLayers;
258  else if( IsBackLayer( aLayer ) )
259  extraLayers = backLayers;
260 
261  if( extraLayers )
262  {
263  const LAYER_NUM* l = extraLayers;
264 
265  while( *l >= 0 )
266  m_view->SetTopLayer( *l++ );
267 
268  // Move the active layer to the top
269  if( !IsCopperLayer( aLayer ) )
271  }
272  else if( IsCopperLayer( aLayer ) )
273  {
274  // Display labels for copper layers on the top
275  m_view->SetTopLayer( GetNetnameLayer( aLayer ) );
276  }
277 
279 }
280 
281 
283 {
284  // Load layer & elements visibility settings
285  for( LAYER_NUM i = 0; i < PCB_LAYER_ID_COUNT; ++i )
286  {
287  m_view->SetLayerVisible( i, aBoard->IsLayerVisible( PCB_LAYER_ID( i ) ) );
288 
289  // Synchronize netname layers as well
290  if( IsCopperLayer( i ) )
292  }
293 
295  {
296  m_view->SetLayerVisible( i, aBoard->IsElementVisible( i ) );
297  }
298 
299  // Enable some layers that are GAL specific
304 }
305 
306 
307 void PCB_DRAW_PANEL_GAL::GetMsgPanelInfo( std::vector<MSG_PANEL_ITEM>& aList )
308 {
309  BOARD* board = static_cast<PCB_BASE_FRAME*>( m_parent )->GetBoard();
310  wxString txt;
311  int viasCount = 0;
312  int trackSegmentsCount = 0;
313 
314  for( const BOARD_ITEM* item = board->m_Track; item; item = item->Next() )
315  {
316  if( item->Type() == PCB_VIA_T )
317  viasCount++;
318  else
319  trackSegmentsCount++;
320  }
321 
322  txt.Printf( wxT( "%d" ), board->GetPadCount() );
323  aList.push_back( MSG_PANEL_ITEM( _( "Pads" ), txt, DARKGREEN ) );
324 
325  txt.Printf( wxT( "%d" ), viasCount );
326  aList.push_back( MSG_PANEL_ITEM( _( "Vias" ), txt, DARKGREEN ) );
327 
328  txt.Printf( wxT( "%d" ), trackSegmentsCount );
329  aList.push_back( MSG_PANEL_ITEM( _( "Track Segments" ), txt, DARKGREEN ) );
330 
331  txt.Printf( wxT( "%d" ), board->GetNodesCount() );
332  aList.push_back( MSG_PANEL_ITEM( _( "Nodes" ), txt, DARKCYAN ) );
333 
334  txt.Printf( wxT( "%d" ), board->GetNetCount() );
335  aList.push_back( MSG_PANEL_ITEM( _( "Nets" ), txt, RED ) );
336 
337  txt.Printf( wxT( "%d" ), board->GetConnectivity()->GetUnconnectedCount() );
338  aList.push_back( MSG_PANEL_ITEM( _( "Unconnected" ), txt, BLUE ) );
339 }
340 
341 
343 {
344  PCB_BASE_FRAME* frame = dynamic_cast<PCB_BASE_FRAME*>( GetParent() );
345 
346  if( frame )
347  {
348  SetTopLayer( frame->GetActiveLayer() );
349  DISPLAY_OPTIONS* displ_opts = (DISPLAY_OPTIONS*) frame->GetDisplayOptions();
350  static_cast<KIGFX::PCB_RENDER_SETTINGS*>(
351  m_view->GetPainter()->GetSettings() )->LoadDisplayOptions( displ_opts );
352  }
353 
355 }
356 
357 
359 {
360  for( LAYER_NUM i = 0; (unsigned) i < sizeof( GAL_LAYER_ORDER ) / sizeof( LAYER_NUM ); ++i )
361  {
362  LAYER_NUM layer = GAL_LAYER_ORDER[i];
363  wxASSERT( layer < KIGFX::VIEW::VIEW_MAX_LAYERS );
364 
365  m_view->SetLayerOrder( layer, i );
366  }
367 }
368 
369 
371 {
372  bool rv = EDA_DRAW_PANEL_GAL::SwitchBackend( aGalType );
374  return rv;
375 }
376 
377 
379 {
380  // caching makes no sense for Cairo and other software renderers
382 
383  for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; i++ )
384  m_view->SetLayerTarget( i, target );
385 
386  for( LAYER_NUM i = 0; (unsigned) i < sizeof( GAL_LAYER_ORDER ) / sizeof( LAYER_NUM ); ++i )
387  {
388  LAYER_NUM layer = GAL_LAYER_ORDER[i];
389  wxASSERT( layer < KIGFX::VIEW::VIEW_MAX_LAYERS );
390 
391  // Set layer display dependencies & targets
392  if( IsCopperLayer( layer ) )
393  m_view->SetRequired( GetNetnameLayer( layer ), layer );
394  else if( IsNetnameLayer( layer ) )
395  m_view->SetLayerDisplayOnly( layer );
396  }
397 
400 
401  // Some more required layers settings
407 
408  // Front modules
418 
419  // Back modules
429 
434 
438 }
void SetWorksheet(KIGFX::WORKSHEET_VIEWITEM *aWorksheet)
Function SetWorksheet Sets (or updates) worksheet used by the draw panel.
Definition: colors.h:57
KIGFX::GAL * m_gal
Interface for drawing objects on a 2D-surface.
void DisplayBoard(const BOARD *aBoard)
Function DisplayBoard adds all items from the current board to the VIEW, so they can be displayed by ...
to draw blind/buried vias
bool IsElementVisible(GAL_LAYER_ID LAYER_aPCB) const
Function IsElementVisible tests whether a given element category is visible.
void setDefaultLayerDeps()
Sets rendering targets & dependencies for layers.
Class that draws missing connections on a PCB.
void SetRequired(int aLayerId, int aRequiredId, bool aRequired=true)
Function SetRequired() Marks the aRequiredId layer as required for the aLayerId layer.
Definition: view.cpp:381
void SetLayerOrder(int aLayer, int aRenderingOrder)
Function SetLayerOrder() Sets rendering order of a particular layer.
Definition: view.cpp:589
GAL_TYPE m_backend
Currently used GAL.
void SetTopLayer(int aLayer, bool aEnabled=true)
Function SetTopLayer() Sets given layer to be displayed on the top or sets back the default order of ...
Definition: view.cpp:748
void GetMsgPanelInfo(std::vector< MSG_PANEL_ITEM > &aList) override
>
Class RENDER_SETTINGS Contains all the knowledge about how graphical objects are drawn on any output ...
Definition: painter.h:56
int GetNetnameLayer(int aLayer)
Returns a netname layer corresponding to the given layer.
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
virtual bool SwitchBackend(GAL_TYPE aGalType)
Function SwitchBackend Switches method of rendering graphics.
anchor of items having an anchor point (texts, footprints)
bool IsBackLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a back layer.
void setDefaultLayerOrder()
Reassigns layer order to the initial settings.
EDA_DRAW_FRAME * GetParentEDAFrame() const
Function GetParentEDAFrame() Returns parent EDA_DRAW_FRAME, if available or NULL otherwise.
Class BOARD to handle a board.
Class that computes missing connections on a PCB.
void RecacheAllItems()
Function RecacheAllItems() Rebuilds GAL display lists.
Definition: view.cpp:1253
MODULE * Next() const
Definition: class_module.h:100
show modules on back
GAL_LAYER_ID
GAL layers are "virtual" layers, i.e.
to draw via holes (pad holes do not use this layer)
show modules values (when texts are visibles)
DLIST< SEGZONE > m_Zone
Definition: class_board.h:247
std::unique_ptr< KIGFX::WORKSHEET_VIEWITEM > m_worksheet
Currently used worksheet
void UpdateAllLayersOrder()
Function UpdateLayerOrder() Does everything that is needed to apply the rendering order of layers...
Definition: view.cpp:815
Add new GAL layers here.
Class VIEW_ITEM - is an abstract base class for deriving all objects that can be added to a VIEW...
Definition: view_item.h:82
Class EDA_DRAW_FRAME is the base class for create windows for drawing purpose.
Definition: draw_frame.h:53
Class PCB_PAINTER Contains methods for drawing PCB-specific items.
Definition: pcb_painter.h:166
void ImportLegacyColors(const COLORS_DESIGN_SETTINGS *aSettings) override
Function ImportLegacyColors Loads a list of color settings for layers.
Definition: pcb_painter.cpp:66
smd pads, back layer
WX_VIEW_CONTROLS class definition.
void SetActiveLayer(int aLayerId, bool aEnabled=true)
Function SetActiveLayer Sets the specified layer as active - it means that it can be drawn in a speci...
Definition: painter.h:76
const LAYER_NUM GAL_LAYER_ORDER[]
Functions relatives to tracks, vias and segments used to fill zones.
void * GetDisplayOptions() override
Function GetDisplayOptions returns the display options current in use Display options are relative to...
Auxiliary rendering target (noncached)
Definition: definitions.h:42
SEGZONE * Next() const
Definition: class_track.h:358
show modules on front
std::unique_ptr< KIGFX::RATSNEST_VIEWITEM > m_ratsnest
Ratsnest view item
Class that handles properties and drawing of worksheet layout.
Class PCB_RENDER_SETTINGS Stores PCB specific render settings.
Definition: pcb_painter.h:62
void SetLayerTarget(int aLayer, RENDER_TARGET aTarget)
Function SetLayerTarget() Changes the rendering target for a particular layer.
Definition: view.h:424
wxWindow * m_parent
Pointer to the parent window.
PCB_LAYER_ID
A quick note on layer IDs:
Classes used in Pcbnew, CvPcb and GerbView.
void ClearActiveLayers()
Function ClearActiveLayers Clears the list of active layers.
Definition: painter.h:98
void Clear()
Function Clear() Removes all items from the view.
Definition: view.cpp:982
int GetLayerOrder(int aLayer) const
Function GetLayerOrder() Returns rendering order of a particular layer.
Definition: view.cpp:597
void SetLayerDisplayOnly(int aLayer, bool aDisplayOnly=true)
Definition: view.h:411
multilayer pads, usually with holes
to draw usual through hole vias
static const int VIEW_MAX_LAYERS
maximum number of layers that may be shown
Definition: view.h:641
COLORS_DESIGN_SETTINGS * GetColorsSettings() const
Function GetColorSettings.
Definition: class_board.h:564
PCB_DRAW_PANEL_GAL(wxWindow *aParentWindow, wxWindowID aWindowId, const wxPoint &aPosition, const wxSize &aSize, KIGFX::GAL_DISPLAY_OPTIONS &aOptions, GAL_TYPE aGalType=GAL_TYPE_OPENGL)
Items that may change while the view stays the same (noncached)
Definition: definitions.h:43
general purpose overlay
Definition: colors.h:60
void SetLayerVisible(int aLayer, bool aVisible=true)
Function SetLayerVisible() Controls the visibility of a particular layer.
Definition: view.h:387
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:1025
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:196
void SyncLayersVisibility(const BOARD *aBoard)
Function SyncLayersVisibility Updates "visibility" property of each layer of a given BOARD...
to draw pad holes (plated or not plated)
unsigned GetPadCount() const
Function GetPadCount.
void UseColorScheme(const COLORS_DESIGN_SETTINGS *aSettings)
Function UseColorScheme Applies layer color settings.
void ClearTopLayers()
Function ClearTopLayers() Removes all layers from the on-the-top set (they are no longer displayed ov...
Definition: view.cpp:800
virtual void SetHighContrastLayer(int aLayer) override
>
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
Class DISPLAY_OPTIONS handles display options like enable/disable some optional drawings.
Definition: pcbstruct.h:62
BOARD * GetBoard()
bool SwitchBackend(GAL_TYPE aGalType) override
Function SwitchBackend Switches method of rendering graphics.
bool IsFrontLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a front layer.
virtual RENDER_SETTINGS * GetSettings()=0
Function GetSettings Returns pointer to current settings that are going to be used when drawing items...
TRACK * Next() const
Definition: class_track.h:98
smd pads, front layer
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:996
Main rendering target (cached)
Definition: definitions.h:41
handle color for not plated holes
KIGFX::VIEW * m_view
Stores view settings (scale, center, etc.) and items to be drawn.
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
unsigned GetNodesCount() const
Function GetNodesCount.
DLIST< MODULE > m_Modules
Definition: class_board.h:245
Class COLORS_DESIGN_SETTINGS is a list of color settings for designs in Eeschema, Pcbnew and GerbView...
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
void SetPainter(PAINTER *aPainter)
Function SetPainter() Sets the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:186
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:108
void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:311
DLIST< TRACK > m_Track
Definition: class_board.h:246
virtual void SetTopLayer(int aLayer) override
>
Module description (excepted pads)
Class EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:53
KIGFX::PAINTER * m_painter
Contains information about how to draw items using GAL.
void OnShow() override
>
void UpdateAllLayersColor()
Function UpdateAllLayersColor() Applies the new coloring scheme to all layers.
Definition: view.cpp:674
#define NETNAMES_LAYER_INDEX(layer)
Macro for obtaining netname layer for a given PCB layer.
Handle colors used to draw all items or layers.
virtual PCB_LAYER_ID GetActiveLayer() const
Function GetActiveLayer returns the active layer.
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Function GetConnectivity() returns list of missing connections between components/tracks.
Definition: class_board.h:290
class PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer...
virtual void * GetDisplayOptions()
Function GetDisplayOptions A way to pass info to draw functions.
Definition: draw_frame.h:832
show modules references (when texts are visibles)
Additional netnames layers (not associated with a PCB layer)
bool IsNetnameLayer(LAYER_NUM aLayer)
Function IsNetnameLayer tests whether a layer is a netname layer.
unsigned GetNetCount() const
Function GetNetCount.
Definition: class_board.h:786
bool IsLayerVisible(PCB_LAYER_ID aLayer) const
Function IsLayerVisible is a proxy function that calls the correspondent function in m_BoardSettings ...
Definition: class_board.h:443