diff --git a/.circleci/config.yml b/.circleci/config.yml index 3920718c..1099a201 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -33,11 +33,11 @@ workflows: <<: *std-filters - build-android-armhf: <<: *std-filters - - build-flatpak-arm64-2208: + - build-flatpak-aarch64-2208: <<: *std-filters - build-flatpak-x86-2208: <<: *std-filters - - build-flatpak-arm64-2408: + - build-flatpak-aarch64-2408: <<: *std-filters - build-flatpak-x86-2408: <<: *std-filters @@ -202,12 +202,13 @@ jobs: command: ci\circleci-build-msvc.bat - deploy-code: deploy_use_orb: false - build-flatpak-arm64-2208: + build-flatpak-aarch64-2208: machine: image: ubuntu-2204:current resource_class: arm.medium environment: - - OCPN_TARGET: flatpak-arm64 + - OCPN_TARGET: flatpak + - BUILD_ARCH: aarch64 - FLATPAK_BRANCH: stable - CLOUDSMITH_PKG_EXT: gz - SDK_VER: 22.08 @@ -224,6 +225,7 @@ jobs: resource_class: arm.medium environment: - OCPN_TARGET: flatpak + - BUILD_ARCH: x86_64 - FLATPAK_BRANCH: stable - CLOUDSMITH_PKG_EXT: gz - SDK_VER: 22.08 @@ -235,12 +237,13 @@ jobs: command: bash ci/circleci-build-flatpak.sh no_output_timeout: 30m - deploy-code - build-flatpak-arm64-2408: + build-flatpak-aarch64-2408: machine: image: ubuntu-2204:current resource_class: arm.medium environment: - - OCPN_TARGET: flatpak-arm64 + - OCPN_TARGET: flatpak + - BUILD_ARCH: aarch64 - FLATPAK_BRANCH: stable - CLOUDSMITH_PKG_EXT: gz - SDK_VER: 24.08 @@ -257,6 +260,7 @@ jobs: resource_class: arm.medium environment: - OCPN_TARGET: flatpak + - BUILD_ARCH: x86_64 - FLATPAK_BRANCH: stable - CLOUDSMITH_PKG_EXT: gz - SDK_VER: 24.08 @@ -308,8 +312,7 @@ jobs: - deploy-code build-debian-x86_64-12-bookworm: machine: - image: ubuntu-2204:current - resource_class: arm.medium + image: ubuntu-2404:current environment: - OCPN_TARGET: bookworm - BUILD_GTK3: true @@ -331,7 +334,7 @@ jobs: environment: - OCPN_TARGET=bullseye-armhf - DOCKER_IMAGE=jongough/debian-armhf:bullseye - - BUILD_FLbuild-debian-arm64-12-bookwormAGS=-j3 + - BUILD_FLAGS=-j3 - BUILD_ENV=debian - BUILD_GTK3: true - DEPLOY_USE_ORB: true diff --git a/CMakeLists.txt b/CMakeLists.txt index b2e472da..6f9eb70f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,7 @@ # - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, # - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # ----------------------------------------------------------------------------- -# Frontend2 Author: Jon Gough Testplugn(TP) v1.0.310.0 15/10/2024 DD/MM/YYYY +# Frontend2 Author: Jon Gough Testplugn(TP) v1.0.318.0 21/12/2024 DD/MM/YYYY # format buildCI:yes provideODAPI:yes validateJSON:yes # --------------------------------------------------------------------------- # -- When changing this file do NOT change the order of the sections. -- Make @@ -60,9 +60,9 @@ set(PACKAGE "ocpn_draw") set(VERSION_MAJOR "1") set(VERSION_MINOR "8") -set(VERSION_PATCH "56") +set(VERSION_PATCH "57") set(VERSION_TWEAK "0") -set(VERSION_DATE "23/10/2024") # DD/MM/YYYY format +set(VERSION_DATE "21/12/2024") # DD/MM/YYYY format set(OCPN_MIN_VERSION "ov50") set(OCPN_API_VERSION_MAJOR "1") set(OCPN_API_VERSION_MINOR "17") diff --git a/src/ODConfig.cpp b/src/ODConfig.cpp index 5e248e45..23b47a0a 100644 --- a/src/ODConfig.cpp +++ b/src/ODConfig.cpp @@ -44,805 +44,832 @@ #include #endif -ODConfig::ODConfig(const wxString &appName, const wxString &vendorName, const wxString &LocalFileName) -{ - //ODConfig *pCF = new MyConfig::MyConfig( wxString( _T("") ), wxString( _T("") ), gConfig_File ); - //g_pODConfig->LoadMyConfig( 0 ); - - m_sODNavObjSetFile = *g_pData; - - m_sODNavObjSetFile += wxS( "ODnavobj.xml" ); - m_sODNavObjSetChangesFile = m_sODNavObjSetFile + _T( ".changes" ); - - m_pODNavObjectInputSet = NULL; - m_pODNavObjectChangesSet = NULL; - m_bSkipChangeSetUpdate = FALSE; - -} +ODConfig::ODConfig(const wxString& appName, const wxString& vendorName, + const wxString& LocalFileName) { + // ODConfig *pCF = new MyConfig::MyConfig( wxString( _T("") ), wxString( + // _T("") ), gConfig_File ); g_pODConfig->LoadMyConfig( 0 ); + + m_sODNavObjSetFile = *g_pData; + + m_sODNavObjSetFile += wxS("ODnavobj.xml"); + m_sODNavObjSetChangesFile = m_sODNavObjSetFile + _T( ".changes" ); -ODConfig::~ODConfig() -{ - //dtor + m_pODNavObjectInputSet = NULL; + m_pODNavObjectChangesSet = NULL; + m_bSkipChangeSetUpdate = FALSE; } -void ODConfig::LateInit(void) -{ - m_sImport_Path = g_sDefaultImportPath; - m_sImport_Type = g_sDefaultImportType; +ODConfig::~ODConfig() { + // dtor } -void ODConfig::DeInit(void) -{ - g_sDefaultImportPath = m_sImport_Path; - g_sDefaultImportType = m_sImport_Type; +void ODConfig::LateInit(void) { + m_sImport_Path = g_sDefaultImportPath; + m_sImport_Type = g_sDefaultImportType; } -bool ODConfig::AddNewPath( ODPath *pb, int crm ) -{ - if( pb->m_bIsInLayer ) - return true; +void ODConfig::DeInit(void) { + g_sDefaultImportPath = m_sImport_Path; + g_sDefaultImportType = m_sImport_Type; +} +bool ODConfig::AddNewPath(ODPath* pb, int crm) { + if (pb->m_bIsInLayer) return true; - if( !m_bSkipChangeSetUpdate ) { - m_pODNavObjectChangesSet->AddPath( pb, "add" ); - } + if (!m_bSkipChangeSetUpdate) { + m_pODNavObjectChangesSet->AddPath(pb, "add"); + } - return true; + return true; } -bool ODConfig::UpdatePath( ODPath *pb ) -{ - if( pb->m_bIsInLayer ) return true; - - if( !m_bSkipChangeSetUpdate ) { - if(pb->m_bSaveUpdates) - m_pODNavObjectChangesSet->AddPath( pb, "update" ); +bool ODConfig::UpdatePath(ODPath* pb) { + if (pb->m_bIsInLayer) return true; - } + if (!m_bSkipChangeSetUpdate) { + if (pb->m_bSaveUpdates) m_pODNavObjectChangesSet->AddPath(pb, "update"); + } - return true; + return true; } -bool ODConfig::DeleteConfigPath( ODPath *pb ) -{ - if( pb->m_bIsInLayer ) return true; - - if( !m_bSkipChangeSetUpdate ) { - m_pODNavObjectChangesSet->AddPath( pb, "delete" ); - - } - return true; +bool ODConfig::DeleteConfigPath(ODPath* pb) { + if (pb->m_bIsInLayer) return true; + + if (!m_bSkipChangeSetUpdate) { + m_pODNavObjectChangesSet->AddPath(pb, "delete"); + } + return true; } -bool ODConfig::AddNewODPoint( ODPoint *pODP, int crm ) -{ - if( pODP->m_bIsInLayer ) - return true; +bool ODConfig::AddNewODPoint(ODPoint* pODP, int crm) { + if (pODP->m_bIsInLayer) return true; - if(!pODP->m_bIsolatedMark) - return true; + if (!pODP->m_bIsolatedMark) return true; - if( !m_bSkipChangeSetUpdate ) { - m_pODNavObjectChangesSet->AddODPoint( pODP, "add" ); - } + if (!m_bSkipChangeSetUpdate) { + m_pODNavObjectChangesSet->AddODPoint(pODP, "add"); + } - return true; + return true; } -bool ODConfig::UpdateODPoint( ODPoint *pODP ) -{ - if( pODP->m_bIsInLayer ) - return true; +bool ODConfig::UpdateODPoint(ODPoint* pODP) { + if (pODP->m_bIsInLayer) return true; - if( !m_bSkipChangeSetUpdate ) { - m_pODNavObjectChangesSet->AddODPoint( pODP, "update" ); - } + if (!m_bSkipChangeSetUpdate) { + m_pODNavObjectChangesSet->AddODPoint(pODP, "update"); + } - return true; + return true; } -bool ODConfig::DeleteODPoint( ODPoint *pODP ) -{ - if( pODP->m_bIsInLayer ) - return true; +bool ODConfig::DeleteODPoint(ODPoint* pODP) { + if (pODP->m_bIsInLayer) return true; - if( !m_bSkipChangeSetUpdate ) { - m_pODNavObjectChangesSet->AddODPoint( pODP, "delete" ); - } + if (!m_bSkipChangeSetUpdate) { + m_pODNavObjectChangesSet->AddODPoint(pODP, "delete"); + } - return true; + return true; } -bool ODConfig::ExportGPXPaths( wxWindow* parent, PathList *pPaths, const wxString suggestedName ) -{ - wxFileDialog saveDialog( NULL, _( "Export GPX file" ), m_sGPX_Path, suggestedName, - wxT ( "GPX files (*.gpx)|*.gpx" ), wxFD_SAVE ); +bool ODConfig::ExportGPXPaths(wxWindow* parent, PathList* pPaths, + const wxString suggestedName) { + wxFileDialog saveDialog(NULL, _("Export GPX file"), m_sGPX_Path, + suggestedName, wxT("GPX files (*.gpx)|*.gpx"), + wxFD_SAVE); #ifdef __WXOSX__ - if(parent) - parent->HideWithEffect(wxSHOW_EFFECT_BLEND ); + if (parent) parent->HideWithEffect(wxSHOW_EFFECT_BLEND); #endif - int response = saveDialog.ShowModal(); + int response = saveDialog.ShowModal(); #ifdef __WXOSX__ - if(parent) - parent->ShowWithEffect(wxSHOW_EFFECT_BLEND ); + if (parent) parent->ShowWithEffect(wxSHOW_EFFECT_BLEND); #endif - wxString path = saveDialog.GetPath(); - wxFileName fn( path ); - m_sGPX_Path = fn.GetPath(); + wxString path = saveDialog.GetPath(); + wxFileName fn(path); + m_sGPX_Path = fn.GetPath(); - if( response == wxID_OK ) { - fn.SetExt( _T ( "gpx" ) ); + if (response == wxID_OK) { + fn.SetExt(_T ( "gpx" )); - if( wxFileExists( fn.GetFullPath() ) ) { - int answer = OCPNMessageBox_PlugIn( parent, _("Overwrite existing file?"), _("Confirm"), - wxICON_QUESTION | wxYES_NO | wxCANCEL | wxSTAY_ON_TOP ); - if( answer != wxID_YES ) return false; - } + if (wxFileExists(fn.GetFullPath())) { + int answer = OCPNMessageBox_PlugIn( + parent, _("Overwrite existing file?"), _("Confirm"), + wxICON_QUESTION | wxYES_NO | wxCANCEL | wxSTAY_ON_TOP); + if (answer != wxID_YES) return false; + } - ODNavObjectChanges *pgpx = new ODNavObjectChanges; - pgpx->AddGPXPathsList( pPaths ); - pgpx->SaveFile(fn.GetFullPath()); - delete pgpx; + ODNavObjectChanges* pgpx = new ODNavObjectChanges; + pgpx->AddGPXPathsList(pPaths); + pgpx->SaveFile(fn.GetFullPath()); + delete pgpx; - return true; - } else - return false; + return true; + } else + return false; } -bool ODConfig::ExportGPXODPoints( wxWindow* parent, ODPointList *pODPoints, const wxString suggestedName ) -{ - wxFileDialog saveDialog( NULL, _( "Export GPX file" ), m_sGPX_Path, suggestedName, - wxT ( "GPX files (*.gpx)|*.gpx" ), wxFD_SAVE ); +bool ODConfig::ExportGPXODPoints(wxWindow* parent, ODPointList* pODPoints, + const wxString suggestedName) { + wxFileDialog saveDialog(NULL, _("Export GPX file"), m_sGPX_Path, + suggestedName, wxT("GPX files (*.gpx)|*.gpx"), + wxFD_SAVE); - int response = saveDialog.ShowModal(); + int response = saveDialog.ShowModal(); - wxString path = saveDialog.GetPath(); - wxFileName fn( path ); - m_sGPX_Path = fn.GetPath(); + wxString path = saveDialog.GetPath(); + wxFileName fn(path); + m_sGPX_Path = fn.GetPath(); - if( response == wxID_OK ) { - fn.SetExt( _T ( "gpx" ) ); + if (response == wxID_OK) { + fn.SetExt(_T ( "gpx" )); - if( wxFileExists( fn.GetFullPath() ) ) { - int answer = OCPNMessageBox_PlugIn( parent, _("Overwrite existing file?"), _("Confirm"), - wxICON_QUESTION | wxYES_NO | wxCANCEL | wxSTAY_ON_TOP ); - if( answer != wxID_YES ) return false; - } + if (wxFileExists(fn.GetFullPath())) { + int answer = OCPNMessageBox_PlugIn( + parent, _("Overwrite existing file?"), _("Confirm"), + wxICON_QUESTION | wxYES_NO | wxCANCEL | wxSTAY_ON_TOP); + if (answer != wxID_YES) return false; + } - ODNavObjectChanges *pgpx = new ODNavObjectChanges; - pgpx->AddGPXODPointsList( pODPoints ); - pgpx->SaveFile(fn.GetFullPath()); - delete pgpx; + ODNavObjectChanges* pgpx = new ODNavObjectChanges; + pgpx->AddGPXODPointsList(pODPoints); + pgpx->SaveFile(fn.GetFullPath()); + delete pgpx; - return true; - } else - return false; + return true; + } else + return false; } -void ODConfig::UpdateNavObj( void ) -{ -// Create the NavObjectCollection, and save to specified file - ODNavObjectChanges *pNavObjectSet = new ODNavObjectChanges(); +void ODConfig::UpdateNavObj(void) { + // Create the NavObjectCollection, and save to specified file + ODNavObjectChanges* pNavObjectSet = new ODNavObjectChanges(); - pNavObjectSet->CreateAllGPXObjects(); - pNavObjectSet->SaveFile( m_sODNavObjSetFile ); - - delete pNavObjectSet; + pNavObjectSet->CreateAllGPXObjects(); + pNavObjectSet->SaveFile(m_sODNavObjSetFile); - if( ::wxFileExists( m_sODNavObjSetChangesFile ) ){ - wxLogNull logNo; - delete m_pODNavObjectChangesSet; - } + delete pNavObjectSet; + + if (::wxFileExists(m_sODNavObjSetChangesFile)) { + wxLogNull logNo; + delete m_pODNavObjectChangesSet; + } } -void ODConfig::LoadNavObjects() -{ - // next thing to do is read tracks, etc from the NavObject XML file, - wxString sLogMessage; - sLogMessage.append( _("Loading navobjects from ") ); - sLogMessage.append(m_sODNavObjSetFile ); - wxLogMessage( sLogMessage ); - CreateRotatingNavObjBackup(); - - if( NULL == m_pODNavObjectInputSet ) - m_pODNavObjectInputSet = new ODNavObjectChanges(); - - if( wxFileExists( m_sODNavObjSetFile ) && - m_pODNavObjectInputSet->load_file( m_sODNavObjSetFile.fn_str() ) ) - m_pODNavObjectInputSet->LoadAllGPXObjects(); - - wxLogMessage( _T("Done loading ODnavobjects") ); - delete m_pODNavObjectInputSet; - - if( wxFileExists( m_sODNavObjSetChangesFile ) ) { - - wxULongLong size = wxFileName::GetSize(m_sODNavObjSetChangesFile); - - //We crashed last time :( - //That's why this file still exists... - //Let's reconstruct the unsaved changes - m_pODNavObjectChangesSet->load_file( m_sODNavObjSetChangesFile.fn_str() ); - - - // Remove the file before applying the changes, - // just in case the changes file itself causes a fault. - // If it does fault, at least the next restart will proceed without fault. - m_pODNavObjectChangesSet->RemoveChangesFile(); - - if(size != 0){ - wxString sLogMessage; - sLogMessage.append( _("Applying changes from ") ); - sLogMessage.append( m_sODNavObjSetChangesFile ); - wxLogMessage( sLogMessage ); - m_pODNavObjectChangesSet->ApplyChanges(); - } - +void ODConfig::LoadNavObjects() { + // next thing to do is read tracks, etc from the NavObject XML file, + wxString sLogMessage; + sLogMessage.append(_("Loading navobjects from ")); + sLogMessage.append(m_sODNavObjSetFile); + wxLogMessage(sLogMessage); + CreateRotatingNavObjBackup(); + + if (NULL == m_pODNavObjectInputSet) + m_pODNavObjectInputSet = new ODNavObjectChanges(); + + if (wxFileExists(m_sODNavObjSetFile) && + m_pODNavObjectInputSet->load_file(m_sODNavObjSetFile.fn_str())) + m_pODNavObjectInputSet->LoadAllGPXObjects(); + + wxLogMessage(_T("Done loading ODnavobjects")); + delete m_pODNavObjectInputSet; + + if (wxFileExists(m_sODNavObjSetChangesFile)) { + wxULongLong size = wxFileName::GetSize(m_sODNavObjSetChangesFile); + + // We crashed last time :( + // That's why this file still exists... + // Let's reconstruct the unsaved changes + m_pODNavObjectChangesSet->load_file(m_sODNavObjSetChangesFile.fn_str()); + + // Remove the file before applying the changes, + // just in case the changes file itself causes a fault. + // If it does fault, at least the next restart will proceed without fault. + m_pODNavObjectChangesSet->RemoveChangesFile(); + + if (size != 0) { + wxString sLogMessage; + sLogMessage.append(_("Applying changes from ")); + sLogMessage.append(m_sODNavObjSetChangesFile); + wxLogMessage(sLogMessage); + m_pODNavObjectChangesSet->ApplyChanges(); } + } } -bool ODConfig::LoadLayers(wxString &path) -{ - wxArrayString file_array; - wxDir dir; - ODLayer *l_lLayer; - dir.Open( path ); - if( dir.IsOpened() ) { - wxString filename; - bool cont = dir.GetFirst( &filename ); - while( cont ) { - file_array.Clear(); - filename.Prepend( wxFileName::GetPathSeparator() ); - filename.Prepend( path ); - wxFileName f( filename ); - size_t nfiles = 0; - if( f.GetExt().IsSameAs( wxT("gpx") ) ) - file_array.Add( filename); // single-gpx-file layer - else{ - if(wxDir::Exists( filename ) ){ - wxDir dir( filename ); - if( dir.IsOpened() ){ - nfiles = dir.GetAllFiles( filename, &file_array, wxT("*.gpx") ); // layers subdirectory set - } - } - } - - if( file_array.GetCount() ){ - l_lLayer = new ODLayer(); - l_lLayer->m_LayerID = ++g_LayerIdx; - l_lLayer->m_LayerFileName = file_array[0]; - if( file_array.GetCount() <= 1 ) - wxFileName::SplitPath( file_array[0], NULL, NULL, &( l_lLayer->m_LayerName ), NULL, NULL ); - else - wxFileName::SplitPath( filename, NULL, NULL, &( l_lLayer->m_LayerName ), NULL, NULL ); - - bool bLayerViz = g_bShowLayers; - - if( g_VisibleLayers.Contains( l_lLayer->m_LayerName ) ) - bLayerViz = true; - if( g_InvisibleLayers.Contains( l_lLayer->m_LayerName ) ) - bLayerViz = false; - - l_lLayer->m_bIsVisible = bLayerViz; - - wxString laymsg; - laymsg.Printf( wxT("New layer %d: %s"), l_lLayer->m_LayerID, l_lLayer->m_LayerName.c_str() ); - wxLogMessage( laymsg ); - - g_pLayerList->Insert( l_lLayer ); - - // Load the entire file array as a single layer - - for( unsigned int i = 0; i < file_array.GetCount(); i++ ) { - wxString file_path = file_array[i]; - - if( ::wxFileExists( file_path ) ) { - ODNavObjectChanges *pSet = new ODNavObjectChanges; - pSet->load_file(file_path.fn_str()); - long nItems = pSet->LoadAllGPXObjectsAsLayer(l_lLayer->m_LayerID, bLayerViz); - l_lLayer->m_NoOfItems += nItems; - - wxString objmsg; - objmsg.Printf( wxT("Loaded GPX file %s with %ld items."), file_path.c_str(), nItems ); - wxLogMessage( objmsg ); - - delete pSet; - } - } - } - - cont = dir.GetNext( &filename ); +bool ODConfig::LoadLayers(wxString& path) { + wxArrayString file_array; + wxDir dir; + ODLayer* l_lLayer; + dir.Open(path); + if (dir.IsOpened()) { + wxString filename; + bool cont = dir.GetFirst(&filename); + while (cont) { + file_array.Clear(); + filename.Prepend(wxFileName::GetPathSeparator()); + filename.Prepend(path); + wxFileName f(filename); + size_t nfiles = 0; + if (f.GetExt().IsSameAs(wxT("gpx"))) + file_array.Add(filename); // single-gpx-file layer + else { + if (wxDir::Exists(filename)) { + wxDir dir(filename); + if (dir.IsOpened()) { + nfiles = dir.GetAllFiles(filename, &file_array, + wxT("*.gpx")); // layers subdirectory set + } } - } - - // make sure any EBL hanging of the boat is repositioned - wxEBLListNode *node = g_pEBLList->GetFirst(); - for(size_t i = 0; i < g_pEBLList->GetCount(); i++) { - EBL *ebl = (EBL *)node->GetData(); - if(ebl->m_bCentreOnBoat) { - bool l_bSaveUpdatesState = ebl->m_bSaveUpdates; - ebl->m_bSaveUpdates = false; - ebl->CentreOnBoat(true); - ebl->m_bSaveUpdates = l_bSaveUpdatesState; + } + + if (file_array.GetCount()) { + l_lLayer = new ODLayer(); + l_lLayer->m_LayerID = ++g_LayerIdx; + l_lLayer->m_LayerFileName = file_array[0]; + if (file_array.GetCount() <= 1) + wxFileName::SplitPath(file_array[0], NULL, NULL, + &(l_lLayer->m_LayerName), NULL, NULL); + else + wxFileName::SplitPath(filename, NULL, NULL, &(l_lLayer->m_LayerName), + NULL, NULL); + + bool bLayerViz = g_bShowLayers; + + if (g_VisibleLayers.Contains(l_lLayer->m_LayerName)) bLayerViz = true; + if (g_InvisibleLayers.Contains(l_lLayer->m_LayerName)) + bLayerViz = false; + + l_lLayer->m_bIsVisible = bLayerViz; + + wxString laymsg; + laymsg.Printf(wxT("New layer %d: %s"), l_lLayer->m_LayerID, + l_lLayer->m_LayerName.c_str()); + wxLogMessage(laymsg); + + g_pLayerList->Insert(l_lLayer); + + // Load the entire file array as a single layer + + for (unsigned int i = 0; i < file_array.GetCount(); i++) { + wxString file_path = file_array[i]; + + if (::wxFileExists(file_path)) { + ODNavObjectChanges* pSet = new ODNavObjectChanges; + pSet->load_file(file_path.fn_str()); + long nItems = + pSet->LoadAllGPXObjectsAsLayer(l_lLayer->m_LayerID, bLayerViz); + l_lLayer->m_NoOfItems += nItems; + + wxString objmsg; + objmsg.Printf(wxT("Loaded GPX file %s with %ld items."), + file_path.c_str(), nItems); + wxLogMessage(objmsg); + + delete pSet; + } } - node = node->GetNext(); + } + + cont = dir.GetNext(&filename); } - - return true; + } + + // make sure any EBL hanging of the boat is repositioned + wxEBLListNode* node = g_pEBLList->GetFirst(); + for (size_t i = 0; i < g_pEBLList->GetCount(); i++) { + EBL* ebl = (EBL*)node->GetData(); + if (ebl->m_bCentreOnBoat) { + bool l_bSaveUpdatesState = ebl->m_bSaveUpdates; + ebl->m_bSaveUpdates = false; + ebl->CentreOnBoat(true); + ebl->m_bSaveUpdates = l_bSaveUpdatesState; + } + node = node->GetNext(); + } + + return true; } -void ODConfig::ExportGPX( wxWindow* parent, bool bviz_only, bool blayer ) -{ - wxFileDialog saveDialog( NULL, _( "Export GPX file" ), m_sGPX_Path, wxT ( "" ), - wxT ( "GPX files (*.gpx)|*.gpx" ), wxFD_SAVE ); +void ODConfig::ExportGPX(wxWindow* parent, bool bviz_only, bool blayer) { + wxFileDialog saveDialog(NULL, _("Export GPX file"), m_sGPX_Path, wxT(""), + wxT("GPX files (*.gpx)|*.gpx"), wxFD_SAVE); - int response = saveDialog.ShowModal(); + int response = saveDialog.ShowModal(); - wxString path = saveDialog.GetPath(); - wxFileName fn( path ); - m_sGPX_Path = fn.GetPath(); + wxString path = saveDialog.GetPath(); + wxFileName fn(path); + m_sGPX_Path = fn.GetPath(); - if( response == wxID_OK ) { - fn.SetExt( _T ( "gpx" ) ); + if (response == wxID_OK) { + fn.SetExt(_T ( "gpx" )); - if( wxFileExists( fn.GetFullPath() ) ) { - int answer = OCPNMessageBox_PlugIn( parent, _("Overwrite existing file?"), _("Confirm"), - wxICON_QUESTION | wxYES_NO | wxCANCEL | wxSTAY_ON_TOP ); - if( answer != wxID_YES ) return; - } + if (wxFileExists(fn.GetFullPath())) { + int answer = OCPNMessageBox_PlugIn( + parent, _("Overwrite existing file?"), _("Confirm"), + wxICON_QUESTION | wxYES_NO | wxCANCEL | wxSTAY_ON_TOP); + if (answer != wxID_YES) return; + } - ::wxBeginBusyCursor(); + ::wxBeginBusyCursor(); - ODNavObjectChanges *pgpx = new ODNavObjectChanges; + ODNavObjectChanges* pgpx = new ODNavObjectChanges; - wxProgressDialog *pprog = NULL; - int count = g_pODPointMan->GetODPointList()->GetCount(); - if( count > 200) { - pprog = new wxProgressDialog( _("Export GPX file"), _T("0/0"), count, NULL, - wxPD_APP_MODAL | wxPD_SMOOTH | - wxPD_ELAPSED_TIME | wxPD_ESTIMATED_TIME | wxPD_REMAINING_TIME ); - pprog->SetSize( 400, wxDefaultCoord ); - pprog->Centre(); - } + wxProgressDialog* pprog = NULL; + int count = g_pODPointMan->GetODPointList()->GetCount(); + if (count > 200) { + pprog = new wxProgressDialog(_("Export GPX file"), _T("0/0"), count, NULL, + wxPD_APP_MODAL | wxPD_SMOOTH | + wxPD_ELAPSED_TIME | wxPD_ESTIMATED_TIME | + wxPD_REMAINING_TIME); + pprog->SetSize(400, wxDefaultCoord); + pprog->Centre(); + } - //Points - int ic = 0; + // Points + int ic = 0; - wxPathListNode *node1 = g_pPathList->GetFirst(); -//#ifdef COMPILER_SUPPORTS_CXX11 + wxPathListNode* node1 = g_pPathList->GetFirst(); +// #ifdef COMPILER_SUPPORTS_CXX11 #ifdef OD_USE_CXX11 - //build an unordered map list for high speed access - std::unordered_map tp_hash; - tp_hash.reserve(count); -#else - std::map tp_hash; -#endif - while (node1) { - ODPath *pPath = node1->GetData(); - ODPointList *pODPointList = pPath->m_pODPointList; - wxODPointListNode *node2 = pODPointList->GetFirst(); - ODPoint *pop; - while (node2) { - pop = node2->GetData(); - tp_hash[pop] = pop; - node2 = node2->GetNext(); - } - node1 = node1->GetNext(); - } - - wxODPointListNode *node = g_pODPointMan->GetODPointList()->GetFirst(); - ODPoint *podp; - time_t l_tStart = time(0); - time_t l_tCurrent; - while( node ) { - l_tCurrent = time(0); - if(pprog && l_tStart != l_tCurrent) { - wxString msg; - msg.Printf(_T("%d/%d"), ic, count); - pprog->Update( ic, msg ); - ic++; - } + // build an unordered map list for high speed access + std::unordered_map tp_hash; + tp_hash.reserve(count); +#else + std::map tp_hash; +#endif + while (node1) { + ODPath* pPath = node1->GetData(); + ODPointList* pODPointList = pPath->m_pODPointList; + wxODPointListNode* node2 = pODPointList->GetFirst(); + ODPoint* pop; + while (node2) { + pop = node2->GetData(); + tp_hash[pop] = pop; + node2 = node2->GetNext(); + } + node1 = node1->GetNext(); + } - podp = node->GetData(); + wxODPointListNode* node = g_pODPointMan->GetODPointList()->GetFirst(); + ODPoint* podp; + time_t l_tStart = time(0); + time_t l_tCurrent; + while (node) { + l_tCurrent = time(0); + if (pprog && l_tStart != l_tCurrent) { + wxString msg; + msg.Printf(_T("%d/%d"), ic, count); + pprog->Update(ic, msg); + ic++; + } - bool b_add = true; + podp = node->GetData(); - if( bviz_only && !podp->m_bIsVisible ) - b_add = false; + bool b_add = true; - if( podp->m_bIsInLayer && !blayer ) - b_add = false; - if( b_add) { - if( podp->m_bKeepXPath || tp_hash.find( podp ) == tp_hash.end() ) - pgpx->AddGPXODPoint( podp); - } + if (bviz_only && !podp->m_bIsVisible) b_add = false; - node = node->GetNext(); - } - //Paths - node1 = g_pPathList->GetFirst(); - while( node1 ) { - ODPath *pPath = node1->GetData(); + if (podp->m_bIsInLayer && !blayer) b_add = false; + if (b_add) { + if (podp->m_bKeepXPath || tp_hash.find(podp) == tp_hash.end()) + pgpx->AddGPXODPoint(podp); + } - bool b_add = true; + node = node->GetNext(); + } + // Paths + node1 = g_pPathList->GetFirst(); + while (node1) { + ODPath* pPath = node1->GetData(); - if( bviz_only && !pPath->IsVisible() ) - b_add = false; + bool b_add = true; - if( pPath->m_bIsInLayer && !blayer ) - b_add = false; + if (bviz_only && !pPath->IsVisible()) b_add = false; - if( b_add ) { - pgpx->AddGPXPath( pPath ); - } - node1 = node1->GetNext(); - } + if (pPath->m_bIsInLayer && !blayer) b_add = false; - pgpx->SaveFile( fn.GetFullPath() ); - delete pgpx; - ::wxEndBusyCursor(); + if (b_add) { + pgpx->AddGPXPath(pPath); + } + node1 = node1->GetNext(); + } - if( pprog) - delete pprog; + pgpx->SaveFile(fn.GetFullPath()); + delete pgpx; + ::wxEndBusyCursor(); - } + if (pprog) delete pprog; + } } -void ODConfig::UI_ImportGPX( wxWindow* parent, bool islayer, wxString dirpath, bool isdirectory ) -{ - int response = wxID_CANCEL; - wxArrayString file_array; - ODLayer *l = NULL; +void ODConfig::UI_ImportGPX(wxWindow* parent, bool islayer, wxString dirpath, + bool isdirectory) { + int response = wxID_CANCEL; + wxArrayString file_array; + ODLayer* l = NULL; + + if (!islayer || dirpath.IsSameAs(_T(""))) { + wxString l_ext_list = ""; - if( !islayer || dirpath.IsSameAs( _T("") ) ) { - wxString l_ext_list = ""; - #ifdef __OCPN__ANDROID__ - wxString selectedFile; - response = PlatformFileSelectorDialog( NULL, &selectedFile, _( "Import GPX file" ), m_sImport_Path, - wxT ( "" ), wxT ( "GPX files (*.gpx)|*.gpx|CSV files (*.csv)|*.csv|All files (*.*)|*.*" )); - if(response == wxID_OK){ - file_array.Add(selectedFile); - } + wxString selectedFile; + response = PlatformFileSelectorDialog( + NULL, &selectedFile, _("Import GPX file"), m_sImport_Path, wxT(""), + wxT("GPX files (*.gpx)|*.gpx|CSV files (*.csv)|*.csv|All files " + "(*.*)|*.*")); + if (response == wxID_OK) { + file_array.Add(selectedFile); + } #else - wxFileDialog openDialog( NULL, _( "Import GPX file" ), m_sImport_Path, wxT ( "" ), - wxT ( "GPX files (*.gpx)|*.gpx|CSV files (*.csv)|*.csv|All files (*.*)|*.*" ), - wxFD_OPEN | wxFD_MULTIPLE ); - openDialog.Centre(); - response = openDialog.ShowModal(); - if( response == wxID_OK ) { - openDialog.GetPaths( file_array ); - - // Record the currently selected directory for later use - if( file_array.GetCount() ) { - wxFileName fn( file_array[0] ); - m_sGPX_Path = fn.GetPath(); - } - } -#endif + wxFileDialog openDialog(NULL, _("Import GPX file"), m_sImport_Path, wxT(""), + wxT("GPX files (*.gpx)|*.gpx|CSV files " + "(*.csv)|*.csv|All files (*.*)|*.*"), + wxFD_OPEN | wxFD_MULTIPLE); + openDialog.Centre(); + response = openDialog.ShowModal(); + if (response == wxID_OK) { + openDialog.GetPaths(file_array); + + // Record the currently selected directory for later use + if (file_array.GetCount()) { + wxFileName fn(file_array[0]); + m_sGPX_Path = fn.GetPath(); + } + } +#endif + } else { + if (isdirectory) { + if (wxDir::GetAllFiles(dirpath, &file_array, wxT("*.gpx"))) + response = wxID_OK; } else { - if( isdirectory ) { - if( wxDir::GetAllFiles( dirpath, &file_array, wxT("*.gpx") ) ) - response = wxID_OK; - } else { - file_array.Add( dirpath ); - response = wxID_OK; + file_array.Add(dirpath); + response = wxID_OK; + } + } + + if (response == wxID_OK) { + if (islayer) { + l = new ODLayer(); + l->m_LayerID = ++g_LayerIdx; + l->m_LayerFileName = file_array[0]; + if (file_array.GetCount() <= 1) + wxFileName::SplitPath(file_array[0], NULL, NULL, &(l->m_LayerName), + NULL, NULL); + else { + if (dirpath.IsSameAs(_T(""))) + wxFileName::SplitPath(m_sImport_Path, NULL, NULL, &(l->m_LayerName), + NULL, NULL); + else + wxFileName::SplitPath(dirpath, NULL, NULL, &(l->m_LayerName), NULL, + NULL); + } + + bool bLayerViz = g_bShowLayers; + if (g_VisibleLayers.Contains(l->m_LayerName)) bLayerViz = true; + if (g_InvisibleLayers.Contains(l->m_LayerName)) bLayerViz = false; + l->m_bIsVisible = bLayerViz; + + ODLayerList::iterator iter; + bool l_foundLayer = false; + for (iter = g_pLayerList->begin(); iter != g_pLayerList->end(); ++iter) { + ODLayer* current = *iter; + if (current->GetName() == l->m_LayerName) { + l_foundLayer = true; + break; } + } + wxString laymsg; + if (l_foundLayer) { + laymsg.Printf(wxT("Layer %d: %s is a duplicate"), l->m_LayerID, + l->m_LayerName.c_str()); + } else { + laymsg.Printf(wxT("New layer %d: %s"), l->m_LayerID, + l->m_LayerName.c_str()); + } + wxLogMessage(laymsg); + + g_pLayerList->Insert(l); } - if( response == wxID_OK ) { - - if( islayer ) { - l = new ODLayer(); - l->m_LayerID = ++g_LayerIdx; - l->m_LayerFileName = file_array[0]; - if( file_array.GetCount() <= 1 ) wxFileName::SplitPath( file_array[0], NULL, NULL, - &( l->m_LayerName ), NULL, NULL ); - else { - if( dirpath.IsSameAs( _T("") ) ) wxFileName::SplitPath( m_sImport_Path, NULL, NULL, - &( l->m_LayerName ), NULL, NULL ); - else - wxFileName::SplitPath( dirpath, NULL, NULL, &( l->m_LayerName ), NULL, NULL ); - } - - bool bLayerViz = g_bShowLayers; - if( g_VisibleLayers.Contains( l->m_LayerName ) ) - bLayerViz = true; - if( g_InvisibleLayers.Contains( l->m_LayerName ) ) - bLayerViz = false; - l->m_bIsVisible = bLayerViz; - - wxString laymsg; - laymsg.Printf( _("New layer %d: %s"), l->m_LayerID, l->m_LayerName.c_str() ); - wxLogMessage( laymsg ); - - g_pLayerList->Insert( l ); + for (unsigned int i = 0; i < file_array.GetCount(); i++) { + wxString path = file_array[i]; + + if (wxFileExists(path)) { + ODNavObjectChanges* pSet = new ODNavObjectChanges; + if (m_sImport_Type == _T("gpx")) { + pSet->load_file(path.fn_str()); + if (islayer) { + l->m_NoOfItems += + pSet->LoadAllGPXObjectsAsLayer(l->m_LayerID, l->m_bIsVisible); + } else + pSet->LoadAllGPXObjects( + true); // Import with full vizibility of names and objects + } else { + if (islayer) { + l->m_NoOfItems += pSet->Load_CSV_File(path.fn_str(), l->m_LayerID, + l->m_bIsVisible); + } else { + pSet->Load_CSV_File(path.fn_str()); + } } - for( unsigned int i = 0; i < file_array.GetCount(); i++ ) { - wxString path = file_array[i]; - - if( wxFileExists( path ) ) { - - ODNavObjectChanges *pSet = new ODNavObjectChanges; - if(m_sImport_Type == _T("gpx")) { - pSet->load_file(path.fn_str()); - if(islayer){ - l->m_NoOfItems += pSet->LoadAllGPXObjectsAsLayer(l->m_LayerID, l->m_bIsVisible); - } - else - pSet->LoadAllGPXObjects( true ); // Import with full vizibility of names and objects - } else { - if(islayer) { - l->m_NoOfItems += pSet->Load_CSV_File(path.fn_str(), l->m_LayerID, l->m_bIsVisible); - } else { - pSet->Load_CSV_File(path.fn_str()); - - } - } - - delete pSet; - } - } + delete pSet; + } + } - // make sure any EBL hanging off the boat is repositioned - wxEBLListNode *node = g_pEBLList->GetFirst(); - for(size_t i = 0; i < g_pEBLList->GetCount(); i++) { - EBL *ebl = (EBL *)node->GetData(); - if(ebl->m_bCentreOnBoat) { - bool l_bSaveUpdatesState = ebl->m_bSaveUpdates; - ebl->m_bSaveUpdates = false; - ebl->CentreOnBoat(true); - ebl->m_bSaveUpdates = l_bSaveUpdatesState; - } - node = node->GetNext(); - } + // make sure any EBL hanging off the boat is repositioned + wxEBLListNode* node = g_pEBLList->GetFirst(); + for (size_t i = 0; i < g_pEBLList->GetCount(); i++) { + EBL* ebl = (EBL*)node->GetData(); + if (ebl->m_bCentreOnBoat) { + bool l_bSaveUpdatesState = ebl->m_bSaveUpdates; + ebl->m_bSaveUpdates = false; + ebl->CentreOnBoat(true); + ebl->m_bSaveUpdates = l_bSaveUpdatesState; + } + node = node->GetNext(); } + } } -void ODConfig::UI_Import( wxWindow* parent, bool islayer, bool isTemporary, wxString dirpath, bool isdirectory ) -{ - int response = wxID_CANCEL; - wxArrayString file_array; - ODLayer *l_pLayer = NULL; - - if(m_sImport_Type == _T("csv")) { - m_sWildcardString = _T("CSV files (*.csv)|*.csv|GPX files (*.gpx)|*.gpx|All files (*.*)|*.*"); - } else if(m_sImport_Type == _T("gpx")) { - m_sWildcardString = _T("GPX files (*.gpx)|*.gpx|CSV files (*.csv)|*.csv|All files (*.*)|*.*"); - } else if(m_sImport_Type == _T("*")) { - m_sWildcardString = _T("All files (*.*)|*.*|GPX files (*.gpx)|*.gpx|CSV files (*.csv)|*.csv"); - } else { - m_sWildcardString = _T("GPX files (*.gpx)|*.gpx|CSV files (*.csv)|*.csv|All files (*.*)|*.*"); - } +void ODConfig::UI_Import(wxWindow* parent, bool islayer, bool isTemporary, + wxString dirpath, bool isdirectory) { + int response = wxID_CANCEL; + wxArrayString file_array; + ODLayer* l_pLayer = NULL; + + if (m_sImport_Type == _T("csv")) { + m_sWildcardString = + _T("CSV files (*.csv)|*.csv|GPX files (*.gpx)|*.gpx|All files ") + _T("(*.*)|*.*"); + } else if (m_sImport_Type == _T("gpx")) { + m_sWildcardString = + _T("GPX files (*.gpx)|*.gpx|CSV files (*.csv)|*.csv|All files ") + _T("(*.*)|*.*"); + } else if (m_sImport_Type == _T("*")) { + m_sWildcardString = + _T("All files (*.*)|*.*|GPX files (*.gpx)|*.gpx|CSV files ") + _T("(*.csv)|*.csv"); + } else { + m_sWildcardString = + _T("GPX files (*.gpx)|*.gpx|CSV files (*.csv)|*.csv|All files ") + _T("(*.*)|*.*"); + } #ifdef __OCPN__ANDROID__ - wxString selectedFile; - response = PlatformFileSelectorDialog( NULL, &selectedFile, _( "Import GPX file" ), m_sImport_Path, - wxT ( "" ), m_sWildcardString); - if(response == wxID_OK){ - file_array.Add(selectedFile); - } + wxString selectedFile; + response = + PlatformFileSelectorDialog(NULL, &selectedFile, _("Import GPX file"), + m_sImport_Path, wxT(""), m_sWildcardString); + if (response == wxID_OK) { + file_array.Add(selectedFile); + } #else - wxFileDialog openDialog( parent, _( "Import file" ), m_sImport_Path, _T(""), m_sWildcardString, - wxFD_OPEN | wxFD_MULTIPLE ); - openDialog.Centre(); - response = openDialog.ShowModal(); - if( response == wxID_OK ) { - openDialog.GetPaths( file_array ); - - // Record the currently selected directory for later use - if( file_array.GetCount() ) { - wxFileName fn( file_array[0] ); - m_sImport_Path = fn.GetPath(); - m_sImport_Type = fn.GetExt(); - } - - } else { - if(dirpath.IsEmpty()) - response = wxID_CANCEL; - else { - if( isdirectory ) { - if( wxDir::GetAllFiles( dirpath, &file_array, wxT("*.gpx") ) ) - response = wxID_OK; - } else { - file_array.Add( dirpath ); - response = wxID_OK; - } - } + wxFileDialog openDialog(parent, _("Import file"), m_sImport_Path, _T(""), + m_sWildcardString, wxFD_OPEN | wxFD_MULTIPLE); + openDialog.Centre(); + response = openDialog.ShowModal(); + if (response == wxID_OK) { + openDialog.GetPaths(file_array); + + // Record the currently selected directory for later use + if (file_array.GetCount()) { + wxFileName fn(file_array[0]); + m_sImport_Path = fn.GetPath(); + m_sImport_Type = fn.GetExt(); } -#endif - if( response == wxID_OK ) { - wxString l_sImportFileName = wxEmptyString; - - for( unsigned int i = 0; i < file_array.GetCount(); i++ ) { - wxString path = file_array[i]; - wxFileName l_fn(file_array[i]); - - if( wxFileExists( path ) ) { - if(islayer) { - if(isTemporary) { - if(i==0) { - l_pLayer = new ODLayer(); - l_pLayer->m_LayerID = ++g_LayerIdx; - if( file_array.GetCount() <= 1 ) wxFileName::SplitPath( file_array[0], NULL, NULL, &(l_pLayer->m_LayerName), NULL, NULL ); - else { - if( dirpath.IsSameAs( _T("") ) ) wxFileName::SplitPath( m_sImport_Path, NULL, NULL, &(l_pLayer->m_LayerName), NULL, NULL ); - else - wxFileName::SplitPath( dirpath, NULL, NULL, &(l_pLayer->m_LayerName), NULL, NULL ); - } - - bool bLayerViz = g_bShowLayers; - if( g_VisibleLayers.Contains( l_pLayer->m_LayerName ) ) - bLayerViz = true; - if( g_InvisibleLayers.Contains( l_pLayer->m_LayerName ) ) - bLayerViz = false; - l_pLayer->m_bIsVisibleOnChart = bLayerViz; - - wxString laymsg; - laymsg.Printf( _("New layer %d: %s"), l_pLayer->m_LayerID, l_pLayer->m_LayerName.c_str() ); - wxLogMessage( laymsg ); - - g_pLayerList->Insert( l_pLayer ); - } - } else { - l_pLayer = new ODLayer(); - l_pLayer->m_LayerID = ++g_LayerIdx; - l_pLayer->m_LayerName = l_fn.GetName(); - - wxString destf, f, name, ext; - f = path; - wxFileName::SplitPath(f, NULL , NULL, &name, &ext); - destf = g_PrivateDataDir->ToStdString(); - g_ocpn_draw_pi->appendOSDirSlash(&destf); - destf.Append(_T("Layers")); - g_ocpn_draw_pi->appendOSDirSlash(&destf); - if (!wxDirExists(destf)) { - if( !wxMkdir(destf, wxS_DIR_DEFAULT) ) - wxLogMessage( _T("Error creating layer directory") ); - } - - destf << name << _T(".") << ext; - wxString msg; - if( wxCopyFile(f, destf, true) ) { - msg.Printf(_T("File: %s.%s also added to persistent layers"), name, ext); - l_pLayer->m_LayerFileName = destf; - } - else - msg.Printf(_T("Failed adding %s.%s to persistent layers"), name, ext); - wxLogMessage(msg); - - bool bLayerViz = g_bShowLayers; - if( g_VisibleLayers.Contains( l_pLayer->m_LayerName ) ) - bLayerViz = true; - if( g_InvisibleLayers.Contains( l_pLayer->m_LayerName ) ) - bLayerViz = false; - l_pLayer->m_bIsVisibleOnChart = bLayerViz; - - wxString laymsg; - laymsg.Printf( _("New layer %d: %s"), l_pLayer->m_LayerID, l_pLayer->m_LayerName.c_str() ); - wxLogMessage( laymsg ); - - g_pLayerList->Insert( l_pLayer ); - } - - } - - ODNavObjectChanges *pSet = new ODNavObjectChanges; - if(l_fn.GetExt() == _T("csv")) { - if(l_pLayer) { - l_pLayer->m_NoOfItems += pSet->Load_CSV_File(path.fn_str(), l_pLayer->m_LayerID, l_pLayer->m_bIsVisibleOnChart); - } else { - pSet->Load_CSV_File(path.fn_str(), 0, true); - } - }else if(l_fn.GetExt() == _T("gpx")) { - pSet->load_file(path.fn_str()); - if(islayer){ - l_pLayer->m_NoOfItems += pSet->LoadAllGPXObjectsAsLayer(l_pLayer->m_LayerID, l_pLayer->m_bIsVisibleOnChart); - } - else - pSet->LoadAllGPXObjects( true ); // Import with full vizibility of names and objects - } - - - delete pSet; - } - } - - // make sure any EBL hanging of the boat is repositioned - wxEBLListNode *node = g_pEBLList->GetFirst(); - for(size_t i = 0; i < g_pEBLList->GetCount(); i++) { - EBL *ebl = (EBL *)node->GetData(); - if(ebl->m_bCentreOnBoat) { - bool l_bSaveUpdatesState = ebl->m_bSaveUpdates; - ebl->m_bSaveUpdates = false; - ebl->CentreOnBoat(true); - ebl->m_bSaveUpdates = l_bSaveUpdatesState; - } - node = node->GetNext(); - } + + } else { + if (dirpath.IsEmpty()) + response = wxID_CANCEL; + else { + if (isdirectory) { + if (wxDir::GetAllFiles(dirpath, &file_array, wxT("*.gpx"))) + response = wxID_OK; + } else { + file_array.Add(dirpath); + response = wxID_OK; + } } -} + } +#endif + if (response == wxID_OK) { + wxString l_sImportFileName = wxEmptyString; + + for (unsigned int i = 0; i < file_array.GetCount(); i++) { + wxString path = file_array[i]; + wxFileName l_fn(file_array[i]); + + if (wxFileExists(path)) { + if (islayer) { + if (isTemporary) { + if (i == 0) { + l_pLayer = new ODLayer(); + l_pLayer->m_LayerID = ++g_LayerIdx; + if (file_array.GetCount() <= 1) + wxFileName::SplitPath(file_array[0], NULL, NULL, + &(l_pLayer->m_LayerName), NULL, NULL); + else { + if (dirpath.IsSameAs(_T(""))) + wxFileName::SplitPath(m_sImport_Path, NULL, NULL, + &(l_pLayer->m_LayerName), NULL, NULL); + else + wxFileName::SplitPath(dirpath, NULL, NULL, + &(l_pLayer->m_LayerName), NULL, NULL); + } -void ODConfig::CreateRotatingNavObjBackup() -{ - //Rotate navobj backups, but just in case there are some changes in the current version - //to prevent the user trying to "fix" the problem by continuously starting the - //application to overwrite all of his good backups... - if( g_navobjbackups > 0 ) { - wxFile f; - wxString oldname = m_sODNavObjSetFile; - wxString newname = wxString::Format( _T("%s.1"), m_sODNavObjSetFile.c_str() ); - - wxFileOffset s_diff = 1; - if( wxFileExists( newname ) ) { - - if( f.Open(oldname) ){ - s_diff = f.Length(); - f.Close(); - } + bool bLayerViz = g_bShowLayers; + if (g_VisibleLayers.Contains(l_pLayer->m_LayerName)) + bLayerViz = true; + if (g_InvisibleLayers.Contains(l_pLayer->m_LayerName)) + bLayerViz = false; + l_pLayer->m_bIsVisibleOnChart = bLayerViz; + + wxString laymsg; + laymsg.Printf(_("New layer %d: %s"), l_pLayer->m_LayerID, + l_pLayer->m_LayerName.c_str()); + wxLogMessage(laymsg); - if( f.Open(newname) ){ - s_diff -= f.Length(); - f.Close(); + g_pLayerList->Insert(l_pLayer); + } + } else { + l_pLayer = new ODLayer(); + l_pLayer->m_LayerID = ++g_LayerIdx; + l_pLayer->m_LayerName = l_fn.GetName(); + + wxString destf, f, name, ext; + f = path; + wxFileName::SplitPath(f, NULL, NULL, &name, &ext); + destf = g_PrivateDataDir->ToStdString(); + g_ocpn_draw_pi->appendOSDirSlash(&destf); + destf.Append(_T("Layers")); + g_ocpn_draw_pi->appendOSDirSlash(&destf); + if (!wxDirExists(destf)) { + if (!wxMkdir(destf, wxS_DIR_DEFAULT)) + wxLogMessage(_T("Error creating layer directory")); } - } + destf << name << _T(".") << ext; + wxString msg; + if (wxCopyFile(f, destf, true)) { + msg.Printf( + _T("File: %s.%s also potentially added to persistent layers"), + name, ext); + l_pLayer->m_LayerFileName = destf; + } else + msg.Printf(_T("Failed adding %s.%s to persistent layers"), name, + ext); + wxLogMessage(msg); - if ( s_diff != 0 ) - { - for( int i = g_navobjbackups - 1; i >= 1; i-- ) - { - oldname = wxString::Format( _T("%s.%d"), m_sODNavObjSetFile.c_str(), i ); - newname = wxString::Format( _T("%s.%d"), m_sODNavObjSetFile.c_str(), i + 1 ); - if( wxFile::Exists( oldname ) ) - wxCopyFile( oldname, newname ); + bool bLayerViz = g_bShowLayers; + if (g_VisibleLayers.Contains(l_pLayer->m_LayerName)) + bLayerViz = true; + if (g_InvisibleLayers.Contains(l_pLayer->m_LayerName)) + bLayerViz = false; + l_pLayer->m_bIsVisibleOnChart = bLayerViz; + + ODLayerList::iterator iter; + bool l_foundLayer = false; + for (iter = g_pLayerList->begin(); iter != g_pLayerList->end(); + ++iter) { + ODLayer* current = *iter; + if (current->GetName() == l_pLayer->m_LayerName) { + l_foundLayer = true; + break; + } } - - if( wxFile::Exists( m_sODNavObjSetFile ) ) - { - newname = wxString::Format( _T("%s.1"), m_sODNavObjSetFile.c_str() ); - wxCopyFile( m_sODNavObjSetFile, newname ); + wxString laymsg; + if (l_foundLayer) { + laymsg.Printf(wxT("Layer %d: %s is a duplicate, not added"), + l_pLayer->m_LayerID, l_pLayer->m_LayerName.c_str()); + wxLogMessage(laymsg); + continue; + } else { + laymsg.Printf(wxT("New layer %d: %s"), l_pLayer->m_LayerID, + l_pLayer->m_LayerName.c_str()); + wxLogMessage(laymsg); } + + g_pLayerList->Insert(l_pLayer); + } } + + ODNavObjectChanges* pSet = new ODNavObjectChanges; + if (l_fn.GetExt() == _T("csv")) { + if (l_pLayer) { + l_pLayer->m_NoOfItems += + pSet->Load_CSV_File(path.fn_str(), l_pLayer->m_LayerID, + l_pLayer->m_bIsVisibleOnChart); + } else { + pSet->Load_CSV_File(path.fn_str(), 0, true); + } + } else if (l_fn.GetExt() == _T("gpx")) { + pSet->load_file(path.fn_str()); + if (islayer) { + l_pLayer->m_NoOfItems += pSet->LoadAllGPXObjectsAsLayer( + l_pLayer->m_LayerID, l_pLayer->m_bIsVisibleOnChart); + } else + pSet->LoadAllGPXObjects( + true); // Import with full vizibility of names and objects + } + + delete pSet; + } } - //try to clean the backups the user doesn't want - breaks if he deleted some by hand as it tries to be effective... - for( int i = g_navobjbackups + 1; i <= 99; i++ ) - if( wxFile::Exists( wxString::Format( _T("%s.%d"), m_sODNavObjSetFile.c_str(), i ) ) ) - ::wxRemoveFile( wxString::Format( _T("%s.%d"), m_sODNavObjSetFile.c_str(), i ) ); - else - break; + + // make sure any EBL hanging of the boat is repositioned + wxEBLListNode* node = g_pEBLList->GetFirst(); + for (size_t i = 0; i < g_pEBLList->GetCount(); i++) { + EBL* ebl = (EBL*)node->GetData(); + if (ebl->m_bCentreOnBoat) { + bool l_bSaveUpdatesState = ebl->m_bSaveUpdates; + ebl->m_bSaveUpdates = false; + ebl->CentreOnBoat(true); + ebl->m_bSaveUpdates = l_bSaveUpdatesState; + } + node = node->GetNext(); + } + } +} + +void ODConfig::CreateRotatingNavObjBackup() { + // Rotate navobj backups, but just in case there are some changes in the + // current version to prevent the user trying to "fix" the problem by + // continuously starting the application to overwrite all of his good + // backups... + if (g_navobjbackups > 0) { + wxFile f; + wxString oldname = m_sODNavObjSetFile; + wxString newname = wxString::Format(_T("%s.1"), m_sODNavObjSetFile.c_str()); + + wxFileOffset s_diff = 1; + if (wxFileExists(newname)) { + if (f.Open(oldname)) { + s_diff = f.Length(); + f.Close(); + } + + if (f.Open(newname)) { + s_diff -= f.Length(); + f.Close(); + } + } + + if (s_diff != 0) { + for (int i = g_navobjbackups - 1; i >= 1; i--) { + oldname = wxString::Format(_T("%s.%d"), m_sODNavObjSetFile.c_str(), i); + newname = + wxString::Format(_T("%s.%d"), m_sODNavObjSetFile.c_str(), i + 1); + if (wxFile::Exists(oldname)) wxCopyFile(oldname, newname); + } + + if (wxFile::Exists(m_sODNavObjSetFile)) { + newname = wxString::Format(_T("%s.1"), m_sODNavObjSetFile.c_str()); + wxCopyFile(m_sODNavObjSetFile, newname); + } + } + } + // try to clean the backups the user doesn't want - breaks if he deleted some + // by hand as it tries to be effective... + for (int i = g_navobjbackups + 1; i <= 99; i++) + if (wxFile::Exists( + wxString::Format(_T("%s.%d"), m_sODNavObjSetFile.c_str(), i))) + ::wxRemoveFile( + wxString::Format(_T("%s.%d"), m_sODNavObjSetFile.c_str(), i)); + else + break; } -bool ODConfig::ODPointIsInPathList( ODPoint *podp ) -{ - bool IsInList = false; +bool ODConfig::ODPointIsInPathList(ODPoint* podp) { + bool IsInList = false; - wxPathListNode *node1 = g_pPathList->GetFirst(); - while( node1 ) { - ODPath *pPath = node1->GetData(); - ODPointList *pODPointList = pPath->m_pODPointList; + wxPathListNode* node1 = g_pPathList->GetFirst(); + while (node1) { + ODPath* pPath = node1->GetData(); + ODPointList* pODPointList = pPath->m_pODPointList; - wxODPointListNode *node2 = pODPointList->GetFirst(); - ODPoint *ppodp; + wxODPointListNode* node2 = pODPointList->GetFirst(); + ODPoint* ppodp; - while( node2 ) { - ppodp = node2->GetData(); + while (node2) { + ppodp = node2->GetData(); - if( podp->IsSame( ppodp ) ) { - IsInList = true; - break; - } + if (podp->IsSame(ppodp)) { + IsInList = true; + break; + } - node2 = node2->GetNext(); - } - node1 = node1->GetNext(); + node2 = node2->GetNext(); } - return IsInList; + node1 = node1->GetNext(); + } + return IsInList; } -