KiCad PCB EDA Suite
KIGFX::DS_PAINTER Class Reference

Methods for drawing worksheet 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 drawing worksheet 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 173 of file ds_painter.cpp.

174 {
175  auto item = dynamic_cast<const EDA_ITEM*>( aItem );
176 
177  if( !item )
178  return false;
179 
180  switch( item->Type() )
181  {
182  case WSG_LINE_T: draw( (DS_DRAW_ITEM_LINE*) item, aLayer ); break;
183  case WSG_POLY_T: draw( (DS_DRAW_ITEM_POLYPOLYGONS*) item, aLayer ); break;
184  case WSG_RECT_T: draw( (DS_DRAW_ITEM_RECT*) item, aLayer ); break;
185  case WSG_TEXT_T: draw( (DS_DRAW_ITEM_TEXT*) item, aLayer ); break;
186  case WSG_BITMAP_T: draw( (DS_DRAW_ITEM_BITMAP*) item, aLayer ); break;
187  case WSG_PAGE_T: draw( (DS_DRAW_ITEM_PAGE*) item, aLayer ); break;
188  default: return false;
189  }
190 
191  return true;
192 }
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:195

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 195 of file ds_painter.cpp.

196 {
197  m_gal->SetIsStroke( true );
198  m_gal->SetIsFill( false );
199  m_gal->SetStrokeColor( m_renderSettings.GetColor( aItem, aLayer ) );
201  m_gal->DrawLine( VECTOR2D( aItem->GetStart() ), VECTOR2D( aItem->GetEnd() ) );
202 }
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:622
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 205 of file ds_painter.cpp.

206 {
207  m_gal->SetIsStroke( true );
208  m_gal->SetIsFill( false );
209  m_gal->SetStrokeColor( m_renderSettings.GetColor( aItem, aLayer ) );
211  m_gal->DrawRectangle( VECTOR2D( aItem->GetStart() ), VECTOR2D( aItem->GetEnd() ) );
212 }
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:622
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 215 of file ds_painter.cpp.

216 {
217  m_gal->SetFillColor( m_renderSettings.GetColor( aItem, aLayer ) );
218  m_gal->SetIsFill( true );
219  m_gal->SetIsStroke( false );
220 
222 
223  for( int idx = 0; idx < item->GetPolygons().OutlineCount(); ++idx )
224  {
225  SHAPE_LINE_CHAIN& outline = item->GetPolygons().Outline( idx );
226  m_gal->DrawPolygon( outline );
227  }
228 }
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.
SHAPE_LINE_CHAIN.
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 231 of file ds_painter.cpp.

232 {
233  VECTOR2D position( aItem->GetTextPos().x, aItem->GetTextPos().y );
234  int penWidth = std::max( aItem->GetEffectiveTextPenWidth(),
236 
237  m_gal->Save();
238  m_gal->Translate( position );
239  m_gal->Rotate( -aItem->GetTextAngle() * M_PI / 1800.0 );
240  m_gal->SetStrokeColor( m_renderSettings.GetColor( aItem, aLayer ) );
241  m_gal->SetLineWidth( penWidth );
242  m_gal->SetTextAttributes( aItem );
243  m_gal->SetIsFill( false );
244  m_gal->SetIsStroke( true );
245  m_gal->StrokeText( aItem->GetShownText(), VECTOR2D( 0, 0 ), 0.0 );
246  m_gal->Restore();
247 }
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:181
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.
virtual void Rotate(double aAngle)
Rotate the context.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:622
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:254
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:141

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 250 of file ds_painter.cpp.

251 {
252  m_gal->Save();
253  auto* bitmap = static_cast<DS_DATA_ITEM_BITMAP*>( aItem->GetPeer() );
254 
255  VECTOR2D position = aItem->GetPosition();
256  m_gal->Translate( position );
257 
258  // When the image scale factor is not 1.0, we need to modify the actual scale
259  // as the image scale factor is similar to a local zoom
260  double img_scale = bitmap->m_ImageBitmap->GetScale();
261 
262  if( img_scale != 1.0 )
263  m_gal->Scale( VECTOR2D( img_scale, img_scale ) );
264 
265  m_gal->DrawBitmap( *bitmap->m_ImageBitmap );
266 
267 #if 0 // For bounding box debug purpose only
268  EDA_RECT bbox = aItem->GetBoundingBox();
269  m_gal->SetIsFill( true );
270  m_gal->SetIsStroke( true );
271  m_gal->SetFillColor( COLOR4D( 1, 1, 1, 0.4 ) );
272  m_gal->SetStrokeColor( COLOR4D( 0, 0, 0, 1 ) );
273 
274  if( img_scale != 1.0 )
275  m_gal->Scale( VECTOR2D( 1.0, 1.0 ) );
276 
277  m_gal->DrawRectangle( VECTOR2D( bbox.GetOrigin() ) - position,
278  VECTOR2D( bbox.GetEnd() ) - position );
279 #endif
280 
281  m_gal->Restore();
282 }
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:108
VECTOR2< double > VECTOR2D
Definition: vector2d.h:622
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
const wxPoint GetOrigin() const
Definition: eda_rect.h:106
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:98

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 285 of file ds_painter.cpp.

286 {
287  VECTOR2D origin = VECTOR2D( 0.0, 0.0 );
288  VECTOR2D end = VECTOR2D( aItem->GetPageSize().x,
289  aItem->GetPageSize().y );
290 
291  m_gal->SetIsStroke( true );
292 
293  // Use a gray color for the border color
295  m_gal->SetIsFill( false );
297 
298  m_gal->DrawRectangle( origin, end );
299 
300  // Draw the corner marker
301  double marker_size = aItem->GetMarkerSize();
302 
304  VECTOR2D pos = VECTOR2D( aItem->GetMarkerPos().x, aItem->GetMarkerPos().y );
305 
306  // Draw a circle and a X
307  m_gal->DrawCircle( pos, marker_size );
308  m_gal->DrawLine( VECTOR2D( pos.x - marker_size, pos.y - marker_size),
309  VECTOR2D( pos.x + marker_size, pos.y + marker_size ) );
310  m_gal->DrawLine( VECTOR2D( pos.x + marker_size, pos.y - marker_size),
311  VECTOR2D( pos.x - marker_size, pos.y + marker_size ) );
312 }
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:622
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 315 of file ds_painter.cpp.

316 {
317  VECTOR2D origin = VECTOR2D( 0.0, 0.0 );
318  VECTOR2D end = VECTOR2D( aPageInfo->GetWidthMils() * aScaleFactor,
319  aPageInfo->GetHeightMils() * aScaleFactor );
320 
321  m_gal->SetIsStroke( true );
322  // Use a gray color for the border color
324  m_gal->SetIsFill( false );
325  m_gal->DrawRectangle( origin, end );
326 }
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:622
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: