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 
34 #include <class_board.h>
35 #include <class_module.h>
36 #include <class_track.h>
37 #include <wxBasePcbFrame.h>
38 
39 #include <functional>
40 using namespace std::placeholders;
41 
43 {
48 
51 
56 
59 
90 
93 
96 };
97 
98 
99 PCB_DRAW_PANEL_GAL::PCB_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWindowId,
100  const wxPoint& aPosition, const wxSize& aSize,
101  KIGFX::GAL_DISPLAY_OPTIONS& aOptions, GAL_TYPE aGalType ) :
102 EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalType )
103 {
106 
109 
110  // Load display options (such as filled/outline display of items).
111  // Can be made only if the parent window is an EDA_DRAW_FRAME (or a derived class)
112  // which is not always the case (namely when it is used from a wxDialog like the pad editor)
114 
115  if( frame )
116  {
117  DISPLAY_OPTIONS* displ_opts = (DISPLAY_OPTIONS*) frame->GetDisplayOptions();
118  static_cast<KIGFX::PCB_RENDER_SETTINGS*>( m_view->GetPainter()->GetSettings() )->LoadDisplayOptions( displ_opts );
119  }
120 }
121 
122 
124 {
125  delete m_painter;
126 }
127 
128 
130 {
131  m_view->Clear();
132 
133  // Load zones
134  for( int i = 0; i < aBoard->GetAreaCount(); ++i )
135  m_view->Add( (KIGFX::VIEW_ITEM*) ( aBoard->GetArea( i ) ) );
136 
137  // Load drawings
138  for( BOARD_ITEM* drawing = aBoard->m_Drawings; drawing; drawing = drawing->Next() )
139  m_view->Add( drawing );
140 
141  // Load tracks
142  for( TRACK* track = aBoard->m_Track; track; track = track->Next() )
143  m_view->Add( track );
144 
145  // Load modules and its additional elements
146  for( MODULE* module = aBoard->m_Modules; module; module = module->Next() )
147  {
148  module->RunOnChildren( std::bind( &KIGFX::VIEW::Add, m_view, _1, -1 ) );
149  m_view->Add( module );
150  }
151 
152  // Segzones (equivalent of ZONE_CONTAINER for legacy boards)
153  for( SEGZONE* zone = aBoard->m_Zone; zone; zone = zone->Next() )
154  m_view->Add( zone );
155 
156  // Ratsnest
157  m_ratsnest.reset( new KIGFX::RATSNEST_VIEWITEM( aBoard->GetRatsnest() ) );
158  m_view->Add( m_ratsnest.get() );
159 
160  // Display settings
161  UseColorScheme( aBoard->GetColorsSettings() );
162 }
163 
164 
166 {
167  m_worksheet.reset( aWorksheet );
168  m_view->Add( m_worksheet.get() );
169 }
170 
171 
173 {
175  rs = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( m_view->GetPainter()->GetSettings() );
176  rs->ImportLegacyColors( aSettings );
177 }
178 
179 
181 {
182  // Set display settings for high contrast mode
184 
185  SetTopLayer( aLayer );
186 
187  rSettings->ClearActiveLayers();
188  rSettings->SetActiveLayer( aLayer );
189 
190  if( IsCopperLayer( aLayer ) )
191  {
192  // Bring some other layers to the front in case of copper layers and make them colored
193  // fixme do not like the idea of storing the list of layers here,
194  // should be done in some other way I guess..
195  LAYER_NUM layers[] = {
200  };
201 
202  for( unsigned int i = 0; i < sizeof( layers ) / sizeof( LAYER_NUM ); ++i )
203  rSettings->SetActiveLayer( layers[i] );
204 
205  // Pads should be shown too
206  if( aLayer == B_Cu )
207  {
211  }
212  else if( aLayer == F_Cu )
213  {
217  }
218  }
219 
221 }
222 
223 
225 {
228  m_view->SetTopLayer( aLayer );
229 
230  // Layers that should always have on-top attribute enabled
231  const LAYER_NUM layers[] = {
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 < LAYER_ID_COUNT; ++i )
286  {
287  m_view->SetLayerVisible( i, aBoard->IsLayerVisible( LAYER_ID( i ) ) );
288 
289  // Synchronize netname layers as well
290  if( IsCopperLayer( i ) )
292  }
293 
294  for( LAYER_NUM i = 0; i < END_PCB_VISIBLE_LIST; ++i )
295  {
296  m_view->SetLayerVisible( ITEM_GAL_LAYER( 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->GetRatsnest()->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
405 
406  // Front modules
416 
417  // Back modules
427 
432 
436 }
void SetWorksheet(KIGFX::WORKSHEET_VIEWITEM *aWorksheet)
Function SetWorksheet Sets (or updates) worksheet used by the draw panel.
show modules on front
Definition: colors.h:57
multilayer pads, usually with holes
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 ...
void setDefaultLayerDeps()
Sets rendering targets & dependencies for layers.
Class that draws missing connections on a PCB.
virtual LAYER_ID GetActiveLayer() const
Function GetActiveLayer returns the active layer.
void SetRequired(int aLayerId, int aRequiredId, bool aRequired=true)
Function SetRequired() Marks the aRequiredId layer as required for the aLayerId layer.
Definition: view.cpp:380
void SetLayerOrder(int aLayer, int aRenderingOrder)
Function SetLayerOrder() Sets rendering order of a particular layer.
Definition: view.cpp:588
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:747
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.
bool IsBackLayer(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.
bool IsFrontLayer(LAYER_ID aLayerId)
Layer classification: check if it's a front layer.
void RecacheAllItems()
Function RecacheAllItems() Rebuilds GAL display lists.
Definition: view.cpp:1252
MODULE * Next() const
Definition: class_module.h:99
DLIST< SEGZONE > m_Zone
Definition: class_board.h:245
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:814
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:163
void ImportLegacyColors(const COLORS_DESIGN_SETTINGS *aSettings) override
Function ImportLegacyColors Loads a list of color settings for layers.
Definition: pcb_painter.cpp:66
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:75
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:362
std::unique_ptr< KIGFX::RATSNEST_VIEWITEM > m_ratsnest
Ratsnest view item
BOARD_ITEM * Next() const
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.
Classes used in Pcbnew, CvPcb and GerbView.
void ClearActiveLayers()
Function ClearActiveLayers Clears the list of active layers.
Definition: painter.h:97
void Clear()
Function Clear() Removes all items from the view.
Definition: view.cpp:981
int GetLayerOrder(int aLayer) const
Function GetLayerOrder() Returns rendering order of a particular layer.
Definition: view.cpp:596
void SetLayerDisplayOnly(int aLayer, bool aDisplayOnly=true)
Definition: view.h:411
static const int VIEW_MAX_LAYERS
maximum number of layers that may be shown
Definition: view.h:640
show modules references (when texts are visibles)
COLORS_DESIGN_SETTINGS * GetColorsSettings() const
Function GetColorSettings.
Definition: class_board.h:561
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)
DLIST< BOARD_ITEM > m_Drawings
Definition: class_board.h:242
Items that may change while the view stays the same (noncached)
Definition: definitions.h:43
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:1051
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...
unsigned GetPadCount() const
Function GetPadCount.
Definition: class_board.h:741
RN_DATA * GetRatsnest() const
Function GetRatsnest() returns list of missing connections between components/tracks.
Definition: class_board.h:287
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:799
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 IsLayerVisible(LAYER_ID aLayer) const
Function IsLayerVisible is a proxy function that calls the correspondent function in m_BoardSettings ...
Definition: class_board.h:440
virtual RENDER_SETTINGS * GetSettings()=0
Function GetSettings Returns pointer to current settings that are going to be used when drawing items...
#define ITEM_GAL_LAYER(layer)
macro for obtaining layer number for specific item (eg. pad or text)
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
Main rendering target (cached)
Definition: definitions.h:41
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:166
LAYER_ID
Enum LAYER_ID is the set of PCB layers.
unsigned GetNodesCount() const
Function GetNodesCount.
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.
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:310
DLIST< TRACK > m_Track
Definition: class_board.h:244
virtual void SetTopLayer(int aLayer) override
>
general purpose overlay
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:673
Handle colors used to draw all items or layers.
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:818
#define NETNAMES_GAL_LAYER(layer)
show modules values (when texts are visibles)
bool IsNetnameLayer(LAYER_NUM aLayer)
Function IsNetnameLayer tests whether a layer is a netname layer.
unsigned GetNetCount() const
Function GetNetCount.
Definition: class_board.h:814
int GetUnconnectedCount() const
Function GetUnconnectedCount() Returns the number of missing connections.