KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 <gal/painter.h>
32
33#include <geometry/seg.h>
34
35namespace KIGFX {
36
38{
39 virtual ~COMMAND() {};
40 virtual void Execute( VIEW* aView ) const = 0;
41};
42
43
45{
46 COMMAND_LINE( const VECTOR2D& aP0, const VECTOR2D& aP1 ) :
47 m_p0( aP0 ),
48 m_p1( aP1 ) {}
49
50 virtual void Execute( VIEW* aView ) const override
51 {
52 aView->GetGAL()->DrawLine( m_p0, m_p1 );
53 }
54
57};
58
59
61{
62 COMMAND_RECTANGLE( const VECTOR2D& aP0, const VECTOR2D& aP1 ) :
63 m_p0( aP0 ),
64 m_p1( aP1 )
65 { }
66
67 virtual void Execute( VIEW* aView ) const override
68 {
69 aView->GetGAL()->DrawRectangle( m_p0, m_p1 );
70 }
71
74};
75
76
78{
79 COMMAND_CIRCLE( const VECTOR2D& aCenter, double aRadius ) :
80 m_center(aCenter),
81 m_radius(aRadius)
82 { }
83
84 virtual void Execute( VIEW* aView ) const override
85 {
86 aView->GetGAL()->DrawCircle( m_center, m_radius );
87 }
88
90 double m_radius;
91};
92
93
95{
96 COMMAND_ARC( const VECTOR2D& aCenter, double aRadius, const EDA_ANGLE& aStartAngle,
97 const EDA_ANGLE& aEndAngle ) :
98 m_center( aCenter ),
99 m_radius( aRadius ),
100 m_startAngle( aStartAngle ),
101 m_endAngle( aEndAngle )
102 { }
103
104 virtual void Execute( VIEW* aView ) const override
105 {
107 }
108
110 double m_radius;
113};
114
115
117{
118 COMMAND_POLYGON( const std::deque<VECTOR2D>& aPointList ) :
119 m_pointList( aPointList )
120 { }
121
122 virtual void Execute( VIEW* aView ) const override
123 {
124 aView->GetGAL()->DrawPolygon( m_pointList );
125 }
126
127 std::deque<VECTOR2D> m_pointList;
128};
129
130
132{
134 m_polySet( aPolySet )
135 { }
136
137 virtual void Execute( VIEW* aView ) const override
138 {
139 aView->GetGAL()->DrawPolygon( m_polySet );
140 }
141
143};
144
145
147{
148 COMMAND_POINT_POLYGON( const VECTOR2D aPointList[], int aListSize )
149 {
150 m_pointList.reserve( aListSize );
151
152 for( int ii = 0; ii < aListSize; ii++ )
153 m_pointList.push_back( aPointList[ii] );
154 }
155
156 virtual void Execute( VIEW* aView ) const override
157 {
158 aView->GetGAL()->DrawPolygon( &m_pointList[0], (int)m_pointList.size() );
159 }
160
161 std::vector<VECTOR2D> m_pointList;
162};
163
164
166{
167 COMMAND_SET_STROKE( bool aIsStroke ) :
168 m_isStroke( aIsStroke )
169 { }
170
171 virtual void Execute( VIEW* aView ) const override
172 {
173 aView->GetGAL()->SetIsStroke( m_isStroke );
174 }
175
177};
178
179
181{
182 COMMAND_SET_FILL( bool aIsFill ) :
183 m_isFill( aIsFill )
184 { }
185
186 virtual void Execute( VIEW* aView ) const override
187 {
188 aView->GetGAL()->SetIsFill( m_isFill );
189 }
190
192};
193
194
196{
197 COMMAND_SET_COLOR( bool aIsStroke, const COLOR4D& aColor ) :
198 m_isStroke( aIsStroke ),
199 m_color( aColor )
200 { }
201
202 virtual void Execute( VIEW* aView ) const override
203 {
204 if( m_isStroke )
205 aView->GetGAL()->SetStrokeColor( m_color );
206 else
207 aView->GetGAL()->SetFillColor( m_color );
208 }
209
212};
213
214
216{
217 COMMAND_SET_WIDTH( double aWidth ) :
218 m_width( aWidth )
219 { }
220
221 virtual void Execute( VIEW* aView ) const override
222 {
223 aView->GetGAL()->SetLineWidth( m_width );
224 }
225
226 double m_width;
227};
228
229
231{
233 m_size( aSize )
234 { };
235
236 virtual void Execute( VIEW* aView ) const override
237 {
238 aView->GetGAL()->SetGlyphSize( m_size );
239 }
240
242};
243
244
246{
247 COMMAND_BITMAP_TEXT( const wxString& aText, const VECTOR2I& aPosition,
248 const EDA_ANGLE& aAngle ) :
249 m_text( aText ),
250 m_pos( aPosition ),
251 m_angle( aAngle )
252 { }
253
254 virtual void Execute( VIEW* aView ) const override
255 {
256 aView->GetGAL()->BitmapText( m_text, m_pos, m_angle );
257 }
258
259 wxString m_text;
262};
263
265{
266}
267
268
270{
272}
273
274
276{
278 delete cmd;
279
280 m_commands.clear();
281}
282
283
285{
287}
288
289
291{
292 BOX2I maxBox;
293
294 maxBox.SetMaximum();
295 return maxBox;
296}
297
298
299void VIEW_OVERLAY::ViewDraw( int aLayer, VIEW* aView ) const
300{
301 auto gal = aView->GetGAL();
302 gal->PushDepth();
303 gal->SetLayerDepth( gal->GetMinDepth() );
304
305 for( const VIEW_OVERLAY::COMMAND* cmd : m_commands )
306 cmd->Execute( aView );
307
308 gal->PopDepth();
309}
310
311
312void VIEW_OVERLAY::ViewGetLayers( int aLayers[], int& aCount ) const
313{
314 aLayers[0] = LAYER_GP_OVERLAY;
315 aCount = 1;
316}
317
318
319void VIEW_OVERLAY::Line( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint )
320{
321 m_commands.push_back( new COMMAND_LINE( aStartPoint, aEndPoint ) );
322}
323
324
325void VIEW_OVERLAY::Line( const SEG& aSeg )
326{
327 Line( aSeg.A, aSeg.B );
328}
329
330
331void VIEW_OVERLAY::Segment( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint, double aWidth )
332{
333 SetLineWidth( aWidth );
334 Line( aStartPoint, aEndPoint );
335}
336
337
339{
340 SetIsStroke( true );
341 SetIsFill( false );
342
343 for( int i = 0; i < aPolyLine.SegmentCount(); i++ )
344 Line( aPolyLine.CSegment( i ) );
345}
346
347
349{
350 m_commands.push_back( new COMMAND_POLY_POLYGON( aPolySet ) );
351}
352
353
354void VIEW_OVERLAY::Polygon( const std::deque<VECTOR2D>& aPointList )
355{
356 m_commands.push_back( new COMMAND_POLYGON( aPointList ) );
357}
358
359
360void VIEW_OVERLAY::Polygon( const VECTOR2D aPointList[], int aListSize )
361{
362 m_commands.push_back( new COMMAND_POINT_POLYGON( aPointList, aListSize ) );
363}
364
365
366void VIEW_OVERLAY::Circle( const VECTOR2D& aCenterPoint, double aRadius )
367{
368 m_commands.push_back( new COMMAND_CIRCLE( aCenterPoint, aRadius ) );
369}
370
371
372void VIEW_OVERLAY::Arc( const VECTOR2D& aCenterPoint, double aRadius, const EDA_ANGLE& aStartAngle,
373 const EDA_ANGLE& aEndAngle )
374{
375 m_commands.push_back( new COMMAND_ARC( aCenterPoint, aRadius, aStartAngle, aEndAngle ) );
376}
377
378
379void VIEW_OVERLAY::Rectangle( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint )
380{
381 m_commands.push_back( new COMMAND_RECTANGLE( aStartPoint, aEndPoint ) );
382}
383
384
385void VIEW_OVERLAY::SetIsFill( bool aIsFillEnabled )
386{
387 m_commands.push_back( new COMMAND_SET_FILL( aIsFillEnabled ) );
388}
389
390
392{
393 m_commands.push_back( new COMMAND_GLYPH_SIZE( aSize ) );
394}
395
396
397void VIEW_OVERLAY::BitmapText( const wxString& aText, const VECTOR2I& aPosition,
398 const EDA_ANGLE& aAngle )
399{
400 m_commands.push_back( new COMMAND_BITMAP_TEXT( aText, aPosition, aAngle ) );
401}
402
403
404void VIEW_OVERLAY::SetIsStroke( bool aIsStrokeEnabled )
405{
406 m_commands.push_back( new COMMAND_SET_STROKE( aIsStrokeEnabled ) );
407}
408
409
411{
412 m_fillColor = aColor;
413 m_commands.push_back( new COMMAND_SET_COLOR( false, aColor ) );
414}
415
416
418{
419 m_strokeColor = aColor;
420 m_commands.push_back( new COMMAND_SET_COLOR( true, aColor ) );
421}
422
423void VIEW_OVERLAY::SetLineWidth( double aLineWidth )
424{
425 m_commands.push_back( new COMMAND_SET_WIDTH( aLineWidth ) );
426}
427
428void VIEW_OVERLAY::Cross( const VECTOR2D& aP, int aSize )
429{
430 Line( aP + VECTOR2D( -aSize, -aSize ), aP + VECTOR2D( aSize, aSize ) );
431 Line( aP + VECTOR2D( aSize, -aSize ), aP + VECTOR2D( -aSize, aSize ) );
432}
433
434
435} // namespace
void SetMaximum()
Definition: box2.h:64
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 DrawArc(const VECTOR2D &aCenterPoint, double aRadius, const EDA_ANGLE &aStartAngle, const EDA_ANGLE &aAngle)
Draw an arc.
virtual void BitmapText(const wxString &aText, const VECTOR2I &aPosition, const EDA_ANGLE &aAngle)
Draw a text using a bitmap font.
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:68
GAL * GetGAL() const
Return the #GAL this view is using to draw graphical primitives.
Definition: view.h:197
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:222
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:247
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:587