//--------------------------------------------------------- bool CWKSP_Module_Manager::_Update(bool bSyncToCtrl) { if( !bSyncToCtrl ) { // Get_Control()->Freeze(); for(int i=SG_Get_Module_Library_Manager().Get_Count()-1; i>=0; i--) { CSG_Module_Library *pLibrary = SG_Get_Module_Library_Manager().Get_Library(i); CWKSP_Module_Library *pItem = Get_Library(pLibrary); if( !pItem ) { CWKSP_Module_Group *pGroup = Get_Group(pLibrary->Get_Category().c_str()); if( !pGroup ) { Add_Item(pGroup = new CWKSP_Module_Group(pLibrary->Get_Category().c_str())); } pGroup->Add_Library(pLibrary); } else if( pItem->Get_Library()->Get_Type() == MODULE_CHAINS ) { pItem->Update(); } } // Get_Control()->Thaw(); } m_pMenu_Modules->Update(); return( true ); }
//--------------------------------------------------------- bool CData_Source_PgSQL::Source_Create(const wxTreeItemId &Item) { CData_Source_PgSQL_Data *pData = Item.IsOk() ? (CData_Source_PgSQL_Data *)GetItemData(Item) : NULL; if( pData == NULL ) return( false ); if( pData->Get_Type() == TYPE_ROOT || pData->Get_Type() == TYPE_SERVER ) { CSG_Module *pModule = SG_Get_Module_Library_Manager().Get_Module("db_pgsql", DB_PGSQL_DB_Create); if( pModule && pModule->On_Before_Execution() ) { if( pData->Get_Type() == TYPE_SERVER ) { pModule->Set_Parameter("PG_HOST", pData->Get_Host()); pModule->Set_Parameter("PG_PORT", pData->Get_Port()); } if( DLG_Parameters(pModule->Get_Parameters()) ) { pModule->Execute(); } } } return( true ); }
//--------------------------------------------------------- void CData_Source_PgSQL::Source_Open(const wxTreeItemId &Item) { CData_Source_PgSQL_Data *pData = Item.IsOk() ? (CData_Source_PgSQL_Data *)GetItemData(Item) : NULL; if( pData == NULL ) return; if( pData->Get_Type() == TYPE_ROOT || pData->Get_Type() == TYPE_SERVER ) { CSG_Module *pModule = SG_Get_Module_Library_Manager().Get_Module("db_pgsql", DB_PGSQL_Get_Connection); // CGet_Connection if( pModule && pModule->On_Before_Execution() ) { if( pData->Get_Type() == TYPE_SERVER ) { pModule->Set_Parameter("PG_HOST", pData->Get_Host()); pModule->Set_Parameter("PG_PORT", pData->Get_Port()); } if( DLG_Parameters(pModule->Get_Parameters()) ) { pModule->Execute(); } } } else if( pData->is_Connected() ) { Update_Source(Item); } else if( !Source_Open(pData, true) ) { DLG_Message_Show_Error(_TL("Could not connect to data source."), _TL("Connect to PostgreSQL")); } }
//--------------------------------------------------------- bool CWKSP_Module_Manager::Open(const wxString &File_Name) { if( SG_Get_Module_Library_Manager().Add_Library(File_Name) ) { _Update(false); return( true ); } return( false ); }
//--------------------------------------------------------- bool PGSQL_Save_Shapes (CSG_Shapes *pShapes) { CSG_Module *pModule = SG_Get_Module_Library_Manager().Get_Module("db_pgsql", DB_PGSQL_Shapes_Save); if( pModule && pModule->On_Before_Execution() && pModule->Set_Parameter("SHAPES", pShapes) && DLG_Parameters(pModule->Get_Parameters()) && pModule->Execute() ) { return( true ); } return( false ); }
//--------------------------------------------------------- bool CWKSP_Module_Manager::Initialise(void) { CONFIG_Read("/MODULES", &m_Parameters); CONFIG_Do_Save(m_Parameters("SAVE_CONFIG")->asBool()); g_pSAGA->Process_Set_Frequency(m_Parameters("PROCESS_UPDATE")->asInt()); #ifdef _OPENMP SG_OMP_Set_Max_Num_Threads(m_Parameters("OMP_THREADS_MAX")->asInt()); #endif //----------------------------------------------------- wxString Library; for(int i=0; CONFIG_Read(CFG_LIBS, wxString::Format(CFG_LIBF, i), Library); i++) { if( !wxFileExists(Library) ) { wxFileName fn(Library); fn.MakeAbsolute(g_pSAGA->Get_App_Path()); Library = fn.GetFullPath(); } SG_Get_Module_Library_Manager().Add_Library(Library); } if( SG_Get_Module_Library_Manager().Get_Count() == 0 ) { #if defined(_SAGA_LINUX) if( (SG_Get_Module_Library_Manager().Add_Directory(CSG_String(MODULE_LIBRARY_PATH), false) + SG_Get_Module_Library_Manager().Add_Directory(SG_File_Make_Path(CSG_String(SHARE_PATH), SG_T("toolchains")), false)) == 0 ) #endif SG_Get_Module_Library_Manager().Add_Directory(g_pSAGA->Get_App_Path(), true); } _Update(false); return( true ); }
//--------------------------------------------------------- bool PGSQL_Save_Grid (CSG_Grid *pGrid) { CSG_Module *pModule = SG_Get_Module_Library_Manager().Get_Module("db_pgsql", DB_PGSQL_Raster_Save); if( pModule && pModule->On_Before_Execution() && pModule->Set_Parameter("NAME", pGrid->Get_Name()) ) { pModule->Get_Parameters()->Get_Parameter("GRIDS")->asList()->Del_Items(); if( pModule->Get_Parameters()->Get_Parameter("GRIDS")->asList()->Add_Item(pGrid) && DLG_Parameters(pModule->Get_Parameters()) && pModule->Execute() ) { return( true ); } } return( false ); }
//--------------------------------------------------------- CSG_Grid * CLandsat_Import::Get_Projection(CSG_Grid *pGrid, const CSG_String &Proj4) { if( pGrid->Get_Projection().is_Okay() == false ) { return( NULL ); } CSG_Module *pModule = SG_Get_Module_Library_Manager().Get_Module(SG_T("pj_proj4"), 4); // Coordinate Transformation (Grid) if( pModule == NULL ) { return( NULL ); } int Interpolation; switch( Parameters("INTERPOLATION")->asInt() ) { case 0: Interpolation = GRID_INTERPOLATION_NearestNeighbour; break; case 1: Interpolation = GRID_INTERPOLATION_Bilinear ; break; default: Interpolation = GRID_INTERPOLATION_BSpline ; break; } Message_Add(CSG_String::Format(SG_T("\n%s (%s: %s)\n"), _TL("re-projection to geographic coordinates"), _TL("original"), pGrid->Get_Projection().Get_Name().c_str()), false); pModule->Settings_Push(NULL); if( pModule->Set_Parameter("CRS_PROJ4" , Proj4 ) && pModule->Set_Parameter("INTERPOLATION", Interpolation) && pModule->Set_Parameter("SOURCE" , pGrid ) && pModule->Execute() ) { pGrid = pModule->Get_Parameters("TARGET")->Get_Parameter("GRID")->asGrid(); pModule->Settings_Pop(); return( pGrid ); } pModule->Settings_Pop(); Message_Add(CSG_String::Format(SG_T("\n%s: %s\n"), _TL("re-projection"), _TL("failed")), false); return( NULL ); }
//--------------------------------------------------------- bool CWKSP_Module_Manager::On_Command(int Cmd_ID) { switch( Cmd_ID ) { default: return( CWKSP_Base_Manager::On_Command(Cmd_ID) ); case ID_CMD_MODULES_OPEN: Open(); break; case ID_CMD_MODULES_SEARCH: { CWKSP_Base_Item *pItem = g_pModule_Ctrl->Search_Item(_TL("Run Tool"), WKSP_ITEM_Module); if( pItem && pItem->GetId().IsOk() && pItem->Get_Type() == WKSP_ITEM_Module ) { ((CWKSP_Module *)pItem)->Execute(true); } } break; case ID_CMD_MODULES_SAVE_DOCS: { wxString Path; if( DLG_Directory(Path, _TL("Create Tool Description Files")) ) { MSG_General_Add(wxString::Format(SG_T("%s..."), _TL("Create Tool Description Files")), true, true); SG_Get_Module_Library_Manager().Get_Summary(&Path); MSG_General_Add(_TL("okay"), false, false, SG_UI_MSG_STYLE_SUCCESS); } } break; } return( true ); }
//--------------------------------------------------------- void CWKSP_Module_Manager::Open(void) { wxArrayString File_Paths; if( DLG_Open(File_Paths, ID_DLG_MODULES_OPEN) ) { MSG_General_Add_Line(); bool bUpdate = false; for(size_t i=0; i<File_Paths.GetCount(); i++) { if( SG_Get_Module_Library_Manager().Add_Library(File_Paths[i]) ) { bUpdate = true; } } if( bUpdate ) { _Update(false); } } }
//--------------------------------------------------------- bool CWKSP_Shapes::_Edit_Split(void) { if( Get_Shapes()->Get_Type() == SHAPE_TYPE_Polygon || Get_Shapes()->Get_Type() == SHAPE_TYPE_Line ) { switch( m_Edit_Mode ) { default: break; //------------------------------------------------- case EDIT_SHAPE_MODE_Normal: m_Edit_Mode = EDIT_SHAPE_MODE_Split; if( m_Edit_Shapes.Get_Count() == 0 ) { m_Edit_Shapes.Add_Shape(Get_Shapes()->Get_Selection()); } if( m_Edit_Shapes.Get_Count() > 1 ) { m_Edit_Shapes.Get_Shape(1)->Del_Parts(); } else { m_Edit_Shapes.Add_Shape(); } return( true ); //------------------------------------------------- case EDIT_SHAPE_MODE_Split: m_Edit_Mode = EDIT_SHAPE_MODE_Normal; CSG_Module *pModule = Get_Shapes()->Get_Type() == SHAPE_TYPE_Polygon ? SG_Get_Module_Library_Manager().Get_Module(SG_T("shapes_polygons"), 8) // Polygon-Line Intersection : SG_Get_Module_Library_Manager().Get_Module(SG_T("shapes_lines" ), 6); // Split Lines with Lines if( pModule ) { CSG_Shapes Line(SHAPE_TYPE_Line), Split(Get_Shapes()->Get_Type()); Line.Add_Shape(); for(int i=0; i<m_Edit_Shapes.Get_Shape(1)->Get_Point_Count(); i++) { Line.Get_Shape(0)->Add_Point(m_Edit_Shapes.Get_Shape(1)->Get_Point(i)); } m_Edit_Shapes.Del_Shape(1); //----------------------------------------- bool bResult; CSG_Parameters P; P.Assign(pModule->Get_Parameters()); pModule->Set_Manager(NULL); if( Get_Shapes()->Get_Type() == SHAPE_TYPE_Polygon ) { bResult = pModule->Get_Parameters()->Set_Parameter("POLYGONS" , &m_Edit_Shapes) && pModule->Get_Parameters()->Set_Parameter("LINES" , &Line) && pModule->Get_Parameters()->Set_Parameter("INTERSECT", &Split) && pModule->Execute(); } else // if( Get_Shapes()->Get_Type() == SHAPE_TYPE_Line ) { bResult = pModule->Get_Parameters()->Set_Parameter("LINES" , &m_Edit_Shapes) && pModule->Get_Parameters()->Set_Parameter("SPLIT" , &Line) && pModule->Get_Parameters()->Set_Parameter("INTERSECT", &Split) && pModule->Execute(); } //----------------------------------------- if( bResult ) { if( m_Edit_pShape ) { m_Edit_pShape->Assign(Split.Get_Shape(0), false); for(int iSplit=1; iSplit<Split.Get_Count(); iSplit++) { CSG_Shape *pSplit = Split.Get_Shape(iSplit); for(int iPart=0; iPart<pSplit->Get_Part_Count(); iPart++) { for(int iPoint=0, jPart=m_Edit_pShape->Get_Part_Count(); iPoint<pSplit->Get_Point_Count(iPart); iPoint++) { m_Edit_pShape->Add_Point(pSplit->Get_Point(iPoint, iPart), jPart); } } } } else if( Get_Shapes()->Get_Selection_Count() == 1 ) // if( !m_Edit_pShape ) { CSG_Shape *pSelection = Get_Shapes()->Get_Selection(); pSelection->Assign(Split.Get_Shape(0), false); for(int iSplit=1; iSplit<Split.Get_Count(); iSplit++) { CSG_Shape *pSplit = Get_Shapes()->Add_Shape(Split.Get_Shape(iSplit)); ((CSG_Table_Record *)pSplit)->Assign(pSelection); Get_Shapes()->Select(pSplit, true); } m_Edit_Shapes.Del_Shapes(); } } pModule->Get_Parameters()->Assign_Values(&P); pModule->Set_Manager(P.Get_Manager()); } Update_Views(false); return( true ); } } return( false ); }
//--------------------------------------------------------- wxString CWKSP_Module_Manager::Get_Description(void) { return( SG_Get_Module_Library_Manager().Get_Summary().c_str() ); }
//--------------------------------------------------------- bool CSG_Shapes::Create(const CSG_String &File_Name) { Destroy(); SG_UI_Msg_Add(CSG_String::Format("%s: %s...", _TL("Load shapes"), File_Name.c_str()), true); //----------------------------------------------------- bool bResult = File_Name.BeforeFirst(':').Cmp("PGSQL") && SG_File_Exists(File_Name) && _Load_ESRI(File_Name); if( bResult ) { Set_File_Name(File_Name, true); Load_MetaData(File_Name); } //----------------------------------------------------- else if( File_Name.BeforeFirst(':').Cmp("PGSQL") == 0 ) // database source { CSG_String s(File_Name); s = s.AfterFirst(':'); CSG_String Host (s.BeforeFirst(':')); s = s.AfterFirst(':'); CSG_String Port (s.BeforeFirst(':')); s = s.AfterFirst(':'); CSG_String DBName(s.BeforeFirst(':')); s = s.AfterFirst(':'); CSG_String Table (s.BeforeFirst(':')); CSG_Module *pModule = SG_Get_Module_Library_Manager().Get_Module("db_pgsql", 0); // CGet_Connections if( pModule != NULL ) { SG_UI_ProgressAndMsg_Lock(true); //--------------------------------------------- CSG_Table Connections; CSG_String Connection = DBName + " [" + Host + ":" + Port + "]"; pModule->Settings_Push(); if( pModule->On_Before_Execution() && SG_MODULE_PARAMETER_SET("CONNECTIONS", &Connections) && pModule->Execute() ) // CGet_Connections { for(int i=0; !bResult && i<Connections.Get_Count(); i++) { if( !Connection.Cmp(Connections[i].asString(0)) ) { bResult = true; } } } pModule->Settings_Pop(); //--------------------------------------------- if( bResult && (bResult = (pModule = SG_Get_Module_Library_Manager().Get_Module("db_pgsql", 20)) != NULL) == true ) // CPGIS_Shapes_Load { pModule->Settings_Push(); bResult = pModule->On_Before_Execution() && SG_MODULE_PARAMETER_SET("CONNECTION", Connection) && SG_MODULE_PARAMETER_SET("TABLES" , Table) && SG_MODULE_PARAMETER_SET("SHAPES" , this) && pModule->Execute(); pModule->Settings_Pop(); } SG_UI_ProgressAndMsg_Lock(false); } } //----------------------------------------------------- if( bResult ) { Set_Modified(false); Set_Update_Flag(); SG_UI_Msg_Add(_TL("okay"), false, SG_UI_MSG_STYLE_SUCCESS); return( true ); } for(int iShape=Get_Count()-1; iShape>=0; iShape--) // be kind, keep at least those shapes that have been loaded successfully { if( !Get_Shape(iShape)->is_Valid() ) { Del_Shape(iShape); } } if( Get_Count() <= 0 ) { Destroy(); } SG_UI_Msg_Add(_TL("failed"), false, SG_UI_MSG_STYLE_FAILURE); return( false ); }