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 <worksheet_viewitem.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 using namespace std::placeholders;
36 
37 
38 GERBVIEW_DRAW_PANEL_GAL::GERBVIEW_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWindowId,
39  const wxPoint& aPosition, const wxSize& aSize,
40  KIGFX::GAL_DISPLAY_OPTIONS& aOptions, GAL_TYPE aGalType ) :
41 EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalType )
42 {
43  m_view = new KIGFX::VIEW( true );
44  m_view->SetGAL( m_gal );
45  GetGAL()->SetWorldUnitLength( 1.0/IU_PER_MM /* 10 nm */ / 25.4 /* 1 inch in mm */ );
46 
47  m_painter.reset( new KIGFX::GERBVIEW_PAINTER( m_gal ) );
48  m_view->SetPainter( m_painter.get() );
49 
51 
53 
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 = (GBR_DISPLAY_OPTIONS*) frame->GetDisplayOptions();
61  static_cast<KIGFX::GERBVIEW_RENDER_SETTINGS*>( m_view->GetPainter()->GetSettings() )
62  ->LoadDisplayOptions( displ_opts );
63  UseColorScheme( frame->m_colorsSettings );
64  }
65 }
66 
67 
69 {
70 }
71 
72 
74 {
76  rs = static_cast<KIGFX::GERBVIEW_RENDER_SETTINGS*>( m_view->GetPainter()->GetSettings() );
77  rs->ImportLegacyColors( aSettings );
78 }
79 
80 
82 {
83  // Set display settings for high contrast mode
85 
86  SetTopLayer( aLayer );
87 
88  rSettings->ClearActiveLayers();
89  rSettings->SetActiveLayer( aLayer );
90  rSettings->SetActiveLayer( 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*>( GetParent() );
106 
107  if( frame )
108  {
109  SetTopLayer( frame->GetActiveLayer() );
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 consumming
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*>( GetParent() );
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 == NULL ) // Graphic layer not yet used
138  continue;
139 
140  for( GERBER_DRAW_ITEM* item = gerber->GetItemsList(); item; item = item->Next() )
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 
164  // for( int i = GERBVIEW_LAYER_ID_START; i < GERBVIEW_LAYER_ID_RESERVED; i++ )
165  // m_view->SetLayerDisplayOnly( i );
166 
173 
176 
179 }
180 
181 
183 {
184  m_worksheet.reset( aWorksheet );
185  m_view->Add( m_worksheet.get() );
186 }
187 
188 
190 {
192 
193  for( int i = 0; i < GERBER_DRAWLAYERS_COUNT; ++i )
194  {
196  m_view->SetLayerOrder( GERBER_DRAW_LAYER( i ), ( 2 * i ) + 1 );
197  }
198 
199  m_view->SetTopLayer( aLayer );
200 
201  // Move DCODE layer to the top
202  m_view->SetTopLayer( GERBER_DCODE_LAYER( aLayer ) );
203 
205 
207 
209 }
210 
211 
213 {
214  if( m_worksheet )
215  return m_worksheet->ViewBBox();
216 
217  return BOX2I();
218 }
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: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:859
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.
BOX2I GetDefaultViewBBox() const override
void RecacheAllItems()
Function RecacheAllItems() Rebuilds GAL display lists.
Definition: view.cpp:1401
Class GERBER_FILE_IMAGE holds the Image data and parameters for one gerber file and layer parameters ...
void UpdateAllLayersOrder()
Function UpdateLayerOrder() Does everything that is needed to apply the rendering order of layers.
Definition: view.cpp:926
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.
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:712
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
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
#define GERBER_DRAWLAYERS_COUNT
void ClearActiveLayers()
Function ClearActiveLayers Clears the list of active layers.
Definition: painter.h:98
GERBER_FILE_IMAGE * GetGbrImage(int aIdx)
Class GERBVIEW_PAINTER Contains methods for drawing GerbView-specific items.
void Clear()
Function Clear() Removes all items from the view.
Definition: view.cpp:1110
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:50
KIGFX::GAL * GetGAL() const
Function GetGAL() Returns a pointer to the GAL instance used in the panel.
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:911
std::unique_ptr< KIGFX::WORKSHEET_VIEWITEM > m_worksheet
Currently used worksheet
GERBER_DRAW_ITEM * Next() const
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.
GERBER_DRAW_ITEM * GetItemsList()
Function GetItemsList.
size_t i
Definition: json11.cpp:597
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 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:346
#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:797
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.
EDA_UNITS_T
Definition: common.h:160
virtual void * GetDisplayOptions()
A way to pass info to draw functions.
Definition: draw_frame.h:948