How to modify the default value of arguments in context menu

Hi,

I’m using a method which is shown in the contect menu and which is is used by the user to select a shift on a graph that he wants to applied. I have seen that the default value printed in the box opened from the menu can be a non static variable as the last enterd value. How can I do that ? I have tried in my header something like this :

protected:
double fCurrentXShift;
virtual void SetXShift(double XShift); //MENU={Hierarchy=“Shift/SetXShift”} ARGS={XShift=>fCurrentXShift}

but nothing is printed in the box when I click on SetXShift in the ContextMenu

An idea ?

Jérémie

Hi Jérémie,

I’m not sure I understand what you’re trying to do… Could you post a small, running piece of code showing it?

Cheers, Bertrand.

Hi Bellenot

It’s quite complicated to show what I want to do by posting a small piece of code. Perhaps it will be clearer with screenshots. I am using a TTask which execute different methods on electronic signals which are printed on a Canvas. These methods are shown on the menu bar of the TTask as the Shift method for example (Screenshot1). When I click on it, the open box which ask for a parameter (Screenshot2). The default value of this parameter is manually initialize at 0, but I want that this default value is equal to the last entered value, contained in a variable of my Class (fCurrentXShift for example). I have seen that it is possible to do that with the ROOT interpretor with something like that in the class header:
virtual void SetXShift(double XShift); //MENU={Hierarchy=“Shift/SetXShift”} ARGS={XShift=>fCurrentXShift}
But this is not working.

Is it more understandable ?

Jérémie




Hi Jeremie,

You need a getter for the fCurrentXShift variable, then it will work. For example, this works for me:

protected: double fCurrentXShift; public: virtual void SetXShift(double XShift) {} //*MENU* *ARGS={XShift=>fCurrentXShift}* virtual double GetCurrentXShift() const { return fCurrentXShift; } But it doesn’t work without the GetCurrentXShift() method.

Cheers, Bertrand.

Perfect, it works now!

Thank you very much :smiley:

1 Like

Hi,

I re-open my old post. Is there a way to do the same thing, with a multi-input method ? Typically, I want to define the method from the context menu:
void SetSomething(float a, float b);

and that the values of a, and b proposed by default in the opened window, are the current values of ma class variables fA, and fB ?

Thanks in advance

Jérémie

   void SetSomething(float a, float b); // *MENU* *ARGS={a=>fA,b=>fB}

I don’t understand why but it doesn’t work for me, here is what I’ve done:

class MyClass : public TH1D
{

RQ_OBJECT("MyClass");

private:
    Float_t fLenghtFactor = 1.;
    Float_t fWidth        = 6.;
    Float_t fFWHM_0       = 9.;
    Float_t fFWHM_1       = 0.004;
    Float_t fFWHM_2       = 0.;

public:

MyClass(TH2 *hist);
~MyClass();

void SetBackground(Float_t LenghtFactor, Float_t Width, Float_t FWHM_0, Float_t FWHM_1, Float_t FWHM_2); //*MENU* *ARGS={LenghtFactor=>fLenghtFactor,Width=>fWidth,FWHM_0=>fFWHM_0,FWHM_1=>fFWHM_1,FWHM_2=>fFWHM_2}

ClassDef(MyClass,1);

};

Please read this:


And then, could you send code which can be run, and describe what are the errors you get?

Please find attached an example that you can run.
The histogram that is plotted is the one from my derivated class. If you make a right click on it, and execute the SetBackground Method, the default values are not the one of the variables of my class.

Thanks in advance

Jérémietest.C (1.0 KB)

Here is the modified macro. You need the getters to properly set the default values, and the initialisation has to be done in the constructor.
test.C (1.3 KB)

Perfect, thank you !