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>
30
31namespace KIGFX {
32
34{
35 virtual ~COMMAND() {};
36 virtual void Execute( VIEW* aView ) const = 0;
37};
38
39
41{
42 COMMAND_LINE( const VECTOR2D& aP0, const VECTOR2D& aP1 ) :
43 m_p0( aP0 ),
44 m_p1( aP1 ) {}
45
46 virtual void Execute( VIEW* aView ) const override
47 {
48 aView->GetGAL()->DrawLine( m_p0, m_p1 );
49 }
50
53};
54
55
57{
58 COMMAND_RECTANGLE( const VECTOR2D& aP0, const VECTOR2D& aP1 ) :
59 m_p0( aP0 ),
60 m_p1( aP1 )
61 { }
62
63 virtual void Execute( VIEW* aView ) const override
64 {
65 aView->GetGAL()->DrawRectangle( m_p0, m_p1 );
66 }
67
70};
71
72
74{
75 COMMAND_CIRCLE( const VECTOR2D& aCenter, double aRadius ) :
76 m_center(aCenter),
77 m_radius(aRadius)
78 { }
79
80 virtual void Execute( VIEW* aView ) const override
81 {
82 aView->GetGAL()->DrawCircle( m_center, m_radius );
83 }
84
86 double m_radius;
87};
88
89
91{
92 COMMAND_ARC( const VECTOR2D& aCenter, double aRadius, const EDA_ANGLE& aStartAngle,
93 const EDA_ANGLE& aEndAngle ) :
94 m_center( aCenter ),
95 m_radius( aRadius ),
96 m_startAngle( aStartAngle ),
97 m_endAngle( aEndAngle )
98 { }
99
100 virtual void Execute( VIEW* aView ) const override
101 {
103 }
104
106 double m_radius;
109};
110
111
113{
114 COMMAND_POLYGON( const std::deque<VECTOR2D>& aPointList ) :
115 m_pointList( aPointList )
116 { }
117
118 virtual void Execute( VIEW* aView ) const override
119 {
120 aView->GetGAL()->DrawPolygon( m_pointList );
121 }
122
123 std::deque<VECTOR2D> m_pointList;
124};
125
126
128{
130 m_polySet( aPolySet )
131 { }
132
133 virtual void Execute( VIEW* aView ) const override
134 {
135 aView->GetGAL()->DrawPolygon( m_polySet );
136 }
137
139};
140
141
143{
144 COMMAND_POINT_POLYGON( const VECTOR2D aPointList[], int aListSize )
145 {
146 m_pointList.reserve( aListSize );
147
148 for( int ii = 0; ii < aListSize; ii++ )
149 m_pointList.push_back( aPointList[ii] );
150 }
151
152 virtual void Execute( VIEW* aView ) const override
153 {
154 aView->GetGAL()->DrawPolygon( &m_pointList[0], (int)m_pointList.size() );
155 }
156
157 std::vector<VECTOR2D> m_pointList;
158};
159
160
162{
163 COMMAND_SET_STROKE( bool aIsStroke ) :
164 m_isStroke( aIsStroke )
165 { }
166
167 virtual void Execute( VIEW* aView ) const override
168 {
169 aView->GetGAL()->SetIsStroke( m_isStroke );
170 }
171
173};
174
175
177{
178 COMMAND_SET_FILL( bool aIsFill ) :
179 m_isFill( aIsFill )
180 { }
181
182 virtual void Execute( VIEW* aView ) const override
183 {
184 aView->GetGAL()->SetIsFill( m_isFill );
185 }
186
188};
189
190
192{
193 COMMAND_SET_COLOR( bool aIsStroke, const COLOR4D& aColor ) :
194 m_isStroke( aIsStroke ),
195 m_color( aColor )
196 { }
197
198 virtual void Execute( VIEW* aView ) const override
199 {
200 if( m_isStroke )
201 aView->GetGAL()->SetStrokeColor( m_color );
202 else
203 aView->GetGAL()->SetFillColor( m_color );
204 }
205
208};
209
210
212{
213 COMMAND_SET_WIDTH( double aWidth ) :
214 m_width( aWidth )
215 { }
216
217 virtual void Execute( VIEW* aView ) const override
218 {
219 aView->GetGAL()->SetLineWidth( m_width );
220 }
221
222 double m_width;
223};
224
225
227{
229 m_size( aSize )
230 { };
231
232 virtual void Execute( VIEW* aView ) const override
233 {
234 aView->GetGAL()->SetGlyphSize( m_size );
235 }
236
238};
239
240
242{
243 COMMAND_BITMAP_TEXT( const wxString& aText, const VECTOR2I& aPosition,
244 const EDA_ANGLE& aAngle ) :
245 m_text( aText ),
246 m_pos( aPosition ),
247 m_angle( aAngle )
248 { }
249
250 virtual void Execute( VIEW* aView ) const override
251 {
252 aView->GetGAL()->BitmapText( m_text, m_pos, m_angle );
253 }
254
255 wxString m_text;
258};
259
260
264
265
270
271
273{
274 return wxT( "VIEW_OVERLAY" );
275}
276
277
279{
281 delete cmd;
282
283 m_commands.clear();
284}
285
286
288{
290}
291
292
294{
295 BOX2I maxBox;
296
297 maxBox.SetMaximum();
298 return maxBox;
299}
300
301
302void VIEW_OVERLAY::ViewDraw( int aLayer, VIEW* aView ) const
303{
304 GAL& gal = *aView->GetGAL();
305
307 gal.SetLayerDepth( gal.GetMinDepth() );
308
309 for( const VIEW_OVERLAY::COMMAND* cmd : m_commands )
310 cmd->Execute( aView );
311}
312
313
314std::vector<int> VIEW_OVERLAY::ViewGetLayers() const
315{
316 return { LAYER_GP_OVERLAY };
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
424
425void VIEW_OVERLAY::SetLineWidth( double aLineWidth )
426{
427 m_commands.push_back( new COMMAND_SET_WIDTH( aLineWidth ) );
428}
429
430
431void VIEW_OVERLAY::Cross( const VECTOR2D& aP, int aSize )
432{
433 Line( aP + VECTOR2D( -aSize, -aSize ), aP + VECTOR2D( aSize, aSize ) );
434 Line( aP + VECTOR2D( aSize, -aSize ), aP + VECTOR2D( -aSize, aSize ) );
435}
436
437
438} // namespace
BOX2< VECTOR2I > BOX2I
Definition box2.h:918
constexpr void SetMaximum()
Definition box2.h:76
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:207
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:29
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:683
VECTOR2< double > VECTOR2D
Definition vector2d.h:682