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/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 215 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().

216 {
217  PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) Panel->GetParent();
218  ZONE_CONTAINER* zone = pcbframe->GetBoard()->m_CurrentZoneContour;
219 
220  if( zone )
221  {
222  zone->DrawWhileCreateOutline( Panel, DC, GR_XOR );
223  zone->RemoveAllContours();
224  if( zone->IsNew() )
225  {
226  delete zone;
227  pcbframe->GetBoard()->m_CurrentZoneContour = NULL;
228  }
229  else
230  zone->ClearFlags();
231  }
232 
233  pcbframe->SetCurItem( NULL );
234  s_AddCutoutToCurrentZone = false;
235  s_CurrentZone = NULL;
236  Panel->SetMouseCapture( NULL, NULL );
237 }
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:219
static bool s_AddCutoutToCurrentZone
ZONE_CONTAINER * m_CurrentZoneContour
zone contour currently in progress
Definition: class_board.h:263
void SetCurItem(BOARD_ITEM *aItem, bool aDisplayInfo=true)
Function SetCurItem sets the currently selected item and displays it in the MsgPanel.
BOARD * GetBoard() const
virtual EDA_DRAW_FRAME * GetParent() const =0
virtual void SetMouseCapture(MOUSE_CAPTURE_CALLBACK aMouseCaptureCallback, END_MOUSE_CAPTURE_CALLBACK aEndMouseCaptureCallback)
Function SetMouseCapture sets the mouse capture and end mouse capture callbacks to aMouseCaptureCallb...
static ZONE_CONTAINER * s_CurrentZone
Class PCB_EDIT_FRAME is the main frame for Pcbnew.
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:257
void RemoveAllContours(void)
Definition: class_zone.h:476
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 436 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().

437 {
438  PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) Panel->GetParent();
439  ZONE_CONTAINER* zone = (ZONE_CONTAINER*) pcbframe->GetCurItem();
440 
441  if( zone->IsMoving() )
442  {
443  wxPoint offset;
445  zone->Move( offset );
446  }
447  else if( zone->IsDragging() )
448  {
450  int selection = zone->GetSelectedCorner();
451  zone->MoveEdge( offset, selection );
452  }
453  else
454  {
455  if( s_CornerIsNew )
456  {
457  zone->Outline()->RemoveVertex( zone->GetSelectedCorner() );
458  }
459  else
460  {
462  zone->Outline()->Vertex( zone->GetSelectedCorner() ) = pos;
463  }
464  }
465 
466  Panel->SetMouseCapture( NULL, NULL );
468  s_PickedList. ClearListAndDeleteItems();
469  Panel->Refresh();
470 
471  pcbframe->SetCurItem( NULL );
472  zone->ClearFlags();
473  s_AddCutoutToCurrentZone = false;
474  s_CurrentZone = NULL;
475 }
void MoveEdge(const wxPoint &offset, int aEdge)
Function MoveEdge Move the outline Edge.
Definition: class_zone.cpp:908
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
bool IsMoving() const
Definition: base_struct.h:221
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:242
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
virtual EDA_DRAW_FRAME * GetParent() const =0
virtual void SetMouseCapture(MOUSE_CAPTURE_CALLBACK aMouseCaptureCallback, END_MOUSE_CAPTURE_CALLBACK aEndMouseCaptureCallback)
Function SetMouseCapture sets the mouse capture and end mouse capture callbacks to aMouseCaptureCallb...
static ZONE_CONTAINER * s_CurrentZone
static wxPoint s_CornerInitialPosition
void Move(const wxPoint &offset) override
Function Move Move the outlines.
Definition: class_zone.cpp:891
static PICKED_ITEMS_LIST s_PickedList
void RemoveVertex(int aGlobalIndex)
Function RemoveVertex deletes the aGlobalIndex-th vertex.
Class PCB_EDIT_FRAME is the main frame for Pcbnew.
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:257
int GetSelectedCorner() const
Definition: class_zone.h:207
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL)
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:222
static void Show_New_Edge_While_Move_Mouse ( EDA_DRAW_PANEL aPanel,
wxDC *  aDC,
const wxPoint aPosition,
bool  aErase 
)
static

Definition at line 832 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().

834 {
835  PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) aPanel->GetParent();
836  wxPoint c_pos = pcbframe->GetCrossHairPosition();
837  ZONE_CONTAINER* zone = pcbframe->GetBoard()->m_CurrentZoneContour;
838 
839  if( !zone )
840  return;
841 
842  int icorner = zone->GetNumCorners() - 1;
843 
844  if( icorner < 1 )
845  return; // We must have 2 (or more) corners
846 
847  if( aErase ) // Undraw edge in old position
848  {
849  zone->DrawWhileCreateOutline( aPanel, aDC );
850  }
851 
852  // Redraw the current edge in its new position
853  if( pcbframe->GetZoneSettings().m_Zone_45_Only )
854  {
855  // calculate the new position as allowed
856  wxPoint StartPoint = static_cast<wxPoint>( zone->GetCornerPosition( icorner - 1 ) );
857  c_pos = CalculateSegmentEndPoint( c_pos, StartPoint );
858  }
859 
860  zone->SetCornerPosition( icorner, c_pos );
861 
862  zone->DrawWhileCreateOutline( aPanel, aDC );
863 }
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:441
const ZONE_SETTINGS & GetZoneSettings() const
ZONE_CONTAINER * m_CurrentZoneContour
zone contour currently in progress
Definition: class_board.h:263
BOARD * GetBoard() const
const VECTOR2I & GetCornerPosition(int aCornerIndex) const
Definition: class_zone.h:481
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:800
virtual EDA_DRAW_FRAME * GetParent() const =0
void SetCornerPosition(int aCornerIndex, wxPoint new_pos)
Definition: class_zone.h:492
Class PCB_EDIT_FRAME is the main frame for Pcbnew.
wxPoint GetCrossHairPosition(bool aInvertY=false) const
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 479 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().

481 {
482  PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) aPanel->GetParent();
483  ZONE_CONTAINER* zone = (ZONE_CONTAINER*) pcbframe->GetCurItem();
484 
485  if( aErase ) // Undraw edge in old position
486  {
487  zone->Draw( aPanel, aDC, GR_XOR );
488  }
489 
490  wxPoint pos = pcbframe->GetCrossHairPosition();
491 
492  if( zone->IsMoving() )
493  {
494  wxPoint offset;
495  offset = pos - s_CursorLastPosition;
496  zone->Move( offset );
497  s_CursorLastPosition = pos;
498  }
499  else if( zone->IsDragging() )
500  {
501  wxPoint offset = pos - s_CursorLastPosition;
502  int selection = zone->GetSelectedCorner();
503  zone->MoveEdge( offset, selection );
504  s_CursorLastPosition = pos;
505  }
506  else
507  {
508  zone->Outline()->Vertex( zone->GetSelectedCorner() ) = pos;
509  }
510 
511  zone->Draw( aPanel, aDC, GR_XOR );
512 }
void MoveEdge(const wxPoint &offset, int aEdge)
Function MoveEdge Move the outline Edge.
Definition: class_zone.cpp:908
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:221
SHAPE_POLY_SET * Outline()
Definition: class_zone.h:242
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
virtual EDA_DRAW_FRAME * GetParent() const =0
void Move(const wxPoint &offset) override
Function Move Move the outlines.
Definition: class_zone.cpp:891
Class PCB_EDIT_FRAME is the main frame for Pcbnew.
int GetSelectedCorner() const
Definition: class_zone.h:207
BOARD_ITEM * GetCurItem()
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Return the current cross hair position in logical (drawing) coordinates.
bool IsDragging() const
Definition: base_struct.h:222

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.