KiCad PCB EDA Suite
editedge.cpp File Reference

Edit segments and edges of PCB. More...

#include <fctsys.h>
#include <class_drawpanel.h>
#include <confirm.h>
#include <pcb_edit_frame.h>
#include <gr_basic.h>
#include <pcbnew.h>
#include <protos.h>
#include <macros.h>
#include <class_board.h>
#include <class_drawsegment.h>

Go to the source code of this file.

Functions

static void Abort_EditEdge (EDA_DRAW_PANEL *aPanel, wxDC *DC)
 
static void DrawSegment (EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aPosition, bool aErase)
 
static void Move_Segment (EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aPosition, bool aErase)
 

Variables

static wxPoint s_InitialPosition
 
static wxPoint s_LastPosition
 

Detailed Description

Edit segments and edges of PCB.

Definition in file editedge.cpp.

Function Documentation

static void Abort_EditEdge ( EDA_DRAW_PANEL aPanel,
wxDC *  DC 
)
static

Definition at line 206 of file editedge.cpp.

References EDA_DRAW_PANEL::CallMouseCapture(), EDA_ITEM::ClearFlags(), BOARD_ITEM::DeleteStructure(), DRAWSEGMENT::Draw(), EDA_DRAW_FRAME::GetCrossHairPosition(), BASE_SCREEN::GetCurItem(), EDA_DRAW_PANEL::GetParent(), EDA_DRAW_PANEL::GetScreen(), GR_OR, EDA_ITEM::IsNew(), EDA_DRAW_PANEL::Refresh(), EDA_DRAW_FRAME::SetCrossHairPosition(), PCB_BASE_FRAME::SetCurItem(), and EDA_DRAW_PANEL::SetMouseCapture().

Referenced by PCB_EDIT_FRAME::Begin_DrawSegment(), and PCB_EDIT_FRAME::Start_Move_DrawItem().

207 {
208  DRAWSEGMENT* Segment = (DRAWSEGMENT*) aPanel->GetScreen()->GetCurItem();
209 
210  if( Segment == NULL )
211  {
212  aPanel->SetMouseCapture( NULL, NULL );
213  return;
214  }
215 
216  if( Segment->IsNew() )
217  {
218  aPanel->CallMouseCapture( DC, wxDefaultPosition, false );
219  Segment ->DeleteStructure();
220  Segment = NULL;
221  }
222  else
223  {
224  wxPoint pos = aPanel->GetParent()->GetCrossHairPosition();
226  aPanel->CallMouseCapture( DC, wxDefaultPosition, true );
227  aPanel->GetParent()->SetCrossHairPosition( pos );
228  Segment->ClearFlags();
229  Segment->Draw( aPanel, DC, GR_OR );
230  }
231 
232 #ifdef USE_WX_OVERLAY
233  aPanel->Refresh();
234 #endif
235 
236  aPanel->SetMouseCapture( NULL, NULL );
237  ( (PCB_EDIT_FRAME*) aPanel->GetParent() )->SetCurItem( NULL );
238 }
virtual BASE_SCREEN * GetScreen()=0
EDA_ITEM * GetCurItem() const
Definition: base_screen.h:233
bool IsNew() const
Definition: base_struct.h:219
static wxPoint s_InitialPosition
Definition: editedge.cpp:51
void DeleteStructure()
Function DeleteStructure deletes this object after UnLink()ing it from its owner if it has one...
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...
virtual void CallMouseCapture(wxDC *aDC, const wxPoint &aPosition, bool aErase)
Function CallMouseCapture calls the mouse capture callback.
Definition: gr_basic.h:38
Class PCB_EDIT_FRAME is the main frame for Pcbnew.
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:257
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL)
void SetCrossHairPosition(const wxPoint &aPosition, bool aSnapToGrid=true)
Set the screen cross hair position to aPosition in logical (drawing) units.
void Draw(EDA_DRAW_PANEL *panel, wxDC *DC, GR_DRAWMODE aDrawMode, const wxPoint &aOffset=ZeroOffset) override
Function Draw BOARD_ITEMs have their own color information.
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Return the current cross hair position in logical (drawing) coordinates.
static void DrawSegment ( EDA_DRAW_PANEL aPanel,
wxDC *  aDC,
const wxPoint aPosition,
bool  aErase 
)
static

Definition at line 331 of file editedge.cpp.

References CalculateSegmentEndPoint(), DRAWSEGMENT::Draw(), EDA_DRAW_FRAME::GetCrossHairPosition(), BASE_SCREEN::GetCurItem(), EDA_DRAW_PANEL::GetDisplayOptions(), EDA_DRAW_PANEL::GetParent(), EDA_DRAW_PANEL::GetScreen(), DRAWSEGMENT::GetShape(), DRAWSEGMENT::GetStart(), GR_XOR, S_SEGMENT, DRAWSEGMENT::SetEnd(), and SKETCH.

Referenced by PCB_EDIT_FRAME::Begin_DrawSegment().

332 {
333  DRAWSEGMENT* Segment = (DRAWSEGMENT*) aPanel->GetScreen()->GetCurItem();
334  auto frame = (PCB_EDIT_FRAME*) ( aPanel->GetParent() );
335  if( Segment == NULL )
336  return;
337 
338  auto displ_opts = (PCB_DISPLAY_OPTIONS*) ( aPanel->GetDisplayOptions() );
339  bool tmp = displ_opts->m_DisplayDrawItemsFill;
340 
341  displ_opts->m_DisplayDrawItemsFill = SKETCH;
342 
343  if( aErase )
344  Segment->Draw( aPanel, aDC, GR_XOR );
345 
346  if( frame->Settings().m_use45DegreeGraphicSegments && Segment->GetShape() == S_SEGMENT )
347  {
348  wxPoint pt;
349 
351  Segment->GetStart() );
352  Segment->SetEnd( pt );
353  }
354  else // here the angle is arbitrary
355  {
356  Segment->SetEnd( aPanel->GetParent()->GetCrossHairPosition() );
357  }
358 
359  Segment->Draw( aPanel, aDC, GR_XOR );
360  displ_opts->m_DisplayDrawItemsFill = tmp;
361 }
virtual BASE_SCREEN * GetScreen()=0
EDA_ITEM * GetCurItem() const
Definition: base_screen.h:233
usual segment : line with rounded ends
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
Class PCB_DISPLAY_OPTIONS handles display options like enable/disable some optional drawings...
STROKE_T GetShape() const
Class PCB_EDIT_FRAME is the main frame for Pcbnew.
void SetEnd(const wxPoint &aEnd)
virtual void * GetDisplayOptions()
Function GetDisplayOptions A way to pass info to draw functions.
void Draw(EDA_DRAW_PANEL *panel, wxDC *DC, GR_DRAWMODE aDrawMode, const wxPoint &aOffset=ZeroOffset) override
Function Draw BOARD_ITEMs have their own color information.
const wxPoint & GetStart() const
Function GetStart returns the starting point of the graphic.
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Return the current cross hair position in logical (drawing) coordinates.
static void Move_Segment ( EDA_DRAW_PANEL aPanel,
wxDC *  aDC,
const wxPoint aPosition,
bool  aErase 
)
static

Definition at line 90 of file editedge.cpp.

References delta, DRAWSEGMENT::Draw(), EDA_DRAW_FRAME::GetCrossHairPosition(), BASE_SCREEN::GetCurItem(), EDA_DRAW_PANEL::GetParent(), EDA_DRAW_PANEL::GetScreen(), GR_XOR, DRAWSEGMENT::Move(), and s_LastPosition.

Referenced by PCB_EDIT_FRAME::Start_Move_DrawItem().

92 {
93  DRAWSEGMENT* segment = (DRAWSEGMENT*) aPanel->GetScreen()->GetCurItem();
94 
95  if( segment == NULL )
96  return;
97 
98  if( aErase )
99  segment->Draw( aPanel, aDC, GR_XOR );
100 
101  wxPoint delta;
102  delta = aPanel->GetParent()->GetCrossHairPosition() - s_LastPosition;
103 
104  segment->Move( delta );
105 
107 
108  segment->Draw( aPanel, aDC, GR_XOR );
109 }
virtual BASE_SCREEN * GetScreen()=0
virtual void Move(const wxPoint &aMoveVector) override
Function Move move this object.
EDA_ITEM * GetCurItem() const
Definition: base_screen.h:233
static const int delta[8][2]
Definition: solve.cpp:112
virtual EDA_DRAW_FRAME * GetParent() const =0
static wxPoint s_LastPosition
Definition: editedge.cpp:52
void Draw(EDA_DRAW_PANEL *panel, wxDC *DC, GR_DRAWMODE aDrawMode, const wxPoint &aOffset=ZeroOffset) override
Function Draw BOARD_ITEMs have their own color information.
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Return the current cross hair position in logical (drawing) coordinates.

Variable Documentation

wxPoint s_InitialPosition
static

Definition at line 51 of file editedge.cpp.

wxPoint s_LastPosition
static

Definition at line 52 of file editedge.cpp.

Referenced by Move_Segment().