diff --git a/3d-viewer/dialogs/3d_cache_dialogs.cpp b/3d-viewer/dialogs/3d_cache_dialogs.cpp index f41e7893b2..676726141f 100644 --- a/3d-viewer/dialogs/3d_cache_dialogs.cpp +++ b/3d-viewer/dialogs/3d_cache_dialogs.cpp @@ -45,7 +45,7 @@ bool S3D::Select3DModel( wxWindow* aParent, S3D_CACHE* aCache, wxString& prevMod bool S3D::Configure3DPaths( wxWindow* aParent, FILENAME_RESOLVER* aResolver ) { - DIALOG_CONFIGURE_PATHS dlg( aParent, aResolver ); + DIALOG_CONFIGURE_PATHS dlg( aParent ); // Use QuasiModal so that HTML help window will work return( dlg.ShowQuasiModal() == wxID_OK ); diff --git a/common/dialogs/dialog_configure_paths.cpp b/common/dialogs/dialog_configure_paths.cpp index 99cf538365..464646133a 100644 --- a/common/dialogs/dialog_configure_paths.cpp +++ b/common/dialogs/dialog_configure_paths.cpp @@ -54,12 +54,11 @@ enum SEARCH_PATH_GRID_COLUMNS }; -DIALOG_CONFIGURE_PATHS::DIALOG_CONFIGURE_PATHS( wxWindow* aParent, FILENAME_RESOLVER* aResolver ) : +DIALOG_CONFIGURE_PATHS::DIALOG_CONFIGURE_PATHS( wxWindow* aParent ) : DIALOG_CONFIGURE_PATHS_BASE( aParent ), m_errorGrid( nullptr ), m_errorRow( -1 ), m_errorCol( -1 ), - m_resolver( aResolver ), m_gridWidth( 0 ), m_gridWidthsDirty( true ), m_helpBox( nullptr ), @@ -67,10 +66,6 @@ DIALOG_CONFIGURE_PATHS::DIALOG_CONFIGURE_PATHS( wxWindow* aParent, FILENAME_RESO { m_btnAddEnvVar->SetBitmap( KiBitmap( BITMAPS::small_plus ) ); m_btnDeleteEnvVar->SetBitmap( KiBitmap( BITMAPS::small_trash ) ); - m_btnAddSearchPath->SetBitmap( KiBitmap( BITMAPS::small_plus ) ); - m_btnDeleteSearchPath->SetBitmap( KiBitmap( BITMAPS::small_trash ) ); - m_btnMoveUp->SetBitmap( KiBitmap( BITMAPS::small_up ) ); - m_btnMoveDown->SetBitmap( KiBitmap( BITMAPS::small_down ) ); m_EnvVars->ClearRows(); m_EnvVars->AppendCols( 1 ); // for the isExternal flags @@ -81,39 +76,16 @@ DIALOG_CONFIGURE_PATHS::DIALOG_CONFIGURE_PATHS( wxWindow* aParent, FILENAME_RESO attr->SetEditor( new GRID_CELL_PATH_EDITOR( this, m_EnvVars, &m_curdir, wxEmptyString ) ); m_EnvVars->SetColAttr( TV_VALUE_COL, attr ); - attr = new wxGridCellAttr; - attr->SetEditor( new GRID_CELL_PATH_EDITOR( this, m_SearchPaths, &m_curdir, wxEmptyString ) ); - m_SearchPaths->SetColAttr( TV_VALUE_COL, attr ); - // Give a bit more room for combobox editors m_EnvVars->SetDefaultRowSize( m_EnvVars->GetDefaultRowSize() + 4 ); - m_SearchPaths->SetDefaultRowSize( m_SearchPaths->GetDefaultRowSize() + 4 ); m_EnvVars->PushEventHandler( new GRID_TRICKS( m_EnvVars, [this]( wxCommandEvent& aEvent ) { OnAddEnvVar( aEvent ); } ) ); - m_SearchPaths->PushEventHandler( new GRID_TRICKS( m_SearchPaths, - [this]( wxCommandEvent& aEvent ) - { - OnAddSearchPath( aEvent ); - } ) ); m_EnvVars->SetSelectionMode( wxGrid::wxGridSelectionModes::wxGridSelectRows ); - m_SearchPaths->SetSelectionMode( wxGrid::wxGridSelectionModes::wxGridSelectRows ); - - if( m_resolver ) - { - m_SearchPaths->ClearRows(); - m_SearchPaths->UseNativeColHeader( true ); - - // prohibit these characters in the alias names: []{}()%~<>"='`;:.,&?/\|$ - m_aliasValidator.SetStyle( wxFILTER_EXCLUDE_CHAR_LIST ); - m_aliasValidator.SetCharExcludes( wxT( "{}[]()%~<>\"='`;:.,&?/\\|$" ) ); - } - else - m_sb3DSearchPaths->Show( false ); SetInitialFocus( m_EnvVars ); SetupStandardButtons(); @@ -122,9 +94,6 @@ DIALOG_CONFIGURE_PATHS::DIALOG_CONFIGURE_PATHS( wxWindow* aParent, FILENAME_RESO m_EnvVars->Connect( wxEVT_GRID_CELL_CHANGING, wxGridEventHandler( DIALOG_CONFIGURE_PATHS::OnGridCellChanging ), nullptr, this ); - m_SearchPaths->Connect( wxEVT_GRID_CELL_CHANGING, - wxGridEventHandler( DIALOG_CONFIGURE_PATHS::OnGridCellChanging ), - nullptr, this ); GetSizer()->SetSizeHints( this ); Centre(); @@ -134,15 +103,11 @@ DIALOG_CONFIGURE_PATHS::DIALOG_CONFIGURE_PATHS( wxWindow* aParent, FILENAME_RESO DIALOG_CONFIGURE_PATHS::~DIALOG_CONFIGURE_PATHS() { // Delete the GRID_TRICKS. - m_SearchPaths->PopEventHandler( true ); m_EnvVars->PopEventHandler( true ); m_EnvVars->Disconnect( wxEVT_GRID_CELL_CHANGING, wxGridEventHandler( DIALOG_CONFIGURE_PATHS::OnGridCellChanging ), nullptr, this ); - m_SearchPaths->Disconnect( wxEVT_GRID_CELL_CHANGING, - wxGridEventHandler( DIALOG_CONFIGURE_PATHS::OnGridCellChanging ), - nullptr, this ); } @@ -151,26 +116,6 @@ bool DIALOG_CONFIGURE_PATHS::TransferDataToWindow() if( !wxDialog::TransferDataToWindow() ) return false; - // Do 3D search paths first so they get first crack at setting m_curdir - - if( m_resolver ) - { - const std::list* paths = m_resolver->GetPaths(); - - for( auto it = paths->begin(); it != paths->end(); ++it ) - { - if ( !( *it ).m_Alias.StartsWith( "${" ) && !( *it ).m_Alias.StartsWith( "$(" ) ) - { - AppendSearchPath( it->m_Alias, it->m_Pathvar, it->m_Description ); - - if( m_curdir.IsEmpty() ) - m_curdir = it->m_Pathexp; - } - } - } - - // Environment variables - const ENV_VAR_MAP& envVars = Pgm().GetLocalEnvVariables(); for( auto it = envVars.begin(); it != envVars.end(); ++it ) @@ -213,29 +158,9 @@ void DIALOG_CONFIGURE_PATHS::AppendEnvVar( const wxString& aName, const wxString } -void DIALOG_CONFIGURE_PATHS::AppendSearchPath( const wxString& aName, const wxString& aPath, - const wxString& aDescription ) -{ - int i = m_SearchPaths->GetNumberRows(); - - m_SearchPaths->AppendRows( 1 ); - - m_SearchPaths->SetCellValue( i, SP_ALIAS_COL, aName ); - - wxGridCellAttr* nameCellAttr = m_SearchPaths->GetOrCreateCellAttr( i, SP_ALIAS_COL ); - wxGridCellTextEditor* nameTextEditor = new GRID_CELL_TEXT_EDITOR(); - nameTextEditor->SetValidator( m_aliasValidator ); - nameCellAttr->SetEditor( nameTextEditor ); - nameCellAttr->DecRef(); - - m_SearchPaths->SetCellValue( i, SP_PATH_COL, aPath ); - m_SearchPaths->SetCellValue( i, SP_DESC_COL, aDescription ); -} - - bool DIALOG_CONFIGURE_PATHS::TransferDataFromWindow() { - if( !m_EnvVars->CommitPendingChanges() || !m_SearchPaths->CommitPendingChanges() ) + if( !m_EnvVars->CommitPendingChanges() ) return false; if( !wxDialog::TransferDataFromWindow() ) @@ -301,43 +226,6 @@ bool DIALOG_CONFIGURE_PATHS::TransferDataFromWindow() Pgm().SetLocalEnvVariables(); - // 3D search paths - - if( m_resolver ) - { - std::vector alist; - SEARCH_PATH alias; - - for( int row = 0; row < m_SearchPaths->GetNumberRows(); ++row ) - { - alias.m_Alias = m_SearchPaths->GetCellValue( row, SP_ALIAS_COL ); - alias.m_Pathvar = m_SearchPaths->GetCellValue( row, SP_PATH_COL ); - alias.m_Description = m_SearchPaths->GetCellValue( row, SP_DESC_COL ); - - if( alias.m_Alias.IsEmpty() ) - { - m_errorGrid = m_SearchPaths; - m_errorRow = row; - m_errorCol = SP_ALIAS_COL; - m_errorMsg = _( "3D search path alias cannot be empty." ); - return false; - } - else if( alias.m_Pathvar.IsEmpty() ) - { - m_errorGrid = m_SearchPaths; - m_errorRow = row; - m_errorCol = SP_PATH_COL; - m_errorMsg = _( "3D search path cannot be empty." ); - return false; - } - - alist.push_back( alias ); - } - - if( !m_resolver->UpdatePathList( alist ) ) - return false; - } - return true; } @@ -426,21 +314,6 @@ void DIALOG_CONFIGURE_PATHS::OnAddEnvVar( wxCommandEvent& event ) } -void DIALOG_CONFIGURE_PATHS::OnAddSearchPath( wxCommandEvent& event ) -{ - if( !m_SearchPaths->CommitPendingChanges() ) - return; - - AppendSearchPath( wxEmptyString, wxEmptyString, wxEmptyString); - - m_SearchPaths->MakeCellVisible( m_SearchPaths->GetNumberRows() - 1, SP_ALIAS_COL ); - m_SearchPaths->SetGridCursor( m_SearchPaths->GetNumberRows() - 1, SP_ALIAS_COL ); - - m_SearchPaths->EnableCellEditControl( true ); - m_SearchPaths->ShowCellEditControl(); -} - - void DIALOG_CONFIGURE_PATHS::OnRemoveEnvVar( wxCommandEvent& event ) { int curRow = m_EnvVars->GetGridCursorRow(); @@ -463,115 +336,6 @@ void DIALOG_CONFIGURE_PATHS::OnRemoveEnvVar( wxCommandEvent& event ) } -void DIALOG_CONFIGURE_PATHS::OnDeleteSearchPath( wxCommandEvent& event ) -{ - wxArrayInt selectedRows = m_SearchPaths->GetSelectedRows(); - - if( selectedRows.empty() && m_SearchPaths->GetGridCursorRow() >= 0 ) - selectedRows.push_back( m_SearchPaths->GetGridCursorRow() ); - - if( selectedRows.empty() ) - return; - - m_SearchPaths->CommitPendingChanges( true /* silent mode; we don't care if it's valid */ ); - - // Reverse sort so deleting a row doesn't change the indexes of the other rows. - selectedRows.Sort( []( int* first, int* second ) { return *second - *first; } ); - - for( int row : selectedRows ) - { - m_SearchPaths->DeleteRows( row, 1 ); - - // if there are still rows in grid, make previous row visible - if( m_SearchPaths->GetNumberRows() ) - { - m_SearchPaths->MakeCellVisible( std::max( 0, row-1 ), - m_SearchPaths->GetGridCursorCol() ); - m_SearchPaths->SetGridCursor( std::max( 0, row-1 ), - m_SearchPaths->GetGridCursorCol() ); - } - } -} - - -void DIALOG_CONFIGURE_PATHS::OnSearchPathMoveUp( wxCommandEvent& event ) -{ - if( !m_SearchPaths->CommitPendingChanges() ) - return; - - int curRow = m_SearchPaths->GetGridCursorRow(); - int prevRow = curRow - 1; - - if( curRow > 0 ) - { - for( int i = 0; i < m_SearchPaths->GetNumberCols(); ++i ) - { - wxString tmp = m_SearchPaths->GetCellValue( curRow, i ); - m_SearchPaths->SetCellValue( curRow, i, m_SearchPaths->GetCellValue( prevRow, i ) ); - m_SearchPaths->SetCellValue( prevRow, i, tmp ); - } - - m_SearchPaths->SetGridCursor( prevRow, m_SearchPaths->GetGridCursorCol() ); - } - else - { - wxBell(); - } -} - - -void DIALOG_CONFIGURE_PATHS::OnSearchPathMoveDown( wxCommandEvent& event ) -{ - if( !m_SearchPaths->CommitPendingChanges() ) - return; - - int curRow = m_SearchPaths->GetGridCursorRow(); - int nextRow = curRow + 1; - - if( curRow < m_SearchPaths->GetNumberRows() - 1 ) - { - for( int i = 0; i < m_SearchPaths->GetNumberCols(); ++i ) - { - wxString tmp = m_SearchPaths->GetCellValue( curRow, i ); - m_SearchPaths->SetCellValue( curRow, i, m_SearchPaths->GetCellValue( nextRow, i ) ); - m_SearchPaths->SetCellValue( nextRow, i, tmp ); - } - - m_SearchPaths->SetGridCursor( nextRow, m_SearchPaths->GetGridCursorCol() ); - } - else - { - wxBell(); - } -} - - -void DIALOG_CONFIGURE_PATHS::OnGridCellRightClick( wxGridEvent& aEvent ) -{ - wxASSERT((int) TV_VALUE_COL == (int) SP_PATH_COL ); - - if( aEvent.GetCol() == TV_VALUE_COL ) - { - wxMenu menu; - - AddMenuItem( &menu, 1, _( "File Browser..." ), KiBitmap( BITMAPS::small_folder ) ); - - if( GetPopupMenuSelectionFromUser( menu ) == 1 ) - { - wxDirDialog dlg( nullptr, _( "Select Path" ), m_curdir, - wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST ); - - if( dlg.ShowModal() == wxID_OK ) - { - wxGrid* grid = dynamic_cast( aEvent.GetEventObject() ); - grid->SetCellValue( aEvent.GetRow(), TV_VALUE_COL, dlg.GetPath() ); - m_curdir = dlg.GetPath(); - } - } - } -} - - void DIALOG_CONFIGURE_PATHS::OnUpdateUI( wxUpdateUIEvent& event ) { if( m_gridWidthsDirty ) @@ -583,19 +347,6 @@ void DIALOG_CONFIGURE_PATHS::OnUpdateUI( wxUpdateUIEvent& event ) m_EnvVars->SetColSize( TV_VALUE_COL, width - m_EnvVars->GetColSize( TV_NAME_COL ) ); - width = m_SearchPaths->GetClientRect().GetWidth(); - - m_SearchPaths->AutoSizeColumn( SP_ALIAS_COL ); - m_SearchPaths->SetColSize( SP_ALIAS_COL, - std::max( m_SearchPaths->GetColSize( SP_ALIAS_COL ), 120 ) ); - - m_SearchPaths->AutoSizeColumn( SP_PATH_COL ); - m_SearchPaths->SetColSize( SP_PATH_COL, - std::max( m_SearchPaths->GetColSize( SP_PATH_COL ), 300 ) ); - - m_SearchPaths->SetColSize( SP_DESC_COL, width - - ( m_SearchPaths->GetColSize( SP_ALIAS_COL ) + - m_SearchPaths->GetColSize( SP_PATH_COL ) ) ); m_gridWidth = m_EnvVars->GetSize().GetX(); m_gridWidthsDirty = false; } diff --git a/common/dialogs/dialog_configure_paths_base.cpp b/common/dialogs/dialog_configure_paths_base.cpp index 89e52fc3ed..cad4e2017b 100644 --- a/common/dialogs/dialog_configure_paths_base.cpp +++ b/common/dialogs/dialog_configure_paths_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version 3.9.0 Jul 27 2020) +// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b3) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -35,9 +35,9 @@ DIALOG_CONFIGURE_PATHS_BASE::DIALOG_CONFIGURE_PATHS_BASE( wxWindow* parent, wxWi m_EnvVars->SetColSize( 1, 454 ); m_EnvVars->EnableDragColMove( false ); m_EnvVars->EnableDragColSize( true ); - m_EnvVars->SetColLabelSize( 22 ); m_EnvVars->SetColLabelValue( 0, _("Name") ); m_EnvVars->SetColLabelValue( 1, _("Path") ); + m_EnvVars->SetColLabelSize( 22 ); m_EnvVars->SetColLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER ); // Rows @@ -71,67 +71,6 @@ DIALOG_CONFIGURE_PATHS_BASE::DIALOG_CONFIGURE_PATHS_BASE( wxWindow* parent, wxWi bSizerMain->Add( sbEnvVars, 1, wxEXPAND|wxALL, 5 ); - m_sb3DSearchPaths = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("3D Search Paths") ), wxVERTICAL ); - - m_SearchPaths = new WX_GRID( m_sb3DSearchPaths->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); - - // Grid - m_SearchPaths->CreateGrid( 1, 3 ); - m_SearchPaths->EnableEditing( true ); - m_SearchPaths->EnableGridLines( true ); - m_SearchPaths->EnableDragGridSize( false ); - m_SearchPaths->SetMargins( 0, 0 ); - - // Columns - m_SearchPaths->SetColSize( 0, 150 ); - m_SearchPaths->SetColSize( 1, 300 ); - m_SearchPaths->SetColSize( 2, 154 ); - m_SearchPaths->EnableDragColMove( false ); - m_SearchPaths->EnableDragColSize( true ); - m_SearchPaths->SetColLabelSize( 22 ); - m_SearchPaths->SetColLabelValue( 0, _("Alias") ); - m_SearchPaths->SetColLabelValue( 1, _("Path") ); - m_SearchPaths->SetColLabelValue( 2, _("Description") ); - m_SearchPaths->SetColLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER ); - - // Rows - m_SearchPaths->AutoSizeRows(); - m_SearchPaths->EnableDragRowSize( false ); - m_SearchPaths->SetRowLabelSize( 0 ); - m_SearchPaths->SetRowLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER ); - - // Label Appearance - - // Cell Defaults - m_SearchPaths->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP ); - m_SearchPaths->SetMinSize( wxSize( 604,150 ) ); - - m_sb3DSearchPaths->Add( m_SearchPaths, 1, wxALL|wxEXPAND, 5 ); - - wxBoxSizer* bSizerSearchPathBtns; - bSizerSearchPathBtns = new wxBoxSizer( wxHORIZONTAL ); - - m_btnAddSearchPath = new wxBitmapButton( m_sb3DSearchPaths->GetStaticBox(), wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW|0 ); - bSizerSearchPathBtns->Add( m_btnAddSearchPath, 0, wxBOTTOM|wxLEFT|wxRIGHT, 5 ); - - m_btnMoveUp = new wxBitmapButton( m_sb3DSearchPaths->GetStaticBox(), wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW|0 ); - bSizerSearchPathBtns->Add( m_btnMoveUp, 0, wxBOTTOM|wxRIGHT, 5 ); - - m_btnMoveDown = new wxBitmapButton( m_sb3DSearchPaths->GetStaticBox(), wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW|0 ); - bSizerSearchPathBtns->Add( m_btnMoveDown, 0, wxBOTTOM|wxRIGHT, 5 ); - - - bSizerSearchPathBtns->Add( 0, 0, 0, wxEXPAND|wxRIGHT|wxLEFT, 5 ); - - m_btnDeleteSearchPath = new wxBitmapButton( m_sb3DSearchPaths->GetStaticBox(), wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW|0 ); - bSizerSearchPathBtns->Add( m_btnDeleteSearchPath, 0, wxBOTTOM|wxRIGHT, 5 ); - - - m_sb3DSearchPaths->Add( bSizerSearchPathBtns, 0, wxEXPAND, 5 ); - - - bSizerMain->Add( m_sb3DSearchPaths, 1, wxEXPAND|wxTOP|wxRIGHT|wxLEFT, 5 ); - m_sdbSizer = new wxStdDialogButtonSizer(); m_sdbSizerOK = new wxButton( this, wxID_OK ); m_sdbSizer->AddButton( m_sdbSizerOK ); @@ -155,12 +94,6 @@ DIALOG_CONFIGURE_PATHS_BASE::DIALOG_CONFIGURE_PATHS_BASE( wxWindow* parent, wxWi m_EnvVars->Connect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_CONFIGURE_PATHS_BASE::OnGridSize ), NULL, this ); m_btnAddEnvVar->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_CONFIGURE_PATHS_BASE::OnAddEnvVar ), NULL, this ); m_btnDeleteEnvVar->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_CONFIGURE_PATHS_BASE::OnRemoveEnvVar ), NULL, this ); - m_SearchPaths->Connect( wxEVT_GRID_CELL_CHANGED, wxGridEventHandler( DIALOG_CONFIGURE_PATHS_BASE::OnGridCellChange ), NULL, this ); - m_SearchPaths->Connect( wxEVT_GRID_CELL_RIGHT_CLICK, wxGridEventHandler( DIALOG_CONFIGURE_PATHS_BASE::OnGridCellRightClick ), NULL, this ); - m_btnAddSearchPath->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_CONFIGURE_PATHS_BASE::OnAddSearchPath ), NULL, this ); - m_btnMoveUp->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_CONFIGURE_PATHS_BASE::OnSearchPathMoveUp ), NULL, this ); - m_btnMoveDown->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_CONFIGURE_PATHS_BASE::OnSearchPathMoveDown ), NULL, this ); - m_btnDeleteSearchPath->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_CONFIGURE_PATHS_BASE::OnDeleteSearchPath ), NULL, this ); m_sdbSizerHelp->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_CONFIGURE_PATHS_BASE::OnHelp ), NULL, this ); } @@ -171,12 +104,6 @@ DIALOG_CONFIGURE_PATHS_BASE::~DIALOG_CONFIGURE_PATHS_BASE() m_EnvVars->Disconnect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_CONFIGURE_PATHS_BASE::OnGridSize ), NULL, this ); m_btnAddEnvVar->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_CONFIGURE_PATHS_BASE::OnAddEnvVar ), NULL, this ); m_btnDeleteEnvVar->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_CONFIGURE_PATHS_BASE::OnRemoveEnvVar ), NULL, this ); - m_SearchPaths->Disconnect( wxEVT_GRID_CELL_CHANGED, wxGridEventHandler( DIALOG_CONFIGURE_PATHS_BASE::OnGridCellChange ), NULL, this ); - m_SearchPaths->Disconnect( wxEVT_GRID_CELL_RIGHT_CLICK, wxGridEventHandler( DIALOG_CONFIGURE_PATHS_BASE::OnGridCellRightClick ), NULL, this ); - m_btnAddSearchPath->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_CONFIGURE_PATHS_BASE::OnAddSearchPath ), NULL, this ); - m_btnMoveUp->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_CONFIGURE_PATHS_BASE::OnSearchPathMoveUp ), NULL, this ); - m_btnMoveDown->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_CONFIGURE_PATHS_BASE::OnSearchPathMoveDown ), NULL, this ); - m_btnDeleteSearchPath->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_CONFIGURE_PATHS_BASE::OnDeleteSearchPath ), NULL, this ); m_sdbSizerHelp->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_CONFIGURE_PATHS_BASE::OnHelp ), NULL, this ); } diff --git a/common/dialogs/dialog_configure_paths_base.fbp b/common/dialogs/dialog_configure_paths_base.fbp index cb3b3c4885..9fa11c52b2 100644 --- a/common/dialogs/dialog_configure_paths_base.fbp +++ b/common/dialogs/dialog_configure_paths_base.fbp @@ -1,6 +1,6 @@ - + C++ @@ -14,6 +14,7 @@ dialog_configure_paths_base 1000 none + 1 DIALOG_CONFIGURE_PATHS_BASE @@ -25,6 +26,7 @@ 1 1 UI + 0 0 0 @@ -50,6 +52,7 @@ DIALOG_SHIM; dialog_shim.h Configure Paths + 0 @@ -182,6 +185,7 @@ + 0 @@ -265,6 +269,7 @@ + 0 @@ -329,423 +334,6 @@ - - 5 - wxEXPAND|wxTOP|wxRIGHT|wxLEFT - 1 - - wxID_ANY - 3D Search Paths - - m_sb3DSearchPaths - wxVERTICAL - 1 - protected - - 5 - wxALL|wxEXPAND - 1 - - 1 - 1 - 1 - 1 - - - - - 0 - 1 - - - - 1 - - - wxALIGN_LEFT - - wxALIGN_TOP - 0 - 1 - wxALIGN_CENTER - 22 - "Alias" "Path" "Description" - wxALIGN_CENTER - 3 - 150,300,154 - - 1 - 0 - Dock - 0 - Left - 0 - 1 - 0 - 0 - 1 - 1 - - 1 - - - 1 - 0 - 0 - wxID_ANY - - - - 0 - 0 - - 0 - - - 0 - 604,150 - 1 - m_SearchPaths - 1 - - - protected - 1 - - Resizable - wxALIGN_CENTER - 0 - - wxALIGN_CENTER - - 1 - 1 - - WX_GRID; widgets/wx_grid.h; forward_declare - 0 - - - - - OnGridCellChange - OnGridCellRightClick - - - - 5 - wxEXPAND - 0 - - - bSizerSearchPathBtns - wxHORIZONTAL - none - - 5 - wxBOTTOM|wxLEFT|wxRIGHT - 0 - - 1 - 1 - 1 - 1 - - - - - - - - - 1 - 0 - 1 - - 1 - - 0 - 0 - - Dock - 0 - Left - 1 - - 1 - - - 0 - 0 - wxID_ANY - Add Path - - 0 - - 0 - - - 0 - -1,-1 - 1 - m_btnAddSearchPath - 1 - - - protected - 1 - - - - Resizable - 1 - - - ; forward_declare - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - - OnAddSearchPath - - - - 5 - wxBOTTOM|wxRIGHT - 0 - - 1 - 1 - 1 - 1 - - - - - - - - - 1 - 0 - 1 - - 1 - - 0 - 0 - - Dock - 0 - Left - 1 - - 1 - - - 0 - 0 - wxID_ANY - Move Up - - 0 - - 0 - - - 0 - -1,-1 - 1 - m_btnMoveUp - 1 - - - protected - 1 - - - - Resizable - 1 - - - ; forward_declare - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - - OnSearchPathMoveUp - - - - 5 - wxBOTTOM|wxRIGHT - 0 - - 1 - 1 - 1 - 1 - - - - - - - - - 1 - 0 - 1 - - 1 - - 0 - 0 - - Dock - 0 - Left - 1 - - 1 - - - 0 - 0 - wxID_ANY - Move Down - - 0 - - 0 - - - 0 - -1,-1 - 1 - m_btnMoveDown - 1 - - - protected - 1 - - - - Resizable - 1 - - - ; forward_declare - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - - OnSearchPathMoveDown - - - - 5 - wxEXPAND|wxRIGHT|wxLEFT - 0 - - 0 - protected - 0 - - - - 5 - wxBOTTOM|wxRIGHT - 0 - - 1 - 1 - 1 - 1 - - - - - - - - - 1 - 0 - 1 - - 1 - - 0 - 0 - - Dock - 0 - Left - 1 - - 1 - - - 0 - 0 - wxID_ANY - Delete Path - - 0 - - 0 - - - 0 - -1,-1 - 1 - m_btnDeleteSearchPath - 1 - - - protected - 1 - - - - Resizable - 1 - - - ; forward_declare - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - - OnDeleteSearchPath - - - - - - 5 wxALL|wxEXPAND diff --git a/common/dialogs/dialog_configure_paths_base.h b/common/dialogs/dialog_configure_paths_base.h index 0cf4d871f4..6ab5ae66ea 100644 --- a/common/dialogs/dialog_configure_paths_base.h +++ b/common/dialogs/dialog_configure_paths_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version 3.9.0 Jul 27 2020) +// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b3) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -42,12 +42,6 @@ class DIALOG_CONFIGURE_PATHS_BASE : public DIALOG_SHIM WX_GRID* m_EnvVars; wxBitmapButton* m_btnAddEnvVar; wxBitmapButton* m_btnDeleteEnvVar; - wxStaticBoxSizer* m_sb3DSearchPaths; - WX_GRID* m_SearchPaths; - wxBitmapButton* m_btnAddSearchPath; - wxBitmapButton* m_btnMoveUp; - wxBitmapButton* m_btnMoveDown; - wxBitmapButton* m_btnDeleteSearchPath; wxStdDialogButtonSizer* m_sdbSizer; wxButton* m_sdbSizerOK; wxButton* m_sdbSizerCancel; @@ -58,18 +52,13 @@ class DIALOG_CONFIGURE_PATHS_BASE : public DIALOG_SHIM virtual void OnGridSize( wxSizeEvent& event ) { event.Skip(); } virtual void OnAddEnvVar( wxCommandEvent& event ) { event.Skip(); } virtual void OnRemoveEnvVar( wxCommandEvent& event ) { event.Skip(); } - virtual void OnGridCellChange( wxGridEvent& event ) { event.Skip(); } - virtual void OnGridCellRightClick( wxGridEvent& event ) { event.Skip(); } - virtual void OnAddSearchPath( wxCommandEvent& event ) { event.Skip(); } - virtual void OnSearchPathMoveUp( wxCommandEvent& event ) { event.Skip(); } - virtual void OnSearchPathMoveDown( wxCommandEvent& event ) { event.Skip(); } - virtual void OnDeleteSearchPath( wxCommandEvent& event ) { event.Skip(); } virtual void OnHelp( wxCommandEvent& event ) { event.Skip(); } public: DIALOG_CONFIGURE_PATHS_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Configure Paths"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); + ~DIALOG_CONFIGURE_PATHS_BASE(); }; diff --git a/common/filename_resolver.cpp b/common/filename_resolver.cpp index be74caebfc..10ec4b6196 100644 --- a/common/filename_resolver.cpp +++ b/common/filename_resolver.cpp @@ -37,7 +37,6 @@ // configuration file version #define CFGFILE_VERSION 1 -#define RESOLVER_CONFIG wxT( "3Dresolver.cfg" ) // flag bits used to track different one-off messages to users #define ERRFLG_ALIAS (1) @@ -48,8 +47,6 @@ static std::mutex mutex_resolver; -static bool getHollerith( const std::string& aString, size_t& aIndex, wxString& aResult ); - FILENAME_RESOLVER::FILENAME_RESOLVER() : m_pgm( nullptr ), @@ -176,9 +173,13 @@ bool FILENAME_RESOLVER::createPathList() if( GetKicadPaths( epaths ) ) { - for( const wxString& curr_path : epaths ) + for( const wxString& currPath : epaths ) { - wxString pathVal = ExpandEnvVarSubstitutions( curr_path, m_project ); + wxString currPathVarFormat = currPath; + currPathVarFormat.Prepend( wxS( "${" ) ); + currPathVarFormat.Append( wxS( "}" ) ); + + wxString pathVal = ExpandEnvVarSubstitutions( currPathVarFormat, m_project ); if( pathVal.empty() ) { @@ -191,19 +192,21 @@ bool FILENAME_RESOLVER::createPathList() lpath.m_Pathexp = fndummy.GetFullPath(); } - lpath.m_Alias = curr_path; - lpath.m_Pathvar = curr_path; + lpath.m_Alias = currPath; + lpath.m_Pathvar = currPath; if( !lpath.m_Pathexp.empty() && psep == *lpath.m_Pathexp.rbegin() ) lpath.m_Pathexp.erase( --lpath.m_Pathexp.end() ); + // we add it first with the alias set to the non-variable format + m_paths.push_back( lpath ); + + // now add it with the "new variable format ${VAR}" + lpath.m_Alias = currPathVarFormat; m_paths.push_back( lpath ); } } - if( !m_configDir.empty() ) - readPathList(); - if( m_paths.empty() ) return false; @@ -233,7 +236,7 @@ bool FILENAME_RESOLVER::UpdatePathList( const std::vector< SEARCH_PATH >& aPathL for( const SEARCH_PATH& path : aPathList ) addPath( path ); - return WritePathList( m_configDir, RESOLVER_CONFIG, false ); + return true; } @@ -481,118 +484,6 @@ bool FILENAME_RESOLVER::addPath( const SEARCH_PATH& aPath ) } -bool FILENAME_RESOLVER::readPathList() -{ - if( m_configDir.empty() ) - { - std::ostringstream ostr; - ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; - wxString errmsg = "3D configuration directory is unknown"; - ostr << " * " << errmsg.ToUTF8(); - wxLogTrace( MASK_3D_RESOLVER, "%s\n", ostr.str().c_str() ); - return false; - } - - wxFileName cfgpath( m_configDir, RESOLVER_CONFIG ); - - // This should be the same as wxWidgets 3.0 wxPATH_NORM_ALL which is deprecated in 3.1. - // There are known issues with environment variable expansion so maybe we should be using - // our own ExpandEnvVarSubstitutions() here instead. - cfgpath.Normalize( FN_NORMALIZE_FLAGS | wxPATH_NORM_ENV_VARS ); - wxString cfgname = cfgpath.GetFullPath(); - - size_t nitems = m_paths.size(); - - std::ifstream cfgFile; - std::string cfgLine; - - if( !wxFileName::Exists( cfgname ) ) - { - std::ostringstream ostr; - ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; - wxString errmsg = "no 3D configuration file"; - ostr << " * " << errmsg.ToUTF8() << " '"; - ostr << cfgname.ToUTF8() << "'"; - wxLogTrace( MASK_3D_RESOLVER, "%s\n", ostr.str().c_str() ); - return false; - } - - cfgFile.open( cfgname.ToUTF8() ); - - if( !cfgFile.is_open() ) - { - std::ostringstream ostr; - ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; - wxString errmsg = "Could not open configuration file"; - ostr << " * " << errmsg.ToUTF8() << " '" << cfgname.ToUTF8() << "'"; - wxLogTrace( MASK_3D_RESOLVER, "%s\n", ostr.str().c_str() ); - return false; - } - - int lineno = 0; - SEARCH_PATH al; - size_t idx; - int vnum = 0; // version number - - while( cfgFile.good() ) - { - cfgLine.clear(); - std::getline( cfgFile, cfgLine ); - ++lineno; - - if( cfgLine.empty() ) - { - if( cfgFile.eof() ) - break; - - continue; - } - - if( 1 == lineno && cfgLine.compare( 0, 2, "#V" ) == 0 ) - { - // extract the version number and parse accordingly - if( cfgLine.size() > 2 ) - { - std::istringstream istr; - istr.str( cfgLine.substr( 2 ) ); - istr >> vnum; - } - - continue; - } - - idx = 0; - - if( !getHollerith( cfgLine, idx, al.m_Alias ) ) - continue; - - // Don't add KICAD6_3DMODEL_DIR, one of its legacy equivalents, or KIPRJMOD from a - // config file. They're system variables are are defined at runtime. - if( al.m_Alias == "${KICAD6_3DMODEL_DIR}" - || al.m_Alias == "${KIPRJMOD}" || al.m_Alias == "$(KIPRJMOD)" - || al.m_Alias == "${KISYS3DMOD}" || al.m_Alias == "$(KISYS3DMOD)" ) - { - continue; - } - - if( !getHollerith( cfgLine, idx, al.m_Pathvar ) ) - continue; - - if( !getHollerith( cfgLine, idx, al.m_Description ) ) - continue; - - addPath( al ); - } - - cfgFile.close(); - - if( vnum < CFGFILE_VERSION ) - WritePathList( m_configDir, RESOLVER_CONFIG, false ); - - return( m_paths.size() != nitems ); -} - - bool FILENAME_RESOLVER::WritePathList( const wxString& aDir, const wxString& aFilename, bool aResolvePaths ) { @@ -858,101 +749,6 @@ bool FILENAME_RESOLVER::SplitAlias( const wxString& aFileName, } -static bool getHollerith( const std::string& aString, size_t& aIndex, wxString& aResult ) -{ - aResult.clear(); - - if( aIndex >= aString.size() ) - { - std::ostringstream ostr; - ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; - wxString errmsg = "bad Hollerith string on line"; - ostr << " * " << errmsg.ToUTF8() << "\n'" << aString << "'"; - wxLogTrace( MASK_3D_RESOLVER, "%s\n", ostr.str().c_str() ); - - return false; - } - - size_t i2 = aString.find( '"', aIndex ); - - if( std::string::npos == i2 ) - { - std::ostringstream ostr; - ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; - wxString errmsg = "missing opening quote mark in config file"; - ostr << " * " << errmsg.ToUTF8() << "\n'" << aString << "'"; - wxLogTrace( MASK_3D_RESOLVER, "%s\n", ostr.str().c_str() ); - - return false; - } - - ++i2; - - if( i2 >= aString.size() ) - { - std::ostringstream ostr; - ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; - wxString errmsg = "invalid entry (unexpected end of line)"; - ostr << " * " << errmsg.ToUTF8() << "\n'" << aString << "'"; - wxLogTrace( MASK_3D_RESOLVER, "%s\n", ostr.str().c_str() ); - - return false; - } - - std::string tnum; - - while( aString[i2] >= '0' && aString[i2] <= '9' ) - tnum.append( 1, aString[i2++] ); - - if( tnum.empty() || aString[i2++] != ':' ) - { - std::ostringstream ostr; - ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; - wxString errmsg = "bad Hollerith string on line"; - ostr << " * " << errmsg.ToUTF8() << "\n'" << aString << "'"; - wxLogTrace( MASK_3D_RESOLVER, "%s\n", ostr.str().c_str() ); - - return false; - } - - std::istringstream istr; - istr.str( tnum ); - size_t nchars; - istr >> nchars; - - if( (i2 + nchars) >= aString.size() ) - { - std::ostringstream ostr; - ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; - wxString errmsg = "invalid entry (unexpected end of line)"; - ostr << " * " << errmsg.ToUTF8() << "\n'" << aString << "'"; - wxLogTrace( MASK_3D_RESOLVER, "%s\n", ostr.str().c_str() ); - - return false; - } - - if( nchars > 0 ) - { - aResult = wxString::FromUTF8( aString.substr( i2, nchars ).c_str() ); - i2 += nchars; - } - - if( i2 >= aString.size() || aString[i2] != '"' ) - { - std::ostringstream ostr; - ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; - wxString errmsg = "missing closing quote mark in config file"; - ostr << " * " << errmsg.ToUTF8() << "\n'" << aString << "'"; - wxLogTrace( MASK_3D_RESOLVER, "%s\n", ostr.str().c_str() ); - - return false; - } - - aIndex = i2 + 1; - return true; -} - - bool FILENAME_RESOLVER::ValidateFileName( const wxString& aFileName, bool& hasAlias ) const { // Rules: @@ -1066,32 +862,30 @@ bool FILENAME_RESOLVER::GetKicadPaths( std::list< wxString >& paths ) const while( mS != mE ) { // filter out URLs, template directories, and known system paths - if( mS->first == wxString( "KICAD_PTEMPLATES" ) - || mS->first == wxString( "KICAD6_FOOTPRINT_DIR" ) ) + if( mS->first == wxS( "KICAD_PTEMPLATES" ) + || mS->first == wxS( "KICAD6_FOOTPRINT_DIR" ) ) { ++mS; continue; } - if( wxString::npos != mS->second.GetValue().find( wxString( "://" ) ) ) + if( wxString::npos != mS->second.GetValue().find( wxS( "://" ) ) ) { ++mS; continue; } - wxString tmp( "${" ); - tmp.Append( mS->first ); - tmp.Append( "}" ); - paths.push_back( tmp ); + //also add the path without the ${} to act as legacy alias support for older files + paths.push_back( mS->first ); - if( tmp == "${KICAD6_3DMODEL_DIR}" ) + if( mS->first == wxS("KICAD6_3DMODEL_DIR") ) hasKisys3D = true; ++mS; } if( !hasKisys3D ) - paths.emplace_back("${KICAD6_3DMODEL_DIR}" ); + paths.emplace_back( wxS("KICAD6_3DMODEL_DIR") ); return true; } diff --git a/common/settings/common_settings.cpp b/common/settings/common_settings.cpp index 291a1fc3b8..b6d18ba596 100644 --- a/common/settings/common_settings.cpp +++ b/common/settings/common_settings.cpp @@ -19,9 +19,12 @@ */ #include +#include +#include #include #include +#include #include #include #include @@ -42,7 +45,7 @@ const std::set envVarBlacklist = ///! Update the schema version whenever a migration is required -const int commonSchemaVersion = 2; +const int commonSchemaVersion = 3; COMMON_SETTINGS::COMMON_SETTINGS() : JSON_SETTINGS( "kicad_common", SETTINGS_LOC::USER, commonSchemaVersion ), @@ -341,6 +344,7 @@ COMMON_SETTINGS::COMMON_SETTINGS() : registerMigration( 0, 1, std::bind( &COMMON_SETTINGS::migrateSchema0to1, this ) ); registerMigration( 1, 2, std::bind( &COMMON_SETTINGS::migrateSchema1to2, this ) ); + registerMigration( 2, 3, std::bind( &COMMON_SETTINGS::migrateSchema2to3, this ) ); } @@ -412,6 +416,38 @@ bool COMMON_SETTINGS::migrateSchema1to2() } +bool COMMON_SETTINGS::migrateSchema2to3() +{ + wxFileName cfgpath; + cfgpath.AssignDir( SETTINGS_MANAGER::GetUserSettingsPath() ); + cfgpath.AppendDir( wxT( "3d" ) ); + cfgpath.SetFullName( "3Dresolver.cfg" ); + cfgpath.MakeAbsolute(); + + std::vector legacyPaths; + readLegacy3DResolverCfg( cfgpath.GetFullPath(), legacyPaths ); + + for( const LEGACY_3D_SEARCH_PATH& path : legacyPaths ) + { + const wxString& key = path.m_Alias; + const wxString& val = path.m_Pathvar; + + if( !m_Env.vars.count( key ) ) + { + wxLogTrace( traceEnvVars, "COMMON_SETTINGS: Loaded new var: %s = %s", key, val ); + m_Env.vars[key] = ENV_VAR_ITEM( key, val ); + } + } + + if( cfgpath.FileExists() ) + { + wxRemoveFile( cfgpath.GetFullPath() ); + } + + return true; +} + + bool COMMON_SETTINGS::MigrateFromLegacy( wxConfigBase* aCfg ) { bool ret = true; @@ -536,3 +572,197 @@ void COMMON_SETTINGS::InitializeEnvironment() path.AppendDir( wxT( "symbols" ) ); addVar( wxT( "KICAD6_SYMBOL_DIR" ), path.GetFullPath() ); } + + +bool COMMON_SETTINGS::readLegacy3DResolverCfg( const wxString& path, + std::vector& aSearchPaths ) +{ + wxFileName cfgpath( path ); + + // This should be the same as wxWidgets 3.0 wxPATH_NORM_ALL which is deprecated in 3.1. + // There are known issues with environment variable expansion so maybe we should be using + // our own ExpandEnvVarSubstitutions() here instead. + cfgpath.Normalize( FN_NORMALIZE_FLAGS | wxPATH_NORM_ENV_VARS ); + wxString cfgname = cfgpath.GetFullPath(); + + std::ifstream cfgFile; + std::string cfgLine; + + if( !wxFileName::Exists( cfgname ) ) + { + std::ostringstream ostr; + ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; + wxString errmsg = "no 3D configuration file"; + ostr << " * " << errmsg.ToUTF8() << " '"; + ostr << cfgname.ToUTF8() << "'"; + wxLogTrace( traceSettings, "%s\n", ostr.str().c_str() ); + return false; + } + + cfgFile.open( cfgname.ToUTF8() ); + + if( !cfgFile.is_open() ) + { + std::ostringstream ostr; + ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; + wxString errmsg = "Could not open configuration file"; + ostr << " * " << errmsg.ToUTF8() << " '" << cfgname.ToUTF8() << "'"; + wxLogTrace( traceSettings, "%s\n", ostr.str().c_str() ); + return false; + } + + int lineno = 0; + LEGACY_3D_SEARCH_PATH al; + size_t idx; + int vnum = 0; // version number + + while( cfgFile.good() ) + { + cfgLine.clear(); + std::getline( cfgFile, cfgLine ); + ++lineno; + + if( cfgLine.empty() ) + { + if( cfgFile.eof() ) + break; + + continue; + } + + if( 1 == lineno && cfgLine.compare( 0, 2, "#V" ) == 0 ) + { + // extract the version number and parse accordingly + if( cfgLine.size() > 2 ) + { + std::istringstream istr; + istr.str( cfgLine.substr( 2 ) ); + istr >> vnum; + } + + continue; + } + + idx = 0; + + if( !getLegacy3DHollerith( cfgLine, idx, al.m_Alias ) ) + continue; + + // Don't add KICAD6_3DMODEL_DIR, one of its legacy equivalents, or KIPRJMOD from a + // config file. They're system variables are are defined at runtime. + if( al.m_Alias == "${KICAD6_3DMODEL_DIR}" || al.m_Alias == "${KIPRJMOD}" + || al.m_Alias == "$(KIPRJMOD)" || al.m_Alias == "${KISYS3DMOD}" + || al.m_Alias == "$(KISYS3DMOD)" ) + { + continue; + } + + if( !getLegacy3DHollerith( cfgLine, idx, al.m_Pathvar ) ) + continue; + + if( !getLegacy3DHollerith( cfgLine, idx, al.m_Description ) ) + continue; + + aSearchPaths.push_back( al ); + } + + cfgFile.close(); + + return true; +} + + +bool COMMON_SETTINGS::getLegacy3DHollerith( const std::string& aString, size_t& aIndex, + wxString& aResult ) +{ + aResult.clear(); + + if( aIndex >= aString.size() ) + { + std::ostringstream ostr; + ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; + wxString errmsg = "bad Hollerith string on line"; + ostr << " * " << errmsg.ToUTF8() << "\n'" << aString << "'"; + wxLogTrace( traceSettings, "%s\n", ostr.str().c_str() ); + + return false; + } + + size_t i2 = aString.find( '"', aIndex ); + + if( std::string::npos == i2 ) + { + std::ostringstream ostr; + ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; + wxString errmsg = "missing opening quote mark in config file"; + ostr << " * " << errmsg.ToUTF8() << "\n'" << aString << "'"; + wxLogTrace( traceSettings, "%s\n", ostr.str().c_str() ); + + return false; + } + + ++i2; + + if( i2 >= aString.size() ) + { + std::ostringstream ostr; + ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; + wxString errmsg = "invalid entry (unexpected end of line)"; + ostr << " * " << errmsg.ToUTF8() << "\n'" << aString << "'"; + wxLogTrace( traceSettings, "%s\n", ostr.str().c_str() ); + + return false; + } + + std::string tnum; + + while( aString[i2] >= '0' && aString[i2] <= '9' ) + tnum.append( 1, aString[i2++] ); + + if( tnum.empty() || aString[i2++] != ':' ) + { + std::ostringstream ostr; + ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; + wxString errmsg = "bad Hollerith string on line"; + ostr << " * " << errmsg.ToUTF8() << "\n'" << aString << "'"; + wxLogTrace( traceSettings, "%s\n", ostr.str().c_str() ); + + return false; + } + + std::istringstream istr; + istr.str( tnum ); + size_t nchars; + istr >> nchars; + + if( ( i2 + nchars ) >= aString.size() ) + { + std::ostringstream ostr; + ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; + wxString errmsg = "invalid entry (unexpected end of line)"; + ostr << " * " << errmsg.ToUTF8() << "\n'" << aString << "'"; + wxLogTrace( traceSettings, "%s\n", ostr.str().c_str() ); + + return false; + } + + if( nchars > 0 ) + { + aResult = wxString::FromUTF8( aString.substr( i2, nchars ).c_str() ); + i2 += nchars; + } + + if( i2 >= aString.size() || aString[i2] != '"' ) + { + std::ostringstream ostr; + ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; + wxString errmsg = "missing closing quote mark in config file"; + ostr << " * " << errmsg.ToUTF8() << "\n'" << aString << "'"; + wxLogTrace( traceSettings, "%s\n", ostr.str().c_str() ); + + return false; + } + + aIndex = i2 + 1; + return true; +} \ No newline at end of file diff --git a/common/tool/common_control.cpp b/common/tool/common_control.cpp index 78f7d03427..6f325b7c15 100644 --- a/common/tool/common_control.cpp +++ b/common/tool/common_control.cpp @@ -111,7 +111,7 @@ int COMMON_CONTROL::ConfigurePaths( const TOOL_EVENT& aEvent ) } else { - DIALOG_CONFIGURE_PATHS dlg( m_frame, nullptr ); + DIALOG_CONFIGURE_PATHS dlg( m_frame ); if( dlg.ShowModal() == wxID_OK ) m_frame->Kiway().CommonSettingsChanged( true, false ); diff --git a/include/dialogs/dialog_configure_paths.h b/include/dialogs/dialog_configure_paths.h index 6cfc2a5c38..89f52e3592 100644 --- a/include/dialogs/dialog_configure_paths.h +++ b/include/dialogs/dialog_configure_paths.h @@ -30,15 +30,13 @@ #include #include - -class FILENAME_RESOLVER; class HTML_WINDOW; class DIALOG_CONFIGURE_PATHS: public DIALOG_CONFIGURE_PATHS_BASE { public: - DIALOG_CONFIGURE_PATHS( wxWindow* aParent, FILENAME_RESOLVER* aResolver ); + DIALOG_CONFIGURE_PATHS( wxWindow* aParent ); ~DIALOG_CONFIGURE_PATHS() override; bool TransferDataToWindow() override; @@ -46,16 +44,11 @@ public: protected: // Various button callbacks - void OnGridCellRightClick( wxGridEvent& event ) override; void OnGridSize( wxSizeEvent& event ) override; void OnUpdateUI( wxUpdateUIEvent& event ) override; void OnGridCellChanging( wxGridEvent& event ); void OnAddEnvVar( wxCommandEvent& event ) override; void OnRemoveEnvVar( wxCommandEvent& event ) override; - void OnAddSearchPath( wxCommandEvent& event ) override; - void OnDeleteSearchPath( wxCommandEvent& event ) override; - void OnSearchPathMoveUp( wxCommandEvent& event ) override; - void OnSearchPathMoveDown( wxCommandEvent& event ) override; void OnHelp( wxCommandEvent& event ) override; void AppendEnvVar( const wxString& aName, const wxString& aPath, bool isExternal ); @@ -67,7 +60,6 @@ private: int m_errorRow; int m_errorCol; - FILENAME_RESOLVER* m_resolver; wxString m_curdir; wxTextValidator m_aliasValidator; diff --git a/include/filename_resolver.h b/include/filename_resolver.h index 9fc4b26222..8e68e42280 100644 --- a/include/filename_resolver.h +++ b/include/filename_resolver.h @@ -161,13 +161,6 @@ private: */ bool addPath( const SEARCH_PATH& aPath ); - /** - * Read a list of path names from a configuration file. - * - * @return true if a file was found and contained at least one valid path. - */ - bool readPathList( void ); - /** * Check the ${ENV_VAR} component of a path and adds it to the resolver's path list if * it is not yet in the list. diff --git a/include/settings/common_settings.h b/include/settings/common_settings.h index a8d2181882..ce7876fa3c 100644 --- a/include/settings/common_settings.h +++ b/include/settings/common_settings.h @@ -155,6 +155,19 @@ public: private: bool migrateSchema0to1(); bool migrateSchema1to2(); + bool migrateSchema2to3(); + + struct LEGACY_3D_SEARCH_PATH + { + wxString m_Alias; // alias to the base path + wxString m_Pathvar; // base path as stored in the config file + wxString m_Pathexp; // expanded base path + wxString m_Description; // description of the aliased path + }; + + static bool getLegacy3DHollerith( const std::string& aString, size_t& aIndex, + wxString& aResult ); + bool readLegacy3DResolverCfg( const wxString& aPath, std::vector& aSearchPaths ); public: APPEARANCE m_Appearance; diff --git a/pcbnew/pcbnew.cpp b/pcbnew/pcbnew.cpp index 8bc5e25086..be3db8a972 100644 --- a/pcbnew/pcbnew.cpp +++ b/pcbnew/pcbnew.cpp @@ -116,7 +116,7 @@ static struct IFACE : public KIFACE_BASE case DIALOG_CONFIGUREPATHS: { - DIALOG_CONFIGURE_PATHS dlg( aParent, aKiway->Prj().Get3DFilenameResolver() ); + DIALOG_CONFIGURE_PATHS dlg( aParent ); // The dialog's constructor probably failed to set its Kiway because the // dynamic_cast fails when aParent was allocated by a separate compilation