Origin Version: 7.5
I have written the following sample code to show how to move a particular data plot to the bottom of the plot list. This area were not completely finished in terms of Origin C support and thus no documentation were available. But I found that given the current (Origin 7.5) implementation, it is already possible to do some limited manipulations.
static bool dataplots_move_row_to_bottom_top(TreeNode& tr, int nRow, bool bMoveToTopOfTree = true)
{
Tree trTemp;
TreeNode tr1stPlot;// for the case of bMoveToTopOfTree
int nCount = 0;
string strName;
string strPrefix;
foreach(TreeNode trNode in tr.Children)
{
strName = trNode.tagName;
int nIndex = string_to_prefix_end_number(strPrefix.GetBuffer(MAXLINE), strName);
strPrefix.ReleaseBuffer();
if(strPrefix.CompareNoCase("DataPlot") != 0)
continue;
if(!tr1stPlot)
tr1stPlot = trNode;// remember 1st DataPlot node for insert later
// top level
if(nRow == nCount)
{
trTemp = trNode; // make copy
tr.RemoveChild(trNode);
break;
}
nCount++;
}
if(trTemp)
{
if(!bMoveToTopOfTree) // bottom of tree, then top of plot list
tr.AddNode(trTemp.Clone());
else // move to bottom of plot list, which means top of the tree
{
if(!tr1stPlot)
{
out_str("No data plot in layer, nothing to move");
return false;
}
TreeNode tr1 = tr.InsertNode(tr1stPlot, "Junk");// tagName does not matter, will be replaced later
tr1.Replace(trTemp.Clone());
}
return true;
}
return false;
}
void test_mv_plot(int nPlot, bool bRegroup = false)
{
GraphLayer gl = Project.ActiveLayer();
if(!gl)
return;
Tree tr;
bool bWasGroup = gl.UngroupPlots();
gl.GetLayerContents(tr, GETLC_DATAPLOTS);
if(dataplots_move_row_to_bottom_top(tr.FirstNode, nPlot))
{
gl.AddPlots(tr.FirstNode, ADDPLOTSFROMTREE_EDIT);
if(bWasGroup && bRegroup)
gl.GroupPlots(0);
gl.LT_execute("legend -s");// this will force the legend to update
gl.GetPage().Refresh();
}
}
CP
Edited by - cpyang on 09/20/2004 4:00:00 PM