diff --git a/eeschema/sch_text.cpp b/eeschema/sch_text.cpp index 38c1c64f9e..69a8e89af9 100644 --- a/eeschema/sch_text.cpp +++ b/eeschema/sch_text.cpp @@ -1149,11 +1149,16 @@ bool SCH_GLOBALLABEL::ResolveTextVar( wxString* token, int aDepth ) const { if( token->IsSameAs( wxT( "INTERSHEET_REFS" ) ) && Schematic() ) { - auto it = Schematic()->GetPageRefsMap().find( GetText() ); + SCHEMATIC_SETTINGS& settings = Schematic()->Settings(); + wxString ref; + 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 pageListCopy; 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() ); } - token->Printf( "%s", settings.m_IntersheetRefsPrefix ); - if( ( settings.m_IntersheetRefsFormatShort ) && ( pageListCopy.size() > 2 ) ) { - token->Append( wxString::Format( wxT( "%s..%s" ), - pageListCopy.front(), - pageListCopy.back() ) ); + ref.Append( wxString::Format( wxT( "%s..%s" ), + pageListCopy.front(), + pageListCopy.back() ) ); } else { for( const wxString& pageNo : pageListCopy ) - token->Append( wxString::Format( wxT( "%s," ), pageNo ) ); + ref.Append( wxString::Format( wxT( "%s," ), pageNo ) ); - if( !token->IsEmpty() && token->Last() == ',' ) - token->RemoveLast(); + if( !ref.IsEmpty() && ref.Last() == ',' ) + ref.RemoveLast(); } - - token->Append( settings.m_IntersheetRefsSuffix ); } + *token = settings.m_IntersheetRefsPrefix + ref + settings.m_IntersheetRefsSuffix; return true; } diff --git a/eeschema/tools/sch_drawing_tools.cpp b/eeschema/tools/sch_drawing_tools.cpp index 07e44db430..797ef01554 100644 --- a/eeschema/tools/sch_drawing_tools.cpp +++ b/eeschema/tools/sch_drawing_tools.cpp @@ -806,6 +806,9 @@ SCH_TEXT* SCH_DRAWING_TOOLS::createNewText( const VECTOR2I& aPosition, int aType case LAYER_GLOBLABEL: textItem = new SCH_GLOBALLABEL( (wxPoint) aPosition ); textItem->SetShape( m_lastGlobalLabelShape ); + + if( settings.m_IntersheetRefsShow ) + static_cast( textItem )->GetIntersheetRefs()->SetVisible( true ); break; default: @@ -936,8 +939,19 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent ) 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 = - [&] () + [&]() { m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); m_view->ClearPreview(); @@ -1064,15 +1078,15 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent ) } } + item->AutoplaceFields( /* aScreen */ nullptr, /* aManual */ false ); + // Restore cursor after dialog controls->WarpCursor( controls->GetCursorPosition(), true ); if( item ) { item->SetFlags( IS_NEW | IS_MOVED ); - m_view->ClearPreview(); - m_view->AddToPreview( item->Clone() ); - m_selectionTool->AddItemToSel( item ); + updatePreview(); // update the cursor so it looks correct before another event setCursor(); @@ -1085,8 +1099,6 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent ) else { item->ClearFlags( IS_MOVED ); - item->AutoplaceFields( /* aScreen */ nullptr, /* aManual */ false ); - m_frame->AddItemToScreenAndUndoList( m_frame->GetScreen(), (SCH_ITEM*) item, false ); item = nullptr; @@ -1109,8 +1121,7 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent ) if( selection.GetSize() == 1 ) { item = (SCH_ITEM*) selection.Front(); - m_view->ClearPreview(); - m_view->AddToPreview( item->Clone() ); + updatePreview(); } else { @@ -1119,9 +1130,11 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent ) } else if( item && ( evt->IsAction( &ACTIONS::refreshPreview ) || evt->IsMotion() ) ) { - static_cast( item )->SetPosition( (wxPoint) cursorPos ); - m_view->ClearPreview(); - m_view->AddToPreview( item->Clone() ); + SCH_ITEM* sch_item = static_cast( item ); + + item->SetPosition( (wxPoint) cursorPos ); + item->AutoplaceFields( /* aScreen */ nullptr, /* aManual */ false ); + updatePreview(); } else if( item && evt->IsAction( &ACTIONS::doDelete ) ) {