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 <pcb_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_data.h>
33 
34 #include <colors_design_settings.h>
35 #include <class_board.h>
36 #include <class_module.h>
37 #include <class_track.h>
38 #include <class_marker_pcb.h>
39 #include <pcb_base_frame.h>
40 #include <confirm.h>
41 
43 
44 #include <functional>
45 using namespace std::placeholders;
46 
48 {
50  LAYER_DRC,
53 
56 
61 
64 
95 
98 
101 };
102 
103 
104 PCB_DRAW_PANEL_GAL::PCB_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWindowId,
105  const wxPoint& aPosition, const wxSize& aSize,
106  KIGFX::GAL_DISPLAY_OPTIONS& aOptions, GAL_TYPE aGalType ) :
107 EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalType )
108 {
109  m_view = new KIGFX::PCB_VIEW( true );
110  m_view->SetGAL( m_gal );
111 
112  m_painter.reset( new KIGFX::PCB_PAINTER( m_gal ) );
113  m_view->SetPainter( m_painter.get() );
114 
117 
118  // View controls is the first in the event handler chain, so the Tool Framework operates
119  // on updated viewport data.
121 
122  // Load display options (such as filled/outline display of items).
123  // Can be made only if the parent window is an EDA_DRAW_FRAME (or a derived class)
124  // which is not always the case (namely when it is used from a wxDialog like the pad editor)
126 
127  if( frame )
128  {
129  auto opts = (PCB_DISPLAY_OPTIONS*) frame->GetDisplayOptions();
130  static_cast<KIGFX::PCB_VIEW*>( m_view )->UpdateDisplayOptions( opts );
131  }
132 }
133 
134 
136 {
137 }
138 
139 
141 {
142  m_view->Clear();
143 
144  // Load zones
145  for( auto zone : aBoard->Zones() )
146  {
147  zone->CacheTriangulation();
148  m_view->Add( zone );
149  }
150 
151  // Load drawings
152  for( auto drawing : const_cast<BOARD*>(aBoard)->Drawings() )
153  m_view->Add( drawing );
154 
155  // Load tracks
156  for( TRACK* track = aBoard->m_Track; track; track = track->Next() )
157  m_view->Add( track );
158 
159  // Load modules and its additional elements
160  for( MODULE* module = aBoard->m_Modules; module; module = module->Next() )
161  m_view->Add( module );
162 
163  // Segzones (deprecated, equivalent of ZONE_CONTAINERfilled areas for very old boards)
164  for( SEGZONE* zone = aBoard->m_SegZoneDeprecated; zone; zone = zone->Next() )
165  m_view->Add( zone );
166 
167  // DRC markers
168  for( int marker_idx = 0; marker_idx < aBoard->GetMARKERCount(); ++marker_idx )
169  {
170  m_view->Add( aBoard->GetMARKER( marker_idx ) );
171  }
172 
173  // Ratsnest
174  m_ratsnest.reset( new KIGFX::RATSNEST_VIEWITEM( aBoard->GetConnectivity() ) );
175  m_view->Add( m_ratsnest.get() );
176 }
177 
178 
180 {
181  m_worksheet.reset( aWorksheet );
182  m_view->Add( m_worksheet.get() );
183 }
184 
185 
187 {
189  rs = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( m_view->GetPainter()->GetSettings() );
190  rs->ImportLegacyColors( aSettings );
191  m_gal->SetGridColor( aSettings->GetLayerColor( LAYER_GRID ) );
192  m_gal->SetCursorColor( aSettings->GetItemColor( LAYER_CURSOR ) );
193 }
194 
195 
197 {
198  // Set display settings for high contrast mode
200 
201  SetTopLayer( aLayer );
202 
203  rSettings->ClearActiveLayers();
204  rSettings->SetActiveLayer( aLayer );
205 
206  if( IsCopperLayer( aLayer ) )
207  {
208  // Bring some other layers to the front in case of copper layers and make them colored
209  // fixme do not like the idea of storing the list of layers here,
210  // should be done in some other way I guess..
211  LAYER_NUM layers[] = {
212  GetNetnameLayer( aLayer ),
217  };
218 
219  for( unsigned int i = 0; i < sizeof( layers ) / sizeof( LAYER_NUM ); ++i )
220  rSettings->SetActiveLayer( layers[i] );
221 
222  // Pads should be shown too
223  if( aLayer == B_Cu )
224  {
225  rSettings->SetActiveLayer( LAYER_PAD_BK );
226  rSettings->SetActiveLayer( LAYER_MOD_BK );
228  }
229  else if( aLayer == F_Cu )
230  {
231  rSettings->SetActiveLayer( LAYER_PAD_FR );
232  rSettings->SetActiveLayer( LAYER_MOD_FR );
234  }
235  }
236 
238 }
239 
240 
242 {
245  m_view->SetTopLayer( aLayer );
246 
247  // Layers that should always have on-top attribute enabled
248  const LAYER_NUM layers[] = {
252  LAYER_DRC
253  };
254 
255  for( unsigned int i = 0; i < sizeof( layers ) / sizeof( LAYER_NUM ); ++i )
256  m_view->SetTopLayer( layers[i] );
257 
258  // Extra layers that are brought to the top if a F.* or B.* is selected
259  const LAYER_NUM frontLayers[] = {
262  };
263 
264  const LAYER_NUM backLayers[] = {
267  };
268 
269  const LAYER_NUM* extraLayers = NULL;
270 
271  // Bring a few more extra layers to the top depending on the selected board side
272  if( IsFrontLayer( aLayer ) )
273  extraLayers = frontLayers;
274  else if( IsBackLayer( aLayer ) )
275  extraLayers = backLayers;
276 
277  if( extraLayers )
278  {
279  const LAYER_NUM* l = extraLayers;
280 
281  while( *l >= 0 )
282  m_view->SetTopLayer( *l++ );
283 
284  // Move the active layer to the top
285  if( !IsCopperLayer( aLayer ) )
287  }
288  else if( IsCopperLayer( aLayer ) )
289  {
290  // Display labels for copper layers on the top
291  m_view->SetTopLayer( GetNetnameLayer( aLayer ) );
292  }
293 
295 }
296 
297 
299 {
300  // Load layer & elements visibility settings
301  for( LAYER_NUM i = 0; i < PCB_LAYER_ID_COUNT; ++i )
303 
305  m_view->SetLayerVisible( i, aBoard->IsElementVisible( i ) );
306 
307  // Always enable netname layers, as their visibility is controlled by layer dependencies
309  m_view->SetLayerVisible( i, true );
310 
311  // Enable some layers that are GAL specific
315 }
316 
317 
318 void PCB_DRAW_PANEL_GAL::GetMsgPanelInfo( std::vector<MSG_PANEL_ITEM>& aList )
319 {
320  BOARD* board = static_cast<PCB_BASE_FRAME*>( m_parent )->GetBoard();
321  wxString txt;
322  int viasCount = 0;
323  int trackSegmentsCount = 0;
324 
325  for( const BOARD_ITEM* item = board->m_Track; item; item = item->Next() )
326  {
327  if( item->Type() == PCB_VIA_T )
328  viasCount++;
329  else
330  trackSegmentsCount++;
331  }
332 
333  txt.Printf( wxT( "%d" ), board->GetPadCount() );
334  aList.push_back( MSG_PANEL_ITEM( _( "Pads" ), txt, DARKGREEN ) );
335 
336  txt.Printf( wxT( "%d" ), viasCount );
337  aList.push_back( MSG_PANEL_ITEM( _( "Vias" ), txt, DARKGREEN ) );
338 
339  txt.Printf( wxT( "%d" ), trackSegmentsCount );
340  aList.push_back( MSG_PANEL_ITEM( _( "Track Segments" ), txt, DARKGREEN ) );
341 
342  txt.Printf( wxT( "%d" ), board->GetNodesCount() );
343  aList.push_back( MSG_PANEL_ITEM( _( "Nodes" ), txt, DARKCYAN ) );
344 
345  txt.Printf( wxT( "%d" ), board->GetNetCount() );
346  aList.push_back( MSG_PANEL_ITEM( _( "Nets" ), txt, RED ) );
347 
348  txt.Printf( wxT( "%d" ), board->GetConnectivity()->GetUnconnectedCount() );
349  aList.push_back( MSG_PANEL_ITEM( _( "Unrouted" ), txt, BLUE ) );
350 }
351 
352 
354 {
355  PCB_BASE_FRAME* frame = dynamic_cast<PCB_BASE_FRAME*>( GetParent() );
356 
357  try
358  {
359  // Check if the current rendering backend can be properly initialized
360  m_view->UpdateItems();
361  }
362  catch( const std::runtime_error& e )
363  {
364  // Fallback to software renderer
365  DisplayError( frame, e.what() );
366  bool use_gal = SwitchBackend( GAL_TYPE_CAIRO );
367  frame->UseGalCanvas( use_gal );
368  }
369 
370  if( frame )
371  {
372  SetTopLayer( frame->GetActiveLayer() );
374  static_cast<KIGFX::PCB_RENDER_SETTINGS*>(
375  m_view->GetPainter()->GetSettings() )->LoadDisplayOptions( displ_opts );
376  }
377 
379 }
380 
381 
383 {
384  for( LAYER_NUM i = 0; (unsigned) i < sizeof( GAL_LAYER_ORDER ) / sizeof( LAYER_NUM ); ++i )
385  {
386  LAYER_NUM layer = GAL_LAYER_ORDER[i];
387  wxASSERT( layer < KIGFX::VIEW::VIEW_MAX_LAYERS );
388 
389  m_view->SetLayerOrder( layer, i );
390  }
391 }
392 
393 
395 {
396  bool rv = EDA_DRAW_PANEL_GAL::SwitchBackend( aGalType );
398  return rv;
399 }
400 
401 
403 {
404  if( m_ratsnest )
405  m_view->Update( m_ratsnest.get() );
406 }
407 
408 
410 {
411  if( m_worksheet )
412  return m_worksheet->ViewBBox();
413 
414  return BOX2I();
415 }
416 
417 
419 {
420  // caching makes no sense for Cairo and other software renderers
422 
423  for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; i++ )
424  m_view->SetLayerTarget( i, target );
425 
426  for( LAYER_NUM i = 0; (unsigned) i < sizeof( GAL_LAYER_ORDER ) / sizeof( LAYER_NUM ); ++i )
427  {
428  LAYER_NUM layer = GAL_LAYER_ORDER[i];
429  wxASSERT( layer < KIGFX::VIEW::VIEW_MAX_LAYERS );
430 
431  // Set layer display dependencies & targets
432  if( IsCopperLayer( layer ) )
433  m_view->SetRequired( GetNetnameLayer( layer ), layer );
434  else if( IsNetnameLayer( layer ) )
435  m_view->SetLayerDisplayOnly( layer );
436  }
437 
440 
441  // Some more required layers settings
447 
448  // Front modules
452 
453  // Back modules
457 
462 
466 }
467 
468 
470 {
471  return static_cast<KIGFX::PCB_VIEW*>( m_view );
472 }
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.
to draw blind/buried vias
BOX2< VECTOR2I > BOX2I
Definition: box2.h:468
MARKER_PCB * GetMARKER(int index) const
Function GetMARKER returns the MARKER at a given index.
Definition: class_board.h:322
void setDefaultLayerDeps()
Sets rendering targets & dependencies for layers.
Class that draws missing connections on a PCB.
KIGFX::WX_VIEW_CONTROLS * m_viewControls
Control for VIEW (moving, zooming, etc.)
void SetRequired(int aLayerId, int aRequiredId, bool aRequired=true)
Function SetRequired() Marks the aRequiredId layer as required for the aLayerId layer.
Definition: view.cpp:404
void SetLayerOrder(int aLayer, int aRenderingOrder)
Function SetLayerOrder() Sets rendering order of a particular layer.
Definition: view.cpp:612
GAL_TYPE m_backend
Currently used GAL.
virtual 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:803
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
multilayer pads, usually with holes
int GetNetnameLayer(int aLayer)
Returns a netname layer corresponding to the given layer.
This file is part of the common library.
Handle colors used to draw all items or layers.
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
Class WX_VIEW_CONTROLS is a specific implementation of class VIEW_CONTROLS for wxWidgets library...
virtual bool SwitchBackend(GAL_TYPE aGalType)
Function SwitchBackend Switches method of rendering graphics.
handle color for not plated holes (holes, not pads)
anchor of items having an anchor point (texts, footprints)
bool IsBackLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it&#39;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:1335
MODULE * Next() const
Definition: class_module.h:121
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)
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:870
Add new GAL layers here.
Class EDA_DRAW_FRAME is the base class for create windows for drawing purpose.
Definition: draw_frame.h:63
Class PCB_PAINTER Contains methods for drawing PCB-specific items.
Definition: pcb_painter.h:186
void ImportLegacyColors(const COLORS_DESIGN_SETTINGS *aSettings) override
Function ImportLegacyColors Loads a list of color settings for layers.
Definition: pcb_painter.cpp:73
smd pads, back layer
WX_VIEW_CONTROLS class definition.
void RedrawRatsnest()
Forces refresh of the ratsnest visual representation
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.
KIGFX::PCB_VIEW * view() const
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
virtual void UseGalCanvas(bool aEnable) override
>
SEGZONE * Next() const
Definition: class_track.h:364
Classes used in Pcbnew, CvPcb and GerbView.
show modules on front
std::unique_ptr< KIGFX::RATSNEST_VIEWITEM > m_ratsnest
Ratsnest view item
COLOR4D GetItemColor(int aItemIdx) const
Function GetItemColor.
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
void SetGridColor(const COLOR4D &aGridColor)
Set the grid color.
Markers used to show a drc problem on boards.
wxWindow * m_parent
Pointer to the parent window.
Class PCB_DISPLAY_OPTIONS handles display options like enable/disable some optional drawings...
PCB_LAYER_ID
A quick note on layer IDs:
void ClearActiveLayers()
Function ClearActiveLayers Clears the list of active layers.
Definition: painter.h:98
void DisplayBoard(BOARD *aBoard)
Function DisplayBoard adds all items from the current board to the VIEW, so they can be displayed by ...
void Clear()
Function Clear() Removes all items from the view.
Definition: view.cpp:1051
int GetLayerOrder(int aLayer) const
Function GetLayerOrder() Returns rendering order of a particular layer.
Definition: view.cpp:620
std::unique_ptr< KIGFX::PAINTER > m_painter
Contains information about how to draw items using GAL.
DLIST< SEGZONE > m_SegZoneDeprecated
Definition: class_board.h:247
void SetLayerDisplayOnly(int aLayer, bool aDisplayOnly=true)
Definition: view.h:411
to draw usual through hole vias
static const int VIEW_MAX_LAYERS
maximum number of layers that may be shown
Definition: view.h:675
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
void UpdateItems()
Function UpdateItems() Iterates through the list of items that asked for updating and updates them...
Definition: view.cpp:1354
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:196
void SetCursorColor(const COLOR4D &aCursorColor)
Set the cursor color.
void SyncLayersVisibility(const BOARD *aBoard)
Function SyncLayersVisibility Updates "visibility" property of each layer of a given BOARD...
virtual void Update(VIEW_ITEM *aItem, int aUpdateFlags)
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: view.cpp:1499
unsigned GetPadCount() const
Function GetPadCount.
BOX2I GetDefaultViewBBox() const override
>
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:855
virtual void SetHighContrastLayer(int aLayer) override
>
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
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&#39;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...
bool IsElementVisible(GAL_LAYER_ID aLayer) const
Function IsElementVisible tests whether a given element category is visible.
ZONE_CONTAINERS & Zones()
Definition: class_board.h:253
TRACK * Next() const
Definition: class_track.h:99
smd pads, front layer
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:169
unsigned GetNodesCount() const
Function GetNodesCount.
DLIST< MODULE > m_Modules
Definition: class_board.h:245
size_t i
Definition: json11.cpp:597
COLOR4D GetLayerColor(LAYER_NUM aLayer) const
Function GetLayerColor.
Class COLORS_DESIGN_SETTINGS is a list of color settings for designs in Pcbnew.
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:96
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:334
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
void OnShow() override
>
void UpdateAllLayersColor()
Function UpdateAllLayersColor() Applies the new coloring scheme to all layers.
Definition: view.cpp:743
void SetGAL(GAL *aGal)
Function SetGAL() Assigns a rendering device for the VIEW.
Definition: view.cpp:507
#define NETNAMES_LAYER_INDEX(layer)
Macro for obtaining netname layer for a given PCB layer.
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:185
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:291
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:918
show modules references (when texts are visibles)
Additional netnames layers (not associated with a PCB layer)
int GetMARKERCount() const
Function GetMARKERCount.
Definition: class_board.h:334
bool IsNetnameLayer(LAYER_NUM aLayer)
Function IsNetnameLayer tests whether a layer is a netname layer.
unsigned GetNetCount() const
Function GetNetCount.
Definition: class_board.h:773
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:452