2009-11-04 20:46:53 +00:00
|
|
|
/*****************************************************/
|
|
|
|
/* Component library edit field manipulation code. */
|
|
|
|
/*****************************************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
|
|
|
#include "confirm.h"
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "program.h"
|
|
|
|
#include "general.h"
|
|
|
|
#include "protos.h"
|
2010-02-16 16:21:52 +00:00
|
|
|
#include "libeditframe.h"
|
2009-09-25 18:49:04 +00:00
|
|
|
#include "class_library.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2009-09-04 18:57:37 +00:00
|
|
|
static void ShowMoveField( WinEDA_DrawPanel* panel, wxDC* DC, bool erase );
|
2009-05-13 10:26:11 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
extern int m_unit;
|
2007-06-05 12:10:51 +00:00
|
|
|
static wxPoint StartCursor, LastTextPosition;
|
|
|
|
|
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
static void ExitMoveField( WinEDA_DrawPanel* Panel, wxDC* DC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-04-17 16:25:29 +00:00
|
|
|
Panel->ManageCurseur = NULL;
|
|
|
|
Panel->ForceCloseManageCurseur = NULL;
|
2009-09-25 18:49:04 +00:00
|
|
|
|
|
|
|
WinEDA_LibeditFrame* parent = ( WinEDA_LibeditFrame* ) Panel->GetParent();
|
|
|
|
|
|
|
|
if( parent == NULL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
LIB_DRAW_ITEM* item = parent->GetDrawItem();
|
|
|
|
|
|
|
|
if( item == NULL )
|
2008-11-24 06:53:43 +00:00
|
|
|
return;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-09-04 18:57:37 +00:00
|
|
|
wxPoint curpos = Panel->GetScreen()->m_Curseur;
|
|
|
|
|
2008-04-17 16:25:29 +00:00
|
|
|
Panel->GetScreen()->m_Curseur = StartCursor;
|
2008-11-24 06:53:43 +00:00
|
|
|
ShowMoveField( Panel, DC, TRUE );
|
2008-04-17 16:25:29 +00:00
|
|
|
Panel->GetScreen()->m_Curseur = curpos;
|
2009-09-25 18:49:04 +00:00
|
|
|
item->m_Flags = 0;
|
|
|
|
parent->SetDrawItem( NULL );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-08 13:19:28 +00:00
|
|
|
void WinEDA_LibeditFrame::StartMoveField( wxDC* DC, LIB_FIELD* field )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-11-24 06:53:43 +00:00
|
|
|
wxPoint startPos;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
if( ( m_component == NULL ) || ( field == NULL ) )
|
2008-11-24 06:53:43 +00:00
|
|
|
return;
|
2009-09-04 18:57:37 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
m_drawItem = field;
|
2008-04-17 16:25:29 +00:00
|
|
|
LastTextPosition = field->m_Pos;
|
2009-09-25 18:49:04 +00:00
|
|
|
m_drawItem->m_Flags |= IS_MOVED;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-04-17 16:25:29 +00:00
|
|
|
startPos.x = LastTextPosition.x;
|
|
|
|
startPos.y = -LastTextPosition.y;
|
2008-11-24 06:53:43 +00:00
|
|
|
DrawPanel->CursorOff( DC );
|
2008-04-17 16:25:29 +00:00
|
|
|
GetScreen()->m_Curseur = startPos;
|
|
|
|
DrawPanel->MouseToCursorSchema();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-04-17 16:25:29 +00:00
|
|
|
DrawPanel->ManageCurseur = ShowMoveField;
|
|
|
|
DrawPanel->ForceCloseManageCurseur = ExitMoveField;
|
2008-11-24 06:53:43 +00:00
|
|
|
DrawPanel->ManageCurseur( DrawPanel, DC, TRUE );
|
2008-04-17 16:25:29 +00:00
|
|
|
StartCursor = GetScreen()->m_Curseur;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
DrawPanel->CursorOn( DC );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
/*
|
|
|
|
* Routine to display text 'Field' on the move.
|
|
|
|
* Normally called by cursor management code.
|
|
|
|
*/
|
2008-11-24 06:53:43 +00:00
|
|
|
static void ShowMoveField( WinEDA_DrawPanel* panel, wxDC* DC, bool erase )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-09-25 18:49:04 +00:00
|
|
|
WinEDA_LibeditFrame* parent = (WinEDA_LibeditFrame*) panel->GetParent();
|
|
|
|
|
|
|
|
if( parent == NULL )
|
|
|
|
return;
|
|
|
|
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_FIELD* Field = (LIB_FIELD*) parent->GetDrawItem();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-09-22 12:27:57 +00:00
|
|
|
if( Field == NULL )
|
2008-11-24 06:53:43 +00:00
|
|
|
return;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
wxString text = Field->GetFullText( parent->GetUnit() );
|
2008-11-12 17:27:32 +00:00
|
|
|
|
2008-04-17 16:25:29 +00:00
|
|
|
if( erase )
|
2009-09-04 18:57:37 +00:00
|
|
|
Field->Draw( panel, DC, wxPoint( 0, 0 ), -1, g_XorMode, &text,
|
|
|
|
DefaultTransformMatrix );
|
2008-04-17 16:25:29 +00:00
|
|
|
|
|
|
|
LastTextPosition.x = panel->GetScreen()->m_Curseur.x;
|
2008-11-24 06:53:43 +00:00
|
|
|
LastTextPosition.y = -panel->GetScreen()->m_Curseur.y;
|
2008-04-17 16:25:29 +00:00
|
|
|
|
|
|
|
Field->m_Pos = LastTextPosition;
|
2009-09-04 18:57:37 +00:00
|
|
|
Field->Draw( panel, DC, wxPoint( 0, 0 ), -1, g_XorMode, &text,
|
|
|
|
DefaultTransformMatrix );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2009-10-08 13:19:28 +00:00
|
|
|
void WinEDA_LibeditFrame::PlaceField( wxDC* DC, LIB_FIELD* Field )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-11-24 06:53:43 +00:00
|
|
|
if( Field == NULL )
|
|
|
|
return;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-04-17 16:25:29 +00:00
|
|
|
Field->m_Flags = 0;
|
|
|
|
Field->m_Pos.x = GetScreen()->m_Curseur.x;
|
2008-11-24 06:53:43 +00:00
|
|
|
Field->m_Pos.y = -GetScreen()->m_Curseur.y;
|
|
|
|
DrawPanel->CursorOff( DC );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
wxString fieldText = Field->GetFullText( m_unit );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-09-04 18:57:37 +00:00
|
|
|
Field->Draw( DrawPanel, DC, wxPoint( 0, 0 ), -1, GR_DEFAULT_DRAWMODE,
|
|
|
|
&fieldText, DefaultTransformMatrix );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-09-04 18:57:37 +00:00
|
|
|
DrawPanel->CursorOn( DC );
|
2010-02-18 20:07:29 +00:00
|
|
|
OnModify( );
|
2008-04-17 16:25:29 +00:00
|
|
|
DrawPanel->ManageCurseur = NULL;
|
|
|
|
DrawPanel->ForceCloseManageCurseur = NULL;
|
2009-09-25 18:49:04 +00:00
|
|
|
m_drawItem = NULL;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-08 13:19:28 +00:00
|
|
|
void WinEDA_LibeditFrame::EditField( wxDC* DC, LIB_FIELD* Field )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-05-13 10:26:11 +00:00
|
|
|
wxString Text;
|
|
|
|
wxString title;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
if( Field == NULL )
|
|
|
|
return;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
switch( Field->m_FieldId )
|
|
|
|
{
|
|
|
|
case REFERENCE:
|
|
|
|
title = wxT( "Reference:" );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VALUE:
|
2009-05-13 10:26:11 +00:00
|
|
|
title = wxT( "Component Name / Value:" );
|
2008-11-24 06:53:43 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-04-17 16:25:29 +00:00
|
|
|
Text = Field->m_Text;
|
2009-09-04 18:57:37 +00:00
|
|
|
|
|
|
|
/* FIXME: Use wxTextEntry dialog here and check for cancel button. */
|
2008-11-24 06:53:43 +00:00
|
|
|
Get_Message( title, _( "Edit field" ), Text, this );
|
|
|
|
Text.Replace( wxT( " " ), wxT( "_" ) );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-10-21 20:02:25 +00:00
|
|
|
wxString fieldText = Field->GetFullText( m_unit );
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
/* If the value field is changed, this is equivalent to creating a new
|
|
|
|
* component from the old one. Check for an existing library entry of
|
|
|
|
* this "new" component and change the value only if there is no existing
|
|
|
|
* entry with the same name.
|
2009-05-13 10:26:11 +00:00
|
|
|
*/
|
2009-09-25 18:49:04 +00:00
|
|
|
if( Field->m_FieldId == VALUE && Text != Field->m_Text )
|
2009-05-13 10:26:11 +00:00
|
|
|
{
|
2009-09-14 13:24:17 +00:00
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
/* Test for an existing name in the current components alias list. */
|
2009-09-22 12:27:57 +00:00
|
|
|
if( Field->GetParent()->m_AliasList.Index( Text, false ) != wxNOT_FOUND )
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
|
|
|
msg.Printf( _( "The field name <%s> is an existing alias of the \
|
|
|
|
component <%s>.\nPlease choose another name that does not conflict with any \
|
|
|
|
names in the alias list." ),
|
2009-10-16 17:18:23 +00:00
|
|
|
GetChars( Text ),
|
|
|
|
GetChars( Field->GetParent()->GetName() ) );
|
2009-09-14 13:24:17 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Test for an existing entry in the library to prevent duplicate
|
|
|
|
* entry names.
|
|
|
|
*/
|
2009-09-25 18:49:04 +00:00
|
|
|
if( m_library && m_library->FindEntry( Text ) != NULL )
|
2009-05-13 10:26:11 +00:00
|
|
|
{
|
2009-09-14 13:24:17 +00:00
|
|
|
msg.Printf( _( "The field name <%s> conflicts with an existing \
|
|
|
|
entry in the component library <%s>.\nPlease choose another name that does \
|
|
|
|
not conflict with any library entries." ),
|
2009-10-16 17:18:23 +00:00
|
|
|
GetChars( Text ),
|
|
|
|
GetChars( m_library->GetName() ) );
|
2009-09-14 13:24:17 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
return;
|
2009-05-13 10:26:11 +00:00
|
|
|
}
|
|
|
|
|
2009-10-21 20:02:25 +00:00
|
|
|
Field->GetParent()->SetName( Text );
|
|
|
|
}
|
2009-09-04 18:57:37 +00:00
|
|
|
|
|
|
|
Field->Draw( DrawPanel, DC, wxPoint( 0, 0 ), -1, g_XorMode, &fieldText,
|
|
|
|
DefaultTransformMatrix );
|
2008-04-17 16:25:29 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
if( !Text.IsEmpty() )
|
2008-04-17 16:25:29 +00:00
|
|
|
{
|
2009-09-22 12:27:57 +00:00
|
|
|
SaveCopyInUndoList( Field->GetParent() );
|
2008-04-17 16:25:29 +00:00
|
|
|
Field->m_Text = Text;
|
|
|
|
}
|
2008-11-24 06:53:43 +00:00
|
|
|
else
|
2009-09-04 18:57:37 +00:00
|
|
|
{
|
2008-11-24 06:53:43 +00:00
|
|
|
DisplayError( this, _( "No new text: no change" ) );
|
2009-09-04 18:57:37 +00:00
|
|
|
}
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
fieldText = Field->GetFullText( m_unit );
|
2009-09-04 18:57:37 +00:00
|
|
|
int drawMode = g_XorMode;
|
2008-04-17 16:25:29 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
if( Field->m_Flags == 0 )
|
2009-09-04 18:57:37 +00:00
|
|
|
drawMode = GR_DEFAULT_DRAWMODE;
|
2008-04-17 16:25:29 +00:00
|
|
|
|
2009-09-04 18:57:37 +00:00
|
|
|
Field->Draw( DrawPanel, DC, wxPoint( 0, 0 ), -1, drawMode, &fieldText,
|
|
|
|
DefaultTransformMatrix );
|
2008-04-17 16:25:29 +00:00
|
|
|
|
2010-02-18 20:07:29 +00:00
|
|
|
OnModify( );
|
2009-09-14 13:24:17 +00:00
|
|
|
UpdateAliasSelectList();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2009-09-04 18:57:37 +00:00
|
|
|
/*
|
2009-11-04 20:46:53 +00:00
|
|
|
* Rotate a field horizontally or vertically.
|
|
|
|
*
|
|
|
|
* If a field is being edited, rotate.
|
|
|
|
* Otherwise rotate the field at the current cursor position.
|
2008-11-24 06:53:43 +00:00
|
|
|
*/
|
2009-10-08 13:19:28 +00:00
|
|
|
void WinEDA_LibeditFrame::RotateField( wxDC* DC, LIB_FIELD* Field )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
if( Field == NULL )
|
|
|
|
return;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2010-02-18 20:07:29 +00:00
|
|
|
OnModify( );
|
2008-11-24 06:53:43 +00:00
|
|
|
DrawPanel->CursorOff( DC );
|
|
|
|
GRSetDrawMode( DC, g_XorMode );
|
2009-09-04 18:57:37 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
wxString fieldText = Field->GetFullText( m_unit );
|
2009-09-04 18:57:37 +00:00
|
|
|
|
|
|
|
Field->Draw( DrawPanel, DC, wxPoint( 0, 0 ), -1, g_XorMode, &fieldText,
|
|
|
|
DefaultTransformMatrix );
|
2008-11-24 06:53:43 +00:00
|
|
|
|
|
|
|
if( Field->m_Orient )
|
|
|
|
Field->m_Orient = 0;
|
|
|
|
else
|
2009-10-01 14:17:47 +00:00
|
|
|
Field->m_Orient = 900;
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2009-09-04 18:57:37 +00:00
|
|
|
int drawMode = g_XorMode;
|
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
if( Field->m_Flags == 0 )
|
2009-09-04 18:57:37 +00:00
|
|
|
drawMode = GR_DEFAULT_DRAWMODE;
|
|
|
|
|
|
|
|
Field->Draw( DrawPanel, DC, wxPoint( 0, 0 ), -1, drawMode, &fieldText,
|
|
|
|
DefaultTransformMatrix );
|
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
DrawPanel->CursorOn( DC );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
LIB_DRAW_ITEM* WinEDA_LibeditFrame::LocateItemUsingCursor()
|
2007-12-11 16:41:43 +00:00
|
|
|
{
|
2009-09-25 18:49:04 +00:00
|
|
|
if( m_component == NULL )
|
2008-11-24 06:53:43 +00:00
|
|
|
return NULL;
|
2008-04-17 16:25:29 +00:00
|
|
|
|
2009-10-01 14:17:47 +00:00
|
|
|
if( ( m_drawItem == NULL ) || ( m_drawItem->m_Flags == 0 ) )
|
2009-05-13 10:26:11 +00:00
|
|
|
{
|
2009-10-01 14:17:47 +00:00
|
|
|
m_drawItem = m_component->LocateDrawItem( m_unit, m_convert,
|
|
|
|
TYPE_NOT_INIT,
|
|
|
|
GetScreen()->m_MousePosition );
|
|
|
|
|
|
|
|
if( m_drawItem == NULL )
|
|
|
|
m_drawItem = m_component->LocateDrawItem( m_unit, m_convert,
|
|
|
|
TYPE_NOT_INIT,
|
|
|
|
GetScreen()->m_Curseur );
|
2008-04-17 16:25:29 +00:00
|
|
|
}
|
2009-09-04 18:57:37 +00:00
|
|
|
|
2009-10-01 14:17:47 +00:00
|
|
|
return m_drawItem;
|
2007-12-11 16:41:43 +00:00
|
|
|
}
|