← Back to team overview

kicad-developers team mailing list archive

Re: GAL canvas strategy - testers needed!

 

Le 16/09/2018 à 23:37, Jeff Young a écrit :
> I pushed JP’s commit and another that fixes up zoom & scroll issues
> entering and leaving sheets.
> 
> Cheers,
> Jeff.

Thanks.

Attached a new patch that fixes a Eeschema crash created by commit fcd80cdb
(when using SYMBOL_PREVIEW_WIDGET, due to a null pointer used in
onPaint() ).

It also fixes a few rendering artifacts.


-- 
Jean-Pierre CHARRAS
From a42631df241339ce6c60477167b5c555b75521cf Mon Sep 17 00:00:00 2001
From: jean-pierre charras <jp.charras@xxxxxxxxxx>
Date: Mon, 17 Sep 2018 11:22:11 +0200
Subject: [PATCH] Fix a Eeschema crash when using a SYMBOL_PREVIEW_WIDGET. Fix
 also a few draw artifacts.

---
 common/draw_panel_gal.cpp                  | 15 +++--
 eeschema/sch_painter.cpp                   |  3 -
 eeschema/widgets/symbol_preview_widget.cpp | 75 +++++++++++++---------
 eeschema/widgets/symbol_preview_widget.h   |  5 ++
 4 files changed, 62 insertions(+), 36 deletions(-)

diff --git a/common/draw_panel_gal.cpp b/common/draw_panel_gal.cpp
index 25787ad88..81397a4a3 100644
--- a/common/draw_panel_gal.cpp
+++ b/common/draw_panel_gal.cpp
@@ -163,10 +163,16 @@ void EDA_DRAW_PANEL_GAL::onPaint( wxPaintEvent& WXUNUSED( aEvent ) )
     KIGFX::RENDER_SETTINGS* settings = static_cast<KIGFX::RENDER_SETTINGS*>( m_painter->GetSettings() );
 
     m_viewControls->UpdateScrollbars();
-    GetParentEDAFrame()->GetScreen()->SetZoom( GetLegacyZoom() );
 
-    VECTOR2D center = GetView()->GetCenter();
-    GetParentEDAFrame()->SetScrollCenterPosition( wxPoint( center.x, center.y ) );
+    // Update current zoom settings if the canvas is managed by a EDA frame
+    // (i.e. not by a preview panel in a dialog)
+    if( GetParentEDAFrame() && GetParentEDAFrame()->GetScreen() )
+    {
+        GetParentEDAFrame()->GetScreen()->SetZoom( GetLegacyZoom() );
+
+        VECTOR2D center = GetView()->GetCenter();
+        GetParentEDAFrame()->SetScrollCenterPosition( wxPoint( center.x, center.y ) );
+    }
 
     try
     {
@@ -184,7 +190,8 @@ void EDA_DRAW_PANEL_GAL::onPaint( wxPaintEvent& WXUNUSED( aEvent ) )
 
         if( m_view->IsDirty() )
         {
-            if( m_backend != GAL_TYPE_OPENGL )   // already called in opengl
+            if( m_backend != GAL_TYPE_OPENGL &&     // Already called in opengl
+                m_view->IsTargetDirty( KIGFX::TARGET_NONCACHED ) )
                 m_gal->ClearScreen();
 
             m_view->ClearTargets();
diff --git a/eeschema/sch_painter.cpp b/eeschema/sch_painter.cpp
index fe579b8f4..c1ba3cf4b 100644
--- a/eeschema/sch_painter.cpp
+++ b/eeschema/sch_painter.cpp
@@ -421,9 +421,6 @@ void SCH_PAINTER::draw( LIB_POLYLINE *aLine, int aLayer )
     for( auto p : aLine->GetPolyPoints() )
         vtx.push_back ( mapCoords( p ) );
 
-//    if( aLine->GetFillMode() == FILLED_WITH_BG_BODYCOLOR || aLine->GetFillMode() == FILLED_SHAPE )
-//        vtx.push_back( vtx[0] );
-
     m_gal->DrawPolygon( vtx );
 }
 
diff --git a/eeschema/widgets/symbol_preview_widget.cpp b/eeschema/widgets/symbol_preview_widget.cpp
index cd9a0d8b8..d994809e7 100644
--- a/eeschema/widgets/symbol_preview_widget.cpp
+++ b/eeschema/widgets/symbol_preview_widget.cpp
@@ -68,6 +68,8 @@ SYMBOL_PREVIEW_WIDGET::SYMBOL_PREVIEW_WIDGET( wxWindow* aParent, KIWAY& aKiway,
     m_statusSizer->ShowItems( false );
 
     SetSizer( outer_sizer );
+
+    Connect( wxEVT_SIZE, wxSizeEventHandler( SYMBOL_PREVIEW_WIDGET::onSize ), NULL, this );
 }
 
 
@@ -87,6 +89,42 @@ void SYMBOL_PREVIEW_WIDGET::SetStatusText( wxString const& aText )
 }
 
 
+void SYMBOL_PREVIEW_WIDGET::onSize( wxSizeEvent& aEvent )
+{
+    aEvent.Skip();
+
+    if( m_previewItem )
+    {
+        fitOnDrawArea();
+        m_preview->ForceRefresh();
+    }
+}
+
+
+void SYMBOL_PREVIEW_WIDGET::fitOnDrawArea()
+{
+    if( !m_previewItem )
+        return;
+
+    // set the view scale to fit the item on screen
+    // Calculate the draw scale to fit the drawing area
+    KIGFX::VIEW* view = m_preview->GetView();
+
+    // Calculate the drawing area size, in internal units, for a scaling factor = 1.0
+    view->SetScale( 1.0 );
+    VECTOR2D  clientSize = view->ToWorld( m_preview->GetClientSize(), false );
+    double    scale = std::min( fabs( clientSize.x / m_itemBBox.GetWidth() ),
+                                fabs( clientSize.y / m_itemBBox.GetHeight() ) );
+
+    // Above calculation will yield an exact fit; add a bit of whitespace around symbol
+    scale /= 1.2;
+
+    // Now fix the best scale
+    view->SetScale( scale );
+    view->SetCenter( m_itemBBox.Centre() );
+}
+
+
 void SYMBOL_PREVIEW_WIDGET::DisplaySymbol( const LIB_ID& aSymbolID, int aUnit )
 {
     KIGFX::VIEW* view = m_preview->GetView();
@@ -128,22 +166,11 @@ void SYMBOL_PREVIEW_WIDGET::DisplaySymbol( const LIB_ID& aSymbolID, int aUnit )
         view->Add( alias );
         m_previewItem = alias;
 
-        // Calculate the draw scale to fit the drawing area
-
-        // First, get the symbole size, in internal units
-        BOX2I     bBox = alias->GetPart()->GetUnitBoundingBox( aUnit, 0 );
-        // Now calculate the drawing area size, in internal units, for a scaling factor = 1.0
-        view->SetScale( 1.0 );
-        VECTOR2D  clientSize = view->ToWorld( m_preview->GetClientSize(), false );
-        double    scale = std::min( fabs( clientSize.x / bBox.GetWidth() ),
-                                    fabs( clientSize.y / bBox.GetHeight() ) );
-
-        // Above calculation will yield an exact fit; add a bit of whitespace around symbol
-        scale /= 1.2;
+        // Get the symbole size, in internal units
+        m_itemBBox = alias->GetPart()->GetUnitBoundingBox( aUnit, 0 );
 
-        // Now fix the best scale
-        view->SetScale( scale );
-        view->SetCenter( bBox.Centre() );
+        // Calculate the draw scale to fit the drawing area
+        fitOnDrawArea();
     }
 
     m_preview->ForceRefresh();
@@ -177,21 +204,11 @@ void SYMBOL_PREVIEW_WIDGET::DisplayPart( LIB_PART* aPart, int aUnit )
         view->Add( aPart );
         m_previewItem = aPart;
 
-        // Calculate the draw scale to fit the drawing area
+        // Get the symbole size, in internal units
+        m_itemBBox = aPart->GetUnitBoundingBox( aUnit, 0 );
 
-        // First, get the symbole size, in internal units
-        BOX2I     bBox = aPart->GetUnitBoundingBox( aUnit, 0 );
-        // Now calculate the drawing area size, in internal units, for a scaling factor = 1.0
-        view->SetScale( 1.0 );
-        VECTOR2D  clientSize = view->ToWorld( m_preview->GetClientSize(), false );
-        double    scale = std::min( fabs( clientSize.x / bBox.GetWidth() ),
-                                    fabs( clientSize.y / bBox.GetHeight() ) );
-        // Above calculation will yield an exact fit; add a bit of whitespace around symbol
-        scale /= 1.2;
-
-        // Now fix the best scale
-        view->SetScale( scale );
-        view->SetCenter( bBox.Centre() );
+        // Calculate the draw scale to fit the drawing area
+        fitOnDrawArea();
     }
 
     m_preview->ForceRefresh();
diff --git a/eeschema/widgets/symbol_preview_widget.h b/eeschema/widgets/symbol_preview_widget.h
index c817b1fe4..581ed84e7 100644
--- a/eeschema/widgets/symbol_preview_widget.h
+++ b/eeschema/widgets/symbol_preview_widget.h
@@ -63,6 +63,10 @@ public:
     void DisplayPart( LIB_PART* aPart, int aUnit );
 
 private:
+    void onSize( wxSizeEvent& aEvent );
+
+    void fitOnDrawArea();    // set the view scale to fit the item on screen and center
+
     KIWAY&                     m_kiway;
 
     KIGFX::GAL_DISPLAY_OPTIONS m_galDisplayOptions;
@@ -72,6 +76,7 @@ private:
     wxSizer*                   m_statusSizer;
 
     EDA_ITEM*                  m_previewItem;
+    BOX2I                      m_itemBBox;      // The size of the current item
 };
 
 
-- 
2.17.0.windows.1


Follow ups

References