KiCad PCB EDA Suite
polygon_item.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) 2017 Kicad Developers, see AUTHORS.txt for contributors.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
25 
27 
29 #include <view/view.h>
30 #include <pcb_painter.h>
31 
32 using namespace KIGFX::PREVIEW;
33 
34 
37 {
38 }
39 
40 void POLYGON_ITEM::SetPoints( const std::vector<VECTOR2I>& aLockedPts,
41  const std::vector<VECTOR2I>& aLeaderPts )
42 {
45 
48 
49  for( auto& pt: aLockedPts )
50  {
51  m_lockedChain.Append( pt, false );
52  m_polyfill.Append( pt );
53  }
54 
55  for( auto& pt: aLeaderPts )
56  {
57  m_leaderChain.Append( pt, false );
58  m_polyfill.Append( pt );
59  }
60 }
61 
62 
64 {
65  auto& gal = *aView->GetGAL();
66  auto rs = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( aView->GetPainter()->GetSettings() );
67 
68  gal.DrawPolyline( m_lockedChain );
69  gal.DrawPolygon( m_polyfill );
70 
71  // draw the leader line in a different color
72  gal.SetStrokeColor( rs->GetLayerColor( LAYER_AUX_ITEMS ) );
73  gal.DrawPolyline( m_leaderChain );
74 }
75 
76 
78 {
79  return m_polyfill.BBox();
80 }
virtual const BOX2I ViewBBox() const override
Gets the bounding box of the polygon
SIMPLE_OVERLAY_ITEM is class that represents a visual area drawn on a canvas, used to temporarily dem...
void SetPoints(const std::vector< VECTOR2I > &aLockedInPts, const std::vector< VECTOR2I > &aLeaderPts)
Set the polygon points.
SHAPE_POLY_SET m_polyfill
polygon fill
Definition: polygon_item.h:77
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
Class PCB_RENDER_SETTINGS Stores PCB specific render settings.
Definition: pcb_painter.h:62
Auxillary items (guides, rulre, etc)
GAL * GetGAL() const
Function GetGAL() Returns the GAL this view is using to draw graphical primitives.
Definition: view.h:177
void drawPreviewShape(KIGFX::VIEW *aView) const override
Draw rectangle and centre line onto GAL
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:196
int NewOutline()
Creates a new empty polygon in the set and returns its index
SHAPE_LINE_CHAIN m_leaderChain
Definition: polygon_item.h:74
virtual RENDER_SETTINGS * GetSettings()=0
Function GetSettings Returns pointer to current settings that are going to be used when drawing items...
void RemoveAllContours()
Removes all outlines & holes (clears) the polygon set.
void Clear()
Function Clear() Removes all points from the line chain.
Class VIEW.
Definition: view.h:58
SHAPE_LINE_CHAIN m_lockedChain
complete polyline of locked in and leader points
Definition: polygon_item.h:74
const BOX2I BBox(int aClearance=0) const override
Function BBox()
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline) ...