KiCad PCB EDA Suite
basic_gal.h
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 
25 #ifndef BASIC_GAL_H
26 #define BASIC_GAL_H
27 
28 #include <plot_common.h>
29 #include <class_eda_rect.h>
30 
31 #include <gal/stroke_font.h>
33 #include <newstroke_font.h>
34 
35 /*
36  * class BASIC_GAL is a minimal GAL implementation to draw, plot and convert
37  * stroke texts to a set of segments for DRC tests, and to calculate text sizes.
38  *
39  * Currently it allows to use GAL and STROKE_FONT methods in legacy draw mode
40  * (using wxDC functions) in plot functions only for texts.
41  * It is used also to calculate the text bounding boxes
42  *
43  * The main purpose is to avoid duplicate code to do the same thing in GAL canvas
44  * legacy canvas, plotter canvas and DRC.
45  *
46  * It will be certainly removed when a full GAL canvas using wxDC is implemented
47  * (or at least restricted to plotter and DRC "canvas")
48  */
49 
50 struct TRANSFORM_PRM // A helper class to transform coordinates in BASIC_GAL canvas
51 {
54  double m_rotAngle;
55 };
56 
57 class BASIC_GAL: public KIGFX::GAL
58 {
59 public:
60  wxDC* m_DC;
62 
63 private:
65  std::stack <TRANSFORM_PRM> m_transformHistory;
66 
67 public:
68  BASIC_GAL( KIGFX::GAL_DISPLAY_OPTIONS& aDisplayOptions ) :
69  GAL( aDisplayOptions )
70  {
71  m_DC = NULL;
72  m_Color = RED;
73  m_plotter = NULL;
74  m_callback = NULL;
75  m_isClipped = false;
76  }
77 
78  void SetPlotter( PLOTTER* aPlotter )
79  {
80  m_plotter = aPlotter;
81  }
82 
83  void SetCallback( void (* aCallback)( int x0, int y0, int xf, int yf ) )
84  {
85  m_callback = aCallback;
86  }
87 
90  void SetClipBox( EDA_RECT* aClipBox )
91  {
92  m_isClipped = aClipBox != NULL;
93 
94  if( aClipBox )
95  m_clipBox = *aClipBox;
96  }
97 
99  virtual void Save() override
100  {
101  m_transformHistory.push( m_transform );
102  }
103 
104  virtual void Restore() override
105  {
106  m_transform = m_transformHistory.top();
107  m_transformHistory.pop();
108  }
109 
110 
115  virtual void DrawPolyline( const std::deque<VECTOR2D>& aPointList ) override;
116 
121  virtual void DrawLine( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint ) override;
122 
128  virtual void Translate( const VECTOR2D& aTranslation ) override
129  {
130  m_transform.m_moveOffset += aTranslation;
131  }
132 
138  virtual void Rotate( double aAngle ) override
139  {
140  m_transform.m_rotAngle = aAngle;
141  m_transform.m_rotCenter = m_transform.m_moveOffset;
142  }
143 
144 private:
145  // Apply the roation/translation transform to aPoint
146  const VECTOR2D transform( const VECTOR2D& aPoint ) const;
147 
148  // A clip box, to clip drawings in a wxDC (mandatory to avoid draw issues)
149  EDA_RECT m_clipBox; // The clip box
150  bool m_isClipped; // Allows/disallows clipping
151 
152  // When calling the draw functions outside a wxDC, to get the basic drawings
153  // lines / polylines ..., a callback function (used in DRC) to store
154  // coordinates of each segment:
155  void (* m_callback)( int x0, int y0, int xf, int yf );
156 
157  // When calling the draw functions for plot, the plotter acts as a wxDC
158  // to plot basic items
160 };
161 
162 
163 extern BASIC_GAL basic_gal;
164 
165 #endif // define BASIC_GAL_H
bool m_isClipped
Definition: basic_gal.h:150
EDA_RECT m_clipBox
Definition: basic_gal.h:149
const VECTOR2D transform(const VECTOR2D &aPoint) const
Definition: basic_gal.cpp:47
std::stack< TRANSFORM_PRM > m_transformHistory
Definition: basic_gal.h:65
double m_rotAngle
Definition: basic_gal.h:54
GAL(GAL_DISPLAY_OPTIONS &aOptions)
virtual void Rotate(double aAngle) override
Rotate the context.
Definition: basic_gal.h:138
virtual void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint) override
Start and end points are defined as 2D-Vectors.
Definition: basic_gal.cpp:105
virtual void Save() override
Save the context.
Definition: basic_gal.h:99
COLOR4D m_Color
Definition: basic_gal.h:61
VECTOR2D m_moveOffset
Definition: basic_gal.h:53
Common plot library Plot settings, and plotting engines (Postscript, Gerber, HPGL and DXF) ...
Definition: colors.h:60
virtual void Restore() override
Restore the context.
Definition: basic_gal.h:104
void SetPlotter(PLOTTER *aPlotter)
Definition: basic_gal.h:78
virtual void Translate(const VECTOR2D &aTranslation) override
Translate the context.
Definition: basic_gal.h:128
void SetCallback(void(*aCallback)(int x0, int y0, int xf, int yf))
Definition: basic_gal.h:83
VECTOR2D m_rotCenter
Definition: basic_gal.h:52
PLOTTER * m_plotter
Definition: basic_gal.h:159
Base plotter engine class.
Definition: plot_common.h:86
BASIC_GAL(KIGFX::GAL_DISPLAY_OPTIONS &aDisplayOptions)
Definition: basic_gal.h:68
wxDC * m_DC
Definition: basic_gal.h:60
Class EDA_RECT handles the component boundary box.
TRANSFORM_PRM m_transform
Definition: basic_gal.h:64
BASIC_GAL basic_gal
void(* m_callback)(int x0, int y0, int xf, int yf)
Definition: basic_gal.h:155
virtual void DrawPolyline(const std::deque< VECTOR2D > &aPointList) override
Draw a polyline.
Definition: basic_gal.cpp:54
void SetClipBox(EDA_RECT *aClipBox)
Set a clip box for drawings If NULL, no clip will be made.
Definition: basic_gal.h:90
Class GAL is the abstract interface for drawing on a 2D-surface.
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39