QWidget* ParametersDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem& option, const QModelIndex &index) const { const ParametersModel* model = static_cast< const ParametersModel* >( index.model() ); SoField* field = model->ModelItem( index )->GetField(); if( field->getTypeId().isDerivedFrom( SoSFEnum::getClassTypeId() ) ) { QComboBox* editor = new QComboBox( parent ); SoSFEnum* enumField = static_cast< SoSFEnum* >( field ); for( int i = 0; i < enumField->getNumEnums() ; ++i ) { SbName enumName; enumField->getEnum( i , enumName ); editor->addItem( enumName.getString() ); } return editor; } else if( field->getTypeId().isDerivedFrom( SoMField::getClassTypeId() ) ) { ContainerEditor* editor = new ContainerEditor( parent ); editor->setGeometry(option.rect); connect( editor, SIGNAL( editingFinished( ) ), this, SLOT( CloseEditor() )); return editor; } else { QLineEdit* editor = new QLineEdit(parent); return editor; } }
void ParametersDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { const ParametersModel* model = static_cast< const ParametersModel* >( index.model() ); SoField* field = model->ModelItem( index )->GetField(); if( field->getTypeId().isDerivedFrom( SoSFEnum::getClassTypeId() ) ) { SoSFEnum* enumField = static_cast< SoSFEnum* >( field ); int selectedIndex = enumField->getValue(); QComboBox* combo = static_cast<QComboBox *>(editor); combo->setCurrentIndex( selectedIndex ); } else if( field->getTypeId().isDerivedFrom( SoMField::getClassTypeId() ) ) { QString value = index.model()->data(index, Qt::DisplayRole).toString(); ContainerEditor* containerEdit = static_cast< ContainerEditor *>(editor); containerEdit->SetData( value ); } else { QString value = index.model()->data(index, Qt::DisplayRole).toString(); QLineEdit *textEdit = static_cast<QLineEdit *>(editor); textEdit->setText(value); } }
SoMField * QCtkXipSGWidget::getMField(const char * fieldContainerName, const char * fieldName) { SoField * field = getSoField(fieldContainerName, fieldName); if(field->isOfType(SoMField::getClassTypeId())) return (SoMField *) field; return 0; }
void SoBuiltinFieldConverter::evaluate() // //////////////////////////////////////////////////////////////////////// { // For efficiency and to reduce bloat, we don't use the standard // SO_ENGINE_OUTPUT macro: #ifdef DEBUG if (input == NULL) { SoDebugError::post("(internal) SoBuiltinFieldConverter::evaluate", "NULL input field"); return; } #endif // We know that our engineOutput cannot be disabled, since nobody // but us has access to it. If we are connected from an // engineOutput and that engineOutput is disabled, we still want // to convert that value - this will happen the first time this // engine is evaluated after the output is disabled. After the // first time, notification will be blocked, so we don't have to // check for a disabled output here. for (int i = 0; i < output->getNumConnections(); i++) { SoField *outField = (*output)[i]; if (!outField->isReadOnly()) doConversion(outField); } }
void SoVRMLShape::notify(SoNotList * list) { SoField * f = list->getLastField(); if (f && f->getTypeId() == SoSFNode::getClassTypeId()) { PRIVATE(this)->childlistvalid = FALSE; } inherited::notify(list); }
bool SoXipImage::setField(SoNode * node, SbName field, const char * value) { if (node) { SoField * fp = node->getField(field); if (fp) return fp->set( value ) == TRUE; } return false; }
bool SoXipImage::connectFields(SoNode * fromNode, SbName fromField, SoNode * toNode, SbName toField) { if (fromNode && toNode) { SoField * fromF = fromNode->getField(fromField); SoField * toF = toNode->getField(toField); if (fromF && toF) return toF->connectFrom( fromF ) == TRUE; } return false; }
void SoFCCSysDragger::finishDragCB(void *data, SoDragger *) { SoFCCSysDragger *sudoThis = reinterpret_cast<SoFCCSysDragger *>(data); // note: when creating a second view of the document and then closing // the first viewer it deletes the camera. However, the attached field // of the cameraSensor will be detached automatically. SoField* field = sudoThis->cameraSensor.getAttachedField(); if (field) { SoCamera* camera = static_cast<SoCamera*>(field->getContainer()); if (camera->getTypeId() == SoPerspectiveCamera::getClassTypeId()) cameraCB(sudoThis, nullptr); } }
bool SoXipImage::connectField(SoNode * fromNode, SbName fromField, SoField * toField, bool invert) { if (fromNode && toField) { SoField * fromF = fromNode->getField(fromField); if (fromF) { if (invert) return fromF->connectFrom( toField ) == TRUE; else return toField->connectFrom( fromF ) == TRUE; } } return false; }
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; }
void SoFCCSysDragger::idleCB(void *data, SoSensor *) { SoFCCSysDragger *sudoThis = reinterpret_cast<SoFCCSysDragger *>(data); SoField* field = sudoThis->cameraSensor.getAttachedField(); if (field) { SoCamera* camera = static_cast<SoCamera*>(field->getContainer()); SbMatrix localToWorld = sudoThis->getLocalToWorldMatrix(); SbVec3f origin; localToWorld.multVecMatrix(SbVec3f(0.0, 0.0, 0.0), origin); SbViewVolume viewVolume = camera->getViewVolume(); float radius = sudoThis->draggerSize.getValue() / 2.0; float localScale = viewVolume.getWorldToScreenScale(origin, radius); SbVec3f scaleVector(localScale, localScale, localScale); SoScale *localScaleNode = SO_GET_ANY_PART(sudoThis, "scaleNode", SoScale); localScaleNode->scaleFactor.setValue(scaleVector); sudoThis->autoScaleResult.setValue(localScale); } }
void SoUnknownNode::copyContents(const SoFieldContainer *fromFC, SbBool copyConnections) // //////////////////////////////////////////////////////////////////////// { // Make sure the copy has the correct class name const SoUnknownNode *fromUnk = (const SoUnknownNode *) fromFC; setClassName(fromUnk->className); // For each field in the original node, create a new field and add // it to the new node // NOTE: We can't use SoNode::copyContents() to copy the field // data, since that uses SoFieldData::overlay(), which assumes the // fields have the same offsets in both nodes. Instead, we just // copy the field values ourselves. const SoFieldData *fromData = fromUnk->getFieldData(); SoFieldData *toData = (SoFieldData *) getFieldData(); int i; for (i = 0; i < fromData->getNumFields(); i++) { SoField *fromField = fromData->getField(fromUnk, i); const SbName fieldName = fromData->getFieldName(i); SoType fieldType = fromField->getTypeId(); SoField *toField = (SoField *) (fieldType.createInstance()); toField->enableNotify(FALSE); toField->setContainer(this); toField->setDefault(TRUE); toField->enableNotify(TRUE); toData->addField(this, fieldName.getString(), toField); toField->setContainer(this); toField->copyFrom(*fromField); toField->setIgnored(fromField->isIgnored()); toField->setDefault(fromField->isDefault()); toField->fixCopy(copyConnections); if (fromField->isConnected() && copyConnections) toField->copyConnection(fromField); } // Copy the kids for (i = 0; i < fromUnk->hiddenChildren.getLength(); i++) { // If this node is being copied, it must be "inside" (see // SoNode::copy() for details.) Therefore, all of its children // must be inside, as well, since our addToCopyDict() takes // care of that. SoNode *fromKid = fromUnk->getChild(i); SoNode *kidCopy = (SoNode *) findCopy(fromKid, copyConnections); #ifdef DEBUG if (kidCopy == NULL) SoDebugError::post("(internal) SoUnknownNode::copyContents", "Child %d has not been copied yet", i); #endif /* DEBUG */ hiddenChildren.append(kidCopy); } // No need to copy the override flag, since this flag will have no // effect on an unknown node, and it is not read from or written // to files. }
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; } } }
SbBool SoUnknownNode::readInstance(SoInput *in, unsigned short flags) // //////////////////////////////////////////////////////////////////////// { int i; // This is mostly the normal SoGroup reading code, but we look for // an alternateRep field after reading and move our public // children onto the hidden children list: hasChildren = (!in->isBinary() || (flags & IS_GROUP)); SbBool result; if (hasChildren) { result = SoGroup::readInstance(in, flags); // If read ASCII AND didn't read any children, set hasChildren // to FALSE: if (!in->isBinary() && getNumChildren() == 0) hasChildren = FALSE; // Add all kids to hiddenChildren, then remove them all from the // regular (SoGroup) list for (i = 0; i < getNumChildren(); i++) { hiddenChildren.append(getChild(i)); } removeAllChildren(); } else { result = SoNode::readInstance(in, flags); } // Check to see if an alternate representation was read and // store a pointer to it if one is found. int num = instanceFieldData->getNumFields(); SbBool haveAlternateRep = FALSE; for (i=0; i<num; i++) { if (instanceFieldData->getFieldName(i) == SbName("alternateRep")) { SoField *f = instanceFieldData->getField(this, i); if (f->isOfType(SoSFNode::getClassTypeId())) { haveAlternateRep = TRUE; SoSFNode *alternateRepField = (SoSFNode *)f; SoNode *n = alternateRepField->getValue(); if (n != NULL) addChild(n); } break; } } // If no alternateRep was specified, look for a field named "isA" // of type MFString and try to automatically create an // alternateRep: if (!haveAlternateRep) for (i=0; i<num; i++) { if (instanceFieldData->getFieldName(i) == SbName("isA")) { SoField *f = instanceFieldData->getField(this, i); if (f->isOfType(SoMFString::getClassTypeId())) { createFromIsA((SoMFString *)f); } } } return result; }
SbBool SoXipSFData::isSame(const SoField &f) const { return (getTypeId() == f.getTypeId() && (*this) == (const SoXipSFData &) f); }
void SoUnknownEngine::copyContents(const SoFieldContainer *fromFC, SbBool copyConnections) // //////////////////////////////////////////////////////////////////////// { // Make sure the copy has the correct class name const SoUnknownEngine *fromUnk = (const SoUnknownEngine *) fromFC; setClassName(fromUnk->className); // For each input in the original engine, create a new input and add // it to the new engine // NOTE: We can't use SoEngine::copyContents() to copy the field // data, since that uses SoFieldData::overlay(), which assumes the // fields have the same offsets in both engines. Instead, we just // copy the field values ourselves. const SoFieldData *fromData = fromUnk->getFieldData(); SoFieldData *toData = (SoFieldData *) getFieldData(); int i; for (i = 0; i < fromData->getNumFields(); i++) { SoField *fromField = fromData->getField(fromUnk, i); const SbName fieldName = fromData->getFieldName(i); SoType fieldType = fromField->getTypeId(); SoField *toField = (SoField *) (fieldType.createInstance()); toField->enableNotify(FALSE); toField->setContainer(this); toField->setDefault(TRUE); toField->enableNotify(TRUE); toData->addField(this, fieldName.getString(), toField); toField->setContainer(this); toField->copyFrom(*fromField); toField->setIgnored(fromField->isIgnored()); toField->setDefault(fromField->isDefault()); toField->fixCopy(copyConnections); if (fromField->isConnected() && copyConnections) toField->copyConnection(fromField); } // Copy the outputs SoEngineOutputData *toOutData = (SoEngineOutputData *) getOutputData(); SoEngineOutputList outList; fromUnk->getOutputs(outList); for(i = 0; i < outList.getLength(); i++) { SoEngineOutput *newOut = new SoEngineOutput; const SoType outType = outList[i]->getConnectionType(); SbName outName; getOutputName( outList[i], outName ); toOutData->addOutput(this, outName.getString(), newOut, outType); newOut->setContainer(this); } }