Handle cascading selections in placement.

See https://forum.kicad.info/t/call-for-testers-eemodern/16663/32
This commit is contained in:
Jeff Young 2019-05-01 10:24:43 +01:00
parent e9dd8542d1
commit 58ba573038
8 changed files with 53 additions and 57 deletions

View File

@ -228,7 +228,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnBrowseLibrary( wxCommandEvent& event
LIB_ID id;
id.Parse( m_libraryNameTextCtrl->GetValue(), LIB_ID::ID_SCH );
auto sel = GetParent()->SelectComponentFromLibTree( nullptr, dummy, true, 0, 0, false, &id );
auto sel = GetParent()->SelectCompFromLibTree( nullptr, dummy, true, 0, 0, false, &id );
if( !sel.LibId.IsValid() )
return;

View File

@ -96,15 +96,15 @@ SCH_BASE_FRAME::COMPONENT_SELECTION SCH_BASE_FRAME::SelectComponentFromLibBrowse
}
SCH_BASE_FRAME::COMPONENT_SELECTION SCH_BASE_FRAME::SelectComponentFromLibTree(
const SCHLIB_FILTER* aFilter,
std::vector<COMPONENT_SELECTION>& aHistoryList,
bool aAllowBrowser,
int aUnit,
int aConvert,
bool aShowFootprints,
const LIB_ID* aHighlight,
bool aAllowFields )
SCH_BASE_FRAME::COMPONENT_SELECTION SCH_BASE_FRAME::SelectCompFromLibTree(
const SCHLIB_FILTER* aFilter,
std::vector<COMPONENT_SELECTION>& aHistoryList,
bool aUseLibBrowser,
int aUnit,
int aConvert,
bool aShowFootprints,
const LIB_ID* aHighlight,
bool aAllowFields )
{
std::unique_lock<std::mutex> dialogLock( DIALOG_CHOOSE_COMPONENT::g_Mutex, std::defer_lock );
wxString dialogTitle;
@ -167,7 +167,7 @@ SCH_BASE_FRAME::COMPONENT_SELECTION SCH_BASE_FRAME::SelectComponentFromLibTree(
dialogTitle.Printf( _( "Choose Symbol (%d items loaded)" ), adapter->GetItemCount() );
DIALOG_CHOOSE_COMPONENT dlg( this, dialogTitle, adapterPtr, aConvert,
aAllowFields, aShowFootprints, aAllowBrowser );
aAllowFields, aShowFootprints, aUseLibBrowser );
if( dlg.ShowQuasiModal() == wxID_CANCEL )
return COMPONENT_SELECTION();

View File

@ -1470,16 +1470,11 @@ void LIB_EDIT_FRAME::OnAddPartToSchematic( wxCommandEvent& event )
}
SCH_COMPONENT* component = new SCH_COMPONENT( *GetCurPart(), GetCurPart()->GetLibId(),
g_CurrentSheet, GetUnit(), GetConvert(),
wxPoint( 0, 0 ), true );
g_CurrentSheet, GetUnit(), GetConvert() );
// Be sure the link to the corresponding LIB_PART is OK:
component->Resolve( *Prj().SchSymbolLibTable() );
MSG_PANEL_ITEMS items;
component->GetMsgPanelInfo( schframe->GetUserUnits(), items );
schframe->SetMsgPanel( items );
if( schframe->GetAutoplaceFields() )
component->AutoplaceFields( /* aScreen */ NULL, /* aManual */ false );

View File

@ -222,7 +222,7 @@ public:
*
* @return the selected component
*/
COMPONENT_SELECTION SelectComponentFromLibTree(
COMPONENT_SELECTION SelectCompFromLibTree(
const SCHLIB_FILTER* aFilter,
std::vector<COMPONENT_SELECTION>& aHistoryList,
bool aUseLibBrowser,

View File

@ -122,7 +122,7 @@ SCH_COMPONENT::SCH_COMPONENT( const wxPoint& aPos, SCH_ITEM* aParent ) :
SCH_COMPONENT::SCH_COMPONENT( LIB_PART& aPart, LIB_ID aLibId, SCH_SHEET_PATH* sheet,
int unit, int convert, const wxPoint& pos, bool setNewItemFlag ) :
int unit, int convert, const wxPoint& pos ) :
SCH_ITEM( NULL, SCH_COMPONENT_T )
{
Init( pos );
@ -135,9 +135,6 @@ SCH_COMPONENT::SCH_COMPONENT( LIB_PART& aPart, LIB_ID aLibId, SCH_SHEET_PATH* sh
SetTimeStamp( GetNewTimeStamp() );
if( setNewItemFlag )
m_Flags = IS_NEW | IS_MOVED;
// Copy fields from the library component
UpdateFields( true, true );
@ -151,6 +148,20 @@ SCH_COMPONENT::SCH_COMPONENT( LIB_PART& aPart, LIB_ID aLibId, SCH_SHEET_PATH* sh
m_prefix = aPart.GetReferenceField().GetText() + wxT( "?" );
}
SCH_COMPONENT::SCH_COMPONENT( LIB_PART& aPart, SCH_SHEET_PATH* aSheet,
SCH_BASE_FRAME::COMPONENT_SELECTION& aSel, const wxPoint& pos ) :
SCH_COMPONENT( aPart, aSel.LibId, aSheet, aSel.Unit, aSel.Convert, pos )
{
// Set any fields that were modified as part of the component selection
for( auto const& i : aSel.Fields )
{
auto field = this->GetField( i.first );
if( field )
field->SetText( i.second );
}
}
SCH_COMPONENT::SCH_COMPONENT( const SCH_COMPONENT& aComponent ) :
SCH_ITEM( aComponent )

View File

@ -36,6 +36,7 @@
#include <set>
#include <lib_draw_item.h>
#include <sch_pin.h>
#include <sch_base_frame.h>
class SCH_SCREEN;
class SCH_SHEET_PATH;
@ -129,9 +130,11 @@ public:
*/
SCH_COMPONENT( LIB_PART& aPart, LIB_ID aLibId, SCH_SHEET_PATH* aSheet,
int unit = 0, int convert = 0,
const wxPoint& pos = wxPoint( 0, 0 ),
bool setNewItemFlag = false );
const wxPoint& pos = wxPoint( 0, 0 ) );
SCH_COMPONENT( LIB_PART& aPart, SCH_SHEET_PATH* aSheet,
SCH_BASE_FRAME::COMPONENT_SELECTION& aSel,
const wxPoint& pos = wxPoint( 0, 0 ) );
/**
* Clones \a aComponent into a new schematic symbol object.
*

View File

@ -350,21 +350,21 @@ int SCH_DRAWING_TOOL::doPlaceComponent( SCH_COMPONENT* aComponent, SCHLIB_FILTER
SCH_BASE_FRAME::HISTORY_LIST aHistoryList )
{
VECTOR2I cursorPos = m_controls->GetCursorPosition();
m_toolMgr->RunAction( SCH_ACTIONS::clearSelection, true );
m_controls->ShowCursor( true );
m_controls->SetSnapping( true );
Activate();
// Add all the drawable parts to preview
// If a component was passed in get it ready for placement.
if( aComponent )
{
aComponent->SetPosition( (wxPoint)cursorPos );
aComponent->SetFlags( IS_NEW | IS_MOVED );
m_frame->SaveCopyInUndoList( aComponent, UR_NEW, false );
m_toolMgr->RunAction( SCH_ACTIONS::clearSelection, true );
m_toolMgr->RunAction( SCH_ACTIONS::addItemToSel, true, aComponent );
m_view->ClearPreview();
m_view->AddToPreview( aComponent->Clone() );
// Queue up a refresh event so we don't have to wait for the next mouse-moved event
m_toolMgr->RunAction( SCH_ACTIONS::refreshPreview );
}
// Main loop: keep receiving events
@ -393,44 +393,36 @@ int SCH_DRAWING_TOOL::doPlaceComponent( SCH_COMPONENT* aComponent, SCHLIB_FILTER
{
if( !aComponent )
{
m_toolMgr->RunAction( SCH_ACTIONS::clearSelection, true );
m_frame->SetRepeatItem( nullptr );
// Pick the module to be placed
m_frame->SetRepeatItem( NULL );
m_frame->GetCanvas()->SetIgnoreMouseEvents( true );
auto sel = m_frame->SelectComponentFromLibTree( aFilter, aHistoryList, true, 1, 1,
m_frame->GetShowFootprintPreviews() );
auto sel = m_frame->SelectCompFromLibTree( aFilter, aHistoryList, true, 1, 1,
m_frame->GetShowFootprintPreviews());
m_frame->GetCanvas()->SetIgnoreMouseEvents( false );
// Restore cursor after dialog
m_frame->GetCanvas()->MoveCursorToCrossHair();
m_frame->GetCanvas()->SetIgnoreMouseEvents( false );
LIB_PART* part = nullptr;
if( sel.LibId.IsValid() )
part = m_frame->GetLibPart( sel.LibId );
LIB_PART* part = sel.LibId.IsValid() ? m_frame->GetLibPart( sel.LibId ) : nullptr;
if( !part )
continue;
aComponent = new SCH_COMPONENT( *part, sel.LibId, g_CurrentSheet, sel.Unit,
sel.Convert, (wxPoint)cursorPos, true );
aComponent = new SCH_COMPONENT( *part, g_CurrentSheet, sel, (wxPoint) cursorPos );
// Be sure the link to the corresponding LIB_PART is OK:
aComponent->Resolve( *m_frame->Prj().SchSymbolLibTable() );
// Set any fields that have been modified
for( auto const& i : sel.Fields )
{
auto field = aComponent->GetField( i.first );
if( field )
field->SetText( i.second );
}
if( m_frame->GetAutoplaceFields() )
aComponent->AutoplaceFields( /* aScreen */ NULL, /* aManual */ false );
aComponent->SetFlags( IS_MOVED );
aComponent->SetFlags( IS_NEW | IS_MOVED );
m_frame->SaveCopyInUndoList( aComponent, UR_NEW, false );
m_frame->SetRepeatItem( aComponent );
m_frame->GetScreen()->SetCurItem( aComponent );

View File

@ -819,16 +819,11 @@ void LIB_VIEW_FRAME::OnAddPartToSchematic( wxCommandEvent& aEvent )
SCH_COMPONENT* component = new SCH_COMPONENT( *getSelectedSymbol(),
getSelectedAlias()->GetLibId(),
g_CurrentSheet, m_unit, m_convert,
wxPoint( 0, 0 ), true );
g_CurrentSheet, m_unit, m_convert );
// Be sure the link to the corresponding LIB_PART is OK:
component->Resolve( *Prj().SchSymbolLibTable() );
MSG_PANEL_ITEMS items;
component->GetMsgPanelInfo( schframe->GetUserUnits(), items );
schframe->SetMsgPanel( items );
if( schframe->GetAutoplaceFields() )
component->AutoplaceFields( /* aScreen */ NULL, /* aManual */ false );