KiCad PCB EDA Suite
Loading...
Searching...
No Matches
zone_preview_notebook.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) 2023 Ethan Chien <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
26#include <wx/debug.h>
27#include <wx/imaglist.h>
28#include <wx/panel.h>
29#include <wx/gdicmn.h>
30#include <wx/string.h>
31#include <wx/sizer.h>
32#include <wx/dcbuffer.h>
33#include <board.h>
34#include <zone.h>
35#include <gal/color4d.h>
36#include <view/view.h>
40#include <pcb_edit_frame.h>
41
42
44{
45 WIDTH = 16,
46 HEIGHT = 16,
47
48};
49
50
51class ZONE_PREVIEW_NOTEBOOK_PAGE : public wxPanel
52{
53public:
54 ZONE_PREVIEW_NOTEBOOK_PAGE( wxWindow* aParent, BOARD* aBoard, ZONE* aZone, PCB_LAYER_ID aLayer,
56 wxPanel( aParent ),
57 m_layer( aLayer ),
58 m_canvas( nullptr )
59 {
60 SetSizer( new wxBoxSizer( wxHORIZONTAL ) );
61
62 m_canvas = new ZONE_PREVIEW_CANVAS( aBoard, aZone->Clone( aLayer ), aLayer, this, aOpts, aGalType );
63 GetSizer()->Add( m_canvas, 1, wxEXPAND );
64 Layout();
65 GetSizer()->Fit( this );
66 }
67
68 int GetLayer() const { return m_layer; }
70
71private:
74};
75
76
78 wxNotebook( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize ),
79 m_pcbFrame( aPcbFrame ),
80 m_hasSavedZoom( false ),
81 m_savedScale( 1.0 ),
82 m_savedCenter( 0, 0 )
83{
84 Bind( wxEVT_BOOKCTRL_PAGE_CHANGED, &ZONE_PREVIEW_NOTEBOOK::OnPageChanged, this );
85
87
88 wxImageList* imageList = new wxImageList( swatchSize.x, swatchSize.y );
89
90 for( int i = 0; i < PCB_LAYER_ID::PCB_LAYER_ID_COUNT; i++ )
91 {
92 const KIGFX::COLOR4D color = aPcbFrame->GetColorSettings()->GetColor( i );
93 wxBitmap swatch = COLOR_SWATCH::MakeBitmap( color != COLOR4D::UNSPECIFIED ? color : COLOR4D::WHITE,
95 swatchSize,
96 { 5, 6 },
98 { 1, 2, 2, 1 } );
99
100 imageList->Add( swatch, *wxWHITE );
101 }
102
103 AssignImageList( imageList );
104
105 Layout();
106 GetSizer()->Fit( this );
107}
108
109
111{
112 int preferredLayer = UNDEFINED_LAYER;
113
114 if( GetSelection() >= 0 && GetSelection() < (int) GetPageCount() )
115 {
117 static_cast<ZONE_PREVIEW_NOTEBOOK_PAGE*>( GetCurrentPage() );
118 preferredLayer = curPage->GetLayer();
119
120 KIGFX::VIEW* view = curPage->GetCanvas()->GetView();
121
122 if( view )
123 {
124 m_savedScale = view->GetScale();
125 m_savedCenter = view->GetCenter();
126 m_hasSavedZoom = true;
127 }
128 }
129
130 while( GetPageCount() )
131 RemovePage( 0 );
132
133 if( !aZone )
134 return;
135
136 ZONE_PREVIEW_NOTEBOOK_PAGE* preferredPage = nullptr;
137
138 for( PCB_LAYER_ID layer : aZone->GetLayerSet().UIOrder() )
139 {
140 BOARD* board = m_pcbFrame->GetBoard();
141 wxString layerName = board->GetLayerName( layer );
143 new ZONE_PREVIEW_NOTEBOOK_PAGE( this, board, aZone, layer,
144 m_pcbFrame->GetGalDisplayOptions(),
145 m_pcbFrame->GetCanvas()->GetBackend() );
146
147 AddPage( page, layerName, false, layer );
148 page->Layout();
149
150 if( m_hasSavedZoom )
152 else
153 page->GetCanvas()->ZoomFitScreen();
154
155 if( layer == preferredLayer )
156 preferredPage = page;
157 }
158
159 if( !preferredPage )
160 preferredPage = static_cast<ZONE_PREVIEW_NOTEBOOK_PAGE*>( GetPage( 0 ) );
161
162 SetSelection( FindPage( preferredPage ) );
163
164 // Reinit canvas size parameters and display
165 PostSizeEvent();
166}
167
168
169void ZONE_PREVIEW_NOTEBOOK::OnPageChanged( wxNotebookEvent& aEvent )
170{
171 SetSelection( aEvent.GetSelection() );
172 aEvent.Skip();
173
174 // Reinit canvas size parameters and display
175 PostSizeEvent();
176}
177
178
180{
181 for( int ii = 0; ii < (int) GetPageCount(); ++ii )
182 static_cast<ZONE_PREVIEW_NOTEBOOK_PAGE*>( GetPage( ii ) )->GetCanvas()->ZoomFitScreen();
183}
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:322
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition board.cpp:729
static const COLOR4D WHITE
Definition color4d.h:405
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition color4d.h:402
COLOR4D GetColor(int aLayer) const
static wxBitmap MakeBitmap(const KIGFX::COLOR4D &aColor, const KIGFX::COLOR4D &aBackground, const wxSize &aSize, const wxSize &aCheckerboardSize, const KIGFX::COLOR4D &aCheckerboardBackground, const std::vector< int > &aMargins={ 0, 0, 0, 0 })
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:105
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:67
double GetScale() const
Definition view.h:277
const VECTOR2D & GetCenter() const
Return the center point of this VIEW (in world space coordinates).
Definition view.h:347
LSEQ UIOrder() const
Return the copper, technical and user layers in the order shown in layer widget.
Definition lset.cpp:743
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
virtual COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const override
Helper to retrieve the current color settings.
virtual KIGFX::PCB_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
void LockZoom(double aScale, const VECTOR2D &aCenter)
ZONE_PREVIEW_NOTEBOOK_PAGE(wxWindow *aParent, BOARD *aBoard, ZONE *aZone, PCB_LAYER_ID aLayer, GAL_DISPLAY_OPTIONS_IMPL &aOpts, EDA_DRAW_PANEL_GAL::GAL_TYPE aGalType)
ZONE_PREVIEW_CANVAS * GetCanvas() const
ZONE_PREVIEW_NOTEBOOK(wxWindow *aParent, PCB_BASE_FRAME *aPcbFrame)
void OnPageChanged(wxNotebookEvent &aEvent)
void OnZoneSelectionChanged(ZONE *new_zone)
Handle a list of polygons defining a copper zone.
Definition zone.h:73
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition zone.cpp:218
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition zone.h:136
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:60
@ UNDEFINED_LAYER
Definition layer_ids.h:61
@ PCB_LAYER_ID_COUNT
Definition layer_ids.h:171