KiCad PCB EDA Suite
KIGFX::DS_PAINTER Class Reference

Methods for painting drawing sheet items. More...

#include <ds_painter.h>

Inheritance diagram for KIGFX::DS_PAINTER:
KIGFX::PAINTER

Public Member Functions

 DS_PAINTER (GAL *aGal)
 
virtual bool Draw (const VIEW_ITEM *, int) override
 Takes an instance of VIEW_ITEM and passes it to a function that knows how to draw the item. More...
 
void DrawBorder (const PAGE_INFO *aPageInfo, int aScaleFactor) const
 
virtual RENDER_SETTINGSGetSettings () override
 Return a pointer to current settings that are going to be used when drawing items. More...
 
void SetGAL (GAL *aGal)
 Changes Graphics Abstraction Layer used for drawing items for a new one. More...
 

Protected Attributes

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

Private Member Functions

void draw (const DS_DRAW_ITEM_LINE *aItem, int aLayer) const
 
void draw (const DS_DRAW_ITEM_RECT *aItem, int aLayer) const
 
void draw (const DS_DRAW_ITEM_POLYPOLYGONS *aItem, int aLayer) const
 
void draw (const DS_DRAW_ITEM_TEXT *aItem, int aLayer) const
 
void draw (const DS_DRAW_ITEM_BITMAP *aItem, int aLayer) const
 
void draw (const DS_DRAW_ITEM_PAGE *aItem, int aLayer) const
 

Private Attributes

DS_RENDER_SETTINGS m_renderSettings
 

Detailed Description

Methods for painting drawing sheet items.

Definition at line 98 of file ds_painter.h.

Constructor & Destructor Documentation

◆ DS_PAINTER()

KIGFX::DS_PAINTER::DS_PAINTER ( GAL aGal)
inline

Definition at line 101 of file ds_painter.h.

101  :
102  PAINTER( aGal )
103  { }
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 KIGFX::DS_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 172 of file ds_painter.cpp.

173 {
174  auto item = dynamic_cast<const EDA_ITEM*>( aItem );
175 
176  if( !item )
177  return false;
178 
179  switch( item->Type() )
180  {
181  case WSG_LINE_T: draw( (DS_DRAW_ITEM_LINE*) item, aLayer ); break;
182  case WSG_POLY_T: draw( (DS_DRAW_ITEM_POLYPOLYGONS*) item, aLayer ); break;
183  case WSG_RECT_T: draw( (DS_DRAW_ITEM_RECT*) item, aLayer ); break;
184  case WSG_TEXT_T: draw( (DS_DRAW_ITEM_TEXT*) item, aLayer ); break;
185  case WSG_BITMAP_T: draw( (DS_DRAW_ITEM_BITMAP*) item, aLayer ); break;
186  case WSG_PAGE_T: draw( (DS_DRAW_ITEM_PAGE*) item, aLayer ); break;
187  default: return false;
188  }
189 
190  return true;
191 }
A graphic text.
Definition: ds_draw_item.h:297
A rectangle with thick segment showing the page limits and a marker showing the coordinate origin.
Definition: ds_draw_item.h:252
Non filled rectangle with thick segment.
Definition: ds_draw_item.h:205
void draw(const DS_DRAW_ITEM_LINE *aItem, int aLayer) const
Definition: ds_painter.cpp:194

References WSG_BITMAP_T, WSG_LINE_T, WSG_PAGE_T, WSG_POLY_T, WSG_RECT_T, and WSG_TEXT_T.

Referenced by DS_PROXY_VIEW_ITEM::ViewDraw().

◆ draw() [1/6]

void KIGFX::DS_PAINTER::draw ( const DS_DRAW_ITEM_LINE aItem,
int  aLayer 
) const
private

Definition at line 194 of file ds_painter.cpp.

195 {
196  m_gal->SetIsStroke( true );
197  m_gal->SetIsFill( false );
198  m_gal->SetStrokeColor( m_renderSettings.GetColor( aItem, aLayer ) );
200  m_gal->DrawLine( VECTOR2D( aItem->GetStart() ), VECTOR2D( aItem->GetEnd() ) );
201 }
DS_RENDER_SETTINGS m_renderSettings
Definition: ds_painter.h:122
virtual void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a line.
const wxPoint & GetStart() const
Definition: ds_draw_item.h:133
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.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:621
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
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...
Definition: ds_painter.cpp:71
int GetDefaultPenWidth() const
virtual int GetPenWidth() const
Definition: ds_draw_item.h:70
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
const wxPoint & GetEnd() const
Definition: ds_draw_item.h:135

References DS_DRAW_ITEM_LINE::GetEnd(), DS_DRAW_ITEM_BASE::GetPenWidth(), and DS_DRAW_ITEM_LINE::GetStart().

◆ draw() [2/6]

void KIGFX::DS_PAINTER::draw ( const DS_DRAW_ITEM_RECT aItem,
int  aLayer 
) const
private

Definition at line 204 of file ds_painter.cpp.

205 {
206  m_gal->SetIsStroke( true );
207  m_gal->SetIsFill( false );
208  m_gal->SetStrokeColor( m_renderSettings.GetColor( aItem, aLayer ) );
210  m_gal->DrawRectangle( VECTOR2D( aItem->GetStart() ), VECTOR2D( aItem->GetEnd() ) );
211 }
virtual void DrawRectangle(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a rectangle.
DS_RENDER_SETTINGS m_renderSettings
Definition: ds_painter.h:122
const wxPoint & GetStart() const
Definition: ds_draw_item.h:219
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.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:621
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
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...
Definition: ds_painter.cpp:71
int GetDefaultPenWidth() const
const wxPoint & GetEnd() const
Definition: ds_draw_item.h:221
virtual int GetPenWidth() const
Definition: ds_draw_item.h:70
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.

References DS_DRAW_ITEM_RECT::GetEnd(), DS_DRAW_ITEM_BASE::GetPenWidth(), and DS_DRAW_ITEM_RECT::GetStart().

◆ draw() [3/6]

void KIGFX::DS_PAINTER::draw ( const DS_DRAW_ITEM_POLYPOLYGONS aItem,
int  aLayer 
) const
private

Definition at line 214 of file ds_painter.cpp.

215 {
216  m_gal->SetFillColor( m_renderSettings.GetColor( aItem, aLayer ) );
217  m_gal->SetIsFill( true );
218  m_gal->SetIsStroke( false );
219 
221 
222  for( int idx = 0; idx < item->GetPolygons().OutlineCount(); ++idx )
223  {
224  SHAPE_LINE_CHAIN& outline = item->GetPolygons().Outline( idx );
225  m_gal->DrawPolygon( outline );
226  }
227 }
virtual void SetFillColor(const COLOR4D &aColor)
Set the fill color.
int OutlineCount() const
Return the number of vertices in a given outline/hole.
DS_RENDER_SETTINGS m_renderSettings
Definition: ds_painter.h:122
GAL * m_gal
Instance of graphic abstraction layer that gives an interface to call commands used to draw (eg.
Definition: painter.h:101
SHAPE_POLY_SET & GetPolygons()
Definition: ds_draw_item.h:170
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
SHAPE_LINE_CHAIN & Outline(int aIndex)
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...
Definition: ds_painter.cpp:71
virtual void DrawPolygon(const std::deque< VECTOR2D > &aPointList)
Draw a polygon.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.

References DS_DRAW_ITEM_POLYPOLYGONS::GetPolygons(), SHAPE_POLY_SET::Outline(), and SHAPE_POLY_SET::OutlineCount().

◆ draw() [4/6]

void KIGFX::DS_PAINTER::draw ( const DS_DRAW_ITEM_TEXT aItem,
int  aLayer 
) const
private

Definition at line 230 of file ds_painter.cpp.

231 {
232  VECTOR2D position( aItem->GetTextPos().x, aItem->GetTextPos().y );
233  int penWidth = std::max( aItem->GetEffectiveTextPenWidth(),
235 
236  m_gal->Save();
237  m_gal->Translate( position );
238  m_gal->Rotate( -aItem->GetTextAngle() * M_PI / 1800.0 );
239  m_gal->SetStrokeColor( m_renderSettings.GetColor( aItem, aLayer ) );
240  m_gal->SetLineWidth( penWidth );
241  m_gal->SetTextAttributes( aItem );
242  m_gal->SetIsFill( false );
243  m_gal->SetIsStroke( true );
244  m_gal->StrokeText( aItem->GetShownText(), VECTOR2D( 0, 0 ), 0.0 );
245  m_gal->Restore();
246 }
virtual void SetTextAttributes(const EDA_TEXT *aText)
Loads attributes of the given text (bold/italic/underline/mirrored and so on).
DS_RENDER_SETTINGS m_renderSettings
Definition: ds_painter.h:122
double GetTextAngle() const
Definition: eda_text.h:195
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:159
virtual void SetLineWidth(float aLineWidth)
Set the line width.
virtual void Rotate(double aAngle)
Rotate the context.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:621
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...
Definition: ds_painter.cpp:71
virtual void Restore()
Restore the context.
int GetDefaultPenWidth() const
const wxPoint & GetTextPos() const
Definition: eda_text.h:268
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 wxString GetShownText(int aDepth=0) const
Return the string actually shown after processing of the base text.
Definition: eda_text.h:162

References EDA_TEXT::GetEffectiveTextPenWidth(), EDA_TEXT::GetShownText(), EDA_TEXT::GetTextAngle(), EDA_TEXT::GetTextPos(), and VECTOR2< T >::Rotate().

◆ draw() [5/6]

void KIGFX::DS_PAINTER::draw ( const DS_DRAW_ITEM_BITMAP aItem,
int  aLayer 
) const
private

Definition at line 249 of file ds_painter.cpp.

250 {
251  m_gal->Save();
252  auto* bitmap = static_cast<DS_DATA_ITEM_BITMAP*>( aItem->GetPeer() );
253 
254  VECTOR2D position = aItem->GetPosition();
255  m_gal->Translate( position );
256 
257  // When the image scale factor is not 1.0, we need to modify the actual scale
258  // as the image scale factor is similar to a local zoom
259  double img_scale = bitmap->m_ImageBitmap->GetScale();
260 
261  if( img_scale != 1.0 )
262  m_gal->Scale( VECTOR2D( img_scale, img_scale ) );
263 
264  m_gal->DrawBitmap( *bitmap->m_ImageBitmap );
265 
266 #if 0 // For bounding box debug purpose only
267  EDA_RECT bbox = aItem->GetBoundingBox();
268  m_gal->SetIsFill( true );
269  m_gal->SetIsStroke( true );
270  m_gal->SetFillColor( COLOR4D( 1, 1, 1, 0.4 ) );
271  m_gal->SetStrokeColor( COLOR4D( 0, 0, 0, 1 ) );
272 
273  if( img_scale != 1.0 )
274  m_gal->Scale( VECTOR2D( 1.0, 1.0 ) );
275 
276  m_gal->DrawRectangle( VECTOR2D( bbox.GetOrigin() ) - position,
277  VECTOR2D( bbox.GetEnd() ) - position );
278 #endif
279 
280  m_gal->Restore();
281 }
virtual void SetFillColor(const COLOR4D &aColor)
Set the fill color.
virtual void DrawRectangle(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a rectangle.
wxPoint GetPosition() const override
Definition: ds_draw_item.h:350
virtual void DrawBitmap(const BITMAP_BASE &aBitmap)
Draw a bitmap image.
const EDA_RECT GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
GAL * m_gal
Instance of graphic abstraction layer that gives an interface to call commands used to draw (eg.
Definition: painter.h:101
const wxPoint GetEnd() const
Definition: eda_rect.h:112
VECTOR2< double > VECTOR2D
Definition: vector2d.h:621
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
const wxPoint GetOrigin() const
Definition: eda_rect.h:110
virtual void Scale(const VECTOR2D &aScale)
Scale the context.
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
DS_DATA_ITEM * GetPeer() const
Definition: ds_draw_item.h:63
virtual void Restore()
Restore the context.
Handle the component boundary box.
Definition: eda_rect.h:42
virtual void Save()
Save the context.
virtual void Translate(const VECTOR2D &aTranslation)
Translate the context.
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103

References DS_DRAW_ITEM_BITMAP::GetBoundingBox(), EDA_RECT::GetEnd(), EDA_RECT::GetOrigin(), DS_DRAW_ITEM_BASE::GetPeer(), and DS_DRAW_ITEM_BITMAP::GetPosition().

◆ draw() [6/6]

void KIGFX::DS_PAINTER::draw ( const DS_DRAW_ITEM_PAGE aItem,
int  aLayer 
) const
private

Definition at line 284 of file ds_painter.cpp.

285 {
286  VECTOR2D origin = VECTOR2D( 0.0, 0.0 );
287  VECTOR2D end = VECTOR2D( aItem->GetPageSize().x,
288  aItem->GetPageSize().y );
289 
290  m_gal->SetIsStroke( true );
291 
292  // Use a gray color for the border color
294  m_gal->SetIsFill( false );
296 
297  m_gal->DrawRectangle( origin, end );
298 
299  // Draw the corner marker
300  double marker_size = aItem->GetMarkerSize();
301 
303  VECTOR2D pos = VECTOR2D( aItem->GetMarkerPos().x, aItem->GetMarkerPos().y );
304 
305  // Draw a circle and a X
306  m_gal->DrawCircle( pos, marker_size );
307  m_gal->DrawLine( VECTOR2D( pos.x - marker_size, pos.y - marker_size),
308  VECTOR2D( pos.x + marker_size, pos.y + marker_size ) );
309  m_gal->DrawLine( VECTOR2D( pos.x + marker_size, pos.y - marker_size),
310  VECTOR2D( pos.x - marker_size, pos.y + marker_size ) );
311 }
virtual void DrawRectangle(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a rectangle.
const wxPoint & GetMarkerPos() const
Definition: ds_draw_item.h:266
DS_RENDER_SETTINGS m_renderSettings
Definition: ds_painter.h:122
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.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:621
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
wxSize GetPageSize() const
Definition: ds_draw_item.h:265
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
double GetMarkerSize() const
Definition: ds_draw_item.h:268
virtual void DrawCircle(const VECTOR2D &aCenterPoint, double aRadius)
Draw a circle using world coordinates.
int GetDefaultPenWidth() const
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.

References DS_DRAW_ITEM_PAGE::GetMarkerPos(), DS_DRAW_ITEM_PAGE::GetMarkerSize(), DS_DRAW_ITEM_PAGE::GetPageSize(), VECTOR2< T >::x, and VECTOR2< T >::y.

◆ DrawBorder()

void KIGFX::DS_PAINTER::DrawBorder ( const PAGE_INFO aPageInfo,
int  aScaleFactor 
) const

Definition at line 314 of file ds_painter.cpp.

315 {
316  VECTOR2D origin = VECTOR2D( 0.0, 0.0 );
317  VECTOR2D end = VECTOR2D( aPageInfo->GetWidthMils() * aScaleFactor,
318  aPageInfo->GetHeightMils() * aScaleFactor );
319 
320  m_gal->SetIsStroke( true );
321  // Use a gray color for the border color
323  m_gal->SetIsFill( false );
324  m_gal->DrawRectangle( origin, end );
325 }
virtual void DrawRectangle(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a rectangle.
int GetHeightMils() const
Definition: page_info.h:133
DS_RENDER_SETTINGS m_renderSettings
Definition: ds_painter.h:122
GAL * m_gal
Instance of graphic abstraction layer that gives an interface to call commands used to draw (eg.
Definition: painter.h:101
VECTOR2< double > VECTOR2D
Definition: vector2d.h:621
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
int GetWidthMils() const
Definition: page_info.h:130

References PAGE_INFO::GetHeightMils(), and PAGE_INFO::GetWidthMils().

Referenced by DS_PROXY_VIEW_ITEM::ViewDraw().

◆ GetSettings()

virtual RENDER_SETTINGS* KIGFX::DS_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 111 of file ds_painter.h.

111 { return &m_renderSettings; }
DS_RENDER_SETTINGS m_renderSettings
Definition: ds_painter.h:122

References m_renderSettings.

Referenced by DS_PROXY_VIEW_ITEM::ViewDraw().

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

DS_RENDER_SETTINGS KIGFX::DS_PAINTER::m_renderSettings
private

Definition at line 122 of file ds_painter.h.

Referenced by GetSettings().


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