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

📄 wks_utils.c

📁 图像处理的压缩算法
💻 C
📖 第 1 页 / 共 4 页
字号:
				iRet = GetNonContiguousWksSelection(strSelectedRanges, iNumRanges, TRUE); // Get entire worksheet/workbook as selection

			if( iRet )                                                         // Now if no selection or bad selection...
			{
				if( !bAppend )                                                 // If user is not appending...
				{
					tr.Reset();                                                // Reset node
					tr.Range1.Display.strVal = "";                             // Indicate no selection
					tr.Range1.C1.nVal = -1;
					tr.Wks.strVal = "";
				}
				return iRet;                                                   // Return warning or error code
			}
		}
	
		if( bAppend )                                                          // If user wants to append...
			iBeginNodeNum = tr.GetNodeCount() - 1;                             // Set begining node number - 1 for Wks node
		else                                                                   // Else not appending...
		{
			tr.Reset();                                                        // Reset TreeNode
			iBeginNodeNum = 0;                                                 // Set begining node number to 0
		}
	
		for( ii = 0; ii < iNumRanges; ii++ )                                   // For each selected range...
		{
			strRange = strSelectedRanges.GetToken( ii, ',' );                  // Get range
			ParseWksSelection(strRange, strWksName, strSheetName, iC1, iC2, iR1, iR2); // Parse range into column and row indices
			strRange = GetSingleColumnRangeWithoutRows(strRange);              // Only add single column range without rows                       
			strNodeName.Format("Range%d", ii + iBeginNodeNum + 1);             // Get subnode name
			trSubNode = tr.AddNode(strNodeName);                               // Add subnode to tree
			trSubNode.Display.strVal = strRange;                               // Assign display and index nodes
			trSubNode.C1.nVal = iC1;
			trSubNode.C2.nVal = iC1;
			trSubNode.R1.nVal = -1;
			trSubNode.R2.nVal = -1
		}
		
		tr.Wks.strVal = strWksName;
	}
	else                                                                       // Else TreeNode is invalid return error...
		return WKS_UTILS_INVALID_TREENODE_ERROR;

	return WKS_UTILS_NO_ERROR;                                                 // Success!
}




typedef	bool	(*PFN_tree_reporting_prepare_targets)(TreeNode &trRep, DWORD &dwTarget, string &strNoteWnd, BOOL *pbAppendToNote);




/**
		It outputs a report from a worksheet to a Note window and/or to the Ouput log, based on the
		parameters supplied by the trRep tree argument.
	Example:
		// Make sure that there is a worksheet with the name "Data1" with at least five columns and
		// 35 rows before running this example.
		void	test_wks_report()
		{
			Worksheet		wks("Data1");
			
			Tree			trWhole;
			
			// How?
			trWhole.Reporting.Settings.Outputlog.Mode.nVal = 0;
			
			trWhole.Reporting.Settings.Note.Name.strVal = "Note1";
			trWhole.Reporting.Settings.Note.Mode.nVal = 1;
			//
			
			// What?
			trWhole.Reporting.Contents.Wks.Range1.r1.nVal = 17;
			trWhole.Reporting.Contents.Wks.Range1.r2.nVal = 22;
			trWhole.Reporting.Contents.Wks.Range1.c1.nVal = 1;
			trWhole.Reporting.Contents.Wks.Range1.c2.nVal = 3;
			
			trWhole.Reporting.Contents.Wks.Range1.r1.nVal = 25;
			trWhole.Reporting.Contents.Wks.Range1.r2.nVal = 33;
			trWhole.Reporting.Contents.Wks.Range1.c1.nVal = 2;
			trWhole.Reporting.Contents.Wks.Range1.c2.nVal = 4;
			//
		
			/////
			if (trWhole.Reporting)
				wks_report(wks, trWhole.Reporting, TRUE);
			/////
		}
	Parameters:
		wksOutput=the worksheet to be output.
	Return:
		Returns TRUE if OK, otherwise FALSE.
*/
BOOL  	wks_report(Worksheet& wksOutput, TreeNode &trRep, BOOL bBatchProcessing)
{
	if (!trRep || !wksOutput)
	{
		ASSERT(FALSE);
		return FALSE;
	}
	
	
	TreeNode		trSett = trRep.Settings;
	if (!trSett)
	{
		out_str("No Settings branch, don't know how to report.");
		return TRUE;
	}
	
	// Printing:
	if( bBatchProcessing )
	{
		TreeNode	trWks = trRep.Settings.Wks;
		if( trWks )
		{
			WorksheetPage WksPage;
			wksOutput.GetParent(WksPage);

			if( WksPage )
				WksPage.Print(trWks);
		}
	}

	
	TreeNode		trCntsWks = trRep.Settings.Wks;
	if (!trCntsWks)
	{
		out_str("No Contents.Wks branch, nothing to report.");
		return TRUE;
	}
	

	/*
	// Output log:
	BOOL			bOutputLogReplace = FALSE;
	DWORD			dwTarget = 0;
	if (trSett.Outputlog)
	{
		dwTarget |= TYPETARGET_OUTPUTLOG;
		if (trSett.Outputlog.Mode)
			bOutputLogReplace = trSett.Outputlog.Mode.nVal;
		
		// Here need to empty OutputLog if bOutputLogReplace.
	}

	// Notes window:
	string			strNoteWnd;
	BOOL			bNoteTextReplace = FALSE;
	if (trSett.Note)
	{
		if (trSett.Note.Mode)
			bNoteTextReplace = trSett.Note.Mode.nVal;
		
		if (trSett.Note.WINDOWNAME)
			strNoteWnd = trSett.Note.WINDOWNAME.strVal;
		
		if ( !strNoteWnd.IsEmpty() && get_create_Note(strNoteWnd) )
		{
			dwTarget |= TYPETARGET_NAMED_WINDOW;
			
			Note	nt(strNoteWnd);
			if ( bNoteTextReplace )
				nt.Text = "";	// empty
		}
	}
	*/
	DWORD		dwTarget = 0;	// where should the report go
	string		strNoteWnd;
	
	
	PFN_tree_reporting_prepare_targets	pfn = Project.FindFunction("tree_reporting_prepare_targets", "Originlab\\tree_Utils.c");
	if (pfn)
	{
		if (!pfn(trRep, dwTarget, strNoteWnd, NULL))
			return FALSE;
	}
	else
	{
		ASSERT(FALSE);
		return FALSE;
	}
	
	if (!dwTarget)
		return TRUE;	// nothing to do
	
	// The header table:
	//TreeNode		trTable = trRep.Contents.Header.Table;
	//if (trTable)
	//	dump_wks_header_table(trTable, dwTarget, strNoteWnd);
	
	// The worksheet data:
	BOOL			bOK = wksOutput.Type(dwTarget, strNoteWnd, 5, 0, 0, trCntsWks);
	
	
	return TRUE;
}

static void sort_vectors(const vector<int>& vs1, vector<int>& vs2)
{
	Worksheet wks;
	wks.Create(NULL, CREATE_HIDDEN);
	Dataset da(wks, 0);
	Dataset db(wks, 1);
	da = vs1;
	db = vs2;
	Curve crv( wks, 0, 1 );
	crv.Sort();
	vector vt;
	da = db;
	db = vs2;
	crv.Sort();
	vs2 = db;
	wks.Destroy();
}
	

int wks_report_parameters(Worksheet& wks, int nRow, const TreeNode& trParams, const TreeNode& trCols)
{
	// now we will report the parameters, we will only use P1, P2 etc and ignore
	// other possible values in this branch
	// first, using P1, we determine the titles
	TreeNode trP1 = trParams.P1;
	vector<int> vsIDs;
	vector<int> vsCols;
	vector<string> vsLabels;
	vector<string> vsNames;
	int nCol = 0;
	if(trP1)
	{		
		int nTitleRow = nRow++;
		string strTemp;
		foreach(TreeNode trItem in trP1.Children)
		{
			TreeNode trOputputName = trCols.GetNode(trItem.tagName);
			// has to exist
			if(trOputputName)
				strTemp = trOputputName.strVal;
			else
				strTemp = "";// should be error
			
			vsIDs.Add(trOputputName.ID); // we need this later to determin how to show the value
			vsCols.Add(nCol++);
			vsLabels.Add(strTemp);
			vsNames.Add(trItem.tagName);
			//wks.SetCell(nTitleRow, nCol++, strTemp);
		}
		// we need to order the parameter according to their IDs, so smaller ID will be shown more to the left
		sort_vectors(vsIDs, vsCols);
		
		for(int nc = 0; nc < nCol; nc++)
		{
			wks.SetCell(nRow, nc, STR_SEPARATOR_CELL); //separator
			wks.SetCell(nTitleRow, vsCols[nc], vsLabels[nc]);
		}
		
		nRow++;
	}
	
	TreeNodeCollection tcParameters(trParams, "P");
	int ii = nRow;
	foreach(TreeNode trParam in tcParameters)
	{
		for(int jj = 0; jj < vsNames.GetSize(); jj++)
		{
			TreeNode trItem = trParam.GetNode(vsNames[jj]);
			if(!trItem)
			{
				ASSERT(FALSE);
				printf("Err: %s has missing entry at %s\n", trParam.tagName, vsNames[jj]);
				continue;
			}
			nCol = vsCols[jj];
			if(FWR_PARA_NAME == vsIDs[jj])
				wks.SetCell(ii, nCol, trItem.strVal);
			else if(FWR_PARA_VARY == vsIDs[jj])
				wks.SetCell(ii, nCol, trItem.nVal > 0? "":"Fixed");
			else
				wks.SetCell(ii, nCol, trItem.dVal);
		}
		ii++;
	}
	return ii;
}

/**
	find column by name and return index
	Return:
		column index (0 offset) or -1 if given column name does not exist	
*/
int wks_get_col_index(Worksheet& wks, LPCSTR lpcszColName)
{
	Column cc = wks.Columns(lpcszColName);
	if(cc)
		return cc.GetIndex();
	
	return -1;
}

void wks_fill_separator_line(Worksheet& wks, int nRow, int nCol1, int nCol2)
{
	for(int ii = nCol1; ii <= nCol2; ii++)
		wks.SetCell(nRow, ii, "---");
}

int wks_report_table(
	Worksheet& wks, int nRow, int nCol, 
	LPCSTR lpcszTitle, vector<string>& vsColTitles, vector<string>& vsRowTitles, matrix<double> matValues)
{
	int nNumCols = vsColTitles.GetSize();
	int nNumRows = vsRowTitles.GetSize();
	if(nNumCols != matValues.GetNumCols() || nNumRows != matValues.GetNumRows())
	{
		printf("Err: wks_report_table found inconsistent matValues passed in\n");
		return nRow;
	}
	
	wks.SetCell(nRow++, nCol, "");// make a blank like
	wks.SetCell(nRow++, nCol, lpcszTitle);
	wks_fill_separator_line(wks, nRow++, nCol, nCol + nNumCols + 1); // need to add Row heading
	int nc, nr, ii, jj;
	for(nc = nCol + 1, ii = 0; ii < nNumCols; ii++, nc++)
		wks.SetCell(nRow, nc, vsColTitles[ii]);
	nRow++;
	wks_fill_separator_line(wks, nRow++, nCol, nCol + nNumCols + 1);// need to add Row heading
	// row heading
	for(nr = nRow, ii = 0; ii < nNumRows; ii++, nr++)
		wks.SetCell(nr, nCol, vsRowTitles[ii]);
	
	// mat data
	for(nr = nRow, ii = 0; ii < nNumRows; ii++, nr++)
	{
		for(nc = nCol+1, jj = 0; jj < nNumCols; jj++, nc++)
		{
			wks.SetCell(nr, nc, matValues[ii][jj]);
		}
	}
	
	return nRow + nNumRows;
}


⌨️ 快捷键说明

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