//--------------------------------------------------------- bool CWRF_Import::On_Execute(void) { CSG_String File; //----------------------------------------------------- File = Parameters("FILE") ->asString(); Parameters("GRIDS")->asGridList()->Del_Items(); //----------------------------------------------------- if( !m_Index.Load(SG_File_Make_Path(SG_File_Get_Path(File), SG_T("index"))) ) { Error_Set(_TL("error reading index file")); return( false ); } //----------------------------------------------------- if( !Load(File) ) { Error_Set(_TL("error loading data file")); return( false ); } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- bool DLG_Open(wxString &File_Path, const wxString &Caption, const wxString &def_Dir, const wxString &def_File, const wxString &Filter) { wxString Dir(def_Dir); if( !wxDirExists(def_Dir) ) { CONFIG_Read(CONFIG_GROUP_FILE_DLG, DLG_Get_FILE_Config(-1), Dir); } wxFileDialog dlg(MDI_Get_Top_Window(), Caption, Dir, def_File, Filter, wxFD_OPEN|wxFD_FILE_MUST_EXIST); if( dlg.ShowModal() == wxID_OK ) { File_Path = dlg.GetPath(); if( !wxDirExists(def_Dir) ) { CONFIG_Write(CONFIG_GROUP_FILE_DLG, DLG_Get_FILE_Config(-1), SG_File_Get_Path(File_Path).w_str()); } return( true ); } return( false ); }
//--------------------------------------------------------- bool DLG_Open(wxArrayString &File_Paths, const wxString &Caption, const wxString &def_Dir, const wxString &Filter) { wxString Dir(def_Dir); if( !wxDirExists(def_Dir) ) { CONFIG_Read(CONFIG_GROUP_FILE_DLG, DLG_Get_FILE_Config(-1), Dir); } wxFileDialog dlg(MDI_Get_Top_Window(), Caption, Dir, wxT(""), Filter, wxFD_OPEN|wxFD_FILE_MUST_EXIST|wxFD_MULTIPLE); if( dlg.ShowModal() == wxID_OK ) { dlg.GetPaths(File_Paths); if( File_Paths.GetCount() > 0 ) { if( !wxDirExists(def_Dir) ) { CONFIG_Write(CONFIG_GROUP_FILE_DLG, DLG_Get_FILE_Config(-1), SG_File_Get_Path(File_Paths[0]).w_str()); } return( true ); } } return( false ); }
//--------------------------------------------------------- bool DLG_Image_Save(wxString &File_Path, int &Type, const wxString &def_Dir, const wxString &def_File) { static int Filter_Index = 3; wxString Dir(def_Dir); if( !wxDirExists(def_Dir) ) { CONFIG_Read(CONFIG_GROUP_FILE_DLG, DLG_Get_FILE_Config(-1), Dir); } wxFileDialog dlg( MDI_Get_Top_Window(), _TL("Save As Image"), Dir, def_File, wxString::Format( "%s (*.bmp)|*.bmp|" "%s (*.jpg)|*.jpg;*.jif;*.jpeg|" "%s (*.tif)|*.tif;*.tiff|" "%s (*.png)|*.png|" "%s (*.gif)|*.gif|" "%s (*.pcx)|*.pcx", _TL("Windows or OS/2 Bitmap"), _TL("JPEG - JFIF Compliant"), _TL("Tagged Image File Format"), _TL("Portable Network Graphics"), _TL("CompuServe Graphics Interchange"), _TL("Zsoft Paintbrush") ), wxFD_SAVE|wxFD_OVERWRITE_PROMPT ); dlg.SetFilterIndex(Filter_Index); if( dlg.ShowModal() == wxID_OK ) { File_Path = dlg.GetPath(); Filter_Index = dlg.GetFilterIndex(); switch( Filter_Index ) { default: Type = wxBITMAP_TYPE_BMP ; break; case 1: Type = wxBITMAP_TYPE_JPEG; break; case 2: Type = wxBITMAP_TYPE_TIF ; break; case 3: Type = wxBITMAP_TYPE_PNG ; break; case 4: Type = wxBITMAP_TYPE_GIF ; break; case 5: Type = wxBITMAP_TYPE_PCX ; break; case 6: Type = wxBITMAP_TYPE_PNM ; break; } if( !wxDirExists(def_Dir) ) { CONFIG_Write(CONFIG_GROUP_FILE_DLG, DLG_Get_FILE_Config(-1), SG_File_Get_Path(File_Path).w_str()); } return( true ); } return( false ); }
//--------------------------------------------------------- bool CSG_Module_Library::Create(const CSG_String &File_Name) { Destroy(); TSG_PFNC_MLB_Initialize MLB_Initialize; TSG_PFNC_MLB_Get_Interface MLB_Get_Interface; wxString sPath; wxFileName fName(File_Name.c_str()); fName.MakeAbsolute(); m_File_Name = fName.GetFullPath(); //----------------------------------------------------- if( wxGetEnv(ENV_LIB_PATH, &sPath) && sPath.Length() > 0 ) { wxSetEnv(ENV_LIB_PATH, CSG_String::Format(SG_T("%s%c%s"), sPath.c_str(), ENV_LIB_SEPA, SG_File_Get_Path(m_File_Name).c_str())); } else { wxSetEnv(ENV_LIB_PATH, SG_File_Get_Path(m_File_Name).c_str()); } //----------------------------------------------------- if( m_pLibrary->Load(m_File_Name.c_str()) && (MLB_Get_Interface = (TSG_PFNC_MLB_Get_Interface) m_pLibrary->GetSymbol(SYMBOL_MLB_Get_Interface)) != NULL && (MLB_Initialize = (TSG_PFNC_MLB_Initialize) m_pLibrary->GetSymbol(SYMBOL_MLB_Initialize) ) != NULL && MLB_Initialize(m_File_Name) ) { m_pInterface = MLB_Get_Interface(); } //----------------------------------------------------- if( sPath.Length() > 0 ) { wxSetEnv(ENV_LIB_PATH, sPath); } else { wxUnsetEnv(ENV_LIB_PATH); } //----------------------------------------------------- if( Get_Count() > 0 ) { for(int i=0; i<Get_Count(); i++) Get_Module(i)->Set_Managed(false); return( true ); } Destroy(); return( false ); }
//--------------------------------------------------------- bool CWKSP_Project::_Compatibility_Load_Data(const wxString &FileName) { CSG_String sLine; CSG_File Stream; if( !Stream.Open(&FileName, SG_FILE_R, true) ) { return( false ); } //------------------------------------------------- while( Stream.Read_Line(sLine) && sLine.Cmp(DATA_ENTRIES_BEGIN) ); if( sLine.Cmp(DATA_ENTRIES_BEGIN) ) { return( false ); } g_pSAGA_Frame->Freeze(); g_pData->Get_Menu_Files()->Set_Update(false); while( _Compatibility_Load_Data(Stream, SG_File_Get_Path(&FileName).w_str()) ); g_pData->Get_Menu_Files()->Set_Update(true); //------------------------------------------------- while( Stream.Read_Line(sLine) && sLine.Cmp(MAP_ENTRIES_BEGIN) ); if( !sLine.Cmp(MAP_ENTRIES_BEGIN) ) { while( _Compatibility_Load_Map(Stream, SG_File_Get_Path(&FileName).w_str()) ); } switch( g_pData->Get_Parameter("PROJECT_MAP_ARRANGE")->asInt() ) { case 1: g_pSAGA_Frame->Tile(wxHORIZONTAL); break; case 2: g_pSAGA_Frame->Tile(wxVERTICAL ); break; } g_pSAGA_Frame->Thaw(); return( true ); }
//--------------------------------------------------------- int CSurfer_Export::On_Parameter_Changed(CSG_Parameters *pParameters, CSG_Parameter *pParameter) { if( pParameter->Cmp_Identifier("GRID") && pParameter->asGrid() ) { CSG_String Path(SG_File_Get_Path((*pParameters)["FILE"].asString())); pParameters->Set_Parameter("FILE", SG_File_Make_Path(Path, pParameter->asGrid()->Get_Name(), "grd")); } return( CSG_Tool_Grid::On_Parameter_Changed(pParameters, pParameter) ); }
bool DLG_Save(wxString &File_Path, int ID_DLG) { wxString def_Dir, def_Name; def_Name = SG_File_Get_Name(File_Path, true).w_str(); def_Dir = SG_File_Get_Path(File_Path).w_str(); if( !wxDirExists(def_Dir) ) { CONFIG_Read(CONFIG_GROUP_FILE_DLG, DLG_Get_FILE_Config(ID_DLG), def_Dir); } if( DLG_Save(File_Path, DLG_Get_FILE_Caption(ID_DLG), def_Dir, def_Name, DLG_Get_FILE_Filter(ID_DLG)) ) { CONFIG_Write(CONFIG_GROUP_FILE_DLG, DLG_Get_FILE_Config(ID_DLG), SG_File_Get_Path(File_Path).w_str()); return( true ); } return( false ); }
bool DLG_Open(wxArrayString &File_Paths, int ID_DLG) { wxString def_Dir; CONFIG_Read(CONFIG_GROUP_FILE_DLG, DLG_Get_FILE_Config(ID_DLG), def_Dir); if( DLG_Open(File_Paths, DLG_Get_FILE_Caption(ID_DLG), def_Dir, DLG_Get_FILE_Filter(ID_DLG)) ) { CONFIG_Write(CONFIG_GROUP_FILE_DLG, DLG_Get_FILE_Config(ID_DLG), SG_File_Get_Path(File_Paths[0]).w_str()); return( true ); } return( false ); }
//--------------------------------------------------------- CSG_String SG_File_Make_Path(const SG_Char *Directory, const SG_Char *Name, const SG_Char *Extension) { wxFileName fn; fn.AssignDir(Directory && *Directory ? Directory : SG_File_Get_Path(Name).c_str()); if( Extension && *Extension ) { fn.SetName (SG_File_Get_Name(Name, false).c_str()); fn.SetExt (Extension); } else { fn.SetFullName (SG_File_Get_Name(Name, true).c_str()); } return( fn.GetFullPath().c_str() ); }
//--------------------------------------------------------- bool CSG_Grid::_Load_Native(const CSG_String &File_Name, TSG_Grid_Memory_Type Memory_Type) { bool bResult, hdr_bFlip, hdr_bSwapBytes; int iType, hdr_Offset, NX, NY; double Cellsize, xMin, yMin; CSG_File Stream; TSG_Data_Type hdr_Type; CSG_Grid_System System; CSG_String File_Data, Value; //----------------------------------------------------- bResult = false; if( Stream.Open(File_Name, SG_FILE_R, false) ) { //------------------------------------------------- // Load Header... hdr_Type = SG_DATATYPE_Undefined; hdr_Offset = 0; hdr_bFlip = false; hdr_bSwapBytes = false; NX = NY = 0; Cellsize = 0.0; xMin = 0.0; yMin = 0.0; //------------------------------------------------- do { switch( _Load_Native_Get_Key(Stream, Value) ) { case GRID_FILE_KEY_NAME: Set_Name (Value); break; case GRID_FILE_KEY_DESCRIPTION: Set_Description (Value); break; case GRID_FILE_KEY_UNITNAME: Set_Unit (Value); break; case GRID_FILE_KEY_CELLCOUNT_X: NX = Value.asInt(); break; case GRID_FILE_KEY_CELLCOUNT_Y: NY = Value.asInt(); break; case GRID_FILE_KEY_POSITION_XMIN: xMin = Value.asDouble(); break; case GRID_FILE_KEY_POSITION_YMIN: yMin = Value.asDouble(); break; case GRID_FILE_KEY_CELLSIZE: Cellsize = Value.asDouble(); break; case GRID_FILE_KEY_Z_FACTOR: m_zFactor = Value.asDouble(); break; case GRID_FILE_KEY_NODATA_VALUE: Set_NoData_Value(Value.asDouble()); break; case GRID_FILE_KEY_DATAFILE_OFFSET: hdr_Offset = Value.asInt(); break; case GRID_FILE_KEY_BYTEORDER_BIG: hdr_bSwapBytes = Value.Find(GRID_FILE_KEY_TRUE) >= 0; break; case GRID_FILE_KEY_TOPTOBOTTOM: hdr_bFlip = Value.Find(GRID_FILE_KEY_TRUE) >= 0; break; case GRID_FILE_KEY_DATAFILE_NAME: if( SG_File_Get_Path(Value).Length() > 0 ) { File_Data = Value; } else { File_Data = SG_File_Make_Path(SG_File_Get_Path(File_Name), Value); } break; case GRID_FILE_KEY_DATAFORMAT: for(iType=0; iType<SG_DATATYPE_Undefined && hdr_Type == SG_DATATYPE_Undefined; iType++) { if( Value.Find(gSG_Data_Type_Identifier[iType]) >= 0 ) { hdr_Type = (TSG_Data_Type)iType; } } break; } } while( !Stream.is_EOF() ); //------------------------------------------------- // Load Data... if( m_System.Assign(Cellsize, xMin, yMin, NX, NY) ) { //--------------------------------------------- // ASCII... if( !SG_Data_Type_is_Numeric(hdr_Type) ) { if( m_Type >= SG_DATATYPE_Undefined ) { m_Type = SG_DATATYPE_Float; } if( Stream.Open(File_Data , SG_FILE_R, false) || Stream.Open(SG_File_Make_Path(NULL, File_Name, SG_T( "dat")) , SG_FILE_R, false) || Stream.Open(SG_File_Make_Path(NULL, File_Name, SG_T("sdat")) , SG_FILE_R, false) ) { Stream.Seek(hdr_Offset); bResult = _Load_ASCII(Stream, Memory_Type, hdr_bFlip); } } //--------------------------------------------- // Binary... else { if( m_Type >= SG_DATATYPE_Undefined ) { m_Type = hdr_Type; } if( (NX = SG_Grid_Cache_Check(m_System, Get_nValueBytes())) > 0 ) { Set_Buffer_Size(NX); if( _Cache_Create(File_Data , hdr_Type, hdr_Offset, hdr_bSwapBytes, hdr_bFlip) || _Cache_Create(SG_File_Make_Path(NULL, File_Name, SG_T( "dat")) , hdr_Type, hdr_Offset, hdr_bSwapBytes, hdr_bFlip) || _Cache_Create(SG_File_Make_Path(NULL, File_Name, SG_T("sdat")) , hdr_Type, hdr_Offset, hdr_bSwapBytes, hdr_bFlip) ) { return( true ); } Memory_Type = GRID_MEMORY_Cache; } if( _Memory_Create(Memory_Type) ) { if( Stream.Open(File_Data , SG_FILE_R, true) || Stream.Open(SG_File_Make_Path(NULL, File_Name, SG_T( "dat")) , SG_FILE_R, true) || Stream.Open(SG_File_Make_Path(NULL, File_Name, SG_T("sdat")) , SG_FILE_R, true) ) { Stream.Seek(hdr_Offset); bResult = _Load_Binary(Stream, hdr_Type, hdr_bFlip, hdr_bSwapBytes); } } } } } return( bResult ); }
bool DLG_Open(wxString &File_Path, const wxString &Caption, const wxString &Filter) { return( DLG_Open(File_Path, Caption, SG_File_Get_Path(File_Path).w_str(), SG_File_Get_Name(File_Path, true).w_str(), Filter) ); }
bool DLG_Directory(wxString &Directory, const wxString &Caption) { return( DLG_Directory(Directory, Caption, SG_File_Get_Path(Directory).w_str()) ); }
//--------------------------------------------------------- void CWKSP_Module_Manager::_Make_HTML_Docs(void) { CSG_Parameters Options(NULL, LNG("Create HTML Documentation"), LNG("")); Options.Add_FilePath(NULL, "DIR", LNG("Choose Documentation Folder"), LNG(""), NULL, NULL, true, true); if( !DLG_Parameters(&Options) ) { return; } //----------------------------------------------------- bool bDirectory; CSG_File Stream_Module, Stream_Lib, Stream_Libs, Stream_List; wxString LibName, Directory, Main, s; wxFileName FileName; MSG_General_Add(wxString::Format(wxT("%s..."), LNG("Creating module documentation files")), true, true); bDirectory = wxDirExists(Options("DIR")->asString()); Directory = bDirectory ? Options("DIR")->asString() : SG_File_Get_Path(g_pSAGA->Get_App_Path()).c_str(); //----------------------------------------------------- FileName.AssignDir (Directory); FileName.SetExt (wxT("html")); FileName.SetName (wxT("index")); Stream_Libs.Open(FileName.GetFullPath().c_str(), SG_FILE_W, false); Stream_Libs.Printf(SG_T("<html><head><title>SAGA - System for Automated Geoscientific Analyses</title></head><body>")); Stream_Libs.Printf(SG_T("<h1><a href=\"http://www.saga-gis.org\">SAGA - System for Automated Geoscientific Analyses</a></h1>")); Stream_Libs.Printf(SG_T("<h2>%s</h2>\n<ul>\n"), LNG("Module Library Descriptions")); Main = FileName.GetFullPath(); //----------------------------------------------------- for(int i=0; i<Get_Count() && PROGRESSBAR_Set_Position(i, Get_Count()); i++) { LibName = SG_File_Get_Name(Get_Library(i)->Get_File_Name(), false).c_str(); FileName.AssignDir (bDirectory ? Directory.c_str() : SG_File_Get_Path(Get_Library(i)->Get_File_Name()).c_str()); FileName.AppendDir (LibName); FileName.SetExt (wxT("html")); if( wxDirExists(FileName.GetPath()) || wxMkdir(FileName.GetPath()) ) { //--------------------------------------------- // create a frame FileName.SetName(wxT("index")); if( Stream_Lib.Open(FileName.GetFullPath().c_str(), SG_FILE_W, false) ) { if( Stream_Libs.is_Open() ) { s = Get_FilePath_Relative(Directory.c_str(), FileName.GetFullPath().c_str()).c_str(); if( s[0] == '\\' ) s = s.AfterFirst('\\'); if(s[0]=='/') s = s.AfterFirst('/'); Stream_Libs.Printf(wxT("<li><a href=\"%s\">%s</a></li>\n"), s.c_str(), Get_Library(i)->Get_Name().c_str()); } Stream_Lib.Printf(SG_T("<html><head><title>SAGA - System for Automated Geoscientific Analyses</title></head>")); Stream_Lib.Printf(SG_T("<frameset cols=\"200,*\" frameborder=\"0\" framespacing=\"0\" border=\"0\">")); Stream_Lib.Printf(SG_T(" <frame frameborder=\"0\" noresize src=\"modules.html\" name=\"MODULES\">")); Stream_Lib.Printf(SG_T(" <frame frameborder=\"0\" noresize src=\"%s.html\" name=\"CONTENT\">") , LibName.c_str()); Stream_Lib.Printf(SG_T("</frameset></html>")); } //--------------------------------------------- // write the modules if( bDirectory ) s = wxT("./../index"); else s = Get_FilePath_Relative(Main.c_str(), FileName.GetFullPath().c_str()).c_str(); if( s[0] == '\\' ) s = s.AfterFirst('\\'); if(s[0]=='/') s = s.AfterFirst('/'); FileName.SetName(wxT("modules")); Stream_List.Open(FileName.GetFullPath().c_str(), SG_FILE_W, false); Stream_List.Printf(SG_T("<body bgcolor=\"#CCCCCC\">")); Stream_List.Printf(SG_T("<b><a target=\"_top\" href=\"http://www.saga-gis.org\">SAGA</a></b><hr>")); Stream_List.Printf(SG_T("<b><a target=\"_top\" href=\"%s.html\">%s</a></b><hr>"), s.c_str(), LNG("Library Overview")); Stream_List.Printf(SG_T("<b><a target=\"CONTENT\" href=\"%s.html\">%s</a></b><hr><ul>"), LibName.c_str(), Get_Library(i)->Get_Name().c_str()); FileName.SetName(LibName); if( Stream_Lib.Open(FileName.GetFullPath().c_str(), SG_FILE_W, false) ) { Stream_Lib.Printf(wxT("%s<hr><ul>"), Get_Library(i)->Get_Description().c_str()); for(int j=0; j<Get_Library(i)->Get_Count(); j++) { FileName.SetName(wxString::Format(wxT("%s_%02d"), LibName.c_str(), Get_Library(i)->Get_Module(j)->Get_Index())); if( Stream_Module.Open(FileName.GetFullPath().c_str(), SG_FILE_W, false) ) { Stream_Module.Printf(wxT("%s"), Get_Library(i)->Get_Module(j)->Get_Description().c_str()); Stream_Lib .Printf(wxT("<li><a target=\"CONTENT\" href=\"%s\">%s</a></li>"), FileName.GetFullName().c_str(), Get_Library(i)->Get_Module(j)->Get_Name().c_str()); Stream_List.Printf(wxT("<li><a target=\"CONTENT\" href=\"%s\">%s</a></li>"), FileName.GetFullName().c_str(), Get_Library(i)->Get_Module(j)->Get_Name().c_str()); } } } } } //----------------------------------------------------- if( Stream_Libs.is_Open() ) { Stream_Libs.Printf(wxT("</ul>")); } PROCESS_Set_Okay(true); MSG_General_Add(LNG("okay"), false, false, SG_UI_MSG_STYLE_SUCCESS); }
//--------------------------------------------------------- bool CWKSP_Project::_Load(const wxString &FileName, bool bAdd, bool bUpdateMenu) { if( wxFileExists(FileName) && !bAdd && g_pData->Get_Count() > 0 ) { switch( DLG_Message_YesNoCancel(_TL("Close all data sets"), _TL("Load Project")) ) { case 0: if( !g_pData->Close(true) ) return( false ); break; case 2: return( false ); } } //------------------------------------------------- MSG_General_Add_Line(); MSG_General_Add(wxString::Format("%s: %s", _TL("Load project"), FileName), true, true); //------------------------------------------------- bool bSuccess = false; CSG_MetaData Project, *pNode; if( _Compatibility_Load_Data(FileName) ) { bSuccess = true; } else if( !wxFileExists(FileName) ) { MSG_Error_Add(_TL("file does not exist." ), true, true, SG_UI_MSG_STYLE_FAILURE); } else if( !Project.Load(&FileName) ) { MSG_Error_Add(_TL("could not read project file." ), true, true, SG_UI_MSG_STYLE_FAILURE); } else if( Project.Get_Name().CmpNoCase("SAGA_PROJECT") ) { MSG_Error_Add(_TL("invalid project file." ), true, true, SG_UI_MSG_STYLE_FAILURE); } else if( (pNode = Project.Get_Child("DATA")) == NULL || pNode->Get_Children_Count() <= 0 ) { MSG_Error_Add(_TL("no data entries in project file."), true, true, SG_UI_MSG_STYLE_FAILURE); } else if( !_Load_DBConnections(*pNode) ) { MSG_Error_Add(_TL("could not connect to database." ), true, true, SG_UI_MSG_STYLE_FAILURE); } else { int i; CSG_String Version(Project.Get_Property("VERSION")); bSuccess = true; //------------------------------------------------- g_pData->Get_Menu_Files()->Set_Update(false); for(i=0; i<pNode->Get_Children_Count(); i++) { _Load_Data(*pNode->Get_Child(i), SG_File_Get_Path(&FileName).w_str(), true , Version); } for(i=0; i<pNode->Get_Children_Count(); i++) { _Load_Data(*pNode->Get_Child(i), SG_File_Get_Path(&FileName).w_str(), false, Version); } g_pData->Get_Menu_Files()->Set_Update(true); //------------------------------------------------- g_pSAGA_Frame->Freeze(); if( (pNode = Project.Get_Child("MAPS")) != NULL && pNode->Get_Children_Count() > 0 ) { for(int j=0; j<pNode->Get_Children_Count(); j++) { _Load_Map(*pNode->Get_Child(j), SG_File_Get_Path(&FileName).w_str()); } } switch( g_pData->Get_Parameter("PROJECT_MAP_ARRANGE")->asInt() ) { case 1: g_pSAGA_Frame->Tile(wxHORIZONTAL); break; case 2: g_pSAGA_Frame->Tile(wxVERTICAL ); break; } g_pSAGA_Frame->Thaw(); } //----------------------------------------------------- if( bSuccess ) { if( bUpdateMenu ) { g_pData->Get_Menu_Files()->Recent_Add(SG_DATAOBJECT_TYPE_Undefined, FileName); } MSG_General_Add(_TL("Project has been successfully loaded."), true, true, SG_UI_MSG_STYLE_SUCCESS); m_File_Name = FileName; _Set_Project_Name(); return( true ); } if( bUpdateMenu ) { g_pData->Get_Menu_Files()->Recent_Del(SG_DATAOBJECT_TYPE_Undefined, FileName); } MSG_General_Add(_TL("Could not load project."), true, true, SG_UI_MSG_STYLE_FAILURE); return( false ); }
bool DLG_Save(wxString &File_Path, const wxChar *Caption, const wxChar *Filter) { return( DLG_Save(File_Path, Caption, SG_File_Get_Path(File_Path), SG_File_Get_Name(File_Path, true), Filter) ); }
bool CGPX2SHP::On_Execute(void) { CSG_String sCmd; CSG_String sFile = Parameters("FILE")->asString(); CSG_String sBasePath = Parameters("BASEPATH")->asString(); CSG_String sShapefile; bool bWaypoints = Parameters("WAYPOINTS")->asBool(); bool bTrackpoints = Parameters("TRACKPOINTS")->asBool(); bool bRoutes = Parameters("ROUTES")->asBool(); bool bAdd = Parameters("ADD")->asBool(); CSG_Shapes *pShapes; sCmd = sBasePath + SG_T("\\gpx2shp "); if (bWaypoints) { sCmd += SG_T("-w "); }//if if (bTrackpoints) { sCmd += SG_T("-t "); }//if if (bRoutes) { sCmd += SG_T("-r "); }//if sCmd += sFile; system(sCmd.b_str()); if( bAdd ) { CSG_String sDir(SG_File_Get_Path(sFile)), sName(SG_File_Get_Name(sFile, false)); //------------------------------------------------- sFile = SG_File_Make_Path(sDir, sName + SG_T("_wpt"), SG_T("shp")); pShapes = SG_Create_Shapes(sFile); if( pShapes->is_Valid() ) DataObject_Add(pShapes, false); else delete(pShapes); //------------------------------------------------- sFile = SG_File_Make_Path(sDir, sName + SG_T("_trk"), SG_T("shp")); pShapes = SG_Create_Shapes(sFile); if( pShapes->is_Valid() ) DataObject_Add(pShapes, false); else delete(pShapes); //------------------------------------------------- sFile = SG_File_Make_Path(sDir, sName + SG_T("_rte"), SG_T("shp")); pShapes = SG_Create_Shapes(sFile); if( pShapes->is_Valid() ) DataObject_Add(pShapes, false); else delete(pShapes); }//if return true; }//method
//--------------------------------------------------------- bool CWKSP_Project::_Save(const wxString &FileName, bool bSaveModified, bool bUpdateMenu) { int i, j; wxString ProjectDir, oldFileName(m_File_Name); CSG_MetaData Project, *pNode; CWKSP_Table_Manager *pTables; CWKSP_Shapes_Manager *pShapes; CWKSP_TIN_Manager *pTINs; CWKSP_PointCloud_Manager *pPointClouds; CWKSP_Grid_Manager *pGrids; //----------------------------------------------------- m_File_Name = FileName; if( bSaveModified && !g_pData->Save_Modified() ) { m_File_Name = oldFileName; return( false ); } //----------------------------------------------------- ProjectDir = SG_File_Get_Path(&FileName).w_str(); Project.Set_Name ("SAGA_PROJECT"); Project.Add_Property("VERSION", SAGA_VERSION); //----------------------------------------------------- pNode = Project.Add_Child("DATA"); if( (pTables = g_pData->Get_Tables()) != NULL ) { for(i=0; i<pTables->Get_Count(); i++) { _Save_Data(*pNode, ProjectDir, pTables->Get_Data(i)->Get_Object(), pTables->Get_Data(i)->Get_Parameters() ); } } if( (pTINs = g_pData->Get_TINs()) != NULL ) { for(i=0; i<pTINs->Get_Count(); i++) { _Save_Data(*pNode, ProjectDir, pTINs->Get_Data(i)->Get_Object(), pTINs->Get_Data(i)->Get_Parameters() ); } } if( (pPointClouds = g_pData->Get_PointClouds()) != NULL ) { for(i=0; i<pPointClouds->Get_Count(); i++) { _Save_Data(*pNode, ProjectDir, pPointClouds->Get_Data(i)->Get_Object(), pPointClouds->Get_Data(i)->Get_Parameters() ); } } if( (pShapes = g_pData->Get_Shapes()) != NULL ) { for(j=0; j<pShapes->Get_Count(); j++) { for(i=0; i<pShapes->Get_Shapes_Type(j)->Get_Count(); i++) { _Save_Data(*pNode, ProjectDir, pShapes->Get_Shapes_Type(j)->Get_Data(i)->Get_Object(), pShapes->Get_Shapes_Type(j)->Get_Data(i)->Get_Parameters() ); } } } if( (pGrids = g_pData->Get_Grids()) != NULL ) { for(j=0; j<pGrids->Get_Count(); j++) { for(i=0; i<pGrids->Get_System(j)->Get_Count(); i++) { _Save_Data(*pNode, ProjectDir, ((CWKSP_Data_Item *)pGrids->Get_System(j)->Get_Item(i))->Get_Object(), ((CWKSP_Data_Item *)pGrids->Get_System(j)->Get_Item(i))->Get_Parameters() ); } } } //----------------------------------------------------- if( g_pMaps->Get_Count() > 0 ) { pNode = Project.Add_Child("MAPS"); for(i=0; i<g_pMaps->Get_Count(); i++) { _Save_Map(*pNode, ProjectDir, g_pMaps->Get_Map(i)); } } //----------------------------------------------------- if( Project.Save(&FileName) ) { m_File_Name = FileName; if( bUpdateMenu ) g_pData->Get_Menu_Files()->Recent_Add(SG_DATAOBJECT_TYPE_Undefined, FileName); MSG_General_Add(_TL("Project has been saved."), true, true, SG_UI_MSG_STYLE_SUCCESS); _Set_Project_Name(); PROGRESSBAR_Set_Position(0); return( true ); } m_File_Name.Clear(); if( bUpdateMenu ) g_pData->Get_Menu_Files()->Recent_Del(SG_DATAOBJECT_TYPE_Undefined, FileName); MSG_General_Add(_TL("Could not save project."), true, true, SG_UI_MSG_STYLE_FAILURE); PROGRESSBAR_Set_Position(0); return( false ); }
//--------------------------------------------------------- bool CPointCloud_Create_Tileshape_From_SPCVF::On_Execute(void) { CSG_String sFileName; CSG_Shapes *pShapes; CSG_MetaData SPCVF; CSG_String sPathSPCVF, sFilePath; int iPoints; double dBBoxXMin, dBBoxYMin, dBBoxXMax, dBBoxYMax; //----------------------------------------------------- sFileName = Parameters("FILENAME")->asString(); pShapes = Parameters("TILE_SHP")->asShapes(); //----------------------------------------------------- if( !SPCVF.Create(sFileName) || SPCVF.Get_Name().CmpNoCase(SG_T("SPCVFDataset")) ) { SG_UI_Msg_Add_Error(_TL("Please provide a valid *.scpvf file!")); return( false ); } //----------------------------------------------------- CSG_String sMethodPaths; SPCVF.Get_Property(SG_T("Paths"), sMethodPaths); if( !sMethodPaths.CmpNoCase(SG_T("absolute")) ) { sPathSPCVF = SG_T(""); } else if( !sMethodPaths.CmpNoCase(SG_T("relative")) ) { sPathSPCVF = SG_File_Get_Path(sFileName); sPathSPCVF.Replace(SG_T("\\"), SG_T("/")); } else { SG_UI_Msg_Add_Error(_TL("Encountered invalid path description in *.spcvf file!")); return( false ); } //----------------------------------------------------- pShapes->Destroy(); pShapes->Add_Field(_TL("ID"), SG_DATATYPE_Int); pShapes->Add_Field(_TL("Filepath"), SG_DATATYPE_String); pShapes->Add_Field(_TL("File"), SG_DATATYPE_String); pShapes->Add_Field(_TL("Points"), SG_DATATYPE_Int); pShapes->Set_Name(CSG_String::Format(_TL("Tileshape_%s"), SG_File_Get_Name(sFileName, false).c_str())); //----------------------------------------------------- CSG_MetaData *pDatasets = SPCVF.Get_Child(SG_T("Datasets")); for(int i=0; i<pDatasets->Get_Children_Count(); i++) { CSG_MetaData *pDataset = pDatasets->Get_Child(i); CSG_MetaData *pBBox = pDataset->Get_Child(SG_T("BBox")); pDataset->Get_Property(SG_T("File"), sFilePath); pDataset->Get_Property(SG_T("Points"), iPoints); pBBox->Get_Property(SG_T("XMin"), dBBoxXMin); pBBox->Get_Property(SG_T("YMin"), dBBoxYMin); pBBox->Get_Property(SG_T("XMax"), dBBoxXMax); pBBox->Get_Property(SG_T("YMax"), dBBoxYMax); //----------------------------------------------------- CSG_Shape *pShape = pShapes->Add_Shape(); pShape->Add_Point(dBBoxXMin, dBBoxYMin); pShape->Add_Point(dBBoxXMin, dBBoxYMax); pShape->Add_Point(dBBoxXMax, dBBoxYMax); pShape->Add_Point(dBBoxXMax, dBBoxYMin); pShape->Set_Value(0, i + 1); if( sPathSPCVF.Length() == 0 ) // absolute paths { pShape->Set_Value(1, sFilePath.BeforeLast('/')); pShape->Set_Value(2, sFilePath.AfterLast('/')); } else // relative paths { pShape->Set_Value(1, sPathSPCVF); pShape->Set_Value(2, sFilePath); } pShape->Set_Value(3, iPoints); } //----------------------------------------------------- return( true ); }
//--------------------------------------------------------- bool CPointCloud_Create_SPCVF::On_Execute(void) { CSG_Strings sFiles; CSG_String sFileInputList, sFileName; int iMethodPaths; CSG_MetaData SPCVF; CSG_Projection projSPCVF; double dNoData; std::vector<TSG_Data_Type> vFieldTypes; std::vector<CSG_String> vFieldNames; double dBBoxXMin = std::numeric_limits<int>::max(); double dBBoxYMin = std::numeric_limits<int>::max(); double dBBoxXMax = std::numeric_limits<int>::min(); double dBBoxYMax = std::numeric_limits<int>::min(); int iSkipped = 0, iEmpty = 0; int iDatasetCount = 0; double dPointCount = 0.0; double dZMin = std::numeric_limits<double>::max(); double dZMax = -std::numeric_limits<double>::max(); //----------------------------------------------------- sFileName = Parameters("FILENAME")->asString(); iMethodPaths = Parameters("METHOD_PATHS")->asInt(); sFileInputList = Parameters("INPUT_FILE_LIST")->asString(); //----------------------------------------------------- if( !Parameters("FILES")->asFilePath()->Get_FilePaths(sFiles) && sFileInputList.Length() <= 0 ) { SG_UI_Msg_Add_Error(_TL("Please provide some input files!")); return( false ); } //----------------------------------------------------- if( sFiles.Get_Count() <= 0 ) { CSG_Table *pTable = new CSG_Table(); if( !pTable->Create(sFileInputList, TABLE_FILETYPE_Text_NoHeadLine) ) { SG_UI_Msg_Add_Error(_TL("Input file list could not be opened!")); delete( pTable ); return( false ); } sFiles.Clear(); for (int i=0; i<pTable->Get_Record_Count(); i++) { sFiles.Add(pTable->Get_Record(i)->asString(0)); } delete( pTable ); } //----------------------------------------------------- SPCVF.Set_Name(SG_T("SPCVFDataset")); SPCVF.Add_Property(SG_T("Version"), SG_T("1.1")); switch( iMethodPaths ) { default: case 0: SPCVF.Add_Property(SG_T("Paths"), SG_T("absolute")); break; case 1: SPCVF.Add_Property(SG_T("Paths"), SG_T("relative")); break; } //----------------------------------------------------- CSG_MetaData *pSPCVFHeader = SPCVF.Add_Child( SG_T("Header")); CSG_MetaData *pSPCVFFiles = pSPCVFHeader->Add_Child( SG_T("Datasets")); CSG_MetaData *pSPCVFPoints = pSPCVFHeader->Add_Child( SG_T("Points")); CSG_MetaData *pSRS = pSPCVFHeader->Add_Child( SG_T("SRS")); CSG_MetaData *pSPCVFBBox = pSPCVFHeader->Add_Child( SG_T("BBox")); CSG_MetaData *pSPCVFZStats = pSPCVFHeader->Add_Child( SG_T("ZStats")); CSG_MetaData *pSPCVFNoData = pSPCVFHeader->Add_Child( SG_T("NoData")); CSG_MetaData *pSPCVFAttr = pSPCVFHeader->Add_Child( SG_T("Attributes")); CSG_MetaData *pSPCVFDatasets = NULL; //----------------------------------------------------- for(int i=0; i<sFiles.Get_Count() && Set_Progress(i, sFiles.Get_Count()); i++) { CSG_PointCloud *pPC = SG_Create_PointCloud(sFiles[i]); //----------------------------------------------------- if( i==0 ) // first dataset determines projection, NoData value and table structure { projSPCVF = pPC->Get_Projection(); dNoData = pPC->Get_NoData_Value(); pSPCVFNoData->Add_Property(SG_T("Value"), dNoData); pSPCVFAttr->Add_Property(SG_T("Count"), pPC->Get_Field_Count()); for(int iField=0; iField<pPC->Get_Field_Count(); iField++) { vFieldTypes.push_back(pPC->Get_Field_Type(iField)); vFieldNames.push_back(pPC->Get_Field_Name(iField)); CSG_MetaData *pSPCVFField = pSPCVFAttr->Add_Child(CSG_String::Format(SG_T("Field_%d"), iField + 1)); pSPCVFField->Add_Property(SG_T("Name"), pPC->Get_Field_Name(iField)); pSPCVFField->Add_Property(SG_T("Type"), gSG_Data_Type_Identifier[pPC->Get_Field_Type(iField)]); } if( projSPCVF.is_Okay() ) { pSRS->Add_Property(SG_T("Projection"), projSPCVF.Get_Name()); pSRS->Add_Property(SG_T("WKT"), projSPCVF.Get_WKT()); } else { pSRS->Add_Property(SG_T("Projection"), SG_T("Undefined Coordinate System")); } pSPCVFDatasets = SPCVF.Add_Child(SG_T("Datasets")); } else // validate projection, NoData value and table structure { bool bSkip = false; if( pPC->Get_Field_Count() != (int)vFieldTypes.size() ) { bSkip = true; } if( !bSkip && projSPCVF.is_Okay() ) { if ( !pPC->Get_Projection().is_Okay() || SG_STR_CMP(pPC->Get_Projection().Get_WKT(), projSPCVF.Get_WKT()) ) { bSkip = true; } } if( !bSkip ) { for(int iField=0; iField<pPC->Get_Field_Count(); iField++) { if( pPC->Get_Field_Type(iField) != vFieldTypes.at(iField) ) { bSkip = true; break; } if( SG_STR_CMP(pPC->Get_Field_Name(iField), vFieldNames.at(iField)) ) { bSkip = true; break; } } } if( bSkip ) { SG_UI_Msg_Add(CSG_String::Format(_TL("Skipping dataset %s because of incompatibility with the first input dataset!"), sFiles[i].c_str()), true); delete( pPC ); iSkipped++; continue; } } //----------------------------------------------------- if( pPC->Get_Point_Count() <= 0 ) { delete( pPC ); iEmpty++; continue; } //----------------------------------------------------- CSG_MetaData *pDataset = pSPCVFDatasets->Add_Child(SG_T("PointCloud")); CSG_String sFilePath; switch( iMethodPaths ) { default: case 0: sFilePath = SG_File_Get_Path_Absolute(sFiles.Get_String(i)); break; case 1: sFilePath = SG_File_Get_Path_Relative(SG_File_Get_Path(sFileName), sFiles.Get_String(i)); break; } sFilePath.Replace(SG_T("\\"), SG_T("/")); pDataset->Add_Property(SG_T("File"), sFilePath); pDataset->Add_Property(SG_T("Points"), pPC->Get_Point_Count()); pDataset->Add_Property(SG_T("ZMin"), pPC->Get_ZMin()); pDataset->Add_Property(SG_T("ZMax"), pPC->Get_ZMax()); //----------------------------------------------------- CSG_MetaData *pBBox = pDataset->Add_Child(SG_T("BBox")); pBBox->Add_Property(SG_T("XMin"), pPC->Get_Extent().Get_XMin()); pBBox->Add_Property(SG_T("YMin"), pPC->Get_Extent().Get_YMin()); pBBox->Add_Property(SG_T("XMax"), pPC->Get_Extent().Get_XMax()); pBBox->Add_Property(SG_T("YMax"), pPC->Get_Extent().Get_YMax()); if( dBBoxXMin > pPC->Get_Extent().Get_XMin() ) dBBoxXMin = pPC->Get_Extent().Get_XMin(); if( dBBoxYMin > pPC->Get_Extent().Get_YMin() ) dBBoxYMin = pPC->Get_Extent().Get_YMin(); if( dBBoxXMax < pPC->Get_Extent().Get_XMax() ) dBBoxXMax = pPC->Get_Extent().Get_XMax(); if( dBBoxYMax < pPC->Get_Extent().Get_YMax() ) dBBoxYMax = pPC->Get_Extent().Get_YMax(); iDatasetCount += 1; dPointCount += pPC->Get_Point_Count(); if( dZMin > pPC->Get_ZMin() ) dZMin = pPC->Get_ZMin(); if( dZMax < pPC->Get_ZMax() ) dZMax = pPC->Get_ZMax(); delete( pPC ); } //----------------------------------------------------- pSPCVFBBox->Add_Property(SG_T("XMin"), dBBoxXMin); pSPCVFBBox->Add_Property(SG_T("YMin"), dBBoxYMin); pSPCVFBBox->Add_Property(SG_T("XMax"), dBBoxXMax); pSPCVFBBox->Add_Property(SG_T("YMax"), dBBoxYMax); pSPCVFFiles->Add_Property(SG_T("Count"), iDatasetCount); pSPCVFPoints->Add_Property(SG_T("Count"), CSG_String::Format(SG_T("%.0f"), dPointCount)); pSPCVFZStats->Add_Property(SG_T("ZMin"), dZMin); pSPCVFZStats->Add_Property(SG_T("ZMax"), dZMax); //----------------------------------------------------- if( !SPCVF.Save(sFileName) ) { SG_UI_Msg_Add_Error(CSG_String::Format(_TL("Unable to save %s file!"), sFileName.c_str())); return( false ); } //----------------------------------------------------- if( iSkipped > 0 ) { SG_UI_Msg_Add(CSG_String::Format(_TL("WARNING: %d dataset(s) skipped because of incompatibilities!"), iSkipped), true); } if( iEmpty > 0 ) { SG_UI_Msg_Add(CSG_String::Format(_TL("WARNING: %d dataset(s) skipped because they are empty!"), iEmpty), true); } SG_UI_Msg_Add(CSG_String::Format(_TL("SPCVF successfully created from %d dataset(s)."), iDatasetCount), true); //----------------------------------------------------- return( true ); }