kicad/eeschema/edit_component_in_lib.cpp

402 lines
12 KiB
C++
Raw Normal View History

2007-05-06 16:03:28 +00:00
/**************************************************************/
/* librairy editor: edition of component general properties */
2007-05-06 16:03:28 +00:00
/**************************************************************/
#include "fctsys.h"
2009-04-12 14:39:54 +00:00
#include "appl_wxstruct.h"
2007-05-06 16:03:28 +00:00
#include "common.h"
#include "macros.h"
#include "class_drawpanel.h"
#include "confirm.h"
#include "gestfich.h"
#include "wxEeschemaStruct.h"
2007-05-06 16:03:28 +00:00
#include "general.h"
#include "protos.h"
2010-02-16 16:21:52 +00:00
#include "libeditframe.h"
#include "class_library.h"
#include "eeschema_id.h"
2007-05-06 16:03:28 +00:00
/* Dialog box to edit a libentry (a component in library) properties */
2007-05-06 16:03:28 +00:00
/* Creates a NoteBook dialog
* Edition:
* Doc and keys words
* Parts per package
* General properties
* Fields are NOT edited here. There is a specific dialog box to do that
2007-09-20 21:06:49 +00:00
*/
2007-05-06 16:03:28 +00:00
#include "dialog_edit_component_in_lib.h"
2007-05-06 16:03:28 +00:00
void WinEDA_LibeditFrame::OnEditComponentProperties( wxCommandEvent& event )
2007-05-06 16:03:28 +00:00
{
bool partLocked = GetComponent()->UnitsLocked();
DIALOG_EDIT_COMPONENT_IN_LIBRARY dlg( this );
2007-05-06 16:03:28 +00:00
if( dlg.ShowModal() == wxID_CANCEL )
return;
2007-05-06 16:03:28 +00:00
if( partLocked != GetComponent()->UnitsLocked() )
{
// g_EditPinByPinIsOn is set to the better value, if m_UnitSelectionLocked has changed
g_EditPinByPinIsOn = GetComponent()->UnitsLocked() ? true : false;
}
UpdateAliasSelectList();
UpdatePartSelectList();
DisplayLibInfos();
DisplayCmpDoc();
OnModify();
DrawPanel->Refresh();
2007-05-06 16:03:28 +00:00
}
2007-09-20 21:06:49 +00:00
void DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnOkClick( wxCommandEvent& event )
2007-05-06 16:03:28 +00:00
{
2007-09-20 21:06:49 +00:00
/* Update the doc, keyword and doc filename strings */
int index;
LIB_ALIAS* alias;
LIB_COMPONENT* component = m_Parent->GetComponent();
if( component == NULL )
{
EndModal( wxID_CANCEL );
return;
}
m_Parent->SaveCopyInUndoList( component );
alias = component->GetAlias( m_Parent->GetAliasName() );
wxCHECK_RET( alias != NULL,
wxT( "Alias \"" ) + m_Parent->GetAliasName() + wxT( "\" of component \"" ) +
component->GetName() + wxT( "\" does not exist." ) );
alias->SetDescription( m_DocCtrl->GetValue() );
alias->SetKeyWords( m_KeywordsCtrl->GetValue() );
alias->SetDocFileName( m_DocfileCtrl->GetValue() );
2007-09-20 21:06:49 +00:00
component->SetAliases( m_PartAliasListCtrl->GetStrings() );
2007-09-20 21:06:49 +00:00
index = m_SelNumberOfUnits->GetValue();
ChangeNbUnitsPerPackage( index );
2007-09-20 21:06:49 +00:00
if( m_AsConvertButt->GetValue() )
2007-09-20 21:06:49 +00:00
{
if( !m_Parent->GetShowDeMorgan() )
2007-09-20 21:06:49 +00:00
{
m_Parent->SetShowDeMorgan( true );
SetUnsetConvert();
2007-09-20 21:06:49 +00:00
}
}
else
{
if( m_Parent->GetShowDeMorgan() )
2007-09-20 21:06:49 +00:00
{
m_Parent->SetShowDeMorgan( false );
SetUnsetConvert();
2007-09-20 21:06:49 +00:00
}
}
component->SetShowPinNumbers( m_ShowPinNumButt->GetValue() );
component->SetShowPinNames( m_ShowPinNameButt->GetValue() );
2007-09-20 21:06:49 +00:00
if( m_PinsNameInsideButt->GetValue() == false )
component->SetPinNameOffset( 0 ); // pin text outside the body (name is on the pin)
2007-09-20 21:06:49 +00:00
else
{
component->SetPinNameOffset( m_SetSkew->GetValue() );
// Ensure component->m_TextInside != 0, because the meaning is "text outside".
if( component->GetPinNameOffset() == 0 )
component->SetPinNameOffset( 20 ); // give a reasonnable value
}
2007-09-20 21:06:49 +00:00
if( m_OptionPower->GetValue() == true )
component->SetPower();
2007-09-20 21:06:49 +00:00
else
component->SetNormal();
2007-09-20 21:06:49 +00:00
/* Set the option "Units locked".
* Obviously, cannot be true if there is only one part */
component->LockUnits( m_OptionPartsLocked->GetValue() );
if( component->GetPartCount() <= 1 )
component->LockUnits( false );
2007-09-20 21:06:49 +00:00
/* Update the footprint filter list */
component->GetFootPrints().Clear();
component->GetFootPrints() = m_FootprintFilterListBox->GetStrings();
2007-09-20 21:06:49 +00:00
EndModal( wxID_OK );
2007-05-06 16:03:28 +00:00
}
void DIALOG_EDIT_COMPONENT_IN_LIBRARY::CopyDocToAlias( wxCommandEvent& WXUNUSED (event) )
2007-05-06 16:03:28 +00:00
{
if( m_Parent == NULL )
return;
LIB_ALIAS* alias;
LIB_COMPONENT* component = m_Parent->GetComponent();
if( component == NULL )
2007-09-20 21:06:49 +00:00
return;
alias = component->GetAlias( m_Parent->GetAliasName() );
if( alias == NULL )
return;
m_DocCtrl->SetValue( alias->GetDescription() );
m_DocfileCtrl->SetValue( alias->GetDocFileName() );
m_KeywordsCtrl->SetValue( alias->GetKeyWords() );
2007-05-06 16:03:28 +00:00
}
2007-09-20 21:06:49 +00:00
void DIALOG_EDIT_COMPONENT_IN_LIBRARY::DeleteAllAliasOfPart( wxCommandEvent& WXUNUSED (event) )
2007-05-06 16:03:28 +00:00
{
if( m_PartAliasListCtrl->FindString( m_Parent->GetAliasName() ) != wxNOT_FOUND )
{
wxString msg;
msg.Printf( _( "Alias <%s> cannot be removed while it is being edited!" ),
GetChars( m_Parent->GetAliasName() ) );
DisplayError( this, msg );
return;
}
if( IsOK( this, _( "Remove all aliases from list?" ) ) )
2007-09-20 21:06:49 +00:00
{
m_PartAliasListCtrl->Clear();
m_ButtonDeleteAllAlias->Enable( false );
m_ButtonDeleteOneAlias->Enable( false );
2007-09-20 21:06:49 +00:00
}
2007-05-06 16:03:28 +00:00
}
2007-09-20 21:06:49 +00:00
2007-05-06 16:03:28 +00:00
/* Add a new name to the alias list box
2007-09-20 21:06:49 +00:00
* New name cannot be the root name, and must not exists
*/
void DIALOG_EDIT_COMPONENT_IN_LIBRARY::AddAliasOfPart( wxCommandEvent& WXUNUSED (event) )
2007-05-06 16:03:28 +00:00
{
2007-09-20 21:06:49 +00:00
wxString aliasname;
LIB_COMPONENT* component = m_Parent->GetComponent();
CMP_LIBRARY* library = m_Parent->GetLibrary();
2007-09-20 21:06:49 +00:00
if( component == NULL )
2007-09-20 21:06:49 +00:00
return;
wxTextEntryDialog dlg( this, _( "New alias:" ), _( "Component Alias" ), aliasname );
if( dlg.ShowModal() != wxID_OK )
return; // cancelled by user
2007-09-20 21:06:49 +00:00
aliasname = dlg.GetValue( );
aliasname.Replace( wxT( " " ), wxT( "_" ) );
if( aliasname.IsEmpty() )
return;
2007-09-20 21:06:49 +00:00
if( m_PartAliasListCtrl->FindString( aliasname ) != wxNOT_FOUND
|| library->FindEntry( aliasname ) != NULL )
2007-09-20 21:06:49 +00:00
{
wxString msg;
msg.Printf( _( "Alias or component name <%s> already exists in library <%s>." ),
GetChars( aliasname ),
GetChars( library->GetName() ) );
DisplayError( this, msg );
return;
2007-09-20 21:06:49 +00:00
}
m_PartAliasListCtrl->Append( aliasname );
if( m_Parent->GetAliasName().CmpNoCase( component->GetName() ) == 0 )
m_ButtonDeleteAllAlias->Enable( true );
m_ButtonDeleteOneAlias->Enable( true );
2007-05-06 16:03:28 +00:00
}
2007-09-20 21:06:49 +00:00
void DIALOG_EDIT_COMPONENT_IN_LIBRARY::DeleteAliasOfPart( wxCommandEvent& WXUNUSED (event) )
2007-05-06 16:03:28 +00:00
{
wxString aliasname = m_PartAliasListCtrl->GetStringSelection();
2007-09-20 21:06:49 +00:00
if( aliasname.IsEmpty() )
return;
if( aliasname.CmpNoCase( m_Parent->GetAliasName() ) == 0 )
2007-09-20 21:06:49 +00:00
{
wxString msg;
msg.Printf( _( "Alias <%s> cannot be removed while it is being edited!" ),
GetChars( aliasname ) );
2007-09-20 21:06:49 +00:00
DisplayError( this, msg );
return;
}
m_PartAliasListCtrl->Delete( m_PartAliasListCtrl->GetSelection() );
LIB_COMPONENT* component = m_Parent->GetComponent();
if( component )
component->RemoveAlias( aliasname );
2007-09-20 21:06:49 +00:00
if( m_PartAliasListCtrl->IsEmpty() )
2007-09-20 21:06:49 +00:00
{
m_ButtonDeleteAllAlias->Enable( false );
m_ButtonDeleteOneAlias->Enable( false );
2007-09-20 21:06:49 +00:00
}
2007-05-06 16:03:28 +00:00
}
/*
* Change the number of parts per package.
2007-09-20 21:06:49 +00:00
*/
bool DIALOG_EDIT_COMPONENT_IN_LIBRARY::ChangeNbUnitsPerPackage( int MaxUnit )
2007-05-06 16:03:28 +00:00
{
LIB_COMPONENT* component = m_Parent->GetComponent();
2007-09-20 21:06:49 +00:00
if( component == NULL || component->GetPartCount() == MaxUnit || MaxUnit < 1 )
return false;
2007-09-20 21:06:49 +00:00
if( MaxUnit < component->GetPartCount()
&& !IsOK( this, _( "Delete extra parts from component?" ) ) )
return false;
2007-09-20 21:06:49 +00:00
component->SetPartCount( MaxUnit );
return true;
2007-05-06 16:03:28 +00:00
}
/*
* Set or clear the component alternate body style ( DeMorgan ).
2007-09-20 21:06:49 +00:00
*/
bool DIALOG_EDIT_COMPONENT_IN_LIBRARY::SetUnsetConvert()
2007-05-06 16:03:28 +00:00
{
LIB_COMPONENT* component = m_Parent->GetComponent();
2007-09-20 21:06:49 +00:00
if( component == NULL
|| ( m_Parent->GetShowDeMorgan() == component->HasConversion() ) )
return false;
if( m_Parent->GetShowDeMorgan() )
{
if( !IsOK( this, _( "Add new pins for alternate body style ( DeMorgan ) to component?" ) ) )
return false;
2007-09-20 21:06:49 +00:00
}
else if( component->HasConversion() )
2007-09-20 21:06:49 +00:00
{
if( !IsOK( this, _( "Delete alternate body style (DeMorgan) draw items from component?" ) ) )
{
m_Parent->SetShowDeMorgan( true );
return false;
}
2007-09-20 21:06:49 +00:00
}
component->SetConversion( m_Parent->GetShowDeMorgan() );
m_Parent->OnModify();
return true;
2007-05-06 16:03:28 +00:00
}
2007-09-20 21:06:49 +00:00
void DIALOG_EDIT_COMPONENT_IN_LIBRARY::BrowseAndSelectDocFile( wxCommandEvent& event )
2007-05-06 16:03:28 +00:00
{
2007-09-20 21:06:49 +00:00
wxString FullFileName, mask;
wxString docpath, filename;
2007-09-20 21:06:49 +00:00
docpath = wxGetApp().ReturnLastVisitedLibraryPath( wxT( "doc" ) );
2007-09-20 21:06:49 +00:00
mask = wxT( "*" );
2007-09-20 21:06:49 +00:00
FullFileName = EDA_FileSelector( _( "Doc Files" ),
docpath, /* Chemin par defaut */
wxEmptyString, /* nom fichier par defaut */
wxEmptyString, /* extension par defaut */
mask, /* Masque d'affichage */
this,
wxFD_OPEN,
true
2007-09-20 21:06:49 +00:00
);
if( FullFileName.IsEmpty() )
return;
/* If the path is already in the library search paths
2009-04-12 14:39:54 +00:00
* list, just add the library name to the list. Otherwise, add
* the library name with the full or relative path.
* the relative path, when possible is preferable,
* because it preserve use of default libraries paths, when the path is a sub path of
* these default paths
2009-04-12 14:39:54 +00:00
*/
wxFileName fn = FullFileName;
wxGetApp().SaveLastVisitedLibraryPath( fn.GetPath() );
filename = wxGetApp().ReturnFilenameWithRelativePathInLibPath( FullFileName );
2009-10-23 15:28:45 +00:00
// Filenames are always stored in unix like mode, ie separator "\" is stored as "/"
// to ensure files are identical under unices and windows
#ifdef __WINDOWS__
filename.Replace( wxT( "\\" ), wxT( "/" ) );
2009-10-23 15:28:45 +00:00
#endif
m_DocfileCtrl->SetValue( filename );
2007-05-06 16:03:28 +00:00
}
void DIALOG_EDIT_COMPONENT_IN_LIBRARY::DeleteAllFootprintFilter( wxCommandEvent& WXUNUSED (event) )
2007-05-06 16:03:28 +00:00
{
2007-09-20 21:06:49 +00:00
if( IsOK( this, _( "Ok to Delete FootprintFilter LIST" ) ) )
{
m_FootprintFilterListBox->Clear();
m_ButtonDeleteAllFootprintFilter->Enable( false );
m_ButtonDeleteOneFootprintFilter->Enable( false );
2007-09-20 21:06:49 +00:00
}
2007-05-06 16:03:28 +00:00
}
2007-09-20 21:06:49 +00:00
/* Add a new name to the footprint filter list box
* Obvioulsy, cannot be void
2007-09-20 21:06:49 +00:00
*/
void DIALOG_EDIT_COMPONENT_IN_LIBRARY::AddFootprintFilter( wxCommandEvent& WXUNUSED (event) )
2007-05-06 16:03:28 +00:00
{
2007-09-20 21:06:49 +00:00
wxString Line;
LIB_COMPONENT* component = m_Parent->GetComponent();
2007-09-20 21:06:49 +00:00
if( component == NULL )
2007-09-20 21:06:49 +00:00
return;
wxTextEntryDialog dlg( this, _( "Add Footprint Filter" ), _( "Footprint Filter" ), Line );
if( dlg.ShowModal() != wxID_OK )
return; // cancelled by user
2007-09-20 21:06:49 +00:00
Line = dlg.GetValue();
2007-09-20 21:06:49 +00:00
Line.Replace( wxT( " " ), wxT( "_" ) );
if( Line.IsEmpty() )
return;
2007-09-20 21:06:49 +00:00
/* test for an existing name: */
int index = m_FootprintFilterListBox->FindString( Line );
if( index != wxNOT_FOUND )
2007-09-20 21:06:49 +00:00
{
wxString msg;
msg.Printf( _( "Foot print filter <%s> is already defined." ), GetChars( Line ) );
DisplayError( this, msg );
return;
2007-09-20 21:06:49 +00:00
}
m_FootprintFilterListBox->Append( Line );
m_ButtonDeleteAllFootprintFilter->Enable( true );
m_ButtonDeleteOneFootprintFilter->Enable( true );
2007-05-06 16:03:28 +00:00
}
2007-09-20 21:06:49 +00:00
void DIALOG_EDIT_COMPONENT_IN_LIBRARY::DeleteOneFootprintFilter( wxCommandEvent& WXUNUSED (event) )
2007-05-06 16:03:28 +00:00
{
LIB_COMPONENT* component = m_Parent->GetComponent();
2007-09-20 21:06:49 +00:00
int ii = m_FootprintFilterListBox->GetSelection();
2007-05-06 16:03:28 +00:00
2007-09-20 21:06:49 +00:00
m_FootprintFilterListBox->Delete( ii );
2007-05-06 16:03:28 +00:00
if( !component || (m_FootprintFilterListBox->GetCount() == 0) )
2007-09-20 21:06:49 +00:00
{
m_ButtonDeleteAllFootprintFilter->Enable( false );
m_ButtonDeleteOneFootprintFilter->Enable( false );
2007-09-20 21:06:49 +00:00
}
}