📄 graph.h
字号:
/*------------------------------------------------------------------------------*
* File Name: graph.h *
* Creation: 9/5/2001 *
* Purpose: Origin C header for GraphLayer class and other related functions *
* Copyright (c) OriginLab Corp.2001 *
* All Rights Reserved *
* *
* Modification Log: *
*------------------------------------------------------------------------------*/
#ifndef _GRAPH_H
#define _GRAPH_H
#include <common.h> // must always include this, has printf etc
#ifndef _STRING_H
#include <string.h> // most likely you will also need strings
#endif // _STRING_H
#include <OC_const.h> // consts used in Origin internal functions
#include <oPlotIDs.h> // IDM_PLOT_* ids and related const
#ifndef _DATA_H
#include <data.h>
#endif // _DATA_H
#include <ORgObj.h>
/** >Internal Origin Objects
The Layer class provides methods and properties common to all internal Origin
layers. All Origin pages (windows) except note pages contain one or more layers.
Origin objects found "on" a page are generally contained by layers which are
themselves contained by the page. Origin layers may contain many different graph
objects thus the Layer class contains a collection of all the graph objects
in the layer. An Origin C Layer object is a wrapper object that is a reference
to an internal Origin layer object. Origin C wrapper objects do not actually
exist in Origin and merely refer to the internal Origin object. Consequently,
multiple Origin C wrapper objects can refer to the same internal Origin object.
The Layer class is derived from the OriginObject class from which it inherits
methods and properties.
Example:
// This example assumes Graph1 with X axis label "XB" is active window/layer in Origin
Layer lyr; // Declare a Layer object named lyr
lyr = Project.ActiveLayer(); // Attach lyr to active layer in "Graph1"
GraphObject go ; // Declare a GraphObject named go
go = lyr.GraphObjects("XB"); // Attach go to X Axis Label with name "XB"
if(go.IsValid()) // If graph object exists...
printf("Name of GraphObject is %s\n", go.GetName()); // Display its name
*/
class Layer : public OriginObject
{
public:
/**
Default constructor which constructs an unattached Layer object.
The member function IsValid() of the base class OriginObject
can be used to determine if the object is valid (attached to an internal
Origin layer object)
Parameters:
None
Example:
void run_Layer_constructor()
{
Layer lay;
if (lay.IsValid())
out_str("Object is valid");
else
out_str("Object is not valid"); // it should be invalid
}
*/
Layer();
/**
Copy constructor which constructs a Layer object from an existing
Layer object.
The member function IsValid() of the base class OriginObject
can be used to determine if the object is valid (attached to an internal
Origin layer object)
Parameters:
layer = the source Layer object
Example:
void run_Layer_constructor()
{
Layer lay;
Layer lay2(lay);
if (lay2.IsValid())
out_str("Object is valid");
else
out_str("Object is not valid"); // it should be invalid
}
*/
Layer(Layer & layer);
/**
It returns the index'th GraphObject in the layer.
GraphObjects are text labels, rectangles, lines, arrows, etc, which
can be drawn inside graphs, worksheets, and layouts,
Parametes:
index = GraphObject index
Returns:
the index'th GraphObject in the layer.
Example:
// For this example to run, a graph window with the name "Graph1" must exist in the project.
void run_Layer_GraphObjects()
{
// Create a Layer object and attach it to the active layer in "Graph1" graph window.
GraphLayer lay("Graph1");
GraphObject grobj;
// Get the first GraphObject in the layer:
grobj = lay.GraphObjects(0);
// Make sure that the object is valid:
if (!grobj.IsValid())
{
out_str("No GraphicObject!");
return;
}
// Display its name:
printf("The name of the first GraphObject in layer is %s\n", grobj.GetName());
}
*/
GraphObject GraphObjects(int index);
/**
It returns the GraphObject with the given name in the layer.
GraphObjects are text labels, rectangles, lines, arrows, etc, which
can be drawn inside graphs, worksheets, and layouts,
Parametes:
lpcszName = pointer to the string representing the name of the GraphObject
Returns:
the GraphObject with the name lpcszName in the layer.
Example:
// For this example to run, a graph window with the name "Graph1" must exist in the project.
// Also, in the active layer create a text label with the name "Text". You can change
// the name of the text label GraphObject using the "Label Control" dialog box (use
// the context menu on the text label to bring up the dialog).
void run_Layer_GraphObjects()
{
// Create a Layer object and attach it to the active layer in "Graph1" graph window.
GraphLayer lay("Graph1");
GraphObject grobj;
// Get the GraphObject with the name "Text":
grobj = lay.GraphObjects("Text");
// Make sure that the object is valid:
if (!grobj.IsValid())
{
out_str("No GraphicObject!");
return;
}
// Display its name:
printf("The name of the GraphObject is %s\n", grobj.GetName());
}
*/
GraphObject GraphObjects(LPCSTR lpcszName);
/**
It gets the parent Page object (the Page containing this layer).
Parameters:
None
Returns:
the parent Page object
Example:
// For this example to run, a graph window with the name "Graph1" must exist in the project.
void run_Layer_GetPage()
{
// Create a Layer object and attach it to the active layer in "Graph1" graph window.
GraphLayer lay("Graph1");
Page pg;
// Get the parent page:
pg = lay.GetPage();
printf("The name of the parent page is %s\n", pg.GetName());
}
*/
Page GetPage();
/**
It detaches the internal Origin layer from this object.
Parameters:
None
Returns:
void
Example:
// For this example to run, a graph window with the name "Graph1" must exist in the project.
void run_Layer_Detach()
{
// Create a Layer object and attach it to the active layer in "Graph1" graph window.
GraphLayer lay("Graph1");
// We can check if the object lay is valid (attached to
// an internal Origin layer) by calling the method "IsValid)"
if ( lay.IsValid() )
out_str("Object is valid"); // it should valid (if "Graph1" exists)
else
out_str("Object is not valid");
// Now detach:
lay.Detach();
if ( lay.IsValid() )
out_str("Object is valid");
else
out_str("Object is not valid"); // it should be invalid because we detached it
}
*/
void Detach();
/**
Removes one GraphObject from layer. The object is referred to by index.
Parameters:
index = the GraphObject index
Return:
TRUE for success, otherwise FALSE
Example:
// For this example to run, a graph window with the name "Graph1" must exist in the project.
void run_Layer_RemoveGraphObject()
{
// Create a Layer object and attach it to the active layer in "Graph1" graph window.
GraphLayer lay("Graph1");
GraphObject grobj;
// Get the first GraphObject in the layer:
grobj = lay.GraphObjects(0);
// Make sure that the object is valid:
if (!grobj.IsValid())
{
out_str("No GraphicObject!");
return;
}
// Display its name:
printf("The name of the first GraphObject is %s\n", grobj.GetName());
// Now remove the first GraphObject:
lay.RemoveGraphObject(0);
// Get the new first GraphObject in the layer:
grobj = lay.GraphObjects(0);
// Make sure that the object is valid:
if (!grobj.IsValid())
{
out_str("No GraphicObject!");
return;
}
// Display its name:
printf("The name of the first GraphObject is %s\n", grobj.GetName());
}
*/
BOOL RemoveGraphObject(int index);
/**
Removes one GraphObject from layer. The object is referred to by name (lpcszName).
Parameters:
lpcszName = the GraphObject name
Return:
TRUE for success, otherwise FALSE
Example:
// For this example to run, a graph window with the name "Graph1" must exist in the project.
// Also, in the active layer create a text label with the name "Text". You can change
// the name of the text label GraphObject using the "Label Control" dialog box (use
// the context menu on the text label to bring up the dialog).
void run_Layer_RemoveGraphObject()
{
// Create a Layer object and attach it to the active layer in "Graph1" graph window.
GraphLayer lay("Graph1");
GraphObject grobj;
// Get the GraphObject named "Text" in the layer:
grobj = lay.GraphObjects("Text");
// Make sure that the object is valid:
if (!grobj.IsValid())
{
out_str("No GraphicObject!");
return;
}
// Display its name:
printf("The name of the GraphObject is %s\n", grobj.GetName());
// Now remove the GraphObject with the name "Text":
lay.RemoveGraphObject("Text");
// Get the the GraphObject named "Text" in the layer again:
grobj = lay.GraphObjects("Text");
// Make sure that the object is invalid (because we removed it above):
if (!grobj.IsValid())
{
out_str("No GraphicObject!");
return;
}
}
*/
BOOL RemoveGraphObject(LPCSTR lpcszName);
/**
The Collection property of all GraphObjects in the layer.
Example:
// For this example to run, a graph window with the name "Graph1" must exist in the project.
void run_Layer_GraphObjects_Collection()
{
// Create a Layer object and attach it to the active layer in "Graph1" graph window.
GraphLayer lay("Graph1");
GraphObject grobj;
Collection<GraphObject> grobjcollection;
// Get the collection object from the layer:
grobjcollection = lay.GraphObjects;
// Use foreach-loop to loop over all the GraphObjects in the collection
foreach (grobj in grobjcollection)
{
// Display the name:
out_str(grobj.GetName());
}
}
*/
Collection<GraphObject> GraphObjects;
/**
Get the index of the Layer in the parent page, 0 offset
Remark:
This method returns 1-offset index in Origin 7, and in Origin 7.5 and later, it has been made consistent to return 0-offset index.
Return:
The index of the specific layer in its parent page
Example:
// For this example to run, a graph window with the name "Graph1" must exist in the project.
// Make sure that the window has several layers.
// Make layer 2 active before running the function.
void run_GetIndex()
{
// Create a Layer object and attach it to the active layer in "Graph1" graph window.
GraphLayer lay("Graph1");
// Displaye the active index (it should be "2" if the active layer is the second layer):
out_int("Active layer index is ", lay.GetIndex() + 1); // convert C index to LabTalk index
}
*/
int GetIndex();
/**
Execute labtalk script with the current layer as the active layer. This command has the combination effect of labtalk's "win -o" and "layer -o"
Example:
// For this example to run, a graph window with the name "Graph1" must exist in the project.
// Make sure that the window has several layers.
// Make layer 2 active before running the function.
void run_Layer_LT_execute()
{
GraphPage page("Graph1");
// Create a Layer object and attach it to the first layer in "Graph1" graph window.
GraphLayer lay = page.Layers(0);
double xx = -10.0;
// we will set X scales in the layer using LabTalk script:
string str;
// Construct the LabTalk script to be executed:
str.Format("layer.x.from=%f;layer.x.to=%f;", xx, xx + 10.0);
// Execute the script. After this script executes, the first layer
// will have the x-axis running from -10 to 0.
lay.LT_execute(str);
}
*/
BOOL LT_execute(LPCSTR lpcszstr, int wCntrl = 0);
#if _OC_VER >= 0x0750
/**
Get the layer's internal info
Return:
a generic value that depends on the request
Parameters:
nType = specify the info to obtain
*/
DWORD GetSystemParam(int nParamType);
#endif //_OC_VER >= 0x0750
};
/** >Internal Origin Objects
The Layout class provides methods and properties common to all internal Origin layout
layers. Origin layout pages contain a layout layer which contains other objects on the
layout page. An Origin C Layout object is a wrapper object that is a reference to an internal
Origin layout object. Origin C wrapper objects do not actually exist in Origin and merely
refer to the internal Origin object. Consequently, multiple Origin C wrapper objects
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -