KiCad PCB EDA Suite
Loading...
Searching...
No Matches
panel_zone_gal.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
25#include "panel_zone_gal.h"
26#include <pcb_track.h>
27#include <pcb_marker.h>
28#include <wx/event.h>
29#include <wx/gdicmn.h>
30#include <wx/string.h>
31
32#include <base_screen.h>
33#include <base_units.h>
34#include <bitmaps.h>
37#include <eda_draw_frame.h>
39#include <id.h>
40#include <kiface_base.h>
42#include <tool/actions.h>
43#include <tool/common_tools.h>
44#include <tool/tool_manager.h>
45#include <view/view.h>
46#include <view/view_controls.h>
47#include <board.h>
49#include "zone_painter.h"
51
52
54{
57
58};
59
60
61PANEL_ZONE_GAL::PANEL_ZONE_GAL( BOARD* aPcb, wxWindow* aParentWindow,
62 KIGFX::GAL_DISPLAY_OPTIONS& aOptions, wxWindowID aWindowId,
63 const wxPoint& aPosition, const wxSize& aSize, GAL_TYPE aGalType ) :
64 PCB_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, wxDefaultSize, aOptions,
65 aGalType ),
66 m_pcb( aPcb ), m_layer( UNDEFINED_LAYER ),
67 m_pcb_bounding_box( std::make_unique<BOARD_EDGES_BOUNDING_ITEM>( aPcb->GetBoardEdgesBoundingBox() ) ),
68 m_zone( nullptr )
69{
70 m_view->UseDrawPriority( true );
71 m_painter = std::make_unique<ZONE_PAINTER>( m_gal, FRAME_FOOTPRINT_PREVIEW );
72 m_view->SetPainter( m_painter.get() );
75 ShowScrollbars( wxSHOW_SB_NEVER, wxSHOW_SB_NEVER );
77 m_painter->GetSettings()->SetBackgroundColor(
79}
80
81
83{
84}
85
86BOX2I PANEL_ZONE_GAL::GetBoardBoundingBox( bool aBoardEdgesOnly ) const
87{
88 BOX2I area = aBoardEdgesOnly ? m_pcb->GetBoardEdgesBoundingBox() : m_pcb->GetBoundingBox();
89
90 if( area.GetWidth() == 0 && area.GetHeight() == 0 )
91 {
92 wxSize pageSize = GetPageSizeIU();
93 area.SetOrigin( 0, 0 );
94 area.SetEnd( pageSize.x, pageSize.y );
95 }
96
97 return area;
98}
99
100const BOX2I PANEL_ZONE_GAL::GetDocumentExtents( bool aIncludeAllVisible ) const
101{
102 if( aIncludeAllVisible || !m_pcb->IsLayerVisible( Edge_Cuts ) )
103 return GetBoardBoundingBox( false );
104 else
105 return GetBoardBoundingBox( true );
106}
107
109{
110 if( m_layer == aLayer )
111 return false;
112
113 m_layer = aLayer;
114 // Load layer & elements visibility settings
115
116 for( int i = 0; i < PCB_LAYER_ID_COUNT; ++i )
117 m_view->SetLayerVisible( i, m_layer == i || Edge_Cuts == i );
118
119 Refresh();
120 return true;
121}
122
123
125{
126 if( m_zone )
127 m_view->Remove( m_zone );
128
129 if( aZone )
130 {
131 m_view->Add( aZone, DRAW_ORDER_ZONE );
132
133 if( !OnLayerSelected( aZone->GetFirstLayer() ) )
134 Refresh();
135 }
136 else
137 {
138 Refresh();
139 }
140
141 m_zone = aZone;
142}
143
145{
147 return wxSize( sizeIU.x, sizeIU.y );
148}
149
151{
152 BOX2I bBox = GetDocumentExtents();
153 BOX2I defaultBox = GetDefaultViewBBox();
154
155 m_view->SetScale( 1.0 );
156 const wxSize clientSize = GetSize();
157 VECTOR2D screenSize = m_view->ToWorld(
158 VECTOR2D( static_cast<double>( clientSize.x ), static_cast<double>( clientSize.y ) ),
159 false );
160
161 if( bBox.GetWidth() == 0 || bBox.GetHeight() == 0 )
162 bBox = defaultBox;
163
164 VECTOR2D vsize = bBox.GetSize();
165 double scale = m_view->GetScale()
166 / std::max( fabs( vsize.x / screenSize.x ), fabs( vsize.y / screenSize.y ) );
167
168 if( !std::isfinite( scale ) )
169 {
170 m_view->SetCenter( VECTOR2D( 0, 0 ) );
171 Refresh();
172 return;
173 }
174
176 m_view->SetCenter( bBox.Centre() );
177 Refresh();
178}
BASE_SCREEN class implementation.
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:112
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:317
const BOX2I GetBoardEdgesBoundingBox() const
Return the board bounding box calculated using exclusively the board edges (graphics on Edge....
Definition: board.h:1002
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: board.h:988
const PAGE_INFO & GetPageSettings() const
Definition: board.h:742
bool IsLayerVisible(PCB_LAYER_ID aLayer) const
A proxy function that calls the correspondent function in m_BoardSettings tests whether a given layer...
Definition: board.cpp:913
constexpr void SetOrigin(const Vec &pos)
Definition: box2.h:237
constexpr size_type GetWidth() const
Definition: box2.h:214
constexpr Vec Centre() const
Definition: box2.h:97
constexpr size_type GetHeight() const
Definition: box2.h:215
constexpr const SizeVec & GetSize() const
Definition: box2.h:206
constexpr void SetEnd(coord_type x, coord_type y)
Definition: box2.h:297
std::unique_ptr< KIGFX::PAINTER > m_painter
Contains information about how to draw items using GAL.
KIGFX::GAL * m_gal
Interface for drawing objects on a 2D-surface.
KIGFX::VIEW * m_view
Stores view settings (scale, center, etc.) and items to be drawn.
void StartDrawing()
Begin drawing if it was stopped previously.
double GetScale() const
Definition: view.h:276
virtual void SetScale(double aScale, VECTOR2D aAnchor={ 0, 0 })
Set the scaling factor, zooming around a given anchor point.
Definition: view.cpp:570
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:298
virtual void Remove(VIEW_ITEM *aItem)
Remove a VIEW_ITEM from the view.
Definition: view.cpp:341
void SetPainter(PAINTER *aPainter)
Set the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:210
void SetLayerVisible(int aLayer, bool aVisible=true)
Control the visibility of a particular layer.
Definition: view.h:400
VECTOR2D ToWorld(const VECTOR2D &aCoord, bool aAbsolute=true) const
Converts a screen space point/vector to a point/vector in world space coordinates.
Definition: view.cpp:467
void UseDrawPriority(bool aFlag)
Definition: view.h:713
void SetCenter(const VECTOR2D &aCenter)
Set the center point of the VIEW (i.e.
Definition: view.cpp:596
const VECTOR2D GetSizeIU(double aIUScale) const
Gets the page size in internal units.
Definition: page_info.h:171
const BOX2I GetDocumentExtents(bool aIncludeAllVisible=true) const
void ActivateSelectedZone(ZONE *aZone) override
BOX2I GetBoardBoundingBox(bool aBoardEdgesOnly) const
PANEL_ZONE_GAL(BOARD *aPcb, wxWindow *aParentWindow, KIGFX::GAL_DISPLAY_OPTIONS &aOptions, wxWindowID aWindowId=0, const wxPoint &aPosition=wxDefaultPosition, const wxSize &aSize=wxDefaultSize, GAL_TYPE aGalType=GAL_TYPE_OPENGL)
const wxSize GetPageSizeIU() const
std::unique_ptr< BOARD_EDGES_BOUNDING_ITEM > m_pcb_bounding_box
bool OnLayerSelected(int aLayer)
Show the zone painting on layer.
~PANEL_ZONE_GAL() override
void UpdateColors()
Update the color settings in the painter and GAL.
BOX2I GetDefaultViewBBox() const override
Return the bounding box of the view that should be used if model is not valid.
static wxColour GetCanvasBackgroundColor()
Handle a list of polygons defining a copper zone.
Definition: zone.h:74
PCB_LAYER_ID GetFirstLayer() const
Definition: zone.cpp:481
@ FRAME_FOOTPRINT_PREVIEW
Definition: frame_type.h:48
@ Edge_Cuts
Definition: layer_ids.h:112
@ UNDEFINED_LAYER
Definition: layer_ids.h:61
@ PCB_LAYER_ID_COUNT
Definition: layer_ids.h:171
STL namespace.
DRAW_ORDER
@ DRAW_ORDER_BOARD_BOUNDING
@ DRAW_ORDER_ZONE
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
const int scale
const double IU_PER_MILS
Definition: base_units.h:77
VECTOR2< double > VECTOR2D
Definition: vector2d.h:694