KiCad PCB EDA Suite
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 
25 
27 
29 #include <view/view.h>
30 
31 using namespace KIGFX::PREVIEW;
32 
34  const VECTOR2D& aClStart, const VECTOR2D& aClEnd, double aAspect )
35 {
36  SHAPE_POLY_SET poly;
37  poly.NewOutline();
38 
39  /*
40  * The point layout of the rectangle goes like this,
41  * but start/end don't have to be horz/vert
42  *
43  * 0 ---------------- 1 -----
44  * | | ^
45  * s--------cl------->e |cl|/aspect
46  * | | v
47  * 3----------------- 2 -----
48  */
49 
50  // vector down the centre line of the rectangle
51  const VECTOR2D cl = aClEnd - aClStart;
52 
53  // the "side" of the rectangle is the centre line rotated by 90 deg
54  // and scaled by the aspect ratio
55  const VECTOR2D side = cl.Rotate( M_PI / 2.0 ) * aAspect;
56 
57  VECTOR2D pt = aClStart + ( side / 2.0 );
58  poly.Append( pt );
59 
60  pt += cl;
61  poly.Append( pt );
62 
63  pt -= side;
64  poly.Append( pt );
65 
66  pt -= cl;
67  poly.Append( pt );
68 
69  return poly;
70 }
71 
72 
74  const TWO_POINT_GEOMETRY_MANAGER& aGeomMgr,
75  double aAspect ):
76  m_geomMgr( aGeomMgr ),
77  m_aspect( aAspect )
78 {
79 }
80 
81 
83 {
85  m_geomMgr.GetEnd(),
86  m_aspect );
87 }
88 
89 
91 {
92  return getOutline().BBox();
93 }
94 
95 
97 {
98  auto& gal = *aView->GetGAL();
99 
101  gal.DrawPolygon( getOutline() );
102 }
Class TWO_POINT_GEOMETRY_MANAGER.
VECTOR2< T > Rotate(double aAngle) const
Function Rotate rotates the vector by a given angle.
Definition: vector2d.h:372
void drawPreviewShape(KIGFX::VIEW *aView) const override
Draw rectangle and centre line onto GAL
virtual void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a line.
GAL * GetGAL() const
Function GetGAL() Returns the GAL this view is using to draw graphical primitives.
Definition: view.h:177
SHAPE_POLY_SET getOutline() const
Get the rectangular outline
Class SHAPE_POLY_SET.
CENTRELINE_RECT_ITEM(const TWO_POINT_GEOMETRY_MANAGER &aGeomMgr, double aAspect)
int NewOutline()
Creates a new empty polygon in the set and returns its index
virtual const BOX2I ViewBBox() const override
Gets the bounding box of the rectangle
double m_aspect
The aspect ratio of the rectangle to draw
static SHAPE_POLY_SET getRectangleAlongCentreLine(const VECTOR2D &aClStart, const VECTOR2D &aClEnd, double aAspect)
Class VIEW.
Definition: view.h:58
const BOX2I BBox(int aClearance=0) const override
Function BBox()
const TWO_POINT_GEOMETRY_MANAGER & m_geomMgr
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) ...