KiCad PCB EDA Suite
KIGFX::GERBVIEW_PAINTER Class Reference

GERBVIEW_PAINTER Contains methods for drawing GerbView-specific items. More...

#include <gerbview_painter.h>

Inheritance diagram for KIGFX::GERBVIEW_PAINTER:
KIGFX::PAINTER

Public Member Functions

 GERBVIEW_PAINTER (GAL *aGal)
 
virtual void ApplySettings (const RENDER_SETTINGS *aSettings) override
 Function ApplySettings Loads colors and display modes settings that are going to be used when drawing items. More...
 
virtual GERBVIEW_RENDER_SETTINGSGetSettings () override
 
virtual bool Draw (const VIEW_ITEM *aItem, int aLayer) override
 Function Draw Takes an instance of VIEW_ITEM and passes it to a function that know how to draw the item. More...
 
void SetGAL (GAL *aGal)
 Function SetGAL Changes Graphics Abstraction Layer used for drawing items for a new one. More...
 

Protected Member Functions

void draw (GERBER_DRAW_ITEM *aVia, int aLayer)
 
void drawPolygon (GERBER_DRAW_ITEM *aParent, const SHAPE_POLY_SET &aPolygon, bool aFilled, bool aShift=false)
 Helper routine to draw a polygon. More...
 
void drawFlashedShape (GERBER_DRAW_ITEM *aItem, bool aFilled)
 Helper to draw a flashed shape (aka spot) More...
 
void drawApertureMacro (GERBER_DRAW_ITEM *aParent, bool aFilled)
 Helper to draw an aperture macro shape. More...
 
int getLineThickness (int aActualThickness) const
 Function getLineThickness() Get the thickness to draw for a line (e.g. More...
 

Protected Attributes

GERBVIEW_RENDER_SETTINGS m_gerbviewSettings
 
GALm_gal
 Instance of graphic abstraction layer that gives an interface to call commands used to draw (eg. More...
 
COLOR4D m_brightenedColor
 Color of brightened item frame. More...
 

Detailed Description

GERBVIEW_PAINTER Contains methods for drawing GerbView-specific items.

Definition at line 167 of file gerbview_painter.h.

Constructor & Destructor Documentation

◆ GERBVIEW_PAINTER()

GERBVIEW_PAINTER::GERBVIEW_PAINTER ( GAL aGal)

Definition at line 155 of file gerbview_painter.cpp.

155  :
156  PAINTER( aGal )
157 {
158 }
PAINTER(GAL *aGal)
Constructor PAINTER( GAL* ) initializes this object for painting on any of the polymorphic GRAPHICS_A...
Definition: painter.cpp:32

Member Function Documentation

◆ ApplySettings()

virtual void KIGFX::GERBVIEW_PAINTER::ApplySettings ( const RENDER_SETTINGS aSettings)
inlineoverridevirtual

Function ApplySettings Loads colors and display modes settings that are going to be used when drawing items.

Parameters
aSettingsare settings to be applied.

Implements KIGFX::PAINTER.

Definition at line 173 of file gerbview_painter.h.

174  {
175  m_gerbviewSettings = *static_cast<const GERBVIEW_RENDER_SETTINGS*>( aSettings );
176  }
GERBVIEW_RENDER_SETTINGS m_gerbviewSettings

References m_gerbviewSettings.

◆ Draw()

bool GERBVIEW_PAINTER::Draw ( const VIEW_ITEM aItem,
int  aLayer 
)
overridevirtual

Function Draw Takes an instance of VIEW_ITEM and passes it to a function that know how to draw the item.

Parameters
aItemis an item to be drawn.
aLayertells which layer is currently rendered so that draw functions may know what to draw (eg. for pads there are separate layers for holes, because they have other dimensions then the pad itself.

Implements KIGFX::PAINTER.

Definition at line 174 of file gerbview_painter.cpp.

175 {
176  const EDA_ITEM* item = static_cast<const EDA_ITEM*>( aItem );
177 
178  // the "cast" applied in here clarifies which overloaded draw() is called
179  switch( item->Type() )
180  {
181  case GERBER_DRAW_ITEM_T:
182  draw( static_cast<GERBER_DRAW_ITEM*>( const_cast<EDA_ITEM*>( item ) ), aLayer );
183  break;
184 
185  default:
186  // Painter does not know how to draw the object
187  return false;
188  }
189 
190  return true;
191 }
void draw(GERBER_DRAW_ITEM *aVia, int aLayer)
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:159
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193

References draw(), GERBER_DRAW_ITEM_T, and EDA_ITEM::Type().

◆ draw()

void GERBVIEW_PAINTER::draw ( GERBER_DRAW_ITEM aVia,
int  aLayer 
)
protected

Definition at line 196 of file gerbview_painter.cpp.

197 {
198  VECTOR2D start( aItem->GetABPosition( aItem->m_Start ) ); // TODO(JE) Getter
199  VECTOR2D end( aItem->GetABPosition( aItem->m_End ) ); // TODO(JE) Getter
200  int width = aItem->m_Size.x; // TODO(JE) Getter
201  bool isFilled = true;
202  COLOR4D color;
203  // TODO(JE) This doesn't actually work properly for ImageNegative
204  bool isNegative = ( aItem->GetLayerPolarity() ^ aItem->m_GerberImageFile->m_ImageNegative );
205 
206  // Draw DCODE overlay text
207  if( IsDCodeLayer( aLayer ) )
208  {
209  wxString codeText;
210  VECTOR2D textPosition;
211  double textSize;
212  double orient;
213 
214  if( !aItem->GetTextD_CodePrms( textSize, textPosition, orient ) )
215  return;
216 
217  color = m_gerbviewSettings.GetColor( aItem, aLayer );
218  codeText.Printf( "D%d", aItem->m_DCode );
219 
220  m_gal->SetIsStroke( true );
221  m_gal->SetIsFill( false );
223  m_gal->SetFillColor( COLOR4D( 0, 0, 0, 0 ) );
224  m_gal->SetLineWidth( textSize/10 );
225  m_gal->SetFontBold( false );
226  m_gal->SetFontItalic( false );
227  m_gal->SetTextMirrored( false );
228  m_gal->SetGlyphSize( VECTOR2D( textSize, textSize) );
231  m_gal->BitmapText( codeText, textPosition, orient );
232 
233  return;
234  }
235 
236  color = m_gerbviewSettings.GetColor( aItem, aLayer );
237 
238  // TODO: Should brightened color be a preference?
239  if( aItem->IsBrightened() )
240  color = COLOR4D( 0.0, 1.0, 0.0, 0.75 );
241 
242  m_gal->SetNegativeDrawMode( isNegative );
245  m_gal->SetIsFill( isFilled );
246  m_gal->SetIsStroke( !isFilled );
247 
248  switch( aItem->m_Shape )
249  {
250  case GBR_POLYGON:
251  {
253  m_gal->SetIsFill( isFilled );
254  m_gal->SetIsStroke( !isFilled );
255 
256  if( isNegative && !isFilled )
257  {
258  m_gal->SetNegativeDrawMode( false );
259  m_gal->SetStrokeColor( GetSettings()->GetColor( aItem, aLayer ) );
260  }
261 
262  if( !isFilled )
264 
265  std::vector<VECTOR2I> pts = aItem->m_Polygon.COutline( 0 ).CPoints();
266 
267  for( auto& pt : pts )
268  pt = aItem->GetABPosition( pt );
269 
270 
271  SHAPE_POLY_SET absolutePolygon;
272  SHAPE_LINE_CHAIN chain( pts );
273  chain.SetClosed( true );
274  absolutePolygon.AddOutline( chain );
275 
276  // Degenerated polygons (having < 3 points) are drawn as lines
277  // to avoid issues in draw polygon functions
278  if( !isFilled || absolutePolygon.COutline( 0 ).PointCount() < 3 )
279  m_gal->DrawPolyline( absolutePolygon.COutline( 0 ) );
280  else
281  {
282  // On Opengl, a not convex filled polygon is usually drawn by using triangles as primitives.
283  // CacheTriangulation() can create basic triangle primitives to draw the polygon solid shape
284  // on Opengl
285  if( m_gal->IsOpenGlEngine() )
286  absolutePolygon.CacheTriangulation();
287 
288  m_gal->DrawPolygon( absolutePolygon );
289  }
290 
291  break;
292  }
293 
294  case GBR_CIRCLE:
295  {
296  isFilled = m_gerbviewSettings.m_lineFill;
297  double radius = GetLineLength( aItem->m_Start, aItem->m_End );
298  m_gal->DrawCircle( start, radius );
299  break;
300  }
301 
302  case GBR_ARC:
303  {
304  isFilled = m_gerbviewSettings.m_lineFill;
305 
306  // These are swapped because wxDC fills arcs counterclockwise and GAL
307  // fills them clockwise.
308  wxPoint arcStart = aItem->m_End;
309  wxPoint arcEnd = aItem->m_Start;
310 
311  // Gerber arcs are 3-point (start, center, end)
312  // GAL needs center, radius, start angle, end angle
313  double radius = GetLineLength( arcStart, aItem->m_ArcCentre );
314  VECTOR2D center = aItem->GetABPosition( aItem->m_ArcCentre );
315  VECTOR2D startVec = VECTOR2D( aItem->GetABPosition( arcStart ) ) - center;
316  VECTOR2D endVec = VECTOR2D( aItem->GetABPosition( arcEnd ) ) - center;
317 
318  m_gal->SetIsFill( isFilled );
319  m_gal->SetIsStroke( !isFilled );
320  m_gal->SetLineWidth( isFilled ? width : m_gerbviewSettings.m_outlineWidth );
321 
322  double startAngle = startVec.Angle();
323  double endAngle = endVec.Angle();
324 
325  // GAL fills in direction of increasing angle, so we have to convert
326  // the angle from the -PI to PI domain of atan2() to ensure that
327  // the arc goes in the right direction
328  if( startAngle > endAngle )
329  endAngle += (2 * M_PI);
330 
331  // In Gerber, 360-degree arcs are stored in the file with start equal to end
332  if( arcStart == arcEnd )
333  {
334  endAngle = startAngle + 2*M_PI;
335  }
336 
337  m_gal->DrawArcSegment( center, radius, startAngle, endAngle, width );
338 
339 #if 0 // Arc Debugging only
340  m_gal->SetIsFill( false );
341  m_gal->SetIsStroke( true );
342  m_gal->SetLineWidth( 5 );
343  m_gal->SetStrokeColor( COLOR4D( 0.1, 0.5, 0.0, 0.5 ) );
344  m_gal->DrawLine( center, aItem->GetABPosition( arcStart ) );
345  m_gal->SetStrokeColor( COLOR4D( 0.6, 0.1, 0.0, 0.5 ) );
346  m_gal->DrawLine( center, aItem->GetABPosition( arcEnd ) );
347 #endif
348 
349 #if 0 // Bbox arc Debugging only
350  m_gal->SetIsFill( false );
351  m_gal->SetIsStroke( true );
352  EDA_RECT box = aItem->GetBoundingBox();
353  m_gal->SetLineWidth( 5 );
354  m_gal->SetStrokeColor( COLOR4D(0.9, 0.9, 0, 0.4) );
355  // box coordinates are already in AB position.
356  m_gal->DrawRectangle( box.GetOrigin(), box.GetEnd() );
357 #endif
358  break;
359  }
360 
361  case GBR_SPOT_CIRCLE:
362  case GBR_SPOT_RECT:
363  case GBR_SPOT_OVAL:
364  case GBR_SPOT_POLY:
365  case GBR_SPOT_MACRO:
366  {
367  isFilled = m_gerbviewSettings.m_spotFill;
368  drawFlashedShape( aItem, isFilled );
369  break;
370  }
371 
372  case GBR_SEGMENT:
373  {
374  /* Plot a line from m_Start to m_End.
375  * Usually, a round pen is used, but some gerber files use a rectangular pen
376  * In fact, any aperture can be used to plot a line.
377  * currently: only a square pen is handled (I believe using a polygon gives a strange plot).
378  */
379  isFilled = m_gerbviewSettings.m_lineFill;
380  m_gal->SetIsFill( isFilled );
381  m_gal->SetIsStroke( !isFilled );
382 
383  if( isNegative && !isFilled )
384  m_gal->SetStrokeColor( GetSettings()->GetColor( aItem, aLayer ) );
385 
386  // TODO(JE) Refactor this to allow const aItem
387  D_CODE* code = aItem->GetDcodeDescr();
388  if( code && code->m_Shape == APT_RECT )
389  {
390  if( aItem->m_Polygon.OutlineCount() == 0 )
391  aItem->ConvertSegmentToPolygon();
392 
393  drawPolygon( aItem, aItem->m_Polygon, isFilled );
394  }
395  else
396  {
397  if( !isFilled )
399 
400  m_gal->DrawSegment( start, end, width );
401  }
402  break;
403  }
404 
405  default:
406  wxASSERT_MSG( false, "GERBER_DRAW_ITEM shape is unknown!" );
407  break;
408  }
409 
410  // Enable for bounding box debugging
411  #if 0
412  const BOX2I& bb = aItem->ViewBBox();
413  m_gal->SetIsStroke( true );
414  m_gal->SetIsFill( true );
415  m_gal->SetLineWidth( 3 );
416  m_gal->SetStrokeColor( COLOR4D(0.9, 0.9, 0, 0.4) );
417  m_gal->SetFillColor( COLOR4D(0.9, 0.9, 0, 0.1) );
418  m_gal->DrawRectangle( bb.GetOrigin(), bb.GetEnd() );
419  #endif
420 }
GERBVIEW_RENDER_SETTINGS m_gerbviewSettings
virtual void SetFillColor(const COLOR4D &aColor)
Set the fill color.
void SetFontItalic(const bool aItalic)
Set italic property of current font.
virtual void DrawPolyline(const std::deque< VECTOR2D > &aPointList)
Draw a polyline.
virtual const COLOR4D & GetColor(const VIEW_ITEM *aItem, int aLayer) const override
Function GetColor Returns the color that should be used to draw the specific VIEW_ITEM on the specifi...
virtual void DrawRectangle(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a rectangle.
bool IsDCodeLayer(int aLayer)
double GetLineLength(const wxPoint &aPointA, const wxPoint &aPointB)
Return the length of a line segment defined by aPointA and aPointB.
Definition: trigo.h:206
const Vec GetEnd() const
Definition: box2.h:195
virtual void BitmapText(const wxString &aText, const VECTOR2D &aPosition, double aRotationAngle)
Draws a text using a bitmap font.
APERTURE_T m_Shape
shape ( Line, rectangle, circle , oval .. )
Definition: dcode.h:95
int color
Definition: DXF_plotter.cpp:61
bool m_lineFill
Flag determining if lines should be drawn with fill.
void drawFlashedShape(GERBER_DRAW_ITEM *aItem, bool aFilled)
Helper to draw a flashed shape (aka spot)
virtual void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a line.
int PointCount() const
Function PointCount()
bool m_spotFill
Flag determining if spots should be drawn with fill.
Definition: dcode.h:52
GAL * m_gal
Instance of graphic abstraction layer that gives an interface to call commands used to draw (eg.
Definition: painter.h:110
virtual void SetLineWidth(float aLineWidth)
Set the line width.
const wxPoint GetEnd() const
Definition: eda_rect.h:116
void SetFontBold(const bool aBold)
Set bold property of current font.
virtual void DrawSegment(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint, double aWidth)
Draw a rounded segment.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
SHAPE_POLY_SET.
const wxPoint GetOrigin() const
Definition: eda_rect.h:114
virtual bool IsOpenGlEngine()
Returns true if the GAL engine is a opengl based type.
void SetTextMirrored(const bool aMirrored)
Set a mirrored property of text.
void SetVerticalJustify(const EDA_TEXT_VJUSTIFY_T aVerticalJustify)
Set the vertical justify for text drawing.
double Angle() const
Function Angle computes the angle of the vector.
Definition: vector2d.h:313
int AddOutline(const SHAPE_LINE_CHAIN &aOutline)
Adds a new outline to the set and returns its index
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
virtual GERBVIEW_RENDER_SETTINGS * GetSettings() override
bool m_polygonFill
Flag determining if polygons should be drawn with fill.
virtual void DrawPolygon(const std::deque< VECTOR2D > &aPointList)
Draw a polygon.
D_CODE holds a gerber DCODE (also called Aperture) definition.
Definition: dcode.h:82
virtual void DrawCircle(const VECTOR2D &aCenterPoint, double aRadius)
Draw a circle using world coordinates.
SHAPE_LINE_CHAIN.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
void drawPolygon(GERBER_DRAW_ITEM *aParent, const SHAPE_POLY_SET &aPolygon, bool aFilled, bool aShift=false)
Helper routine to draw a polygon.
void SetGlyphSize(const VECTOR2D aGlyphSize)
Set the font glyph size.
virtual void DrawArcSegment(const VECTOR2D &aCenterPoint, double aRadius, double aStartAngle, double aEndAngle, double aWidth)
Draw an arc segment.
void SetHorizontalJustify(const EDA_TEXT_HJUSTIFY_T aHorizontalJustify)
Set the horizontal justify for text drawing.
const Vec & GetOrigin() const
Definition: box2.h:193
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
virtual void SetNegativeDrawMode(bool aSetting)
Sets negative draw mode in the renderer.
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:99

References SHAPE_POLY_SET::AddOutline(), VECTOR2< T >::Angle(), APT_RECT, KIGFX::GAL::BitmapText(), SHAPE_POLY_SET::CacheTriangulation(), color, GERBER_DRAW_ITEM::ConvertSegmentToPolygon(), SHAPE_POLY_SET::COutline(), SHAPE_LINE_CHAIN::CPoints(), KIGFX::GAL::DrawArcSegment(), KIGFX::GAL::DrawCircle(), drawFlashedShape(), KIGFX::GAL::DrawLine(), KIGFX::GAL::DrawPolygon(), drawPolygon(), KIGFX::GAL::DrawPolyline(), KIGFX::GAL::DrawRectangle(), KIGFX::GAL::DrawSegment(), GBR_ARC, GBR_CIRCLE, GBR_POLYGON, GBR_SEGMENT, GBR_SPOT_CIRCLE, GBR_SPOT_MACRO, GBR_SPOT_OVAL, GBR_SPOT_POLY, GBR_SPOT_RECT, GERBER_DRAW_ITEM::GetABPosition(), GERBER_DRAW_ITEM::GetBoundingBox(), KIGFX::GERBVIEW_RENDER_SETTINGS::GetColor(), GERBER_DRAW_ITEM::GetDcodeDescr(), EDA_RECT::GetEnd(), BOX2< Vec >::GetEnd(), GERBER_DRAW_ITEM::GetLayerPolarity(), GetLineLength(), EDA_RECT::GetOrigin(), BOX2< Vec >::GetOrigin(), GetSettings(), GERBER_DRAW_ITEM::GetTextD_CodePrms(), GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER, EDA_ITEM::IsBrightened(), IsDCodeLayer(), KIGFX::GAL::IsOpenGlEngine(), GERBER_DRAW_ITEM::m_ArcCentre, GERBER_DRAW_ITEM::m_DCode, GERBER_DRAW_ITEM::m_End, KIGFX::PAINTER::m_gal, GERBER_DRAW_ITEM::m_GerberImageFile, m_gerbviewSettings, GERBER_FILE_IMAGE::m_ImageNegative, KIGFX::GERBVIEW_RENDER_SETTINGS::m_lineFill, KIGFX::RENDER_SETTINGS::m_outlineWidth, GERBER_DRAW_ITEM::m_Polygon, KIGFX::GERBVIEW_RENDER_SETTINGS::m_polygonFill, GERBER_DRAW_ITEM::m_Shape, D_CODE::m_Shape, GERBER_DRAW_ITEM::m_Size, KIGFX::GERBVIEW_RENDER_SETTINGS::m_spotFill, GERBER_DRAW_ITEM::m_Start, SHAPE_POLY_SET::OutlineCount(), SHAPE_LINE_CHAIN::PointCount(), SHAPE_LINE_CHAIN::SetClosed(), KIGFX::GAL::SetFillColor(), KIGFX::GAL::SetFontBold(), KIGFX::GAL::SetFontItalic(), KIGFX::GAL::SetGlyphSize(), KIGFX::GAL::SetHorizontalJustify(), KIGFX::GAL::SetIsFill(), KIGFX::GAL::SetIsStroke(), KIGFX::GAL::SetLineWidth(), KIGFX::GAL::SetNegativeDrawMode(), KIGFX::GAL::SetStrokeColor(), KIGFX::GAL::SetTextMirrored(), KIGFX::GAL::SetVerticalJustify(), and GERBER_DRAW_ITEM::ViewBBox().

Referenced by Draw().

◆ drawApertureMacro()

void GERBVIEW_PAINTER::drawApertureMacro ( GERBER_DRAW_ITEM aParent,
bool  aFilled 
)
protected

Helper to draw an aperture macro shape.

Definition at line 569 of file gerbview_painter.cpp.

570 {
571  D_CODE* code = aParent->GetDcodeDescr();
572  APERTURE_MACRO* macro = code->GetMacro();
573 
574  SHAPE_POLY_SET* macroShape = macro->GetApertureMacroShape( aParent, aParent->m_Start );
575 
578 
579  if( !aFilled )
580  {
581  for( int i = 0; i < macroShape->OutlineCount(); i++ )
582  m_gal->DrawPolyline( macroShape->COutline( i ) );
583  }
584  else
585  m_gal->DrawPolygon( *macroShape );
586 }
GERBVIEW_RENDER_SETTINGS m_gerbviewSettings
virtual void DrawPolyline(const std::deque< VECTOR2D > &aPointList)
Draw a polyline.
D_CODE * GetDcodeDescr() const
Function GetDcodeDescr returns the GetDcodeDescr of this object, or NULL.
int OutlineCount() const
Returns the number of outlines in the set
GAL * m_gal
Instance of graphic abstraction layer that gives an interface to call commands used to draw (eg.
Definition: painter.h:110
virtual void SetLineWidth(float aLineWidth)
Set the line width.
SHAPE_POLY_SET * GetApertureMacroShape(const GERBER_DRAW_ITEM *aParent, wxPoint aShapePos)
Function GetApertureMacroShape Calculate the primitive shape for flashed items.
SHAPE_POLY_SET.
bool m_polygonFill
Flag determining if polygons should be drawn with fill.
virtual void DrawPolygon(const std::deque< VECTOR2D > &aPointList)
Draw a polygon.
D_CODE holds a gerber DCODE (also called Aperture) definition.
Definition: dcode.h:82
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
APERTURE_MACRO * GetMacro() const
Definition: dcode.h:157
Struct APERTURE_MACRO helps support the "aperture macro" defined within standard RS274X.
Definition: am_primitive.h:163

References SHAPE_POLY_SET::COutline(), KIGFX::GAL::DrawPolygon(), KIGFX::GAL::DrawPolyline(), APERTURE_MACRO::GetApertureMacroShape(), GERBER_DRAW_ITEM::GetDcodeDescr(), D_CODE::GetMacro(), KIGFX::PAINTER::m_gal, m_gerbviewSettings, KIGFX::RENDER_SETTINGS::m_outlineWidth, KIGFX::GERBVIEW_RENDER_SETTINGS::m_polygonFill, GERBER_DRAW_ITEM::m_Start, SHAPE_POLY_SET::OutlineCount(), and KIGFX::GAL::SetLineWidth().

Referenced by drawFlashedShape().

◆ drawFlashedShape()

void GERBVIEW_PAINTER::drawFlashedShape ( GERBER_DRAW_ITEM aItem,
bool  aFilled 
)
protected

Helper to draw a flashed shape (aka spot)

Definition at line 451 of file gerbview_painter.cpp.

452 {
453  D_CODE* code = aItem->GetDcodeDescr();
454 
455  wxASSERT_MSG( code, "drawFlashedShape: Item has no D_CODE!" );
456 
457  if( !code )
458  return;
459 
460  m_gal->SetIsFill( aFilled );
461  m_gal->SetIsStroke( !aFilled );
463 
464  switch( aItem->m_Shape )
465  {
466  case GBR_SPOT_CIRCLE:
467  {
468  int radius = code->m_Size.x >> 1;
469  VECTOR2D start( aItem->GetABPosition( aItem->m_Start ) );
470 
471  if( !aFilled || code->m_DrillShape == APT_DEF_NO_HOLE )
472  {
473  m_gal->DrawCircle( start, radius );
474  }
475  else // rectangular hole
476  {
477  if( code->m_Polygon.OutlineCount() == 0 )
478  code->ConvertShapeToPolygon();
479 
480  drawPolygon( aItem, code->m_Polygon, aFilled, true );
481  }
482 
483  break;
484  }
485 
486  case GBR_SPOT_RECT:
487  {
488  wxPoint codeStart;
489  wxPoint aShapePos = aItem->m_Start;
490  codeStart.x = aShapePos.x - code->m_Size.x / 2;
491  codeStart.y = aShapePos.y - code->m_Size.y / 2;
492  wxPoint codeEnd = codeStart + code->m_Size;
493  codeStart = aItem->GetABPosition( codeStart );
494  codeEnd = aItem->GetABPosition( codeEnd );
495 
496  if( !aFilled || code->m_DrillShape == APT_DEF_NO_HOLE )
497  {
498  m_gal->DrawRectangle( VECTOR2D( codeStart ), VECTOR2D( codeEnd ) );
499  }
500  else
501  {
502  if( code->m_Polygon.OutlineCount() == 0 )
503  code->ConvertShapeToPolygon();
504 
505  drawPolygon( aItem, code->m_Polygon, aFilled, true );
506  }
507  break;
508  }
509 
510  case GBR_SPOT_OVAL:
511  {
512  int radius = 0;
513 
514  wxPoint codeStart = aItem->m_Start;
515  wxPoint codeEnd = aItem->m_Start;
516 
517  if( code->m_Size.x > code->m_Size.y ) // horizontal oval
518  {
519  int delta = (code->m_Size.x - code->m_Size.y) / 2;
520  codeStart.x -= delta;
521  codeEnd.x += delta;
522  radius = code->m_Size.y;
523  }
524  else // horizontal oval
525  {
526  int delta = (code->m_Size.y - code->m_Size.x) / 2;
527  codeStart.y -= delta;
528  codeEnd.y += delta;
529  radius = code->m_Size.x;
530  }
531 
532  codeStart = aItem->GetABPosition( codeStart );
533  codeEnd = aItem->GetABPosition( codeEnd );
534 
535  if( !aFilled || code->m_DrillShape == APT_DEF_NO_HOLE )
536  {
537  m_gal->DrawSegment( codeStart, codeEnd, radius );
538  }
539  else
540  {
541  if( code->m_Polygon.OutlineCount() == 0 )
542  code->ConvertShapeToPolygon();
543 
544  drawPolygon( aItem, code->m_Polygon, aFilled, true );
545  }
546  break;
547  }
548 
549  case GBR_SPOT_POLY:
550  {
551  if( code->m_Polygon.OutlineCount() == 0 )
552  code->ConvertShapeToPolygon();
553 
554  drawPolygon( aItem, code->m_Polygon, aFilled, true );
555  break;
556  }
557 
558  case GBR_SPOT_MACRO:
559  drawApertureMacro( aItem, aFilled );
560  break;
561 
562  default:
563  wxASSERT_MSG( false, wxT( "Unknown Gerber flashed shape!" ) );
564  break;
565  }
566 }
GERBVIEW_RENDER_SETTINGS m_gerbviewSettings
virtual void DrawRectangle(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a rectangle.
D_CODE * GetDcodeDescr() const
Function GetDcodeDescr returns the GetDcodeDescr of this object, or NULL.
int OutlineCount() const
Returns the number of outlines in the set
wxSize m_Size
Horizontal and vertical dimensions.
Definition: dcode.h:94
GAL * m_gal
Instance of graphic abstraction layer that gives an interface to call commands used to draw (eg.
Definition: painter.h:110
virtual void SetLineWidth(float aLineWidth)
Set the line width.
void drawApertureMacro(GERBER_DRAW_ITEM *aParent, bool aFilled)
Helper to draw an aperture macro shape.
wxPoint GetABPosition(const wxPoint &aXYPosition) const
Function GetABPosition returns the image position of aPosition for this object.
virtual void DrawSegment(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint, double aWidth)
Draw a rounded segment.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
APERTURE_DEF_HOLETYPE m_DrillShape
shape of the hole (0 = no hole, round = 1, rect = 2) */
Definition: dcode.h:98
D_CODE holds a gerber DCODE (also called Aperture) definition.
Definition: dcode.h:82
virtual void DrawCircle(const VECTOR2D &aCenterPoint, double aRadius)
Draw a circle using world coordinates.
SHAPE_POLY_SET m_Polygon
Definition: dcode.h:107
void drawPolygon(GERBER_DRAW_ITEM *aParent, const SHAPE_POLY_SET &aPolygon, bool aFilled, bool aShift=false)
Helper routine to draw a polygon.
void ConvertShapeToPolygon()
Function ConvertShapeToPolygon convert a shape to an equivalent polygon.
Definition: dcode.cpp:301
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.

References APT_DEF_NO_HOLE, D_CODE::ConvertShapeToPolygon(), drawApertureMacro(), KIGFX::GAL::DrawCircle(), drawPolygon(), KIGFX::GAL::DrawRectangle(), KIGFX::GAL::DrawSegment(), GBR_SPOT_CIRCLE, GBR_SPOT_MACRO, GBR_SPOT_OVAL, GBR_SPOT_POLY, GBR_SPOT_RECT, GERBER_DRAW_ITEM::GetABPosition(), GERBER_DRAW_ITEM::GetDcodeDescr(), D_CODE::m_DrillShape, KIGFX::PAINTER::m_gal, m_gerbviewSettings, KIGFX::RENDER_SETTINGS::m_outlineWidth, D_CODE::m_Polygon, GERBER_DRAW_ITEM::m_Shape, D_CODE::m_Size, GERBER_DRAW_ITEM::m_Start, SHAPE_POLY_SET::OutlineCount(), KIGFX::GAL::SetIsFill(), KIGFX::GAL::SetIsStroke(), KIGFX::GAL::SetLineWidth(), wxPoint::x, and wxPoint::y.

Referenced by draw().

◆ drawPolygon()

void GERBVIEW_PAINTER::drawPolygon ( GERBER_DRAW_ITEM aParent,
const SHAPE_POLY_SET aPolygon,
bool  aFilled,
bool  aShift = false 
)
protected

Helper routine to draw a polygon.

Parameters
aParentPointer to the draw item for AB Position calculation
aPolygonthe polygon to draw
aFilledIf true, draw the polygon as filled, otherwise only outline
aShiftIf true, draw the polygon relative to the parent item position

Definition at line 423 of file gerbview_painter.cpp.

425 {
426  wxASSERT( aPolygon.OutlineCount() == 1 );
427 
428  if( aPolygon.OutlineCount() == 0 )
429  return;
430 
431  SHAPE_POLY_SET poly;
432  poly.NewOutline();
433  const std::vector<VECTOR2I> pts = aPolygon.COutline( 0 ).CPoints();
434  VECTOR2I offset = aShift ? VECTOR2I( aParent->m_Start ) : VECTOR2I( 0, 0 );
435 
436  for( auto& pt : pts )
437  poly.Append( aParent->GetABPosition( pt + offset ) );
438 
441 
442  if( !aFilled )
443  {
444  m_gal->DrawPolyline( poly.COutline( 0 ) );
445  }
446  else
447  m_gal->DrawPolygon( poly );
448 }
GERBVIEW_RENDER_SETTINGS m_gerbviewSettings
virtual void DrawPolyline(const std::deque< VECTOR2D > &aPointList)
Draw a polyline.
int OutlineCount() const
Returns the number of outlines in the set
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
GAL * m_gal
Instance of graphic abstraction layer that gives an interface to call commands used to draw (eg.
Definition: painter.h:110
virtual void SetLineWidth(float aLineWidth)
Set the line width.
wxPoint GetABPosition(const wxPoint &aXYPosition) const
Function GetABPosition returns the image position of aPosition for this object.
const std::vector< VECTOR2I > & CPoints() const
SHAPE_POLY_SET.
int NewOutline()
Creates a new empty polygon in the set and returns its index
bool m_polygonFill
Flag determining if polygons should be drawn with fill.
virtual void DrawPolygon(const std::deque< VECTOR2D > &aPointList)
Draw a polygon.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline)

References SHAPE_POLY_SET::Append(), SHAPE_POLY_SET::COutline(), SHAPE_LINE_CHAIN::CPoints(), KIGFX::GAL::DrawPolygon(), KIGFX::GAL::DrawPolyline(), GERBER_DRAW_ITEM::GetABPosition(), KIGFX::PAINTER::m_gal, m_gerbviewSettings, KIGFX::RENDER_SETTINGS::m_outlineWidth, KIGFX::GERBVIEW_RENDER_SETTINGS::m_polygonFill, GERBER_DRAW_ITEM::m_Start, SHAPE_POLY_SET::NewOutline(), SHAPE_POLY_SET::OutlineCount(), and KIGFX::GAL::SetLineWidth().

Referenced by draw(), and drawFlashedShape().

◆ getLineThickness()

int GERBVIEW_PAINTER::getLineThickness ( int  aActualThickness) const
protected

Function getLineThickness() Get the thickness to draw for a line (e.g.

0 thickness lines get a minimum value).

Parameters
aActualThicknessline own thickness
Returns
the thickness to draw

Definition at line 162 of file gerbview_painter.cpp.

163 {
164  // if items have 0 thickness, draw them with the outline
165  // width, otherwise respect the set value (which, no matter
166  // how small will produce something)
167  if( aActualThickness == 0 )
169 
170  return aActualThickness;
171 }
GERBVIEW_RENDER_SETTINGS m_gerbviewSettings

References m_gerbviewSettings, and KIGFX::RENDER_SETTINGS::m_outlineWidth.

◆ GetSettings()

virtual GERBVIEW_RENDER_SETTINGS* KIGFX::GERBVIEW_PAINTER::GetSettings ( )
inlineoverridevirtual

Implements KIGFX::PAINTER.

Definition at line 179 of file gerbview_painter.h.

180  {
181  return &m_gerbviewSettings;
182  }
GERBVIEW_RENDER_SETTINGS m_gerbviewSettings

References m_gerbviewSettings.

Referenced by draw().

◆ SetGAL()

void KIGFX::PAINTER::SetGAL ( GAL aGal)
inlineinherited

Function SetGAL Changes Graphics Abstraction Layer used for drawing items for a new one.

Parameters
aGalis the new GAL instance.

Definition at line 78 of file painter.h.

79  {
80  m_gal = aGal;
81  }
GAL * m_gal
Instance of graphic abstraction layer that gives an interface to call commands used to draw (eg.
Definition: painter.h:110

References KIGFX::PAINTER::m_gal.

Member Data Documentation

◆ m_brightenedColor

COLOR4D KIGFX::PAINTER::m_brightenedColor
protectedinherited

Color of brightened item frame.

Definition at line 113 of file painter.h.

◆ m_gal

◆ m_gerbviewSettings

GERBVIEW_RENDER_SETTINGS KIGFX::GERBVIEW_PAINTER::m_gerbviewSettings
protected

The documentation for this class was generated from the following files: