From 1a0f3b79cc17bf134abbb5a52d2405951639cfdf Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sat, 8 Sep 2018 13:12:41 +0200 Subject: [PATCH] Fix SCH_BITMAP handling in gal. --- eeschema/edit_bitmap.cpp | 1 + eeschema/onrightclick.cpp | 3 ++- eeschema/sch_bitmap.cpp | 3 +-- eeschema/sch_bitmap.h | 11 +++++++++++ eeschema/sch_painter.cpp | 7 +++++++ eeschema/schedit.cpp | 17 ++++++++++++++--- eeschema/schematic_undo_redo.cpp | 4 ++++ 7 files changed, 40 insertions(+), 6 deletions(-) diff --git a/eeschema/edit_bitmap.cpp b/eeschema/edit_bitmap.cpp index 822f3feba3..3fc3a5c44b 100644 --- a/eeschema/edit_bitmap.cpp +++ b/eeschema/edit_bitmap.cpp @@ -124,6 +124,7 @@ SCH_BITMAP* SCH_EDIT_FRAME::CreateNewImage( wxDC* aDC ) return NULL; } + image->SetFlags( IS_NEW | IS_MOVED ); auto view = static_cast( m_canvas )->GetView(); diff --git a/eeschema/onrightclick.cpp b/eeschema/onrightclick.cpp index b78753049e..3a42388d62 100644 --- a/eeschema/onrightclick.cpp +++ b/eeschema/onrightclick.cpp @@ -142,7 +142,8 @@ bool SCH_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu ) bool actionCancelled = false; item = LocateAndShowItem( aPosition, SCH_COLLECTOR::AllItemsButPins, 0, &actionCancelled ); - printf("Locateandshow %d %d item %p\n", aPosition.x, aPosition.y, item ); + printf("Locateandshow %d %d item %p type %d\n", aPosition.x, aPosition.y, + item, item ? item->Type() : 0 ); fflush(0); // If the clarify item selection context menu is aborted, don't show the context menu. if( item == NULL && actionCancelled ) diff --git a/eeschema/sch_bitmap.cpp b/eeschema/sch_bitmap.cpp index c9bb683fef..c746439281 100644 --- a/eeschema/sch_bitmap.cpp +++ b/eeschema/sch_bitmap.cpp @@ -128,8 +128,7 @@ void SCH_BITMAP::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset GRSetDrawMode( aDC, aDrawMode ); #endif - //fixme-gal - //m_image->DrawBitmap( aPanel, aDC, pos ); + m_image->DrawBitmap( aDC, pos ); } else // draws bounding box only (used to move items) { diff --git a/eeschema/sch_bitmap.h b/eeschema/sch_bitmap.h index 5ece25af11..9e4452b283 100644 --- a/eeschema/sch_bitmap.h +++ b/eeschema/sch_bitmap.h @@ -84,6 +84,17 @@ public: return m_image->GetScalingFactor(); } + /** + * @return the m_Scale image "zoom" value + * m_Scale is an user dependant value, and is similar to a "zoom" value + * m_Scale = 1.0 = original size of bitmap. + * m_Scale < 1.0 = the bitmap is drawn smaller than its original size. + * m_Scale > 1.0 = the bitmap is drawn bigger than its original size. + */ + double GetImageScale() const + { + return m_image->GetScale(); + } wxString GetClass() const override { diff --git a/eeschema/sch_painter.cpp b/eeschema/sch_painter.cpp index 3b2428fb43..04f7e46321 100644 --- a/eeschema/sch_painter.cpp +++ b/eeschema/sch_painter.cpp @@ -1317,7 +1317,14 @@ void SCH_PAINTER::draw( SCH_BITMAP *aBitmap, int aLayer ) { m_gal->Save(); m_gal->Translate( aBitmap->GetPosition() ); + + // When the image scale factor is not 1.0, we need to modify the actual + // as the image scale factor is similar to a local zoom + if( aBitmap->GetImageScale() != 1.0 ) + m_gal->Scale( VECTOR2D( aBitmap->GetImageScale(), aBitmap->GetImageScale() ) ); + m_gal->DrawBitmap( *aBitmap->GetImage() ); + m_gal->Restore(); } diff --git a/eeschema/schedit.cpp b/eeschema/schedit.cpp index 7a147ec343..75470e3159 100644 --- a/eeschema/schedit.cpp +++ b/eeschema/schedit.cpp @@ -430,17 +430,18 @@ void SCH_EDIT_FRAME::OnMoveItem( wxCommandEvent& aEvent ) case SCH_SHEET_PIN_T: case SCH_FIELD_T: case SCH_SHEET_T: + case SCH_BITMAP_T: PrepareMoveItem( item, nullptr ); break; - case SCH_BITMAP_T: +/* case SCH_BITMAP_T: // move an image is a special case: // we cannot undraw/redraw a bitmap just using our xor mode // the MoveImage function handle this undraw/redraw difficulty // By redrawing the full bounding box -// MoveImage( (SCH_BITMAP*) item, &dc ); + MoveImage( (SCH_BITMAP*) item, &dc ); break; - +*/ case SCH_MARKER_T: // Moving a marker has no sense break; @@ -923,6 +924,9 @@ void SCH_EDIT_FRAME::OnRotate( wxCommandEvent& aEvent ) case SCH_BITMAP_T: RotateImage( (SCH_BITMAP*) item ); + // The bitmap is cached in Opengl: clear the cache, because + // the cache data is invalid + GetCanvas()->GetGAL()->ClearCache(); break; case SCH_SHEET_T: @@ -1093,6 +1097,9 @@ void SCH_EDIT_FRAME::OnEditItem( wxCommandEvent& aEvent ) case SCH_BITMAP_T: EditImage( (SCH_BITMAP*) item ); + // The bitmap is cached in Opengl: clear the cache, because + // the cache data is perhaps invalid + GetCanvas()->GetGAL()->ClearCache(); break; case SCH_LINE_T: // These items have no param to edit @@ -1284,6 +1291,10 @@ void SCH_EDIT_FRAME::OnOrient( wxCommandEvent& aEvent ) else if( aEvent.GetId() == ID_SCH_MIRROR_Y ) MirrorImage( (SCH_BITMAP*) item, false ); + // The bitmap is cached in Opengl: clear the cache, because + // the cache data is invalid + GetCanvas()->GetGAL()->ClearCache(); + break; case SCH_SHEET_T: diff --git a/eeschema/schematic_undo_redo.cpp b/eeschema/schematic_undo_redo.cpp index a18a72a9e7..88aa574705 100644 --- a/eeschema/schematic_undo_redo.cpp +++ b/eeschema/schematic_undo_redo.cpp @@ -381,6 +381,10 @@ void SCH_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed } } + // Bitmaps are cached in Opengl: clear the cache, because + // the cache data can be invalid + GetCanvas()->GetGAL()->ClearCache(); + GetCanvas()->GetView()->UpdateAllItems( KIGFX::ALL ); }