Symbol editor: rework on multi-unit symbols: pin edition synchronization is now only between units (Work in progress)

The synchronization between body styles of the same units is removed.
This is easier to understand by users.
This commit is contained in:
jean-pierre charras 2018-01-09 08:54:24 +01:00
parent 1d2752ee47
commit 019eed0d28
3 changed files with 52 additions and 68 deletions

View File

@ -617,7 +617,7 @@ void LIB_EDIT_FRAME::OnUpdatePinByPin( wxUpdateUIEvent& event )
{
LIB_PART* part = GetCurPart();
event.Enable( part && ( part->GetUnitCount() > 1 || m_showDeMorgan ) );
event.Enable( part && part->GetUnitCount() > 1 && !part->UnitsLocked() );
event.Check( m_editPinsSeparately );
}
@ -1412,24 +1412,30 @@ void LIB_EDIT_FRAME::deleteItem( wxDC* aDC )
if( item->Type() == LIB_PIN_T )
{
LIB_PIN* pin = (LIB_PIN*) item;
LIB_PIN* pin = static_cast<LIB_PIN*>( item );
wxPoint pos = pin->GetPosition();
part->RemoveDrawItem( (LIB_ITEM*) pin, m_canvas, aDC );
// when pin edition is synchronized, all pins of the same body style
// are removed:
if( SynchronizePins() )
{
LIB_PIN* tmp = part->GetNextPin();
int curr_convert = pin->GetConvert();
LIB_PIN* next_pin = part->GetNextPin();
while( tmp != NULL )
while( next_pin != NULL )
{
pin = tmp;
tmp = part->GetNextPin( pin );
pin = next_pin;
next_pin = part->GetNextPin( pin );
if( pin->GetPosition() != pos )
continue;
part->RemoveDrawItem( (LIB_ITEM*) pin );
if( pin->GetConvert() != curr_convert )
continue;
part->RemoveDrawItem( pin );
}
}
@ -1495,8 +1501,7 @@ bool LIB_EDIT_FRAME::SynchronizePins()
{
LIB_PART* part = GetCurPart();
return !m_editPinsSeparately && ( part &&
( part->HasConversion() || part->IsMulti() ) );
return !m_editPinsSeparately && part && part->IsMulti() && !part->UnitsLocked();
}

View File

@ -210,9 +210,12 @@ public:
void Process_Config( wxCommandEvent& event );
/**
* @return True if the edit pins per part or convert is false and the current
* component has multiple parts or body styles. Otherwise false is
* returned.
* Pin edition (add, delete, move...) can be synchronized between units
* when units are interchangeable because in this case similar pins are expected
* at the same location
* @return true if the edit pins separately option is false and the current symbol
* has multiple interchengeable units.
* Otherwise return false.
*/
bool SynchronizePins();
@ -566,16 +569,11 @@ private:
void StartMovePin( wxDC* DC );
/**
* Adds copies of \a aPin for \a aUnit in components with multiple parts and
* \a aConvert for components that have multiple body styles.
* Adds copies of \a aPin in components with multiple units in all units
*
* @param aPin The pin to copy.
* @param aUnit The unit to add a copy of \a aPin to.
* @param aConvert The alternate body style to add a copy of \a aPin to.
* @param aDeMorgan Flag to indicate if \a aPin should be created for the
* alternate body style.
* @param aPin The pin to copy to others units.
*/
void CreateImagePins( LIB_PIN* aPin, int aUnit, int aConvert, bool aDeMorgan );
void CreateImagePins( LIB_PIN* aPin );
/**
* Places an anchor reference coordinate for the current component.

View File

@ -1,9 +1,9 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
* Copyright (C) 2004-2018 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -241,9 +241,6 @@ static void AbortPinMove( EDA_DRAW_PANEL* Panel, wxDC* DC )
void LIB_EDIT_FRAME::PlacePin()
{
LIB_PIN* cur_pin = (LIB_PIN*) GetDrawItem();
bool ask_for_pin = true;
wxPoint newpos;
bool status;
// Some tests
if( !cur_pin || cur_pin->Type() != LIB_PIN_T )
@ -252,16 +249,23 @@ void LIB_EDIT_FRAME::PlacePin()
return;
}
wxPoint newpos;
newpos = GetCrossHairPosition( true );
LIB_PART* part = GetCurPart();
// Test for an other pin in same new position:
for( LIB_PIN* pin = part->GetNextPin(); pin; pin = part->GetNextPin( pin ) )
// Test for an other pin in same new position in other units:
bool ask_for_pin = true;
for( LIB_PIN* pin = part->GetNextPin(); pin; pin = part->GetNextPin( pin ) )
{
if( pin == cur_pin || newpos != pin->GetPosition() || pin->GetFlags() )
continue;
// test for same body style
if( pin->GetConvert() && pin->GetConvert() != cur_pin->GetConvert() )
continue;
if( ask_for_pin && SynchronizePins() )
{
m_canvas->SetIgnoreMouseEvents( true );
@ -269,7 +273,7 @@ void LIB_EDIT_FRAME::PlacePin()
msg.Printf( _( "This position is already occupied by another pin, in unit %d.\n"
"Continue?" ), pin->GetUnit() );
status = IsOK( this, msg );
bool status = IsOK( this, msg );
m_canvas->MoveCursorToCrossHair();
m_canvas->SetIgnoreMouseEvents( false );
@ -298,7 +302,7 @@ void LIB_EDIT_FRAME::PlacePin()
LastPinShape = cur_pin->GetShape();
if( SynchronizePins() )
CreateImagePins( cur_pin, m_unit, m_convert, m_showDeMorgan );
CreateImagePins( cur_pin );
m_lastDrawItem = cur_pin;
part->AddDrawItem( GetDrawItem() );
@ -336,16 +340,22 @@ void LIB_EDIT_FRAME::StartMovePin( wxDC* DC )
LIB_PART* part = GetCurPart();
// Mark pins for moving.
for( LIB_PIN* pin = part->GetNextPin(); pin; pin = part->GetNextPin( pin ) )
// Clear pin flags and mark pins for moving. All pins having the same location
// orientation, and body style are flagged.
for( LIB_PIN* pin = part->GetNextPin(); pin; pin = part->GetNextPin( pin ) )
{
pin->ClearFlags();
if( !SynchronizePins() )
continue;
if( pin == cur_pin )
continue;
if( pin->GetPosition() == cur_pin->GetPosition() &&
pin->GetOrientation() == cur_pin->GetOrientation() && SynchronizePins() )
pin->GetOrientation() == cur_pin->GetOrientation() &&
pin->GetConvert() == cur_pin->GetConvert()
)
{
pin->SetFlags( IS_LINKED | IS_MOVED );
}
@ -489,7 +499,7 @@ void LIB_EDIT_FRAME::CreatePin( wxDC* DC )
}
void LIB_EDIT_FRAME::CreateImagePins( LIB_PIN* aPin, int aUnit, int aConvert, bool aDeMorgan )
void LIB_EDIT_FRAME::CreateImagePins( LIB_PIN* aPin )
{
int ii;
LIB_PIN* newPin;
@ -499,33 +509,17 @@ void LIB_EDIT_FRAME::CreateImagePins( LIB_PIN* aPin, int aUnit, int aConvert, bo
if( !SynchronizePins() )
return;
// When units are interchangeable, all units are expected to have similar pins
// at the same position
// to facilitate pin edition, create pins for all other units and all other shapes
// at the same position as aPin
// For the current unit, provide a pin for the "convert" body style,
// at the current position, if the pin is not common to all body styles.
if( aDeMorgan && ( aPin->GetConvert() != 0 ) )
{
newPin = (LIB_PIN*) aPin->Clone();
if( aPin->GetConvert() > 1 )
newPin->SetConvert( 1 );
else
newPin->SetConvert( 2 );
aPin->GetParent()->AddDrawItem( newPin );
}
// to facilitate pin edition, create similar pins for all other units at
// the same position as aPin
if( aPin->GetUnit() == 0 ) // Pin common to all units: no need to create similar pins.
return;
// When units are interchangeable, all units are expected to have similar pins
// at the same position
// to facilitate pin edition, create pins for all other units for the current body style
// at the same position as aPin
for( ii = 1; ii <= aPin->GetParent()->GetUnitCount(); ii++ )
{
if( ii == aUnit )
if( ii == aPin->GetUnit() )
continue;
newPin = (LIB_PIN*) aPin->Clone();
@ -537,21 +531,8 @@ void LIB_EDIT_FRAME::CreateImagePins( LIB_PIN* aPin, int aUnit, int aConvert, bo
unknownNum.Printf( "%s-U%c", aPin->GetNumber(), wxChar( 'A' + ii - 1 ) );
newPin->SetNumber( unknownNum );
if( aConvert != 0 )
newPin->SetConvert( 1 );
newPin->SetUnit( ii );
aPin->GetParent()->AddDrawItem( newPin );
// If this new pin is common to shapes, no need to create a similar pin for other body style
if( !( aDeMorgan && ( aPin->GetConvert() != 0 ) ) )
continue;
// add a similar pin to the other body style
newPin = (LIB_PIN*) newPin->Clone();
newPin->SetConvert( 2 );
aPin->GetParent()->AddDrawItem( newPin );
}
}