int PCBNEW_CONTROL::PanControl( const TOOL_EVENT& aEvent ) { long type = aEvent.Parameter<long>(); KIGFX::VIEW* view = getView(); GRID_HELPER gridHelper( m_frame ); VECTOR2D center = view->GetCenter(); VECTOR2I gridSize = gridHelper.GetGrid() * 10; switch( type ) { case COMMON_ACTIONS::CURSOR_UP: center -= VECTOR2D( 0, gridSize.y ); break; case COMMON_ACTIONS::CURSOR_DOWN: center += VECTOR2D( 0, gridSize.y ); break; case COMMON_ACTIONS::CURSOR_LEFT: center -= VECTOR2D( gridSize.x, 0 ); break; case COMMON_ACTIONS::CURSOR_RIGHT: center += VECTOR2D( gridSize.x, 0 ); break; default: assert( false ); break; } view->SetCenter( center ); return 0; }
int PCBNEW_CONTROL::ZoomFitScreen( const TOOL_EVENT& aEvent ) { KIGFX::VIEW* view = getView(); EDA_DRAW_PANEL_GAL* galCanvas = m_frame->GetGalCanvas(); BOARD* board = getModel<BOARD>(); board->ComputeBoundingBox(); BOX2I boardBBox = board->ViewBBox(); VECTOR2D scrollbarSize = VECTOR2D( galCanvas->GetSize() - galCanvas->GetClientSize() ); VECTOR2D screenSize = view->ToWorld( galCanvas->GetClientSize(), false ); if( boardBBox.GetWidth() == 0 || boardBBox.GetHeight() == 0 ) { // Empty view view->SetScale( 17.0 ); // works fine for the standard worksheet frame view->SetCenter( screenSize / 2.0 ); } else { VECTOR2D vsize = boardBBox.GetSize(); double scale = view->GetScale() / std::max( fabs( vsize.x / screenSize.x ), fabs( vsize.y / screenSize.y ) ); view->SetScale( scale ); view->SetCenter( boardBBox.Centre() ); } // Take scrollbars into account VECTOR2D worldScrollbarSize = view->ToWorld( scrollbarSize, false ); view->SetCenter( view->GetCenter() + worldScrollbarSize / 2.0 ); return 0; }
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; }
/* Handles the selection of tools, menu, and popup menu commands. */ void PL_EDITOR_FRAME::Process_Special_Functions( wxCommandEvent& event ) { wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED ); cmd.SetEventObject( this ); switch( event.GetId() ) { case wxID_PREFERENCES: ShowPreferences( PlEditorHotkeysDescr, PlEditorHotkeysDescr, wxT( "pl_editor" ) ); break; case ID_PREFERENCES_HOTKEY_SHOW_CURRENT_LIST: DisplayHotkeyList( this, PlEditorHotkeysDescr ); break; case ID_SELECT_PAGE_NUMBER: { KIGFX::VIEW* view = GetGalCanvas()->GetView(); view->SetLayerVisible( LAYER_WORKSHEET_PAGE1, m_pageSelectBox->GetSelection() == 0 ); view->SetLayerVisible( LAYER_WORKSHEET_PAGEn, m_pageSelectBox->GetSelection() == 1 ); m_canvas->Refresh(); } break; default: wxMessageBox( wxT( "PL_EDITOR_FRAME::Process_Special_Functions error" ) ); break; } }
/* * Update variables with new options */ bool PANEL_PCBNEW_DISPLAY_OPTIONS::TransferDataFromWindow() { PCB_DISPLAY_OPTIONS* displ_opts = (PCB_DISPLAY_OPTIONS*) m_frame->GetDisplayOptions(); displ_opts->m_ShowTrackClearanceMode = UTIL::GetValFromConfig( traceClearanceSelectMap, m_OptDisplayTracksClearance->GetSelection() ); displ_opts->m_DisplayPadIsol = m_OptDisplayPadClearence->GetValue(); displ_opts->m_DisplayPadNum = m_OptDisplayPadNumber->GetValue(); m_frame->SetElementVisibility( LAYER_NO_CONNECTS, m_OptDisplayPadNoConn->GetValue() ); displ_opts->m_DisplayNetNamesMode = m_ShowNetNamesOption->GetSelection(); displ_opts->m_DisplayRatsnestLinesCurved = m_OptDisplayCurvedRatsnestLines->GetValue(); m_galOptsPanel->TransferDataFromWindow(); // Apply changes to the GAL KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView(); KIGFX::PCB_PAINTER* painter = static_cast<KIGFX::PCB_PAINTER*>( view->GetPainter() ); KIGFX::PCB_RENDER_SETTINGS* settings = painter->GetSettings(); settings->LoadDisplayOptions( displ_opts, m_frame->ShowPageLimits() ); view->RecacheAllItems(); view->MarkTargetDirty( KIGFX::TARGET_NONCACHED ); m_frame->GetCanvas()->Refresh(); return true; }
int PCBNEW_CONTROL::ZoomCenter( const TOOL_EVENT& aEvent ) { KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView(); view->SetCenter( getViewControls()->GetCursorPosition() ); return 0; }
bool InvokeDXFDialogBoardImport( PCB_BASE_FRAME* aCaller ) { DIALOG_DXF_IMPORT dlg( aCaller ); bool success = ( dlg.ShowModal() == wxID_OK ); if( success ) { const std::list<BOARD_ITEM*>& list = dlg.GetImportedItems(); PICKED_ITEMS_LIST picklist; BOARD* board = aCaller->GetBoard(); KIGFX::VIEW* view = aCaller->GetGalCanvas()->GetView(); std::list<BOARD_ITEM*>::const_iterator it, itEnd; for( it = list.begin(), itEnd = list.end(); it != itEnd; ++it ) { BOARD_ITEM* item = *it; board->Add( item ); ITEM_PICKER itemWrapper( item, UR_NEW ); picklist.PushItem( itemWrapper ); if( aCaller->IsGalCanvasActive() ) view->Add( item ); } aCaller->SaveCopyInUndoList( picklist, UR_NEW, wxPoint( 0, 0 ) ); aCaller->OnModify(); } return success; }
void PCB_LAYER_WIDGET::OnRenderColorChange( int aId, COLOR4D aColor ) { wxASSERT( aId > GAL_LAYER_ID_START && aId < GAL_LAYER_ID_END ); myframe->Settings().Colors().SetItemColor( static_cast<GAL_LAYER_ID>( aId ), aColor ); EDA_DRAW_PANEL_GAL* galCanvas = myframe->GetGalCanvas(); if( galCanvas && myframe->IsGalCanvasActive() ) { if( aId == LAYER_GRID ) galCanvas->GetGAL()->SetGridColor( aColor ); KIGFX::VIEW* view = galCanvas->GetView(); view->GetPainter()->GetSettings()->ImportLegacyColors( &myframe->Settings().Colors() ); view->MarkTargetDirty( KIGFX::TARGET_NONCACHED ); // useful to update rastnest view->UpdateLayerColor( aId ); // plated-through-holes don't have their own color; they use the background color if( aId == LAYER_PCB_BACKGROUND ) view->UpdateLayerColor( LAYER_PADS_PLATEDHOLES ); galCanvas->ForceRefresh(); } myframe->ReCreateHToolbar(); myframe->GetCanvas()->Refresh(); }
void PCB_LAYER_WIDGET::OnLayerColorChange( int aLayer, COLOR4D aColor ) { // Avoid setting the alpha channel, when we are in legacy mode, // because in legacy mode the alpha channel is not used, but changing it // destroys the GAL color setup if( !myframe->IsGalCanvasActive() ) { COLOR4D oldColor = myframe->Settings().Colors().GetLayerColor( aLayer ); aColor.a = oldColor.a; } myframe->Settings().Colors().SetLayerColor( aLayer, aColor ); if( myframe->IsGalCanvasActive() ) { KIGFX::VIEW* view = myframe->GetGalCanvas()->GetView(); view->GetPainter()->GetSettings()->ImportLegacyColors( &myframe->Settings().Colors() ); view->UpdateLayerColor( aLayer ); view->UpdateLayerColor( GetNetnameLayer( aLayer ) ); } myframe->ReCreateHToolbar(); myframe->GetCanvas()->Refresh(); if( aLayer == LAYER_PCB_BACKGROUND ) myframe->SetDrawBgColor( aColor ); }
bool InvokeDXFDialogModuleImport( PCB_BASE_FRAME* aCaller, MODULE* aModule ) { wxASSERT( aModule ); DIALOG_DXF_IMPORT dlg( aCaller ); bool success = ( dlg.ShowModal() == wxID_OK ); if( success ) { const std::list<BOARD_ITEM*>& list = dlg.GetImportedItems(); KIGFX::VIEW* view = aCaller->GetGalCanvas()->GetView(); aCaller->SaveCopyInUndoList( aModule, UR_MODEDIT ); aCaller->OnModify(); std::list<BOARD_ITEM*>::const_iterator it, itEnd; for( it = list.begin(), itEnd = list.end(); it != itEnd; ++it ) { BOARD_ITEM* item = *it; BOARD_ITEM* converted = NULL; // Modules use different types for the same things, // so we need to convert imported items to appropriate classes. switch( item->Type() ) { case PCB_LINE_T: { converted = new EDGE_MODULE( aModule ); *static_cast<DRAWSEGMENT*>( converted ) = *static_cast<DRAWSEGMENT*>( item ); aModule->Add( converted ); static_cast<EDGE_MODULE*>( converted )->SetLocalCoord(); delete item; break; } case PCB_TEXT_T: { converted = new TEXTE_MODULE( aModule ); *static_cast<TEXTE_PCB*>( converted ) = *static_cast<TEXTE_PCB*>( item ); aModule->Add( converted ); static_cast<TEXTE_MODULE*>( converted )->SetLocalCoord(); delete item; break; } default: wxLogDebug( wxT( "type %d currently not handled" ), item->Type() ); break; } if( aCaller->IsGalCanvasActive() && converted ) view->Add( converted ); } } return success; }
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 PCB_LAYER_WIDGET::OnLayerColorChange( int aLayer, EDA_COLOR_T aColor ) { myframe->GetBoard()->SetLayerColor( ToLAYER_ID( aLayer ), aColor ); if( myframe->IsGalCanvasActive() ) { KIGFX::VIEW* view = myframe->GetGalCanvas()->GetView(); view->GetPainter()->GetSettings()->ImportLegacyColors( myframe->GetBoard()->GetColorsSettings() ); view->UpdateLayerColor( aLayer ); } myframe->GetCanvas()->Refresh(); }
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; }
int PCBNEW_CONTROL::ZoomInOutCenter( const TOOL_EVENT& aEvent ) { KIGFX::VIEW* view = getView(); double zoomScale = 1.0; if( aEvent.IsAction( &COMMON_ACTIONS::zoomInCenter ) ) zoomScale = 1.3; else if( aEvent.IsAction( &COMMON_ACTIONS::zoomOutCenter ) ) zoomScale = 0.7; view->SetScale( view->GetScale() * zoomScale ); return 0; }
int PCBNEW_CONTROL::ZoomInOut( const TOOL_EVENT& aEvent ) { KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView(); double zoomScale = 1.0; if( aEvent.IsAction( &COMMON_ACTIONS::zoomIn ) ) zoomScale = 1.3; else if( aEvent.IsAction( &COMMON_ACTIONS::zoomOut ) ) zoomScale = 0.7; view->SetScale( view->GetScale() * zoomScale, getViewControls()->GetCursorPosition() ); return 0; }
void GERBER_LAYER_WIDGET::OnLayerColorChange( int aLayer, COLOR4D aColor ) { // NOTE: Active layer in GerbView is stored as 0-indexed, but layer color is // stored according to the GERBER_DRAW_LAYER() offset. myframe->SetLayerColor( GERBER_DRAW_LAYER( aLayer ), aColor ); myframe->m_SelLayerBox->ResyncBitmapOnly(); if( myframe->IsGalCanvasActive() ) { KIGFX::VIEW* view = myframe->GetGalCanvas()->GetView(); view->GetPainter()->GetSettings()->ImportLegacyColors( myframe->m_colorsSettings ); view->UpdateLayerColor( GERBER_DRAW_LAYER( aLayer ) ); } myframe->GetCanvas()->Refresh(); }
void PCB_EDIT_FRAME::syncLayerVisibilities() { m_Layers->SyncLayerVisibilities(); KIGFX::VIEW* view = GetGalCanvas()->GetView(); // Load layer & elements visibility settings for( LAYER_NUM i = 0; i < NB_LAYERS; ++i ) { view->SetLayerVisible( i, m_Pcb->IsLayerVisible( i ) ); // Synchronize netname layers as well if( IsCopperLayer( i ) ) view->SetLayerVisible( GetNetnameLayer( i ), m_Pcb->IsLayerVisible( i ) ); } for( LAYER_NUM i = 0; i < END_PCB_VISIBLE_LIST; ++i ) { view->SetLayerVisible( ITEM_GAL_LAYER( i ), m_Pcb->IsElementVisible( i ) ); } // Enable some layers that are GAL specific view->SetLayerVisible( ITEM_GAL_LAYER( PADS_HOLES_VISIBLE ), true ); view->SetLayerVisible( ITEM_GAL_LAYER( VIAS_HOLES_VISIBLE ), true ); view->SetLayerVisible( ITEM_GAL_LAYER( WORKSHEET ), true ); view->SetLayerVisible( ITEM_GAL_LAYER( GP_OVERLAY ), true ); }
void FOOTPRINT_EDIT_FRAME::RestoreCopyFromUndoList( wxCommandEvent& aEvent ) { if( UndoRedoBlocked() ) return; if( GetScreen()->GetUndoCommandCount() <= 0 ) return; // Inform tools that undo command was issued TOOL_EVENT event( TC_MESSAGE, TA_UNDO_REDO, AS_GLOBAL ); m_toolManager->ProcessEvent( event ); if( UndoRedoBlocked() ) return; // Save current module state in redo list PICKED_ITEMS_LIST* lastcmd = new PICKED_ITEMS_LIST(); MODULE* module = GetBoard()->m_Modules.PopFront(); ITEM_PICKER wrapper( module, UR_MODEDIT ); KIGFX::VIEW* view = GetGalCanvas()->GetView(); lastcmd->PushItem( wrapper ); GetScreen()->PushCommandToRedoList( lastcmd ); view->Remove( module ); module->RunOnChildren( std::bind( &KIGFX::VIEW::Remove, view, _1 ) ); // Retrieve last module state from undo list lastcmd = GetScreen()->PopCommandFromUndoList(); wrapper = lastcmd->PopItem(); module = (MODULE*) wrapper.GetItem(); delete lastcmd; if( module ) { GetBoard()->Add( module, ADD_APPEND ); view->Add( module ); module->RunOnChildren( std::bind( &KIGFX::VIEW::Add, view, _1 ) ); module->ViewUpdate(); } SetCurItem( NULL ); OnModify(); m_canvas->Refresh(); }
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 EDIT_TOOL::processChanges( const PICKED_ITEMS_LIST* aList ) { KIGFX::VIEW* view = getView(); RN_DATA* ratsnest = getModel<BOARD>()->GetRatsnest(); for( unsigned int i = 0; i < aList->GetCount(); ++i ) { UNDO_REDO_T operation = aList->GetPickedItemStatus( i ); BOARD_ITEM* updItem = static_cast<BOARD_ITEM*>( aList->GetPickedItem( i ) ); switch( operation ) { case UR_CHANGED: ratsnest->Update( updItem ); // fall through case UR_MODEDIT: updItem->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); break; case UR_DELETED: if( updItem->Type() == PCB_MODULE_T ) static_cast<MODULE*>( updItem )->RunOnChildren( boost::bind( &KIGFX::VIEW::Remove, view, _1 ) ); view->Remove( updItem ); //ratsnest->Remove( updItem ); // this is done in BOARD::Remove break; case UR_NEW: if( updItem->Type() == PCB_MODULE_T ) static_cast<MODULE*>( updItem )->RunOnChildren( boost::bind( &KIGFX::VIEW::Add, view, _1 ) ); view->Add( updItem ); //ratsnest->Add( updItem ); // this is done in BOARD::Add break; default: assert( false ); // Not handled break; } } }
void PCB_EDIT_FRAME::setHighContrastLayer( LAYER_NUM aLayer ) { // Set display settings for high contrast mode KIGFX::VIEW* view = GetGalCanvas()->GetView(); KIGFX::RENDER_SETTINGS* rSettings = view->GetPainter()->GetSettings(); setTopLayer( aLayer ); rSettings->ClearActiveLayers(); rSettings->SetActiveLayer( aLayer ); if( IsCopperLayer( aLayer ) ) { // Bring some other layers to the front in case of copper layers and make them colored // fixme do not like the idea of storing the list of layers here, // should be done in some other way I guess.. LAYER_NUM layers[] = { GetNetnameLayer( aLayer ), ITEM_GAL_LAYER( VIAS_VISIBLE ), ITEM_GAL_LAYER( VIAS_HOLES_VISIBLE ), ITEM_GAL_LAYER( PADS_VISIBLE ), ITEM_GAL_LAYER( PADS_HOLES_VISIBLE ), NETNAMES_GAL_LAYER( PADS_NETNAMES_VISIBLE ), ITEM_GAL_LAYER( GP_OVERLAY ), ITEM_GAL_LAYER( RATSNEST_VISIBLE ) }; for( unsigned int i = 0; i < sizeof( layers ) / sizeof( LAYER_NUM ); ++i ) rSettings->SetActiveLayer( layers[i] ); // Pads should be shown too if( aLayer == FIRST_COPPER_LAYER ) { rSettings->SetActiveLayer( ITEM_GAL_LAYER( PAD_BK_VISIBLE ) ); rSettings->SetActiveLayer( NETNAMES_GAL_LAYER( PAD_BK_NETNAMES_VISIBLE ) ); } else if( aLayer == LAST_COPPER_LAYER ) { rSettings->SetActiveLayer( ITEM_GAL_LAYER( PAD_FR_VISIBLE ) ); rSettings->SetActiveLayer( NETNAMES_GAL_LAYER( PAD_FR_NETNAMES_VISIBLE ) ); } } view->UpdateAllLayersColor(); }
void PCB_LAYER_WIDGET::OnLayerVisible( int aLayer, bool isVisible, bool isFinal ) { BOARD* brd = myframe->GetBoard(); LSET visibleLayers = brd->GetVisibleLayers(); visibleLayers.set( aLayer, isVisible ); brd->SetVisibleLayers( visibleLayers ); EDA_DRAW_PANEL_GAL* galCanvas = myframe->GetGalCanvas(); if( galCanvas ) { KIGFX::VIEW* view = galCanvas->GetView(); view->SetLayerVisible( aLayer, isVisible ); view->RecacheAllItems( true ); } if( isFinal ) myframe->GetCanvas()->Refresh(); }
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 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; }
void PCB_LAYER_WIDGET::OnLayerVisible( LAYER_NUM aLayer, bool isVisible, bool isFinal ) { BOARD* brd = myframe->GetBoard(); LAYER_MSK visibleLayers = brd->GetVisibleLayers(); if( isVisible ) visibleLayers |= GetLayerMask( aLayer ); else visibleLayers &= ~GetLayerMask( aLayer ); brd->SetVisibleLayers( visibleLayers ); EDA_DRAW_PANEL_GAL* galCanvas = myframe->GetGalCanvas(); if( galCanvas ) { KIGFX::VIEW* view = galCanvas->GetView(); view->SetLayerVisible( aLayer, isVisible ); } if( isFinal ) myframe->GetCanvas()->Refresh(); }
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; }
int PCB_EDITOR_CONTROL::ZoneMerge( const TOOL_EVENT& aEvent ) { SELECTION selection = m_toolMgr->GetTool<SELECTION_TOOL>()->GetSelection(); BOARD* board = getModel<BOARD>(); RN_DATA* ratsnest = board->GetRatsnest(); KIGFX::VIEW* view = getView(); if( selection.Size() < 2 ) return 0; PICKED_ITEMS_LIST changes; int netcode = -1; // Loop through all combinations for( int ia1 = 0; ia1 < selection.Size() - 1; ++ia1 ) { ZONE_CONTAINER* curr_area = dynamic_cast<ZONE_CONTAINER*>( selection.Item<EDA_ITEM>( ia1 ) ); if( !curr_area ) continue; netcode = curr_area->GetNetCode(); EDA_RECT b1 = curr_area->Outline()->GetBoundingBox(); bool mod_ia1 = false; for( int ia2 = selection.Size() - 1; ia2 > ia1; --ia2 ) { ZONE_CONTAINER* area2 = dynamic_cast<ZONE_CONTAINER*>( selection.Item<EDA_ITEM>( ia2 ) ); if( !area2 ) continue; if( area2->GetNetCode() != netcode ) continue; if( curr_area->GetPriority() != area2->GetPriority() ) continue; if( curr_area->GetIsKeepout() != area2->GetIsKeepout() ) continue; if( curr_area->GetLayer() != area2->GetLayer() ) continue; EDA_RECT b2 = area2->Outline()->GetBoundingBox(); if( b1.Intersects( b2 ) ) { EDA_ITEM* backup = curr_area->Clone(); bool ret = board->TestAreaIntersection( curr_area, area2 ); if( ret && board->CombineAreas( &changes, curr_area, area2 ) ) { mod_ia1 = true; selection.items.RemovePicker( ia2 ); ITEM_PICKER picker( curr_area, UR_CHANGED ); picker.SetLink( backup ); changes.PushItem( picker ); } else { delete backup; } } } if( mod_ia1 ) --ia1; // if modified, we need to check it again } m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); m_frame->SaveCopyInUndoList( changes, UR_UNSPECIFIED ); for( unsigned i = 0; i < changes.GetCount(); ++i ) { ITEM_PICKER picker = changes.GetItemWrapper( i ); BOARD_ITEM* item = static_cast<BOARD_ITEM*>( picker.GetItem() ); if( picker.GetStatus() == UR_DELETED ) { view->Remove( item ); ratsnest->Remove( item ); } else if( picker.GetStatus() == UR_CHANGED ) { item->ViewUpdate( KIGFX::VIEW_ITEM::ALL ); m_toolMgr->RunAction( COMMON_ACTIONS::selectItem, true, item ); } } return 0; }
int PCB_EDITOR_CONTROL::PlaceTarget( const TOOL_EVENT& aEvent ) { KIGFX::VIEW* view = getView(); KIGFX::VIEW_CONTROLS* controls = getViewControls(); BOARD* board = getModel<BOARD>(); PCB_TARGET* target = new PCB_TARGET( board ); // Init the new item attributes target->SetLayer( Edge_Cuts ); target->SetWidth( board->GetDesignSettings().m_EdgeSegmentWidth ); target->SetSize( Millimeter2iu( 5 ) ); VECTOR2I cursorPos = controls->GetCursorPosition(); target->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) ); // Add a VIEW_GROUP that serves as a preview for the new item KIGFX::VIEW_GROUP preview( view ); preview.Add( target ); view->Add( &preview ); preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); controls->SetSnapping( true ); Activate(); m_frame->SetToolID( ID_PCB_MIRE_BUTT, wxCURSOR_PENCIL, _( "Add layer alignment target" ) ); // Main loop: keep receiving events while( OPT_TOOL_EVENT evt = Wait() ) { cursorPos = controls->GetCursorPosition(); if( evt->IsCancel() || evt->IsActivate() ) break; else if( evt->IsAction( &COMMON_ACTIONS::incWidth ) ) { target->SetWidth( target->GetWidth() + WIDTH_STEP ); preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } else if( evt->IsAction( &COMMON_ACTIONS::decWidth ) ) { int width = target->GetWidth(); if( width > WIDTH_STEP ) { target->SetWidth( width - WIDTH_STEP ); preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } } else if( evt->IsClick( BUT_LEFT ) ) { assert( target->GetSize() > 0 ); assert( target->GetWidth() > 0 ); view->Add( target ); board->Add( target ); target->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); m_frame->OnModify(); m_frame->SaveCopyInUndoList( target, UR_NEW ); preview.Remove( target ); // Create next PCB_TARGET target = new PCB_TARGET( *target ); preview.Add( target ); } else if( evt->IsMotion() ) { target->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) ); preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } } delete target; controls->SetSnapping( false ); view->Remove( &preview ); m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); return 0; }
int PCB_EDITOR_CONTROL::PlaceModule( const TOOL_EVENT& aEvent ) { MODULE* module = NULL; KIGFX::VIEW* view = getView(); KIGFX::VIEW_CONTROLS* controls = getViewControls(); BOARD* board = getModel<BOARD>(); // Add a VIEW_GROUP that serves as a preview for the new item KIGFX::VIEW_GROUP preview( view ); view->Add( &preview ); m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); controls->ShowCursor( true ); controls->SetSnapping( true ); Activate(); m_frame->SetToolID( ID_PCB_MODULE_BUTT, wxCURSOR_HAND, _( "Add footprint" ) ); // Main loop: keep receiving events while( OPT_TOOL_EVENT evt = Wait() ) { VECTOR2I cursorPos = controls->GetCursorPosition(); if( evt->IsCancel() || evt->IsActivate() ) { if( module ) { board->Delete( module ); // it was added by LoadModuleFromLibrary() module = NULL; preview.Clear(); preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); controls->ShowCursor( true ); } else break; if( evt->IsActivate() ) // now finish unconditionally break; } else if( module && evt->Category() == TC_COMMAND ) { if( evt->IsAction( &COMMON_ACTIONS::rotate ) ) { module->Rotate( module->GetPosition(), m_frame->GetRotationAngle() ); preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } else if( evt->IsAction( &COMMON_ACTIONS::flip ) ) { module->Flip( module->GetPosition() ); preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } } else if( evt->IsClick( BUT_LEFT ) ) { if( !module ) { // Pick the module to be placed module = m_frame->LoadModuleFromLibrary( wxEmptyString, m_frame->Prj().PcbFootprintLibs(), true, NULL ); if( module == NULL ) continue; module->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) ); // Add all the drawable parts to preview preview.Add( module ); module->RunOnChildren( boost::bind( &KIGFX::VIEW_GROUP::Add, &preview, _1 ) ); preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } else { // Place the selected module module->RunOnChildren( boost::bind( &KIGFX::VIEW::Add, view, _1 ) ); view->Add( module ); module->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); m_frame->OnModify(); m_frame->SaveCopyInUndoList( module, UR_NEW ); // Remove from preview preview.Remove( module ); module->RunOnChildren( boost::bind( &KIGFX::VIEW_GROUP::Remove, &preview, _1 ) ); module = NULL; // to indicate that there is no module that we currently modify } bool placing = ( module != NULL ); controls->SetAutoPan( placing ); controls->CaptureCursor( placing ); controls->ShowCursor( !placing ); } else if( module && evt->IsMotion() ) { module->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) ); preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } } controls->ShowCursor( false ); controls->SetSnapping( false ); controls->SetAutoPan( false ); controls->CaptureCursor( false ); view->Remove( &preview ); m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); return 0; }