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
 Adding horizontal + vertical GROT_LINE to Layer

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
TreeNode Posted - 11/09/2010 : 11:30:28 AM
Origin Ver. and Service Release: Origin 8, SR6
Operating System: Win XP

Hi,

Im going crazy with adding horizontal and vertical Lines to Layer.
I found the following topic, examples and reference:

Forum topic:
http://www.originlab.com/forum/topic.asp?TOPIC_ID=8152&SearchTerms=GROT_LINE

AddLine example:
http://ocwiki.originlab.com/index.php?title=OriginC:Add_Graph_Object#Line

OriginC Reference
http://ocwiki.originlab.com/index.php?title=Category:GraphObject_%28class%29

But all that didnt make me achieve my aims.
I want to simply add horizontal and vertical Lines to a GraphLayer at definite position,
and with a definite length (width).

I tried to set the properties with the methods offered by the class GraphObject, and I also tried
to set them by updating Property-Theme-Tree -> go.ApplyFormat(tr, true, true);
But in both cases the added Line does not behave as I would expect.

Here is some code, I tried to set line properties with:

void set_line_properties_ex1()
{
	GraphLayer gl = Project.ActiveLayer();
	GraphObject go = gl.CreateGraphObject(GROT_LINE);

	go.Attach = 2;	// Attach to Axes, Scale
	go.X = 120;		// X-Position of Line
	go.DX = 200;	// Width of the Line
	go.Y = -16;		// y-Position of Line
	
	Tree tr;
    //tr.Root.Span.nVal = 2; // 1 to span over the whole layer
    tr.Root.Direction.nVal = LN_HORIZONTAL; // vertical or horizontal  
    tr.Root.Color.nVal = SYSCOLOR_BLACK;
    tr.Root.Width.dVal = 1;
    tr.Root.Event.nVal = GRCT_MOVE;
    //tr.Root.Script.strVal = strScript; // set script, run it after the Event specified by nExecMode
    
    // Dimensions
    //tr.Root.Dimension.Units.nVal = 5;
    //tr.Root.Dimension.Left.dVal = 120.0;
    //tr.Root.Dimension.Width.dVal = 100.0;
    //tr.Root.Dimension.Top.dVal = -14.0;
    
    if( 0 == go.UpdateThemeIDs(tr.Root) ) // 0 means no error
    {
        bool bRet = go.ApplyFormat(tr, true, true); // return true if applied format successfully
    }
	
	printf("X: %f\nY: %f\nDX: %f\nDY: %f\nWidth: %f\nHeight: %f\nTop: %f\nLeft: %f\n",
			go.X, go.Y, go.DX, go.DY, go.Width, go.Height, go.Top, go.Left);
	
	tr = go.GetFormat(FPB_ALL, FOB_ALL, true, true);
	out_tree(tr);
}


The position and Span of the Line should be attached to the X- and Y-Axis. So related to the DataPlots in the Layer the
line should always have the same position.

Can someone give me an example how to handle GROT_LINE GraphObjects in the way I need, and make me succeed in my business?
I would be very thankful for your help!

|-- TreeNode
...|-- a??
...|-- ha!!
3   L A T E S T    R E P L I E S    (Newest First)
rlewis Posted - 11/10/2010 : 2:18:34 PM
Indeed ... OriginLab has quite a few goodies in "Originc\OriginLab" folder ....
It would be very useful if they were to document those functiona and other utilties more fully ...
TreeNode Posted - 11/10/2010 : 04:50:07 AM
Hi rlewis,

thank you very much for quick reply! The function works fine for me.
I just had to set the parameter bSpan = false, because I dont want a line spanning over whole layer.

bool add_line(Layer& lay, GraphObject& go, double x0=0, double y0 = 0, int nAttach= ATTACH_TO_SCALE, int nDirection = LN_VERTICAL,
              bool bSpan=true, bool bPercent = true, double x1=50, double y1 = 50, int nColor = 1, LPCSTR lpcszName = NULL);


Great solution! But why I cant find such functions in help files?


|-- TreeNode
...|-- a??
...|-- ha!!
rlewis Posted - 11/10/2010 : 02:07:17 AM
There is an OriginLab utility function 'add_line" which may solve your problem ...

As written, the function below will draw a red horizontal line which spans the width of the active graphlayer half way up the y-axis


void DrawHorizontalLine()
{
	GraphLayer gL = Project.ActiveLayer();
	GraphObject gO;
	if(gL.IsValid()==true)
	{
		string PathToOCFile=GetAppPath(true)+"OriginC\\Originlab\\grobj_utils.c";
		if(Project.Compile(PathToOCFile)==true)
		{
			double x0=gL.X.From; 
			double x1=gL.X.To;
			double y0=gL.Y.From+((gL.Y.To-gL.Y.From)/2.0);
			double y1=y0;
			int nAttach =2;
			string lpcszName="MyLine";
			add_line(gL,gO,x0,y0, nAttach,LN_HORIZONTAL,true,false,x1,y1,1,lpcszName);
		}
	}
}

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