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-2021 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 <plotters/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 void BASIC_GAL::doDrawPolyline( const std::vector<wxPoint>& aLocalPointList )
57 {
58  if( m_DC )
59  {
60  if( m_isFillEnabled )
61  {
62  GRPoly( m_isClipped ? &m_clipBox : nullptr, m_DC, aLocalPointList.size(),
63  &aLocalPointList[0], 0, GetLineWidth(), m_Color, m_Color );
64  }
65  else
66  {
67  for( unsigned ii = 1; ii < aLocalPointList.size(); ++ii )
68  {
69  GRCSegm( m_isClipped ? &m_clipBox : nullptr, m_DC, aLocalPointList[ ii - 1],
70  aLocalPointList[ii], GetLineWidth(), m_Color );
71  }
72  }
73  }
74  else if( m_plotter )
75  {
76  m_plotter->MoveTo( aLocalPointList[0] );
77 
78  for( unsigned ii = 1; ii < aLocalPointList.size(); ii++ )
79  {
80  m_plotter->LineTo( aLocalPointList[ii] );
81  }
82 
83  m_plotter->PenFinish();
84  }
85  else if( m_callback )
86  {
87  for( unsigned ii = 1; ii < aLocalPointList.size(); ii++ )
88  {
89  m_callback( aLocalPointList[ ii - 1].x, aLocalPointList[ ii - 1].y,
90  aLocalPointList[ii].x, aLocalPointList[ii].y, m_callbackData );
91  }
92  }
93 }
94 
95 
96 void BASIC_GAL::DrawPolyline( const std::deque<VECTOR2D>& aPointList )
97 {
98  if( aPointList.size() < 2 )
99  return;
100 
101  std::vector<wxPoint> polyline_corners;
102 
103  for( const VECTOR2D& pt : aPointList )
104  polyline_corners.emplace_back( (wxPoint) transform( pt ) );
105 
106  doDrawPolyline( polyline_corners );
107 }
108 
109 
110 void BASIC_GAL::DrawPolyline( const VECTOR2D aPointList[], int aListSize )
111 {
112  if( aListSize < 2 )
113  return;
114 
115  std::vector<wxPoint> polyline_corners;
116 
117  for( int ii = 0; ii < aListSize; ++ii )
118  polyline_corners.emplace_back( (wxPoint) transform( aPointList[ ii ] ) );
119 
120  doDrawPolyline( polyline_corners );
121 }
122 
123 
124 void BASIC_GAL::DrawLine( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint )
125 {
126  VECTOR2D startVector = transform( aStartPoint );
127  VECTOR2D endVector = transform( aEndPoint );
128 
129  if( m_DC )
130  {
131  if( m_isFillEnabled )
132  {
133  GRLine( m_isClipped ? &m_clipBox : nullptr, m_DC, startVector.x, startVector.y,
134  endVector.x, endVector.y, GetLineWidth(), m_Color );
135  }
136  else
137  {
138  GRCSegm( m_isClipped ? &m_clipBox : nullptr, m_DC, startVector.x, startVector.y,
139  endVector.x, endVector.y, GetLineWidth(), 0, m_Color );
140  }
141  }
142  else if( m_plotter )
143  {
144  m_plotter->MoveTo( wxPoint( startVector.x, startVector.y ) );
145  m_plotter->LineTo( wxPoint( endVector.x, endVector.y ) );
146  m_plotter->PenFinish();
147  }
148  else if( m_callback )
149  {
150  m_callback( startVector.x, startVector.y, endVector.x, endVector.y, m_callbackData );
151  }
152 }
Plot settings, and plotting engines (PostScript, Gerber, HPGL and DXF)
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:236
virtual void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint) override
Start and end points are defined as 2D-Vectors.
Definition: basic_gal.cpp:124
void GRLine(EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, int width, const COLOR4D &Color, wxPenStyle aStyle)
Definition: gr_basic.cpp:197
void doDrawPolyline(const std::vector< wxPoint > &aLocalPointList)
Definition: basic_gal.cpp:56
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
void GRPoly(EDA_RECT *ClipBox, wxDC *DC, int n, const wxPoint *Points, bool Fill, int width, const COLOR4D &Color, const COLOR4D &BgColor)
Draw a new polyline and fill it if Fill, in drawing space.
Definition: gr_basic.cpp:453
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:96
void GRCSegm(EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, int width, int aPenSize, const COLOR4D &Color)
Definition: gr_basic.cpp:227