kicad/pcbnew/edtxtmod.cpp

269 lines
7.4 KiB
C++
Raw Normal View History

/********************/
/* Edi module text. */
/********************/
#include "fctsys.h"
#include "gr_basic.h"
#include "common.h"
#include "class_drawpanel.h"
#include "pcbnew.h"
#include "drawtxt.h"
#include "trigo.h"
#include "protos.h"
static void Show_MoveTexte_Module( WinEDA_DrawPanel* panel,
wxDC* DC,
bool erase );
2009-08-11 14:10:34 +00:00
static void AbortMoveTextModule( WinEDA_DrawPanel* Panel, wxDC* DC );
wxPoint MoveVector; // Move vector for move edge, exported
// to dialog_edit mod_text.cpp
static wxPoint TextInitialPosition; // Mouse cursor initial position for
// undo/abort move command
static int TextInitialOrientation; // module text initial orientation for
// undo/abort move+rot command+rot
/* Add a new graphical text to the active module (footprint)
* Note there always are 2 texts: reference and value.
* New texts have the member TEXTE_MODULE.m_Type set to TEXT_is_DIVERS
*/
TEXTE_MODULE* WinEDA_BasePcbFrame::CreateTextModule( MODULE* Module, wxDC* DC )
{
TEXTE_MODULE* Text;
Text = new TEXTE_MODULE( Module );
/* Add the new text object to the beginning of the draw item list. */
2009-08-11 10:27:21 +00:00
if( Module )
Module->m_Drawings.PushFront( Text );
Text->m_Flags = IS_NEW;
Text->m_Text = wxT( "text" );
2010-07-20 18:11:34 +00:00
g_ModuleTextWidth = Clamp_Text_PenSize( g_ModuleTextWidth,
MIN( g_ModuleTextSize.x,
g_ModuleTextSize.y ), true );
Text->m_Size = g_ModuleTextSize;
Text->m_Thickness = g_ModuleTextWidth;
Text->m_Pos = GetScreen()->m_Curseur;
Text->SetLocalCoord();
2009-08-11 10:27:21 +00:00
InstallTextModOptionsFrame( Text, NULL );
DrawPanel->MouseToCursorSchema();
Text->m_Flags = 0;
2009-08-11 10:27:21 +00:00
if( DC )
Text->Draw( DrawPanel, DC, GR_OR );
Text->DisplayInfo( this );
return Text;
}
/* Rotate text 90 degrees.
*/
void WinEDA_BasePcbFrame::RotateTextModule( TEXTE_MODULE* Text, wxDC* DC )
{
if( Text == NULL )
return;
MODULE* module = (MODULE*) Text->GetParent();
if( module && module->m_Flags == 0 && Text->m_Flags == 0 ) // prepare undo
// command
{
2009-08-11 10:27:21 +00:00
if( this->m_Ident == PCB_FRAME )
SaveCopyInUndoList( module, UR_CHANGED );
2009-08-11 10:27:21 +00:00
}
2008-04-29 03:18:02 +00:00
// we expect MoveVector to be (0,0) if there is no move in progress
Text->Draw( DrawPanel, DC, GR_XOR, MoveVector );
Text->m_Orient += 900;
while( Text->m_Orient >= 1800 )
Text->m_Orient -= 1800;
2008-04-29 03:18:02 +00:00
Text->Draw( DrawPanel, DC, GR_XOR, MoveVector );
Text->DisplayInfo( this );
2009-08-11 10:27:21 +00:00
if( module )
module->m_LastEdit_Time = time( NULL );
OnModify();
}
/*
* Deletes text in module (if not the reference or value)
*/
void WinEDA_BasePcbFrame::DeleteTextModule( TEXTE_MODULE* Text )
{
MODULE* Module;
if( Text == NULL )
return;
Module = (MODULE*) Text->GetParent();
if( Text->m_Type == TEXT_is_DIVERS )
{
2008-04-29 03:18:02 +00:00
DrawPanel->PostDirtyRect( Text->GetBoundingBox() );
Text->DeleteStructure();
OnModify();
Module->m_LastEdit_Time = time( NULL );
}
}
/*
* Abort text move in progress.
*
* If a text is selected, its initial coordinates are regenerated.
*/
static void AbortMoveTextModule( WinEDA_DrawPanel* Panel, wxDC* DC )
{
BASE_SCREEN* screen = Panel->GetScreen();
TEXTE_MODULE* Text = (TEXTE_MODULE*) screen->GetCurItem();
MODULE* Module;
Panel->ManageCurseur = NULL;
Panel->ForceCloseManageCurseur = NULL;
if( Text == NULL )
return;
Module = (MODULE*) Text->GetParent();
2008-04-29 03:18:02 +00:00
Text->DrawUmbilical( Panel, DC, GR_XOR, -MoveVector );
2008-04-01 05:21:50 +00:00
Text->Draw( Panel, DC, GR_XOR, MoveVector );
2009-08-11 14:10:34 +00:00
// If the text was moved (the move does not change internal data)
// it could be rotated while moving. So set old value for orientation
if( (Text->m_Flags & IS_MOVED) )
2009-08-11 14:10:34 +00:00
Text->m_Orient = TextInitialOrientation;
/* Redraw the text */
2008-04-29 03:18:02 +00:00
Panel->PostDirtyRect( Text->GetBoundingBox() );
// leave it at (0,0) so we can use it Rotate when not moving.
MoveVector.x = MoveVector.y = 0;
Text->m_Flags = 0;
Module->m_Flags = 0;
screen->SetCurItem( NULL );
}
/* Start a text move.
*/
void WinEDA_BasePcbFrame::StartMoveTexteModule( TEXTE_MODULE* Text, wxDC* DC )
{
MODULE* Module;
if( Text == NULL )
return;
Module = (MODULE*) Text->GetParent();
Text->m_Flags |= IS_MOVED;
Module->m_Flags |= IN_EDIT;
MoveVector.x = MoveVector.y = 0;
2008-04-29 03:18:02 +00:00
DrawPanel->CursorOff( DC );
TextInitialPosition = Text->m_Pos;
2009-08-11 10:27:21 +00:00
TextInitialOrientation = Text->m_Orient;
// Center cursor on initial position of text
GetScreen()->m_Curseur = TextInitialPosition;
DrawPanel->MouseToCursorSchema();
DrawPanel->CursorOn( DC );
Text->DisplayInfo( this );
SetCurItem( Text );
DrawPanel->ManageCurseur = Show_MoveTexte_Module;
2009-08-11 14:10:34 +00:00
DrawPanel->ForceCloseManageCurseur = AbortMoveTextModule;
DrawPanel->ManageCurseur( DrawPanel, DC, TRUE );
}
/* Place the text a the cursor position when the left mouse button is clicked.
*/
void WinEDA_BasePcbFrame::PlaceTexteModule( TEXTE_MODULE* Text, wxDC* DC )
{
if( Text != NULL )
{
2008-04-29 03:18:02 +00:00
DrawPanel->PostDirtyRect( Text->GetBoundingBox() );
Text->DrawUmbilical( DrawPanel, DC, GR_XOR, -MoveVector );
2008-04-29 03:18:02 +00:00
/* Update the coordinates for anchor. */
MODULE* Module = (MODULE*) Text->GetParent();
if( Module )
{
2009-08-11 14:10:34 +00:00
// Prepare undo command (a rotation can be made while moving)
EXCHG( Text->m_Orient, TextInitialOrientation );
2009-08-11 10:27:21 +00:00
if( m_Ident == PCB_FRAME )
SaveCopyInUndoList( Module, UR_CHANGED );
2009-08-11 14:10:34 +00:00
else
SaveCopyInUndoList( Module, UR_MODEDIT );
EXCHG( Text->m_Orient, TextInitialOrientation );
2009-08-11 14:10:34 +00:00
// Set the new position for text.
Text->m_Pos = GetScreen()->m_Curseur;
2009-08-11 10:27:21 +00:00
wxPoint textRelPos = Text->m_Pos - Module->m_Pos;
RotatePoint( &textRelPos, -Module->m_Orient );
Text->m_Pos0 = textRelPos;
Text->m_Flags = 0;
Module->m_Flags = 0;
Module->m_LastEdit_Time = time( NULL );
OnModify();
/* Redraw text. */
2008-04-29 03:18:02 +00:00
DrawPanel->PostDirtyRect( Text->GetBoundingBox() );
}
2009-08-11 14:10:34 +00:00
else
Text->m_Pos = GetScreen()->m_Curseur;
}
2008-04-29 03:18:02 +00:00
// leave it at (0,0) so we can use it Rotate when not moving.
MoveVector.x = MoveVector.y = 0;
DrawPanel->ManageCurseur = NULL;
DrawPanel->ForceCloseManageCurseur = NULL;
}
static void Show_MoveTexte_Module( WinEDA_DrawPanel* panel, wxDC* DC,
bool erase )
{
BASE_SCREEN* screen = panel->GetScreen();
TEXTE_MODULE* Text = (TEXTE_MODULE*) screen->GetCurItem();
if( Text == NULL )
return;
// Erase umbilical and text if necessary
if( erase )
{
Text->DrawUmbilical( panel, DC, GR_XOR, -MoveVector );
2008-04-01 05:21:50 +00:00
Text->Draw( panel, DC, GR_XOR, MoveVector );
}
2009-08-11 10:27:21 +00:00
MoveVector = TextInitialPosition - screen->m_Curseur;
// Draw umbilical if text moved
if( MoveVector.x || MoveVector.y )
Text->DrawUmbilical( panel, DC, GR_XOR, -MoveVector );
// Redraw text
2008-04-01 05:21:50 +00:00
Text->Draw( panel, DC, GR_XOR, MoveVector );
}