2008-12-20 17:28:25 +00:00
|
|
|
/*********************************************************************/
|
|
|
|
/* Edition of texts on copper and technical layers (TEXTE_PCB class) */
|
|
|
|
/*********************************************************************/
|
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
2008-12-20 17:28:25 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "pcbnew.h"
|
2009-07-30 11:04:07 +00:00
|
|
|
#include "wxPcbStruct.h"
|
2009-10-28 11:48:47 +00:00
|
|
|
#include "class_board_design_settings.h"
|
2008-12-20 17:28:25 +00:00
|
|
|
|
2009-08-03 07:55:08 +00:00
|
|
|
#include "protos.h"
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
|
2008-12-20 17:28:25 +00:00
|
|
|
static void Move_Texte_Pcb( WinEDA_DrawPanel* panel, wxDC* DC, bool erase );
|
|
|
|
static void Abort_Edit_Pcb_Text( WinEDA_DrawPanel* Panel, wxDC* DC );
|
|
|
|
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
static TEXTE_PCB s_TextCopy( (BOARD_ITEM*) NULL ); /* copy of the edited text
|
|
|
|
* (used to undo/redo/abort
|
|
|
|
* a complex edition command
|
|
|
|
*/
|
|
|
|
|
2008-12-20 17:28:25 +00:00
|
|
|
|
|
|
|
/*
|
2009-11-14 22:15:22 +00:00
|
|
|
* Abort current text edit progress.
|
|
|
|
*
|
|
|
|
* If a text is selected, its initial coord are regenerated
|
2008-12-20 17:28:25 +00:00
|
|
|
*/
|
2009-11-14 22:15:22 +00:00
|
|
|
void Abort_Edit_Pcb_Text( WinEDA_DrawPanel* Panel, wxDC* DC )
|
2008-12-20 17:28:25 +00:00
|
|
|
{
|
2009-08-03 07:55:08 +00:00
|
|
|
Panel->ManageCurseur = NULL;
|
|
|
|
Panel->ForceCloseManageCurseur = NULL;
|
2009-12-21 12:05:36 +00:00
|
|
|
( (WinEDA_PcbFrame*) Panel->GetParent() )->SetCurItem( NULL );
|
2008-12-20 17:28:25 +00:00
|
|
|
|
2009-08-03 07:55:08 +00:00
|
|
|
TEXTE_PCB* TextePcb = (TEXTE_PCB*) Panel->GetScreen()->GetCurItem();
|
2008-12-20 17:28:25 +00:00
|
|
|
|
2009-08-03 07:55:08 +00:00
|
|
|
if( TextePcb == NULL ) // Should not occur
|
|
|
|
return;
|
|
|
|
|
|
|
|
TextePcb->Draw( Panel, DC, GR_XOR );
|
|
|
|
|
|
|
|
if( (TextePcb->m_Flags & IS_NEW) ) // If new: remove it
|
2008-12-20 17:28:25 +00:00
|
|
|
{
|
2009-08-03 07:55:08 +00:00
|
|
|
TextePcb->DeleteStructure();
|
|
|
|
return;
|
2008-12-20 17:28:25 +00:00
|
|
|
}
|
|
|
|
|
2009-08-03 07:55:08 +00:00
|
|
|
|
|
|
|
SwapData(TextePcb, &s_TextCopy);
|
|
|
|
TextePcb->Draw( Panel, DC, GR_OR );
|
|
|
|
TextePcb->m_Flags = 0;
|
2008-12-20 17:28:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Place the current text being moving
|
|
|
|
*/
|
2009-11-14 22:15:22 +00:00
|
|
|
void WinEDA_PcbFrame::Place_Texte_Pcb( TEXTE_PCB* TextePcb, wxDC* DC )
|
2008-12-20 17:28:25 +00:00
|
|
|
{
|
2009-08-03 07:55:08 +00:00
|
|
|
DrawPanel->ManageCurseur = NULL;
|
|
|
|
DrawPanel->ForceCloseManageCurseur = NULL;
|
|
|
|
SetCurItem( NULL );
|
|
|
|
|
2008-12-20 17:28:25 +00:00
|
|
|
if( TextePcb == NULL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
TextePcb->Draw( DrawPanel, DC, GR_OR );
|
|
|
|
GetScreen()->SetModify();
|
2009-08-03 07:55:08 +00:00
|
|
|
|
|
|
|
if( (TextePcb->m_Flags & IS_NEW) ) // If new: prepare undo command
|
|
|
|
{
|
|
|
|
SaveCopyInUndoList( TextePcb, UR_NEW );
|
|
|
|
TextePcb->m_Flags = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( TextePcb->m_Flags == IS_MOVED ) // If moved only
|
2009-11-14 22:15:22 +00:00
|
|
|
SaveCopyInUndoList( TextePcb, UR_MOVED,
|
|
|
|
TextePcb->m_Pos - s_TextCopy.m_Pos );
|
2009-08-03 07:55:08 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// Restore initial params
|
|
|
|
SwapData( TextePcb, &s_TextCopy);
|
|
|
|
// Prepare undo command
|
|
|
|
SaveCopyInUndoList( TextePcb, UR_CHANGED );
|
|
|
|
SwapData( TextePcb, &s_TextCopy);
|
|
|
|
// Restore current params
|
|
|
|
}
|
|
|
|
|
2008-12-20 17:28:25 +00:00
|
|
|
TextePcb->m_Flags = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Initialize parameters to move a pcb text
|
2008-12-20 17:28:25 +00:00
|
|
|
*/
|
2009-11-14 22:15:22 +00:00
|
|
|
void WinEDA_PcbFrame::StartMoveTextePcb( TEXTE_PCB* TextePcb, wxDC* DC )
|
2008-12-20 17:28:25 +00:00
|
|
|
{
|
|
|
|
if( TextePcb == NULL )
|
|
|
|
return;
|
2009-08-03 07:55:08 +00:00
|
|
|
|
|
|
|
// if it is an existing item: prepare a copy to undo/abort command
|
|
|
|
if( (TextePcb->m_Flags & IS_NEW) == 0 )
|
|
|
|
s_TextCopy.Copy( TextePcb );
|
|
|
|
|
2008-12-20 17:28:25 +00:00
|
|
|
TextePcb->Draw( DrawPanel, DC, GR_XOR );
|
|
|
|
TextePcb->m_Flags |= IS_MOVED;
|
2009-04-17 08:51:02 +00:00
|
|
|
TextePcb->DisplayInfo( this );
|
2008-12-20 17:28:25 +00:00
|
|
|
DrawPanel->ManageCurseur = Move_Texte_Pcb;
|
|
|
|
DrawPanel->ForceCloseManageCurseur = Abort_Edit_Pcb_Text;
|
|
|
|
SetCurItem( TextePcb );
|
|
|
|
DrawPanel->ManageCurseur( DrawPanel, DC, FALSE );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Move PCB text following the cursor. */
|
2008-12-20 17:28:25 +00:00
|
|
|
static void Move_Texte_Pcb( WinEDA_DrawPanel* panel, wxDC* DC, bool erase )
|
|
|
|
{
|
|
|
|
TEXTE_PCB* TextePcb = (TEXTE_PCB*) panel->GetScreen()->GetCurItem();
|
|
|
|
|
|
|
|
if( TextePcb == NULL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( erase )
|
|
|
|
TextePcb->Draw( panel, DC, GR_XOR );
|
|
|
|
|
|
|
|
TextePcb->m_Pos = panel->GetScreen()->m_Curseur;
|
|
|
|
|
|
|
|
TextePcb->Draw( panel, DC, GR_XOR );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void WinEDA_PcbFrame::Delete_Texte_Pcb( TEXTE_PCB* TextePcb, wxDC* DC )
|
|
|
|
{
|
|
|
|
if( TextePcb == NULL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
TextePcb->Draw( DrawPanel, DC, GR_XOR );
|
|
|
|
|
2009-08-03 07:55:08 +00:00
|
|
|
SaveCopyInUndoList( TextePcb, UR_DELETED );
|
|
|
|
TextePcb->UnLink();
|
2008-12-20 17:28:25 +00:00
|
|
|
DrawPanel->ManageCurseur = NULL;
|
|
|
|
DrawPanel->ForceCloseManageCurseur = NULL;
|
|
|
|
SetCurItem( NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEXTE_PCB* WinEDA_PcbFrame::Create_Texte_Pcb( wxDC* DC )
|
|
|
|
{
|
|
|
|
TEXTE_PCB* TextePcb;
|
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
TextePcb = new TEXTE_PCB( GetBoard() );
|
2008-12-20 17:28:25 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Add text to the board item list. */
|
2009-01-05 05:21:35 +00:00
|
|
|
GetBoard()->Add( TextePcb );
|
2008-12-20 17:28:25 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Update text properties. */
|
2009-08-03 07:55:08 +00:00
|
|
|
TextePcb->m_Flags = IS_NEW;
|
|
|
|
TextePcb->SetLayer( ( (PCB_SCREEN*) GetScreen() )->m_Active_Layer );
|
2008-12-20 20:38:39 +00:00
|
|
|
TextePcb->m_Mirror = false;
|
2009-12-07 03:46:13 +00:00
|
|
|
if( TextePcb->GetLayer() == LAYER_N_BACK )
|
2008-12-20 20:38:39 +00:00
|
|
|
TextePcb->m_Mirror = true;
|
2008-12-20 17:28:25 +00:00
|
|
|
|
|
|
|
TextePcb->m_Size = g_DesignSettings.m_PcbTextSize;
|
|
|
|
TextePcb->m_Pos = GetScreen()->m_Curseur;
|
|
|
|
TextePcb->m_Width = g_DesignSettings.m_PcbTextWidth;
|
|
|
|
|
|
|
|
InstallTextPCBOptionsFrame( TextePcb, DC );
|
|
|
|
if( TextePcb->m_Text.IsEmpty() )
|
|
|
|
{
|
2009-08-03 07:55:08 +00:00
|
|
|
TextePcb->DeleteStructure();
|
2008-12-20 17:28:25 +00:00
|
|
|
TextePcb = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
StartMoveTextePcb( TextePcb, DC );
|
|
|
|
|
|
|
|
return TextePcb;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void WinEDA_PcbFrame::Rotate_Texte_Pcb( TEXTE_PCB* TextePcb, wxDC* DC )
|
|
|
|
{
|
|
|
|
int angle = 900;
|
|
|
|
int drawmode = GR_XOR;
|
|
|
|
|
|
|
|
if( TextePcb == NULL )
|
|
|
|
return;
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Erase previous text. */
|
2008-12-20 17:28:25 +00:00
|
|
|
TextePcb->Draw( DrawPanel, DC, GR_XOR );
|
|
|
|
|
|
|
|
TextePcb->m_Orient += angle;
|
2009-08-03 07:55:08 +00:00
|
|
|
NORMALIZE_ANGLE( TextePcb->m_Orient );
|
2008-12-20 17:28:25 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Redraw text in new position. */
|
2008-12-20 17:28:25 +00:00
|
|
|
TextePcb->Draw( DrawPanel, DC, drawmode );
|
2009-04-17 08:51:02 +00:00
|
|
|
TextePcb->DisplayInfo( this );
|
2009-08-03 07:55:08 +00:00
|
|
|
if( TextePcb->m_Flags == 0 ) // i.e. not edited, or moved
|
|
|
|
SaveCopyInUndoList( TextePcb, UR_ROTATED, TextePcb->m_Pos );
|
2009-11-14 22:15:22 +00:00
|
|
|
else // set flag edit, to show it was a complex command
|
2009-08-03 07:55:08 +00:00
|
|
|
TextePcb->m_Flags |= IN_EDIT;
|
2008-12-20 17:28:25 +00:00
|
|
|
|
|
|
|
GetScreen()->SetModify();
|
|
|
|
}
|