예제 #1
0
void
ModuleFeedbackManager::updateColorBar(RenderObject *containerObject)
{

    RenderObject *colorObj = NULL;
    const char *colormapString = NULL;

    if (containerObject)
    {
        colorObj = containerObject->getColors();
        if (!colorObj)
            colorObj = containerObject->getTexture();
        if (colorObj)
        {
            colormapString = colorObj->getAttribute("COLORMAP");
            if (colormapString == NULL && colorObj->isSet())
            {
                size_t noElems = colorObj->getNumElements();
                for (size_t elem = 0; elem < noElems; ++elem)
                {
                    colormapString = colorObj->getElement(elem)->getAttribute("COLORMAP");
                    if (colormapString)
                        break;
                }
            }
            // compute colorbar
            std::string tmpStr = ModuleName(geomObjectName_.c_str());
            const char *modname = tmpStr.c_str();
            float min = 0.0;
            float max = 1.0;
            int numColors;
            float *r = NULL;
            float *g = NULL;
            float *b = NULL;
            float *a = NULL;
            char *species = NULL;
            if (colormapString)
            {
                //cerr << "ModuleFeedbackManager::updateColorBar(..) COLORMAPSTRING " << colormapString << endl;
                ColorBar::parseAttrib(colormapString, species, min, max, numColors, r, g, b, a);
            }
            else
            {
                species = new char[16];
                strcpy(species, "NoColors");
                numColors = 2;
                min = 0.0;
                min = 1.0;
                r = new float[2];
                g = new float[2];
                b = new float[2];
                a = new float[2];
                r[0] = 0.0;
                g[0] = 0.0;
                b[0] = 0.0;
                a[0] = 1.0;
                r[1] = 1.0;
                g[1] = 1.0;
                b[1] = 1.0;
                a[1] = 1.0;
            }

            // color bar
            if (colorBar_)
            {
                colorBar_->update(species, min, max, numColors, r, g, b, a);
            }
            else
            {
                //cerr << "ModuleFeedbackManager::updateColorBar(..) MODNAME <" << modname << ">" << endl;
                colorBar_ = new ColorBar(colorsButton_, menu_,
                                         modname, species, min, max, numColors, r, g, b, a);
            }
            delete[] species;
            delete[] r;
            delete[] g;
            delete[] b;
            delete[] a;
        }
        else // container without colors
        {
            if (colorBar_) // the previous object had colors
                delete colorBar_;
            colorBar_ = NULL;
        }
    }
    else // no container
    {
        if (colorBar_) //the previous object had colors
            delete colorBar_;
        colorBar_ = NULL;
    }
}