Commit ef865aab authored by Maciej Suminski's avatar Maciej Suminski

Grid settings apply to GAL based rendering.

parent 322c71d2
...@@ -236,6 +236,14 @@ void EDA_DRAW_FRAME::SkipNextLeftButtonReleaseEvent() ...@@ -236,6 +236,14 @@ void EDA_DRAW_FRAME::SkipNextLeftButtonReleaseEvent()
void EDA_DRAW_FRAME::OnToggleGridState( wxCommandEvent& aEvent ) void EDA_DRAW_FRAME::OnToggleGridState( wxCommandEvent& aEvent )
{ {
SetGridVisibility( !IsGridVisible() ); SetGridVisibility( !IsGridVisible() );
#ifdef KICAD_GAL
if( m_galCanvasActive )
{
m_galCanvas->GetGAL()->SetGridVisibility( IsGridVisible() );
m_galCanvas->Refresh();
}
else
#endif /* KICAD_GAL */
m_canvas->Refresh(); m_canvas->Refresh();
} }
...@@ -388,6 +396,14 @@ void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event ) ...@@ -388,6 +396,14 @@ void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event )
m_LastGridSizeId = id - ID_POPUP_GRID_LEVEL_1000; m_LastGridSizeId = id - ID_POPUP_GRID_LEVEL_1000;
screen->SetGrid( id ); screen->SetGrid( id );
screen->SetCrossHairPosition( screen->RefPos( true ) ); screen->SetCrossHairPosition( screen->RefPos( true ) );
#ifdef KICAD_GAL
if( m_galCanvasActive )
{
KiGfx::GAL* gal = m_galCanvas->GetGAL();
gal->SetGridSize( VECTOR2D( screen->GetGrid().m_Size ) );
}
#endif /* KICAD_GAL */
Refresh(); Refresh();
} }
...@@ -945,33 +961,45 @@ void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable ) ...@@ -945,33 +961,45 @@ void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable )
KiGfx::VIEW* view = m_galCanvas->GetView(); KiGfx::VIEW* view = m_galCanvas->GetView();
KiGfx::GAL* gal = m_galCanvas->GetGAL(); KiGfx::GAL* gal = m_galCanvas->GetGAL();
if( aEnable && m_galCanvasActive )
{
// When we switch between GAL based canvases, all we need is a refresh
m_galCanvas->Refresh();
}
if( !( aEnable ^ m_galCanvasActive ) )
return;
double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor(); double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor();
// Display the same view after canvas switching // Display the same view after canvas switching
if( aEnable ) if( aEnable )
{ {
double zoom = 1 / ( zoomFactor * m_canvas->GetZoom() ); BASE_SCREEN* screen = GetScreen();
view->SetScale( zoom );
// Switch to GAL rendering
if( !m_galCanvasActive )
{
// Change view settings only if GAL was not active previously
double zoom = 1.0 / ( zoomFactor * m_canvas->GetZoom() );
view->SetScale( zoom );
view->SetCenter( VECTOR2D( m_canvas->GetScreenCenterLogicalPosition() ) ); view->SetCenter( VECTOR2D( m_canvas->GetScreenCenterLogicalPosition() ) );
} }
// Set up grid settings
gal->SetGridVisibility( IsGridVisible() );
// Default grid color - dark cyan does not look good
//gal->SetGridColor( KiGfx::COLOR4D( GetGridColor() ) );
gal->SetGridColor( KiGfx::COLOR4D( 0.1, 0.1, 0.1, 1.0 ) );
gal->SetGridSize( VECTOR2D( screen->GetGridSize() ) );
gal->SetGridOrigin( VECTOR2D( screen->GetGridOrigin() ) );
gal->SetGridOriginMarkerSize( 15 );
gal->SetGridDrawThreshold( 10 );
}
else else
{ {
double zoom = 1 / ( zoomFactor * view->GetScale() ); // Switch to standard rendering
if( m_galCanvasActive )
{
// Change view settings only if GAL was active previously
double zoom = 1.0 / ( zoomFactor * view->GetScale() );
m_canvas->SetZoom( zoom ); m_canvas->SetZoom( zoom );
VECTOR2D center = view->GetCenter(); VECTOR2D center = view->GetCenter();
RedrawScreen( wxPoint( center.x, center.y ), false ); RedrawScreen( wxPoint( center.x, center.y ), false );
} }
}
m_canvas->SetEvtHandlerEnabled( !aEnable ); m_canvas->SetEvtHandlerEnabled( !aEnable );
m_galCanvas->SetEvtHandlerEnabled( aEnable ); m_galCanvas->SetEvtHandlerEnabled( aEnable );
......
...@@ -140,11 +140,6 @@ void EDA_DRAW_PANEL_GAL::Refresh( bool eraseBackground, const wxRect* rect ) ...@@ -140,11 +140,6 @@ void EDA_DRAW_PANEL_GAL::Refresh( bool eraseBackground, const wxRect* rect )
m_gal->BeginDrawing(); m_gal->BeginDrawing();
m_gal->SetBackgroundColor( KiGfx::COLOR4D( 0, 0, 0, 1.0 ) ); m_gal->SetBackgroundColor( KiGfx::COLOR4D( 0, 0, 0, 1.0 ) );
m_gal->ClearScreen(); m_gal->ClearScreen();
m_gal->SetGridOrigin( VECTOR2D( 0, 0 ) );
m_gal->SetGridOriginMarkerSize( 15 );
m_gal->SetGridSize( VECTOR2D( METRIC_UNIT_LENGTH / 10000.0, METRIC_UNIT_LENGTH / 10000.0 ) );
m_gal->SetGridDrawThreshold( 10 );
m_gal->SetLayerDepth( 0 );
m_gal->DrawGrid(); m_gal->DrawGrid();
m_view->Redraw(); m_view->Redraw();
......
...@@ -44,6 +44,7 @@ GAL::GAL() ...@@ -44,6 +44,7 @@ GAL::GAL()
SetZoomFactor( 1.0 ); SetZoomFactor( 1.0 );
SetFillColor( COLOR4D( 0.0, 0.0, 0.0, 0.0 ) ); SetFillColor( COLOR4D( 0.0, 0.0, 0.0, 0.0 ) );
SetStrokeColor( COLOR4D( 1.0, 1.0, 1.0, 1.0 ) ); SetStrokeColor( COLOR4D( 1.0, 1.0, 1.0, 1.0 ) );
SetGridVisibility( true );
SetGridColor( COLOR4D( 1, 1, 1, 0.1 ) ); SetGridColor( COLOR4D( 1, 1, 1, 0.1 ) );
SetCoarseGrid( 5 ); SetCoarseGrid( 5 );
SetLineWidth( 1.0 ); SetLineWidth( 1.0 );
...@@ -58,6 +59,9 @@ GAL::~GAL() ...@@ -58,6 +59,9 @@ GAL::~GAL()
void GAL::DrawGrid() void GAL::DrawGrid()
{ {
if( !gridVisibility )
return;
// The grid consists of lines // The grid consists of lines
// For the drawing the start points, end points and increments have to be calculated in world coordinates // For the drawing the start points, end points and increments have to be calculated in world coordinates
VECTOR2D screenStartPoint( 0, 0 ); VECTOR2D screenStartPoint( 0, 0 );
...@@ -98,6 +102,7 @@ void GAL::DrawGrid() ...@@ -98,6 +102,7 @@ void GAL::DrawGrid()
double origSize = (double) gridOriginMarkerSize / worldScale; double origSize = (double) gridOriginMarkerSize / worldScale;
// Draw the origin marker
SetStrokeColor( COLOR4D( 1.0, 1.0, 1.0, 1.0 ) ); SetStrokeColor( COLOR4D( 1.0, 1.0, 1.0, 1.0 ) );
SetIsFill( false ); SetIsFill( false );
DrawLine( gridOrigin + VECTOR2D( -origSize, -origSize ), gridOrigin + VECTOR2D( origSize, origSize ) ); DrawLine( gridOrigin + VECTOR2D( -origSize, -origSize ), gridOrigin + VECTOR2D( origSize, origSize ) );
...@@ -109,6 +114,7 @@ void GAL::DrawGrid() ...@@ -109,6 +114,7 @@ void GAL::DrawGrid()
if( std::max( gridScreenSizeDense, gridScreenSizeCoarse ) < gridDrawThreshold ) if( std::max( gridScreenSizeDense, gridScreenSizeCoarse ) < gridDrawThreshold )
return; return;
SetLayerDepth( 0.0 );
// Now draw the grid, every coarse grid line gets the double width // Now draw the grid, every coarse grid line gets the double width
for( int j = gridStartY; j < gridEndY; j += 1 ) for( int j = gridStartY; j < gridEndY; j += 1 )
{ {
......
...@@ -1909,10 +1909,12 @@ void OPENGL_GAL::DrawGridLine( const VECTOR2D& aStartPoint, const VECTOR2D& aEnd ...@@ -1909,10 +1909,12 @@ void OPENGL_GAL::DrawGridLine( const VECTOR2D& aStartPoint, const VECTOR2D& aEnd
if( aStartPoint.x == aEndPoint.x ) if( aStartPoint.x == aEndPoint.x )
{ {
// Vertical grid line
perpendicularVector = VECTOR2D( 0.5 * lineWidth, 0 ); perpendicularVector = VECTOR2D( 0.5 * lineWidth, 0 );
} }
else else
{ {
// Horizontal grid line
perpendicularVector = VECTOR2D( 0, 0.5 * lineWidth ); perpendicularVector = VECTOR2D( 0, 0.5 * lineWidth );
} }
......
...@@ -524,6 +524,16 @@ public: ...@@ -524,6 +524,16 @@ public:
// Grid methods // Grid methods
// ------------- // -------------
/**
* @brief Sets the visibility setting of the grid.
*
* @param aVisibility is the new visibility setting of the grid.
*/
inline void SetGridVisibility( bool aVisibility )
{
gridVisibility = aVisibility;
}
/** /**
* @brief Set the origin point for the grid. * @brief Set the origin point for the grid.
* *
...@@ -698,6 +708,8 @@ protected: ...@@ -698,6 +708,8 @@ protected:
double layerDepth; ///< The actual layer depth double layerDepth; ///< The actual layer depth
VECTOR2D depthRange; ///< Range of the depth VECTOR2D depthRange; ///< Range of the depth
// Grid settings
bool gridVisibility; ///< Should the grid be shown
VECTOR2D gridSize; ///< The grid size VECTOR2D gridSize; ///< The grid size
VECTOR2D gridOrigin; ///< The grid origin VECTOR2D gridOrigin; ///< The grid origin
COLOR4D gridColor; ///< Color of the grid COLOR4D gridColor; ///< Color of the grid
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment