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 <gerbview_frame.h>
27 #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  // Load display options (such as filled/outline display of items).
56  auto frame = static_cast< GERBVIEW_FRAME* >( GetParentEDAFrame() );
57 
58  if( frame )
59  {
60  auto& displ_opts = frame->GetDisplayOptions();
61  auto rs = static_cast<KIGFX::GERBVIEW_RENDER_SETTINGS*>(
63 
64  rs->LoadDisplayOptions( displ_opts );
65  rs->LoadColors( Pgm().GetSettingsManager().GetColorSettings() );
66  }
67 }
68 
69 
71 {
72 }
73 
74 
76 {
77  // Set display settings for high contrast mode
79 
80  SetTopLayer( aLayer );
81 
82  rSettings->ClearActiveLayers();
83  rSettings->SetActiveLayer( aLayer );
84  rSettings->SetActiveLayer( GERBER_DCODE_LAYER( aLayer ) );
85 
87 }
88 
89 
91  std::vector<MSG_PANEL_ITEM>& aList )
92 {
93 
94 }
95 
96 
98 {
99  GERBVIEW_FRAME* frame = dynamic_cast<GERBVIEW_FRAME*>( GetParentEDAFrame() );
100 
101  if( frame )
102  {
103  SetTopLayer( frame->GetActiveLayer() );
104  auto& displ_opts = frame->GetDisplayOptions();
105  static_cast<KIGFX::GERBVIEW_RENDER_SETTINGS*>(
106  m_view->GetPainter()->GetSettings() )->LoadDisplayOptions( displ_opts );
107  }
108 
110 }
111 
112 
114 {
115  bool rv = EDA_DRAW_PANEL_GAL::SwitchBackend( aGalType );
116 
117  // The next onPaint event will call m_view->UpdateItems() that is very time consumming
118  // after switching to opengl. Clearing m_view and rebuild it is much faster
119  if( aGalType == GAL_TYPE_OPENGL )
120  {
121  GERBVIEW_FRAME* frame = dynamic_cast<GERBVIEW_FRAME*>( GetParentEDAFrame() );
122 
123  if( frame )
124  {
125  m_view->Clear();
126 
127  for( int layer = GERBER_DRAWLAYERS_COUNT-1; layer>= 0; --layer )
128  {
129  GERBER_FILE_IMAGE* gerber = frame->GetImagesList()->GetGbrImage( layer );
130 
131  if( gerber == NULL ) // Graphic layer not yet used
132  continue;
133 
134  for( GERBER_DRAW_ITEM* item : gerber->GetItems() )
135  {
136  m_view->Add (item );
137  }
138  }
139  }
140  }
141 
143 
144  GetGAL()->SetWorldUnitLength( 1.0/IU_PER_MM /* 10 nm */ / 25.4 /* 1 inch in mm */ );
145 
146  return rv;
147 }
148 
149 
151 {
152  // caching makes no sense for Cairo and other software renderers
154 
155  for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; i++ )
156  m_view->SetLayerTarget( i, target );
157 
158  // for( int i = GERBVIEW_LAYER_ID_START; i < GERBVIEW_LAYER_ID_RESERVED; i++ )
159  // m_view->SetLayerDisplayOnly( i );
160 
167 
170 
173 }
174 
175 
177 {
178  m_worksheet.reset( aWorksheet );
179  m_view->Add( m_worksheet.get() );
180 }
181 
182 
184 {
186 
187  for( int i = 0; i < GERBER_DRAWLAYERS_COUNT; ++i )
188  {
190  m_view->SetLayerOrder( GERBER_DRAW_LAYER( i ), ( 2 * i ) + 1 );
191  }
192 
193  m_view->SetTopLayer( aLayer );
194 
195  // Move DCODE layer to the top
196  m_view->SetTopLayer( GERBER_DCODE_LAYER( aLayer ) );
197 
199 
201 
203 }
204 
205 
207 {
208  // Even in Gervbview, this is the LAYER_WORKSHEET that controls the visibility
209  // of the worksheet
211  return m_worksheet->ViewBBox();
212 
213  return BOX2I();
214 }
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:522
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:104
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:663
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:856
RENDER_SETTINGS Contains all the knowledge about how graphical objects are drawn on any output surfac...
GERBER_DRAW_ITEMS & GetItems()
WX_VIEW_CONTROLS is a specific implementation of class VIEW_CONTROLS for wxWidgets library.
static constexpr double IU_PER_MM
Mock up a conversion function.
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:1395
GERBER_FILE_IMAGE holds the Image data and parameters for one gerber file and layer parameters (TODO:...
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
const GBR_DISPLAY_OPTIONS & GetDisplayOptions() const
void UpdateAllLayersOrder()
Function UpdateLayerOrder() Does everything that is needed to apply the rendering order of layers.
Definition: view.cpp:923
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)
The base class for create windows for drawing purpose.
void setDefaultLayerDeps()
Sets rendering targets & dependencies for layers.
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:697
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...
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:423
#define NULL
#define GERBER_DRAWLAYERS_COUNT
void ClearActiveLayers()
Function ClearActiveLayers Clears the list of active layers.
GERBER_FILE_IMAGE * GetGbrImage(int aIdx)
void Clear()
Function Clear() Removes all items from the view.
Definition: view.cpp:1107
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:411
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.
SETTINGS_MANAGER * GetSettingsManager()
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:908
virtual RENDER_SETTINGS * GetSettings()=0
Function GetAdapter Returns pointer to current settings that are going to be used when drawing items.
int GetActiveLayer() const
Function SetActiveLayer returns the active layer.
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
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:345
std::unique_ptr< KIGFX::WS_PROXY_VIEW_ITEM > m_worksheet
Currently used worksheet
#define GERBER_DRAW_LAYER(x)
VIEW.
Definition: view.h:61
void UpdateAllLayersColor()
Function UpdateAllLayersColor() Applies the new coloring scheme to all layers.
Definition: view.cpp:794
void SetGAL(GAL *aGal)
Function SetGAL() Assigns a rendering device for the VIEW.
Definition: view.cpp:518
GERBER_FILE_IMAGE_LIST * GetImagesList() const
Accessors to GERBER_FILE_IMAGE_LIST and GERBER_FILE_IMAGE data.
bool IsLayerVisible(int aLayer) const
Function IsLayerVisible() Returns information about visibility of a particular layer.
Definition: view.h:405