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_CIRCLE( const VECTOR2D& aCenter, double aRadius ) :
63  m_center(aCenter),
64  m_radius(aRadius) {}
65 
66  virtual void Execute( VIEW* aView ) const override
67  {
68  aView->GetGAL()->DrawCircle( m_center, m_radius );
69  }
70 
72  double m_radius;
73 };
74 
75 
77 {
78  COMMAND_ARC( const VECTOR2D& aCenter, double aRadius, double aStartAngle, double aEndAngle ) :
79  m_center( aCenter ),
80  m_radius( aRadius ),
81  m_startAngle( aStartAngle ),
82  m_endAngle( aEndAngle )
83  { }
84 
85  virtual void Execute( VIEW* aView ) const override
86  {
87  aView->GetGAL()->DrawArc( m_center, m_radius, m_startAngle, m_endAngle );
88  }
89 
91  double m_radius;
92  double m_startAngle;
93  double m_endAngle;
94 };
95 
96 
98 {
99  COMMAND_SET_STROKE( bool aIsStroke ) :
100  m_isStroke( aIsStroke ) {}
101 
102  virtual void Execute( VIEW* aView ) const override
103  {
104  aView->GetGAL()->SetIsStroke( m_isStroke );
105  }
106 
108 };
109 
110 
112 {
113  COMMAND_SET_FILL( bool aIsFill ) :
114  m_isFill( aIsFill ) {}
115 
116  virtual void Execute( VIEW* aView ) const override
117  {
118  aView->GetGAL()->SetIsFill( m_isFill );
119  }
120 
121  bool m_isFill;
122 };
123 
124 
126 {
127  COMMAND_SET_COLOR( bool aIsStroke, const COLOR4D& aColor ) :
128  m_isStroke( aIsStroke ),
129  m_color( aColor ) {}
130 
131  virtual void Execute( VIEW* aView ) const override
132  {
133  if( m_isStroke )
134  aView->GetGAL()->SetStrokeColor( m_color );
135  else
136  aView->GetGAL()->SetFillColor( m_color );
137  }
138 
141 };
142 
143 
145 {
146  COMMAND_SET_WIDTH( double aWidth ) :
147  m_width( aWidth ) {}
148 
149  virtual void Execute( VIEW* aView ) const override
150  {
151  aView->GetGAL()->SetLineWidth( m_width );
152  }
153 
154  double m_width;
155 };
156 
157 
159 {
160 }
161 
162 
164 {
165  releaseCommands();
166 }
167 
168 
170 {
171  for( auto cmd : m_commands )
172  delete cmd;
173 
174  m_commands.clear();
175 }
176 
177 
179 {
180  releaseCommands();
181 }
182 
183 
185 {
186  BOX2I maxBox;
187 
188  maxBox.SetMaximum();
189  return maxBox;
190 }
191 
192 
193 void VIEW_OVERLAY::ViewDraw( int aLayer, VIEW* aView ) const
194 {
195  for( const auto& cmd : m_commands )
196  cmd->Execute( aView );
197 }
198 
199 
200 void VIEW_OVERLAY::ViewGetLayers( int aLayers[], int& aCount ) const
201 {
202  aLayers[0] = LAYER_GP_OVERLAY;
203  aCount = 1;
204 }
205 
206 
207 void VIEW_OVERLAY::Line( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint )
208 {
209  m_commands.push_back( new COMMAND_LINE( aStartPoint, aEndPoint ) );
210 }
211 
212 
213 void VIEW_OVERLAY::Line( const SEG& aSeg )
214 {
215  Line( aSeg.A, aSeg.B );
216 }
217 
218 
219 void VIEW_OVERLAY::Segment( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint, double aWidth )
220 {
221 }
222 
223 
224 void VIEW_OVERLAY::Polyline( std::deque<VECTOR2D>& aPointList )
225 {
226 }
227 
228 
229 void VIEW_OVERLAY::Circle( const VECTOR2D& aCenterPoint, double aRadius )
230 {
231  m_commands.push_back( new COMMAND_CIRCLE( aCenterPoint, aRadius ) );
232 }
233 
234 
235 void VIEW_OVERLAY::Arc( const VECTOR2D& aCenterPoint,
236  double aRadius,
237  double aStartAngle,
238  double aEndAngle )
239 {
240  m_commands.push_back( new COMMAND_ARC( aCenterPoint, aRadius, aStartAngle, aEndAngle ) );
241 }
242 
243 
244 void VIEW_OVERLAY::Rectangle( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint )
245 {
246 }
247 
248 
249 void VIEW_OVERLAY::Polygon( const std::deque<VECTOR2D>& aPointList )
250 {
251 }
252 
253 
254 void VIEW_OVERLAY::SetIsFill( bool aIsFillEnabled )
255 {
256  m_commands.push_back( new COMMAND_SET_FILL( aIsFillEnabled ) );
257 }
258 
259 
260 void VIEW_OVERLAY::SetIsStroke( bool aIsStrokeEnabled )
261 {
262  m_commands.push_back( new COMMAND_SET_STROKE( aIsStrokeEnabled ) );
263 }
264 
265 
266 void VIEW_OVERLAY::SetFillColor( const COLOR4D& aColor )
267 {
268  m_commands.push_back( new COMMAND_SET_COLOR( false, aColor ) );
269 }
270 
271 
273 {
274  m_commands.push_back( new COMMAND_SET_COLOR( true, aColor ) );
275 }
276 
277 void VIEW_OVERLAY::SetLineWidth( double aLineWidth )
278 {
279  m_commands.push_back( new COMMAND_SET_WIDTH( aLineWidth ) );
280 }
281 
282 } // namespace
virtual void SetFillColor(const COLOR4D &aColor)
Set the fill color.
void Polyline(std::deque< VECTOR2D > &aPointList)
virtual void Execute(VIEW *aView) const =0
std::vector< COMMAND * > m_commands
Definition: view_overlay.h:81
virtual void Execute(VIEW *aView) const override
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:58
void Segment(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint, double aWidth)
virtual void DrawArc(const VECTOR2D &aCenterPoint, double aRadius, double aStartAngle, double aEndAngle)
Draw an arc.
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...
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)
void SetMaximum()
Definition: box2.h:71
general purpose overlay
void SetStrokeColor(const COLOR4D &aColor)
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. ...
virtual void Execute(VIEW *aView) const override
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
virtual void Execute(VIEW *aView) const override
Board layer functions and definitions.
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
VECTOR2I A
Definition: seg.h:46
COMMAND_SET_COLOR(bool aIsStroke, const COLOR4D &aColor)
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:47