Add copy to text items in pcbnew. Automatically mirror text items added to back silkscreen (bug 1017446).

This commit is contained in:
Marco Mattila 2012-07-04 22:50:47 +03:00
parent 1f1a7703d9
commit b7c5649463
9 changed files with 115 additions and 52 deletions

View File

@ -439,6 +439,13 @@ public:
bool OnHotkeyEditItem( int aIdCommand ); 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 * Function OnHotkeyMoveItem
* Moves or drag the item (footprint, track, text .. ) found under the mouse cursor * Moves or drag the item (footprint, track, text .. ) found under the mouse cursor
@ -911,9 +918,9 @@ public:
// Handling texts on the board // Handling texts on the board
void Rotate_Texte_Pcb( TEXTE_PCB* TextePcb, wxDC* DC ); void Rotate_Texte_Pcb( TEXTE_PCB* TextePcb, wxDC* DC );
void FlipTextePcb( TEXTE_PCB* aTextePcb, wxDC* aDC ); 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 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 Place_Texte_Pcb( TEXTE_PCB* TextePcb, wxDC* DC );
void InstallTextPCBOptionsFrame( TEXTE_PCB* TextPCB, wxDC* DC ); void InstallTextPCBOptionsFrame( TEXTE_PCB* TextPCB, wxDC* DC );

View File

@ -48,6 +48,7 @@
#include <class_module.h> #include <class_module.h>
#include <class_track.h> #include <class_track.h>
#include <class_zone.h> #include <class_zone.h>
#include <class_pcb_text.h>
#include <modview_frame.h> #include <modview_frame.h>
#include <class_pcb_layer_box_selector.h> #include <class_pcb_layer_box_selector.h>
@ -83,6 +84,7 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
case ID_AUX_TOOLBAR_PCB_SELECT_LAYER_PAIR: case ID_AUX_TOOLBAR_PCB_SELECT_LAYER_PAIR:
case ID_POPUP_PCB_ROTATE_TEXTEPCB: case ID_POPUP_PCB_ROTATE_TEXTEPCB:
case ID_POPUP_PCB_FLIP_TEXTEPCB: case ID_POPUP_PCB_FLIP_TEXTEPCB:
case ID_POPUP_PCB_COPY_TEXTEPCB:
case ID_POPUP_PCB_EDIT_TEXTEPCB: case ID_POPUP_PCB_EDIT_TEXTEPCB:
case ID_POPUP_PCB_EDIT_MIRE: case ID_POPUP_PCB_EDIT_MIRE:
case ID_POPUP_PCB_ROTATE_TEXTMODULE: case ID_POPUP_PCB_ROTATE_TEXTMODULE:
@ -939,6 +941,12 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
m_canvas->MoveCursorToCrossHair(); m_canvas->MoveCursorToCrossHair();
break; 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: case ID_POPUP_PCB_FLIP_TEXTEPCB:
FlipTextePcb( (TEXTE_PCB*) GetCurItem(), &dc ); FlipTextePcb( (TEXTE_PCB*) GetCurItem(), &dc );
m_canvas->MoveCursorToCrossHair(); m_canvas->MoveCursorToCrossHair();

View File

@ -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->ClearFlags();
TextePcb->Draw( Panel, DC, GR_OR ); TextePcb->Draw( Panel, DC, GR_OR );
} }
@ -110,10 +110,10 @@ void PCB_EDIT_FRAME::Place_Texte_Pcb( TEXTE_PCB* TextePcb, wxDC* DC )
else else
{ {
// Restore initial params // Restore initial params
SwapData( TextePcb, &s_TextCopy); SwapData( TextePcb, &s_TextCopy );
// Prepare undo command // Prepare undo command
SaveCopyInUndoList( TextePcb, UR_CHANGED ); SaveCopyInUndoList( TextePcb, UR_CHANGED );
SwapData( TextePcb, &s_TextCopy); SwapData( TextePcb, &s_TextCopy );
// Restore current params // 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* aTextePcb, wxDC* aDC, bool aErase )
*/
void PCB_EDIT_FRAME::StartMoveTextePcb( TEXTE_PCB* TextePcb, wxDC* DC )
{ {
if( TextePcb == NULL ) if( aTextePcb == NULL )
return; return;
// if it is an existing item: prepare a copy to undo/abort command // if it is an existing item: prepare a copy to undo/abort command
if( !TextePcb->IsNew() ) if( !aTextePcb->IsNew() )
s_TextCopy.Copy( TextePcb ); s_TextCopy.Copy( aTextePcb );
TextePcb->Draw( m_canvas, DC, GR_XOR ); aTextePcb->SetFlags( IS_MOVED );
TextePcb->SetFlags( IS_MOVED ); aTextePcb->DisplayInfo( this );
TextePcb->DisplayInfo( this );
GetScreen()->SetCrossHairPosition( TextePcb->GetPosition() ); GetScreen()->SetCrossHairPosition( aTextePcb->GetPosition() );
m_canvas->MoveCursorToCrossHair(); m_canvas->MoveCursorToCrossHair();
m_canvas->SetMouseCapture( Move_Texte_Pcb, Abort_Edit_Pcb_Text ); m_canvas->SetMouseCapture( Move_Texte_Pcb, Abort_Edit_Pcb_Text );
SetCurItem( TextePcb ); SetCurItem( aTextePcb );
m_canvas->CallMouseCapture( DC, wxDefaultPosition, false ); 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 ) if( aErase )
TextePcb->Draw( aPanel, aDC, GR_XOR ); TextePcb->Draw( aPanel, aDC, GR_XOR );
TextePcb->m_Pos = aPanel->GetScreen()->GetCrossHairPosition(); TextePcb->SetPosition( aPanel->GetScreen()->GetCrossHairPosition() );
TextePcb->Draw( aPanel, aDC, GR_XOR ); 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() ); if( aText )
/* 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() )
{ {
TextePcb->DeleteStructure(); textePcb->Copy( aText );
TextePcb = NULL; GetBoard()->Add( textePcb );
textePcb->SetFlags( IS_NEW );
StartMoveTextePcb( textePcb, aDC, false ); // Don't erase aText when copying
} }
else 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;
} }

View File

@ -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 HkFlipItem( wxT( "Flip Item" ), HK_FLIP_ITEM, 'F' );
static EDA_HOTKEY HkRotateItem( wxT( "Rotate Item" ), HK_ROTATE_ITEM, 'R' ); 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 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 HkDragFootprint( wxT( "Drag Footprint" ), HK_DRAG_ITEM, 'G' );
static EDA_HOTKEY HkGetAndMoveFootprint( wxT( "Get and Move Footprint" ), static EDA_HOTKEY HkGetAndMoveFootprint( wxT( "Get and Move Footprint" ),
HK_GET_AND_MOVE_FOOTPRINT, 'T' ); HK_GET_AND_MOVE_FOOTPRINT, 'T' );
@ -209,7 +210,7 @@ EDA_HOTKEY* board_edit_Hotkey_List[] =
&HkAddNewTrack, &HkAddVia, &HkAddMicroVia, &HkAddNewTrack, &HkAddVia, &HkAddMicroVia,
&HkSwitchTrackPosture, &HkSwitchTrackPosture,
&HkDragTrackKeepSlope, &HkDragTrackKeepSlope,
&HkPlaceItem, &HkPlaceItem, &HkCopyItem,
&HkEndTrack, &HkMoveItem, &HkFlipItem, &HkEndTrack, &HkMoveItem, &HkFlipItem,
&HkRotateItem, &HkDragFootprint, &HkRotateItem, &HkDragFootprint,
&HkGetAndMoveFootprint, &HkLock_Unlock_Footprint, &HkSavefile, &HkGetAndMoveFootprint, &HkLock_Unlock_Footprint, &HkSavefile,

View File

@ -15,6 +15,7 @@ enum hotkey_id_commnand {
HK_BACK_SPACE, HK_BACK_SPACE,
HK_ROTATE_ITEM, HK_ROTATE_ITEM,
HK_FLIP_ITEM, HK_FLIP_ITEM,
HK_COPY_ITEM,
HK_MOVE_ITEM, HK_MOVE_ITEM,
HK_DRAG_ITEM, HK_DRAG_ITEM,
HK_GET_AND_MOVE_FOOTPRINT, HK_GET_AND_MOVE_FOOTPRINT,

View File

@ -620,6 +620,10 @@ void PCB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosit
OnHotkeyMoveItem( HK_MOVE_ITEM ); OnHotkeyMoveItem( HK_MOVE_ITEM );
break; break;
case HK_COPY_ITEM:
evt_type = OnHotkeyCopyItem();
break;
case HK_ROTATE_ITEM: // Rotation case HK_ROTATE_ITEM: // Rotation
OnHotkeyRotateItem( HK_ROTATE_ITEM ); OnHotkeyRotateItem( HK_ROTATE_ITEM );
break; 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 case HK_SWITCH_HIGHCONTRAST_MODE: // switch to high contrast mode and refresh the canvas
DisplayOpt.ContrastModeDisplay = !DisplayOpt.ContrastModeDisplay; DisplayOpt.ContrastModeDisplay = !DisplayOpt.ContrastModeDisplay;
m_canvas->Refresh(); m_canvas->Refresh();
break; break;
} }
if( evt_type != 0 ) if( evt_type != 0 )
@ -715,6 +719,7 @@ bool PCB_EDIT_FRAME::OnHotkeyDeleteItem( wxDC* aDC )
return true; return true;
} }
bool PCB_EDIT_FRAME::OnHotkeyEditItem( int aIdCommand ) bool PCB_EDIT_FRAME::OnHotkeyEditItem( int aIdCommand )
{ {
BOARD_ITEM* item = GetCurItem(); 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 ) bool PCB_EDIT_FRAME::OnHotkeyMoveItem( int aIdCommand )
{ {
BOARD_ITEM* item = GetCurItem(); BOARD_ITEM* item = GetCurItem();

View File

@ -346,7 +346,7 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
case ID_PCB_ADD_TEXT_BUTT: case ID_PCB_ADD_TEXT_BUTT:
if( (DrawStruct == NULL) || (DrawStruct->GetFlags() == 0) ) if( (DrawStruct == NULL) || (DrawStruct->GetFlags() == 0) )
{ {
SetCurItem( Create_Texte_Pcb( aDC ) ); SetCurItem( CreateTextePcb( aDC ) );
m_canvas->MoveCursorToCrossHair(); m_canvas->MoveCursorToCrossHair();
m_canvas->SetAutoPanRequest( true ); m_canvas->SetAutoPanRequest( true );
} }

View File

@ -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 ); msg = AddHotkeyName( _( "Move" ), g_Board_Editor_Hokeys_Descr, HK_MOVE_ITEM );
AddMenuItem( sub_menu_Text, ID_POPUP_PCB_MOVE_TEXTEPCB_REQUEST, AddMenuItem( sub_menu_Text, ID_POPUP_PCB_MOVE_TEXTEPCB_REQUEST,
msg, KiBitmap( move_text_xpm ) ); 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 ); 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 ) ); 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 ); 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_EDIT_TEXTEPCB, msg, KiBitmap( edit_text_xpm ) );
AddMenuItem( sub_menu_Text, ID_POPUP_PCB_RESET_TEXT_SIZE, if( !flags )
_( "Reset Size" ), KiBitmap( reset_text_xpm ) ); {
AddMenuItem( sub_menu_Text, ID_POPUP_PCB_RESET_TEXT_SIZE,
_( "Reset Size" ), KiBitmap( reset_text_xpm ) );
sub_menu_Text->AppendSeparator(); sub_menu_Text->AppendSeparator();
msg = AddHotkeyName( _( "Delete" ), g_Board_Editor_Hokeys_Descr, HK_DELETE ); msg = AddHotkeyName( _( "Delete" ), g_Board_Editor_Hokeys_Descr, HK_DELETE );
AddMenuItem( sub_menu_Text, ID_POPUP_PCB_DELETE_TEXTEPCB, msg, KiBitmap( delete_text_xpm ) ); AddMenuItem( sub_menu_Text, ID_POPUP_PCB_DELETE_TEXTEPCB, msg, KiBitmap( delete_text_xpm ) );
}
} }

View File

@ -66,6 +66,7 @@ enum pcbnew_ids
ID_POPUP_PCB_MOVE_TEXTEPCB_REQUEST, ID_POPUP_PCB_MOVE_TEXTEPCB_REQUEST,
ID_POPUP_PCB_ROTATE_TEXTEPCB, ID_POPUP_PCB_ROTATE_TEXTEPCB,
ID_POPUP_PCB_COPY_TEXTEPCB,
ID_POPUP_PCB_FLIP_TEXTEPCB, ID_POPUP_PCB_FLIP_TEXTEPCB,
ID_POPUP_PCB_EDIT_TEXTEPCB, ID_POPUP_PCB_EDIT_TEXTEPCB,
ID_POPUP_PCB_DELETE_TEXTEPCB, ID_POPUP_PCB_DELETE_TEXTEPCB,