KiCad PCB EDA Suite
zones_by_polygon.cpp File Reference
#include <fctsys.h>
#include <kiface_i.h>
#include <class_drawpanel.h>
#include <confirm.h>
#include <pcb_edit_frame.h>
#include <board_commit.h>
#include <view/view.h>
#include <class_board.h>
#include <class_zone.h>
#include <pcbnew.h>
#include <zones.h>
#include <pcbnew_id.h>
#include <protos.h>
#include <zones_functions_for_undo_redo.h>
#include <drc.h>
#include <connectivity_data.h>
#include <widgets/progress_reporter.h>
#include <zone_filler.h>

Go to the source code of this file.

Functions

static void Abort_Zone_Create_Outline (EDA_DRAW_PANEL *Panel, wxDC *DC)
 Function Abort_Zone_Create_Outline cancels the Begin_Zone command if at least one EDGE_ZONE was created. More...
 
static void Show_New_Edge_While_Move_Mouse (EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aPosition, bool aErase)
 
static void Abort_Zone_Move_Corner_Or_Outlines (EDA_DRAW_PANEL *Panel, wxDC *DC)
 Function Abort_Zone_Move_Corner_Or_Outlines cancels the Begin_Zone state if at least one EDGE_ZONE has been created. More...
 
static void Show_Zone_Corner_Or_Outline_While_Move_Mouse (EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aPosition, bool aErase)
 Redraws the zone outline when moving a corner according to the cursor position. More...
 

Variables

static wxPoint s_CornerInitialPosition
 
static bool s_CornerIsNew
 
static bool s_AddCutoutToCurrentZone
 
static ZONE_CONTAINERs_CurrentZone
 
static wxPoint s_CursorLastPosition
 
static PICKED_ITEMS_LIST s_PickedList
 
static PICKED_ITEMS_LIST s_AuxiliaryList
 

Function Documentation

static void Abort_Zone_Create_Outline ( EDA_DRAW_PANEL Panel,
wxDC *  DC 
)
static

Function Abort_Zone_Create_Outline cancels the Begin_Zone command if at least one EDGE_ZONE was created.

Definition at line 226 of file zones_by_polygon.cpp.

References EDA_ITEM::ClearFlags(), ZONE_CONTAINER::DrawWhileCreateOutline(), PCB_BASE_FRAME::GetBoard(), EDA_DRAW_PANEL::GetParent(), GR_XOR, EDA_ITEM::IsNew(), BOARD::m_CurrentZoneContour, ZONE_CONTAINER::RemoveAllContours(), s_AddCutoutToCurrentZone, PCB_BASE_FRAME::SetCurItem(), and EDA_DRAW_PANEL::SetMouseCapture().

Referenced by PCB_EDIT_FRAME::Begin_Zone(), and PCB_EDIT_FRAME::End_Zone().

227 {
228  PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) Panel->GetParent();
229  ZONE_CONTAINER* zone = pcbframe->GetBoard()->m_CurrentZoneContour;
230 
231  if( zone )
232  {
233  zone->DrawWhileCreateOutline( Panel, DC, GR_XOR );
234  zone->RemoveAllContours();
235  if( zone->IsNew() )
236  {
237  delete zone;
238  pcbframe->GetBoard()->m_CurrentZoneContour = NULL;
239  }
240  else
241  zone->ClearFlags();
242  }
243 
244  pcbframe->SetCurItem( NULL );
245  s_AddCutoutToCurrentZone = false;
246  s_CurrentZone = NULL;
247  Panel->SetMouseCapture( NULL, NULL );
248 }
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
void DrawWhileCreateOutline(EDA_DRAW_PANEL *panel, wxDC *DC, GR_DRAWMODE draw_mode=GR_OR)
Function DrawWhileCreateOutline Draws the zone outline when it is created.
Definition: class_zone.cpp:545
bool IsNew() const
Definition: base_struct.h:227
static bool s_AddCutoutToCurrentZone
ZONE_CONTAINER * m_CurrentZoneContour
zone contour currently in progress
Definition: class_board.h:259
void SetCurItem(BOARD_ITEM *aItem, bool aDisplayInfo=true)
Function SetCurItem sets the currently selected item and displays it in the MsgPanel.
BOARD * GetBoard() const
static ZONE_CONTAINER * s_CurrentZone
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:180
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:265
void SetMouseCapture(MOUSE_CAPTURE_CALLBACK aMouseCaptureCallback, END_MOUSE_CAPTURE_CALLBACK aEndMouseCaptureCallback)
Function SetMouseCapture sets the mouse capture and end mouse capture callbacks to aMouseCaptureCallb...
void RemoveAllContours(void)
Definition: class_zone.h:449
void Abort_Zone_Move_Corner_Or_Outlines ( EDA_DRAW_PANEL Panel,
wxDC *  DC 
)
static

Function Abort_Zone_Move_Corner_Or_Outlines cancels the Begin_Zone state if at least one EDGE_ZONE has been created.

Definition at line 447 of file zones_by_polygon.cpp.

References EDA_ITEM::ClearFlags(), PICKED_ITEMS_LIST::ClearListAndDeleteItems(), PCB_BASE_FRAME::GetCurItem(), EDA_DRAW_PANEL::GetParent(), ZONE_CONTAINER::GetSelectedCorner(), EDA_ITEM::IsDragging(), EDA_ITEM::IsMoving(), ZONE_CONTAINER::Move(), ZONE_CONTAINER::MoveEdge(), ZONE_CONTAINER::Outline(), EDA_DRAW_PANEL::Refresh(), SHAPE_POLY_SET::RemoveVertex(), s_AddCutoutToCurrentZone, s_CornerInitialPosition, s_CornerIsNew, s_CursorLastPosition, PCB_BASE_FRAME::SetCurItem(), EDA_DRAW_PANEL::SetMouseCapture(), and SHAPE_POLY_SET::Vertex().

Referenced by PCB_EDIT_FRAME::Start_Move_Zone_Corner(), PCB_EDIT_FRAME::Start_Move_Zone_Drag_Outline_Edge(), and PCB_EDIT_FRAME::Start_Move_Zone_Outlines().

448 {
449  PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) Panel->GetParent();
450  ZONE_CONTAINER* zone = (ZONE_CONTAINER*) pcbframe->GetCurItem();
451 
452  if( zone->IsMoving() )
453  {
454  wxPoint offset;
456  zone->Move( offset );
457  }
458  else if( zone->IsDragging() )
459  {
461  int selection = zone->GetSelectedCorner();
462  zone->MoveEdge( offset, selection );
463  }
464  else
465  {
466  if( s_CornerIsNew )
467  {
468  zone->Outline()->RemoveVertex( zone->GetSelectedCorner() );
469  }
470  else
471  {
473  zone->Outline()->Vertex( zone->GetSelectedCorner() ) = pos;
474  }
475  }
476 
477  Panel->SetMouseCapture( NULL, NULL );
479  s_PickedList. ClearListAndDeleteItems();
480  Panel->Refresh();
481 
482  pcbframe->SetCurItem( NULL );
483  zone->ClearFlags();
484  s_AddCutoutToCurrentZone = false;
485  s_CurrentZone = NULL;
486 }
void MoveEdge(const wxPoint &offset, int aEdge)
Function MoveEdge Move the outline Edge.
Definition: class_zone.cpp:914
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
bool IsMoving() const
Definition: base_struct.h:229
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL) override
Update the board display after modifying it bu a python script (note: it is automatically called by a...
Definition: draw_panel.cpp:338
static bool s_CornerIsNew
static bool s_AddCutoutToCurrentZone
void SetCurItem(BOARD_ITEM *aItem, bool aDisplayInfo=true)
Function SetCurItem sets the currently selected item and displays it in the MsgPanel.
SHAPE_POLY_SET * Outline()
Definition: class_zone.h:236
static wxPoint s_CursorLastPosition
static PICKED_ITEMS_LIST s_AuxiliaryList
VECTOR2I & Vertex(int aIndex, int aOutline, int aHole)
Returns the index-th vertex in a given hole outline within a given outline
static ZONE_CONTAINER * s_CurrentZone
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:180
static wxPoint s_CornerInitialPosition
void Move(const wxPoint &offset) override
Function Move Move the outlines.
Definition: class_zone.cpp:897
static PICKED_ITEMS_LIST s_PickedList
void RemoveVertex(int aGlobalIndex)
Function RemoveVertex deletes the aGlobalIndex-th vertex.
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:265
int GetSelectedCorner() const
Definition: class_zone.h:201
void SetMouseCapture(MOUSE_CAPTURE_CALLBACK aMouseCaptureCallback, END_MOUSE_CAPTURE_CALLBACK aEndMouseCaptureCallback)
Function SetMouseCapture sets the mouse capture and end mouse capture callbacks to aMouseCaptureCallb...
BOARD_ITEM * GetCurItem()
void ClearListAndDeleteItems()
Function ClearListAndDeleteItems deletes the list of pickers, AND the data pointed by m_PickedItem or...
bool IsDragging() const
Definition: base_struct.h:230
static void Show_New_Edge_While_Move_Mouse ( EDA_DRAW_PANEL aPanel,
wxDC *  aDC,
const wxPoint aPosition,
bool  aErase 
)
static

Definition at line 841 of file zones_by_polygon.cpp.

References CalculateSegmentEndPoint(), ZONE_CONTAINER::DrawWhileCreateOutline(), PCB_BASE_FRAME::GetBoard(), ZONE_CONTAINER::GetCornerPosition(), EDA_DRAW_FRAME::GetCrossHairPosition(), ZONE_CONTAINER::GetNumCorners(), EDA_DRAW_PANEL::GetParent(), PCB_BASE_FRAME::GetZoneSettings(), BOARD::m_CurrentZoneContour, ZONE_SETTINGS::m_Zone_45_Only, and ZONE_CONTAINER::SetCornerPosition().

Referenced by PCB_EDIT_FRAME::Begin_Zone().

843 {
844  PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) aPanel->GetParent();
845  wxPoint c_pos = pcbframe->GetCrossHairPosition();
846  ZONE_CONTAINER* zone = pcbframe->GetBoard()->m_CurrentZoneContour;
847 
848  if( !zone )
849  return;
850 
851  int icorner = zone->GetNumCorners() - 1;
852 
853  if( icorner < 1 )
854  return; // We must have 2 (or more) corners
855 
856  if( aErase ) // Undraw edge in old position
857  {
858  zone->DrawWhileCreateOutline( aPanel, aDC );
859  }
860 
861  // Redraw the current edge in its new position
862  if( pcbframe->GetZoneSettings().m_Zone_45_Only )
863  {
864  // calculate the new position as allowed
865  wxPoint StartPoint = static_cast<wxPoint>( zone->GetCornerPosition( icorner - 1 ) );
866  c_pos = CalculateSegmentEndPoint( c_pos, StartPoint );
867  }
868 
869  zone->SetCornerPosition( icorner, c_pos );
870 
871  zone->DrawWhileCreateOutline( aPanel, aDC );
872 }
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
void DrawWhileCreateOutline(EDA_DRAW_PANEL *panel, wxDC *DC, GR_DRAWMODE draw_mode=GR_OR)
Function DrawWhileCreateOutline Draws the zone outline when it is created.
Definition: class_zone.cpp:545
int GetNumCorners(void) const
Access to m_Poly parameters.
Definition: class_zone.h:414
const ZONE_SETTINGS & GetZoneSettings() const
ZONE_CONTAINER * m_CurrentZoneContour
zone contour currently in progress
Definition: class_board.h:259
BOARD * GetBoard() const
const VECTOR2I & GetCornerPosition(int aCornerIndex) const
Definition: class_zone.h:454
wxPoint CalculateSegmentEndPoint(const wxPoint &aPosition, const wxPoint &aOrigin)
Determine end point for a segment direction 0, 90, or 45 degrees depending on it&#39;s position from the ...
Definition: editrack.cpp:826
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:180
void SetCornerPosition(int aCornerIndex, wxPoint new_pos)
Definition: class_zone.h:465
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Function GetCrossHairPosition return the current cross hair position in logical (drawing) coordinates...
void Show_Zone_Corner_Or_Outline_While_Move_Mouse ( EDA_DRAW_PANEL aPanel,
wxDC *  aDC,
const wxPoint aPosition,
bool  aErase 
)
static

Redraws the zone outline when moving a corner according to the cursor position.

Definition at line 490 of file zones_by_polygon.cpp.

References ZONE_CONTAINER::Draw(), EDA_DRAW_FRAME::GetCrossHairPosition(), PCB_BASE_FRAME::GetCurItem(), EDA_DRAW_PANEL::GetParent(), ZONE_CONTAINER::GetSelectedCorner(), GR_XOR, EDA_ITEM::IsDragging(), EDA_ITEM::IsMoving(), ZONE_CONTAINER::Move(), ZONE_CONTAINER::MoveEdge(), ZONE_CONTAINER::Outline(), s_CursorLastPosition, and SHAPE_POLY_SET::Vertex().

Referenced by PCB_EDIT_FRAME::Start_Move_Zone_Corner(), PCB_EDIT_FRAME::Start_Move_Zone_Drag_Outline_Edge(), and PCB_EDIT_FRAME::Start_Move_Zone_Outlines().

492 {
493  PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) aPanel->GetParent();
494  ZONE_CONTAINER* zone = (ZONE_CONTAINER*) pcbframe->GetCurItem();
495 
496  if( aErase ) // Undraw edge in old position
497  {
498  zone->Draw( aPanel, aDC, GR_XOR );
499  }
500 
501  wxPoint pos = pcbframe->GetCrossHairPosition();
502 
503  if( zone->IsMoving() )
504  {
505  wxPoint offset;
506  offset = pos - s_CursorLastPosition;
507  zone->Move( offset );
508  s_CursorLastPosition = pos;
509  }
510  else if( zone->IsDragging() )
511  {
512  wxPoint offset = pos - s_CursorLastPosition;
513  int selection = zone->GetSelectedCorner();
514  zone->MoveEdge( offset, selection );
515  s_CursorLastPosition = pos;
516  }
517  else
518  {
519  zone->Outline()->Vertex( zone->GetSelectedCorner() ) = pos;
520  }
521 
522  zone->Draw( aPanel, aDC, GR_XOR );
523 }
void MoveEdge(const wxPoint &offset, int aEdge)
Function MoveEdge Move the outline Edge.
Definition: class_zone.cpp:914
void Draw(EDA_DRAW_PANEL *panel, wxDC *DC, GR_DRAWMODE aDrawMode, const wxPoint &offset=ZeroOffset) override
Function Draw Draws the zone outline.
Definition: class_zone.cpp:276
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
bool IsMoving() const
Definition: base_struct.h:229
SHAPE_POLY_SET * Outline()
Definition: class_zone.h:236
static wxPoint s_CursorLastPosition
VECTOR2I & Vertex(int aIndex, int aOutline, int aHole)
Returns the index-th vertex in a given hole outline within a given outline
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:180
void Move(const wxPoint &offset) override
Function Move Move the outlines.
Definition: class_zone.cpp:897
int GetSelectedCorner() const
Definition: class_zone.h:201
BOARD_ITEM * GetCurItem()
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Function GetCrossHairPosition return the current cross hair position in logical (drawing) coordinates...
bool IsDragging() const
Definition: base_struct.h:230

Variable Documentation

PICKED_ITEMS_LIST s_AuxiliaryList
static

Definition at line 73 of file zones_by_polygon.cpp.

wxPoint s_CornerInitialPosition
static

Definition at line 67 of file zones_by_polygon.cpp.

Referenced by Abort_Zone_Move_Corner_Or_Outlines().

ZONE_CONTAINER* s_CurrentZone
static

Definition at line 70 of file zones_by_polygon.cpp.

Referenced by PCB_EDIT_FRAME::Begin_Zone(), and PCB_EDIT_FRAME::End_Zone().

wxPoint s_CursorLastPosition
static
PICKED_ITEMS_LIST s_PickedList
static

Definition at line 72 of file zones_by_polygon.cpp.