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 GAL& gal = *aView->GetGAL();
302
304 gal.SetLayerDepth( gal.GetMinDepth() );
305
306 for( const VIEW_OVERLAY::COMMAND* cmd : m_commands )
307 cmd->Execute( aView );
308}
309
310
311void VIEW_OVERLAY::ViewGetLayers( int aLayers[], int& aCount ) const
312{
313 aLayers[0] = LAYER_GP_OVERLAY;
314 aCount = 1;
315}
316
317
318void VIEW_OVERLAY::Line( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint )
319{
320 m_commands.push_back( new COMMAND_LINE( aStartPoint, aEndPoint ) );
321}
322
323
324void VIEW_OVERLAY::Line( const SEG& aSeg )
325{
326 Line( aSeg.A, aSeg.B );
327}
328
329
330void VIEW_OVERLAY::Segment( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint, double aWidth )
331{
332 SetLineWidth( aWidth );
333 Line( aStartPoint, aEndPoint );
334}
335
336
338{
339 SetIsStroke( true );
340 SetIsFill( false );
341
342 for( int i = 0; i < aPolyLine.SegmentCount(); i++ )
343 Line( aPolyLine.CSegment( i ) );
344}
345
346
348{
349 m_commands.push_back( new COMMAND_POLY_POLYGON( aPolySet ) );
350}
351
352
353void VIEW_OVERLAY::Polygon( const std::deque<VECTOR2D>& aPointList )
354{
355 m_commands.push_back( new COMMAND_POLYGON( aPointList ) );
356}
357
358
359void VIEW_OVERLAY::Polygon( const VECTOR2D aPointList[], int aListSize )
360{
361 m_commands.push_back( new COMMAND_POINT_POLYGON( aPointList, aListSize ) );
362}
363
364
365void VIEW_OVERLAY::Circle( const VECTOR2D& aCenterPoint, double aRadius )
366{
367 m_commands.push_back( new COMMAND_CIRCLE( aCenterPoint, aRadius ) );
368}
369
370
371void VIEW_OVERLAY::Arc( const VECTOR2D& aCenterPoint, double aRadius, const EDA_ANGLE& aStartAngle,
372 const EDA_ANGLE& aEndAngle )
373{
374 m_commands.push_back( new COMMAND_ARC( aCenterPoint, aRadius, aStartAngle, aEndAngle ) );
375}
376
377
378void VIEW_OVERLAY::Rectangle( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint )
379{
380 m_commands.push_back( new COMMAND_RECTANGLE( aStartPoint, aEndPoint ) );
381}
382
383
384void VIEW_OVERLAY::SetIsFill( bool aIsFillEnabled )
385{
386 m_commands.push_back( new COMMAND_SET_FILL( aIsFillEnabled ) );
387}
388
389
391{
392 m_commands.push_back( new COMMAND_GLYPH_SIZE( aSize ) );
393}
394
395
396void VIEW_OVERLAY::BitmapText( const wxString& aText, const VECTOR2I& aPosition,
397 const EDA_ANGLE& aAngle )
398{
399 m_commands.push_back( new COMMAND_BITMAP_TEXT( aText, aPosition, aAngle ) );
400}
401
402
403void VIEW_OVERLAY::SetIsStroke( bool aIsStrokeEnabled )
404{
405 m_commands.push_back( new COMMAND_SET_STROKE( aIsStrokeEnabled ) );
406}
407
408
410{
411 m_fillColor = aColor;
412 m_commands.push_back( new COMMAND_SET_COLOR( false, aColor ) );
413}
414
415
417{
418 m_strokeColor = aColor;
419 m_commands.push_back( new COMMAND_SET_COLOR( true, aColor ) );
420}
421
422void VIEW_OVERLAY::SetLineWidth( double aLineWidth )
423{
424 m_commands.push_back( new COMMAND_SET_WIDTH( aLineWidth ) );
425}
426
427void VIEW_OVERLAY::Cross( const VECTOR2D& aP, int aSize )
428{
429 Line( aP + VECTOR2D( -aSize, -aSize ), aP + VECTOR2D( aSize, aSize ) );
430 Line( aP + VECTOR2D( aSize, -aSize ), aP + VECTOR2D( -aSize, aSize ) );
431}
432
433
434} // namespace
constexpr void SetMaximum()
Definition: box2.h:80
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
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.
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:203
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:219
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:690