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
 can't compile/user input
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

rpaczkowski

USA
Posts

Posted - 02/15/2005 :  10:52:33 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version (Select Help-->About Origin): 7.5
Operating System: Win 2000

Hello,

I have two problems, with the first one being interesting. I built a source code in the past few days. Today I made some changes and when I want to compile, I am told "No changed files found. Choose rebuild all if you want to recompile anyway". So I do, call the program and am told "Command Error!". I have no idea what I am doing wrong, since until yesterday, everything worked.

The second thing is this: I have a curve built (through the C-program), from which I want to subtract a straight line. Depending on the shape of the curve, this line will be different every time, so it has to be defined manually, not through the program. How do I program this manually selecting a straight line to be subtracted and then do further curve manipulations through the program?

easwar

USA
1965 Posts

Posted - 02/15/2005 :  12:03:27 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Answer to your first question:
The code file may be open in code builder and you may be making edits, but looks like the file has not been added to the workspace. This is why you get the messate" no changeed files foumd."

So with the file open, go to File menu and select Add to Workspace.
Note that when you open a file, in the file open dialog, there is a check box as well, to add the file to workspace when opening. You could optionally turn this on and then any file that is opened is added to workspace automatically.

Easwar
OriginLab

Go to Top of Page

rpaczkowski

USA
Posts

Posted - 02/15/2005 :  12:44:11 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
easwar,

Thank you for solving Problem #1. I wonder why I deleted the file from the workspace.

Any ideas about #2?

Ralph
Go to Top of Page

easwar

USA
1965 Posts

Posted - 02/15/2005 :  1:56:25 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Ralph,

It is possible via LabTalk to get user to click on a graph and get the coordinates. A method for this does not exist in OC, but LabTalk code such as below could be contained in some OC function.

Easwar
OriginLab


RunText.show = 1; // turn on help text
count=1;
dotool 2;

def quittoolbox // this is the main loop where all code subsequtent
{ // to accepting points needs to be placed
if( 2 != count ) //first check if user has successfully selected two points
return;

xpos1=;
ypos1=;
xpos2=;
ypos2=;

RunText.show = 0;
}


def pointproc
{
xpos$(count)=x;
ypos$(count)=y;
if( count >= 2 )
dotool 0;
count+=1;
}



Go to Top of Page

easwar

USA
1965 Posts

Posted - 02/15/2005 :  5:17:59 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Ralph,

The code pasted below shows one way to wrap the LT code and get this to work with OC.

Easwar
OriginLab


#include <Origin.h>

////////////////////////////////////////////////////////////////////////////////////
// This example shows how to get x, y coordinates of points clicked by user
// on a graph layer.
// Number of points to be fetched is pased as parameter. Default is 2.
// So for 5 points, type this command in the script window:
// read_screen_points 5
//
void read_screen_points(int nPts = 2)
{
// Declare vectors to hold coordinates
vector vecX, vecY;
// Call function to get points
int iRet = get_screen_reader_points(nPts, vecX, vecY);
if( iRet < 0 )
printf("Function call to get screen points returned error: %d\n", iRet);

printf("User clicked on %d points\n", iRet);
if( 0 != iRet )
{
printf("X, Y coordinates of points are:\n");
for(int ii = 0; ii < iRet; ii++)
printf(" %d: X = %f, Y = %f\n", ii, vecX[ii], vecY[ii]);
}
}

// This static function handles calling LabTalk to get user to click on the screen.
// Parameters:
// nPts: no. of points that user should click
// vecX: vector to hold x coordinates of points, passed by reference
// vecX: vector to hold y coordinates of points, passed by reference
// Return:
// -1: no. of points inappropriate
// >=0: no. of points user actually clicked
static int get_screen_reader_points(int nPts, vector& vecX, vector& vecY)
{
// Return error if number of points not appropriate
// Arbitary upper limit of 99 - change as desired
if( nPts < 1 || nPts > 99) return -1;

// Run the LabTalk section in this file to give user control to click points
string strThisFile = __FILE__;
string strCMD;
strCMD.Format("run.section(%s,GetScreenPts,%d)", strThisFile, nPts);
LT_execute(strCMD);

// On return, the LabTalk variable tmp_scr_count has number of points user clicked + 1
double dCount;
LT_get_var("tmp_scr_count", &dCount);
int nCount = (int) (dCount - 1);
if( 0 == nCount ) return 0;

// Get values of x, y coordinates from LabTalk variables and delete the vars
vecX.SetSize(nCount);
vecY.SetSize(nCount);
string strX, strY;
double dX, dY;
for(int ii = 1; ii <= nCount; ii++)
{
strX.Format("tmp_scr_pos_x%d", ii);
strY.Format("tmp_scr_pos_y%d", ii);
LT_get_var(strX, &vecX[ii - 1]);
LT_get_var(strY, &vecY[ii - 1]);
strCMD.Format("del -v %s", strX);
LT_execute(strCMD);
strCMD.Format("del -v %s", strY);
LT_execute(strCMD);
}

// Delete the count LabTalk variable
LT_execute("del -v tmp_scr_count;");

// Return the number of points clicked by user
return nCount;
}

// This section of LabTalk will be ignored by compiler since it is contained within an ifdef block.
// The section of script within this block can then be successfully called by a run.section LabTalk command.
#ifdef LABTALK
[GetScreenPts]
// Number of points to get is passed as 1st parameter
// Select screen reader tool
dotool 2;

// Main loop to accept points
tmp_scr_count = 1;
def quittoolbox
{
// Check if user has clicked required number of points
if( 1 == tmp_scr_count )
done = 1;
if( %1 != tmp_scr_count )
return;
}

// Get points and store in temp string variables
def pointproc
{
tmp_scr_pos_x$(tmp_scr_count)=x;
tmp_scr_pos_y$(tmp_scr_count)=y;
if( tmp_scr_count >= %1 )
{
dotool 0;
// Set the variable to break the infinite loop
done = 1;
}
tmp_scr_count += 1;
}
// Set up an "infinite loop" so code waits for user to click points
for( done = 0; done == 0; )
{
// wait a while
sec -p 0.1;
}
#endif
////////////////////////////////////////////////////////////////////////////////////



Go to Top of Page

rpaczkowski

USA
Posts

Posted - 02/16/2005 :  2:38:07 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
easwar,

Thank you so much for the C-code. I am sure I can do something with this.

Ralph
Go to Top of Page

verrallr@a

Canada
44 Posts

Posted - 02/18/2005 :  10:15:51 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I've just been looking at Easwar's LabTalk code, because I sometimes want to get coordinates of points in a graph.

RunText.show = 1; // turn on help text

When I execute this statement, I get this error:

RUNTEXT.SHOW is an illegal name for defining a variable. It must not start with a number, nor an operator and may not contain a dot.
#Command Error!

What is the statement "RunText.show=1;" supposed to do, and why does it just give me an error.

Go to Top of Page

easwar

USA
1965 Posts

Posted - 02/18/2005 :  10:24:42 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:

What is the statement "RunText.show=1;" supposed to do, and why does it just give me an error.



Hi,

This statement appeared in my first post where I had pasted some code from a project that had a text object called RunText. So this statement was just making that object visible on the graph. Setting show to 0 will make the object invisible etc. It therefore gave an error for you because there was no such object in your window. My apologies for this confusion. Please look at the updated script code in my second posting, which is part of the Origin C function within the ifdef block.

Easwar
OriginLab


Go to Top of Page

verrallr@a

Canada
44 Posts

Posted - 02/21/2005 :  5:37:53 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hello Easwar,

Thanks for explaining RunText.Show=1;

Your second insert, showing how to wrap the LT code with OC, was very interesting. There are, I believe, quite a few "slick" points in it. For example, your use of "LT_execute(strCmd)" and your use of #ifdef LABTALK. Since I am not very familiar with C programming, I even had to look up what STATIC meant, in my C programming book.

Let me only ask you this:

In your first message, for DoTool, you used
DoTool 1;
def quittoolbox
...
def pointproc
...

That's actually how I have done it also.

But in your second message, with LT combined with OC, you used a different method. You used:

// Set up an "infinite loop" so code waits for user to click points
for( done = 0; done == 0; )
{
// wait a while
sec -p 0.1;
}

Why did you do it differently this time. Could you have used your first method again, or did you have to do it differently this time. Just curious. You actually don't need to answer this question.

(I don't expect to ever have to do such complicated programming - I just need to create simple OC functions. If ever I need to do complicated programming, I think I will just look to see if that has already been done, for example, in your "Origin C Programming Examples List" web site.)

Richard.
Go to Top of Page

easwar

USA
1965 Posts

Posted - 02/22/2005 :  10:22:55 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Richard,

This "slick" method of including LabTalk code inside Origin C using an ifdef block is from one of our developers, not my idea!

As for LT_execute() that is just a method to send script command strings to be execute while in Origin C. This is documented in the help files.

Now, regarding the "infinite" loop, which one of our engineers helped me with, the reason to include that is that unless this loop is present, the code does not wait for user interaction to finish, and the control goes back to Origin C code too soon.

Easwar
OriginLab


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