Fanning Software Consulting

Changing iTool Properties Programmatically

QUESTION: I want to call the iPlot program from within my IDL program. However, I want it to come up in "stretch-to-fit" mode automatically. I do not want to have to change this every time from the Visualization Browser. How can I do this? I find the documentation, uh, confusing.

ANSWER: Yes, confusing and (in this case) incomplete. Chris Torrence let us in on the secret to how this can be done. The key to it is the undocumented (and subject to change in future versions of IDL) iTool function _IDLitSys_GetSystem. Chris promises that there is a much simpler way to change iTool properties coming in future versions of IDL, but for the moment, at least, you can change the program after the fact by code similar to the following.

First, call the iTool you are interested in changing with the Identifier keyword. This is an output keyword and will return the ID of the tool you are using.

   data = Sin(Findgen(101) * !Radeg)
   iPlot, data, Identifier=idTool

Now use the undocumented function _IDLitSys_GetSystem to retreive the system object, and by that the particular iTool you are using:

   theSystem = _IDLitSys_GetSystem()
   theTool = theSystem -> GetByIdentifier(idTool)

The easiest way to determine the object identifiers of the properties you want to set is to examine the contents of the Visualization Browser and trace through the object heirarchy to the property you are interested in. In our case, the path to the property we are interested in is "WINDOW/VIEW_1/VISUALIZATION LAYER", and the property is "STRETCH_TO_FIT". You have to do a bit of guessing about the name of the property, but it is more or less consistent with the property label in the Visualization Browser.

To set the property, you call the DoSetProperty method on the tool object.

   void = theTool -> DoSetProperty('WINDOW/VIEW_1/VISUALIZATION LAYER', 'STRETCH_TO_FIT', 1)

Here you can set as many properties of the visualization as you like. None of them take effect until they are committed in the next step.

   theTool -> CommitActions

Other iTool Command Line Modifications

Chris goes on to point out that there are good examples of iTool modifications in the IDL_DIR/examples/demo/demosrc directory. He recommends the programs d_icontour, d_icurvefit, and d_iimage in particular.

Here is code from d_icurvefit that illustrates how to use a DoAction method to cause the Curve Fitting operation to be called, then a legend added to the plot automatically once the Curve Fit dialog has been dismissed. Chris points out that with the combination of the DoSetProperty and DoAction methods, almost any "interactive" iTool operation can be executed from the IDL command line.

   n = 50
    x = (findgen(n) - 25)/2
    yerr = 0.1
    y = 2 + 0.1*x + 3*exp(-((x - 1)/2)^2) + yerr*randomn(1,n)
    yerror = replicate(yerr, n)

    IPLOT, x, y, $
        COLOR = [255,0,0], $
        ERRORBAR_COLOR = [255,0,0], $
        THICK = 2, $
        LINESTYLE = 6, $
        NAME = 'Gaussian+Linear', $
        SYM_INDEX = 4, $
        XTITLE = 'Angle  !9F!X (degrees)', $
        YTITLE = 'Area (m!u2!n)', $
        YERROR = yerror, $
        /NO_SAVEPROMPT

    oSys = _IDLitSys_GetSystem()
    oTool = oSys->_GetCurrentTool()
    void = oTool->DoAction('Operations/Operations/Filter/Curve Fitting')
    oWin = oTool->GetCurrentWindow()
    oWin->ClearSelections
    void = oTool->DoAction('Operations/Insert/Legend')

Google
 
Web Coyote's Guide to IDL Programming