KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pane_zone_viewer.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 (C) 2023 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
25#include "pane_zone_viewer.h"
26#include <wx/artprov.h>
27#include <wx/dataview.h>
28#include <wx/colour.h>
29#include <wx/debug.h>
30#include <wx/event.h>
31#include <wx/imaglist.h>
32#include <wx/panel.h>
33#include <wx/xrc/xmlres.h>
34#include <wx/intl.h>
35#include <wx/dataview.h>
36#include <wx/gdicmn.h>
37#include <wx/font.h>
38#include <wx/colour.h>
39#include <wx/settings.h>
40#include <wx/string.h>
41#include <wx/sizer.h>
42#include <wx/statbox.h>
43#include <wx/button.h>
44#include <wx/bitmap.h>
45#include <wx/image.h>
46#include <wx/icon.h>
47#include <wx/dialog.h>
48#include <wx/graphics.h>
49#include <wx/dcbuffer.h>
50#include <board.h>
51#include <gal/color4d.h>
52#include "panel_zone_gal.h"
53#include <wx/dataview.h>
57#include <pcb_edit_frame.h>
59class PANEL_ZONE_GAL_CONTAINER : public wxPanel
60{
61 wxBoxSizer* m_sizer;
64
65public:
66 PANEL_ZONE_GAL_CONTAINER( wxWindow* aParent, int aLayer ) :
67 wxPanel( aParent ), m_sizer( new wxBoxSizer( wxHORIZONTAL ) ), m_layer( aLayer )
68 {
69 SetSizer( m_sizer );
70 }
71 int GetLayer() const { return m_layer; }
72 void TakeGAL( PANEL_ZONE_GAL*& now )
73 {
74 if( !m_gal )
75 return;
76
77 m_sizer->Detach( m_gal );
78 now = m_gal;
79 m_gal = nullptr;
80 }
81
88 {
89 wxASSERT( !m_gal );
90 m_gal = aGal;
91 m_sizer->Add( m_gal, 1, wxEXPAND );
92 Layout();
93 m_sizer->Fit( this );
94 }
95
102 {
103 if( aGal->GetParent() == this )
104 return;
105
106 static_cast<PANEL_ZONE_GAL_CONTAINER*>( aGal->GetParent() )->TakeGAL( m_gal );
107 m_gal->Reparent( this );
108 m_sizer->Add( m_gal, 1, wxEXPAND );
109 Layout();
110 m_sizer->Fit( this );
111 }
112};
113
114PANE_ZONE_VIEWER::PANE_ZONE_VIEWER( wxWindow* aParent, PCB_BASE_FRAME* aPcbFrame ) :
115 wxNotebook( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize ), m_pcbFrame( aPcbFrame )
116{
117 Bind( wxEVT_BOOKCTRL_PAGE_CHANGED, &PANE_ZONE_VIEWER::OnNotebook, this );
118
119 wxImageList* imageList = new wxImageList( ZONE_MANAGER_PREFERENCE::LAYER_ICON_SIZE::WIDTH,
121
122 for( int i = 0; i < PCB_LAYER_ID::PCB_LAYER_ID_COUNT; i++ )
123 {
124 const KIGFX::COLOR4D color = aPcbFrame->GetColorSettings()->GetColor( i );
125 imageList->Add( COLOR_SWATCH::MakeBitmap(
126 color != COLOR4D::UNSPECIFIED ? color : COLOR4D::WHITE, COLOR4D::UNSPECIFIED,
129 { 5, 6 }, COLOR4D::WHITE ) );
130 }
131
132 AssignImageList( imageList );
133}
134
135
137
139{
140 while( GetPageCount() )
141 RemovePage( 0 );
142
143 if( !aZone )
144 return;
145
146 const PCB_LAYER_ID firstLayer = aZone->GetFirstLayer();
147
148 for( PCB_LAYER_ID layer : aZone->GetLayerSet().Seq() )
149 {
150 wxString layerName =
151 m_pcbFrame->GetBoard()->GetLayerName( static_cast<PCB_LAYER_ID>( layer ) );
152
153 if( auto existingContainer = m_zoneContainers.find( layer );
154 existingContainer != m_zoneContainers.end() )
155 {
156 AddPage( existingContainer->second, layerName, false, layer );
157 }
158 else
159 {
160 PANEL_ZONE_GAL_CONTAINER* container = new PANEL_ZONE_GAL_CONTAINER( this, layer );
161 m_zoneContainers.try_emplace( layer, container );
162 AddPage( container, layerName, false, layer );
163 }
164 }
165
166 SetSelection( FindPage( m_zoneContainers[firstLayer] ) );
167
168 if( !m_zoneGAL )
169 {
173 m_zoneContainers[firstLayer]->InitZoneGAL( m_zoneGAL );
174 }
175 else
176 {
177 m_zoneContainers[firstLayer]->ResetZoneGAL( m_zoneGAL );
178 }
179
181}
182
183void PANE_ZONE_VIEWER::OnNotebook( wxNotebookEvent& aEvent )
184{
185 const int idx = aEvent.GetSelection();
186 PANEL_ZONE_GAL_CONTAINER* container = static_cast<PANEL_ZONE_GAL_CONTAINER*>( GetPage( idx ) );
187 container->ResetZoneGAL( m_zoneGAL );
188 m_zoneGAL->OnLayerSelected( container->GetLayer() );
189 SetSelection( idx );
190 aEvent.Skip();
191}
int color
Definition: DXF_plotter.cpp:58
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition: board.cpp:579
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)
GAL_DISPLAY_OPTIONS_IMPL & GetGalDisplayOptions()
Return a reference to the gal rendering options used by GAL for rendering.
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
LSEQ Seq(const LSEQ &aSequence) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:410
void InitZoneGAL(PANEL_ZONE_GAL *aGal)
Initialize the gal , shall only be called once while the gal is first constructed.
PANEL_ZONE_GAL_CONTAINER(wxWindow *aParent, int aLayer)
void ResetZoneGAL(PANEL_ZONE_GAL *aGal)
Reuse the only one zone gal between different container.
void TakeGAL(PANEL_ZONE_GAL *&now)
void ActivateSelectedZone(ZONE *aZone) override
bool OnLayerSelected(int aLayer)
Show the zone painting on layer.
void ActivateSelectedZone(ZONE *new_zone) override
std::unordered_map< int, PANEL_ZONE_GAL_CONTAINER * > m_zoneContainers
PANE_ZONE_VIEWER(wxWindow *aParent, PCB_BASE_FRAME *aPcbFrame)
PANEL_ZONE_GAL * m_zoneGAL
~PANE_ZONE_VIEWER() override
void OnNotebook(wxNotebookEvent &aEvent)
PCB_BASE_FRAME * m_pcbFrame
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
BOARD * GetBoard() const
virtual COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const override
Helper to retrieve the current color settings.
Handle a list of polygons defining a copper zone.
Definition: zone.h:73
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 GetFirstLayer() const
Definition: zone.cpp:453
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60