From f6962b62022d4a36245c66650f122bbe0c9a9216 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Wed, 11 Aug 2010 15:15:30 +0200 Subject: [PATCH 1/3] minor change when deleting a pad in modedit: the pad is deleted silently --- include/wxBasePcbFrame.h | 9 ++++++++- pcbnew/editmod.cpp | 2 +- pcbnew/modedit.cpp | 2 +- pcbnew/modedit_onclick.cpp | 12 +++--------- pcbnew/move-drag_pads.cpp | 36 +++++++++++++++++++++--------------- 5 files changed, 34 insertions(+), 27 deletions(-) diff --git a/include/wxBasePcbFrame.h b/include/wxBasePcbFrame.h index e2ddb64cb3..2ffa5a47f2 100644 --- a/include/wxBasePcbFrame.h +++ b/include/wxBasePcbFrame.h @@ -257,7 +257,14 @@ public: wxDC* DC ); void AddPad( MODULE* Module, bool draw ); - void DeletePad( D_PAD* Pad ); + /** Function DeletePad + * Delete the pad aPad. + * Refresh the modified screen area + * Refresh modified parameters of the parent module (bounding box, last date) + * @param aPad = the pad to delete + * @param aQuery = true to promt for confirmation, false to delete silently + */ + void DeletePad( D_PAD* aPad, bool aQuery = true ); void StartMovePad( D_PAD* Pad, wxDC* DC ); void RotatePad( D_PAD* Pad, wxDC* DC ); void PlacePad( D_PAD* Pad, wxDC* DC ); diff --git a/pcbnew/editmod.cpp b/pcbnew/editmod.cpp index e57bdeb734..075c139b3a 100644 --- a/pcbnew/editmod.cpp +++ b/pcbnew/editmod.cpp @@ -118,7 +118,7 @@ void WinEDA_ModuleEditFrame::RemoveStruct( EDA_BaseStruct* Item ) switch( Item->Type() ) { case TYPE_PAD: - DeletePad( (D_PAD*) Item ); + DeletePad( (D_PAD*) Item, false ); break; case TYPE_TEXTE_MODULE: diff --git a/pcbnew/modedit.cpp b/pcbnew/modedit.cpp index bb79bcca5a..a079b750fd 100644 --- a/pcbnew/modedit.cpp +++ b/pcbnew/modedit.cpp @@ -518,7 +518,7 @@ void WinEDA_ModuleEditFrame::Process_Special_Functions( wxCommandEvent& event ) case ID_POPUP_PCB_DELETE_PAD: SaveCopyInUndoList( GetBoard()->m_Modules, UR_MODEDIT ); - DeletePad( (D_PAD*) GetScreen()->GetCurItem() ); + DeletePad( (D_PAD*) GetScreen()->GetCurItem(), false ); SetCurItem( NULL ); DrawPanel->MouseToCursorSchema(); break; diff --git a/pcbnew/modedit_onclick.cpp b/pcbnew/modedit_onclick.cpp index f6e8dcf48d..bac1bf9be1 100644 --- a/pcbnew/modedit_onclick.cpp +++ b/pcbnew/modedit_onclick.cpp @@ -116,19 +116,13 @@ m_Flags != 0\nStruct @%p, type %d m_Flag %X" ), break; case ID_MODEDIT_DELETE_ITEM_BUTT: - - // Item in edit, cannot delete it - if( DrawStruct && (DrawStruct->m_Flags != 0) ) + if( DrawStruct == NULL || // No item to delete + (DrawStruct->m_Flags != 0) ) // Item in edit, cannot delete it break; - DrawStruct = ModeditLocateAndDisplay(); - if( DrawStruct == NULL || (DrawStruct->m_Flags != 0) ) - break; - if( DrawStruct->Type() != TYPE_MODULE ) //GetBoard()->m_Modules ) + if( DrawStruct->Type() != TYPE_MODULE ) // Cannot delete the module itself { - // Cannot delete the module itself SaveCopyInUndoList( GetBoard()->m_Modules, UR_MODEDIT ); RemoveStruct( DrawStruct ); - DrawStruct = NULL; SetCurItem( NULL ); } break; diff --git a/pcbnew/move-drag_pads.cpp b/pcbnew/move-drag_pads.cpp index 273c828667..9ddd692b65 100644 --- a/pcbnew/move-drag_pads.cpp +++ b/pcbnew/move-drag_pads.cpp @@ -227,30 +227,36 @@ void WinEDA_BasePcbFrame::AddPad( MODULE* Module, bool draw ) } -/* Function to delete the pad. */ -void WinEDA_BasePcbFrame::DeletePad( D_PAD* Pad ) +/** Function DeletePad + * Delete the pad aPad. + * Refresh the modified screen area + * Refresh modified parameters of the parent module (bounding box, last date) + * @param aPad = the pad to delete + * @param aQuery = true to promt for confirmation, false to delete silently + */ +void WinEDA_BasePcbFrame::DeletePad( D_PAD* aPad, bool aQuery ) { MODULE* Module; - wxString line; - - if( Pad == NULL ) + + if( aPad == NULL ) return; - Module = (MODULE*) Pad->GetParent(); + Module = (MODULE*) aPad->GetParent(); Module->m_LastEdit_Time = time( NULL ); - line.Printf( _( "Delete Pad (module %s %s) " ), - GetChars( Module->m_Reference->m_Text ), - GetChars( Module->m_Value->m_Text ) ); - if( !IsOK( this, line ) ) - return; + if( aQuery ) + { + wxString msg; + msg.Printf( _( "Delete Pad (module %s %s) " ), + GetChars( Module->m_Reference->m_Text ), + GetChars( Module->m_Value->m_Text ) ); + if( !IsOK( this, msg ) ) + return; + } m_Pcb->m_Status_Pcb = 0; - - Pad->DeleteStructure(); - + aPad->DeleteStructure(); DrawPanel->PostDirtyRect( Module->GetBoundingBox() ); - Module->Set_Rectangle_Encadrement(); OnModify(); From 2a14f2d55e52204a257b9e68c5991ecb6133d1c1 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Thu, 12 Aug 2010 07:57:14 +0200 Subject: [PATCH 2/3] minor code cleaning --- pcbnew/automove.cpp | 85 ++++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 44 deletions(-) diff --git a/pcbnew/automove.cpp b/pcbnew/automove.cpp index 3db70b8707..534ae746d8 100644 --- a/pcbnew/automove.cpp +++ b/pcbnew/automove.cpp @@ -36,17 +36,56 @@ wxString ModulesMaskSelection = wxT( "*" ); void WinEDA_PcbFrame::AutoPlace( wxCommandEvent& event ) { int id = event.GetId(); - INSTALL_DC( dc, DrawPanel ); bool on_state; if( m_HToolBar == NULL ) return; + INSTALL_DC( dc, DrawPanel ); + switch( id ) { case ID_TOOLBARH_PCB_AUTOPLACE: + on_state = m_HToolBar->GetToolState( ID_TOOLBARH_PCB_AUTOPLACE ); + if( on_state ) + { + m_HToolBar->ToggleTool( ID_TOOLBARH_PCB_AUTOROUTE, FALSE ); + m_HTOOL_current_state = ID_TOOLBARH_PCB_AUTOPLACE; + } + else + m_HTOOL_current_state = 0; + return; + case ID_TOOLBARH_PCB_AUTOROUTE: - break; + on_state = m_HToolBar->GetToolState( ID_TOOLBARH_PCB_AUTOROUTE ); + if( on_state ) + { + m_HToolBar->ToggleTool( ID_TOOLBARH_PCB_AUTOPLACE, FALSE ); + m_HTOOL_current_state = ID_TOOLBARH_PCB_AUTOROUTE; + } + else + m_HTOOL_current_state = 0; + return; + + + case ID_POPUP_PCB_AUTOROUTE_SELECT_LAYERS: + return; + + case ID_POPUP_PCB_AUTOPLACE_FIXE_MODULE: + FixeModule( (MODULE*) GetScreen()->GetCurItem(), TRUE ); + return; + + case ID_POPUP_PCB_AUTOPLACE_FREE_MODULE: + FixeModule( (MODULE*) GetScreen()->GetCurItem(), FALSE ); + return; + + case ID_POPUP_PCB_AUTOPLACE_FREE_ALL_MODULES: + FixeModule( NULL, FALSE ); + return; + + case ID_POPUP_PCB_AUTOPLACE_FIXE_ALL_MODULES: + FixeModule( NULL, TRUE ); + return; case ID_POPUP_CANCEL_CURRENT_COMMAND: if( DrawPanel->ManageCurseur @@ -68,44 +107,6 @@ void WinEDA_PcbFrame::AutoPlace( wxCommandEvent& event ) switch( id ) { - case ID_TOOLBARH_PCB_AUTOPLACE: - on_state = m_HToolBar->GetToolState( ID_TOOLBARH_PCB_AUTOPLACE ); - if( on_state ) - { - m_HToolBar->ToggleTool( ID_TOOLBARH_PCB_AUTOROUTE, FALSE ); - m_HTOOL_current_state = ID_TOOLBARH_PCB_AUTOPLACE; - } - else - m_HTOOL_current_state = 0; - break; - - case ID_TOOLBARH_PCB_AUTOROUTE: - on_state = m_HToolBar->GetToolState( ID_TOOLBARH_PCB_AUTOROUTE ); - if( on_state ) - { - m_HToolBar->ToggleTool( ID_TOOLBARH_PCB_AUTOPLACE, FALSE ); - m_HTOOL_current_state = ID_TOOLBARH_PCB_AUTOROUTE; - } - else - m_HTOOL_current_state = 0; - break; - - case ID_POPUP_PCB_AUTOPLACE_FIXE_MODULE: - FixeModule( (MODULE*) GetScreen()->GetCurItem(), TRUE ); - break; - - case ID_POPUP_PCB_AUTOPLACE_FREE_MODULE: - FixeModule( (MODULE*) GetScreen()->GetCurItem(), FALSE ); - break; - - case ID_POPUP_PCB_AUTOPLACE_FREE_ALL_MODULES: - FixeModule( NULL, FALSE ); - break; - - case ID_POPUP_PCB_AUTOPLACE_FIXE_ALL_MODULES: - FixeModule( NULL, TRUE ); - break; - case ID_POPUP_PCB_AUTOPLACE_CURRENT_MODULE: AutoPlaceModule( (MODULE*) GetScreen()->GetCurItem(), PLACE_1_MODULE, &dc ); @@ -155,9 +156,6 @@ void WinEDA_PcbFrame::AutoPlace( wxCommandEvent& event ) Reset_Noroutable( &dc ); break; - case ID_POPUP_PCB_AUTOROUTE_SELECT_LAYERS: - break; - default: DisplayError( this, wxT( "AutoPlace command error" ) ); break; @@ -165,7 +163,6 @@ void WinEDA_PcbFrame::AutoPlace( wxCommandEvent& event ) GetBoard()->m_Status_Pcb &= ~DO_NOT_SHOW_GENERAL_RASTNEST; Compile_Ratsnest( &dc, true ); - SetToolbars(); } From 7774d684c78fffa45c6323ef601f2e8562f31f2e Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Tue, 17 Aug 2010 12:41:44 +0200 Subject: [PATCH 3/3] Pcbnew: Added move and rotate hot keys in board editor. hotkeys.cpp code cleaned. Fixed a bug that can crashes Pcbnew when switching track posture. --- include/wxPcbStruct.h | 6 +- pcbnew/automove.cpp | 16 +- pcbnew/controle.cpp | 2 +- pcbnew/edit.cpp | 7 +- pcbnew/hotkeys.cpp | 323 ++++++++++++++++++---------------------- pcbnew/hotkeys.h | 2 +- pcbnew/onrightclick.cpp | 21 +-- pcbnew/pcbframe.cpp | 4 +- pcbnew/pcbnew_id.h | 4 +- pcbnew/tool_pcb.cpp | 4 +- 10 files changed, 179 insertions(+), 210 deletions(-) diff --git a/include/wxPcbStruct.h b/include/wxPcbStruct.h index a67e4d51bc..19dfcd781c 100644 --- a/include/wxPcbStruct.h +++ b/include/wxPcbStruct.h @@ -281,18 +281,16 @@ public: * Moves or drag the item (footprint, track, text .. ) found under the mouse cursor * Only a footprint or a track can be dragged * @param aIdCommand = the hotkey command id - * @param aDC = current device context * @return true if an item was moved */ - bool OnHotkeyMoveItem( int aIdCommand, wxDC* aDC ); + bool OnHotkeyMoveItem( int aIdCommand ); /** Function OnHotkeyRotateItem * Rotate the item (text or footprint) found under the mouse cursor * @param aIdCommand = the hotkey command id - * @param aDC = current device context * @return true if an item was moved */ - bool OnHotkeyRotateItem( int aIdCommand, wxDC* aDC ); + bool OnHotkeyRotateItem( int aIdCommand ); void OnCloseWindow( wxCloseEvent& Event ); void Process_Special_Functions( wxCommandEvent& event ); diff --git a/pcbnew/automove.cpp b/pcbnew/automove.cpp index 534ae746d8..e5a75e4a4d 100644 --- a/pcbnew/automove.cpp +++ b/pcbnew/automove.cpp @@ -45,23 +45,23 @@ void WinEDA_PcbFrame::AutoPlace( wxCommandEvent& event ) switch( id ) { - case ID_TOOLBARH_PCB_AUTOPLACE: - on_state = m_HToolBar->GetToolState( ID_TOOLBARH_PCB_AUTOPLACE ); + case ID_TOOLBARH_PCB_MODE_MODULE: + on_state = m_HToolBar->GetToolState( ID_TOOLBARH_PCB_MODE_MODULE ); if( on_state ) { - m_HToolBar->ToggleTool( ID_TOOLBARH_PCB_AUTOROUTE, FALSE ); - m_HTOOL_current_state = ID_TOOLBARH_PCB_AUTOPLACE; + m_HToolBar->ToggleTool( ID_TOOLBARH_PCB_MODE_TRACKS, FALSE ); + m_HTOOL_current_state = ID_TOOLBARH_PCB_MODE_MODULE; } else m_HTOOL_current_state = 0; return; - case ID_TOOLBARH_PCB_AUTOROUTE: - on_state = m_HToolBar->GetToolState( ID_TOOLBARH_PCB_AUTOROUTE ); + case ID_TOOLBARH_PCB_MODE_TRACKS: + on_state = m_HToolBar->GetToolState( ID_TOOLBARH_PCB_MODE_TRACKS ); if( on_state ) { - m_HToolBar->ToggleTool( ID_TOOLBARH_PCB_AUTOPLACE, FALSE ); - m_HTOOL_current_state = ID_TOOLBARH_PCB_AUTOROUTE; + m_HToolBar->ToggleTool( ID_TOOLBARH_PCB_MODE_MODULE, FALSE ); + m_HTOOL_current_state = ID_TOOLBARH_PCB_MODE_TRACKS; } else m_HTOOL_current_state = 0; diff --git a/pcbnew/controle.cpp b/pcbnew/controle.cpp index 7297e467f2..f375134b68 100644 --- a/pcbnew/controle.cpp +++ b/pcbnew/controle.cpp @@ -83,7 +83,7 @@ BOARD_ITEM* WinEDA_BasePcbFrame::PcbGeneralLocateAndDisplay( int aHotKeyCode ) { switch( m_HTOOL_current_state ) { - case ID_TOOLBARH_PCB_AUTOPLACE: + case ID_TOOLBARH_PCB_MODE_MODULE: scanList = GENERAL_COLLECTOR::ModuleItems; break; diff --git a/pcbnew/edit.cpp b/pcbnew/edit.cpp index 8f4b99b1be..8906ab28e7 100644 --- a/pcbnew/edit.cpp +++ b/pcbnew/edit.cpp @@ -348,10 +348,13 @@ void WinEDA_PcbFrame::Process_Special_Functions( wxCommandEvent& event ) case ID_POPUP_PCB_SWITCH_TRACK_POSTURE: /* change the position of initial segment when creating new tracks * switch from _/ to -\ . + * If a track is in progress, it will be redrawn */ - ShowNewTrackWhenMovingCursor( DrawPanel, &dc, false ); + if( DrawPanel->ManageCurseur == ShowNewTrackWhenMovingCursor ) + ShowNewTrackWhenMovingCursor( DrawPanel, &dc, false ); g_Alternate_Track_Posture = !g_Alternate_Track_Posture; - ShowNewTrackWhenMovingCursor( DrawPanel, &dc, false ); + if( DrawPanel->ManageCurseur == ShowNewTrackWhenMovingCursor ) + ShowNewTrackWhenMovingCursor( DrawPanel, &dc, false ); break; case ID_POPUP_PCB_PLACE_MICROVIA: diff --git a/pcbnew/hotkeys.cpp b/pcbnew/hotkeys.cpp index 3fbc36cb78..57525c90e7 100644 --- a/pcbnew/hotkeys.cpp +++ b/pcbnew/hotkeys.cpp @@ -78,7 +78,7 @@ static Ki_HotkeyInfo HkFlipFootprint( wxT( "Flip Footprint" ), HK_FLIP_FOOTPRINT 'F' ); static Ki_HotkeyInfo HkRotateItem( wxT( "Rotate Item" ), HK_ROTATE_ITEM, 'R' ); static Ki_HotkeyInfo HkMoveItem( wxT( "Move Item" ), HK_MOVE_ITEM, 'M' ); -static Ki_HotkeyInfo HkDragFootprint( wxT( "Drag Footprint" ), HK_DRAG_FOOTPRINT_OR_TRACK, +static Ki_HotkeyInfo HkDragFootprint( wxT( "Drag Footprint" ), HK_DRAG_ITEM, 'G' ); static Ki_HotkeyInfo HkGetAndMoveFootprint( wxT( "Get and Move Footprint" ), HK_GET_AND_MOVE_FOOTPRINT, 'T' ); @@ -222,6 +222,7 @@ void WinEDA_PcbFrame::OnHotKey( wxDC* aDC, int aHotkeyCode, EDA_BaseStruct* aIte bool itemCurrentlyEdited = (GetCurItem() && GetCurItem()->m_Flags); MODULE* module = NULL; + int evt_type = 0; //Used to post a wxCommandEvent on demand /* Convert lower to upper case * (the usual toupper function has problem with non ascii codes like function keys @@ -315,33 +316,27 @@ void WinEDA_PcbFrame::OnHotKey( wxDC* aDC, int aHotkeyCode, EDA_BaseStruct* aIte break; case HK_ZOOM_IN: - cmd.SetId( ID_POPUP_ZOOM_IN ); - GetEventHandler()->ProcessEvent( cmd ); + evt_type = ID_POPUP_ZOOM_IN; break; case HK_ZOOM_OUT: - cmd.SetId( ID_POPUP_ZOOM_OUT ); - GetEventHandler()->ProcessEvent( cmd ); + evt_type = ID_POPUP_ZOOM_OUT; break; case HK_ZOOM_REDRAW: - cmd.SetId( ID_ZOOM_REDRAW ); - GetEventHandler()->ProcessEvent( cmd ); - break; - - case HK_ZOOM_CENTER: - cmd.SetId( ID_POPUP_ZOOM_CENTER ); - GetEventHandler()->ProcessEvent( cmd ); - break; - - case HK_ADD_MODULE: - cmd.SetId( ID_COMPONENT_BUTT ); - GetEventHandler()->ProcessEvent( cmd ); + evt_type = ID_ZOOM_REDRAW; break; case HK_ZOOM_AUTO: - cmd.SetId( ID_ZOOM_PAGE ); - GetEventHandler()->ProcessEvent( cmd ); + evt_type = ID_ZOOM_PAGE; + break; + + case HK_ZOOM_CENTER: + evt_type = ID_POPUP_ZOOM_CENTER; + break; + + case HK_ADD_MODULE: + evt_type = ID_COMPONENT_BUTT; break; case HK_UNDO: @@ -374,13 +369,13 @@ void WinEDA_PcbFrame::OnHotKey( wxDC* aDC, int aHotkeyCode, EDA_BaseStruct* aIte break; case HK_BACK_SPACE: - if( m_ID_current_state == ID_TRACK_BUTT && getActiveLayer() - <= LAYER_N_FRONT ) + if( m_ID_current_state == ID_TRACK_BUTT && (getActiveLayer() <= LAYER_N_FRONT) ) { if( !itemCurrentlyEdited ) { // no track is currently being edited - select a segment and remove it. - // @todo: possibly? pass the HK command code to PcbGeneralLocateAndDisplay() so it can restrict its search to specific item types. + // @todo: possibly? pass the HK command code to PcbGeneralLocateAndDisplay() + // so it can restrict its search to specific item types. aItem = PcbGeneralLocateAndDisplay(); // don't let backspace delete modules!! @@ -416,40 +411,22 @@ void WinEDA_PcbFrame::OnHotKey( wxDC* aDC, int aHotkeyCode, EDA_BaseStruct* aIte case HK_GET_AND_MOVE_FOOTPRINT: if( !itemCurrentlyEdited ) - { - wxCommandEvent evt; - evt.SetId( ID_POPUP_PCB_GET_AND_MOVE_MODULE_REQUEST ); - Process_Special_Functions( evt ); - } + evt_type = ID_POPUP_PCB_GET_AND_MOVE_MODULE_REQUEST; break; case HK_FIND_ITEM: if( !itemCurrentlyEdited ) - { - wxCommandEvent evt; - evt.SetId( ID_FIND_ITEMS ); - Process_Special_Functions( evt ); - } + evt_type = ID_FIND_ITEMS; break; case HK_LOAD_BOARD: if( !itemCurrentlyEdited ) - { - // try not to duplicate save, load code etc. - wxCommandEvent evt; - evt.SetId( ID_LOAD_FILE ); - Files_io( evt ); - } + evt_type = ID_LOAD_FILE ; break; case HK_SAVE_BOARD: if( !itemCurrentlyEdited ) - { - // try not to duplicate save, load code etc. - wxCommandEvent evt; - evt.SetId( ID_SAVE_BOARD ); - Files_io( evt ); - } + evt_type = ID_SAVE_BOARD; break; case HK_ADD_MICROVIA: // Place a micro via if a track is in progress @@ -464,14 +441,7 @@ void WinEDA_PcbFrame::OnHotKey( wxDC* aDC, int aHotkeyCode, EDA_BaseStruct* aIte // place micro via and switch layer if( IsMicroViaAcceptable() ) - { - int v_type = GetBoard()->GetBoardDesignSettings()->m_CurrentViaType; - GetBoard()->GetBoardDesignSettings()->m_CurrentViaType = VIA_MICROVIA; - Other_Layer_Route( (TRACK*) GetCurItem(), aDC ); - GetBoard()->GetBoardDesignSettings()->m_CurrentViaType = v_type; - if( DisplayOpt.ContrastModeDisplay ) - DrawPanel->Refresh(); - } + evt_type = ID_POPUP_PCB_PLACE_MICROVIA; break; case HK_ADD_VIA: // Switch to alternate layer and Place a via if a track is in progress @@ -486,19 +456,14 @@ void WinEDA_PcbFrame::OnHotKey( wxDC* aDC, int aHotkeyCode, EDA_BaseStruct* aIte return; if( (GetCurItem()->m_Flags & IS_NEW) == 0 ) return; - Other_Layer_Route( (TRACK*) GetCurItem(), aDC ); // place via and switch layer - if( DisplayOpt.ContrastModeDisplay ) - DrawPanel->Refresh(); + evt_type = ID_POPUP_PCB_PLACE_VIA; break; case HK_SWITCH_TRACK_POSTURE: - /* change the position of initial segment when creating new tracks * switch from _/ to -\ . */ - ShowNewTrackWhenMovingCursor( DrawPanel, aDC, false ); - g_Alternate_Track_Posture = !g_Alternate_Track_Posture; - ShowNewTrackWhenMovingCursor( DrawPanel, aDC, false ); + evt_type = ID_POPUP_PCB_SWITCH_TRACK_POSTURE ; break; case HK_ADD_NEW_TRACK: // Start new track @@ -561,22 +526,30 @@ void WinEDA_PcbFrame::OnHotKey( wxDC* aDC, int aHotkeyCode, EDA_BaseStruct* aIte } break; - case HK_DRAG_FOOTPRINT_OR_TRACK: // Start drag module or track segment - OnHotkeyMoveItem( HK_DRAG_FOOTPRINT_OR_TRACK, aDC ); + case HK_DRAG_ITEM: // Start drag module or track segment + OnHotkeyMoveItem( HK_DRAG_ITEM ); break; case HK_MOVE_ITEM: // Start move item - OnHotkeyMoveItem( HK_MOVE_ITEM, aDC ); + OnHotkeyMoveItem( HK_MOVE_ITEM ); break; case HK_ROTATE_ITEM: // Rotation - OnHotkeyRotateItem( HK_ROTATE_ITEM, aDC ); + OnHotkeyRotateItem( HK_ROTATE_ITEM ); break; case HK_FLIP_FOOTPRINT: // move to other side - OnHotkeyRotateItem( HK_FLIP_FOOTPRINT, aDC ); + OnHotkeyRotateItem( HK_FLIP_FOOTPRINT ); break; } + + if( evt_type != 0 ) + { + wxCommandEvent evt( wxEVT_COMMAND_MENU_SELECTED ); + evt.SetEventObject( this ); + evt.SetId( evt_type ); + wxPostEvent( this, evt ); + } } @@ -592,7 +565,8 @@ void WinEDA_ModuleEditFrame::OnHotKey( wxDC* aDC, int hotkey, if( hotkey == 0 ) return; - bool ItemFree = (GetCurItem() == 0 || GetCurItem()->m_Flags == 0); + BOARD_ITEM* item = GetCurItem(); + bool ItemFree = (item == 0) || (item->m_Flags == 0); wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED ); cmd.SetEventObject( this ); @@ -678,7 +652,8 @@ void WinEDA_ModuleEditFrame::OnHotKey( wxDC* aDC, int hotkey, */ bool WinEDA_PcbFrame::OnHotkeyDeleteItem( wxDC* aDC ) { - bool ItemFree = (GetCurItem() == NULL) || (GetCurItem()->m_Flags == 0); + BOARD_ITEM* item = GetCurItem(); + bool ItemFree = (item == NULL) || (item->m_Flags == 0); switch( m_ID_current_state ) { @@ -687,15 +662,15 @@ bool WinEDA_PcbFrame::OnHotkeyDeleteItem( wxDC* aDC ) return false; if( ItemFree ) { - BOARD_ITEM* DrawStruct = PcbGeneralLocateAndDisplay(); - if( DrawStruct && DrawStruct->Type() != TYPE_TRACK ) + item = PcbGeneralLocateAndDisplay(); + if( item && item->Type() != TYPE_TRACK ) return false; - Delete_Track( aDC, (TRACK*) DrawStruct ); + Delete_Track( aDC, (TRACK*) item ); } - else if( GetCurItem()->Type() == TYPE_TRACK ) + else if( item->Type() == TYPE_TRACK ) { // simple lines for debugger: - TRACK* track = (TRACK*) GetCurItem(); + TRACK* track = (TRACK*) item; track = Delete_Segment( aDC, track ); SetCurItem( track ); OnModify(); @@ -729,59 +704,37 @@ bool WinEDA_PcbFrame::OnHotkeyDeleteItem( wxDC* aDC ) /** Function OnHotkeyMoveItem - * Moves or drag the item (footprint, track, text .. ) found under the mouse cursor - * Only a footprint or a track can be dragged + * Move or drag the item (footprint, track, text .. ) found under the mouse cursor + * An item can be moved (or dragged) only if there is no item currently edited + * Only a footprint, a pad or a track can be dragged * @param aIdCommand = the hotkey command id - * @param aDC = current device context * @return true if an item was moved */ -bool WinEDA_PcbFrame::OnHotkeyMoveItem( int aIdCommand, wxDC* aDC ) +bool WinEDA_PcbFrame::OnHotkeyMoveItem( int aIdCommand ) { - bool itemCurrentlyEdited = (GetCurItem() && GetCurItem()->m_Flags); + BOARD_ITEM* item = GetCurItem(); + bool itemCurrentlyEdited = item && item->m_Flags; if( itemCurrentlyEdited ) return false; - BOARD_ITEM* item = NULL; - - if( m_ID_current_state == ID_COMPONENT_BUTT ) - { - item = Locate_Prefered_Module( GetBoard(), CURSEUR_OFF_GRILLE - | IGNORE_LOCKED | VISIBLE_ONLY - #if defined(USE_MATCH_LAYER) - | MATCH_LAYER - #endif - ); - - if( item == NULL ) // no footprint found - item = Locate_Prefered_Module( GetBoard(), - CURSEUR_OFF_GRILLE | VISIBLE_ONLY ); - } - if( item == NULL ) - item = PcbGeneralLocateAndDisplay(); + item = PcbGeneralLocateAndDisplay(); if( item == NULL ) return false; SetCurItem( item ); + int evt_type = 0; //Used to post a wxCommandEvent on demand + switch( item->Type() ) { case TYPE_TRACK: case TYPE_VIA: if( aIdCommand == HK_MOVE_ITEM ) - { - Start_MoveOneNodeOrSegment( (TRACK*) item, aDC, - ID_POPUP_PCB_MOVE_TRACK_NODE ); - return true; - } - if( aIdCommand == HK_DRAG_FOOTPRINT_OR_TRACK ) - { - //Start_DragTrackSegmentAndKeepSlope( (TRACK*) DrawStruct, aDC ); - Start_MoveOneNodeOrSegment( (TRACK*) item, aDC, - ID_POPUP_PCB_DRAG_TRACK_SEGMENT ); - return true; - } + evt_type = ID_POPUP_PCB_MOVE_TRACK_NODE; + if( aIdCommand == HK_DRAG_ITEM ) + evt_type = ID_POPUP_PCB_DRAG_TRACK_SEGMENT; break; case TYPE_MODULE: @@ -797,107 +750,119 @@ bool WinEDA_PcbFrame::OnHotkeyMoveItem( int aIdCommand, wxDC* aDC ) DisplayInfoMessage( this, msg ); break; } - - // Send the module via socket to EESCHEMA's search facility. - SendMessageToEESCHEMA( module ); - - // Start move module - GetScreen()->m_Curseur = module->m_Pos; - DrawPanel->MouseToCursorSchema(); - if( aIdCommand == HK_DRAG_FOOTPRINT_OR_TRACK ) - g_Drag_Pistes_On = true; - - StartMove_Module( module, aDC ); + if( aIdCommand == HK_MOVE_ITEM ) + evt_type = ID_POPUP_PCB_MOVE_MODULE_REQUEST; + if( aIdCommand == HK_DRAG_ITEM ) + evt_type = ID_POPUP_PCB_DRAG_MODULE_REQUEST; } - return true; + break; + + case TYPE_PAD: + if( aIdCommand == HK_MOVE_ITEM ) + evt_type = ID_POPUP_PCB_MOVE_PAD_REQUEST; + if( aIdCommand == HK_DRAG_ITEM ) + evt_type = ID_POPUP_PCB_DRAG_PAD_REQUEST; + break; + + case TYPE_TEXTE: + evt_type = ID_POPUP_PCB_MOVE_TEXTEPCB_REQUEST; + break; + + case TYPE_MIRE: + evt_type = ID_POPUP_PCB_MOVE_MIRE_REQUEST; + break; + + case TYPE_ZONE_CONTAINER: + evt_type = ID_POPUP_PCB_MOVE_ZONE_OUTLINES; + break; + + case TYPE_TEXTE_MODULE: + evt_type = ID_POPUP_PCB_MOVE_TEXTMODULE_REQUEST; + break; + + case TYPE_DRAWSEGMENT: + evt_type = ID_POPUP_PCB_MOVE_DRAWING_REQUEST; + break; default: break; } + if( evt_type != 0 ) + { + wxCommandEvent evt( wxEVT_COMMAND_MENU_SELECTED ); + evt.SetEventObject( this ); + evt.SetId( evt_type ); + wxPostEvent( this, evt ); + return true; + } + return false; } /** Function OnHotkeyRotateItem * Rotate the item (text or footprint) found under the mouse cursor + * Note: + * this command can be used with an item currently in edit + * Only some items can be rotated (footprints and texts) * @param aIdCommand = the hotkey command id - * @param aDC = current device context * @return true if an item was moved */ -bool WinEDA_PcbFrame::OnHotkeyRotateItem( int aIdCommand, wxDC* aDC ) +bool WinEDA_PcbFrame::OnHotkeyRotateItem( int aIdCommand ) { - bool itemCurrentlyEdited = (GetCurItem() && GetCurItem()->m_Flags); - - MODULE* module = NULL; + BOARD_ITEM* item = GetCurItem(); + bool itemCurrentlyEdited = item && item->m_Flags; + int evt_type = 0; // Used to post a wxCommandEvent on demand if( !itemCurrentlyEdited ) - { - module = Locate_Prefered_Module( GetBoard(), CURSEUR_OFF_GRILLE - | IGNORE_LOCKED | VISIBLE_ONLY -#if defined(USE_MATCH_LAYER) - | MATCH_LAYER -#endif - ); + item = PcbGeneralLocateAndDisplay(); - if( module == NULL ) // no footprint found - { - module = Locate_Prefered_Module( GetBoard(), - CURSEUR_OFF_GRILLE | VISIBLE_ONLY ); - if( module ) - { - // a footprint is found, but locked or on an other layer - if( module->IsLocked() ) - { - wxString msg; - msg.Printf( _( "Footprint %s found, but locked" ), - module->m_Reference->m_Text.GetData() ); - DisplayInfoMessage( this, msg ); - } - module = NULL; - } - } - } - else if( GetCurItem()->Type() == TYPE_MODULE ) - { - module = (MODULE*) GetCurItem(); - - // @todo: might need to add a layer check in if() below - if( (GetCurItem()->m_Flags == 0) && module->IsLocked() ) - module = NULL; // do not move, rotate ... it. - } - if( module == NULL ) + if( item == NULL ) return false; - /* I'd like to make sending to EESCHEMA edge triggered, but the - * simple mouse click on a module when the arrow icon is in play - * does not set GetCurItem() at this time, nor does a mouse click - * when the local ratsnest icon is in play set GetCurItem(), and these - * actions also call SendMessageToEESCHEMA(). - * if( GetCurItem() != module ) - */ - { - // Send the module via socket to EESCHEMA's search facility. - SendMessageToEESCHEMA( module ); - SetCurItem( module ); - } + SetCurItem( item ); - switch( aIdCommand ) + switch( item->Type() ) { - case HK_ROTATE_ITEM: // Rotation - if( module->m_Flags == 0 ) // not currently in edit, prepare undo command - SaveCopyInUndoList( module, UR_ROTATED, module->m_Pos ); - Rotate_Module( aDC, module, 900, true ); + case TYPE_MODULE: + { + MODULE* module = (MODULE*) item; + if( module->IsLocked() ) + { + wxString msg; + msg.Printf( _( "Footprint %s is locked" ), + module->m_Reference->m_Text.GetData() ); + DisplayInfoMessage( this, msg ); + break; + } + if( aIdCommand == HK_ROTATE_ITEM ) // Rotation + evt_type = ID_POPUP_PCB_ROTATE_MODULE_COUNTERCLOCKWISE; + if( aIdCommand == HK_FLIP_FOOTPRINT ) // move to other side + evt_type = ID_POPUP_PCB_CHANGE_SIDE_MODULE; + } break; - case HK_FLIP_FOOTPRINT: // move to other side - if( module->m_Flags == 0 ) // not currently in edit, prepare undo command - SaveCopyInUndoList( module, UR_FLIPPED, module->m_Pos ); - Change_Side_Module( module, aDC ); + case TYPE_TEXTE: + evt_type = ID_POPUP_PCB_ROTATE_TEXTEPCB; + break; + + case TYPE_TEXTE_MODULE: + evt_type = ID_POPUP_PCB_ROTATE_TEXTMODULE; + break; + + default: break; } - module->DisplayInfo( this ); + if( evt_type != 0 ) + { + wxCommandEvent evt( wxEVT_COMMAND_MENU_SELECTED ); + evt.SetEventObject( this ); + evt.SetId( evt_type ); + wxPostEvent( this, evt ); + return true; + } - return true; + return false; } diff --git a/pcbnew/hotkeys.h b/pcbnew/hotkeys.h index 4888f3f058..ccbe7a352d 100644 --- a/pcbnew/hotkeys.h +++ b/pcbnew/hotkeys.h @@ -15,7 +15,7 @@ enum hotkey_id_commnand { HK_BACK_SPACE, HK_ROTATE_ITEM, HK_MOVE_ITEM, - HK_DRAG_FOOTPRINT_OR_TRACK, + HK_DRAG_ITEM, HK_FLIP_FOOTPRINT, HK_GET_AND_MOVE_FOOTPRINT, HK_LOCK_UNLOCK_FOOTPRINT, diff --git a/pcbnew/onrightclick.cpp b/pcbnew/onrightclick.cpp index 613d5933df..599507cf94 100644 --- a/pcbnew/onrightclick.cpp +++ b/pcbnew/onrightclick.cpp @@ -120,7 +120,7 @@ bool WinEDA_PcbFrame::OnRightClick( const wxPoint& aMousePos, wxMenu* aPopMenu ) case TYPE_MODULE: createPopUpMenuForFootprints( (MODULE*) item, aPopMenu ); - if( m_HTOOL_current_state == ID_TOOLBARH_PCB_AUTOPLACE ) + if( m_HTOOL_current_state == ID_TOOLBARH_PCB_MODE_MODULE ) { aPopMenu->AppendSeparator(); @@ -146,7 +146,7 @@ bool WinEDA_PcbFrame::OnRightClick( const wxPoint& aMousePos, wxMenu* aPopMenu ) _( "Auto Place Module" ) ); } - if( m_HTOOL_current_state == ID_TOOLBARH_PCB_AUTOROUTE ) + if( m_HTOOL_current_state == ID_TOOLBARH_PCB_MODE_TRACKS ) { if( !flags ) aPopMenu->Append( ID_POPUP_PCB_AUTOROUTE_MODULE, _( "Autoroute Module" ) ); @@ -318,7 +318,7 @@ bool WinEDA_PcbFrame::OnRightClick( const wxPoint& aMousePos, wxMenu* aPopMenu ) break; case 0: - if( m_HTOOL_current_state == ID_TOOLBARH_PCB_AUTOPLACE ) + if( m_HTOOL_current_state == ID_TOOLBARH_PCB_MODE_MODULE ) { wxMenu* commands = new wxMenu; ADD_MENUITEM_WITH_SUBMENU( aPopMenu, commands, @@ -342,7 +342,7 @@ bool WinEDA_PcbFrame::OnRightClick( const wxPoint& aMousePos, wxMenu* aPopMenu ) aPopMenu->AppendSeparator(); } - if( m_HTOOL_current_state == ID_TOOLBARH_PCB_AUTOROUTE ) + if( m_HTOOL_current_state == ID_TOOLBARH_PCB_MODE_TRACKS ) { wxMenu* commands = new wxMenu; aPopMenu->Append( ID_POPUP_PCB_AUTOROUTE_COMMANDS, _( "Autoroute" ), commands ); @@ -641,7 +641,7 @@ void WinEDA_PcbFrame::createPopUpMenuForFootprints( MODULE* aModule, wxMenu* men msg = AddHotkeyName( _( "Move" ), s_Board_Editor_Hokeys_Descr, HK_MOVE_ITEM ); ADD_MENUITEM( sub_menu_footprint, ID_POPUP_PCB_MOVE_MODULE_REQUEST, msg, move_module_xpm ); - msg = AddHotkeyName( _( "Drag" ), s_Board_Editor_Hokeys_Descr, HK_DRAG_FOOTPRINT_OR_TRACK ); + msg = AddHotkeyName( _( "Drag" ), s_Board_Editor_Hokeys_Descr, HK_DRAG_ITEM ); ADD_MENUITEM( sub_menu_footprint, ID_POPUP_PCB_DRAG_MODULE_REQUEST, msg, drag_module_xpm ); } @@ -689,8 +689,9 @@ void WinEDA_PcbFrame::createPopUpMenuForFpTexts( TEXTE_MODULE* FpText, wxMenu* m msg, move_field_xpm ); } + msg = AddHotkeyName( _( "Rotate" ), s_Board_Editor_Hokeys_Descr, HK_ROTATE_ITEM ); ADD_MENUITEM( sub_menu_Fp_text, ID_POPUP_PCB_ROTATE_TEXTMODULE, - _( "Rotate" ), rotate_field_xpm ); + msg, rotate_field_xpm ); if( !flags ) { msg = AddHotkeyName( _( "Edit" ), s_Board_Editor_Hokeys_Descr, HK_EDIT_ITEM ); @@ -742,8 +743,9 @@ void WinEDA_PcbFrame::createPopUpMenuForFpPads( D_PAD* Pad, wxMenu* menu ) msg = AddHotkeyName( _( "Move" ), s_Board_Editor_Hokeys_Descr, HK_MOVE_ITEM ); ADD_MENUITEM( sub_menu_Pad, ID_POPUP_PCB_MOVE_PAD_REQUEST, msg, move_pad_xpm ); + msg = AddHotkeyName( _( "Drag" ), s_Board_Editor_Hokeys_Descr, HK_DRAG_ITEM ); ADD_MENUITEM( sub_menu_Pad, ID_POPUP_PCB_DRAG_PAD_REQUEST, - _( "Drag" ), drag_pad_xpm ); + msg, drag_pad_xpm ); msg = AddHotkeyName( _( "Edit Pad" ), s_Board_Editor_Hokeys_Descr, HK_EDIT_ITEM ); ADD_MENUITEM( sub_menu_Pad, ID_POPUP_PCB_EDIT_PAD, msg, options_pad_xpm ); @@ -767,7 +769,7 @@ void WinEDA_PcbFrame::createPopUpMenuForFpPads( D_PAD* Pad, wxMenu* menu ) ADD_MENUITEM( sub_menu_Pad, ID_POPUP_PCB_DELETE_PAD, _( "Delete" ), delete_pad_xpm ); - if( m_HTOOL_current_state == ID_TOOLBARH_PCB_AUTOROUTE ) + if( m_HTOOL_current_state == ID_TOOLBARH_PCB_MODE_TRACKS ) { menu->Append( ID_POPUP_PCB_AUTOROUTE_PAD, _( "Autoroute Pad" ) ); menu->Append( ID_POPUP_PCB_AUTOROUTE_NET, _( "Autoroute Net" ) ); @@ -801,8 +803,9 @@ void WinEDA_PcbFrame::createPopUpMenuForTexts( TEXTE_PCB* Text, wxMenu* menu ) ADD_MENUITEM( sub_menu_Text, ID_POPUP_PCB_MOVE_TEXTEPCB_REQUEST, msg, move_text_xpm ); } + msg = AddHotkeyName( _( "Rotate" ), s_Board_Editor_Hokeys_Descr, HK_ROTATE_ITEM ); ADD_MENUITEM( sub_menu_Text, ID_POPUP_PCB_ROTATE_TEXTEPCB, - _( "Rotate" ), rotate_pos_xpm ); + msg, rotate_pos_xpm ); msg = AddHotkeyName( _( "Edit" ), s_Board_Editor_Hokeys_Descr, HK_EDIT_ITEM ); ADD_MENUITEM( sub_menu_Text, ID_POPUP_PCB_EDIT_TEXTEPCB, msg, edit_text_xpm ); diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index 16493ca265..1039fb7c60 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -183,8 +183,8 @@ BEGIN_EVENT_TABLE( WinEDA_PcbFrame, WinEDA_BasePcbFrame ) WinEDA_PcbFrame::Tracks_and_Vias_Size_Event ) EVT_KICAD_CHOICEBOX( ID_AUX_TOOLBAR_PCB_VIA_SIZE, WinEDA_PcbFrame::Tracks_and_Vias_Size_Event ) - EVT_TOOL( ID_TOOLBARH_PCB_AUTOPLACE, WinEDA_PcbFrame::AutoPlace ) - EVT_TOOL( ID_TOOLBARH_PCB_AUTOROUTE, WinEDA_PcbFrame::AutoPlace ) + EVT_TOOL( ID_TOOLBARH_PCB_MODE_MODULE, WinEDA_PcbFrame::AutoPlace ) + EVT_TOOL( ID_TOOLBARH_PCB_MODE_TRACKS, WinEDA_PcbFrame::AutoPlace ) EVT_TOOL( ID_TOOLBARH_PCB_FREEROUTE_ACCESS, WinEDA_PcbFrame::Access_to_External_Tool ) diff --git a/pcbnew/pcbnew_id.h b/pcbnew/pcbnew_id.h index 75c76db69c..df87fa3c12 100644 --- a/pcbnew/pcbnew_id.h +++ b/pcbnew/pcbnew_id.h @@ -215,8 +215,8 @@ enum pcbnew_ids ID_MENU_PCB_SWAP_LAYERS, ID_GEN_EXPORT_FILE_VRML, - ID_TOOLBARH_PCB_AUTOPLACE, - ID_TOOLBARH_PCB_AUTOROUTE, + ID_TOOLBARH_PCB_MODE_MODULE, + ID_TOOLBARH_PCB_MODE_TRACKS, ID_TOOLBARH_PCB_FREEROUTE_ACCESS, ID_AUX_TOOLBAR_PCB_SELECT_LAYER_PAIR, diff --git a/pcbnew/tool_pcb.cpp b/pcbnew/tool_pcb.cpp index e049b9af5d..68d318dbc2 100644 --- a/pcbnew/tool_pcb.cpp +++ b/pcbnew/tool_pcb.cpp @@ -274,11 +274,11 @@ void WinEDA_PcbFrame::ReCreateHToolbar() *LayerPairBitmap, SEL_LAYER_HELP ); m_HToolBar->AddSeparator(); - m_HToolBar->AddTool( ID_TOOLBARH_PCB_AUTOPLACE, wxEmptyString, + m_HToolBar->AddTool( ID_TOOLBARH_PCB_MODE_MODULE, wxEmptyString, wxBitmap( mode_module_xpm ), _( "Mode footprint: manual and automatic move and place modules" ), wxITEM_CHECK ); - m_HToolBar->AddTool( ID_TOOLBARH_PCB_AUTOROUTE, wxEmptyString, + m_HToolBar->AddTool( ID_TOOLBARH_PCB_MODE_TRACKS, wxEmptyString, wxBitmap( mode_track_xpm ), _( "Mode track: autorouting" ), wxITEM_CHECK );