← Back to team overview

kicad-developers team mailing list archive

Re: GAL canvas strategy - testers needed!

 

Le 08/09/2018 à 13:16, jp charras a écrit :
> Le 07/09/2018 à 23:50, Jeff Young a écrit :
>> I pushed a few more bug fixes, an implementation of line styles (dashed,
>> dotted, etc.) and a fix for the dragging-object (‘G’ hotkey) bug.
>>
>> Cheers,
>> Jeff.
> 
> 
> Hi Jeff,
> Attached 2 patches.
> The first one fixes minor visibility issues.
> The second fixes issues relative to SCH_BITMAP display and edition.
> 
> Cheers,
> 

Sorry Jeff,
My second patch has a bug (creates a crash when right clicking on an
empty area, due to use of a null pointer in a debug message).
Attached, the new patch with the fix.

Really Sorry.

-- 
Jean-Pierre CHARRAS
From 5b3665ed59820464938f2365b79161bd08347890 Mon Sep 17 00:00:00 2001
From: jean-pierre charras <jp.charras@xxxxxxxxxx>
Date: Sat, 8 Sep 2018 13:12:41 +0200
Subject: [PATCH 2/2] 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 e5d04e8a6..fac6b5d0e 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<SCH_DRAW_PANEL*>( m_canvas )->GetView();
 
diff --git a/eeschema/onrightclick.cpp b/eeschema/onrightclick.cpp
index fe72dd65a..39b44de45 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 c9bb683fe..c74643928 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 b318b8be4..8b2ea93db 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 3b2428fb4..04f7e4632 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 ce7ab4aca..0f32d34fd 100644
--- a/eeschema/schedit.cpp
+++ b/eeschema/schedit.cpp
@@ -443,17 +443,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;
@@ -936,6 +937,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:
@@ -1072,6 +1076,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
@@ -1263,6 +1270,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 a18a72a9e..88aa57470 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 );
 }
 
-- 
2.17.0.windows.1


Follow ups

References