2011-12-29 20:11:42 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2012-06-08 09:56:42 +00:00
|
|
|
* 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.
|
2011-12-29 20:11:42 +00:00
|
|
|
*
|
|
|
|
* 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
|
2015-04-06 19:50:12 +00:00
|
|
|
* @brief Editing of text on copper and technical layers (TEXTE_PCB class)
|
2011-12-29 20:11:42 +00:00
|
|
|
*/
|
2008-12-20 17:28:25 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <pcbnew.h>
|
|
|
|
#include <wxPcbStruct.h>
|
|
|
|
#include <macros.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_pcb_text.h>
|
2013-11-20 17:26:47 +00:00
|
|
|
#include <class_board_item.h>
|
2009-08-03 07:55:08 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
|
2011-02-03 19:27:28 +00:00
|
|
|
static void Move_Texte_Pcb( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
|
|
|
|
bool aErase );
|
2011-01-21 19:30:59 +00:00
|
|
|
static void Abort_Edit_Pcb_Text( EDA_DRAW_PANEL* Panel, wxDC* DC );
|
2008-12-20 17:28:25 +00:00
|
|
|
|
|
|
|
|
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
|
|
|
*/
|
2011-01-21 19:30:59 +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();
|
2011-03-01 19:26:17 +00:00
|
|
|
( (PCB_EDIT_FRAME*) Panel->GetParent() )->SetCurItem( NULL );
|
2008-12-20 17:28:25 +00:00
|
|
|
|
2011-02-13 09:07:30 +00:00
|
|
|
Panel->SetMouseCapture( NULL, NULL );
|
|
|
|
|
2009-08-03 07:55:08 +00:00
|
|
|
if( TextePcb == NULL ) // Should not occur
|
|
|
|
return;
|
|
|
|
|
2012-11-24 23:23:36 +00:00
|
|
|
#ifndef USE_WX_OVERLAY
|
2009-08-03 07:55:08 +00:00
|
|
|
TextePcb->Draw( Panel, DC, GR_XOR );
|
2012-11-24 23:23:36 +00:00
|
|
|
#endif
|
2009-08-03 07:55:08 +00:00
|
|
|
|
2011-02-21 13:54:29 +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
|
|
|
|
2013-11-20 17:26:47 +00:00
|
|
|
TextePcb->SwapData( &s_TextCopy );
|
2011-12-21 13:42:02 +00:00
|
|
|
TextePcb->ClearFlags();
|
2012-11-24 23:23:36 +00:00
|
|
|
#ifndef USE_WX_OVERLAY
|
2010-03-09 09:51:22 +00:00
|
|
|
TextePcb->Draw( Panel, DC, GR_OR );
|
2012-11-24 23:23:36 +00:00
|
|
|
#else
|
|
|
|
Panel->Refresh();
|
|
|
|
#endif
|
2008-12-20 17:28:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Place the current text being moving
|
|
|
|
*/
|
2011-03-01 19:26:17 +00:00
|
|
|
void PCB_EDIT_FRAME::Place_Texte_Pcb( TEXTE_PCB* TextePcb, wxDC* DC )
|
2008-12-20 17:28:25 +00:00
|
|
|
{
|
2011-12-22 13:28:11 +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;
|
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
TextePcb->Draw( m_canvas, DC, GR_OR );
|
2010-02-19 13:23:58 +00:00
|
|
|
OnModify();
|
2009-08-03 07:55:08 +00:00
|
|
|
|
2011-02-21 13:54:29 +00:00
|
|
|
if( TextePcb->IsNew() ) // If new: prepare undo command
|
2009-08-03 07:55:08 +00:00
|
|
|
{
|
|
|
|
SaveCopyInUndoList( TextePcb, UR_NEW );
|
2011-12-21 13:42:02 +00:00
|
|
|
TextePcb->ClearFlags();
|
2009-08-03 07:55:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-21 13:42:02 +00:00
|
|
|
if( TextePcb->IsMoving() ) // If moved only
|
|
|
|
{
|
2013-03-18 19:36:07 +00:00
|
|
|
SaveCopyInUndoList( TextePcb, UR_MOVED,
|
|
|
|
TextePcb->GetTextPosition() - s_TextCopy.GetTextPosition() );
|
2011-12-21 13:42:02 +00:00
|
|
|
}
|
2009-08-03 07:55:08 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// Restore initial params
|
2013-11-20 17:26:47 +00:00
|
|
|
TextePcb->SwapData( &s_TextCopy );
|
2009-08-03 07:55:08 +00:00
|
|
|
// Prepare undo command
|
|
|
|
SaveCopyInUndoList( TextePcb, UR_CHANGED );
|
|
|
|
// Restore current params
|
2013-11-20 17:26:47 +00:00
|
|
|
TextePcb->SwapData( &s_TextCopy );
|
2009-08-03 07:55:08 +00:00
|
|
|
}
|
|
|
|
|
2011-12-21 13:42:02 +00:00
|
|
|
TextePcb->ClearFlags();
|
2012-11-24 23:23:36 +00:00
|
|
|
#ifdef USE_WX_OVERLAY
|
|
|
|
m_canvas->Refresh();
|
|
|
|
#endif
|
2008-12-20 17:28:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-04 19:50:47 +00:00
|
|
|
void PCB_EDIT_FRAME::StartMoveTextePcb( TEXTE_PCB* aTextePcb, wxDC* aDC, bool aErase )
|
2008-12-20 17:28:25 +00:00
|
|
|
{
|
2012-07-04 19:50:47 +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
|
2012-07-04 19:50:47 +00:00
|
|
|
if( !aTextePcb->IsNew() )
|
|
|
|
s_TextCopy.Copy( aTextePcb );
|
2009-08-03 07:55:08 +00:00
|
|
|
|
2012-07-04 19:50:47 +00:00
|
|
|
aTextePcb->SetFlags( IS_MOVED );
|
2013-01-12 17:32:24 +00:00
|
|
|
SetMsgPanel( aTextePcb );
|
2011-07-04 21:32:49 +00:00
|
|
|
|
2012-11-24 23:23:36 +00:00
|
|
|
#ifdef USE_WX_OVERLAY
|
|
|
|
m_canvas->Refresh();
|
|
|
|
#endif
|
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
SetCrossHairPosition( aTextePcb->GetTextPosition() );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2011-07-04 21:32:49 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->SetMouseCapture( Move_Texte_Pcb, Abort_Edit_Pcb_Text );
|
2012-07-04 19:50:47 +00:00
|
|
|
SetCurItem( aTextePcb );
|
|
|
|
m_canvas->CallMouseCapture( aDC, wxDefaultPosition, aErase );
|
2008-12-20 17:28:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
// Move PCB text following the cursor.
|
2011-02-03 19:27:28 +00:00
|
|
|
static void Move_Texte_Pcb( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
|
|
|
|
bool aErase )
|
2008-12-20 17:28:25 +00:00
|
|
|
{
|
2011-02-03 19:27:28 +00:00
|
|
|
TEXTE_PCB* TextePcb = (TEXTE_PCB*) aPanel->GetScreen()->GetCurItem();
|
2008-12-20 17:28:25 +00:00
|
|
|
|
|
|
|
if( TextePcb == NULL )
|
|
|
|
return;
|
|
|
|
|
2011-02-03 19:27:28 +00:00
|
|
|
if( aErase )
|
|
|
|
TextePcb->Draw( aPanel, aDC, GR_XOR );
|
2008-12-20 17:28:25 +00:00
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
TextePcb->SetTextPosition( aPanel->GetParent()->GetCrossHairPosition() );
|
2008-12-20 17:28:25 +00:00
|
|
|
|
2011-02-03 19:27:28 +00:00
|
|
|
TextePcb->Draw( aPanel, aDC, GR_XOR );
|
2008-12-20 17:28:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-01 19:26:17 +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;
|
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
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();
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->SetMouseCapture( NULL, NULL );
|
2008-12-20 17:28:25 +00:00
|
|
|
SetCurItem( NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-04 19:50:47 +00:00
|
|
|
TEXTE_PCB* PCB_EDIT_FRAME::CreateTextePcb( wxDC* aDC, TEXTE_PCB* aText )
|
2008-12-20 17:28:25 +00:00
|
|
|
{
|
2012-07-04 19:50:47 +00:00
|
|
|
TEXTE_PCB* textePcb = new TEXTE_PCB( GetBoard() );
|
2008-12-20 17:28:25 +00:00
|
|
|
|
2012-07-04 19:50:47 +00:00
|
|
|
if( aText )
|
2008-12-20 17:28:25 +00:00
|
|
|
{
|
2012-07-04 19:50:47 +00:00
|
|
|
textePcb->Copy( aText );
|
|
|
|
GetBoard()->Add( textePcb );
|
|
|
|
textePcb->SetFlags( IS_NEW );
|
2014-02-10 14:40:25 +00:00
|
|
|
if( aDC )
|
|
|
|
StartMoveTextePcb( textePcb, aDC, false ); // Don't erase aText when copying
|
2008-12-20 17:28:25 +00:00
|
|
|
}
|
|
|
|
else
|
2011-09-07 19:41:04 +00:00
|
|
|
{
|
2012-07-04 19:50:47 +00:00
|
|
|
GetBoard()->Add( textePcb );
|
|
|
|
textePcb->SetFlags( IS_NEW );
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2015-09-03 07:44:30 +00:00
|
|
|
LAYER_ID layer = GetActiveLayer();
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2012-07-04 19:50:47 +00:00
|
|
|
textePcb->SetLayer( layer );
|
|
|
|
|
2012-11-28 18:04:57 +00:00
|
|
|
// Set the mirrored option for layers on the BACK side of the board
|
2014-06-24 16:17:18 +00:00
|
|
|
if( layer == B_Cu || layer == B_SilkS ||
|
|
|
|
layer == B_Paste || layer == B_Mask ||
|
|
|
|
layer == B_Adhes
|
2012-11-28 18:04:57 +00:00
|
|
|
)
|
2012-07-04 19:50:47 +00:00
|
|
|
textePcb->SetMirrored( true );
|
|
|
|
|
|
|
|
textePcb->SetSize( GetBoard()->GetDesignSettings().m_PcbTextSize );
|
2013-08-03 05:15:23 +00:00
|
|
|
textePcb->SetTextPosition( GetCrossHairPosition() );
|
2012-07-04 19:50:47 +00:00
|
|
|
textePcb->SetThickness( GetBoard()->GetDesignSettings().m_PcbTextWidth );
|
|
|
|
|
|
|
|
InstallTextPCBOptionsFrame( textePcb, aDC );
|
|
|
|
|
|
|
|
if( textePcb->GetText().IsEmpty() )
|
|
|
|
{
|
|
|
|
textePcb->DeleteStructure();
|
|
|
|
textePcb = NULL;
|
|
|
|
}
|
2014-02-10 14:40:25 +00:00
|
|
|
else if( aDC )
|
2012-07-04 19:50:47 +00:00
|
|
|
{
|
|
|
|
StartMoveTextePcb( textePcb, aDC );
|
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
}
|
2008-12-20 17:28:25 +00:00
|
|
|
|
2012-07-04 19:50:47 +00:00
|
|
|
return textePcb;
|
2008-12-20 17:28:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-01 19:26:17 +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;
|
|
|
|
|
2013-05-29 18:00:40 +00:00
|
|
|
// Erase previous text:
|
2011-12-22 13:28:11 +00:00
|
|
|
TextePcb->Draw( m_canvas, DC, GR_XOR );
|
2008-12-20 17:28:25 +00:00
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
TextePcb->SetOrientation( TextePcb->GetOrientation() + angle );
|
2008-12-20 17:28:25 +00:00
|
|
|
|
2013-05-29 18:00:40 +00:00
|
|
|
// Redraw text in new position:
|
2012-05-30 17:38:52 +00:00
|
|
|
TextePcb->Draw( m_canvas, DC, GR_XOR );
|
2013-01-12 17:32:24 +00:00
|
|
|
SetMsgPanel( TextePcb );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-12-21 13:42:02 +00:00
|
|
|
if( TextePcb->GetFlags() == 0 ) // i.e. not edited, or moved
|
2013-03-18 19:36:07 +00:00
|
|
|
SaveCopyInUndoList( TextePcb, UR_ROTATED, TextePcb->GetTextPosition() );
|
2009-11-14 22:15:22 +00:00
|
|
|
else // set flag edit, to show it was a complex command
|
2011-12-21 13:42:02 +00:00
|
|
|
TextePcb->SetFlags( IN_EDIT );
|
2008-12-20 17:28:25 +00:00
|
|
|
|
2010-02-19 13:23:58 +00:00
|
|
|
OnModify();
|
2012-11-24 23:23:36 +00:00
|
|
|
#ifdef USE_WX_OVERLAY
|
|
|
|
m_canvas->Refresh();
|
|
|
|
#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 );
|
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
aTextePcb->Flip( aTextePcb->GetTextPosition() );
|
2012-05-30 17:38:52 +00:00
|
|
|
|
|
|
|
aTextePcb->Draw( m_canvas, aDC, GR_XOR );
|
2013-01-12 17:32:24 +00:00
|
|
|
SetMsgPanel( aTextePcb );
|
2012-05-30 17:38:52 +00:00
|
|
|
|
|
|
|
if( aTextePcb->GetFlags() == 0 ) // i.e. not edited, or moved
|
2013-03-18 19:36:07 +00:00
|
|
|
SaveCopyInUndoList( aTextePcb, UR_FLIPPED, aTextePcb->GetTextPosition() );
|
2013-05-29 18:00:40 +00:00
|
|
|
else // set edit flag, for the current command
|
2012-05-30 17:38:52 +00:00
|
|
|
aTextePcb->SetFlags( IN_EDIT );
|
|
|
|
|
|
|
|
OnModify();
|
2012-11-24 23:23:36 +00:00
|
|
|
#ifdef USE_WX_OVERLAY
|
|
|
|
m_canvas->Refresh();
|
|
|
|
#endif
|
2012-05-30 17:38:52 +00:00
|
|
|
}
|