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 <wxPcbStruct.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_stuff.h>
#include <connectivity_data.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 220 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().

221 {
222  PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) Panel->GetParent();
223  ZONE_CONTAINER* zone = pcbframe->GetBoard()->m_CurrentZoneContour;
224 
225  if( zone )
226  {
227  zone->DrawWhileCreateOutline( Panel, DC, GR_XOR );
228  zone->RemoveAllContours();
229  if( zone->IsNew() )
230  {
231  delete zone;
232  pcbframe->GetBoard()->m_CurrentZoneContour = NULL;
233  }
234  else
235  zone->ClearFlags();
236  }
237 
238  pcbframe->SetCurItem( NULL );
239  s_AddCutoutToCurrentZone = false;
240  s_CurrentZone = NULL;
241  Panel->SetMouseCapture( NULL, NULL );
242 }
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:78
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:552
bool IsNew() const
Definition: base_struct.h:230
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:174
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:268
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:515
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 439 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().

440 {
441  PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) Panel->GetParent();
442  ZONE_CONTAINER* zone = (ZONE_CONTAINER*) pcbframe->GetCurItem();
443 
444  if( zone->IsMoving() )
445  {
446  wxPoint offset;
448  zone->Move( offset );
449  }
450  else if( zone->IsDragging() )
451  {
453  int selection = zone->GetSelectedCorner();
454  zone->MoveEdge( offset, selection );
455  }
456  else
457  {
458  if( s_CornerIsNew )
459  {
460  zone->Outline()->RemoveVertex( zone->GetSelectedCorner() );
461  }
462  else
463  {
465  zone->Outline()->Vertex( zone->GetSelectedCorner() ) = pos;
466  }
467  }
468 
469  Panel->SetMouseCapture( NULL, NULL );
471  s_PickedList. ClearListAndDeleteItems();
472  Panel->Refresh();
473 
474  pcbframe->SetCurItem( NULL );
475  zone->ClearFlags();
476  s_AddCutoutToCurrentZone = false;
477  s_CurrentZone = NULL;
478 }
void MoveEdge(const wxPoint &offset, int aEdge)
Function MoveEdge Move the outline Edge.
Definition: class_zone.cpp:921
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:78
bool IsMoving() const
Definition: base_struct.h:232
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:325
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:262
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:174
static wxPoint s_CornerInitialPosition
void Move(const wxPoint &offset) override
Function Move Move the outlines.
Definition: class_zone.cpp:904
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:268
int GetSelectedCorner() const
Definition: class_zone.h:227
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:233
static void Show_New_Edge_While_Move_Mouse ( EDA_DRAW_PANEL aPanel,
wxDC *  aDC,
const wxPoint aPosition,
bool  aErase 
)
static

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

832 {
833  PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) aPanel->GetParent();
834  wxPoint c_pos = pcbframe->GetCrossHairPosition();
835  ZONE_CONTAINER* zone = pcbframe->GetBoard()->m_CurrentZoneContour;
836 
837  if( !zone )
838  return;
839 
840  int icorner = zone->GetNumCorners() - 1;
841 
842  if( icorner < 1 )
843  return; // We must have 2 (or more) corners
844 
845  if( aErase ) // Undraw edge in old position
846  {
847  zone->DrawWhileCreateOutline( aPanel, aDC );
848  }
849 
850  // Redraw the current edge in its new position
851  if( pcbframe->GetZoneSettings().m_Zone_45_Only )
852  {
853  // calculate the new position as allowed
854  wxPoint StartPoint = static_cast<wxPoint>( zone->GetCornerPosition( icorner - 1 ) );
855  c_pos = CalculateSegmentEndPoint( c_pos, StartPoint );
856  }
857 
858  zone->SetCornerPosition( icorner, c_pos );
859 
860  zone->DrawWhileCreateOutline( aPanel, aDC );
861 }
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:78
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:552
int GetNumCorners(void) const
Access to m_Poly parameters.
Definition: class_zone.h:480
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:520
wxPoint CalculateSegmentEndPoint(const wxPoint &aPosition, const wxPoint &aOrigin)
Determine end point for a segment direction 0, 90, or 45 degrees depending on it's position from the ...
Definition: editrack.cpp:831
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:174
void SetCornerPosition(int aCornerIndex, wxPoint new_pos)
Definition: class_zone.h:531
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 482 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().

484 {
485  PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) aPanel->GetParent();
486  ZONE_CONTAINER* zone = (ZONE_CONTAINER*) pcbframe->GetCurItem();
487 
488  if( aErase ) // Undraw edge in old position
489  {
490  zone->Draw( aPanel, aDC, GR_XOR );
491  }
492 
493  wxPoint pos = pcbframe->GetCrossHairPosition();
494 
495  if( zone->IsMoving() )
496  {
497  wxPoint offset;
498  offset = pos - s_CursorLastPosition;
499  zone->Move( offset );
500  s_CursorLastPosition = pos;
501  }
502  else if( zone->IsDragging() )
503  {
504  wxPoint offset = pos - s_CursorLastPosition;
505  int selection = zone->GetSelectedCorner();
506  zone->MoveEdge( offset, selection );
507  s_CursorLastPosition = pos;
508  }
509  else
510  {
511  zone->Outline()->Vertex( zone->GetSelectedCorner() ) = pos;
512  }
513 
514  zone->Draw( aPanel, aDC, GR_XOR );
515 }
void MoveEdge(const wxPoint &offset, int aEdge)
Function MoveEdge Move the outline Edge.
Definition: class_zone.cpp:921
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:283
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:78
bool IsMoving() const
Definition: base_struct.h:232
SHAPE_POLY_SET * Outline()
Definition: class_zone.h:262
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:174
void Move(const wxPoint &offset) override
Function Move Move the outlines.
Definition: class_zone.cpp:904
int GetSelectedCorner() const
Definition: class_zone.h:227
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:233

Variable Documentation

PICKED_ITEMS_LIST s_AuxiliaryList
static

Definition at line 69 of file zones_by_polygon.cpp.

wxPoint s_CornerInitialPosition
static

Definition at line 63 of file zones_by_polygon.cpp.

Referenced by Abort_Zone_Move_Corner_Or_Outlines().

ZONE_CONTAINER* s_CurrentZone
static

Definition at line 66 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 68 of file zones_by_polygon.cpp.