//--------------------------------------------------------- void CCMD_Module::Usage(void) { if( m_pLibrary && m_pModule ) { CMD_Print(""); wxString sUsage = wxString::Format(SG_T("Usage: saga_cmd %s %s %s"), m_pLibrary->Get_Library_Name().c_str(), m_pModule ->Get_ID ().c_str(), m_CMD.GetUsageString().AfterFirst(' ').AfterFirst(' ') ); SG_PRINTF(sUsage); } }
//--------------------------------------------------------- bool CCMD_Module::Execute(CSG_String sLibName, int argc, char *argv[]) { int i; //----------------------------------------------------- if( !m_pModule ) { return( false ); } if( argc <= 1 ) { wxString sUsage = m_CMD.GetUsageString(); sUsage = wxString::Format(SG_T("Usage: saga_cmd %s %d %s"), sLibName.c_str(), m_pModule->Get_ID(), sUsage.AfterFirst(' ').AfterFirst(' ')); SG_PRINTF(sUsage); return( false ); } //----------------------------------------------------- // m_CMD.SetCmdLine(argc, argv); // // We can't do it this way (passing argv as char**) because then we use an // overload of the method which (re-)sets the locale from the current // enviromment; in order to prevent this, we use wxString overload wxString sCmdLine; for(i=1; i<argc; i++) { wxString sTmp = argv[i]; sCmdLine += wxString::Format(SG_T("\"%s\" "), sTmp.c_str()); } m_CMD.SetCmdLine(sCmdLine); //----------------------------------------------------- bool bResult = _Get_Parameters(m_pModule->Get_Parameters()); for(i=0; bResult && i<m_pModule->Get_Parameters_Count(); i++) { _Get_Parameters(m_pModule->Get_Parameters(i)); } if( !bResult ) { CMD_Print(""); wxString sUsage = m_CMD.GetUsageString(); sUsage = wxString::Format(SG_T("Usage: saga_cmd %s %d %s"), sLibName.c_str(), m_pModule->Get_ID(), sUsage.AfterFirst(' ').AfterFirst(' ')); SG_PRINTF(sUsage); } //----------------------------------------------------- CMD_Set_Module(this); if( bResult && m_pModule->On_Before_Execution() ) { bResult = m_pModule->Execute(); m_pModule->On_After_Execution(); } CMD_Set_Module(NULL); //----------------------------------------------------- if( bResult ) { _Save_Output(m_pModule->Get_Parameters()); for(i=0; i<m_pModule->Get_Parameters_Count(); i++) { _Save_Output(m_pModule->Get_Parameters(i)); } SG_Get_Data_Manager().Delete_Unsaved(); // remove temporary data to save memory resources } else { CMD_Print_Error(_TL("executing tool"), m_pModule->Get_Name()); } return( bResult ); }
//--------------------------------------------------------- int Callback(TSG_UI_Callback_ID ID, CSG_UI_Parameter &Param_1, CSG_UI_Parameter &Param_2) { static int iBuisy = 0; static int iPercent = -1; const SG_Char Buisy[4] = { '|', '/', '-', '\\' }; int Result = 1; //----------------------------------------------------- switch( ID ) { default: Result = 0; break; /////////////////////////////////////////////////////// // // /////////////////////////////////////////////////////// //----------------------------------------------------- case CALLBACK_PROCESS_GET_OKAY: if( g_bShow_Progress && Param_1.True ) { SG_PRINTF(SG_T("\r%c "), Buisy[iBuisy++]); iBuisy %= 4; } break; //----------------------------------------------------- case CALLBACK_PROCESS_SET_OKAY: break; //----------------------------------------------------- case CALLBACK_PROCESS_SET_PROGRESS: if( g_bShow_Progress ) { int i = Param_2.Number != 0.0 ? 1 + (int)(100.0 * Param_1.Number / Param_2.Number) : 100; if( i != iPercent ) { if( g_bXML ) { SG_PRINTF(SG_T("<%s>%d</%s>\n"), SG_XML_PROGRESS, iPercent = i, SG_XML_PROGRESS); } else { if( iPercent < 0 || i < iPercent ) { SG_PRINTF(SG_T("\n")); } SG_PRINTF(SG_T("\r%3d%%"), iPercent = i); } } } break; //----------------------------------------------------- case CALLBACK_PROCESS_SET_READY: iPercent = -1; break; //----------------------------------------------------- case CALLBACK_PROCESS_SET_TEXT: if( g_bShow_Messages ) { CMD_Print(Param_1.String, SG_XML_MESSAGE_PROC); } break; /////////////////////////////////////////////////////// // // /////////////////////////////////////////////////////// //----------------------------------------------------- case CALLBACK_MESSAGE_ADD: if( g_bShow_Messages ) { CMD_Print(Param_1.String, SG_XML_MESSAGE); } break; //----------------------------------------------------- case CALLBACK_MESSAGE_ADD_ERROR: CMD_Print_Error(Param_1.String); break; //----------------------------------------------------- case CALLBACK_MESSAGE_ADD_EXECUTION: if( g_bShow_Messages ) { CMD_Print(Param_1.String, SG_XML_MESSAGE_EXEC); } break; /////////////////////////////////////////////////////// // // /////////////////////////////////////////////////////// //----------------------------------------------------- case CALLBACK_DLG_MESSAGE: if( g_bShow_Messages ) { CMD_Print(Param_2.String + ": " + Param_1.String, NULL); } break; //----------------------------------------------------- case CALLBACK_DLG_CONTINUE: Result = CMD_Get_YesNo(Param_2.String.c_str(), Param_1.String.c_str()); break; //----------------------------------------------------- case CALLBACK_DLG_ERROR: Result = CMD_Get_YesNo(Param_2.String.c_str(), Param_1.String.c_str()); break; /////////////////////////////////////////////////////// // // /////////////////////////////////////////////////////// //----------------------------------------------------- case CALLBACK_DATAOBJECT_ADD: Result = SG_Get_Data_Manager().Add((CSG_Data_Object *)Param_1.Pointer) ? 1 : 0; break; //----------------------------------------------------- case CALLBACK_DATAOBJECT_UPDATE: break; //----------------------------------------------------- case CALLBACK_DATAOBJECT_SHOW: break; //----------------------------------------------------- case CALLBACK_DATAOBJECT_COLORS_GET: break; //----------------------------------------------------- case CALLBACK_DATAOBJECT_COLORS_SET: break; //----------------------------------------------------- case CALLBACK_DATAOBJECT_PARAMS_GET: break; //----------------------------------------------------- case CALLBACK_DATAOBJECT_PARAMS_SET: break; //----------------------------------------------------- case CALLBACK_DLG_PARAMETERS: Result = g_pCMD_Module && g_pCMD_Module->Get_Parameters((CSG_Parameters *)Param_1.Pointer) ? 1 : 0; break; /////////////////////////////////////////////////////// // // /////////////////////////////////////////////////////// //----------------------------------------------------- } return( Result ); }
//--------------------------------------------------------- void CMD_Print_Error (const CSG_String &Error) { CMD_Print(stderr, CSG_String::Format(SG_T("%s: %s"), _TL("Error"), Error.c_str()), SG_XML_ERROR); }