Show field children when creating new labels.

And in particular, show reasonable intersheet reference facsimiles.
This commit is contained in:
Jeff Young 2021-04-02 11:18:25 +01:00
parent 04f7fbfa4a
commit c7d689a022
2 changed files with 39 additions and 24 deletions

View File

@ -1149,11 +1149,16 @@ bool SCH_GLOBALLABEL::ResolveTextVar( wxString* token, int aDepth ) const
{ {
if( token->IsSameAs( wxT( "INTERSHEET_REFS" ) ) && Schematic() ) if( token->IsSameAs( wxT( "INTERSHEET_REFS" ) ) && Schematic() )
{ {
SCHEMATIC_SETTINGS& settings = Schematic()->Settings();
wxString ref;
auto it = Schematic()->GetPageRefsMap().find( GetText() ); auto it = Schematic()->GetPageRefsMap().find( GetText() );
if( it != Schematic()->GetPageRefsMap().end() ) if( it == Schematic()->GetPageRefsMap().end() )
{
ref = "?";
}
else
{ {
SCHEMATIC_SETTINGS& settings = Schematic()->Settings();
std::vector<wxString> pageListCopy; std::vector<wxString> pageListCopy;
pageListCopy.insert( pageListCopy.end(), it->second.begin(), it->second.end() ); pageListCopy.insert( pageListCopy.end(), it->second.begin(), it->second.end() );
@ -1167,26 +1172,23 @@ bool SCH_GLOBALLABEL::ResolveTextVar( wxString* token, int aDepth ) const
currentPage ), pageListCopy.end() ); currentPage ), pageListCopy.end() );
} }
token->Printf( "%s", settings.m_IntersheetRefsPrefix );
if( ( settings.m_IntersheetRefsFormatShort ) && ( pageListCopy.size() > 2 ) ) if( ( settings.m_IntersheetRefsFormatShort ) && ( pageListCopy.size() > 2 ) )
{ {
token->Append( wxString::Format( wxT( "%s..%s" ), ref.Append( wxString::Format( wxT( "%s..%s" ),
pageListCopy.front(), pageListCopy.front(),
pageListCopy.back() ) ); pageListCopy.back() ) );
} }
else else
{ {
for( const wxString& pageNo : pageListCopy ) for( const wxString& pageNo : pageListCopy )
token->Append( wxString::Format( wxT( "%s," ), pageNo ) ); ref.Append( wxString::Format( wxT( "%s," ), pageNo ) );
if( !token->IsEmpty() && token->Last() == ',' ) if( !ref.IsEmpty() && ref.Last() == ',' )
token->RemoveLast(); ref.RemoveLast();
} }
token->Append( settings.m_IntersheetRefsSuffix );
} }
*token = settings.m_IntersheetRefsPrefix + ref + settings.m_IntersheetRefsSuffix;
return true; return true;
} }

View File

@ -806,6 +806,9 @@ SCH_TEXT* SCH_DRAWING_TOOLS::createNewText( const VECTOR2I& aPosition, int aType
case LAYER_GLOBLABEL: case LAYER_GLOBLABEL:
textItem = new SCH_GLOBALLABEL( (wxPoint) aPosition ); textItem = new SCH_GLOBALLABEL( (wxPoint) aPosition );
textItem->SetShape( m_lastGlobalLabelShape ); textItem->SetShape( m_lastGlobalLabelShape );
if( settings.m_IntersheetRefsShow )
static_cast<SCH_GLOBALLABEL*>( textItem )->GetIntersheetRefs()->SetVisible( true );
break; break;
default: default:
@ -936,6 +939,17 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::PENCIL ); m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::PENCIL );
}; };
auto updatePreview =
[&]()
{
m_view->ClearPreview();
m_view->AddToPreview( item->Clone() );
item->RunOnChildren( [&]( SCH_ITEM* aChild )
{
m_view->AddToPreview( aChild->Clone() );
} );
};
auto cleanup = auto cleanup =
[&]() [&]()
{ {
@ -1064,15 +1078,15 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
} }
} }
item->AutoplaceFields( /* aScreen */ nullptr, /* aManual */ false );
// Restore cursor after dialog // Restore cursor after dialog
controls->WarpCursor( controls->GetCursorPosition(), true ); controls->WarpCursor( controls->GetCursorPosition(), true );
if( item ) if( item )
{ {
item->SetFlags( IS_NEW | IS_MOVED ); item->SetFlags( IS_NEW | IS_MOVED );
m_view->ClearPreview(); updatePreview();
m_view->AddToPreview( item->Clone() );
m_selectionTool->AddItemToSel( item );
// update the cursor so it looks correct before another event // update the cursor so it looks correct before another event
setCursor(); setCursor();
@ -1085,8 +1099,6 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
else else
{ {
item->ClearFlags( IS_MOVED ); item->ClearFlags( IS_MOVED );
item->AutoplaceFields( /* aScreen */ nullptr, /* aManual */ false );
m_frame->AddItemToScreenAndUndoList( m_frame->GetScreen(), (SCH_ITEM*) item, false ); m_frame->AddItemToScreenAndUndoList( m_frame->GetScreen(), (SCH_ITEM*) item, false );
item = nullptr; item = nullptr;
@ -1109,8 +1121,7 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
if( selection.GetSize() == 1 ) if( selection.GetSize() == 1 )
{ {
item = (SCH_ITEM*) selection.Front(); item = (SCH_ITEM*) selection.Front();
m_view->ClearPreview(); updatePreview();
m_view->AddToPreview( item->Clone() );
} }
else else
{ {
@ -1119,9 +1130,11 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
} }
else if( item && ( evt->IsAction( &ACTIONS::refreshPreview ) || evt->IsMotion() ) ) else if( item && ( evt->IsAction( &ACTIONS::refreshPreview ) || evt->IsMotion() ) )
{ {
static_cast<SCH_ITEM*>( item )->SetPosition( (wxPoint) cursorPos ); SCH_ITEM* sch_item = static_cast<SCH_ITEM*>( item );
m_view->ClearPreview();
m_view->AddToPreview( item->Clone() ); item->SetPosition( (wxPoint) cursorPos );
item->AutoplaceFields( /* aScreen */ nullptr, /* aManual */ false );
updatePreview();
} }
else if( item && evt->IsAction( &ACTIONS::doDelete ) ) else if( item && evt->IsAction( &ACTIONS::doDelete ) )
{ {