Fix issues with Kicad Manager frame and new kicad_sch files.

Fixes https://gitlab.com/kicad/code/kicad/issues/4410
This commit is contained in:
Jeff Young 2020-05-12 12:53:45 +01:00
parent c3b50d38dd
commit 06dea92bcb
13 changed files with 75 additions and 35 deletions

View File

@ -266,7 +266,7 @@ void PAGE_INFO::SetHeightMils( int aHeightInMils )
void PAGE_INFO::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const
{
aFormatter->Print( aNestLevel, "(page %s", aFormatter->Quotew( GetType() ).c_str() );
aFormatter->Print( aNestLevel, "(paper %s", aFormatter->Quotew( GetType() ).c_str() );
// The page dimensions are only required for user defined page sizes.
// Internally, the page size is in mils

View File

@ -650,7 +650,7 @@ int SCH_REFERENCE_LIST::CheckAnnotation( REPORTER& aReporter )
SCH_REFERENCE::SCH_REFERENCE( SCH_COMPONENT* aComponent, LIB_PART* aLibPart,
SCH_SHEET_PATH& aSheetPath )
const SCH_SHEET_PATH& aSheetPath )
{
wxASSERT( aComponent != NULL );

View File

@ -39,4 +39,8 @@
*/
//#define SEXPR_SCHEMATIC_FILE_VERSION 20200310 // Initial version. Sheet fields were named
// incorectly (using symbol field vocabulary).
#define SEXPR_SCHEMATIC_FILE_VERSION 20200506
//#define SEXPR_SCHEMATIC_FILE_VERSION 20200506 // Used "page" instead of "paper" for paper
// sizes.
#define SEXPR_SCHEMATIC_FILE_VERSION 20200512

View File

@ -81,7 +81,7 @@ public:
}
SCH_REFERENCE( SCH_COMPONENT* aComponent, LIB_PART* aLibComponent,
SCH_SHEET_PATH& aSheetPath );
const SCH_SHEET_PATH& aSheetPath );
SCH_COMPONENT* GetComp() const { return m_RootCmp; }

View File

@ -1477,7 +1477,7 @@ LIB_TEXT* SCH_SEXPR_PARSER::parseText()
void SCH_SEXPR_PARSER::parsePAGE_INFO( PAGE_INFO& aPageInfo )
{
wxCHECK_RET( CurTok() == T_page,
wxCHECK_RET( CurTok() == T_paper,
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as a PAGE_INFO." ) );
T token;
@ -1886,9 +1886,12 @@ void SCH_SEXPR_PARSER::ParseSchematic( SCH_SHEET* aSheet )
token = NextTok();
if( token == T_page && m_requiredVersion <= 20200506 )
token = T_paper;
switch( token )
{
case T_page:
case T_paper:
{
PAGE_INFO pageInfo;
parsePAGE_INFO( pageInfo );
@ -1896,6 +1899,16 @@ void SCH_SEXPR_PARSER::ParseSchematic( SCH_SHEET* aSheet )
break;
}
case T_page:
{
// Only saved for top-level sniffing in Kicad Manager frame and other external
// tool usage with flat hierarchies
NeedSYMBOLorNUMBER();
NeedSYMBOLorNUMBER();
NeedRIGHT();
break;
}
case T_title_block:
{
TITLE_BLOCK tb;
@ -1986,7 +1999,7 @@ void SCH_SEXPR_PARSER::ParseSchematic( SCH_SHEET* aSheet )
break;
default:
Expecting( "symbol, page, title_block, bitmap, sheet, junction, no_connect, "
Expecting( "symbol, paper, page, title_block, bitmap, sheet, junction, no_connect, "
"bus_entry, line, bus, text, label, global_label, hierarchical_label, "
"symbol_instances, or bus_alias" );
}

View File

@ -612,6 +612,10 @@ void SCH_SEXPR_PLUGIN::Format( SCH_SHEET* aSheet )
// m_out->Print( 1, "(uuid %s)\n\n", m_out->Quotew( aSheet->m_Uuid.AsString() ).c_str() );
m_out->Print( 1, "(page %d %d)\n\n",
screen->m_ScreenNumber,
screen->m_NumberOfScreens );
screen->GetPageSettings().Format( m_out, 1, 0 );
m_out->Print( 0, "\n" );
screen->GetTitleBlock().Format( m_out, 1, 0 );
@ -624,18 +628,20 @@ void SCH_SEXPR_PLUGIN::Format( SCH_SHEET* aSheet )
m_out->Print( 1, ")\n\n" );
// @todo save schematic instance information (page #).
for( const auto& alias : screen->GetBusAliases() )
{
saveBusAlias( alias, 1 );
}
// Enforce item ordering
auto cmp = []( const SCH_ITEM* a, const SCH_ITEM* b ) { return *a < *b; };
auto cmp = []( const SCH_ITEM* a, const SCH_ITEM* b )
{
return *a < *b;
};
std::multiset<SCH_ITEM*, decltype( cmp )> save_map( cmp );
for( auto item : screen->Items() )
for( SCH_ITEM* item : screen->Items() )
save_map.insert( item );
KICAD_T itemType = TYPE_NOT_INIT;
@ -719,7 +725,7 @@ void SCH_SEXPR_PLUGIN::Format( SCH_SHEET* aSheet )
SCH_SHEET_LIST sheetPaths( aSheet );
for( auto sheetPath : sheetPaths )
for( const SCH_SHEET_PATH& sheetPath : sheetPaths )
{
SCH_REFERENCE_LIST instances;
@ -742,7 +748,7 @@ void SCH_SEXPR_PLUGIN::Format( SCH_SHEET* aSheet )
m_out->Print( 0, "\n" );
m_out->Print( 1, "(symbol_instances\n" );
for( auto instance : screen->m_symbolInstances )
for( const COMPONENT_INSTANCE_REFERENCE& instance : screen->m_symbolInstances )
{
m_out->Print( 2, "(path %s (reference %s) (unit %d))\n",
m_out->Quotew( instance.m_Path.AsString() ).c_str(),

View File

@ -184,7 +184,7 @@ void SCH_SHEET_PATH::UpdateAllScreenReferences()
void SCH_SHEET_PATH::GetComponents( SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols,
bool aForceIncludeOrphanComponents )
bool aForceIncludeOrphanComponents ) const
{
for( auto item : LastScreen()->Items().OfType( SCH_COMPONENT_T ) )
{

View File

@ -258,7 +258,7 @@ public:
* The normal option is false, and set to true only to build the full list of components.
*/
void GetComponents( SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols = true,
bool aForceIncludeOrphanComponents = false );
bool aForceIncludeOrphanComponents = false ) const;
/**
* Function GetMultiUnitComponents

View File

@ -71,6 +71,7 @@ output_low
unconnected
output
page
paper
passive
path
pin

View File

@ -44,9 +44,10 @@ class KICAD_SETTINGS;
enum TreeFileType {
TREE_ROOT = 0,
TREE_PROJECT,
TREE_SCHEMA, // Schematic file (.sch)
TREE_LEGACY_SCHEMATIC, // Schematic file (.sch)
TREE_SEXPR_SCHEMATIC, // Schematic file (.sch)
TREE_LEGACY_PCB, // board file (.brd) legacy format
TREE_SEXP_PCB, // board file (.kicad_brd) new s expression format
TREE_SEXPR_PCB, // board file (.kicad_brd) new s expression format
TREE_GERBER, // Gerber file (.pho, .g*)
TREE_HTML, // HTML file (.htm, *.html)
TREE_PDF, // PDF file (.pdf)

View File

@ -265,9 +265,10 @@ wxString TREE_PROJECT_FRAME::GetFileExt( TreeFileType type )
switch( type )
{
case TREE_PROJECT: return ProjectFileExtension;
case TREE_SCHEMA: return LegacySchematicFileExtension;
case TREE_LEGACY_SCHEMATIC: return LegacySchematicFileExtension;
case TREE_SEXPR_SCHEMATIC: return KiCadSchematicFileExtension;
case TREE_LEGACY_PCB: return LegacyPcbFileExtension;
case TREE_SEXP_PCB: return KiCadPcbFileExtension;
case TREE_SEXPR_PCB: return KiCadPcbFileExtension;
case TREE_GERBER: return GerberFileExtensionWildCard;
case TREE_HTML: return HtmlFileExtension;
case TREE_PDF: return PdfFileExtension;
@ -308,19 +309,16 @@ wxTreeItemId TREE_PROJECT_FRAME::AddItemToTreeProject(
{
// Filter
wxRegEx reg;
bool addFile = false;
bool isSchematic = false;
bool addFile = false;
for( unsigned i = 0; i < m_filters.size(); i++ )
for( const wxString& m_filter : m_filters )
{
wxCHECK2_MSG( reg.Compile( m_filters[i], wxRE_ICASE ), continue,
wxString::Format( "Regex %s failed to compile.", m_filters[i] ) );
wxCHECK2_MSG( reg.Compile( m_filter, wxRE_ICASE ), continue,
wxString::Format( "Regex %s failed to compile.", m_filter ) );
if( reg.Matches( aName ) )
{
addFile = true;
isSchematic = ( fn.GetExt() == "sch" || fn.GetExt() == "kicad_sch" );
break;
}
}
@ -340,7 +338,7 @@ wxTreeItemId TREE_PROJECT_FRAME::AddItemToTreeProject(
// create is sent to the wxFileSystemWatcher, but the file still has 0 byte
// so it cannot detected as root sheet
// This is an ugly fix.
if( isSchematic )
if( fn.GetExt() == "sch" || fn.GetExt() == "kicad_sch" )
{
wxString fullFileName = aName.BeforeLast( '.' );
wxString rootName;
@ -362,16 +360,31 @@ wxTreeItemId TREE_PROJECT_FRAME::AddItemToTreeProject(
addFile = false;
// check the first 100 lines for the "Sheet 1" string
// check the first 100 lines for the "Sheet 1" or "(page 1" string
for( int i = 0; i<100; ++i )
{
if( !fgets( line, sizeof(line), fp ) )
break;
if( !strncmp( line, "Sheet 1 ", 8 ) )
if( fn.GetExt() == "sch" )
{
addFile = true;
break;
if( strncmp( line, "Sheet 1 ", 8 ) == 0 )
{
addFile = true;
break;
}
} else if( fn.GetExt() == "kicad_sch" )
{
char* start = line;
while( *start == ' ' )
start++;
if( strncmp( start, "(page 1 ", 8 ) == 0 )
{
addFile = true;
break;
}
}
}

View File

@ -168,7 +168,8 @@ void TREEPROJECT_ITEM::Activate( TREE_PROJECT_FRAME* aTreePrjFrame )
m_parent->Toggle( id );
break;
case TREE_SCHEMA:
case TREE_LEGACY_SCHEMATIC:
case TREE_SEXPR_SCHEMATIC:
if( fullFileName == frame->SchFileName() )
{
toolMgr->RunAction( KICAD_MANAGER_ACTIONS::editSchematic, true );
@ -181,7 +182,7 @@ void TREEPROJECT_ITEM::Activate( TREE_PROJECT_FRAME* aTreePrjFrame )
break;
case TREE_LEGACY_PCB:
case TREE_SEXP_PCB:
case TREE_SEXPR_PCB:
if( fullFileName == frame->PcbFileName() || fullFileName == frame->PcbLegacyFileName() )
{
toolMgr->RunAction( KICAD_MANAGER_ACTIONS::editPCB, true );

View File

@ -56,9 +56,10 @@ TREEPROJECTFILES::TREEPROJECTFILES( TREE_PROJECT_FRAME* parent )
m_ImageList = new wxImageList( iconsize.x, iconsize.y, true, TREE_MAX );
m_ImageList->Add( KiBitmap( new_project_xpm ) ); // TREE_PROJECT
m_ImageList->Add( KiBitmap( eeschema_xpm ) ); // TREE_SCHEMA
m_ImageList->Add( KiBitmap( eeschema_xpm ) ); // TREE_LEGACY_SCHEMATIC
m_ImageList->Add( KiBitmap( eeschema_xpm ) ); // TREE_SEXPR_SCHEMATIC
m_ImageList->Add( KiBitmap( pcbnew_xpm ) ); // TREE_LEGACY_PCB
m_ImageList->Add( KiBitmap( pcbnew_xpm ) ); // TREE_SFMT_PCB
m_ImageList->Add( KiBitmap( pcbnew_xpm ) ); // TREE_SEXPR_PCB
m_ImageList->Add( KiBitmap( icon_gerbview_small_xpm ) ); // TREE_GERBER
m_ImageList->Add( KiBitmap( html_xpm ) ); // TREE_HTML
m_ImageList->Add( KiBitmap( datasheet_xpm ) ); // TREE_PDF