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 GERBVIEW_RENDER_SETTINGSGetSettings () override
 Return a pointer to current settings that are going to be used when drawing items. More...
 
virtual bool Draw (const VIEW_ITEM *aItem, int aLayer) override
 Takes an instance of VIEW_ITEM and passes it to a function that knows how to draw the item. More...
 
void SetGAL (GAL *aGal)
 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...
 

Detailed Description

GERBVIEW_PAINTER Contains methods for drawing GerbView-specific items.

Definition at line 171 of file gerbview_painter.h.

Constructor & Destructor Documentation

◆ GERBVIEW_PAINTER()

GERBVIEW_PAINTER::GERBVIEW_PAINTER ( GAL aGal)

Definition at line 161 of file gerbview_painter.cpp.

161  :
162  PAINTER( aGal )
163 {
164 }
PAINTER(GAL *aGal)
Initialize this object for painting on any of the polymorphic GRAPHICS_ABSTRACTION_LAYER* derivatives...
Definition: painter.cpp:32

Member Function Documentation

◆ Draw()

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

Takes an instance of VIEW_ITEM and passes it to a function that knows 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 180 of file gerbview_painter.cpp.

181 {
182  const EDA_ITEM* item = dynamic_cast<const EDA_ITEM*>( aItem );
183 
184  if( !item )
185  return false;
186 
187  // the "cast" applied in here clarifies which overloaded draw() is called
188  switch( item->Type() )
189  {
190  case GERBER_DRAW_ITEM_T:
191  draw( static_cast<GERBER_DRAW_ITEM*>( const_cast<EDA_ITEM*>( item ) ), aLayer );
192  break;
193 
194  default:
195  // Painter does not know how to draw the object
196  return false;
197  }
198 
199  return true;
200 }
void draw(GERBER_DRAW_ITEM *aVia, int aLayer)
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:150
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:163

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 205 of file gerbview_painter.cpp.

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

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, D_CODE::m_Shape, GERBER_DRAW_ITEM::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::SetFontUnderlined(), 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 579 of file gerbview_painter.cpp.

580 {
581  D_CODE* code = aParent->GetDcodeDescr();
582  APERTURE_MACRO* macro = code->GetMacro();
583 
584  SHAPE_POLY_SET* macroShape = macro->GetApertureMacroShape( aParent, aParent->m_Start );
585 
588 
589  if( !aFilled )
590  {
591  for( int i = 0; i < macroShape->OutlineCount(); i++ )
592  m_gal->DrawPolyline( macroShape->COutline( i ) );
593  }
594  else
595  m_gal->DrawPolygon( *macroShape );
596 }
GERBVIEW_RENDER_SETTINGS m_gerbviewSettings
virtual void DrawPolyline(const std::deque< VECTOR2D > &aPointList)
Draw a polyline.
D_CODE * GetDcodeDescr() const
Return the GetDcodeDescr of this object, or NULL.
int OutlineCount() const
Return the number of vertices in a given outline/hole.
GAL * m_gal
Instance of graphic abstraction layer that gives an interface to call commands used to draw (eg.
Definition: painter.h:101
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.
Represent a set of closed polygons.
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:162

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 461 of file gerbview_painter.cpp.

462 {
463  D_CODE* code = aItem->GetDcodeDescr();
464 
465  wxASSERT_MSG( code, "drawFlashedShape: Item has no D_CODE!" );
466 
467  if( !code )
468  return;
469 
470  m_gal->SetIsFill( aFilled );
471  m_gal->SetIsStroke( !aFilled );
473 
474  switch( aItem->m_Shape )
475  {
476  case GBR_SPOT_CIRCLE:
477  {
478  int radius = code->m_Size.x >> 1;
479  VECTOR2D start( aItem->GetABPosition( aItem->m_Start ) );
480 
481  if( !aFilled || code->m_DrillShape == APT_DEF_NO_HOLE )
482  {
483  m_gal->DrawCircle( start, radius );
484  }
485  else // rectangular hole
486  {
487  if( code->m_Polygon.OutlineCount() == 0 )
488  code->ConvertShapeToPolygon();
489 
490  drawPolygon( aItem, code->m_Polygon, aFilled, true );
491  }
492 
493  break;
494  }
495 
496  case GBR_SPOT_RECT:
497  {
498  wxPoint codeStart;
499  wxPoint aShapePos = aItem->m_Start;
500  codeStart.x = aShapePos.x - code->m_Size.x / 2;
501  codeStart.y = aShapePos.y - code->m_Size.y / 2;
502  wxPoint codeEnd = codeStart + code->m_Size;
503  codeStart = aItem->GetABPosition( codeStart );
504  codeEnd = aItem->GetABPosition( codeEnd );
505 
506  if( !aFilled || code->m_DrillShape == APT_DEF_NO_HOLE )
507  {
508  m_gal->DrawRectangle( VECTOR2D( codeStart ), VECTOR2D( codeEnd ) );
509  }
510  else
511  {
512  if( code->m_Polygon.OutlineCount() == 0 )
513  code->ConvertShapeToPolygon();
514 
515  drawPolygon( aItem, code->m_Polygon, aFilled, true );
516  }
517  break;
518  }
519 
520  case GBR_SPOT_OVAL:
521  {
522  int radius = 0;
523 
524  wxPoint codeStart = aItem->m_Start;
525  wxPoint codeEnd = aItem->m_Start;
526 
527  if( code->m_Size.x > code->m_Size.y ) // horizontal oval
528  {
529  int delta = (code->m_Size.x - code->m_Size.y) / 2;
530  codeStart.x -= delta;
531  codeEnd.x += delta;
532  radius = code->m_Size.y;
533  }
534  else // horizontal oval
535  {
536  int delta = (code->m_Size.y - code->m_Size.x) / 2;
537  codeStart.y -= delta;
538  codeEnd.y += delta;
539  radius = code->m_Size.x;
540  }
541 
542  codeStart = aItem->GetABPosition( codeStart );
543  codeEnd = aItem->GetABPosition( codeEnd );
544 
545  if( !aFilled || code->m_DrillShape == APT_DEF_NO_HOLE )
546  {
547  m_gal->DrawSegment( codeStart, codeEnd, radius );
548  }
549  else
550  {
551  if( code->m_Polygon.OutlineCount() == 0 )
552  code->ConvertShapeToPolygon();
553 
554  drawPolygon( aItem, code->m_Polygon, aFilled, true );
555  }
556  break;
557  }
558 
559  case GBR_SPOT_POLY:
560  {
561  if( code->m_Polygon.OutlineCount() == 0 )
562  code->ConvertShapeToPolygon();
563 
564  drawPolygon( aItem, code->m_Polygon, aFilled, true );
565  break;
566  }
567 
568  case GBR_SPOT_MACRO:
569  drawApertureMacro( aItem, aFilled );
570  break;
571 
572  default:
573  wxASSERT_MSG( false, wxT( "Unknown Gerber flashed shape!" ) );
574  break;
575  }
576 }
GERBVIEW_RENDER_SETTINGS m_gerbviewSettings
virtual void DrawRectangle(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a rectangle.
D_CODE * GetDcodeDescr() const
Return the GetDcodeDescr of this object, or NULL.
int OutlineCount() const
Return the number of vertices in a given outline/hole.
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:101
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
Return 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:622
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:300
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(), and KIGFX::GAL::SetLineWidth().

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 433 of file gerbview_painter.cpp.

435 {
436  wxASSERT( aPolygon.OutlineCount() == 1 );
437 
438  if( aPolygon.OutlineCount() == 0 )
439  return;
440 
441  SHAPE_POLY_SET poly;
442  poly.NewOutline();
443  const std::vector<VECTOR2I> pts = aPolygon.COutline( 0 ).CPoints();
444  VECTOR2I offset = aShift ? VECTOR2I( aParent->m_Start ) : VECTOR2I( 0, 0 );
445 
446  for( auto& pt : pts )
447  poly.Append( aParent->GetABPosition( pt + offset ) );
448 
451 
452  if( !aFilled )
453  {
454  m_gal->DrawPolyline( poly.COutline( 0 ) );
455  }
456  else
457  m_gal->DrawPolygon( poly );
458 }
GERBVIEW_RENDER_SETTINGS m_gerbviewSettings
virtual void DrawPolyline(const std::deque< VECTOR2D > &aPointList)
Draw a polyline.
int OutlineCount() const
Return the number of vertices in a given outline/hole.
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
GAL * m_gal
Instance of graphic abstraction layer that gives an interface to call commands used to draw (eg.
Definition: painter.h:101
virtual void SetLineWidth(float aLineWidth)
Set the line width.
wxPoint GetABPosition(const wxPoint &aXYPosition) const
Return the image position of aPosition for this object.
const std::vector< VECTOR2I > & CPoints() const
Represent a set of closed polygons.
int NewOutline()
Creates a new hole in a given outline.
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)
Add a new vertex to the contour indexed by aOutline and aHole (defaults to the outline of the last po...

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 168 of file gerbview_painter.cpp.

169 {
170  // if items have 0 thickness, draw them with the outline
171  // width, otherwise respect the set value (which, no matter
172  // how small will produce something)
173  if( aActualThickness == 0 )
175 
176  return aActualThickness;
177 }
GERBVIEW_RENDER_SETTINGS m_gerbviewSettings

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

◆ GetSettings()

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

Return a pointer to current settings that are going to be used when drawing items.

Returns
Current rendering settings.

Implements KIGFX::PAINTER.

Definition at line 177 of file gerbview_painter.h.

178  {
179  return &m_gerbviewSettings;
180  }
GERBVIEW_RENDER_SETTINGS m_gerbviewSettings

References m_gerbviewSettings.

Referenced by draw().

◆ SetGAL()

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

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

Parameters
aGalis the new GAL instance.

Definition at line 75 of file painter.h.

76  {
77  m_gal = aGal;
78  }
GAL * m_gal
Instance of graphic abstraction layer that gives an interface to call commands used to draw (eg.
Definition: painter.h:101

References KIGFX::PAINTER::m_gal.

Member Data Documentation

◆ m_gal

◆ m_gerbviewSettings

GERBVIEW_RENDER_SETTINGS KIGFX::GERBVIEW_PAINTER::m_gerbviewSettings
protected

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