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 (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 "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(
68 std::make_unique<BOARD_EDGES_BOUNDING_ITEM>( aPcb->GetBoardEdgesBoundingBox() ) ),
69 m_zone( nullptr )
70{
71 m_view->UseDrawPriority( true );
72 m_painter = std::make_unique<ZONE_PAINTER>( m_gal, FRAME_FOOTPRINT_PREVIEW );
73 m_view->SetPainter( m_painter.get() );
76 ShowScrollbars( wxSHOW_SB_NEVER, wxSHOW_SB_NEVER );
78 m_painter->GetSettings()->SetBackgroundColor(
80}
81
82
84{
85}
86
87BOX2I PANEL_ZONE_GAL::GetBoardBoundingBox( bool aBoardEdgesOnly ) const
88{
89 BOX2I area = aBoardEdgesOnly ? m_pcb->GetBoardEdgesBoundingBox() : m_pcb->GetBoundingBox();
90
91 if( area.GetWidth() == 0 && area.GetHeight() == 0 )
92 {
93 wxSize pageSize = GetPageSizeIU();
94 area.SetOrigin( 0, 0 );
95 area.SetEnd( pageSize.x, pageSize.y );
96 }
97
98 return area;
99}
100
101const BOX2I PANEL_ZONE_GAL::GetDocumentExtents( bool aIncludeAllVisible ) const
102{
103 if( aIncludeAllVisible || !m_pcb->IsLayerVisible( Edge_Cuts ) )
104 return GetBoardBoundingBox( false );
105 else
106 return GetBoardBoundingBox( true );
107}
108
110{
111 if( m_layer == aLayer )
112 return false;
113
114 m_layer = aLayer;
115 // Load layer & elements visibility settings
116
117 for( int i = 0; i < PCB_LAYER_ID_COUNT; ++i )
118 m_view->SetLayerVisible( i, m_layer == i || Edge_Cuts == i );
119
120 Refresh();
121 return true;
122}
123
124
126{
127 if( m_zone )
128 m_view->Remove( m_zone );
129
130 if( aZone )
131 {
132 m_view->Add( aZone, DRAW_ORDER_ZONE );
133
134 if( !OnLayerSelected( aZone->GetFirstLayer() ) )
135 Refresh();
136 }
137 else
138 {
139 Refresh();
140 }
141
142 m_zone = aZone;
143}
144
146{
148 return wxSize( sizeIU.x, sizeIU.y );
149}
150
152{
153 BOX2I bBox = GetDocumentExtents();
154 BOX2I defaultBox = GetDefaultViewBBox();
155
156 m_view->SetScale( 1.0 );
157 const wxSize clientSize = GetSize();
158 VECTOR2D screenSize = m_view->ToWorld(
159 VECTOR2D( static_cast<double>( clientSize.x ), static_cast<double>( clientSize.y ) ),
160 false );
161
162 if( bBox.GetWidth() == 0 || bBox.GetHeight() == 0 )
163 bBox = defaultBox;
164
165 VECTOR2D vsize = bBox.GetSize();
166 double scale = m_view->GetScale()
167 / std::max( fabs( vsize.x / screenSize.x ), fabs( vsize.y / screenSize.y ) );
168
169 if( !std::isfinite( scale ) )
170 {
171 m_view->SetCenter( VECTOR2D( 0, 0 ) );
172 Refresh();
173 return;
174 }
175
177 m_view->SetCenter( bBox.Centre() );
178 Refresh();
179}
BASE_SCREEN class implementation.
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:108
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:281
const BOX2I GetBoardEdgesBoundingBox() const
Return the board bounding box calculated using exclusively the board edges (graphics on Edge....
Definition: board.h:908
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: board.h:894
const PAGE_INFO & GetPageSettings() const
Definition: board.h:668
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:686
void SetOrigin(const Vec &pos)
Definition: box2.h:203
coord_type GetHeight() const
Definition: box2.h:189
coord_type GetWidth() const
Definition: box2.h:188
Vec Centre() const
Definition: box2.h:71
const Vec & GetSize() const
Definition: box2.h:180
void SetEnd(coord_type x, coord_type y)
Definition: box2.h:256
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:271
virtual void SetScale(double aScale, VECTOR2D aAnchor={ 0, 0 })
Set the scaling factor, zooming around a given anchor point.
Definition: view.cpp:552
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:315
virtual void Remove(VIEW_ITEM *aItem)
Remove a VIEW_ITEM from the view.
Definition: view.cpp:354
void SetPainter(PAINTER *aPainter)
Set the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:205
void SetLayerVisible(int aLayer, bool aVisible=true)
Control the visibility of a particular layer.
Definition: view.h:395
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:449
void UseDrawPriority(bool aFlag)
Definition: view.h:697
void SetCenter(const VECTOR2D &aCenter)
Set the center point of the VIEW (i.e.
Definition: view.cpp:578
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:72
PCB_LAYER_ID GetFirstLayer() const
Definition: zone.cpp:246
@ FRAME_FOOTPRINT_PREVIEW
Definition: frame_type.h:48
@ Edge_Cuts
Definition: layer_ids.h:113
@ UNDEFINED_LAYER
Definition: layer_ids.h:61
@ PCB_LAYER_ID_COUNT
Definition: layer_ids.h:137
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:587