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

📄 fileimport.c

📁 图像处理的压缩算法
💻 C
📖 第 1 页 / 共 3 页
字号:
		}
	}
	else // assume matrix
	{
		MatrixPage matpg(str);
		if( matpg )
		{
/// EJP: how to check if matrix is empty?
///			MatrixLayer ml(str);
///			if( ml && !ml.HasData() )
			return TRUE;
		}
	}
	return FALSE;
}

//--------------------------------------------------------------------------
// GetTargetGraphPage
//
// Determine the target graph page for the data to be plotted in.
// This is determined using the filter and, if drag-drop, the window
// name and layer.
//--------------------------------------------------------------------------
static GraphPage GetTargetGraphPage(TreeNode &trFilter, LPCSTR lpcszWinName, int iWinLayer)
{
	string strWinName;
	if( lpcszWinName )
		strWinName = lpcszWinName;

	GraphPage pageGraph(strWinName);
	if( pageGraph ) // if DragDrop on Graph window
	{
		if( FILTER_DDGRAPH_OPENONLY == fuGetDragDropGraph(trFilter) )
			pageGraph.Detach(); // do not plot the data
	}
	else if( strWinName.IsEmpty() ) // if File Open or DragDrop on Workspace
	{
		int iDragDrop = fuGetDragDropWorkspace(trFilter);

		if( iDragDrop == FILTER_DDWORKSPACE_PLOT_1LAYER ||
			iDragDrop == FILTER_DDWORKSPACE_PLOT_MULTILAYER )
		{
			GraphPage pgTemp(s_strGraphPage);
			pageGraph = pgTemp;
		}

		if( !pageGraph && iDragDrop != FILTER_DDWORKSPACE_OPENONLY )
		{
			string str = fuGetPlotTemplate(trFilter);
			if( str.IsEmpty() )
				pageGraph.Create(); // default template
			else
				pageGraph.Create(str);
			
			if( pageGraph )
				s_strGraphPage = pageGraph.GetName();	
		}
	}

	return pageGraph;
}

//--------------------------------------------------------------------------
// GraphData
//
// Determine the target graph page for the data to be plotted in.
// This is determined using the filter and, if drag-drop, the window
// name and layer.
//
// Return:
// zero for success, non-zero for error
//--------------------------------------------------------------------------
static int GraphData(GraphPage &grpgTarget, int iLayer, int iPlotID, Page &pageData)
{
	GraphLayer grLayer = grpgTarget.Layers(iLayer);

	switch( pageData.GetType() )
	{
	case EXIST_WKS:
		Worksheet wks = pageData.Layers();
		grLayer.AddPlot(wks, iPlotID);
		break;
	case EXIST_MATRIX:
/// EJP 03-07-2003: Currently we can not get Matrix.  CP will fix.
///		Matrix mat = pageData.Layers();
///		grLayer.AddPlot(mat, iPlotID);
		break;
	default:
		return 1; // unsupported page type
	}
		
	return 0; // success
}

//--------------------------------------------------------------------------
// PrepareWksColsForImport
//
// Call this function to setup the columns for a named wks based on the
// settings in a filter.
//
// This function still does not consider partial import nor import mode
// settings.
//#define ASCIMP_MODE_REPLACE_DATA		0
//#define ASCIMP_MODE_APPEND_COLS			1
//#define ASCIMP_MODE_APPEND_ROWS			2
//--------------------------------------------------------------------------
int PrepareWksColsForImport(Page &pgTarget, TreeNode &trFilter, LPCSTR lpcszFile)
{
	int n, nCols = 0;
	string str;

	Worksheet wks(pgTarget.GetName());
	if( !wks )
		return IMPERR_PREPARE_WKS; // error, no worksheet
	
	///////////////////////////////////////////////////////
	// The following (switch on filter type) will set nCols
	// to the number of columns in the data file.
	// This number may not always be correct, but should be
	// sufficient for setting up the wks columns.
	//
	// It may be easier/safer to use the ColDesignations or
	// ColFormats setting in the filter.  I will look into
	// this later.
	///////////////////////////////////////////////////////
	switch( trFilter.Type.nVal )
	{
	case FILTER_TYPE_ASCII:
		ASCIMP ascimp;
		fuGetASCIMP(trFilter, ascimp);
		if( ascimp.iDelimited )
		{
			/// EJP 07-29-2003 v7.0637 QA70-4898 PREPARE_WKS_FOR_IMPORT_NEED_USE_CORRECT_NUM_COLUMNS
			// The wizard has been improved as far as scanning number of columns.
			// The user also now has the ability to set the number of columns.
			// Here we should assume the filter contains the correct number of columns.
			///	// This scans the file and tries to figure out
			///	// the delimiter and then counts the columns.
			///	// While the filter already contains the delimiter
			///	// there is no way to pass that to the scanning
			///	// function.
			///	ASCIMP ascimpTemp;
			///	AscImpReadFileStruct(lpcszFile, &ascimpTemp);
			///	nCols = ascimpTemp.iNumColumns;
			nCols = ascimp.iNumColumns;
			/// end PREPARE_WKS_FOR_IMPORT_NEED_USE_CORRECT_NUM_COLUMNS
		}
		else // fixed width, count tokens
		{
			// This counts the number of column widths
			// specified by the user.  This may be less than
			// the actual columns in the file since the last
			// width value is repeated until the end of line
			// is reached
			str = ascimp.szFixedWidth;
			nCols = str.GetNumTokens(',');
		}
		break;
	case FILTER_TYPE_BINARY:
		BINIMP binimp;
		fuGetBINIMP(trFilter, binimp);
		for( n = 0; n < binimp.vParamCount.GetSize(); n++ )
			nCols += binimp.vParamCount[n];
		if( nCols != binimp.iNumColumns )
		{
			binimp.iNumColumns = nCols;
			printf("BINIMP.iNumColumns updated\n");
		}
		break;
	case FILTER_TYPE_USERDEFINED:
		return IMPERR_NONE; // filter type not supported
	default:
		return IMPERR_FILTER_TYPE; // error, unknown filter type
	}

	///////////////////////////////////////////////////
	// The following will adjust nCols based on the
	// partial import settings.
	///////////////////////////////////////////////////
	int nFirstSourceCol = 0;
	if( trFilter.Common.Partial.nVal )
	{
		nFirstSourceCol = trFilter.Common.PartialC1.nVal;
		
		if( nFirstSourceCol > trFilter.Common.PartialC2.nVal )
			nCols -= nFirstSourceCol;
		else
			nCols = trFilter.Common.PartialC2.nVal - nFirstSourceCol + 1;
	}
	
	///////////////////////////////////////////////////
	// The following (switch on import mode) will
	// adjust nCols based on the import mode.
	///////////////////////////////////////////////////
	int nFirstTargetCol = 0;
	int nNumExistingCols = wks.GetNumCols();
	int nNewCols = 0;
	switch( fuGetImportMode(trFilter) )
	{
	case ASCIMP_MODE_REPLACE_DATA:
	case ASCIMP_MODE_APPEND_ROWS:
		if( nCols > nNumExistingCols )
			nNewCols = nCols - nNumExistingCols;
		break;
	case ASCIMP_MODE_APPEND_COLS:
		nFirstTargetCol = FindEmptyColumn(wks);
		if( nFirstTargetCol >= 0 )
		{
			nNewCols = nCols - (nNumExistingCols - nFirstTargetCol);
		}
		else // no empty columns
		{
			nFirstTargetCol = nNumExistingCols;
			nNewCols = nCols;
		}
		break;
	}
	/// EJP 08-29-2003 v7.5680 IMPROVE_IMPORT_SPEED_OF_MANY_COLS
	///for( n = nNumExistingCols; n < nCols; n++ )
	///wks.AddCol();
	if( nNewCols > 0 )
	{
		str.Format("work -a %d", nNewCols);
		pgTarget.LT_execute(str);
	}
	/// end IMPROVE_IMPORT_SPEED_OF_MANY_COLS

	///////////////////////////////////////////////////////
	// The follwoing will construct the designation and
	// format strings.
	///////////////////////////////////////////////////////
	bool bRepetitive = fuGetRepetitive(trFilter);

	// Start with the designations and formats in the filter.
	string strColDesig = fuGetDesignations(trFilter);
	string strColFormat = fuGetFormats(trFilter);

	// If a partial import then remove the skipped columns	
	if( nFirstSourceCol )
	{
		strColDesig.Delete(0, nFirstSourceCol);
		strColFormat.Delete(0, nFirstSourceCol);
	}
	
	/// EJP 08-07-2003 v7.0648 QA70-4934 FIX_COL_DESIGNATIONS_AND_FORMATS_SET
	/*
	if( nNumExistingCols ) // if not replacing data
	{
		if( ASCIMP_MODE_APPEND_ROWS == fuGetImportMode(trFilter) )
		{
			strColDesig.Delete(0, nNumExistingCols);
			strColFormat.Delete(0, nNumExistingCols);
		}

		string strExistColDesig = wks.GetColDesignations();
		if( strExistColDesig.GetLength() > nNumExistingCols )
			strExistColDesig.Delete(nNumExistingCols, strExistColDesig.GetLength() - nNumExistingCols);
			
		string strExistColFormat = wks.GetColFormats();
		if( strExistColFormat.GetLength() > nNumExistingCols )
			strExistColFormat.Delete(nNumExistingCols, strExistColFormat.GetLength() - nNumExistingCols);
		
		strColDesig.Insert(0, strExistColDesig);
		strColFormat.Insert(0, strExistColFormat);
	}
	*/
	if( nFirstTargetCol ) // if not importing into the first column
	{
		string strExistColDesig = wks.GetColDesignations();
		strExistColDesig.Delete(nFirstTargetCol, strExistColDesig.GetLength() - nFirstTargetCol);
		strColDesig.Insert(0, strExistColDesig);
		
		string strExistColFormat = wks.GetColFormats();
		strExistColFormat.Delete(nFirstTargetCol, strExistColFormat.GetLength() - nFirstTargetCol);
		strColFormat.Insert(0, strExistColFormat);
	}
	/// end FIX_COL_DESIGNATIONS_AND_FORMATS_SET

	/// EJP 08-12-2003 v7.0656 QA70-4808 IMPORT_INTO_LOCKED_COL_WARNING
	if( wks.IsWriteProtected(nFirstTargetCol, nFirstTargetCol + nCols) )
	{
		if( IDNO == MessageBox(GetWindow(),
			_L("The data's target window has a locked column.\nDo you want to continue import?"),
			_L("File Import"), MB_YESNO) )
		{
			return IMPERR_CANCEL_ON_LOCKED_COL;
		}
	}
	/// end IMPORT_INTO_LOCKED_COL_WARNING
	
	/// EJP 09-15-2003 v7.5695 QA70-5135.19 AVOID_UNWANTED_REPEATING_OF_LAST_COL_DESIG_AND_FORMAT
	// When the col designation and format strings have less cols than the wks
	// we need to append the current existing settings to avoid having our
	// last setting repeating and overwriting the existing settings.
	if( strColDesig.GetLength() < wks.GetNumCols() && !bRepetitive )
	{
		string strTmp = wks.GetColFormats();
		strTmp.Delete(0, strColDesig.GetLength());
		strColFormat += strTmp;
		
		strTmp = wks.GetColDesignations();
		strTmp.Delete(0, strColDesig.GetLength());
		strColDesig += strTmp;
	}
	/// end AVOID_UNWANTED_REPEATING_OF_LAST_COL_DESIG_AND_FORMAT
	
	if( !strColDesig.IsEmpty() )
		wks.SetColDesignations(strColDesig, bRepetitive);
	if( !strColFormat.IsEmpty() )
		wks.SetColFormats(strColFormat, bRepetitive);

	return IMPERR_NONE;
}

//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
static int HeaderVariablesToPageInfo(Page &pgTarget, TreeNode &trFilter, LPCSTR lpcszFile)
{
	if( !pgTarget || lpcszFile == NULL )
		return 1;
	
	pgTarget.Info.Add("User");
	pgTarget.Info.User.AddSection("Variables");
	
	StringArray saNames;
	StringArray saValues;
	GetHeaderVariableNamesAndValues(trFilter, saNames, saValues, lpcszFile);

	string str;
	
	using var = pgTarget.Info.User.Variables;    
	for( int n = 0; n < saNames.GetSize(); n++ )
		var.AddString(saNames[n], saValues[n]);

	return 0;
}

static int GetHeaderVariableNamesAndValues(TreeNode &trFilter, StringArray &saNames, StringArray &saValues, LPCSTR lpcszFile)
{
	if( FILTER_TYPE_ASCII != trFilter.Type.nVal && FILTER_TYPE_BINARY != trFilter.Type.nVal )
		return 1;

	saNames.SetSize(0);
	saValues.SetSize(0);

	string str;
	
	if( FILTER_TYPE_ASCII == trFilter.Type.nVal )
	{
		/// EJP 07-28-2003 v7.0637 QA70-4911 IMPROVE_HDR_VAR_SCAN
		/*
		int iFirstLine, iLastLine, iSeparator;
		if( fuGetHdrVarScan(trFilter, iFirstLine, iLastLine, iSeparator) )
		{
			StringArray saLines;
			ReadFileLines(saLines, lpcszFile, iLastLine - iFirstLine + 1, iFirstLine);

⌨️ 快捷键说明

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