The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Determining the amount of groups in a GraphLayer

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
Rodolf Posted - 02/26/2009 : 07:38:30 AM
Origin Ver. and Service Release (Select Help-->About Origin): Origin 8 SR4
Operating System: Windows XP

Hello

I am programmatically grouping plots and change their colors, but I get into trouble with determining how many groups are in a GraphLayer. This is because the member Groups() of the graphlayer class is not defined as a collection, whereas for instance DataPlots is. Therefore, I cannot use the following code to count the number of groupplots:

int ngroups=0;
Collection<GroupPlot> gpcoll;
gpcoll = gl.Groups;

GroupPlot gpl;
foreach ( gpl in gpcoll )
ngroups++;

If I try to determine the amount of groups by trying to assign each of the GroupPlots for increasining i:

gplot=gl.Groups(i);

If I put this in a while loop and try to check if gplot exist, at the point that i becomes larger than the amount of groups, I get the error "invalid indexing into a collection", which is strange considering I can not get it as a collection in the first place.

Is there a workaround to determine the amount of groups? I have a GraphLayer that has both groups and single curves in it.

Cheers,

Rodolf
6   L A T E S T    R E P L I E S    (Newest First)
additive Posted - 04/14/2009 : 08:39:21 AM
quote:
Originally posted by yuivanov
GroupPlot gPlot;
gPlot = gL.Groups(i);


Separation of declaration and initialization will solve the problem.



This works only for groups set to "Dependent" edit mode (group tab of the group's first data plot). If it is set to "independant" the error still exists. Thus, I cannot change GroupPlot properties (of a group that I cannot attach).

Does anybody know how to set this attribute with OriginC?
I used

gl.AddPlot(dr, IDM_PLOT_LINE, GAP_GROUP_PLOTS);

and

m_gl.GroupPlots(iFirstDataPlotIndex, iLastDataPlotIndex);


The only workaround I could find is saving the manual setting to a template (but this does not work for variable group numbers).

Thanks,

Michael


yuivanov Posted - 03/02/2009 : 3:51:00 PM
Hello Ruthven
Regarding the OriginC misbehaviour that you observed.
The following code is tricky in general for the compilers


Begin:
 GroupPlot gPlot = gL.Groups(i);
 i++;
 goto Begin;


From the point of view of the control flow this code would appear to look like that (which of cause will fail to compile)
GroupPlot gPlot = gL.Groups(i);
i++;
GroupPlot gPlot = gL.Groups(i);
i++;
GroupPlot gPlot = gL.Groups(i);
i++;
GroupPlot gPlot = gL.Groups(i);
i++;
GroupPlot gPlot = gL.Groups(i);
...

So usually there is a compiler trickery involved (that we overlooked) which results in declaration and initialization being "decoupled" to handle this kind of control flow.
Please see
http://science.kennesaw.edu/~khoganso/csis3100/dec-init.htm
for more info.

We will still have to adress this issue, for now you can do it "manually", if you break line in two - it will work as expected:

GroupPlot gPlot;
gPlot = gL.Groups(i);


Separation of declaration and initialization will solve the problem.
Thanks
Yuri
Rodolf Posted - 03/02/2009 : 03:27:34 AM
Thanks, this works OK.
I also found another workaround that works on a valid GroupLayer gl, but it's a bit messy:

Ngroups=0;
Tree tr;
gl.GetLayerContents(tr, GETLC_DATAPLOTS);
TreeNode tn;
foreach(tn in tr.Layer0.Children)
{
if(tn.tagName=="Group"){
Ngroups++;
}
}
yuivanov Posted - 02/27/2009 : 3:04:21 PM
Hello
Although Groups function is not defined as collection it shares some code with them and also error messages. Sorry for the confusion.
Looks like there is no clear way to get the number of group plot objects in the layer, so you will have to use workaround.
Here is one possible:

int CountGroupsInActiveLayer()
{
	GraphLayer gl = Project.ActiveLayer(); 
	if( !gl )
		return -1;
	
	int nReturn = 0;
	try
	{
		while(TRUE)
		{
			GroupPlot gPlot = gl.Groups(nReturn);
			nReturn++;
		}
	}
	catch(int nErr)
	{
	}
	
	return nReturn;
}
Rodolf Posted - 02/27/2009 : 03:29:28 AM
Thanks for the reaction. It is a bit strange that your code does not select the right GroupPlot, because I don't have that particular problem. I created a Graph with a couple of groups with different amounts of plots within each group. If I run the following code:

int TestProg2(int ngroups)
{
int j;
GraphLayer gL = Project.ActiveLayer();

if(gL.IsValid()==true)
{
for(int i=0; i<ngroups;i++){
GroupPlot gPlot = gL.Groups(i);
j=gPlot.GetCount();
printf("No. of plots in Group %d = %d \n",i,j);
}
}
return (-1);
}

(fill in the right amount of groups as argument), I get the expected result: for each of the GroupPlot gL.Groups(i) returns the right amount of DataPlots within the group.

That being said, the fact that it reports "invalid indexing into a collection" when i becomes to large while you can't get a collection of GroupPlots does seem like a bug to me.
rlewis Posted - 02/26/2009 : 11:47:48 AM
I did some tests using the debugging code below and found that there is an Origin Bug at the line indicated.
Regardless of the value of "i" the GroupPlot object always points to the first Group in the graphLayer (if there is one).

int TestProg()
{
	GraphLayer gL = Project.ActiveLayer(); 
 	if(gL.IsValid()==true)
 	{
 		int i=0, j=-1;
 		try
 		{
 			Begin:
 			GroupPlot gPlot = gL.Groups(i); \\ Bug here ...
 			j=gPlot.GetCount();
 			if(j<1)
 			{
 				throw (1);
 			}
 			out_int("Loop Index = ",i);
 			if(i<=10)
 			{
 				j=-1;
 				i++;
 				goto Begin;
 			}
 		}
 		catch (int iErr)
 		{
 			switch (iErr)
 			{
 				case 1:
 					return (i);
 				break;
 				default:
 					return (-1);
 				break;
 			}
 		}
 	}
 	return (-1);
}

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000