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 (C) 2018-2022 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( true );
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
61 COLOR_SETTINGS* color_settings;
62
63 if( auto frame = dynamic_cast<GERBVIEW_FRAME*>( GetParentEDAFrame() ) )
64 color_settings = frame->GetColorSettings();
65 else
66 color_settings = Pgm().GetSettingsManager().GetColorSettings();
67
68 wxASSERT( color_settings );
69 auto renderSettings = static_cast<KIGFX::GERBVIEW_RENDER_SETTINGS*>( m_painter->GetSettings() );
70 renderSettings->LoadColors( color_settings );
71}
72
73
75{
76}
77
78
80{
81 // Set display settings for high contrast mode
83
84 SetTopLayer( aLayer );
85
86 rSettings->ClearHighContrastLayers();
87 rSettings->SetLayerIsHighContrast( aLayer );
88 rSettings->SetLayerIsHighContrast( GERBER_DCODE_LAYER( aLayer ) );
89
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
108}
109
110
112{
113 bool rv = EDA_DRAW_PANEL_GAL::SwitchBackend( aGalType );
114
115 // The next onPaint event will call m_view->UpdateItems() that is very time consuming
116 // after switching to opengl. Clearing m_view and rebuild it is much faster
117 if( aGalType == GAL_TYPE_OPENGL )
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 ) // Graphic layer not yet used
130 continue;
131
132 for( GERBER_DRAW_ITEM* item : gerber->GetItems() )
133 {
134 m_view->Add (item );
135 }
136 }
137 }
138 }
139
141
142 GetGAL()->SetWorldUnitLength( 1.0/gerbIUScale.IU_PER_MM /* 10 nm */ / 25.4 /* 1 inch in mm */ );
143
144 return rv;
145}
146
147
149{
150 // caching makes no sense for Cairo and other software renderers
152
153 for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; i++ )
154 m_view->SetLayerTarget( i, target );
155
162
165
168}
169
170
172{
173 m_drawingSheet.reset( aDrawingSheet );
174 m_view->Add( m_drawingSheet.get() );
175}
176
177
179{
181
182 for( int i = 0; i < GERBER_DRAWLAYERS_COUNT; ++i )
183 {
185 GERBER_DRAW_LAYER( 2 * i ) );
186 m_view->SetLayerOrder( GERBER_DRAW_LAYER( i ), GERBER_DRAW_LAYER( ( 2 * i ) + 1 ) );
187 }
188
189 m_view->SetTopLayer( aLayer );
190
191 // Move DCODE layer to the top
193
195
197
199}
200
201
203{
204 // Even in Gervbview, LAYER_DRAWINGSHEET controls the visibility of the drawingsheet
206 return m_drawingSheet->ViewBBox();
207
208 return BOX2I();
209}
constexpr EDA_IU_SCALE gerbIUScale
Definition: base_units.h:107
BOX2< VECTOR2I > BOX2I
Definition: box2.h:887
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:68
void UpdateAllLayersOrder()
Do everything that is needed to apply the rendering order of layers.
Definition: view.cpp:897
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:459
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:315
void SetPainter(PAINTER *aPainter)
Set the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:205
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:493
void SetLayerTarget(int aLayer, RENDER_TARGET aTarget)
Change the rendering target for a particular layer.
Definition: view.h:471
void Clear()
Remove all items from the view.
Definition: view.cpp:1124
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
static constexpr int VIEW_MAX_LAYERS
Rendering order modifier for layers that are marked as top layers.
Definition: view.h:729
void RecacheAllItems()
Rebuild GAL display lists.
Definition: view.cpp:1410
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
bool IsLayerVisible(int aLayer) const
Return information about visibility of a particular layer.
Definition: view.h:412
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:215
void SetScaleLimits(double aMaximum, double aMinimum)
Set minimum and maximum values for scale.
Definition: view.h:311
void SetLayerOrder(int aLayer, int aRenderingOrder)
Set rendering order of a particular layer.
Definition: view.cpp:638
An implementation of class VIEW_CONTROLS for wxWidgets library.
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:142
COLOR_SETTINGS * GetColorSettings(const wxString &aName="user")
Retrieves a color settings object that applications can read colors from.
@ LAYER_GERBVIEW_BACKGROUND
Definition: layer_ids.h:432
@ LAYER_DCODES
Definition: layer_ids.h:428
@ LAYER_NEGATIVE_OBJECTS
Definition: layer_ids.h:429
@ LAYER_GERBVIEW_AXES
Definition: layer_ids.h:431
@ LAYER_GERBVIEW_GRID
Definition: layer_ids.h:430
#define GERBER_DCODE_LAYER(x)
Definition: layer_ids.h:441
@ LAYER_DRAWINGSHEET
drawingsheet frame and titleblock
Definition: layer_ids.h:221
@ LAYER_GP_OVERLAY
general purpose overlay
Definition: layer_ids.h:222
@ LAYER_SELECT_OVERLAY
currently selected items overlay
Definition: layer_ids.h:223
#define GERBER_DRAWLAYERS_COUNT
Definition: layer_ids.h:418
#define GERBER_DRAW_LAYER(x)
Definition: layer_ids.h:439
@ TARGET_NONCACHED
Auxiliary rendering target (noncached)
Definition: definitions.h:49
@ TARGET_CACHED
Main rendering target (cached)
Definition: definitions.h:48
@ TARGET_OVERLAY
Items that may change while the view stays the same (noncached)
Definition: definitions.h:50
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1059
see class PGM_BASE
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