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 The 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, see <https://www.gnu.org/licenses/>.
21 */
22
23#include <view/view.h>
24#include <view/view_item.h>
25#include <view/view_overlay.h>
27#include <gal/painter.h>
28
29#include <geometry/seg.h>
31
32
33namespace KIGFX {
34
36{
37 virtual ~COMMAND() {};
38 virtual void Execute( VIEW* aView ) const = 0;
39};
40
41
43{
44 COMMAND_LINE( const VECTOR2D& aP0, const VECTOR2D& aP1 ) :
45 m_p0( aP0 ),
46 m_p1( aP1 ) {}
47
48 virtual void Execute( VIEW* aView ) const override
49 {
50 aView->GetGAL()->DrawLine( m_p0, m_p1 );
51 }
52
55};
56
57
59{
60 COMMAND_RECTANGLE( const VECTOR2D& aP0, const VECTOR2D& aP1 ) :
61 m_p0( aP0 ),
62 m_p1( aP1 )
63 { }
64
65 virtual void Execute( VIEW* aView ) const override
66 {
67 aView->GetGAL()->DrawRectangle( m_p0, m_p1 );
68 }
69
72};
73
74
76{
77 COMMAND_CIRCLE( const VECTOR2D& aCenter, double aRadius ) :
78 m_center(aCenter),
79 m_radius(aRadius)
80 { }
81
82 virtual void Execute( VIEW* aView ) const override
83 {
84 aView->GetGAL()->DrawCircle( m_center, m_radius );
85 }
86
88 double m_radius;
89};
90
91
93{
94 COMMAND_ARC( const VECTOR2D& aCenter, double aRadius, const EDA_ANGLE& aStartAngle,
95 const EDA_ANGLE& aEndAngle ) :
96 m_center( aCenter ),
97 m_radius( aRadius ),
98 m_startAngle( aStartAngle ),
99 m_endAngle( aEndAngle )
100 { }
101
102 virtual void Execute( VIEW* aView ) const override
103 {
105 }
106
108 double m_radius;
111};
112
113
115{
116 COMMAND_POLYGON( const std::deque<VECTOR2D>& aPointList ) :
117 m_pointList( aPointList )
118 { }
119
120 virtual void Execute( VIEW* aView ) const override
121 {
122 aView->GetGAL()->DrawPolygon( m_pointList );
123 }
124
125 std::deque<VECTOR2D> m_pointList;
126};
127
128
130{
132 m_polySet( aPolySet )
133 { }
134
135 virtual void Execute( VIEW* aView ) const override
136 {
137 aView->GetGAL()->DrawPolygon( m_polySet );
138 }
139
141};
142
143
145{
146 COMMAND_POINT_POLYGON( const VECTOR2D aPointList[], int aListSize )
147 {
148 m_pointList.reserve( aListSize );
149
150 for( int ii = 0; ii < aListSize; ii++ )
151 m_pointList.push_back( aPointList[ii] );
152 }
153
154 virtual void Execute( VIEW* aView ) const override
155 {
156 aView->GetGAL()->DrawPolygon( &m_pointList[0], (int)m_pointList.size() );
157 }
158
159 std::vector<VECTOR2D> m_pointList;
160};
161
162
164{
165 COMMAND_SET_STROKE( bool aIsStroke ) :
166 m_isStroke( aIsStroke )
167 { }
168
169 virtual void Execute( VIEW* aView ) const override
170 {
171 aView->GetGAL()->SetIsStroke( m_isStroke );
172 }
173
175};
176
177
179{
180 COMMAND_SET_FILL( bool aIsFill ) :
181 m_isFill( aIsFill )
182 { }
183
184 virtual void Execute( VIEW* aView ) const override
185 {
186 aView->GetGAL()->SetIsFill( m_isFill );
187 }
188
190};
191
192
194{
195 COMMAND_SET_COLOR( bool aIsStroke, const COLOR4D& aColor ) :
196 m_isStroke( aIsStroke ),
197 m_color( aColor )
198 { }
199
200 virtual void Execute( VIEW* aView ) const override
201 {
202 if( m_isStroke )
203 aView->GetGAL()->SetStrokeColor( m_color );
204 else
205 aView->GetGAL()->SetFillColor( m_color );
206 }
207
210};
211
212
214{
215 COMMAND_SET_WIDTH( double aWidth ) :
216 m_width( aWidth )
217 { }
218
219 virtual void Execute( VIEW* aView ) const override
220 {
221 aView->GetGAL()->SetLineWidth( m_width );
222 }
223
224 double m_width;
225};
226
227
229{
231 m_size( aSize )
232 { };
233
234 virtual void Execute( VIEW* aView ) const override
235 {
236 aView->GetGAL()->SetGlyphSize( m_size );
237 }
238
240};
241
242
244{
245 COMMAND_BITMAP_TEXT( const wxString& aText, const VECTOR2I& aPosition,
246 const EDA_ANGLE& aAngle ) :
247 m_text( aText ),
248 m_pos( aPosition ),
249 m_angle( aAngle )
250 { }
251
252 virtual void Execute( VIEW* aView ) const override
253 {
254 aView->GetGAL()->BitmapText( m_text, m_pos, m_angle );
255 }
256
257 wxString m_text;
260};
261
262
266
267
272
273
275{
276 return wxT( "VIEW_OVERLAY" );
277}
278
279
281{
283 delete cmd;
284
285 m_commands.clear();
286}
287
288
290{
292}
293
294
296{
297 BOX2I maxBox;
298
299 maxBox.SetMaximum();
300 return maxBox;
301}
302
303
304void VIEW_OVERLAY::ViewDraw( int aLayer, VIEW* aView ) const
305{
306 GAL& gal = *aView->GetGAL();
307
309 gal.SetLayerDepth( gal.GetMinDepth() );
310
311 for( const VIEW_OVERLAY::COMMAND* cmd : m_commands )
312 cmd->Execute( aView );
313}
314
315
316std::vector<int> VIEW_OVERLAY::ViewGetLayers() const
317{
318 return { LAYER_GP_OVERLAY };
319}
320
321
322void VIEW_OVERLAY::Line( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint )
323{
324 m_commands.push_back( new COMMAND_LINE( aStartPoint, aEndPoint ) );
325}
326
327
328void VIEW_OVERLAY::Line( const SEG& aSeg )
329{
330 Line( aSeg.A, aSeg.B );
331}
332
333
334void VIEW_OVERLAY::Segment( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint, double aWidth )
335{
336 SetLineWidth( aWidth );
337 Line( aStartPoint, aEndPoint );
338}
339
340
342{
343 SetIsStroke( true );
344 SetIsFill( false );
345
346 for( int i = 0; i < aPolyLine.SegmentCount(); i++ )
347 Line( aPolyLine.CSegment( i ) );
348}
349
350
352{
353 m_commands.push_back( new COMMAND_POLY_POLYGON( aPolySet ) );
354}
355
356
357void VIEW_OVERLAY::Polygon( const std::deque<VECTOR2D>& aPointList )
358{
359 m_commands.push_back( new COMMAND_POLYGON( aPointList ) );
360}
361
362
363void VIEW_OVERLAY::Polygon( const VECTOR2D aPointList[], int aListSize )
364{
365 m_commands.push_back( new COMMAND_POINT_POLYGON( aPointList, aListSize ) );
366}
367
368
369void VIEW_OVERLAY::Circle( const VECTOR2D& aCenterPoint, double aRadius )
370{
371 m_commands.push_back( new COMMAND_CIRCLE( aCenterPoint, aRadius ) );
372}
373
374
375void VIEW_OVERLAY::Arc( const VECTOR2D& aCenterPoint, double aRadius, const EDA_ANGLE& aStartAngle,
376 const EDA_ANGLE& aEndAngle )
377{
378 m_commands.push_back( new COMMAND_ARC( aCenterPoint, aRadius, aStartAngle, aEndAngle ) );
379}
380
381
382void VIEW_OVERLAY::Rectangle( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint )
383{
384 m_commands.push_back( new COMMAND_RECTANGLE( aStartPoint, aEndPoint ) );
385}
386
387
388void VIEW_OVERLAY::SetIsFill( bool aIsFillEnabled )
389{
390 m_commands.push_back( new COMMAND_SET_FILL( aIsFillEnabled ) );
391}
392
393
395{
396 m_commands.push_back( new COMMAND_GLYPH_SIZE( aSize ) );
397}
398
399
400void VIEW_OVERLAY::BitmapText( const wxString& aText, const VECTOR2I& aPosition,
401 const EDA_ANGLE& aAngle )
402{
403 m_commands.push_back( new COMMAND_BITMAP_TEXT( aText, aPosition, aAngle ) );
404}
405
406
407void VIEW_OVERLAY::SetIsStroke( bool aIsStrokeEnabled )
408{
409 m_commands.push_back( new COMMAND_SET_STROKE( aIsStrokeEnabled ) );
410}
411
412
414{
415 m_fillColor = aColor;
416 m_commands.push_back( new COMMAND_SET_COLOR( false, aColor ) );
417}
418
419
421{
422 m_strokeColor = aColor;
423 m_commands.push_back( new COMMAND_SET_COLOR( true, aColor ) );
424}
425
426
427void VIEW_OVERLAY::SetLineWidth( double aLineWidth )
428{
429 m_commands.push_back( new COMMAND_SET_WIDTH( aLineWidth ) );
430}
431
432
433void VIEW_OVERLAY::Cross( const VECTOR2D& aP, int aSize )
434{
435 Line( aP + VECTOR2D( -aSize, -aSize ), aP + VECTOR2D( aSize, aSize ) );
436 Line( aP + VECTOR2D( aSize, -aSize ), aP + VECTOR2D( -aSize, aSize ) );
437}
438
439
440} // namespace
BOX2< VECTOR2I > BOX2I
Definition box2.h:914
constexpr void SetMaximum()
Definition box2.h:77
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
Attribute save/restore for GAL attributes.
Abstract interface for drawing on a 2D-surface.
virtual void DrawPolygon(const std::deque< VECTOR2D > &aPointList)
Draw a polygon.
virtual void SetLayerDepth(double aLayerDepth)
Set the depth of the layer (position on the z-axis)
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.
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.
double GetMinDepth() const
virtual void BitmapText(const wxString &aText, const VECTOR2I &aPosition, const EDA_ANGLE &aAngle)
Draw a text using a bitmap font.
friend class VIEW
Definition view_item.h:201
void SetGlyphSize(const VECTOR2I &aSize)
void SetLineWidth(double aLineWidth)
void Polygon(const std::deque< VECTOR2D > &aPointList)
std::vector< COMMAND * > m_commands
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.
virtual std::vector< int > ViewGetLayers() const override
Return the all the layers within the VIEW the object is painted on.
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)
wxString GetClass() const override
Return the class name.
GAL * GetGAL() const
Return the GAL this view is using to draw graphical primitives.
Definition view.h:224
Definition seg.h:38
VECTOR2I A
Definition seg.h:45
VECTOR2I B
Definition seg.h:46
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:275
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:30
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)
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< int32_t > VECTOR2I
Definition vector2d.h:708
VECTOR2< double > VECTOR2D
Definition vector2d.h:707