void LENGTH_TUNER_TOOL::handleCommonEvents( const TOOL_EVENT& aEvent ) { if( aEvent.IsAction( &ACT_RouterOptions ) ) { DIALOG_PNS_SETTINGS settingsDlg( m_frame, m_router->Settings() ); if( settingsDlg.ShowModal() ) { // FIXME: do we need an explicit update? } } PNS_MEANDER_PLACER_BASE* placer = static_cast<PNS_MEANDER_PLACER_BASE*>( m_router->Placer() ); if( !placer ) return; if( aEvent.IsAction( &ACT_Settings ) ) { PNS_MEANDER_SETTINGS settings = placer->MeanderSettings(); DIALOG_PNS_LENGTH_TUNING_SETTINGS settingsDlg( m_frame, settings, m_router->Mode() ); if( settingsDlg.ShowModal() ) { placer->UpdateSettings( settings ); } m_savedMeanderSettings = placer->MeanderSettings(); } }
int PCBNEW_CONTROL::ZoneDisplayMode( const TOOL_EVENT& aEvent ) { KIGFX::PCB_PAINTER* painter = static_cast<KIGFX::PCB_PAINTER*>( m_frame->GetGalCanvas()->GetView()->GetPainter() ); KIGFX::PCB_RENDER_SETTINGS* settings = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( painter->GetSettings() ); DISPLAY_OPTIONS* displ_opts = (DISPLAY_OPTIONS*)m_frame->GetDisplayOptions(); // Apply new display options to the GAL canvas if( aEvent.IsAction( &COMMON_ACTIONS::zoneDisplayEnable ) ) displ_opts->m_DisplayZonesMode = 0; else if( aEvent.IsAction( &COMMON_ACTIONS::zoneDisplayDisable ) ) displ_opts->m_DisplayZonesMode = 1; else if( aEvent.IsAction( &COMMON_ACTIONS::zoneDisplayOutlines ) ) displ_opts->m_DisplayZonesMode = 2; else assert( false ); settings->LoadDisplayOptions( displ_opts ); BOARD* board = getModel<BOARD>(); for( int i = 0; i < board->GetAreaCount(); ++i ) board->GetArea( i )->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); m_frame->GetGalCanvas()->Refresh(); return 0; }
void ROUTER_TOOL::handleCommonEvents( const TOOL_EVENT& aEvent ) { #ifdef DEBUG if( aEvent.IsKeyPressed() ) { switch( aEvent.KeyCode() ) { case '0': TRACEn( 2, "saving drag/route log...\n" ); m_router->DumpLog(); break; } } else #endif if( aEvent.IsAction( &ACT_RouterOptions ) ) { DIALOG_PNS_SETTINGS settingsDlg( m_frame, m_router->Settings() ); if( settingsDlg.ShowModal() ) { // FIXME: do we need an explicit update? } } else if( aEvent.IsAction( &ACT_SetDpDimensions ) ) { PNS_SIZES_SETTINGS sizes = m_router->Sizes(); DIALOG_PNS_DIFF_PAIR_DIMENSIONS settingsDlg( m_frame, sizes ); if( settingsDlg.ShowModal() ) { m_router->UpdateSizes( sizes ); } } else if( aEvent.IsAction( &ACT_CustomTrackWidth ) ) { BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings(); DIALOG_TRACK_VIA_SIZE sizeDlg( m_frame, bds ); if( sizeDlg.ShowModal() ) { bds.UseCustomTrackViaSize( true ); m_toolMgr->RunAction( COMMON_ACTIONS::trackViaSizeChanged ); } } else if( aEvent.IsAction( &COMMON_ACTIONS::trackViaSizeChanged ) ) { PNS_SIZES_SETTINGS sizes( m_router->Sizes() ); sizes.ImportCurrent( m_board->GetDesignSettings() ); m_router->UpdateSizes( sizes ); } }
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; }
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; }
int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent ) { bool increment = aEvent.IsAction( &COMMON_ACTIONS::duplicateIncrement ); // first, check if we have a selection, or try to get one SELECTION_TOOL* selTool = m_toolMgr->GetTool<SELECTION_TOOL>(); const SELECTION& selection = selTool->GetSelection(); // Be sure that there is at least one item that we can modify if( !hoverSelection( selection ) ) return 0; // we have a selection to work on now, so start the tool process PCB_BASE_FRAME* editFrame = getEditFrame<PCB_BASE_FRAME>(); editFrame->OnModify(); // prevent other tools making undo points while the duplicate is going on // so that if you cancel, you don't get a duplicate object hiding over // the original incUndoInhibit(); if( m_editModules ) editFrame->SaveCopyInUndoList( editFrame->GetBoard()->m_Modules, UR_MODEDIT ); std::vector<BOARD_ITEM*> old_items; for( int i = 0; i < selection.Size(); ++i ) { BOARD_ITEM* item = selection.Item<BOARD_ITEM>( i ); if( item ) old_items.push_back( item ); } for( unsigned i = 0; i < old_items.size(); ++i ) { BOARD_ITEM* item = old_items[i]; // Unselect the item, so we won't pick it up again // Do this first, so a single-item duplicate will correctly call // SetCurItem and show the item properties m_toolMgr->RunAction( COMMON_ACTIONS::unselectItem, true, item ); BOARD_ITEM* new_item = NULL; if( m_editModules ) new_item = editFrame->GetBoard()->m_Modules->DuplicateAndAddItem( item, increment ); else { #if 0 // @TODO: see if we allow zone duplication here // Duplicate zones is especially tricky (overlaping zones must be merged) // so zones are not duplicated if( item->Type() != PCB_ZONE_AREA_T ) #endif new_item = editFrame->GetBoard()->DuplicateAndAddItem( item, increment ); } if( new_item ) { if( new_item->Type() == PCB_MODULE_T ) { static_cast<MODULE*>( new_item )->RunOnChildren( boost::bind( &KIGFX::VIEW::Add, getView(), _1 ) ); } editFrame->GetGalCanvas()->GetView()->Add( new_item ); // Select the new item, so we can pick it up m_toolMgr->RunAction( COMMON_ACTIONS::selectItem, true, new_item ); } } // record the new items as added if( !m_editModules ) editFrame->SaveCopyInUndoList( selection.items, UR_NEW ); editFrame->DisplayToolMsg( wxString::Format( _( "Duplicated %d item(s)" ), (int) old_items.size() ) ); // pick up the selected item(s) and start moving // this works well for "dropping" copies around TOOL_EVENT evt = COMMON_ACTIONS::editActivate.MakeEvent(); Main( evt ); // and re-enable undos decUndoInhibit(); return 0; }
bool TOOL_EVT_UTILS::IsRotateToolEvt( const TOOL_EVENT& aEvt ) { return aEvt.IsAction( &PCB_ACTIONS::rotateCw ) || aEvt.IsAction( &PCB_ACTIONS::rotateCcw ); }
bool TOOL_EVT_UTILS::IsCancelInteractive( const TOOL_EVENT& aEvt ) { return aEvt.IsAction( &ACTIONS::cancelInteractive ) || aEvt.IsActivate() || aEvt.IsCancel(); }
int PL_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent ) { // We might be running as the same shape in another co-routine. Make sure that one // gets whacked. m_toolMgr->DeactivateTool(); bool isDrawLine; bool isImmediate = false; if( aEvent.IsAction( &PL_ACTIONS::drawLine ) ) { isDrawLine = true; m_frame->SetToolID( ID_PL_LINE_TOOL, wxCURSOR_PENCIL, _( "Draw line" ) ); } else if( aEvent.IsAction( &PL_ACTIONS::drawRectangle ) ) { isDrawLine = false; m_frame->SetToolID( ID_PL_RECTANGLE_TOOL, wxCURSOR_PENCIL, _( "Draw rectangle" ) ); } else if( aEvent.IsAction( &PL_ACTIONS::addLine ) ) { isDrawLine = true; isImmediate = true; } else if( aEvent.IsAction( &PL_ACTIONS::addRectangle ) ) { isDrawLine = false; isImmediate = true; } else wxCHECK_MSG( false, 0, "Unknown action in PL_DRAWING_TOOLS::DrawShape()" ); m_toolMgr->RunAction( PL_ACTIONS::clearSelection, true ); getViewControls()->ShowCursor( true ); Activate(); WS_DRAW_ITEM_BASE* item = nullptr; // Main loop: keep receiving events while( auto evt = Wait() ) { VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) ); if( TOOL_EVT_UTILS::IsCancelInteractive( evt.get() ) ) { m_toolMgr->RunAction( PL_ACTIONS::clearSelection, true ); if( item ) { item = nullptr; m_frame->RollbackFromUndo(); if( !evt->IsActivate() && !isImmediate ) continue; } break; } else if( evt->IsClick( BUT_LEFT ) || ( isImmediate && !item ) ) { if( !item ) // start drawing { m_frame->SaveCopyInUndoList(); m_toolMgr->RunAction( PL_ACTIONS::clearSelection, true ); WS_DATA_ITEM::WS_ITEM_TYPE dataType; if( isDrawLine ) dataType = WS_DATA_ITEM::WS_SEGMENT; else dataType = WS_DATA_ITEM::WS_RECT; WS_DATA_ITEM* dataItem = m_frame->AddPageLayoutItem( dataType ); dataItem->MoveToUi( (wxPoint) cursorPos ); item = dataItem->GetDrawItems()[0]; item->SetFlags( IS_NEW ); m_selectionTool->AddItemToSel( item ); } else // finish drawing { item->ClearEditFlags(); item = nullptr; m_frame->OnModify(); if( isImmediate ) { m_toolMgr->RunAction( ACTIONS::activatePointEditor ); break; } } } else if( evt->IsAction( &PL_ACTIONS::refreshPreview ) || evt->IsMotion() ) { if( item ) { item->GetPeer()->MoveEndPointToUi( (wxPoint) cursorPos ); item->SetEnd( item->GetPeer()->GetEndPosUi( 0 ) ); getView()->Update( item ); } } else if( evt->IsClick( BUT_RIGHT ) ) { // Warp after context menu only if dragging... if( !item ) m_toolMgr->VetoContextMenuMouseWarp(); m_menu.ShowContextMenu( m_selectionTool->GetSelection() ); } // Enable autopanning and cursor capture only when there is a shape being drawn getViewControls()->SetAutoPan( !!item ); getViewControls()->CaptureCursor( !!item ); } m_frame->SetNoToolSelected(); return 0; }
int PL_DRAWING_TOOLS::PlaceItem( const TOOL_EVENT& aEvent ) { bool isText; bool isImmediate = false; if( aEvent.IsAction( &PL_ACTIONS::placeText ) ) { isText = true; m_frame->SetToolID( ID_PL_TEXT_TOOL, wxCURSOR_PENCIL, _( "Add text" ) ); } else if( aEvent.IsAction( &PL_ACTIONS::placeImage ) ) { isText = false; m_frame->SetToolID( ID_PL_IMAGE_TOOL, wxCURSOR_PENCIL, _( "Add image" ) ); } else if( aEvent.IsAction( & PL_ACTIONS::addText ) ) { isText = true; isImmediate = true; } else if( aEvent.IsAction( & PL_ACTIONS::addImage ) ) { isText = false; isImmediate = true; } else wxCHECK_MSG( false, 0, "Unknown action in PL_DRAWING_TOOLS::PlaceItem()" ); VECTOR2I cursorPos; WS_DRAW_ITEM_BASE* item = nullptr; m_toolMgr->RunAction( PL_ACTIONS::clearSelection, true ); getViewControls()->ShowCursor( true ); Activate(); // Main loop: keep receiving events while( OPT_TOOL_EVENT evt = Wait() ) { cursorPos = getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) ); if( TOOL_EVT_UTILS::IsCancelInteractive( evt.get() ) ) { if( item ) { m_toolMgr->RunAction( PL_ACTIONS::clearSelection, true ); delete item; item = nullptr; // There's nothing to roll-back, but we still need to pop the undo stack m_frame->RollbackFromUndo(); if( !evt->IsActivate() && !isImmediate ) continue; } break; } else if( evt->IsClick( BUT_LEFT ) || ( isImmediate && !item ) ) { // First click creates... if( !item ) { m_frame->SaveCopyInUndoList(); m_toolMgr->RunAction( PL_ACTIONS::clearSelection, true ); WS_DATA_ITEM* dataItem; dataItem = m_frame->AddPageLayoutItem( isText ? WS_DATA_ITEM::WS_TEXT : WS_DATA_ITEM::WS_BITMAP ); item = dataItem->GetDrawItems()[0]; item->SetFlags( IS_NEW | IS_MOVED ); m_selectionTool->AddItemToSel( item ); } // ... and second click places: else { item->GetPeer()->MoveStartPointToUi( (wxPoint) cursorPos ); item->SetPosition( item->GetPeer()->GetStartPosUi( 0 ) ); item->ClearEditFlags(); getView()->Update( item ); item = nullptr; m_frame->OnModify(); if( isImmediate ) break; } } else if( evt->IsClick( BUT_RIGHT ) ) { // Warp after context menu only if dragging... if( !item ) m_toolMgr->VetoContextMenuMouseWarp(); m_menu.ShowContextMenu( m_selectionTool->GetSelection() ); } else if( item && ( evt->IsAction( &PL_ACTIONS::refreshPreview ) || evt->IsMotion() ) ) { item->GetPeer()->MoveStartPointToUi( (wxPoint) cursorPos ); item->SetPosition( item->GetPeer()->GetStartPosUi( 0 ) ); getView()->Update( item ); } // Enable autopanning and cursor capture only when there is an item to be placed getViewControls()->SetAutoPan( !!item ); getViewControls()->CaptureCursor( !!item ); } m_frame->SetNoToolSelected(); return 0; }
int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent ) { // Note: original items are no more modified. bool increment = aEvent.IsAction( &COMMON_ACTIONS::duplicateIncrement ); // first, check if we have a selection, or try to get one SELECTION_TOOL* selTool = m_toolMgr->GetTool<SELECTION_TOOL>(); const SELECTION& selection = selTool->GetSelection(); // Be sure that there is at least one item that we can modify if( !hoverSelection() ) return 0; // we have a selection to work on now, so start the tool process PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>(); std::vector<BOARD_ITEM*> old_items; for( int i = 0; i < selection.Size(); ++i ) { BOARD_ITEM* item = selection.Item<BOARD_ITEM>( i ); if( item ) old_items.push_back( item ); } for( unsigned i = 0; i < old_items.size(); ++i ) { BOARD_ITEM* item = old_items[i]; // Unselect the item, so we won't pick it up again // Do this first, so a single-item duplicate will correctly call // SetCurItem and show the item properties m_toolMgr->RunAction( COMMON_ACTIONS::unselectItem, true, item ); BOARD_ITEM* new_item = NULL; if( m_editModules ) new_item = editFrame->GetBoard()->m_Modules->Duplicate( item, increment ); else { #if 0 // @TODO: see if we allow zone duplication here // Duplicate zones is especially tricky (overlaping zones must be merged) // so zones are not duplicated if( item->Type() != PCB_ZONE_AREA_T ) #endif new_item = editFrame->GetBoard()->Duplicate( item ); } if( new_item ) { m_commit->Add( new_item ); // Select the new item, so we can pick it up m_toolMgr->RunAction( COMMON_ACTIONS::selectItem, true, new_item ); } } // record the new items as added if( !selection.Empty() ) { editFrame->DisplayToolMsg( wxString::Format( _( "Duplicated %d item(s)" ), (int) old_items.size() ) ); // If items were duplicated, pick them up // this works well for "dropping" copies around and pushes the commit TOOL_EVENT evt = COMMON_ACTIONS::editActivate.MakeEvent(); Main( evt ); } return 0; };