Commit 93a3d4cb authored by jean-pierre charras's avatar jean-pierre charras
Browse files

Eeschema: back to KICAD_KEEPCASE option, to find parts in lib, when using case...

Eeschema: back to KICAD_KEEPCASE option, to find parts in lib, when using case sensitive option (default).
Schematic component properties dialog: add 2 helper buttons to manage the chip name (name of the corresponding part in lib)
- a browse button to chose an other chip name
- a test button, to know if the part exists. If not existing, list the parts found when searching using a case insensitive comparison.
parent 0cf334a0
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -26,6 +26,19 @@ set( CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules )
#option( USE_KIWAY_DLLS "Build the major modules as KIFACE DLLs or DSOs, will soon be the norm." ON )
set( USE_KIWAY_DLLS true )  # this is now mandatory, the code is the same anyways, the old code is gone.

# The desire is to migrate designs *away from* case independence, and to create designs which use
# literally (case specific) interpreted component names.  But for backwards compatibility,
# you may turn OFF this option if you really must.  (Remember that with KiCad using text
# data files, typically you would be better off simply doctoring those files into
# a case literal state with a text editor and move forward into the brave new
# world of case specificity.  Also, BOM generators may not work properly when you
# have this option turned OFF, the xml export's referential integrity is broken
# on library part name.  Hence the default is ON now, as of 29-Jan-2014.
option( KICAD_KEEPCASE
    "ON= case specific string matching on component names, OFF= match names as if they were spelt using uppercase."
    ON
    )

option( USE_WX_GRAPHICS_CONTEXT
    "Use wxGraphicsContext for rendering ( default OFF). Warning, this is experimental" )

@@ -231,6 +244,10 @@ if( CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" )

endif( CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" )

if( KICAD_KEEPCASE )
    add_definitions( -DKICAD_KEEPCASE )
endif()

if( USE_WX_OVERLAY OR APPLE )
    add_definitions( -DUSE_WX_OVERLAY )
endif()
+3 −3
Original line number Diff line number Diff line
@@ -46,11 +46,11 @@ class LIB_FIELD;
/// Compiler controlled string compare function, either case independent or not:
inline int Cmp_KEEPCASE( const wxString& aString1, const wxString& aString2 )
{
#if 1
    // case specificity:
#ifdef KICAD_KEEPCASE
    // case specificity, the normal behavior:
    return aString1.Cmp( aString2 );
#else
    // case independence (no more in use)
    // case independence (only for guys who want that: not recommended)
    return aString1.CmpNoCase( aString2 );
#endif
}
+4 −5
Original line number Diff line number Diff line
@@ -902,7 +902,8 @@ LIB_ALIAS* PART_LIBS::FindLibraryEntry( const wxString& aName, const wxString& a
/* searches all libraries in the list for an entry, using a case insensitive comparison.
 * Used to find an entry, when the normal (case sensitive) search fails.
  */
LIB_ALIAS* PART_LIBS::FindLibraryNearEntry( const wxString& aEntryName,
void PART_LIBS::FindLibraryNearEntries( std::vector<LIB_ALIAS*>& aCandidates,
                                        const wxString& aEntryName,
                                        const wxString& aLibraryName )
{
    BOOST_FOREACH( PART_LIB& lib, *this )
@@ -921,7 +922,7 @@ LIB_ALIAS* PART_LIBS::FindLibraryNearEntry( const wxString& aEntryName,
        for( ;; )
        {
            if( entry_name.CmpNoCase( aEntryName ) == 0 )
                return entry;
                aCandidates.push_back( entry );

            entry = lib.GetNextEntry( entry_name );
            entry_name = entry->GetName();
@@ -930,8 +931,6 @@ LIB_ALIAS* PART_LIBS::FindLibraryNearEntry( const wxString& aEntryName,
                break;
        }
    }

    return NULL;
}


+9 −13
Original line number Diff line number Diff line
@@ -217,23 +217,19 @@ public:
            const wxString& aLibraryName = wxEmptyString );

    /**
     * Function FindLibraryNearEntry
     * Function FindLibraryNearEntries
     * Searches all libraries in the list for an entry, using a case insensitive comparison.
     * Used to find an entry, when the normal (case sensitive) search fails.
     * Needed because during a long time, eeschema was using a case insensitive search.
     * Therefore, for old schematics (<= 2013), or libs,
     * which mixed upper case and lower case entry names, for compatibility reasons, if
     * a normal search fails, this case insensitive search can be made.
     * Could be also usefull also in some dialogs, when searching parts in libs.
     * Remember this is a linear search, therefore slower than the normal binary search
     * Helper function used in dialog to find all candidates.
     * During a long time, eeschema was using a case insensitive search.
     * Therefore, for old schematics (<= 2013), or libs, for some components,
     * the chip name (name of alias in lib) can be broken.
     * This function can be used to display a list of candidates, in component properties dialog.
     *
     * The object can be either a part or an alias.
     *
     * @param aEntryName - Name of entry to search for (case insensitive).
     * @param aEntryName - Name of entries to search for (case insensitive).
     * @param aLibraryName - Name of the library to search.
     * @return The entry object if found, otherwise NULL.
     * @param aCandidates - a std::vector to store candidates
     */
    LIB_ALIAS* FindLibraryNearEntry( const wxString& aEntryName,
    void FindLibraryNearEntries( std::vector<LIB_ALIAS*>& aCandidates, const wxString& aEntryName,
            const wxString& aLibraryName = wxEmptyString );

    /**
+67 −24
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@
#include <base_units.h>

#include <general.h>
#include <sch_base_frame.h>
#include <class_library.h>
#include <sch_component.h>
#include <dialog_helpers.h>
@@ -116,6 +117,8 @@ private:
    void deleteFieldButtonHandler( wxCommandEvent& event );
    void moveUpButtonHandler( wxCommandEvent& event );
    void showButtonHandler( wxCommandEvent& event );
	void OnTestChipName( wxCommandEvent& event );
	void OnSelectChipName( wxCommandEvent& event );

    SCH_FIELD* findField( const wxString& aFieldName );

@@ -205,6 +208,65 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnListItemDeselected( wxListEvent& even
    }
}

void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnTestChipName( wxCommandEvent& event )
{
    wxString partname = chipnameTextCtrl->GetValue();
    LIB_PART* entry = Prj().SchLibs()->FindLibPart( partname );

    wxString msg;

    if( entry )
    {
        msg.Printf( _( "Component '%s' found in library '%s'" ),
                    GetChars( partname ), GetChars( entry->GetLibraryName() ) );
        wxMessageBox( msg );
        return;
    }

    msg.Printf( _( "Component '%s' not found in any library" ), GetChars( partname ) );

#ifdef KICAD_KEEPCASE
    // Try to find components which have a name "near" the current chip name,
    // i.e. the same name when the comparison is case insensitive.
    // Could be helpful for old designs when lower cases and upper case were
    // equivalent.
    std::vector<LIB_ALIAS*> candidates;
    Prj().SchLibs()->FindLibraryNearEntries( candidates, partname );

    if( candidates.size() == 0 )
    {
        wxMessageBox( msg );
        return;
    }

    // Some candidates are found. Show them:
    msg << wxT("\n") << _( "However, some candidates are found:" );

    // add candidate names:
    for( unsigned ii = 0; ii < candidates.size(); ii++ )
    {
        msg << wxT("\n") <<
            wxString::Format( _( "'%s' found in library '%s'" ),
                              GetChars( candidates[ii]->GetName() ),
                              GetChars( candidates[ii]->GetLibraryName() ) );
    }
#endif
    wxMessageBox( msg );
}


void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnSelectChipName( wxCommandEvent& event )
{
    wxArrayString dummy;
    int dummyunit = 1;
    wxString chipname = m_Parent->SelectComponentFromLibrary( wxEmptyString, dummy, dummyunit,
                                                              true, NULL, NULL );
    if( chipname.IsEmpty() )
        return;

    chipnameTextCtrl->SetValue( chipname );
}


void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnListItemSelected( wxListEvent& event )
{
@@ -222,9 +284,9 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnCloseDialog( wxCloseEvent& event )
    // On wxWidgets 2.8, and on Linux, calling EndQuasiModal here is mandatory
    // Otherwise, the main event loop is never restored, and Eeschema does not
    // respond to any event, because the DIALOG_SHIM destructor is never called.
    // on wxWidgets 3.0, or on Windows, the DIALOG_SHIM destructor is called,
    // On wxWidgets 3.0, or on Windows, the DIALOG_SHIM destructor is called,
    // and calls EndQuasiModal.
    // therefore calling EndQuasiModal here is not mandatory but it creates no issues
    // therefore calling EndQuasiModal here is not always mandatory but it creates no issues
    EndQuasiModal( wxID_CANCEL );
}

@@ -251,29 +313,10 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copyPanelToOptions()

        if( libs->FindLibraryEntry( newname ) == NULL )
        {
            if( LIB_ALIAS* entry = libs->FindLibraryNearEntry( newname ) )
            {
                wxString near_name = entry->GetName();
            wxString msg = wxString::Format( _(
                    "Component '%s' not found!\n"
                    "But the component '%s' exists\n"
                    "Do you want to use it?"),
                    GetChars( newname ), GetChars( near_name ) );

                if( IsOK( this, msg ) )
                {
                    chipnameTextCtrl->SetValue( near_name );
                    m_Cmp->SetPartName( near_name, libs );
                }
            }
            else
            {
                wxString msg = wxString::Format( _(
                    "Component '%s' not found!" ),
                    GetChars( newname ) );
                "Component '%s' not found!" ),  GetChars( newname ) );
            DisplayError( this, msg );
        }
        }
        else    // Change component from lib!
        {
            m_Cmp->SetPartName( newname, libs );
Loading