2011-12-29 20:11:42 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
|
|
|
|
* Copyright (C) 1992-2011 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
|
|
|
|
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>
|
2008-12-20 17:28:25 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <protos.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;
|
|
|
|
|
|
|
|
TextePcb->Draw( Panel, DC, GR_XOR );
|
|
|
|
|
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
|
|
|
|
|
|
|
SwapData(TextePcb, &s_TextCopy);
|
2011-12-21 13:42:02 +00:00
|
|
|
TextePcb->ClearFlags();
|
2010-03-09 09:51:22 +00:00
|
|
|
TextePcb->Draw( Panel, DC, GR_OR );
|
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
|
|
|
|
{
|
2011-02-11 20:48:13 +00:00
|
|
|
SaveCopyInUndoList( TextePcb, UR_MOVED, TextePcb->m_Pos - s_TextCopy.m_Pos );
|
2011-12-21 13:42:02 +00:00
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
|
2011-12-21 13:42:02 +00:00
|
|
|
TextePcb->ClearFlags();
|
2008-12-20 17:28:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Initialize parameters to move a pcb text
|
2008-12-20 17:28:25 +00:00
|
|
|
*/
|
2011-03-01 19:26:17 +00:00
|
|
|
void PCB_EDIT_FRAME::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
|
2011-02-21 13:54:29 +00:00
|
|
|
if( !TextePcb->IsNew() )
|
2009-08-03 07:55:08 +00:00
|
|
|
s_TextCopy.Copy( TextePcb );
|
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
TextePcb->Draw( m_canvas, DC, GR_XOR );
|
2011-12-21 13:42:02 +00:00
|
|
|
TextePcb->SetFlags( IS_MOVED );
|
2009-04-17 08:51:02 +00:00
|
|
|
TextePcb->DisplayInfo( this );
|
2011-07-04 21:32:49 +00:00
|
|
|
|
|
|
|
GetScreen()->SetCrossHairPosition( TextePcb->GetPosition() );
|
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 );
|
2008-12-20 17:28:25 +00:00
|
|
|
SetCurItem( TextePcb );
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
|
2008-12-20 17:28:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-14 22:15:22 +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
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
TextePcb->m_Pos = aPanel->GetScreen()->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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
TEXTE_PCB* PCB_EDIT_FRAME::Create_Texte_Pcb( wxDC* DC )
|
2008-12-20 17:28:25 +00:00
|
|
|
{
|
|
|
|
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. */
|
2011-12-21 13:42:02 +00:00
|
|
|
TextePcb->SetFlags( IS_NEW );
|
2009-08-03 07:55:08 +00:00
|
|
|
TextePcb->SetLayer( ( (PCB_SCREEN*) GetScreen() )->m_Active_Layer );
|
2008-12-20 20:38:39 +00:00
|
|
|
TextePcb->m_Mirror = false;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
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
|
|
|
|
++PCBNew
* Removed Pcb_Frame argument from BOARD() constructor, since it precludes
having a BOARD being edited by more than one editor, it was a bad design.
And this meant removing m_PcbFrame from BOARD.
* removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame
* Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp
* added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance
* a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed,
such as dialog_mask_clearance, dialog_drc, etc.
* Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it
with build_version.h's #define BOARD_FILE_VERSION, although there may be a
better place for this constant.
* Made the public functions in PARAM_CFG_ARRAY be type const.
void SaveParam(..) const and void ReadParam(..) const
* PARAM_CFG_BASE now has virtual destructor since we have various way of
destroying the derived class and boost::ptr_vector must be told about this.
* Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use
an automatic PARAM_CFG_ARRAY which is on the stack.\
* PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array,
since it has to access the current BOARD and the BOARD can change.
Remember BOARD_DESIGN_SETTINGS are now in the BOARD.
* Made the m_BoundingBox member private, this was a brutally hard task,
and indicative of the lack of commitment to accessors and object oriented
design on the part of KiCad developers. We must do better.
Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox().
* Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
|
|
|
TextePcb->m_Size = GetBoard()->GetDesignSettings().m_PcbTextSize;
|
2011-02-11 20:48:13 +00:00
|
|
|
TextePcb->m_Pos = GetScreen()->GetCrossHairPosition();
|
++PCBNew
* Removed Pcb_Frame argument from BOARD() constructor, since it precludes
having a BOARD being edited by more than one editor, it was a bad design.
And this meant removing m_PcbFrame from BOARD.
* removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame
* Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp
* added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance
* a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed,
such as dialog_mask_clearance, dialog_drc, etc.
* Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it
with build_version.h's #define BOARD_FILE_VERSION, although there may be a
better place for this constant.
* Made the public functions in PARAM_CFG_ARRAY be type const.
void SaveParam(..) const and void ReadParam(..) const
* PARAM_CFG_BASE now has virtual destructor since we have various way of
destroying the derived class and boost::ptr_vector must be told about this.
* Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use
an automatic PARAM_CFG_ARRAY which is on the stack.\
* PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array,
since it has to access the current BOARD and the BOARD can change.
Remember BOARD_DESIGN_SETTINGS are now in the BOARD.
* Made the m_BoundingBox member private, this was a brutally hard task,
and indicative of the lack of commitment to accessors and object oriented
design on the part of KiCad developers. We must do better.
Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox().
* Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
|
|
|
TextePcb->m_Thickness = GetBoard()->GetDesignSettings().m_PcbTextWidth;
|
2008-12-20 17:28:25 +00:00
|
|
|
|
|
|
|
InstallTextPCBOptionsFrame( TextePcb, DC );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2008-12-20 17:28:25 +00:00
|
|
|
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
|
2011-09-07 19:41:04 +00:00
|
|
|
{
|
2008-12-20 17:28:25 +00:00
|
|
|
StartMoveTextePcb( TextePcb, DC );
|
2011-09-07 19:41:04 +00:00
|
|
|
}
|
2008-12-20 17:28:25 +00:00
|
|
|
|
|
|
|
return TextePcb;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
int drawmode = GR_XOR;
|
|
|
|
|
|
|
|
if( TextePcb == NULL )
|
|
|
|
return;
|
|
|
|
|
2009-11-14 22:15:22 +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
|
|
|
|
|
|
|
TextePcb->m_Orient += angle;
|
2011-01-05 17:28:55 +00:00
|
|
|
NORMALIZE_ANGLE_POS( TextePcb->m_Orient );
|
2008-12-20 17:28:25 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Redraw text in new position. */
|
2011-12-22 13:28:11 +00:00
|
|
|
TextePcb->Draw( m_canvas, DC, drawmode );
|
2009-04-17 08:51:02 +00:00
|
|
|
TextePcb->DisplayInfo( this );
|
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
|
2009-08-03 07:55:08 +00:00
|
|
|
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
|
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();
|
2008-12-20 17:28:25 +00:00
|
|
|
}
|