2007-08-20 01:20:48 +00:00
|
|
|
/********************************/
|
2011-04-08 17:41:52 +00:00
|
|
|
/* Schematic component edition */
|
2007-08-20 01:20:48 +00:00
|
|
|
/********************************/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
|
|
|
#include "confirm.h"
|
2010-11-10 15:30:12 +00:00
|
|
|
#include "class_sch_screen.h"
|
|
|
|
#include "wxEeschemaStruct.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
#include "general.h"
|
|
|
|
#include "protos.h"
|
2009-09-25 18:49:04 +00:00
|
|
|
#include "class_library.h"
|
2010-11-11 21:10:27 +00:00
|
|
|
#include "sch_component.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
|
2011-03-29 15:21:35 +00:00
|
|
|
/*
|
|
|
|
* Move standard text field. This routine is normally attached to the cursor.
|
2009-11-03 13:26:31 +00:00
|
|
|
*/
|
2011-03-29 15:21:35 +00:00
|
|
|
static void moveField( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, bool aErase )
|
2010-04-27 19:19:04 +00:00
|
|
|
{
|
2011-03-29 15:21:35 +00:00
|
|
|
wxPoint pos;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-03-29 15:21:35 +00:00
|
|
|
SCH_EDIT_FRAME* frame = (SCH_EDIT_FRAME*) aPanel->GetParent();
|
2011-04-08 17:41:52 +00:00
|
|
|
SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen();
|
|
|
|
SCH_FIELD* currentField = (SCH_FIELD*)screen->GetCurItem();
|
2011-03-29 15:21:35 +00:00
|
|
|
|
2011-04-08 17:41:52 +00:00
|
|
|
if( (currentField == NULL) || (currentField->Type() != SCH_FIELD_T) )
|
2007-08-20 01:20:48 +00:00
|
|
|
return;
|
|
|
|
|
2011-03-29 15:21:35 +00:00
|
|
|
SCH_COMPONENT* component = (SCH_COMPONENT*) currentField->GetParent();
|
|
|
|
|
|
|
|
currentField->m_AddExtraText = frame->m_Multiflag;
|
|
|
|
|
|
|
|
if( aErase )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-03-29 15:21:35 +00:00
|
|
|
currentField->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
|
|
|
|
}
|
|
|
|
|
|
|
|
pos = ( (SCH_COMPONENT*) currentField->GetParent() )->m_Pos;
|
|
|
|
|
|
|
|
// Actual positions are calculated by the rotation/mirror transform
|
|
|
|
// But here we want the relative position of the moved field
|
|
|
|
// and we know the actual position.
|
|
|
|
// So we are using the inverse rotation/mirror transform.
|
2011-04-08 17:41:52 +00:00
|
|
|
wxPoint pt( screen->GetCrossHairPosition() - pos );
|
2011-03-29 15:21:35 +00:00
|
|
|
|
|
|
|
TRANSFORM itrsfm = component->GetTransform().InverseTransform();
|
|
|
|
currentField->m_Pos = pos + itrsfm.TransformCoordinate( pt );
|
|
|
|
|
|
|
|
currentField->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void abortMoveField( EDA_DRAW_PANEL* aPanel, wxDC* aDC )
|
|
|
|
{
|
|
|
|
SCH_EDIT_FRAME* frame = (SCH_EDIT_FRAME*) aPanel->GetParent();
|
2011-04-08 17:41:52 +00:00
|
|
|
SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen();
|
|
|
|
SCH_FIELD* currentField = (SCH_FIELD*) screen->GetCurItem();
|
2011-03-29 15:21:35 +00:00
|
|
|
|
|
|
|
if( currentField )
|
|
|
|
{
|
|
|
|
currentField->m_AddExtraText = frame->m_Multiflag;
|
|
|
|
currentField->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
|
2011-04-08 17:41:52 +00:00
|
|
|
currentField->ClearFlags();
|
2011-03-29 15:21:35 +00:00
|
|
|
currentField->m_Pos = frame->m_OldPos;
|
2011-04-08 17:41:52 +00:00
|
|
|
currentField->Draw( aPanel, aDC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2011-04-08 17:41:52 +00:00
|
|
|
screen->SetCurItem( NULL );
|
2011-03-29 15:21:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_EDIT_FRAME::MoveField( SCH_FIELD* aField, wxDC* aDC )
|
|
|
|
{
|
|
|
|
wxCHECK_RET( aField && (aField->Type() == SCH_FIELD_T) && !aField->GetText().IsEmpty(),
|
|
|
|
wxT( "Cannot move invalid component field." ) );
|
|
|
|
|
|
|
|
LIB_COMPONENT* libEntry;
|
2009-11-03 13:26:31 +00:00
|
|
|
wxPoint pos, newpos;
|
2008-11-24 06:53:43 +00:00
|
|
|
SCH_COMPONENT* comp = (SCH_COMPONENT*) aField->GetParent();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-04-08 17:41:52 +00:00
|
|
|
GetScreen()->SetCurItem( aField );
|
2011-04-05 14:46:51 +00:00
|
|
|
SetUndoItem( comp );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
pos = comp->m_Pos;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-01-19 10:34:56 +00:00
|
|
|
/* Positions are computed by the rotation/mirror transform. */
|
2009-01-02 13:19:34 +00:00
|
|
|
newpos = aField->m_Pos - pos;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-12-14 21:39:31 +00:00
|
|
|
newpos = comp->GetTransform().TransformCoordinate( newpos ) + pos;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-03-29 15:21:35 +00:00
|
|
|
DrawPanel->CrossHairOff( aDC );
|
2011-02-11 20:48:13 +00:00
|
|
|
GetScreen()->SetCrossHairPosition( newpos );
|
|
|
|
DrawPanel->MoveCursorToCrossHair();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-04-08 17:41:52 +00:00
|
|
|
m_OldPos = aField->m_Pos;
|
2008-11-24 06:53:43 +00:00
|
|
|
m_Multiflag = 0;
|
2011-03-29 15:21:35 +00:00
|
|
|
|
|
|
|
if( aField->GetId() == REFERENCE )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-03-29 15:21:35 +00:00
|
|
|
libEntry = CMP_LIBRARY::FindLibraryComponent( comp->GetLibName() );
|
2009-08-27 11:41:56 +00:00
|
|
|
|
2011-03-29 15:21:35 +00:00
|
|
|
if( (libEntry != NULL) && (libEntry->GetPartCount() > 1) )
|
|
|
|
m_Multiflag = 1;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2011-03-29 15:21:35 +00:00
|
|
|
DrawPanel->SetMouseCapture( moveField, abortMoveField );
|
|
|
|
aField->SetFlags( IS_MOVED );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-03-29 15:21:35 +00:00
|
|
|
DrawPanel->CrossHairOn( aDC );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
void SCH_EDIT_FRAME::EditComponentFieldText( SCH_FIELD* aField, wxDC* aDC )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-03-25 19:16:05 +00:00
|
|
|
wxCHECK_RET( aField != NULL && aField->Type() == SCH_FIELD_T,
|
2011-03-29 15:21:35 +00:00
|
|
|
wxT( "Cannot edit invalid schematic field." ) );
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
int fieldNdx, flag;
|
2011-03-25 19:16:05 +00:00
|
|
|
SCH_COMPONENT* component = (SCH_COMPONENT*) aField->GetParent();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
wxCHECK_RET( component != NULL && component->Type() == SCH_COMPONENT_T,
|
|
|
|
wxT( "Invalid schematic field parent item." ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
LIB_COMPONENT* entry = CMP_LIBRARY::FindLibraryComponent( component->GetLibName() );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
wxCHECK_RET( entry != NULL, wxT( "Library entry for component <" ) +
|
|
|
|
component->GetLibName() + wxT( "> could not be found." ) );
|
2010-12-07 16:10:42 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
fieldNdx = aField->GetId();
|
2009-08-27 11:41:56 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
if( fieldNdx == VALUE && entry->IsPower() )
|
|
|
|
{
|
2011-03-29 15:21:35 +00:00
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "%s is a power component and it's value cannot be modified!\n\nYou must \
|
|
|
|
create a new power component with the new value." ), GetChars( entry->GetName() ) );
|
|
|
|
DisplayInfoMessage( this, msg );
|
2011-03-25 19:16:05 +00:00
|
|
|
return;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
flag = 0;
|
2009-08-27 11:41:56 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
if( fieldNdx == REFERENCE && entry->GetPartCount() > 1 )
|
|
|
|
flag = 1;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-03-29 15:21:35 +00:00
|
|
|
// Save old component in undo list if not already in edit, or moving.
|
2011-03-25 19:16:05 +00:00
|
|
|
if( aField->GetFlags() == 0 )
|
|
|
|
SaveCopyInUndoList( component, UR_CHANGED );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
wxString newtext = aField->m_Text;
|
|
|
|
DrawPanel->m_IgnoreMouseEvents = true;
|
2010-07-20 10:30:40 +00:00
|
|
|
|
2011-03-29 15:21:35 +00:00
|
|
|
wxString title;
|
|
|
|
title.Printf( _( "Edit %s Field" ), GetChars( aField->m_Name ) );
|
|
|
|
|
2011-01-21 14:19:06 +00:00
|
|
|
wxTextEntryDialog dlg( this, wxEmptyString , title, newtext );
|
2011-03-29 15:21:35 +00:00
|
|
|
int response = dlg.ShowModal();
|
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
DrawPanel->MoveCursorToCrossHair();
|
|
|
|
DrawPanel->m_IgnoreMouseEvents = false;
|
2010-07-20 10:30:40 +00:00
|
|
|
newtext = dlg.GetValue( );
|
2010-07-21 08:15:54 +00:00
|
|
|
newtext.Trim( true );
|
|
|
|
newtext.Trim( false );
|
2010-07-20 10:30:40 +00:00
|
|
|
|
2011-03-29 15:21:35 +00:00
|
|
|
if ( response != wxID_OK || newtext == aField->GetText() )
|
|
|
|
return; // canceled by user
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
aField->m_AddExtraText = flag;
|
|
|
|
aField->Draw( DrawPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
if( !newtext.IsEmpty() )
|
|
|
|
{
|
2011-06-01 08:45:34 +00:00
|
|
|
if( aField->m_Text.IsEmpty() ) // Means the field was not already in use
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-03-25 19:16:05 +00:00
|
|
|
aField->m_Pos = component->m_Pos;
|
|
|
|
aField->m_Size.x = aField->m_Size.y = m_TextFieldSize;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
if( fieldNdx == REFERENCE )
|
|
|
|
{
|
2011-05-31 16:29:14 +00:00
|
|
|
// Test is reference is acceptable:
|
|
|
|
if( SCH_COMPONENT::IsReferenceStringValid( newtext ) )
|
|
|
|
{
|
|
|
|
component->SetRef( GetSheet(), newtext );
|
|
|
|
aField->m_Text = newtext;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DisplayError( this, _( "Illegal reference string! No change" ) );
|
|
|
|
}
|
2008-03-20 01:50:21 +00:00
|
|
|
}
|
2011-06-01 08:45:34 +00:00
|
|
|
else
|
|
|
|
aField->m_Text = newtext;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2009-11-03 13:26:31 +00:00
|
|
|
else
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2008-11-24 06:53:43 +00:00
|
|
|
if( fieldNdx == REFERENCE )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-03-25 19:16:05 +00:00
|
|
|
DisplayError( this, _( "The reference field cannot be empty! No change" ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2008-11-24 06:53:43 +00:00
|
|
|
else if( fieldNdx == VALUE )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-03-25 19:16:05 +00:00
|
|
|
DisplayError( this, _( "The value field cannot be empty! No change" ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-03-25 19:16:05 +00:00
|
|
|
aField->m_Text = wxT( "~" );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
aField->Draw( DrawPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
|
|
|
|
component->DisplayInfo( this );
|
2010-04-27 19:19:04 +00:00
|
|
|
OnModify();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-29 15:21:35 +00:00
|
|
|
void SCH_EDIT_FRAME::RotateField( SCH_FIELD* aField, wxDC* aDC )
|
2010-04-27 19:19:04 +00:00
|
|
|
{
|
2011-03-29 15:21:35 +00:00
|
|
|
wxCHECK_RET( aField != NULL && aField->Type() == SCH_FIELD_T && !aField->GetText().IsEmpty(),
|
|
|
|
wxT( "Cannot rotate invalid schematic field." ) );
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
int flag = 0;
|
2011-03-29 15:21:35 +00:00
|
|
|
LIB_COMPONENT* libEntry;
|
|
|
|
SCH_COMPONENT* component = (SCH_COMPONENT*) aField->GetParent();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-03-29 15:21:35 +00:00
|
|
|
if( aField->GetId() == REFERENCE )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-03-29 15:21:35 +00:00
|
|
|
libEntry = CMP_LIBRARY::FindLibraryComponent( component->GetLibName() );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-03-29 15:21:35 +00:00
|
|
|
if( (libEntry != NULL) && (libEntry->GetPartCount() > 1) )
|
|
|
|
flag = 1;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2011-03-29 15:21:35 +00:00
|
|
|
// Save old component in undo list if not already in edit, or moving.
|
|
|
|
if( aField->GetFlags() == 0 )
|
|
|
|
SaveCopyInUndoList( component, UR_CHANGED );
|
2008-10-06 05:44:29 +00:00
|
|
|
|
2011-03-29 15:21:35 +00:00
|
|
|
aField->m_AddExtraText = flag;
|
|
|
|
aField->Draw( DrawPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
|
2008-10-06 05:44:29 +00:00
|
|
|
|
2011-03-29 15:21:35 +00:00
|
|
|
if( aField->m_Orient == TEXT_ORIENT_HORIZ )
|
|
|
|
aField->m_Orient = TEXT_ORIENT_VERT;
|
|
|
|
else
|
|
|
|
aField->m_Orient = TEXT_ORIENT_HORIZ;
|
2008-03-20 01:50:21 +00:00
|
|
|
|
2011-03-29 15:21:35 +00:00
|
|
|
aField->Draw( DrawPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
|
2008-03-20 01:50:21 +00:00
|
|
|
|
2010-05-23 17:39:47 +00:00
|
|
|
OnModify();
|
2007-12-11 16:41:43 +00:00
|
|
|
}
|