_ROOT Version: 6.14/02
_Platform:Ubuntu18.04
Compiler: Not Provided
Hi,
I got a problem on TGraph class. In order to insert a point in the position where my mouse is, I write a function like this:
#include “TCanvas.h”
#include “TPad.h”
bool InsertPoint2(TPad *c, TGraph *g)
{
c->cd();Int_t px = c->GetEventX(); Int_t py = c->GetEventY(); cout<<" px= "<<setw(8)<<px<<"; py= "<<setw(8)<<py<<endl; double ax=c->AbsPixeltoX(px); double ay=c->AbsPixeltoY(py); cout<<" ax= "<<setw(8)<<ax<<"; ay= "<<setw(8)<<ay<<endl; double xmin,xmax,ymin,ymax; cout<<" Axis range is:\n"; c->GetRangeAxis(xmin,ymin,xmax,ymax); cout<<" xmin="<<setw(8)<<xmin<<"; xmax="<<setw(8)<<xmax<<"; ymin="<<setw(8)<<ymin<<"; ymax="<<setw(8)<<ymax<<endl; if(ax>=xmin&&ax<=xmax&&ay>=ymin&&ay<=ymax) { g->SetPoint(g->GetN(),ax,ay); c->Update(); return true; } else { cout<<" Out of range!"<<endl; return false; }
}
Any how, it works in the command by calling it like this:
bool insertstate=InsertPoint2(c1,g1)
But when I call this function in a script, the mouse position can’t be updated, it’s always in the same position.
Here is the code:
cin.sync(); char c; cip->cd(); cout<<" Input [Y] when mouse is in the correct place!(Input 'N' to quit):"; while(cin>>c) { cout<<" Your input is:"<<int(c)<<endl; if(c=='Y'||c=='y') { insertstate=InsertPoint2(cip,g3c[editline-1]); if(insertstate) cout<<" Insert point to line NO."<<setw(3)<<editline<<" Succeed!\n"; else cout<<" Insert point to line NO."<<setw(3)<<editline<<" Failed!\n"; } else if(c=='N'||c=='n') { cout<<" Line NO."<<setw(2)<<editline<<" has done!\n"; break; } else { cout<<" Invalid input!\n"; cout<<" Input [Y] when mouse is in the correct place!(Input 'N' to quit):"; } cin.sync(); }
Why this happened?