← Back to team overview

kicad-developers team mailing list archive

Re: GAL canvas strategy - testers needed!

 

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,

-- 
Jean-Pierre CHARRAS
From 7ed5964adf5e255ec85de99ace4708493a42d179 Mon Sep 17 00:00:00 2001
From: jean-pierre charras <jp.charras@xxxxxxxxxx>
Date: Fri, 7 Sep 2018 18:13:20 +0200
Subject: [PATCH 1/2] Set the reight grid visibility at start. Display axis in
 libedit and viewlib.

---
 common/gal/opengl/opengl_gal.cpp    | 4 ++--
 eeschema/libedit/lib_edit_frame.cpp | 2 ++
 eeschema/sch_edit_frame.cpp         | 3 +++
 eeschema/viewlib_frame.cpp          | 4 +++-
 4 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp
index 4ca422b75..409047bca 100644
--- a/common/gal/opengl/opengl_gal.cpp
+++ b/common/gal/opengl/opengl_gal.cpp
@@ -1000,7 +1000,7 @@ void OPENGL_GAL::DrawCurve( const VECTOR2D& aStartPoint, const VECTOR2D& aContro
 void OPENGL_GAL::DrawBitmap( const BITMAP_BASE& aBitmap )
 {
     int ppi = aBitmap.GetPPI();
-    
+
     double w = (double) aBitmap.GetSizePixels().x / (double) ppi / worldUnitLength * 10.0; // no idea where the factor 10 comes from...
     double h = (double) aBitmap.GetSizePixels().y / (double) ppi / worldUnitLength * 10.0;
 
@@ -1009,7 +1009,7 @@ void OPENGL_GAL::DrawBitmap( const BITMAP_BASE& aBitmap )
     glm::vec4 v0 = xform * glm::vec4( -w/2, -h/2, 0.0, 0.0 );
     glm::vec4 v1 = xform * glm::vec4( w/2, h/2, 0.0, 0.0 );
     glm::vec4 trans = xform[3];
-    
+
     auto id = bitmapCache->RequestBitmap( &aBitmap );
 
     auto oldTarget = GetTarget();
diff --git a/eeschema/libedit/lib_edit_frame.cpp b/eeschema/libedit/lib_edit_frame.cpp
index f6dcc0f48..c64395de6 100644
--- a/eeschema/libedit/lib_edit_frame.cpp
+++ b/eeschema/libedit/lib_edit_frame.cpp
@@ -278,6 +278,8 @@ LIB_EDIT_FRAME::LIB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
     SyncView();
     GetGalCanvas()->GetViewControls()->SetSnapping( true );
     GetGalCanvas()->GetView()->UseDrawPriority( true );
+    GetGalCanvas()->GetGAL()->SetGridVisibility( IsGridVisible() );
+    GetGalCanvas()->GetGAL()->SetAxesEnabled( true );
 }
 
 
diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp
index d6cd1d0eb..2bdcfb1f8 100644
--- a/eeschema/sch_edit_frame.cpp
+++ b/eeschema/sch_edit_frame.cpp
@@ -429,6 +429,9 @@ SCH_EDIT_FRAME::SCH_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ):
 
     Zoom_Automatique( false );
 
+    if( GetGalCanvas() )
+        GetGalCanvas()->GetGAL()->SetGridVisibility( IsGridVisible() );
+
     // Net list generator
     DefaultExecFlags();
 
diff --git a/eeschema/viewlib_frame.cpp b/eeschema/viewlib_frame.cpp
index c6abab4c0..4c3d35771 100644
--- a/eeschema/viewlib_frame.cpp
+++ b/eeschema/viewlib_frame.cpp
@@ -203,6 +203,8 @@ LIB_VIEW_FRAME::LIB_VIEW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame
 
     SyncView();
     GetGalCanvas()->GetViewControls()->SetSnapping( true );
+    GetGalCanvas()->GetGAL()->SetAxesEnabled( true );
+    GetGalCanvas()->GetGAL()->SetGridVisibility( IsGridVisible() );
 }
 
 
@@ -760,6 +762,6 @@ const BOX2I LIB_VIEW_FRAME::GetDocumentExtents() const
     {
         EDA_RECT bbox = part->GetUnitBoundingBox( m_unit, m_convert );
         return BOX2I( bbox.GetOrigin(), VECTOR2I( bbox.GetWidth(), bbox.GetHeight() ) );
-        
+
     }
 }
\ No newline at end of file
-- 
2.17.0.windows.1

From 817603ca89c03c727a03c32b4c7a32a247cb3c90 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        |  2 +-
 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, 39 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..5785c2688 100644
--- a/eeschema/onrightclick.cpp
+++ b/eeschema/onrightclick.cpp
@@ -142,7 +142,7 @@ 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->Type() ); 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