Eeschema: implement new symbol library file s-expression formatter.

CHANGES: Symbol library file format has been converted to s-expressions.

Add support code for picking apart symbols at some future junction that
will allow full inheritance conversion of existing symbol libraries.  For
now, symbols arranged by unit and body style numbers are nested for round
robin testing of symbol libraries once the parser is complete.
This commit is contained in:
Wayne Stambaugh 2020-02-13 08:39:52 -05:00
parent d6706c257c
commit e1900161a7
34 changed files with 2747 additions and 81 deletions

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2012 CERN * Copyright (C) 2012 CERN
* Copyright (C) 1992-2018 KiCad Developers, see change_log.txt for contributors. * Copyright (C) 1992-2020 KiCad Developers, see change_log.txt for contributors.
* *
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -181,7 +181,7 @@ wxString MessageTextFromValue( EDA_UNITS aUnits, double aValue, bool aUseMils, E
else else
{ {
#if defined( EESCHEMA ) #if defined( EESCHEMA )
format = wxT( "%.2f" ); format = wxT( "%.4f" );
#else #else
format = wxT( "%.3f" ); format = wxT( "%.3f" );
#endif #endif
@ -526,9 +526,7 @@ std::string FormatInternalUnits( int aValue )
double engUnits = aValue; double engUnits = aValue;
int len; int len;
#ifndef EESCHEMA
engUnits /= IU_PER_MM; engUnits /= IU_PER_MM;
#endif
if( engUnits != 0.0 && fabs( engUnits ) <= 0.0001 ) if( engUnits != 0.0 && fabs( engUnits ) <= 0.0001 )
{ {
@ -537,11 +535,9 @@ std::string FormatInternalUnits( int aValue )
while( --len > 0 && buf[len] == '0' ) while( --len > 0 && buf[len] == '0' )
buf[len] = '\0'; buf[len] = '\0';
#ifndef EESCHEMA
if( buf[len] == '.' ) if( buf[len] == '.' )
buf[len] = '\0'; buf[len] = '\0';
else else
#endif
++len; ++len;
} }
else else

View File

@ -3,7 +3,7 @@
* *
* Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com> * Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -114,6 +114,7 @@ wxString AddFileExtListToFilter( const std::vector<std::string>& aExts )
} }
const std::string KiCadSymbolLibFileExtension( "kicad_sym" );
const std::string SchematicSymbolFileExtension( "sym" ); const std::string SchematicSymbolFileExtension( "sym" );
const std::string SchematicLibraryFileExtension( "lib" ); const std::string SchematicLibraryFileExtension( "lib" );
@ -172,9 +173,15 @@ wxString SchematicSymbolFileWildcard()
} }
wxString KiCadSymbolLibFileWildcard()
{
return _( "KiCad symbol library files" ) + AddFileExtListToFilter( { "kicad_sym" } );
}
wxString SchematicLibraryFileWildcard() wxString SchematicLibraryFileWildcard()
{ {
return _( "KiCad symbol library files" ) + AddFileExtListToFilter( { "lib" } ); return _( "KiCad legacy symbol library files" ) + AddFileExtListToFilter( { "lib" } );
} }

View File

@ -199,6 +199,7 @@ set( EESCHEMA_SRCS
sch_plugin.cpp sch_plugin.cpp
sch_preview_panel.cpp sch_preview_panel.cpp
sch_screen.cpp sch_screen.cpp
sch_sexpr_plugin.cpp
sch_sheet.cpp sch_sheet.cpp
sch_sheet_path.cpp sch_sheet_path.cpp
sch_sheet_pin.cpp sch_sheet_pin.cpp
@ -476,4 +477,12 @@ make_lexer(
T_BOMCFG_T T_BOMCFG_T
) )
make_lexer(
eeschema_kiface_objects
symbol_lib.keywords
symbol_lib_lexer.h
symbol_lib_keywords.cpp
TSYMBOL_LIB_T
)
add_subdirectory( plugins ) add_subdirectory( plugins )

View File

@ -90,7 +90,7 @@ LIB_PART::LIB_PART( const wxString& aName, LIB_PART* aParent, PART_LIB* aLibrary
{ {
m_dateLastEdition = 0; m_dateLastEdition = 0;
m_unitCount = 1; m_unitCount = 1;
m_pinNameOffset = Mils2iu( 40 ); m_pinNameOffset = Mils2iu( DEFAULT_PIN_NAME_OFFSET );
m_options = ENTRY_NORMAL; m_options = ENTRY_NORMAL;
m_unitsLocked = false; m_unitsLocked = false;
m_showPinNumbers = true; m_showPinNumbers = true;
@ -1123,3 +1123,161 @@ void LIB_PART::SetSubpartIdNotation( int aSep, int aFirstId )
if( aFirstId == '1' && aSep != 0 ) if( aFirstId == '1' && aSep != 0 )
m_subpartFirstId = aFirstId; m_subpartFirstId = aFirstId;
} }
std::vector<LIB_ITEM*> LIB_PART::GetUnitItems( int aUnit, int aConvert )
{
std::vector<LIB_ITEM*> unitItems;
for( LIB_ITEM& item : m_drawings )
{
if( item.Type() == LIB_FIELD_T )
continue;
if( ( aConvert == -1 && item.GetUnit() == aUnit )
|| ( aUnit == -1 && item.GetConvert() == aConvert )
|| ( aUnit == item.GetUnit() && aConvert == item.GetConvert() ) )
unitItems.push_back( &item );
}
return unitItems;
}
std::vector<struct PART_UNITS> LIB_PART::GetUnitDrawItems()
{
std::vector<struct PART_UNITS> units;
for( LIB_ITEM& item : m_drawings )
{
if( item.Type() == LIB_FIELD_T )
continue;
int unit = item.GetUnit();
int convert = item.GetConvert();
auto it = std::find_if( units.begin(), units.end(),
[unit, convert] ( const auto& a ) {
return a.m_unit == unit && a.m_convert == convert;
} );
if( it == units.end() )
{
struct PART_UNITS newUnit;
newUnit.m_unit = item.GetUnit();
newUnit.m_convert = item.GetConvert();
newUnit.m_items.push_back( &item );
units.emplace_back( newUnit );
}
else
{
it->m_items.push_back( &item );
}
}
return units;
}
std::vector<struct PART_UNITS> LIB_PART::GetUniqueUnits()
{
int unitNum;
size_t i;
struct PART_UNITS unit;
std::vector<LIB_ITEM*> compareDrawItems;
std::vector<LIB_ITEM*> currentDrawItems;
std::vector<struct PART_UNITS> uniqueUnits;
// The first unit is guarenteed to be unique so always include it.
unit.m_unit = 1;
unit.m_convert = 1;
unit.m_items = GetUnitItems( 1, 1 );
// There are no unique units if there are no draw items other than fields.
if( unit.m_items.size() == 0 )
return uniqueUnits;
uniqueUnits.emplace_back( unit );
if( ( GetUnitCount() == 1 || UnitsLocked() ) && !HasConversion() )
return uniqueUnits;
currentDrawItems = unit.m_items;
for( unitNum = 2; unitNum <= GetUnitCount(); unitNum++ )
{
compareDrawItems = GetUnitItems( unitNum, 1 );
wxCHECK2_MSG( compareDrawItems.size() != 0, continue,
"Multiple unit symbol defined with empty units." );
if( currentDrawItems.size() != compareDrawItems.size() )
{
unit.m_unit = unitNum;
unit.m_convert = 1;
unit.m_items = compareDrawItems;
uniqueUnits.emplace_back( unit );
}
else
{
for( i = 0; i < currentDrawItems.size(); i++ )
{
if( currentDrawItems[i]->compare( *compareDrawItems[i],
LIB_ITEM::COMPARE_FLAGS::UNIT ) != 0 )
{
unit.m_unit = unitNum;
unit.m_convert = 1;
unit.m_items = compareDrawItems;
uniqueUnits.emplace_back( unit );
}
}
}
}
if( HasConversion() )
{
currentDrawItems = GetUnitItems( 1, 2 );
if( ( GetUnitCount() == 1 || UnitsLocked() ) )
{
unit.m_unit = 1;
unit.m_convert = 2;
unit.m_items = currentDrawItems;
uniqueUnits.emplace_back( unit );
return uniqueUnits;
}
for( unitNum = 2; unitNum <= GetUnitCount(); unitNum++ )
{
compareDrawItems = GetUnitItems( unitNum, 2 );
wxCHECK2_MSG( compareDrawItems.size() != 0, continue,
"Multiple unit symbol defined with empty units." );
if( currentDrawItems.size() != compareDrawItems.size() )
{
unit.m_unit = unitNum;
unit.m_convert = 2;
unit.m_items = compareDrawItems;
uniqueUnits.emplace_back( unit );
}
else
{
for( i = 0; i < currentDrawItems.size(); i++ )
{
if( currentDrawItems[i]->compare( *compareDrawItems[i],
LIB_ITEM::COMPARE_FLAGS::UNIT ) != 0 )
{
unit.m_unit = unitNum;
unit.m_convert = 2;
unit.m_items = compareDrawItems;
uniqueUnits.emplace_back( unit );
}
}
}
}
}
return uniqueUnits;
}

View File

@ -3,7 +3,7 @@
* *
* Copyright (C) 2004-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2004-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com> * Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 2004-2019 KiCad Developers, see change_log.txt for contributors. * Copyright (C) 2004-2020 KiCad Developers, see change_log.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -82,6 +82,14 @@ struct PART_DRAW_OPTIONS
}; };
struct PART_UNITS
{
int m_unit; ///< The unit number.
int m_convert; ///< The alternate body style of the unit.
std::vector<LIB_ITEM*> m_items; ///< The items unique to this unit and alternate body style.
};
/** /**
* Define a library symbol object. * Define a library symbol object.
* *
@ -584,6 +592,36 @@ public:
*/ */
std::unique_ptr< LIB_PART > Flatten() const; std::unique_ptr< LIB_PART > Flatten() const;
/**
* Return a list of LIB_ITEM objects separated by unit and convert number.
*
* @note This does not include LIB_FIELD objects since they are not associated with
* unit and/or convert numbers.
*/
std::vector<struct PART_UNITS> GetUnitDrawItems();
/**
* Return a list of unit numbers that are unique to this symbol.
*
* If the symbol is inherited (alias), the unique units of the parent symbol are returned.
* When comparing pins, the pin number is ignored.
*
* @return a list of unique unit numbers and their associated draw items.
*/
std::vector<struct PART_UNITS> GetUniqueUnits();
/**
* Return a list of item pointers for \a aUnit and \a aConvert for this symbol.
*
* @note #LIB_FIELD objects are not included.
*
* @param aUnit is the unit number of the item, -1 includes all units.
* @param aConvert is the alternate body styple of the item, -1 includes all body styles.
*
* @return a list of unit items.
*/
std::vector<LIB_ITEM*> GetUnitItems( int aUnit, int aConvert );
#if defined(DEBUG) #if defined(DEBUG)
void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); } void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
#endif #endif

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2004-2019 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2004-2020 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2019 CERN * Copyright (C) 2019 CERN
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -74,7 +74,7 @@ bool LIB_ARC::HitTest( const wxPoint& aRefPoint, int aAccuracy ) const
// We are on the circle, ensure we are only on the arc, i.e. between // We are on the circle, ensure we are only on the arc, i.e. between
// m_ArcStart and m_ArcEnd // m_ArcStart and m_ArcEnd
wxPoint startEndVector = twoPointVector( m_ArcStart, m_ArcEnd); wxPoint startEndVector = twoPointVector( m_ArcStart, m_ArcEnd );
wxPoint startRelativePositionVector = twoPointVector( m_ArcStart, relativePosition ); wxPoint startRelativePositionVector = twoPointVector( m_ArcStart, relativePosition );
wxPoint centerStartVector = twoPointVector( m_Pos, m_ArcStart ); wxPoint centerStartVector = twoPointVector( m_Pos, m_ArcStart );
@ -132,10 +132,15 @@ EDA_ITEM* LIB_ARC::Clone() const
} }
int LIB_ARC::compare( const LIB_ITEM& aOther ) const int LIB_ARC::compare( const LIB_ITEM& aOther, LIB_ITEM::COMPARE_FLAGS aCompareFlags ) const
{ {
wxASSERT( aOther.Type() == LIB_ARC_T ); wxASSERT( aOther.Type() == LIB_ARC_T );
int retv = LIB_ITEM::compare( aOther );
if( retv )
return retv;
const LIB_ARC* tmp = ( LIB_ARC* ) &aOther; const LIB_ARC* tmp = ( LIB_ARC* ) &aOther;
if( m_Pos.x != tmp->m_Pos.x ) if( m_Pos.x != tmp->m_Pos.x )

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2004-2019 KiCad Developers, see change_log.txt for contributors. * Copyright (C) 2004-2020 KiCad Developers, see change_log.txt for contributors.
* Copyright (C) 2019 CERN * Copyright (C) 2019 CERN
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -139,7 +139,8 @@ private:
* - Arc start angle. * - Arc start angle.
* - Arc end angle. * - Arc end angle.
*/ */
int compare( const LIB_ITEM& aOther ) const override; int compare( const LIB_ITEM& aOther,
LIB_ITEM::COMPARE_FLAGS aCompareFlags = LIB_ITEM::COMPARE_FLAGS::NORMAL ) const override;
}; };

View File

@ -1,7 +1,7 @@
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2004-2019 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2004-2020 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -51,10 +51,15 @@ EDA_ITEM* LIB_BEZIER::Clone() const
} }
int LIB_BEZIER::compare( const LIB_ITEM& aOther ) const int LIB_BEZIER::compare( const LIB_ITEM& aOther, LIB_ITEM::COMPARE_FLAGS aCompareFlags ) const
{ {
wxASSERT( aOther.Type() == LIB_BEZIER_T ); wxASSERT( aOther.Type() == LIB_BEZIER_T );
int retv = LIB_ITEM::compare( aOther );
if( retv )
return retv;
const LIB_BEZIER* tmp = ( LIB_BEZIER* ) &aOther; const LIB_BEZIER* tmp = ( LIB_BEZIER* ) &aOther;
if( m_BezierPoints.size() != tmp->m_BezierPoints.size() ) if( m_BezierPoints.size() != tmp->m_BezierPoints.size() )

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2004-2019 KiCad Developers, see change_log.txt for contributors. * Copyright (C) 2004-2020 KiCad Developers, see change_log.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -29,8 +29,7 @@
/** /**
* LIB_BEZIER * Define a bezier curve graphic body item.
* defines bezier curve graphic body item.
*/ */
class LIB_BEZIER : public LIB_ITEM class LIB_BEZIER : public LIB_ITEM
{ {
@ -80,7 +79,7 @@ public:
void MoveTo( const wxPoint& aPosition ) override; void MoveTo( const wxPoint& aPosition ) override;
wxPoint GetPosition() const override; wxPoint GetPosition() const override;
void MirrorHorizontal( const wxPoint& aCenter ) override; void MirrorHorizontal( const wxPoint& aCenter ) override;
void MirrorVertical( const wxPoint& aCenter ) override; void MirrorVertical( const wxPoint& aCenter ) override;
@ -107,7 +106,8 @@ private:
* - Bezier horizontal (X) point position. * - Bezier horizontal (X) point position.
* - Bezier vertical (Y) point position. * - Bezier vertical (Y) point position.
*/ */
int compare( const LIB_ITEM& aOther ) const override; int compare( const LIB_ITEM& aOther,
LIB_ITEM::COMPARE_FLAGS aCompareFlags = LIB_ITEM::COMPARE_FLAGS::NORMAL ) const override;
}; };

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2004-2019 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2004-2020 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -90,10 +90,15 @@ EDA_ITEM* LIB_CIRCLE::Clone() const
} }
int LIB_CIRCLE::compare( const LIB_ITEM& aOther ) const int LIB_CIRCLE::compare( const LIB_ITEM& aOther, LIB_ITEM::COMPARE_FLAGS aCompareFlags ) const
{ {
wxASSERT( aOther.Type() == LIB_CIRCLE_T ); wxASSERT( aOther.Type() == LIB_CIRCLE_T );
int retv = LIB_ITEM::compare( aOther, aCompareFlags );
if( retv )
return retv;
const LIB_CIRCLE* tmp = ( LIB_CIRCLE* ) &aOther; const LIB_CIRCLE* tmp = ( LIB_CIRCLE* ) &aOther;
if( m_Pos.x != tmp->m_Pos.x ) if( m_Pos.x != tmp->m_Pos.x )

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2004-2019 KiCad Developers, see change_log.txt for contributors. * Copyright (C) 2004-2020 KiCad Developers, see change_log.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -107,7 +107,8 @@ private:
* - Circle vertical (Y) position. * - Circle vertical (Y) position.
* - Circle radius. * - Circle radius.
*/ */
int compare( const LIB_ITEM& aOther ) const override; int compare( const LIB_ITEM& aOther,
LIB_ITEM::COMPARE_FLAGS aCompareFlags = LIB_ITEM::COMPARE_FLAGS::NORMAL ) const override;
}; };

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2004-2019 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2004-2020 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -55,7 +55,7 @@ LIB_FIELD::LIB_FIELD( int idfield ) :
} }
LIB_FIELD::LIB_FIELD( int aID, wxString& aName ) : LIB_FIELD::LIB_FIELD( int aID, const wxString& aName ) :
LIB_ITEM( LIB_FIELD_T, NULL ) LIB_ITEM( LIB_FIELD_T, NULL )
{ {
Init( aID ); Init( aID );
@ -184,11 +184,16 @@ void LIB_FIELD::Copy( LIB_FIELD* aTarget ) const
} }
int LIB_FIELD::compare( const LIB_ITEM& other ) const int LIB_FIELD::compare( const LIB_ITEM& aOther, LIB_ITEM::COMPARE_FLAGS aCompareFlags ) const
{ {
wxASSERT( other.Type() == LIB_FIELD_T ); wxASSERT( aOther.Type() == LIB_FIELD_T );
const LIB_FIELD* tmp = ( LIB_FIELD* ) &other; int retv = LIB_ITEM::compare( aOther, aCompareFlags );
if( retv )
return retv;
const LIB_FIELD* tmp = ( LIB_FIELD* ) &aOther;
if( m_id != tmp->m_id ) if( m_id != tmp->m_id )
return m_id - tmp->m_id; return m_id - tmp->m_id;
@ -449,3 +454,9 @@ BITMAP_DEF LIB_FIELD::GetMenuImage() const
{ {
return move_xpm; return move_xpm;
} }
bool LIB_FIELD::IsMandatory() const
{
return m_id < MANDATORY_FIELDS;
}

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2004-2019 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2004-2020 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -84,7 +84,7 @@ public:
LIB_FIELD( int idfield = 2 ); LIB_FIELD( int idfield = 2 );
LIB_FIELD( int aID, wxString& aName ); LIB_FIELD( int aID, const wxString& aName );
LIB_FIELD( LIB_PART * aParent, int idfield = 2 ); LIB_FIELD( LIB_PART * aParent, int idfield = 2 );
@ -198,6 +198,8 @@ public:
EDA_ITEM* Clone() const override; EDA_ITEM* Clone() const override;
bool IsMandatory() const;
private: private:
/** /**
@ -212,7 +214,8 @@ private:
* - Field width. * - Field width.
* - Field height. * - Field height.
*/ */
int compare( const LIB_ITEM& aOther ) const override; int compare( const LIB_ITEM& aOther,
LIB_ITEM::COMPARE_FLAGS aCompareFlags = LIB_ITEM::COMPARE_FLAGS::NORMAL ) const override;
}; };
typedef std::vector< LIB_FIELD > LIB_FIELDS; typedef std::vector< LIB_FIELD > LIB_FIELDS;

View File

@ -73,12 +73,25 @@ void LIB_ITEM::GetMsgPanelInfo( EDA_UNITS aUnits, MSG_PANEL_ITEMS& aList )
} }
int LIB_ITEM::compare( const LIB_ITEM& aOther, LIB_ITEM::COMPARE_FLAGS aCompareFlags ) const
{
if( Type() != aOther.Type() )
return Type() - aOther.Type();
// When comparing unit LIB_ITEM objects, we ignore the unit number.
if( !( aCompareFlags & COMPARE_FLAGS::UNIT ) && m_Unit != aOther.m_Unit )
return m_Unit - aOther.m_Unit;
if( !( aCompareFlags & COMPARE_FLAGS::UNIT ) && m_Convert != aOther.m_Convert )
return m_Convert - m_Convert;
return 0;
}
bool LIB_ITEM::operator==( const LIB_ITEM& aOther ) const bool LIB_ITEM::operator==( const LIB_ITEM& aOther ) const
{ {
return ( ( Type() == aOther.Type() ) return compare( aOther ) == 0;
&& ( m_Unit == aOther.m_Unit )
&& ( m_Convert == aOther.m_Convert )
&& compare( aOther ) == 0 );
} }

View File

@ -3,7 +3,7 @@
* *
* Copyright (C) 2015 Jean-Pierre Charras, jaen-pierre.charras at wanadoo.fr * Copyright (C) 2015 Jean-Pierre Charras, jaen-pierre.charras at wanadoo.fr
* Copyright (C) 2015 Wayne Stambaugh <stambaughw@gmail.com> * Copyright (C) 2015 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 2004-2019 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2004-2020 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -106,6 +106,15 @@ public:
// Define the enums for basic // Define the enums for basic
enum LIB_CONVERT : int { BASE = 1, DEMORGAN = 2 }; enum LIB_CONVERT : int { BASE = 1, DEMORGAN = 2 };
/**
* The list of flags used by the #compare function.
*
* - NORMAL This compares everthing between two #LIB_ITEM objects.
* - UNIT This compare flag ignores unit and convert and pin number information when
* comparing #LIB_ITEM objects for unit comparison.
*/
enum COMPARE_FLAGS : int { NORMAL = 0x00, UNIT = 0x01 };
/** /**
* Provide a user-consumable name of the object type. Perform localization when * Provide a user-consumable name of the object type. Perform localization when
* called so that run-time language selection works. * called so that run-time language selection works.
@ -309,7 +318,7 @@ public:
void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); } void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
#endif #endif
private: protected:
/** /**
* Provide the draw object specific comparison called by the == and < operators. * Provide the draw object specific comparison called by the == and < operators.
@ -321,12 +330,18 @@ private:
* - KICAD_T enum value. * - KICAD_T enum value.
* - Result of derived classes comparison. * - Result of derived classes comparison.
* *
* @note Make sure you call down to #LIB_ITEM::compare before doing any derived object
* comparisons or you will break the sorting using the symbol library file format.
*
* @param aOther A reference to the other #LIB_ITEM to compare the arc against. * @param aOther A reference to the other #LIB_ITEM to compare the arc against.
* @param aCompareFlags The flags used to perform the comparison.
*
* @return An integer value less than 0 if the object is less than \a aOther ojbect, * @return An integer value less than 0 if the object is less than \a aOther ojbect,
* zero if the object is equal to \a aOther object, or greater than 0 if the * zero if the object is equal to \a aOther object, or greater than 0 if the
* object is greater than \a aOther object. * object is greater than \a aOther object.
*/ */
virtual int compare( const LIB_ITEM& aOther ) const = 0; virtual int compare( const LIB_ITEM& aOther,
LIB_ITEM::COMPARE_FLAGS aCompareFlags = LIB_ITEM::COMPARE_FLAGS::NORMAL ) const;
}; };

View File

@ -1237,18 +1237,25 @@ EDA_ITEM* LIB_PIN::Clone() const
} }
int LIB_PIN::compare( const LIB_ITEM& other ) const int LIB_PIN::compare( const LIB_ITEM& aOther, LIB_ITEM::COMPARE_FLAGS aCompareFlags ) const
{ {
wxASSERT( other.Type() == LIB_PIN_T ); wxASSERT( aOther.Type() == LIB_PIN_T );
const LIB_PIN* tmp = (LIB_PIN*) &other; int retv = LIB_ITEM::compare( aOther, aCompareFlags );
if( m_number != tmp->m_number ) if( retv )
return retv;
const LIB_PIN* tmp = (LIB_PIN*) &aOther;
// When comparing units, we do not compare the part numbers. If everything else is
// identical, then we can just renumber the parts for the inherited symbol.
if( !( aCompareFlags & COMPARE_FLAGS::UNIT ) && m_number != tmp->m_number )
return m_number.Cmp( tmp->m_number ); return m_number.Cmp( tmp->m_number );
int result = m_name.CmpNoCase( tmp->m_name ); int result = m_name.CmpNoCase( tmp->m_name );
if( result != 0 ) if( result )
return result; return result;
if( m_position.x != tmp->m_position.x ) if( m_position.x != tmp->m_position.x )
@ -1257,6 +1264,30 @@ int LIB_PIN::compare( const LIB_ITEM& other ) const
if( m_position.y != tmp->m_position.y ) if( m_position.y != tmp->m_position.y )
return m_position.y - tmp->m_position.y; return m_position.y - tmp->m_position.y;
if( m_length != tmp->m_length )
return m_length - tmp->m_length;
if( m_orientation != tmp->m_orientation )
return m_orientation - tmp->m_orientation;
if( m_shape != tmp->m_shape )
return static_cast<int>( m_shape ) - static_cast<int>( tmp->m_shape );
if( m_type != tmp->m_type )
return static_cast<int>( m_type ) - static_cast<int>( tmp->m_type );
if( m_attributes != tmp->m_attributes )
return m_attributes - tmp->m_attributes;
if( m_width != tmp->m_width )
return m_width - tmp->m_width;
if( m_numTextSize != tmp->m_numTextSize )
return m_numTextSize - tmp->m_numTextSize;
if( m_nameTextSize != tmp->m_nameTextSize )
return m_nameTextSize - tmp->m_nameTextSize;
return 0; return 0;
} }

View File

@ -3,7 +3,7 @@
* *
* Copyright (C) 2015 Jean-Pierre Charras, jaen-pierre.charras at wanadoo.fr * Copyright (C) 2015 Jean-Pierre Charras, jaen-pierre.charras at wanadoo.fr
* Copyright (C) 2015 Wayne Stambaugh <stambaughw@gmail.com> * Copyright (C) 2015 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 2004-2019 KiCad Developers, see change_log.txt for contributors. * Copyright (C) 2004-2020 KiCad Developers, see change_log.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -39,6 +39,9 @@ class SCH_COMPONENT;
#include "pin_type.h" #include "pin_type.h"
#include "class_libentry.h" #include "class_libentry.h"
/// The offset of the pin name string from the end of the pin in mils.
#define DEFAULT_PIN_NAME_OFFSET 40
// Circle diameter drawn at the active end of pins: // Circle diameter drawn at the active end of pins:
#define TARGET_PIN_RADIUS Mils2iu( 15 ) #define TARGET_PIN_RADIUS Mils2iu( 15 )
@ -472,7 +475,8 @@ private:
* - Pin horizontal (X) position. * - Pin horizontal (X) position.
* - Pin vertical (Y) position. * - Pin vertical (Y) position.
*/ */
int compare( const LIB_ITEM& aOther ) const override; int compare( const LIB_ITEM& aOther,
LIB_ITEM::COMPARE_FLAGS aCompareFlags = LIB_ITEM::COMPARE_FLAGS::NORMAL ) const override;
}; };

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2004-2019 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2004-2020 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -52,10 +52,15 @@ EDA_ITEM* LIB_POLYLINE::Clone() const
} }
int LIB_POLYLINE::compare( const LIB_ITEM& aOther ) const int LIB_POLYLINE::compare( const LIB_ITEM& aOther, LIB_ITEM::COMPARE_FLAGS aCompareFlags ) const
{ {
wxASSERT( aOther.Type() == LIB_POLYLINE_T ); wxASSERT( aOther.Type() == LIB_POLYLINE_T );
int retv = LIB_ITEM::compare( aOther );
if( retv )
return retv;
const LIB_POLYLINE* tmp = (LIB_POLYLINE*) &aOther; const LIB_POLYLINE* tmp = (LIB_POLYLINE*) &aOther;
if( m_PolyPoints.size() != tmp->m_PolyPoints.size() ) if( m_PolyPoints.size() != tmp->m_PolyPoints.size() )

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2004-2019 KiCad Developers, see change_log.txt for contributors. * Copyright (C) 2004-2020 KiCad Developers, see change_log.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -119,7 +119,8 @@ private:
* - Line segment point horizontal (X) position. * - Line segment point horizontal (X) position.
* - Line segment point vertical (Y) position. * - Line segment point vertical (Y) position.
*/ */
int compare( const LIB_ITEM& aOther ) const override; int compare( const LIB_ITEM& aOther,
LIB_ITEM::COMPARE_FLAGS aCompareFlags = LIB_ITEM::COMPARE_FLAGS::NORMAL ) const override;
}; };

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2004-2019 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2004-2020 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -52,10 +52,15 @@ EDA_ITEM* LIB_RECTANGLE::Clone() const
} }
int LIB_RECTANGLE::compare( const LIB_ITEM& aOther ) const int LIB_RECTANGLE::compare( const LIB_ITEM& aOther, LIB_ITEM::COMPARE_FLAGS aCompareFlags ) const
{ {
wxASSERT( aOther.Type() == LIB_RECTANGLE_T ); wxASSERT( aOther.Type() == LIB_RECTANGLE_T );
int retv = LIB_ITEM::compare( aOther );
if( retv )
return retv;
const LIB_RECTANGLE* tmp = ( LIB_RECTANGLE* ) &aOther; const LIB_RECTANGLE* tmp = ( LIB_RECTANGLE* ) &aOther;
if( m_Pos.x != tmp->m_Pos.x ) if( m_Pos.x != tmp->m_Pos.x )

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2004-2019 KiCad Developers, see change_log.txt for contributors. * Copyright (C) 2004-2020 KiCad Developers, see change_log.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -105,7 +105,8 @@ private:
* - Rectangle horizontal (X) end position. * - Rectangle horizontal (X) end position.
* - Rectangle vertical (Y) end position. * - Rectangle vertical (Y) end position.
*/ */
int compare( const LIB_ITEM& aOther ) const override; int compare( const LIB_ITEM& aOther,
LIB_ITEM::COMPARE_FLAGS aCompareFlags = LIB_ITEM::COMPARE_FLAGS::NORMAL ) const override;
}; };

View File

@ -1,7 +1,7 @@
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2004-2019 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2004-2020 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -89,11 +89,16 @@ EDA_ITEM* LIB_TEXT::Clone() const
} }
int LIB_TEXT::compare( const LIB_ITEM& other ) const int LIB_TEXT::compare( const LIB_ITEM& aOther, LIB_ITEM::COMPARE_FLAGS aCompareFlags ) const
{ {
wxASSERT( other.Type() == LIB_TEXT_T ); wxASSERT( aOther.Type() == LIB_TEXT_T );
const LIB_TEXT* tmp = ( LIB_TEXT* ) &other; int retv = LIB_ITEM::compare( aOther, aCompareFlags );
if( retv )
return retv;
const LIB_TEXT* tmp = ( LIB_TEXT* ) &aOther;
int result = GetText().CmpNoCase( tmp->GetText() ); int result = GetText().CmpNoCase( tmp->GetText() );

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2004-2017 KiCad Developers, see change_log.txt for contributors. * Copyright (C) 2004-2020 KiCad Developers, see change_log.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -115,7 +115,8 @@ private:
* - Text width. * - Text width.
* - Text height. * - Text height.
*/ */
int compare( const LIB_ITEM& aOther ) const override; int compare( const LIB_ITEM& aOther,
LIB_ITEM::COMPARE_FLAGS aCompareFlags = LIB_ITEM::COMPARE_FLAGS::NORMAL ) const override;
}; };

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2017 CERN * Copyright (C) 2017 CERN
* Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2019-2020 KiCad Developers, see AUTHORS.txt for contributors.
* @author Maciej Suminski <maciej.suminski@cern.ch> * @author Maciej Suminski <maciej.suminski@cern.ch>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -31,8 +31,9 @@
#include <pgm_base.h> #include <pgm_base.h>
#include <kiway.h> #include <kiway.h>
#include <profile.h> #include <profile.h>
#include <symbol_lib_table.h> #include <sch_io_mgr.h>
#include <sch_legacy_plugin.h> #include <sch_legacy_plugin.h>
#include <symbol_lib_table.h>
#include <list> #include <list>
@ -129,12 +130,13 @@ SYMBOL_LIB_TABLE_ROW* LIB_MANAGER::GetLibrary( const wxString& aLibrary ) const
} }
bool LIB_MANAGER::SaveLibrary( const wxString& aLibrary, const wxString& aFileName ) bool LIB_MANAGER::SaveLibrary( const wxString& aLibrary, const wxString& aFileName,
SCH_IO_MGR::SCH_FILE_T aFileType )
{ {
wxCHECK( LibraryExists( aLibrary ), false ); wxCHECK( LibraryExists( aLibrary ), false );
wxFileName fn( aFileName ); wxFileName fn( aFileName );
wxCHECK( !fn.FileExists() || fn.IsFileWritable(), false ); wxCHECK( !fn.FileExists() || fn.IsFileWritable(), false );
SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_LEGACY ) ); SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( aFileType ) );
bool res = true; // assume all libraries are successfully saved bool res = true; // assume all libraries are successfully saved
auto it = m_libs.find( aLibrary ); auto it = m_libs.find( aLibrary );

View File

@ -33,6 +33,7 @@
#include <memory> #include <memory>
#include <wx/arrstr.h> #include <wx/arrstr.h>
#include <symbol_tree_synchronizing_adapter.h> #include <symbol_tree_synchronizing_adapter.h>
#include <sch_io_mgr.h>
#include <sch_screen.h> #include <sch_screen.h>
class LIB_PART; class LIB_PART;
@ -235,7 +236,8 @@ public:
* @param aFileName is the target file name. * @param aFileName is the target file name.
* @return True on success, false otherwise. * @return True on success, false otherwise.
*/ */
bool SaveLibrary( const wxString& aLibrary, const wxString& aFileName ); bool SaveLibrary( const wxString& aLibrary, const wxString& aFileName,
SCH_IO_MGR::SCH_FILE_T aFileType = SCH_IO_MGR::SCH_FILE_T::SCH_LEGACY );
/** /**
* Reverts unsaved changes for a particular part. * Reverts unsaved changes for a particular part.

View File

@ -3,7 +3,7 @@
* *
* Copyright (C) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com> * Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 2004-2019 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2004-2020 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -789,6 +789,7 @@ bool LIB_EDIT_FRAME::saveLibrary( const wxString& aLibrary, bool aNewFile )
{ {
wxFileName fn; wxFileName fn;
wxString msg; wxString msg;
SCH_IO_MGR::SCH_FILE_T aFileType = SCH_IO_MGR::SCH_FILE_T::SCH_LEGACY;
PROJECT& prj = Prj(); PROJECT& prj = Prj();
m_toolManager->RunAction( ACTIONS::cancelInteractive, true ); m_toolManager->RunAction( ACTIONS::cancelInteractive, true );
@ -812,8 +813,11 @@ bool LIB_EDIT_FRAME::saveLibrary( const wxString& aLibrary, bool aNewFile )
fn.SetName( aLibrary ); fn.SetName( aLibrary );
fn.SetExt( SchematicLibraryFileExtension ); fn.SetExt( SchematicLibraryFileExtension );
wxString wildcards = SchematicLibraryFileWildcard();
wildcards += "|" + KiCadSymbolLibFileWildcard();
wxFileDialog dlg( this, wxString::Format( _( "Save Library \"%s\" As..." ), aLibrary ), wxFileDialog dlg( this, wxString::Format( _( "Save Library \"%s\" As..." ), aLibrary ),
default_path, fn.GetFullName(), SchematicLibraryFileWildcard(), default_path, fn.GetFullName(), wildcards,
wxFD_SAVE | wxFD_OVERWRITE_PROMPT ); wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
if( dlg.ShowModal() == wxID_CANCEL ) if( dlg.ShowModal() == wxID_CANCEL )
@ -821,10 +825,16 @@ bool LIB_EDIT_FRAME::saveLibrary( const wxString& aLibrary, bool aNewFile )
fn = dlg.GetPath(); fn = dlg.GetPath();
// The GTK file chooser doesn't return the file extension added to // Update the file extension and plugin if a different library type was selected.
// file name so add it here. if( dlg.GetFilterIndex() == 0 )
if( fn.GetExt().IsEmpty() ) {
fn.SetExt( SchematicLibraryFileExtension ); fn.SetExt( SchematicLibraryFileExtension );
}
else
{
fn.SetExt( KiCadSymbolLibFileExtension );
aFileType = SCH_IO_MGR::SCH_FILE_T::SCH_KICAD;
}
} }
else else
{ {
@ -848,7 +858,7 @@ bool LIB_EDIT_FRAME::saveLibrary( const wxString& aLibrary, bool aNewFile )
if( !backupFile( docFileName, "bck" ) ) if( !backupFile( docFileName, "bck" ) )
return false; return false;
if( !m_libMgr->SaveLibrary( aLibrary, fn.GetFullPath() ) ) if( !m_libMgr->SaveLibrary( aLibrary, fn.GetFullPath(), aFileType ) )
{ {
msg.Printf( _( "Failed to save changes to symbol library file \"%s\"" ), msg.Printf( _( "Failed to save changes to symbol library file \"%s\"" ),
fn.GetFullPath() ); fn.GetFullPath() );

View File

@ -196,8 +196,8 @@ void SCH_BASE_FRAME::UpdateStatusBar()
break; break;
case EDA_UNITS::MILLIMETRES: case EDA_UNITS::MILLIMETRES:
absformatter = "X %.2f Y %.2f"; absformatter = "X %.4f Y %.4f";
locformatter = "dx %.2f dy %.2f dist %.2f"; locformatter = "dx %.4f dy %.4f dist %.4f";
break; break;
case EDA_UNITS::UNSCALED: case EDA_UNITS::UNSCALED:

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2016 CERN * Copyright (C) 2016 CERN
* Copyright (C) 2016-2017 KiCad Developers, see change_log.txt for contributors. * Copyright (C) 2016-2020 KiCad Developers, see change_log.txt for contributors.
* *
* @author Wayne Stambaugh <stambaughw@gmail.com> * @author Wayne Stambaugh <stambaughw@gmail.com>
* *
@ -26,6 +26,7 @@
#include <sch_io_mgr.h> #include <sch_io_mgr.h>
#include <sch_legacy_plugin.h> #include <sch_legacy_plugin.h>
#include <sch_eagle_plugin.h> #include <sch_eagle_plugin.h>
#include <sch_sexpr_plugin.h>
#include <wildcards_and_files_ext.h> #include <wildcards_and_files_ext.h>
@ -55,6 +56,8 @@ SCH_PLUGIN* SCH_IO_MGR::FindPlugin( SCH_FILE_T aFileType )
{ {
case SCH_LEGACY: case SCH_LEGACY:
return new SCH_LEGACY_PLUGIN(); return new SCH_LEGACY_PLUGIN();
case SCH_KICAD:
return new SCH_SEXPR_PLUGIN();
case SCH_EAGLE: case SCH_EAGLE:
return new SCH_EAGLE_PLUGIN(); return new SCH_EAGLE_PLUGIN();
} }
@ -87,6 +90,9 @@ const wxString SCH_IO_MGR::ShowType( SCH_FILE_T aType )
case SCH_LEGACY: case SCH_LEGACY:
return wxString( wxT( "Legacy" ) ); return wxString( wxT( "Legacy" ) );
case SCH_KICAD:
return wxString( "KiCad" );
case SCH_EAGLE: case SCH_EAGLE:
return wxString( wxT( "EAGLE" ) ); return wxString( wxT( "EAGLE" ) );
} }
@ -101,6 +107,8 @@ SCH_IO_MGR::SCH_FILE_T SCH_IO_MGR::EnumFromStr( const wxString& aType )
if( aType == wxT( "Legacy" ) ) if( aType == wxT( "Legacy" ) )
return SCH_LEGACY; return SCH_LEGACY;
else if( aType == "KiCad" )
return SCH_KICAD;
else if( aType == wxT( "EAGLE" ) ) else if( aType == wxT( "EAGLE" ) )
return SCH_EAGLE; return SCH_EAGLE;
@ -134,6 +142,10 @@ SCH_IO_MGR::SCH_FILE_T SCH_IO_MGR::GuessPluginTypeFromLibPath( const wxString& a
{ {
ret = SCH_LEGACY; ret = SCH_LEGACY;
} }
else if( fn.GetExt() == KiCadSymbolLibFileExtension )
{
ret = SCH_KICAD;
}
return ret; return ret;
} }

View File

@ -5,7 +5,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2016 CERN * Copyright (C) 2016 CERN
* Copyright (C) 2016-2017 KiCad Developers, see CHANGELOG.TXT for contributors. * Copyright (C) 2016-2020 KiCad Developers, see CHANGELOG.TXT for contributors.
* *
* @author Wayne Stambaugh <stambaughw@gmail.com> * @author Wayne Stambaugh <stambaughw@gmail.com>
* *
@ -53,7 +53,7 @@ public:
DEFINE_ENUM_VECTOR( SCH_FILE_T, DEFINE_ENUM_VECTOR( SCH_FILE_T,
{ {
SCH_LEGACY, ///< Legacy Eeschema file formats prior to s-expression. SCH_LEGACY, ///< Legacy Eeschema file formats prior to s-expression.
// SCH_KICAD, ///< The s-expression version of the schematic file formats. SCH_KICAD, ///< The s-expression version of the schematic file formats.
SCH_EAGLE, ///< Autodesk Eagle file format SCH_EAGLE, ///< Autodesk Eagle file format
// Add your schematic type here. // Add your schematic type here.

File diff suppressed because it is too large Load Diff

171
eeschema/sch_sexpr_plugin.h Normal file
View File

@ -0,0 +1,171 @@
#ifndef _SCH_SEXPR_PLUGIN_H_
#define _SCH_SEXPR_PLUGIN_H_
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2020 CERN
*
* @author Wayne Stambaugh <stambaughw@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <memory>
#include <sch_io_mgr.h>
#include <stack>
#include <general.h>
class KIWAY;
class LINE_READER;
class SCH_SCREEN;
class SCH_SHEET;
class SCH_BITMAP;
class SCH_JUNCTION;
class SCH_NO_CONNECT;
class SCH_LINE;
class SCH_BUS_ENTRY_BASE;
class SCH_TEXT;
class SCH_COMPONENT;
class SCH_FIELD;
class PROPERTIES;
class SELECTION;
class SCH_SEXPR_PLUGIN_CACHE;
class LIB_PART;
class PART_LIB;
class BUS_ALIAS;
/**
* A #SCH_PLUGIN derivation for loading schematic files using the new s-expression
* file format.
*
* As with all SCH_PLUGINs there is no UI dependencies i.e. windowing calls allowed.
*/
class SCH_SEXPR_PLUGIN : public SCH_PLUGIN
{
public:
SCH_SEXPR_PLUGIN();
virtual ~SCH_SEXPR_PLUGIN();
const wxString GetName() const override
{
return wxT( "Eeschema-Legacy" );
}
const wxString GetFileExtension() const override
{
return wxT( "sch" );
}
/**
* The property used internally by the plugin to enable cache buffering which prevents
* the library file from being written every time the cache is changed. This is useful
* when writing the schematic cache library file or saving a library to a new file name.
*/
static const char* PropBuffering;
int GetModifyHash() const override;
SCH_SHEET* Load( const wxString& aFileName, KIWAY* aKiway,
SCH_SHEET* aAppendToMe = nullptr,
const PROPERTIES* aProperties = nullptr ) override;
void LoadContent( LINE_READER& aReader, SCH_SCREEN* aScreen,
int version = EESCHEMA_VERSION );
void Save( const wxString& aFileName, SCH_SCREEN* aScreen, KIWAY* aKiway,
const PROPERTIES* aProperties = nullptr ) override;
void Format( SCH_SCREEN* aScreen );
void Format( SELECTION* aSelection, OUTPUTFORMATTER* aFormatter );
void EnumerateSymbolLib( wxArrayString& aSymbolNameList,
const wxString& aLibraryPath,
const PROPERTIES* aProperties = nullptr ) override;
void EnumerateSymbolLib( std::vector<LIB_PART*>& aSymbolList,
const wxString& aLibraryPath,
const PROPERTIES* aProperties = nullptr ) override;
LIB_PART* LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
const PROPERTIES* aProperties = nullptr ) override;
void SaveSymbol( const wxString& aLibraryPath, const LIB_PART* aSymbol,
const PROPERTIES* aProperties = nullptr ) override;
void DeleteSymbol( const wxString& aLibraryPath, const wxString& aSymbolName,
const PROPERTIES* aProperties = nullptr ) override;
void CreateSymbolLib( const wxString& aLibraryPath,
const PROPERTIES* aProperties = nullptr ) override;
bool DeleteSymbolLib( const wxString& aLibraryPath,
const PROPERTIES* aProperties = nullptr ) override;
void SaveLibrary( const wxString& aLibraryPath,
const PROPERTIES* aProperties = nullptr ) override;
bool CheckHeader( const wxString& aFileName ) override;
bool IsSymbolLibWritable( const wxString& aLibraryPath ) override;
const wxString& GetError() const override { return m_error; }
static LIB_PART* ParsePart( LINE_READER& aReader, int majorVersion = 0, int minorVersion = 0 );
static void FormatPart( LIB_PART* aPart, OUTPUTFORMATTER& aFormatter );
private:
void loadHierarchy( SCH_SHEET* aSheet );
void loadHeader( LINE_READER& aReader, SCH_SCREEN* aScreen );
void loadPageSettings( LINE_READER& aReader, SCH_SCREEN* aScreen );
void loadFile( const wxString& aFileName, SCH_SCREEN* aScreen );
SCH_SHEET* loadSheet( LINE_READER& aReader );
SCH_BITMAP* loadBitmap( LINE_READER& aReader );
SCH_JUNCTION* loadJunction( LINE_READER& aReader );
SCH_NO_CONNECT* loadNoConnect( LINE_READER& aReader );
SCH_LINE* loadWire( LINE_READER& aReader );
SCH_BUS_ENTRY_BASE* loadBusEntry( LINE_READER& aReader );
SCH_TEXT* loadText( LINE_READER& aReader );
SCH_COMPONENT* loadComponent( LINE_READER& aReader );
std::shared_ptr<BUS_ALIAS> loadBusAlias( LINE_READER& aReader, SCH_SCREEN* aScreen );
void saveComponent( SCH_COMPONENT* aComponent );
void saveField( SCH_FIELD* aField );
void saveBitmap( SCH_BITMAP* aBitmap );
void saveSheet( SCH_SHEET* aSheet );
void saveJunction( SCH_JUNCTION* aJunction );
void saveNoConnect( SCH_NO_CONNECT* aNoConnect );
void saveBusEntry( SCH_BUS_ENTRY_BASE* aBusEntry );
void saveLine( SCH_LINE* aLine );
void saveText( SCH_TEXT* aText );
void saveBusAlias( std::shared_ptr<BUS_ALIAS> aAlias );
void cacheLib( const wxString& aLibraryFileName );
bool isBuffering( const PROPERTIES* aProperties );
protected:
int m_version; ///< Version of file being loaded.
/** For throwing exceptions or errors on partial schematic loads. */
wxString m_error;
wxString m_path; ///< Root project path for loading child sheets.
std::stack<wxString> m_currentPath;///< Stack to maintain nested sheet paths
const PROPERTIES* m_props; ///< Passed via Save() or Load(), no ownership, may be nullptr.
KIWAY* m_kiway; ///< Required for path to legacy component libraries.
SCH_SHEET* m_rootSheet; ///< The root sheet of the schematic being loaded..
OUTPUTFORMATTER* m_out; ///< The output formatter for saving SCH_SCREEN objects.
SCH_SEXPR_PLUGIN_CACHE* m_cache;
/// initialize PLUGIN like a constructor would.
void init( KIWAY* aKiway, const PROPERTIES* aProperties = nullptr );
};
#endif // _SCH_SEXPR_PLUGIN_H_

View File

@ -0,0 +1,59 @@
alternate
anchor
arc
at
atomic
bezier
bidirectional
circle
clock
clock_low
color
edge_clock_high
end
extends
fill
hint_alt_swap
hint_pin_swap
input
input_low
inverted
inverted_clock
kicad_symbol_lib
length
line
mid
name
non_logic
number
open_collector
open_emitter
output_low
unconnected
output
passive
pin
pin_del
pin_merge
pin_rename
polyline
power
power_in
power_out
property
property_del
pts
radius
rectangle
required
shape
start
stroke
symbol
text
tri_state
type
unspecified
uuid
width
xy

View File

@ -4,7 +4,7 @@
* Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2007-2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com> * Copyright (C) 2007-2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com> * Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -125,6 +125,7 @@ extern const std::string EquFileExtension;
extern const std::string LegacyPcbFileExtension; extern const std::string LegacyPcbFileExtension;
extern const std::string KiCadPcbFileExtension; extern const std::string KiCadPcbFileExtension;
#define PcbFileExtension KiCadPcbFileExtension // symlink choice #define PcbFileExtension KiCadPcbFileExtension // symlink choice
extern const std::string KiCadSymbolLibFileExtension;
extern const std::string PageLayoutDescrFileExtension; extern const std::string PageLayoutDescrFileExtension;
extern const std::string LegacyFootprintLibPathExtension; extern const std::string LegacyFootprintLibPathExtension;
@ -170,6 +171,7 @@ extern wxString AllFilesWildcard();
extern wxString ComponentFileWildcard(); extern wxString ComponentFileWildcard();
extern wxString PageLayoutDescrFileWildcard(); extern wxString PageLayoutDescrFileWildcard();
extern wxString SchematicSymbolFileWildcard(); extern wxString SchematicSymbolFileWildcard();
extern wxString KiCadSymbolLibFileWildcard();
extern wxString SchematicLibraryFileWildcard(); extern wxString SchematicLibraryFileWildcard();
extern wxString ProjectFileWildcard(); extern wxString ProjectFileWildcard();
extern wxString SchematicFileWildcard(); extern wxString SchematicFileWildcard();

View File

@ -1,7 +1,7 @@
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2019 KiCad Developers, see CHANGELOG.TXT for contributors. * Copyright (C) 2019-2020 KiCad Developers, see CHANGELOG.TXT for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -39,7 +39,8 @@
class TEST_LIB_PART_FIXTURE class TEST_LIB_PART_FIXTURE
{ {
public: public:
TEST_LIB_PART_FIXTURE() : m_part_no_data( "part_name", nullptr ) TEST_LIB_PART_FIXTURE() :
m_part_no_data( "part_name", nullptr )
{ {
} }
@ -368,6 +369,68 @@ BOOST_AUTO_TEST_CASE( Compare )
} }
/**
* Check the fetch unit items code.
*/
BOOST_AUTO_TEST_CASE( GetUnitItems )
{
// There are no unit draw items in the empty LIB_PART object.
BOOST_CHECK( m_part_no_data.GetUnitItems( 1, 1 ).size() == 0 );
// A single unique unit with 1 pin common to all units and all body styles.
LIB_PIN* pin1 = new LIB_PIN( &m_part_no_data );
m_part_no_data.AddDrawItem( pin1 );
BOOST_CHECK( m_part_no_data.GetUnitItems( 0, 0 ).size() == 1 );
// A single unique unit with 1 pin in unit 1 and common to all body styles.
pin1->SetUnit( 1 );
BOOST_CHECK( m_part_no_data.GetUnitItems( 1, 0 ).size() == 1 );
// A single unique unit with 1 pin in unit 1 and body style 1.
pin1->SetConvert( 1 );
BOOST_CHECK( m_part_no_data.GetUnitItems( 1, 1 ).size() == 1 );
// Two unique units with pin 1 assigned to unit 1 and body style 1 and pin 2 assinged to
// unit 2 and body style 1.
LIB_PIN* pin2 = new LIB_PIN( &m_part_no_data );
m_part_no_data.SetUnitCount( 2 );
pin2->SetUnit( 2 );
pin2->SetConvert( 2 );
pin2->SetNumber( "4" );
m_part_no_data.AddDrawItem( pin2 );
BOOST_CHECK( m_part_no_data.GetUnitItems( 2, 2 ).size() == 1 );
// Make pin 1 body style common to all units.
pin1->SetConvert( 0 );
BOOST_CHECK( m_part_no_data.GetUnitItems( 1, 1 ).size() == 0 );
BOOST_CHECK( m_part_no_data.GetUnitItems( 2, 1 ).size() == 1 );
m_part_no_data.RemoveDrawItem( pin2 );
m_part_no_data.RemoveDrawItem( pin1 );
m_part_no_data.RemoveDrawItem( m_part_no_data.GetNextDrawItem() );
}
/**
* Check the fetch unit draw items code.
*/
BOOST_AUTO_TEST_CASE( GetUnitDrawItems )
{
// There are no unit draw items in the empty LIB_PART object.
BOOST_CHECK( m_part_no_data.GetUnitDrawItems().size() == 0 );
// A single unique unit with 1 pin common to all units and all body styles.
LIB_PIN* pin1 = new LIB_PIN( &m_part_no_data );
pin1->SetNumber( "1" );
m_part_no_data.AddDrawItem( pin1 );
std::vector<struct PART_UNITS> units = m_part_no_data.GetUnitDrawItems();
BOOST_CHECK( units.size() == 1 );
BOOST_CHECK( units[0].m_unit == 0 );
BOOST_CHECK( units[0].m_convert == 0 );
BOOST_CHECK( units[0].m_items[0] == pin1 );
}
/** /**
* Check inheritance support. * Check inheritance support.
*/ */