You can replace or update data in an existing iTool using either of two methods: using the iTool's creation routine and one of the VIEW keywords, or by retrieving the data object and calling the SetData method. Both methods will change the data stored in the Data Manager and will cause the display to be updated automatically.
You can replace data in an existing iTool by using the iTool's creation command with the VIEW_NUMBER or VIEW_NEXT keyword set to a view that uses the data you wish to replace.
| Note |
For example, suppose you have an iPlot tool with a single view, created with the following command:
IPLOT, myData1
Assuming the iPlot tool is selected, the following command will replace the data in the tool (myData1) with a new data set (myData2):
IPLOT, myData2, VIEW_NUMBER=1
| Note |
In our example, if myData1 is not in use by any other iTool, it will be removed from the iTools Data Manager by this operation. If myData1 is used by a visualization in another view or another iTool, it will not be deleted.
| Note |
You can replace the data that underlies a visualization using the SetData method of the IDLitData class. This technique has the advantage of preserving other changes you may have made to your visualization (property changes, etc.), but requires that you first retrieve the object identifier for the data item you want to replace. This, in turn, requires that you know the parameter name of the of the parameter that contains the data.
To retrieve a list of parameter names for a visualization type, use the QueryParameter method of the IDLitParameter class. The following example creates a plot visualization and retrieves the names of the plot visualization's registered parameters:
; Create the plot visualization
IPLOT, RANDOMU(seed, 15)
idTool = ITGETCURRENT(TOOL=oTool)
; Retrieve the object reference to the plot visualization object.
idPlot = oTool->FindIdentifiers('*plot', /VISUALIZATIONS)
oPlot = oTool->GetByIdentifier(idPlot)
; Retrieve and print the parameter names.
oPlotParams = oPlot->QueryParameters(COUNT=count)
For i=0,count-1 DO PRINT, oPlotParms[i]
IDL prints:
Y X VERTICES Y ERROR X ERROR PALETTE VERTEX_COLORS
Once you know the name of the parameter whose data you wish to change, retrieve the IDLitData object associated with that parameter using the GetParameter method of the IDLitParameter class. You can then use the SetData method of the IDLitData class to insert new data into the parameter. The following example changes the data associated with the "Y" parameter of the plot visualization created in the previous section:
oDataY = oPlot->GetParameter('Y')
success = oDataY->SetData(FINDGEN(50))
It is also possible to use the FindIdentifiers method to retrieve the full identifier of a data object stored in the Data Manager, and use that identifier to retrieve the IDLitData object using the GetByIdentifier method of the IDLitContainer class. While this approach might seem simpler than retrieving the parameter names from the visualization and using the GetParameter method, it has the drawback that identifiers for objects in the Data Manager do not necessarily correspond to a single visualization. As a result, it can be difficult to determine which data item is which, based solely on inspection of the identifier.
Under some circumstances this may not be a problem. For example, if your code creates a new visualization based on data supplied at the command line, you will know that the data object or objects created in the Data Manager will be the last items in the Data Manager container object. The following code creates a new surface visualization using the ISURFACE command, and then immediately retrieves the data identifier of the last data item inserted into the Data Manager:
ISURFACE, DIST(40) idTool = ITGETCURRENT(TOOL=oTool) allData = oTool->FindIdentifiers(/DATA_MANAGER, COUNT=c) idDataSurface = allData[c-1] PRINT, idDataSurface
IDL prints:
/DATA MANAGER/SURFACE PARAMETERS/Z
You then could the use the data identifier to retrieve a reference to the data object and change the data value using the SetData method:
oSurfaceData = oTool->GetByIdentifier(idDataSurface) success = oSurfaceData->SetData(1/(DIST(40)+1))