symbol editor: Improve pin duplication
When duplicating pins in the symbol editor the duplicated pins will have unique pin numbers assigned if the duplication target had the pin number specified
This commit is contained in:
parent
0536ab4f6c
commit
487c8f8e39
|
@ -1153,6 +1153,27 @@ bool LIB_SYMBOL::HasConversion() const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int LIB_SYMBOL::GetMaxPinNumber() const
|
||||||
|
{
|
||||||
|
int maxPinNumber = 0;
|
||||||
|
LIB_SYMBOL_SPTR parent = m_parent.lock();
|
||||||
|
const LIB_ITEMS_CONTAINER& drawItems = parent ? parent->m_drawings : m_drawings;
|
||||||
|
|
||||||
|
for( const LIB_ITEM& item : drawItems[LIB_PIN_T] )
|
||||||
|
{
|
||||||
|
const LIB_PIN* pin = static_cast<const LIB_PIN*>( &item );
|
||||||
|
long currentPinNumber = 0;
|
||||||
|
bool isNum = pin->GetNumber().ToLong( ¤tPinNumber );
|
||||||
|
|
||||||
|
if( isNum && currentPinNumber > maxPinNumber )
|
||||||
|
{
|
||||||
|
maxPinNumber = currentPinNumber;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return maxPinNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void LIB_SYMBOL::ClearTempFlags()
|
void LIB_SYMBOL::ClearTempFlags()
|
||||||
{
|
{
|
||||||
|
|
|
@ -453,6 +453,12 @@ public:
|
||||||
*/
|
*/
|
||||||
bool HasConversion() const;
|
bool HasConversion() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the highest pin number of the symbol's pins.
|
||||||
|
* If none of the pins has pin number assigned it returns 0.
|
||||||
|
*/
|
||||||
|
int GetMaxPinNumber() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the status flag all draw objects in this symbol.
|
* Clears the status flag all draw objects in this symbol.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -605,6 +605,17 @@ void SYMBOL_EDITOR_EDIT_TOOL::editSymbolProperties()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SYMBOL_EDITOR_EDIT_TOOL::handlePinDuplication( LIB_PIN* aOldPin, LIB_PIN* aNewPin,
|
||||||
|
int& aSymbolLastPinNumber )
|
||||||
|
{
|
||||||
|
if( !aNewPin->GetNumber().IsEmpty() )
|
||||||
|
{
|
||||||
|
// when duplicating a pin in symbol editor, assigning identical pin number
|
||||||
|
// to the old one does not makes any sense, so assign the next unassigned number to it
|
||||||
|
aSymbolLastPinNumber++;
|
||||||
|
aNewPin->SetNumber( wxString::Format( wxT( "%i" ), aSymbolLastPinNumber ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int SYMBOL_EDITOR_EDIT_TOOL::PinTable( const TOOL_EVENT& aEvent )
|
int SYMBOL_EDITOR_EDIT_TOOL::PinTable( const TOOL_EVENT& aEvent )
|
||||||
{
|
{
|
||||||
|
@ -803,11 +814,24 @@ int SYMBOL_EDITOR_EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent )
|
||||||
saveCopyInUndoList( m_frame->GetCurSymbol(), UNDO_REDO::LIBEDIT );
|
saveCopyInUndoList( m_frame->GetCurSymbol(), UNDO_REDO::LIBEDIT );
|
||||||
|
|
||||||
EDA_ITEMS newItems;
|
EDA_ITEMS newItems;
|
||||||
|
int symbolLastPinNumber = -1;
|
||||||
|
|
||||||
for( unsigned ii = 0; ii < selection.GetSize(); ++ii )
|
for( unsigned ii = 0; ii < selection.GetSize(); ++ii )
|
||||||
{
|
{
|
||||||
LIB_ITEM* oldItem = static_cast<LIB_ITEM*>( selection.GetItem( ii ) );
|
LIB_ITEM* oldItem = static_cast<LIB_ITEM*>( selection.GetItem( ii ) );
|
||||||
LIB_ITEM* newItem = (LIB_ITEM*) oldItem->Clone();
|
LIB_ITEM* newItem = (LIB_ITEM*) oldItem->Clone();
|
||||||
|
|
||||||
|
if( oldItem->Type() == LIB_PIN_T )
|
||||||
|
{
|
||||||
|
if( symbolLastPinNumber == -1 )
|
||||||
|
{
|
||||||
|
symbolLastPinNumber = symbol->GetMaxPinNumber();
|
||||||
|
}
|
||||||
|
|
||||||
|
handlePinDuplication( static_cast<LIB_PIN*>( oldItem ),
|
||||||
|
static_cast<LIB_PIN*>( newItem ), symbolLastPinNumber );
|
||||||
|
}
|
||||||
|
|
||||||
oldItem->ClearFlags( IS_NEW | IS_PASTED | SELECTED );
|
oldItem->ClearFlags( IS_NEW | IS_PASTED | SELECTED );
|
||||||
newItem->SetFlags( IS_NEW | IS_PASTED | SELECTED );
|
newItem->SetFlags( IS_NEW | IS_PASTED | SELECTED );
|
||||||
newItem->SetParent( symbol );
|
newItem->SetParent( symbol );
|
||||||
|
|
|
@ -69,6 +69,7 @@ private:
|
||||||
void editTextBoxProperties( LIB_ITEM* aItem );
|
void editTextBoxProperties( LIB_ITEM* aItem );
|
||||||
void editFieldProperties( LIB_FIELD* aField );
|
void editFieldProperties( LIB_FIELD* aField );
|
||||||
void editSymbolProperties();
|
void editSymbolProperties();
|
||||||
|
void handlePinDuplication(LIB_PIN* aOldPin, LIB_PIN* aNewPin, int &aSymbolLastPinNumber );
|
||||||
|
|
||||||
///< Set up handlers for various events.
|
///< Set up handlers for various events.
|
||||||
void setTransitions() override;
|
void setTransitions() override;
|
||||||
|
|
Loading…
Reference in New Issue