3.12.1 Graph Control Dialog
Version Info
Minimum Origin Version Required: Origin 8 SR0
Need to do before Running Examples
- New a c file named "GraphControl Example.c" and save to \OriginC\Originlab folder.
- Open Origin, open 2D Gaussian.ogm from \Samples\Matrix Conversion and Gridding folder. Choose menu Plot -> 3D Surface -> Color Map Surface to plot a 3D graph.
- Add the above c file to current workspace and compile.
- Run "OpenGraphPreviewDlg 0" to open dialog, click "UP" button, source graph changed, but preview on dialog not update. If run "OpenGraphPreviewDlg 1" to open dialog, click "UP" button, source graph and preview both changed.
Example
#include <..\Originlab\DialogEx.h>
void OpenGraphPreviewDlg(bool bRealTimeUpdate = true)
{
GraphLayer gl = Project.ActiveLayer();
if( gl )
{
// open preview dialog
GraphPage gp = gl.GetPage();
GraphPreviewDlg dlgEx(gp, bRealTimeUpdate);
dlgEx.DoModalEx( GetWindow() );
}
}
class GraphPreviewDlg : public ResizeDialog
{
public:
GraphPreviewDlg(GraphPage& gp, bool bRealTimeUpdate, int ID = IDD_GETNBOX_PREVIEW);
~GraphPreviewDlg();
int DoModalEx(HWND hWndParent);
protected:
EVENTS_BEGIN
ON_INIT(OnInitDialog)
ON_BN_CLICKED(IDC_PARAMS_MORE, OnBtnClick)
EVENTS_END
BOOL OnInitDialog();
BOOL OnBtnClick(Control ctrl);
private:
void updatePreview();
private:
GraphPage m_gpSource;
PictureControl m_pictControl;
bool m_bRealTimeUpdate;
};
GraphPreviewDlg::GraphPreviewDlg(GraphPage& gp, bool bRealTimeUpdate, int ID)
:ResizeDialog(ID, "ODlg")
{
m_gpSource = gp;
m_bRealTimeUpdate = bRealTimeUpdate;
}
GraphPreviewDlg::~GraphPreviewDlg()
{
}
BOOL GraphPreviewDlg::OnInitDialog()
{
ResizeDialog::OnInitDialog();
// to hidden ususeful controls
vector<int> vnHiddenIDs = {IDC_ERR_MESSAGE_BOX, IDC_PARAMS_DESCRIPTION, IDC_GETN_RESULT_PREVIEW};
for(int nn = 0; nn < vnHiddenIDs.GetSize(); nn++)
{
Control ctrl = GetItem(vnHiddenIDs[nn]);
if(ctrl)
ctrl.Visible = false;
}
Control btn = GetItem(IDC_PARAMS_MORE);
if( btn )
btn.Text = "UP";
Control cntrl = GetItem(IDC_PARAMS_PREVIEW);
if(cntrl)
m_pictControl.CreateControl(cntrl.GetSafeHwnd());
// this property to no stretch to enable scroll bar
//m_pictControl.DrawMode = PCDM_NO_STRETCH;
updatePreview();
return true;
}
void GraphPreviewDlg::updatePreview()
{
PictureHolder phDst;
m_gpSource.GetPicture(phDst, "EMF", 72, -1, EMBEDGRAPH_HIDE_LEGENDS);
m_pictControl.SetPicture(phDst);
}
BOOL GraphPreviewDlg::OnBtnClick(Control ctrl)
{
GraphLayer gl = m_gpSource.Layers(); // active layer
DataPlot dp = gl.DataPlots(); // active data plot
Curve crv(dp);
crv += 1; // add 1 to each y data point, data plotting line will be moved up
if( m_bRealTimeUpdate )
updatePreview();
return true;
}
int GraphPreviewDlg::DoModalEx(HWND hWndParent)
{
InitMsgMap();
DWORD dwDlgOptions = 0;
int nRet = DoModal(hWndParent, dwDlgOptions);
return nRet;
}
|