<commit_before>/**************************************************************/
/*  librairy editor: edition of component general properties  */
/**************************************************************/

#include "fctsys.h"
#include "appl_wxstruct.h"
#include "common.h"
#include "confirm.h"
#include "gestfich.h"

#include "program.h"
#include "general.h"
#include "protos.h"
#include "libeditfrm.h"
#include "class_library.h"


/* Dialog box to edit a libentry (a component in library) properties */

/* 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
 */

#include "dialog_edit_component_in_lib.h"


void WinEDA_LibeditFrame::OnEditComponentProperties( wxCommandEvent& event )
{
    EditComponentProperties();
}


void WinEDA_LibeditFrame::EditComponentProperties()
{
    wxASSERT( m_component != NULL && m_library != NULL );

    DIALOG_EDIT_COMPONENT_IN_LIBRARY dlg( this );

    if( dlg.ShowModal() == wxID_CANCEL )
        return;

    UpdateAliasSelectList();
    UpdatePartSelectList();
    DisplayLibInfos();
    DisplayCmpDoc();
    GetScreen()->SetModify();
    SaveCopyInUndoList( m_component );
}



void DIALOG_EDIT_COMPONENT_IN_LIBRARY::InitPanelDoc()
{
    CMP_LIB_ENTRY* entry;
    LIB_COMPONENT* component = m_Parent->GetComponent();
    CMP_LIBRARY* library = m_Parent->GetLibrary();

    if( component == NULL )
        return;

    if( m_Parent->GetAliasName().IsEmpty() )
    {
        entry = component;
    }
    else
    {
        entry =
            ( CMP_LIB_ENTRY* ) library->FindAlias( m_Parent->GetAliasName() );

        if( entry == NULL )
            return;
    }

    m_Doc->SetValue( entry->m_Doc );
    m_Keywords->SetValue( entry->m_KeyWord );
    m_Docfile->SetValue( entry->m_DocFile );
}


/*
 * create the basic panel for component properties editing
 */
void DIALOG_EDIT_COMPONENT_IN_LIBRARY::InitBasicPanel()
{
    LIB_COMPONENT* component = m_Parent->GetComponent();

    if( m_Parent->GetShowDeMorgan() )
        m_AsConvertButt->SetValue( true );

    /* Default values for a new component. */
    if( component == NULL )
    {
        m_ShowPinNumButt->SetValue( true );
        m_ShowPinNameButt->SetValue( true );
        m_PinsNameInsideButt->SetValue( true );
        m_SelNumberOfUnits->SetValue( 1 );
        m_SetSkew->SetValue( 40 );
        m_OptionPower->SetValue( false );
        m_OptionPartsLocked->SetValue( false );
        return;
    }

    m_ShowPinNumButt->SetValue( component->m_DrawPinNum );
    m_ShowPinNameButt->SetValue( component->m_DrawPinName );
    m_PinsNameInsideButt->SetValue( component->m_TextInside != 0 );
    m_SelNumberOfUnits->SetValue( component->m_UnitCount );
    m_SetSkew->SetValue( component->m_TextInside );
    m_OptionPower->SetValue( component->m_Options == ENTRY_POWER );
    m_OptionPartsLocked->SetValue( component->m_UnitSelectionLocked );
}


void DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnOkClick( wxCommandEvent& event )
{

    /* Update the doc, keyword and doc filename strings */
    size_t i;
    int index;
    CMP_LIB_ENTRY* entry;
    LIB_COMPONENT* component = m_Parent->GetComponent();
    CMP_LIBRARY* library = m_Parent->GetLibrary();

    if( m_Parent->GetAliasName().IsEmpty() )
    {
        entry = (CMP_LIB_ENTRY*) component;
    }
    else
    {
        entry = library->FindEntry( m_Parent->GetAliasName() );
    }

    if( entry == NULL )
    {
        wxString msg;
        msg.Printf( _( "Alias <%s> not found for component <%s> in library \
<%s>." ),
                    (const wxChar*) m_Parent->GetAliasName(),
                    (const wxChar*) component->GetName(),
                    (const wxChar*) library->GetName() );
        wxMessageBox( msg, _( "Component Library Error" ),
                      wxID_OK | wxICON_ERROR, this );
    }
    else
    {
        entry->m_Doc = m_Doc->GetValue();
        entry->m_KeyWord = m_Keywords->GetValue();
        entry->m_DocFile = m_Docfile->GetValue();
    }

    if( m_PartAliasList->GetStrings() != component->m_AliasList )
    {
        LIB_ALIAS* alias;
        wxArrayString aliases = m_PartAliasList->GetStrings();

        /* Add names not existing in the old alias list. */
        for( i = 0; i < aliases.GetCount(); i++ )
        {
            index = component->m_AliasList.Index( aliases[ i ], false );

            if( index != wxNOT_FOUND )
                continue;

            alias = new LIB_ALIAS( aliases[ i ], component );

            if( !library->AddAlias( alias ) )
            {
                delete alias;
                alias = NULL;
            }
        }

        /* Remove names and library alias entries not in the new alias list. */
        for( i = 0; component->m_AliasList.GetCount(); i++ )
        {
            index = aliases.Index( component->m_AliasList[ i ], false );

            if( index == wxNOT_FOUND )
                continue;

            CMP_LIB_ENTRY* alias =
                library->FindAlias( component->m_AliasList[ i ] );
            if( alias != NULL )
                library->RemoveEntry( alias );
        }

        component->m_AliasList = aliases;
    }

    index = m_SelNumberOfUnits->GetValue();
    ChangeNbUnitsPerPackage( index );

    if( m_AsConvertButt->GetValue() )
    {
        if( !m_Parent->GetShowDeMorgan() )
        {
            m_Parent->SetShowDeMorgan( true );
            SetUnsetConvert();<commit_msg>eeschema: segfault at add/del alias in libedit<commit_after>/**************************************************************/
/*  librairy editor: edition of component general properties  */
/**************************************************************/

#include "fctsys.h"
#include "appl_wxstruct.h"
#include "common.h"
#include "confirm.h"
#include "gestfich.h"

#include "program.h"
#include "general.h"
#include "protos.h"
#include "libeditfrm.h"
#include "class_library.h"


/* Dialog box to edit a libentry (a component in library) properties */

/* 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
 */

#include "dialog_edit_component_in_lib.h"


void WinEDA_LibeditFrame::OnEditComponentProperties( wxCommandEvent& event )
{
    EditComponentProperties();
}


void WinEDA_LibeditFrame::EditComponentProperties()
{
    wxASSERT( m_component != NULL && m_library != NULL );

    DIALOG_EDIT_COMPONENT_IN_LIBRARY dlg( this );

    if( dlg.ShowModal() == wxID_CANCEL )
        return;

    UpdateAliasSelectList();
    UpdatePartSelectList();
    DisplayLibInfos();
    DisplayCmpDoc();
    GetScreen()->SetModify();
    SaveCopyInUndoList( m_component );
}



void DIALOG_EDIT_COMPONENT_IN_LIBRARY::InitPanelDoc()
{
    CMP_LIB_ENTRY* entry;
    LIB_COMPONENT* component = m_Parent->GetComponent();
    CMP_LIBRARY* library = m_Parent->GetLibrary();

    if( component == NULL )
        return;

    if( m_Parent->GetAliasName().IsEmpty() )
    {
        entry = component;
    }
    else
    {
        entry =
            ( CMP_LIB_ENTRY* ) library->FindAlias( m_Parent->GetAliasName() );

        if( entry == NULL )
            return;
    }

    m_Doc->SetValue( entry->m_Doc );
    m_Keywords->SetValue( entry->m_KeyWord );
    m_Docfile->SetValue( entry->m_DocFile );
}


/*
 * create the basic panel for component properties editing
 */
void DIALOG_EDIT_COMPONENT_IN_LIBRARY::InitBasicPanel()
{
    LIB_COMPONENT* component = m_Parent->GetComponent();

    if( m_Parent->GetShowDeMorgan() )
        m_AsConvertButt->SetValue( true );

    /* Default values for a new component. */
    if( component == NULL )
    {
        m_ShowPinNumButt->SetValue( true );
        m_ShowPinNameButt->SetValue( true );
        m_PinsNameInsideButt->SetValue( true );
        m_SelNumberOfUnits->SetValue( 1 );
        m_SetSkew->SetValue( 40 );
        m_OptionPower->SetValue( false );
        m_OptionPartsLocked->SetValue( false );
        return;
    }

    m_ShowPinNumButt->SetValue( component->m_DrawPinNum );
    m_ShowPinNameButt->SetValue( component->m_DrawPinName );
    m_PinsNameInsideButt->SetValue( component->m_TextInside != 0 );
    m_SelNumberOfUnits->SetValue( component->m_UnitCount );
    m_SetSkew->SetValue( component->m_TextInside );
    m_OptionPower->SetValue( component->m_Options == ENTRY_POWER );
    m_OptionPartsLocked->SetValue( component->m_UnitSelectionLocked );
}


void DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnOkClick( wxCommandEvent& event )
{

    /* Update the doc, keyword and doc filename strings */
    size_t i;
    int index;
    CMP_LIB_ENTRY* entry;
    LIB_COMPONENT* component = m_Parent->GetComponent();
    CMP_LIBRARY* library = m_Parent->GetLibrary();

    if( m_Parent->GetAliasName().IsEmpty() )
    {
        entry = (CMP_LIB_ENTRY*) component;
    }
    else
    {
        entry = library->FindEntry( m_Parent->GetAliasName() );
    }

    if( entry == NULL )
    {
        wxString msg;
        msg.Printf( _( "Alias <%s> not found for component <%s> in library \
<%s>." ),
                    (const wxChar*) m_Parent->GetAliasName(),
                    (const wxChar*) component->GetName(),
                    (const wxChar*) library->GetName() );
        wxMessageBox( msg, _( "Component Library Error" ),
                      wxID_OK | wxICON_ERROR, this );
    }
    else
    {
        entry->m_Doc = m_Doc->GetValue();
        entry->m_KeyWord = m_Keywords->GetValue();
        entry->m_DocFile = m_Docfile->GetValue();
    }

    if( m_PartAliasList->GetStrings() != component->m_AliasList )
    {
        LIB_ALIAS* alias;
        wxArrayString aliases = m_PartAliasList->GetStrings();

        /* Add names not existing in the old alias list. */
        for( i = 0; i < aliases.GetCount(); i++ )
        {
            index = component->m_AliasList.Index( aliases[ i ], false );

            if( index != wxNOT_FOUND )
                continue;

            alias = new LIB_ALIAS( aliases[ i ], component );

            if( !library->AddAlias( alias ) )
            {
                delete alias;
                alias = NULL;
            }
        }

        /* Remove names and library alias entries not in the new alias list. */
        for( i = 0; i < component->m_AliasList.GetCount(); i++ )
        {
            index = aliases.Index( component->m_AliasList[ i ], false );

            if( index == wxNOT_FOUND )
                continue;

            CMP_LIB_ENTRY* alias =
                library->FindAlias( component->m_AliasList[ i ] );
            if( alias != NULL )
                library->RemoveEntry( alias );
        }

        component->m_AliasList = aliases;
    }

    index = m_SelNumberOfUnits->GetValue();
    ChangeNbUnitsPerPackage( index );

    if( m_AsConvertButt->GetValue() )
    {
        if( !m_Parent->GetShowDeMorgan() )
        {
            m_Parent->SetShowDeMorgan( true );
            SetUnsetConvert();
{'fraction_non_alphanumeric': 0.13985697474427447, 'fraction_numerical': 0.0010862677650040735, 'mean_word_length': 2.5684754521963824, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 139, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5880542', 'n_tokens_mistral': 3518, 'n_tokens_neox': 3395, 'n_words': 710}