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 #include <painter.h>
26 #include <view/view.h>
27 
28 using namespace KIGFX::PREVIEW;
29 
30 const double POLYGON_ITEM::POLY_LINE_WIDTH = 1;
31 
34 {
35 }
36 
37 
38 void POLYGON_ITEM::SetPoints( const SHAPE_LINE_CHAIN& aLockedInPts,
39  const SHAPE_LINE_CHAIN& aLeaderPts )
40 {
41  m_lockedChain = aLockedInPts;
42  m_leaderChain = aLeaderPts;
43 
46 
47  for( int i = 0; i < aLockedInPts.PointCount(); ++i )
48  m_polyfill.Append( aLockedInPts.CPoint( i ) );
49 
50  for( int i = 0; i < aLeaderPts.PointCount(); ++i )
51  m_polyfill.Append( aLeaderPts.CPoint( i ) );
52 }
53 
54 
56 {
57  auto& gal = *aView->GetGAL();
58  auto rs = aView->GetPainter()->GetSettings();
59 
60  if( m_lockedChain.PointCount() >= 2 )
61  {
62  gal.SetLineWidth( (float) aView->ToWorld( POLY_LINE_WIDTH ) );
63  gal.DrawPolyline( m_lockedChain );
64  }
65 
66  // draw the leader line in a different color
67  if( m_leaderChain.PointCount() >= 2 )
68  {
69  gal.SetStrokeColor( rs->GetLayerColor( LAYER_AUX_ITEMS ) );
70  gal.DrawPolyline( m_leaderChain );
71  }
72 
73  for( int j = 0; j < m_polyfill.OutlineCount(); ++j )
74  {
75  const SHAPE_LINE_CHAIN& outline = m_polyfill.COutline( j );
76 
77  if( outline.PointCount() >= 2 )
78  gal.DrawPolygon( outline );
79  }
80 }
81 
82 
84 {
85  return m_polyfill.BBox();
86 }
virtual const BOX2I ViewBBox() const override
Gets the bounding box of the polygon
static const double POLY_LINE_WIDTH
Definition: polygon_item.h:79
int OutlineCount() const
Returns the number of outlines in the set
VECTOR2D ToWorld(const VECTOR2D &aCoord, bool aAbsolute=true) const
Function ToWorld() Converts a screen space point/vector to a point/vector in world space coordinates.
Definition: view.cpp:456
SIMPLE_OVERLAY_ITEM is class that represents a visual area drawn on a canvas, used to temporarily dem...
GAL * GetGAL() const
Function GetGAL() Returns the GAL this view is using to draw graphical primitives.
Definition: view.h:182
SHAPE_POLY_SET m_polyfill
polygon fill
Definition: polygon_item.h:77
int PointCount() const
Function PointCount()
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:201
const VECTOR2I & CPoint(int aIndex) const
Function Point()
Auxiliary items (guides, rule, etc)
void drawPreviewShape(KIGFX::VIEW *aView) const override
Draw rectangle and centre line onto GAL
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 GetAdapter Returns pointer to current settings that are going to be used when drawing items.
SHAPE_LINE_CHAIN.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
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.
VIEW.
Definition: view.h:63
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)