diff --git a/common/page_info.cpp b/common/page_info.cpp index 886cd2d9bf..31aa6183bb 100644 --- a/common/page_info.cpp +++ b/common/page_info.cpp @@ -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 diff --git a/eeschema/component_references_lister.cpp b/eeschema/component_references_lister.cpp index f038a1ca6d..28ff8e675a 100644 --- a/eeschema/component_references_lister.cpp +++ b/eeschema/component_references_lister.cpp @@ -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 ); diff --git a/eeschema/sch_file_versions.h b/eeschema/sch_file_versions.h index 69a53e664b..b1dbab01cf 100644 --- a/eeschema/sch_file_versions.h +++ b/eeschema/sch_file_versions.h @@ -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 diff --git a/eeschema/sch_reference_list.h b/eeschema/sch_reference_list.h index 4611e2a469..9e0c12d347 100644 --- a/eeschema/sch_reference_list.h +++ b/eeschema/sch_reference_list.h @@ -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; } diff --git a/eeschema/sch_sexpr_parser.cpp b/eeschema/sch_sexpr_parser.cpp index 7e61694a1b..02c9f24689 100644 --- a/eeschema/sch_sexpr_parser.cpp +++ b/eeschema/sch_sexpr_parser.cpp @@ -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" ); } diff --git a/eeschema/sch_sexpr_plugin.cpp b/eeschema/sch_sexpr_plugin.cpp index 839c281aab..11f293727e 100644 --- a/eeschema/sch_sexpr_plugin.cpp +++ b/eeschema/sch_sexpr_plugin.cpp @@ -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 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(), diff --git a/eeschema/sch_sheet_path.cpp b/eeschema/sch_sheet_path.cpp index c6c4a4c537..ee0b56e414 100644 --- a/eeschema/sch_sheet_path.cpp +++ b/eeschema/sch_sheet_path.cpp @@ -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 ) ) { diff --git a/eeschema/sch_sheet_path.h b/eeschema/sch_sheet_path.h index 5fa83eefc6..d3df3bbe4a 100644 --- a/eeschema/sch_sheet_path.h +++ b/eeschema/sch_sheet_path.h @@ -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 diff --git a/eeschema/schematic.keywords b/eeschema/schematic.keywords index f2e4139ba1..f0e26882cc 100644 --- a/eeschema/schematic.keywords +++ b/eeschema/schematic.keywords @@ -71,6 +71,7 @@ output_low unconnected output page +paper passive path pin diff --git a/kicad/kicad_manager_frame.h b/kicad/kicad_manager_frame.h index 7f5a868fe0..ff0b323e5b 100644 --- a/kicad/kicad_manager_frame.h +++ b/kicad/kicad_manager_frame.h @@ -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) diff --git a/kicad/tree_project_frame.cpp b/kicad/tree_project_frame.cpp index 1e05c93e38..cd18e72aa1 100644 --- a/kicad/tree_project_frame.cpp +++ b/kicad/tree_project_frame.cpp @@ -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; + } } } diff --git a/kicad/treeproject_item.cpp b/kicad/treeproject_item.cpp index e40a7b153c..ac1ba242ca 100644 --- a/kicad/treeproject_item.cpp +++ b/kicad/treeproject_item.cpp @@ -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 ); diff --git a/kicad/treeprojectfiles.cpp b/kicad/treeprojectfiles.cpp index 3630777378..12718ccecd 100644 --- a/kicad/treeprojectfiles.cpp +++ b/kicad/treeprojectfiles.cpp @@ -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