//--------------------------------------------------------- bool CWKSP_Tool_Manager::_Update(bool bSyncToCtrl) { if( !bSyncToCtrl ) { // Get_Control()->Freeze(); for(int i=SG_Get_Tool_Library_Manager().Get_Count()-1; i>=0; i--) { CSG_Tool_Library *pLibrary = SG_Get_Tool_Library_Manager().Get_Library(i); CWKSP_Tool_Library *pItem = Get_Library(pLibrary); if( !pItem ) { CWKSP_Tool_Group *pGroup = Get_Group(pLibrary->Get_Category().c_str()); if( !pGroup ) { Add_Item(pGroup = new CWKSP_Tool_Group(pLibrary->Get_Category().c_str())); } pGroup->Add_Library(pLibrary); } else if( pItem->Get_Library()->Get_Type() == TOOL_CHAINS ) { pItem->Update(); } } // Get_Control()->Thaw(); } m_pMenu_Tools->Update(); return( true ); }
//--------------------------------------------------------- CWKSP_Tool_Library::~CWKSP_Tool_Library(void) { _Del_Tools(); if( MDI_Get_Frame() ) // don't unload library, if gui is closing (i.e. main window == NULL) { SG_Get_Tool_Library_Manager().Del_Library(m_pLibrary); } }
//--------------------------------------------------------- bool CWKSP_Tool_Manager::Open(const wxString &File_Name) { if( SG_Get_Tool_Library_Manager().Add_Library(File_Name) ) { _Update(false); return( true ); } return( false ); }
//--------------------------------------------------------- bool CWKSP_Tool_Manager::Initialise(void) { CONFIG_Read("/TOOLS", &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_Tool_Library_Manager().Add_Library(Library); } if( SG_Get_Tool_Library_Manager().Get_Count() == 0 ) { #if defined(_SAGA_LINUX) if( (SG_Get_Tool_Library_Manager().Add_Directory(CSG_String(MODULE_LIBRARY_PATH), false) + SG_Get_Tool_Library_Manager().Add_Directory(SG_File_Make_Path(CSG_String(SHARE_PATH), SG_T("toolchains")), false)) == 0 ) #endif SG_Get_Tool_Library_Manager().Add_Directory(g_pSAGA->Get_App_Path(), true); } _Update(false); return( true ); }
//--------------------------------------------------------- bool CWKSP_Tool_Library::On_Command(int Cmd_ID) { switch( Cmd_ID ) { default: return( CWKSP_Base_Manager::On_Command(Cmd_ID) ); case ID_CMD_WKSP_ITEM_CLOSE: SG_Get_Tool_Library_Manager().Del_Library(m_pLibrary); break; case ID_CMD_WKSP_ITEM_RETURN: break; } return( true ); }
//--------------------------------------------------------- bool CWKSP_Map_Graticule::Get_Graticule(const CSG_Rect &Extent) { bool bResult = false; m_Graticule .Create(SHAPE_TYPE_Line ); m_Coordinates.Create(SHAPE_TYPE_Point); CSG_Tool *pTool = SG_Get_Tool_Library_Manager().Get_Tool("pj_proj4", 14); if( pTool && Get_Map()->Get_Projection().is_Okay() ) { SG_UI_Msg_Lock (true); SG_UI_Progress_Lock(true); pTool->Settings_Push(); if( pTool->Set_Parameter("XMIN" , Extent.Get_XMin()) && pTool->Set_Parameter("XMAX" , Extent.Get_XMax()) && pTool->Set_Parameter("YMIN" , Extent.Get_YMin()) && pTool->Set_Parameter("YMAX" , Extent.Get_YMax()) && pTool->Set_Parameter("INTERVAL" , m_Parameters("INTERVAL")) && pTool->Set_Parameter("FIXED" , m_Parameters("FIXED")) && pTool->Set_Parameter("FITTED" , m_Parameters("FITTED")) && pTool->Set_Parameter("RESOLUTION", m_Parameters("RESOLUTION")) && pTool->Set_Parameter("GRATICULE" , &m_Graticule) && pTool->Set_Parameter("COORDS" , &m_Coordinates) && pTool->Set_Parameter("CRS_PROJ4" , Get_Map()->Get_Projection().Get_Proj4()) && pTool->On_Before_Execution() && pTool->Execute() ) { bResult = true; } pTool->Settings_Pop(); SG_UI_Msg_Lock (false); SG_UI_Progress_Lock(false); } return( bResult ); }
//--------------------------------------------------------- bool CWKSP_Tool_Manager::On_Command(int Cmd_ID) { switch( Cmd_ID ) { default: return( CWKSP_Base_Manager::On_Command(Cmd_ID) ); case ID_CMD_TOOLS_OPEN: Open(); break; case ID_CMD_TOOLS_SEARCH: { CWKSP_Base_Item *pItem = g_pTool_Ctrl->Search_Item(_TL("Run Tool"), WKSP_ITEM_Tool); if( pItem && pItem->GetId().IsOk() && pItem->Get_Type() == WKSP_ITEM_Tool ) { ((CWKSP_Tool *)pItem)->Execute(true); } } break; case ID_CMD_TOOLS_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_Tool_Library_Manager().Get_Summary(&Path); MSG_General_Add(_TL("okay"), false, false, SG_UI_MSG_STYLE_SUCCESS); } } break; } return( true ); }
//--------------------------------------------------------- void CWKSP_Tool_Manager::Open(void) { wxArrayString File_Paths; if( DLG_Open(File_Paths, ID_DLG_TOOLS_OPEN) ) { MSG_General_Add_Line(); bool bUpdate = false; for(size_t i=0; i<File_Paths.GetCount(); i++) { if( SG_Get_Tool_Library_Manager().Add_Library(File_Paths[i]) ) { bUpdate = true; } } if( bUpdate ) { _Update(false); } } }
//--------------------------------------------------------- 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); } //----------------------------------------------------- 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_Tool *pTool = SG_Get_Tool_Library_Manager().Get_Tool("db_pgsql", 0); // CGet_Connections if( pTool != NULL ) { SG_UI_ProgressAndMsg_Lock(true); //--------------------------------------------- CSG_Table Connections; CSG_String Connection = DBName + " [" + Host + ":" + Port + "]"; pTool->Settings_Push(); if( pTool->On_Before_Execution() && SG_TOOL_PARAMETER_SET("CONNECTIONS", &Connections) && pTool->Execute() ) // CGet_Connections { for(int i=0; !bResult && i<Connections.Get_Count(); i++) { if( !Connection.Cmp(Connections[i].asString(0)) ) { bResult = true; } } } pTool->Settings_Pop(); //--------------------------------------------- if( bResult && (bResult = (pTool = SG_Get_Tool_Library_Manager().Get_Tool("db_pgsql", 20)) != NULL) == true ) // CPGIS_Shapes_Load { pTool->Settings_Push(); bResult = pTool->On_Before_Execution() && SG_TOOL_PARAMETER_SET("CONNECTION", Connection) && SG_TOOL_PARAMETER_SET("TABLES" , Table) && SG_TOOL_PARAMETER_SET("SHAPES" , this) && pTool->Execute(); pTool->Settings_Pop(); } SG_UI_ProgressAndMsg_Lock(false); } } //----------------------------------------------------- if( bResult ) { Set_Modified(false); Set_Update_Flag(); SG_UI_Process_Set_Ready(); 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_Process_Set_Ready(); SG_UI_Msg_Add(_TL("failed"), false, SG_UI_MSG_STYLE_FAILURE); return( 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_Tool *pTool = Get_Shapes()->Get_Type() == SHAPE_TYPE_Polygon ? SG_Get_Tool_Library_Manager().Get_Tool(SG_T("shapes_polygons"), 8) // Polygon-Line Intersection : SG_Get_Tool_Library_Manager().Get_Tool(SG_T("shapes_lines" ), 6); // Split Lines with Lines if( pTool ) { 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(pTool->Get_Parameters()); pTool->Set_Manager(NULL); if( Get_Shapes()->Get_Type() == SHAPE_TYPE_Polygon ) { bResult = pTool->Get_Parameters()->Set_Parameter("POLYGONS" , &m_Edit_Shapes) && pTool->Get_Parameters()->Set_Parameter("LINES" , &Line) && pTool->Get_Parameters()->Set_Parameter("INTERSECT", &Split) && pTool->Execute(); } else // if( Get_Shapes()->Get_Type() == SHAPE_TYPE_Line ) { bResult = pTool->Get_Parameters()->Set_Parameter("LINES" , &m_Edit_Shapes) && pTool->Get_Parameters()->Set_Parameter("SPLIT" , &Line) && pTool->Get_Parameters()->Set_Parameter("INTERSECT", &Split) && pTool->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(); } } pTool->Get_Parameters()->Assign_Values(&P); pTool->Set_Manager(P.Get_Manager()); } Update_Views(false); return( true ); } } return( false ); }
//--------------------------------------------------------- wxString CWKSP_Tool_Manager::Get_Description(void) { return( SG_Get_Tool_Library_Manager().Get_Summary().c_str() ); }
//--------------------------------------------------------- inline void CVIEW_Map_Control::_Set_StatusBar(CSG_Point ptWorld) { static bool bBuisy = false; if( bBuisy == false ) { bBuisy = true; CSG_Tool *pProjector = NULL; if( m_pMap->Get_Parameter("GCS_POSITION")->asBool() && m_pMap->Get_Projection().is_Okay() && (pProjector = SG_Get_Tool_Library_Manager().Get_Tool("pj_proj4", 2)) != NULL ) // Coordinate Transformation (Shapes) { if( pProjector->is_Executing() ) { pProjector = NULL; } else { SG_UI_Progress_Lock(true); SG_UI_Msg_Lock (true); CSG_Shapes prj(SHAPE_TYPE_Point), gcs(SHAPE_TYPE_Point); prj.Add_Shape()->Add_Point(ptWorld); prj.Get_Projection().Assign(m_pMap->Get_Projection()); pProjector->Settings_Push(NULL); if( pProjector->Set_Parameter("CRS_PROJ4", SG_T("+proj=longlat +ellps=WGS84 +datum=WGS84")) && pProjector->Set_Parameter("SOURCE" , &prj) && pProjector->Set_Parameter("TARGET" , &gcs) && pProjector->Execute() ) { CSG_Point ptWorld_gcs = gcs.Get_Shape(0)->Get_Point(0); STATUSBAR_Set_Text(wxString::Format("X %s", SG_Double_To_Degree(ptWorld_gcs.Get_X()).c_str()), STATUSBAR_VIEW_X); STATUSBAR_Set_Text(wxString::Format("Y %s", SG_Double_To_Degree(ptWorld_gcs.Get_Y()).c_str()), STATUSBAR_VIEW_Y); pProjector->Settings_Pop(); } else { pProjector->Settings_Pop(); pProjector = NULL; } SG_UI_Progress_Lock(false); SG_UI_Msg_Lock (false); } } if( !pProjector ) { STATUSBAR_Set_Text(wxString::Format("X %f", ptWorld.Get_X()), STATUSBAR_VIEW_X); STATUSBAR_Set_Text(wxString::Format("Y %f", ptWorld.Get_Y()), STATUSBAR_VIEW_Y); } if( m_Mode == MAP_MODE_DISTANCE ) { STATUSBAR_Set_Text(wxString::Format("D %f", m_Distance + m_Distance_Move), STATUSBAR_VIEW_Z); } else if( Get_Active_Layer() ) { STATUSBAR_Set_Text(wxString::Format("Z %s", Get_Active_Layer()->Get_Value(ptWorld, _Get_World(2.0)).c_str()), STATUSBAR_VIEW_Z); } else { STATUSBAR_Set_Text("Z", STATUSBAR_VIEW_Z); } bBuisy = false; } }