⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sys_utils.c

📁 图像处理的压缩算法
💻 C
📖 第 1 页 / 共 4 页
字号:
*/
string BrowseGetPath( LPCSTR lpcszPath, LPCSTR lpcszDialogName ) // lpcszPath = NULL, lpcszDialogName = NULL
{
	double dErr;
	char szTemp[ MAXFULLPATH ];
	string strDefaultPath = lpcszPath;
	string strDialogName = lpcszDialogName;
	string strReturnPath;

	_LT_Obj
	{
		if( strDefaultPath.IsEmpty() )               // If path is not passed as argument...
			strDefaultPath = FDLog.Path$;            //   get last used path from FDLog object for tracking

		FDLogInit();                                 // Initialize LabTalk FDLog object

		if( !strDefaultPath.IsEmpty() )              // If path is passed as argument...
		{
			FDLog.Path$ = strDefaultPath;            //   initialize path
			FDLog.Default$ = strDefaultPath;         //   initialize filename which is same as path for this DB
		}
		FDLog.DlgName$ = strDialogName;              // Initialize dialog box name

		dErr = FDLog.OpenPath( "A" );   // Open browse dialog box and put result into %A Labtalk string
		
		if( dErr )                      // If Cancel button is clicked...
			strReturnPath.Empty();      //   return empty string
		else                            // Else OK is clicked...
		{
			LT_get_str( "%A", szTemp, MAXFULLPATH );//   get path browsed to from %A LabTalk variable
			strReturnPath = szTemp;                 //   return path browsed to
		}
	}

	return strReturnPath;
}

//////////////////////////////////////////////////////////////////////////////////
/**
		Open an FDLog Open dialog box passing the file types to list in an array
		of strings.
	Example:
		string strPath;
		StringArray saFiletypes;
		saFiletypes.SetSize( 3 );
		saFiletypes[0]="[Project (*.OPJ)] *.OPJ";
		saFiletypes[1]="[Old version (*.ORG)] *.ORG";
		saFiletypes[2]="[Worksheets (*.OGW)] *.OGW";
		strPath = GetOpenBox( saFiletypes ); // or
		//strPath = GetOpenBox( saFiletypes, "C:\\Program Files\\" ); // or
		//strPath = GetOpenBox( saFiletypes, "C:\\Program Files\\", "Origin" ); // or
		//strPath = GetOpenBox( saFiletypes, "C:\\Program Files\\", "Origin", "OpenOPJ" );
		if( strPath.IsEmpty() )
			out_str( "User has cancelled the Open dialog box." );
		else
			printf( "The file chosen is %s\n.", strPath );
	Parameters:
		saFiletypes=Vector containing file types to list in the dialog box, each element
			of vector must follow syntax of LabTalk FDLog.TypeN$ object property
		lpcszPath=Initial path when dialog opens, default NULL uses FDLog tracking
		lpcszFileName=Initial filename when dialog opens, default NULL uses an empty string 
		lpcszDialogName=Title of the dialog box, default NULL uses "Open" 
	Return:
		Returns the path and filename of a selecetd file or an empty string if Cancel button
		in dialog box is clicked.
*/
string GetOpenBox( StringArray &saFiletypes, LPCSTR lpcszPath, LPCSTR lpcszFilename,
	 LPCSTR lpcszDialogName ) // lpcszPath = NULL, lpcszFilename = NULL, lpcszDialogName = NULL
{
	//------------------- GJL v7.0357 QA70-4078 3/17/03 ORIGINC_MULTI_OPEN_SUPPORT
	StringArray saFilePaths;
	GetFileDialogBox( saFilePaths, saFiletypes, FDLOG_TYPE_OPEN_SINGLE, lpcszPath, lpcszFilename, lpcszDialogName );
	return saFilePaths[0];
	//return GetFileDialogBox( saFiletypes, FALSE, lpcszPath, lpcszFilename, lpcszDialogName );
	//------------------- QA70-4078
}

/**
		An FDLog.UseGroup version of GetOpenBox that uses an enumerated FDLog.UseGroup
		code to indicate the set of file types to list. See sys_utils.h or the Origin.ini
		file for a list of the enumerated FDLOG.UseGroup codes.
	Example:
		string strPath;
		strPath = GetOpenBox( FDLOG_ORIGIN ); // or
		//strPath = GetOpenBox( FDLOG_EXCEL, "C:\\Program Files\\" ); // or
		//strPath = GetOpenBox( FDLOG_ASCII, "C:\\Program Files\\", "Origin" ); // or
		//strPath = GetOpenBox( FDLOG_SCRIPT, "C:\\Program Files\\", "Origin", "OpenOGS" );
		if( strPath.IsEmpty() )
			out_str( "User has cancelled the Open dialog box." );
		else
			printf( "The file chosen is %s\n.", strPath );
	Parameters:
		nFDLogUseGroup=A LabTalk FDLog.UseGroup code as enumerated in sys_utils.h and in
			the Origin.ini file
		lpcszPath=Initial path when dialog opens, default NULL uses FDLog tracking
		lpcszFileName=Initial filename when dialog opens, default NULL uses an empty string
		lpcszDialogName=Title of the dialog box, default NULL uses "Open"
	Return:
		Returns the path and filename of a selected file or an empty string if Cancel button
		in dialog box is clicked.
*/
string GetOpenBox( FDLogUseGroup nFDLogUseGroup, LPCSTR lpcszPath, LPCSTR lpcszFilename,
	 LPCSTR lpcszDialogName ) // lpcszPath = NULL, lpcszFilename = NULL, lpcszDialogName = NULL
{
	//------------------- GJL v7.0357 QA70-4078 3/17/03 ORIGINC_MULTI_OPEN_SUPPORT
	StringArray saFilePaths;
	GetFileDialogBox( saFilePaths, nFDLogUseGroup, FDLOG_TYPE_OPEN_SINGLE, lpcszPath, lpcszFilename, lpcszDialogName );
	return saFilePaths[0];
	//return GetFileDialogBox( nFDLogUseGroup, FALSE, lpcszPath, lpcszFilename, lpcszDialogName );
	//------------------- QA70-4078

}

//////////////////////////////////////////////////////////////////////////////////
/**
		An easier to use version of GetOpenBox that works for a single file type.
	Example:
		string strPath;
		strPath = GetOpenBox(); // or
		//strPath = GetOpenBox( "[Old version (*.ORG)] *.ORG" ); // or
		//strPath = GetOpenBox( "*.OPJ"); // or
		//strPath = GetOpenBox( "*.ocw Workspace", GetAppPath() + "OriginC\\" ); // or
		//strPath = GetOpenBox( "*.ocw Workspace", GetAppPath() + "OriginC\\", "Origin" ); // or
		//strPath = GetOpenBox( "*.ocw Workspace", "C:\\Program Files\\", "Origin", "Open Workspace" );
		if( strPath.IsEmpty() )
			out_str( "User has cancelled the Open dialog box." );
		else
			printf( "The file chosen is %s\n.", strPath );
	Parameters:
		lpcszFileType="*.ext description", or "[decription (*.ext)] *.ext", or just "*.ext"
		lpcszPath=Initial path when dialog opens, default NULL uses FDLog tracking
		lpcszFileName=Initial filename when dialog opens, default NULL uses an empty string
		lpcszDialogName=Title of the dialog box, default NULL uses "Open"
	Return:
		Returns the path and filename of a selecetd file or an empty string if Cancel button
		in dialog box is clicked.
*/
string GetOpenBox( LPCSTR lpcszFileType, LPCSTR lpcszPath, LPCSTR lpcszFilename,
	 LPCSTR lpcszDialogName ) // lpcszFileType = "*.* All Files", lpcszPath = NULL, lpcszFileName = NULL, lpcszDialogName = NULL
{
	//------------------- GJL v7.0357 QA70-4078 3/17/03 ORIGINC_MULTI_OPEN_SUPPORT
	StringArray saFilePaths;
	GetFileDialogBox( saFilePaths, lpcszFileType, FDLOG_TYPE_OPEN_SINGLE, lpcszPath, lpcszFilename, lpcszDialogName );
	return saFilePaths[0];
	//return GetFileDialogBox( lpcszFileType, FALSE, lpcszPath, lpcszFilename, lpcszDialogName );
	//------------------- QA70-4078
}

//////////////////////////////////////////////////////////////////////////////////
/**
		Open an FDLog SaveAs dialog box passing the file types to list in an array
		of strings.
	Example:
		string strPath;
		StringArray saFiletypes;
		saFiletypes.SetSize( 3 );
		saFiletypes[0]="[Project (*.OPJ)] *.OPJ";
		saFiletypes[1]="[Old version (*.ORG)] *.ORG";
		saFiletypes[2]="[Worksheets (*.OGW)] *.OGW";
		strPath = GetSaveAsBox( saFiletypes ); // or
		//strPath = GetSaveAsBox( saFiletypes, "C:\\Program Files\\" ); // or
		//strPath = GetSaveAsBox( saFiletypes, "C:\\Program Files\\", "Origin" ); // or
		//strPath = GetSaveAsBox( saFiletypes, "C:\\Program Files\\", "Origin", "SaveAsOPJ" );
		if( strPath.IsEmpty() )
			out_str( "User has cancelled the SaveAs dialog box." );
		else
			printf( "The file chosen is %s\n.", strPath );
	Parameters:
		saFiletypes=Vector containing file types to list in the dialog box, each element
			of vector must follow syntax of LabTalk FDLog.TypeN$ object property
		lpcszPath=Initial path when dialog opens, default NULL uses FDLog tracking
		lpcszFileName=Initial filename when dialog opens, default NULL uses an empty string 
		lpcszDialogName=Title of the dialog box, default NULL uses "SaveAs" 
	Return:
		Returns the path and filename of a selecetd file or an empty string if Cancel button
		in dialog box is clicked.
*/
string GetSaveAsBox( StringArray &saFiletypes, LPCSTR lpcszPath, LPCSTR lpcszFilename,
	 LPCSTR lpcszDialogName ) // lpcszPath = NULL, lpcszFilename = NULL, lpcszDialogName = NULL
{
	//------------------- GJL v7.0357 QA70-4078 3/17/03 ORIGINC_MULTI_OPEN_SUPPORT
	StringArray saFilePaths;
	GetFileDialogBox( saFilePaths, saFiletypes, FDLOG_TYPE_SAVE_AS, lpcszPath, lpcszFilename, lpcszDialogName );
	return saFilePaths[0];
	//return GetFileDialogBox( saFiletypes, TRUE, lpcszPath, lpcszFilename, lpcszDialogName );
	//------------------- QA70-4078
}

/**
		An FDLog.UseGroup version of GetSaveAsBox that uses an enumerated FDLog.UseGroup
		code to indicate the set of file types to list. See sys_utils.h or the Origin.ini
		file for a list of the enumerated FDLOG.UseGroup codes.
	Example:
		string strPath;
		strPath = GetSaveAsBox( FDLOG_ORIGIN ); // or
		//strPath = GetSaveAsBox( FDLOG_EXCEL, "C:\\Program Files\\" ); // or
		//strPath = GetSaveAsBox( FDLOG_ASCII, "C:\\Program Files\\", "Origin" ); // or
		//strPath = GetSaveAsBox( FDLOG_SCRIPT, "C:\\Program Files\\", "Origin", "SaveAsOGS" );
		if( strPath.IsEmpty() )
			out_str( "User has cancelled the SaveAs dialog box." );
		else
			printf( "The file chosen is %s\n.", strPath );
	Parameters:
		nFDLogUseGroup=A LabTalk FDLog.UseGroup code as enumerated in sys_utils.h and in
			the Origin.ini file
		lpcszPath=Initial path when dialog opens, default NULL uses FDLog tracking
		lpcszFileName=Initial filename when dialog opens, default NULL uses an empty string
		lpcszDialogName=Title of the dialog box, default NULL uses "SaveAs"
	Return:
		Returns the path and filename of a selected file or an empty string if Cancel button
		in dialog box is clicked.
*/
string GetSaveAsBox( FDLogUseGroup nFDLogUseGroup, LPCSTR lpcszPath, LPCSTR lpcszFilename,
	 LPCSTR lpcszDialogName ) // lpcszPath = NULL, lpcszFilename = NULL, lpcszDialogName = NULL
{
	//------------------- GJL v7.0357 QA70-4078 3/17/03 ORIGINC_MULTI_OPEN_SUPPORT
	StringArray saFilePaths;	
	GetFileDialogBox( saFilePaths, nFDLogUseGroup, FDLOG_TYPE_SAVE_AS, lpcszPath, lpcszFilename, lpcszDialogName );
	return saFilePaths[0];
	//return GetFileDialogBox( nFDLogUseGroup, TRUE, lpcszPath, lpcszFilename, lpcszDialogName );
	//------------------- QA70-4078
}

//////////////////////////////////////////////////////////////////////////////////
/**
		An easier to use version of GetSaveAsBox that works for a single file type.
	Example:
		string strPath;
		strPath = GetSaveAsBox(); // or
		//strPath = GetSaveAsBox( "[Old version (*.ORG)] *.ORG" ); // or
		//strPath = GetSaveAsBox( "*.OPJ"); // or
		//strPath = GetSaveAsBox( "*.ocw Workspace", GetAppPath() + "OriginC\\" ); // or
		//strPath = GetSaveAsBox( "*.ocw Workspace", GetAppPath() + "OriginC\\", "Origin" ); // or
		//strPath = GetSaveAsBox( "*.ocw Workspace", "C:\\Program Files\\", "Origin", "SaveAs Workspace" );
		if( strPath.IsEmpty() )
			out_str( "User has cancelled the SaveAs dialog box." );
		else
			printf( "The file chosen is %s\n.", strPath );
	Parameters:
		lpcszFileType="*.ext description", or "[decription (*.ext)] *.ext", or just "*.ext"
		lpcszPath=Initial path when dialog opens, default NULL uses FDLog tracking
		lpcszFileName=Initial filename when dialog opens, default NULL uses an empty string
		lpcszDialogName=Title of the dialog box, default NULL uses "SaveAs"
	Return:
		Returns the path and filename of a selecetd file or an empty string if Cancel button
		in dialog box is clicked.
*/
string GetSaveAsBox( LPCSTR lpcszFileType, LPCSTR lpcszPath, LPCSTR lpcszFilename,
	 LPCSTR lpcszDialogName ) // lpcszFileType = "*.* All Files", lpcszPath = NULL, lpcszFileName = NULL, lpcszDialogName = NULL
{
	//------------------- GJL v7.0357 QA70-4078 3/17/03 ORIGINC_MULTI_OPEN_SUPPORT
	StringArray saFilePaths;	
	GetFileDialogBox( saFilePaths, lpcszFileType, FDLOG_TYPE_SAVE_AS, lpcszPath, lpcszFilename, lpcszDialogName );
	return saFilePaths[0];
	//return GetFileDialogBox( lpcszFileType, TRUE, lpcszPath, lpcszFilename, lpcszDialogName );
	//------------------- QA70-4078
}

/////////////////////////////////////////////////////////////////
// These functions make it easy to put complex expression together
/////////////////////////////////////////////////////////////////
//---- CPY 2/3/03 we have decided to change to use Macros so that Re(aa)=1 can be used
//
//double Re(complex cc)
//{
//	return cc.m_re;
//}
//double Im(complex cc)
//{
//	return cc.m_im;
//}
//----
complex Conj(complex cc)
{
	return cc.Conjugate();
}

/** >Character/String Manipulation
		Converts string to a complex. If the input cannot be converted to a value of complex. The return value is undefined.
		The function stops reading the input string at the first character that it cannot recognize as part of a number. 
		This character may be the null character ('\0') terminating the string.
	Parameter:
		lpcsz = the string to convert.
	Return:
		a complex
	Example:
		void	run_atof()
		{
			char	szString[] = " -4.05 - 3.007i";
			complex	c = atof(szString);
			out_complex("value = ", c);
		}
*/
#define IS_INTRODUCTORY_LETTER(_cc) ( (_cc) == 'e' || (_cc) == 'E' || (_cc) == 'd' || (_cc) == 'D' )
#define IS_PLUS_OR_MINUS(_cc) ( (_cc) == '-' || (_cc) == '+' )

complex atoc(LPCSTR lpcsz)
{
	complex c;

	string str(lpcsz);
	str.TrimRight();
	str.TrimLeft();
	
	int nLength = str.GetLength();
	if( nLength <= 0 )
		return c;
	
	LPSTR lpstr = str.GetBuffer(nLength + 1);
	LPSTR lpc = lpstr + nLength - 1;
	
	if( 'i' == *lpc )
	{
		*lpc = '\0';
		
		// Find operator '+' or '-'
		while( lpc > lpstr )
		{
			// if not an exponent sign
			if( IS_PLUS_OR_MINUS(*lpc) && !IS_INTRODUCTORY_LETTER(*(lpc - 1)) )
				break; // we found the operator
			lpc--;
		}
		
		// Get the imaginary part
		LPSTR lpIm;
		if( lpc == lpstr )
			lpIm = lpc;
		else
			lpIm = (lpc + 1);
		
		string strIm(lpIm);
		strIm.TrimRight();
		strIm.TrimLeft();
		
		if( IS_PLUS_OR_MINUS(*lpc) )
			strIm.Insert(0, *lpc);

		if( (c.m_im = atof(strIm)) == 0.0 )
			c.m_im = 1; // If only 'i' in the imaginary part

		*lpc = '\0';
	}
	
	// Get the real part
	c.m_re = atof(lpstr);
	str.ReleaseBuffer(nLength);
	
	return c;
}

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

// this function is added because LabTalk has both rnd and ran, so we allow
// the same in Origin C
double ran(int nSeed)
{
	return rnd(nSeed);
}

//////////////////////////////////////////////////////////////////////////////////
/** >System
		Get the text data copied onto the clipboard.
	Example:
		string strClipboardText;
		BOOL bSuccess;
		bSuccess = GetClipboardText( strClipboardText );
		if( bSuccess )
			out_str( strClipboardText );
		else
			out_str( "Error reading Clipboard or Clipboard is empty." );
	Parameters:
		strData = Output text copied from clipboard
	Return:
		Returns TRUE and a string containing text copied onto the clipboard
		on success or returns FALSE and an empty string on failure or if
		the Clipboard is empty.
*/
BOOL GetClipboardText( string& strData )
{
	BOOL bRet = FALSE;                                        // Declare and intitialize variables                                             
	strData = "";
	
	if( OpenClipboard(NULL) )                                 // If the clipboard opens successflly...

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -