KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 The 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, see <https://www.gnu.org/licenses/>.
18 */
19
22#include <gal/painter.h>
23#include <view/view.h>
24
25using namespace KIGFX::PREVIEW;
26
27const double POLYGON_ITEM::POLY_LINE_WIDTH = 1;
28
35
36
38{
39 m_lineColor = lineColor;
40}
41
42
44{
45 m_leaderColor = leaderColor;
46}
47
48
49void POLYGON_ITEM::SetPoints( const SHAPE_LINE_CHAIN& aLockedInPts,
50 const SHAPE_LINE_CHAIN& aLeaderPts, const SHAPE_LINE_CHAIN& aLoopPts )
51{
52 m_lockedChain = aLockedInPts;
53 m_leaderChain = aLeaderPts;
54 m_loopChain = aLoopPts;
55
56 m_polyfill.RemoveAllContours();
57 m_polyfill.NewOutline();
58
59 for( int i = 0; i < aLockedInPts.PointCount(); ++i )
60 m_polyfill.Append( aLockedInPts.CPoint( i ) );
61
62 for( int i = 0; i < aLeaderPts.PointCount(); ++i )
63 m_polyfill.Append( aLeaderPts.CPoint( i ) );
64
65 for( int i = 0; i < aLoopPts.PointCount(); ++i )
66 m_polyfill.Append( aLoopPts.CPoint( i ) );
67}
68
69
71{
72 KIGFX::GAL& gal = *aView->GetGAL();
73 RENDER_SETTINGS* renderSettings = aView->GetPainter()->GetSettings();
74
75 gal.SetIsStroke( true );
76
77 if( m_lockedChain.PointCount() >= 2 )
78 {
81
82 gal.SetLineWidth( (float) aView->ToWorld( POLY_LINE_WIDTH ) );
84 }
85
86 // draw the leader line in a different color
87 if( m_leaderChain.PointCount() >= 2 )
88 {
91 else
92 gal.SetStrokeColor( renderSettings->GetLayerColor( LAYER_AUX_ITEMS ) );
93
95 }
96
97 gal.SetIsStroke( false );
98
99 for( int j = 0; j < m_polyfill.OutlineCount(); ++j )
100 {
101 const SHAPE_LINE_CHAIN& outline = m_polyfill.COutline( j );
102
103 if( outline.PointCount() >= 2 )
104 gal.DrawPolygon( outline );
105 }
106}
107
108
110{
111 return m_polyfill.BBox();
112}
BOX2< VECTOR2I > BOX2I
Definition box2.h:918
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition color4d.h:398
Abstract interface for drawing on a 2D-surface.
virtual void DrawPolygon(const std::deque< VECTOR2D > &aPointList)
Draw a polygon.
virtual void SetLineWidth(float aLineWidth)
Set the line width.
virtual void DrawPolyline(const std::deque< VECTOR2D > &aPointList)
Draw a polyline.
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
KIGFX::COLOR4D m_lineColor
the preview leader line color
virtual const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
void SetLeaderColor(KIGFX::COLOR4D leaderColor)
Gets the bounding box of the polygon.
void drawPreviewShape(KIGFX::VIEW *aView) const override
< Draw rectangle and center line onto GAL
void SetLineColor(KIGFX::COLOR4D lineColor)
Sets the color of the outline leader line.
SHAPE_LINE_CHAIN m_lockedChain
void SetPoints(const SHAPE_LINE_CHAIN &aLockedInPts, const SHAPE_LINE_CHAIN &aLeaderPts, const SHAPE_LINE_CHAIN &aLoopPts)
Set the polygon points.
static const double POLY_LINE_WIDTH
SHAPE_LINE_CHAIN m_leaderChain
POLYGON_ITEM()
Sets the color of the preview outline.
SHAPE_POLY_SET m_polyfill
the preview outline color
SHAPE_LINE_CHAIN m_loopChain
polygon fill
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:63
GAL * GetGAL() const
Return the GAL this view is using to draw graphical primitives.
Definition view.h:207
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:534
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition view.h:225
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
int PointCount() const
Return the number of points (vertices) in this line chain.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
@ LAYER_AUX_ITEMS
Auxiliary items (guides, rule, etc).
Definition layer_ids.h:279