KiCad PCB EDA Suite
Loading...
Searching...
No Matches
centreline_rect_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 change_log.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
27#include <view/view.h>
28#include <trigo.h>
29
30using namespace KIGFX::PREVIEW;
31
33 const VECTOR2D& aClEnd, double aAspect )
34{
35 SHAPE_POLY_SET poly;
36 poly.NewOutline();
37
38 /*
39 * The point layout of the rectangle goes like this,
40 * but start/end don't have to be horz/vert
41 *
42 * 0 ---------------- 1 -----
43 * | | ^
44 * s--------cl------->e |cl|/aspect
45 * | | v
46 * 3----------------- 2 -----
47 */
48
49 // vector down the centre line of the rectangle
50 VECTOR2D cl = aClEnd - aClStart;
51
52 // don't allow degenerate polygons
53 if( cl.x == 0 && cl.y == 0 )
54 cl.x = 1.0;
55
56 // the "side" of the rectangle is the centre line rotated by 90 deg
57 // and scaled by the aspect ratio
58 VECTOR2D side = cl;
59 RotatePoint( side, -ANGLE_90 );
60 side = side * aAspect;
61
62 VECTOR2D pt = aClStart + ( side / 2.0 );
63 poly.Append( pt );
64
65 pt += cl;
66 poly.Append( pt );
67
68 pt -= side;
69 poly.Append( pt );
70
71 pt -= cl;
72 poly.Append( pt );
73
74 return poly;
75}
76
77
79 double aAspect ) :
80 m_geomMgr( aGeomMgr ),
81 m_aspect( aAspect )
82{
83}
84
85
87{
89}
90
91
93{
94 return getOutline().BBox();
95}
96
97
99{
100 KIGFX::GAL& gal = *aView->GetGAL();
101
103 gal.DrawPolygon( getOutline() );
104}
static SHAPE_POLY_SET getRectangleAlongCentreLine(const VECTOR2D &aClStart, const VECTOR2D &aClEnd, double aAspect)
Abstract interface for drawing on a 2D-surface.
virtual void DrawPolygon(const std::deque< VECTOR2D > &aPointList)
Draw a polygon.
virtual void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a line.
virtual const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
void drawPreviewShape(KIGFX::VIEW *aView) const override
Draw the preview onto the given GAL.
SHAPE_POLY_SET getOutline() const
< Get the rectangular outline
const TWO_POINT_GEOMETRY_MANAGER & m_geomMgr
The aspect ratio of the rectangle to draw.
CENTRELINE_RECT_ITEM(const TWO_POINT_GEOMETRY_MANAGER &aGeomMgr, double aAspect)
Gets the bounding box of the rectangle.
Represent a very simple geometry manager for items that have a start and end point.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:68
GAL * GetGAL() const
Return the #GAL this view is using to draw graphical primitives.
Definition: view.h:197
Represent a set of closed polygons.
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)
int NewOutline()
Creates a new empty polygon in the set and returns its index.
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
static constexpr EDA_ANGLE ANGLE_90
Definition: eda_angle.h:437
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
Definition: trigo.cpp:228