Making a Renderer Persistent
If the graphic objects are created using a specific renderer, you must save that renderer to render the objects in the same way the next time they are loaded. The class IlvSDOLayer, for example, lets you specify a renderer that will be saved with the layer. See IlvSDOLayer::setFeatureRenderer in the Reference Manual.
The ColorLineRenderer presented in the previous section derives from the IlvFeatureRenderer abstract class. This class specifies three methods related to persistence: the isPersistent method specifies whether the renderer is persistent, the write method that writes the renderer in an IlvOutputFile, and the save method that saves the class and the renderer. To implement a persistent renderer, you then have to overwrite the isPersistent method and the write method.
IlvBoolean ColorLineRenderer::isPersistent() { return IlvTrue; } void ColorLineRenderer::write(IlvOutputFile& output) const { IlvWriteString(output, _attributeName); if(_colorModel->isPersistent()) { output.getStream() << 1 << IlvSpc(); _colorModel->write(output); } else { output.getStream() << 1 << IlvSpc(); IlvWarning("colormodel not saved"); } } |
You can, however, build the renderer using any other color model, which might not be persistent. In this case, the color model is not saved and the write method generates a warning.
If the color model is not saved with the renderer, a default color model is created when the renderer is read.
ColorLineRenderer::ColorLineRenderer(IlvInputFile& stream) :IlvFeatureRenderer(stream.getDisplay(), IlvTrue) { char* s = IlvReadString(stream); if(s) _attributeName = strcpy(new char[strlen(s)+1], s); IlvInt hasColorModel; stream.getStream() >> hasColorModel; if(hasColorModel) { _colorModel = (IlvMapColorModel*) IlvMapClassInfo::ReadObject(IlvMapColorModel::ClassInfo(), stream, 0); } else { _colorModel = IlvIntervalColorModel::MakeElevationColorModel(); } } |