//--------------------------------------------------------- void CVIEW_ScatterPlot::On_AsTable(wxCommandEvent &event) { if( m_Trend.Get_Data_Count() > 1 ) { CSG_Table *pTable = new CSG_Table; pTable->Fmt_Name("%s: [%s]-[%s]", _TL("Scatterplot"), m_sX.c_str(), m_sY.c_str()); pTable->Add_Field("ID", SG_DATATYPE_Int ); pTable->Add_Field(m_sX, SG_DATATYPE_Double); pTable->Add_Field(m_sY, SG_DATATYPE_Double); for(int i=0; i<m_Trend.Get_Data_Count() && PROGRESSBAR_Set_Position(i, m_Trend.Get_Data_Count()); i++) { CSG_Table_Record *pRecord = pTable->Add_Record(); pRecord->Set_Value(0, i + 1); pRecord->Set_Value(1, m_Trend.Get_Data_X(i)); pRecord->Set_Value(2, m_Trend.Get_Data_Y(i)); } PROGRESSBAR_Set_Position(0); g_pData->Add(pTable); } }
//--------------------------------------------------------- bool CVIEW_ScatterPlot::_Initialize_Table(void) { int xField = m_Parameters("FIELD_X")->asInt(); int yField = m_Parameters("FIELD_Y")->asInt(); CHECK_DATA(m_pTable); if( !m_pTable || xField < 0 || xField >= m_pTable->Get_Field_Count() || yField < 0 || yField >= m_pTable->Get_Field_Count() ) { return( false ); } int maxSamples = m_Options("SAMPLES_MAX")->asInt(); double Step = maxSamples > 0 && m_pTable->Get_Count() > maxSamples ? m_pTable->Get_Count() / maxSamples : 1.0; m_sTitle.Printf("%s: [%s]", _TL("Scatterplot"), m_pTable->Get_Name()); m_sX.Printf("%s", m_pTable->Get_Field_Name(xField)); m_sY.Printf("%s", m_pTable->Get_Field_Name(yField)); for(double i=0; i<m_pTable->Get_Record_Count() && PROGRESSBAR_Set_Position(i, m_pTable->Get_Record_Count()); i+=Step) { CSG_Table_Record *pRecord = m_pTable->Get_Record((int)i); if( !pRecord->is_NoData(xField) && !pRecord->is_NoData(yField) ) { m_Trend.Add_Data(pRecord->asDouble(xField), pRecord->asDouble(yField)); } } return( true ); }
//--------------------------------------------------------- bool CVIEW_ScatterPlot::_Initialize_Grids(CSG_Grid *pGrid_X, CSG_Grid *pGrid_Y) { CHECK_DATA(pGrid_X); CHECK_DATA(pGrid_Y); if( !pGrid_X || !pGrid_Y ) { return( false ); } //----------------------------------------------------- m_sTitle.Printf("%s: [%s/%s]", _TL("Scatterplot"), pGrid_X->Get_Name(), pGrid_Y->Get_Name()); m_sX.Printf("%s", pGrid_X->Get_Name()); m_sY.Printf("%s", pGrid_Y->Get_Name()); bool bEqual = pGrid_X->Get_System() == pGrid_Y->Get_System(); int maxSamples = m_Options("SAMPLES_MAX")->asInt(); double Step = maxSamples > 0 && pGrid_X->Get_NCells() > maxSamples ? pGrid_X->Get_NCells() / maxSamples : 1.0; for(double dCell=0; dCell<pGrid_X->Get_NCells() && PROGRESSBAR_Set_Position(dCell, pGrid_X->Get_NCells()); dCell+=Step) { sLong iCell = (sLong)dCell; if( !pGrid_X->is_NoData(iCell) ) { if( bEqual ) { if( !pGrid_Y->is_NoData(iCell) ) { m_Trend.Add_Data(pGrid_X->asDouble(iCell), pGrid_Y->asDouble(iCell)); } } else { TSG_Point p = pGrid_X->Get_System().Get_Grid_to_World( (int)(iCell % pGrid_X->Get_NX()), (int)(iCell / pGrid_X->Get_NX()) ); double y; if( pGrid_Y->Get_Value(p, y) ) { m_Trend.Add_Data(pGrid_X->asDouble(iCell), y); } } } } return( true ); }
//--------------------------------------------------------- bool CVIEW_ScatterPlot::_Initialize_Shapes(void) { CSG_Shapes *pPoints = m_Parameters("POINTS")->asShapes(); int Field = m_Parameters("FIELD" )->asInt(); TSG_Grid_Resampling Resampling; switch( m_Parameters("RESAMPLING")->asInt() ) { default: Resampling = GRID_RESAMPLING_NearestNeighbour; break; case 1: Resampling = GRID_RESAMPLING_Bilinear ; break; case 2: Resampling = GRID_RESAMPLING_BicubicSpline ; break; case 3: Resampling = GRID_RESAMPLING_BSpline ; break; } CHECK_DATA(m_pGrid); CHECK_DATA(pPoints); if( !m_pGrid || !pPoints || Field < 0 || Field >= pPoints->Get_Field_Count() ) { return( false ); } m_sTitle.Printf("%s: [%s/%s]", _TL("Scatterplot"), m_pGrid->Get_Name(), pPoints->Get_Name()); m_sX.Printf("%s", m_pGrid->Get_Name()); m_sY.Printf("%s", pPoints->Get_Field_Name(Field)); int maxSamples = m_Options("SAMPLES_MAX")->asInt(); double x, Step = maxSamples > 0 && pPoints->Get_Count() > maxSamples ? pPoints->Get_Count() / maxSamples : 1.0; for(double i=0; i<pPoints->Get_Count() && PROGRESSBAR_Set_Position(i, pPoints->Get_Count()); i+=Step) { CSG_Shape *pShape = pPoints->Get_Shape((int)i); if( !pShape->is_NoData(Field) && m_pGrid->Get_Value(pShape->Get_Point(0), x, Resampling) ) { m_Trend.Add_Data(x, pShape->asDouble(Field)); } } return( true ); }
//--------------------------------------------------------- bool CVIEW_Table_Control::_Set_Records(bool bSelection_To_Top) { BeginBatch(); //----------------------------------------------------- if( m_bSelOnly && m_pTable->Get_Selection_Count() <= 0 ) { m_bSelOnly = false; } int Difference, nRecords = m_bSelOnly ? m_pTable->Get_Selection_Count() : m_pTable->Get_Count(); if( (Difference = nRecords - GetNumberRows()) > 0 ) { AppendRows(Difference); } else if( Difference < 0 && (Difference = -Difference < GetNumberRows() ? -Difference : GetNumberRows()) > 0 ) { DeleteRows(0, Difference); } m_pRecords = (CSG_Table_Record **)SG_Realloc(m_pRecords, nRecords * sizeof(CSG_Table_Record *)); ClearSelection(); //----------------------------------------------------- if( m_bSelOnly ) { // #pragma omp parallel for for(int iRecord=0; iRecord<nRecords; iRecord++) { _Set_Record(iRecord, m_pTable->Get_Selection(iRecord)); } } else if( !bSelection_To_Top ) { // #pragma omp parallel for for(int iRecord=0; iRecord<nRecords; iRecord++) { _Set_Record(iRecord, m_pTable->Get_Record_byIndex(iRecord)); } } else // if( bSelection_To_Top && m_pTable->Get_Selection_Count() > 0 ) { for(int iRecord=0, iSel=0, iNoSel=m_pTable->Get_Selection_Count(); iRecord<nRecords && PROGRESSBAR_Set_Position(iRecord, nRecords); iRecord++) { CSG_Table_Record *pRecord = m_pTable->Get_Record_byIndex(iRecord); if( pRecord->is_Selected() ) { _Set_Record(iSel ++, pRecord); } else { _Set_Record(iNoSel++, pRecord); } } PROCESS_Set_Okay(); } //----------------------------------------------------- EndBatch(); _Update_Views(); return( true ); }
//--------------------------------------------------------- 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); }
//--------------------------------------------------------- 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::_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 ); }