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  KIGFX::GAL& gal = *aView->GetGAL();
58  RENDER_SETTINGS* renderSettings = aView->GetPainter()->GetSettings();
59 
60  if( m_lockedChain.PointCount() >= 2 )
61  {
62  gal.SetLineWidth( (float) aView->ToWorld( POLY_LINE_WIDTH ) );
64  }
65 
66  // draw the leader line in a different color
67  if( m_leaderChain.PointCount() >= 2 )
68  {
69  gal.SetStrokeColor( renderSettings->GetLayerColor( LAYER_AUX_ITEMS ) );
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 void DrawPolyline(const std::deque< VECTOR2D > &aPointList)
Draw a polyline.
virtual const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
static const double POLY_LINE_WIDTH
Definition: polygon_item.h:73
int OutlineCount() const
Return the number of vertices in a given outline/hole.
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
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:451
SIMPLE_OVERLAY_ITEM is class that represents a visual area drawn on a canvas, used to temporarily dem...
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
GAL * GetGAL() const
Return the #GAL this view is using to draw graphical primitives.
Definition: view.h:189
int PointCount() const
Function PointCount()
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:207
virtual void SetLineWidth(float aLineWidth)
Set the line width.
const VECTOR2I & CPoint(int aIndex) const
Function Point()
Auxiliary items (guides, rule, etc)
void drawPreviewShape(KIGFX::VIEW *aView) const override
< Draw rectangle and center line onto GAL
int NewOutline()
Creates a new hole in a given outline.
SHAPE_LINE_CHAIN m_leaderChain
polygon fill
Definition: polygon_item.h:68
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
virtual void DrawPolygon(const std::deque< VECTOR2D > &aPointList)
Draw a polygon.
SHAPE_LINE_CHAIN.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
void SetPoints(const SHAPE_LINE_CHAIN &aLockedInPts, const SHAPE_LINE_CHAIN &aLeaderPts)
Set the polygon points.
POLYGON_ITEM()
Gets the bounding box of the polygon.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:67
SHAPE_LINE_CHAIN m_lockedChain
Definition: polygon_item.h:68
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
Abstract interface for drawing on a 2D-surface.
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Add a new vertex to the contour indexed by aOutline and aHole (defaults to the outline of the last po...