forked from KiCad/kicad-source-mirror
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic_gal.h
179 lines (149 loc) · 5.26 KB
/
basic_gal.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef BASIC_GAL_H
#define BASIC_GAL_H
#include <eda_rect.h>
#include <gal/stroke_font.h>
#include <gal/graphics_abstraction_layer.h>
#include <newstroke_font.h>
class PLOTTER;
/*
* A minimal GAL implementation to draw, plot and convert stroke texts to a set of segments
* for DRC tests, and to calculate text sizes.
*
* Currently it allows one to use GAL and STROKE_FONT methods in legacy draw mode
* (using wxDC functions) in plot functions only for texts.
* It is used also to calculate the text bounding boxes
*
* The main purpose is to avoid duplicate code to do the same thing in GAL canvas,
* print & plotter canvasses and DRC.
*
* It will be certainly removed when a full GAL canvas using wxDC is implemented
* (or at least restricted to plotter and DRC "canvas")
*/
struct TRANSFORM_PRM // A helper class to transform coordinates in BASIC_GAL canvas
{
VECTOR2D m_rotCenter;
VECTOR2D m_moveOffset;
double m_rotAngle;
};
class BASIC_GAL: public KIGFX::GAL
{
public:
BASIC_GAL( KIGFX::GAL_DISPLAY_OPTIONS& aDisplayOptions ) :
GAL( aDisplayOptions ),
m_DC( nullptr ),
m_Color( RED ),
m_transform(),
m_clipBox(),
m_isClipped( false ),
m_callback( nullptr ),
m_callbackData( nullptr ),
m_plotter( nullptr )
{
}
void SetPlotter( PLOTTER* aPlotter )
{
m_plotter = aPlotter;
}
void SetCallback( void (* aCallback)( int x0, int y0, int xf, int yf, void* aData ),
void* aData )
{
m_callback = aCallback;
m_callbackData = aData;
}
/// Set a clip box for drawings
/// If NULL, no clip will be made
void SetClipBox( EDA_RECT* aClipBox )
{
m_isClipped = aClipBox != nullptr;
if( aClipBox )
m_clipBox = *aClipBox;
}
/// Save the context.
virtual void Save() override
{
m_transformHistory.push( m_transform );
}
virtual void Restore() override
{
m_transform = m_transformHistory.top();
m_transformHistory.pop();
}
/**
* Draw a polyline
*
* @param aPointList is a list of 2D-Vectors containing the polyline points.
*/
virtual void DrawPolyline( const std::deque<VECTOR2D>& aPointList ) override;
virtual void DrawPolyline( const VECTOR2D aPointList[], int aListSize ) override;
/**
* Start and end points are defined as 2D-Vectors.
*
* @param aStartPoint is the start point of the line.
* @param aEndPoint is the end point of the line.
*/
virtual void DrawLine( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint ) override;
/**
* Translate the context.
*
* @param aTranslation is the translation vector.
*/
virtual void Translate( const VECTOR2D& aTranslation ) override
{
m_transform.m_moveOffset += aTranslation;
}
/**
* Rotate the context.
*
* @param aAngle is the rotation angle in radians.
*/
virtual void Rotate( double aAngle ) override
{
m_transform.m_rotAngle = aAngle;
m_transform.m_rotCenter = m_transform.m_moveOffset;
}
private:
void doDrawPolyline( const std::vector<wxPoint>& aLocalPointList );
// Apply the rotation/translation transform to aPoint
const VECTOR2D transform( const VECTOR2D& aPoint ) const;
public:
wxDC* m_DC;
COLOR4D m_Color;
private:
TRANSFORM_PRM m_transform;
std::stack <TRANSFORM_PRM> m_transformHistory;
// A clip box, to clip drawings in a wxDC (mandatory to avoid draw issues)
EDA_RECT m_clipBox; // The clip box
bool m_isClipped; // Allows/disallows clipping
// When calling the draw functions outside a wxDC, to get the basic drawings
// lines / polylines ..., a callback function (used in DRC) to store
// coordinates of each segment:
void (* m_callback)( int x0, int y0, int xf, int yf, void* aData );
void* m_callbackData; // a optional parameter for m_callback
// When calling the draw functions for plot, the plotter acts as a wxDC to plot basic items.
PLOTTER* m_plotter;
};
extern BASIC_GAL basic_gal;
#endif // define BASIC_GAL_H