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 along
17 * with this program. If not, see <http://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();
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
72{
73}
74
75
77{
78 // Set display settings for high contrast mode
80
81 SetTopLayer( aLayer );
82
83 rSettings->ClearHighContrastLayers();
84 rSettings->SetLayerIsHighContrast( aLayer );
85 rSettings->SetLayerIsHighContrast( GERBER_DCODE_LAYER( aLayer ) );
86
88}
89
90
92 std::vector<MSG_PANEL_ITEM>& aList )
93{
94}
95
96
98{
99 GERBVIEW_FRAME* frame = dynamic_cast<GERBVIEW_FRAME*>( GetParentEDAFrame() );
100
101 if( frame )
102 SetTopLayer( frame->GetActiveLayer() );
103
105}
106
107
109{
110 bool rv = EDA_DRAW_PANEL_GAL::SwitchBackend( aGalType );
111
112 // The next onPaint event will call m_view->UpdateItems() that is very time consuming
113 // after switching to opengl. Clearing m_view and rebuild it is much faster
114 if( aGalType == GAL_TYPE_OPENGL )
115 {
116 GERBVIEW_FRAME* frame = dynamic_cast<GERBVIEW_FRAME*>( GetParentEDAFrame() );
117
118 if( frame )
119 {
120 m_view->Clear();
121
122 for( int layer = GERBER_DRAWLAYERS_COUNT-1; layer>= 0; --layer )
123 {
124 GERBER_FILE_IMAGE* gerber = frame->GetImagesList()->GetGbrImage( layer );
125
126 if( gerber == nullptr ) // Graphic layer not yet used
127 continue;
128
129 for( GERBER_DRAW_ITEM* item : gerber->GetItems() )
130 {
131 m_view->Add (item );
132 }
133 }
134 }
135 }
136
138
139 GetGAL()->SetWorldUnitLength( 1.0/gerbIUScale.IU_PER_MM /* 10 nm */ / 25.4 /* 1 inch in mm */ );
140
141 return rv;
142}
143
144
146{
147 // caching makes no sense for Cairo and other software renderers
149
150 for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; i++ )
151 m_view->SetLayerTarget( i, target );
152
159
162
165}
166
167
169{
170 m_drawingSheet.reset( aDrawingSheet );
171 m_view->Add( m_drawingSheet.get() );
172}
173
174
176{
178
179 for( int i = 0; i < GERBER_DRAWLAYERS_COUNT; ++i )
180 {
182 GERBER_DRAW_LAYER( 2 * i ) );
183 m_view->SetLayerOrder( GERBER_DRAW_LAYER( i ), GERBER_DRAW_LAYER( ( 2 * i ) + 1 ) );
184 }
185
186 m_view->SetTopLayer( aLayer );
187
188 // Move DCODE layer to the top
190
192
194
196}
197
198
200{
201 // Even in Gervbview, LAYER_DRAWINGSHEET controls the visibility of the drawingsheet
203 return m_drawingSheet->ViewBBox();
204
205 return BOX2I();
206}
constexpr EDA_IU_SCALE gerbIUScale
Definition: base_units.h:111
BOX2< VECTOR2I > BOX2I
Definition: box2.h:922
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.
@ GAL_TYPE_OPENGL
OpenGL implementation.
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
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.
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)
virtual void SetTopLayer(int aLayer) override
Return the bounding box of the view that should be used if model is not valid.
virtual ~GERBVIEW_DRAW_PANEL_GAL()
Take care of display settings for the given layer to be displayed in high contrast mode.
void OnShow() override
Called when the window is shown for the first time.
virtual void SetHighContrastLayer(int aLayer) override
bool SwitchBackend(GAL_TYPE aGalType) override
Move the selected layer to the top, so it is displayed above all others.
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Called when the window is shown for the first time.
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
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
void ClearHighContrastLayers()
Clear the list of active layers.
void SetLayerIsHighContrast(int aLayerId, bool aEnabled=true)
Set the specified layer as high-contrast.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:66
void UpdateAllLayersOrder()
Do everything that is needed to apply the rendering order of layers.
Definition: view.cpp:906
void SetLayerDisplayOnly(int aLayer, bool aDisplayOnly=true)
Set a layer display-only (ie: to be rendered but not returned by hit test queries).
Definition: view.h:481
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:298
void SetPainter(PAINTER *aPainter)
Set the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:210
void UpdateAllLayersColor()
Apply the new coloring scheme to all layers.
Definition: view.cpp:775
void SetGAL(GAL *aGal)
Assign a rendering device for the VIEW.
Definition: view.cpp:511
void SetLayerTarget(int aLayer, RENDER_TARGET aTarget)
Change the rendering target for a particular layer.
Definition: view.h:497
void Clear()
Remove all items from the view.
Definition: view.cpp:1143
void ClearTopLayers()
Remove all layers from the on-the-top set (they are no longer displayed over the rest of layers).
Definition: view.cpp:891
static constexpr int VIEW_MAX_LAYERS
Maximum number of layers that may be shown.
Definition: view.h:745
void RecacheAllItems()
Rebuild GAL display lists.
Definition: view.cpp:1451
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:839
bool IsLayerVisible(int aLayer) const
Return information about visibility of a particular layer.
Definition: view.h:422
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:220
void SetScaleLimits(double aMaximum, double aMinimum)
Set minimum and maximum values for scale.
Definition: view.h:316
void SetLayerOrder(int aLayer, int aRenderingOrder)
Set rendering order of a particular layer.
Definition: view.cpp:656
An implementation of class VIEW_CONTROLS for wxWidgets library.
@ LAYER_GERBVIEW_BACKGROUND
Definition: layer_ids.h:521
@ LAYER_DCODES
Definition: layer_ids.h:517
@ LAYER_NEGATIVE_OBJECTS
Definition: layer_ids.h:518
@ LAYER_GERBVIEW_AXES
Definition: layer_ids.h:520
@ LAYER_GERBVIEW_GRID
Definition: layer_ids.h:519
#define GERBER_DCODE_LAYER(x)
Definition: layer_ids.h:530
@ LAYER_DRAWINGSHEET
Sheet frame and title block.
Definition: layer_ids.h:277
@ LAYER_GP_OVERLAY
General purpose overlay.
Definition: layer_ids.h:278
@ LAYER_SELECT_OVERLAY
Selected items overlay.
Definition: layer_ids.h:279
#define GERBER_DRAWLAYERS_COUNT
Number of draw layers in Gerbview.
Definition: layer_ids.h:507
#define GERBER_DRAW_LAYER(x)
Definition: layer_ids.h:528
@ TARGET_NONCACHED
Auxiliary rendering target (noncached)
Definition: definitions.h:38
@ TARGET_CACHED
Main rendering target (cached)
Definition: definitions.h:37
@ TARGET_OVERLAY
Items that may change while the view stays the same (noncached)
Definition: definitions.h:39
see class PGM_BASE
#define DEFAULT_THEME
COLOR_SETTINGS * GetColorSettings(const wxString &aName)
const double IU_PER_MM
Definition: base_units.h:76
WX_VIEW_CONTROLS class definition.
#define ZOOM_MIN_LIMIT_GERBVIEW
Definition: zoom_defines.h:62
#define ZOOM_MAX_LIMIT_GERBVIEW
Definition: zoom_defines.h:61