diff --git a/eeschema/edit_bitmap.cpp b/eeschema/edit_bitmap.cpp index 95c548af09..2519ddf920 100644 --- a/eeschema/edit_bitmap.cpp +++ b/eeschema/edit_bitmap.cpp @@ -35,82 +35,22 @@ #include -static void abortMoveBitmap( EDA_DRAW_PANEL* aPanel, wxDC* aDC ) -{ - SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen(); - SCH_BITMAP* item = (SCH_BITMAP*) screen->GetCurItem(); - SCH_EDIT_FRAME* parent = (SCH_EDIT_FRAME*) aPanel->GetParent(); - - parent->SetRepeatItem( NULL ); - - if( item == NULL ) /* no current item */ - return; - - if( item->IsNew() ) - { - delete item; - item = NULL; - } - else // Move command on an existing text item, restore the data of the original. - { - item->ClearFlags(); - - SCH_BITMAP * olditem = (SCH_BITMAP*) parent->GetUndoItem(); - - wxCHECK_RET( olditem != NULL && item->Type() == olditem->Type() && - item->Type() == SCH_BITMAP_T, - wxT( "Cannot restore undefined last text item." ) ); - - // Never delete existing item, because it can be referenced by an undo/redo command - // Just restore its data - item->SwapData( olditem ); - parent->SetUndoItem( NULL ); - } - - screen->SetCurItem( item ); - aPanel->Refresh(); -} - -static void moveBitmap( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, bool aErase ) -{ - auto panel = static_cast ( aPanel ); - SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen(); - SCH_BITMAP* image = (SCH_BITMAP*) screen->GetCurItem(); - auto preview = panel->GetView()->GetPreview(); - - if ( ! image ) - return; - - // Draw the bitmap at it's new position. - image->SetPosition( aPanel->GetParent()->GetCrossHairPosition() - image->GetStoredPos() ); - - auto view = panel->GetView(); - - view->ClearPreview(); - view->AddToPreview( image, false ); - view->SetVisible( preview, true ); - view->Update( preview ); - - view->MarkTargetDirty( KIGFX::TARGET_NONCACHED ); -} - SCH_BITMAP* SCH_EDIT_FRAME::CreateNewImage( wxDC* aDC ) { wxFileDialog fileDlg( this, _( "Choose Image" ), wxEmptyString, wxEmptyString, _( "Image Files " ) + wxImage::GetImageExtWildcard(), wxFD_OPEN ); - int diag = fileDlg.ShowModal(); - if( diag != wxID_OK ) - return NULL; + if( fileDlg.ShowModal() != wxID_OK ) + return nullptr; wxString fullFilename = fileDlg.GetPath(); if( !wxFileExists( fullFilename ) ) { - wxMessageBox( _( "Couldn't load image from \"%s\"" ), GetChars( fullFilename ) ); - return NULL; + wxMessageBox( _( "Couldn't load image from \"%s\"" ), fullFilename ); + return nullptr; } wxPoint pos = GetCrossHairPosition(); @@ -119,23 +59,15 @@ SCH_BITMAP* SCH_EDIT_FRAME::CreateNewImage( wxDC* aDC ) if( !image->ReadImageFile( fullFilename ) ) { - wxMessageBox( _( "Couldn't load image from \"%s\"" ), GetChars( fullFilename ) ); + wxMessageBox( _( "Couldn't load image from \"%s\"" ), fullFilename ); delete image; - return NULL; + return nullptr; } - image->SetFlags( IS_NEW | IS_MOVED ); + image->SetFlags( IS_NEW ); + PrepareMoveItem( image ); - auto view = static_cast( m_canvas )->GetView(); - - view->ClearPreview(); - view->AddToPreview( image, false ); - - - m_canvas->SetMouseCapture( moveBitmap, abortMoveBitmap ); - GetScreen()->SetCurItem( image ); - - OnModify(); +// OnModify(); return image; } diff --git a/eeschema/schedit.cpp b/eeschema/schedit.cpp index 907daa9686..5704f1927a 100644 --- a/eeschema/schedit.cpp +++ b/eeschema/schedit.cpp @@ -680,7 +680,6 @@ static void moveItemWithMouseCursor( EDA_DRAW_PANEL* aPanel, wxDC* aDC, SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen(); SCH_ITEM* item = screen->GetCurItem(); auto panel = static_cast( aPanel ); - auto view = panel->GetView(); wxCHECK_RET( (item != NULL), wxT( "Cannot move invalid schematic item." ) ); @@ -689,14 +688,23 @@ static void moveItemWithMouseCursor( EDA_DRAW_PANEL* aPanel, wxDC* aDC, item->SetPosition( cpos ); - // Draw the item item at it's new position. + // Draw the item at it's new position. item->SetWireImage(); // While moving, the item may choose to render differently + auto view = panel->GetView(); view->ClearPreview(); view->AddToPreview( item, false ); + + // Needed when moving a bitmap image to avoid ugly rendering and artifacts, + // because a bitmap is drawn only as non cached + if( item->Type() == SCH_BITMAP_T ) + view->MarkTargetDirty( KIGFX::TARGET_NONCACHED ); } +/** + * Callback function called when aborting a move item with mouse cursor command. + */ static void abortMoveItem( EDA_DRAW_PANEL* aPanel, wxDC* aDC ) { SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen();