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-2021 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>
25 #include <zoom_defines.h>
26 
27 #include <gerbview_frame.h>
29 #include <pgm_base.h>
31 
32 #include <gerber_file_image.h>
33 #include <gerber_file_image_list.h>
34 
35 #include <functional>
36 #include <memory>
37 
38 using namespace std::placeholders;
39 
40 
41 GERBVIEW_DRAW_PANEL_GAL::GERBVIEW_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWindowId,
42  const wxPoint& aPosition, const wxSize& aSize,
44  GAL_TYPE aGalType ) :
45 EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalType )
46 {
47  m_view = new KIGFX::VIEW( true );
48  m_view->SetGAL( m_gal );
49  GetGAL()->SetWorldUnitLength( 1.0/IU_PER_MM /* 10 nm */ / 25.4 /* 1 inch in mm */ );
50 
51  m_painter = std::make_unique<KIGFX::GERBVIEW_PAINTER>( m_gal );
52  m_view->SetPainter( m_painter.get() );
53 
54  // This fixes the zoom in and zoom out limits:
56 
58 
60 
61  // Load display options (such as filled/outline display of items).
62  auto frame = static_cast< GERBVIEW_FRAME* >( GetParentEDAFrame() );
63 
64  if( frame )
65  {
66  auto& displ_opts = frame->GetDisplayOptions();
67  auto rs = static_cast<KIGFX::GERBVIEW_RENDER_SETTINGS*>(
69 
70  rs->LoadDisplayOptions( displ_opts );
71  rs->LoadColors( Pgm().GetSettingsManager().GetColorSettings() );
72  }
73 }
74 
75 
77 {
78 }
79 
80 
82 {
83  // Set display settings for high contrast mode
85 
86  SetTopLayer( aLayer );
87 
88  rSettings->ClearHighContrastLayers();
89  rSettings->SetLayerIsHighContrast( aLayer );
90  rSettings->SetLayerIsHighContrast( GERBER_DCODE_LAYER( aLayer ) );
91 
93 }
94 
95 
97  std::vector<MSG_PANEL_ITEM>& aList )
98 {
99 
100 }
101 
102 
104 {
105  GERBVIEW_FRAME* frame = dynamic_cast<GERBVIEW_FRAME*>( GetParentEDAFrame() );
106 
107  if( frame )
108  {
109  SetTopLayer( frame->GetActiveLayer() );
110  auto& displ_opts = frame->GetDisplayOptions();
111  static_cast<KIGFX::GERBVIEW_RENDER_SETTINGS*>(
112  m_view->GetPainter()->GetSettings() )->LoadDisplayOptions( displ_opts );
113  }
114 
116 }
117 
118 
120 {
121  bool rv = EDA_DRAW_PANEL_GAL::SwitchBackend( aGalType );
122 
123  // The next onPaint event will call m_view->UpdateItems() that is very time consuming
124  // after switching to opengl. Clearing m_view and rebuild it is much faster
125  if( aGalType == GAL_TYPE_OPENGL )
126  {
127  GERBVIEW_FRAME* frame = dynamic_cast<GERBVIEW_FRAME*>( GetParentEDAFrame() );
128 
129  if( frame )
130  {
131  m_view->Clear();
132 
133  for( int layer = GERBER_DRAWLAYERS_COUNT-1; layer>= 0; --layer )
134  {
135  GERBER_FILE_IMAGE* gerber = frame->GetImagesList()->GetGbrImage( layer );
136 
137  if( gerber == nullptr ) // Graphic layer not yet used
138  continue;
139 
140  for( GERBER_DRAW_ITEM* item : gerber->GetItems() )
141  {
142  m_view->Add (item );
143  }
144  }
145  }
146  }
147 
149 
150  GetGAL()->SetWorldUnitLength( 1.0/IU_PER_MM /* 10 nm */ / 25.4 /* 1 inch in mm */ );
151 
152  return rv;
153 }
154 
155 
157 {
158  // caching makes no sense for Cairo and other software renderers
160 
161  for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; i++ )
162  m_view->SetLayerTarget( i, target );
163 
170 
173 
176 }
177 
178 
180 {
181  m_drawingSheet.reset( aDrawingSheet );
182  m_view->Add( m_drawingSheet.get() );
183 }
184 
185 
187 {
189 
190  for( int i = 0; i < GERBER_DRAWLAYERS_COUNT; ++i )
191  {
193  GERBER_DRAW_LAYER( 2 * i ) );
194  m_view->SetLayerOrder( GERBER_DRAW_LAYER( i ), GERBER_DRAW_LAYER( ( 2 * i ) + 1 ) );
195  }
196 
197  m_view->SetTopLayer( aLayer );
198 
199  // Move DCODE layer to the top
200  m_view->SetTopLayer( GERBER_DCODE_LAYER( aLayer ) );
201 
203 
205 
207 }
208 
209 
211 {
212  // Even in Gervbview, LAYER_DRAWINGSHEET controls the visibility of the drawingsheet
214  return m_drawingSheet->ViewBBox();
215 
216  return BOX2I();
217 }
void SetScaleLimits(double aMaximum, double aMinimum)
Set minimum and maximum values for scale.
Definition: view.h:304
KIGFX::GAL * m_gal
Interface for drawing objects on a 2D-surface.
currently selected items overlay
Definition: layer_ids.h:215
virtual void SetHighContrastLayer(int aLayer) override
BOX2< VECTOR2I > BOX2I
Definition: box2.h:506
#define GERBER_DCODE_LAYER(x)
Definition: layer_ids.h:400
KIGFX::WX_VIEW_CONTROLS * m_viewControls
Control for VIEW (moving, zooming, etc.)
void SetLayerOrder(int aLayer, int aRenderingOrder)
Set rendering order of a particular layer.
Definition: view.cpp:633
GAL_TYPE m_backend
Currently used GAL.
virtual void SetTopLayer(int aLayer, bool aEnabled=true)
Set given layer to be displayed on the top or sets back the default order of layers.
Definition: view.cpp:830
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
GERBER_DRAW_ITEMS & GetItems()
An 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)
Switch method of rendering graphics.
BOX2I GetDefaultViewBBox() const override
Return the bounding box of the view that should be used if model is not valid.
void RecacheAllItems()
Rebuild GAL display lists.
Definition: view.cpp:1389
Hold the image data and parameters for one gerber file and layer parameters.
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Called when the window is shown for the first time.
const GBR_DISPLAY_OPTIONS & GetDisplayOptions() const
void UpdateAllLayersOrder()
Do everything that is needed to apply the rendering order of layers.
Definition: view.cpp:897
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()
< Set rendering targets & dependencies for layers.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:208
WX_VIEW_CONTROLS class definition.
static constexpr int VIEW_MAX_LAYERS
maximum number of layers that may be shown
Definition: view.h:711
Auxiliary rendering target (noncached)
Definition: definitions.h:49
#define ZOOM_MAX_LIMIT_GERBVIEW
Definition: zoom_defines.h:58
void SetLayerTarget(int aLayer, RENDER_TARGET aTarget)
Change the rendering target for a particular layer.
Definition: view.h:461
#define ZOOM_MIN_LIMIT_GERBVIEW
Definition: zoom_defines.h:59
GERBER_FILE_IMAGE * GetGbrImage(int aIdx)
std::unique_ptr< DS_PROXY_VIEW_ITEM > m_drawingSheet
void Clear()
Remove all items from the view.
Definition: view.cpp:1104
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:449
#define GERBER_DRAWLAYERS_COUNT
Definition: layer_ids.h:378
Items that may change while the view stays the same (noncached)
Definition: definitions.h:50
KIGFX::GAL * GetGAL() const
Return a pointer to the GAL instance used in the panel.
void SetLayerIsHighContrast(int aLayerId, bool aEnabled=true)
Set the specified layer as high-contrast.
drawingsheet frame and titleblock
Definition: layer_ids.h:213
SETTINGS_MANAGER * GetSettingsManager()
#define GERBER_DRAW_LAYER(x)
Definition: layer_ids.h:398
void SetWorldUnitLength(double aWorldUnitLength)
Set the unit length.
void ClearTopLayers()
Remove all layers from the on-the-top set (they are no longer displayed over the rest of layers).
Definition: view.cpp:882
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
void OnShow() override
Called when the window is shown for the first time.
int GetActiveLayer() const
Return the active layer.
bool SwitchBackend(GAL_TYPE aGalType) override
Move the selected layer to the top, so it is displayed above all others.
see class PGM_BASE
virtual ~GERBVIEW_DRAW_PANEL_GAL()
Take care of display settings for the given layer to be displayed in high contrast mode.
Main rendering target (cached)
Definition: definitions.h:48
KIGFX::VIEW * m_view
Stores view settings (scale, center, etc.) and items to be drawn.
void SetDrawingSheet(DS_PROXY_VIEW_ITEM *aDrawingSheet)
Set or update the drawing-sheet (borders and title block) used by the draw panel.
general purpose overlay
Definition: layer_ids.h:214
EDA_DRAW_FRAME * GetParentEDAFrame() const
Returns parent EDA_DRAW_FRAME, if available or NULL otherwise.
virtual void SetTopLayer(int aLayer) override
Return the bounding box of the view that should be used if model is not valid.
void ClearHighContrastLayers()
Clear the list of active layers.
void SetPainter(PAINTER *aPainter)
Set the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:198
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:318
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:68
void UpdateAllLayersColor()
Apply the new coloring scheme to all layers.
Definition: view.cpp:766
void SetGAL(GAL *aGal)
Assign a rendering device for the VIEW.
Definition: view.cpp:491
GERBER_FILE_IMAGE_LIST * GetImagesList() const
Accessors to GERBER_FILE_IMAGE_LIST and GERBER_FILE_IMAGE data.
bool IsLayerVisible(int aLayer) const
Return information about visibility of a particular layer.
Definition: view.h:405