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 
41 void POLYGON_ITEM::SetPoints( const SHAPE_LINE_CHAIN& aLockedInPts,
42  const SHAPE_LINE_CHAIN& aLeaderPts )
43 {
44  m_lockedChain = aLockedInPts;
45  m_leaderChain = aLeaderPts;
46 
49 
50  for( int i = 0; i < aLockedInPts.PointCount(); ++i )
51  m_polyfill.Append( aLockedInPts.CPoint( i ) );
52 
53  for( int i = 0; i < aLeaderPts.PointCount(); ++i )
54  m_polyfill.Append( aLeaderPts.CPoint( i ) );
55 }
56 
57 
59 {
60  auto& gal = *aView->GetGAL();
61  auto rs = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( aView->GetPainter()->GetSettings() );
62 
63  gal.DrawPolyline( m_lockedChain );
64  gal.DrawPolygon( m_polyfill );
65 
66  // draw the leader line in a different color
67  gal.SetStrokeColor( rs->GetLayerColor( LAYER_AUX_ITEMS ) );
68  gal.DrawPolyline( m_leaderChain );
69 }
70 
71 
73 {
74  return m_polyfill.BBox();
75 }
virtual const BOX2I ViewBBox() const override
Gets the bounding box of the polygon
int PointCount() const
Function PointCount()
SIMPLE_OVERLAY_ITEM is class that represents a visual area drawn on a canvas, used to temporarily dem...
SHAPE_POLY_SET m_polyfill
polygon fill
Definition: polygon_item.h:77
Class PCB_RENDER_SETTINGS Stores PCB specific render settings.
Definition: pcb_painter.h:62
Auxillary items (guides, rule, 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...
Class SHAPE_LINE_CHAIN.
size_t i
Definition: json11.cpp:597
void RemoveAllContours()
Removes all outlines & holes (clears) the polygon set.
void SetPoints(const SHAPE_LINE_CHAIN &aLockedInPts, const SHAPE_LINE_CHAIN &aLeaderPts)
Set the polygon points.
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 VECTOR2I & CPoint(int aIndex) const
Function CPoint()
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) ...