2011-01-15 18:06:10 +00:00
|
|
|
/**
|
|
|
|
* @file dialog_edit_component_in_schematic.cpp
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
#include <wx/tooltip.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <appl_wxstruct.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <class_sch_screen.h>
|
|
|
|
#include <wxEeschemaStruct.h>
|
2012-04-13 18:51:24 +00:00
|
|
|
#include <base_units.h>
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <general.h>
|
|
|
|
#include <class_library.h>
|
|
|
|
#include <sch_component.h>
|
|
|
|
#include <dialog_helpers.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <dialog_edit_component_in_schematic.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2008-11-26 00:20:16 +00:00
|
|
|
int DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::s_SelectedRow;
|
2009-01-29 17:30:38 +00:00
|
|
|
wxSize DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::s_LastSize = wxDefaultSize;
|
2009-01-29 08:58:48 +00:00
|
|
|
|
|
|
|
|
2011-08-30 19:24:28 +00:00
|
|
|
void SCH_EDIT_FRAME::EditComponent( SCH_COMPONENT* aComponent )
|
2008-11-24 06:53:43 +00:00
|
|
|
{
|
2011-08-30 19:24:28 +00:00
|
|
|
wxCHECK_RET( aComponent != NULL && aComponent->Type() == SCH_COMPONENT_T,
|
|
|
|
wxT( "Invalid component object pointer. Bad Programmer!" ) );
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->SetIgnoreMouseEvents( true );
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2011-08-30 19:24:28 +00:00
|
|
|
DIALOG_EDIT_COMPONENT_IN_SCHEMATIC* dlg = new DIALOG_EDIT_COMPONENT_IN_SCHEMATIC( this );
|
2009-01-29 08:58:48 +00:00
|
|
|
|
2011-04-19 16:30:28 +00:00
|
|
|
dlg->InitBuffers( aComponent );
|
2009-01-29 17:30:38 +00:00
|
|
|
|
2011-04-19 16:30:28 +00:00
|
|
|
wxSize sizeNow = dlg->GetSize();
|
2009-01-29 08:58:48 +00:00
|
|
|
|
2011-02-02 19:01:21 +00:00
|
|
|
// this relies on wxDefaultSize being -1,-1, be careful here.
|
|
|
|
if( sizeNow.GetWidth() < DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::s_LastSize.GetWidth()
|
|
|
|
|| sizeNow.GetHeight() < DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::s_LastSize.GetHeight() )
|
|
|
|
{
|
2011-04-19 16:30:28 +00:00
|
|
|
dlg->SetSize( DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::s_LastSize );
|
2011-02-02 19:01:21 +00:00
|
|
|
}
|
2009-01-29 08:58:48 +00:00
|
|
|
|
2011-08-30 19:24:28 +00:00
|
|
|
// make sure the chipnameTextCtrl is wide enough to hold any unusually long chip names:
|
2011-04-19 16:30:28 +00:00
|
|
|
EnsureTextCtrlWidth( dlg->chipnameTextCtrl );
|
2008-11-24 21:06:50 +00:00
|
|
|
|
2011-04-19 16:30:28 +00:00
|
|
|
dlg->ShowModal();
|
2009-01-29 08:58:48 +00:00
|
|
|
|
2011-02-02 19:01:21 +00:00
|
|
|
// Some of the field values are long and are not always fully visible because the
|
|
|
|
// window comes up too narrow. Remember user's manual window resizing efforts here
|
|
|
|
// so it comes up wide enough next time.
|
2011-04-19 16:30:28 +00:00
|
|
|
DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::s_LastSize = dlg->GetSize();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->SetIgnoreMouseEvents( false );
|
2011-04-19 16:30:28 +00:00
|
|
|
dlg->Destroy();
|
2008-11-24 06:53:43 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-12-31 09:27:19 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::DIALOG_EDIT_COMPONENT_IN_SCHEMATIC( wxWindow* parent ) :
|
|
|
|
DIALOG_EDIT_COMPONENT_IN_SCHEMATIC_FBP( parent )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
m_Parent = (SCH_EDIT_FRAME*) parent;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-12-04 20:53:11 +00:00
|
|
|
m_LibEntry = NULL;
|
2008-11-26 06:25:20 +00:00
|
|
|
m_skipCopyFromPanel = false;
|
2008-11-24 21:06:50 +00:00
|
|
|
|
2008-12-31 09:27:19 +00:00
|
|
|
wxListItem columnLabel;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-12-31 09:27:19 +00:00
|
|
|
columnLabel.SetImage( -1 );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-12-31 09:27:19 +00:00
|
|
|
columnLabel.SetText( _( "Name" ) );
|
2008-11-24 21:06:50 +00:00
|
|
|
fieldListCtrl->InsertColumn( 0, columnLabel );
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2008-12-31 09:27:19 +00:00
|
|
|
columnLabel.SetText( _( "Value" ) );
|
2008-11-24 21:06:50 +00:00
|
|
|
fieldListCtrl->InsertColumn( 1, columnLabel );
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2010-07-12 14:07:09 +00:00
|
|
|
wxString label = _( "Size" ) + ReturnUnitSymbol( g_UserUnit );
|
2008-11-26 00:20:16 +00:00
|
|
|
textSizeLabel->SetLabel( label );
|
|
|
|
|
2008-12-31 09:27:19 +00:00
|
|
|
label = _( "Pos " );
|
2008-11-26 00:20:16 +00:00
|
|
|
label += _( "X" );
|
2010-07-12 14:07:09 +00:00
|
|
|
label += ReturnUnitSymbol( g_UserUnit );
|
2008-11-26 00:20:16 +00:00
|
|
|
posXLabel->SetLabel( label );
|
|
|
|
|
2008-12-31 09:27:19 +00:00
|
|
|
label = _( "Pos " );
|
2008-11-26 00:20:16 +00:00
|
|
|
label += _( "Y" );
|
2010-07-12 14:07:09 +00:00
|
|
|
label += ReturnUnitSymbol( g_UserUnit );
|
2008-11-26 00:20:16 +00:00
|
|
|
posYLabel->SetLabel( label );
|
2008-11-24 21:06:50 +00:00
|
|
|
|
|
|
|
copySelectedFieldToPanel();
|
2008-11-24 06:53:43 +00:00
|
|
|
|
|
|
|
wxToolTip::Enable( true );
|
2009-07-26 17:16:42 +00:00
|
|
|
|
2011-09-22 19:16:55 +00:00
|
|
|
GetSizer()->SetSizeHints( this );
|
|
|
|
Center();
|
2011-03-14 19:17:42 +00:00
|
|
|
|
|
|
|
stdDialogButtonSizerOK->SetDefault();
|
2008-12-31 15:01:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-24 21:06:50 +00:00
|
|
|
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnListItemDeselected( wxListEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-12-31 09:27:19 +00:00
|
|
|
D( printf( "OnListItemDeselected()\n" ); )
|
2008-11-26 00:20:16 +00:00
|
|
|
|
2008-11-26 06:25:20 +00:00
|
|
|
if( !m_skipCopyFromPanel )
|
|
|
|
{
|
|
|
|
if( !copyPanelToSelectedField() )
|
|
|
|
event.Skip(); // do not go to the next row
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2008-11-24 21:06:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnListItemSelected( wxListEvent& event )
|
|
|
|
{
|
2008-12-31 09:27:19 +00:00
|
|
|
D( printf( "OnListItemSelected()\n" ); )
|
2008-11-24 21:06:50 +00:00
|
|
|
|
2008-11-26 00:20:16 +00:00
|
|
|
// remember the selected row, statically
|
|
|
|
s_SelectedRow = event.GetIndex();
|
2008-11-24 21:06:50 +00:00
|
|
|
|
|
|
|
copySelectedFieldToPanel();
|
|
|
|
}
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-11-26 00:20:16 +00:00
|
|
|
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnCancelButtonClick( wxCommandEvent& event )
|
2008-03-20 01:50:21 +00:00
|
|
|
{
|
2008-11-26 00:20:16 +00:00
|
|
|
EndModal( 1 );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-26 00:20:16 +00:00
|
|
|
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copyPanelToOptions()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-12-31 09:27:19 +00:00
|
|
|
wxString newname = chipnameTextCtrl->GetValue();
|
|
|
|
|
2010-10-22 15:02:11 +00:00
|
|
|
#ifndef KICAD_KEEPCASE
|
2008-11-26 00:20:16 +00:00
|
|
|
newname.MakeUpper();
|
2010-10-22 15:02:11 +00:00
|
|
|
#endif
|
2008-11-26 00:20:16 +00:00
|
|
|
newname.Replace( wxT( " " ), wxT( "_" ) );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-11-26 00:20:16 +00:00
|
|
|
if( newname.IsEmpty() )
|
2011-04-19 16:30:28 +00:00
|
|
|
DisplayError( NULL, _( "No Component Name!" ) );
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2008-11-26 00:20:16 +00:00
|
|
|
else if( newname.CmpNoCase( m_Cmp->m_ChipName ) )
|
|
|
|
{
|
2009-09-18 14:56:05 +00:00
|
|
|
if( CMP_LIBRARY::FindLibraryEntry( newname ) == NULL )
|
2008-11-26 00:20:16 +00:00
|
|
|
{
|
|
|
|
wxString message;
|
2011-04-19 16:30:28 +00:00
|
|
|
message.Printf( _( "Component [%s] not found!" ), GetChars( newname ) );
|
|
|
|
DisplayError( NULL, message );
|
2008-11-26 00:20:16 +00:00
|
|
|
}
|
2008-11-27 18:42:19 +00:00
|
|
|
else // Change component from lib!
|
2008-11-26 00:20:16 +00:00
|
|
|
{
|
|
|
|
m_Cmp->m_ChipName = newname;
|
|
|
|
}
|
|
|
|
}
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2011-08-30 19:24:28 +00:00
|
|
|
// For components with multiple shapes (De Morgan representation) Set the selected shape:
|
2008-11-26 00:20:16 +00:00
|
|
|
if( convertCheckBox->IsEnabled() )
|
|
|
|
{
|
2010-12-14 15:56:30 +00:00
|
|
|
m_Cmp->SetConvert( convertCheckBox->GetValue() ? 2 : 1 );
|
2008-11-26 00:20:16 +00:00
|
|
|
}
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2011-08-30 19:24:28 +00:00
|
|
|
//Set the part selection in multiple part per package
|
2010-12-14 15:56:30 +00:00
|
|
|
if( m_Cmp->GetUnit() )
|
2008-11-26 00:20:16 +00:00
|
|
|
{
|
|
|
|
int unit_selection = unitChoice->GetCurrentSelection() + 1;
|
2011-12-08 21:05:43 +00:00
|
|
|
m_Cmp->SetUnitSelection( &m_Parent->GetCurrentSheet(), unit_selection );
|
2010-12-14 15:56:30 +00:00
|
|
|
m_Cmp->SetUnit( unit_selection );
|
2008-11-26 00:20:16 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-11-26 00:20:16 +00:00
|
|
|
switch( orientationRadioBox->GetSelection() )
|
|
|
|
{
|
|
|
|
case 0:
|
2010-01-13 21:15:54 +00:00
|
|
|
m_Cmp->SetOrientation( CMP_ORIENT_0 );
|
2008-11-26 00:20:16 +00:00
|
|
|
break;
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2008-11-26 00:20:16 +00:00
|
|
|
case 1:
|
2010-01-13 21:15:54 +00:00
|
|
|
m_Cmp->SetOrientation( CMP_ORIENT_90 );
|
2008-11-26 00:20:16 +00:00
|
|
|
break;
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2008-11-26 00:20:16 +00:00
|
|
|
case 2:
|
2010-01-13 21:15:54 +00:00
|
|
|
m_Cmp->SetOrientation( CMP_ORIENT_180 );
|
2008-11-26 00:20:16 +00:00
|
|
|
break;
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2008-11-26 00:20:16 +00:00
|
|
|
case 3:
|
2010-01-13 21:15:54 +00:00
|
|
|
m_Cmp->SetOrientation( CMP_ORIENT_270 );
|
2008-11-26 00:20:16 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2008-11-26 00:20:16 +00:00
|
|
|
int mirror = mirrorRadioBox->GetSelection();
|
2008-12-31 09:27:19 +00:00
|
|
|
|
2008-11-26 00:20:16 +00:00
|
|
|
switch( mirror )
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
break;
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2008-11-26 00:20:16 +00:00
|
|
|
case 1:
|
2010-01-13 21:15:54 +00:00
|
|
|
m_Cmp->SetOrientation( CMP_MIRROR_X );
|
2008-11-26 00:20:16 +00:00
|
|
|
break;
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2008-11-26 00:20:16 +00:00
|
|
|
case 2:
|
2010-01-13 21:15:54 +00:00
|
|
|
m_Cmp->SetOrientation( CMP_MIRROR_Y );
|
2008-11-26 00:20:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-11-24 06:53:43 +00:00
|
|
|
|
|
|
|
|
2008-11-26 00:20:16 +00:00
|
|
|
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnOKButtonClick( wxCommandEvent& event )
|
|
|
|
{
|
2011-08-30 19:24:28 +00:00
|
|
|
bool removeRemainingFields = false;
|
|
|
|
|
2008-11-26 00:20:16 +00:00
|
|
|
if( !copyPanelToSelectedField() )
|
|
|
|
return;
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2011-05-31 16:29:14 +00:00
|
|
|
if( ! SCH_COMPONENT::IsReferenceStringValid( m_FieldsBuf[REFERENCE].m_Text ) )
|
|
|
|
{
|
2011-08-30 19:24:28 +00:00
|
|
|
DisplayError( NULL, _( "Illegal reference. A reference must start with a letter" ) );
|
2011-05-31 16:29:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-08-30 19:24:28 +00:00
|
|
|
// save old cmp in undo list if not already in edit, or moving ...
|
2008-11-26 00:20:16 +00:00
|
|
|
if( m_Cmp->m_Flags == 0 )
|
2009-07-26 17:16:42 +00:00
|
|
|
m_Parent->SaveCopyInUndoList( m_Cmp, UR_CHANGED );
|
2008-11-26 00:20:16 +00:00
|
|
|
|
2011-01-18 10:42:49 +00:00
|
|
|
copyPanelToOptions();
|
|
|
|
|
2008-11-26 00:20:16 +00:00
|
|
|
// change all field positions from relative to absolute
|
2008-12-31 09:27:19 +00:00
|
|
|
for( unsigned i = 0; i<m_FieldsBuf.size(); ++i )
|
2008-11-26 00:20:16 +00:00
|
|
|
{
|
|
|
|
m_FieldsBuf[i].m_Pos += m_Cmp->m_Pos;
|
|
|
|
}
|
|
|
|
|
2011-08-30 19:24:28 +00:00
|
|
|
// Delete any fields with no name before we copy all of m_FieldsBuf back into the component.
|
2010-06-17 16:30:10 +00:00
|
|
|
for( unsigned i = MANDATORY_FIELDS; i<m_FieldsBuf.size(); )
|
2008-11-26 00:20:16 +00:00
|
|
|
{
|
2011-12-07 18:47:59 +00:00
|
|
|
if( m_FieldsBuf[i].GetName( false ).IsEmpty() || m_FieldsBuf[i].GetText().IsEmpty() )
|
2008-11-26 00:20:16 +00:00
|
|
|
{
|
2011-08-30 19:24:28 +00:00
|
|
|
// If a field has no value and is not it the field template list, warn the user
|
|
|
|
// that it will be remove from the component. This gives the user a chance to
|
|
|
|
// correct the problem before removing the undefined fields. It should also
|
|
|
|
// resolve most of the bug reports and questions regarding missing fields.
|
2011-12-07 18:47:59 +00:00
|
|
|
if( !m_FieldsBuf[i].GetName( false ).IsEmpty() && m_FieldsBuf[i].GetText().IsEmpty()
|
|
|
|
&& !m_Parent->GetTemplates().HasFieldName( m_FieldsBuf[i].GetName( false ) )
|
2011-08-30 19:24:28 +00:00
|
|
|
&& !removeRemainingFields )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
msg.Printf( _( "The field name <%s> does not have a value and is not defined in \
|
|
|
|
the field template list. Empty field values are invalid an will be removed from the component. \
|
|
|
|
Do you wish to remove this and all remaining undefined fields?" ),
|
2011-12-07 18:47:59 +00:00
|
|
|
GetChars( m_FieldsBuf[i].GetName( false ) ) );
|
2011-08-30 19:24:28 +00:00
|
|
|
|
|
|
|
wxMessageDialog dlg( this, msg, _( "Remove Fields" ), wxYES_NO | wxNO_DEFAULT );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_NO )
|
|
|
|
return;
|
|
|
|
|
|
|
|
removeRemainingFields = true;
|
|
|
|
}
|
|
|
|
|
2008-11-26 00:20:16 +00:00
|
|
|
m_FieldsBuf.erase( m_FieldsBuf.begin() + i );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
2010-11-18 21:10:52 +00:00
|
|
|
LIB_COMPONENT* entry = CMP_LIBRARY::FindLibraryComponent( m_Cmp->m_ChipName );
|
2008-11-26 00:20:16 +00:00
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
if( entry && entry->IsPower() )
|
2008-11-26 00:20:16 +00:00
|
|
|
m_FieldsBuf[VALUE].m_Text = m_Cmp->m_ChipName;
|
|
|
|
|
|
|
|
// copy all the fields back, and change the length of m_Fields.
|
|
|
|
m_Cmp->SetFields( m_FieldsBuf );
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2011-08-30 19:24:28 +00:00
|
|
|
// Reference has a specific initialization, depending on the current active sheet
|
|
|
|
// because for a given component, in a complex hierarchy, there are more than one
|
2010-01-13 13:43:36 +00:00
|
|
|
// reference.
|
2011-12-08 21:05:43 +00:00
|
|
|
m_Cmp->SetRef( &m_Parent->GetCurrentSheet(), m_FieldsBuf[REFERENCE].m_Text );
|
2010-01-13 13:43:36 +00:00
|
|
|
|
2010-11-18 21:10:52 +00:00
|
|
|
m_Parent->OnModify();
|
2011-01-21 19:30:59 +00:00
|
|
|
m_Parent->GetScreen()->TestDanglingEnds();
|
2011-12-22 13:28:11 +00:00
|
|
|
m_Parent->GetCanvas()->Refresh( true );
|
2008-11-26 00:20:16 +00:00
|
|
|
|
|
|
|
EndModal( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-26 06:25:20 +00:00
|
|
|
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::addFieldButtonHandler( wxCommandEvent& event )
|
|
|
|
{
|
2008-12-31 09:27:19 +00:00
|
|
|
// in case m_FieldsBuf[REFERENCE].m_Orient has changed on screen only, grab
|
|
|
|
// screen contents.
|
2008-11-26 06:25:20 +00:00
|
|
|
if( !copyPanelToSelectedField() )
|
|
|
|
return;
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
unsigned fieldNdx = m_FieldsBuf.size();
|
2008-11-26 06:25:20 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_FIELD blank( wxPoint(), fieldNdx, m_Cmp );
|
2008-11-26 06:25:20 +00:00
|
|
|
|
|
|
|
blank.m_Orient = m_FieldsBuf[REFERENCE].m_Orient;
|
|
|
|
|
|
|
|
m_FieldsBuf.push_back( blank );
|
2011-12-07 18:47:59 +00:00
|
|
|
m_FieldsBuf[fieldNdx].SetName( TEMPLATE_FIELDNAME::GetDefaultFieldName( fieldNdx ) );
|
2008-11-26 06:25:20 +00:00
|
|
|
|
2008-12-31 15:01:29 +00:00
|
|
|
m_skipCopyFromPanel = true;
|
2008-11-26 06:25:20 +00:00
|
|
|
setRowItem( fieldNdx, m_FieldsBuf[fieldNdx] );
|
|
|
|
|
|
|
|
setSelectedFieldNdx( fieldNdx );
|
|
|
|
m_skipCopyFromPanel = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::deleteFieldButtonHandler( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
unsigned fieldNdx = getSelectedFieldNdx();
|
|
|
|
|
|
|
|
if( fieldNdx >= m_FieldsBuf.size() ) // traps the -1 case too
|
|
|
|
return;
|
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
if( fieldNdx < MANDATORY_FIELDS )
|
2008-11-26 06:25:20 +00:00
|
|
|
{
|
|
|
|
wxBell();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-12-31 15:01:29 +00:00
|
|
|
m_skipCopyFromPanel = true;
|
2008-11-26 06:25:20 +00:00
|
|
|
m_FieldsBuf.erase( m_FieldsBuf.begin() + fieldNdx );
|
|
|
|
fieldListCtrl->DeleteItem( fieldNdx );
|
|
|
|
|
|
|
|
if( fieldNdx >= m_FieldsBuf.size() )
|
|
|
|
--fieldNdx;
|
|
|
|
|
2011-08-30 19:24:28 +00:00
|
|
|
updateDisplay();
|
2008-12-31 15:01:29 +00:00
|
|
|
|
2008-11-26 06:25:20 +00:00
|
|
|
setSelectedFieldNdx( fieldNdx );
|
|
|
|
m_skipCopyFromPanel = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::moveUpButtonHandler( wxCommandEvent& event )
|
2008-11-26 06:25:20 +00:00
|
|
|
{
|
|
|
|
unsigned fieldNdx = getSelectedFieldNdx();
|
|
|
|
|
|
|
|
if( fieldNdx >= m_FieldsBuf.size() ) // traps the -1 case too
|
|
|
|
return;
|
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
if( fieldNdx <= MANDATORY_FIELDS )
|
2008-11-26 06:25:20 +00:00
|
|
|
{
|
|
|
|
wxBell();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !copyPanelToSelectedField() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// swap the fieldNdx field with the one before it, in both the vector
|
|
|
|
// and in the fieldListCtrl
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_FIELD tmp = m_FieldsBuf[fieldNdx - 1];
|
2008-11-26 06:25:20 +00:00
|
|
|
|
2008-12-31 09:27:19 +00:00
|
|
|
D( printf( "tmp.m_Text=\"%s\" tmp.m_Name=\"%s\"\n",
|
2011-12-07 18:47:59 +00:00
|
|
|
TO_UTF8( tmp.m_Text ), TO_UTF8( tmp.GetName( false ) ) ); )
|
2008-11-26 06:25:20 +00:00
|
|
|
|
2008-12-31 09:27:19 +00:00
|
|
|
m_FieldsBuf[fieldNdx - 1] = m_FieldsBuf[fieldNdx];
|
|
|
|
setRowItem( fieldNdx - 1, m_FieldsBuf[fieldNdx] );
|
2008-11-26 06:25:20 +00:00
|
|
|
|
|
|
|
m_FieldsBuf[fieldNdx] = tmp;
|
|
|
|
setRowItem( fieldNdx, tmp );
|
|
|
|
|
2011-08-30 19:24:28 +00:00
|
|
|
updateDisplay();
|
2008-12-31 15:01:29 +00:00
|
|
|
|
2008-11-26 06:25:20 +00:00
|
|
|
m_skipCopyFromPanel = true;
|
|
|
|
setSelectedFieldNdx( fieldNdx - 1 );
|
|
|
|
m_skipCopyFromPanel = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-26 00:20:16 +00:00
|
|
|
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::setSelectedFieldNdx( int aFieldNdx )
|
|
|
|
{
|
2009-12-02 21:44:03 +00:00
|
|
|
/* deselect old selection, but I think this is done by single selection
|
|
|
|
* flag within fieldListCtrl.
|
|
|
|
* fieldListCtrl->SetItemState( s_SelectedRow, 0,
|
|
|
|
* wxLIST_STATE_SELECTED|wxLIST_STATE_FOCUSED);
|
2008-12-31 09:27:19 +00:00
|
|
|
*/
|
2008-11-26 00:20:16 +00:00
|
|
|
|
|
|
|
if( aFieldNdx >= (int) m_FieldsBuf.size() )
|
|
|
|
aFieldNdx = m_FieldsBuf.size() - 1;
|
|
|
|
|
|
|
|
if( aFieldNdx < 0 )
|
|
|
|
aFieldNdx = 0;
|
|
|
|
|
|
|
|
fieldListCtrl->SetItemState( aFieldNdx, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
|
|
|
|
fieldListCtrl->EnsureVisible( aFieldNdx );
|
|
|
|
|
|
|
|
s_SelectedRow = aFieldNdx;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::getSelectedFieldNdx()
|
|
|
|
{
|
|
|
|
return s_SelectedRow;
|
2008-11-24 06:53:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
SCH_FIELD* DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::findField( const wxString& aFieldName )
|
2008-12-31 16:49:45 +00:00
|
|
|
{
|
2010-06-17 16:30:10 +00:00
|
|
|
for( unsigned i=0; i<m_FieldsBuf.size(); ++i )
|
|
|
|
{
|
2011-12-07 18:47:59 +00:00
|
|
|
if( aFieldName == m_FieldsBuf[i].GetName( false ) )
|
2010-06-17 16:30:10 +00:00
|
|
|
return &m_FieldsBuf[i];
|
|
|
|
}
|
2011-08-30 19:24:28 +00:00
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
return NULL;
|
2008-12-31 16:49:45 +00:00
|
|
|
}
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::InitBuffers( SCH_COMPONENT* aComponent )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-11-24 06:53:43 +00:00
|
|
|
m_Cmp = aComponent;
|
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
/* We have 3 component related field lists to be aware of: 1) UI
|
|
|
|
presentation, 2) fields in component ram copy, and 3) fields recorded
|
|
|
|
with component on disk. m_FieldsBuf is the list of UI fields, and this
|
|
|
|
list is not the same as the list which is in the component, which is
|
|
|
|
also not the same as the list on disk. All 3 lists are potentially
|
|
|
|
different. In the UI we choose to preserve the order of the first
|
|
|
|
MANDATORY_FIELDS which are sometimes called fixed fields. Then we append
|
|
|
|
the template fieldnames in the exact same order as the template
|
|
|
|
fieldname editor shows them. Then we append any user defined fieldnames
|
|
|
|
which came from the component.
|
|
|
|
*/
|
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
m_LibEntry = CMP_LIBRARY::FindLibraryComponent( m_Cmp->m_ChipName );
|
2008-11-26 00:20:16 +00:00
|
|
|
|
|
|
|
#if 0 && defined(DEBUG)
|
2008-12-31 09:27:19 +00:00
|
|
|
for( int i = 0; i<aComponent->GetFieldCount(); ++i )
|
2008-11-26 00:20:16 +00:00
|
|
|
{
|
2008-12-31 09:27:19 +00:00
|
|
|
printf( "Orig[%d] (x=%d, y=%d)\n", i, aComponent->m_Fields[i].m_Pos.x,
|
|
|
|
aComponent->m_Fields[i].m_Pos.y );
|
2008-11-26 00:20:16 +00:00
|
|
|
}
|
2008-12-31 09:27:19 +00:00
|
|
|
|
2008-11-26 00:20:16 +00:00
|
|
|
#endif
|
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
// When this code was written, all field constructors ensure that the fixed fields
|
|
|
|
// are all present within a component. So we can knowingly copy them over
|
|
|
|
// in the normal order. Copy only the fixed fields at first.
|
|
|
|
// Please do not break the field constructors.
|
|
|
|
|
|
|
|
m_FieldsBuf.clear();
|
2010-11-18 21:10:52 +00:00
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
for( int i=0; i<MANDATORY_FIELDS; ++i )
|
|
|
|
{
|
|
|
|
m_FieldsBuf.push_back( aComponent->m_Fields[i] );
|
|
|
|
|
|
|
|
// make the editable field position relative to the component
|
|
|
|
m_FieldsBuf[i].m_Pos -= m_Cmp->m_Pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add template fieldnames:
|
|
|
|
// Now copy in the template fields, in the order that they are present in the
|
|
|
|
// template field editor UI.
|
|
|
|
const TEMPLATE_FIELDNAMES& tfnames = m_Parent->GetTemplateFieldNames();
|
2011-08-30 19:24:28 +00:00
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
for( TEMPLATE_FIELDNAMES::const_iterator it = tfnames.begin(); it!=tfnames.end(); ++it )
|
|
|
|
{
|
|
|
|
// add a new field unconditionally to the UI only
|
2010-08-29 16:09:07 +00:00
|
|
|
SCH_FIELD fld( wxPoint(0,0), -1 /* id is a relic */, m_Cmp, it->m_Name );
|
2010-06-17 16:30:10 +00:00
|
|
|
|
|
|
|
// See if field by same name already exists in component.
|
|
|
|
SCH_FIELD* schField = aComponent->FindField( it->m_Name );
|
|
|
|
|
|
|
|
// If the field does not already exist in the component, then we
|
|
|
|
// use defaults from the template fieldname, otherwise the original
|
|
|
|
// values from the component will be set.
|
|
|
|
if( !schField )
|
|
|
|
{
|
|
|
|
if( !it->m_Visible )
|
|
|
|
fld.m_Attributs |= TEXT_NO_VISIBLE;
|
|
|
|
else
|
|
|
|
fld.m_Attributs &= ~TEXT_NO_VISIBLE;
|
|
|
|
|
|
|
|
fld.m_Text = it->m_Value; // empty? ok too.
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fld = *schField;
|
|
|
|
|
|
|
|
// make the editable field position relative to the component
|
|
|
|
fld.m_Pos -= m_Cmp->m_Pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_FieldsBuf.push_back( fld );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Lastly, append any original fields from the component which were not added
|
|
|
|
// from the set of fixed fields nor from the set of template fields.
|
|
|
|
for( unsigned i=MANDATORY_FIELDS; i<aComponent->m_Fields.size(); ++i )
|
|
|
|
{
|
|
|
|
SCH_FIELD* cmp = &aComponent->m_Fields[i];
|
2011-12-07 18:47:59 +00:00
|
|
|
SCH_FIELD* buf = findField( cmp->GetName( false ) );
|
2010-06-17 16:30:10 +00:00
|
|
|
|
|
|
|
if( !buf )
|
|
|
|
{
|
|
|
|
int newNdx = m_FieldsBuf.size();
|
|
|
|
m_FieldsBuf.push_back( *cmp );
|
|
|
|
|
|
|
|
// make the editable field position relative to the component
|
|
|
|
m_FieldsBuf[newNdx].m_Pos -= m_Cmp->m_Pos;
|
|
|
|
}
|
|
|
|
}
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2008-12-31 16:49:45 +00:00
|
|
|
|
2008-11-26 00:20:16 +00:00
|
|
|
#if 0 && defined(DEBUG)
|
2008-12-31 09:27:19 +00:00
|
|
|
for( unsigned i = 0; i<m_FieldsBuf.size(); ++i )
|
2008-11-26 00:20:16 +00:00
|
|
|
{
|
2010-06-17 16:30:10 +00:00
|
|
|
printf( "m_FieldsBuf[%d] (x=%-3d, y=%-3d) name:%s\n", i, m_FieldsBuf[i].m_Pos.x,
|
2011-12-07 18:47:59 +00:00
|
|
|
m_FieldsBuf[i].m_Pos.y, TO_UTF8(m_FieldsBuf[i].GetName( false ) ) );
|
2008-11-26 00:20:16 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-12-08 21:05:43 +00:00
|
|
|
m_FieldsBuf[REFERENCE].m_Text = m_Cmp->GetRef( &m_Parent->GetCurrentSheet() );
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2008-12-31 09:27:19 +00:00
|
|
|
for( unsigned i = 0; i<m_FieldsBuf.size(); ++i )
|
2008-11-24 06:53:43 +00:00
|
|
|
{
|
2008-11-26 00:20:16 +00:00
|
|
|
setRowItem( i, m_FieldsBuf[i] );
|
2008-11-24 06:53:43 +00:00
|
|
|
}
|
2008-11-24 21:06:50 +00:00
|
|
|
|
2008-11-26 00:20:16 +00:00
|
|
|
#if 0 && defined(DEBUG)
|
2008-12-31 09:27:19 +00:00
|
|
|
for( unsigned i = 0; i<m_FieldsBuf.size(); ++i )
|
2008-11-26 00:20:16 +00:00
|
|
|
{
|
2008-12-31 09:27:19 +00:00
|
|
|
printf( "after[%d] (x=%d, y=%d)\n", i, m_FieldsBuf[i].m_Pos.x,
|
|
|
|
m_FieldsBuf[i].m_Pos.y );
|
2008-11-26 00:20:16 +00:00
|
|
|
}
|
2008-12-31 09:27:19 +00:00
|
|
|
|
2008-11-26 00:20:16 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
copyOptionsToPanel();
|
|
|
|
|
|
|
|
// put focus on the list ctrl
|
|
|
|
fieldListCtrl->SetFocus();
|
|
|
|
|
|
|
|
// resume editing at the last row edited, last time dialog was up.
|
|
|
|
setSelectedFieldNdx( s_SelectedRow );
|
2008-11-24 21:06:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-30 19:24:28 +00:00
|
|
|
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::setRowItem( int aFieldNdx, const SCH_FIELD& aField )
|
2008-11-24 21:06:50 +00:00
|
|
|
{
|
|
|
|
wxASSERT( aFieldNdx >= 0 );
|
|
|
|
|
2008-11-26 00:20:16 +00:00
|
|
|
// insert blanks if aFieldNdx is referencing a "yet to be defined" row
|
2008-11-24 21:06:50 +00:00
|
|
|
while( aFieldNdx >= fieldListCtrl->GetItemCount() )
|
|
|
|
{
|
2008-12-31 09:27:19 +00:00
|
|
|
long ndx = fieldListCtrl->InsertItem( fieldListCtrl->GetItemCount(), wxEmptyString );
|
2008-11-24 21:06:50 +00:00
|
|
|
|
|
|
|
wxASSERT( ndx >= 0 );
|
|
|
|
|
|
|
|
fieldListCtrl->SetItem( ndx, 1, wxEmptyString );
|
|
|
|
}
|
|
|
|
|
2011-12-07 18:47:59 +00:00
|
|
|
fieldListCtrl->SetItem( aFieldNdx, 0, aField.GetName( false ) );
|
|
|
|
fieldListCtrl->SetItem( aFieldNdx, 1, aField.GetText() );
|
2008-11-24 21:06:50 +00:00
|
|
|
|
|
|
|
// recompute the column widths here, after setting texts
|
|
|
|
fieldListCtrl->SetColumnWidth( 0, wxLIST_AUTOSIZE );
|
|
|
|
fieldListCtrl->SetColumnWidth( 1, wxLIST_AUTOSIZE );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-24 21:06:50 +00:00
|
|
|
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copySelectedFieldToPanel()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-11-24 21:06:50 +00:00
|
|
|
unsigned fieldNdx = getSelectedFieldNdx();
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2008-11-24 21:06:50 +00:00
|
|
|
if( fieldNdx >= m_FieldsBuf.size() ) // traps the -1 case too
|
2008-11-24 06:53:43 +00:00
|
|
|
return;
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_FIELD& field = m_FieldsBuf[fieldNdx];
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2008-11-26 00:20:16 +00:00
|
|
|
showCheckBox->SetValue( !(field.m_Attributs & TEXT_NO_VISIBLE) );
|
|
|
|
|
|
|
|
rotateCheckBox->SetValue( field.m_Orient == TEXT_ORIENT_VERT );
|
|
|
|
|
2008-12-31 09:27:19 +00:00
|
|
|
int style = 0;
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2008-12-31 09:27:19 +00:00
|
|
|
if( field.m_Italic )
|
|
|
|
style = 1;
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2009-05-28 17:39:40 +00:00
|
|
|
if( field.m_Bold )
|
2008-12-31 09:27:19 +00:00
|
|
|
style |= 2;
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2008-12-31 09:27:19 +00:00
|
|
|
m_StyleRadioBox->SetSelection( style );
|
2008-12-28 18:00:37 +00:00
|
|
|
|
2010-12-21 12:41:17 +00:00
|
|
|
// Select the right text justification
|
|
|
|
if( field.m_HJustify == GR_TEXT_HJUSTIFY_LEFT )
|
|
|
|
m_FieldHJustifyCtrl->SetSelection(0);
|
|
|
|
else if( field.m_HJustify == GR_TEXT_HJUSTIFY_RIGHT )
|
|
|
|
m_FieldHJustifyCtrl->SetSelection(2);
|
|
|
|
else
|
|
|
|
m_FieldHJustifyCtrl->SetSelection(1);
|
|
|
|
|
|
|
|
if( field.m_VJustify == GR_TEXT_VJUSTIFY_BOTTOM )
|
|
|
|
m_FieldVJustifyCtrl->SetSelection(0);
|
|
|
|
else if( field.m_VJustify == GR_TEXT_VJUSTIFY_TOP )
|
|
|
|
m_FieldVJustifyCtrl->SetSelection(2);
|
|
|
|
else
|
|
|
|
m_FieldVJustifyCtrl->SetSelection(1);
|
|
|
|
|
|
|
|
|
2011-12-07 18:47:59 +00:00
|
|
|
fieldNameTextCtrl->SetValue( field.GetName( false ) );
|
2008-11-24 21:06:50 +00:00
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
// the names of the fixed fields are not editable, others are.
|
|
|
|
fieldNameTextCtrl->Enable( fieldNdx >= MANDATORY_FIELDS );
|
|
|
|
fieldNameTextCtrl->SetEditable( fieldNdx >= MANDATORY_FIELDS );
|
|
|
|
|
|
|
|
// only user defined fields may be moved, and not the top most user defined
|
|
|
|
// field since it would be moving up into the fixed fields, > not >=
|
|
|
|
moveUpButton->Enable( fieldNdx > MANDATORY_FIELDS );
|
|
|
|
|
|
|
|
// may only delete user defined fields
|
|
|
|
deleteFieldButton->Enable( fieldNdx >= MANDATORY_FIELDS );
|
2008-11-24 21:06:50 +00:00
|
|
|
|
|
|
|
fieldValueTextCtrl->SetValue( field.m_Text );
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
// For power symbols, the value is NOR editable, because value and pin
|
|
|
|
// name must be same and can be edited only in library editor
|
2010-10-04 18:54:14 +00:00
|
|
|
if( fieldNdx == VALUE && m_LibEntry && m_LibEntry->IsPower() )
|
2009-09-26 17:22:47 +00:00
|
|
|
fieldValueTextCtrl->Enable( false );
|
|
|
|
else
|
|
|
|
fieldValueTextCtrl->Enable( true );
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2012-04-16 17:39:32 +00:00
|
|
|
textSizeTextCtrl->SetValue( EDA_GRAPHIC_TEXT_CTRL::FormatSize( g_UserUnit, field.m_Size.x ) );
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2008-11-26 00:20:16 +00:00
|
|
|
wxPoint coord = field.m_Pos;
|
|
|
|
wxPoint zero = -m_Cmp->m_Pos; // relative zero
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
// If the field value is empty and the position is at relative zero, we
|
|
|
|
// set the initial position as a small offset from the ref field, and
|
|
|
|
// orient it the same as the ref field. That is likely to put it at least
|
2008-11-24 06:53:43 +00:00
|
|
|
// close to the desired position.
|
2008-11-26 00:20:16 +00:00
|
|
|
if( coord == zero && field.m_Text.IsEmpty() )
|
2008-11-24 06:53:43 +00:00
|
|
|
{
|
2008-11-26 00:20:16 +00:00
|
|
|
rotateCheckBox->SetValue( m_FieldsBuf[REFERENCE].m_Orient == TEXT_ORIENT_VERT );
|
2008-11-24 21:06:50 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
coord.x = m_FieldsBuf[REFERENCE].m_Pos.x
|
2010-06-17 16:30:10 +00:00
|
|
|
+ ( fieldNdx - MANDATORY_FIELDS + 1 ) * 100;
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
coord.y = m_FieldsBuf[REFERENCE].m_Pos.y
|
2010-06-17 16:30:10 +00:00
|
|
|
+ ( fieldNdx - MANDATORY_FIELDS + 1 ) * 100;
|
2008-11-24 21:06:50 +00:00
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
// coord can compute negative if field is < MANDATORY_FIELDS, e.g. FOOTPRINT.
|
2008-11-26 00:20:16 +00:00
|
|
|
// That is ok, we basically don't want all the new empty fields on
|
|
|
|
// top of each other.
|
2008-11-24 06:53:43 +00:00
|
|
|
}
|
|
|
|
|
2012-04-13 18:51:24 +00:00
|
|
|
wxString coordText = ReturnStringFromValue( g_UserUnit, coord.x );
|
2008-11-26 00:20:16 +00:00
|
|
|
posXTextCtrl->SetValue( coordText );
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2012-04-13 18:51:24 +00:00
|
|
|
coordText = ReturnStringFromValue( g_UserUnit, coord.y );
|
2008-11-26 00:20:16 +00:00
|
|
|
posYTextCtrl->SetValue( coordText );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2008-11-24 06:53:43 +00:00
|
|
|
|
|
|
|
|
2008-11-26 00:20:16 +00:00
|
|
|
bool DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copyPanelToSelectedField()
|
2008-11-24 21:06:50 +00:00
|
|
|
{
|
|
|
|
unsigned fieldNdx = getSelectedFieldNdx();
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2008-11-26 00:20:16 +00:00
|
|
|
if( fieldNdx >= m_FieldsBuf.size() ) // traps the -1 case too
|
|
|
|
return true;
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_FIELD& field = m_FieldsBuf[fieldNdx];
|
2008-11-24 21:06:50 +00:00
|
|
|
|
2008-11-26 00:20:16 +00:00
|
|
|
if( showCheckBox->GetValue() )
|
|
|
|
field.m_Attributs &= ~TEXT_NO_VISIBLE;
|
|
|
|
else
|
|
|
|
field.m_Attributs |= TEXT_NO_VISIBLE;
|
|
|
|
|
|
|
|
if( rotateCheckBox->GetValue() )
|
|
|
|
field.m_Orient = TEXT_ORIENT_VERT;
|
|
|
|
else
|
|
|
|
field.m_Orient = TEXT_ORIENT_HORIZ;
|
|
|
|
|
|
|
|
rotateCheckBox->SetValue( field.m_Orient == TEXT_ORIENT_VERT );
|
|
|
|
|
2010-12-21 12:41:17 +00:00
|
|
|
// Copy the text justification
|
2012-01-03 17:14:17 +00:00
|
|
|
EDA_TEXT_HJUSTIFY_T hjustify[3] = {
|
2010-12-21 12:41:17 +00:00
|
|
|
GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_HJUSTIFY_CENTER,
|
|
|
|
GR_TEXT_HJUSTIFY_RIGHT
|
|
|
|
};
|
|
|
|
|
2012-01-03 17:14:17 +00:00
|
|
|
EDA_TEXT_VJUSTIFY_T vjustify[3] = {
|
2010-12-21 12:41:17 +00:00
|
|
|
GR_TEXT_VJUSTIFY_BOTTOM, GR_TEXT_VJUSTIFY_CENTER,
|
|
|
|
GR_TEXT_VJUSTIFY_TOP
|
|
|
|
};
|
|
|
|
|
|
|
|
field.m_HJustify = hjustify[m_FieldHJustifyCtrl->GetSelection()];
|
|
|
|
field.m_VJustify = vjustify[m_FieldVJustifyCtrl->GetSelection()];
|
2008-12-28 18:00:37 +00:00
|
|
|
|
2011-12-07 18:47:59 +00:00
|
|
|
field.SetName( fieldNameTextCtrl->GetValue() );
|
2011-08-30 19:24:28 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
/* Void fields texts for REFERENCE and VALUE (value is the name of the
|
2011-08-30 19:24:28 +00:00
|
|
|
* component in lib ! ) are not allowed
|
2009-01-02 17:31:32 +00:00
|
|
|
* change them only for a new non void value
|
2011-08-30 19:24:28 +00:00
|
|
|
* When void, usually netlists are broken
|
2009-01-02 17:31:32 +00:00
|
|
|
*/
|
|
|
|
if( !fieldValueTextCtrl->GetValue().IsEmpty() || fieldNdx > VALUE )
|
|
|
|
field.m_Text = fieldValueTextCtrl->GetValue();
|
2008-11-24 21:06:50 +00:00
|
|
|
|
2008-11-26 00:20:16 +00:00
|
|
|
setRowItem( fieldNdx, field ); // update fieldListCtrl
|
2008-11-24 21:06:50 +00:00
|
|
|
|
2012-04-16 17:39:32 +00:00
|
|
|
field.m_Size.x = EDA_GRAPHIC_TEXT_CTRL::ParseSize( textSizeTextCtrl->GetValue(), g_UserUnit );
|
2008-11-26 00:20:16 +00:00
|
|
|
field.m_Size.y = field.m_Size.x;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-12-31 09:27:19 +00:00
|
|
|
int style = m_StyleRadioBox->GetSelection();
|
2012-04-16 17:39:32 +00:00
|
|
|
|
2008-12-31 09:27:19 +00:00
|
|
|
if( (style & 1 ) != 0 )
|
|
|
|
field.m_Italic = true;
|
|
|
|
else
|
|
|
|
field.m_Italic = false;
|
2008-12-28 18:00:37 +00:00
|
|
|
|
2008-12-31 09:27:19 +00:00
|
|
|
if( (style & 2 ) != 0 )
|
2009-05-28 17:39:40 +00:00
|
|
|
field.m_Bold = true;
|
2008-12-31 09:27:19 +00:00
|
|
|
else
|
2009-05-28 17:39:40 +00:00
|
|
|
field.m_Bold = false;
|
2008-12-28 18:00:37 +00:00
|
|
|
|
2012-04-16 17:39:32 +00:00
|
|
|
field.m_Pos.x = ReturnValueFromString( g_UserUnit, posXTextCtrl->GetValue() );
|
|
|
|
field.m_Pos.y = ReturnValueFromString( g_UserUnit, posYTextCtrl->GetValue() );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-11-26 00:20:16 +00:00
|
|
|
return true;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2008-11-26 00:20:16 +00:00
|
|
|
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copyOptionsToPanel()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-11-26 00:20:16 +00:00
|
|
|
int choiceCount = unitChoice->GetCount();
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2008-11-27 18:42:19 +00:00
|
|
|
// Remove non existing choices (choiceCount must be <= number for parts)
|
2009-10-05 17:52:41 +00:00
|
|
|
int unitcount = m_LibEntry ? m_LibEntry->GetPartCount() : 1;
|
2008-12-31 09:27:19 +00:00
|
|
|
|
|
|
|
if( unitcount < 1 )
|
2008-11-27 18:42:19 +00:00
|
|
|
unitcount = 1;
|
2009-01-29 08:58:48 +00:00
|
|
|
|
2008-12-04 20:53:11 +00:00
|
|
|
if( unitcount < choiceCount )
|
2008-11-27 18:42:19 +00:00
|
|
|
{
|
2008-12-31 09:27:19 +00:00
|
|
|
while( unitcount < choiceCount )
|
2008-11-27 18:42:19 +00:00
|
|
|
{
|
|
|
|
choiceCount--;
|
2008-12-31 09:27:19 +00:00
|
|
|
unitChoice->Delete( choiceCount );
|
2008-11-27 18:42:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// For components with multiple parts per package, set the unit selection
|
|
|
|
choiceCount = unitChoice->GetCount();
|
2010-11-18 21:10:52 +00:00
|
|
|
|
2010-12-14 15:56:30 +00:00
|
|
|
if( m_Cmp->GetUnit() <= choiceCount )
|
|
|
|
unitChoice->SetSelection( m_Cmp->GetUnit() - 1 );
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2008-11-27 18:42:19 +00:00
|
|
|
// Disable unit selection if only one unit exists:
|
2008-12-31 09:27:19 +00:00
|
|
|
if( choiceCount <= 1 )
|
|
|
|
unitChoice->Enable( false );
|
2008-11-27 18:42:19 +00:00
|
|
|
|
2010-01-13 21:15:54 +00:00
|
|
|
int orientation = m_Cmp->GetOrientation()
|
|
|
|
& ~( CMP_MIRROR_X | CMP_MIRROR_Y );
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2008-11-26 00:20:16 +00:00
|
|
|
if( orientation == CMP_ORIENT_90 )
|
|
|
|
orientationRadioBox->SetSelection( 1 );
|
|
|
|
else if( orientation == CMP_ORIENT_180 )
|
|
|
|
orientationRadioBox->SetSelection( 2 );
|
|
|
|
else if( orientation == CMP_ORIENT_270 )
|
|
|
|
orientationRadioBox->SetSelection( 3 );
|
2008-11-26 05:08:37 +00:00
|
|
|
else
|
|
|
|
orientationRadioBox->SetSelection( 0 );
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2010-01-13 21:15:54 +00:00
|
|
|
int mirror = m_Cmp->GetOrientation() & ( CMP_MIRROR_X | CMP_MIRROR_Y );
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2010-01-13 21:15:54 +00:00
|
|
|
if( mirror == CMP_MIRROR_X )
|
2008-11-26 00:20:16 +00:00
|
|
|
{
|
|
|
|
mirrorRadioBox->SetSelection( 1 );
|
2008-12-31 09:27:19 +00:00
|
|
|
D( printf( "mirror=X,1\n" ); )
|
2008-11-26 00:20:16 +00:00
|
|
|
}
|
2010-01-13 21:15:54 +00:00
|
|
|
else if( mirror == CMP_MIRROR_Y )
|
2008-11-26 00:20:16 +00:00
|
|
|
{
|
|
|
|
mirrorRadioBox->SetSelection( 2 );
|
2008-12-31 09:27:19 +00:00
|
|
|
D( printf( "mirror=Y,2\n" ); )
|
2008-11-26 00:20:16 +00:00
|
|
|
}
|
2008-11-26 05:08:37 +00:00
|
|
|
else
|
|
|
|
mirrorRadioBox->SetSelection( 0 );
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
// Activate/Desactivate the normal/convert option ? (activated only if
|
|
|
|
// the component has more than one shape)
|
2010-12-14 15:56:30 +00:00
|
|
|
if( m_Cmp->GetConvert() > 1 )
|
2008-11-27 18:42:19 +00:00
|
|
|
{
|
2008-11-26 00:20:16 +00:00
|
|
|
convertCheckBox->SetValue( true );
|
2008-11-27 18:42:19 +00:00
|
|
|
}
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2009-09-29 18:38:21 +00:00
|
|
|
if( m_LibEntry == NULL || !m_LibEntry->HasConversion() )
|
2008-11-24 06:53:43 +00:00
|
|
|
{
|
2008-11-26 00:20:16 +00:00
|
|
|
convertCheckBox->Enable( false );
|
2008-11-24 06:53:43 +00:00
|
|
|
}
|
|
|
|
|
2008-11-26 00:20:16 +00:00
|
|
|
// Show the "Parts Locked" option?
|
2010-06-24 18:31:43 +00:00
|
|
|
if( !m_LibEntry || !m_LibEntry->UnitsLocked() )
|
2008-11-24 06:53:43 +00:00
|
|
|
{
|
2008-12-31 09:27:19 +00:00
|
|
|
D( printf( "partsAreLocked->false\n" ); )
|
2008-11-26 00:20:16 +00:00
|
|
|
partsAreLockedLabel->Show( false );
|
2008-11-24 06:53:43 +00:00
|
|
|
}
|
|
|
|
|
2011-08-30 19:24:28 +00:00
|
|
|
// Set the component's library name.
|
2008-11-26 00:20:16 +00:00
|
|
|
chipnameTextCtrl->SetValue( m_Cmp->m_ChipName );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2011-08-30 19:24:28 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <kicad_device_context.h>
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2011-08-30 19:24:28 +00:00
|
|
|
/* reinitialize components parameters to default values found in lib
|
2008-12-31 09:27:19 +00:00
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::SetInitCmp( wxCommandEvent& event )
|
2008-11-24 06:53:43 +00:00
|
|
|
{
|
2009-09-18 14:56:05 +00:00
|
|
|
LIB_COMPONENT* entry;
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2008-11-26 00:20:16 +00:00
|
|
|
if( m_Cmp == NULL )
|
|
|
|
return;
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
entry = CMP_LIBRARY::FindLibraryComponent( m_Cmp->m_ChipName );
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2008-11-26 00:20:16 +00:00
|
|
|
if( entry == NULL )
|
|
|
|
return;
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2010-07-11 17:26:03 +00:00
|
|
|
// save old cmp in undo list if not already in edit, or moving ...
|
|
|
|
if( m_Cmp->m_Flags == 0 )
|
|
|
|
m_Parent->SaveCopyInUndoList( m_Cmp, UR_CHANGED );
|
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
INSTALL_UNBUFFERED_DC( dc, m_Parent->GetCanvas() );
|
|
|
|
m_Cmp->Draw( m_Parent->GetCanvas(), &dc, wxPoint( 0, 0 ), g_XorMode );
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2010-06-30 13:08:50 +00:00
|
|
|
// Initialize field values to default values found in library:
|
2009-10-21 20:02:25 +00:00
|
|
|
LIB_FIELD& refField = entry->GetReferenceField();
|
|
|
|
m_Cmp->GetField( REFERENCE )->m_Pos = refField.m_Pos + m_Cmp->m_Pos;
|
|
|
|
m_Cmp->GetField( REFERENCE )->ImportValues( refField );
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2009-10-21 20:02:25 +00:00
|
|
|
LIB_FIELD& valField = entry->GetValueField();
|
|
|
|
m_Cmp->GetField( VALUE )->m_Pos = valField.m_Pos + m_Cmp->m_Pos;
|
|
|
|
m_Cmp->GetField( VALUE )->ImportValues( valField );
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2010-01-13 21:15:54 +00:00
|
|
|
m_Cmp->SetOrientation( CMP_NORMAL );
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2011-08-30 19:24:28 +00:00
|
|
|
m_Parent->OnModify();
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_Cmp->Draw( m_Parent->GetCanvas(), &dc, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
|
2008-11-26 00:20:16 +00:00
|
|
|
EndModal( 1 );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|