📄 project.cpp
字号:
///////////////////////////////////////////////////////////
// //
// SAGA //
// //
// System for Automated Geoscientific Analyses //
// //
// User Interface //
// //
// Program: SAGA //
// //
//-------------------------------------------------------//
// //
// Project.cpp //
// //
// Copyright (C) 2005 by Olaf Conrad //
// //
//-------------------------------------------------------//
// //
// This file is part of 'SAGA - System for Automated //
// Geoscientific Analyses'. SAGA is free software; you //
// can redistribute it and/or modify it under the terms //
// of the GNU General Public License as published by the //
// Free Software Foundation; version 2 of the License. //
// //
// SAGA is distributed in the hope that it will be //
// useful, but WITHOUT ANY WARRANTY; without even the //
// implied warranty of MERCHANTABILITY or FITNESS FOR A //
// PARTICULAR PURPOSE. See the GNU General Public //
// License for more details. //
// //
// You should have received a copy of the GNU General //
// Public License along with this program; if not, //
// write to the Free Software Foundation, Inc., //
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, //
// USA. //
// //
//-------------------------------------------------------//
// //
// contact: Olaf Conrad //
// Institute of Geography //
// University of Goettingen //
// Goldschmidtstr. 5 //
// 37077 Goettingen //
// Germany //
// //
// e-mail: oconrad@saga-gis.org //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
// $Id: project.cpp,v 1.13 2007/03/01 15:31:45 oconrad Exp $
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
#include <wx/string.h>
#include <wx/filename.h>
#include <saga_api/saga_api.h>
#include "helper.h"
#include "res_dialogs.h"
#include "saga_frame.h"
#include "wksp_data_manager.h"
#include "wksp_data_menu_files.h"
#include "wksp_table_manager.h"
#include "wksp_table.h"
#include "wksp_shapes_manager.h"
#include "wksp_shapes_type.h"
#include "wksp_shapes.h"
#include "wksp_tin_manager.h"
#include "wksp_tin.h"
#include "wksp_grid_manager.h"
#include "wksp_grid_system.h"
#include "wksp_grid.h"
#include "wksp_map_manager.h"
#include "wksp_map.h"
#include "wksp_map_layer.h"
#include "wksp_layer.h"
#include "project.h"
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
#define DATA_ENTRIES_BEGIN wxT("[DATA_ENTRIES_BEGIN]")
#define DATA_ENTRIES_END wxT("[DATA_ENTRIES_END]")
#define DATA_ENTRY_BEGIN wxT("[DATA_ENTRY_BEGIN]")
#define DATA_ENTRY_END wxT("[DATA_ENTRY_END]")
//---------------------------------------------------------
#define MAP_ENTRIES_BEGIN wxT("[MAP_ENTRIES_BEGIN]")
#define MAP_ENTRIES_END wxT("[MAP_ENTRIES_END]")
#define MAP_ENTRY_BEGIN wxT("[MAP_ENTRY_BEGIN]")
#define MAP_ENTRY_END wxT("[MAP_ENTRY_END]")
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
CWKSP_Project::CWKSP_Project(void)
{
}
//---------------------------------------------------------
CWKSP_Project::~CWKSP_Project(void)
{
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
bool CWKSP_Project::Has_File_Name(void)
{
return( wxFileExists(m_File_Name) );
}
//---------------------------------------------------------
bool CWKSP_Project::Clr_File_Name(void)
{
m_File_Name.Clear();
g_pSAGA_Frame->Set_Project_Name();
return( true );
}
//---------------------------------------------------------
bool CWKSP_Project::_Set_Project_Name(void)
{
if( Has_File_Name() )
{
wxFileName fn(m_File_Name);
if( fn.GetFullName().CmpNoCase(wxT("saga_gui.cfg")) )
{
g_pSAGA_Frame->Set_Project_Name(m_File_Name);
return( true );
}
Clr_File_Name();
}
return( false );
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
bool CWKSP_Project::Load(bool bAdd)
{
wxString FileName;
return( DLG_Open(FileName, ID_DLG_PROJECT_OPEN) && _Load(FileName, bAdd, true) );
}
//---------------------------------------------------------
bool CWKSP_Project::Load(const wxChar *FileName, bool bAdd, bool bUpdateMenu)
{
return( _Load(FileName, bAdd, bUpdateMenu) );
}
//---------------------------------------------------------
bool CWKSP_Project::Save(void)
{
wxString FileName;
return( DLG_Save(FileName, ID_DLG_PROJECT_SAVE) && _Save(FileName, true, true) );
}
//---------------------------------------------------------
bool CWKSP_Project::Save(bool bSaveAsOnError)
{
if( Has_File_Name() )
{
return( _Save(m_File_Name, true, true) );
}
return( bSaveAsOnError ? Save() : false );
}
//---------------------------------------------------------
bool CWKSP_Project::Save(const wxChar *FileName, bool bSaveModified)
{
return( _Save(FileName, bSaveModified, false) );
}
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
bool CWKSP_Project::_Load(const wxChar *FileName, bool bAdd, bool bUpdateMenu)
{
bool bSuccess;
CSG_File Stream;
CSG_String sLine, ProjectDir;
//-----------------------------------------------------
bSuccess = false;
MSG_General_Add(wxString::Format(wxT("%s: %s"), LNG("[MSG] Load project"), FileName), true, true);
//-----------------------------------------------------
if( wxFileExists(FileName) )
{
if( !bAdd && g_pData->Get_Count() > 0 )
{
switch( DLG_Message_YesNoCancel(LNG("[TXT] Close all data sets"), LNG("[CAP] Load Project")) )
{
case 0:
if( !g_pData->Close(true) )
return( false );
break;
case 2: return( false );
}
}
//-------------------------------------------------
if( Stream.Open(FileName, SG_FILE_R, true) )
{
ProjectDir = SG_File_Get_Path(FileName);
while( Stream.Read_Line(sLine) && sLine.Cmp(DATA_ENTRIES_BEGIN) );
if( !sLine.Cmp(DATA_ENTRIES_BEGIN) )
{
g_pData->Get_FileMenus()->Set_Update(false);
while( _Load_Data(Stream, ProjectDir) );
g_pData->Get_FileMenus()->Set_Update(true);
bSuccess = true;
}
//-------------------------------------------------
while( Stream.Read_Line(sLine) && sLine.Cmp(MAP_ENTRIES_BEGIN) );
if( !sLine.Cmp(MAP_ENTRIES_BEGIN) )
{
while( _Load_Map(Stream, ProjectDir) );
}
Stream.Close();
}
}
//-----------------------------------------------------
if( bSuccess )
{
m_File_Name = FileName;
if( bUpdateMenu )
g_pData->Get_FileMenus()->Recent_Add(DATAOBJECT_TYPE_Undefined, FileName);
MSG_General_Add(LNG("[MSG] Project has been successfully loaded."), true, true);
_Set_Project_Name();
return( true );
}
else
{
if( bUpdateMenu )
g_pData->Get_FileMenus()->Recent_Del(DATAOBJECT_TYPE_Undefined, FileName);
MSG_General_Add(LNG("[MSG] Could not load project."), true, true);
return( false );
}
}
//---------------------------------------------------------
bool CWKSP_Project::_Save(const wxChar *FileName, bool bSaveModified, bool bUpdateMenu)
{
int i, j;
CSG_String ProjectDir, oldFileName(m_File_Name);
CSG_File Stream;
CWKSP_Table_Manager *pTables;
CWKSP_Shapes_Manager *pShapes;
CWKSP_TIN_Manager *pTINs;
CWKSP_Grid_Manager *pGrids;
//-----------------------------------------------------
m_File_Name = FileName;
if( bSaveModified && !Save_Modified(g_pData) )
{
m_File_Name = oldFileName;
return( false );
}
if( Stream.Open(FileName, SG_FILE_W, true) )
{
ProjectDir = SG_File_Get_Path(FileName);
Stream.Printf(wxT("\n%s\n"), DATA_ENTRIES_BEGIN);
//-------------------------------------------------
if( (pTables = g_pData->Get_Tables()) != NULL )
{
for(i=0; i<pTables->Get_Count(); i++)
{
_Save_Data(Stream, ProjectDir,
pTables->Get_Table(i)->Get_Table(),
pTables->Get_Table(i)->Get_Parameters()
);
}
}
if( (pShapes = g_pData->Get_Shapes()) != NULL )
{
for(j=0; j<pShapes->Get_Count(); j++)
{
for(i=0; i<((CWKSP_Shapes_Type *)pShapes->Get_Item(j))->Get_Count(); i++)
{
_Save_Data(Stream, ProjectDir,
((CWKSP_Shapes_Type *)pShapes->Get_Item(j))->Get_Shapes(i)->Get_Shapes(),
((CWKSP_Shapes_Type *)pShapes->Get_Item(j))->Get_Shapes(i)->Get_Parameters()
);
}
}
}
if( (pTINs = g_pData->Get_TINs()) != NULL )
{
for(i=0; i<pTINs->Get_Count(); i++)
{
_Save_Data(Stream, ProjectDir,
pTINs->Get_TIN(i)->Get_TIN(),
pTINs->Get_TIN(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(Stream, ProjectDir,
pGrids->Get_System(j)->Get_Grid(i)->Get_Grid(),
pGrids->Get_System(j)->Get_Grid(i)->Get_Parameters()
);
}
}
}
Stream.Printf(wxT("%s\n"), DATA_ENTRIES_END);
//-------------------------------------------------
if( g_pMaps->Get_Count() > 0 )
{
Stream.Printf(wxT("\n%s\n"), MAP_ENTRIES_BEGIN);
for(i=0; i<g_pMaps->Get_Count(); i++)
{
_Save_Map(Stream, ProjectDir, g_pMaps->Get_Map(i));
}
Stream.Printf(wxT("%s\n"), MAP_ENTRIES_END);
}
//-------------------------------------------------
m_File_Name = FileName;
if( bUpdateMenu )
g_pData->Get_FileMenus()->Recent_Add(DATAOBJECT_TYPE_Undefined, FileName);
MSG_General_Add(LNG("[MSG] Project has been saved."), true, true);
_Set_Project_Name();
return( true );
}
m_File_Name.Clear();
if( bUpdateMenu )
g_pData->Get_FileMenus()->Recent_Del(DATAOBJECT_TYPE_Undefined, FileName);
MSG_General_Add(LNG("[MSG] Could not save project."), true, true);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -