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 );
62 GetSizer()->Add( m_canvas, 1, wxEXPAND );
63 }
64
65 int GetLayer() const { return m_layer; }
67
68private:
71};
72
73
75 wxNotebook( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize ),
76 m_pcbFrame( aPcbFrame )
77{
78 Bind( wxEVT_BOOKCTRL_PAGE_CHANGED, &ZONE_PREVIEW_NOTEBOOK::OnPageChanged, this );
79
81
82 wxImageList* imageList = new wxImageList( swatchSize.x, swatchSize.y );
83
84 for( int i = 0; i < PCB_LAYER_ID::PCB_LAYER_ID_COUNT; i++ )
85 {
86 const KIGFX::COLOR4D color = aPcbFrame->GetColorSettings()->GetColor( i );
89 swatchSize,
90 { 5, 6 },
92 { 1, 2, 2, 1 } );
93
94 imageList->Add( swatch, *wxWHITE );
95 }
96
97 AssignImageList( imageList );
98}
99
100
102{
103 int preferredLayer = UNDEFINED_LAYER;
104
105 if( GetSelection() >= 0 && GetSelection() < (int) GetPageCount() )
106 preferredLayer = static_cast<ZONE_PREVIEW_NOTEBOOK_PAGE*>( GetCurrentPage() )->GetLayer();
107
108 while( GetPageCount() )
109 RemovePage( 0 );
110
111 if( !aZone )
112 return;
113
114 ZONE_PREVIEW_NOTEBOOK_PAGE* preferredPage = nullptr;
115
116 for( PCB_LAYER_ID layer : aZone->GetLayerSet().UIOrder() )
117 {
118 BOARD* board = m_pcbFrame->GetBoard();
119 wxString layerName = board->GetLayerName( layer );
120 ZONE_PREVIEW_NOTEBOOK_PAGE* page = new ZONE_PREVIEW_NOTEBOOK_PAGE( this, board, aZone, layer,
121 m_pcbFrame->GetGalDisplayOptions() );
122
123 AddPage( page, layerName, false, layer );
124 page->Layout();
125 page->GetCanvas()->ZoomFitScreen();
126
127 if( layer == preferredLayer )
128 preferredPage = page;
129 }
130
131 if( !preferredPage )
132 preferredPage = static_cast<ZONE_PREVIEW_NOTEBOOK_PAGE*>( GetPage( 0 ) );
133
134 SetSelection( FindPage( preferredPage ) );
135
136 // Reinit canvas size parameters and display
137 PostSizeEvent();
138}
139
140
141void ZONE_PREVIEW_NOTEBOOK::OnPageChanged( wxNotebookEvent& aEvent )
142{
143 SetSelection( aEvent.GetSelection() );
144 aEvent.Skip();
145
146 // Reinit canvas size parameters and display
147 PostSizeEvent();
148}
149
150
152{
153 for( int ii = 0; ii < (int) GetPageCount(); ++ii )
154 static_cast<ZONE_PREVIEW_NOTEBOOK_PAGE*>( GetPage( ii ) )->GetCanvas()->ZoomFitScreen();
155}
int color
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:695
static const COLOR4D WHITE
Definition color4d.h:401
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition color4d.h:398
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:104
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)
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