KiCad PCB EDA Suite
KIGFX::PCB_PAINTER Class Reference

Contains methods for drawing PCB-specific items. More...

#include <pcb_painter.h>

Inheritance diagram for KIGFX::PCB_PAINTER:
KIGFX::PAINTER KIGFX::PCB_PRINT_PAINTER

Public Member Functions

 PCB_PAINTER (GAL *aGal)
 
virtual PCB_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 (const TRACK *aTrack, int aLayer)
 
void draw (const ARC *aArc, int aLayer)
 
void draw (const VIA *aVia, int aLayer)
 
void draw (const PAD *aPad, int aLayer)
 
void draw (const PCB_SHAPE *aSegment, int aLayer)
 
void draw (const PCB_TEXT *aText, int aLayer)
 
void draw (const FP_TEXT *aText, int aLayer)
 
void draw (const FOOTPRINT *aFootprint, int aLayer)
 
void draw (const PCB_GROUP *aGroup, int aLayer)
 
void draw (const ZONE *aZone, int aLayer)
 
void draw (const DIMENSION_BASE *aDimension, int aLayer)
 
void draw (const PCB_TARGET *aTarget)
 
void draw (const PCB_MARKER *aMarker, int aLayer)
 
int getLineThickness (int aActualThickness) const
 Get the thickness to draw for a line (e.g. More...
 
virtual int getDrillShape (const PAD *aPad) const
 Return drill shape of a pad. More...
 
virtual VECTOR2D getDrillSize (const PAD *aPad) const
 Return drill size for a pad (internal units). More...
 
virtual int getDrillSize (const VIA *aVia) const
 Return drill diameter for a via (internal units). More...
 

Protected Attributes

PCB_RENDER_SETTINGS m_pcbSettings
 
GALm_gal
 Instance of graphic abstraction layer that gives an interface to call commands used to draw (eg. More...
 

Detailed Description

Contains methods for drawing PCB-specific items.

Definition at line 241 of file pcb_painter.h.

Constructor & Destructor Documentation

◆ PCB_PAINTER()

PCB_PAINTER::PCB_PAINTER ( GAL aGal)

Definition at line 417 of file pcb_painter.cpp.

417  :
418  PAINTER( aGal )
419 {
420 }
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 PCB_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 453 of file pcb_painter.cpp.

454 {
455  const EDA_ITEM* item = dynamic_cast<const EDA_ITEM*>( aItem );
456 
457  if( !item )
458  return false;
459 
460  if( ADVANCED_CFG::GetCfg().m_DrawBoundingBoxes )
461  {
462  // Show bounding boxes of painted objects for debugging.
463  EDA_RECT box = item->GetBoundingBox();
464  m_gal->SetIsFill( false );
465  m_gal->SetIsStroke( true );
466  m_gal->SetStrokeColor( item->IsSelected() ? COLOR4D( 1.0, 0.2, 0.2, 1 ) :
467  COLOR4D( 0.2, 0.2, 0.2, 1 ) );
468  m_gal->SetLineWidth( Mils2iu( 3 ) );
469  m_gal->DrawRectangle( box.GetOrigin(), box.GetEnd() );
470  }
471 
472  // the "cast" applied in here clarifies which overloaded draw() is called
473  switch( item->Type() )
474  {
475  case PCB_TRACE_T:
476  draw( static_cast<const TRACK*>( item ), aLayer );
477  break;
478 
479  case PCB_ARC_T:
480  draw( static_cast<const ARC*>( item ), aLayer );
481  break;
482 
483  case PCB_VIA_T:
484  draw( static_cast<const VIA*>( item ), aLayer );
485  break;
486 
487  case PCB_PAD_T:
488  draw( static_cast<const PAD*>( item ), aLayer );
489  break;
490 
491  case PCB_SHAPE_T:
492  case PCB_FP_SHAPE_T:
493  draw( static_cast<const PCB_SHAPE*>( item ), aLayer );
494  break;
495 
496  case PCB_TEXT_T:
497  draw( static_cast<const PCB_TEXT*>( item ), aLayer );
498  break;
499 
500  case PCB_FP_TEXT_T:
501  draw( static_cast<const FP_TEXT*>( item ), aLayer );
502  break;
503 
504  case PCB_FOOTPRINT_T:
505  draw( static_cast<const FOOTPRINT*>( item ), aLayer );
506  break;
507 
508  case PCB_GROUP_T:
509  draw( static_cast<const PCB_GROUP*>( item ), aLayer );
510  break;
511 
512  case PCB_ZONE_T:
513  draw( static_cast<const ZONE*>( item ), aLayer );
514  break;
515 
516  case PCB_FP_ZONE_T:
517  draw( static_cast<const ZONE*>( item ), aLayer );
518  break;
519 
520  case PCB_DIM_ALIGNED_T:
521  case PCB_DIM_CENTER_T:
523  case PCB_DIM_LEADER_T:
524  draw( static_cast<const DIMENSION_BASE*>( item ), aLayer );
525  break;
526 
527  case PCB_TARGET_T:
528  draw( static_cast<const PCB_TARGET*>( item ) );
529  break;
530 
531  case PCB_MARKER_T:
532  draw( static_cast<const PCB_MARKER*>( item ), aLayer );
533  break;
534 
535  default:
536  // Painter does not know how to draw the object
537  return false;
538  }
539 
540  return true;
541 }
virtual void DrawRectangle(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a rectangle.
class ALIGNED_DIMENSION, a linear dimension (graphic item)
Definition: typeinfo.h:100
class LEADER, a leader dimension (graphic item)
Definition: typeinfo.h:101
class FP_TEXT, text in a footprint
Definition: typeinfo.h:92
bool IsSelected() const
Definition: eda_item.h:173
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:108
class CENTER_DIMENSION, a center point marking (graphic item)
Definition: typeinfo.h:102
class PCB_TEXT, text on a layer
Definition: typeinfo.h:91
class ARC, an arc track segment on a copper layer
Definition: typeinfo.h:97
class FP_SHAPE, a footprint edge
Definition: typeinfo.h:93
class PAD, a pad in a footprint
Definition: typeinfo.h:89
GAL * m_gal
Instance of graphic abstraction layer that gives an interface to call commands used to draw (eg.
Definition: painter.h:101
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
virtual void SetLineWidth(float aLineWidth)
Set the line width.
const wxPoint GetEnd() const
Definition: eda_rect.h:108
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
const wxPoint GetOrigin() const
Definition: eda_rect.h:106
class ZONE, a copper pour area
Definition: typeinfo.h:105
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:104
class FOOTPRINT, a footprint
Definition: typeinfo.h:88
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
class MARKER_PCB, a marker used to show something
Definition: typeinfo.h:98
class ZONE, managed by a footprint
Definition: typeinfo.h:94
Handle the component boundary box.
Definition: eda_rect.h:42
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:150
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
class ORTHOGONAL_DIMENSION, a linear dimension constrained to x/y
Definition: typeinfo.h:103
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
virtual const EDA_RECT GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition: eda_item.cpp:73
void draw(const TRACK *aTrack, int aLayer)
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
class PCB_SHAPE, a segment not on copper layers
Definition: typeinfo.h:90
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:163
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98

References draw(), KIGFX::GAL::DrawRectangle(), EDA_ITEM::GetBoundingBox(), ADVANCED_CFG::GetCfg(), EDA_RECT::GetEnd(), EDA_RECT::GetOrigin(), EDA_ITEM::IsSelected(), KIGFX::PAINTER::m_gal, PCB_ARC_T, PCB_DIM_ALIGNED_T, PCB_DIM_CENTER_T, PCB_DIM_LEADER_T, PCB_DIM_ORTHOGONAL_T, PCB_FOOTPRINT_T, PCB_FP_SHAPE_T, PCB_FP_TEXT_T, PCB_FP_ZONE_T, PCB_GROUP_T, PCB_MARKER_T, PCB_PAD_T, PCB_SHAPE_T, PCB_TARGET_T, PCB_TEXT_T, PCB_TRACE_T, PCB_VIA_T, PCB_ZONE_T, KIGFX::GAL::SetIsFill(), KIGFX::GAL::SetIsStroke(), KIGFX::GAL::SetLineWidth(), KIGFX::GAL::SetStrokeColor(), and EDA_ITEM::Type().

◆ draw() [1/13]

void PCB_PAINTER::draw ( const TRACK aTrack,
int  aLayer 
)
protected

Definition at line 544 of file pcb_painter.cpp.

545 {
546  VECTOR2D start( aTrack->GetStart() );
547  VECTOR2D end( aTrack->GetEnd() );
548  int width = aTrack->GetWidth();
549  COLOR4D color = m_pcbSettings.GetColor( aTrack, aLayer );
550 
551  if( IsNetnameLayer( aLayer ) )
552  {
554  return;
555 
556  if( aTrack->GetNetCode() <= NETINFO_LIST::UNCONNECTED )
557  return;
558 
559  VECTOR2D line = ( end - start );
560  double length = line.EuclideanNorm();
561 
562  // Check if the track is long enough to have a netname displayed
563  if( length < 10 * width )
564  return;
565 
566  const wxString& netName = UnescapeString( aTrack->GetShortNetname() );
567  double textSize = width;
568  double penWidth = width / 12.0;
569  VECTOR2D textPosition = start + line / 2.0; // center of the track
570  double textOrientation;
571 
572  if( end.y == start.y ) // horizontal
573  {
574  textOrientation = 0;
575  textPosition.y += penWidth;
576  }
577  else if( end.x == start.x ) // vertical
578  {
579  textOrientation = M_PI / 2;
580  textPosition.x += penWidth;
581  }
582  else
583  {
584  textOrientation = -atan( line.y / line.x );
585  textPosition.x += penWidth / 1.4;
586  textPosition.y += penWidth / 1.4;
587  }
588 
589 
590  m_gal->SetIsStroke( true );
591  m_gal->SetIsFill( false );
593  m_gal->SetLineWidth( penWidth );
594  m_gal->SetFontBold( false );
595  m_gal->SetFontItalic( false );
596  m_gal->SetFontUnderlined( false );
597  m_gal->SetTextMirrored( false );
598  m_gal->SetGlyphSize( VECTOR2D( textSize * 0.55, textSize * 0.55 ) );
601  m_gal->BitmapText( netName, textPosition, textOrientation );
602 
603  return;
604  }
605  else if( IsCopperLayer( aLayer ) )
606  {
607  // Draw a regular track
608  bool outline_mode = m_pcbSettings.m_sketchMode[LAYER_TRACKS];
611  m_gal->SetIsStroke( outline_mode );
612  m_gal->SetIsFill( not outline_mode );
614 
615  m_gal->DrawSegment( start, end, width );
616  }
617 
618  // Clearance lines
619  constexpr int clearanceFlags = PCB_RENDER_SETTINGS::CL_EXISTING
621 
622  if( ( m_pcbSettings.m_clearanceDisplayFlags & clearanceFlags ) == clearanceFlags )
623  {
624  int clearance = aTrack->GetOwnClearance( m_pcbSettings.GetActiveLayer() );
625 
627  m_gal->SetIsFill( false );
628  m_gal->SetIsStroke( true );
630  m_gal->DrawSegment( start, end, width + clearance * 2 );
631  }
632 }
virtual void SetFillColor(const COLOR4D &aColor)
Set the fill color.
virtual void BitmapText(const wxString &aText, const VECTOR2D &aPosition, double aRotationAngle)
Draw a text using a bitmap font.
const wxPoint & GetStart() const
Definition: track.h:116
bool m_sketchMode[GAL_LAYER_ID_END]
Definition: pcb_painter.h:196
int color
Definition: DXF_plotter.cpp:60
Define a general 2D-vector/point.
Definition: vector2d.h:61
PCB_RENDER_SETTINGS m_pcbSettings
Definition: pcb_painter.h:295
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 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.
wxString GetShortNetname() const
VECTOR2< double > VECTOR2D
Definition: vector2d.h:622
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
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.
void SetFontItalic(bool aItalic)
Set italic property of current font.
int m_clearanceDisplayFlags
How to display nets and netclasses with color overrides.
Definition: pcb_painter.h:216
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
void SetGlyphSize(const VECTOR2D aSize)
Set the font glyph size.
int GetWidth() const
Definition: track.h:110
void SetFontUnderlined(bool aUnderlined)
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:151
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...
PCB_LAYER_ID GetActiveLayer() const
virtual int GetOwnClearance(PCB_LAYER_ID aLayer, wxString *aSource=nullptr) const
Return an item's "own" clearance in internal units.
const wxPoint & GetEnd() const
Definition: track.h:113
bool IsCopperLayer(LAYER_NUM aLayerId)
Tests whether a layer is a copper layer.
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
Definition: vector2d.h:293
void SetHorizontalJustify(const EDA_TEXT_HJUSTIFY_T aHorizontalJustify)
Set the horizontal justify for text drawing.
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
static const int UNCONNECTED
Constant that forces initialization of a netinfo item to the NETINFO_ITEM ORPHANED (typically -1) whe...
Definition: netinfo.h:365
bool IsNetnameLayer(LAYER_NUM aLayer)
Test whether a layer is a netname layer.
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98

References KIGFX::GAL::BitmapText(), KIGFX::PCB_RENDER_SETTINGS::CL_EXISTING, KIGFX::PCB_RENDER_SETTINGS::CL_TRACKS, color, KIGFX::GAL::DrawSegment(), VECTOR2< T >::EuclideanNorm(), KIGFX::RENDER_SETTINGS::GetActiveLayer(), KIGFX::PCB_RENDER_SETTINGS::GetColor(), TRACK::GetEnd(), BOARD_CONNECTED_ITEM::GetNetCode(), BOARD_CONNECTED_ITEM::GetOwnClearance(), BOARD_CONNECTED_ITEM::GetShortNetname(), TRACK::GetStart(), TRACK::GetWidth(), GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER, IsCopperLayer(), IsNetnameLayer(), LAYER_TRACKS, KIGFX::PCB_RENDER_SETTINGS::m_clearanceDisplayFlags, KIGFX::PAINTER::m_gal, KIGFX::PCB_RENDER_SETTINGS::m_netNamesOnTracks, KIGFX::RENDER_SETTINGS::m_outlineWidth, m_pcbSettings, KIGFX::PCB_RENDER_SETTINGS::m_sketchMode, 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::SetStrokeColor(), KIGFX::GAL::SetTextMirrored(), KIGFX::GAL::SetVerticalJustify(), NETINFO_LIST::UNCONNECTED, UnescapeString(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by Draw().

◆ draw() [2/13]

void PCB_PAINTER::draw ( const ARC aArc,
int  aLayer 
)
protected

Definition at line 635 of file pcb_painter.cpp.

636 {
637  VECTOR2D center( aArc->GetCenter() );
638  int width = aArc->GetWidth();
639  COLOR4D color = m_pcbSettings.GetColor( aArc, aLayer );
640  double radius = aArc->GetRadius();
641  double start_angle = DECIDEG2RAD( aArc->GetArcAngleStart() );
642  double angle = DECIDEG2RAD( aArc->GetAngle() );
643 
644  if( IsNetnameLayer( aLayer ) )
645  {
646  // Ummm, yeah. Anyone fancy implementing text on a path?
647  return;
648  }
649  else if( IsCopperLayer( aLayer ) )
650  {
651  // Draw a regular track
652  bool outline_mode = m_pcbSettings.m_sketchMode[LAYER_TRACKS];
655  m_gal->SetIsStroke( outline_mode );
656  m_gal->SetIsFill( not outline_mode );
658 
659  m_gal->DrawArcSegment( center, radius, start_angle, start_angle + angle, width );
660  }
661 
662  // Clearance lines
663  constexpr int clearanceFlags = PCB_RENDER_SETTINGS::CL_EXISTING
665 
666  if( ( m_pcbSettings.m_clearanceDisplayFlags & clearanceFlags ) == clearanceFlags )
667  {
668  int clearance = aArc->GetOwnClearance( m_pcbSettings.GetActiveLayer() );
669 
671  m_gal->SetIsFill( false );
672  m_gal->SetIsStroke( true );
674 
675  m_gal->DrawArcSegment( center, radius, start_angle, start_angle + angle,
676  width + clearance * 2 );
677  }
678 }
virtual void SetFillColor(const COLOR4D &aColor)
Set the fill color.
virtual wxPoint GetCenter() const override
This defaults to the center of the bounding box if not overridden.
Definition: track.h:301
bool m_sketchMode[GAL_LAYER_ID_END]
Definition: pcb_painter.h:196
int color
Definition: DXF_plotter.cpp:60
Define a general 2D-vector/point.
Definition: vector2d.h:61
PCB_RENDER_SETTINGS m_pcbSettings
Definition: pcb_painter.h:295
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.
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
double GetRadius() const
Definition: track.cpp:944
int m_clearanceDisplayFlags
How to display nets and netclasses with color overrides.
Definition: pcb_painter.h:216
double GetAngle() const
Definition: track.cpp:950
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
int GetWidth() const
Definition: track.h:110
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
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...
double DECIDEG2RAD(double deg)
Definition: trigo.h:235
PCB_LAYER_ID GetActiveLayer() const
virtual int GetOwnClearance(PCB_LAYER_ID aLayer, wxString *aSource=nullptr) const
Return an item's "own" clearance in internal units.
bool IsCopperLayer(LAYER_NUM aLayerId)
Tests whether a layer is a copper layer.
virtual void DrawArcSegment(const VECTOR2D &aCenterPoint, double aRadius, double aStartAngle, double aEndAngle, double aWidth)
Draw an arc segment.
double GetArcAngleStart() const
Definition: track.cpp:962
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
bool IsNetnameLayer(LAYER_NUM aLayer)
Test whether a layer is a netname layer.
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98

References PNS::angle(), KIGFX::PCB_RENDER_SETTINGS::CL_EXISTING, KIGFX::PCB_RENDER_SETTINGS::CL_TRACKS, color, DECIDEG2RAD(), KIGFX::GAL::DrawArcSegment(), KIGFX::RENDER_SETTINGS::GetActiveLayer(), ARC::GetAngle(), ARC::GetArcAngleStart(), ARC::GetCenter(), KIGFX::PCB_RENDER_SETTINGS::GetColor(), BOARD_CONNECTED_ITEM::GetOwnClearance(), ARC::GetRadius(), TRACK::GetWidth(), IsCopperLayer(), IsNetnameLayer(), LAYER_TRACKS, KIGFX::PCB_RENDER_SETTINGS::m_clearanceDisplayFlags, KIGFX::PAINTER::m_gal, KIGFX::RENDER_SETTINGS::m_outlineWidth, m_pcbSettings, KIGFX::PCB_RENDER_SETTINGS::m_sketchMode, KIGFX::GAL::SetFillColor(), KIGFX::GAL::SetIsFill(), KIGFX::GAL::SetIsStroke(), KIGFX::GAL::SetLineWidth(), and KIGFX::GAL::SetStrokeColor().

◆ draw() [3/13]

void PCB_PAINTER::draw ( const VIA aVia,
int  aLayer 
)
protected

Definition at line 681 of file pcb_painter.cpp.

682 {
683  BOARD* board = aVia->GetBoard();
685  COLOR4D color = m_pcbSettings.GetColor( aVia, aLayer );
686  VECTOR2D center( aVia->GetStart() );
687 
688  if( color == COLOR4D::CLEAR )
689  return;
690 
691  // Draw description layer
692  if( IsNetnameLayer( aLayer ) )
693  {
694  VECTOR2D position( center );
695 
696  // Is anything that we can display enabled?
697  if( !m_pcbSettings.m_netNamesOnVias || aVia->GetNetname().empty() )
698  return;
699 
700  double maxSize = PCB_RENDER_SETTINGS::MAX_FONT_SIZE;
701  double size = aVia->GetWidth();
702 
703  // Font size limits
704  if( size > maxSize )
705  size = maxSize;
706 
707  m_gal->Save();
708  m_gal->Translate( position );
709 
710  // Default font settings
713 
714  // Set the text position to the pad shape position (the pad position is not the best place)
715  VECTOR2D textpos( 0.0, 0.0 );
716 
717  wxString netname = UnescapeString( aVia->GetShortNetname() );
718  // calculate the size of net name text:
719  double tsize = 1.5 * size / netname.Length();
720  tsize = std::min( tsize, size );
721  // Use a smaller text size to handle interline, pen size..
722  tsize *= 0.7;
723  VECTOR2D namesize( tsize, tsize );
724 
725  m_gal->SetGlyphSize( namesize );
726  m_gal->SetLineWidth( namesize.x / 12.0 );
727  m_gal->BitmapText( netname, textpos, 0.0 );
728 
729  m_gal->Restore();
730 
731  return;
732  }
733  else if( aLayer == LAYER_VIA_HOLEWALLS )
734  {
735  int platingThickness = bds.GetHolePlatingThickness();
736 
737  m_gal->SetIsFill( false );
738  m_gal->SetIsStroke( true );
740  m_gal->SetLineWidth( platingThickness );
741 
742  m_gal->DrawCircle( center, ( getDrillSize( aVia ) + platingThickness ) / 2.0 );
743 
744  return;
745  }
746 
747  bool sketchMode = false;
748 
749  switch( aVia->GetViaType() )
750  {
754  default: wxASSERT( false ); break;
755  }
756 
757  if( sketchMode )
758  {
759  // Outline mode
760  m_gal->SetIsStroke( true );
761  m_gal->SetIsFill( false );
764  }
765  else
766  {
767  // Filled mode
768  m_gal->SetIsFill( true );
769  m_gal->SetIsStroke( false );
771  }
772 
773  if( aLayer == LAYER_VIA_HOLES )
774  {
775  m_gal->DrawCircle( center, getDrillSize( aVia ) / 2.0 );
776  }
778  {
779  m_gal->DrawCircle( center, aVia->GetWidth() / 2.0 );
780  }
781  else if( aLayer == LAYER_VIA_BBLIND || aLayer == LAYER_VIA_MICROVIA )
782  {
783  // Outer circles of blind/buried and micro-vias are drawn in a special way to indicate the
784  // top and bottom layers
785  PCB_LAYER_ID layerTop, layerBottom;
786  aVia->LayerPair( &layerTop, &layerBottom );
787 
788  double radius = aVia->GetWidth() / 2.0;
789 
790  if( !sketchMode )
791  m_gal->SetLineWidth( ( aVia->GetWidth() - aVia->GetDrillValue() ) / 2.0 );
792 
793  m_gal->DrawArc( center, radius, M_PI / 2.0, M_PI );
794  m_gal->DrawArc( center, radius, 3.0 * M_PI / 2.0, 2.0 * M_PI );
795 
796  if( sketchMode )
797  m_gal->SetStrokeColor( m_pcbSettings.GetColor( aVia, layerTop ) );
798  else
799  m_gal->SetFillColor( m_pcbSettings.GetColor( aVia, layerTop ) );
800 
801  m_gal->DrawArc( center, radius, 0.0, M_PI / 2.0 );
802 
803  if( sketchMode )
804  m_gal->SetStrokeColor( m_pcbSettings.GetColor( aVia, layerBottom ) );
805  else
806  m_gal->SetFillColor( m_pcbSettings.GetColor( aVia, layerBottom ) );
807 
808  m_gal->DrawArc( center, radius, M_PI, 3.0 * M_PI / 2.0 );
809  }
810 
811  // Clearance lines
812  constexpr int clearanceFlags = PCB_RENDER_SETTINGS::CL_EXISTING | PCB_RENDER_SETTINGS::CL_VIAS;
813 
814  if( ( m_pcbSettings.m_clearanceDisplayFlags & clearanceFlags ) == clearanceFlags
815  && aLayer != LAYER_VIA_HOLES )
816  {
817  PCB_LAYER_ID activeLayer = m_pcbSettings.GetActiveLayer();
818  double radius;
819 
820  if( aVia->FlashLayer( activeLayer ) )
821  radius = aVia->GetWidth() / 2.0;
822  else
823  radius = getDrillSize( aVia ) / 2.0 + bds.GetHolePlatingThickness();
824 
826  m_gal->SetIsFill( false );
827  m_gal->SetIsStroke( true );
829  m_gal->DrawCircle( center, radius + aVia->GetOwnClearance( activeLayer ) );
830  }
831 }
virtual void SetFillColor(const COLOR4D &aColor)
Set the fill color.
void LayerPair(PCB_LAYER_ID *top_layer, PCB_LAYER_ID *bottom_layer) const
Function LayerPair Return the 2 layers used by the via (the via actually uses all layers between thes...
Definition: track.cpp:435
to draw blind/buried vias
virtual void BitmapText(const wxString &aText, const VECTOR2D &aPosition, double aRotationAngle)
Draw a text using a bitmap font.
const wxPoint & GetStart() const
Definition: track.h:116
to draw via holes (pad holes do not use this layer)
int GetHolePlatingThickness() const
Pad & via drills are finish size.
virtual void DrawArc(const VECTOR2D &aCenterPoint, double aRadius, double aStartAngle, double aEndAngle)
Draw an arc.
bool m_sketchMode[GAL_LAYER_ID_END]
Definition: pcb_painter.h:196
int color
Definition: DXF_plotter.cpp:60
Define a general 2D-vector/point.
Definition: vector2d.h:61
wxString GetNetname() const
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.h:593
PCB_RENDER_SETTINGS m_pcbSettings
Definition: pcb_painter.h:295
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.
virtual VECTOR2D getDrillSize(const PAD *aPad) const
Return drill size for a pad (internal units).
PCB_LAYER_ID
A quick note on layer IDs:
bool GetDrawIndividualViaLayers() const
Definition: pcb_painter.h:174
void ResetTextAttributes()
Reset text attributes to default styling.
wxString GetShortNetname() const
#define NULL
static const double MAX_FONT_SIZE
< Maximum font size for netnames (and other dynamically shown strings)
Definition: pcb_painter.h:194
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
int GetDrillValue() const
Function GetDrillValue "calculates" the drill value for vias (m-Drill if > 0, or default drill value ...
Definition: track.cpp:173
static const COLOR4D CLEAR
Definition: color4d.h:369
bool FlashLayer(int aLayer) const
Checks to see whether the via should have a pad on the specific layer.
Definition: track.cpp:494
to draw usual through hole vias
virtual BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:46
int m_clearanceDisplayFlags
How to display nets and netclasses with color overrides.
Definition: pcb_painter.h:216
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
void SetGlyphSize(const VECTOR2D aSize)
Set the font glyph size.
virtual void Restore()
Restore the context.
int GetWidth() const
Definition: track.h:110
virtual void DrawCircle(const VECTOR2D &aCenterPoint, double aRadius)
Draw a circle using world coordinates.
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:151
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...
VIATYPE GetViaType() const
Definition: track.h:373
PCB_LAYER_ID GetActiveLayer() const
virtual int GetOwnClearance(PCB_LAYER_ID aLayer, wxString *aSource=nullptr) const
Return an item's "own" clearance in internal units.
virtual void Save()
Save the context.
virtual void Translate(const VECTOR2D &aTranslation)
Translate the context.
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
bool IsNetnameLayer(LAYER_NUM aLayer)
Test whether a layer is a netname layer.
Container for design settings for a BOARD object.
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98

References KIGFX::GAL::BitmapText(), BLIND_BURIED, KIGFX::PCB_RENDER_SETTINGS::CL_EXISTING, KIGFX::PCB_RENDER_SETTINGS::CL_VIAS, KIGFX::COLOR4D::CLEAR, color, KIGFX::GAL::DrawArc(), KIGFX::GAL::DrawCircle(), VIA::FlashLayer(), KIGFX::RENDER_SETTINGS::GetActiveLayer(), BOARD_ITEM::GetBoard(), KIGFX::PCB_RENDER_SETTINGS::GetColor(), BOARD::GetDesignSettings(), KIGFX::PCB_RENDER_SETTINGS::GetDrawIndividualViaLayers(), getDrillSize(), VIA::GetDrillValue(), BOARD_DESIGN_SETTINGS::GetHolePlatingThickness(), BOARD_CONNECTED_ITEM::GetNetname(), BOARD_CONNECTED_ITEM::GetOwnClearance(), BOARD_CONNECTED_ITEM::GetShortNetname(), TRACK::GetStart(), VIA::GetViaType(), TRACK::GetWidth(), IsNetnameLayer(), LAYER_VIA_BBLIND, LAYER_VIA_HOLES, LAYER_VIA_HOLEWALLS, LAYER_VIA_MICROVIA, LAYER_VIA_THROUGH, VIA::LayerPair(), KIGFX::PCB_RENDER_SETTINGS::m_clearanceDisplayFlags, KIGFX::PAINTER::m_gal, KIGFX::PCB_RENDER_SETTINGS::m_netNamesOnVias, KIGFX::RENDER_SETTINGS::m_outlineWidth, m_pcbSettings, KIGFX::PCB_RENDER_SETTINGS::m_sketchMode, KIGFX::PCB_RENDER_SETTINGS::MAX_FONT_SIZE, MICROVIA, NULL, KIGFX::GAL::ResetTextAttributes(), KIGFX::GAL::Restore(), KIGFX::GAL::Save(), KIGFX::GAL::SetFillColor(), KIGFX::GAL::SetGlyphSize(), KIGFX::GAL::SetIsFill(), KIGFX::GAL::SetIsStroke(), KIGFX::GAL::SetLineWidth(), KIGFX::GAL::SetStrokeColor(), THROUGH, KIGFX::GAL::Translate(), UnescapeString(), and VECTOR2< T >::x.

◆ draw() [4/13]

void PCB_PAINTER::draw ( const PAD aPad,
int  aLayer 
)
protected

Definition at line 840 of file pcb_painter.cpp.

841 {
842  BOARD* board = aPad->GetBoard();
844  COLOR4D color = m_pcbSettings.GetColor( aPad, aLayer );
845 
846  if( IsNetnameLayer( aLayer ) )
847  {
848  // Is anything that we can display enabled?
850  {
851  bool displayNetname = ( m_pcbSettings.m_netNamesOnPads && !aPad->GetNetname().empty() );
852  EDA_RECT padBBox = aPad->GetBoundingBox();
853  VECTOR2D position = padBBox.Centre();
854  VECTOR2D padsize = VECTOR2D( padBBox.GetSize() );
855 
856  if( aPad->GetShape() != PAD_SHAPE::CUSTOM )
857  {
858  // Don't allow a 45ยบ rotation to bloat a pad's bounding box unnecessarily
859  double limit = std::min( aPad->GetSize().x, aPad->GetSize().y ) * 1.1;
860 
861  if( padsize.x > limit && padsize.y > limit )
862  {
863  padsize.x = limit;
864  padsize.y = limit;
865  }
866  }
867 
868  double maxSize = PCB_RENDER_SETTINGS::MAX_FONT_SIZE;
869  double size = padsize.y;
870 
871  m_gal->Save();
872  m_gal->Translate( position );
873 
874  // Keep the size ratio for the font, but make it smaller
875  if( padsize.x < padsize.y )
876  {
877  m_gal->Rotate( DECIDEG2RAD( -900.0 ) );
878  size = padsize.x;
879  std::swap( padsize.x, padsize.y );
880  }
881 
882  // Font size limits
883  if( size > maxSize )
884  size = maxSize;
885 
886  // Default font settings
889  m_gal->SetFontBold( false );
890  m_gal->SetFontItalic( false );
891  m_gal->SetFontUnderlined( false );
892  m_gal->SetTextMirrored( false );
893  m_gal->SetStrokeColor( m_pcbSettings.GetColor( aPad, aLayer ) );
894  m_gal->SetIsStroke( true );
895  m_gal->SetIsFill( false );
896 
897  // We have already translated the GAL to be centered at the center of the pad's
898  // bounding box
899  VECTOR2D textpos( 0.0, 0.0 );
900 
901  // Divide the space, to display both pad numbers and netnames and set the Y text
902  // position to display 2 lines
903  if( displayNetname && m_pcbSettings.m_padNumbers )
904  {
905  size = size / 2.0;
906  textpos.y = size / 2.0;
907  }
908 
909  if( displayNetname )
910  {
911  wxString netname = UnescapeString( aPad->GetShortNetname() );
912  wxString pinType = aPad->GetPinType();
913 
914  if( pinType == wxT( "no_connect" ) || pinType.EndsWith( wxT( "+no_connect" ) ) )
915  netname = "x";
916  else if( pinType == wxT( "free" ) && isImplicitNet( netname ) )
917  netname = "*";
918 
919  // calculate the size of net name text:
920  double tsize = 1.5 * padsize.x / netname.Length();
921  tsize = std::min( tsize, size );
922  // Use a smaller text size to handle interline, pen size..
923  tsize *= 0.7;
924  VECTOR2D namesize( tsize, tsize );
925 
926  m_gal->SetGlyphSize( namesize );
927  m_gal->SetLineWidth( namesize.x / 12.0 );
928  m_gal->BitmapText( netname, textpos, 0.0 );
929  }
930 
932  {
933  const wxString& padName = aPad->GetName();
934  textpos.y = -textpos.y;
935  double tsize = 1.5 * padsize.x / padName.Length();
936  tsize = std::min( tsize, size );
937  // Use a smaller text size to handle interline, pen size..
938  tsize *= 0.7;
939  tsize = std::min( tsize, size );
940  VECTOR2D numsize( tsize, tsize );
941 
942  m_gal->SetGlyphSize( numsize );
943  m_gal->SetLineWidth( numsize.x / 12.0 );
944  m_gal->BitmapText( padName, textpos, 0.0 );
945  }
946 
947  m_gal->Restore();
948  }
949  return;
950  }
951  else if( aLayer == LAYER_PAD_HOLEWALLS )
952  {
953  int platingThickness = bds.GetHolePlatingThickness();
954 
955  m_gal->SetIsFill( false );
956  m_gal->SetIsStroke( true );
957  m_gal->SetLineWidth( platingThickness );
959 
960  const SHAPE_SEGMENT* seg = aPad->GetEffectiveHoleShape();
961  int holeSize = seg->GetWidth() + platingThickness;
962 
963  if( seg->GetSeg().A == seg->GetSeg().B ) // Circular hole
964  m_gal->DrawCircle( seg->GetSeg().A, holeSize / 2 );
965  else
966  m_gal->DrawSegment( seg->GetSeg().A, seg->GetSeg().B, holeSize );
967 
968  return;
969  }
970 
972  {
973  // Outline mode
974  m_gal->SetIsFill( false );
975  m_gal->SetIsStroke( true );
978  }
979  else
980  {
981  // Filled mode
982  m_gal->SetIsFill( true );
983  m_gal->SetIsStroke( false );
985  }
986 
987  if( aLayer == LAYER_PAD_PLATEDHOLES || aLayer == LAYER_NON_PLATEDHOLES )
988  {
989  const SHAPE_SEGMENT* seg = aPad->GetEffectiveHoleShape();
990 
991  if( seg->GetSeg().A == seg->GetSeg().B ) // Circular hole
992  m_gal->DrawCircle( seg->GetSeg().A, getDrillSize( aPad ).x / 2 );
993  else
994  m_gal->DrawSegment( seg->GetSeg().A, seg->GetSeg().B, seg->GetWidth() );
995  }
996  else
997  {
998  wxSize pad_size = aPad->GetSize();
999  wxSize margin;
1000 
1001  switch( aLayer )
1002  {
1003  case F_Mask:
1004  case B_Mask:
1005  margin.x = margin.y = aPad->GetSolderMaskMargin();
1006  break;
1007 
1008  case F_Paste:
1009  case B_Paste:
1010  margin = aPad->GetSolderPasteMargin();
1011  break;
1012 
1013  default:
1014  margin.x = margin.y = 0;
1015  break;
1016  }
1017 
1018  std::unique_ptr<PAD> dummyPad;
1019  std::shared_ptr<SHAPE_COMPOUND> shapes;
1020  bool simpleShapes = true;
1021 
1022  if( margin.x != margin.y && aPad->GetShape() != PAD_SHAPE::CUSTOM )
1023  {
1024  // Our algorithms below (polygon inflation in particular) can't handle differential
1025  // inflation along separate axes. So for those cases we build a dummy pad instead,
1026  // and inflate it.
1027 
1028  // Margin is added to both sides. If the total margin is larger than the pad
1029  // then don't display this layer
1030  if( pad_size.x + 2 * margin.x <= 0 || pad_size.y + 2 * margin.y <= 0 )
1031  return;
1032 
1033  dummyPad.reset( static_cast<PAD*>( aPad->Duplicate() ) );
1034  dummyPad->SetSize( pad_size + margin + margin );
1035  shapes = std::dynamic_pointer_cast<SHAPE_COMPOUND>( dummyPad->GetEffectiveShape() );
1036  margin.x = margin.y = 0;
1037  }
1038  else
1039  {
1040  shapes = std::dynamic_pointer_cast<SHAPE_COMPOUND>( aPad->GetEffectiveShape() );
1041  }
1042 
1043  if( aPad->GetShape() == PAD_SHAPE::CUSTOM && ( margin.x || margin.y ) )
1044  {
1045  // We can't draw as shapes because we don't know which edges are internal and which
1046  // are external (so we don't know when to apply the margin and when not to).
1047  simpleShapes = false;
1048  }
1049 
1050  for( const SHAPE* shape : shapes->Shapes() )
1051  {
1052  // Drawing components of compound shapes in outline mode produces a mess.
1054  simpleShapes = false;
1055 
1056  if( !simpleShapes )
1057  break;
1058 
1059  switch( shape->Type() )
1060  {
1061  case SH_SEGMENT:
1062  case SH_CIRCLE:
1063  case SH_RECT:
1064  case SH_SIMPLE:
1065  // OK so far
1066  break;
1067 
1068  default:
1069  // Not OK
1070  simpleShapes = false;
1071  break;
1072  }
1073  }
1074 
1075  if( simpleShapes )
1076  {
1077  for( const SHAPE* shape : shapes->Shapes() )
1078  {
1079  switch( shape->Type() )
1080  {
1081  case SH_SEGMENT:
1082  {
1083  const SHAPE_SEGMENT* seg = (const SHAPE_SEGMENT*) shape;
1084  int effectiveWidth = seg->GetWidth() + 2 * margin.x;
1085 
1086  if( effectiveWidth > 0 )
1087  m_gal->DrawSegment( seg->GetSeg().A, seg->GetSeg().B, effectiveWidth );
1088  }
1089  break;
1090 
1091  case SH_CIRCLE:
1092  {
1093  const SHAPE_CIRCLE* circle = (const SHAPE_CIRCLE*) shape;
1094  int effectiveRadius = circle->GetRadius() + margin.x;
1095 
1096  if( effectiveRadius > 0 )
1097  m_gal->DrawCircle( circle->GetCenter(), effectiveRadius );
1098  }
1099  break;
1100 
1101  case SH_RECT:
1102  {
1103  const SHAPE_RECT* r = (const SHAPE_RECT*) shape;
1104  VECTOR2I pos = r->GetPosition();
1105  VECTOR2I effectiveMargin = margin;
1106 
1107  // This is a bit of an encapsulation leak, but fixing it would be a lot of
1108  // work. We don't want to apply margins to the "internal" rectangle of a
1109  // rounded rect. Only the 4 segments that form the edges get the margin.
1110  if( aPad->GetShape() == PAD_SHAPE::ROUNDRECT )
1111  effectiveMargin = { 0, 0 };
1112 
1113  if( effectiveMargin.x < 0 )
1114  {
1115  // A negative margin just produces a smaller rect.
1116 
1117  VECTOR2I effectiveSize = r->GetSize() + effectiveMargin;
1118 
1119  if( effectiveSize.x > 0 && effectiveSize.y > 0 )
1120  m_gal->DrawRectangle( pos - effectiveMargin, pos + effectiveSize );
1121  }
1122  else if( effectiveMargin.x > 0 )
1123  {
1124  // A positive margin produces a larger rect, but with rounded corners
1125 
1126  m_gal->DrawRectangle( r->GetPosition(), r->GetPosition() + r->GetSize() );
1127 
1128  // Use segments to produce the margin with rounded corners
1129  m_gal->DrawSegment( pos,
1130  pos + VECTOR2I( r->GetWidth(), 0 ),
1131  effectiveMargin.x * 2 );
1132  m_gal->DrawSegment( pos + VECTOR2I( r->GetWidth(), 0 ),
1133  pos + r->GetSize(),
1134  effectiveMargin.x * 2 );
1135  m_gal->DrawSegment( pos + r->GetSize(),
1136  pos + VECTOR2I( 0, r->GetHeight() ),
1137  effectiveMargin.x * 2 );
1138  m_gal->DrawSegment( pos + VECTOR2I( 0, r->GetHeight() ),
1139  pos,
1140  effectiveMargin.x * 2 );
1141  }
1142  else
1143  {
1144  m_gal->DrawRectangle( r->GetPosition(), r->GetPosition() + r->GetSize() );
1145  }
1146  }
1147  break;
1148 
1149  case SH_SIMPLE:
1150  {
1151  const SHAPE_SIMPLE* poly = static_cast<const SHAPE_SIMPLE*>( shape );
1152  m_gal->DrawPolygon( poly->Vertices() );
1153 
1154  // Now add on a rounded margin (using segments) if the margin > 0
1155  if( margin.x > 0 )
1156  {
1157  for( size_t ii = 0; ii < poly->GetSegmentCount(); ++ii )
1158  {
1159  SEG seg = poly->GetSegment( ii );
1160  m_gal->DrawSegment( seg.A, seg.B, margin.x * 2 );
1161  }
1162  }
1163  }
1164  break;
1165 
1166  default:
1167  // Better not get here; we already pre-flighted the shapes...
1168  break;
1169  }
1170  }
1171  }
1172  else
1173  {
1174  // This is expensive. Avoid if possible.
1175 
1176  SHAPE_POLY_SET polySet;
1177  aPad->TransformShapeWithClearanceToPolygon( polySet, ToLAYER_ID( aLayer ), margin.x,
1178  bds.m_MaxError, ERROR_INSIDE );
1179  m_gal->DrawPolygon( polySet );
1180  }
1181  }
1182 
1183  constexpr int clearanceFlags = PCB_RENDER_SETTINGS::CL_PADS;
1184 
1185  if( ( m_pcbSettings.m_clearanceDisplayFlags & clearanceFlags ) == clearanceFlags
1186  && ( aLayer == LAYER_PAD_FR || aLayer == LAYER_PAD_BK || aLayer == LAYER_PADS_TH ) )
1187  {
1188  /* Showing the clearance area is not obvious.
1189  * - A pad can be removed from some copper layers.
1190  * - For non copper layers, what is the clearance area?
1191  * So for copper layers, the clearance area is the shape if the pad is flashed on this
1192  * layer and the hole clearance area for other copper layers.
1193  * For other layers, use the pad shape, although one can use an other criteria,
1194  * depending on the non copper layer.
1195  */
1196  int activeLayer = m_pcbSettings.GetActiveLayer();
1197  bool flashActiveLayer = IsCopperLayer( activeLayer ) ?
1198  aPad->FlashLayer( activeLayer ) : true;
1199 
1200  if( flashActiveLayer || aPad->GetDrillSize().x )
1201  {
1203  m_gal->SetIsStroke( true );
1204  m_gal->SetIsFill( false );
1206 
1207  int clearance = aPad->GetOwnClearance( m_pcbSettings.GetActiveLayer() );
1208 
1209  if( flashActiveLayer && clearance > 0 )
1210  {
1211  auto shape = std::dynamic_pointer_cast<SHAPE_COMPOUND>( aPad->GetEffectiveShape() );
1212 
1213  if( shape && shape->Size() == 1 && shape->Shapes()[0]->Type() == SH_SEGMENT )
1214  {
1215  const SHAPE_SEGMENT* seg = (SHAPE_SEGMENT*) shape->Shapes()[0];
1216  m_gal->DrawSegment( seg->GetSeg().A, seg->GetSeg().B,
1217  seg->GetWidth() + 2 * clearance );
1218  }
1219  else if( shape && shape->Size() == 1 && shape->Shapes()[0]->Type() == SH_CIRCLE )
1220  {
1221  const SHAPE_CIRCLE* circle = (SHAPE_CIRCLE*) shape->Shapes()[0];
1222  m_gal->DrawCircle( circle->GetCenter(), circle->GetRadius() + clearance );
1223  }
1224  else
1225  {
1226  SHAPE_POLY_SET polySet;
1227 
1228  // Use ERROR_INSIDE because it avoids Clipper and is therefore much faster.
1229  aPad->TransformShapeWithClearanceToPolygon( polySet, ToLAYER_ID( aLayer ),
1230  clearance,
1231  bds.m_MaxError, ERROR_INSIDE );
1232  m_gal->DrawPolygon( polySet );
1233  }
1234  }
1235  else if( aPad->GetEffectiveHoleShape() && clearance > 0 )
1236  {
1237  clearance += bds.GetHolePlatingThickness();
1238 
1239  const SHAPE_SEGMENT* seg = aPad->GetEffectiveHoleShape();
1240  m_gal->DrawSegment( seg->GetSeg().A, seg->GetSeg().B,
1241  seg->GetWidth() + 2 * clearance );
1242  }
1243  }
1244  }
1245 }
virtual void SetFillColor(const COLOR4D &aColor)
Set the fill color.
virtual const SEG GetSegment(int aIndex) const override
Definition: shape_simple.h:185
virtual void DrawRectangle(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a rectangle.
SHAPE_SIMPLE.
Definition: shape_simple.h:43
int GetRadius() const
Definition: shape_circle.h:107
multilayer pads, usually with holes
virtual void BitmapText(const wxString &aText, const VECTOR2D &aPosition, double aRotationAngle)
Draw a text using a bitmap font.
handle color for not plated holes (holes, not pads)
int GetHolePlatingThickness() const
Pad & via drills are finish size.
bool m_sketchMode[GAL_LAYER_ID_END]
Definition: pcb_painter.h:196
int color
Definition: DXF_plotter.cpp:60
Define a general 2D-vector/point.
Definition: vector2d.h:61
const SHAPE_SEGMENT * GetEffectiveHoleShape() const
Return a SHAPE object representing the pad's hole.
Definition: pad.cpp:285
wxString GetNetname() const
bool isImplicitNet(const wxString &aNetName)
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.h:593
const VECTOR2I GetCenter() const
Definition: shape_circle.h:112
PCB_RENDER_SETTINGS m_pcbSettings
Definition: pcb_painter.h:295
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
const SEG & GetSeg() const
virtual void SetLineWidth(float aLineWidth)
Set the line width.
virtual void Rotate(double aAngle)
Rotate the context.
virtual VECTOR2D getDrillSize(const PAD *aPad) const
Return drill size for a pad (internal units).
const VECTOR2I GetSize() const
Definition: shape_rect.h:124
void SetFontBold(const bool aBold)
Set bold property of current font.
const wxSize & GetDrillSize() const
Definition: pad.h:242
bool FlashLayer(int aLayer) const
Check to see whether the pad should be flashed on the specific layer.
Definition: pad.cpp:202
virtual void DrawSegment(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint, double aWidth)
Draw a rounded segment.
wxString GetShortNetname() const
VECTOR2< double > VECTOR2D
Definition: vector2d.h:622
static const double MAX_FONT_SIZE
< Maximum font size for netnames (and other dynamically shown strings)
Definition: pcb_painter.h:194
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
Represent a set of closed polygons.
const VECTOR2I & GetPosition() const
Definition: shape_rect.h:116
const wxSize & GetSize() const
Definition: pad.h:232
virtual BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:46
const wxString & GetName() const
Definition: pad.h:133
const EDA_RECT GetBoundingBox() const override
The bounding box is cached, so this will be efficient most of the time.
Definition: pad.cpp:517
const wxString & GetPinType() const
Definition: pad.h:145
PAD_SHAPE GetShape() const
Definition: pad.h:169
const SHAPE_LINE_CHAIN & Vertices() const
Function Vertices()
Definition: shape_simple.h:133
virtual std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER) const override
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
Definition: pad.cpp:276
An abstract shape on 2D plane.
Definition: shape.h:116
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.
void SetFontItalic(bool aItalic)
Set italic property of current font.
circle
Definition: shape.h:46
int m_clearanceDisplayFlags
How to display nets and netclasses with color overrides.
Definition: pcb_painter.h:216
int GetSolderMaskMargin() const
Definition: pad.cpp:696
Definition: seg.h:41
virtual size_t GetSegmentCount() const override
Definition: shape_simple.h:187
void TransformShapeWithClearanceToPolygon(SHAPE_POLY_SET &aCornerBuffer, PCB_LAYER_ID aLayer, int aClearanceValue, int aMaxError, ERROR_LOC aErrorLoc, bool ignoreLineWidth=false) const override
Convert the pad shape to a closed polygon.
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
void SetGlyphSize(const VECTOR2D aSize)
Set the font glyph size.
smd pads, front layer
virtual void Restore()
Restore the context.
virtual void DrawPolygon(const std::deque< VECTOR2D > &aPointList)
Draw a polygon.
void SetFontUnderlined(bool aUnderlined)
wxSize GetSolderPasteMargin() const
Usually < 0 (mask shape smaller than pad)because the margin can be dependent on the pad size,...
Definition: pad.cpp:741
virtual void DrawCircle(const VECTOR2D &aCenterPoint, double aRadius)
Draw a circle using world coordinates.
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:151
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...
VECTOR2I A
Definition: seg.h:49
Handle the component boundary box.
Definition: eda_rect.h:42
double DECIDEG2RAD(double deg)
Definition: trigo.h:235
PCB_LAYER_ID GetActiveLayer() const
virtual int GetOwnClearance(PCB_LAYER_ID aLayer, wxString *aSource=nullptr) const
Return an item's "own" clearance in internal units.
wxPoint Centre() const
Definition: eda_rect.h:60
bool IsCopperLayer(LAYER_NUM aLayerId)
Tests whether a layer is a copper layer.
virtual BOARD_ITEM * Duplicate() const
Create a copy of this BOARD_ITEM.
Definition: board_item.h:202
const int GetHeight() const
Definition: shape_rect.h:140
axis-aligned rectangle
Definition: shape.h:43
virtual void Save()
Save the context.
void SetHorizontalJustify(const EDA_TEXT_HJUSTIFY_T aHorizontalJustify)
Set the horizontal justify for text drawing.
const int GetWidth() const
Definition: shape_rect.h:132
virtual void Translate(const VECTOR2D &aTranslation)
Translate the context.
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
int GetWidth() const
simple polygon
Definition: shape.h:47
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:905
const wxSize GetSize() const
Definition: eda_rect.h:96
bool IsNetnameLayer(LAYER_NUM aLayer)
Test whether a layer is a netname layer.
line segment
Definition: shape.h:44
Container for design settings for a BOARD object.
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98
VECTOR2I B
Definition: seg.h:50

References SEG::A, SEG::B, B_Mask, B_Paste, KIGFX::GAL::BitmapText(), EDA_RECT::Centre(), KIGFX::PCB_RENDER_SETTINGS::CL_PADS, color, CUSTOM, DECIDEG2RAD(), KIGFX::GAL::DrawCircle(), KIGFX::GAL::DrawPolygon(), KIGFX::GAL::DrawRectangle(), KIGFX::GAL::DrawSegment(), BOARD_ITEM::Duplicate(), ERROR_INSIDE, F_Mask, F_Paste, PAD::FlashLayer(), KIGFX::RENDER_SETTINGS::GetActiveLayer(), BOARD_ITEM::GetBoard(), PAD::GetBoundingBox(), SHAPE_CIRCLE::GetCenter(), KIGFX::PCB_RENDER_SETTINGS::GetColor(), BOARD::GetDesignSettings(), PAD::GetDrillSize(), getDrillSize(), PAD::GetEffectiveHoleShape(), PAD::GetEffectiveShape(), SHAPE_RECT::GetHeight(), BOARD_DESIGN_SETTINGS::GetHolePlatingThickness(), PAD::GetName(), BOARD_CONNECTED_ITEM::GetNetname(), BOARD_CONNECTED_ITEM::GetOwnClearance(), PAD::GetPinType(), SHAPE_RECT::GetPosition(), SHAPE_CIRCLE::GetRadius(), SHAPE_SEGMENT::GetSeg(), SHAPE_SIMPLE::GetSegment(), SHAPE_SIMPLE::GetSegmentCount(), PAD::GetShape(), BOARD_CONNECTED_ITEM::GetShortNetname(), EDA_RECT::GetSize(), SHAPE_RECT::GetSize(), PAD::GetSize(), PAD::GetSolderMaskMargin(), PAD::GetSolderPasteMargin(), SHAPE_RECT::GetWidth(), SHAPE_SEGMENT::GetWidth(), GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER, IsCopperLayer(), isImplicitNet(), IsNetnameLayer(), LAYER_NON_PLATEDHOLES, LAYER_PAD_BK, LAYER_PAD_FR, LAYER_PAD_HOLEWALLS, LAYER_PAD_PLATEDHOLES, LAYER_PADS_TH, KIGFX::PCB_RENDER_SETTINGS::m_clearanceDisplayFlags, KIGFX::PAINTER::m_gal, BOARD_DESIGN_SETTINGS::m_MaxError, KIGFX::PCB_RENDER_SETTINGS::m_netNamesOnPads, KIGFX::RENDER_SETTINGS::m_outlineWidth, KIGFX::PCB_RENDER_SETTINGS::m_padNumbers, m_pcbSettings, KIGFX::PCB_RENDER_SETTINGS::m_sketchMode, KIGFX::PCB_RENDER_SETTINGS::MAX_FONT_SIZE, KIGFX::GAL::Restore(), KIGFX::GAL::Rotate(), ROUNDRECT, KIGFX::GAL::Save(), 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::SetStrokeColor(), KIGFX::GAL::SetTextMirrored(), KIGFX::GAL::SetVerticalJustify(), SH_CIRCLE, SH_RECT, SH_SEGMENT, SH_SIMPLE, ToLAYER_ID(), PAD::TransformShapeWithClearanceToPolygon(), KIGFX::GAL::Translate(), UnescapeString(), SHAPE_SIMPLE::Vertices(), VECTOR2< T >::x, and VECTOR2< T >::y.

◆ draw() [5/13]

void PCB_PAINTER::draw ( const PCB_SHAPE aSegment,
int  aLayer 
)
protected

Definition at line 1248 of file pcb_painter.cpp.

1249 {
1250  const COLOR4D& color = m_pcbSettings.GetColor( aShape, aShape->GetLayer() );
1251  bool sketch = m_pcbSettings.m_sketchGraphics;
1252  int thickness = getLineThickness( aShape->GetWidth() );
1253  VECTOR2D start( aShape->GetStart() );
1254  VECTOR2D end( aShape->GetEnd() );
1255 
1256  if( sketch )
1257  {
1258  m_gal->SetIsFill( false );
1259  m_gal->SetIsStroke( true );
1261  }
1262 
1263  m_gal->SetFillColor( color );
1265 
1266  switch( aShape->GetShape() )
1267  {
1269  if( sketch )
1270  {
1271  m_gal->DrawSegment( start, end, thickness );
1272  }
1273  else
1274  {
1275  m_gal->SetIsFill( true );
1276  m_gal->SetIsStroke( false );
1277 
1278  m_gal->DrawSegment( start, end, thickness );
1279  }
1280  break;
1281 
1282  case PCB_SHAPE_TYPE::RECT:
1283  {
1284  std::vector<wxPoint> pts = aShape->GetRectCorners();
1285 
1286  if( sketch )
1287  {
1288  m_gal->DrawSegment( pts[0], pts[1], thickness );
1289  m_gal->DrawSegment( pts[1], pts[2], thickness );
1290  m_gal->DrawSegment( pts[2], pts[3], thickness );
1291  m_gal->DrawSegment( pts[3], pts[0], thickness );
1292  }
1293  else
1294  {
1295  m_gal->SetIsFill( true );
1296  m_gal->SetIsStroke( false );
1297 
1298  if( thickness > 0 )
1299  {
1300  m_gal->DrawSegment( pts[0], pts[1], thickness );
1301  m_gal->DrawSegment( pts[1], pts[2], thickness );
1302  m_gal->DrawSegment( pts[2], pts[3], thickness );
1303  m_gal->DrawSegment( pts[3], pts[0], thickness );
1304  }
1305 
1306  if( aShape->IsFilled() )
1307  {
1308  SHAPE_POLY_SET poly;
1309  poly.NewOutline();
1310 
1311  for( const wxPoint& pt : pts )
1312  poly.Append( pt );
1313 
1314  m_gal->DrawPolygon( poly );
1315  }
1316  }
1317  }
1318  break;
1319 
1320  case PCB_SHAPE_TYPE::ARC:
1321  if( sketch )
1322  {
1323  m_gal->DrawArcSegment( start, aShape->GetRadius(),
1324  DECIDEG2RAD( aShape->GetArcAngleStart() ),
1325  DECIDEG2RAD( aShape->GetArcAngleStart() + aShape->GetAngle() ), // Change this
1326  thickness );
1327  }
1328  else
1329  {
1330  m_gal->SetIsFill( true );
1331  m_gal->SetIsStroke( false );
1332 
1333  m_gal->DrawArcSegment( start, aShape->GetRadius(),
1334  DECIDEG2RAD( aShape->GetArcAngleStart() ),
1335  DECIDEG2RAD( aShape->GetArcAngleStart() + aShape->GetAngle() ), // Change this
1336  thickness );
1337  }
1338  break;
1339 
1341  if( sketch )
1342  {
1343  m_gal->DrawCircle( start, aShape->GetRadius() - thickness / 2 );
1344  m_gal->DrawCircle( start, aShape->GetRadius() + thickness / 2 );
1345  }
1346  else
1347  {
1348  m_gal->SetIsFill( aShape->IsFilled() );
1349  m_gal->SetIsStroke( thickness > 0 );
1350  m_gal->SetLineWidth( thickness );
1351 
1352  m_gal->DrawCircle( start, aShape->GetRadius() );
1353  }
1354  break;
1355 
1357  {
1358  SHAPE_POLY_SET& shape = const_cast<PCB_SHAPE*>( aShape )->GetPolyShape();
1359  const FOOTPRINT* parentFootprint = aShape->GetParentFootprint();
1360 
1361  if( shape.OutlineCount() == 0 )
1362  break;
1363 
1364  if( parentFootprint )
1365  {
1366  m_gal->Save();
1367  m_gal->Translate( parentFootprint->GetPosition() );
1368  m_gal->Rotate( -parentFootprint->GetOrientationRadians() );
1369  }
1370 
1371  if( sketch )
1372  {
1373  for( int ii = 0; ii < shape.Outline( 0 ).SegmentCount(); ++ii )
1374  {
1375  SEG seg = shape.Outline( 0 ).Segment( ii );
1376  m_gal->DrawSegment( seg.A, seg.B, thickness );
1377  }
1378  }
1379  else
1380  {
1381  m_gal->SetIsFill( true );
1382  m_gal->SetIsStroke( false );
1383 
1384  if( thickness > 0 )
1385  {
1386  for( int ii = 0; ii < shape.Outline( 0 ).SegmentCount(); ++ii )
1387  {
1388  SEG seg = shape.Outline( 0 ).Segment( ii );
1389  m_gal->DrawSegment( seg.A, seg.B, thickness );
1390  }
1391  }
1392 
1393  if( aShape->IsFilled() )
1394  {
1395  // On Opengl, a not convex filled polygon is usually drawn by using triangles
1396  // as primitives. CacheTriangulation() can create basic triangle primitives to
1397  // draw the polygon solid shape on Opengl. GLU tesselation is much slower, so
1398  // currently we are using our tesselation.
1399  if( m_gal->IsOpenGlEngine() && !shape.IsTriangulationUpToDate() )
1400  shape.CacheTriangulation();
1401 
1402  m_gal->DrawPolygon( shape );
1403  }
1404  }
1405 
1406  if( parentFootprint )
1407  m_gal->Restore();
1408  }
1409  break;
1410 
1411  case PCB_SHAPE_TYPE::CURVE:
1412  if( sketch )
1413  {
1414  // Use thickness as filter value to convert the curve to polyline when the curve
1415  // is not supported
1416  m_gal->DrawCurve( VECTOR2D( aShape->GetStart() ),
1417  VECTOR2D( aShape->GetBezControl1() ),
1418  VECTOR2D( aShape->GetBezControl2() ),
1419  VECTOR2D( aShape->GetEnd() ), thickness );
1420  }
1421  else
1422  {
1423  m_gal->SetIsFill( aShape->IsFilled() );
1424  m_gal->SetIsStroke( thickness > 0 );
1425  m_gal->SetLineWidth( thickness );
1426 
1427  // Use thickness as filter value to convert the curve to polyline when the curve
1428  // is not supported
1429  m_gal->DrawCurve( VECTOR2D( aShape->GetStart() ),
1430  VECTOR2D( aShape->GetBezControl1() ),
1431  VECTOR2D( aShape->GetBezControl2() ),
1432  VECTOR2D( aShape->GetEnd() ), thickness );
1433  }
1434  break;
1435 
1436  case PCB_SHAPE_TYPE::LAST:
1437  break;
1438  }
1439 }
virtual void SetFillColor(const COLOR4D &aColor)
Set the fill color.
double GetOrientationRadians() const
Definition: footprint.h:188
int OutlineCount() const
Return the number of vertices in a given outline/hole.
int color
Definition: DXF_plotter.cpp:60
Define a general 2D-vector/point.
Definition: vector2d.h:61
PCB_RENDER_SETTINGS m_pcbSettings
Definition: pcb_painter.h:295
bool IsTriangulationUpToDate() const
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.
virtual void Rotate(double aAngle)
Rotate the context.
polygon (not yet used for tracks, but could be in microwave apps)
int getLineThickness(int aActualThickness) const
Get the thickness to draw for a line (e.g.
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.
SHAPE_LINE_CHAIN & Outline(int aIndex)
segment with non rounded ends
last value for this list
virtual bool IsOpenGlEngine()
Return true if the GAL engine is a OpenGL based type.
int NewOutline()
Creates a new hole in a given outline.
int SegmentCount() const
Function SegmentCount()
Definition: seg.h:41
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
SEG Segment(int aIndex)
Function Segment()
virtual void Restore()
Restore the context.
virtual void DrawPolygon(const std::deque< VECTOR2D > &aPointList)
Draw a polygon.
virtual void DrawCircle(const VECTOR2D &aCenterPoint, double aRadius)
Draw a circle using world coordinates.
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...
VECTOR2I A
Definition: seg.h:49
double DECIDEG2RAD(double deg)
Definition: trigo.h:235
usual segment : line with rounded ends
wxPoint GetPosition() const override
Definition: footprint.h:182
virtual void DrawArcSegment(const VECTOR2D &aCenterPoint, double aRadius, double aStartAngle, double aEndAngle, double aWidth)
Draw an arc segment.
void CacheTriangulation(bool aPartition=true)
virtual void Save()
Save the context.
Arcs (with rounded ends)
virtual void Translate(const VECTOR2D &aTranslation)
Translate the context.
virtual void DrawCurve(const VECTOR2D &startPoint, const VECTOR2D &controlPointA, const VECTOR2D &controlPointB, const VECTOR2D &endPoint, double aFilterValue=0.0)
Draw a cubic bezier spline.
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
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...
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98
VECTOR2I B
Definition: seg.h:50

References SEG::A, SHAPE_POLY_SET::Append(), ARC, SEG::B, SHAPE_POLY_SET::CacheTriangulation(), CIRCLE, color, CURVE, DECIDEG2RAD(), KIGFX::GAL::DrawArcSegment(), KIGFX::GAL::DrawCircle(), KIGFX::GAL::DrawCurve(), KIGFX::GAL::DrawPolygon(), KIGFX::GAL::DrawSegment(), PCB_SHAPE::GetAngle(), PCB_SHAPE::GetArcAngleStart(), PCB_SHAPE::GetBezControl1(), PCB_SHAPE::GetBezControl2(), KIGFX::PCB_RENDER_SETTINGS::GetColor(), PCB_SHAPE::GetEnd(), BOARD_ITEM::GetLayer(), getLineThickness(), FOOTPRINT::GetOrientationRadians(), PCB_SHAPE::GetParentFootprint(), FOOTPRINT::GetPosition(), PCB_SHAPE::GetRadius(), PCB_SHAPE::GetRectCorners(), PCB_SHAPE::GetShape(), PCB_SHAPE::GetStart(), PCB_SHAPE::GetWidth(), PCB_SHAPE::IsFilled(), KIGFX::GAL::IsOpenGlEngine(), SHAPE_POLY_SET::IsTriangulationUpToDate(), LAST, KIGFX::PAINTER::m_gal, KIGFX::RENDER_SETTINGS::m_outlineWidth, m_pcbSettings, KIGFX::PCB_RENDER_SETTINGS::m_sketchGraphics, SHAPE_POLY_SET::NewOutline(), SHAPE_POLY_SET::Outline(), SHAPE_POLY_SET::OutlineCount(), POLYGON, RECT, KIGFX::GAL::Restore(), KIGFX::GAL::Rotate(), KIGFX::GAL::Save(), SEGMENT, SHAPE_LINE_CHAIN::Segment(), SHAPE_LINE_CHAIN::SegmentCount(), KIGFX::GAL::SetFillColor(), KIGFX::GAL::SetIsFill(), KIGFX::GAL::SetIsStroke(), KIGFX::GAL::SetLineWidth(), KIGFX::GAL::SetStrokeColor(), and KIGFX::GAL::Translate().

◆ draw() [6/13]

void PCB_PAINTER::draw ( const PCB_TEXT aText,
int  aLayer 
)
protected

Definition at line 1442 of file pcb_painter.cpp.

1443 {
1444  wxString shownText( aText->GetShownText() );
1445 
1446  if( shownText.Length() == 0 )
1447  return;
1448 
1449  const COLOR4D& color = m_pcbSettings.GetColor( aText, aText->GetLayer() );
1450  VECTOR2D position( aText->GetTextPos().x, aText->GetTextPos().y );
1451 
1453  {
1454  // Outline mode
1456  }
1457  else
1458  {
1459  // Filled mode
1461  }
1462 
1464  m_gal->SetIsFill( false );
1465  m_gal->SetIsStroke( true );
1466  m_gal->SetTextAttributes( aText );
1467  m_gal->StrokeText( shownText, position, aText->GetTextAngleRadians() );
1468 }
virtual void SetTextAttributes(const EDA_TEXT *aText)
Loads attributes of the given text (bold/italic/underline/mirrored and so on).
bool m_sketchMode[GAL_LAYER_ID_END]
Definition: pcb_painter.h:196
int color
Definition: DXF_plotter.cpp:60
Define a general 2D-vector/point.
Definition: vector2d.h:61
PCB_RENDER_SETTINGS m_pcbSettings
Definition: pcb_painter.h:295
GAL * m_gal
Instance of graphic abstraction layer that gives an interface to call commands used to draw (eg.
Definition: painter.h:101
int GetEffectiveTextPenWidth(int aDefaultWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultWidth.
Definition: eda_text.cpp:157
virtual void SetLineWidth(float aLineWidth)
Set the line width.
wxString GetShownText(int aDepth=0) const override
Return the string actually shown after processing of the base text.
Definition: pcb_text.cpp:53
int getLineThickness(int aActualThickness) const
Get the thickness to draw for a line (e.g.
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
virtual void StrokeText(const wxString &aText, const VECTOR2D &aPosition, double aRotationAngle)
Draw a vector type text using preloaded Newstroke font.
double GetTextAngleRadians() const
Definition: eda_text.h:184
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
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...
const wxPoint & GetTextPos() const
Definition: eda_text.h:254
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:173
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98

References color, KIGFX::PCB_RENDER_SETTINGS::GetColor(), EDA_TEXT::GetEffectiveTextPenWidth(), BOARD_ITEM::GetLayer(), getLineThickness(), PCB_TEXT::GetShownText(), EDA_TEXT::GetTextAngleRadians(), EDA_TEXT::GetTextPos(), KIGFX::PAINTER::m_gal, KIGFX::RENDER_SETTINGS::m_outlineWidth, m_pcbSettings, KIGFX::PCB_RENDER_SETTINGS::m_sketchMode, KIGFX::PCB_RENDER_SETTINGS::m_sketchText, KIGFX::GAL::SetIsFill(), KIGFX::GAL::SetIsStroke(), KIGFX::GAL::SetLineWidth(), KIGFX::GAL::SetStrokeColor(), KIGFX::GAL::SetTextAttributes(), and KIGFX::GAL::StrokeText().

◆ draw() [7/13]

void PCB_PAINTER::draw ( const FP_TEXT aText,
int  aLayer 
)
protected

Definition at line 1471 of file pcb_painter.cpp.

1472 {
1473  wxString shownText( aText->GetShownText() );
1474 
1475  if( shownText.Length() == 0 )
1476  return;
1477 
1478  const COLOR4D& color = m_pcbSettings.GetColor( aText, aLayer );
1479  VECTOR2D position( aText->GetTextPos().x, aText->GetTextPos().y );
1480 
1482  {
1483  // Outline mode
1485  }
1486  else
1487  {
1488  // Filled mode
1490  }
1491 
1493  m_gal->SetIsFill( false );
1494  m_gal->SetIsStroke( true );
1495  m_gal->SetTextAttributes( aText );
1496  m_gal->StrokeText( shownText, position, aText->GetDrawRotationRadians() );
1497 
1498  // Draw the umbilical line
1499  if( aText->IsSelected() )
1500  {
1503  m_gal->DrawLine( position, aText->GetParent()->GetPosition() );
1504  }
1505 }
bool IsSelected() const
Definition: eda_item.h:173
anchor of items having an anchor point (texts, footprints)
virtual void SetTextAttributes(const EDA_TEXT *aText)
Loads attributes of the given text (bold/italic/underline/mirrored and so on).
int color
Definition: DXF_plotter.cpp:60
Define a general 2D-vector/point.
Definition: vector2d.h:61
PCB_RENDER_SETTINGS m_pcbSettings
Definition: pcb_painter.h:295
virtual wxPoint GetPosition() const
Definition: eda_item.h:302
virtual void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a line.
GAL * m_gal
Instance of graphic abstraction layer that gives an interface to call commands used to draw (eg.
Definition: painter.h:101
int GetEffectiveTextPenWidth(int aDefaultWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultWidth.
Definition: eda_text.cpp:157
virtual void SetLineWidth(float aLineWidth)
Set the line width.
int getLineThickness(int aActualThickness) const
Get the thickness to draw for a line (e.g.
double GetDrawRotationRadians() const
Definition: fp_text.h:175
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
virtual void StrokeText(const wxString &aText, const VECTOR2D &aPosition, double aRotationAngle)
Draw a vector type text using preloaded Newstroke font.
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
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...
const wxPoint & GetTextPos() const
Definition: eda_text.h:254
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:168
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
virtual wxString GetShownText(int aDepth=0) const override
Return the string actually shown after processing of the base text.
Definition: fp_text.cpp:398
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98

References color, KIGFX::GAL::DrawLine(), KIGFX::PCB_RENDER_SETTINGS::GetColor(), FP_TEXT::GetDrawRotationRadians(), EDA_TEXT::GetEffectiveTextPenWidth(), getLineThickness(), BOARD_ITEM::GetParent(), EDA_ITEM::GetPosition(), FP_TEXT::GetShownText(), EDA_TEXT::GetTextPos(), EDA_ITEM::IsSelected(), LAYER_ANCHOR, KIGFX::PAINTER::m_gal, KIGFX::RENDER_SETTINGS::m_outlineWidth, m_pcbSettings, KIGFX::PCB_RENDER_SETTINGS::m_sketchText, KIGFX::GAL::SetIsFill(), KIGFX::GAL::SetIsStroke(), KIGFX::GAL::SetLineWidth(), KIGFX::GAL::SetStrokeColor(), KIGFX::GAL::SetTextAttributes(), and KIGFX::GAL::StrokeText().

◆ draw() [8/13]

void PCB_PAINTER::draw ( const FOOTPRINT aFootprint,
int  aLayer 
)
protected

Definition at line 1508 of file pcb_painter.cpp.

1509 {
1510  if( aLayer == LAYER_ANCHOR )
1511  {
1512  const COLOR4D color = m_pcbSettings.GetColor( aFootprint, aLayer );
1513 
1514  // Keep the size and width constant, not related to the scale because the anchor
1515  // is just a marker on screen
1516  double anchorSize = 5.0 / m_gal->GetWorldScale(); // 5 pixels size
1517  double anchorThickness = 1.0 / m_gal->GetWorldScale(); // 1 pixels width
1518 
1519  // Draw anchor
1520  m_gal->SetIsFill( false );
1521  m_gal->SetIsStroke( true );
1523  m_gal->SetLineWidth( anchorThickness );
1524 
1525  VECTOR2D center = aFootprint->GetPosition();
1526  m_gal->DrawLine( center - VECTOR2D( anchorSize, 0 ), center + VECTOR2D( anchorSize, 0 ) );
1527  m_gal->DrawLine( center - VECTOR2D( 0, anchorSize ), center + VECTOR2D( 0, anchorSize ) );
1528 
1529 #if 0 // For debug purpose only: draw the footing bounding box
1530  double bboxThickness = 1.0 / m_gal->GetWorldScale();
1531  m_gal->SetLineWidth( bboxThickness );
1532  EDA_RECT rect = aFootprint->GetBoundingBox();
1533  m_gal->DrawRectangle( VECTOR2D( rect.GetOrigin() ), VECTOR2D( rect.GetEnd() ) );
1534 
1535  double bboxThickness = 3.0 / m_gal->GetWorldScale();
1536  m_gal->SetLineWidth( bboxThickness );
1537  SHAPE_POLY_SET convex = aFootprint->GetBoundingHull();
1538 
1539  m_gal->DrawPolyline( convex.COutline( 0 ) );
1540 #endif
1541  }
1542 }
virtual void DrawPolyline(const std::deque< VECTOR2D > &aPointList)
Draw a polyline.
virtual void DrawRectangle(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a rectangle.
SHAPE_POLY_SET GetBoundingHull() const
Return a bounding polygon for the shapes and pads in the footprint.
Definition: footprint.cpp:739
anchor of items having an anchor point (texts, footprints)
int color
Definition: DXF_plotter.cpp:60
Define a general 2D-vector/point.
Definition: vector2d.h:61
PCB_RENDER_SETTINGS m_pcbSettings
Definition: pcb_painter.h:295
virtual void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a line.
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
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 void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
const EDA_RECT GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: footprint.cpp:631
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...
Handle the component boundary box.
Definition: eda_rect.h:42
wxPoint GetPosition() const override
Definition: footprint.h:182
double GetWorldScale() const
Get the world scale.
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98

References color, SHAPE_POLY_SET::COutline(), KIGFX::GAL::DrawLine(), KIGFX::GAL::DrawPolyline(), KIGFX::GAL::DrawRectangle(), FOOTPRINT::GetBoundingBox(), FOOTPRINT::GetBoundingHull(), KIGFX::PCB_RENDER_SETTINGS::GetColor(), EDA_RECT::GetEnd(), EDA_RECT::GetOrigin(), FOOTPRINT::GetPosition(), KIGFX::GAL::GetWorldScale(), LAYER_ANCHOR, KIGFX::PAINTER::m_gal, m_pcbSettings, KIGFX::GAL::SetIsFill(), KIGFX::GAL::SetIsStroke(), KIGFX::GAL::SetLineWidth(), and KIGFX::GAL::SetStrokeColor().

◆ draw() [9/13]

void PCB_PAINTER::draw ( const PCB_GROUP aGroup,
int  aLayer 
)
protected

Definition at line 1545 of file pcb_painter.cpp.

1546 {
1547  if( aLayer == LAYER_ANCHOR )
1548  {
1549  if( aGroup->IsSelected() && !( aGroup->GetParent() && aGroup->GetParent()->IsSelected() ) )
1550  {
1551  // Selected on our own; draw enclosing box
1552  }
1553  else if( aGroup->IsEntered() )
1554  {
1555  // Entered group; draw enclosing box
1556  }
1557  else
1558  {
1559  return;
1560  }
1561 
1562  const COLOR4D color = m_pcbSettings.GetColor( aGroup, LAYER_ANCHOR );
1563 
1564  EDA_RECT bbox = aGroup->GetBoundingBox();
1567  wxPoint topLeft = bbox.GetPosition();
1568  wxPoint width = wxPoint( bbox.GetWidth(), 0 );
1569  wxPoint height = wxPoint( 0, bbox.GetHeight() );
1570 
1571  m_gal->DrawLine( topLeft, topLeft + width );
1572  m_gal->DrawLine( topLeft + width, topLeft + width + height );
1573  m_gal->DrawLine( topLeft + width + height, topLeft + height );
1574  m_gal->DrawLine( topLeft + height, topLeft );
1575 
1576  wxString name = aGroup->GetName();
1577 
1578  int ptSize = 12;
1579  int scaledSize = abs( KiROUND( m_gal->GetScreenWorldMatrix().GetScale().x * ptSize ) );
1580  int unscaledSize = Mils2iu( ptSize );
1581 
1582  // Scale by zoom a bit, but not too much
1583  int textSize = ( scaledSize + ( unscaledSize * 2 ) ) / 3;
1584  int penWidth = textSize / 10;
1585  wxPoint textOffset = wxPoint( width.x / 2, - KiROUND( textSize * 0.5 ) );
1586  wxPoint titleHeight = wxPoint( 0, KiROUND( textSize * 2.0 ) );
1587 
1588  if( !name.IsEmpty() && (int) aGroup->GetName().Length() * textSize < bbox.GetWidth() )
1589  {
1590  m_gal->DrawLine( topLeft, topLeft - titleHeight );
1591  m_gal->DrawLine( topLeft - titleHeight, topLeft + width - titleHeight );
1592  m_gal->DrawLine( topLeft + width - titleHeight, topLeft + width );
1593 
1594  m_gal->SetFontBold( false );
1595  m_gal->SetFontItalic( true );
1596  m_gal->SetFontUnderlined( false );
1600  m_gal->SetIsFill( false );
1601  m_gal->SetGlyphSize( VECTOR2D( textSize, textSize ) );
1602  m_gal->SetLineWidth( penWidth );
1603  m_gal->StrokeText( aGroup->GetName(), topLeft + textOffset, 0.0 );
1604  }
1605  }
1606 }
bool IsSelected() const
Definition: eda_item.h:173
const MATRIX3x3D & GetScreenWorldMatrix() const
Get the screen <-> world transformation matrix.
anchor of items having an anchor point (texts, footprints)
bool IsFlippedX() const
Return true if flip flag for the X axis is set.
int color
Definition: DXF_plotter.cpp:60
int GetWidth() const
Definition: eda_rect.h:114
PCB_RENDER_SETTINGS m_pcbSettings
Definition: pcb_painter.h:295
const EDA_RECT GetBoundingBox() const override
May be re-implemented for each derived class in order to handle all the types given by its member dat...
Definition: pcb_group.cpp:210
virtual void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a line.
VECTOR2< T > GetScale() const
Get the scale components of the matrix.
Definition: matrix3x3.h:269
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 SetFontBold(const bool aBold)
Set bold property of current font.
bool IsEntered() const
Definition: eda_item.h:174
VECTOR2< double > VECTOR2D
Definition: vector2d.h:622
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
wxString GetName() const
Definition: pcb_group.h:65
virtual void StrokeText(const wxString &aText, const VECTOR2D &aPosition, double aRotationAngle)
Draw a vector type text using preloaded Newstroke font.
const wxPoint GetPosition() const
Definition: eda_rect.h:107
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.
void SetFontItalic(bool aItalic)
Set italic property of current font.
int GetHeight() const
Definition: eda_rect.h:115
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
void SetGlyphSize(const VECTOR2D aSize)
Set the font glyph size.
void SetFontUnderlined(bool aUnderlined)
const char * name
Definition: DXF_plotter.cpp:59
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...
Handle the component boundary box.
Definition: eda_rect.h:42
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:68
void SetHorizontalJustify(const EDA_TEXT_HJUSTIFY_T aHorizontalJustify)
Set the horizontal justify for text drawing.
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:168
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98

References color, KIGFX::GAL::DrawLine(), PCB_GROUP::GetBoundingBox(), KIGFX::PCB_RENDER_SETTINGS::GetColor(), EDA_RECT::GetHeight(), PCB_GROUP::GetName(), BOARD_ITEM::GetParent(), EDA_RECT::GetPosition(), MATRIX3x3< T >::GetScale(), KIGFX::GAL::GetScreenWorldMatrix(), EDA_RECT::GetWidth(), GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_BOTTOM, EDA_ITEM::IsEntered(), KIGFX::GAL::IsFlippedX(), EDA_ITEM::IsSelected(), KiROUND(), LAYER_ANCHOR, KIGFX::PAINTER::m_gal, KIGFX::RENDER_SETTINGS::m_outlineWidth, m_pcbSettings, name, KIGFX::GAL::SetFontBold(), KIGFX::GAL::SetFontItalic(), KIGFX::GAL::SetFontUnderlined(), KIGFX::GAL::SetGlyphSize(), KIGFX::GAL::SetHorizontalJustify(), KIGFX::GAL::SetIsFill(), KIGFX::GAL::SetLineWidth(), KIGFX::GAL::SetStrokeColor(), KIGFX::GAL::SetTextMirrored(), KIGFX::GAL::SetVerticalJustify(), KIGFX::GAL::StrokeText(), and VECTOR2< T >::x.

◆ draw() [10/13]

void PCB_PAINTER::draw ( const ZONE aZone,
int  aLayer 
)
protected

aLayer will be the virtual zone layer (LAYER_ZONE_START, ... in GAL_LAYER_ID) This is used for draw ordering in the GAL. The color for the zone comes from the associated copper layer ( aLayer - LAYER_ZONE_START ) and the visibility comes from the combination of that copper layer and LAYER_ZONES

Definition at line 1609 of file pcb_painter.cpp.

1610 {
1617  wxASSERT( IsZoneLayer( aLayer ) );
1618  PCB_LAYER_ID layer = static_cast<PCB_LAYER_ID>( aLayer - LAYER_ZONE_START );
1619 
1620  if( !aZone->IsOnLayer( layer ) )
1621  return;
1622 
1623  COLOR4D color = m_pcbSettings.GetColor( aZone, layer );
1624  std::deque<VECTOR2D> corners;
1626 
1627  // Draw the outline
1628  const SHAPE_POLY_SET* outline = aZone->Outline();
1629 
1630  if( m_pcbSettings.m_zoneOutlines && outline && outline->OutlineCount() > 0 )
1631  {
1633  m_gal->SetIsFill( false );
1634  m_gal->SetIsStroke( true );
1636 
1637  // Draw each contour (main contour and holes)
1638 
1639  /* This line:
1640  * m_gal->DrawPolygon( *outline );
1641  * should be enough, but currently does not work to draw holes contours in a complex polygon
1642  * so each contour is draw as a simple polygon
1643  */
1644 
1645  // Draw the main contour
1646  m_gal->DrawPolyline( outline->COutline( 0 ) );
1647 
1648  // Draw holes
1649  int holes_count = outline->HoleCount( 0 );
1650 
1651  for( int ii = 0; ii < holes_count; ++ii )
1652  m_gal->DrawPolyline( outline->CHole( 0, ii ) );
1653 
1654  // Draw hatch lines
1655  for( const SEG& hatchLine : aZone->GetHatchLines() )
1656  m_gal->DrawLine( hatchLine.A, hatchLine.B );
1657  }
1658 
1659  // Draw the filling
1660  if( displayMode == ZONE_DISPLAY_MODE::SHOW_FILLED
1661  || displayMode == ZONE_DISPLAY_MODE::SHOW_FILLED_OUTLINE )
1662  {
1663  const SHAPE_POLY_SET& polySet = aZone->GetFilledPolysList( layer );
1664 
1665  if( polySet.OutlineCount() == 0 ) // Nothing to draw
1666  return;
1667 
1668  // Set up drawing options
1669  int outline_thickness = 0;
1670 
1671  if( aZone->GetFilledPolysUseThickness( layer ) )
1672  outline_thickness = aZone->GetMinThickness();
1673 
1675  m_gal->SetFillColor( color );
1676  m_gal->SetLineWidth( outline_thickness );
1677 
1678  if( displayMode == ZONE_DISPLAY_MODE::SHOW_FILLED )
1679  {
1680  m_gal->SetIsFill( true );
1681  m_gal->SetIsStroke( outline_thickness > 0 );
1682  }
1683  else if( displayMode == ZONE_DISPLAY_MODE::SHOW_FILLED_OUTLINE )
1684  {
1685  m_gal->SetIsFill( false );
1686  m_gal->SetIsStroke( true );
1687  }
1688 
1689  m_gal->DrawPolygon( polySet );
1690  }
1691 }
virtual void SetFillColor(const COLOR4D &aColor)
Set the fill color.
virtual void DrawPolyline(const std::deque< VECTOR2D > &aPointList)
Draw a polyline.
Virtual layers for stacking zones and tracks on a given copper layer.
Filled polygons are shown.
int OutlineCount() const
Return the number of vertices in a given outline/hole.
Outlines of filled polygons are shown.
SHAPE_POLY_SET * Outline()
Definition: zone.h:317
int color
Definition: DXF_plotter.cpp:60
virtual bool IsOnLayer(PCB_LAYER_ID) const override
Test to see if this object is on the given layer.
Definition: zone.cpp:314
const SHAPE_POLY_SET & GetFilledPolysList(PCB_LAYER_ID aLayer) const
Definition: zone.h:632
const SHAPE_LINE_CHAIN & CHole(int aOutline, int aHole) const
PCB_RENDER_SETTINGS m_pcbSettings
Definition: pcb_painter.h:295
virtual void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a line.
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.
PCB_LAYER_ID
A quick note on layer IDs:
int GetMinThickness() const
Definition: zone.h:241
const std::vector< SEG > & GetHatchLines() const
Definition: zone.h:797
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
Represent a set of closed polygons.
bool IsZoneLayer(LAYER_NUM aLayer)
int HoleCount(int aOutline) const
Return the reference to aIndex-th outline in the set.
Definition: seg.h:41
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
virtual void DrawPolygon(const std::deque< VECTOR2D > &aPointList)
Draw a polygon.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
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 SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
ZONE_DISPLAY_MODE m_zoneDisplayMode
Definition: pcb_painter.h:212
bool GetFilledPolysUseThickness() const
Definition: zone.h:686
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98

References SHAPE_POLY_SET::CHole(), color, SHAPE_POLY_SET::COutline(), KIGFX::GAL::DrawLine(), KIGFX::GAL::DrawPolygon(), KIGFX::GAL::DrawPolyline(), KIGFX::PCB_RENDER_SETTINGS::GetColor(), ZONE::GetFilledPolysList(), ZONE::GetFilledPolysUseThickness(), ZONE::GetHatchLines(), ZONE::GetMinThickness(), SHAPE_POLY_SET::HoleCount(), ZONE::IsOnLayer(), IsZoneLayer(), LAYER_ZONE_START, KIGFX::PAINTER::m_gal, KIGFX::RENDER_SETTINGS::m_outlineWidth, m_pcbSettings, KIGFX::PCB_RENDER_SETTINGS::m_zoneDisplayMode, KIGFX::PCB_RENDER_SETTINGS::m_zoneOutlines, ZONE::Outline(), SHAPE_POLY_SET::OutlineCount(), KIGFX::GAL::SetFillColor(), KIGFX::GAL::SetIsFill(), KIGFX::GAL::SetIsStroke(), KIGFX::GAL::SetLineWidth(), KIGFX::GAL::SetStrokeColor(), SHOW_FILLED, and SHOW_FILLED_OUTLINE.

◆ draw() [11/13]

void PCB_PAINTER::draw ( const DIMENSION_BASE aDimension,
int  aLayer 
)
protected

Definition at line 1694 of file pcb_painter.cpp.

1695 {
1696  const COLOR4D& strokeColor = m_pcbSettings.GetColor( aDimension, aLayer );
1697 
1698  m_gal->SetStrokeColor( strokeColor );
1699  m_gal->SetIsFill( false );
1700  m_gal->SetIsStroke( true );
1701 
1703  {
1704  // Outline mode
1706  }
1707  else
1708  {
1709  // Filled mode
1710  m_gal->SetLineWidth( getLineThickness( aDimension->GetLineThickness() ) );
1711  }
1712 
1713  // Draw dimension shapes
1714  // TODO(JE) lift this out
1715  for( const std::shared_ptr<SHAPE>& shape : aDimension->GetShapes() )
1716  {
1717  switch( shape->Type() )
1718  {
1719  case SH_SEGMENT:
1720  {
1721  const SEG& seg = static_cast<const SHAPE_SEGMENT*>( shape.get() )->GetSeg();
1722  m_gal->DrawLine( seg.A, seg.B );
1723  break;
1724  }
1725 
1726  case SH_CIRCLE:
1727  {
1728  int radius = static_cast<const SHAPE_CIRCLE*>( shape.get() )->GetRadius();
1729  m_gal->DrawCircle( shape->Centre(), radius );
1730  break;
1731  }
1732 
1733  default:
1734  break;
1735  }
1736  }
1737  // Draw text
1738  const PCB_TEXT& text = aDimension->Text();
1739  VECTOR2D position( text.GetTextPos().x, text.GetTextPos().y );
1740 
1742  {
1743  // Outline mode
1745  }
1746  else
1747  {
1748  // Filled mode
1749  m_gal->SetLineWidth( getLineThickness( text.GetEffectiveTextPenWidth() ) );
1750  }
1751 
1752  m_gal->SetTextAttributes( &text );
1753  m_gal->StrokeText( text.GetShownText(), position, text.GetTextAngleRadians() );
1754 }
virtual void SetTextAttributes(const EDA_TEXT *aText)
Loads attributes of the given text (bold/italic/underline/mirrored and so on).
Define a general 2D-vector/point.
Definition: vector2d.h:61
PCB_RENDER_SETTINGS m_pcbSettings
Definition: pcb_painter.h:295
virtual void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a line.
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.
int GetLineThickness() const
Definition: dimension.h:187
int getLineThickness(int aActualThickness) const
Get the thickness to draw for a line (e.g.
const std::vector< std::shared_ptr< SHAPE > > & GetShapes() const
Definition: dimension.h:215
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
virtual void StrokeText(const wxString &aText, const VECTOR2D &aPosition, double aRotationAngle)
Draw a vector type text using preloaded Newstroke font.
PCB_TEXT & Text()
Definition: dimension.h:209
circle
Definition: shape.h:46
Definition: seg.h:41
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
virtual void DrawCircle(const VECTOR2D &aCenterPoint, double aRadius)
Draw a circle using world coordinates.
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...
VECTOR2I A
Definition: seg.h:49
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
line segment
Definition: shape.h:44
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98
VECTOR2I B
Definition: seg.h:50

References SEG::A, SEG::B, KIGFX::GAL::DrawCircle(), KIGFX::GAL::DrawLine(), KIGFX::PCB_RENDER_SETTINGS::GetColor(), DIMENSION_BASE::GetLineThickness(), getLineThickness(), DIMENSION_BASE::GetShapes(), KIGFX::PAINTER::m_gal, KIGFX::RENDER_SETTINGS::m_outlineWidth, m_pcbSettings, KIGFX::PCB_RENDER_SETTINGS::m_sketchGraphics, KIGFX::PCB_RENDER_SETTINGS::m_sketchText, KIGFX::GAL::SetIsFill(), KIGFX::GAL::SetIsStroke(), KIGFX::GAL::SetLineWidth(), KIGFX::GAL::SetStrokeColor(), KIGFX::GAL::SetTextAttributes(), SH_CIRCLE, SH_SEGMENT, KIGFX::GAL::StrokeText(), DIMENSION_BASE::Text(), and text.

◆ draw() [12/13]

void PCB_PAINTER::draw ( const PCB_TARGET aTarget)
protected

Definition at line 1757 of file pcb_painter.cpp.

1758 {
1759  const COLOR4D& strokeColor = m_pcbSettings.GetColor( aTarget, aTarget->GetLayer() );
1760  VECTOR2D position( aTarget->GetPosition() );
1761  double size, radius;
1762 
1763  m_gal->SetLineWidth( getLineThickness( aTarget->GetWidth() ) );
1764  m_gal->SetStrokeColor( strokeColor );
1765  m_gal->SetIsFill( false );
1766  m_gal->SetIsStroke( true );
1767 
1768  m_gal->Save();
1769  m_gal->Translate( position );
1770 
1771  if( aTarget->GetShape() )
1772  {
1773  // shape x
1774  m_gal->Rotate( M_PI / 4.0 );
1775  size = 2.0 * aTarget->GetSize() / 3.0;
1776  radius = aTarget->GetSize() / 2.0;
1777  }
1778  else
1779  {
1780  // shape +
1781  size = aTarget->GetSize() / 2.0;
1782  radius = aTarget->GetSize() / 3.0;
1783  }
1784 
1785  m_gal->DrawLine( VECTOR2D( -size, 0.0 ), VECTOR2D( size, 0.0 ) );
1786  m_gal->DrawLine( VECTOR2D( 0.0, -size ), VECTOR2D( 0.0, size ) );
1787  m_gal->DrawCircle( VECTOR2D( 0.0, 0.0 ), radius );
1788 
1789  m_gal->Restore();
1790 }
int GetSize() const
Definition: pcb_target.h:67
Define a general 2D-vector/point.
Definition: vector2d.h:61
PCB_RENDER_SETTINGS m_pcbSettings
Definition: pcb_painter.h:295
virtual void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a line.
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.
virtual void Rotate(double aAngle)
Rotate the context.
wxPoint GetPosition() const override
Definition: pcb_target.h:61
int GetWidth() const
Definition: pcb_target.h:70
int getLineThickness(int aActualThickness) const
Get the thickness to draw for a line (e.g.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:622
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
virtual void Restore()
Restore the context.
virtual void DrawCircle(const VECTOR2D &aCenterPoint, double aRadius)
Draw a circle using world coordinates.
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...
int GetShape() const
Definition: pcb_target.h:64
virtual void Save()
Save the context.
virtual void Translate(const VECTOR2D &aTranslation)
Translate the context.
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:173
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98

References KIGFX::GAL::DrawCircle(), KIGFX::GAL::DrawLine(), KIGFX::PCB_RENDER_SETTINGS::GetColor(), BOARD_ITEM::GetLayer(), getLineThickness(), PCB_TARGET::GetPosition(), PCB_TARGET::GetShape(), PCB_TARGET::GetSize(), PCB_TARGET::GetWidth(), KIGFX::PAINTER::m_gal, m_pcbSettings, KIGFX::GAL::Restore(), KIGFX::GAL::Rotate(), KIGFX::GAL::Save(), KIGFX::GAL::SetIsFill(), KIGFX::GAL::SetIsStroke(), KIGFX::GAL::SetLineWidth(), KIGFX::GAL::SetStrokeColor(), and KIGFX::GAL::Translate().

◆ draw() [13/13]

void PCB_PAINTER::draw ( const PCB_MARKER aMarker,
int  aLayer 
)
protected

Definition at line 1793 of file pcb_painter.cpp.

1794 {
1795  bool isShadow = aLayer == LAYER_MARKER_SHADOWS;
1796 
1797  // Don't paint shadows for invisible markers.
1798  // It would be nice to do this through layer dependencies but we can't do an "or" there today
1799  if( isShadow && aMarker->GetBoard()
1800  && !aMarker->GetBoard()->IsElementVisible( aMarker->GetColorLayer() ) )
1801  {
1802  return;
1803  }
1804 
1805  SHAPE_LINE_CHAIN polygon;
1806  aMarker->ShapeToPolygon( polygon );
1807 
1809  : aMarker->GetColorLayer() );
1810 
1811  m_gal->Save();
1812  m_gal->Translate( aMarker->GetPosition() );
1813 
1814  if( isShadow )
1815  {
1817  m_gal->SetIsStroke( true );
1818  m_gal->SetLineWidth( aMarker->MarkerScale() );
1819  }
1820  else
1821  {
1822  m_gal->SetFillColor( color );
1823  m_gal->SetIsFill( true );
1824  }
1825 
1826  m_gal->DrawPolygon( polygon );
1827  m_gal->Restore();
1828 }
virtual void SetFillColor(const COLOR4D &aColor)
Set the fill color.
int color
Definition: DXF_plotter.cpp:60
PCB_RENDER_SETTINGS m_pcbSettings
Definition: pcb_painter.h:295
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.
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
virtual BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:46
GAL_LAYER_ID GetColorLayer() const
Definition: pcb_marker.cpp:179
bool IsElementVisible(GAL_LAYER_ID aLayer) const
Test whether a given element category is visible.
Definition: board.cpp:507
void ShapeToPolygon(SHAPE_LINE_CHAIN &aPolygon, int aScale=-1) const
Return the shape polygon in internal units in a SHAPE_LINE_CHAIN the coordinates are relatives to the...
int MarkerScale() const
The scaling factor to convert polygonal shape coordinates to internal units.
Definition: marker_base.h:66
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
virtual void Restore()
Restore the context.
virtual void DrawPolygon(const std::deque< VECTOR2D > &aPointList)
Draw a polygon.
SHAPE_LINE_CHAIN.
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 Save()
Save the context.
virtual void Translate(const VECTOR2D &aTranslation)
Translate the context.
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
wxPoint GetPosition() const override
Definition: pcb_marker.h:67
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98

References color, KIGFX::GAL::DrawPolygon(), BOARD_ITEM::GetBoard(), KIGFX::PCB_RENDER_SETTINGS::GetColor(), PCB_MARKER::GetColorLayer(), PCB_MARKER::GetPosition(), BOARD::IsElementVisible(), LAYER_MARKER_SHADOWS, KIGFX::PAINTER::m_gal, m_pcbSettings, MARKER_BASE::MarkerScale(), KIGFX::GAL::Restore(), KIGFX::GAL::Save(), KIGFX::GAL::SetFillColor(), KIGFX::GAL::SetIsFill(), KIGFX::GAL::SetIsStroke(), KIGFX::GAL::SetLineWidth(), KIGFX::GAL::SetStrokeColor(), MARKER_BASE::ShapeToPolygon(), and KIGFX::GAL::Translate().

◆ getDrillShape()

int PCB_PAINTER::getDrillShape ( const PAD aPad) const
protectedvirtual

Return drill shape of a pad.

Reimplemented in KIGFX::PCB_PRINT_PAINTER.

Definition at line 435 of file pcb_painter.cpp.

436 {
437  return aPad->GetDrillShape();
438 }
PAD_DRILL_SHAPE_T GetDrillShape() const
Definition: pad.h:354

References PAD::GetDrillShape().

Referenced by KIGFX::PCB_PRINT_PAINTER::getDrillShape().

◆ getDrillSize() [1/2]

VECTOR2D PCB_PAINTER::getDrillSize ( const PAD aPad) const
protectedvirtual

Return drill size for a pad (internal units).

Reimplemented in KIGFX::PCB_PRINT_PAINTER.

Definition at line 441 of file pcb_painter.cpp.

442 {
443  return VECTOR2D( aPad->GetDrillSize() );
444 }
const wxSize & GetDrillSize() const
Definition: pad.h:242
VECTOR2< double > VECTOR2D
Definition: vector2d.h:622

References PAD::GetDrillSize().

Referenced by draw(), and KIGFX::PCB_PRINT_PAINTER::getDrillSize().

◆ getDrillSize() [2/2]

int PCB_PAINTER::getDrillSize ( const VIA aVia) const
protectedvirtual

Return drill diameter for a via (internal units).

Reimplemented in KIGFX::PCB_PRINT_PAINTER.

Definition at line 447 of file pcb_painter.cpp.

448 {
449  return aVia->GetDrillValue();
450 }
int GetDrillValue() const
Function GetDrillValue "calculates" the drill value for vias (m-Drill if > 0, or default drill value ...
Definition: track.cpp:173

References VIA::GetDrillValue().

◆ getLineThickness()

int PCB_PAINTER::getLineThickness ( int  aActualThickness) const
protected

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 423 of file pcb_painter.cpp.

424 {
425  // if items have 0 thickness, draw them with the outline
426  // width, otherwise respect the set value (which, no matter
427  // how small will produce something)
428  if( aActualThickness == 0 )
430 
431  return aActualThickness;
432 }
PCB_RENDER_SETTINGS m_pcbSettings
Definition: pcb_painter.h:295

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

Referenced by draw().

◆ GetSettings()

virtual PCB_RENDER_SETTINGS* KIGFX::PCB_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 247 of file pcb_painter.h.

248  {
249  return &m_pcbSettings;
250  }
PCB_RENDER_SETTINGS m_pcbSettings
Definition: pcb_painter.h:295

References m_pcbSettings.

Referenced by APPEARANCE_CONTROLS::OnLayerAlphaChanged(), PCBNEW_PRINTOUT::setupPainter(), PANEL_DISPLAY_OPTIONS::TransferDataFromWindow(), PANEL_EDIT_OPTIONS::TransferDataFromWindow(), TRACK::ViewGetLOD(), VIA::ViewGetLOD(), and PAD::ViewGetLOD().

◆ 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_pcbSettings

PCB_RENDER_SETTINGS KIGFX::PCB_PAINTER::m_pcbSettings
protected

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