int PCBNEW_CONTROL::ZoomPreset( const TOOL_EVENT& aEvent ) { unsigned int idx = aEvent.Parameter<long>(); std::vector<double>& zoomList = m_frame->GetScreen()->m_ZoomList; KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView(); KIGFX::GAL* gal = m_frame->GetGalCanvas()->GetGAL(); m_frame->SetPresetZoom( idx ); if( idx == 0 ) // Zoom Auto { return ZoomFitScreen( aEvent ); } else if( idx >= zoomList.size() ) { assert( false ); return 0; } double selectedZoom = zoomList[idx]; double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor(); view->SetScale( 1.0 / ( zoomFactor * selectedZoom ) ); return 0; }
void EDA_DRAW_FRAME::UseGalCanvas() { KIGFX::GAL* gal = GetGalCanvas()->GetGAL(); // Set up grid settings gal->SetGridVisibility( IsGridVisible() ); gal->SetGridSize( VECTOR2D( GetScreen()->GetGridSize() ) ); gal->SetGridOrigin( VECTOR2D( GetGridOrigin() ) ); // Transfer EDA_DRAW_PANEL settings KIGFX::VIEW_CONTROLS* viewControls = GetGalCanvas()->GetViewControls(); viewControls->EnableCursorWarping( !m_canvas->GetEnableZoomNoCenter() ); viewControls->EnableMousewheelPan( m_canvas->GetEnableMousewheelPan() ); viewControls->EnableAutoPan( m_canvas->GetEnableAutoPan() ); m_canvas->SetEvtHandlerEnabled( false ); GetGalCanvas()->SetEvtHandlerEnabled( true ); GetGalCanvas()->StartDrawing(); // Switch panes // JEY TODO: drop down to a single pane.... m_auimgr.GetPane( "DrawFrame" ).Show( false ); m_auimgr.GetPane( "DrawFrameGal" ).Show( true ); m_auimgr.Update(); // Reset current tool on switch(); SetNoToolSelected(); }
int PCBNEW_CONTROL::ZoomFitScreen( const TOOL_EVENT& aEvent ) { KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView(); KIGFX::GAL* gal = m_frame->GetGalCanvas()->GetGAL(); BOARD* board = getModel<BOARD>(); board->ComputeBoundingBox(); BOX2I boardBBox = board->ViewBBox(); VECTOR2I screenSize = gal->GetScreenPixelSize(); if( boardBBox.GetSize().x == 0 || boardBBox.GetSize().y == 0 ) { // Empty view view->SetCenter( view->ToWorld( VECTOR2D( screenSize.x / 2, screenSize.y / 2 ) ) ); view->SetScale( 17.0 ); } else { // Autozoom to board double iuPerX = screenSize.x ? boardBBox.GetWidth() / screenSize.x : 1.0; double iuPerY = screenSize.y ? boardBBox.GetHeight() / screenSize.y : 1.0; double bestZoom = std::max( iuPerX, iuPerY ); double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor(); double zoom = 1.0 / ( zoomFactor * bestZoom ); view->SetCenter( boardBBox.Centre() ); view->SetScale( zoom ); } return 0; }
void SIMPLE_OVERLAY_ITEM::setupGal( KIGFX::GAL& aGal ) const { // default impl: set up the GAL options we have - the // overriding class can add to this if needed aGal.SetLineWidth( m_lineWidth ); aGal.SetStrokeColor( m_strokeColor ); aGal.SetFillColor( m_fillColor ); aGal.SetIsStroke( true ); aGal.SetIsFill( true ); }
void PCB_EDIT_FRAME::SetCursorShape( int aCursorShape ) { const unsigned int BIG_CURSOR = 8000; const unsigned int SMALL_CURSOR = 80; EDA_DRAW_FRAME::SetCursorShape( aCursorShape ); KIGFX::GAL* gal = GetGalCanvas()->GetGAL(); if( gal ) gal->SetCursorSize( aCursorShape ? BIG_CURSOR : SMALL_CURSOR ); }
int PCBNEW_CONTROL::SwitchCursor( const TOOL_EVENT& aEvent ) { const unsigned int BIG_CURSOR = 8000; const unsigned int SMALL_CURSOR = 80; PCB_BASE_FRAME* frame = getEditFrame<PCB_BASE_FRAME>(); KIGFX::GAL* gal = frame->GetGalCanvas()->GetGAL(); gal->SetCursorSize( frame->GetCursorShape() ? BIG_CURSOR : SMALL_CURSOR ); return 0; }
int PCBNEW_CONTROL::SwitchCursor( const TOOL_EVENT& aEvent ) { const unsigned int BIG_CURSOR = 4000; const unsigned int SMALL_CURSOR = 80; KIGFX::GAL* gal = getEditFrame<PCB_BASE_FRAME>()->GetGalCanvas()->GetGAL(); if( gal->GetCursorSize() == BIG_CURSOR ) gal->SetCursorSize( SMALL_CURSOR ); else gal->SetCursorSize( BIG_CURSOR ); return 0; }
int PCBNEW_CONTROL::ZoomInOutCenter( TOOL_EVENT& aEvent ) { KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView(); KIGFX::GAL* gal = m_frame->GetGalCanvas()->GetGAL(); if( aEvent.IsAction( &COMMON_ACTIONS::zoomInCenter ) ) m_frame->SetPrevZoom(); else if( aEvent.IsAction( &COMMON_ACTIONS::zoomOutCenter ) ) m_frame->SetNextZoom(); double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor(); double zoom = 1.0 / ( zoomFactor * m_frame->GetZoom() ); view->SetScale( zoom ); setTransitions(); return 0; }
void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable ) { KIGFX::VIEW* view = GetGalCanvas()->GetView(); KIGFX::GAL* gal = GetGalCanvas()->GetGAL(); // Display the same view after canvas switching if( aEnable ) { // Switch to GAL renderer from legacy if( !m_galCanvasActive ) { // Set up viewport double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor(); double zoom = 1.0 / ( zoomFactor * m_canvas->GetZoom() ); view->SetScale( zoom ); view->SetCenter( VECTOR2D( m_canvas->GetScreenCenterLogicalPosition() ) ); } // Set up grid settings gal->SetGridVisibility( IsGridVisible() ); gal->SetGridSize( VECTOR2D( GetScreen()->GetGridSize() ) ); gal->SetGridOrigin( VECTOR2D( GetGridOrigin() ) ); // Transfer EDA_DRAW_PANEL settings GetGalCanvas()->GetViewControls()->EnableCursorWarping( !m_canvas->GetEnableZoomNoCenter() ); GetGalCanvas()->GetViewControls()->EnableMousewheelPan( m_canvas->GetEnableMousewheelPan() ); GetGalCanvas()->GetViewControls()->EnableAutoPan( m_canvas->GetEnableAutoPan() ); } else if( m_galCanvasActive ) { // Switch to legacy renderer from GAL double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor(); // TODO replace it with EDA_DRAW_PANEL_GAL::GetLegacyZoom m_canvas->SetZoom( 1.0 / ( zoomFactor * view->GetScale() ) ); VECTOR2D center = view->GetCenter(); AdjustScrollBars( wxPoint( center.x, center.y ) ); } m_canvas->SetEvtHandlerEnabled( !aEnable ); GetGalCanvas()->SetEvtHandlerEnabled( aEnable ); // Switch panes m_auimgr.GetPane( wxT( "DrawFrame" ) ).Show( !aEnable ); m_auimgr.GetPane( wxT( "DrawFrameGal" ) ).Show( aEnable ); m_auimgr.Update(); // Reset current tool on switch(); SetNoToolSelected(); m_galCanvasActive = aEnable; }
/** * Draw simple ticks on the back of a line such that the line is * divided into n parts. * * @param aGal the GAL to draw on * @param aOrigin start of line to draw ticks on * @param aLine line vector * @param aTickLen length of ticks in IU * @param aNumDivisions number of parts to divide the line into */ void drawBacksideTicks( KIGFX::GAL& aGal, const VECTOR2D& aOrigin, const VECTOR2D& aLine, double aTickLen, int aNumDivisions ) { const double backTickSpace = aLine.EuclideanNorm() / aNumDivisions; const auto backTickVec = aLine.Rotate( M_PI_2 ).Resize( aTickLen ); for( int i = 0; i < aNumDivisions + 1; ++i ) { const auto backTickPos = aOrigin + aLine.Resize( backTickSpace * i ); aGal.DrawLine( backTickPos, backTickPos + backTickVec ); } }
/** * Draw labelled ticks on a line. Ticks are spaced according to a * maximum density. Miror ticks are not labelled. * * @param aGal the GAL to draw on * @param aOrigin start of line to draw ticks on * @param aLine line vector * @param aMinorTickLen length of minor ticks in IU */ void drawTicksAlongLine( KIGFX::GAL& aGal, const VECTOR2D& aOrigin, const VECTOR2D& aLine, double aMinorTickLen ) { VECTOR2D tickLine = aLine.Rotate( -M_PI_2 ); double tickSpace; TICK_FORMAT tickF = getTickFormatForScale( aGal.GetWorldScale(), tickSpace ); // number of ticks in whole ruler int numTicks = (int) std::ceil( aLine.EuclideanNorm() / tickSpace ); // work out which way up the tick labels go double labelAngle = -tickLine.Angle(); if( aLine.Angle() > 0 ) { aGal.SetHorizontalJustify( GR_TEXT_HJUSTIFY_LEFT ); } else { aGal.SetHorizontalJustify( GR_TEXT_HJUSTIFY_RIGHT ); labelAngle += M_PI; } // text and ticks are dimmed aGal.SetStrokeColor( PreviewOverlayDefaultColor().WithAlpha( PreviewOverlayDeemphAlpha( true ) ) ); const auto labelOffset = tickLine.Resize( aMinorTickLen * ( majorTickLengthFactor + 1 ) ); for( int i = 0; i < numTicks; ++i ) { const auto tickPos = aOrigin + aLine.Resize( tickSpace * i ); double length = aMinorTickLen; bool drawLabel = false; if( i % tickF.majorStep == 0) { drawLabel = true; length *= majorTickLengthFactor; } else if( tickF.midStep && i % tickF.midStep == 0 ) { drawLabel = true; length *= midTickLengthFactor; } aGal.DrawLine( tickPos, tickPos + tickLine.Resize( length ) ); if( drawLabel ) { wxString label = DimensionLabel( "", tickSpace * i, g_UserUnit ); // FIXME: spaces choke OpenGL lp:1668455 label.erase( std::remove( label.begin(), label.end(), ' ' ), label.end() ); aGal.BitmapText( label, tickPos + labelOffset, labelAngle ); } } }
void EDA_DRAW_FRAME::OnSelectZoom( wxCommandEvent& event ) { if( m_zoomSelectBox == NULL ) return; // Should not happen! int id = m_zoomSelectBox->GetCurrentSelection(); if( id < 0 || !( id < (int)m_zoomSelectBox->GetCount() ) ) return; if( id == 0 ) // Auto zoom (Fit in Page) { Zoom_Automatique( true ); } else { id--; double selectedZoom = GetScreen()->m_ZoomList[id]; if( GetScreen()->GetZoom() == selectedZoom ) return; GetScreen()->SetZoom( selectedZoom ); if( IsGalCanvasActive() ) { // Apply computed view settings to GAL KIGFX::VIEW* view = GetGalCanvas()->GetView(); KIGFX::GAL* gal = GetGalCanvas()->GetGAL(); double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor(); double zoom = 1.0 / ( zoomFactor * GetZoom() ); view->SetScale( zoom ); GetGalCanvas()->Refresh(); } else RedrawScreen( GetScrollCenterPosition(), false ); } }
const wxString EDA_DRAW_FRAME::GetZoomLevelIndicator() const { wxString Line; double level = 0.0; if( IsGalCanvasActive() ) { KIGFX::GAL* gal = m_galCanvas->GetGAL(); KIGFX::VIEW* view = m_galCanvas->GetView(); double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor(); level = m_zoomLevelCoeff * zoomFactor * view->GetScale(); } else if( BASE_SCREEN* screen = GetScreen() ) { level = m_zoomLevelCoeff / (double) screen->GetZoom(); } // returns a human readable value which can be displayed as zoom // level indicator in dialogs. Line.Printf( wxT( "Z %.2f" ), level ); return Line; }
int PCBNEW_CONTROL::ZoomFitScreen( TOOL_EVENT& aEvent ) { KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView(); KIGFX::GAL* gal = m_frame->GetGalCanvas()->GetGAL(); BOX2I boardBBox = getModel<BOARD>( PCB_T )->ViewBBox(); VECTOR2I screenSize = gal->GetScreenPixelSize(); double iuPerX = screenSize.x ? boardBBox.GetWidth() / screenSize.x : 1.0; double iuPerY = screenSize.y ? boardBBox.GetHeight() / screenSize.y : 1.0; double bestZoom = std::max( iuPerX, iuPerY ); // This is needed to avoid "jumpy" zooms if first hot key was used and then mouse scroll // (or other way round). m_frame->GetScreen()->SetZoom( bestZoom ); double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor(); double zoom = 1.0 / ( zoomFactor * bestZoom ); view->SetScale( zoom ); view->SetCenter( boardBBox.Centre() ); setTransitions(); return 0; }
void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable ) { KIGFX::VIEW* view = GetGalCanvas()->GetView(); KIGFX::GAL* gal = GetGalCanvas()->GetGAL(); double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor(); // Display the same view after canvas switching if( aEnable ) { BASE_SCREEN* screen = GetScreen(); // Switch to GAL rendering if( !IsGalCanvasActive() ) { // Set up viewport double zoom = 1.0 / ( zoomFactor * m_canvas->GetZoom() ); view->SetScale( zoom ); view->SetCenter( VECTOR2D( m_canvas->GetScreenCenterLogicalPosition() ) ); } // Set up grid settings gal->SetGridVisibility( IsGridVisible() ); gal->SetGridSize( VECTOR2D( screen->GetGridSize().x, screen->GetGridSize().y ) ); gal->SetGridOrigin( VECTOR2D( GetGridOrigin() ) ); } else { // Switch to standard rendering if( IsGalCanvasActive() ) { // Change view settings only if GAL was active previously double zoom = 1.0 / ( zoomFactor * view->GetScale() ); m_canvas->SetZoom( zoom ); VECTOR2D center = view->GetCenter(); RedrawScreen( wxPoint( center.x, center.y ), false ); } } m_canvas->SetEvtHandlerEnabled( !aEnable ); GetGalCanvas()->SetEvtHandlerEnabled( aEnable ); // Switch panes m_auimgr.GetPane( wxT( "DrawFrame" ) ).Show( !aEnable ); m_auimgr.GetPane( wxT( "DrawFrameGal" ) ).Show( aEnable ); m_auimgr.Update(); // Reset current tool on switch(); SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); m_galCanvasActive = aEnable; }
void VIEW_GROUP::ViewDraw( int aLayer, VIEW* aView ) const { KIGFX::GAL* gal = aView->GetGAL(); PAINTER* painter = aView->GetPainter(); bool isSelection = m_layer == LAYER_SELECT_OVERLAY; const auto drawList = updateDrawList(); std::unordered_map<int, std::vector<VIEW_ITEM*>> layer_item_map; // Build a list of layers used by the items in the group for( auto item : drawList ) { int item_layers[VIEW::VIEW_MAX_LAYERS], item_layers_count; item->ViewGetLayers( item_layers, item_layers_count ); for( int i = 0; i < item_layers_count; i++ ) { if( layer_item_map.count( item_layers[i] ) == 0 ) { layer_item_map.emplace( std::make_pair( item_layers[i], std::vector<VIEW_ITEM*>() ) ); } layer_item_map[ item_layers[i] ].push_back( item ); } } int layers[VIEW::VIEW_MAX_LAYERS] = { 0 }; int layers_count = 0; for( const auto& entry : layer_item_map ) { layers[ layers_count++ ] = entry.first; } aView->SortLayers( layers, layers_count ); // Now draw the layers in sorted order gal->PushDepth(); for( int i = 0; i < layers_count; i++ ) { int layer = layers[i]; bool draw = aView->IsLayerVisible( layer ); if( isSelection ) { switch( layer ) { case LAYER_PADS_TH: case LAYER_PADS_PLATEDHOLES: case LAYER_PAD_FR: case LAYER_PAD_BK: draw = true; break; default: break; } } if( draw ) { gal->AdvanceDepth(); for( auto item : layer_item_map[ layers[i] ] ) { if( !painter->Draw( item, layers[i] ) ) item->ViewDraw( layers[i], aView ); // Alternative drawing method } } } gal->PopDepth(); }