kicad/pcbnew/edit_pcb_text.cpp

287 lines
7.8 KiB
C++
Raw Normal View History

/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file edit_pcb_text.cpp
* @brief Editimg of text on copper and technical layers (TEXTE_PCB class)
*/
2008-12-20 17:28:25 +00:00
#include <fctsys.h>
#include <gr_basic.h>
#include <class_drawpanel.h>
#include <pcbnew.h>
#include <wxPcbStruct.h>
#include <macros.h>
#include <class_board.h>
#include <class_pcb_text.h>
2008-12-20 17:28:25 +00:00
#include <protos.h>
2009-08-03 07:55:08 +00:00
static void Move_Texte_Pcb( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
bool aErase );
static void Abort_Edit_Pcb_Text( EDA_DRAW_PANEL* Panel, wxDC* DC );
2008-12-20 17:28:25 +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
/*
* Abort current text edit progress.
*
* If a text is selected, its initial coord are regenerated
2008-12-20 17:28:25 +00:00
*/
void Abort_Edit_Pcb_Text( EDA_DRAW_PANEL* Panel, wxDC* DC )
2008-12-20 17:28:25 +00:00
{
2009-08-03 07:55:08 +00:00
TEXTE_PCB* TextePcb = (TEXTE_PCB*) Panel->GetScreen()->GetCurItem();
( (PCB_EDIT_FRAME*) Panel->GetParent() )->SetCurItem( NULL );
2008-12-20 17:28:25 +00:00
Panel->SetMouseCapture( NULL, NULL );
2009-08-03 07:55:08 +00:00
if( TextePcb == NULL ) // Should not occur
return;
#ifndef USE_WX_OVERLAY
2009-08-03 07:55:08 +00:00
TextePcb->Draw( Panel, DC, GR_XOR );
#endif
2009-08-03 07:55:08 +00:00
if( TextePcb->IsNew() ) // 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->ClearFlags();
#ifndef USE_WX_OVERLAY
TextePcb->Draw( Panel, DC, GR_OR );
#else
Panel->Refresh();
#endif
2008-12-20 17:28:25 +00:00
}
/*
* Place the current text being moving
*/
void PCB_EDIT_FRAME::Place_Texte_Pcb( TEXTE_PCB* TextePcb, wxDC* DC )
2008-12-20 17:28:25 +00:00
{
m_canvas->SetMouseCapture( NULL, NULL );
2009-08-03 07:55:08 +00:00
SetCurItem( NULL );
2008-12-20 17:28:25 +00:00
if( TextePcb == NULL )
return;
TextePcb->Draw( m_canvas, DC, GR_OR );
OnModify();
2009-08-03 07:55:08 +00:00
if( TextePcb->IsNew() ) // If new: prepare undo command
2009-08-03 07:55:08 +00:00
{
SaveCopyInUndoList( TextePcb, UR_NEW );
TextePcb->ClearFlags();
2009-08-03 07:55:08 +00:00
return;
}
if( TextePcb->IsMoving() ) // If moved only
{
SaveCopyInUndoList( TextePcb, UR_MOVED,
TextePcb->GetTextPosition() - s_TextCopy.GetTextPosition() );
}
2009-08-03 07:55:08 +00:00
else
{
// Restore initial params
SwapData( TextePcb, &s_TextCopy );
2009-08-03 07:55:08 +00:00
// Prepare undo command
SaveCopyInUndoList( TextePcb, UR_CHANGED );
SwapData( TextePcb, &s_TextCopy );
2009-08-03 07:55:08 +00:00
// Restore current params
}
TextePcb->ClearFlags();
#ifdef USE_WX_OVERLAY
2013-09-06 09:31:16 +00:00
RefreshCanvas();
#endif
2008-12-20 17:28:25 +00:00
}
void PCB_EDIT_FRAME::StartMoveTextePcb( TEXTE_PCB* aTextePcb, wxDC* aDC, bool aErase )
2008-12-20 17:28:25 +00:00
{
if( aTextePcb == NULL )
2008-12-20 17:28:25 +00:00
return;
2009-08-03 07:55:08 +00:00
// if it is an existing item: prepare a copy to undo/abort command
if( !aTextePcb->IsNew() )
s_TextCopy.Copy( aTextePcb );
2009-08-03 07:55:08 +00:00
aTextePcb->SetFlags( IS_MOVED );
SetMsgPanel( aTextePcb );
#ifdef USE_WX_OVERLAY
2013-09-06 09:31:16 +00:00
RefreshCanvas();
#endif
GetScreen()->SetCrossHairPosition( aTextePcb->GetTextPosition() );
m_canvas->MoveCursorToCrossHair();
m_canvas->SetMouseCapture( Move_Texte_Pcb, Abort_Edit_Pcb_Text );
SetCurItem( aTextePcb );
m_canvas->CallMouseCapture( aDC, wxDefaultPosition, aErase );
2008-12-20 17:28:25 +00:00
}
/* Move PCB text following the cursor. */
static void Move_Texte_Pcb( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
bool aErase )
2008-12-20 17:28:25 +00:00
{
TEXTE_PCB* TextePcb = (TEXTE_PCB*) aPanel->GetScreen()->GetCurItem();
2008-12-20 17:28:25 +00:00
if( TextePcb == NULL )
return;
if( aErase )
TextePcb->Draw( aPanel, aDC, GR_XOR );
2008-12-20 17:28:25 +00:00
TextePcb->SetTextPosition( aPanel->GetScreen()->GetCrossHairPosition() );
2008-12-20 17:28:25 +00:00
TextePcb->Draw( aPanel, aDC, GR_XOR );
2008-12-20 17:28:25 +00:00
}
void PCB_EDIT_FRAME::Delete_Texte_Pcb( TEXTE_PCB* TextePcb, wxDC* DC )
2008-12-20 17:28:25 +00:00
{
if( TextePcb == NULL )
return;
TextePcb->Draw( m_canvas, DC, GR_XOR );
2008-12-20 17:28:25 +00:00
2009-08-03 07:55:08 +00:00
SaveCopyInUndoList( TextePcb, UR_DELETED );
TextePcb->UnLink();
m_canvas->SetMouseCapture( NULL, NULL );
2008-12-20 17:28:25 +00:00
SetCurItem( NULL );
}
TEXTE_PCB* PCB_EDIT_FRAME::CreateTextePcb( wxDC* aDC, TEXTE_PCB* aText )
2008-12-20 17:28:25 +00:00
{
TEXTE_PCB* textePcb = new TEXTE_PCB( GetBoard() );
2008-12-20 17:28:25 +00:00
if( aText )
2008-12-20 17:28:25 +00:00
{
textePcb->Copy( aText );
GetBoard()->Add( textePcb );
textePcb->SetFlags( IS_NEW );
StartMoveTextePcb( textePcb, aDC, false ); // Don't erase aText when copying
2008-12-20 17:28:25 +00:00
}
else
{
GetBoard()->Add( textePcb );
textePcb->SetFlags( IS_NEW );
LAYER_NUM layer = ( (PCB_SCREEN*) GetScreen() )->m_Active_Layer;
textePcb->SetLayer( layer );
// Set the mirrored option for layers on the BACK side of the board
if( layer == LAYER_N_BACK || layer == SILKSCREEN_N_BACK ||
layer == SOLDERPASTE_N_BACK || layer == SOLDERMASK_N_BACK ||
layer == ADHESIVE_N_BACK
)
textePcb->SetMirrored( true );
textePcb->SetSize( GetBoard()->GetDesignSettings().m_PcbTextSize );
textePcb->SetTextPosition( GetScreen()->GetCrossHairPosition() );
textePcb->SetThickness( GetBoard()->GetDesignSettings().m_PcbTextWidth );
InstallTextPCBOptionsFrame( textePcb, aDC );
if( textePcb->GetText().IsEmpty() )
{
textePcb->DeleteStructure();
textePcb = NULL;
}
else
{
StartMoveTextePcb( textePcb, aDC );
}
}
2008-12-20 17:28:25 +00:00
return textePcb;
2008-12-20 17:28:25 +00:00
}
void PCB_EDIT_FRAME::Rotate_Texte_Pcb( TEXTE_PCB* TextePcb, wxDC* DC )
2008-12-20 17:28:25 +00:00
{
int angle = 900;
if( TextePcb == NULL )
return;
// Erase previous text:
TextePcb->Draw( m_canvas, DC, GR_XOR );
2008-12-20 17:28:25 +00:00
TextePcb->SetOrientation( TextePcb->GetOrientation() + angle );
2008-12-20 17:28:25 +00:00
// Redraw text in new position:
2012-05-30 17:38:52 +00:00
TextePcb->Draw( m_canvas, DC, GR_XOR );
SetMsgPanel( TextePcb );
if( TextePcb->GetFlags() == 0 ) // i.e. not edited, or moved
SaveCopyInUndoList( TextePcb, UR_ROTATED, TextePcb->GetTextPosition() );
else // set flag edit, to show it was a complex command
TextePcb->SetFlags( IN_EDIT );
2008-12-20 17:28:25 +00:00
OnModify();
#ifdef USE_WX_OVERLAY
2013-09-06 09:31:16 +00:00
RefreshCanvas();
#endif
2008-12-20 17:28:25 +00:00
}
2012-05-30 17:38:52 +00:00
void PCB_EDIT_FRAME::FlipTextePcb( TEXTE_PCB* aTextePcb, wxDC* aDC )
{
if( aTextePcb == NULL )
return;
aTextePcb->Draw( m_canvas, aDC, GR_XOR );
aTextePcb->Flip( aTextePcb->GetTextPosition() );
2012-05-30 17:38:52 +00:00
aTextePcb->Draw( m_canvas, aDC, GR_XOR );
SetMsgPanel( aTextePcb );
2012-05-30 17:38:52 +00:00
if( aTextePcb->GetFlags() == 0 ) // i.e. not edited, or moved
SaveCopyInUndoList( aTextePcb, UR_FLIPPED, aTextePcb->GetTextPosition() );
else // set edit flag, for the current command
2012-05-30 17:38:52 +00:00
aTextePcb->SetFlags( IN_EDIT );
OnModify();
#ifdef USE_WX_OVERLAY
2013-09-06 09:31:16 +00:00
RefreshCanvas();
#endif
2012-05-30 17:38:52 +00:00
}