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 <ratsnest_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 211 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().

212 {
213  PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) Panel->GetParent();
214  ZONE_CONTAINER* zone = pcbframe->GetBoard()->m_CurrentZoneContour;
215 
216  if( zone )
217  {
218  zone->DrawWhileCreateOutline( Panel, DC, GR_XOR );
219  zone->RemoveAllContours();
220  if( zone->IsNew() )
221  {
222  delete zone;
223  pcbframe->GetBoard()->m_CurrentZoneContour = NULL;
224  }
225  else
226  zone->ClearFlags();
227  }
228 
229  pcbframe->SetCurItem( NULL );
230  s_AddCutoutToCurrentZone = false;
231  s_CurrentZone = NULL;
232  Panel->SetMouseCapture( NULL, NULL );
233 }
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:374
bool IsNew() const
Definition: base_struct.h:216
static bool s_AddCutoutToCurrentZone
ZONE_CONTAINER * m_CurrentZoneContour
zone contour currently in progress
Definition: class_board.h:254
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:175
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:254
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:416
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 431 of file zones_by_polygon.cpp.

References EDA_ITEM::ClearFlags(), PICKED_ITEMS_LIST::ClearListAndDeleteItems(), CPolyLine::DeleteCorner(), PCB_BASE_FRAME::GetCurItem(), EDA_DRAW_PANEL::GetParent(), ZONE_CONTAINER::GetSelectedCorner(), EDA_ITEM::IsDragging(), EDA_ITEM::IsMoving(), ZONE_CONTAINER::Move(), CPolyLine::MoveCorner(), ZONE_CONTAINER::MoveEdge(), ZONE_CONTAINER::Outline(), EDA_DRAW_PANEL::Refresh(), s_AddCutoutToCurrentZone, s_CornerInitialPosition, s_CornerIsNew, s_CursorLastPosition, PCB_BASE_FRAME::SetCurItem(), EDA_DRAW_PANEL::SetMouseCapture(), wxPoint::x, and wxPoint::y.

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

432 {
433  PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) Panel->GetParent();
434  ZONE_CONTAINER* zone = (ZONE_CONTAINER*) pcbframe->GetCurItem();
435 
436  if( zone->IsMoving() )
437  {
438  wxPoint offset;
440  zone->Move( offset );
441  }
442  else if( zone->IsDragging() )
443  {
445  int selection = zone->GetSelectedCorner();
446  zone->MoveEdge( offset, selection );
447  }
448  else
449  {
450  if( s_CornerIsNew )
451  {
452  zone->Outline()->DeleteCorner( zone->GetSelectedCorner() );
453  }
454  else
455  {
457  zone->Outline()->MoveCorner( zone->GetSelectedCorner(), pos.x, pos.y );
458  }
459  }
460 
461  Panel->SetMouseCapture( NULL, NULL );
463  s_PickedList. ClearListAndDeleteItems();
464  Panel->Refresh();
465 
466  pcbframe->SetCurItem( NULL );
467  zone->ClearFlags();
468  s_AddCutoutToCurrentZone = false;
469  s_CurrentZone = NULL;
470 }
void MoveEdge(const wxPoint &offset, int aEdge)
Function MoveEdge Move the outline Edge.
Definition: class_zone.cpp:695
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:78
bool IsMoving() const
Definition: base_struct.h:218
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL) override
Definition: draw_panel.cpp:326
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.
static wxPoint s_CursorLastPosition
static PICKED_ITEMS_LIST s_AuxiliaryList
static ZONE_CONTAINER * s_CurrentZone
CPolyLine * Outline()
Definition: class_zone.h:212
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:175
static wxPoint s_CornerInitialPosition
void Move(const wxPoint &offset) override
Function Move Move the outlines.
Definition: class_zone.cpp:675
static PICKED_ITEMS_LIST s_PickedList
void DeleteCorner(int ic)
Function DeleteCorner remove the given corner.
Definition: PolyLine.cpp:222
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:254
int GetSelectedCorner() const
Definition: class_zone.h:199
void MoveCorner(int ic, int x, int y)
Definition: PolyLine.cpp:211
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:219
static void Show_New_Edge_While_Move_Mouse ( EDA_DRAW_PANEL aPanel,
wxDC *  aDC,
const wxPoint aPosition,
bool  aErase 
)
static

Definition at line 826 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, ZONE_CONTAINER::SetCornerPosition(), wxPoint::x, and wxPoint::y.

Referenced by PCB_EDIT_FRAME::Begin_Zone().

828 {
829  PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) aPanel->GetParent();
830  wxPoint c_pos = pcbframe->GetCrossHairPosition();
831  ZONE_CONTAINER* zone = pcbframe->GetBoard()->m_CurrentZoneContour;
832 
833  if( !zone )
834  return;
835 
836  int icorner = zone->GetNumCorners() - 1;
837 
838  if( icorner < 1 )
839  return; // We must have 2 (or more) corners
840 
841  if( aErase ) // Undraw edge in old position
842  {
843  zone->DrawWhileCreateOutline( aPanel, aDC );
844  }
845 
846  // Redraw the current edge in its new position
847  if( pcbframe->GetZoneSettings().m_Zone_45_Only )
848  {
849  // calculate the new position as allowed
850  wxPoint StartPoint = zone->GetCornerPosition( icorner - 1 );
851  CalculateSegmentEndPoint( c_pos, StartPoint.x, StartPoint.y, &c_pos.x, &c_pos.y );
852  }
853 
854  zone->SetCornerPosition( icorner, c_pos );
855 
856  zone->DrawWhileCreateOutline( aPanel, aDC );
857 }
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:374
int GetNumCorners(void) const
Access to m_Poly parameters.
Definition: class_zone.h:411
const ZONE_SETTINGS & GetZoneSettings() const
ZONE_CONTAINER * m_CurrentZoneContour
zone contour currently in progress
Definition: class_board.h:254
BOARD * GetBoard() const
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:175
void CalculateSegmentEndPoint(const wxPoint &aPosition, int ox, int oy, int *fx, int *fy)
Determine coordinate for a segment direction of 0, 90, or 45 degrees depending on it's position from ...
Definition: editrack.cpp:839
void SetCornerPosition(int aCornerIndex, wxPoint new_pos)
Definition: class_zone.h:426
const wxPoint & GetCornerPosition(int aCornerIndex) const
Definition: class_zone.h:421
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 474 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(), CPolyLine::MoveCorner(), ZONE_CONTAINER::MoveEdge(), ZONE_CONTAINER::Outline(), s_CursorLastPosition, wxPoint::x, and wxPoint::y.

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

476 {
477  PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) aPanel->GetParent();
478  ZONE_CONTAINER* zone = (ZONE_CONTAINER*) pcbframe->GetCurItem();
479 
480  if( aErase ) // Undraw edge in old position
481  {
482  zone->Draw( aPanel, aDC, GR_XOR );
483  }
484 
485  wxPoint pos = pcbframe->GetCrossHairPosition();
486 
487  if( zone->IsMoving() )
488  {
489  wxPoint offset;
490  offset = pos - s_CursorLastPosition;
491  zone->Move( offset );
492  s_CursorLastPosition = pos;
493  }
494  else if( zone->IsDragging() )
495  {
496  wxPoint offset = pos - s_CursorLastPosition;
497  int selection = zone->GetSelectedCorner();
498  zone->MoveEdge( offset, selection );
499  s_CursorLastPosition = pos;
500  }
501  else
502  {
503  zone->Outline()->MoveCorner( zone->GetSelectedCorner(), pos.x, pos.y );
504  }
505 
506  zone->Draw( aPanel, aDC, GR_XOR );
507 }
void MoveEdge(const wxPoint &offset, int aEdge)
Function MoveEdge Move the outline Edge.
Definition: class_zone.cpp:695
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:168
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:78
bool IsMoving() const
Definition: base_struct.h:218
static wxPoint s_CursorLastPosition
CPolyLine * Outline()
Definition: class_zone.h:212
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:175
void Move(const wxPoint &offset) override
Function Move Move the outlines.
Definition: class_zone.cpp:675
int GetSelectedCorner() const
Definition: class_zone.h:199
void MoveCorner(int ic, int x, int y)
Definition: PolyLine.cpp:211
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:219

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.