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, see <https://www.gnu.org/licenses/>.
19 */
20
22#include <wx/debug.h>
23#include <wx/imaglist.h>
24#include <wx/panel.h>
25#include <wx/gdicmn.h>
26#include <wx/string.h>
27#include <wx/sizer.h>
28#include <wx/dcbuffer.h>
29#include <board.h>
30#include <zone.h>
31#include <gal/color4d.h>
32#include <view/view.h>
36#include <pcb_edit_frame.h>
37
38
40{
41 WIDTH = 16,
42 HEIGHT = 16,
43
44};
45
46
47class ZONE_PREVIEW_NOTEBOOK_PAGE : public wxPanel
48{
49public:
50 ZONE_PREVIEW_NOTEBOOK_PAGE( wxWindow* aParent, BOARD* aBoard, ZONE* aZone, PCB_LAYER_ID aLayer,
52 wxPanel( aParent ),
53 m_layer( aLayer ),
54 m_canvas( nullptr )
55 {
56 SetSizer( new wxBoxSizer( wxHORIZONTAL ) );
57
58 m_canvas = new ZONE_PREVIEW_CANVAS( aBoard, aZone->Clone( aLayer ), aLayer, this, aOpts, aGalType );
59 GetSizer()->Add( m_canvas, 1, wxEXPAND );
60 Layout();
61 GetSizer()->Fit( this );
62 }
63
64 int GetLayer() const { return m_layer; }
66
67private:
70};
71
72
74 wxNotebook( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize ),
75 m_pcbFrame( aPcbFrame ),
76 m_hasSavedZoom( false ),
77 m_savedScale( 1.0 ),
78 m_savedCenter( 0, 0 )
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 {
113 static_cast<ZONE_PREVIEW_NOTEBOOK_PAGE*>( GetCurrentPage() );
114 preferredLayer = curPage->GetLayer();
115
116 KIGFX::VIEW* view = curPage->GetCanvas()->GetView();
117
118 if( view )
119 {
120 m_savedScale = view->GetScale();
121 m_savedCenter = view->GetCenter();
122 m_hasSavedZoom = true;
123 }
124 }
125
126 while( GetPageCount() )
127 RemovePage( 0 );
128
129 if( !aZone )
130 return;
131
132 ZONE_PREVIEW_NOTEBOOK_PAGE* preferredPage = nullptr;
133
134 for( PCB_LAYER_ID layer : aZone->GetLayerSet().UIOrder() )
135 {
136 BOARD* board = m_pcbFrame->GetBoard();
137 wxString layerName = board->GetLayerName( layer );
139 new ZONE_PREVIEW_NOTEBOOK_PAGE( this, board, aZone, layer,
140 m_pcbFrame->GetGalDisplayOptions(),
141 m_pcbFrame->GetCanvas()->GetBackend() );
142
143 AddPage( page, layerName, false, layer );
144 page->Layout();
145
146 if( m_hasSavedZoom )
148 else
149 page->GetCanvas()->ZoomFitScreen();
150
151 if( layer == preferredLayer )
152 preferredPage = page;
153 }
154
155 if( !preferredPage )
156 preferredPage = static_cast<ZONE_PREVIEW_NOTEBOOK_PAGE*>( GetPage( 0 ) );
157
158 SetSelection( FindPage( preferredPage ) );
159
160 // Reinit canvas size parameters and display
161 PostSizeEvent();
162}
163
164
165void ZONE_PREVIEW_NOTEBOOK::OnPageChanged( wxNotebookEvent& aEvent )
166{
167 SetSelection( aEvent.GetSelection() );
168 aEvent.Skip();
169
170 // Reinit canvas size parameters and display
171 PostSizeEvent();
172}
173
174
176{
177 for( int ii = 0; ii < (int) GetPageCount(); ++ii )
178 static_cast<ZONE_PREVIEW_NOTEBOOK_PAGE*>( GetPage( ii ) )->GetCanvas()->ZoomFitScreen();
179}
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:372
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition board.cpp:793
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:101
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:63
double GetScale() const
Definition view.h:281
const VECTOR2D & GetCenter() const
Return the center point of this VIEW (in world space coordinates).
Definition view.h:351
LSEQ UIOrder() const
Return the copper, technical and user layers in the order shown in layer widget.
Definition lset.cpp:739
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:70
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition zone.cpp:215
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition zone.h:133
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ UNDEFINED_LAYER
Definition layer_ids.h:57
@ PCB_LAYER_ID_COUNT
Definition layer_ids.h:167