diff --git a/common/widgets/widget_hotkey_list.cpp b/common/widgets/widget_hotkey_list.cpp index 00bb23a201..ebab4f52f4 100644 --- a/common/widgets/widget_hotkey_list.cpp +++ b/common/widgets/widget_hotkey_list.cpp @@ -436,8 +436,6 @@ void WIDGET_HOTKEY_LIST::OnSize( wxSizeEvent& aEvent ) if( hk_column_width < HOTKEY_MIN_WIDTH ) hk_column_width = HOTKEY_MIN_WIDTH; - else if( hk_column_width <= 0 ) - hk_column_width = 1; int name_column_width = rect.width - hk_column_width - HORIZ_MARGIN; diff --git a/eeschema/annotate.cpp b/eeschema/annotate.cpp index 1b2a27d232..cfb776073e 100644 --- a/eeschema/annotate.cpp +++ b/eeschema/annotate.cpp @@ -6,7 +6,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2004-2013 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2004-2016 KiCad Developers, see change_log.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -69,7 +69,7 @@ void SCH_EDIT_FRAME::AnnotateComponents( bool aAnnotateSchematic, SCH_SCREENS screens; // Build the sheet list. - SCH_SHEET_LIST sheets; + SCH_SHEET_LIST sheets( g_RootSheet ); // Map of locked components SCH_MULTI_UNIT_REFERENCE_MAP lockedComponents; @@ -187,7 +187,7 @@ void SCH_EDIT_FRAME::AnnotateComponents( bool aAnnotateSchematic, int SCH_EDIT_FRAME::CheckAnnotate( wxArrayString* aMessageList, bool aOneSheetOnly ) { // build the screen list - SCH_SHEET_LIST SheetList; + SCH_SHEET_LIST SheetList( g_RootSheet ); SCH_REFERENCE_LIST ComponentsList; // Build the list of components diff --git a/eeschema/backanno.cpp b/eeschema/backanno.cpp index 671f727bca..046d5d6313 100644 --- a/eeschema/backanno.cpp +++ b/eeschema/backanno.cpp @@ -2,8 +2,8 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 2008-2013 Wayne Stambaugh - * Copyright (C) 2004-2015 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2008-2016 Wayne Stambaugh + * Copyright (C) 2004-2016 KiCad Developers, see change_log.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -53,7 +53,7 @@ void SCH_EDIT_FRAME::backAnnotateFootprints( const std::string& aChangedSetOfRef { // Build a flat list of components in schematic: SCH_REFERENCE_LIST refs; - SCH_SHEET_LIST sheets; + SCH_SHEET_LIST sheets( g_RootSheet ); bool isChanged = false; sheets.GetComponents( Prj().SchLibs(), refs, false ); @@ -135,7 +135,7 @@ bool SCH_EDIT_FRAME::ProcessCmpToFootprintLinkFile( const wxString& aFullFilenam { // Build a flat list of components in schematic: SCH_REFERENCE_LIST referencesList; - SCH_SHEET_LIST sheetList; + SCH_SHEET_LIST sheetList( g_RootSheet ); sheetList.GetComponents( Prj().SchLibs(), referencesList, false ); diff --git a/eeschema/block.cpp b/eeschema/block.cpp index 7a57f2443e..7d8c2bfccf 100644 --- a/eeschema/block.cpp +++ b/eeschema/block.cpp @@ -2,8 +2,8 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 2009-2015 Wayne Stambaugh - * Copyright (C) 2004-2015 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2009-2016 Wayne Stambaugh + * Copyright (C) 2004-2016 KiCad Developers, see change_log.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -448,7 +448,7 @@ void SCH_EDIT_FRAME::PasteListOfItems( wxDC* DC ) { unsigned i; SCH_ITEM* item; - SCH_SHEET_LIST hierarchy; // This is the entire schematic hierarcy. + SCH_SHEET_LIST hierarchy( g_RootSheet ); // This is the entire schematic hierarcy. if( m_blockItems.GetCount() == 0 ) { diff --git a/eeschema/dialogs/dialog_erc.cpp b/eeschema/dialogs/dialog_erc.cpp index 5f15760f52..38ea371cc3 100644 --- a/eeschema/dialogs/dialog_erc.cpp +++ b/eeschema/dialogs/dialog_erc.cpp @@ -201,13 +201,13 @@ void DIALOG_ERC::OnLeftClickMarkersList( wxHtmlLinkEvent& event ) return; // Search for the selected marker - SCH_SHEET_PATH* sheet; - SCH_SHEET_LIST SheetList; + unsigned i; + SCH_SHEET_LIST sheetList( g_RootSheet ); bool notFound = true; - for( sheet = SheetList.GetFirst(); sheet; sheet = SheetList.GetNext() ) + for( i = 0; i < sheetList.size(); i++ ) { - SCH_ITEM* item = (SCH_ITEM*) sheet->LastDrawList(); + SCH_ITEM* item = (SCH_ITEM*) sheetList[i].LastDrawList(); for( ; item; item = item->Next() ) { @@ -231,10 +231,10 @@ void DIALOG_ERC::OnLeftClickMarkersList( wxHtmlLinkEvent& event ) return; } - if( *sheet != m_parent->GetCurrentSheet() ) + if( sheetList[i] != m_parent->GetCurrentSheet() ) { - sheet->LastScreen()->SetZoom( m_parent->GetScreen()->GetZoom() ); - m_parent->SetCurrentSheet( *sheet ); + sheetList[i].LastScreen()->SetZoom( m_parent->GetScreen()->GetZoom() ); + m_parent->SetCurrentSheet( sheetList[i] ); m_parent->GetCurrentSheet().UpdateAllScreenReferences(); } @@ -372,14 +372,12 @@ void DIALOG_ERC::setDRCMatrixButtonState( wxBitmapButton *aButton, int aState ) void DIALOG_ERC::DisplayERC_MarkersList() { - SCH_SHEET_LIST sheetList; + SCH_SHEET_LIST sheetList( g_RootSheet); m_MarkersList->ClearList(); - SCH_SHEET_PATH* sheet = sheetList.GetFirst(); - - for( ; sheet != NULL; sheet = sheetList.GetNext() ) + for( unsigned i = 0; i < sheetList.size(); i++ ) { - SCH_ITEM* item = sheet->LastDrawList(); + SCH_ITEM* item = sheetList[i].LastDrawList(); for( ; item != NULL; item = item->Next() ) { @@ -455,7 +453,7 @@ void DIALOG_ERC::TestErc( wxArrayString* aMessagesList ) m_tstUniqueGlobalLabels = m_cbTestUniqueGlbLabels->GetValue(); // Build the whole sheet list in hierarchy (sheet, not screen) - SCH_SHEET_LIST sheets; + SCH_SHEET_LIST sheets( g_RootSheet ); sheets.AnnotatePowerSymbols( Prj().SchLibs() ); if( m_parent->CheckAnnotate( aMessagesList, false ) ) diff --git a/eeschema/dialogs/dialog_lib_edit_pin.h b/eeschema/dialogs/dialog_lib_edit_pin.h index ba4063ebe4..dab9d9022e 100644 --- a/eeschema/dialogs/dialog_lib_edit_pin.h +++ b/eeschema/dialogs/dialog_lib_edit_pin.h @@ -68,11 +68,11 @@ public: ELECTRICAL_PINTYPE GetElectricalType( void ) { - return m_choiceElectricalType->GetSelection(); + return m_choiceElectricalType->GetPinTypeSelection(); } void SetStyle( GRAPHIC_PINSHAPE style ) { m_choiceStyle->SetSelection( style ); } - GRAPHIC_PINSHAPE GetStyle( void ) { return m_choiceStyle->GetSelection(); } + GRAPHIC_PINSHAPE GetStyle( void ) { return m_choiceStyle->GetPinShapeSelection(); } void SetPinName( const wxString& name ) { m_textPinName->SetValue( name ); } wxString GetPinName( void ) { return m_textPinName->GetValue(); } diff --git a/eeschema/dialogs/dialog_print_using_printer.cpp b/eeschema/dialogs/dialog_print_using_printer.cpp index e5b896bf84..2a1139c761 100644 --- a/eeschema/dialogs/dialog_print_using_printer.cpp +++ b/eeschema/dialogs/dialog_print_using_printer.cpp @@ -315,6 +315,14 @@ void DIALOG_PRINT_USING_PRINTER::OnPrintButtonClick( wxCommandEvent& event ) bool SCH_PRINTOUT::OnPrintPage( int page ) { + SCH_SHEET_LIST sheetList( g_RootSheet ); + + wxCHECK_MSG( page >= 1 && page <= (int)sheetList.size(), false, + wxT( "Cannot print invalid page number." ) ); + + wxCHECK_MSG( sheetList[ page - 1].LastScreen() != NULL, false, + wxT( "Cannot print page with NULL screen." ) ); + wxString msg; msg.Printf( _( "Print page %d" ), page ); m_parent->ClearMsgPanel(); @@ -322,26 +330,10 @@ bool SCH_PRINTOUT::OnPrintPage( int page ) SCH_SCREEN* screen = m_parent->GetScreen(); SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet(); - SCH_SHEET_LIST SheetList( NULL ); - SCH_SHEET_PATH* sheetpath = SheetList.GetSheet( page - 1 ); - SCH_SHEET_PATH list; - - if( sheetpath ) - { - list = *sheetpath; - m_parent->SetCurrentSheet( list ); - m_parent->GetCurrentSheet().UpdateAllScreenReferences(); - m_parent->SetSheetNumberAndCount(); - screen = m_parent->GetCurrentSheet().LastScreen(); - } - else - { - screen = NULL; - } - - if( screen == NULL ) - return false; - + m_parent->SetCurrentSheet( sheetList[ page - 1 ] ); + m_parent->GetCurrentSheet().UpdateAllScreenReferences(); + m_parent->SetSheetNumberAndCount(); + screen = m_parent->GetCurrentSheet().LastScreen(); DrawPage( screen ); m_parent->SetCurrentSheet( oldsheetpath ); m_parent->GetCurrentSheet().UpdateAllScreenReferences(); diff --git a/eeschema/erc.cpp b/eeschema/erc.cpp index a9ef183b1a..71e1e5c31e 100644 --- a/eeschema/erc.cpp +++ b/eeschema/erc.cpp @@ -2,8 +2,8 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 2011 Wayne Stambaugh - * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2011-2016 Wayne Stambaugh + * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -538,15 +538,14 @@ bool WriteDiagnosticERC( const wxString& aFullFileName ) int err_count = 0; int warn_count = 0; int total_count = 0; - SCH_SHEET_LIST sheetList; - SCH_SHEET_PATH* sheet; + SCH_SHEET_LIST sheetList( g_RootSheet ); - for( sheet = sheetList.GetFirst(); sheet != NULL; sheet = sheetList.GetNext() ) + for( unsigned i = 0; i < sheetList.size(); i++ ) { msg << wxString::Format( _( "\n***** Sheet %s\n" ), - GetChars( sheet->PathHumanReadable() ) ); + GetChars( sheetList[i].PathHumanReadable() ) ); - for( SCH_ITEM* item = sheet->LastDrawList(); item != NULL; item = item->Next() ) + for( SCH_ITEM* item = sheetList[i].LastDrawList(); item != NULL; item = item->Next() ) { if( item->Type() != SCH_MARKER_T ) continue; diff --git a/eeschema/find.cpp b/eeschema/find.cpp index d3a29e7c81..a20da8ba47 100644 --- a/eeschema/find.cpp +++ b/eeschema/find.cpp @@ -2,8 +2,8 @@ * 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) 2008-2011 Wayne Stambaugh - * Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2008-2016 Wayne Stambaugh + * Copyright (C) 2004-2016 KiCad Developers, see change_log.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -62,7 +62,7 @@ void SCH_EDIT_FRAME::OnFindDrcMarker( wxFindDialogEvent& event ) static SCH_MARKER* lastMarker = NULL; wxString msg; - SCH_SHEET_LIST schematic; + SCH_SHEET_LIST schematic( g_RootSheet ); SCH_SHEET_PATH* sheetFoundIn = NULL; bool wrap = ( event.GetFlags() & FR_SEARCH_WRAP ) != 0; bool warpCursor = ( ( event.GetId() == wxEVT_COMMAND_FIND_CLOSE ) || @@ -113,7 +113,7 @@ SCH_ITEM* SCH_EDIT_FRAME::FindComponentAndItem( const wxString& aReference, const wxString& aSearchText, bool aWarpMouse ) { - SCH_SHEET_PATH* sheet; + SCH_SHEET_PATH* sheet = NULL; SCH_SHEET_PATH* sheetWithComponentFound = NULL; SCH_ITEM* item = NULL; SCH_COMPONENT* Component = NULL; @@ -121,16 +121,17 @@ SCH_ITEM* SCH_EDIT_FRAME::FindComponentAndItem( const wxString& aReference, bool centerAndRedraw = false; bool notFound = true; LIB_PIN* pin; - SCH_SHEET_LIST sheetList; - - sheet = sheetList.GetFirst(); + SCH_SHEET_LIST sheetList( g_RootSheet ); if( !aSearchHierarchy ) - sheet = m_CurrentSheet; + sheetList.push_back( *m_CurrentSheet ); + else + sheetList.BuildSheetList( g_RootSheet ); - for( ; sheet != NULL; sheet = sheetList.GetNext() ) + for( SCH_SHEET_PATHS_ITER it = sheetList.begin(); it != sheetList.end(); ++it ) { - item = sheet->LastDrawList(); + sheet = &(*it); + item = (*it).LastDrawList(); for( ; ( item != NULL ) && ( notFound == true ); item = item->Next() ) { @@ -181,7 +182,7 @@ SCH_ITEM* SCH_EDIT_FRAME::FindComponentAndItem( const wxString& aReference, } } - if( (aSearchHierarchy == false) || (notFound == false) ) + if( notFound == false ) break; } @@ -361,7 +362,7 @@ void SCH_EDIT_FRAME::OnFindReplace( wxFindDialogEvent& aEvent ) static int nextFoundIndex = 0; SCH_ITEM* item; SCH_SHEET_PATH* sheet; - SCH_SHEET_LIST schematic; + SCH_SHEET_LIST schematic( g_RootSheet ); SCH_FIND_COLLECTOR_DATA data; SCH_FIND_REPLACE_DATA searchCriteria; @@ -454,7 +455,7 @@ void SCH_EDIT_FRAME::OnFindReplace( wxFindDialogEvent& aEvent ) void SCH_EDIT_FRAME::updateFindReplaceView( wxFindDialogEvent& aEvent ) { wxString msg; - SCH_SHEET_LIST schematic; + SCH_SHEET_LIST schematic( g_RootSheet ); SCH_FIND_COLLECTOR_DATA data; SCH_FIND_REPLACE_DATA searchCriteria; bool warpCursor = !( aEvent.GetFlags() & FR_NO_WARP_CURSOR ); diff --git a/eeschema/lib_pin.cpp b/eeschema/lib_pin.cpp index 96fff9fea5..b91101074c 100644 --- a/eeschema/lib_pin.cpp +++ b/eeschema/lib_pin.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2015 Wayne Stambaugh - * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -72,7 +72,8 @@ static const BITMAP_DEF iconsPinsOrientations[] = const wxString LIB_PIN::GetCanonicalElectricalTypeName( ELECTRICAL_PINTYPE aType ) { - assert( aType >= 0 && aType < (int) PINTYPE_COUNT ); + if( aType < 0 || aType >= (int) PINTYPE_COUNT ); + return wxT( "???" ); // These strings are the canonical name of the electrictal type // Not translated, no space in name, only ASCII chars. @@ -93,9 +94,6 @@ const wxString LIB_PIN::GetCanonicalElectricalTypeName( ELECTRICAL_PINTYPE aType wxT( "NotConnected" ) }; - if( aType > (int) PINTYPE_COUNT ) - return wxT( "???" ); - return msgPinElectricType[ aType ]; } diff --git a/eeschema/netlist.cpp b/eeschema/netlist.cpp index 442082ab73..8a490e89f5 100644 --- a/eeschema/netlist.cpp +++ b/eeschema/netlist.cpp @@ -2,8 +2,8 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 2013 Wayne Stambaugh - * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2013-2016 Wayne Stambaugh + * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -67,7 +67,7 @@ int TestDuplicateSheetNames( bool aCreateMarker ); bool SCH_EDIT_FRAME::prepareForNetlist() { - SCH_SHEET_LIST sheets; + SCH_SHEET_LIST sheets( g_RootSheet ); sheets.AnnotatePowerSymbols( Prj().SchLibs() ); @@ -173,7 +173,7 @@ NETLIST_OBJECT_LIST* SCH_EDIT_FRAME::BuildNetListBase() std::auto_ptr ret( new NETLIST_OBJECT_LIST() ); // Creates the flattened sheet list: - SCH_SHEET_LIST aSheets; + SCH_SHEET_LIST aSheets( g_RootSheet ); // Build netlist info bool success = ret->BuildNetListInfo( aSheets ); @@ -197,9 +197,10 @@ bool NETLIST_OBJECT_LIST::BuildNetListInfo( SCH_SHEET_LIST& aSheets ) SCH_SHEET_PATH* sheet; // Fill list with connected items from the flattened sheet list - for( sheet = aSheets.GetFirst(); sheet != NULL; - sheet = aSheets.GetNext() ) + for( unsigned i = 0; i < aSheets.size(); i++ ) { + sheet = &aSheets[i]; + for( SCH_ITEM* item = sheet->LastScreen()->GetDrawItems(); item; item = item->Next() ) { item->GetNetListItem( *this, sheet ); @@ -420,8 +421,7 @@ static int getPriority( const NETLIST_OBJECT* Objet ) * evalLabelsPriority calculates the priority of alabel1 and aLabel2 * return true if alabel1 has a higher priority than aLabel2 */ -static bool evalLabelsPriority( const NETLIST_OBJECT* aLabel1, - const NETLIST_OBJECT* aLabel2 ) +static bool evalLabelsPriority( const NETLIST_OBJECT* aLabel1, const NETLIST_OBJECT* aLabel2 ) { // Global labels have the highest prioriy. // For local labels: names are prefixed by their sheetpath @@ -542,6 +542,7 @@ void NETLIST_OBJECT_LIST::findBestNetNameForEachNet() for( unsigned ii = 0; ii < size(); ii++ ) { item = GetItem( ii ); + if( !item->HasNetNameCandidate() ) list.push_back( item ); } @@ -592,6 +593,7 @@ void NETLIST_OBJECT_LIST::findBestNetNameForEachNet() // changed each time the netlist is built (power components) // and anyway obviously they are not a good candidate SCH_COMPONENT* link = item->GetComponentParent(); + if( link && link->IsInNetlist() ) { // select the better between the previous and this one @@ -711,8 +713,7 @@ void NETLIST_OBJECT_LIST::propageNetCode( int aOldNetCode, int aNewNetCode, bool } -void NETLIST_OBJECT_LIST::pointToPointConnect( NETLIST_OBJECT* aRef, bool aIsBus, - int start ) +void NETLIST_OBJECT_LIST::pointToPointConnect( NETLIST_OBJECT* aRef, bool aIsBus, int start ) { int netCode; @@ -808,7 +809,7 @@ void NETLIST_OBJECT_LIST::pointToPointConnect( NETLIST_OBJECT* aRef, bool aIsBus void NETLIST_OBJECT_LIST::segmentToPointConnect( NETLIST_OBJECT* aJonction, - bool aIsBus, int aIdxStart ) + bool aIsBus, int aIdxStart ) { for( unsigned i = aIdxStart; i < size(); i++ ) { diff --git a/eeschema/netlist_exporters/netlist_exporter.cpp b/eeschema/netlist_exporters/netlist_exporter.cpp index 62e39ccca8..1fee8dc7dd 100644 --- a/eeschema/netlist_exporters/netlist_exporter.cpp +++ b/eeschema/netlist_exporters/netlist_exporter.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 1992-2013 jp.charras at wanadoo.fr * Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.TXT for contributors. + * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.TXT for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -328,22 +328,23 @@ void NETLIST_EXPORTER::findAllInstancesOfComponent( SCH_COMPONENT* aComponent, wxString ref = aComponent->GetRef( aSheetPath ); wxString ref2; - SCH_SHEET_LIST sheetList; + SCH_SHEET_LIST sheetList( g_RootSheet ); - for( SCH_SHEET_PATH* sheet = sheetList.GetFirst(); sheet; sheet = sheetList.GetNext() ) + for( unsigned i = 0; i < sheetList.size(); i++ ) { - for( EDA_ITEM* item = sheet->LastDrawList(); item; item = item->Next() ) + for( EDA_ITEM* item = sheetList[i].LastDrawList(); item; item = item->Next() ) { if( item->Type() != SCH_COMPONENT_T ) continue; SCH_COMPONENT* comp2 = (SCH_COMPONENT*) item; - ref2 = comp2->GetRef( sheet ); + ref2 = comp2->GetRef( &sheetList[i] ); + if( ref2.CmpNoCase( ref ) != 0 ) continue; - int unit2 = comp2->GetUnitSelection( sheet ); // slow + int unit2 = comp2->GetUnitSelection( &sheetList[i] ); // slow for( LIB_PIN* pin = aEntry->GetNextPin(); pin; pin = aEntry->GetNextPin( pin ) ) { @@ -356,7 +357,7 @@ void NETLIST_EXPORTER::findAllInstancesOfComponent( SCH_COMPONENT* aComponent, continue; // A suitable pin is found: add it to the current list - addPinToComponentPinList( comp2, sheet, pin ); + addPinToComponentPinList( comp2, &sheetList[i], pin ); } } } diff --git a/eeschema/netlist_exporters/netlist_exporter_cadstar.cpp b/eeschema/netlist_exporters/netlist_exporter_cadstar.cpp index 2b5b7fbf45..8b3bf65941 100644 --- a/eeschema/netlist_exporters/netlist_exporter_cadstar.cpp +++ b/eeschema/netlist_exporters/netlist_exporter_cadstar.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 1992-2013 jp.charras at wanadoo.fr * Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.TXT for contributors. + * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.TXT for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -53,7 +53,6 @@ bool NETLIST_EXPORTER_CADSTAR::WriteNetlist( const wxString& aOutFileName, unsig wxString StartCmpDesc = StartLine + wxT( "ADD_COM" ); wxString msg; - SCH_SHEET_PATH* sheet; EDA_ITEM* DrawList; SCH_COMPONENT* component; wxString title = wxT( "Eeschema " ) + GetBuildVersion(); @@ -71,13 +70,13 @@ bool NETLIST_EXPORTER_CADSTAR::WriteNetlist( const wxString& aOutFileName, unsig // Create netlist module section m_ReferencesAlreadyFound.Clear(); - SCH_SHEET_LIST SheetList; + SCH_SHEET_LIST sheetList( g_RootSheet ); - for( sheet = SheetList.GetFirst(); sheet != NULL; sheet = SheetList.GetNext() ) + for( unsigned i = 0; i < sheetList.size(); i++ ) { - for( DrawList = sheet->LastDrawList(); DrawList != NULL; DrawList = DrawList->Next() ) + for( DrawList = sheetList[i].LastDrawList(); DrawList != NULL; DrawList = DrawList->Next() ) { - DrawList = component = findNextComponentAndCreatePinList( DrawList, sheet ); + DrawList = component = findNextComponentAndCreatePinList( DrawList, &sheetList[i] ); if( component == NULL ) break; @@ -93,7 +92,7 @@ bool NETLIST_EXPORTER_CADSTAR::WriteNetlist( const wxString& aOutFileName, unsig footprint = wxT( "$noname" ); */ - msg = component->GetRef( sheet ); + msg = component->GetRef( &sheetList[i] ); ret |= fprintf( f, "%s ", TO_UTF8( StartCmpDesc ) ); ret |= fprintf( f, "%s", TO_UTF8( msg ) ); diff --git a/eeschema/netlist_exporters/netlist_exporter_generic.cpp b/eeschema/netlist_exporters/netlist_exporter_generic.cpp index 921e0fc1e4..420d8e36a8 100644 --- a/eeschema/netlist_exporters/netlist_exporter_generic.cpp +++ b/eeschema/netlist_exporters/netlist_exporter_generic.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 1992-2013 jp.charras at wanadoo.fr * Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.TXT for contributors. + * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.TXT for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -108,16 +108,16 @@ XNODE* NETLIST_EXPORTER_GENERIC::makeComponents() m_ReferencesAlreadyFound.Clear(); - SCH_SHEET_LIST sheetList; + SCH_SHEET_LIST sheetList( g_RootSheet ); // Output is xml, so there is no reason to remove spaces from the field values. // And XML element names need not be translated to various languages. - for( SCH_SHEET_PATH* path = sheetList.GetFirst(); path; path = sheetList.GetNext() ) + for( unsigned i = 0; i < sheetList.size(); i++ ) { - for( EDA_ITEM* schItem = path->LastDrawList(); schItem; schItem = schItem->Next() ) + for( EDA_ITEM* schItem = sheetList[i].LastDrawList(); schItem; schItem = schItem->Next() ) { - SCH_COMPONENT* comp = findNextComponentAndCreatePinList( schItem, path ); + SCH_COMPONENT* comp = findNextComponentAndCreatePinList( schItem, &sheetList[i] ); if( !comp ) break; // No component left @@ -131,7 +131,7 @@ XNODE* NETLIST_EXPORTER_GENERIC::makeComponents() // an element. xcomps->AddChild( xcomp = node( sComponent ) ); - xcomp->AddAttribute( sRef, comp->GetRef( path ) ); + xcomp->AddAttribute( sRef, comp->GetRef( &sheetList[i] ) ); xcomp->AddChild( node( sValue, comp->GetField( VALUE )->GetText() ) ); @@ -178,8 +178,8 @@ XNODE* NETLIST_EXPORTER_GENERIC::makeComponents() XNODE* xsheetpath; xcomp->AddChild( xsheetpath = node( sSheetPath ) ); - xsheetpath->AddAttribute( sNames, path->PathHumanReadable() ); - xsheetpath->AddAttribute( sTStamps, path->Path() ); + xsheetpath->AddAttribute( sNames, sheetList[i].PathHumanReadable() ); + xsheetpath->AddAttribute( sTStamps, sheetList[i].Path() ); timeStamp.Printf( sTSFmt, (unsigned long)comp->GetTimeStamp() ); xcomp->AddChild( node( sTStamp, timeStamp ) ); @@ -193,7 +193,7 @@ XNODE* NETLIST_EXPORTER_GENERIC::makeComponents() XNODE* NETLIST_EXPORTER_GENERIC::makeDesignHeader() { SCH_SCREEN* screen; - XNODE* xdesign = node( wxT("design") ); + XNODE* xdesign = node( wxT( "design" ) ); XNODE* xtitleBlock; XNODE* xsheet; XNODE* xcomment; @@ -211,21 +211,21 @@ XNODE* NETLIST_EXPORTER_GENERIC::makeDesignHeader() /* Export the sheets information */ - SCH_SHEET_LIST sheetList; + SCH_SHEET_LIST sheetList( g_RootSheet ); - for( SCH_SHEET_PATH* sheet = sheetList.GetFirst(); sheet; sheet = sheetList.GetNext() ) + for( unsigned i = 0; i < sheetList.size(); i++ ) { - screen = sheet->LastScreen(); + screen = sheetList[i].LastScreen(); xdesign->AddChild( xsheet = node( wxT( "sheet" ) ) ); // get the string representation of the sheet index number. - // Note that sheet->GetIndex() is zero index base and we need to increment the number by one to make - // human readable - sheetTxt.Printf( wxT( "%d" ), ( sheetList.GetIndex() + 1 ) ); + // Note that sheet->GetIndex() is zero index base and we need to increment the + // number by one to make it human readable + sheetTxt.Printf( wxT( "%u" ), i + 1 ); xsheet->AddAttribute( wxT( "number" ), sheetTxt ); - xsheet->AddAttribute( wxT( "name" ), sheet->PathHumanReadable() ); - xsheet->AddAttribute( wxT( "tstamps" ), sheet->Path() ); + xsheet->AddAttribute( wxT( "name" ), sheetList[i].PathHumanReadable() ); + xsheet->AddAttribute( wxT( "tstamps" ), sheetList[i].Path() ); TITLE_BLOCK tb = screen->GetTitleBlock(); diff --git a/eeschema/netlist_exporters/netlist_exporter_orcadpcb2.cpp b/eeschema/netlist_exporters/netlist_exporter_orcadpcb2.cpp index 0aeaccc3d0..1fe6f16ee1 100644 --- a/eeschema/netlist_exporters/netlist_exporter_orcadpcb2.cpp +++ b/eeschema/netlist_exporters/netlist_exporter_orcadpcb2.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 1992-2013 jp.charras at wanadoo.fr * Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.TXT for contributors. + * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.TXT for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -66,13 +66,13 @@ bool NETLIST_EXPORTER_ORCADPCB2::WriteNetlist( const wxString& aOutFileName, uns // Create netlist module section m_ReferencesAlreadyFound.Clear(); - SCH_SHEET_LIST sheetList; + SCH_SHEET_LIST sheetList( g_RootSheet ); - for( SCH_SHEET_PATH* path = sheetList.GetFirst(); path; path = sheetList.GetNext() ) + for( unsigned i = 0; i < sheetList.size(); i++ ) { - for( EDA_ITEM* item = path->LastDrawList(); item; item = item->Next() ) + for( EDA_ITEM* item = sheetList[i].LastDrawList(); item; item = item->Next() ) { - SCH_COMPONENT* comp = findNextComponentAndCreatePinList( item, path ); + SCH_COMPONENT* comp = findNextComponentAndCreatePinList( item, &sheetList[i] ); if( !comp ) break; @@ -87,7 +87,7 @@ bool NETLIST_EXPORTER_ORCADPCB2::WriteNetlist( const wxString& aOutFileName, uns { if( part->GetFootPrints().GetCount() != 0 ) // Put in list { - cmpList.push_back( SCH_REFERENCE( comp, part, *path ) ); + cmpList.push_back( SCH_REFERENCE( comp, part, sheetList[i] ) ); } } @@ -99,10 +99,10 @@ bool NETLIST_EXPORTER_ORCADPCB2::WriteNetlist( const wxString& aOutFileName, uns else footprint = wxT( "$noname" ); - field = comp->GetRef( path ); + field = comp->GetRef( &sheetList[i] ); ret |= fprintf( f, " ( %s %s", - TO_UTF8( comp->GetPath( path ) ), + TO_UTF8( comp->GetPath( &sheetList[i] ) ), TO_UTF8( footprint ) ); ret |= fprintf( f, " %s", TO_UTF8( field ) ); diff --git a/eeschema/netlist_exporters/netlist_exporter_pspice.cpp b/eeschema/netlist_exporters/netlist_exporter_pspice.cpp index 7158bd4d5e..a93b882428 100644 --- a/eeschema/netlist_exporters/netlist_exporter_pspice.cpp +++ b/eeschema/netlist_exporters/netlist_exporter_pspice.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 1992-2013 jp.charras at wanadoo.fr * Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.TXT for contributors. + * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.TXT for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -79,11 +79,11 @@ bool NETLIST_EXPORTER_PSPICE::WriteNetlist( const wxString& aOutFileName, unsign // commands) and create text list starting by [+]pspice , or [+]gnucap // (simulator commands) bufnum[BUFYPOS_LEN] = 0; - SCH_SHEET_LIST sheetList; + SCH_SHEET_LIST sheetList( g_RootSheet ); - for( SCH_SHEET_PATH* sheet = sheetList.GetFirst(); sheet; sheet = sheetList.GetNext() ) + for( unsigned i = 0; i < sheetList.size(); i++ ) { - for( EDA_ITEM* item = sheet->LastDrawList(); item; item = item->Next() ) + for( EDA_ITEM* item = sheetList[i].LastDrawList(); item; item = item->Next() ) { size_t l1, l2; wxChar ident; @@ -162,13 +162,13 @@ bool NETLIST_EXPORTER_PSPICE::WriteNetlist( const wxString& aOutFileName, unsign m_ReferencesAlreadyFound.Clear(); - for( SCH_SHEET_PATH* sheet = sheetList.GetFirst(); sheet; sheet = sheetList.GetNext() ) + for( unsigned i = 0; i < sheetList.size(); i++ ) { - ret |= fprintf( f, "* Sheet Name: %s\n", TO_UTF8( sheet->PathHumanReadable() ) ); + ret |= fprintf( f, "* Sheet Name: %s\n", TO_UTF8( sheetList[i].PathHumanReadable() ) ); - for( EDA_ITEM* item = sheet->LastDrawList(); item; item = item->Next() ) + for( EDA_ITEM* item = sheetList[i].LastDrawList(); item; item = item->Next() ) { - SCH_COMPONENT* comp = findNextComponentAndCreatePinList( item, sheet ); + SCH_COMPONENT* comp = findNextComponentAndCreatePinList( item, &sheetList[i] ); if( !comp ) break; @@ -235,7 +235,7 @@ bool NETLIST_EXPORTER_PSPICE::WriteNetlist( const wxString& aOutFileName, unsign } //Get Standard Reference Designator: - wxString RefName = comp->GetRef( sheet ); + wxString RefName = comp->GetRef( &sheetList[i] ); //Conditionally add Prefix only for devices that begin with U or IC: if( aUsePrefix ) diff --git a/eeschema/plot_schematic_DXF.cpp b/eeschema/plot_schematic_DXF.cpp index 7a8c288b35..af4b0c2ccd 100644 --- a/eeschema/plot_schematic_DXF.cpp +++ b/eeschema/plot_schematic_DXF.cpp @@ -40,7 +40,6 @@ void DIALOG_PLOT_SCHEMATIC::CreateDXFFile( bool aPlotAll, bool aPlotFrameRef ) { SCH_EDIT_FRAME* schframe = m_parent; SCH_SCREEN* screen = schframe->GetScreen(); - SCH_SHEET_PATH* sheetpath; SCH_SHEET_PATH oldsheetpath = schframe->GetCurrentSheet(); /* When printing all pages, the printed page is not the current page. @@ -49,26 +48,21 @@ void DIALOG_PLOT_SCHEMATIC::CreateDXFFile( bool aPlotAll, bool aPlotFrameRef ) * because in complex hierarchies a SCH_SCREEN (a schematic drawings) * is shared between many sheets */ - SCH_SHEET_LIST SheetList( NULL ); + SCH_SHEET_LIST sheetList; + + if( aPlotAll ) + sheetList.BuildSheetList( g_RootSheet ); + else + sheetList.push_back( schframe->GetCurrentSheet() ); - sheetpath = SheetList.GetFirst(); - SCH_SHEET_PATH list; REPORTER& reporter = m_MessagesBox->Reporter(); - while( true ) + for( unsigned i = 0; i < sheetList.size(); i++ ) { - if( aPlotAll ) - { - if( sheetpath == NULL ) - break; - - list = *sheetpath; - schframe->SetCurrentSheet( list ); - schframe->GetCurrentSheet().UpdateAllScreenReferences(); - schframe->SetSheetNumberAndCount(); - screen = schframe->GetCurrentSheet().LastScreen(); - sheetpath = SheetList.GetNext(); - } + schframe->SetCurrentSheet( sheetList[i] ); + schframe->GetCurrentSheet().UpdateAllScreenReferences(); + schframe->SetSheetNumberAndCount(); + screen = schframe->GetCurrentSheet().LastScreen(); wxPoint plot_offset; wxString msg; @@ -102,10 +96,6 @@ void DIALOG_PLOT_SCHEMATIC::CreateDXFFile( bool aPlotAll, bool aPlotFrameRef ) schframe->SetSheetNumberAndCount(); return; } - if( !aPlotAll ) - { - break; - } } schframe->SetCurrentSheet( oldsheetpath ); diff --git a/eeschema/plot_schematic_HPGL.cpp b/eeschema/plot_schematic_HPGL.cpp index ac3bd2fa96..cd954d1a1a 100644 --- a/eeschema/plot_schematic_HPGL.cpp +++ b/eeschema/plot_schematic_HPGL.cpp @@ -111,7 +111,6 @@ void DIALOG_PLOT_SCHEMATIC::SetHPGLPenWidth() void DIALOG_PLOT_SCHEMATIC::createHPGLFile( bool aPlotAll, bool aPlotFrameRef ) { SCH_SCREEN* screen = m_parent->GetScreen(); - SCH_SHEET_PATH* sheetpath; SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet(); /* When printing all pages, the printed page is not the current page. @@ -120,33 +119,27 @@ void DIALOG_PLOT_SCHEMATIC::createHPGLFile( bool aPlotAll, bool aPlotFrameRef ) * because in complex hierarchies a SCH_SCREEN (a schematic drawings) * is shared between many sheets */ - SCH_SHEET_LIST SheetList( NULL ); + SCH_SHEET_LIST sheetList; + + if( aPlotAll ) + sheetList.BuildSheetList( g_RootSheet ); + else + sheetList.push_back( m_parent->GetCurrentSheet() ); - sheetpath = SheetList.GetFirst(); - SCH_SHEET_PATH list; REPORTER& reporter = m_MessagesBox->Reporter(); SetHPGLPenWidth(); - while( true ) + for( unsigned i = 0; i < sheetList.size(); i++ ) { - if( aPlotAll ) - { - if( sheetpath == NULL ) - break; + m_parent->SetCurrentSheet( sheetList[i] ); + m_parent->GetCurrentSheet().UpdateAllScreenReferences(); + m_parent->SetSheetNumberAndCount(); - list = *sheetpath; - m_parent->SetCurrentSheet( list ); - m_parent->GetCurrentSheet().UpdateAllScreenReferences(); - m_parent->SetSheetNumberAndCount(); + screen = m_parent->GetCurrentSheet().LastScreen(); - screen = m_parent->GetCurrentSheet().LastScreen(); - - if( !screen ) // LastScreen() may return NULL - screen = m_parent->GetScreen(); - - sheetpath = SheetList.GetNext(); - } + if( !screen ) // LastScreen() may return NULL + screen = m_parent->GetScreen(); const PAGE_INFO& curPage = screen->GetPageSettings(); @@ -179,7 +172,7 @@ void DIALOG_PLOT_SCHEMATIC::createHPGLFile( bool aPlotAll, bool aPlotFrameRef ) LOCALE_IO toggle; if( Plot_1_Page_HPGL( plotFileName.GetFullPath(), screen, plotPage, plotOffset, - plot_scale, aPlotFrameRef ) ) + plot_scale, aPlotFrameRef ) ) { msg.Printf( _( "Plot: '%s' OK.\n" ), GetChars( plotFileName.GetFullPath() ) ); reporter.Report( msg, REPORTER::RPT_ACTION ); @@ -190,9 +183,6 @@ void DIALOG_PLOT_SCHEMATIC::createHPGLFile( bool aPlotAll, bool aPlotFrameRef ) GetChars( plotFileName.GetFullPath() ) ); reporter.Report( msg, REPORTER::RPT_ERROR ); } - - if( !aPlotAll ) - break; } catch( IO_ERROR& e ) { diff --git a/eeschema/plot_schematic_PDF.cpp b/eeschema/plot_schematic_PDF.cpp index 10376669d5..3640e606b9 100644 --- a/eeschema/plot_schematic_PDF.cpp +++ b/eeschema/plot_schematic_PDF.cpp @@ -41,7 +41,6 @@ void DIALOG_PLOT_SCHEMATIC::createPDFFile( bool aPlotAll, bool aPlotFrameRef ) { SCH_SCREEN* screen = m_parent->GetScreen(); - SCH_SHEET_PATH* sheetpath; SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet(); // sheetpath is saved here /* When printing all pages, the printed page is not the current page. In @@ -51,9 +50,12 @@ void DIALOG_PLOT_SCHEMATIC::createPDFFile( bool aPlotAll, bool aPlotFrameRef ) * between many sheets and component references depend on the actual sheet * path used */ - SCH_SHEET_LIST SheetList( NULL ); + SCH_SHEET_LIST sheetList; - sheetpath = SheetList.GetFirst(); + if( aPlotAll ) + sheetList.BuildSheetList( g_RootSheet ); + else + sheetList.push_back( m_parent->GetCurrentSheet() ); // Allocate the plotter and set the job level parameter PDF_PLOTTER* plotter = new PDF_PLOTTER(); @@ -65,26 +67,14 @@ void DIALOG_PLOT_SCHEMATIC::createPDFFile( bool aPlotAll, bool aPlotFrameRef ) wxFileName plotFileName; REPORTER& reporter = m_MessagesBox->Reporter(); - // First page handling is different - bool first_page = true; - - do + for( unsigned i = 0; i < sheetList.size(); i++ ) { - // Step over the schematic hierarchy - if( aPlotAll ) - { - wxCHECK_RET( sheetpath != NULL, wxT( "Attempt to plot undefined sheet path." ) ); + m_parent->SetCurrentSheet( sheetList[i] ); + m_parent->GetCurrentSheet().UpdateAllScreenReferences(); + m_parent->SetSheetNumberAndCount(); + screen = m_parent->GetCurrentSheet().LastScreen(); - SCH_SHEET_PATH list = *sheetpath; - - m_parent->SetCurrentSheet( list ); - m_parent->GetCurrentSheet().UpdateAllScreenReferences(); - m_parent->SetSheetNumberAndCount(); - screen = m_parent->GetCurrentSheet().LastScreen(); - sheetpath = SheetList.GetNext(); - } - - if( first_page ) + if( i == 0 ) { try @@ -107,8 +97,6 @@ void DIALOG_PLOT_SCHEMATIC::createPDFFile( bool aPlotAll, bool aPlotFrameRef ) SetLocaleTo_C_standard(); setupPlotPagePDF( plotter, screen ); plotter->StartPlot(); - first_page = false; - } catch( const IO_ERROR& e ) { @@ -131,7 +119,7 @@ void DIALOG_PLOT_SCHEMATIC::createPDFFile( bool aPlotAll, bool aPlotFrameRef ) } plotOneSheetPDF( plotter, screen, aPlotFrameRef ); - } while( aPlotAll && sheetpath ); + } // Everything done, close the plot and restore the environment msg.Printf( _( "Plot: '%s' OK.\n" ), GetChars( plotFileName.GetFullPath() ) ); diff --git a/eeschema/plot_schematic_PS.cpp b/eeschema/plot_schematic_PS.cpp index 67cb899241..820ad17dcf 100644 --- a/eeschema/plot_schematic_PS.cpp +++ b/eeschema/plot_schematic_PS.cpp @@ -39,10 +39,9 @@ void DIALOG_PLOT_SCHEMATIC::createPSFile( bool aPlotAll, bool aPlotFrameRef ) { SCH_SCREEN* screen = m_parent->GetScreen(); - SCH_SHEET_PATH* sheetpath; - SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet(); // sheetpath is saved here - PAGE_INFO actualPage; // page size selected in schematic - PAGE_INFO plotPage; // page size selected to plot + SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet(); // sheetpath is saved here + PAGE_INFO actualPage; // page size selected in schematic + PAGE_INFO plotPage; // page size selected to plot /* When printing all pages, the printed page is not the current page. * In complex hierarchies, we must update component references @@ -50,26 +49,19 @@ void DIALOG_PLOT_SCHEMATIC::createPSFile( bool aPlotAll, bool aPlotFrameRef ) * because in complex hierarchies a SCH_SCREEN (a drawing ) * is shared between many sheets and component references depend on the actual sheet path used */ - SCH_SHEET_LIST SheetList( NULL ); + SCH_SHEET_LIST sheetList; - sheetpath = SheetList.GetFirst(); - SCH_SHEET_PATH list; + if( aPlotAll ) + sheetList.BuildSheetList( g_RootSheet ); + else + sheetList.push_back( m_parent->GetCurrentSheet() ); - while( true ) + for( unsigned i = 0; i < sheetList.size(); i++ ) { - if( aPlotAll ) - { - if( sheetpath == NULL ) - break; - - list = *sheetpath; - m_parent->SetCurrentSheet( list ); - m_parent->GetCurrentSheet().UpdateAllScreenReferences(); - m_parent->SetSheetNumberAndCount(); - screen = m_parent->GetCurrentSheet().LastScreen(); - sheetpath = SheetList.GetNext(); - } - + m_parent->SetCurrentSheet( sheetList[i] ); + m_parent->GetCurrentSheet().UpdateAllScreenReferences(); + m_parent->SetSheetNumberAndCount(); + screen = m_parent->GetCurrentSheet().LastScreen(); actualPage = screen->GetPageSettings(); switch( m_pageSizeSelect ) @@ -129,9 +121,6 @@ void DIALOG_PLOT_SCHEMATIC::createPSFile( bool aPlotAll, bool aPlotFrameRef ) msg.Printf( wxT( "PS Plotter exception: %s"), GetChars( e.errorText ) ); reporter.Report( msg, REPORTER::RPT_ERROR ); } - - if( !aPlotAll ) - break; } m_parent->SetCurrentSheet( oldsheetpath ); diff --git a/eeschema/plot_schematic_SVG.cpp b/eeschema/plot_schematic_SVG.cpp index 736f758c45..d704c8e92e 100644 --- a/eeschema/plot_schematic_SVG.cpp +++ b/eeschema/plot_schematic_SVG.cpp @@ -43,108 +43,60 @@ void DIALOG_PLOT_SCHEMATIC::createSVGFile( bool aPrintAll, bool aPrintFrameRef ) { - wxString msg; - REPORTER& reporter = m_MessagesBox->Reporter(); + wxString msg; + REPORTER& reporter = m_MessagesBox->Reporter(); + SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet(); + SCH_SHEET_LIST sheetList; if( aPrintAll ) + sheetList.BuildSheetList( g_RootSheet ); + else + sheetList.push_back( m_parent->GetCurrentSheet() ); + + for( unsigned i = 0; i < sheetList.size(); i++ ) { - SCH_SHEET_PATH* sheetpath; - SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet(); - SCH_SHEET_LIST SheetList( NULL ); - sheetpath = SheetList.GetFirst(); - SCH_SHEET_PATH list; - - for( ; ; ) - { - if( sheetpath == NULL ) - { - break; - } - - SCH_SCREEN* screen; - list = *sheetpath; - m_parent->SetCurrentSheet( list ); - m_parent->GetCurrentSheet().UpdateAllScreenReferences(); - m_parent->SetSheetNumberAndCount(); - screen = m_parent->GetCurrentSheet().LastScreen(); - sheetpath = SheetList.GetNext(); - - try - { - wxString fname = m_parent->GetUniqueFilenameForCurrentSheet(); - wxString ext = SVG_PLOTTER::GetDefaultFileExtension(); - wxFileName plotFileName = createPlotFileName( m_outputDirectoryName, - fname, ext, &reporter ); - - bool success = plotOneSheetSVG( m_parent, plotFileName.GetFullPath(), screen, - getModeColor() ? false : true, - aPrintFrameRef ); - - if( !success ) - { - msg.Printf( _( "Cannot create file '%s'.\n" ), - GetChars( plotFileName.GetFullPath() ) ); - reporter.Report( msg, REPORTER::RPT_ERROR ); - } - else - { - msg.Printf( _( "Plot: '%s' OK.\n" ), - GetChars( plotFileName.GetFullPath() ) ); - reporter.Report( msg, REPORTER::RPT_ACTION ); - } - } - catch( const IO_ERROR& e ) - { - // Cannot plot SVG file - msg.Printf( wxT( "SVG Plotter exception: %s" ), GetChars( e.errorText ) ); - reporter.Report( msg, REPORTER::RPT_ERROR ); - - m_parent->SetCurrentSheet( oldsheetpath ); - m_parent->GetCurrentSheet().UpdateAllScreenReferences(); - m_parent->SetSheetNumberAndCount(); - return; - } - } - - m_parent->SetCurrentSheet( oldsheetpath ); + SCH_SCREEN* screen; + m_parent->SetCurrentSheet( sheetList[i] ); m_parent->GetCurrentSheet().UpdateAllScreenReferences(); m_parent->SetSheetNumberAndCount(); - } - else // Print current sheet - { - SCH_SCREEN* screen = (SCH_SCREEN*) m_parent->GetScreen(); + screen = m_parent->GetCurrentSheet().LastScreen(); try { - wxString fname = screen->GetFileName(); + wxString fname = m_parent->GetUniqueFilenameForCurrentSheet(); wxString ext = SVG_PLOTTER::GetDefaultFileExtension(); - wxFileName fn = createPlotFileName( m_outputDirectoryName, fname, ext ); + wxFileName plotFileName = createPlotFileName( m_outputDirectoryName, + fname, ext, &reporter ); - bool success = plotOneSheetSVG( m_parent, fn.GetFullPath(), screen, + bool success = plotOneSheetSVG( m_parent, plotFileName.GetFullPath(), screen, getModeColor() ? false : true, aPrintFrameRef ); - if( success ) + + if( !success ) + { + msg.Printf( _( "Cannot create file '%s'.\n" ), + GetChars( plotFileName.GetFullPath() ) ); + reporter.Report( msg, REPORTER::RPT_ERROR ); + } + else { msg.Printf( _( "Plot: '%s' OK.\n" ), - GetChars( fn.GetFullPath() ) ); + GetChars( plotFileName.GetFullPath() ) ); reporter.Report( msg, REPORTER::RPT_ACTION ); - - } - else // Error - { - msg.Printf( _( "Unable to create file '%s'.\n" ), - GetChars( fn.GetFullPath() ) ); - reporter.Report( msg, REPORTER::RPT_ERROR ); } } catch( const IO_ERROR& e ) { // Cannot plot SVG file - msg.Printf( wxT( "SVG Plotter exception: %s."), GetChars( e.errorText ) ); + msg.Printf( wxT( "SVG Plotter exception: %s" ), GetChars( e.errorText ) ); reporter.Report( msg, REPORTER::RPT_ERROR ); - return; + break; } } + + m_parent->SetCurrentSheet( oldsheetpath ); + m_parent->GetCurrentSheet().UpdateAllScreenReferences(); + m_parent->SetSheetNumberAndCount(); } diff --git a/eeschema/sch_collectors.cpp b/eeschema/sch_collectors.cpp index 04e6b10ee8..bedfcaa7c9 100644 --- a/eeschema/sch_collectors.cpp +++ b/eeschema/sch_collectors.cpp @@ -1,8 +1,8 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2011 Wayne Stambaugh - * Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2011-2016 Wayne Stambaugh + * Copyright (C) 2004-2016 KiCad Developers, see change_log.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -528,13 +528,12 @@ void SCH_FIND_COLLECTOR::Collect( SCH_FIND_REPLACE_DATA& aFindReplaceData, } else { - SCH_SHEET_LIST schematic; - m_sheetPath = schematic.GetFirst(); + SCH_SHEET_LIST schematic( g_RootSheet ); - while( m_sheetPath != NULL ) + for( unsigned i = 0; i < schematic.size(); i++ ) { + m_sheetPath = &schematic[i]; EDA_ITEM::IterateForward( m_sheetPath->LastDrawList(), this, NULL, m_ScanTypes ); - m_sheetPath = schematic.GetNext(); } } diff --git a/eeschema/sch_sheet_path.cpp b/eeschema/sch_sheet_path.cpp index c143943e10..d4d8ff4de7 100644 --- a/eeschema/sch_sheet_path.cpp +++ b/eeschema/sch_sheet_path.cpp @@ -466,82 +466,23 @@ SCH_SHEET* SCH_SHEET_PATH::FindSheetByName( const wxString& aSheetName ) /********************************************************************/ SCH_SHEET_LIST::SCH_SHEET_LIST( SCH_SHEET* aSheet ) { - m_index = 0; - m_count = 0; - m_list = NULL; m_isRootSheet = false; - if( aSheet == NULL ) - aSheet = g_RootSheet; - - BuildSheetList( aSheet ); -} - - -SCH_SHEET_PATH* SCH_SHEET_LIST::GetFirst() -{ - m_index = 0; - - if( GetCount() > 0 ) - return &( m_list[0] ); - - return NULL; -} - - -SCH_SHEET_PATH* SCH_SHEET_LIST::GetNext() -{ - if( m_index < GetCount() ) - m_index++; - - return GetSheet( m_index ); -} - - -SCH_SHEET_PATH* SCH_SHEET_LIST::GetLast() -{ - if( GetCount() == 0 ) - return NULL; - - m_index = GetCount() - 1; - - return GetSheet( m_index ); -} - - -SCH_SHEET_PATH* SCH_SHEET_LIST::GetPrevious() -{ - if( m_index == 0 ) - return NULL; - - m_index -= 1; - - return GetSheet( m_index ); -} - - -SCH_SHEET_PATH* SCH_SHEET_LIST::GetSheet( int aIndex ) const -{ - if( aIndex < GetCount() ) - return &( m_list[aIndex] ); - - return NULL; + if( aSheet != NULL ) + BuildSheetList( aSheet ); } SCH_SHEET_PATH* SCH_SHEET_LIST::GetSheetByPath( const wxString aPath, bool aHumanReadable ) { - SCH_SHEET_PATH* sheet = GetFirst(); wxString sheetPath; - while( sheet ) + for( unsigned i = 0; i < size(); i++ ) { - sheetPath = ( aHumanReadable ) ? sheet->PathHumanReadable() : sheet->Path(); + sheetPath = ( aHumanReadable ) ? at( i ).PathHumanReadable() : at( i ).Path(); if( sheetPath == aPath ) - return sheet; - - sheet = GetNext(); + return &at( i ); } return NULL; @@ -555,52 +496,41 @@ void SCH_SHEET_LIST::BuildSheetList( SCH_SHEET* aSheet ) if( aSheet == g_RootSheet ) m_isRootSheet = true; - if( m_list == NULL ) - { - int count = aSheet->CountSheets(); - - m_count = count; - m_index = 0; - m_list = new SCH_SHEET_PATH[ count ]; - m_currList.clear(); - } - - m_currList.push_back( aSheet ); + m_currentSheetPath.push_back( aSheet ); /** * @todo: Schematic page number is currently a left over relic and is generated as * SCH_SHEET_PATH object is pushed to the list. This only has meaning when * entire hierarchy is created from the root sheet down. */ - m_currList.SetPageNumber( m_index + 1 ); - m_list[m_index] = m_currList; - m_index++; + m_currentSheetPath.SetPageNumber( size() + 1 ); + push_back( m_currentSheetPath ); if( aSheet->GetScreen() ) { - EDA_ITEM* strct = m_currList.LastDrawList(); + EDA_ITEM* item = m_currentSheetPath.LastDrawList(); - while( strct ) + while( item ) { - if( strct->Type() == SCH_SHEET_T ) + if( item->Type() == SCH_SHEET_T ) { - SCH_SHEET* sheet = (SCH_SHEET*) strct; + SCH_SHEET* sheet = (SCH_SHEET*) item; BuildSheetList( sheet ); } - strct = strct->Next(); + item = item->Next(); } } - m_currList.pop_back(); + m_currentSheetPath.pop_back(); } bool SCH_SHEET_LIST::IsModified() { - for( SCH_SHEET_PATH* sheet = GetFirst(); sheet; sheet = GetNext() ) + for( SCH_SHEET_PATHS_ITER it = begin(); it != end(); ++it ) { - if( sheet->LastScreen() && sheet->LastScreen()->IsModify() ) + if( (*it).LastScreen() && (*it).LastScreen()->IsModify() ) return true; } @@ -610,9 +540,9 @@ bool SCH_SHEET_LIST::IsModified() bool SCH_SHEET_LIST::IsAutoSaveRequired() { - for( SCH_SHEET_PATH* sheet = GetFirst(); sheet; sheet = GetNext() ) + for( SCH_SHEET_PATHS_ITER it = begin(); it != end(); ++it ) { - if( sheet->LastScreen() && sheet->LastScreen()->IsSave() ) + if( (*it).LastScreen() && (*it).LastScreen()->IsSave() ) return true; } @@ -622,10 +552,10 @@ bool SCH_SHEET_LIST::IsAutoSaveRequired() void SCH_SHEET_LIST::ClearModifyStatus() { - for( SCH_SHEET_PATH* sheet = GetFirst(); sheet; sheet = GetNext() ) + for( SCH_SHEET_PATHS_ITER it = begin(); it != end(); ++it ) { - if( sheet->LastScreen() ) - sheet->LastScreen()->ClrModify(); + if( (*it).LastScreen() ) + (*it).LastScreen()->ClrModify(); } } @@ -634,29 +564,32 @@ void SCH_SHEET_LIST::AnnotatePowerSymbols( PART_LIBS* aLibs ) { int ref = 1; - for( SCH_SHEET_PATH* path = GetFirst(); path; path = GetNext() ) - path->AnnotatePowerSymbols( aLibs, &ref ); + for( SCH_SHEET_PATHS_ITER it = begin(); it != end(); ++it ) + (*it).AnnotatePowerSymbols( aLibs, &ref ); } void SCH_SHEET_LIST::GetComponents( PART_LIBS* aLibs, SCH_REFERENCE_LIST& aReferences, - bool aIncludePowerSymbols ) + bool aIncludePowerSymbols ) { - for( SCH_SHEET_PATH* path = GetFirst(); path; path = GetNext() ) - path->GetComponents( aLibs, aReferences, aIncludePowerSymbols ); + for( SCH_SHEET_PATHS_ITER it = begin(); it != end(); ++it ) + (*it).GetComponents( aLibs, aReferences, aIncludePowerSymbols ); } void SCH_SHEET_LIST::GetMultiUnitComponents( PART_LIBS* aLibs, - SCH_MULTI_UNIT_REFERENCE_MAP &aRefList, bool aIncludePowerSymbols ) + SCH_MULTI_UNIT_REFERENCE_MAP &aRefList, + bool aIncludePowerSymbols ) { - for( SCH_SHEET_PATH* path = GetFirst(); path; path = GetNext() ) + for( SCH_SHEET_PATHS_ITER it = begin(); it != end(); ++it ) { SCH_MULTI_UNIT_REFERENCE_MAP tempMap; - path->GetMultiUnitComponents( aLibs, tempMap ); + (*it).GetMultiUnitComponents( aLibs, tempMap ); + BOOST_FOREACH( SCH_MULTI_UNIT_REFERENCE_MAP::value_type& pair, tempMap ) { // Merge this list into the main one unsigned n_refs = pair.second.GetCount(); + for( unsigned thisRef = 0; thisRef < n_refs; ++thisRef ) { aRefList[pair.first].AddItem( pair.second[thisRef] ); @@ -673,11 +606,11 @@ SCH_ITEM* SCH_SHEET_LIST::FindNextItem( KICAD_T aType, SCH_SHEET_PATH** aSheetFo bool firstItemFound = false; SCH_ITEM* drawItem = NULL; - SCH_SHEET_PATH* sheet = GetFirst(); + SCH_SHEET_PATHS_ITER it = begin(); - while( sheet ) + while( it != end() ) { - drawItem = sheet->LastDrawList(); + drawItem = (*it).LastDrawList(); while( drawItem ) { @@ -686,7 +619,7 @@ SCH_ITEM* SCH_SHEET_LIST::FindNextItem( KICAD_T aType, SCH_SHEET_PATH** aSheetFo if( aLastItem == NULL || firstItemFound ) { if( aSheetFoundIn ) - *aSheetFoundIn = sheet; + *aSheetFoundIn = &(*it); return drawItem; } @@ -699,12 +632,12 @@ SCH_ITEM* SCH_SHEET_LIST::FindNextItem( KICAD_T aType, SCH_SHEET_PATH** aSheetFo drawItem = drawItem->Next(); } - sheet = GetNext(); + ++it; - if( sheet == NULL && aLastItem && aWrap && !hasWrapped ) + if( it == end() && aLastItem && aWrap && !hasWrapped ) { hasWrapped = true; - sheet = GetFirst(); + it = begin(); } } @@ -718,11 +651,11 @@ SCH_ITEM* SCH_SHEET_LIST::FindPreviousItem( KICAD_T aType, SCH_SHEET_PATH** aShe bool hasWrapped = false; bool firstItemFound = false; SCH_ITEM* drawItem = NULL; - SCH_SHEET_PATH* sheet = GetLast(); + SCH_SHEET_PATHS_RITER it = rbegin(); - while( sheet ) + while( it != rend() ) { - drawItem = sheet->FirstDrawList(); + drawItem = (*it).FirstDrawList(); while( drawItem ) { @@ -731,7 +664,7 @@ SCH_ITEM* SCH_SHEET_LIST::FindPreviousItem( KICAD_T aType, SCH_SHEET_PATH** aShe if( aLastItem == NULL || firstItemFound ) { if( aSheetFoundIn ) - *aSheetFoundIn = sheet; + *aSheetFoundIn = &(*it); return drawItem; } @@ -744,12 +677,12 @@ SCH_ITEM* SCH_SHEET_LIST::FindPreviousItem( KICAD_T aType, SCH_SHEET_PATH** aShe drawItem = drawItem->Back(); } - sheet = GetPrevious(); + ++it; - if( sheet == NULL && aLastItem && aWrap && !hasWrapped ) + if( it == rend() && aLastItem && aWrap && !hasWrapped ) { hasWrapped = true; - sheet = GetLast(); + it = rbegin(); } } @@ -762,8 +695,8 @@ bool SCH_SHEET_LIST::SetComponentFootprint( const wxString& aReference, { bool found = false; - for( SCH_SHEET_PATH* path = GetFirst(); path; path = GetNext() ) - found = path->SetComponentFootprint( aReference, aFootPrint, aSetVisible ); + for( SCH_SHEET_PATHS_ITER it = begin(); it != end(); ++it ) + found = (*it).SetComponentFootprint( aReference, aFootPrint, aSetVisible ); return found; } @@ -773,16 +706,16 @@ bool SCH_SHEET_LIST::IsComplexHierarchy() const { wxString fileName; - for( int i = 0; i < m_count; i++ ) + for( unsigned i = 0; i < size(); i++ ) { - fileName = m_list[i].Last()->GetFileName(); + fileName = at( i ).Last()->GetFileName(); - for( int j = 0; j < m_count; j++ ) + for( unsigned j = 0; j < size(); j++ ) { if( i == j ) continue; - if( fileName == m_list[j].Last()->GetFileName() ) + if( fileName == at( j ).Last()->GetFileName() ) return true; } } @@ -801,17 +734,17 @@ bool SCH_SHEET_LIST::TestForRecursion( const SCH_SHEET_LIST& aSrcSheetHierarchy, destFn.MakeAbsolute( rootFn.GetPath() ); // Test each SCH_SHEET_PATH in this SCH_SHEET_LIST for potential recursion. - for( int i = 0; i < m_count; i++ ) + for( unsigned i = 0; i < size(); i++ ) { // Test each SCH_SHEET_PATH in the source sheet. - for( int j = 0; j < aSrcSheetHierarchy.GetCount(); j++ ) + for( unsigned j = 0; j < aSrcSheetHierarchy.size(); j++ ) { - SCH_SHEET_PATH* sheetPath = aSrcSheetHierarchy.GetSheet( j ); + const SCH_SHEET_PATH* sheetPath = &aSrcSheetHierarchy[j]; for( unsigned k = 0; k < sheetPath->size(); k++ ) { - if( m_list[i].TestForRecursion( sheetPath->GetSheet( k )->GetFileName(), - aDestFileName ) ) + if( at( i ).TestForRecursion( sheetPath->GetSheet( k )->GetFileName(), + aDestFileName ) ) return true; } } @@ -824,9 +757,9 @@ bool SCH_SHEET_LIST::TestForRecursion( const SCH_SHEET_LIST& aSrcSheetHierarchy, SCH_SHEET* SCH_SHEET_LIST::FindSheetByName( const wxString& aSheetName ) { - for( int i = 0; i < m_count; i++ ) + for( unsigned i = 0; i < size(); i++ ) { - SCH_SHEET* sheet = m_list[i].FindSheetByName( aSheetName ); + SCH_SHEET* sheet = at( i ).FindSheetByName( aSheetName ); if( sheet ) return sheet; diff --git a/eeschema/sch_sheet_path.h b/eeschema/sch_sheet_path.h index d956382f64..3e9f9b99e0 100644 --- a/eeschema/sch_sheet_path.h +++ b/eeschema/sch_sheet_path.h @@ -120,12 +120,19 @@ public: int GetPageNumber() const { return m_pageNumber; } + const SCH_SHEET* GetSheet( unsigned aIndex ) const + { + SCH_SHEET* retv = NULL; + + if( aIndex < size() ) + retv = at( aIndex ); + + return const_cast< SCH_SHEET* >( retv ); + } + SCH_SHEET* GetSheet( unsigned aIndex ) { - if( aIndex < size() ) - return at( aIndex ); - - return NULL; + return const_cast< SCH_SHEET* >( static_cast< const SCH_SHEET_PATH& >( *this ).GetSheet( aIndex ) ); } /** @@ -305,100 +312,40 @@ public: }; +typedef std::vector< SCH_SHEET_PATH > SCH_SHEET_PATHS; +typedef SCH_SHEET_PATHS::iterator SCH_SHEET_PATHS_ITER; +typedef SCH_SHEET_PATHS::const_iterator SCH_SHEET_PATHS_CITER; +typedef SCH_SHEET_PATHS::reverse_iterator SCH_SHEET_PATHS_RITER; +typedef SCH_SHEET_PATHS::const_reverse_iterator SCH_SHEET_PATHS_CRITER; + + /** * Class SCH_SHEET_LIST - * handles the list of Sheets in a hierarchy. - * Sheets are not unique, there can be many sheets with the same - * filename and the same SCH_SCREEN reference. - * The schematic (SCH_SCREEN) is shared between these sheets, - * and component references are specific to a sheet path. - * When a sheet is entered, component references and sheet number are updated. + * + * handles a list of #SCH_SHEET_PATH objects in a flattened hierarchy. + * + * #SCH_SHEET objects are not unique, there can be many sheets with the same filename and + * that share the same #SCH_SCREEN reference. Each The schematic file (#SCH_SCREEN) may + * be shared between these sheets and component references are specific to a sheet path. + * When a sheet is entered, component references and sheet page number are updated. */ -class SCH_SHEET_LIST +class SCH_SHEET_LIST : public SCH_SHEET_PATHS { private: - SCH_SHEET_PATH* m_list; - int m_count; /* Number of sheets included in hierarchy, - * starting at the given sheet in constructor . - * the given sheet is counted - */ - int m_index; /* internal variable to handle GetNext(): cleared by - * GetFirst() and incremented by GetNext() after - * returning the next item in m_list. Also used for - * internal calculations in BuildSheetList() - */ bool m_isRootSheet; - SCH_SHEET_PATH m_currList; + SCH_SHEET_PATH m_currentSheetPath; public: /** * Constructor - * builds the list of sheets from aSheet. - * If aSheet == NULL (default) build the whole list of sheets in hierarchy. - * So usually call it with no parameter. + * build a flattened list of SCH_SHEET_PATH objects from \a aSheet. + * + * If aSheet == NULL, then this is an empty hierarchy which the user can populate. */ SCH_SHEET_LIST( SCH_SHEET* aSheet = NULL ); - ~SCH_SHEET_LIST() - { - if( m_list ) - delete[] m_list; - - m_list = NULL; - } - - /** - * Function GetCount - * @return the number of sheets in list: - * usually the number of sheets found in the whole hierarchy - */ - int GetCount() const { return m_count; } - - /** - * Function GetIndex - * @return the last selected screen index. - */ - int GetIndex() const { return m_index; } - - /** - * Function GetFirst - * @return the first item (sheet) in m_list and prepare calls to GetNext() - */ - SCH_SHEET_PATH* GetFirst(); - - /** - * Function GetNext - * @return the next item (sheet) in m_list or NULL if no more item in - * sheet list - */ - SCH_SHEET_PATH* GetNext(); - - /** - * Function GetLast - * returns the last sheet in the sheet list. - * - * @return Last sheet in the list or NULL if sheet list is empty. - */ - SCH_SHEET_PATH* GetLast(); - - /** - * Function GetPrevious - * returns the previous sheet in the sheet list. - * - * @return The previous sheet in the sheet list or NULL if already at the - * beginning of the list. - */ - SCH_SHEET_PATH* GetPrevious(); - - /** - * Function GetSheet - * - * @param aIndex A index in sheet list to get the sheet. - * @return the sheet at \a aIndex position in m_list or NULL if \a aIndex is - * outside the bounds of the index list. - */ - SCH_SHEET_PATH* GetSheet( int aIndex ) const; + ~SCH_SHEET_LIST() {} /** * Function GetSheetByPath @@ -443,7 +390,8 @@ public: * @param aReferences List of references to populate. * @param aIncludePowerSymbols Set to false to only get normal components. */ - void GetComponents( PART_LIBS* aLibs, SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols = true ); + void GetComponents( PART_LIBS* aLibs, SCH_REFERENCE_LIST& aReferences, + bool aIncludePowerSymbols = true ); /** * Function GetMultiUnitComponents @@ -455,7 +403,7 @@ public: * @param aIncludePowerSymbols Set to false to only get normal components. */ void GetMultiUnitComponents( PART_LIBS* aLibs, SCH_MULTI_UNIT_REFERENCE_MAP &aRefList, - bool aIncludePowerSymbols = true ); + bool aIncludePowerSymbols = true ); /** * Function FindNextItem @@ -530,8 +478,6 @@ public: */ SCH_SHEET* FindSheetByName( const wxString& aSheetName ); -private: - /** * Function BuildSheetList * builds the list of sheets and their sheet path from \a aSheet. diff --git a/eeschema/schframe.cpp b/eeschema/schframe.cpp index db4bfd2644..ecd775f411 100644 --- a/eeschema/schframe.cpp +++ b/eeschema/schframe.cpp @@ -477,15 +477,13 @@ void SCH_EDIT_FRAME::SetSheetNumberAndCount() int sheet_count = g_RootSheet->CountSheets(); int SheetNumber = 1; wxString current_sheetpath = m_CurrentSheet->Path(); - SCH_SHEET_LIST sheetList; + SCH_SHEET_LIST sheetList( g_RootSheet ); // Examine all sheets path to find the current sheets path, // and count them from root to the current sheet path: - SCH_SHEET_PATH* sheet; - - for( sheet = sheetList.GetFirst(); sheet != NULL; sheet = sheetList.GetNext() ) + for( unsigned i = 0; i < sheetList.size(); i++ ) { - wxString sheetpath = sheet->Path(); + wxString sheetpath = sheetList[i].Path(); if( sheetpath == current_sheetpath ) // Current sheet path found break; @@ -614,7 +612,7 @@ void SCH_EDIT_FRAME::OnCloseWindow( wxCloseEvent& aEvent ) return; } - SCH_SHEET_LIST sheetList; + SCH_SHEET_LIST sheetList( g_RootSheet ); if( sheetList.IsModified() ) { @@ -787,7 +785,7 @@ void SCH_EDIT_FRAME::OnUpdateHiddenPins( wxUpdateUIEvent& aEvent ) void SCH_EDIT_FRAME::OnUpdateSave( wxUpdateUIEvent& aEvent ) { - SCH_SHEET_LIST sheetList; + SCH_SHEET_LIST sheetList( g_RootSheet ); aEvent.Enable( sheetList.IsModified() ); } @@ -1232,7 +1230,7 @@ bool SCH_EDIT_FRAME::isAutoSaveRequired() const if( g_RootSheet != NULL ) { - SCH_SHEET_LIST sheetList; + SCH_SHEET_LIST sheetList( g_RootSheet ); return sheetList.IsAutoSaveRequired(); } diff --git a/eeschema/sheet.cpp b/eeschema/sheet.cpp index 95005c671e..f57157ef51 100644 --- a/eeschema/sheet.cpp +++ b/eeschema/sheet.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 2004-2015 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2004-2016 KiCad Developers, see change_log.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -46,7 +46,7 @@ bool SCH_EDIT_FRAME::EditSheet( SCH_SHEET* aSheet, SCH_SHEET_PATH* aHierarchy ) if( aSheet == NULL || aHierarchy == NULL ) return false; - SCH_SHEET_LIST hierarchy; // This is the schematic sheet hierarchy. + SCH_SHEET_LIST hierarchy( g_RootSheet ); // This is the schematic sheet hierarchy. // Get the new texts DIALOG_SCH_SHEET_PROPS dlg( this ); diff --git a/eeschema/widgets/pin_shape_combobox.cpp b/eeschema/widgets/pin_shape_combobox.cpp index 9bab9ff8c5..a2c43c916c 100644 --- a/eeschema/widgets/pin_shape_combobox.cpp +++ b/eeschema/widgets/pin_shape_combobox.cpp @@ -57,9 +57,9 @@ PinShapeComboBox::PinShapeComboBox( wxWindow* parent, } -GRAPHIC_PINSHAPE PinShapeComboBox::GetSelection() +GRAPHIC_PINSHAPE PinShapeComboBox::GetPinShapeSelection() { - return static_cast( wxBitmapComboBox::GetSelection() ); + return static_cast( GetSelection() ); } diff --git a/eeschema/widgets/pin_shape_combobox.h b/eeschema/widgets/pin_shape_combobox.h index 659aa020b7..b1f0bddd03 100644 --- a/eeschema/widgets/pin_shape_combobox.h +++ b/eeschema/widgets/pin_shape_combobox.h @@ -46,6 +46,6 @@ public: const wxValidator& validator = wxDefaultValidator, const wxString& name = wxBitmapComboBoxNameStr ); - GRAPHIC_PINSHAPE GetSelection(); - void SetSelection( GRAPHIC_PINSHAPE aShape ); + GRAPHIC_PINSHAPE GetPinShapeSelection(); + void SetSelection( GRAPHIC_PINSHAPE aShape ); }; diff --git a/eeschema/widgets/pin_type_combobox.cpp b/eeschema/widgets/pin_type_combobox.cpp index 70dd5bd1b0..e587c41fae 100644 --- a/eeschema/widgets/pin_type_combobox.cpp +++ b/eeschema/widgets/pin_type_combobox.cpp @@ -57,9 +57,9 @@ PinTypeComboBox::PinTypeComboBox( wxWindow* parent, } -ELECTRICAL_PINTYPE PinTypeComboBox::GetSelection() +ELECTRICAL_PINTYPE PinTypeComboBox::GetPinTypeSelection() { - return static_cast( wxBitmapComboBox::GetSelection() ); + return static_cast( GetSelection() ); } diff --git a/eeschema/widgets/pin_type_combobox.h b/eeschema/widgets/pin_type_combobox.h index c94c5d67dc..00036e1961 100644 --- a/eeschema/widgets/pin_type_combobox.h +++ b/eeschema/widgets/pin_type_combobox.h @@ -46,6 +46,6 @@ public: const wxValidator& validator = wxDefaultValidator, const wxString& name = wxBitmapComboBoxNameStr ); - ELECTRICAL_PINTYPE GetSelection(); + ELECTRICAL_PINTYPE GetPinTypeSelection(); void SetSelection( ELECTRICAL_PINTYPE aType ); }; diff --git a/kicad/commandframe.cpp b/kicad/commandframe.cpp index 1ed6f66f5b..60041d3829 100644 --- a/kicad/commandframe.cpp +++ b/kicad/commandframe.cpp @@ -36,7 +36,7 @@ LAUNCHER_PANEL::LAUNCHER_PANEL( wxWindow* parent ) : wxPanel( parent, wxID_ANY ) { - m_bitmapButtons_maxHeigth = 0; + m_bitmapButtons_maxHeight = 0; m_buttonSeparation = 10; // control of command buttons position m_buttonsListPosition.x = m_buttonSeparation; m_buttonsListPosition.y = m_buttonSeparation; @@ -48,7 +48,7 @@ LAUNCHER_PANEL::LAUNCHER_PANEL( wxWindow* parent ) : int LAUNCHER_PANEL::GetPanelHeight() const { - int height = m_buttonsListPosition.y + m_bitmapButtons_maxHeigth + int height = m_buttonsListPosition.y + m_bitmapButtons_maxHeight + m_buttonSeparation; return height; } @@ -104,8 +104,8 @@ wxBitmapButton* LAUNCHER_PANEL::AddBitmapButton( wxWindowID aId, const wxBitmap& buttSize.x = aBitmap.GetWidth() + btn_margin; buttSize.y = aBitmap.GetHeight() + btn_margin; - if( m_bitmapButtons_maxHeigth < buttSize.y ) - m_bitmapButtons_maxHeigth = buttSize.y; + if( m_bitmapButtons_maxHeight < buttSize.y ) + m_bitmapButtons_maxHeight = buttSize.y; wxBitmapButton* btn = new wxBitmapButton( this, aId, aBitmap, buttPos, buttSize ); m_buttonLastPosition.x += buttSize.x + m_buttonSeparation; diff --git a/kicad/kicad.h b/kicad/kicad.h index 5e319e70d0..66756e0d8a 100644 --- a/kicad/kicad.h +++ b/kicad/kicad.h @@ -308,7 +308,7 @@ private: * of the first bitmap button */ wxPoint m_buttonLastPosition; // position of the last button in the window - int m_bitmapButtons_maxHeigth; // height of bigger bitmap buttons + int m_bitmapButtons_maxHeight; // height of bigger bitmap buttons // Used to calculate the height of the panel. public: LAUNCHER_PANEL( wxWindow* parent ); diff --git a/pcbnew/class_module.cpp b/pcbnew/class_module.cpp index 113f5c253c..882af4f3a3 100644 --- a/pcbnew/class_module.cpp +++ b/pcbnew/class_module.cpp @@ -1176,6 +1176,7 @@ BOARD_ITEM* MODULE::DuplicateAndAddItem( const BOARD_ITEM* aItem, new_item = new_pad; break; } + case PCB_MODULE_TEXT_T: { const TEXTE_MODULE* old_text = static_cast( aItem ); @@ -1191,6 +1192,7 @@ BOARD_ITEM* MODULE::DuplicateAndAddItem( const BOARD_ITEM* aItem, } break; } + case PCB_MODULE_EDGE_T: { EDGE_MODULE* new_edge = new EDGE_MODULE( @@ -1200,6 +1202,7 @@ BOARD_ITEM* MODULE::DuplicateAndAddItem( const BOARD_ITEM* aItem, new_item = new_edge; break; } + case PCB_MODULE_T: // Ignore the module itself break; diff --git a/pcbnew/dialogs/dialog_create_array.cpp b/pcbnew/dialogs/dialog_create_array.cpp index 45389a732e..ccb30bd805 100644 --- a/pcbnew/dialogs/dialog_create_array.cpp +++ b/pcbnew/dialogs/dialog_create_array.cpp @@ -57,11 +57,9 @@ DIALOG_CREATE_ARRAY::DIALOG_CREATE_ARRAY( PCB_BASE_FRAME* aParent, wxPoint aOrig }; m_choicePriAxisNumbering->Set( DIM( charSetDescriptions ), charSetDescriptions ); m_choiceSecAxisNumbering->Set( DIM( charSetDescriptions ), charSetDescriptions ); - m_choiceCircNumberingType->Set( DIM( charSetDescriptions ), charSetDescriptions );; m_choicePriAxisNumbering->SetSelection( 0 ); m_choiceSecAxisNumbering->SetSelection( 0 ); - m_choiceCircNumberingType->SetSelection( 0 ); Add( m_entryNx, m_options.m_gridNx ); Add( m_entryNy, m_options.m_gridNy ); @@ -93,6 +91,9 @@ DIALOG_CREATE_ARRAY::DIALOG_CREATE_ARRAY( PCB_BASE_FRAME* aParent, wxPoint aOrig Add( m_entryGridPriNumberingOffset, m_options.m_gridPriNumberingOffset ); Add( m_entryGridSecNumberingOffset, m_options.m_gridSecNumberingOffset ); + Add( m_rbGridStartNumberingOpt, m_options.m_gridNumberingScheme ); + Add( m_rbCircStartNumberingOpt, m_options.m_circNumberingScheme ); + RestoreConfigToControls(); // Load units into labels @@ -119,19 +120,8 @@ DIALOG_CREATE_ARRAY::DIALOG_CREATE_ARRAY( PCB_BASE_FRAME* aParent, wxPoint aOrig void DIALOG_CREATE_ARRAY::OnParameterChanged( wxCommandEvent& event ) { - const wxObject* evObj = event.GetEventObject(); - - // some controls result in a change of enablement - if( evObj == m_radioBoxGridNumberingScheme - || evObj == m_checkBoxGridRestartNumbering ) - { - setControlEnablement(); - } - - if( evObj == m_entryCentreX || evObj == m_entryCentreY ) - { - calculateCircularArrayProperties(); - } + setControlEnablement(); + calculateCircularArrayProperties(); } @@ -142,12 +132,12 @@ static const std::string& alphabetFromNumberingScheme( static const std::string alphaHex = "0123456789ABCDEF"; static const std::string alphaFull = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; static const std::string alphaNoIOSQXZ = "ABCDEFGHJKLMNPRTUVWY"; - static const std::string alphaEmpty = ""; switch( type ) { + default: case DIALOG_CREATE_ARRAY::NUMBERING_NUMERIC: - return alphaNumeric; + break; case DIALOG_CREATE_ARRAY::NUMBERING_HEX: return alphaHex; @@ -157,12 +147,9 @@ static const std::string& alphabetFromNumberingScheme( case DIALOG_CREATE_ARRAY::NUMBERING_ALPHA_FULL: return alphaFull; - - default: - wxASSERT_MSG( false, wxString( "Un-handled numbering scheme: " ) << type ); } - return alphaEmpty; + return alphaNumeric; } @@ -183,9 +170,6 @@ static bool getNumberingOffset( const std::string& str, { const std::string alphabet = alphabetFromNumberingScheme( type ); - wxASSERT_MSG( !alphabet.empty(), wxString( - "Unable to determine alphabet for numbering scheme: " ) << type ); - int offset = 0; const int radix = alphabet.length(); @@ -242,8 +226,8 @@ void DIALOG_CREATE_ARRAY::OnOkClick( wxCommandEvent& event ) newGrid->m_2dArrayNumbering = m_radioBoxGridNumberingScheme->GetSelection() != 0; // this is only correct if you set the choice up according to the enum size and order - ok = ok && m_choicePriAxisNumbering->GetSelection() < NUMBERING_TYPE_Max - && m_choiceSecAxisNumbering->GetSelection() < NUMBERING_TYPE_Max; + ok = ok && m_choicePriAxisNumbering->GetSelection() <= NUMBERING_TYPE_MAX + && m_choiceSecAxisNumbering->GetSelection() <= NUMBERING_TYPE_MAX; // mind undefined casts to enums (should not be able to happen) if( ok ) @@ -264,7 +248,7 @@ void DIALOG_CREATE_ARRAY::OnOkClick( wxCommandEvent& event ) m_entryGridSecNumberingOffset->GetValue().ToStdString(), newGrid->m_secAxisNumType, newGrid->m_numberingOffsetY ); - newGrid->m_shouldRenumber = m_checkBoxGridRestartNumbering->GetValue(); + newGrid->m_shouldRenumber = m_rbGridStartNumberingOpt->GetSelection() == 1; // Only use settings if all values are good if( ok ) @@ -284,16 +268,8 @@ void DIALOG_CREATE_ARRAY::OnOkClick( wxCommandEvent& event ) ok = ok && m_entryCircCount->GetValue().ToLong( &newCirc->m_nPts ); newCirc->m_rotateItems = m_entryRotateItemsCb->GetValue(); - - newCirc->m_shouldRenumber = m_checkBoxCircRestartNumbering->GetValue(); - - // This is only correct if you set the choice up according to the enum size and order - ok = ok && m_choiceCircNumberingType->GetSelection() < NUMBERING_TYPE_Max; - - // Mind undefined casts to enums (should not be able to happen) - if( ok ) - newCirc->m_numberingType = - (ARRAY_NUMBERING_TYPE_T) m_choiceCircNumberingType->GetSelection(); + newCirc->m_shouldRenumber = m_rbCircStartNumberingOpt->GetSelection() == 1; + newCirc->m_numberingType = NUMBERING_NUMERIC; ok = ok && m_entryCircNumberingStart->GetValue().ToLong( &newCirc->m_numberingOffset ); @@ -311,17 +287,19 @@ void DIALOG_CREATE_ARRAY::OnOkClick( wxCommandEvent& event ) // assign pointer and ownership here *m_settings = newSettings; - ReadConfigFromControls(); EndModal( wxID_OK ); } + + else + wxMessageBox( _(" Bad parameters" ) ); } void DIALOG_CREATE_ARRAY::setControlEnablement() { - const bool renumber = m_checkBoxGridRestartNumbering->GetValue(); + const bool renumber = m_rbGridStartNumberingOpt->GetSelection() == 1; // If we're not renumbering, we can't set the numbering scheme // or axis numbering types @@ -341,10 +319,7 @@ void DIALOG_CREATE_ARRAY::setControlEnablement() m_entryGridPriNumberingOffset->Enable( renumber ); m_entryGridSecNumberingOffset->Enable( renumber && num2d ); - - // Circular array options - const bool circRenumber = m_checkBoxCircRestartNumbering->GetValue(); - m_choiceCircNumberingType->Enable( circRenumber ); + m_entryCircNumberingStart->Enable( m_rbCircStartNumberingOpt->GetSelection() == 1 ); } @@ -371,25 +346,22 @@ std::string DIALOG_CREATE_ARRAY::ARRAY_OPTIONS::getCoordinateNumber( int n, std::string itemNum; const std::string& alphabet = alphabetFromNumberingScheme( type ); - if( !alphabet.empty() ) - { - const bool nonUnitColsStartAt0 = schemeNonUnitColsStartAt0( type ); + const bool nonUnitColsStartAt0 = schemeNonUnitColsStartAt0( type ); - bool firstRound = true; - int radix = alphabet.length(); + bool firstRound = true; + int radix = alphabet.length(); - do { - int modN = n % radix; + do { + int modN = n % radix; - if( nonUnitColsStartAt0 && !firstRound ) - modN--; // Start the "tens/hundreds/etc column" at "Ax", not "Bx" + if( nonUnitColsStartAt0 && !firstRound ) + modN--; // Start the "tens/hundreds/etc column" at "Ax", not "Bx" - itemNum.insert( 0, 1, alphabet[modN] ); + itemNum.insert( 0, 1, alphabet[modN] ); - n /= radix; - firstRound = false; - } while( n ); - } + n /= radix; + firstRound = false; + } while( n ); return itemNum; } @@ -493,7 +465,7 @@ void DIALOG_CREATE_ARRAY::ARRAY_CIRCULAR_OPTIONS::TransformItem( int n, BOARD_IT if( m_angle == 0 ) // angle is zero, divide evenly into m_nPts - angle = 3600.0 * n / float(m_nPts); + angle = 3600.0 * n / double( m_nPts ); else // n'th step angle = m_angle * n; @@ -508,5 +480,9 @@ void DIALOG_CREATE_ARRAY::ARRAY_CIRCULAR_OPTIONS::TransformItem( int n, BOARD_IT wxString DIALOG_CREATE_ARRAY::ARRAY_CIRCULAR_OPTIONS::GetItemNumber( int aN ) const { - return getCoordinateNumber( aN + m_numberingOffset, m_numberingType ); + // The first new pad has aN number == 1, not 0 + if( m_shouldRenumber ) // numbering pad from initial user value + return getCoordinateNumber( aN - 1 + m_numberingOffset, m_numberingType ); + else // numbering pad from inital pad number + return getCoordinateNumber( aN + m_numberingOffset, m_numberingType ); } diff --git a/pcbnew/dialogs/dialog_create_array.h b/pcbnew/dialogs/dialog_create_array.h index e244dd2e36..11aa83f7f1 100644 --- a/pcbnew/dialogs/dialog_create_array.h +++ b/pcbnew/dialogs/dialog_create_array.h @@ -190,9 +190,10 @@ public: * for pin numbering on BGAs, etc */ NUMBERING_ALPHA_FULL, ///< Full 26-character alphabet - NUMBERING_TYPE_Max ///< Invalid maximum value, insert above here }; + #define NUMBERING_TYPE_MAX NUMBERING_ALPHA_FULL + /** * Persistent dialog options */ @@ -217,11 +218,11 @@ public: */ virtual void TransformItem( int n, BOARD_ITEM* item, const wxPoint& rotPoint ) const = 0; - virtual int GetArraySize() const = 0; + virtual int GetArraySize() const = 0; virtual wxString GetItemNumber( int n ) const = 0; virtual wxString InterpolateNumberIntoString( int n, const wxString& pattern ) const; - bool ShouldRenumberItems() const + bool ShouldRenumberItems() const { return m_shouldRenumber; } @@ -342,8 +343,9 @@ private: std::string m_circCentreX, m_circCentreY, m_circAngle, m_circCount, m_circNumberingOffset; bool m_circRotate; - int m_arrayTypeTab; + int m_gridNumberingScheme; + int m_circNumberingScheme; }; static CREATE_ARRAY_DIALOG_ENTRIES m_options; diff --git a/pcbnew/dialogs/dialog_create_array_base.cpp b/pcbnew/dialogs/dialog_create_array_base.cpp index 22744258df..f9e7b43e54 100644 --- a/pcbnew/dialogs/dialog_create_array_base.cpp +++ b/pcbnew/dialogs/dialog_create_array_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Jun 17 2015) +// C++ code generated with wxFormBuilder (version Jan 1 2016) // http://www.wxformbuilder.org/ // // PLEASE DO "NOT" EDIT THIS FILE! @@ -105,20 +105,22 @@ DIALOG_CREATE_ARRAY_BASE::DIALOG_CREATE_ARRAY_BASE( wxWindow* parent, wxWindowID wxString m_radioBoxGridNumberingAxisChoices[] = { _("Horizontal, then vertical"), _("Vertical, then horizontal") }; int m_radioBoxGridNumberingAxisNChoices = sizeof( m_radioBoxGridNumberingAxisChoices ) / sizeof( wxString ); - m_radioBoxGridNumberingAxis = new wxRadioBox( m_gridPanel, wxID_ANY, _("Numbering Direction"), wxDefaultPosition, wxDefaultSize, m_radioBoxGridNumberingAxisNChoices, m_radioBoxGridNumberingAxisChoices, 1, wxRA_SPECIFY_COLS ); + m_radioBoxGridNumberingAxis = new wxRadioBox( m_gridPanel, wxID_ANY, _("Pad Numbering Direction"), wxDefaultPosition, wxDefaultSize, m_radioBoxGridNumberingAxisNChoices, m_radioBoxGridNumberingAxisChoices, 1, wxRA_SPECIFY_COLS ); m_radioBoxGridNumberingAxis->SetSelection( 0 ); bSizer3->Add( m_radioBoxGridNumberingAxis, 0, wxALL|wxEXPAND, 5 ); - m_checkBoxGridReverseNumbering = new wxCheckBox( m_gridPanel, wxID_ANY, _("Reverse numbering on alternate rows or columns"), wxDefaultPosition, wxDefaultSize, 0 ); + m_checkBoxGridReverseNumbering = new wxCheckBox( m_gridPanel, wxID_ANY, _("Reverse pad numbering on alternate rows or columns"), wxDefaultPosition, wxDefaultSize, 0 ); bSizer3->Add( m_checkBoxGridReverseNumbering, 0, wxALL, 5 ); - m_checkBoxGridRestartNumbering = new wxCheckBox( m_gridPanel, wxID_ANY, _("Restart numbering"), wxDefaultPosition, wxDefaultSize, 0 ); - m_checkBoxGridRestartNumbering->SetValue(true); - bSizer3->Add( m_checkBoxGridRestartNumbering, 0, wxALL, 5 ); + wxString m_rbGridStartNumberingOptChoices[] = { _("Use first free number"), _("From start value") }; + int m_rbGridStartNumberingOptNChoices = sizeof( m_rbGridStartNumberingOptChoices ) / sizeof( wxString ); + m_rbGridStartNumberingOpt = new wxRadioBox( m_gridPanel, wxID_ANY, _("Initial pad number"), wxDefaultPosition, wxDefaultSize, m_rbGridStartNumberingOptNChoices, m_rbGridStartNumberingOptChoices, 1, wxRA_SPECIFY_COLS ); + m_rbGridStartNumberingOpt->SetSelection( 1 ); + bSizer3->Add( m_rbGridStartNumberingOpt, 0, wxALL|wxEXPAND, 5 ); wxString m_radioBoxGridNumberingSchemeChoices[] = { _("Continuous (1, 2, 3...)"), _("Coordinate (A1, A2, ... B1, ...)") }; int m_radioBoxGridNumberingSchemeNChoices = sizeof( m_radioBoxGridNumberingSchemeChoices ) / sizeof( wxString ); - m_radioBoxGridNumberingScheme = new wxRadioBox( m_gridPanel, wxID_ANY, _("Numbering Scheme"), wxDefaultPosition, wxDefaultSize, m_radioBoxGridNumberingSchemeNChoices, m_radioBoxGridNumberingSchemeChoices, 1, wxRA_SPECIFY_COLS ); + m_radioBoxGridNumberingScheme = new wxRadioBox( m_gridPanel, wxID_ANY, _("Pad Numbering Scheme"), wxDefaultPosition, wxDefaultSize, m_radioBoxGridNumberingSchemeNChoices, m_radioBoxGridNumberingSchemeChoices, 1, wxRA_SPECIFY_COLS ); m_radioBoxGridNumberingScheme->SetSelection( 1 ); bSizer3->Add( m_radioBoxGridNumberingScheme, 0, wxALL|wxEXPAND, 5 ); @@ -147,7 +149,7 @@ DIALOG_CREATE_ARRAY_BASE::DIALOG_CREATE_ARRAY_BASE( wxWindow* parent, wxWindowID wxBoxSizer* bSizer5; bSizer5 = new wxBoxSizer( wxHORIZONTAL ); - m_labelGridNumberingOffset = new wxStaticText( m_gridPanel, wxID_ANY, _("Numbering start:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_labelGridNumberingOffset = new wxStaticText( m_gridPanel, wxID_ANY, _("Pad numbering start:"), wxDefaultPosition, wxDefaultSize, 0 ); m_labelGridNumberingOffset->Wrap( -1 ); bSizer5->Add( m_labelGridNumberingOffset, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); @@ -242,37 +244,30 @@ DIALOG_CREATE_ARRAY_BASE::DIALOG_CREATE_ARRAY_BASE( wxWindow* parent, wxWindowID bSizer4->Add( gbSizer2, 0, wxALL|wxEXPAND, 5 ); - wxBoxSizer* bSizer6; - bSizer6 = new wxBoxSizer( wxVERTICAL ); + wxStaticBoxSizer* sbcircPadNumberingSizer; + sbcircPadNumberingSizer = new wxStaticBoxSizer( new wxStaticBox( m_circularPanel, wxID_ANY, _("Pad Numbering Options") ), wxVERTICAL ); - m_checkBoxCircRestartNumbering = new wxCheckBox( m_circularPanel, wxID_ANY, _("Restart numbering"), wxDefaultPosition, wxDefaultSize, 0 ); - m_checkBoxCircRestartNumbering->SetValue(true); - bSizer6->Add( m_checkBoxCircRestartNumbering, 0, wxALL, 5 ); - - m_labelCircNumbering = new wxStaticText( m_circularPanel, wxID_ANY, _("Numbering type:"), wxDefaultPosition, wxDefaultSize, 0 ); - m_labelCircNumbering->Wrap( -1 ); - bSizer6->Add( m_labelCircNumbering, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); - - wxArrayString m_choiceCircNumberingTypeChoices; - m_choiceCircNumberingType = new wxChoice( m_circularPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_choiceCircNumberingTypeChoices, 0 ); - m_choiceCircNumberingType->SetSelection( 0 ); - bSizer6->Add( m_choiceCircNumberingType, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); + wxString m_rbCircStartNumberingOptChoices[] = { _("Use first free number"), _("From start value") }; + int m_rbCircStartNumberingOptNChoices = sizeof( m_rbCircStartNumberingOptChoices ) / sizeof( wxString ); + m_rbCircStartNumberingOpt = new wxRadioBox( sbcircPadNumberingSizer->GetStaticBox(), wxID_ANY, _("Initial pad number"), wxDefaultPosition, wxDefaultSize, m_rbCircStartNumberingOptNChoices, m_rbCircStartNumberingOptChoices, 1, wxRA_SPECIFY_COLS ); + m_rbCircStartNumberingOpt->SetSelection( 0 ); + sbcircPadNumberingSizer->Add( m_rbCircStartNumberingOpt, 0, wxALL|wxEXPAND, 5 ); wxBoxSizer* bSizer7; bSizer7 = new wxBoxSizer( wxHORIZONTAL ); - m_labelCircNumStart = new wxStaticText( m_circularPanel, wxID_ANY, _("Numbering start:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_labelCircNumStart = new wxStaticText( sbcircPadNumberingSizer->GetStaticBox(), wxID_ANY, _("Pad numbering start value:"), wxDefaultPosition, wxDefaultSize, 0 ); m_labelCircNumStart->Wrap( -1 ); bSizer7->Add( m_labelCircNumStart, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); - m_entryCircNumberingStart = new wxTextCtrl( m_circularPanel, wxID_ANY, _("1"), wxDefaultPosition, wxDefaultSize, 0 ); - bSizer7->Add( m_entryCircNumberingStart, 0, wxALL, 5 ); + m_entryCircNumberingStart = new wxTextCtrl( sbcircPadNumberingSizer->GetStaticBox(), wxID_ANY, _("1"), wxDefaultPosition, wxDefaultSize, 0 ); + bSizer7->Add( m_entryCircNumberingStart, 1, wxALL, 5 ); - bSizer6->Add( bSizer7, 0, wxEXPAND, 5 ); + sbcircPadNumberingSizer->Add( bSizer7, 0, wxEXPAND, 5 ); - bSizer4->Add( bSizer6, 1, wxALL|wxEXPAND, 5 ); + bSizer4->Add( sbcircPadNumberingSizer, 1, wxEXPAND|wxALL, 5 ); m_circularPanel->SetSizer( bSizer4 ); @@ -294,7 +289,6 @@ DIALOG_CREATE_ARRAY_BASE::DIALOG_CREATE_ARRAY_BASE( wxWindow* parent, wxWindowID this->SetSizer( bMainSizer ); this->Layout(); - bMainSizer->Fit( this ); // Connect Events this->Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_CREATE_ARRAY_BASE::OnClose ) ); @@ -305,12 +299,13 @@ DIALOG_CREATE_ARRAY_BASE::DIALOG_CREATE_ARRAY_BASE( wxWindow* parent, wxWindowID m_entryOffsetX->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); m_entryOffsetY->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); m_entryStagger->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); - m_checkBoxGridRestartNumbering->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); + m_rbGridStartNumberingOpt->Connect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); m_radioBoxGridNumberingScheme->Connect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); m_entryCentreX->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); m_entryCentreY->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); m_entryCircAngle->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); m_entryCircCount->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); + m_rbCircStartNumberingOpt->Connect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); m_stdButtonsOK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnOkClick ), NULL, this ); } @@ -325,12 +320,13 @@ DIALOG_CREATE_ARRAY_BASE::~DIALOG_CREATE_ARRAY_BASE() m_entryOffsetX->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); m_entryOffsetY->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); m_entryStagger->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); - m_checkBoxGridRestartNumbering->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); + m_rbGridStartNumberingOpt->Disconnect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); m_radioBoxGridNumberingScheme->Disconnect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); m_entryCentreX->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); m_entryCentreY->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); m_entryCircAngle->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); m_entryCircCount->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); + m_rbCircStartNumberingOpt->Disconnect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnParameterChanged ), NULL, this ); m_stdButtonsOK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_CREATE_ARRAY_BASE::OnOkClick ), NULL, this ); } diff --git a/pcbnew/dialogs/dialog_create_array_base.fbp b/pcbnew/dialogs/dialog_create_array_base.fbp index 9f060cc381..f6eb1cc67e 100644 --- a/pcbnew/dialogs/dialog_create_array_base.fbp +++ b/pcbnew/dialogs/dialog_create_array_base.fbp @@ -44,7 +44,7 @@ -1,-1 DIALOG_CREATE_ARRAY_BASE - -1,-1 + 652,473 wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER DIALOG_SHIM; dialog_shim.h Create Array @@ -258,11 +258,11 @@ bSizer2 wxHORIZONTAL none - + 5 wxEXPAND 1 - + wxBOTH @@ -397,7 +397,7 @@ 0 - + 0 0 @@ -577,7 +577,7 @@ 0 - + 0 0 @@ -757,7 +757,7 @@ 0 - + 0 0 @@ -1023,7 +1023,7 @@ 0 - + 0 0 @@ -1289,7 +1289,7 @@ 0 - + 0 0 @@ -1555,7 +1555,7 @@ 0 - + 0 0 @@ -1821,7 +1821,7 @@ 0 - + 0 0 @@ -2014,7 +2014,7 @@ 0 0 wxID_ANY - Numbering Direction + Pad Numbering Direction 1 0 @@ -2104,7 +2104,7 @@ 0 0 wxID_ANY - Reverse numbering on alternate rows or columns + Reverse pad numbering on alternate rows or columns 0 @@ -2159,11 +2159,11 @@ - + 5 - wxALL + wxALL|wxEXPAND 0 - + 1 1 1 @@ -2177,7 +2177,7 @@ 1 0 - 1 + "Use first free number" "From start value" 1 1 @@ -2192,7 +2192,8 @@ 0 0 wxID_ANY - Restart numbering + Initial pad number + 1 0 @@ -2200,7 +2201,7 @@ 0 1 - m_checkBoxGridRestartNumbering + m_rbGridStartNumberingOpt 1 @@ -2208,9 +2209,10 @@ 1 Resizable + 1 1 - + wxRA_SPECIFY_COLS 0 @@ -2222,7 +2224,6 @@ - OnParameterChanged @@ -2239,6 +2240,7 @@ + OnParameterChanged @@ -2280,7 +2282,7 @@ 0 0 wxID_ANY - Numbering Scheme + Pad Numbering Scheme 1 0 @@ -2720,7 +2722,7 @@ 0 0 wxID_ANY - Numbering start: + Pad numbering start: 0 @@ -2806,7 +2808,7 @@ 0 - + 0 0 @@ -2897,7 +2899,7 @@ 0 - + 0 0 @@ -3182,7 +3184,7 @@ 0 - + 0 0 @@ -3448,7 +3450,7 @@ 0 - + 0 0 @@ -3886,7 +3888,7 @@ 0 - + 0 0 @@ -4152,7 +4154,7 @@ 0 - + 0 0 @@ -4389,18 +4391,22 @@ 5 - wxALL|wxEXPAND + wxEXPAND|wxALL 1 - + + wxID_ANY + Pad Numbering Options - bSizer6 + sbcircPadNumberingSizer wxVERTICAL + 1 none - + + 5 - wxALL + wxALL|wxEXPAND 0 - + 1 1 1 @@ -4414,7 +4420,7 @@ 1 0 - 1 + "Use first free number" "From start value" 1 1 @@ -4429,7 +4435,8 @@ 0 0 wxID_ANY - Restart numbering + Initial pad number + 1 0 @@ -4437,177 +4444,7 @@ 0 1 - m_checkBoxCircRestartNumbering - 1 - - - protected - 1 - - Resizable - 1 - - - - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 5 - wxTOP|wxRIGHT|wxLEFT - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - Numbering type: - - 0 - - - 0 - - 1 - m_labelCircNumbering - 1 - - - protected - 1 - - Resizable - 1 - - - - 0 - - - - - -1 - - - - - - - - - - - - - - - - - - - - - - - - - - - 5 - wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - - 0 - - - 0 - - 1 - m_choiceCircNumberingType + m_rbCircStartNumberingOpt 1 @@ -4618,7 +4455,7 @@ 0 1 - + wxRA_SPECIFY_COLS 0 @@ -4630,7 +4467,6 @@ - @@ -4647,6 +4483,7 @@ + OnParameterChanged @@ -4696,7 +4533,7 @@ 0 0 wxID_ANY - Numbering start: + Pad numbering start value: 0 @@ -4750,7 +4587,7 @@ 5 wxALL - 0 + 1 1 1 @@ -4782,7 +4619,7 @@ 0 - + 0 0 diff --git a/pcbnew/dialogs/dialog_create_array_base.h b/pcbnew/dialogs/dialog_create_array_base.h index 3e4f79895d..df1f9903bc 100644 --- a/pcbnew/dialogs/dialog_create_array_base.h +++ b/pcbnew/dialogs/dialog_create_array_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Jun 17 2015) +// C++ code generated with wxFormBuilder (version Jan 1 2016) // http://www.wxformbuilder.org/ // // PLEASE DO "NOT" EDIT THIS FILE! @@ -30,6 +30,7 @@ class DIALOG_SHIM; #include #include #include +#include #include #include #include @@ -69,7 +70,7 @@ class DIALOG_CREATE_ARRAY_BASE : public DIALOG_SHIM wxRadioBox* m_radioBoxGridStaggerType; wxRadioBox* m_radioBoxGridNumberingAxis; wxCheckBox* m_checkBoxGridReverseNumbering; - wxCheckBox* m_checkBoxGridRestartNumbering; + wxRadioBox* m_rbGridStartNumberingOpt; wxRadioBox* m_radioBoxGridNumberingScheme; wxStaticText* m_labelPriAxisNumbering; wxChoice* m_choicePriAxisNumbering; @@ -94,9 +95,7 @@ class DIALOG_CREATE_ARRAY_BASE : public DIALOG_SHIM wxTextCtrl* m_entryCircCount; wxStaticText* m_labelCircRotate; wxCheckBox* m_entryRotateItemsCb; - wxCheckBox* m_checkBoxCircRestartNumbering; - wxStaticText* m_labelCircNumbering; - wxChoice* m_choiceCircNumberingType; + wxRadioBox* m_rbCircStartNumberingOpt; wxStaticText* m_labelCircNumStart; wxTextCtrl* m_entryCircNumberingStart; wxStdDialogButtonSizer* m_stdButtons; @@ -111,7 +110,7 @@ class DIALOG_CREATE_ARRAY_BASE : public DIALOG_SHIM public: - DIALOG_CREATE_ARRAY_BASE( wxWindow* parent, wxWindowID id = wxID_DIALOG_CREATE_ARRAY, const wxString& title = _("Create Array"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); + DIALOG_CREATE_ARRAY_BASE( wxWindow* parent, wxWindowID id = wxID_DIALOG_CREATE_ARRAY, const wxString& title = _("Create Array"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 652,473 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); ~DIALOG_CREATE_ARRAY_BASE(); }; diff --git a/pcbnew/edit.cpp b/pcbnew/edit.cpp index eae9b4cd75..703186bbac 100644 --- a/pcbnew/edit.cpp +++ b/pcbnew/edit.cpp @@ -1,10 +1,10 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr + * Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2015 SoftPLC Corporation, Dick Hollenbeck * Copyright (C) 2015 Wayne Stambaugh - * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -1605,10 +1605,14 @@ void PCB_BASE_EDIT_FRAME::createArray() if( !item ) return; + // Note: original item is no more modified. + bool editingModule = NULL != dynamic_cast( this ); BOARD* board = GetBoard(); - // Remember it is valid only in the module editor + + // Remember this is valid and used only in the module editor. + // in board editor, the parent of items is usually the board. MODULE* module = static_cast( item->GetParent() ); DIALOG_CREATE_ARRAY::ARRAY_OPTIONS* array_opts = NULL; @@ -1633,77 +1637,35 @@ void PCB_BASE_EDIT_FRAME::createArray() // modedit saves everything upfront SaveCopyInUndoList( board->m_Modules, UR_MODEDIT ); } - else - { - // We may also change the original item - SaveCopyInUndoList( item, UR_CHANGED ); - } - wxString cachedString; + #define INCREMENT_REF false + #define INCREMENT_PADNUMBER true - if( item->Type() == PCB_MODULE_T ) + // The first item in list is the original item. We do not modify it + for( int ptN = 1; ptN < array_opts->GetArraySize(); ptN++ ) { - cachedString = static_cast( item )->GetReferencePrefix(); - } - else if( EDA_TEXT* text = dynamic_cast( item ) ) - { - // Copy the text (not just take a reference - cachedString = text->GetText(); - } + BOARD_ITEM* new_item; - for( int ptN = 0; ptN < array_opts->GetArraySize(); ptN++ ) - { - BOARD_ITEM* new_item = NULL; - - if( ptN == 0 ) - { - new_item = item; - } + if( editingModule ) + new_item = module->DuplicateAndAddItem( item, INCREMENT_PADNUMBER ); else - { - if( editingModule ) - new_item = module->DuplicateAndAddItem( item, true ); - else - new_item = board->DuplicateAndAddItem( item, true ); + new_item = board->DuplicateAndAddItem( item, INCREMENT_REF ); - if( new_item ) - { - array_opts->TransformItem( ptN, new_item, rotPoint ); - newItemsList.PushItem( new_item ); - } + if( new_item ) + { + array_opts->TransformItem( ptN, new_item, rotPoint ); + newItemsList.PushItem( new_item ); // For undo list } if( !new_item || !array_opts->ShouldRenumberItems() ) continue; - // Renumber items - switch( new_item->Type() ) - { - case PCB_MODULE_TEXT_T: - case PCB_TEXT_T: - { - EDA_TEXT* text = dynamic_cast( new_item ); - if( text ) - text->SetText( array_opts->InterpolateNumberIntoString( ptN, cachedString ) ); - - break; - } - case PCB_MODULE_T: - { - const wxString padName = array_opts->GetItemNumber( ptN ); - static_cast( new_item )->SetReference( cachedString + padName ); - - break; - } - case PCB_PAD_T: + // Renumber pads. Only new pad number renumbering has meaning, + // in the footprint editor. + if( new_item->Type() == PCB_PAD_T ) { const wxString padName = array_opts->GetItemNumber( ptN ); static_cast( new_item )->SetPadName( padName ); - - break; - } - default: - break; } } diff --git a/pcbnew/legacy_plugin.cpp b/pcbnew/legacy_plugin.cpp index 408d539fdf..a8faa82804 100644 --- a/pcbnew/legacy_plugin.cpp +++ b/pcbnew/legacy_plugin.cpp @@ -3131,1091 +3131,6 @@ void LEGACY_PLUGIN::SaveModule3D( const MODULE* me ) const } -#if 0 - -//-------------------------------------------------------- - - -static inline const char* ShowVertJustify( EDA_TEXT_VJUSTIFY_T vertical ) -{ - const char* rs; - switch( vertical ) - { - case GR_TEXT_VJUSTIFY_TOP: rs = "T"; break; - case GR_TEXT_VJUSTIFY_CENTER: rs = "C"; break; - case GR_TEXT_VJUSTIFY_BOTTOM: rs = "B"; break; - default: rs = "?"; break; - } - return rs; -} - - -static inline const char* ShowHorizJustify( EDA_TEXT_HJUSTIFY_T horizontal ) -{ - const char* rs; - switch( horizontal ) - { - case GR_TEXT_HJUSTIFY_LEFT: rs = "L"; break; - case GR_TEXT_HJUSTIFY_CENTER: rs = "C"; break; - case GR_TEXT_HJUSTIFY_RIGHT: rs = "R"; break; - default: rs = "?"; break; - } - return rs; -} - - -#define SPBUFZ 50 // wire all usages of this together. - -int LEGACY_PLUGIN::biuSprintf( char* buf, BIU aValue ) const -{ - double engUnits = biuToDisk * aValue; - int len; - - if( engUnits != 0.0 && fabsl( engUnits ) <= 0.0001 ) - { - len = snprintf( buf, SPBUFZ, "%.10f", engUnits ); - - while( --len > 0 && buf[len] == '0' ) - buf[len] = '\0'; - - ++len; - } - else - { - // The %.10g is about optimal since we are dealing with a bounded - // range on aValue, and we can be sure that there will never - // be a reason to have more than 6 digits to the right of the - // decimal point because we are converting from integer - // (signed whole numbers) nanometers to mm. A value of - // 0.000001 is one nanometer, the smallest positive nonzero value - // that we can ever have here. If you ever see a board file with - // more digits to the right of the decimal point than 6, this is a - // possibly a bug in a formatting string nearby. - len = snprintf( buf, SPBUFZ, "%.10g", engUnits ); - } - return len; -} - - -std::string LEGACY_PLUGIN::fmtBIU( BIU aValue ) const -{ - char temp[SPBUFZ]; - - int len = biuSprintf( temp, aValue ); - - return std::string( temp, len ); -} - - -std::string LEGACY_PLUGIN::fmtDEG( double aAngle ) const -{ - char temp[50]; - - // @todo a hook site to convert from tenths degrees to degrees for BOARD_FORMAT_VERSION 2. - - // MINGW: snprintf() comes from gcc folks, sprintf() comes from Microsoft. - int len = snprintf( temp, sizeof( temp ), "%.10g", aAngle ); - - return std::string( temp, len ); -} - - -std::string LEGACY_PLUGIN::fmtBIUPair( BIU first, BIU second ) const -{ - char temp[2*SPBUFZ+2]; - char* cp = temp; - - cp += biuSprintf( cp, first ); - - *cp++ = ' '; - - cp += biuSprintf( cp, second ); - - return std::string( temp, cp - temp ); -} - -void LEGACY_PLUGIN::Save( const wxString& aFileName, BOARD* aBoard, const PROPERTIES* aProperties ) -{ - LOCALE_IO toggle; // toggles on, then off, the C locale. - - init( aProperties ); - - FILE* fp = wxFopen( aFileName, wxT( "w" ) ); - if( !fp ) - { - m_error.Printf( _( "Unable to open file '%s'" ), aFileName.GetData() ); - THROW_IO_ERROR( m_error ); - } - - m_filename = aFileName; - - // wxf now owns fp, will close on exception or return - wxFFile wxf( fp ); - - m_fp = fp; // member function accessibility - - wxString header = wxString::Format( - wxT( "PCBNEW-BOARD Version %d date %s\n\n# Created by Pcbnew%s\n\n" ), - LEGACY_BOARD_FILE_VERSION, DateAndTime().GetData(), - GetBuildVersion().GetData() ); - - // save a file header, if caller provided one (with trailing \n hopefully). - fprintf( m_fp, "%s", TO_UTF8( header ) ); - - SaveBOARD( aBoard ); -} - - -wxString LEGACY_PLUGIN::writeError() const -{ - return wxString::Format( _( "error writing to file '%s'" ), m_filename.GetData() ); -} - -#define CHECK_WRITE_ERROR() \ -do { \ - if( ferror( m_fp ) ) \ - { \ - THROW_IO_ERROR( writeError() ); \ - } \ -} while(0) - - -// With the advent of the LSET expansion it was agreed to abort the legacy save since -// we'd have to expand the old format in order to suppor the new LAYER_IDs. - -void LEGACY_PLUGIN::SaveBOARD( const BOARD* aBoard ) const -{ - m_mapping->SetBoard( aBoard ); - - saveGENERAL( aBoard ); - - saveSHEET( aBoard ); - - saveSETUP( aBoard ); - - saveBOARD_ITEMS( aBoard ); -} - - -void LEGACY_PLUGIN::saveGENERAL( const BOARD* aBoard ) const -{ - fprintf( m_fp, "$GENERAL\n" ); - fprintf( m_fp, "encoding utf-8\n" ); - - // tell folks the units used within the file, as early as possible here. - fprintf( m_fp, "Units mm\n" ); - - // Write copper layer count - fprintf( m_fp, "LayerCount %d\n", aBoard->GetCopperLayerCount() ); - - /* No, EnabledLayers has this information, plus g_TabAllCopperLayerMask is - global and globals are not allowed in a plugin. - fprintf( m_fp, - "Ly %8X\n", - g_TabAllCopperLayerMask[NbLayers - 1] | ALL_NO_CU_LAYERS ); - */ - - fprintf( m_fp, "EnabledLayers %08X\n", aBoard->GetEnabledLayers() ); - - if( aBoard->GetEnabledLayers() != aBoard->GetVisibleLayers() ) - fprintf( m_fp, "VisibleLayers %08X\n", aBoard->GetVisibleLayers() ); - - fprintf( m_fp, "Links %d\n", aBoard->GetRatsnestsCount() ); - fprintf( m_fp, "NoConn %d\n", aBoard->GetUnconnectedNetCount() ); - - // Write Bounding box info - EDA_RECT bbbox = ((BOARD*)aBoard)->ComputeBoundingBox(); - - fprintf( m_fp, "Di %s %s\n", - fmtBIUPair( bbbox.GetX(), bbbox.GetY() ).c_str(), - fmtBIUPair( bbbox.GetRight(), bbbox.GetBottom() ).c_str() ); - - fprintf( m_fp, "Ndraw %d\n", aBoard->m_Drawings.GetCount() ); - fprintf( m_fp, "Ntrack %d\n", aBoard->GetNumSegmTrack() ); - fprintf( m_fp, "Nzone %d\n", aBoard->GetNumSegmZone() ); - fprintf( m_fp, "BoardThickness %s\n", fmtBIU( aBoard->GetDesignSettings().GetBoardThickness() ).c_str() ); - fprintf( m_fp, "Nmodule %d\n", aBoard->m_Modules.GetCount() ); - fprintf( m_fp, "Nnets %d\n", m_mapping->GetSize() ); - fprintf( m_fp, "$EndGENERAL\n\n" ); -} - - -void LEGACY_PLUGIN::saveSHEET( const BOARD* aBoard ) const -{ - const PAGE_INFO& pageInfo = aBoard->GetPageSettings(); - const TITLE_BLOCK& tb = ((BOARD*)aBoard)->GetTitleBlock(); - - fprintf( m_fp, "$SHEETDESCR\n" ); - - // paper is described in mils - fprintf( m_fp, "Sheet %s %d %d%s\n", - TO_UTF8( pageInfo.GetType() ), - pageInfo.GetWidthMils(), - pageInfo.GetHeightMils(), - !pageInfo.IsCustom() && pageInfo.IsPortrait() ? - " portrait" : "" - ); - - fprintf( m_fp, "Title %s\n", EscapedUTF8( tb.GetTitle() ).c_str() ); - fprintf( m_fp, "Date %s\n", EscapedUTF8( tb.GetDate() ).c_str() ); - fprintf( m_fp, "Rev %s\n", EscapedUTF8( tb.GetRevision() ).c_str() ); - fprintf( m_fp, "Comp %s\n", EscapedUTF8( tb.GetCompany() ).c_str() ); - fprintf( m_fp, "Comment1 %s\n", EscapedUTF8( tb.GetComment1() ).c_str() ); - fprintf( m_fp, "Comment2 %s\n", EscapedUTF8( tb.GetComment2() ).c_str() ); - fprintf( m_fp, "Comment3 %s\n", EscapedUTF8( tb.GetComment3() ).c_str() ); - fprintf( m_fp, "Comment4 %s\n", EscapedUTF8( tb.GetComment4() ).c_str() ); - fprintf( m_fp, "$EndSHEETDESCR\n\n" ); -} - - -void LEGACY_PLUGIN::saveSETUP( const BOARD* aBoard ) const -{ - const BOARD_DESIGN_SETTINGS& bds = aBoard->GetDesignSettings(); - NETCLASSPTR netclass_default = bds.GetDefault(); - - fprintf( m_fp, "$SETUP\n" ); - - /* Internal units are nobody's business, they are internal. - Units used in the file are now in the "Units" attribute of $GENERAL. - fprintf( m_fp,, "InternalUnit %f INCH\n", 1.0 / PCB_LEGACY_INTERNAL_UNIT ); - */ - - fprintf( m_fp, "Layers %d\n", aBoard->GetCopperLayerCount() ); - - unsigned layerMask = ALL_CU_LAYERS & aBoard->GetEnabledLayers(); - - for( LAYER_NUM layer = FIRST_LAYER; layer <= LAST_COPPER_LAYER; ++layer ) - { - if( layerMask & MASK( layer ) ) - { - fprintf( m_fp, "Layer[%d] %s %s\n", layer, - TO_UTF8( aBoard->GetLayerName( layer ) ), - LAYER::ShowType( aBoard->GetLayerType( layer ) ) ); - } - } - - // Save current default track width, for compatibility with older Pcbnew version; - fprintf( m_fp, "TrackWidth %s\n", - fmtBIU( aBoard->GetDesignSettings().GetCurrentTrackWidth() ).c_str() ); - - // Save custom tracks width list (the first is not saved here: this is the netclass value - for( unsigned ii = 1; ii < aBoard->GetDesignSettings().m_TrackWidthList.size(); ii++ ) - fprintf( m_fp, "TrackWidthList %s\n", fmtBIU( aBoard->GetDesignSettings().m_TrackWidthList[ii] ).c_str() ); - - fprintf( m_fp, "TrackClearence %s\n", fmtBIU( netclass_default->GetClearance() ).c_str() ); - - // ZONE_SETTINGS - fprintf( m_fp, "ZoneClearence %s\n", fmtBIU( aBoard->GetZoneSettings().m_ZoneClearance ).c_str() ); - fprintf( m_fp, "Zone_45_Only %d\n", aBoard->GetZoneSettings().m_Zone_45_Only ); - - fprintf( m_fp, "TrackMinWidth %s\n", fmtBIU( bds.m_TrackMinWidth ).c_str() ); - - fprintf( m_fp, "DrawSegmWidth %s\n", fmtBIU( bds.m_DrawSegmentWidth ).c_str() ); - fprintf( m_fp, "EdgeSegmWidth %s\n", fmtBIU( bds.m_EdgeSegmentWidth ).c_str() ); - - // Save current default via size, for compatibility with older Pcbnew version; - fprintf( m_fp, "ViaSize %s\n", fmtBIU( netclass_default->GetViaDiameter() ).c_str() ); - fprintf( m_fp, "ViaDrill %s\n", fmtBIU( netclass_default->GetViaDrill() ).c_str() ); - fprintf( m_fp, "ViaMinSize %s\n", fmtBIU( bds.m_ViasMinSize ).c_str() ); - fprintf( m_fp, "ViaMinDrill %s\n", fmtBIU( bds.m_ViasMinDrill ).c_str() ); - - // Save custom vias diameters list (the first is not saved here: this is - // the netclass value - for( unsigned ii = 1; ii < aBoard->GetDesignSettings().m_ViasDimensionsList.size(); ii++ ) - fprintf( m_fp, "ViaSizeList %s %s\n", - fmtBIU( aBoard->GetDesignSettings().m_ViasDimensionsList[ii].m_Diameter ).c_str(), - fmtBIU( aBoard->GetDesignSettings().m_ViasDimensionsList[ii].m_Drill ).c_str() ); - - // for old versions compatibility: - fprintf( m_fp, "MicroViaSize %s\n", fmtBIU( netclass_default->GetuViaDiameter() ).c_str() ); - fprintf( m_fp, "MicroViaDrill %s\n", fmtBIU( netclass_default->GetuViaDrill() ).c_str() ); - fprintf( m_fp, "MicroViasAllowed %s\n", fmtBIU( bds.m_MicroViasAllowed ).c_str() ); - fprintf( m_fp, "MicroViaMinSize %s\n", fmtBIU( bds.m_MicroViasMinSize ).c_str() ); - fprintf( m_fp, "MicroViaMinDrill %s\n", fmtBIU( bds.m_MicroViasMinDrill ).c_str() ); - - fprintf( m_fp, "TextPcbWidth %s\n", fmtBIU( bds.m_PcbTextWidth ).c_str() ); - fprintf( m_fp, "TextPcbSize %s\n", fmtBIUSize( bds.m_PcbTextSize ).c_str() ); - - fprintf( m_fp, "EdgeModWidth %s\n", fmtBIU( bds.m_ModuleSegmentWidth ).c_str() ); - fprintf( m_fp, "TextModSize %s\n", fmtBIUSize( bds.m_ModuleTextSize ).c_str() ); - fprintf( m_fp, "TextModWidth %s\n", fmtBIU( bds.m_ModuleTextWidth ).c_str() ); - - fprintf( m_fp, "PadSize %s\n", fmtBIUSize( bds.m_Pad_Master.GetSize() ).c_str() ); - fprintf( m_fp, "PadDrill %s\n", fmtBIU( bds.m_Pad_Master.GetDrillSize().x ).c_str() ); - - fprintf( m_fp, "Pad2MaskClearance %s\n", fmtBIU( bds.m_SolderMaskMargin ).c_str() ); - fprintf( m_fp, "SolderMaskMinWidth %s\n", fmtBIU( bds.m_SolderMaskMinWidth ).c_str() ); - - if( bds.m_SolderPasteMargin != 0 ) - fprintf( m_fp, "Pad2PasteClearance %s\n", fmtBIU( bds.m_SolderPasteMargin ).c_str() ); - - if( bds.m_SolderPasteMarginRatio != 0 ) - fprintf( m_fp, "Pad2PasteClearanceRatio %g\n", bds.m_SolderPasteMarginRatio ); - - fprintf( m_fp, "GridOrigin %s\n", fmtBIUPoint( aBoard->GetGridOrigin() ).c_str() ); - fprintf( m_fp, "AuxiliaryAxisOrg %s\n", fmtBIUPoint( aBoard->GetAuxOrigin() ).c_str() ); - - fprintf( m_fp, "VisibleElements %X\n", bds.GetVisibleElements() ); - - { - STRING_FORMATTER sf; - - aBoard->GetPlotOptions().Format( &sf, 0 ); - - wxString record = FROM_UTF8( sf.GetString().c_str() ); - - record.Replace( wxT("\n"), wxT(""), true ); - record.Replace( wxT(" "), wxT(" "), true); - - fprintf( m_fp, "PcbPlotParams %s\n", TO_UTF8( record ) ); - } - - fprintf( m_fp, "$EndSETUP\n\n" ); -} - - -void LEGACY_PLUGIN::saveBOARD_ITEMS( const BOARD* aBoard ) const -{ - // save the nets - for( NETINFO_MAPPING::iterator net = m_mapping->begin(), netEnd = m_mapping->end(); - net != netEnd; ++net ) - { - saveNETINFO_ITEM( *net ); - } - - // Saved nets do not include netclass names, so save netclasses after nets. - saveNETCLASSES( &aBoard->GetDesignSettings().m_NetClasses ); - - // save the modules - for( MODULE* m = aBoard->m_Modules; m; m = (MODULE*) m->Next() ) - saveMODULE( m ); - - // save the graphics owned by the board (not owned by a module) - for( BOARD_ITEM* gr = aBoard->m_Drawings; gr; gr = gr->Next() ) - { - switch( gr->Type() ) - { - case PCB_TEXT_T: - savePCB_TEXT( (TEXTE_PCB*) gr ); - break; - case PCB_LINE_T: - savePCB_LINE( (DRAWSEGMENT*) gr ); - break; - case PCB_TARGET_T: - savePCB_TARGET( (PCB_TARGET*) gr ); - break; - case PCB_DIMENSION_T: - saveDIMENSION( (DIMENSION*) gr ); - break; - default: - THROW_IO_ERROR( wxString::Format( UNKNOWN_GRAPHIC_FORMAT, gr->Type() ) ); - } - } - - // do not save MARKER_PCBs, they can be regenerated easily - - // save the tracks & vias - fprintf( m_fp, "$TRACK\n" ); - for( TRACK* track = aBoard->m_Track; track; track = track->Next() ) - saveTRACK( track ); - fprintf( m_fp, "$EndTRACK\n" ); - - // save the old obsolete zones which were done by segments (tracks) - fprintf( m_fp, "$ZONE\n" ); - for( SEGZONE* zone = aBoard->m_Zone; zone; zone = zone->Next() ) - saveTRACK( zone ); - fprintf( m_fp, "$EndZONE\n" ); - - // save the polygon (which are the newer technology) zones - for( int i=0; i < aBoard->GetAreaCount(); ++i ) - saveZONE_CONTAINER( aBoard->GetArea( i ) ); - - fprintf( m_fp, "$EndBOARD\n" ); - - CHECK_WRITE_ERROR(); -} - - -void LEGACY_PLUGIN::saveNETINFO_ITEM( const NETINFO_ITEM* aNet ) const -{ - fprintf( m_fp, "$EQUIPOT\n" ); - fprintf( m_fp, "Na %d %s\n", m_mapping->Translate( aNet->GetNet() ), - EscapedUTF8( aNet->GetNetname() ).c_str() ); - fprintf( m_fp, "St %s\n", "~" ); - fprintf( m_fp, "$EndEQUIPOT\n" ); - - CHECK_WRITE_ERROR(); -} - - -void LEGACY_PLUGIN::saveNETCLASSES( const NETCLASSES* aNetClasses ) const -{ - // save the default first. - saveNETCLASS( aNetClasses->GetDefault() ); - - // the rest will be alphabetical in the *.brd file. - for( NETCLASSES::const_iterator it = aNetClasses->begin(); it != aNetClasses->end(); ++it ) - { - NETCLASSPTR netclass = it->second; - saveNETCLASS( netclass ); - } - - CHECK_WRITE_ERROR(); -} - - -void LEGACY_PLUGIN::saveNETCLASS( const NETCLASSPTR nc ) const -{ - fprintf( m_fp, "$NCLASS\n" ); - fprintf( m_fp, "Name %s\n", EscapedUTF8( nc->GetName() ).c_str() ); - fprintf( m_fp, "Desc %s\n", EscapedUTF8( nc->GetDescription() ).c_str() ); - - fprintf( m_fp, "Clearance %s\n", fmtBIU( nc->GetClearance() ).c_str() ); - fprintf( m_fp, "TrackWidth %s\n", fmtBIU( nc->GetTrackWidth() ).c_str() ); - - fprintf( m_fp, "ViaDia %s\n", fmtBIU( nc->GetViaDiameter() ).c_str() ); - fprintf( m_fp, "ViaDrill %s\n", fmtBIU( nc->GetViaDrill() ).c_str() ); - - fprintf( m_fp, "uViaDia %s\n", fmtBIU( nc->GetuViaDiameter() ).c_str() ); - fprintf( m_fp, "uViaDrill %s\n", fmtBIU( nc->GetuViaDrill() ).c_str() ); - - for( NETCLASS::const_iterator it = nc->begin(); it!=nc->end(); ++it ) - fprintf( m_fp, "AddNet %s\n", EscapedUTF8( *it ).c_str() ); - - fprintf( m_fp, "$EndNCLASS\n" ); - - CHECK_WRITE_ERROR(); -} - - -void LEGACY_PLUGIN::saveMODULE_TEXT( const TEXTE_MODULE* me ) const -{ - MODULE* parent = (MODULE*) me->GetParent(); - double orient = me->GetOrientation(); - - // Due to the Pcbnew history, m_Orient is saved in screen value - // but it is handled as relative to its parent footprint - if( parent ) - orient += parent->GetOrientation(); - - wxString txt = me->GetText(); - - fprintf( m_fp, "T%d %s %s %s %s %c %c %d %c %s", - me->GetType(), - fmtBIUPoint( me->GetPos0() ).c_str(), // m_Pos0.x, m_Pos0.y, - - // legacy has goofed reversed order: ( y, x ) - fmtBIUPair( me->GetSize().y, me->GetSize().x ).c_str(), - - fmtDEG( orient ).c_str(), - fmtBIU( me->GetThickness() ).c_str(), // m_Thickness, - me->IsMirrored() ? 'M' : 'N', - me->IsVisible() ? 'V' : 'I', - me->GetLayer(), - me->IsItalic() ? 'I' : 'N', - EscapedUTF8( txt ).c_str() - ); - - if( me->GetHorizJustify() != GR_TEXT_HJUSTIFY_CENTER || - me->GetVertJustify() != GR_TEXT_VJUSTIFY_CENTER ) - { - fprintf( m_fp, " %s %s\n", - ShowHorizJustify( me->GetHorizJustify() ), - ShowVertJustify( me->GetVertJustify() ) - ); - } - else - fprintf( m_fp, "\n" ); - - CHECK_WRITE_ERROR(); -} - - -void LEGACY_PLUGIN::saveMODULE_EDGE( const EDGE_MODULE* me ) const -{ - switch( me->GetShape() ) - { - case S_SEGMENT: - fprintf( m_fp, "DS %s %s %s %d\n", - fmtBIUPoint( me->m_Start0 ).c_str(), - fmtBIUPoint( me->m_End0 ).c_str(), - fmtBIU( me->GetWidth() ).c_str(), - me->GetLayer() ); - break; - - case S_CIRCLE: - fprintf( m_fp, "DC %s %s %s %d\n", - fmtBIUPoint( me->m_Start0 ).c_str(), - fmtBIUPoint( me->m_End0 ).c_str(), - fmtBIU( me->GetWidth() ).c_str(), - me->GetLayer() ); - break; - - case S_ARC: - fprintf( m_fp, "DA %s %s %s %s %d\n", - fmtBIUPoint( me->m_Start0 ).c_str(), - fmtBIUPoint( me->m_End0 ).c_str(), - fmtDEG( me->GetAngle() ).c_str(), - fmtBIU( me->GetWidth() ).c_str(), - me->GetLayer() ); - break; - - case S_POLYGON: - { - const std::vector& polyPoints = me->GetPolyPoints(); - - fprintf( m_fp, "DP %s %s %d %s %d\n", - fmtBIUPoint( me->m_Start0 ).c_str(), - fmtBIUPoint( me->m_End0 ).c_str(), - (int) polyPoints.size(), - fmtBIU( me->GetWidth() ).c_str(), - me->GetLayer() ); - - for( unsigned i = 0; iGetShape() ) ); - } - - CHECK_WRITE_ERROR(); -} - - -void LEGACY_PLUGIN::savePAD( const D_PAD* me ) const -{ - fprintf( m_fp, "$PAD\n" ); - - int cshape; - - switch( me->GetShape() ) - { - case PAD_SHAPE_CIRCLE: cshape = 'C'; break; - case PAD_SHAPE_RECT: cshape = 'R'; break; - case PAD_SHAPE_OVAL: cshape = 'O'; break; - case PAD_SHAPE_TRAPEZOID: cshape = 'T'; break; - - default: - THROW_IO_ERROR( wxString::Format( UNKNOWN_PAD_FORMAT, me->GetShape() ) ); - } - -#if BOARD_FORMAT_VERSION == 1 // saving mode is a compile time option - - wxString wpadname = me->GetPadName(); // universal character set padname - std::string spadname; - - for( unsigned i = 0; wpadname.size(); ++i ) - { - // truncate from universal character down to 8 bit foreign jibber - // jabber byte. This basically duplicates what was done in the old - // BOARD_FORMAT_VERSION 1 code. Any characters that were in the 8 bit - // character space were OK. - spadname += (char) wpadname[i]; - } - - fprintf( m_fp, "Sh \"%s\" %c %s %s %s\n", - spadname.c_str(), // probably ASCII, but possibly jibber jabber -#else - - fprintf( m_fp, "Sh %s %c %s %s %s\n", - // legacy VERSION 2 simply uses UTF8, wrapped in quotes, - // and 99.99 % of the time there is no difference between 1 & 2, - // since ASCII is a subset of UTF8. But if they were not using - // ASCII pad names, then there is a difference in the file. - EscapedUTF8( me->GetPadName() ).c_str(), -#endif - cshape, - fmtBIUSize( me->GetSize() ).c_str(), - fmtBIUSize( me->GetDelta() ).c_str(), - fmtDEG( me->GetOrientation() ).c_str() ); - - fprintf( m_fp, "Dr %s %s", - fmtBIU( me->GetDrillSize().x ).c_str(), - fmtBIUPoint( me->GetOffset() ).c_str() ); - - if( me->GetDrillShape() == PAD_DRILL_SHAPE_OBLONG ) - { - fprintf( m_fp, " %c %s", 'O', fmtBIUSize( me->GetDrillSize() ).c_str() ); - } - - fprintf( m_fp, "\n" ); - - const char* texttype; - - switch( me->GetAttribute() ) - { - case PAD_ATTRIB_STANDARD: texttype = "STD"; break; - case PAD_ATTRIB_SMD: texttype = "SMD"; break; - case PAD_ATTRIB_CONN: texttype = "CONN"; break; - case PAD_ATTRIB_HOLE_NOT_PLATED: texttype = "HOLE"; break; - - default: - THROW_IO_ERROR( wxString::Format( UNKNOWN_PAD_ATTRIBUTE, me->GetAttribute() ) ); - } - - fprintf( m_fp, "At %s N %08X\n", texttype, me->GetLayerSet() ); - - fprintf( m_fp, "Ne %d %s\n", m_mapping->Translate( me->GetNetCode() ), - EscapedUTF8( me->GetNetname() ).c_str() ); - - fprintf( m_fp, "Po %s\n", fmtBIUPoint( me->GetPos0() ).c_str() ); - - if( me->GetPadToDieLength() != 0 ) - fprintf( m_fp, "Le %s\n", fmtBIU( me->GetPadToDieLength() ).c_str() ); - - if( me->GetLocalSolderMaskMargin() != 0 ) - fprintf( m_fp, ".SolderMask %s\n", fmtBIU( me->GetLocalSolderMaskMargin() ).c_str() ); - - if( me->GetLocalSolderPasteMargin() != 0 ) - fprintf( m_fp, ".SolderPaste %s\n", fmtBIU( me->GetLocalSolderPasteMargin() ).c_str() ); - - double ratio = me->GetLocalSolderPasteMarginRatio(); - if( ratio != 0.0 ) - fprintf( m_fp, ".SolderPasteRatio %g\n", ratio ); - - if( me->GetLocalClearance() != 0 ) - fprintf( m_fp, ".LocalClearance %s\n", fmtBIU( me->GetLocalClearance( ) ).c_str() ); - - if( me->GetZoneConnection() != PAD_ZONE_CONN_INHERITED ) - fprintf( m_fp, ".ZoneConnection %d\n", me->GetZoneConnection() ); - - if( me->GetThermalWidth() != 0 ) - fprintf( m_fp, ".ThermalWidth %s\n", fmtBIU( me->GetThermalWidth() ).c_str() ); - - if( me->GetThermalGap() != 0 ) - fprintf( m_fp, ".ThermalGap %s\n", fmtBIU( me->GetThermalGap() ).c_str() ); - - fprintf( m_fp, "$EndPAD\n" ); - - CHECK_WRITE_ERROR(); -} - - -void LEGACY_PLUGIN::saveMODULE( const MODULE* me ) const -{ - char statusTxt[3]; - double orient = me->GetOrientation(); - - // Do not save full FPID. Only the footprint name. The legacy file format should - // never support FPIDs. - fprintf( m_fp, "$MODULE %s\n", me->GetFPID().GetFootprintName().c_str() ); - - statusTxt[0] = me->IsLocked() ? 'F' : '~'; - statusTxt[1] = me->IsPlaced() ? 'P' : '~'; - statusTxt[2] = '\0'; - - fprintf( m_fp, "Po %s %s %d %08lX %08lX %s\n", - fmtBIUPoint( me->GetPosition() ).c_str(), // m_Pos.x, m_Pos.y, - fmtDEG( orient ).c_str(), - me->GetLayer(), - me->GetLastEditTime(), - me->GetTimeStamp(), - statusTxt ); - - fprintf( m_fp, "Li %s\n", me->GetFPID().GetFootprintName().c_str() ); - - if( !me->GetDescription().IsEmpty() ) - { - fprintf( m_fp, "Cd %s\n", TO_UTF8( me->GetDescription() ) ); - } - - if( !me->GetKeywords().IsEmpty() ) - { - fprintf( m_fp, "Kw %s\n", TO_UTF8( me->GetKeywords() ) ); - } - - fprintf( m_fp, "Sc %lX\n", me->GetTimeStamp() ); - fprintf( m_fp, "AR %s\n", TO_UTF8( me->GetPath() ) ); - fprintf( m_fp, "Op %X %X 0\n", me->GetPlacementCost90(), me->GetPlacementCost180() ); - - if( me->GetLocalSolderMaskMargin() != 0 ) - fprintf( m_fp, ".SolderMask %s\n", fmtBIU( me->GetLocalSolderMaskMargin() ).c_str() ); - - if( me->GetLocalSolderPasteMargin() != 0 ) - fprintf( m_fp, ".SolderPaste %s\n", fmtBIU( me->GetLocalSolderPasteMargin() ).c_str() ); - - double ratio = me->GetLocalSolderPasteMarginRatio(); - if( ratio != 0.0 ) - fprintf( m_fp, ".SolderPasteRatio %g\n", ratio ); - - if( me->GetLocalClearance() != 0 ) - fprintf( m_fp, ".LocalClearance %s\n", fmtBIU( me->GetLocalClearance( ) ).c_str() ); - - if( me->GetZoneConnection() != PAD_ZONE_CONN_INHERITED ) - fprintf( m_fp, ".ZoneConnection %d\n", me->GetZoneConnection() ); - - if( me->GetThermalWidth() != 0 ) - fprintf( m_fp, ".ThermalWidth %s\n", fmtBIU( me->GetThermalWidth() ).c_str() ); - - if( me->GetThermalGap() != 0 ) - fprintf( m_fp, ".ThermalGap %s\n", fmtBIU( me->GetThermalGap() ).c_str() ); - - // attributes - if( me->GetAttributes() != MOD_DEFAULT ) - { - fprintf( m_fp, "At" ); - - if( me->GetAttributes() & MOD_CMS ) - fprintf( m_fp, " SMD" ); - - if( me->GetAttributes() & MOD_VIRTUAL ) - fprintf( m_fp, " VIRTUAL" ); - - fprintf( m_fp, "\n" ); - } - - saveMODULE_TEXT( &me->Reference() ); - - saveMODULE_TEXT( &me->Value() ); - - // save drawing elements - for( BOARD_ITEM* gr = me->GraphicalItems(); gr; gr = gr->Next() ) - { - switch( gr->Type() ) - { - case PCB_MODULE_TEXT_T: - saveMODULE_TEXT( static_cast( gr )); - break; - case PCB_MODULE_EDGE_T: - saveMODULE_EDGE( static_cast( gr )); - break; - default: - THROW_IO_ERROR( wxString::Format( UNKNOWN_GRAPHIC_FORMAT, gr->Type() ) ); - } - } - - for( D_PAD* pad = me->Pads(); pad; pad = pad->Next() ) - savePAD( pad ); - - SaveModule3D( me ); - - fprintf( m_fp, "$EndMODULE %s\n", me->GetFPID().GetFootprintName().c_str() ); - - CHECK_WRITE_ERROR(); -} - - -void LEGACY_PLUGIN::savePCB_TARGET( const PCB_TARGET* me ) const -{ - fprintf( m_fp, "$PCB_TARGET\n" ); - - fprintf( m_fp, "Po %X %d %s %s %s %lX\n", - me->GetShape(), - me->GetLayer(), - fmtBIUPoint( me->GetPosition() ).c_str(), - fmtBIU( me->GetSize() ).c_str(), - fmtBIU( me->GetWidth() ).c_str(), - me->GetTimeStamp() - ); - - fprintf( m_fp, "$EndPCB_TARGET\n" ); - - CHECK_WRITE_ERROR(); -} - - -void LEGACY_PLUGIN::savePCB_LINE( const DRAWSEGMENT* me ) const -{ - fprintf( m_fp, "$DRAWSEGMENT\n" ); - - fprintf( m_fp, "Po %d %s %s %s\n", - me->GetShape(), - fmtBIUPoint( me->GetStart() ).c_str(), - fmtBIUPoint( me->GetEnd() ).c_str(), - fmtBIU( me->GetWidth() ).c_str() - ); - - if( me->GetType() != S_CURVE ) - { - fprintf( m_fp, "De %d %d %s %lX %X\n", - me->GetLayer(), - me->GetType(), - fmtDEG( me->GetAngle() ).c_str(), - me->GetTimeStamp(), - me->GetStatus() - ); - } - else - { - fprintf( m_fp, "De %d %d %s %lX %X %s %s\n", - me->GetLayer(), - me->GetType(), - fmtDEG( me->GetAngle() ).c_str(), - me->GetTimeStamp(), - me->GetStatus(), - fmtBIUPoint( me->GetBezControl1() ).c_str(), - fmtBIUPoint( me->GetBezControl2() ).c_str() - ); - } - - fprintf( m_fp, "$EndDRAWSEGMENT\n" ); -} - - -void LEGACY_PLUGIN::saveTRACK( const TRACK* me ) const -{ - int type = 0; - VIATYPE_T viatype = VIA_NOT_DEFINED; - int drill = UNDEFINED_DRILL_DIAMETER; - - if( me->Type() == PCB_VIA_T ) - { - const VIA *via = static_cast(me); - type = 1; - viatype = via->GetViaType(); - drill = via->GetDrill(); - } - - fprintf(m_fp, "Po %d %s %s %s %s\n", - viatype, - fmtBIUPoint( me->GetStart() ).c_str(), - fmtBIUPoint( me->GetEnd() ).c_str(), - fmtBIU( me->GetWidth() ).c_str(), - drill == UNDEFINED_DRILL_DIAMETER ? - "-1" : fmtBIU( drill ).c_str() ); - - fprintf(m_fp, "De %d %d %d %lX %X\n", - me->GetLayer(), type, m_mapping->Translate( me->GetNetCode() ), - me->GetTimeStamp(), me->GetStatus() ); -} - - -void LEGACY_PLUGIN::saveZONE_CONTAINER( const ZONE_CONTAINER* me ) const -{ - fprintf( m_fp, "$CZONE_OUTLINE\n" ); - - // Save the outline main info - // For keepout zones, net code and net name are irrelevant, so we store a dummy value - // just for ZONE_CONTAINER compatibility - fprintf( m_fp, "ZInfo %lX %d %s\n", - me->GetTimeStamp(), - me->GetIsKeepout() ? 0 : m_mapping->Translate( me->GetNetCode() ), - EscapedUTF8( me->GetIsKeepout() ? wxT("") : me->GetNetname() ).c_str() ); - - // Save the outline layer info - fprintf( m_fp, "ZLayer %d\n", me->GetLayer() ); - - // Save the outline aux info - int outline_hatch; - - switch( me->GetHatchStyle() ) - { - default: - case CPolyLine::NO_HATCH: outline_hatch = 'N'; break; - case CPolyLine::DIAGONAL_EDGE: outline_hatch = 'E'; break; - case CPolyLine::DIAGONAL_FULL: outline_hatch = 'F'; break; - } - - fprintf( m_fp, "ZAux %d %c\n", me->GetNumCorners(), outline_hatch ); - - if( me->GetPriority() > 0 ) - fprintf( m_fp, "ZPriority %d\n", me->GetPriority() ); - - // Save pad option and clearance - char padoption; - - switch( me->GetPadConnection() ) - { - default: - case PAD_ZONE_CONN_FULL: padoption = 'I'; break; - case PAD_ZONE_CONN_THERMAL: padoption = 'T'; break; - case PAD_ZONE_CONN_THT_THERMAL: padoption = 'H'; break; // H is for 'hole' since it reliefs holes only - case PAD_ZONE_CONN_NONE: padoption = 'X'; break; - } - - fprintf( m_fp, "ZClearance %s %c\n", - fmtBIU( me->GetZoneClearance() ).c_str(), - padoption ); - - fprintf( m_fp, "ZMinThickness %s\n", fmtBIU( me->GetMinThickness() ).c_str() ); - - fprintf( m_fp, "ZOptions %d %d %c %s %s\n", - me->GetFillMode(), - me->GetArcSegmentCount(), - me->IsFilled() ? 'S' : 'F', - fmtBIU( me->GetThermalReliefGap() ).c_str(), - fmtBIU( me->GetThermalReliefCopperBridge() ).c_str() ); - - if( me->GetIsKeepout() ) - { - fprintf( m_fp, "ZKeepout tracks %c vias %c copperpour %c\n", - me->GetDoNotAllowTracks() ? 'N' : 'Y', - me->GetDoNotAllowVias() ? 'N' : 'Y', - me->GetDoNotAllowCopperPour() ? 'N' : 'Y' ); - } - - fprintf( m_fp, "ZSmoothing %d %s\n", - me->GetCornerSmoothingType(), - fmtBIU( me->GetCornerRadius() ).c_str() ); - - // Save the corner list - const CPOLYGONS_LIST& cv = me->Outline()->m_CornersList; - - for( unsigned it = 0; it < cv.GetCornersCount(); ++it ) - { - fprintf( m_fp, "ZCorner %s %d\n", - fmtBIUPair( cv.GetX( it ), cv.GetY( it ) ).c_str(), - cv.IsEndContour( it ) ); - } - - // Save the PolysList - const CPOLYGONS_LIST& fv = me->GetFilledPolysList(); - if( fv.GetCornersCount() ) - { - fprintf( m_fp, "$POLYSCORNERS\n" ); - - for( unsigned it = 0; it < fv.GetCornersCount(); ++it ) - { - fprintf( m_fp, "%s %d %d\n", - fmtBIUPair( fv.GetX( it ), fv.GetY( it ) ).c_str(), - fv.IsEndContour( it ), - fv.GetUtility( it ) ); - } - - fprintf( m_fp, "$endPOLYSCORNERS\n" ); - } - - typedef std::vector< SEGMENT > SEGMENTS; - - // Save the filling segments list - const SEGMENTS& segs = me->FillSegments(); - - if( segs.size() ) - { - fprintf( m_fp, "$FILLSEGMENTS\n" ); - - for( SEGMENTS::const_iterator it = segs.begin(); it != segs.end(); ++it ) - { - fprintf( m_fp, "%s %s\n", - fmtBIUPoint( it->m_Start ).c_str(), - fmtBIUPoint( it->m_End ).c_str() ); - } - - fprintf( m_fp, "$endFILLSEGMENTS\n" ); - } - - fprintf( m_fp, "$endCZONE_OUTLINE\n" ); - - CHECK_WRITE_ERROR(); -} - - -void LEGACY_PLUGIN::saveDIMENSION( const DIMENSION* me ) const -{ - // note: COTATION was the previous name of DIMENSION - // this old keyword is used here for compatibility - fprintf( m_fp, "$COTATION\n" ); - - fprintf( m_fp, "Ge %d %d %lX\n", me->GetShape(), me->GetLayer(), me->GetTimeStamp() ); - - fprintf( m_fp, "Va %s\n", fmtBIU( me->GetValue() ).c_str() ); - - if( !me->GetText().IsEmpty() ) - fprintf( m_fp, "Te %s\n", EscapedUTF8( me->GetText() ).c_str() ); - else - fprintf( m_fp, "Te \"?\"\n" ); - - fprintf( m_fp, "Po %s %s %s %s %d\n", - fmtBIUPoint( me->Text().GetTextPosition() ).c_str(), - fmtBIUSize( me->Text().GetSize() ).c_str(), - fmtBIU( me->Text().GetThickness() ).c_str(), - fmtDEG( me->Text().GetOrientation() ).c_str(), - me->Text().IsMirrored() ? 0 : 1 // strange but true - ); - - fprintf( m_fp, "Sb %d %s %s %s\n", S_SEGMENT, - fmtBIUPair( me->m_crossBarO.x, me->m_crossBarO.y ).c_str(), - fmtBIUPair( me->m_crossBarF.x, me->m_crossBarF.y ).c_str(), - fmtBIU( me->GetWidth() ).c_str() ); - - fprintf( m_fp, "Sd %d %s %s %s\n", S_SEGMENT, - fmtBIUPair( me->m_featureLineDO.x, me->m_featureLineDO.y ).c_str(), - fmtBIUPair( me->m_featureLineDF.x, me->m_featureLineDF.y ).c_str(), - fmtBIU( me->GetWidth() ).c_str() ); - - fprintf( m_fp, "Sg %d %s %s %s\n", S_SEGMENT, - fmtBIUPair( me->m_featureLineGO.x, me->m_featureLineGO.y ).c_str(), - fmtBIUPair( me->m_featureLineGF.x, me->m_featureLineGF.y ).c_str(), - fmtBIU( me->GetWidth() ).c_str() ); - - fprintf( m_fp, "S1 %d %s %s %s\n", S_SEGMENT, - fmtBIUPair( me->m_crossBarF.x, me->m_crossBarF.y ).c_str(), - fmtBIUPair( me->m_arrowD1F.x, me->m_arrowD1F.y ).c_str(), - fmtBIU( me->GetWidth() ).c_str() ); - - fprintf( m_fp, "S2 %d %s %s %s\n", S_SEGMENT, - fmtBIUPair( me->m_crossBarF.x, me->m_crossBarF.y ).c_str(), - fmtBIUPair( me->m_arrowD2F.x, me->m_arrowD2F.y ).c_str(), - fmtBIU( me->GetWidth() ).c_str() ); - - fprintf( m_fp, "S3 %d %s %s %s\n", S_SEGMENT, - fmtBIUPair( me->m_crossBarO.x, me->m_crossBarO.y ).c_str(), - fmtBIUPair( me->m_arrowG1F.x, me->m_arrowG1F.y ).c_str(), - fmtBIU( me->GetWidth() ).c_str() ); - - fprintf( m_fp, "S4 %d %s %s %s\n", S_SEGMENT, - fmtBIUPair( me->m_crossBarO.x, me->m_crossBarO.y ).c_str(), - fmtBIUPair( me->m_arrowG2F.x, me->m_arrowG2F.y ).c_str(), - fmtBIU( me->GetWidth() ).c_str() ); - - fprintf( m_fp, "$endCOTATION\n" ); - - CHECK_WRITE_ERROR(); -} - - -void LEGACY_PLUGIN::savePCB_TEXT( const TEXTE_PCB* me ) const -{ - if( me->GetText().IsEmpty() ) - return; - - fprintf( m_fp, "$TEXTPCB\n" ); - - wxArrayString* list = wxStringSplit( me->GetText(), '\n' ); - - for( unsigned ii = 0; ii < list->Count(); ii++ ) - { - wxString txt = list->Item( ii ); - - if ( ii == 0 ) - fprintf( m_fp, "Te %s\n", EscapedUTF8( txt ).c_str() ); - else - fprintf( m_fp, "nl %s\n", EscapedUTF8( txt ).c_str() ); - } - - delete list; - - fprintf( m_fp, "Po %s %s %s %s\n", - fmtBIUPoint( me->GetTextPosition() ).c_str(), - fmtBIUSize( me->GetSize() ).c_str(), - fmtBIU( me->GetThickness() ).c_str(), - fmtDEG( me->GetOrientation() ).c_str() ); - - fprintf( m_fp, "De %d %d %lX %s", - me->GetLayer(), - !me->IsMirrored(), - me->GetTimeStamp(), - me->IsItalic() ? "Italic" : "Normal" ); - - if( me->GetHorizJustify() != GR_TEXT_HJUSTIFY_CENTER || - me->GetVertJustify() != GR_TEXT_VJUSTIFY_CENTER ) - { - fprintf( m_fp, " %s %s\n", - ShowHorizJustify( me->GetHorizJustify() ), - ShowVertJustify( me->GetVertJustify() ) - ); - } - else - fprintf( m_fp, "\n" ); - - fprintf( m_fp, "$EndTEXTPCB\n" ); -} - -#endif // NO LEGACY_PLUGIN::Save() - - //------------------------------------------------- /* @@ -4482,96 +3397,6 @@ void LP_CACHE::LoadModules( LINE_READER* aReader ) } -#if 0 -void LP_CACHE::Save() -{ - if( !m_writable ) - { - THROW_IO_ERROR( wxString::Format( - _( "Legacy library file '%s' is read only" ), m_lib_path.GetData() ) ); - } - - wxString tempFileName; - - // a block {} scope to fire wxFFile wxf()'s destructor - { - // CreateTempFileName works better with an absolute path - wxFileName abs_lib_name( m_lib_path ); - - abs_lib_name.MakeAbsolute(); - tempFileName = wxFileName::CreateTempFileName( abs_lib_name.GetFullPath() ); - - //wxLogDebug( wxT( "tempFileName:'%s' m_lib_path:'%s'\n" ), TO_UTF8( tempFileName ), TO_UTF8( m_lib_path ) ); - - FILE* fp = wxFopen( tempFileName, wxT( "w" ) ); - if( !fp ) - { - THROW_IO_ERROR( wxString::Format( - _( "Unable to open or create legacy library file '%s'" ), - m_lib_path.GetData() ) ); - } - - // wxf now owns fp, will close on exception or exit from - // this block {} scope - wxFFile wxf( fp ); - - SaveHeader( fp ); - SaveIndex( fp ); - SaveModules( fp ); - SaveEndOfFile( fp ); - } - - // fp is now closed here, and that seems proper before trying to rename - // the temporary file to m_lib_path. - - wxRemove( m_lib_path ); // it is not an error if this does not exist - - // Even on linux you can see an _intermittent_ error when calling wxRename(), - // and it is fully inexplicable. See if this dodges the error. - wxMilliSleep( 250L ); - - if( !wxRenameFile( tempFileName, m_lib_path ) ) - { - THROW_IO_ERROR( wxString::Format( - _( "Unable to rename tempfile '%s' to library file '%s'" ), - tempFileName.GetData(), - m_lib_path.GetData() ) ); - } -} - - -void LP_CACHE::SaveHeader( FILE* aFile ) -{ - fprintf( aFile, "%s %s\n", FOOTPRINT_LIBRARY_HEADER, TO_UTF8( DateAndTime() ) ); - fprintf( aFile, "# encoding utf-8\n" ); - fprintf( aFile, "Units mm\n" ); -} - - -void LP_CACHE::SaveIndex( FILE* aFile ) -{ - fprintf( aFile, "$INDEX\n" ); - - for( MODULE_CITER it = m_modules.begin(); it != m_modules.end(); ++it ) - { - fprintf( aFile, "%s\n", it->first.c_str() ); - } - - fprintf( aFile, "$EndINDEX\n" ); -} - - -void LP_CACHE::SaveModules( FILE* aFile ) -{ - m_owner->SetFilePtr( aFile ); - - for( MODULE_CITER it = m_modules.begin(); it != m_modules.end(); ++it ) - { - m_owner->saveMODULE( it->second ); - } -} -#endif - void LEGACY_PLUGIN::cacheLib( const wxString& aLibraryPath ) { if( !m_cache || m_cache->m_lib_path != aLibraryPath || @@ -4635,104 +3460,6 @@ MODULE* LEGACY_PLUGIN::FootprintLoad( const wxString& aLibraryPath, } -#if 0 // omit FootprintSave() - -void LEGACY_PLUGIN::FootprintSave( const wxString& aLibraryPath, - const MODULE* aFootprint, const PROPERTIES* aProperties ) -{ - LOCALE_IO toggle; // toggles on, then off, the C locale. - - init( aProperties ); - - cacheLib( aLibraryPath ); - - if( !m_cache->m_writable ) - { - THROW_IO_ERROR( wxString::Format( _( "Library '%s' is read only" ), aLibraryPath.GetData() ) ); - } - - std::string footprintName = aFootprint->GetFPID().GetFootprintName(); - - MODULE_MAP& mods = m_cache->m_modules; - - // quietly overwrite any by same name. - MODULE_CITER it = mods.find( footprintName ); - if( it != mods.end() ) - { - mods.erase( footprintName ); - } - - // I need my own copy for the cache - MODULE* my_module = new MODULE( *aFootprint ); - - // and it's time stamp must be 0, it should have no parent, orientation should - // be zero, and it should be on the front layer. - - my_module->SetTimeStamp( 0 ); - my_module->SetParent( 0 ); - - my_module->SetOrientation( 0 ); - - if( my_module->GetLayer() != F_Cu ) - my_module->Flip( my_module->GetPosition() ); - - mods.insert( footprintName, my_module ); - - m_cache->Save(); -} - - -void LEGACY_PLUGIN::FootprintDelete( const wxString& aLibraryPath, - const wxString& aFootprintName, const PROPERTIES* aProperties ) -{ - LOCALE_IO toggle; // toggles on, then off, the C locale. - - init( NULL ); - - cacheLib( aLibraryPath ); - - if( !m_cache->m_writable ) - { - THROW_IO_ERROR( wxString::Format( _( "Library '%s' is read only" ), aLibraryPath.GetData() ) ); - } - - std::string footprintName = TO_UTF8( aFootprintName ); - - size_t erasedCount = m_cache->m_modules.erase( footprintName ); - - if( erasedCount != 1 ) - { - THROW_IO_ERROR( wxString::Format( - _( "library '%s' has no footprint '%s' to delete" ), - aLibraryPath.GetData(), aFootprintName.GetData() ) ); - } - - m_cache->Save(); -} - - -void LEGACY_PLUGIN::FootprintLibCreate( const wxString& aLibraryPath, const PROPERTIES* aProperties ) -{ - if( wxFileExists( aLibraryPath ) ) - { - THROW_IO_ERROR( wxString::Format( - _( "library '%s' already exists, will not create a new" ), - aLibraryPath.GetData() ) ); - } - - LOCALE_IO toggle; - - init( NULL ); - - delete m_cache; - m_cache = new LP_CACHE( this, aLibraryPath ); - m_cache->Save(); - m_cache->Load(); // update m_writable and m_mod_time -} - -#endif // omit FootprintSave() - - bool LEGACY_PLUGIN::FootprintLibDelete( const wxString& aLibraryPath, const PROPERTIES* aProperties ) { wxFileName fn = aLibraryPath; diff --git a/pcbnew/legacy_plugin.h b/pcbnew/legacy_plugin.h index 18e05199ce..2216438f9a 100644 --- a/pcbnew/legacy_plugin.h +++ b/pcbnew/legacy_plugin.h @@ -79,16 +79,6 @@ public: BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe, const PROPERTIES* aProperties = NULL ); - /* we let go of "save" support when the number of CU layers were expanded from 16 to 32. - void Save( const wxString& aFileName, BOARD* aBoard, const PROPERTIES* aProperties = NULL ); - - void FootprintSave( const wxString& aLibraryPath, const MODULE* aFootprint, - const PROPERTIES* aProperties = NULL ); - void FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName, const PROPERTIES* aProperties = NULL ); - - void FootprintLibCreate( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL ); - */ - wxArrayString FootprintEnumerate( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL); MODULE* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName, @@ -125,7 +115,6 @@ protected: LINE_READER* m_reader; ///< no ownership here. FILE* m_fp; ///< no ownership here. - wxString m_filename; ///< for saves only, name is in m_reader for loads wxString m_field; ///< reused to stuff MODULE fields. int m_loading_format_version; ///< which BOARD_FORMAT_VERSION am I Load()ing? @@ -222,76 +211,6 @@ protected: //-------------------------------------------------- - - //---------------------------------------------------------- -#if 0 - /** - * Function writeError - * returns an error message wxString containing the filename being - * currently written. - */ - wxString writeError() const; - - /// encapsulate the BIU formatting tricks in one place. - int biuSprintf( char* buf, BIU aValue ) const; - - /** - * Function fmtBIU - * converts a BIU to engineering units by scaling and formatting to ASCII. - * This function is the complement of biuParse(). One has to know what the - * other is doing. - */ - std::string fmtBIU( BIU aValue ) const; - - std::string fmtBIUPair( BIU first, BIU second ) const; - - std::string fmtBIUPoint( const wxPoint& aPoint ) const - { - return fmtBIUPair( aPoint.x, aPoint.y ); - } - - std::string fmtBIUSize( const wxSize& aSize ) const - { - return fmtBIUPair( aSize.x, aSize.y ); - } - - /** - * Function fmtDEG - * formats an angle in a way particular to a board file format. This function - * is the opposite or complement of degParse(). One has to know what the - * other is doing. - */ - std::string fmtDEG( double aAngle ) const; - - void saveGENERAL( const BOARD* aBoard ) const; - void saveSHEET( const BOARD* aBoard ) const; - void saveSETUP( const BOARD* aBoard ) const; - void saveBOARD_ITEMS( const BOARD* aBoard ) const; - - void saveMODULE_TEXT( const TEXTE_MODULE* aText ) const; - void saveMODULE_EDGE( const EDGE_MODULE* aGraphic ) const; - void savePAD( const D_PAD* aPad ) const; - - void saveNETINFO_ITEM( const NETINFO_ITEM* aNet ) const; - void saveNETCLASSES( const NETCLASSES* aNetClasses ) const; - void saveNETCLASS( const boost::shared_ptr aNetclass ) const; - - void savePCB_TEXT( const TEXTE_PCB* aText ) const; - void savePCB_TARGET( const PCB_TARGET* aTarget ) const; - void savePCB_LINE( const DRAWSEGMENT* aStroke ) const; - void saveDIMENSION( const DIMENSION* aDimension ) const; - void saveTRACK( const TRACK* aTrack ) const; - void saveBOARD( const BOARD* aBoard ) const; - - /** - * Function saveZONE_CONTAINER - * saves the new polygon zones. - */ - void saveZONE_CONTAINER( const ZONE_CONTAINER* aZone ) const; - - //--------------------------------------------------------- -#endif - /// we only cache one footprint library for now, this determines which one. void cacheLib( const wxString& aLibraryPath ); }; diff --git a/pcbnew/onrightclick.cpp b/pcbnew/onrightclick.cpp index 603355e22c..68c83a369f 100644 --- a/pcbnew/onrightclick.cpp +++ b/pcbnew/onrightclick.cpp @@ -308,11 +308,6 @@ bool PCB_EDIT_FRAME::OnRightClick( const wxPoint& aMousePos, wxMenu* aPopMenu ) AddMenuItem( aPopMenu, ID_POPUP_PCB_DUPLICATE_ITEM, msg, KiBitmap( duplicate_target_xpm ) ); - msg = AddHotkeyName( _("Create Target Array" ), g_Board_Editor_Hokeys_Descr, - HK_CREATE_ARRAY ); - AddMenuItem( aPopMenu, ID_POPUP_PCB_CREATE_ARRAY, - msg, KiBitmap( array_target_xpm ) ); - msg = AddHotkeyName( _( "Edit Target" ), g_Board_Editor_Hokeys_Descr, HK_EDIT_ITEM ); AddMenuItem( aPopMenu, ID_POPUP_PCB_EDIT_MIRE, msg, KiBitmap( edit_xpm ) ); diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 8e7c0b4f0e..7e47fbdb91 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -702,6 +702,8 @@ int EDIT_TOOL::MoveExact( const TOOL_EVENT& aEvent ) int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent ) { + // Note: original items are no more modified. + bool increment = aEvent.IsAction( &COMMON_ACTIONS::duplicateIncrement ); // first, check if we have a selection, or try to get one @@ -803,8 +805,6 @@ int EDIT_TOOL::CreateArray( const TOOL_EVENT& aEvent ) if( !hoverSelection( selection ) ) return 0; - bool originalItemsModified = false; - // we have a selection to work on now, so start the tool process PCB_BASE_FRAME* editFrame = getEditFrame(); @@ -815,11 +815,6 @@ int EDIT_TOOL::CreateArray( const TOOL_EVENT& aEvent ) // Module editors do their undo point upfront for the whole module editFrame->SaveCopyInUndoList( editFrame->GetBoard()->m_Modules, UR_MODEDIT ); } - else - { - // We may also change the original item - editFrame->SaveCopyInUndoList( selection.items, UR_CHANGED ); - } DIALOG_CREATE_ARRAY::ARRAY_OPTIONS* array_opts = NULL; @@ -840,106 +835,66 @@ int EDIT_TOOL::CreateArray( const TOOL_EVENT& aEvent ) if( !item ) continue; - wxString cachedString; - - if( item->Type() == PCB_MODULE_T ) - { - cachedString = static_cast( item )->GetReferencePrefix(); - } - else if( EDA_TEXT* text = dynamic_cast( item ) ) - { - // Copy the text (not just take a reference - cachedString = text->GetText(); - } - // iterate across the array, laying out the item at the // correct position const unsigned nPoints = array_opts->GetArraySize(); - for( unsigned ptN = 0; ptN < nPoints; ++ptN ) + // The first item in list is the original item. We do not modify it + for( unsigned ptN = 1; ptN < nPoints; ++ptN ) { BOARD_ITEM* newItem = NULL; - if( ptN == 0 ) - newItem = item; + // Some items cannot be duplicated + // i.e. the ref and value fields of a footprint or zones + // therefore newItem can be null + + #define INCREMENT_REF false + #define INCREMENT_PADNUMBER true + + if( m_editModules ) + newItem = editFrame->GetBoard()->m_Modules->DuplicateAndAddItem( + item, INCREMENT_PADNUMBER ); else { - // if renumbering, no need to increment - const bool increment = !array_opts->ShouldRenumberItems(); - - // Some items cannot be duplicated - // i.e. the ref and value fields of a footprint or zones - // therefore newItem can be null - - if( m_editModules ) - newItem = editFrame->GetBoard()->m_Modules->DuplicateAndAddItem( item, increment ); - else - { #if 0 - // @TODO: see if we allow zone duplication here - // Duplicate zones is especially tricky (overlaping zones must be merged) - // so zones are not duplicated - if( item->Type() == PCB_ZONE_AREA_T ) - newItem = NULL; - else + // @TODO: see if we allow zone duplication here + // Duplicate zones is especially tricky (overlaping zones must be merged) + // so zones are not duplicated + if( item->Type() == PCB_ZONE_AREA_T ) + newItem = NULL; + else #endif - newItem = editFrame->GetBoard()->DuplicateAndAddItem( item, increment ); - } - - if( newItem ) - { - array_opts->TransformItem( ptN, newItem, rotPoint ); - - m_toolMgr->RunAction( COMMON_ACTIONS::unselectItem, true, newItem ); - - newItemList.PushItem( newItem ); - - if( newItem->Type() == PCB_MODULE_T) - { - static_cast( newItem )->RunOnChildren( boost::bind( &KIGFX::VIEW::Add, - getView(), _1 ) ); - } - - editFrame->GetGalCanvas()->GetView()->Add( newItem ); - getModel()->GetRatsnest()->Update( newItem ); - } + newItem = editFrame->GetBoard()->DuplicateAndAddItem( + item, INCREMENT_REF ); + // @TODO: we should merge zones. This is a bit tricky, because + // the undo command needs saving old area, if it is merged. } - // set the number if needed: + if( newItem ) + { + array_opts->TransformItem( ptN, newItem, rotPoint ); + + m_toolMgr->RunAction( COMMON_ACTIONS::unselectItem, true, newItem ); + + newItemList.PushItem( newItem ); + + if( newItem->Type() == PCB_MODULE_T) + { + static_cast( newItem )->RunOnChildren( boost::bind( &KIGFX::VIEW::Add, + getView(), _1 ) ); + } + + editFrame->GetGalCanvas()->GetView()->Add( newItem ); + getModel()->GetRatsnest()->Update( newItem ); + } + + // Only renumbering pads has meaning: if( newItem && array_opts->ShouldRenumberItems() ) { - switch( newItem->Type() ) - { - case PCB_PAD_T: + if( newItem->Type() == PCB_PAD_T ) { const wxString padName = array_opts->GetItemNumber( ptN ); static_cast( newItem )->SetPadName( padName ); - - originalItemsModified = true; - break; - } - case PCB_MODULE_T: - { - const wxString moduleName = array_opts->GetItemNumber( ptN ); - MODULE* module = static_cast( newItem ); - module->SetReference( cachedString + moduleName ); - - originalItemsModified = true; - break; - } - case PCB_MODULE_TEXT_T: - case PCB_TEXT_T: - { - EDA_TEXT* text = dynamic_cast( newItem ); - if( text ) - text->SetText( array_opts->InterpolateNumberIntoString( ptN, cachedString ) ); - - originalItemsModified = true; - break; - } - default: - // no renumbering of other items - break; } } } @@ -947,15 +902,7 @@ int EDIT_TOOL::CreateArray( const TOOL_EVENT& aEvent ) if( !m_editModules ) { - if( originalItemsModified ) - { - // Update the appearance of the original items - selection.group->ItemsViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); - } - // Add all items as a single undo point for PCB editors - // TODO: Can this be merged into the previous undo point (where - // we saved the original items) editFrame->SaveCopyInUndoList( newItemList, UR_NEW ); } }