void SoEnabledElementsList::enable(SoType elementType, int stackIndex) // //////////////////////////////////////////////////////////////////////// { SoType prev = elements[stackIndex]; // If not enabled before or if enabled before but we are now // enabling a more-specific subclass, add the element. if (prev.isBad() || (elementType != prev && elementType.isDerivedFrom(prev))) { elements.set(stackIndex, elementType); // Increment global counter to indicate that lists have changed counter++; } #ifdef DEBUG // If we aren't enabling a more general super-class (and therefore // don't need to do anything), error: else if (! prev.isDerivedFrom(elementType)) { const char *eltName = elementType.getName().getString(); SoDebugError::post("SoAction::enableElement", "Cannot enable element %s because element %s " "is already enabled", eltName, prev.getName().getString()); } #endif }
SbBool SoType::isDerivedFrom(const SoType parent) const { assert(!this->isBad()); if (parent.isBad()) { #if COIN_DEBUG SoDebugError::postWarning("SoType::isDerivedFrom", "can't compare type '%s' against an invalid type", this->getName().getString()); #endif // COIN_DEBUG return FALSE; } SoType type = *this; do { #if COIN_DEBUG && 0 // debug SoDebugError::postInfo("SoType::isDerivedFrom", "this: '%s' parent: '%s'", type.getName().getString(), parent.getName().getString()); #endif // debug if (type == parent) return TRUE; type = (*SoType::typedatalist)[(int)type.getKey()]->parent; } while (!type.isBad()); return FALSE; }
void SoUnknownNode::createFromIsA(SoMFString *isA) // //////////////////////////////////////////////////////////////////////// { for (int i = 0; i < isA->getNum(); i++) { SoType t = SoType::fromName((*isA)[i]); if (t.canCreateInstance() && t.isDerivedFrom(SoNode::getClassTypeId())) { SoNode *alternateRep = (SoNode *)t.createInstance(); alternateRep->ref(); #ifdef DEBUG if (alternateRep == NULL) { SoDebugError::post("SoUnknownNode::createFromIsA", "SoType.createInstance returned " "NULL (type %s)", t.getName().getString()); return; } #endif // Copy over all fields that are shared: int num = instanceFieldData->getNumFields(); for (int j=0; j<num; j++) { const SbName &fieldName = instanceFieldData->getFieldName(j); SoField *f = instanceFieldData->getField(this, j); // Don't copy over fields with default values: if (f->isDefault()) continue; SoField *nf = alternateRep->getField(fieldName); if (nf != NULL && nf->getTypeId() == f->getTypeId()) { nf->copyFrom(*f); if (f->isConnectedFromField()) { SoField *cf; f->getConnectedField(cf); nf->connectFrom(cf); } else if (f->isConnectedFromEngine()) { SoEngineOutput *eo; f->getConnectedEngine(eo); nf->connectFrom(eo); } } } // And if alternateRep is a group, copy over hidden // children: if (alternateRep->isOfType(SoGroup::getClassTypeId())) { SoGroup *g = (SoGroup *)alternateRep; for (int kid = 0; kid < hiddenChildren.getLength(); kid++) { g->addChild(hiddenChildren[kid]); } } addChild(alternateRep); return; } } }
void SoActionMethodList::addMethod(SoType nodeType, SoActionMethod method) // //////////////////////////////////////////////////////////////////////// { #ifdef DEBUG // Make sure nodeType is a kind of node! if (! nodeType.isDerivedFrom(SoNode::getClassTypeId())) SoDebugError::post("SoAction::addMethod", "%s is not a node type", nodeType.getName().getString()); #endif /* DEBUG */ numValidTypes = 0; (*this)[SoNode::getActionMethodIndex(nodeType)] = method; }
SoGate::SoGate(SoType inputType) // //////////////////////////////////////////////////////////////////////// { SO_ENGINE_CONSTRUCTOR(SoGate); SO_ENGINE_ADD_INPUT(enable, (0)); SO_ENGINE_ADD_INPUT(trigger, ()); myInputData = new SoFieldData(inputData); myOutputData = new SoEngineOutputData(outputData); input = NULL; setup(inputType); typeField.setValue(inputType.getName()); isBuiltIn = TRUE; }
int main(void) { SoDB::init(); SoNodeKit::init(); SoInteraction::init(); SoTypeList tl; const unsigned int n = SoType::getAllDerivedFrom(SoNode::getClassTypeId(), tl); for (unsigned int i=0; i < n; i++) { (void)fprintf(stdout, "%s", tl[i].getName().getString()); SoFieldContainer * fc = (SoFieldContainer *) (tl[i].canCreateInstance() ? tl[i].createInstance() : NULL); if (fc == NULL) { (void)fprintf(stdout, " (abstract)\n"); continue; } (void)fprintf(stdout, "\n"); SoFieldList fl; const unsigned int nrf = fc->getAllFields(fl); for (unsigned int j=0; j < nrf; j++) { SoField * f = fl[j]; SoType ftype = f->getTypeId(); SbName fname; f->getContainer()->getFieldName(f, fname); (void)fprintf(stdout, " %s (%s)\n", fname.getString(), ftype.getName().getString()); if (ftype.isDerivedFrom(SoSFEnum::getClassTypeId())) { list_enums((SoSFEnum *)f); } else if (ftype.isDerivedFrom(SoMFEnum::getClassTypeId())) { list_enums((SoMFEnum *)f); } } } return 0; }
/*! Upgrade \a base, usually created using SoUpgrader::tryCreateNode(), to the latest version of the same node. */ SoBase * SoUpgrader::createUpgrade(const SoBase * base) { soupgrader_init_classes(); SoType type = base->getTypeId(); if (type == SoPackedColorV20::getClassTypeId()) { SoPackedColorV20 * pp = (SoPackedColorV20*) base; return (SoBase*) pp->createUpgrade(); } else if (type == SoShapeHintsV10::getClassTypeId()) { SoShapeHintsV10 * pp = (SoShapeHintsV10*) base; return (SoBase*) pp->createUpgrade(); } else { SoDebugError::post("SoUpgrader::createUpgrade", "No upgrade functionality available for %s", type.getName().getString()); } return NULL; }
void SoGate::setup(SoType inputType) // //////////////////////////////////////////////////////////////////////// { #ifdef DEBUG if (input != NULL) { SoDebugError::post("SoGate::setup", "Already initialized!"); } #endif if (inputType.isDerivedFrom(SoMField::getClassTypeId())) { input = (SoMField *)inputType.createInstance(); } else { input = NULL; } if (input == NULL) { #ifdef DEBUG SoDebugError::post("SoGate::setup", "Couldn't create field of type %s", inputType.getName().getString()); #endif conversionCase = BAD_TYPE; } else { input->setContainer(this); // Pass in the static field data as the parent field data for // the per-instance field data: myInputData->addField(this, "input", input); // Construct the output: output = new SoEngineOutput; output->setContainer(this); myOutputData->addOutput(this, "output", output, inputType); // This handy macro sets up conversionCase, which is used to quickly // decide what type we're hooked up to at evaluate() time: #define DECIDE(class) \ (inputType == SO__CONCAT(SoMF,class)::getClassTypeId()) { \ conversionCase = class; \ } // Set up for which switch to use in evaluate() routine: if DECIDE(BitMask) else if DECIDE(Bool) else if DECIDE(Color) else if DECIDE(Enum) else if DECIDE(Float) else if DECIDE(Int32) else if DECIDE(Matrix) else if DECIDE(Name) else if DECIDE(Node) else if DECIDE(Path) else if DECIDE(Plane) else if DECIDE(Rotation) else if DECIDE(Short) else if DECIDE(String) else if DECIDE(Time) else if DECIDE(UInt32) else if DECIDE(UShort) else if DECIDE(Vec2f) else if DECIDE(Vec3f) else if DECIDE(Vec4f) #undef DECIDE else { #ifdef DEBUG SoDebugError::post("SoGate::setup", "Can't gate field of type %s", inputType.getName().getString()); #endif conversionCase = BAD_TYPE; } } }
void SoCatch::postExceptionMessage(SoType ERR_OBJ_TYPE_ID, const char *OP_DESCR_STR, SoType ACTION_TYPE_ID, const char *END_STR) { SbString objName = "<unknown object>"; try { if(ERR_OBJ_TYPE_ID != SoType::badType()) { objName = ERR_OBJ_TYPE_ID.getName().getString(); } } catch(...) { objName="<error getting objTypeName>"; } SbString opString = ""; try { if(OP_DESCR_STR) { opString = OP_DESCR_STR; } } catch(...) { opString = "<error getting description>"; } SbString actionName = ""; try { if(ACTION_TYPE_ID != SoType::badType()) { actionName = ACTION_TYPE_ID.getName().getString(); } } catch(...) { actionName="<error getting action type name>"; } SbString endString = ""; try { if(END_STR) { endString = END_STR; } } catch(...) { endString = "<error getting endStr name>"; } SbString traceInfos =""; try { traceInfos = SoGlobalTraceBuffer.getTraceDumpString(); } catch(...) { traceInfos="<error getting traceInfos name>"; } try { SoError::post("Crash in %s while %s %s %s %s", objName .getString(), opString .getString(), actionName.getString(), endString .getString(), traceInfos.getString()); } catch(...) { SoError::post("<Could not create error message after catching error>"); } }