Commit b7c56494 authored by Marco Mattila's avatar Marco Mattila

Add copy to text items in pcbnew. Automatically mirror text items added to...

Add copy to text items in pcbnew. Automatically mirror text items added to back silkscreen (bug 1017446).
parent 1f1a7703
......@@ -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 );
......
......@@ -48,6 +48,7 @@
#include <class_module.h>
#include <class_track.h>
#include <class_zone.h>
#include <class_pcb_text.h>
#include <modview_frame.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_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();
......
......@@ -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;
TextePcb = new TEXTE_PCB( GetBoard() );
TEXTE_PCB* 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;
}
......
......@@ -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,
......
......@@ -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,
......
......@@ -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();
......
......@@ -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 );
}
......
......@@ -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 ) );
}
}
......
......@@ -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,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment