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 wxPoint GetPosition () 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 (wxDC *aDC, 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 (wxDC *aDC, 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< wxPoint > m_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

◆ WS_DRAW_TYPE

Constructor & Destructor Documentation

◆ WS_DRAW_ITEM_POLYGON()

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)

References m_fill, m_penWidth, and m_pos.

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_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 235 of file page_layout_graphic_items.cpp.

237 {
238  std::vector<wxPoint> points_moved;
239  wxPoint *points;
240 
241  if( aOffset.x || aOffset.y )
242  {
243  for( auto point: m_Corners )
244  points_moved.push_back( point + aOffset );
245  points = &points_moved[0];
246  }
247  else
248  {
249  points = &m_Corners[0];
250  }
251 
252  auto color = ( aColor == COLOR4D::UNSPECIFIED ) ? GetColor() : aColor;
253 
254  GRSetDrawMode( aDC, ( aDrawMode == UNSPECIFIED_DRAWMODE ? GR_COPY : aDrawMode ) );
255  GRPoly( aClipBox, aDC,
256  m_Corners.size(), points,
258  GetPenWidth(),
259  color, color );
260  GRSetDrawMode( aDC, GR_COPY );
261 }
void GRPoly(EDA_RECT *ClipBox, wxDC *DC, int n, wxPoint Points[], bool Fill, int width, COLOR4D Color, COLOR4D BgColor)
Definition: gr_basic.cpp:701
void GRSetDrawMode(wxDC *DC, GR_DRAWMODE draw_mode)
Definition: gr_basic.cpp:223
int color
Definition: DXF_plotter.cpp:62
std::vector< wxPoint > m_Corners

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

◆ GetColor()

◆ GetParent()

WORKSHEET_DATAITEM* WS_DRAW_ITEM_BASE::GetParent ( void  ) const
inlineinherited

◆ GetPenWidth()

int WS_DRAW_ITEM_POLYGON::GetPenWidth ( ) const
inline

◆ GetPosition()

const wxPoint WS_DRAW_ITEM_POLYGON::GetPosition ( ) const
inline

Definition at line 214 of file worksheet_shape_builder.h.

214 { return m_pos; }

References m_pos.

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

◆ 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_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 264 of file page_layout_graphic_items.cpp.

265 {
266  return TestPointInsidePolygon( &m_Corners[0],
267  m_Corners.size(), aPosition );
268 }
bool TestPointInsidePolygon(const wxPoint *aPolysList, int aCount, const wxPoint &aRefPoint)
Function TestPointInsidePolygon (overlaid) same as previous, but mainly use wxPoint.
std::vector< wxPoint > m_Corners

References m_Corners, and TestPointInsidePolygon().

◆ HitTest() [2/2]

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 271 of file page_layout_graphic_items.cpp.

272 {
273  // Intersection of two polygons is nontrivial. Test if the rectangle intersects
274  // each line, instead.
275 
276  if( m_Corners.size() < 2 )
277  return false;
278 
279  for( size_t i = 1; i < m_Corners.size(); ++i )
280  {
281  if( aRect.Intersects( m_Corners[i - 1], m_Corners[i] ) )
282  return true;
283  }
284 
285  return false;
286 }
std::vector< wxPoint > m_Corners
size_t i
Definition: json11.cpp:597
bool Intersects(const EDA_RECT &aRect) const
Function Intersects tests for a common area between rectangles.

References i, EDA_RECT::Intersects(), and m_Corners.

◆ HitTestEndPoint()

virtual bool WS_DRAW_ITEM_BASE::HitTestEndPoint ( wxDC *  aDC,
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  }

◆ HitTestStartPoint()

bool WS_DRAW_ITEM_POLYGON::HitTestStartPoint ( wxDC *  aDC,
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 289 of file page_layout_graphic_items.cpp.

290 {
291  wxPoint pos = GetPosition();
292  int marker_size = WORKSHEET_DATAITEM::GetMarkerSizeUi( getScaleFromZoom( aDC ) );
293 
294  if( std::abs( pos.x - aPosition.x) <= marker_size / 2 &&
295  std::abs( pos.y - aPosition.y) <= marker_size / 2 )
296  return true;
297 
298  return false;
299 }
const wxPoint GetPosition() const
#define abs(a)
Definition: auxiliary.h:84
static double getScaleFromZoom(wxDC *aDC)
static int GetMarkerSizeUi(double aZoomScale=1.0)

References abs, WORKSHEET_DATAITEM::GetMarkerSizeUi(), GetPosition(), and getScaleFromZoom().

◆ IsFilled()

bool WS_DRAW_ITEM_POLYGON::IsFilled ( ) const
inline

Definition at line 213 of file worksheet_shape_builder.h.

213 { return m_fill; }

References m_fill.

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

Member Data Documentation

◆ m_color

COLOR4D WS_DRAW_ITEM_BASE::m_color
protectedinherited

◆ m_Corners

std::vector<wxPoint> WS_DRAW_ITEM_POLYGON::m_Corners

◆ m_fill

bool WS_DRAW_ITEM_POLYGON::m_fill
private

Definition at line 196 of file worksheet_shape_builder.h.

Referenced by IsFilled(), and WS_DRAW_ITEM_POLYGON().

◆ m_Flags

int WS_DRAW_ITEM_BASE::m_Flags
inherited

◆ m_parent

WORKSHEET_DATAITEM* WS_DRAW_ITEM_BASE::m_parent
protectedinherited

◆ m_penWidth

int WS_DRAW_ITEM_POLYGON::m_penWidth
private

Definition at line 195 of file worksheet_shape_builder.h.

Referenced by GetPenWidth(), and WS_DRAW_ITEM_POLYGON().

◆ m_pos

wxPoint WS_DRAW_ITEM_POLYGON::m_pos
private

Definition at line 192 of file worksheet_shape_builder.h.

Referenced by GetPosition(), and WS_DRAW_ITEM_POLYGON().

◆ m_type

WS_DRAW_TYPE WS_DRAW_ITEM_BASE::m_type
protectedinherited

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