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 <wxPcbStruct.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 212 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(), and EDA_DRAW_PANEL::SetMouseCapture().

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

213 {
214  DRAWSEGMENT* Segment = (DRAWSEGMENT*) aPanel->GetScreen()->GetCurItem();
215 
216  if( Segment == NULL )
217  {
218  aPanel->SetMouseCapture( NULL, NULL );
219  return;
220  }
221 
222  if( Segment->IsNew() )
223  {
224  aPanel->CallMouseCapture( DC, wxDefaultPosition, false );
225  Segment ->DeleteStructure();
226  Segment = NULL;
227  }
228  else
229  {
230  wxPoint pos = aPanel->GetParent()->GetCrossHairPosition();
232  aPanel->CallMouseCapture( DC, wxDefaultPosition, true );
233  aPanel->GetParent()->SetCrossHairPosition( pos );
234  Segment->ClearFlags();
235  Segment->Draw( aPanel, DC, GR_OR );
236  }
237 
238 #ifdef USE_WX_OVERLAY
239  aPanel->Refresh();
240 #endif
241 
242  aPanel->SetMouseCapture( NULL, NULL );
243  ( (PCB_EDIT_FRAME*) aPanel->GetParent() )->SetCurItem( NULL );
244 }
EDA_ITEM * GetCurItem() const
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
bool IsNew() const
Definition: base_struct.h:230
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...
void CallMouseCapture(wxDC *aDC, const wxPoint &aPosition, bool aErase)
Function CallMouseCapture calls the mouse capture callback.
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:174
Definition: gr_basic.h:42
BASE_SCREEN * GetScreen()
Definition: draw_panel.cpp:187
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 SetCrossHairPosition(const wxPoint &aPosition, bool aSnapToGrid=true)
Function SetCrossHairPosition sets the screen cross hair position to aPosition in logical (drawing) u...
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
Function GetCrossHairPosition 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 343 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, DISPLAY_OPTIONS::m_DisplayDrawItemsFill, S_SEGMENT, DRAWSEGMENT::SetEnd(), and SKETCH.

Referenced by PCB_EDIT_FRAME::Begin_DrawSegment().

344 {
345  DRAWSEGMENT* Segment = (DRAWSEGMENT*) aPanel->GetScreen()->GetCurItem();
346  auto frame = (PCB_EDIT_FRAME*) ( aPanel->GetParent() );
347  if( Segment == NULL )
348  return;
349 
350  DISPLAY_OPTIONS* displ_opts = (DISPLAY_OPTIONS*)aPanel->GetDisplayOptions();
351  bool tmp = displ_opts->m_DisplayDrawItemsFill;
352 
353  displ_opts->m_DisplayDrawItemsFill = SKETCH;
354 
355  if( aErase )
356  Segment->Draw( aPanel, aDC, GR_XOR );
357 
358  if( frame->Settings().m_use45DegreeGraphicSegments && Segment->GetShape() == S_SEGMENT )
359  {
360  wxPoint pt;
361 
363  Segment->GetStart() );
364  Segment->SetEnd( pt );
365  }
366  else // here the angle is arbitrary
367  {
368  Segment->SetEnd( aPanel->GetParent()->GetCrossHairPosition() );
369  }
370 
371  Segment->Draw( aPanel, aDC, GR_XOR );
372  displ_opts->m_DisplayDrawItemsFill = tmp;
373 }
EDA_ITEM * GetCurItem() const
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's position from the ...
Definition: editrack.cpp:831
STROKE_T GetShape() const
bool m_DisplayDrawItemsFill
Definition: pcbstruct.h:84
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:174
Class DISPLAY_OPTIONS handles display options like enable/disable some optional drawings.
Definition: pcbstruct.h:62
BASE_SCREEN * GetScreen()
Definition: draw_panel.cpp:187
void SetEnd(const wxPoint &aEnd)
void * GetDisplayOptions()
Function GetDisplayOptions A way to pass info to draw functions.
Definition: draw_panel.cpp:181
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
Function GetCrossHairPosition 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(), DRAWSEGMENT::GetEnd(), EDA_DRAW_PANEL::GetParent(), EDA_DRAW_PANEL::GetScreen(), DRAWSEGMENT::GetStart(), GR_XOR, s_LastPosition, DRAWSEGMENT::SetEnd(), and DRAWSEGMENT::SetStart().

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->SetStart( segment->GetStart() + delta );
105  segment->SetEnd( segment->GetEnd() + delta );
106 
108 
109  segment->Draw( aPanel, aDC, GR_XOR );
110 }
EDA_ITEM * GetCurItem() const
static const int delta[8][2]
Definition: solve.cpp:112
const wxPoint & GetEnd() const
Function GetEnd returns the ending point of the graphic.
static wxPoint s_LastPosition
Definition: editedge.cpp:52
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:174
void SetStart(const wxPoint &aStart)
BASE_SCREEN * GetScreen()
Definition: draw_panel.cpp:187
void SetEnd(const wxPoint &aEnd)
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
Function GetCrossHairPosition 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().