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>
39#include <pcb_edit_frame.h>
40
41
43{
44 WIDTH = 16,
45 HEIGHT = 16,
46
47};
48
49
50class ZONE_PREVIEW_NOTEBOOK_PAGE : public wxPanel
51{
52public:
53 ZONE_PREVIEW_NOTEBOOK_PAGE( wxWindow* aParent, BOARD* aBoard, ZONE* aZone, PCB_LAYER_ID aLayer,
55 wxPanel( aParent ),
56 m_layer( aLayer ),
57 m_canvas( nullptr )
58 {
59 SetSizer( new wxBoxSizer( wxHORIZONTAL ) );
60
61 m_canvas = new ZONE_PREVIEW_CANVAS( aBoard, aZone->Clone( aLayer ), aLayer, this, aOpts, aGalType );
62 GetSizer()->Add( m_canvas, 1, wxEXPAND );
63 Layout();
64 GetSizer()->Fit( this );
65 }
66
67 int GetLayer() const { return m_layer; }
69
70private:
73};
74
75
77 wxNotebook( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize ),
78 m_pcbFrame( aPcbFrame )
79{
80 Bind( wxEVT_BOOKCTRL_PAGE_CHANGED, &ZONE_PREVIEW_NOTEBOOK::OnPageChanged, this );
81
83
84 wxImageList* imageList = new wxImageList( swatchSize.x, swatchSize.y );
85
86 for( int i = 0; i < PCB_LAYER_ID::PCB_LAYER_ID_COUNT; i++ )
87 {
88 const KIGFX::COLOR4D color = aPcbFrame->GetColorSettings()->GetColor( i );
89 wxBitmap swatch = COLOR_SWATCH::MakeBitmap( color != COLOR4D::UNSPECIFIED ? color : COLOR4D::WHITE,
91 swatchSize,
92 { 5, 6 },
94 { 1, 2, 2, 1 } );
95
96 imageList->Add( swatch, *wxWHITE );
97 }
98
99 AssignImageList( imageList );
100
101 Layout();
102 GetSizer()->Fit( this );
103}
104
105
107{
108 int preferredLayer = UNDEFINED_LAYER;
109
110 if( GetSelection() >= 0 && GetSelection() < (int) GetPageCount() )
111 preferredLayer = static_cast<ZONE_PREVIEW_NOTEBOOK_PAGE*>( GetCurrentPage() )->GetLayer();
112
113 while( GetPageCount() )
114 RemovePage( 0 );
115
116 if( !aZone )
117 return;
118
119 ZONE_PREVIEW_NOTEBOOK_PAGE* preferredPage = nullptr;
120
121 for( PCB_LAYER_ID layer : aZone->GetLayerSet().UIOrder() )
122 {
123 BOARD* board = m_pcbFrame->GetBoard();
124 wxString layerName = board->GetLayerName( layer );
125 ZONE_PREVIEW_NOTEBOOK_PAGE* page = new ZONE_PREVIEW_NOTEBOOK_PAGE( this, board, aZone, layer,
126 m_pcbFrame->GetGalDisplayOptions(),
127 m_pcbFrame->GetCanvas()->GetBackend() );
128
129 AddPage( page, layerName, false, layer );
130 page->Layout();
131 page->GetCanvas()->ZoomFitScreen();
132
133 if( layer == preferredLayer )
134 preferredPage = page;
135 }
136
137 if( !preferredPage )
138 preferredPage = static_cast<ZONE_PREVIEW_NOTEBOOK_PAGE*>( GetPage( 0 ) );
139
140 SetSelection( FindPage( preferredPage ) );
141
142 // Reinit canvas size parameters and display
143 PostSizeEvent();
144}
145
146
147void ZONE_PREVIEW_NOTEBOOK::OnPageChanged( wxNotebookEvent& aEvent )
148{
149 SetSelection( aEvent.GetSelection() );
150 aEvent.Skip();
151
152 // Reinit canvas size parameters and display
153 PostSizeEvent();
154}
155
156
158{
159 for( int ii = 0; ii < (int) GetPageCount(); ++ii )
160 static_cast<ZONE_PREVIEW_NOTEBOOK_PAGE*>( GetPage( ii ) )->GetCanvas()->ZoomFitScreen();
161}
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:728
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
LSEQ UIOrder() const
Return the copper, technical and user layers in the order shown in layer widget.
Definition lset.cpp:726
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.
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:74
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition zone.cpp:216
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