KiCad PCB EDA Suite
pinedit.cpp File Reference

Eeschema pin edit code. More...

#include <fctsys.h>
#include <gr_basic.h>
#include <class_drawpanel.h>
#include <confirm.h>
#include <base_units.h>
#include <msgpanel.h>
#include <lib_edit_frame.h>
#include <eeschema_id.h>
#include <class_libentry.h>
#include <lib_pin.h>
#include <general.h>
#include <../common/dialogs/dialog_display_info_HTML_base.h>
#include <dialog_lib_edit_pin.h>

Go to the source code of this file.

Functions

void IncrementLabelMember (wxString &name, int aIncrement)
 
static void AbortPinMove (EDA_DRAW_PANEL *Panel, wxDC *DC)
 Clean up after aborting a move pin command. More...
 
static void DrawMovePin (EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aPositon, bool aErase)
 
static int GetLastPinLength ()
 
static int GetLastPinNameSize ()
 
static int GetLastPinNumSize ()
 
bool sort_by_pin_number (const LIB_PIN *ref, const LIB_PIN *tst)
 

Variables

static wxPoint OldPos
 
static wxPoint PinPreviousPos
 
static ELECTRICAL_PINTYPE LastPinType = PIN_INPUT
 
static int LastPinOrient = PIN_RIGHT
 
static GRAPHIC_PINSHAPE LastPinShape = PINSHAPE_LINE
 
static bool LastPinCommonConvert = false
 
static bool LastPinCommonUnit = false
 
static bool LastPinVisible = true
 
static int LastPinLength = -1
 
static int LastPinNameSize = -1
 
static int LastPinNumSize = -1
 

Detailed Description

Eeschema pin edit code.

Definition in file pinedit.cpp.

Function Documentation

static void AbortPinMove ( EDA_DRAW_PANEL Panel,
wxDC *  DC 
)
static

Clean up after aborting a move pin command.

Definition at line 211 of file pinedit.cpp.

References EDA_ITEM::ClearFlags(), LIB_EDIT_FRAME::GetDrawItem(), EDA_DRAW_PANEL::GetParent(), EDA_ITEM::IsNew(), LIB_PIN_T, EDA_DRAW_PANEL::Refresh(), LIB_EDIT_FRAME::RestoreComponent(), LIB_EDIT_FRAME::SetDrawItem(), LIB_EDIT_FRAME::SetLastDrawItem(), and EDA_ITEM::Type().

Referenced by LIB_EDIT_FRAME::CreatePin(), and LIB_EDIT_FRAME::StartMovePin().

212 {
213  LIB_EDIT_FRAME* parent = (LIB_EDIT_FRAME*) Panel->GetParent();
214 
215  if( parent == NULL )
216  return;
217 
218  LIB_PIN* pin = (LIB_PIN*) parent->GetDrawItem();
219 
220  if( pin == NULL || pin->Type() != LIB_PIN_T )
221  return;
222 
223  pin->ClearFlags();
224 
225  if( pin->IsNew() )
226  delete pin;
227  else
228  parent->RestoreComponent();
229 
230  // clear edit flags
231  parent->SetDrawItem( NULL );
232  parent->SetLastDrawItem( NULL );
233  Panel->Refresh( true );
234 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:209
void RestoreComponent()
Restore the current edited component from its temporary copy.
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:338
bool IsNew() const
Definition: base_struct.h:227
void SetDrawItem(LIB_ITEM *drawItem)
void SetLastDrawItem(LIB_ITEM *drawItem)
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:180
The symbol library editor main window.
LIB_ITEM * GetDrawItem() const
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:265
static void DrawMovePin ( EDA_DRAW_PANEL aPanel,
wxDC *  aDC,
const wxPoint aPositon,
bool  aErase 
)
static

Definition at line 380 of file pinedit.cpp.

References DefaultTransform, LIB_ITEM::Draw(), g_XorMode, EDA_DRAW_FRAME::GetCrossHairPosition(), LIB_EDIT_FRAME::GetDrawItem(), EDA_DRAW_PANEL::GetParent(), LIB_PIN::GetPosition(), LIB_EDIT_FRAME::GetShowElectricalType(), EDA_ITEM::IsNew(), LIB_PIN_T, LIB_PIN::Move(), PIN_DANGLING_HIDDEN, PIN_DRAW_DANGLING, PIN_DRAW_ELECTRICAL_TYPE_NAME, PIN_DRAW_TEXTS, and EDA_ITEM::Type().

Referenced by LIB_EDIT_FRAME::CreatePin(), and LIB_EDIT_FRAME::StartMovePin().

382 {
383  LIB_EDIT_FRAME* parent = (LIB_EDIT_FRAME*) aPanel->GetParent();
384 
385  if( parent == NULL )
386  return;
387 
388  LIB_PIN* cur_pin = (LIB_PIN*) parent->GetDrawItem();
389 
390  if( cur_pin == NULL || cur_pin->Type() != LIB_PIN_T )
391  return;
392 
393  wxPoint pinpos = cur_pin->GetPosition();
395 
396  if( parent->GetShowElectricalType() )
397  show_opts |= PIN_DRAW_ELECTRICAL_TYPE_NAME;
398 
399  // In LIB_PIN::Draw() a void* parameter used as flag to pass show_opts.
400  // Build it:
401  void* showOptions = reinterpret_cast<void*>( show_opts );
402 
403  // Erase pin in old position
404  if( aErase )
405  {
406  cur_pin->Move( PinPreviousPos );
407  cur_pin->Draw( aPanel, aDC, wxPoint( 0, 0 ), COLOR4D::UNSPECIFIED, g_XorMode,
408  showOptions, DefaultTransform );
409  }
410 
411  // Redraw pin in new position
412  cur_pin->Move( aPanel->GetParent()->GetCrossHairPosition( true ) );
413  cur_pin->Draw( aPanel, aDC, wxPoint( 0, 0 ), COLOR4D::UNSPECIFIED, g_XorMode,
414  showOptions, DefaultTransform );
415 
416  PinPreviousPos = cur_pin->GetPosition();
417 
418  /* Keep the original position for existing pin (for Undo command)
419  * and the current position for a new pin */
420  if( !cur_pin->IsNew() )
421  cur_pin->Move( pinpos );
422 }
GR_DRAWMODE g_XorMode
Definition: gr_basic.cpp:73
KICAD_T Type() const
Function Type()
Definition: base_struct.h:209
bool IsNew() const
Definition: base_struct.h:227
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:180
static wxPoint PinPreviousPos
Definition: pinedit.cpp:57
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_pin.h:462
The symbol library editor main window.
TRANSFORM DefaultTransform
Definition: eeschema.cpp:58
virtual void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aOffset, COLOR4D aColor, GR_DRAWMODE aDrawMode, void *aData, const TRANSFORM &aTransform)
Draw an item.
LIB_ITEM * GetDrawItem() const
void Move(const wxPoint &aPosition) override
Move a draw object to aPosition.
Definition: lib_pin.cpp:1591
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Function GetCrossHairPosition return the current cross hair position in logical (drawing) coordinates...
bool GetShowElectricalType()
static int GetLastPinLength ( )
static

Definition at line 70 of file pinedit.cpp.

References LIB_EDIT_FRAME::GetDefaultPinLength(), and LastPinLength.

Referenced by LIB_EDIT_FRAME::CreatePin(), and LIB_EDIT_FRAME::OnEditPin().

71 {
72  if( LastPinLength == -1 )
74 
75  return LastPinLength;
76 }
static int GetDefaultPinLength()
static int LastPinLength
Definition: pinedit.cpp:66
static int GetLastPinNameSize ( )
static

Definition at line 78 of file pinedit.cpp.

References LIB_EDIT_FRAME::GetPinNameDefaultSize(), and LastPinNameSize.

Referenced by LIB_EDIT_FRAME::CreatePin(), and LIB_EDIT_FRAME::OnEditPin().

79 {
80  if( LastPinNameSize == -1 )
82 
83  return LastPinNameSize;
84 }
static int LastPinNameSize
Definition: pinedit.cpp:67
static int GetPinNameDefaultSize()
static int GetLastPinNumSize ( )
static

Definition at line 86 of file pinedit.cpp.

References LIB_EDIT_FRAME::GetPinNumDefaultSize(), and LastPinNumSize.

Referenced by LIB_EDIT_FRAME::CreatePin(), and LIB_EDIT_FRAME::OnEditPin().

87 {
88  if( LastPinNumSize == -1 )
90 
91  return LastPinNumSize;
92 }
static int LastPinNumSize
Definition: pinedit.cpp:68
static int GetPinNumDefaultSize()
void IncrementLabelMember ( wxString &  name,
int  aIncrement 
)

Definition at line 293 of file edit_label.cpp.

Referenced by LIB_EDIT_FRAME::RepeatPinItem().

294 {
295  int ii, nn;
296  long number = 0;
297 
298  ii = name.Len() - 1; nn = 0;
299 
300  if( !isdigit( name.GetChar( ii ) ) )
301  return;
302 
303  while( (ii >= 0) && isdigit( name.GetChar( ii ) ) )
304  {
305  ii--; nn++;
306  }
307 
308  ii++; /* digits are starting at ii position */
309  wxString litt_number = name.Right( nn );
310 
311  if( litt_number.ToLong( &number ) )
312  {
313  number += aIncrement;
314  name.Remove( ii ); name << number;
315  }
316 }
const char * name
Definition: DXF_plotter.cpp:61
bool sort_by_pin_number ( const LIB_PIN ref,
const LIB_PIN tst 
)

Definition at line 664 of file pinedit.cpp.

References LIB_ITEM::GetConvert(), LIB_PIN::GetNumber(), and LIB_ITEM::GetUnit().

Referenced by LIB_EDIT_FRAME::OnCheckComponent().

665 {
666  int test = ref->GetNumber().Cmp( tst->GetNumber() );
667 
668  if( test == 0 )
669  {
670  test = ref->GetConvert() - tst->GetConvert();
671  }
672 
673  if( test == 0 )
674  {
675  test = ref->GetUnit() - tst->GetUnit();
676  }
677 
678  return test < 0;
679 }
int GetUnit() const
const wxString & GetNumber() const
Definition: lib_pin.h:193
int GetConvert() const

Variable Documentation

bool LastPinCommonConvert = false
static

Definition at line 61 of file pinedit.cpp.

Referenced by LIB_EDIT_FRAME::CreatePin(), and LIB_EDIT_FRAME::OnEditPin().

bool LastPinCommonUnit = false
static

Definition at line 62 of file pinedit.cpp.

Referenced by LIB_EDIT_FRAME::CreatePin(), and LIB_EDIT_FRAME::OnEditPin().

int LastPinLength = -1
static

Definition at line 66 of file pinedit.cpp.

Referenced by GetLastPinLength(), and LIB_EDIT_FRAME::OnEditPin().

int LastPinNameSize = -1
static

Definition at line 67 of file pinedit.cpp.

Referenced by GetLastPinNameSize(), and LIB_EDIT_FRAME::OnEditPin().

int LastPinNumSize = -1
static

Definition at line 68 of file pinedit.cpp.

Referenced by GetLastPinNumSize(), and LIB_EDIT_FRAME::OnEditPin().

int LastPinOrient = PIN_RIGHT
static
bool LastPinVisible = true
static

Definition at line 63 of file pinedit.cpp.

Referenced by LIB_EDIT_FRAME::CreatePin(), and LIB_EDIT_FRAME::OnEditPin().

wxPoint OldPos
static

Definition at line 56 of file pinedit.cpp.

wxPoint PinPreviousPos
static

Definition at line 57 of file pinedit.cpp.