//--------------------------------------------------------- bool CWKSP_Module_Manager::Open(const wxChar *File_Name) { CWKSP_Module_Library *pLibrary; //----------------------------------------------------- if( SG_File_Cmp_Extension(File_Name, wxT("mlb")) || SG_File_Cmp_Extension(File_Name, wxT("dll")) || SG_File_Cmp_Extension(File_Name, wxT("so" )) ) { MSG_General_Add(wxString::Format(wxT("%s: %s..."), LNG("[MSG] Load library"), File_Name), true, true); //------------------------------------------------- for(int i=0; i<Get_Count(); i++) { if( SG_STR_CMP(File_Name, Get_Library(i)->Get_File_Name()) == 0 ) { MSG_Error_Add(wxString::Format(wxT("%s\n%s"), File_Name, LNG("[ERR] Library has already been loaded")), true); MSG_General_Add(LNG("[MSG] has already been loaded"), false); return( false ); } } //------------------------------------------------- pLibrary = new CWKSP_Module_Library(File_Name); if( pLibrary->is_Valid() ) { Add_Item(pLibrary); MSG_General_Add(LNG("[MSG] okay"), false, false, SG_UI_MSG_STYLE_SUCCESS); return( true ); } delete(pLibrary); MSG_General_Add(LNG("[MSG] failed"), false, false, SG_UI_MSG_STYLE_FAILURE); } return( false ); }
//--------------------------------------------------------- int Callback(TSG_UI_Callback_ID ID, CSG_UI_Parameter &Param_1, CSG_UI_Parameter &Param_2) { int Result, *iArray; Result = 1; //----------------------------------------------------- switch( ID ) { default: Result = 0; break; /////////////////////////////////////////////////////// // // // // // // /////////////////////////////////////////////////////// //----------------------------------------------------- case CALLBACK_PROCESS_GET_OKAY: Result = PROCESS_Get_Okay(Param_1.True); break; //----------------------------------------------------- case CALLBACK_PROCESS_SET_OKAY: Result = PROCESS_Set_Okay(Param_1.True); break; //----------------------------------------------------- case CALLBACK_PROCESS_SET_PROGRESS: Result = PROGRESSBAR_Set_Position(Param_1.Number, Param_2.Number); break; //----------------------------------------------------- case CALLBACK_PROCESS_SET_READY: STATUSBAR_Set_Text(_TL("ready")); Result = PROGRESSBAR_Set_Position(0); break; //----------------------------------------------------- case CALLBACK_PROCESS_SET_TEXT: STATUSBAR_Set_Text(Param_1.String.c_str()); break; /////////////////////////////////////////////////////// // // // // // // /////////////////////////////////////////////////////// //----------------------------------------------------- case CALLBACK_STOP_EXECUTION: if( g_pModule && g_pModule->is_Executing() ) { Result = g_pModule->Execute(Param_1.True) ? 1 : 0; } else if( g_pModule && g_pModule->is_Interactive() ) { Result = g_pModule->Execute(Param_1.True) ? 1 : 0; } break; /////////////////////////////////////////////////////// // // // // // // /////////////////////////////////////////////////////// //----------------------------------------------------- case CALLBACK_MESSAGE_ADD: iArray = (int *)Param_2.Pointer; MSG_General_Add (Param_1.String.c_str(), iArray[0] != 0, iArray[0] != 0, (TSG_UI_MSG_STYLE)iArray[1]); break; //----------------------------------------------------- case CALLBACK_MESSAGE_ADD_ERROR: MSG_Error_Add (Param_1.String.c_str(), true); break; //----------------------------------------------------- case CALLBACK_MESSAGE_ADD_EXECUTION: iArray = (int *)Param_2.Pointer; MSG_Execution_Add (Param_1.String.c_str(), iArray[0] != 0, iArray[0] != 0, (TSG_UI_MSG_STYLE)iArray[1]); break; /////////////////////////////////////////////////////// // // // // // // /////////////////////////////////////////////////////// //----------------------------------------------------- case CALLBACK_DLG_MESSAGE: DLG_Message_Show(Param_1.String.c_str(), Param_2.String.c_str()); break; //----------------------------------------------------- case CALLBACK_DLG_CONTINUE: Result = DLG_Message_Confirm(Param_1.String.c_str(), Param_2.String.c_str()); break; //----------------------------------------------------- case CALLBACK_DLG_ERROR: Result = DLG_Message_Show_Error(Param_1.String.c_str(), Param_2.String.c_str()); break; /////////////////////////////////////////////////////// // // // // // // /////////////////////////////////////////////////////// //----------------------------------------------------- case CALLBACK_DLG_PARAMETERS: Result = DLG_Parameters((CSG_Parameters *)Param_1.Pointer, Param_2.String.c_str()) ? 1 : 0; break; /////////////////////////////////////////////////////// // // // // // // /////////////////////////////////////////////////////// //----------------------------------------------------- case CALLBACK_DATAOBJECT_ADD: Result = g_pData->Add((CSG_Data_Object *)Param_1.Pointer) ? 1 : 0; if( Result && Param_2.True ) { g_pData->Show((CSG_Data_Object *)Param_1.Pointer, false); } break; //----------------------------------------------------- case CALLBACK_DATAOBJECT_UPDATE: Result = g_pData->Update((CSG_Data_Object *)Param_1.Pointer, (CSG_Parameters *)Param_2.Pointer) ? 1 : 0; break; //----------------------------------------------------- case CALLBACK_DATAOBJECT_SHOW: Result = g_pData->Show((CSG_Data_Object *)Param_1.Pointer, (int)Param_2.Number) ? 1 : 0; break; //----------------------------------------------------- case CALLBACK_DATAOBJECT_ASIMAGE: Result = g_pData->asImage((CSG_Data_Object *)Param_1.Pointer, (CSG_Grid *)Param_2.Pointer) ? 1 : 0; break; //----------------------------------------------------- case CALLBACK_DATAOBJECT_COLORS_GET: Result = g_pData->Get_Colors((CSG_Data_Object *)Param_1.Pointer, (CSG_Colors *)Param_2.Pointer) ? 1 : 0; break; //----------------------------------------------------- case CALLBACK_DATAOBJECT_COLORS_SET: Result = g_pData->Set_Colors((CSG_Data_Object *)Param_1.Pointer, (CSG_Colors *)Param_2.Pointer) ? 1 : 0; break; //----------------------------------------------------- case CALLBACK_DATAOBJECT_PARAMS_GET: Result = g_pData->Get_Parameters((CSG_Data_Object *)Param_1.Pointer, (CSG_Parameters *)Param_2.Pointer) ? 1 : 0; break; //----------------------------------------------------- case CALLBACK_DATAOBJECT_PARAMS_SET: Result = g_pData->Set_Parameters((CSG_Data_Object *)Param_1.Pointer, (CSG_Parameters *)Param_2.Pointer) ? 1 : 0; break; //----------------------------------------------------- case CALLBACK_ODBC_UPDATE: Result = g_pData_Source->Update_ODBC_Source(Param_1.String.c_str()) ? 1 : 0; break; /////////////////////////////////////////////////////// // // // // // // /////////////////////////////////////////////////////// //----------------------------------------------------- case CALLBACK_GUI_GET_WINDOW: Param_1.Pointer = MDI_Get_Frame(); break; /////////////////////////////////////////////////////// // // // // // // /////////////////////////////////////////////////////// //----------------------------------------------------- } return( Result ); }
//--------------------------------------------------------- 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 CWKSP_Project::_Load_Data(CSG_MetaData &Entry, const wxString &ProjectDir, bool bLoad, const CSG_String &Version) { if( !Entry.Cmp_Name("DATASET") || !Entry("FILE") || Entry["FILE"].Get_Content().is_Empty() ) { return( false ); } TSG_Data_Object_Type Type = Entry.Cmp_Property("type", "GRID" ) ? SG_DATAOBJECT_TYPE_Grid : Entry.Cmp_Property("type", "GRIDS" ) ? SG_DATAOBJECT_TYPE_Grids : Entry.Cmp_Property("type", "TABLE" ) ? SG_DATAOBJECT_TYPE_Table : Entry.Cmp_Property("type", "SHAPES") ? SG_DATAOBJECT_TYPE_Shapes : Entry.Cmp_Property("type", "TIN" ) ? SG_DATAOBJECT_TYPE_TIN : Entry.Cmp_Property("type", "POINTS") ? SG_DATAOBJECT_TYPE_PointCloud : SG_DATAOBJECT_TYPE_Undefined; if( Type == SG_DATAOBJECT_TYPE_Undefined ) { return( false ); } //----------------------------------------------------- wxString File = Entry("FILE")->Get_Content().c_str(); if( File.Find("PGSQL") != 0 && wxFileExists(Get_FilePath_Absolute(ProjectDir, File)) ) { File = Get_FilePath_Absolute(ProjectDir, File); } //----------------------------------------------------- CWKSP_Base_Item *pItem = NULL; if( bLoad ) { if( Type == SG_DATAOBJECT_TYPE_Grid && Entry("PARAMETERS")) { for(int i=0; i<Entry["PARAMETERS"].Get_Children_Count() && !pItem; i++) { if( Entry["PARAMETERS"][i].Cmp_Property("id", "FILE_CACHE") ) { bool bCached = Entry["PARAMETERS"][i].Cmp_Content("TRUE", true); pItem = g_pData->Add(SG_Create_Grid(&File, SG_DATATYPE_Undefined, bCached)); } } } } if( !pItem ) { pItem = bLoad ? g_pData->Open(File, Type) : _Get_byFileName(File); } //----------------------------------------------------- if( !pItem || !pItem->Get_Parameters() || !Entry.Get_Child("PARAMETERS") ) { if( bLoad ) { MSG_Error_Add(wxString::Format("%s [%s]", _TL("failed to load data"), File.c_str())); } return( false ); } //----------------------------------------------------- CSG_MetaData *pEntry = Entry("PARAMETERS"); for(int i=0; i<pEntry->Get_Children_Count(); i++) { if( !pEntry->Get_Child(i)->Get_Name().CmpNoCase("DATA") && !pEntry->Get_Child(i)->Get_Content().is_Empty() && pEntry->Get_Child(i)->Get_Content().BeforeFirst(':').CmpNoCase("PGSQL") ) { wxString File(Get_FilePath_Absolute(ProjectDir, pEntry->Get_Child(i)->Get_Content().w_str())); pEntry->Get_Child(i)->Set_Content(&File); // if( SG_Compare_SAGA_Version(Version) < 0 ) { if( pEntry->Get_Child(i)->Cmp_Property("id", "OVERLAY_1") ) { pEntry->Get_Child(i)->Set_Property("id", "OVERLAY_G"); } if( pEntry->Get_Child(i)->Cmp_Property("id", "OVERLAY_2") ) { pEntry->Get_Child(i)->Set_Property("id", "OVERLAY_B"); } } } } pItem->Get_Parameters()->Serialize(*Entry.Get_Child("PARAMETERS"), false); //----------------------------------------------------- if( SG_Compare_Version(Version, "7.0.0") < 0 ) // inter-version-compatibility { CSG_Parameter *pParameter = pItem->Get_Parameter("COLORS_TYPE"); if( pParameter && Type == SG_DATAOBJECT_TYPE_Grid ) { if( pParameter->asInt() == 4 ) { pParameter->Set_Value(6); } // Shade if( pParameter->asInt() == 5 ) { pParameter->Set_Value(4); } // RGB Overlay if( pParameter->asInt() == 6 ) { pParameter->Set_Value(5); } // RGB Composite } } //----------------------------------------------------- if( Type == SG_DATAOBJECT_TYPE_Grid ) { pItem->Get_Parameter("FILE_CACHE")->Set_Value(((CWKSP_Grid *)pItem)->Get_Grid()->is_Cached()); } pItem->Parameters_Changed(); return( true ); }
//--------------------------------------------------------- bool CWKSP_Project::_Load_Data(CSG_MetaData &Entry, const wxString &ProjectDir, bool bLoad, const CSG_String &Version) { if( Entry.Get_Name().Cmp("DATASET") || !Entry.Get_Child("FILE") || Entry.Get_Child("FILE")->Get_Content().is_Empty() ) { return( false ); } TSG_Data_Object_Type Type = Entry.Cmp_Property("type", "GRID" ) ? DATAOBJECT_TYPE_Grid : Entry.Cmp_Property("type", "TABLE" ) ? DATAOBJECT_TYPE_Table : Entry.Cmp_Property("type", "SHAPES") ? DATAOBJECT_TYPE_Shapes : Entry.Cmp_Property("type", "TIN" ) ? DATAOBJECT_TYPE_TIN : Entry.Cmp_Property("type", "POINTS") ? DATAOBJECT_TYPE_PointCloud : DATAOBJECT_TYPE_Undefined; if( Type == DATAOBJECT_TYPE_Undefined ) { return( false ); } //----------------------------------------------------- wxString File = Entry.Get_Child("FILE")->Get_Content().c_str(); if( File.Find("PGSQL") != 0 && wxFileExists(Get_FilePath_Absolute(ProjectDir, File)) ) { File = Get_FilePath_Absolute(ProjectDir, File); } CWKSP_Base_Item *pItem = bLoad ? g_pData->Open(File, Type) : _Get_byFileName(File); if( !pItem || !pItem->Get_Parameters() || !Entry.Get_Child("PARAMETERS") ) { if( bLoad ) { MSG_Error_Add(wxString::Format("%s [%s]", _TL("failed to load data"), File.c_str())); } return( false ); } //----------------------------------------------------- CSG_MetaData *pEntry = Entry("PARAMETERS"); for(int i=0; i<pEntry->Get_Children_Count(); i++) { if( !pEntry->Get_Child(i)->Get_Name().CmpNoCase("DATA") && !pEntry->Get_Child(i)->Get_Content().is_Empty() && pEntry->Get_Child(i)->Get_Content().BeforeFirst(':').Cmp("PGSQL") ) { wxString File(Get_FilePath_Absolute(ProjectDir, pEntry->Get_Child(i)->Get_Content().w_str())); pEntry->Get_Child(i)->Set_Content(&File); // if( SG_Compare_SAGA_Version(Version) < 0 ) { if( pEntry->Get_Child(i)->Cmp_Property("id", "OVERLAY_1") ) { pEntry->Get_Child(i)->Set_Property("id", "OVERLAY_G"); } if( pEntry->Get_Child(i)->Cmp_Property("id", "OVERLAY_2") ) { pEntry->Get_Child(i)->Set_Property("id", "OVERLAY_B"); } } } } pItem->Get_Parameters()->Serialize(*Entry.Get_Child("PARAMETERS"), false); pItem->Parameters_Changed(); return( true ); }