KiCad PCB EDA Suite
basic_gal.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) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
34 #include <gr_basic.h>
35 #include <plotter.h>
36 #include <trigo.h>
37 
38 #include <basic_gal.h>
39 
40 using namespace KIGFX;
41 
43 
44 // the basic GAL doesn't get an external display option object
46 
47 
48 const VECTOR2D BASIC_GAL::transform( const VECTOR2D& aPoint ) const
49 {
50  VECTOR2D point = aPoint + m_transform.m_moveOffset - m_transform.m_rotCenter;
51  point = point.Rotate( m_transform.m_rotAngle ) + m_transform.m_rotCenter;
52  return point;
53 }
54 
55 
56 // Draws a polyline given a list of points already transformed into the local coordinate
57 // system.
58 void BASIC_GAL::doDrawPolyline( const std::vector<wxPoint>& aLocalPointList )
59 {
60  if( m_DC )
61  {
62  if( m_isFillEnabled )
63  {
64  GRPoly( m_isClipped ? &m_clipBox : NULL, m_DC, aLocalPointList.size(),
65  &aLocalPointList[0], 0, GetLineWidth(), m_Color, m_Color );
66  }
67  else
68  {
69  for( unsigned ii = 1; ii < aLocalPointList.size(); ++ii )
70  {
71  GRCSegm( m_isClipped ? &m_clipBox : NULL, m_DC, aLocalPointList[ ii - 1],
72  aLocalPointList[ii], GetLineWidth(), m_Color );
73  }
74  }
75  }
76  else if( m_plotter )
77  {
78  m_plotter->MoveTo( aLocalPointList[0] );
79 
80  for( unsigned ii = 1; ii < aLocalPointList.size(); ii++ )
81  {
82  m_plotter->LineTo( aLocalPointList[ii] );
83  }
84 
85  m_plotter->PenFinish();
86  }
87  else if( m_callback )
88  {
89  for( unsigned ii = 1; ii < aLocalPointList.size(); ii++ )
90  {
91  m_callback( aLocalPointList[ ii - 1].x, aLocalPointList[ ii - 1].y,
92  aLocalPointList[ii].x, aLocalPointList[ii].y, m_callbackData );
93  }
94  }
95 }
96 
97 
98 void BASIC_GAL::DrawPolyline( const std::deque<VECTOR2D>& aPointList )
99 {
100  if( aPointList.size() < 2 )
101  return;
102 
103  std::vector<wxPoint> polyline_corners;
104 
105  for( const VECTOR2D& pt : aPointList )
106  polyline_corners.emplace_back( (wxPoint) transform( pt ) );
107 
108  doDrawPolyline( polyline_corners );
109 }
110 
111 
112 void BASIC_GAL::DrawPolyline( const VECTOR2D aPointList[], int aListSize )
113 {
114  if( aListSize < 2 )
115  return;
116 
117  std::vector<wxPoint> polyline_corners;
118 
119  for( int ii = 0; ii < aListSize; ++ii )
120  polyline_corners.emplace_back( (wxPoint) transform( aPointList[ ii ] ) );
121 
122  doDrawPolyline( polyline_corners );
123 }
124 
125 
126 void BASIC_GAL::DrawLine( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint )
127 {
128  VECTOR2D startVector = transform( aStartPoint );
129  VECTOR2D endVector = transform( aEndPoint );
130 
131  if( m_DC )
132  {
133  if( m_isFillEnabled )
134  {
135  GRLine( m_isClipped ? &m_clipBox : NULL, m_DC, startVector.x, startVector.y,
136  endVector.x, endVector.y, GetLineWidth(), m_Color );
137  }
138  else
139  {
140  GRCSegm( m_isClipped ? &m_clipBox : NULL, m_DC, startVector.x, startVector.y,
141  endVector.x, endVector.y, GetLineWidth(), 0, m_Color );
142  }
143  }
144  else if( m_plotter )
145  {
146  m_plotter->MoveTo( wxPoint( startVector.x, startVector.y ) );
147  m_plotter->LineTo( wxPoint( endVector.x, endVector.y ) );
148  m_plotter->PenFinish();
149  }
150  else if( m_callback )
151  {
152  m_callback( startVector.x, startVector.y,
153  endVector.x, endVector.y, m_callbackData );
154  }
155 }
Plot settings, and plotting engines (PostScript, Gerber, HPGL and DXF)
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:194
void GRPoly(EDA_RECT *ClipBox, wxDC *DC, int n, const wxPoint *Points, bool Fill, int width, COLOR4D Color, COLOR4D BgColor)
Definition: gr_basic.cpp:540
void GRCSegm(EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, int width, int aPenSize, COLOR4D Color)
Definition: gr_basic.cpp:310
#define NULL
virtual void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint) override
Start and end points are defined as 2D-Vectors.
Definition: basic_gal.cpp:126
void GRLine(EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, int width, COLOR4D Color, wxPenStyle aStyle)
Definition: gr_basic.cpp:228
void doDrawPolyline(const std::vector< wxPoint > &aLocalPointList)
Definition: basic_gal.cpp:58
KIGFX::GAL_DISPLAY_OPTIONS basic_displayOptions
Definition: basic_gal.cpp:42
VECTOR2< T > Rotate(double aAngle) const
Rotate the vector by a given angle.
Definition: vector2d.h:371
BASIC_GAL basic_gal(basic_displayOptions)
const VECTOR2D transform(const VECTOR2D &aPoint) const
Definition: basic_gal.cpp:48
virtual void DrawPolyline(const std::deque< VECTOR2D > &aPointList) override
Draw a polyline.
Definition: basic_gal.cpp:98