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) 2018 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 <ws_proxy_view_item.h>
25 
26 #include <colors_design_settings.h>
27 #include <gerbview_frame.h>
28 #include <gbr_display_options.h>
30 
31 #include <gerber_file_image.h>
32 #include <gerber_file_image_list.h>
33 
34 #include <functional>
35 #include <memory>
36 using namespace std::placeholders;
37 
38 
39 GERBVIEW_DRAW_PANEL_GAL::GERBVIEW_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWindowId,
40  const wxPoint& aPosition, const wxSize& aSize,
41  KIGFX::GAL_DISPLAY_OPTIONS& aOptions, GAL_TYPE aGalType ) :
42 EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalType )
43 {
44  m_view = new KIGFX::VIEW( true );
45  m_view->SetGAL( m_gal );
46  GetGAL()->SetWorldUnitLength( 1.0/IU_PER_MM /* 10 nm */ / 25.4 /* 1 inch in mm */ );
47 
48  m_painter = std::make_unique<KIGFX::GERBVIEW_PAINTER>( m_gal );
49  m_view->SetPainter( m_painter.get() );
50 
52 
54 
55 
56  // Load display options (such as filled/outline display of items).
57  auto frame = static_cast< GERBVIEW_FRAME* >( GetParentEDAFrame() );
58 
59  if( frame )
60  {
61  auto& displ_opts = frame->GetDisplayOptions();
62  static_cast<KIGFX::GERBVIEW_RENDER_SETTINGS*>( m_view->GetPainter()->GetSettings() )
63  ->LoadDisplayOptions( displ_opts );
64  UseColorScheme( frame->m_colorsSettings );
65  }
66 }
67 
68 
70 {
71 }
72 
73 
75 {
77  rs = static_cast<KIGFX::GERBVIEW_RENDER_SETTINGS*>( m_view->GetPainter()->GetSettings() );
78  rs->ImportLegacyColors( aSettings );
79 }
80 
81 
83 {
84  // Set display settings for high contrast mode
86 
87  SetTopLayer( aLayer );
88 
89  rSettings->ClearActiveLayers();
90  rSettings->SetActiveLayer( aLayer );
91  rSettings->SetActiveLayer( GERBER_DCODE_LAYER( aLayer ) );
92 
94 }
95 
96 
98  EDA_UNITS aUnits, std::vector<MSG_PANEL_ITEM>& aList )
99 {
100 
101 }
102 
103 
105 {
106  GERBVIEW_FRAME* frame = dynamic_cast<GERBVIEW_FRAME*>( GetParent() );
107 
108  if( frame )
109  {
110  SetTopLayer( frame->GetActiveLayer() );
111  auto& displ_opts = frame->GetDisplayOptions();
112  static_cast<KIGFX::GERBVIEW_RENDER_SETTINGS*>(
113  m_view->GetPainter()->GetSettings() )->LoadDisplayOptions( displ_opts );
114  }
115 
117 }
118 
119 
121 {
122  bool rv = EDA_DRAW_PANEL_GAL::SwitchBackend( aGalType );
123 
124  // The next onPaint event will call m_view->UpdateItems() that is very time consumming
125  // after switching to opengl. Clearing m_view and rebuild it is much faster
126  if( aGalType == GAL_TYPE_OPENGL )
127  {
128  GERBVIEW_FRAME* frame = dynamic_cast<GERBVIEW_FRAME*>( GetParent() );
129 
130  if( frame )
131  {
132  m_view->Clear();
133 
134  for( int layer = GERBER_DRAWLAYERS_COUNT-1; layer>= 0; --layer )
135  {
136  GERBER_FILE_IMAGE* gerber = frame->GetImagesList()->GetGbrImage( layer );
137 
138  if( gerber == NULL ) // Graphic layer not yet used
139  continue;
140 
141  for( GERBER_DRAW_ITEM* item : gerber->GetItems() )
142  {
143  m_view->Add (item );
144  }
145  }
146  }
147  }
148 
150 
151  GetGAL()->SetWorldUnitLength( 1.0/IU_PER_MM /* 10 nm */ / 25.4 /* 1 inch in mm */ );
152 
153  return rv;
154 }
155 
156 
158 {
159  // caching makes no sense for Cairo and other software renderers
161 
162  for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; i++ )
163  m_view->SetLayerTarget( i, target );
164 
165  // for( int i = GERBVIEW_LAYER_ID_START; i < GERBVIEW_LAYER_ID_RESERVED; i++ )
166  // m_view->SetLayerDisplayOnly( i );
167 
174 
177 
180 }
181 
182 
184 {
185  m_worksheet.reset( aWorksheet );
186  m_view->Add( m_worksheet.get() );
187 }
188 
189 
191 {
193 
194  for( int i = 0; i < GERBER_DRAWLAYERS_COUNT; ++i )
195  {
197  m_view->SetLayerOrder( GERBER_DRAW_LAYER( i ), ( 2 * i ) + 1 );
198  }
199 
200  m_view->SetTopLayer( aLayer );
201 
202  // Move DCODE layer to the top
203  m_view->SetTopLayer( GERBER_DCODE_LAYER( aLayer ) );
204 
206 
208 
210 }
211 
212 
214 {
216  return m_worksheet->ViewBBox();
217 
218  return BOX2I();
219 }
EDA_UNITS
Definition: common.h:72
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:521
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:664
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:860
RENDER_SETTINGS Contains all the knowledge about how graphical objects are drawn on any output surfac...
Definition: painter.h:56
GERBER_DRAW_ITEMS & GetItems()
Handle colors used to draw all items or layers.
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.
BOX2I GetDefaultViewBBox() const override
void RecacheAllItems()
Function RecacheAllItems() Rebuilds GAL display lists.
Definition: view.cpp:1402
GERBER_FILE_IMAGE holds the Image data and parameters for one gerber file and layer parameters (TODO:...
const GBR_DISPLAY_OPTIONS & GetDisplayOptions() const
Function GetDisplayOptions returns the display options current in use.
void UpdateAllLayersOrder()
Function UpdateLayerOrder() Does everything that is needed to apply the rendering order of layers.
Definition: view.cpp:927
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.
void GetMsgPanelInfo(EDA_UNITS aUnits, std::vector< MSG_PANEL_ITEM > &aList) override
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:199
WX_VIEW_CONTROLS class definition.
static constexpr int VIEW_MAX_LAYERS
maximum number of layers that may be shown
Definition: view.h:701
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:49
#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:434
#define NULL
#define GERBER_DRAWLAYERS_COUNT
void ClearActiveLayers()
Function ClearActiveLayers Clears the list of active layers.
Definition: painter.h:98
GERBER_FILE_IMAGE * GetGbrImage(int aIdx)
void Clear()
Function Clear() Removes all items from the view.
Definition: view.cpp:1111
void SetWorksheet(KIGFX::WS_PROXY_VIEW_ITEM *aWorksheet)
Sets (or updates) worksheet used by the draw panel.
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:422
Items that may change while the view stays the same (noncached)
Definition: definitions.h:50
KIGFX::GAL * GetGAL() const
Function GetGAL() Returns a pointer to the GAL instance used in the panel.
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:912
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:48
KIGFX::VIEW * m_view
Stores view settings (scale, center, etc.) and items to be drawn.
EDA_DRAW_FRAME * GetParentEDAFrame() const
Function GetParentEDAFrame() Returns parent EDA_DRAW_FRAME, if available or NULL otherwise.
virtual void SetTopLayer(int aLayer) override
currently selected items overlay
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:346
std::unique_ptr< KIGFX::WS_PROXY_VIEW_ITEM > m_worksheet
Currently used worksheet
#define GERBER_DRAW_LAYER(x)
void UseColorScheme(const COLORS_DESIGN_SETTINGS *aSettings)
Function UseColorScheme Applies layer color settings.
VIEW.
Definition: view.h:61
void UpdateAllLayersColor()
Function UpdateAllLayersColor() Applies the new coloring scheme to all layers.
Definition: view.cpp:798
void SetGAL(GAL *aGal)
Function SetGAL() Assigns a rendering device for the VIEW.
Definition: view.cpp:519
GERBER_FILE_IMAGE_LIST * GetImagesList() const
Accessors to GERBER_FILE_IMAGE_LIST and GERBER_FILE_IMAGE data.
void ImportLegacyColors(const COLORS_DESIGN_SETTINGS *aSettings) override
Function ImportLegacyColors Loads a list of color settings for layers.
bool IsLayerVisible(int aLayer) const
Function IsLayerVisible() Returns information about visibility of a particular layer.
Definition: view.h:416