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:376
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:501
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 430 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().

431 {
432  PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) Panel->GetParent();
433  ZONE_CONTAINER* zone = (ZONE_CONTAINER*) pcbframe->GetCurItem();
434 
435  if( zone->IsMoving() )
436  {
437  wxPoint offset;
439  zone->Move( offset );
440  }
441  else if( zone->IsDragging() )
442  {
444  int selection = zone->GetSelectedCorner();
445  zone->MoveEdge( offset, selection );
446  }
447  else
448  {
449  if( s_CornerIsNew )
450  {
451  zone->Outline()->RemoveVertex( zone->GetSelectedCorner() );
452  }
453  else
454  {
456  zone->Outline()->Vertex( zone->GetSelectedCorner() ) = pos;
457  }
458  }
459 
460  Panel->SetMouseCapture( NULL, NULL );
462  s_PickedList. ClearListAndDeleteItems();
463  Panel->Refresh();
464 
465  pcbframe->SetCurItem( NULL );
466  zone->ClearFlags();
467  s_AddCutoutToCurrentZone = false;
468  s_CurrentZone = NULL;
469 }
void MoveEdge(const wxPoint &offset, int aEdge)
Function MoveEdge Move the outline Edge.
Definition: class_zone.cpp:730
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.
SHAPE_POLY_SET * Outline()
Definition: class_zone.h:247
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:175
static wxPoint s_CornerInitialPosition
void Move(const wxPoint &offset) override
Function Move Move the outlines.
Definition: class_zone.cpp:713
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:254
int GetSelectedCorner() const
Definition: class_zone.h:212
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 825 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().

827 {
828  PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) aPanel->GetParent();
829  wxPoint c_pos = pcbframe->GetCrossHairPosition();
830  ZONE_CONTAINER* zone = pcbframe->GetBoard()->m_CurrentZoneContour;
831 
832  if( !zone )
833  return;
834 
835  int icorner = zone->GetNumCorners() - 1;
836 
837  if( icorner < 1 )
838  return; // We must have 2 (or more) corners
839 
840  if( aErase ) // Undraw edge in old position
841  {
842  zone->DrawWhileCreateOutline( aPanel, aDC );
843  }
844 
845  // Redraw the current edge in its new position
846  if( pcbframe->GetZoneSettings().m_Zone_45_Only )
847  {
848  // calculate the new position as allowed
849  wxPoint StartPoint = static_cast<wxPoint>( zone->GetCornerPosition( icorner - 1 ) );
850  CalculateSegmentEndPoint( c_pos, StartPoint.x, StartPoint.y, &c_pos.x, &c_pos.y );
851  }
852 
853  zone->SetCornerPosition( icorner, c_pos );
854 
855  zone->DrawWhileCreateOutline( aPanel, aDC );
856 }
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:376
int GetNumCorners(void) const
Access to m_Poly parameters.
Definition: class_zone.h:466
const ZONE_SETTINGS & GetZoneSettings() const
ZONE_CONTAINER * m_CurrentZoneContour
zone contour currently in progress
Definition: class_board.h:254
BOARD * GetBoard() const
const VECTOR2I & GetCornerPosition(int aCornerIndex) const
Definition: class_zone.h:506
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:517
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 473 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().

475 {
476  PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) aPanel->GetParent();
477  ZONE_CONTAINER* zone = (ZONE_CONTAINER*) pcbframe->GetCurItem();
478 
479  if( aErase ) // Undraw edge in old position
480  {
481  zone->Draw( aPanel, aDC, GR_XOR );
482  }
483 
484  wxPoint pos = pcbframe->GetCrossHairPosition();
485 
486  if( zone->IsMoving() )
487  {
488  wxPoint offset;
489  offset = pos - s_CursorLastPosition;
490  zone->Move( offset );
491  s_CursorLastPosition = pos;
492  }
493  else if( zone->IsDragging() )
494  {
495  wxPoint offset = pos - s_CursorLastPosition;
496  int selection = zone->GetSelectedCorner();
497  zone->MoveEdge( offset, selection );
498  s_CursorLastPosition = pos;
499  }
500  else
501  {
502  zone->Outline()->Vertex( zone->GetSelectedCorner() ) = pos;
503  }
504 
505  zone->Draw( aPanel, aDC, GR_XOR );
506 }
void MoveEdge(const wxPoint &offset, int aEdge)
Function MoveEdge Move the outline Edge.
Definition: class_zone.cpp:730
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:179
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
SHAPE_POLY_SET * Outline()
Definition: class_zone.h:247
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:175
void Move(const wxPoint &offset) override
Function Move Move the outlines.
Definition: class_zone.cpp:713
int GetSelectedCorner() const
Definition: class_zone.h:212
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.