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) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 1992-2016 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 <plot_common.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
45 BASIC_GAL basic_gal( basic_displayOptions );
46 
47 const VECTOR2D BASIC_GAL::transform( const VECTOR2D& aPoint ) const
48 {
49  VECTOR2D point = aPoint + m_transform.m_moveOffset - m_transform.m_rotCenter;
50  point = point.Rotate( m_transform.m_rotAngle ) + m_transform.m_rotCenter;
51  return point;
52 }
53 
54 void BASIC_GAL::DrawPolyline( const std::deque<VECTOR2D>& aPointList )
55 {
56  if( aPointList.empty() )
57  return;
58 
59  std::deque<VECTOR2D>::const_iterator it = aPointList.begin();
60  std::vector <wxPoint> polyline_corners;
61 
62  for( ; it != aPointList.end(); ++it )
63  {
64  VECTOR2D corner = transform(*it);
65  polyline_corners.push_back( wxPoint( corner.x, corner.y ) );
66  }
67 
68  if( m_DC )
69  {
70  if( isFillEnabled )
71  {
72  GRPoly( m_isClipped ? &m_clipBox : NULL, m_DC, polyline_corners.size(),
73  &polyline_corners[0], 0, GetLineWidth(), m_Color, m_Color );
74  }
75  else
76  {
77  for( unsigned ii = 1; ii < polyline_corners.size(); ++ii )
78  {
79  GRCSegm( m_isClipped ? &m_clipBox : NULL, m_DC, polyline_corners[ii-1],
80  polyline_corners[ii], GetLineWidth(), m_Color );
81  }
82  }
83  }
84  else if( m_plotter )
85  {
86  m_plotter->MoveTo( polyline_corners[0] );
87 
88  for( unsigned ii = 1; ii < polyline_corners.size(); ii++ )
89  {
90  m_plotter->LineTo( polyline_corners[ii] );
91  }
92 
93  m_plotter->PenFinish();
94  }
95  else if( m_callback )
96  {
97  for( unsigned ii = 1; ii < polyline_corners.size(); ii++ )
98  {
99  m_callback( polyline_corners[ii-1].x, polyline_corners[ii-1].y,
100  polyline_corners[ii].x, polyline_corners[ii].y );
101  }
102  }
103 }
104 
105 void BASIC_GAL::DrawLine( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint )
106 {
107  VECTOR2D startVector = transform( aStartPoint );
108  VECTOR2D endVector = transform( aEndPoint );
109 
110  if( m_DC )
111  {
112  if( isFillEnabled )
113  {
114  GRLine( m_isClipped ? &m_clipBox : NULL, m_DC, startVector.x, startVector.y,
115  endVector.x, endVector.y, GetLineWidth(), m_Color );
116  }
117  else
118  {
119  GRCSegm( m_isClipped ? &m_clipBox : NULL, m_DC, startVector.x, startVector.y,
120  endVector.x, endVector.y, GetLineWidth(), 0, m_Color );
121  }
122  }
123  else if( m_plotter )
124  {
125  m_plotter->MoveTo( wxPoint( startVector.x, startVector.y ) );
126  m_plotter->LineTo( wxPoint( endVector.x, endVector.y ) );
127  m_plotter->PenFinish();
128  }
129  else if( m_callback )
130  {
131  m_callback( startVector.x, startVector.y,
132  endVector.x, endVector.y );
133  }
134 }
void GRPoly(EDA_RECT *ClipBox, wxDC *DC, int n, wxPoint Points[], bool Fill, int width, COLOR4D Color, COLOR4D BgColor)
Definition: gr_basic.cpp:767
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:56
void GRLine(EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, int width, COLOR4D Color)
Definition: gr_basic.cpp:352
const VECTOR2D transform(const VECTOR2D &aPoint) const
Definition: basic_gal.cpp:47
VECTOR2< T > Rotate(double aAngle) const
Function Rotate rotates the vector by a given angle.
Definition: vector2d.h:373
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:481
virtual void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint) override
Start and end points are defined as 2D-Vectors.
Definition: basic_gal.cpp:105
Common plot library Plot settings, and plotting engines (Postscript, Gerber, HPGL and DXF) ...
KIGFX::GAL_DISPLAY_OPTIONS basic_displayOptions
Definition: basic_gal.cpp:42
BASIC_GAL basic_gal(basic_displayOptions)
virtual void DrawPolyline(const std::deque< VECTOR2D > &aPointList) override
Draw a polyline.
Definition: basic_gal.cpp:54