//---------------------------------------------------------
void			CMD_Print			(const CSG_String &Text, const SG_Char *XML_Tag)
{
	if( g_bXML )
	{
		if( XML_Tag && XML_Tag[0] )
		{
			SG_PRINTF(SG_T("<%s>%s</%s>\n"), XML_Tag, Text.c_str(), XML_Tag);
		}
	}
	else
	{
		SG_PRINTF(SG_T("%s\n"), Text.c_str());
	}
}
Beispiel #2
0
//---------------------------------------------------------
void			Print			(const SG_Char *String)
{
	if( !g_bSilent && String && String[0] )
	{
		SG_PRINTF(String);
	}
}
Beispiel #3
0
//---------------------------------------------------------
void		SG_UI_Dlg_Message(const SG_Char *Message, const SG_Char *Caption)
{
	if( gSG_UI_Callback )
	{
		gSG_UI_Callback(CALLBACK_DLG_MESSAGE, (long)Message, (long)Caption);
	}
	else
	{
		SG_PRINTF(SG_T("\n%s: %s"), Caption, Message);
	}
}
//---------------------------------------------------------
void			CMD_Get_Pause		(void)
{
	if( g_bInteractive )
	{
		SG_PRINTF(SG_T("%s...\n"), _TL("press any key"));

#ifdef _SAGA_MSW
		_getch();
#endif
	}
}
Beispiel #5
0
//---------------------------------------------------------
void			Get_Pause		(void)
{
	if( g_bInteractive )
	{
		SG_PRINTF(SG_T("\n%s..."), LNG("press any key"));

#ifdef _SAGA_MSW
		_getch();
#endif
	}
}
Beispiel #6
0
//---------------------------------------------------------
void		SG_UI_Msg_Add_Error(const SG_Char *Message)
{
	if( gSG_UI_Msg_Lock )
		return;

	if( gSG_UI_Callback )
	{
		gSG_UI_Callback(CALLBACK_MESSAGE_ADD_ERROR, (long)Message, 0);
	}
	else
	{
		SG_PRINTF(SG_T("\n%s: %s"), LNG("Error"), Message);
	}
}
Beispiel #7
0
//---------------------------------------------------------
void		SG_UI_Process_Set_Text(const SG_Char *Text)
{
	if( gSG_UI_Progress_Lock == 0 )
	{
		if( gSG_UI_Callback )
		{
			gSG_UI_Callback(CALLBACK_PROCESS_SET_TEXT, (long)Text, 0);
		}
		else
		{
			SG_PRINTF(SG_T("\n%s"), Text);
		}
	}
}
//---------------------------------------------------------
bool			CMD_Get_YesNo		(const CSG_String &Caption, const CSG_String &Message)
{
	if( g_bInteractive )
	{
#ifdef _SAGA_MSW
		CSG_String	sKey, sYes(SG_T("y")), sNo(SG_T("n"));

		SG_PRINTF(SG_T("%s: %s\n"), Caption.c_str(), Message.c_str());

		SG_PRINTF(SG_T("%s? (%s/%s)\n"), _TL("continue"), sYes.c_str(), sNo.c_str());

		do
		{
			sKey.Printf(SG_T("%c"), _getch());
		}
		while( sYes.CmpNoCase(sKey) && sNo.CmpNoCase(sKey) );

		return( sYes.CmpNoCase(sKey) == 0 );
#endif
	}

	return( true );
}
Beispiel #9
0
//---------------------------------------------------------
bool			Get_YesNo		(const SG_Char *caption, const SG_Char *message)
{
	if( g_bInteractive )
	{
#ifdef _SAGA_MSW
		CSG_String	sKey, sYes(SG_T("y")), sNo(SG_T("n"));

		SG_PRINTF(SG_T("\n%s: %s\n"), caption, message);

		SG_PRINTF(SG_T("%s? (%s/%s)"), LNG("continue"), sYes.c_str(), sNo.c_str());

		do
		{
			sKey.Printf(SG_T("%c"), _getch());
		}
		while( sYes.CmpNoCase(sKey) && sNo.CmpNoCase(sKey) );

		return( sYes.CmpNoCase(sKey) == 0 );
#endif
	}

	return( true );
}
Beispiel #10
0
//---------------------------------------------------------
void		SG_UI_Msg_Add_Execution(const SG_Char *Message, bool bNewLine, TSG_UI_MSG_STYLE Style)
{
	if( gSG_UI_Msg_Lock )
		return;

	if( gSG_UI_Callback )
	{
		int		Parameters[2];

		Parameters[0]	= bNewLine ? 1 : 0;
		Parameters[1]	= Style;

		gSG_UI_Callback(CALLBACK_MESSAGE_ADD_EXECUTION, (long)Message, (long)Parameters);
	}
	else
	{
		SG_PRINTF(SG_T("%s"), Message);

		if( bNewLine )
		{
			SG_PRINTF(SG_T("\n\n"));
		}
	}
}
//---------------------------------------------------------
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);
	}
}
Beispiel #12
0
//---------------------------------------------------------
bool		SG_UI_Process_Get_Okay(bool bBlink)
{
	if( gSG_UI_Callback )
	{
		return( gSG_UI_Callback(CALLBACK_PROCESS_GET_OKAY, gSG_UI_Progress_Lock && bBlink ? 1 : 0, 0) != 0 );
	}
	else
	{
		if( gSG_UI_Progress_Lock && bBlink )
		{
			static int	iBuisy		= 0;
			const SG_Char	Buisy[4]	= {	'|', '/', '-', '\\'	};

			SG_PRINTF(SG_T("\r%c   "), Buisy[iBuisy++]);
			iBuisy	%= 4;
		}
	}

	return( true );
}
Beispiel #13
0
//---------------------------------------------------------
bool		SG_UI_Process_Set_Progress(double Position, double Range)
{
	if( gSG_UI_Progress_Lock > 0 )
	{
		if( gSG_UI_Callback )
		{
			return( gSG_UI_Callback(CALLBACK_PROCESS_GET_OKAY, 0, 0) != 0 );
		}
	}
	else
	{
		if( gSG_UI_Callback )
		{
			return( gSG_UI_Callback(CALLBACK_PROCESS_SET_PROGRESS, (long)&Position, (long)&Range) != 0 );
		}
		else
		{
			SG_PRINTF(SG_T("\r%3d%%"), Range != 0.0 ? 1 + (int)(100.0 * Position / Range) : 100);
		}
	}

	return( true );
}
Beispiel #14
0
//---------------------------------------------------------
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 );
}
Beispiel #15
0
//---------------------------------------------------------
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 );
}
Beispiel #16
0
//---------------------------------------------------------
int		Callback(TSG_UI_Callback_ID ID, long Param_1, long Param_2)
{
	static int		iBuisy		= 0;
	const SG_Char	Buisy[4]	= {	'|', '/', '-', '\\'	};

	int		Result;
	double	d1, d2;

	Result	= 1;

	//-----------------------------------------------------
	switch( ID )
	{
	default:

		Result	= 0;

		break;


	///////////////////////////////////////////////////////
	//                                                   //
	///////////////////////////////////////////////////////

	//-----------------------------------------------------
	case CALLBACK_PROCESS_GET_OKAY:

		if( !g_bSilent && Param_1 != 0 )
		{
			SG_PRINTF(SG_T("\r%c   "), Buisy[iBuisy++]);

			iBuisy	%= 4;
		}

		break;


	//-----------------------------------------------------
	case CALLBACK_PROCESS_SET_OKAY:

		break;


	//-----------------------------------------------------
	case CALLBACK_PROCESS_SET_PROGRESS:

		if( !g_bSilent )
		{
			d1	= *((double *)Param_1);
			d2	= *((double *)Param_2);

			SG_PRINTF(SG_T("\r%3d%%"), d2 != 0.0 ? 1 + (int)(100.0 * d1 / d2) : 100);
		}

		break;

	//-----------------------------------------------------
	case CALLBACK_PROCESS_SET_READY:

		break;


	//-----------------------------------------------------
	case CALLBACK_PROCESS_SET_TEXT:

		if( !g_bSilent )
		{
			SG_PRINTF(SG_T("\n%s\n"), (SG_Char *)Param_1);
		}

		break;


	///////////////////////////////////////////////////////
	//                                                   //
	///////////////////////////////////////////////////////

	//-----------------------------------------------------
	case CALLBACK_MESSAGE_ADD:

		if( !g_bSilent )
		{
			SG_PRINTF(SG_T("\n%s\n"), (SG_Char *)Param_1);
		}

		break;


	//-----------------------------------------------------
	case CALLBACK_MESSAGE_ADD_ERROR:

		Print_Error((SG_Char *)Param_1);

		break;


	//-----------------------------------------------------
	case CALLBACK_MESSAGE_ADD_EXECUTION:

		if( !g_bSilent )
		{
			SG_PRINTF(SG_T("\n%s\n"), (SG_Char *)Param_1);
		}

		break;


	///////////////////////////////////////////////////////
	//                                                   //
	///////////////////////////////////////////////////////

	//-----------------------------------------------------
	case CALLBACK_DLG_MESSAGE:

		if( !g_bSilent )
		{
			SG_PRINTF(SG_T("\n%s: %s\n"), (const SG_Char *)Param_2, (const SG_Char *)Param_1);
		}

		break;


	//-----------------------------------------------------
	case CALLBACK_DLG_CONTINUE:

		Result	= Get_YesNo((const SG_Char *)Param_2, (const SG_Char *)Param_1);

		break;


	//-----------------------------------------------------
	case CALLBACK_DLG_ERROR:

		Result	= Get_YesNo((const SG_Char *)Param_2, (const SG_Char *)Param_1);

		break;


	///////////////////////////////////////////////////////
	//                                                   //
	///////////////////////////////////////////////////////

	//-----------------------------------------------------
	case CALLBACK_DATAOBJECT_CHECK:

		break;


	//-----------------------------------------------------
	case CALLBACK_DATAOBJECT_ADD:

		Result	= 0;

		if( g_pLibrary )
		{
			Result	= g_pLibrary->Add_DataObject((CSG_Data_Object *)Param_1) ? 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	= 0;

		if( g_pLibrary )
		{
			Result	= g_pLibrary->Get_Parameters((CSG_Parameters *)Param_1) ? 1 : 0;
		}

		break;


	///////////////////////////////////////////////////////
	//                                                   //
	///////////////////////////////////////////////////////

	//-----------------------------------------------------
	}

	return( Result );
}