KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 The 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
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
21#include <view/view.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>
34
35#include <functional>
36#include <memory>
37
38using namespace std::placeholders;
39
40
41GERBVIEW_DRAW_PANEL_GAL::GERBVIEW_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWindowId,
42 const wxPoint& aPosition, const wxSize& aSize,
44 GAL_TYPE aGalType ) :
45EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalType )
46{
47 m_view = new KIGFX::VIEW();
48 m_view->SetGAL( m_gal );
49 GetGAL()->SetWorldUnitLength( 1.0/gerbIUScale.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
62
63 if( GERBVIEW_FRAME* frame = dynamic_cast<GERBVIEW_FRAME*>( GetParentEDAFrame() ) )
64 cs = frame->GetColorSettings();
65
66 auto renderSettings = static_cast<KIGFX::GERBVIEW_RENDER_SETTINGS*>( m_painter->GetSettings() );
67 renderSettings->LoadColors( cs );
68}
69
70
74
75
77{
78 // Set display settings for high contrast mode
79 auto rSettings = static_cast<KIGFX::GERBVIEW_RENDER_SETTINGS*>( m_view->GetPainter()->GetSettings() );
80
81 SetTopLayer( aLayer );
82
83 rSettings->ClearHighContrastLayers();
84 rSettings->SetLayerIsHighContrast( aLayer );
85 rSettings->SetLayerIsHighContrast( GERBER_DCODE_LAYER( aLayer ) );
86
87 if( rSettings->GetContrastMode() == GBR_INACTIVE_LAYER_MODE::HIDDEN )
88 m_view->UpdateAllItems( KIGFX::REPAINT );
89 else
90 m_view->UpdateAllLayersColor();
91}
92
93
95 std::vector<MSG_PANEL_ITEM>& aList )
96{
97}
98
99
101{
102 GERBVIEW_FRAME* frame = dynamic_cast<GERBVIEW_FRAME*>( GetParentEDAFrame() );
103
104 if( frame )
105 SetTopLayer( frame->GetActiveLayer() );
106
107 m_view->RecacheAllItems();
108}
109
110
112{
113 bool rv = EDA_DRAW_PANEL_GAL::SwitchBackend( aGalType );
114
115 // UpdateItems() is very slow after switching to an accelerated backend, so rebuild the view.
116 // The base call may have ended on the fallback canvas.
117 if( rv && IsAccelerated( m_backend ) )
118 {
119 GERBVIEW_FRAME* frame = dynamic_cast<GERBVIEW_FRAME*>( GetParentEDAFrame() );
120
121 if( frame )
122 {
123 m_view->Clear();
124
125 for( int layer = GERBER_DRAWLAYERS_COUNT - 1; layer >= 0; --layer )
126 {
127 GERBER_FILE_IMAGE* gerber = frame->GetImagesList()->GetGbrImage( layer );
128
129 if( gerber == nullptr )
130 continue;
131
132 for( GERBER_DRAW_ITEM* item : gerber->GetItems() )
133 m_view->Add( item );
134 }
135 }
136 }
137
139
140 GetGAL()->SetWorldUnitLength( 1.0/gerbIUScale.IU_PER_MM /* 10 nm */ / 25.4 /* 1 inch in mm */ );
141
142 return rv;
143}
144
145
147{
148 // Cairo keeps cached groups in screen coordinates, so caching makes no sense for it
150
151 for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; i++ )
152 m_view->SetLayerTarget( i, target );
153
154 m_view->SetLayerDisplayOnly( LAYER_DCODES );
155 m_view->SetLayerDisplayOnly( LAYER_NEGATIVE_OBJECTS );
156 m_view->SetLayerDisplayOnly( LAYER_GERBVIEW_GRID );
157 m_view->SetLayerDisplayOnly( LAYER_GERBVIEW_AXES );
158 m_view->SetLayerDisplayOnly( LAYER_GERBVIEW_BACKGROUND );
159 m_view->SetLayerDisplayOnly( LAYER_DRAWINGSHEET );
160
162 m_view->SetLayerDisplayOnly( LAYER_SELECT_OVERLAY );
163
165 m_view->SetLayerDisplayOnly( LAYER_GP_OVERLAY );
166}
167
168
170{
171 m_drawingSheet.reset( aDrawingSheet );
172 m_view->Add( m_drawingSheet.get() );
173}
174
175
177{
178 m_view->ClearTopLayers();
179
180 for( int i = 0; i < GERBER_DRAWLAYERS_COUNT; ++i )
181 {
182 m_view->SetLayerOrder( GERBER_DCODE_LAYER( GERBER_DRAW_LAYER( i ) ),
183 GERBER_DRAW_LAYER( 2 * i ) );
184 m_view->SetLayerOrder( GERBER_DRAW_LAYER( i ), GERBER_DRAW_LAYER( ( 2 * i ) + 1 ) );
185 }
186
187 m_view->SetTopLayer( aLayer );
188
189 // Move DCODE layer to the top
190 m_view->SetTopLayer( GERBER_DCODE_LAYER( aLayer ) );
191
192 m_view->SetTopLayer( LAYER_SELECT_OVERLAY );
193
194 m_view->SetTopLayer( LAYER_GP_OVERLAY );
195
196 m_view->UpdateAllLayersOrder();
197}
198
199
201{
202 // Even in Gervbview, LAYER_DRAWINGSHEET controls the visibility of the drawingsheet
203 if( m_drawingSheet && m_view->IsLayerVisible( LAYER_DRAWINGSHEET ) )
204 return m_drawingSheet->ViewBBox();
205
206 return BOX2I();
207}
constexpr EDA_IU_SCALE gerbIUScale
Definition base_units.h:127
BOX2< VECTOR2I > BOX2I
Definition box2.h:914
Color settings are a bit different than most of the settings objects in that there can be more than o...
The base class for create windows for drawing purpose.
std::unique_ptr< KIGFX::PAINTER > m_painter
Contains information about how to draw items using GAL.
KIGFX::GAL * m_gal
Interface for drawing objects on a 2D-surface.
EDA_DRAW_PANEL_GAL(wxWindow *aParentWindow, wxWindowID aWindowId, const wxPoint &aPosition, const wxSize &aSize, KIGFX::GAL_DISPLAY_OPTIONS &aOptions, GAL_TYPE aGalType=GAL_TYPE_OPENGL)
Create a drawing panel that is contained inside aParentWindow.
static bool IsAccelerated(GAL_TYPE aCanvasType)
True for a canvas drawn on the GPU, which keeps cached layers between frames.
KIGFX::VIEW * m_view
Stores view settings (scale, center, etc.) and items to be drawn.
KIGFX::WX_VIEW_CONTROLS * m_viewControls
Control for VIEW (moving, zooming, etc.)
KIGFX::GAL * GetGAL() const
Return a pointer to the GAL instance used in the panel.
virtual bool SwitchBackend(GAL_TYPE aGalType)
Switch method of rendering graphics.
GAL_TYPE m_backend
Currently used GAL.
EDA_DRAW_FRAME * GetParentEDAFrame() const
Returns parent EDA_DRAW_FRAME, if available or NULL otherwise.
GERBER_FILE_IMAGE * GetGbrImage(int aIdx)
Hold the image data and parameters for one gerber file and layer parameters.
GERBER_DRAW_ITEMS & GetItems()
BOX2I GetDefaultViewBBox() const override
Return the bounding box of the view that should be used if model is not valid.
std::unique_ptr< DS_PROXY_VIEW_ITEM > m_drawingSheet
Currently used drawing-sheet (borders and title block)
void SetDrawingSheet(DS_PROXY_VIEW_ITEM *aDrawingSheet)
Set or update the drawing-sheet (borders and title block) used by the draw panel.
void setDefaultLayerDeps()
Set rendering targets & dependencies for layers.
virtual void SetTopLayer(int aLayer) override
Move the selected layer to the top, so it is displayed above all others.
void OnShow() override
Called when the window is shown for the first time.
virtual void SetHighContrastLayer(int aLayer) override
Take care of display settings for the given layer to be displayed in high contrast mode.
GERBVIEW_DRAW_PANEL_GAL(wxWindow *aParentWindow, wxWindowID aWindowId, const wxPoint &aPosition, const wxSize &aSize, KIGFX::GAL_DISPLAY_OPTIONS &aOptions, GAL_TYPE aGalType=GAL_TYPE_MODERN)
bool SwitchBackend(GAL_TYPE aGalType) override
Switch method of rendering graphics.
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
GERBER_FILE_IMAGE_LIST * GetImagesList() const
Accessors to GERBER_FILE_IMAGE_LIST and GERBER_FILE_IMAGE data.
int GetActiveLayer() const
Return the active layer.
void SetWorldUnitLength(double aWorldUnitLength)
Set the unit length.
Store GerbView specific render settings.
void LoadColors(const COLOR_SETTINGS *aSettings) override
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:68
static constexpr int VIEW_MAX_LAYERS
Maximum number of layers that may be shown.
Definition view.h:899
An implementation of class VIEW_CONTROLS for wxWidgets library.
@ LAYER_GERBVIEW_BACKGROUND
Definition layer_ids.h:561
@ LAYER_DCODES
Definition layer_ids.h:557
@ LAYER_NEGATIVE_OBJECTS
Definition layer_ids.h:558
@ LAYER_GERBVIEW_AXES
Definition layer_ids.h:560
@ LAYER_GERBVIEW_GRID
Definition layer_ids.h:559
#define GERBER_DCODE_LAYER(x)
Definition layer_ids.h:570
@ LAYER_DRAWINGSHEET
Sheet frame and title block.
Definition layer_ids.h:274
@ LAYER_GP_OVERLAY
General purpose overlay.
Definition layer_ids.h:275
@ LAYER_SELECT_OVERLAY
Selected items overlay.
Definition layer_ids.h:276
#define GERBER_DRAWLAYERS_COUNT
Number of draw layers in Gerbview.
Definition layer_ids.h:547
#define GERBER_DRAW_LAYER(x)
Definition layer_ids.h:568
@ REPAINT
Item needs to be redrawn.
Definition view_item.h:54
@ TARGET_NONCACHED
Auxiliary rendering target (noncached)
Definition definitions.h:34
@ TARGET_CACHED
Main rendering target (cached)
Definition definitions.h:33
@ TARGET_OVERLAY
Items that may change while the view stays the same (noncached)
Definition definitions.h:35
see class PGM_BASE
#define DEFAULT_THEME
COLOR_SETTINGS * GetColorSettings(const wxString &aName)
WX_VIEW_CONTROLS class definition.
#define ZOOM_MIN_LIMIT_GERBVIEW
#define ZOOM_MAX_LIMIT_GERBVIEW