KiCad PCB EDA Suite
gerbview_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) 2017 KiCad Developers, see AUTHORS.txt for contributors.
5  *
6  * This program is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
21 #include <view/view.h>
22 #include <view/wx_view_controls.h>
23 #include <gerbview_painter.h>
24 #include <worksheet_viewitem.h>
25 
26 #include <colors_design_settings.h>
27 #include <gerbview_frame.h>
28 #include <gbr_display_options.h>
30 
31 #include <functional>
32 using namespace std::placeholders;
33 
34 
35 GERBVIEW_DRAW_PANEL_GAL::GERBVIEW_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWindowId,
36  const wxPoint& aPosition, const wxSize& aSize,
37  KIGFX::GAL_DISPLAY_OPTIONS& aOptions, GAL_TYPE aGalType ) :
38 EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalType )
39 {
40  m_view = new KIGFX::VIEW( true );
41  m_view->SetGAL( m_gal );
42  GetGAL()->SetWorldUnitLength( 1.0/IU_PER_MM /* 10 nm */ / 25.4 /* 1 inch in mm */ );
43 
44  m_painter.reset( new KIGFX::GERBVIEW_PAINTER( m_gal ) );
45  m_view->SetPainter( m_painter.get() );
46 
48 
50 
51 
52  // Load display options (such as filled/outline display of items).
53  auto frame = static_cast< GERBVIEW_FRAME* >( GetParentEDAFrame() );
54 
55  if( frame )
56  {
57  auto displ_opts = (GBR_DISPLAY_OPTIONS*) frame->GetDisplayOptions();
59  ->LoadDisplayOptions( displ_opts );
60  UseColorScheme( frame->m_colorsSettings );
61  }
62 }
63 
64 
66 {
67 }
68 
69 
71 {
74  rs->ImportLegacyColors( aSettings );
75 }
76 
77 
79 {
80  // Set display settings for high contrast mode
82 
83  SetTopLayer( aLayer );
84 
85  rSettings->ClearActiveLayers();
86  rSettings->SetActiveLayer( aLayer );
87  rSettings->SetActiveLayer( GERBER_DCODE_LAYER( aLayer ) );
88 
90 }
91 
92 
94  std::vector<MSG_PANEL_ITEM>& aList )
95 {
96 
97 }
98 
99 
101 {
102  GERBVIEW_FRAME* frame = dynamic_cast<GERBVIEW_FRAME*>( GetParent() );
103 
104  if( frame )
105  {
106  SetTopLayer( frame->GetActiveLayer() );
108  static_cast<KIGFX::GERBVIEW_RENDER_SETTINGS*>(
109  m_view->GetPainter()->GetSettings() )->LoadDisplayOptions( displ_opts );
110  }
111 
113 }
114 
115 
117 {
118  bool rv = EDA_DRAW_PANEL_GAL::SwitchBackend( aGalType );
120 
121  GetGAL()->SetWorldUnitLength( 1.0/IU_PER_MM /* 10 nm */ / 25.4 /* 1 inch in mm */ );
122 
123  return rv;
124 }
125 
126 
128 {
129  // caching makes no sense for Cairo and other software renderers
131 
132  for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; i++ )
133  m_view->SetLayerTarget( i, target );
134 
135  // for( int i = GERBVIEW_LAYER_ID_START; i < GERBVIEW_LAYER_ID_RESERVED; i++ )
136  // m_view->SetLayerDisplayOnly( i );
137 
144 
147 
150 }
151 
152 
154 {
155  m_worksheet.reset( aWorksheet );
156  m_view->Add( m_worksheet.get() );
157 }
158 
159 
161 {
163 
164  for( int i = 0; i < GERBER_DRAWLAYERS_COUNT; ++i )
165  {
167  m_view->SetLayerOrder( GERBER_DRAW_LAYER( i ), ( 2 * i ) + 1 );
168  }
169 
170  m_view->SetTopLayer( aLayer );
171 
172  // Move DCODE layer to the top
173  m_view->SetTopLayer( GERBER_DCODE_LAYER( aLayer ) );
174 
176 
178 
180 }
181 
182 
184 {
185  if( m_worksheet )
186  return m_worksheet->ViewBBox();
187 
188  return BOX2I();
189 }
Class GBR_DISPLAY_OPTIONS is a helper class to handle display options (filling modes and afew other o...
KIGFX::GAL * m_gal
Interface for drawing objects on a 2D-surface.
virtual void SetHighContrastLayer(int aLayer) override
>
BOX2< VECTOR2I > BOX2I
Definition: box2.h:520
KIGFX::WX_VIEW_CONTROLS * m_viewControls
Control for VIEW (moving, zooming, etc.)
void SetLayerOrder(int aLayer, int aRenderingOrder)
Function SetLayerOrder() Sets rendering order of a particular layer.
Definition: view.cpp:661
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:857
Class RENDER_SETTINGS Contains all the knowledge about how graphical objects are drawn on any output ...
Definition: painter.h:56
Handle colors used to draw all items or layers.
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.
EDA_DRAW_FRAME * GetParentEDAFrame() const
Function GetParentEDAFrame() Returns parent EDA_DRAW_FRAME, if available or NULL otherwise.
BOX2I GetDefaultViewBBox() const override
>
void RecacheAllItems()
Function RecacheAllItems() Rebuilds GAL display lists.
Definition: view.cpp:1392
void UpdateAllLayersOrder()
Function UpdateLayerOrder() Does everything that is needed to apply the rendering order of layers...
Definition: view.cpp:924
GERBVIEW_DRAW_PANEL_GAL(wxWindow *aParentWindow, wxWindowID aWindowId, const wxPoint &aPosition, const wxSize &aSize, KIGFX::GAL_DISPLAY_OPTIONS &aOptions, GAL_TYPE aGalType=GAL_TYPE_OPENGL)
int GetActiveLayer()
Function SetActiveLayer returns the active layer.
void setDefaultLayerDeps()
Sets rendering targets & dependencies for layers.
WX_VIEW_CONTROLS class definition.
static constexpr int VIEW_MAX_LAYERS
maximum number of layers that may be shown
Definition: view.h:699
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
Auxiliary rendering target (noncached)
Definition: definitions.h:42
Class that handles properties and drawing of worksheet layout.
#define GERBER_DCODE_LAYER(x)
void SetLayerTarget(int aLayer, RENDER_TARGET aTarget)
Function SetLayerTarget() Changes the rendering target for a particular layer.
Definition: view.h:445
void GetMsgPanelInfo(EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM > &aList) override
>
KIGFX::GAL * GetGAL() const
Function GetGAL() Returns a pointer to the GAL instance used in the panel.
#define GERBER_DRAWLAYERS_COUNT
void ClearActiveLayers()
Function ClearActiveLayers Clears the list of active layers.
Definition: painter.h:98
Class GERBVIEW_PAINTER Contains methods for drawing GerbView-specific items.
std::unique_ptr< KIGFX::PAINTER > m_painter
Contains information about how to draw items using GAL.
void SetLayerDisplayOnly(int aLayer, bool aDisplayOnly=true)
Definition: view.h:433
Items that may change while the view stays the same (noncached)
Definition: definitions.h:43
general purpose overlay
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:199
Class GERBVIEW_RENDER_SETTINGS Stores GerbView specific render settings.
void SetWorldUnitLength(double aWorldUnitLength)
Set the unit length.
void ClearTopLayers()
Function ClearTopLayers() Removes all layers from the on-the-top set (they are no longer displayed ov...
Definition: view.cpp:909
std::unique_ptr< KIGFX::WORKSHEET_VIEWITEM > m_worksheet
Currently used worksheet
virtual RENDER_SETTINGS * GetSettings()=0
Function GetSettings Returns pointer to current settings that are going to be used when drawing items...
bool SwitchBackend(GAL_TYPE aGalType) override
Function SwitchBackend Switches method of rendering graphics.
Main rendering target (cached)
Definition: definitions.h:41
KIGFX::VIEW * m_view
Stores view settings (scale, center, etc.) and items to be drawn.
size_t i
Definition: json11.cpp:597
virtual void SetTopLayer(int aLayer) override
>
currently selected items overlay
void SetWorksheet(KIGFX::WORKSHEET_VIEWITEM *aWorksheet)
Sets (or updates) worksheet used by the draw panel.
Class COLORS_DESIGN_SETTINGS is a list of color settings for designs in Pcbnew.
void SetPainter(PAINTER *aPainter)
Function SetPainter() Sets the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:189
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:344
#define GERBER_DRAW_LAYER(x)
void UseColorScheme(const COLORS_DESIGN_SETTINGS *aSettings)
Function UseColorScheme Applies layer color settings.
Class VIEW.
Definition: view.h:61
void UpdateAllLayersColor()
Function UpdateAllLayersColor() Applies the new coloring scheme to all layers.
Definition: view.cpp:795
void SetGAL(GAL *aGal)
Function SetGAL() Assigns a rendering device for the VIEW.
Definition: view.cpp:517
void ImportLegacyColors(const COLORS_DESIGN_SETTINGS *aSettings) override
Function ImportLegacyColors Loads a list of color settings for layers.
EDA_UNITS_T
Definition: common.h:159
virtual void * GetDisplayOptions()
A way to pass info to draw functions.
Definition: draw_frame.h:941