Eeschema, load a new bitmap image from file: fix crash when aborting.
Remove duplicate code in edit_bitmap.cpp.
This commit is contained in:
parent
dafeb96765
commit
8ecdf58bad
|
@ -35,82 +35,22 @@
|
|||
|
||||
#include <view/view_group.h>
|
||||
|
||||
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<SCH_DRAW_PANEL*> ( 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<SCH_DRAW_PANEL*>( m_canvas )->GetView();
|
||||
|
||||
view->ClearPreview();
|
||||
view->AddToPreview( image, false );
|
||||
|
||||
|
||||
m_canvas->SetMouseCapture( moveBitmap, abortMoveBitmap );
|
||||
GetScreen()->SetCurItem( image );
|
||||
|
||||
OnModify();
|
||||
// OnModify();
|
||||
return image;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<SCH_DRAW_PANEL*>( 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();
|
||||
|
|
Loading…
Reference in New Issue