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
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 switch off Tick Labels of Layers X-Axis
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

TreeNode

64 Posts

Posted - 12/03/2009 :  1:43:20 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi everybody!

I really got busy with the problem to switch off the Tick Labels of
a Layers X-Axis.

In Labtalk there is a possibility to set the label color like this:
Graph!layer.axis.label.color = -1;

But I dont want to use Labtalk at all, because I dont want to call
Labtalk-script from my OriginC-Program

I found sample code for a similar problem. So I tried to adapt this
to my intention:

void set_bottom_tick_labels_off()
{
    GraphPage gp;
    gp.Create("origin");
	
    GraphLayer gl = gp.Layers(0);
    if( !gl )
        return;
 
    Tree trFormat;
 
    // Set value of "Show" in Format-Tree to turn off BottomLabels
    trFormat.Root.Axes.X.Labels.BottomLabels.Show = 0;
 
    int nErr = gl.UpdateThemeIDs( trFormat.Root ); //assign node IDs to all nodes in trFormat, return 0 means success
    if( 0 != nErr)
    {
        out_str("Exist invalid theme tree node in trFormat");
        return;
    }
 
    bool bRepaint = true, bRelative = true, bUndo = true;
    bool bRet = gl.ApplyFormat( trFormat, bRepaint, bRelative, bUndo ) ; //apply format to graph layer
    if( !bRet )
        out_str("Fail to update graph format!!!");
 
    return;
}

But it doesnt work.
When I execute this function, the Tick Labels of the X-Axis are still
there.

Does anybody see what I am doing wrong?
Perhabs I did not understand something basicly concerning to change
properties of an Origin-Object using Theme-Tree.

It would be very helpful to know, how I do it right. Because perhabs
I want to change other properties from a GraphLayer in the same way.

Id be very thankful for help!

<!-- helping each other is a good thing...like TreeNode holding the branches and leaves of a Tree -->

rlewis

Canada
253 Posts

Posted - 12/03/2009 :  4:20:37 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Take a look at this post ...
http://www.originlab.com/forum/topic.asp?TOPIC_ID=8018
Go to Top of Page

Iris_Bai

China
Posts

Posted - 12/03/2009 :  9:42:37 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,


    Tree trFormat;
    trFormat = gl.GetFormat(FPB_ALL, FOB_ALL, true, true);  // add this to get format all tree nodes
 
    // Set value of "Show" in Format-Tree to turn off BottomLabels
    //trFormat.Root.Axes.X.Labels.BottomLabels.Show = 0;
    TreeNode trShow = trFormat.Root.Axes.X.Labels.BottomLabels.GetNode("Show"); // TreeNode calss has a property named Show, so cannot directly access Show node here.
    trShow.nVal = 0;	


Iris
Go to Top of Page

TreeNode

64 Posts

Posted - 12/05/2009 :  03:08:20 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
@rlewis:
Thank you very much for your reply, and to offer your code.
Unfortunatly it seems that I havent got the "rnah_constants.h" file.
When I try to compile, linkin cannot start because include-file not found ;-/

One other problem I see is, that when needing acess to other properties
of a Layer or GraphObject, I am addicted to you writing more functions ;D
So it would be better for me to understand how to change properties using
Theme-Tree in the right way.
Because I am not able to write such a derived class like you did...

@Iris:
Thank you very much for your reply, and to help me for better
understanding using Theme-Tree to change internal Origin-Objects.
I tested your correction, and it works.
At least the Bottom-Tick-Labels are switched off. But unfortunatly
the Legend is switched off too.

I want to explain what I am doing:
I got a Origin-Template with one Layer. The properties for that Layer
are set in that way, like I want it to look like.
Now it depends on data, how much Layer with this style should be
append in my GrapPage. Now only the last Layer should have Bottom-Tick-Labels.
But every Layer except the first should have a Legend.

When I use your corrected function, two switch off the Tick-Labels for
the first three Layers for example, the Legends of these are switched off too.
So I tried the following:
I turned off the Tick-Labels of the Layer in my Template, and later tried to
switch on Tick-Labels for last Layer.
It works, but Legend for the last Layer disappears. Thats a bit weird I think...

<!-- helping each other is a good thing...like TreeNode holding the branches and leaves of a Tree -->
Go to Top of Page

rlewis

Canada
253 Posts

Posted - 12/05/2009 :  11:03:47 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
If you create a headder file containing the enumerations I've described and include that headder file in place of the "rnah_constants.h" file and things should work ...
Go to Top of Page

Iris_Bai

China
Posts

Posted - 12/07/2009 :  02:00:10 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

I saw you load the properties from template for layer 1. In fact, you also can use template to load these properties for other layers. See AddLayer in example codes below, add new graph layer with template format. About legend disappear, please try legend_update function to show or fresh it, see below example.

void example_1()
{
	string strTemplate = "Origin";
	GraphPage gp;
	gp.Create(strTemplate );// create graph with one layer by template
	
	string strLayerName = "Layer2";
	DWORD dwOptions = 0;
	gp.AddLayer(strLayerName, dwOptions, strTemplate);// create layer 2 with the same template of layer 1
	
	// arrange layers as two rows and 1 column
	graph_arrange_layers(gp, 2, 1);
	
	// plot data on two layers
	//.....
	
	// remove Legend for layer 1
	GraphLayer gl_1 = gp.Layers(0);
	if( gl_1)
	{
		string strLegend = "Legend";
		GraphObject go = gl_1.GraphObjects(strLegend);
		if( go )
			gl_1.RemoveGraphObject(strLegend);
	}
	
	// update or show legends after plotting for layer 2
	GraphLayer gl_2 = gp.Layers(1);
	if( gl_2 )
	{
		legend_update(gl_2);
	}	
}


Iris
Go to Top of Page

TreeNode

64 Posts

Posted - 12/10/2009 :  08:01:29 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
@ rlewis:
You are right. Including headder with enumerations was the reason why your code
didnt work for me. I included the headder with the enumerations, and now it works.
Thanks for that.
But I didnt find a function for switching off Tick Labels. Thats the problem I mentioned
above. Now I am addicted to you to write more functions for me. ;D
It would be best for me to understand generally how to access properties of these
objects in the right way.

@ Iris
Thanks for example code. It helps to see how to handle these things in the right way.
But still got problems with updating legends.
I tried the following:


void update_legend()
{
	int nGraphPages = 0, nGraphLayers = 0;

	foreach (GraphPage gp in Project.GraphPages)
	{	
		// number of GraphPages in Project
		nGraphPages++;
		
		foreach (GraphLayer gl in gp.Layers);
		{
			// number of GraphLayers in Project
			nGraphLayers++;
			
			string strLayerName;
			bool bGetName = gl.GetName(strLayerName);
			
			// print name of found Layers
			if(bGetName)
			{
				out_str(strLayerName);
			}
			
			// update or show legends
			legend_update(gl);			
		}
	}
	out_str("Number of GraphPages: " + nGraphPages + "\n" + "Number of GraphLayers: " + nGraphLayers);
}


In my Project is 1 GraphPage with 3 Layers at this time. When now calling the function shown above, it counts 1 GraphPage but only 1 GraphLayer ( should count 3 ).
When no data is imported, nothing happens to the legends.
When data is imported, there appears a Legend, but only for the last Layer.
( Thats the one, which my function found and counted ) But now, when data is imported,
my function counts 4 GraphPages and 4 Layers. What happened ?????

...it wont take long and I am getting mad
please help!!




<!-- helping each other is a good thing...like TreeNode holding the branches and leaves of a Tree -->
Go to Top of Page

rlewis

Canada
253 Posts

Posted - 12/10/2009 :  5:44:30 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi ...
The code listed below is the current version of my "rnGraphAxis" class which now contains member functions for Tick labels and oher things. I hope this helps...

#ifndef _RNAH_GRAPH_AXIS_CLASS_
#define _RNAH_GRAPH_AXIS_CLASS_

#include <rnahl\Library\rnah_constants.h> // Contains the required enumerations ... 

class rnGraphAxis : public Axis
{
public:
	rnGraphAxis() : Axis()
	{
	}
	
	rnGraphAxis(const Axis &axis)  : Axis(axis)
	{
	}

//////////////////////////////      **************      /////////////////////////////////

	int GetType()
	{
/*
	rnGraphAxis::GetType
		On Success ... 	Returns a code for the Type of Axis
			0 .... X Axis
			1 .... Y Axis
			2 .... Z Axis

		On Failure ... 		Returns -1;
		
		Function requires that the following enumeration be declared
		enum
		{
			AXIS_CODE_X=0,
			AXIS_CODE_Y,
			AXIS_CODE_Z,
		};
*/		
		if(IsValid()==true)
		{
			GraphLayer glParent;
			GetParent(glParent);
			if(glParent.IsValid()==true)
			{
				Axis gAxis;
				Axis ThisAxis=(*this);
				gAxis=glParent.XAxis;
				if(gAxis==ThisAxis)
				{
					return (AXIS_CODE_X);
				}
				gAxis=glParent.YAxis;
				if(gAxis==ThisAxis)
				{
					return (AXIS_CODE_Y);
				}
				if(is_3D_graph(glParent)==true)
				{
					gAxis=glParent.ZAxis;
					if(gAxis==ThisAxis)
					{
						return (AXIS_CODE_Z);
					}
				}
			}
		}
		return (-1);
	}

//////////////////////////////      **************      /////////////////////////////////

	bool Display(bool ShowState, bool AxisPrimary=true)
	{
/*
	rnGraphAxis::Display
		Shows/Hides the a GraphLayer Axis
		AxisPrimary = true(default)		.... Operates on the primary axis	XAxis(Bottom)	YAxis(Left)	ZAxis(Front)
		AxisPrimary = false				.... Operates on the secondary axis	XAxis(Top)	YAxis(Right)	ZAxis(Back)
*/		
		if(IsValid()==true)
		{
			AxisObject aO;
			if(AxisPrimary==true)
			{
				AxisObject aO=AxisObjects(AXISOBJPOS_AXIS_FIRST);
			}
			else
			{
				aO=AxisObjects(AXISOBJPOS_AXIS_SECOND);
			}
			if(aO.IsValid()==true)
			{
				aO.Show=ShowState;
				return (true);
			}
		}
		return (false);
	}

//////////////////////////////      **************      /////////////////////////////////

	bool SetTicks(uint TickCode, int ShowState, bool AxisPrimary=true)
	{
/*
	rnGraphAxis::SetTicks
		Sets the Tick Status of the Axis Object as defined by the parameters TickCode and ShowState and Primary
	
		AxisPrimary = true 	(default)	.... Operates on the primary axis	XAxis(Bottom)	YAxis(Left)	ZAxis(Front)
		AxisPrimary = false 			.... Operates on the secondary axis	XAxis(Top)	YAxis(Right)	ZAxis(Back)
	
		Legal Values for TickCode
		AXIS_TICKS_TYPE_NONE = -1
		AXIS_TICKS_TYPE_BOTH = 0
		AXIS_TICKS_TYPE_MAJOR = 1
		AXIS_TICKS_TYPE_MINOR = 2
	
		Legal Values for ShowState
		AXIS_TICKS_POSITION_NONE =-1
		AXIS_TICKS_POSITION_IN_AND_OUT = 0
		AXIS_TICKS_POSITION_IN	=1
		AXIS_TICKS_POSITION_OUT	=2
*/
		if(IsValid()==true)
		{
			AxisObject aO;
			if(AxisPrimary==true)
			{
				aO=AxisObjects(AXISOBJPOS_AXIS_FIRST);
			}
			else
			{
				aO=AxisObjects(AXISOBJPOS_AXIS_SECOND);
			}
			if(aO.IsValid()==true)
			{
				if(ModifyAxisTicks(aO,TickCode,ShowState)==true)
				return (true);
			}
		}
		return (false);
	}

//////////////////////////////      **************      /////////////////////////////////

	bool SetRange(double axisFrom, double axisTo)
	{
/*
	rnGraphAxis::SetRange              
		Sets the range of an axis object ...
*/		
		if(IsValid()==true && axisFrom!=axisTo)
		{
			Tree tr;
			tr=GetFormat(FPB_ALL, FPB_ALL, TRUE, TRUE);
			tr.Root.Scale.From.dVal=axisFrom;
			tr.Root.Scale.To.dVal=axisTo;
			if(UpdateThemeIDs(tr.Root)==0)
			{
				return (ApplyFormat(tr, true, true,true));
			}
		}
		return (false);
	}
	
//////////////////////////////      **************      /////////////////////////////////
	
	bool SetColor(int nColor, bool AxisPrimary=true)
	{
/*
	rnGraphAxis::SetColor              
		Sets the Color of an axis object ...
		AxisPrimary = true(default)		.... Operates on the primary axis	XAxis(Bottom)	YAxis(Left)	ZAxis(Front)
		AxisPrimary = false				.... Operates on the secondary axis	XAxis(Top)	YAxis(Right)	ZAxis(Back)
*/		
		if(IsValid()==true)
		{
			int AxisType=GetType();
			GraphLayer glParent;
			GetParent(glParent);
			if(glParent.IsValid()==true)
			{
				switch (AxisType)
				{
					case AXIS_CODE_X:
						if(AxisPrimary==true)
						{
							glParent.XAxis.AxisObjects(AXISOBJPOS_AXIS_FIRST).BottomTicks.Color.nVal = nColor;
						}
						else
						{
							glParent.XAxis.AxisObjects(AXISOBJPOS_AXIS_SECOND).TopTicks.Color.nVal = nColor;
						}
					break;
					case AXIS_CODE_Y:
						if(AxisPrimary==true)
						{
							glParent.YAxis.AxisObjects(AXISOBJPOS_AXIS_FIRST).LeftTicks.Color.nVal = nColor;
						}
						else
						{
							glParent.YAxis.AxisObjects(AXISOBJPOS_AXIS_SECOND).RightTicks.Color.nVal = nColor;
						}				
					break;				
					case AXIS_CODE_Z:
						if(AxisPrimary==true)
						{
							glParent.ZAxis.AxisObjects(AXISOBJPOS_AXIS_FIRST).FrontTicks.Color.nVal = nColor;
						}
						else
						{
							glParent.ZAxis.AxisObjects(AXISOBJPOS_AXIS_SECOND).BackTicks.Color.nVal = nColor;
						}								
					break;
					default:
						return (false);
					break;
				}
				return (true);
			}
		}
		return (false);
	}

//////////////////////////////      **************      /////////////////////////////////
	
	bool ShowTickLabels(bool ShowState, bool AxisPrimary=true)
	{
/*
	rnGraphAxis::ShowTickLabels              
		Show (ShowState=true) or Hide (ShowState=false) the axis object Tick Labels ...
		AxisPrimary = true(default)		.... Operates on the primary axis	XAxis(Bottom)	YAxis(Left)	ZAxis(Front)
		AxisPrimary = false				.... Operates on the secondary axis	XAxis(Top)	YAxis(Right)	ZAxis(Back)
*/		
		if(IsValid()==true)
		{
			int AxisType=GetType();
			GraphLayer glParent;
			GetParent(glParent);
			if(glParent.IsValid()==true)
			{
				switch (AxisType)
				{
					case AXIS_CODE_X:
						if(AxisPrimary==true)
						{
							glParent.XAxis.AxisObjects(AXISOBJPOS_LABEL_FIRST).BottomLabels.Show.nVal = ShowState;
						}
						else
						{
							glParent.XAxis.AxisObjects(AXISOBJPOS_LABEL_SECOND).TopLabels.Show.nVal = ShowState;
						}
					break;
					case AXIS_CODE_Y:
						if(AxisPrimary==true)
						{
							glParent.YAxis.AxisObjects(AXISOBJPOS_LABEL_FIRST).LeftLabels.Show.nVal = ShowState;
						}
						else
						{
							glParent.YAxis.AxisObjects(AXISOBJPOS_LABEL_SECOND).RightLabels.Show.nVal = ShowState;
						}				
					break;			
					case AXIS_CODE_Z:
						if(AxisPrimary==true)
						{
							glParent.ZAxis.AxisObjects(AXISOBJPOS_LABEL_FIRST).FrontLabels.Show.nVal = ShowState;
						}
						else
						{
							glParent.ZAxis.AxisObjects(AXISOBJPOS_LABEL_SECOND).BackLabels.Show.nVal = ShowState;
						}								
					break;
					default:
						return (false);
					break
				}
				return (true);
			}
		}
		return (false);
	}
	
//////////////////////////////      **************      /////////////////////////////////
	
	bool SetTitle(string strAxisTitle, bool AxisPrimary=true)
	{
/*
	rnGraphAxis::SetTitle
		Sets the Title of the GraphAxis to strAxisTitle
		AxisPrimary = true(default)		.... Operates on the primary axis	XAxis(Bottom)	YAxis(Left)	ZAxis(Front)
		AxisPrimary = false				.... Operates on the secondary axis	XAxis(Top)	YAxis(Right)	ZAxis(Back)		

*/		
		int AxisType=GetType();
		GraphLayer glParent;
		GetParent(glParent);
		if(glParent.IsValid()==true)
		{
			Tree trFormat;
			switch (AxisType)
			{
				case AXIS_CODE_X:
					if(AxisPrimary==true)
					{
						trFormat.Root.Axes.X.Titles.BottomTitle.AddNode("Text").strVal = strAxisTitle;	
					}
					else
					{
						trFormat.Root.Axes.X.Titles.TopTitle.AddNode("Text").strVal = strAxisTitle;
					}
				break;
				case AXIS_CODE_Y:
					if(AxisPrimary==true)
					{
						trFormat.Root.Axes.Y.Titles.LeftTitle.AddNode("Text").strVal = strAxisTitle;	
					}
					else
					{
						trFormat.Root.Axes.Y.Titles.RightTitle.AddNode("Text").strVal = strAxisTitle;
					}						
				break;
				case AXIS_CODE_Z:
					if(AxisPrimary==true)
					{
						trFormat.Root.Axes.Z.Titles.FrontTitle.AddNode("Text").strVal = strAxisTitle;	
					}
					else
					{
						trFormat.Root.Axes.Z.Titles.BackTitle.AddNode("Text").strVal = strAxisTitle;
					}							
				break;
				default:
					return (false);
				break;
			}
			if(glParent.UpdateThemeIDs(trFormat.Root )==0)
			{
				bool bRepaint = true, bRelative = true, bUndo = true;	
				if(glParent.ApplyFormat( trFormat, bRepaint, bRelative, bUndo)==true)
				{
					return (true);
				}
			}
		}
		return (false);
	}

//////////////////////////////      **************      /////////////////////////////////
	
	bool ShowTitle(bool ShowState, bool AxisPrimary=true)
	{
/*
	rnGraphAxis::ShowTitle
		Show (ShowSate=true) / Hide (ShowState=false) the title of the GraphAxis
		AxisPrimary = true(default)		.... Operates on the primary axis     XAxis(Bottom)	    YAxis(Left)	    ZAxis(Front)
		AxisPrimary = false				.... Operates on the secondary axis	  XAxis(Top)	    YAxis(Right)	ZAxis(Back)
*/		
		GraphLayer glParent;
		GetParent(glParent);
		if(glParent.IsValid()==true)
		{
			vector<string> PrimaryAxis={"XB.Show=","YL.Show=","ZF.Show="};
			vector<string> SecondaryAxis={"XT.Show=","YR.Show=","ZB.Show="};
			int AxisType=GetType();
			string strTemp;
			if(ShowState==true)
			{
				strTemp="1";
			}
			else
			{
				strTemp="0";
			}
			string strLTCommand;
			if(AxisPrimary==true)
			{
				strLTCommand=PrimaryAxis[AxisType];
			}
			else
			{
				strLTCommand=SecondaryAxis[AxisType];
			}
			strLTCommand+=strTemp;
			glParent.LT_execute(strLTCommand);
			return (true);
		}
		return (false);		
	}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
private:

	bool ModifyAxisTicks(AxisObject &aO, uint TickCode, int ShowState)
	{
/*
	This function requires that the following enumerations have be declared
	enum
	{
		AXIS_TICKS_POSITION_NONE=-1,
		AXIS_TICKS_POSITION_IN_AND_OUT,
		AXIS_TICKS_POSITION_IN,
		AXIS_TICKS_POSITION_OUT
	};

	enum
	{
		AXIS_TICKS_TYPE_NONE=-1,
		AXIS_TICKS_TYPE_BOTH,
		AXIS_TICKS_TYPE_MAJOR,
		AXIS_TICKS_TYPE_MINOR
	};
*/
		if(aO.IsValid()==true)
		{
			Tree tr;
			tr=aO.GetFormat(FPB_ALL, FOB_ALL, TRUE, TRUE);
			if(ShowState>2 || ShowState<0)
			{
				ShowState=-1;
			}
			switch (TickCode)
			{
				case AXIS_TICKS_TYPE_BOTH:
					tr.Root.Major.dVal=ShowState;
					tr.Root.Minor.dVal=ShowState;
				break;
				case AXIS_TICKS_TYPE_MAJOR:
					tr.Root.Major.dVal=ShowState;
				break;
				case AXIS_TICKS_TYPE_MINOR:
					tr.Root.Minor.dVal=ShowState;
				break;
				case AXIS_TICKS_TYPE_NONE:
				default:
					tr.Root.Minor.dVal=-1;
					tr.Root.Major.dVal=-1;
				break;
			}
			aO.ApplyFormat(tr, true, true,true);
			return (true);
		}
		return (false);
	}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
};

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

#endif // .... _RNAH_GRAPH_AXIS_CLASS_






Go to Top of Page

rlewis

Canada
253 Posts

Posted - 12/14/2009 :  2:21:38 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi ...
The problem with your update_legend example is the semicolon at the end of the line ...

foreach (GraphLayer gl in gp.Layers);

If you remove that semicolon the function will work as you intended
Go to Top of Page

TreeNode

64 Posts

Posted - 12/14/2009 :  2:57:39 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

thank you very much! Really great you found that mistake.
I allready thought that I did not understand anything about OriginC.
But by now you raised my hopes ;D

And thanks again for offering latest version of your code.
I had not the time to try it yet. I had to work and learn for
programming C/C++. Tomorrow theres a test.. ;D

But after that I will continue programming OriginC. Think I will use
your functions for my intention. Because I tried the example code of the older
version, and it seems to work very good.

So thanks again for your help !!



<!-- helping each other is a good thing...like TreeNode holding the branches and leaves of a Tree -->
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000