GetGraphPoints
Name
GetGraphPoints
Remark
The OriginC GetGraphPoints class can be used to interactively pick XY points on a graph. It allows either individual data points on one or more plots to be selected or, similar to the Screen Reader tool, allows arbitrary points to be selected. These selected points are collected and can later be accessed for further use.
Generally, a class is derived from the GetGraphPoints class with some or all event methods overridden to define the desired behavior. Then an instance of that derived class is created and used to actually pick the points.
Hierarchy
Example
The following example goes into detail to discuss the various methods, event methods, and logical flow for using a derived a class of GetGraphPoints in OriginC code.
#include <Origin.h>
// Example of derived class.
class MyGetGraphPoints : public GetGraphPoints
{
public:
// Constructor is called when an instance of this class is created.
// It is here for illustrative purposes and isn't strictly necessary.
MyGetGraphPoints()
{
}
// Destructor is called called when an instance variable goes out of scope or is destroyed.
// It is here for illustrative purposes and isn't strictly necessary.
~MyGetGraphPoints()
{
}
//===============================================
// All event methods overridden for illustration.
//===============================================
// Called immediately after GetGraphPoints::GetPoints() is called and prior to picking points.
void OnStart()
{
printf("OnStart\n");
}
// Called when predefined maximum number of points are picked prior to control
// returning to the OriginC code that initiated the point picking.
void OnFinish()
{
printf("OnFinish\n");
}
// Called when either ESC key is pressed or graph is deactivated. Then control
// returns to the OriginC code that initiated the point picking.
void OnCancel()
{
printf("OnCancel\n");
}
// Called when a new point is picked via double-click or ENTER key pressed
// with point selected.
// The "nPoint" parameter is the zero-based count of picked points up to and including the new point.
void OnNewPoint(int nPoint)
{
// For example, use GetGraphPoints::GetCursorPos() method to retieve the XY coordinates
// and output them. But one could do something else with them.
if( nPoint >= 0 )
{
double dX, dY;
GetCursorPos(dX, dY);
printf("OnNewPoint (X: %f, Y: %f)\n", dX, dY);
}
}
// This event method is called multiple times for each point selected (whether ot not it was
// actually picked). It can be used for supplemental display of information related to the point.
// The "str" parameter is a string reference that can optionally be modified to add
// information to the output in the Data Display window. It can also be ignored.
// Th "nPoint" parameter is the zero-based count of picked points thus far (not including
// the selection that triggered this event method).
// You don't have to use either parameter- you can perform any sort of display action here.
void OnDisplay(string& str, int nPoint)
{
// For example let's add something to the Data Display window.
if( nPoint >=0 && !str.IsEmpty() )
str += "Picked: " + (string)nPoint;
}
}; // End class MyGetGraphPoints.
// Example function that uses derived class.
// It is assumed that a graph is active with at least 1 XY data plot.
void test_GetGraphPoints()
{
// Get the active GraphLayer.
GraphLayer gl = Project.GraphPages(-1).Layers(-1);
if( !gl.IsValid() )
return;
// Get the index of the active DataPlot.
int nPlotIndex = gl.DataPlots(-1).GetIndex();
if( nPlotIndex < 0 )
return;
// Pick a total of 10 points. To pick a seemingly unlimited number of points
// it could be set to something very high such as 1E6.
int nMaxPoints = 10;
// Create an instance of class.
MyGetGraphPoints ggp;
// GetGraphPoints::SetFollowData() must be called prior to calling GetGraphPoints::GetPoints().
// If the 1st parameter is true, point picking is restricted to only actual points on the specified plot index.
// If it is false, arbitrary coordinates anywhere in the layer may be picked.
// The 2nd parameter is the plot index to pick from when the 1st parameter is true.
// Note: if 1st parameter is true, points can be selected from any plot in specified
// layer by passing in -1 for the 2nd parameter.
ggp.SetFollowData(true, nPlotIndex);
// This is optional but must be called prior to calling GetGraphPoints::GetPoints().
// Allows a point to be preselected (thought not picked) when picking starts.
ggp.SetCursorPos(1, 1);
// This too is optional but must be called prior to calling GetGraphPoints::GetPoints().
// Allows a different cursor pattern for picked points on the graph.
// Either -1 for default or CURSOR_VERTICAL_GRID_LINES or CURSOR_HORIZONTAL_GRID_LINES.
ggp.SetCursor(-1);
// This method initiates the point picking process.
// The 1st parameter is the maximum number of points to pick.
// The 2nd parameter is the GraphLayer to pick the point sfrom.
// Note: code will pause here until point picking is done.
ggp.GetPoints(nMaxPoints, gl);
// Will resume here when either the maximum number of picked points has been reached or
// or user pressed the ESC key or graph was deactivated.
// Retrieve the picked X and Y values as vectors.
// The 3rd parameter to GetGraphPoints::GetData() will retieve the zero-based row
// indices for the picked points in its worksheet and the 4th the plot indices of the picked points.
// Note: if 1st parameter to GetGraphPoints::SetFollowData() is false, meaning arbitrary
// picking, the values in the 3rd and 4th parameter vectors will all be -1.
vector vX, vY;
vector<int> vnRows, vnPlots;
ggp.GetData(vX, vY, vnRows, vnPlots);
int nSize = vX.GetSize();
// Simply returns the maximum allow points to pick as specified when calling GetGraphPoints::GetPoints().
int nTotal = ggp.GetTotalPoints();
printf("Picked Points %d of %d Max:\n", nSize, nTotal);
for( int ii = 0; ii < nSize; ii++ )
{
DataPlot dp = gl.DataPlots(vnPlots[ii]);
string strLegend;
dp.GetLegend(strLegend, "@R1");
printf("X=%f, Y=%f, Row=%d, Plot=%s\n", vX[ii], vY[ii], vnRows[ii]+1, strLegend);
}
}
header to Include
origin.h
Reference
Members
Name |
Brief |
GetCursorPos |
Gets the XY coordinates of the cursor during GetPoints process. |
GetData |
Gets the XY points into two vectors for the points that have been picked. |
GetGraphPoints |
Default constructor |
GetPoints |
Initiates the point picking process. |
GetTotalPoints |
Returns the maximum allowed points to pick. |
IsFollowData |
Tests if the particular DataPlot is used to restrict the movements of the reader cursors |
OnCancel |
Called when either the ESC key is pressed or graph is deactivated while picking points. |
OnDisplay |
Called when a point is selected whether or not it was actually being picked. Can be used for supplemental display of information related to the point. |
OnFinish |
Called when when the predefined maximum number of points has been picked and prior to GetGraphPoints::GetPoints() returning. |
OnNewPoint |
Called when a new point is picked via double-click or ENTER key pressed with point selected. |
OnStart |
Called immediately after GetGraphPoints::GetPoints() is called and prior to picking points. |
SetCursor |
Allows specifying the cursor pattern displayed for pick points on the graph. |
SetCursorPos |
Allows a point to be preselected (thought not picked) when picking starts. |
SetFollowData |
Specifies whether point picking is restricted to only actual points on a specified plot index, actual points on any plot in the layer, or at arbitrary coordinates anywhere in the layer. |
Property
|