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 <class_sch_screen.h>
#include <base_units.h>
#include <msgpanel.h>
#include <libeditframe.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 212 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().

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

Definition at line 376 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().

378 {
379  LIB_EDIT_FRAME* parent = (LIB_EDIT_FRAME*) aPanel->GetParent();
380 
381  if( parent == NULL )
382  return;
383 
384  LIB_PIN* cur_pin = (LIB_PIN*) parent->GetDrawItem();
385 
386  if( cur_pin == NULL || cur_pin->Type() != LIB_PIN_T )
387  return;
388 
389  wxPoint pinpos = cur_pin->GetPosition();
391 
392  if( parent->GetShowElectricalType() )
393  show_opts |= PIN_DRAW_ELECTRICAL_TYPE_NAME;
394 
395  // In LIB_PIN::Draw() a void* parameter used as flag to pass show_opts.
396  // Build it:
397  void* showOptions = reinterpret_cast<void*>( show_opts );
398 
399  // Erase pin in old position
400  if( aErase )
401  {
402  cur_pin->Move( PinPreviousPos );
403  cur_pin->Draw( aPanel, aDC, wxPoint( 0, 0 ), COLOR4D::UNSPECIFIED, g_XorMode,
404  showOptions, DefaultTransform );
405  }
406 
407  // Redraw pin in new position
408  cur_pin->Move( aPanel->GetParent()->GetCrossHairPosition( true ) );
409  cur_pin->Draw( aPanel, aDC, wxPoint( 0, 0 ), COLOR4D::UNSPECIFIED, g_XorMode,
410  showOptions, DefaultTransform );
411 
412  PinPreviousPos = cur_pin->GetPosition();
413 
414  /* Keep the original position for existing pin (for Undo command)
415  * and the current position for a new pin */
416  if( !cur_pin->IsNew() )
417  cur_pin->Move( pinpos );
418 }
GR_DRAWMODE g_XorMode
Definition: gr_basic.cpp:51
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
LIB_ITEM * GetDrawItem()
Definition: libeditframe.h:399
bool IsNew() const
Definition: base_struct.h:216
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:175
static wxPoint PinPreviousPos
Definition: pinedit.cpp:58
wxPoint GetPosition() const override
Function GetPosition returns the current draw object position.
Definition: lib_pin.h:471
The component library editor main window.
Definition: libeditframe.h:51
TRANSFORM DefaultTransform
Definition: eeschema.cpp:57
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.
void Move(const wxPoint &aPosition) override
Function Move moves a draw object to aPosition.
Definition: lib_pin.cpp:1969
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Function GetCrossHairPosition return the current cross hair position in logical (drawing) coordinates...
bool GetShowElectricalType()
Definition: libeditframe.h:407
static int GetLastPinLength ( )
static

Definition at line 71 of file pinedit.cpp.

References LIB_EDIT_FRAME::GetDefaultPinLength(), and LastPinLength.

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

72 {
73  if( LastPinLength == -1 )
75 
76  return LastPinLength;
77 }
static int GetDefaultPinLength()
Definition: libeditframe.h:168
static int LastPinLength
Definition: pinedit.cpp:67
static int GetLastPinNameSize ( )
static

Definition at line 79 of file pinedit.cpp.

References LIB_EDIT_FRAME::GetPinNameDefaultSize(), and LastPinNameSize.

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

80 {
81  if( LastPinNameSize == -1 )
83 
84  return LastPinNameSize;
85 }
static int LastPinNameSize
Definition: pinedit.cpp:68
static int GetPinNameDefaultSize()
Definition: libeditframe.h:164
static int GetLastPinNumSize ( )
static

Definition at line 87 of file pinedit.cpp.

References LIB_EDIT_FRAME::GetPinNumDefaultSize(), and LastPinNumSize.

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

88 {
89  if( LastPinNumSize == -1 )
91 
92  return LastPinNumSize;
93 }
static int LastPinNumSize
Definition: pinedit.cpp:69
static int GetPinNumDefaultSize()
Definition: libeditframe.h:160
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
bool sort_by_pin_number ( const LIB_PIN ref,
const LIB_PIN tst 
)

Definition at line 677 of file pinedit.cpp.

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

Referenced by LIB_EDIT_FRAME::OnCheckComponent().

678 {
679  int test = ref->GetNumber() - tst->GetNumber();
680 
681  if( test == 0 )
682  {
683  test = ref->GetConvert() - tst->GetConvert();
684  }
685 
686  if( test == 0 )
687  {
688  test = ref->GetUnit() - tst->GetUnit();
689  }
690 
691  return test < 0;
692 }
int GetUnit() const
long GetNumber() const
Definition: lib_pin.h:173
int GetConvert() const

Variable Documentation

bool LastPinCommonConvert = false
static

Definition at line 62 of file pinedit.cpp.

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

bool LastPinCommonUnit = false
static

Definition at line 63 of file pinedit.cpp.

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

int LastPinLength = -1
static

Definition at line 67 of file pinedit.cpp.

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

int LastPinNameSize = -1
static

Definition at line 68 of file pinedit.cpp.

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

int LastPinNumSize = -1
static

Definition at line 69 of file pinedit.cpp.

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

int LastPinOrient = PIN_RIGHT
static
bool LastPinVisible = true
static

Definition at line 64 of file pinedit.cpp.

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

wxPoint OldPos
static

Definition at line 57 of file pinedit.cpp.

wxPoint PinPreviousPos
static

Definition at line 58 of file pinedit.cpp.