Show preview object for Eeschema junction, noconnect and bus entry tools.

This commit is contained in:
Jeff Young 2019-06-28 19:32:18 +01:00
parent c9ccd8a642
commit a72b5416c3
1 changed files with 55 additions and 45 deletions

View File

@ -349,9 +349,23 @@ int SCH_DRAWING_TOOLS::SingleClickPlace( const TOOL_EVENT& aEvent )
wxPoint cursorPos; wxPoint cursorPos;
KICAD_T type = aEvent.Parameter<KICAD_T>(); KICAD_T type = aEvent.Parameter<KICAD_T>();
if( type == SCH_JUNCTION_T ) auto itemFactory = [&] () -> SCH_ITEM* {
switch( type )
{ {
if( aEvent.HasPosition() ) case SCH_NO_CONNECT_T:
return new SCH_NO_CONNECT( cursorPos );
case SCH_JUNCTION_T:
return new SCH_JUNCTION( cursorPos );
case SCH_BUS_WIRE_ENTRY_T:
return new SCH_BUS_WIRE_ENTRY( cursorPos, g_lastBusEntryShape );
case SCH_BUS_BUS_ENTRY_T:
return new SCH_BUS_BUS_ENTRY( cursorPos, g_lastBusEntryShape );
default:
return nullptr;
}
};
if( type == SCH_JUNCTION_T && aEvent.HasPosition() )
{ {
EE_SELECTION& selection = m_selectionTool->GetSelection(); EE_SELECTION& selection = m_selectionTool->GetSelection();
SCH_LINE* wire = dynamic_cast<SCH_LINE*>( selection.Front() ); SCH_LINE* wire = dynamic_cast<SCH_LINE*>( selection.Front() );
@ -364,14 +378,18 @@ int SCH_DRAWING_TOOLS::SingleClickPlace( const TOOL_EVENT& aEvent )
getViewControls()->WarpCursor( getViewControls()->GetCursorPosition(), true ); getViewControls()->WarpCursor( getViewControls()->GetCursorPosition(), true );
} }
} }
}
else if( aEvent.IsAction( &EE_ACTIONS::placeSheetPin ) ) if( aEvent.IsAction( &EE_ACTIONS::placeSheetPin ) )
type = SCH_SHEET_PIN_T; type = SCH_SHEET_PIN_T;
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
getViewControls()->ShowCursor( true ); getViewControls()->ShowCursor( true );
getViewControls()->SetSnapping( true ); getViewControls()->SetSnapping( true );
SCH_ITEM* previewItem = itemFactory();
m_view->ClearPreview();
m_view->AddToPreview( previewItem->Clone() );
m_frame->PushTool( aEvent.GetCommandStr().get() ); m_frame->PushTool( aEvent.GetCommandStr().get() );
Activate(); Activate();
@ -382,7 +400,7 @@ int SCH_DRAWING_TOOLS::SingleClickPlace( const TOOL_EVENT& aEvent )
// Main loop: keep receiving events // Main loop: keep receiving events
while( TOOL_EVENT* evt = Wait() ) while( TOOL_EVENT* evt = Wait() )
{ {
m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_PENCIL ); m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW );
cursorPos = (wxPoint) getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) ); cursorPos = (wxPoint) getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) );
if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() ) if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
@ -391,46 +409,38 @@ int SCH_DRAWING_TOOLS::SingleClickPlace( const TOOL_EVENT& aEvent )
} }
else if( evt->IsClick( BUT_LEFT ) ) else if( evt->IsClick( BUT_LEFT ) )
{ {
SCH_ITEM* item = nullptr;
if( !m_frame->GetScreen()->GetItem( cursorPos, 0, type ) ) if( !m_frame->GetScreen()->GetItem( cursorPos, 0, type ) )
{ {
switch( type ) if( type == SCH_JUNCTION_T )
m_frame->AddJunction( cursorPos );
else
{ {
case SCH_NO_CONNECT_T: SCH_ITEM* newItem = itemFactory();
item = new SCH_NO_CONNECT( cursorPos ); newItem->SetFlags( IS_NEW );
break;
case SCH_JUNCTION_T:
item = m_frame->AddJunction( cursorPos );
break;
case SCH_BUS_WIRE_ENTRY_T:
item = new SCH_BUS_WIRE_ENTRY( cursorPos, g_lastBusEntryShape );
break;
case SCH_BUS_BUS_ENTRY_T:
item = new SCH_BUS_BUS_ENTRY( cursorPos, g_lastBusEntryShape );
break;
default:
break;
}
}
if( item ) m_frame->AddItemToScreenAndUndoList( newItem );
{ m_frame->SaveCopyForRepeatItem( newItem );
item->SetFlags( IS_NEW );
m_frame->AddItemToScreenAndUndoList( item );
m_frame->SaveCopyForRepeatItem( item );
m_frame->SchematicCleanUp(); m_frame->SchematicCleanUp();
m_frame->TestDanglingEnds(); m_frame->TestDanglingEnds();
m_frame->OnModify(); m_frame->OnModify();
} }
} }
}
else if( evt->IsClick( BUT_RIGHT ) ) else if( evt->IsClick( BUT_RIGHT ) )
{ {
m_menu.ShowContextMenu( m_selectionTool->GetSelection() ); m_menu.ShowContextMenu( m_selectionTool->GetSelection() );
} }
else if( evt->IsAction( &EE_ACTIONS::refreshPreview ) || evt->IsMotion() )
{
previewItem->SetPosition( (wxPoint)cursorPos );
m_view->ClearPreview();
m_view->AddToPreview( previewItem->Clone() );
} }
}
delete previewItem;
m_view->ClearPreview();
m_frame->PopTool(); m_frame->PopTool();
return 0; return 0;