KiCad PCB EDA Suite
view_overlay.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) 2013-2017 CERN
5 * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
6 * @author Tomasz Wlostowski <[email protected]>
7 * @author Maciej Suminski <[email protected]>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, you may find one here:
21 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22 * or you may search the http://www.gnu.org website for the version 2 license,
23 * or you may write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 */
26
27#include <view/view.h>
28#include <view/view_item.h>
29#include <view/view_overlay.h>
31#include <painter.h>
32
33#include <layer_ids.h>
34#include <geometry/seg.h>
35
36namespace KIGFX {
37
39{
40 virtual ~COMMAND() {};
41 virtual void Execute( VIEW* aView ) const = 0;
42};
43
44
46{
47 COMMAND_LINE( const VECTOR2D& aP0, const VECTOR2D& aP1 ) :
48 m_p0( aP0 ),
49 m_p1( aP1 ) {}
50
51 virtual void Execute( VIEW* aView ) const override
52 {
53 aView->GetGAL()->DrawLine( m_p0, m_p1 );
54 }
55
58};
59
60
62{
63 COMMAND_RECTANGLE( const VECTOR2D& aP0, const VECTOR2D& aP1 ) :
64 m_p0( aP0 ),
65 m_p1( aP1 )
66 { }
67
68 virtual void Execute( VIEW* aView ) const override
69 {
70 aView->GetGAL()->DrawRectangle( m_p0, m_p1 );
71 }
72
75};
76
77
79{
80 COMMAND_CIRCLE( const VECTOR2D& aCenter, double aRadius ) :
81 m_center(aCenter),
82 m_radius(aRadius)
83 { }
84
85 virtual void Execute( VIEW* aView ) const override
86 {
87 aView->GetGAL()->DrawCircle( m_center, m_radius );
88 }
89
91 double m_radius;
92};
93
94
96{
97 COMMAND_ARC( const VECTOR2D& aCenter, double aRadius, const EDA_ANGLE& aStartAngle,
98 const EDA_ANGLE& aEndAngle ) :
99 m_center( aCenter ),
100 m_radius( aRadius ),
101 m_startAngle( aStartAngle ),
102 m_endAngle( aEndAngle )
103 { }
104
105 virtual void Execute( VIEW* aView ) const override
106 {
108 }
109
111 double m_radius;
114};
115
116
118{
119 COMMAND_POLYGON( const std::deque<VECTOR2D>& aPointList ) :
120 m_pointList( aPointList )
121 { }
122
123 virtual void Execute( VIEW* aView ) const override
124 {
125 aView->GetGAL()->DrawPolygon( m_pointList );
126 }
127
128 std::deque<VECTOR2D> m_pointList;
129};
130
131
133{
135 m_polySet( aPolySet )
136 { }
137
138 virtual void Execute( VIEW* aView ) const override
139 {
140 aView->GetGAL()->DrawPolygon( m_polySet );
141 }
142
144};
145
146
148{
149 COMMAND_POINT_POLYGON( const VECTOR2D aPointList[], int aListSize )
150 {
151 m_pointList.reserve( aListSize );
152
153 for( int ii = 0; ii < aListSize; ii++ )
154 m_pointList.push_back( aPointList[ii] );
155 }
156
157 virtual void Execute( VIEW* aView ) const override
158 {
159 aView->GetGAL()->DrawPolygon( &m_pointList[0], (int)m_pointList.size() );
160 }
161
162 std::vector<VECTOR2D> m_pointList;
163};
164
165
167{
168 COMMAND_SET_STROKE( bool aIsStroke ) :
169 m_isStroke( aIsStroke )
170 { }
171
172 virtual void Execute( VIEW* aView ) const override
173 {
174 aView->GetGAL()->SetIsStroke( m_isStroke );
175 }
176
178};
179
180
182{
183 COMMAND_SET_FILL( bool aIsFill ) :
184 m_isFill( aIsFill )
185 { }
186
187 virtual void Execute( VIEW* aView ) const override
188 {
189 aView->GetGAL()->SetIsFill( m_isFill );
190 }
191
193};
194
195
197{
198 COMMAND_SET_COLOR( bool aIsStroke, const COLOR4D& aColor ) :
199 m_isStroke( aIsStroke ),
200 m_color( aColor )
201 { }
202
203 virtual void Execute( VIEW* aView ) const override
204 {
205 if( m_isStroke )
206 aView->GetGAL()->SetStrokeColor( m_color );
207 else
208 aView->GetGAL()->SetFillColor( m_color );
209 }
210
213};
214
215
217{
218 COMMAND_SET_WIDTH( double aWidth ) :
219 m_width( aWidth )
220 { }
221
222 virtual void Execute( VIEW* aView ) const override
223 {
224 aView->GetGAL()->SetLineWidth( m_width );
225 }
226
227 double m_width;
228};
229
230
232{
234 m_size( aSize )
235 { };
236
237 virtual void Execute( VIEW* aView ) const override
238 {
239 aView->GetGAL()->SetGlyphSize( m_size );
240 }
241
243};
244
245
247{
248 COMMAND_BITMAP_TEXT( const wxString& aText, const VECTOR2I& aPosition,
249 const EDA_ANGLE& aAngle ) :
250 m_text( aText ),
251 m_pos( aPosition ),
252 m_angle( aAngle )
253 { }
254
255 virtual void Execute( VIEW* aView ) const override
256 {
257 aView->GetGAL()->BitmapText( m_text, m_pos, m_angle );
258 }
259
260 wxString m_text;
263};
264
266{
267}
268
269
271{
273}
274
275
277{
279 delete cmd;
280
281 m_commands.clear();
282}
283
284
286{
288}
289
290
292{
293 BOX2I maxBox;
294
295 maxBox.SetMaximum();
296 return maxBox;
297}
298
299
300void VIEW_OVERLAY::ViewDraw( int aLayer, VIEW* aView ) const
301{
302 auto gal = aView->GetGAL();
303 gal->PushDepth();
304 gal->SetLayerDepth( gal->GetMinDepth() );
305
306 for( const VIEW_OVERLAY::COMMAND* cmd : m_commands )
307 cmd->Execute( aView );
308
309 gal->PopDepth();
310}
311
312
313void VIEW_OVERLAY::ViewGetLayers( int aLayers[], int& aCount ) const
314{
315 aLayers[0] = LAYER_GP_OVERLAY;
316 aCount = 1;
317}
318
319
320void VIEW_OVERLAY::Line( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint )
321{
322 m_commands.push_back( new COMMAND_LINE( aStartPoint, aEndPoint ) );
323}
324
325
326void VIEW_OVERLAY::Line( const SEG& aSeg )
327{
328 Line( aSeg.A, aSeg.B );
329}
330
331
332void VIEW_OVERLAY::Segment( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint, double aWidth )
333{
334 SetLineWidth( aWidth );
335 Line( aStartPoint, aEndPoint );
336}
337
338
340{
341 SetIsStroke( true );
342 SetIsFill( false );
343
344 for( int i = 0; i < aPolyLine.SegmentCount(); i++ )
345 Line( aPolyLine.CSegment( i ) );
346}
347
348
350{
351 m_commands.push_back( new COMMAND_POLY_POLYGON( aPolySet ) );
352}
353
354
355void VIEW_OVERLAY::Polygon( const std::deque<VECTOR2D>& aPointList )
356{
357 m_commands.push_back( new COMMAND_POLYGON( aPointList ) );
358}
359
360
361void VIEW_OVERLAY::Polygon( const VECTOR2D aPointList[], int aListSize )
362{
363 m_commands.push_back( new COMMAND_POINT_POLYGON( aPointList, aListSize ) );
364}
365
366
367void VIEW_OVERLAY::Circle( const VECTOR2D& aCenterPoint, double aRadius )
368{
369 m_commands.push_back( new COMMAND_CIRCLE( aCenterPoint, aRadius ) );
370}
371
372
373void VIEW_OVERLAY::Arc( const VECTOR2D& aCenterPoint, double aRadius, const EDA_ANGLE& aStartAngle,
374 const EDA_ANGLE& aEndAngle )
375{
376 m_commands.push_back( new COMMAND_ARC( aCenterPoint, aRadius, aStartAngle, aEndAngle ) );
377}
378
379
380void VIEW_OVERLAY::Rectangle( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint )
381{
382 m_commands.push_back( new COMMAND_RECTANGLE( aStartPoint, aEndPoint ) );
383}
384
385
386void VIEW_OVERLAY::SetIsFill( bool aIsFillEnabled )
387{
388 m_commands.push_back( new COMMAND_SET_FILL( aIsFillEnabled ) );
389}
390
391
393{
394 m_commands.push_back( new COMMAND_GLYPH_SIZE( aSize ) );
395}
396
397
398void VIEW_OVERLAY::BitmapText( const wxString& aText, const VECTOR2I& aPosition,
399 const EDA_ANGLE& aAngle )
400{
401 m_commands.push_back( new COMMAND_BITMAP_TEXT( aText, aPosition, aAngle ) );
402}
403
404
405void VIEW_OVERLAY::SetIsStroke( bool aIsStrokeEnabled )
406{
407 m_commands.push_back( new COMMAND_SET_STROKE( aIsStrokeEnabled ) );
408}
409
410
412{
413 m_fillColor = aColor;
414 m_commands.push_back( new COMMAND_SET_COLOR( false, aColor ) );
415}
416
417
419{
420 m_strokeColor = aColor;
421 m_commands.push_back( new COMMAND_SET_COLOR( true, aColor ) );
422}
423
424void VIEW_OVERLAY::SetLineWidth( double aLineWidth )
425{
426 m_commands.push_back( new COMMAND_SET_WIDTH( aLineWidth ) );
427}
428
429void VIEW_OVERLAY::Cross( const VECTOR2D& aP, int aSize )
430{
431 Line( aP + VECTOR2D( -aSize, -aSize ), aP + VECTOR2D( aSize, aSize ) );
432 Line( aP + VECTOR2D( aSize, -aSize ), aP + VECTOR2D( -aSize, aSize ) );
433}
434
435
436} // namespace
void SetMaximum()
Definition: box2.h:63
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
virtual void DrawPolygon(const std::deque< VECTOR2D > &aPointList)
Draw a polygon.
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
virtual void DrawRectangle(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a rectangle.
virtual void SetFillColor(const COLOR4D &aColor)
Set the fill color.
virtual void DrawCircle(const VECTOR2D &aCenterPoint, double aRadius)
Draw a circle using world coordinates.
void PushDepth()
Store current drawing depth on the depth stack.
virtual void SetLineWidth(float aLineWidth)
Set the line width.
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
virtual void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a line.
void SetGlyphSize(const VECTOR2I aSize)
virtual void BitmapText(const wxString &aText, const VECTOR2I &aPosition, const EDA_ANGLE &aAngle)
Draw a text using a bitmap font.
virtual void DrawArc(const VECTOR2D &aCenterPoint, double aRadius, const EDA_ANGLE &aStartAngle, const EDA_ANGLE &aEndAngle)
Draw an arc.
void SetGlyphSize(const VECTOR2I &aSize)
void SetLineWidth(double aLineWidth)
void Polygon(const std::deque< VECTOR2D > &aPointList)
std::vector< COMMAND * > m_commands
Definition: view_overlay.h:113
virtual void ViewGetLayers(int aLayers[], int &aCount) const override
Return the all the layers within the VIEW the object is painted on.
void Segment(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint, double aWidth)
void Rectangle(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
void Polyline(const SHAPE_LINE_CHAIN &aPolyLine)
virtual const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
void BitmapText(const wxString &aText, const VECTOR2I &aPosition, const EDA_ANGLE &aAngle)
void SetIsFill(bool aIsFillEnabled)
virtual void ViewDraw(int aLayer, VIEW *aView) const override
Draw the parts of the object belonging to layer aLayer.
void SetFillColor(const COLOR4D &aColor)
void Line(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
void Circle(const VECTOR2D &aCenterPoint, double aRadius)
void Cross(const VECTOR2D &aP, int aSize)
void Arc(const VECTOR2D &aCenterPoint, double aRadius, const EDA_ANGLE &aStartAngle, const EDA_ANGLE &aEndAngle)
void SetIsStroke(bool aIsStrokeEnabled)
void SetStrokeColor(const COLOR4D &aColor)
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:69
GAL * GetGAL() const
Return the #GAL this view is using to draw graphical primitives.
Definition: view.h:195
Definition: seg.h:42
VECTOR2I A
Definition: seg.h:49
VECTOR2I B
Definition: seg.h:50
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
int SegmentCount() const
Return the number of segments in this line chain.
const SEG CSegment(int aIndex) const
Return a constant copy of the aIndex segment in the line chain.
Represent a set of closed polygons.
@ LAYER_GP_OVERLAY
general purpose overlay
Definition: layer_ids.h:218
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:243
COMMAND_ARC(const VECTOR2D &aCenter, double aRadius, const EDA_ANGLE &aStartAngle, const EDA_ANGLE &aEndAngle)
virtual void Execute(VIEW *aView) const override
virtual void Execute(VIEW *aView) const override
COMMAND_BITMAP_TEXT(const wxString &aText, const VECTOR2I &aPosition, const EDA_ANGLE &aAngle)
virtual void Execute(VIEW *aView) const override
COMMAND_CIRCLE(const VECTOR2D &aCenter, double aRadius)
virtual void Execute(VIEW *aView) const override
COMMAND_LINE(const VECTOR2D &aP0, const VECTOR2D &aP1)
virtual void Execute(VIEW *aView) const override
virtual void Execute(VIEW *aView) const override
COMMAND_POINT_POLYGON(const VECTOR2D aPointList[], int aListSize)
std::deque< VECTOR2D > m_pointList
virtual void Execute(VIEW *aView) const override
COMMAND_POLYGON(const std::deque< VECTOR2D > &aPointList)
COMMAND_POLY_POLYGON(const SHAPE_POLY_SET &aPolySet)
virtual void Execute(VIEW *aView) const override
virtual void Execute(VIEW *aView) const override
COMMAND_RECTANGLE(const VECTOR2D &aP0, const VECTOR2D &aP1)
virtual void Execute(VIEW *aView) const override
COMMAND_SET_COLOR(bool aIsStroke, const COLOR4D &aColor)
virtual void Execute(VIEW *aView) const override
virtual void Execute(VIEW *aView) const override
virtual void Execute(VIEW *aView) const override
virtual void Execute(VIEW *aView) const =0
VECTOR2< double > VECTOR2D
Definition: vector2d.h:617