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 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
23#include <view/view.h>
24#include <trigo.h>
25
26using namespace KIGFX::PREVIEW;
27
29 const VECTOR2D& aClEnd, double aAspect )
30{
31 SHAPE_POLY_SET poly;
32 poly.NewOutline();
33
34 /*
35 * The point layout of the rectangle goes like this,
36 * but start/end don't have to be horz/vert
37 *
38 * 0 ---------------- 1 -----
39 * | | ^
40 * s--------cl------->e |cl|/aspect
41 * | | v
42 * 3----------------- 2 -----
43 */
44
45 // vector down the centre line of the rectangle
46 VECTOR2D cl = aClEnd - aClStart;
47
48 // don't allow degenerate polygons
49 if( cl.x == 0 && cl.y == 0 )
50 cl.x = 1.0;
51
52 // the "side" of the rectangle is the centre line rotated by 90 deg
53 // and scaled by the aspect ratio
54 VECTOR2D side = cl;
55 RotatePoint( side, -ANGLE_90 );
56 side = side * aAspect;
57
58 VECTOR2D pt = aClStart + ( side / 2.0 );
59 poly.Append( pt );
60
61 pt += cl;
62 poly.Append( pt );
63
64 pt -= side;
65 poly.Append( pt );
66
67 pt -= cl;
68 poly.Append( pt );
69
70 return poly;
71}
72
73
75 double aAspect ) :
76 m_geomMgr( aGeomMgr ),
77 m_aspect( aAspect )
78{
79}
80
81
86
87
89{
90 return getOutline().BBox();
91}
92
93
95{
96 KIGFX::GAL& gal = *aView->GetGAL();
97
98 gal.DrawLine( m_geomMgr.GetOrigin(), m_geomMgr.GetEnd() );
99 gal.DrawPolygon( getOutline() );
100}
BOX2< VECTOR2I > BOX2I
Definition box2.h:918
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:63
GAL * GetGAL() const
Return the GAL this view is using to draw graphical primitives.
Definition view.h:207
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:413
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:225
VECTOR2< double > VECTOR2D
Definition vector2d.h:682