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

@ -346,32 +346,50 @@ int SCH_DRAWING_TOOLS::PlaceImage( const TOOL_EVENT& aEvent )
int SCH_DRAWING_TOOLS::SingleClickPlace( const TOOL_EVENT& aEvent ) 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() )
{ {
EE_SELECTION& selection = m_selectionTool->GetSelection(); case SCH_NO_CONNECT_T:
SCH_LINE* wire = dynamic_cast<SCH_LINE*>( selection.Front() ); 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( wire ) if( type == SCH_JUNCTION_T && aEvent.HasPosition() )
{ {
SEG seg( wire->GetStartPoint(), wire->GetEndPoint() ); EE_SELECTION& selection = m_selectionTool->GetSelection();
VECTOR2I nearest = seg.NearestPoint( getViewControls()->GetCursorPosition() ); SCH_LINE* wire = dynamic_cast<SCH_LINE*>( selection.Front() );
getViewControls()->SetCrossHairCursorPosition( nearest, false );
getViewControls()->WarpCursor( getViewControls()->GetCursorPosition(), true ); if( wire )
} {
SEG seg( wire->GetStartPoint(), wire->GetEndPoint() );
VECTOR2I nearest = seg.NearestPoint( getViewControls()->GetCursorPosition() );
getViewControls()->SetCrossHairCursorPosition( nearest, false );
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,47 +409,39 @@ 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: m_frame->AddItemToScreenAndUndoList( newItem );
item = m_frame->AddJunction( cursorPos ); m_frame->SaveCopyForRepeatItem( newItem );
break;
case SCH_BUS_WIRE_ENTRY_T: m_frame->SchematicCleanUp();
item = new SCH_BUS_WIRE_ENTRY( cursorPos, g_lastBusEntryShape ); m_frame->TestDanglingEnds();
break; m_frame->OnModify();
case SCH_BUS_BUS_ENTRY_T:
item = new SCH_BUS_BUS_ENTRY( cursorPos, g_lastBusEntryShape );
break;
default:
break;
} }
} }
if( item )
{
item->SetFlags( IS_NEW );
m_frame->AddItemToScreenAndUndoList( item );
m_frame->SaveCopyForRepeatItem( item );
m_frame->SchematicCleanUp();
m_frame->TestDanglingEnds();
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;
} }