From b7c5649463a628d48674f553735648e077124246 Mon Sep 17 00:00:00 2001 From: Marco Mattila Date: Wed, 4 Jul 2012 22:50:47 +0300 Subject: [PATCH] Add copy to text items in pcbnew. Automatically mirror text items added to back silkscreen (bug 1017446). --- include/wxPcbStruct.h | 11 ++++- pcbnew/edit.cpp | 8 +++ pcbnew/edit_pcb_text.cpp | 87 +++++++++++++++++---------------- pcbnew/hotkeys.cpp | 3 +- pcbnew/hotkeys.h | 1 + pcbnew/hotkeys_board_editor.cpp | 38 +++++++++++++- pcbnew/onleftclick.cpp | 2 +- pcbnew/onrightclick.cpp | 16 ++++-- pcbnew/pcbnew_id.h | 1 + 9 files changed, 115 insertions(+), 52 deletions(-) diff --git a/include/wxPcbStruct.h b/include/wxPcbStruct.h index 99867a7a33..e6ba96a238 100644 --- a/include/wxPcbStruct.h +++ b/include/wxPcbStruct.h @@ -439,6 +439,13 @@ public: bool OnHotkeyEditItem( int aIdCommand ); + /** + * Function OnHotkeyCopyItem + * returns the copy event id for copyable items. + * @return Event id of a suitable copy event, zero when no copyable item found. + */ + int OnHotkeyCopyItem(); + /** * Function OnHotkeyMoveItem * Moves or drag the item (footprint, track, text .. ) found under the mouse cursor @@ -911,9 +918,9 @@ public: // Handling texts on the board void Rotate_Texte_Pcb( TEXTE_PCB* TextePcb, wxDC* DC ); void FlipTextePcb( TEXTE_PCB* aTextePcb, wxDC* aDC ); - TEXTE_PCB* Create_Texte_Pcb( wxDC* DC ); + TEXTE_PCB* CreateTextePcb( wxDC* aDC, TEXTE_PCB* aText = NULL ); void Delete_Texte_Pcb( TEXTE_PCB* TextePcb, wxDC* DC ); - void StartMoveTextePcb( TEXTE_PCB* TextePcb, wxDC* DC ); + void StartMoveTextePcb( TEXTE_PCB* aTextePcb, wxDC* aDC, bool aErase = true ); void Place_Texte_Pcb( TEXTE_PCB* TextePcb, wxDC* DC ); void InstallTextPCBOptionsFrame( TEXTE_PCB* TextPCB, wxDC* DC ); diff --git a/pcbnew/edit.cpp b/pcbnew/edit.cpp index 194d94b742..fa57f44f08 100644 --- a/pcbnew/edit.cpp +++ b/pcbnew/edit.cpp @@ -48,6 +48,7 @@ #include #include #include +#include #include #include @@ -83,6 +84,7 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) case ID_AUX_TOOLBAR_PCB_SELECT_LAYER_PAIR: case ID_POPUP_PCB_ROTATE_TEXTEPCB: case ID_POPUP_PCB_FLIP_TEXTEPCB: + case ID_POPUP_PCB_COPY_TEXTEPCB: case ID_POPUP_PCB_EDIT_TEXTEPCB: case ID_POPUP_PCB_EDIT_MIRE: case ID_POPUP_PCB_ROTATE_TEXTMODULE: @@ -939,6 +941,12 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) m_canvas->MoveCursorToCrossHair(); break; + case ID_POPUP_PCB_COPY_TEXTEPCB: + CreateTextePcb( &dc, (TEXTE_PCB*) GetCurItem() ); + m_canvas->MoveCursorToCrossHair(); + m_canvas->SetAutoPanRequest( true ); + break; + case ID_POPUP_PCB_FLIP_TEXTEPCB: FlipTextePcb( (TEXTE_PCB*) GetCurItem(), &dc ); m_canvas->MoveCursorToCrossHair(); diff --git a/pcbnew/edit_pcb_text.cpp b/pcbnew/edit_pcb_text.cpp index c04f6556fa..25ef6f389f 100644 --- a/pcbnew/edit_pcb_text.cpp +++ b/pcbnew/edit_pcb_text.cpp @@ -76,7 +76,7 @@ void Abort_Edit_Pcb_Text( EDA_DRAW_PANEL* Panel, wxDC* DC ) } - SwapData(TextePcb, &s_TextCopy); + SwapData( TextePcb, &s_TextCopy ); TextePcb->ClearFlags(); TextePcb->Draw( Panel, DC, GR_OR ); } @@ -110,10 +110,10 @@ void PCB_EDIT_FRAME::Place_Texte_Pcb( TEXTE_PCB* TextePcb, wxDC* DC ) else { // Restore initial params - SwapData( TextePcb, &s_TextCopy); + SwapData( TextePcb, &s_TextCopy ); // Prepare undo command SaveCopyInUndoList( TextePcb, UR_CHANGED ); - SwapData( TextePcb, &s_TextCopy); + SwapData( TextePcb, &s_TextCopy ); // Restore current params } @@ -121,27 +121,24 @@ void PCB_EDIT_FRAME::Place_Texte_Pcb( TEXTE_PCB* TextePcb, wxDC* DC ) } -/* Initialize parameters to move a pcb text - */ -void PCB_EDIT_FRAME::StartMoveTextePcb( TEXTE_PCB* TextePcb, wxDC* DC ) +void PCB_EDIT_FRAME::StartMoveTextePcb( TEXTE_PCB* aTextePcb, wxDC* aDC, bool aErase ) { - if( TextePcb == NULL ) + if( aTextePcb == NULL ) return; // if it is an existing item: prepare a copy to undo/abort command - if( !TextePcb->IsNew() ) - s_TextCopy.Copy( TextePcb ); + if( !aTextePcb->IsNew() ) + s_TextCopy.Copy( aTextePcb ); - TextePcb->Draw( m_canvas, DC, GR_XOR ); - TextePcb->SetFlags( IS_MOVED ); - TextePcb->DisplayInfo( this ); + aTextePcb->SetFlags( IS_MOVED ); + aTextePcb->DisplayInfo( this ); - GetScreen()->SetCrossHairPosition( TextePcb->GetPosition() ); + GetScreen()->SetCrossHairPosition( aTextePcb->GetPosition() ); m_canvas->MoveCursorToCrossHair(); m_canvas->SetMouseCapture( Move_Texte_Pcb, Abort_Edit_Pcb_Text ); - SetCurItem( TextePcb ); - m_canvas->CallMouseCapture( DC, wxDefaultPosition, false ); + SetCurItem( aTextePcb ); + m_canvas->CallMouseCapture( aDC, wxDefaultPosition, aErase ); } @@ -157,7 +154,7 @@ static void Move_Texte_Pcb( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aP if( aErase ) TextePcb->Draw( aPanel, aDC, GR_XOR ); - TextePcb->m_Pos = aPanel->GetScreen()->GetCrossHairPosition(); + TextePcb->SetPosition( aPanel->GetScreen()->GetCrossHairPosition() ); TextePcb->Draw( aPanel, aDC, GR_XOR ); } @@ -177,40 +174,46 @@ void PCB_EDIT_FRAME::Delete_Texte_Pcb( TEXTE_PCB* TextePcb, wxDC* DC ) } -TEXTE_PCB* PCB_EDIT_FRAME::Create_Texte_Pcb( wxDC* DC ) +TEXTE_PCB* PCB_EDIT_FRAME::CreateTextePcb( wxDC* aDC, TEXTE_PCB* aText ) { - TEXTE_PCB* TextePcb; + TEXTE_PCB* textePcb = new TEXTE_PCB( GetBoard() ); - TextePcb = new TEXTE_PCB( GetBoard() ); - - /* Add text to the board item list. */ - GetBoard()->Add( TextePcb ); - - /* Update text properties. */ - TextePcb->SetFlags( IS_NEW ); - TextePcb->SetLayer( ( (PCB_SCREEN*) GetScreen() )->m_Active_Layer ); - TextePcb->m_Mirror = false; - - if( TextePcb->GetLayer() == LAYER_N_BACK ) - TextePcb->m_Mirror = true; - - TextePcb->m_Size = GetBoard()->GetDesignSettings().m_PcbTextSize; - TextePcb->m_Pos = GetScreen()->GetCrossHairPosition(); - TextePcb->m_Thickness = GetBoard()->GetDesignSettings().m_PcbTextWidth; - - InstallTextPCBOptionsFrame( TextePcb, DC ); - - if( TextePcb->m_Text.IsEmpty() ) + if( aText ) { - TextePcb->DeleteStructure(); - TextePcb = NULL; + textePcb->Copy( aText ); + GetBoard()->Add( textePcb ); + textePcb->SetFlags( IS_NEW ); + StartMoveTextePcb( textePcb, aDC, false ); // Don't erase aText when copying } else { - StartMoveTextePcb( TextePcb, DC ); + GetBoard()->Add( textePcb ); + textePcb->SetFlags( IS_NEW ); + int layer = ( (PCB_SCREEN*) GetScreen() )->m_Active_Layer; + textePcb->SetLayer( layer ); + + if( layer == LAYER_N_BACK + || layer == SILKSCREEN_N_BACK ) + textePcb->SetMirrored( true ); + + textePcb->SetSize( GetBoard()->GetDesignSettings().m_PcbTextSize ); + textePcb->SetPosition( GetScreen()->GetCrossHairPosition() ); + textePcb->SetThickness( GetBoard()->GetDesignSettings().m_PcbTextWidth ); + + InstallTextPCBOptionsFrame( textePcb, aDC ); + + if( textePcb->GetText().IsEmpty() ) + { + textePcb->DeleteStructure(); + textePcb = NULL; + } + else + { + StartMoveTextePcb( textePcb, aDC ); + } } - return TextePcb; + return textePcb; } diff --git a/pcbnew/hotkeys.cpp b/pcbnew/hotkeys.cpp index bc64a74db8..df174ba838 100644 --- a/pcbnew/hotkeys.cpp +++ b/pcbnew/hotkeys.cpp @@ -70,6 +70,7 @@ static EDA_HOTKEY HkEditBoardItem( wxT( "Edit Item" ), HK_EDIT_ITEM, 'E' ); static EDA_HOTKEY HkFlipItem( wxT( "Flip Item" ), HK_FLIP_ITEM, 'F' ); static EDA_HOTKEY HkRotateItem( wxT( "Rotate Item" ), HK_ROTATE_ITEM, 'R' ); static EDA_HOTKEY HkMoveItem( wxT( "Move Item" ), HK_MOVE_ITEM, 'M' ); +static EDA_HOTKEY HkCopyItem( wxT( "Copy Item" ), HK_COPY_ITEM, 'C' ); static EDA_HOTKEY HkDragFootprint( wxT( "Drag Footprint" ), HK_DRAG_ITEM, 'G' ); static EDA_HOTKEY HkGetAndMoveFootprint( wxT( "Get and Move Footprint" ), HK_GET_AND_MOVE_FOOTPRINT, 'T' ); @@ -209,7 +210,7 @@ EDA_HOTKEY* board_edit_Hotkey_List[] = &HkAddNewTrack, &HkAddVia, &HkAddMicroVia, &HkSwitchTrackPosture, &HkDragTrackKeepSlope, - &HkPlaceItem, + &HkPlaceItem, &HkCopyItem, &HkEndTrack, &HkMoveItem, &HkFlipItem, &HkRotateItem, &HkDragFootprint, &HkGetAndMoveFootprint, &HkLock_Unlock_Footprint, &HkSavefile, diff --git a/pcbnew/hotkeys.h b/pcbnew/hotkeys.h index c6f4413f44..8fd8506588 100644 --- a/pcbnew/hotkeys.h +++ b/pcbnew/hotkeys.h @@ -15,6 +15,7 @@ enum hotkey_id_commnand { HK_BACK_SPACE, HK_ROTATE_ITEM, HK_FLIP_ITEM, + HK_COPY_ITEM, HK_MOVE_ITEM, HK_DRAG_ITEM, HK_GET_AND_MOVE_FOOTPRINT, diff --git a/pcbnew/hotkeys_board_editor.cpp b/pcbnew/hotkeys_board_editor.cpp index 4b71934430..416507b60c 100644 --- a/pcbnew/hotkeys_board_editor.cpp +++ b/pcbnew/hotkeys_board_editor.cpp @@ -620,6 +620,10 @@ void PCB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosit OnHotkeyMoveItem( HK_MOVE_ITEM ); break; + case HK_COPY_ITEM: + evt_type = OnHotkeyCopyItem(); + break; + case HK_ROTATE_ITEM: // Rotation OnHotkeyRotateItem( HK_ROTATE_ITEM ); break; @@ -631,7 +635,7 @@ void PCB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosit case HK_SWITCH_HIGHCONTRAST_MODE: // switch to high contrast mode and refresh the canvas DisplayOpt.ContrastModeDisplay = !DisplayOpt.ContrastModeDisplay; m_canvas->Refresh(); - break; + break; } if( evt_type != 0 ) @@ -715,6 +719,7 @@ bool PCB_EDIT_FRAME::OnHotkeyDeleteItem( wxDC* aDC ) return true; } + bool PCB_EDIT_FRAME::OnHotkeyEditItem( int aIdCommand ) { BOARD_ITEM* item = GetCurItem(); @@ -810,6 +815,37 @@ bool PCB_EDIT_FRAME::OnHotkeyEditItem( int aIdCommand ) } +int PCB_EDIT_FRAME::OnHotkeyCopyItem() +{ + BOARD_ITEM* item = GetCurItem(); + bool itemCurrentlyEdited = item && item->GetFlags(); + + if( itemCurrentlyEdited ) + return 0; + + item = PcbGeneralLocateAndDisplay(); + + if( item == NULL ) + return 0; + + SetCurItem( item ); + + int eventId = 0; + + switch( item->Type() ) + { + case PCB_TEXT_T: + eventId = ID_POPUP_PCB_COPY_TEXTEPCB; + break; + default: + eventId = 0; + break; + } + + return eventId; +} + + bool PCB_EDIT_FRAME::OnHotkeyMoveItem( int aIdCommand ) { BOARD_ITEM* item = GetCurItem(); diff --git a/pcbnew/onleftclick.cpp b/pcbnew/onleftclick.cpp index 15b8e1f5ea..f037e987b2 100644 --- a/pcbnew/onleftclick.cpp +++ b/pcbnew/onleftclick.cpp @@ -346,7 +346,7 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) case ID_PCB_ADD_TEXT_BUTT: if( (DrawStruct == NULL) || (DrawStruct->GetFlags() == 0) ) { - SetCurItem( Create_Texte_Pcb( aDC ) ); + SetCurItem( CreateTextePcb( aDC ) ); m_canvas->MoveCursorToCrossHair(); m_canvas->SetAutoPanRequest( true ); } diff --git a/pcbnew/onrightclick.cpp b/pcbnew/onrightclick.cpp index 51d8dc87ed..49098f3cd2 100644 --- a/pcbnew/onrightclick.cpp +++ b/pcbnew/onrightclick.cpp @@ -839,6 +839,9 @@ void PCB_EDIT_FRAME::createPopUpMenuForTexts( TEXTE_PCB* Text, wxMenu* menu ) msg = AddHotkeyName( _( "Move" ), g_Board_Editor_Hokeys_Descr, HK_MOVE_ITEM ); AddMenuItem( sub_menu_Text, ID_POPUP_PCB_MOVE_TEXTEPCB_REQUEST, msg, KiBitmap( move_text_xpm ) ); + msg = AddHotkeyName( _( "Copy" ), g_Board_Editor_Hokeys_Descr, HK_COPY_ITEM ); + AddMenuItem( sub_menu_Text, ID_POPUP_PCB_COPY_TEXTEPCB, + msg, KiBitmap( copyblock_xpm ) ); } msg = AddHotkeyName( _( "Rotate" ), g_Board_Editor_Hokeys_Descr, HK_ROTATE_ITEM ); @@ -847,12 +850,15 @@ void PCB_EDIT_FRAME::createPopUpMenuForTexts( TEXTE_PCB* Text, wxMenu* menu ) AddMenuItem( sub_menu_Text, ID_POPUP_PCB_FLIP_TEXTEPCB, msg, KiBitmap( invert_module_xpm ) ); msg = AddHotkeyName( _( "Edit" ), g_Board_Editor_Hokeys_Descr, HK_EDIT_ITEM ); AddMenuItem( sub_menu_Text, ID_POPUP_PCB_EDIT_TEXTEPCB, msg, KiBitmap( edit_text_xpm ) ); - AddMenuItem( sub_menu_Text, ID_POPUP_PCB_RESET_TEXT_SIZE, - _( "Reset Size" ), KiBitmap( reset_text_xpm ) ); + if( !flags ) + { + AddMenuItem( sub_menu_Text, ID_POPUP_PCB_RESET_TEXT_SIZE, + _( "Reset Size" ), KiBitmap( reset_text_xpm ) ); - sub_menu_Text->AppendSeparator(); - msg = AddHotkeyName( _( "Delete" ), g_Board_Editor_Hokeys_Descr, HK_DELETE ); - AddMenuItem( sub_menu_Text, ID_POPUP_PCB_DELETE_TEXTEPCB, msg, KiBitmap( delete_text_xpm ) ); + sub_menu_Text->AppendSeparator(); + msg = AddHotkeyName( _( "Delete" ), g_Board_Editor_Hokeys_Descr, HK_DELETE ); + AddMenuItem( sub_menu_Text, ID_POPUP_PCB_DELETE_TEXTEPCB, msg, KiBitmap( delete_text_xpm ) ); + } } diff --git a/pcbnew/pcbnew_id.h b/pcbnew/pcbnew_id.h index b1fa634428..527bac274f 100644 --- a/pcbnew/pcbnew_id.h +++ b/pcbnew/pcbnew_id.h @@ -66,6 +66,7 @@ enum pcbnew_ids ID_POPUP_PCB_MOVE_TEXTEPCB_REQUEST, ID_POPUP_PCB_ROTATE_TEXTEPCB, + ID_POPUP_PCB_COPY_TEXTEPCB, ID_POPUP_PCB_FLIP_TEXTEPCB, ID_POPUP_PCB_EDIT_TEXTEPCB, ID_POPUP_PCB_DELETE_TEXTEPCB,