KiCad PCB EDA Suite
WS_DRAW_ITEM_POLYGON Class Reference

#include <worksheet_shape_builder.h>

Inheritance diagram for WS_DRAW_ITEM_POLYGON:
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_POLYGON (WORKSHEET_DATAITEM *aParent, wxPoint aPos, bool aFill, int aPenWidth, COLOR4D aColor)
 
int GetPenWidth () const
 
bool IsFilled () const
 
const wxPointGetPosition () const
 
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_POLYGON. More...
 
virtual bool HitTest (const wxPoint &aPosition) const override
 Virtual function return true if the point aPosition is inside one polygon. 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 (const wxPoint &aPosition) override
 return true if the point aPosition is on the starting point of this item. More...
 
COLOR4D GetColor () const
 
WS_DRAW_TYPE GetType () const
 
WORKSHEET_DATAITEMGetParent () const
 
virtual void DrawWsItem (EDA_RECT *aClipBox, wxDC *aDC)
 The function to draw a WS_DRAW_ITEM. More...
 
virtual bool HitTestEndPoint (const wxPoint &aPosition)
 return true if the point aPosition is near the ending point of this item This is avirtual function which should be overriden for items defien by 2 points the maxi dist is WORKSHEET_DATAITEM::GetMarkerSizeUi()/2 More...
 

Public Attributes

std::vector< wxPointm_Corners
 
int m_Flags
 

Protected Attributes

WS_DRAW_TYPE m_type
 
COLOR4D m_color
 
WORKSHEET_DATAITEMm_parent
 

Private Attributes

wxPoint m_pos
 
int m_penWidth
 
bool m_fill
 

Detailed Description

Definition at line 190 of file worksheet_shape_builder.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

WS_DRAW_ITEM_POLYGON::WS_DRAW_ITEM_POLYGON ( WORKSHEET_DATAITEM aParent,
wxPoint  aPos,
bool  aFill,
int  aPenWidth,
COLOR4D  aColor 
)
inline

Definition at line 202 of file worksheet_shape_builder.h.

203  :
204  WS_DRAW_ITEM_BASE( aParent, wsg_poly, aColor )
205  {
206  m_penWidth = aPenWidth;
207  m_fill = aFill;
208  m_pos = aPos;
209  }
WS_DRAW_ITEM_BASE(WORKSHEET_DATAITEM *aParent, WS_DRAW_TYPE aType, COLOR4D aColor)

Member Function Documentation

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.

References UNSPECIFIED_DRAWMODE.

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.
void WS_DRAW_ITEM_POLYGON::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_POLYGON.

Implements WS_DRAW_ITEM_BASE.

Definition at line 225 of file page_layout_graphic_items.cpp.

References color, FILLED_SHAPE, WS_DRAW_ITEM_BASE::GetColor(), GetPenWidth(), GR_COPY, GRPoly(), GRSetDrawMode(), IsFilled(), m_Corners, NO_FILL, UNSPECIFIED_DRAWMODE, wxPoint::x, and wxPoint::y.

227 {
228  std::vector<wxPoint> points_moved;
229  wxPoint *points;
230 
231  if( aOffset.x || aOffset.y )
232  {
233  for( auto point: m_Corners )
234  points_moved.push_back( point + aOffset );
235  points = &points_moved[0];
236  }
237  else
238  {
239  points = &m_Corners[0];
240  }
241 
242  auto color = ( aColor == COLOR4D::UNSPECIFIED ) ? GetColor() : aColor;
243 
244  GRSetDrawMode( aDC, ( aDrawMode == UNSPECIFIED_DRAWMODE ? GR_COPY : aDrawMode ) );
245  GRPoly( aClipBox, aDC,
246  m_Corners.size(), points,
248  GetPenWidth(),
249  color, color );
250  GRSetDrawMode( aDC, GR_COPY );
251 }
void GRPoly(EDA_RECT *ClipBox, wxDC *DC, int n, wxPoint Points[], bool Fill, int width, COLOR4D Color, COLOR4D BgColor)
Definition: gr_basic.cpp:767
void GRSetDrawMode(wxDC *DC, GR_DRAWMODE draw_mode)
Definition: gr_basic.cpp:290
COLOR4D GetColor() const
std::vector< wxPoint > m_Corners
WORKSHEET_DATAITEM* WS_DRAW_ITEM_BASE::GetParent ( void  ) const
inlineinherited
int WS_DRAW_ITEM_POLYGON::GetPenWidth ( ) const
inline

Definition at line 212 of file worksheet_shape_builder.h.

References m_penWidth.

Referenced by KIGFX::WORKSHEET_VIEWITEM::draw(), DrawWsItem(), and PlotWorkSheet().

const wxPoint& WS_DRAW_ITEM_POLYGON::GetPosition ( ) const
inline

Definition at line 214 of file worksheet_shape_builder.h.

References m_pos.

Referenced by WS_DRAW_ITEM_LIST::Draw(), and HitTestStartPoint().

214 { return m_pos; }
WS_DRAW_TYPE WS_DRAW_ITEM_BASE::GetType ( ) const
inlineinherited

Definition at line 85 of file worksheet_shape_builder.h.

References WS_DRAW_ITEM_BASE::m_type.

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

85 { return m_type; };
bool WS_DRAW_ITEM_POLYGON::HitTest ( const wxPoint aPosition) const
overridevirtual

Virtual function return true if the point aPosition is inside one polygon.

Implements WS_DRAW_ITEM_BASE.

Definition at line 254 of file page_layout_graphic_items.cpp.

References m_Corners, and TestPointInsidePolygon().

255 {
256  return TestPointInsidePolygon( &m_Corners[0],
257  m_Corners.size(), aPosition );
258 }
bool TestPointInsidePolygon(const CPOLYGONS_LIST &aPolysList, int aIdxstart, int aIdxend, int aRefx, int aRefy)
Function TestPointInsidePolygon test if a point is inside or outside a polygon.
std::vector< wxPoint > m_Corners
bool WS_DRAW_ITEM_POLYGON::HitTest ( const EDA_RECT aRect) const
overridevirtual

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

Implements WS_DRAW_ITEM_BASE.

Definition at line 261 of file page_layout_graphic_items.cpp.

References EDA_RECT::Intersects(), and m_Corners.

262 {
263  // Intersection of two polygons is nontrivial. Test if the rectangle intersects
264  // each line, instead.
265 
266  if( m_Corners.size() < 2 )
267  return false;
268 
269  for( size_t i = 1; i < m_Corners.size(); ++i )
270  {
271  if( aRect.Intersects( m_Corners[i - 1], m_Corners[i] ) )
272  return true;
273  }
274 
275  return false;
276 }
std::vector< wxPoint > m_Corners
bool Intersects(const EDA_RECT &aRect) const
Function Intersects tests for a common area between rectangles.
virtual bool WS_DRAW_ITEM_BASE::HitTestEndPoint ( const wxPoint aPosition)
inlinevirtualinherited

return true if the point aPosition is near the ending point of this item This is avirtual function which should be overriden for items defien by 2 points the maxi dist is WORKSHEET_DATAITEM::GetMarkerSizeUi()/2

Reimplemented in WS_DRAW_ITEM_RECT, and WS_DRAW_ITEM_LINE.

Definition at line 130 of file worksheet_shape_builder.h.

131  {
132  return false;
133  }
bool WS_DRAW_ITEM_POLYGON::HitTestStartPoint ( const wxPoint aPosition)
overridevirtual

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

Implements WS_DRAW_ITEM_BASE.

Definition at line 279 of file page_layout_graphic_items.cpp.

References abs, WORKSHEET_DATAITEM::GetMarkerSizeUi(), GetPosition(), wxPoint::x, and wxPoint::y.

280 {
281  wxPoint pos = GetPosition();
282 
283  if( std::abs( pos.x - aPosition.x) <= WORKSHEET_DATAITEM::GetMarkerSizeUi()/2 &&
284  std::abs( pos.y - aPosition.y) <= WORKSHEET_DATAITEM::GetMarkerSizeUi()/2 )
285  return true;
286 
287  return false;
288 }
#define abs(a)
Definition: auxiliary.h:84
const wxPoint & GetPosition() const
bool WS_DRAW_ITEM_POLYGON::IsFilled ( ) const
inline

Definition at line 213 of file worksheet_shape_builder.h.

References m_fill.

Referenced by KIGFX::WORKSHEET_VIEWITEM::draw(), DrawWsItem(), and PlotWorkSheet().

213 { return m_fill; }

Member Data Documentation

COLOR4D WS_DRAW_ITEM_BASE::m_color
protectedinherited

Definition at line 66 of file worksheet_shape_builder.h.

Referenced by WS_DRAW_ITEM_BASE::GetColor().

std::vector<wxPoint> WS_DRAW_ITEM_POLYGON::m_Corners
bool WS_DRAW_ITEM_POLYGON::m_fill
private

Definition at line 196 of file worksheet_shape_builder.h.

Referenced by IsFilled().

int WS_DRAW_ITEM_BASE::m_Flags
inherited

Definition at line 61 of file worksheet_shape_builder.h.

Referenced by PL_EDITOR_FRAME::Locate().

WORKSHEET_DATAITEM* WS_DRAW_ITEM_BASE::m_parent
protectedinherited

Definition at line 67 of file worksheet_shape_builder.h.

Referenced by WS_DRAW_ITEM_BASE::GetParent().

int WS_DRAW_ITEM_POLYGON::m_penWidth
private

Definition at line 195 of file worksheet_shape_builder.h.

Referenced by GetPenWidth().

wxPoint WS_DRAW_ITEM_POLYGON::m_pos
private

Definition at line 192 of file worksheet_shape_builder.h.

Referenced by GetPosition().

WS_DRAW_TYPE WS_DRAW_ITEM_BASE::m_type
protectedinherited

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