예제 #1
0
//------------------------------------------------------------------------------
// update the symbol's color based on Identifier
//------------------------------------------------------------------------------
bool SymbolLoader::setSymbolColor(const int idx, const char* name, const Basic::Identifier* cname)
{
    bool ok = false;

    // Find the symbol
    if (idx >= 1 && idx <= MAX_SYMBOLS) {
        const int i = (idx - 1);
        if(symbols[i] != 0) {

            // Get its graphical component
            Basic::Pair* p = (Basic::Pair*)symbols[i]->getSymbolPair();
            if (p != 0) {
                BasicGL::Graphic* g = dynamic_cast<BasicGL::Graphic*>(p->object());
                if (g != 0) {

                    // If we were passed a name then use it to find the subcomponent
                    // and change 'g' to point to the subcomponent instead.
                    if (name != 0) {
                        Basic::Pair* spair = g->findByName(name);
                        if (spair != 0) {
                            // subcomponent found by name
                            g = (BasicGL::Graphic*)(spair->object());
                        }
                        else {
                            // no subcomponent was found by that name
                            g = 0;
                        }
                    }

                    // Set the color (if we found one)
                    if (g != 0) ok = g->setColor(cname);
                }
            }
        }
    }

    return ok;
}