KiCad PCB EDA Suite
WS_DRAW_ITEM_RECT Class Reference

#include <worksheet_shape_builder.h>

Inheritance diagram for WS_DRAW_ITEM_RECT:
WS_DRAW_ITEM_LINE WS_DRAW_ITEM_BASE

Public Types

enum  WS_DRAW_TYPE {
  wsg_line, wsg_rect, wsg_poly, wsg_text,
  wsg_bitmap
}
 

Public Member Functions

 WS_DRAW_ITEM_RECT (WORKSHEET_DATAITEM *aParent, wxPoint aStart, wxPoint aEnd, int aPenWidth, COLOR4D aColor)
 
virtual void DrawWsItem (EDA_RECT *aClipBox, wxDC *aDC, const wxPoint &aOffset, GR_DRAWMODE aDrawMode, COLOR4D aColor=COLOR4D::UNSPECIFIED) override
 The function to draw a WS_DRAW_ITEM_RECT. More...
 
virtual bool HitTest (const wxPoint &aPosition) const override
 Virtual function return true if the point aPosition is on one edge of the rectangle. More...
 
virtual bool HitTest (const EDA_RECT &aRect) const override
 Virtual function return true if the rect aRect intersects on the item. More...
 
virtual bool HitTestStartPoint (wxDC *aDC, const wxPoint &aPosition) override
 return true if the point aPosition is on the starting point of this item. More...
 
virtual bool HitTestEndPoint (wxDC *aDC, const wxPoint &aPosition) override
 return true if the point aPosition is on the ending point of this item This is avirtual function which should be overriden for items defien by 2 points More...
 
int GetPenWidth () const
 
const wxPoint & GetStart () const
 
const wxPoint & GetEnd () const
 
virtual void DrawWsItem (EDA_RECT *aClipBox, wxDC *aDC)
 The function to draw a WS_DRAW_ITEM. More...
 
COLOR4D GetColor () const
 
WS_DRAW_TYPE GetType () const
 
WORKSHEET_DATAITEMGetParent () const
 

Public Attributes

int m_Flags
 

Protected Attributes

WS_DRAW_TYPE m_type
 
COLOR4D m_color
 
WORKSHEET_DATAITEMm_parent
 

Detailed Description

Definition at line 240 of file worksheet_shape_builder.h.

Member Enumeration Documentation

◆ WS_DRAW_TYPE

Constructor & Destructor Documentation

◆ WS_DRAW_ITEM_RECT()

WS_DRAW_ITEM_RECT::WS_DRAW_ITEM_RECT ( WORKSHEET_DATAITEM aParent,
wxPoint  aStart,
wxPoint  aEnd,
int  aPenWidth,
COLOR4D  aColor 
)
inline

Definition at line 243 of file worksheet_shape_builder.h.

245  :
246  WS_DRAW_ITEM_LINE( aParent, aStart, aEnd, aPenWidth, aColor )
247  {
248  m_type = wsg_rect;
249  }
WS_DRAW_ITEM_LINE(WORKSHEET_DATAITEM *aParent, wxPoint aStart, wxPoint aEnd, int aPenWidth, COLOR4D aColor)

References WS_DRAW_ITEM_BASE::m_type, and WS_DRAW_ITEM_BASE::wsg_rect.

Member Function Documentation

◆ DrawWsItem() [1/2]

virtual void WS_DRAW_ITEM_BASE::DrawWsItem ( EDA_RECT aClipBox,
wxDC *  aDC 
)
inlinevirtualinherited

The function to draw a WS_DRAW_ITEM.

Definition at line 91 of file worksheet_shape_builder.h.

92  {
93  wxPoint offset( 0, 0 );
94  DrawWsItem( aClipBox, aDC, offset, UNSPECIFIED_DRAWMODE, COLOR4D::UNSPECIFIED );
95  }
virtual void DrawWsItem(EDA_RECT *aClipBox, wxDC *aDC)
The function to draw a WS_DRAW_ITEM.

References UNSPECIFIED_DRAWMODE.

◆ DrawWsItem() [2/2]

void WS_DRAW_ITEM_RECT::DrawWsItem ( EDA_RECT aClipBox,
wxDC *  aDC,
const wxPoint &  aOffset,
GR_DRAWMODE  aDrawMode,
COLOR4D  aColor = COLOR4D::UNSPECIFIED 
)
overridevirtual

The function to draw a WS_DRAW_ITEM_RECT.

Reimplemented from WS_DRAW_ITEM_LINE.

Definition at line 302 of file page_layout_graphic_items.cpp.

304 {
305  GRSetDrawMode( aDC, ( aDrawMode == UNSPECIFIED_DRAWMODE ? GR_COPY : aDrawMode ) );
306  GRRect( aClipBox, aDC,
307  GetStart().x + aOffset.x, GetStart().y + aOffset.y,
308  GetEnd().x + aOffset.x, GetEnd().y + aOffset.y,
309  GetPenWidth(),
310  ( aColor == COLOR4D::UNSPECIFIED ) ? GetColor() : aColor );
311  GRSetDrawMode( aDC, GR_COPY );
312 }
void GRSetDrawMode(wxDC *DC, GR_DRAWMODE draw_mode)
Definition: gr_basic.cpp:223
const wxPoint & GetEnd() const
void GRRect(EDA_RECT *aClipBox, wxDC *aDC, int x1, int y1, int x2, int y2, COLOR4D aColor)
Definition: gr_basic.cpp:1003
const wxPoint & GetStart() const

References WS_DRAW_ITEM_BASE::GetColor(), WS_DRAW_ITEM_LINE::GetEnd(), WS_DRAW_ITEM_LINE::GetPenWidth(), WS_DRAW_ITEM_LINE::GetStart(), GR_COPY, GRRect(), GRSetDrawMode(), and UNSPECIFIED_DRAWMODE.

◆ GetColor()

◆ GetEnd()

◆ GetParent()

WORKSHEET_DATAITEM* WS_DRAW_ITEM_BASE::GetParent ( void  ) const
inlineinherited

◆ GetPenWidth()

int WS_DRAW_ITEM_LINE::GetPenWidth ( ) const
inlineinherited

◆ GetStart()

◆ GetType()

WS_DRAW_TYPE WS_DRAW_ITEM_BASE::GetType ( ) const
inlineinherited

Definition at line 85 of file worksheet_shape_builder.h.

85 { return m_type; };

References WS_DRAW_ITEM_BASE::m_type.

Referenced by KIGFX::WORKSHEET_VIEWITEM::ViewDraw().

◆ HitTest() [1/2]

bool WS_DRAW_ITEM_RECT::HitTest ( const wxPoint &  aPosition) const
overridevirtual

Virtual function return true if the point aPosition is on one edge of the rectangle.

Reimplemented from WS_DRAW_ITEM_LINE.

Definition at line 315 of file page_layout_graphic_items.cpp.

316 {
317  int dist = GetPenWidth()/2;
318  wxPoint start = GetStart();
319  wxPoint end;
320  end.x = GetEnd().x;
321  end.y = start.y;
322 
323  // Upper line
324  if( TestSegmentHit( aPosition, start, end, dist ) )
325  return true;
326 
327  // Right line
328  start = end;
329  end.y = GetEnd().y;
330  if( TestSegmentHit( aPosition, start, end, dist ) )
331  return true;
332 
333  // lower line
334  start = end;
335  end.x = GetStart().x;
336  if( TestSegmentHit( aPosition, start, end, dist ) )
337  return true;
338 
339  // left line
340  start = end;
341  end = GetStart();
342  if( TestSegmentHit( aPosition, start, end, dist ) )
343  return true;
344 
345  return false;
346 }
static const int dist[10][10]
Definition: ar_matrix.cpp:320
const wxPoint & GetEnd() const
const wxPoint & GetStart() const
bool TestSegmentHit(const wxPoint &aRefPoint, wxPoint aStart, wxPoint aEnd, int aDist)
Function TestSegmentHit test for hit on line segment i.e.
Definition: trigo.cpp:122

References dist, WS_DRAW_ITEM_LINE::GetEnd(), WS_DRAW_ITEM_LINE::GetPenWidth(), WS_DRAW_ITEM_LINE::GetStart(), and TestSegmentHit().

◆ HitTest() [2/2]

bool WS_DRAW_ITEM_RECT::HitTest ( const EDA_RECT aRect) const
overridevirtual

Virtual function return true if the rect aRect intersects on the item.

Reimplemented from WS_DRAW_ITEM_LINE.

Definition at line 349 of file page_layout_graphic_items.cpp.

350 {
351  wxPoint start = GetStart();
352  wxPoint end;
353  end.x = GetEnd().x;
354  end.y = start.y;
355 
356  // Upper line
357  if( aRect.Intersects( start, end ) )
358  return true;
359 
360  // Right line
361  start = end;
362  end.y = GetEnd().y;
363  if( aRect.Intersects( start, end ) )
364  return true;
365 
366  // lower line
367  start = end;
368  end.x = GetStart().x;
369  if( aRect.Intersects( start, end ) )
370  return true;
371 
372  // left line
373  start = end;
374  end = GetStart();
375  if( aRect.Intersects( start, end ) )
376  return true;
377 
378  return false;
379 }
const wxPoint & GetEnd() const
const wxPoint & GetStart() const
bool Intersects(const EDA_RECT &aRect) const
Function Intersects tests for a common area between rectangles.

References WS_DRAW_ITEM_LINE::GetEnd(), WS_DRAW_ITEM_LINE::GetStart(), and EDA_RECT::Intersects().

◆ HitTestEndPoint()

bool WS_DRAW_ITEM_RECT::HitTestEndPoint ( wxDC *  aDC,
const wxPoint &  aPosition 
)
overridevirtual

return true if the point aPosition is on the ending point of this item This is avirtual function which should be overriden for items defien by 2 points

Reimplemented from WS_DRAW_ITEM_LINE.

Definition at line 395 of file page_layout_graphic_items.cpp.

396 {
397  wxPoint pos = GetEnd();
398  int marker_size = WORKSHEET_DATAITEM::GetMarkerSizeUi( getScaleFromZoom( aDC ) );
399 
400  int dist = (int) hypot( pos.x - aPosition.x, pos.y - aPosition.y );
401 
402  if( dist <= marker_size / 2 )
403  return true;
404 
405  return false;
406 }
static const int dist[10][10]
Definition: ar_matrix.cpp:320
const wxPoint & GetEnd() const
static double getScaleFromZoom(wxDC *aDC)
static int GetMarkerSizeUi(double aZoomScale=1.0)

References dist, WS_DRAW_ITEM_LINE::GetEnd(), WORKSHEET_DATAITEM::GetMarkerSizeUi(), and getScaleFromZoom().

◆ HitTestStartPoint()

bool WS_DRAW_ITEM_RECT::HitTestStartPoint ( wxDC *  aDC,
const wxPoint &  aPosition 
)
overridevirtual

return true if the point aPosition is on the starting point of this item.

Reimplemented from WS_DRAW_ITEM_LINE.

Definition at line 382 of file page_layout_graphic_items.cpp.

383 {
384  wxPoint dist = GetStart() - aPosition;
385  int marker_size = WORKSHEET_DATAITEM::GetMarkerSizeUi( getScaleFromZoom( aDC ) );
386 
387  if( std::abs( dist.x) <= marker_size / 2 &&
388  std::abs( dist.y) <= marker_size / 2 )
389  return true;
390 
391  return false;
392 }
static const int dist[10][10]
Definition: ar_matrix.cpp:320
#define abs(a)
Definition: auxiliary.h:84
const wxPoint & GetStart() const
static double getScaleFromZoom(wxDC *aDC)
static int GetMarkerSizeUi(double aZoomScale=1.0)

References abs, dist, WORKSHEET_DATAITEM::GetMarkerSizeUi(), getScaleFromZoom(), and WS_DRAW_ITEM_LINE::GetStart().

Member Data Documentation

◆ m_color

COLOR4D WS_DRAW_ITEM_BASE::m_color
protectedinherited

◆ m_Flags

int WS_DRAW_ITEM_BASE::m_Flags
inherited

◆ m_parent

WORKSHEET_DATAITEM* WS_DRAW_ITEM_BASE::m_parent
protectedinherited

◆ m_type

WS_DRAW_TYPE WS_DRAW_ITEM_BASE::m_type
protectedinherited

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