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  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
6  * @author Maciej Suminski <maciej.suminski@cern.ch>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 #include <view/view.h>
27 #include <view/view_item.h>
28 #include <view/view_overlay.h>
30 #include <painter.h>
31 
33 #include <geometry/seg.h>
34 
35 namespace 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 ), m_p1( aP1 )
64  {}
65 
66  virtual void Execute( VIEW* aView ) const override
67  {
68  aView->GetGAL()->DrawRectangle( m_p0, m_p1 );
69  }
70 
73 };
74 
75 
77 {
78  COMMAND_CIRCLE( const VECTOR2D& aCenter, double aRadius ) :
79  m_center(aCenter),
80  m_radius(aRadius) {}
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, double aStartAngle, double aEndAngle ) :
95  m_center( aCenter ),
96  m_radius( aRadius ),
97  m_startAngle( aStartAngle ),
98  m_endAngle( aEndAngle )
99  { }
100 
101  virtual void Execute( VIEW* aView ) const override
102  {
103  aView->GetGAL()->DrawArc( m_center, m_radius, m_startAngle, m_endAngle );
104  }
105 
107  double m_radius;
108  double m_startAngle;
109  double m_endAngle;
110 };
111 
112 
114 {
115  COMMAND_POLYLINE( const std::deque<VECTOR2D>& aPointList ) :
116  m_pointList( aPointList ) {}
117 
118  virtual void Execute( VIEW* aView ) const override
119  {
120  aView->GetGAL()->DrawPolyline( m_pointList );
121  }
122 
123  std::deque<VECTOR2D> m_pointList;
124 };
125 
126 
128 {
130  m_polyLine( aLineChain ) {}
131 
132  virtual void Execute( VIEW* aView ) const override
133  {
134  aView->GetGAL()->DrawPolyline( m_polyLine );
135  }
136 
138 };
139 
140 
142 {
143  COMMAND_POINT_POLYLINE( const VECTOR2D aPointList[], int aListSize )
144  {
145  m_pointList.reserve( aListSize );
146 
147  for( int ii = 0; ii < aListSize; ii++ )
148  m_pointList.push_back( aPointList[ii] );
149  }
150 
151  virtual void Execute( VIEW* aView ) const override
152  {
153  aView->GetGAL()->DrawPolyline( &m_pointList[0], (int)m_pointList.size() );
154  }
155 
156  std::vector<VECTOR2D> m_pointList;
157 };
158 
159 
161 {
162  COMMAND_POLYGON( const std::deque<VECTOR2D>& aPointList ) :
163  m_pointList( aPointList ) {}
164 
165  virtual void Execute( VIEW* aView ) const override
166  {
167  aView->GetGAL()->DrawPolygon( m_pointList );
168  }
169 
170  std::deque<VECTOR2D> m_pointList;
171 };
172 
173 
175 {
177  m_polySet( aPolySet ) {}
178 
179  virtual void Execute( VIEW* aView ) const override
180  {
181  aView->GetGAL()->DrawPolygon( m_polySet );
182  }
183 
185 };
186 
187 
189 {
190  COMMAND_POINT_POLYGON( const VECTOR2D aPointList[], int aListSize )
191  {
192  m_pointList.reserve( aListSize );
193 
194  for( int ii = 0; ii < aListSize; ii++ )
195  m_pointList.push_back( aPointList[ii] );
196  }
197 
198  virtual void Execute( VIEW* aView ) const override
199  {
200  aView->GetGAL()->DrawPolygon( &m_pointList[0], (int)m_pointList.size() );
201  }
202 
203  std::vector<VECTOR2D> m_pointList;
204 };
205 
206 
208 {
209  COMMAND_SET_STROKE( bool aIsStroke ) :
210  m_isStroke( aIsStroke ) {}
211 
212  virtual void Execute( VIEW* aView ) const override
213  {
214  aView->GetGAL()->SetIsStroke( m_isStroke );
215  }
216 
218 };
219 
220 
222 {
223  COMMAND_SET_FILL( bool aIsFill ) :
224  m_isFill( aIsFill ) {}
225 
226  virtual void Execute( VIEW* aView ) const override
227  {
228  aView->GetGAL()->SetIsFill( m_isFill );
229  }
230 
231  bool m_isFill;
232 };
233 
234 
236 {
237  COMMAND_SET_COLOR( bool aIsStroke, const COLOR4D& aColor ) :
238  m_isStroke( aIsStroke ),
239  m_color( aColor ) {}
240 
241  virtual void Execute( VIEW* aView ) const override
242  {
243  if( m_isStroke )
244  aView->GetGAL()->SetStrokeColor( m_color );
245  else
246  aView->GetGAL()->SetFillColor( m_color );
247  }
248 
251 };
252 
253 
255 {
256  COMMAND_SET_WIDTH( double aWidth ) :
257  m_width( aWidth ) {}
258 
259  virtual void Execute( VIEW* aView ) const override
260  {
261  aView->GetGAL()->SetLineWidth( m_width );
262  }
263 
264  double m_width;
265 };
266 
267 
269 {
270 }
271 
272 
274 {
275  releaseCommands();
276 }
277 
278 
280 {
281  for( auto cmd : m_commands )
282  delete cmd;
283 
284  m_commands.clear();
285 }
286 
287 
289 {
290  releaseCommands();
291 }
292 
293 
295 {
296  BOX2I maxBox;
297 
298  maxBox.SetMaximum();
299  return maxBox;
300 }
301 
302 
303 void VIEW_OVERLAY::ViewDraw( int aLayer, VIEW* aView ) const
304 {
305  for( const auto& cmd : m_commands )
306  cmd->Execute( aView );
307 }
308 
309 
310 void VIEW_OVERLAY::ViewGetLayers( int aLayers[], int& aCount ) const
311 {
312  aLayers[0] = LAYER_GP_OVERLAY;
313  aCount = 1;
314 }
315 
316 
317 void VIEW_OVERLAY::Line( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint )
318 {
319  m_commands.push_back( new COMMAND_LINE( aStartPoint, aEndPoint ) );
320 }
321 
322 
323 void VIEW_OVERLAY::Line( const SEG& aSeg )
324 {
325  Line( aSeg.A, aSeg.B );
326 }
327 
328 
329 void VIEW_OVERLAY::Segment( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint, double aWidth )
330 {
331  SetLineWidth( aWidth );
332  Line( aStartPoint, aEndPoint );
333 }
334 
335 
336 void VIEW_OVERLAY::Polyline( std::deque<VECTOR2D>& aPointList )
337 {
338 }
339 
340 
341 void VIEW_OVERLAY::Polyline( const VECTOR2D aPointList[], int aListSize )
342 {
343 }
344 
345 
346 void VIEW_OVERLAY::Polyline( const SHAPE_LINE_CHAIN& aLineChain )
347 {
348 }
349 
350 
351 void VIEW_OVERLAY::Polygon( const SHAPE_POLY_SET& aPolySet )
352 {
353  m_commands.push_back( new COMMAND_POLY_POLYGON( aPolySet ) );
354 }
355 
356 
357 void VIEW_OVERLAY::Polygon( const std::deque<VECTOR2D>& aPointList )
358 {
359  m_commands.push_back( new COMMAND_POLYGON( aPointList ) );
360 }
361 
362 
363 void VIEW_OVERLAY::Polygon( const VECTOR2D aPointList[], int aListSize )
364 {
365  m_commands.push_back( new COMMAND_POINT_POLYGON( aPointList, aListSize ) );
366 }
367 
368 
369 void VIEW_OVERLAY::Circle( const VECTOR2D& aCenterPoint, double aRadius )
370 {
371  m_commands.push_back( new COMMAND_CIRCLE( aCenterPoint, aRadius ) );
372 }
373 
374 
375 void VIEW_OVERLAY::Arc( const VECTOR2D& aCenterPoint,
376  double aRadius, double aStartAngle, double aEndAngle )
377 {
378  m_commands.push_back( new COMMAND_ARC( aCenterPoint, aRadius, aStartAngle, aEndAngle ) );
379 }
380 
381 
382 void VIEW_OVERLAY::Rectangle( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint )
383 {
384  m_commands.push_back( new COMMAND_RECTANGLE( aStartPoint, aEndPoint ) );
385 }
386 
387 
388 void VIEW_OVERLAY::SetIsFill( bool aIsFillEnabled )
389 {
390  m_commands.push_back( new COMMAND_SET_FILL( aIsFillEnabled ) );
391 }
392 
393 
394 void VIEW_OVERLAY::SetIsStroke( bool aIsStrokeEnabled )
395 {
396  m_commands.push_back( new COMMAND_SET_STROKE( aIsStrokeEnabled ) );
397 }
398 
399 
400 void VIEW_OVERLAY::SetFillColor( const COLOR4D& aColor )
401 {
402  m_commands.push_back( new COMMAND_SET_COLOR( false, aColor ) );
403 }
404 
405 
407 {
408  m_commands.push_back( new COMMAND_SET_COLOR( true, aColor ) );
409 }
410 
411 void VIEW_OVERLAY::SetLineWidth( double aLineWidth )
412 {
413  m_commands.push_back( new COMMAND_SET_WIDTH( aLineWidth ) );
414 }
415 
416 } // namespace
virtual void SetFillColor(const COLOR4D &aColor)
Set the fill color.
virtual void DrawPolyline(const std::deque< VECTOR2D > &aPointList)
Draw a polyline.
void Polyline(std::deque< VECTOR2D > &aPointList)
virtual void DrawRectangle(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a rectangle.
virtual void Execute(VIEW *aView) const =0
std::vector< COMMAND * > m_commands
Definition: view_overlay.h:104
virtual void Execute(VIEW *aView) const override
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:57
void Segment(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint, double aWidth)
COMMAND_POLYLINE(const std::deque< VECTOR2D > &aPointList)
COMMAND_POLY_POLYGON(const SHAPE_POLY_SET &aPolySet)
virtual void DrawArc(const VECTOR2D &aCenterPoint, double aRadius, double aStartAngle, double aEndAngle)
Draw an arc.
virtual void Execute(VIEW *aView) const override
COMMAND_POINT_POLYLINE(const VECTOR2D aPointList[], int aListSize)
virtual void Execute(VIEW *aView) const override
void SetFillColor(const COLOR4D &aColor)
virtual void ViewGetLayers(int aLayers[], int &aCount) const override
Function ViewGetLayers() Returns the all the layers within the VIEW the object is painted on...
std::deque< VECTOR2D > m_pointList
virtual void Execute(VIEW *aView) const override
virtual void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a line.
void SetIsStroke(bool aIsStrokeEnabled)
virtual void SetLineWidth(float aLineWidth)
Set the line width.
COMMAND_CIRCLE(const VECTOR2D &aCenter, double aRadius)
void Line(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
void Arc(const VECTOR2D &aCenterPoint, double aRadius, double aStartAngle, double aEndAngle)
void Polygon(const std::deque< VECTOR2D > &aPointList)
VIEW_ITEM class definition.
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
GAL * GetGAL() const
Function GetGAL() Returns the GAL this view is using to draw graphical primitives.
Definition: view.h:180
COMMAND_LINE(const VECTOR2D &aP0, const VECTOR2D &aP1)
Class SHAPE_POLY_SET.
virtual void Execute(VIEW *aView) const override
void SetMaximum()
Definition: box2.h:71
general purpose overlay
void SetStrokeColor(const COLOR4D &aColor)
virtual void Execute(VIEW *aView) const override
COMMAND_RECTANGLE(const VECTOR2D &aP0, const VECTOR2D &aP1)
COMMAND_POINT_POLYGON(const VECTOR2D aPointList[], int aListSize)
void SetIsFill(bool aIsFillEnabled)
Definition: seg.h:36
virtual const BOX2I ViewBBox() const override
Function ViewBBox() returns the bounding box of the item covering all its layers. ...
COMMAND_POLYGON(const std::deque< VECTOR2D > &aPointList)
virtual void Execute(VIEW *aView) const override
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
virtual void Execute(VIEW *aView) const override
virtual void Execute(VIEW *aView) const override
virtual void DrawPolygon(const std::deque< VECTOR2D > &aPointList)
Draw a polygon.
Board layer functions and definitions.
virtual void Execute(VIEW *aView) const override
void SetLineWidth(double aLineWidth)
virtual void DrawCircle(const VECTOR2D &aCenterPoint, double aRadius)
Draw a circle using world coordinates.
virtual void Execute(VIEW *aView) const override
Class SHAPE_LINE_CHAIN.
virtual void Execute(VIEW *aView) const override
VECTOR2I A
Definition: seg.h:44
COMMAND_SET_COLOR(bool aIsStroke, const COLOR4D &aColor)
COMMAND_POLY_POLYLINE(const SHAPE_LINE_CHAIN &aLineChain)
void Circle(const VECTOR2D &aCenterPoint, double aRadius)
Class VIEW.
Definition: view.h:61
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
virtual void Execute(VIEW *aView) const override
virtual void ViewDraw(int aLayer, VIEW *aView) const override
Function ViewDraw() Draws the parts of the object belonging to layer aLayer.
COMMAND_ARC(const VECTOR2D &aCenter, double aRadius, double aStartAngle, double aEndAngle)
void Rectangle(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
virtual void Execute(VIEW *aView) const override
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
VECTOR2I B
Definition: seg.h:45