Int32 OSGLoader::mapExtIntFieldType(const Char8 *szFieldname, const Int32 iFieldTypeId) { Int32 returnValue = Inherited::mapExtIntFieldType(szFieldname, iFieldTypeId); if(returnValue < 0 && szFieldname != NULL && _pCurrentFC != NULL) { FieldDescriptionBase *pFieldDesc = _pCurrentFC->getFieldDescription(szFieldname); if(pFieldDesc != NULL) { const FieldType &oFieldType = pFieldDesc->getFieldType(); PINFO << "FieldTypeId invalid, trying to fix. " << std::endl; PINFO << oFieldType.getContentType().getCName() << " comparing with " << FieldTraits<FieldContainer *>::getType().getCName() << std::endl; if(oFieldType.getContentType().isDerivedFrom( FieldTraits<FieldContainer *>::getType()) == true) { PINFO << "FieldContainer * or derived class, " << "parsing as Node" << std::endl; if(oFieldType.getCardinality() == FieldType::SingleField) { returnValue = ScanParseSkel::OSGsfNode; } else { returnValue = ScanParseSkel::OSGmfNode; } } } } return returnValue; }
UInt32 OSGLoader::getFieldType(const Char8 *szFieldname) { UInt32 returnValue = 0; FieldDescriptionBase *pFieldDesc = NULL; if(szFieldname == NULL) return returnValue; if(_pCurrentFC != NULL) { pFieldDesc = _pCurrentFC->getFieldDescription(szFieldname); PINFO << "GF : " << szFieldname << " " << pFieldDesc << std::endl; if(pFieldDesc != NULL) { returnValue = pFieldDesc->getFieldType().getScanTypeId(); } } return returnValue; }
/*-------------------------------------------------------------------------*\ - private - \*-------------------------------------------------------------------------*/ void GenericFieldContainerEditor::updateFieldsPanel(FieldContainer* fc) { _FieldsContainer->clearChildren(); UInt32 NumFields(fc->getType().getNumFieldDescs()); FieldDescriptionBase* Desc; FieldEditorComponentUnrecPtr TheEditor; LabelUnrecPtr TheLabel; ComponentRecPtr TheToolTip; GridBagLayoutConstraintsRefPtr LayoutConstraints; PanelRefPtr FieldPanel; UInt32 NumRows(0),NumRowsForField(1); BorderLayoutRefPtr TheBorderLayout = BorderLayout::create(); BorderLayoutConstraintsRefPtr WestConstraint = BorderLayoutConstraints::create(); WestConstraint->setRegion(BorderLayoutConstraints::BORDER_WEST); BorderLayoutConstraintsRefPtr CenterConstraint = BorderLayoutConstraints::create(); CenterConstraint->setRegion(BorderLayoutConstraints::BORDER_CENTER); //Backgrounds ColorLayerRefPtr HeaderBgLayer = ColorLayer::create(); HeaderBgLayer->setColor(Color4f(0.7f,0.7f,0.7f,1.0f)); ColorLayerRefPtr LightBgLayer = ColorLayer::create(); LightBgLayer->setColor(Color4f(0.9f,0.9f,0.9f,1.0f)); ColorLayerRefPtr DarkBgLayer = ColorLayer::create(); DarkBgLayer->setColor(Color4f(0.8f,0.8f,0.8f,1.0f)); LayoutConstraints = GridBagLayoutConstraints::create(); LayoutConstraints->setGridX(0); LayoutConstraints->setGridY(NumRows); LayoutConstraints->setGridHeight(1); LayoutConstraints->setGridWidth(2); LayoutConstraints->setFill(GridBagLayoutConstraints::FILL_BOTH); LabelRecPtr FieldsLabel = Label::create(); FieldsLabel->setAlignment(Vec2f(0.5f,0.5f)); FieldsLabel->setText("Fields"); FieldsLabel->setBackgrounds(HeaderBgLayer); FieldsLabel->setConstraints(LayoutConstraints); FieldsLabel->setFont(_BoldFont); _FieldsContainer->pushToChildren(FieldsLabel); ++NumRows; if(_GenericNameAttachmentEditor->isTypeEditable(fc->getType())) { //Create the Label TheLabel = Label::create(); TheLabel->setText("Name"); TheLabel->setBackgrounds(NULL); TheLabel->setConstraints(WestConstraint); TheLabel->setPreferredSize(Vec2f(160.0f,22.0f)); //Attach the Generic Name Editor _GenericNameAttachmentEditor->setCommandManager(_CmdManager); _GenericNameAttachmentEditor->attachContainer(fc); _GenericNameAttachmentEditor->setConstraints(CenterConstraint); //Create the Panel LayoutConstraints = GridBagLayoutConstraints::create(); LayoutConstraints->setGridX(0); LayoutConstraints->setGridY(NumRows); LayoutConstraints->setGridHeight(1); LayoutConstraints->setGridWidth(1); LayoutConstraints->setFill(GridBagLayoutConstraints::FILL_BOTH); FieldPanel = Panel::createEmpty(); FieldPanel->setInset(Vec4f(1.0f,1.0f,1.0f,1.0f)); FieldPanel->pushToChildren(TheLabel); FieldPanel->pushToChildren(_GenericNameAttachmentEditor); FieldPanel->setLayout(TheBorderLayout); FieldPanel->setConstraints(LayoutConstraints); FieldPanel->setBackgrounds(LightBgLayer); _FieldsContainer->pushToChildren(FieldPanel); ++NumRows; } UInt32 UsedFieldCount(0); for(UInt32 i(1) ; i<=NumFields ; ++i) { Desc = fc->getFieldDescription(i); if(Desc != NULL && !Desc->isInternal() && Desc->getFieldType().getClass() != FieldType::ParentPtrField && //HACK: Stop the pixel field from being editable on Images !(fc->getType().isDerivedFrom(Image::getClassType()) && Desc->getFieldId() == Image::PixelFieldId)) { //Create the Editor TheEditor = FieldEditorFactory::the()->createDefaultEditor(fc, Desc->getFieldId(), _CmdManager); if(TheEditor != NULL) { NumRowsForField = TheEditor->getNumRequestedRows(); pushToEditors(TheEditor); TheEditor->setConstraints(CenterConstraint); //Create the Label TheLabel = Label::create(); TheLabel->setText(Desc->getCName()); TheLabel->setBackgrounds(NULL); TheLabel->setConstraints(WestConstraint); TheLabel->setPreferredSize(Vec2f(160.0f,22.0f)); TheToolTip = createFieldToolTip(Desc); TheLabel->setToolTip(TheToolTip); //Create the Panel LayoutConstraints = GridBagLayoutConstraints::create(); LayoutConstraints->setGridX(0); LayoutConstraints->setGridY(NumRows); LayoutConstraints->setGridHeight(NumRowsForField); LayoutConstraints->setGridWidth(1); LayoutConstraints->setFill(GridBagLayoutConstraints::FILL_BOTH); FieldPanel = Panel::createEmpty(); FieldPanel->setInset(Vec4f(1.0f,1.0f,1.0f,1.0f)); FieldPanel->pushToChildren(TheLabel); FieldPanel->pushToChildren(TheEditor); FieldPanel->setLayout(TheBorderLayout); FieldPanel->setConstraints(LayoutConstraints); if((UsedFieldCount%2) == 0) { FieldPanel->setBackgrounds(DarkBgLayer); } else { FieldPanel->setBackgrounds(LightBgLayer); } _FieldsContainer->pushToChildren(FieldPanel); NumRows += NumRowsForField; TheEditor->setPreferredSize(Vec2f(50.0f,22.0f * NumRowsForField)); ++UsedFieldCount; } } } //Set the number of rows for the grid layout dynamic_cast<GridBagLayout*>(_FieldsContainer->getLayout())->setRows(NumRows); _FieldsContainer->setPreferredSize(Vec2f(400.0f, NumRows*24.0f)); }
/*! Reads the contents of a field from the stream. It is intended to be used in conjunction with readFieldHeader and uses the information obtained by it (\a fieldName, \a fieldTypeName, \a fieldSize ). If a field is not to be read, but skipped instead, its name can be passed in the \a excludeFields argument. The string has the format: "'name1' 'name2' 'name3'", the spaces between the "'" are mandatory. \param[in] fieldName Name of the field. \param[in] fieldTypeName Type of the field. \param[in] fieldSize Size in bytes of the field. \param[in] excludeFields \param[out] ptrFieldIt Iterator that points to the PtrFieldInfo structure that was created, if this is a "pointer field" - only valid if true is returned. \return True, if the field is a "pointer field", i.e. a field holding pointers to other FieldContainers, false otherwise. */ bool OSBCommonElement::readFieldContent( const std::string &fieldName, const std::string &fieldTypeName, const UInt32 fieldSize, const std::string &excludeFields, PtrFieldListIt &ptrFieldIt ) { OSG_OSB_LOG(("OSBCommonElement::readFieldContent: [%s] [%s] [%u]\n", fieldName.c_str(), fieldTypeName.c_str(), fieldSize)); BinaryReadHandler *rh = editRoot()->getReadHandler(); bool isPtrField = false; FieldDescriptionBase *fieldDesc = getContainer()->getFieldDescription(fieldName.c_str()); if((!excludeFields.empty() ) && (excludeFields.find("'" + fieldName + "'") != std::string::npos) ) { OSG_OSB_LOG(("OSBCommonElement::readFieldContent: " "Skipping excluded field [%s] [%s]\n", fieldName.c_str(), fieldTypeName.c_str())); rh->skip(fieldSize); return false; } if(fieldDesc == 0) { DynFieldContainerInterface *pIf = dynamic_cast<DynFieldContainerInterface *>(getContainer()); if(pIf != NULL) { pIf->addField(fieldTypeName.c_str(), fieldName.c_str()); fieldDesc = getContainer()->getFieldDescription(fieldName.c_str()); } } if(fieldDesc == 0) { FWARNING(("OSBCommonElement::readFieldContent: " "Skipping unknown field [%s] [%s].\n", fieldName.c_str(), fieldTypeName.c_str())); rh->skip(fieldSize); return false; } const FieldType &fieldType = fieldDesc->getFieldType(); UInt32 fieldId = fieldDesc->getFieldId (); BitVector fieldMask = fieldDesc->getFieldMask(); if(fieldType.getContentType().isDerivedFrom( FieldTraits<FieldContainer *>::getMapType()) == true) { ptrFieldIt = readAttachmentMapField(fieldId, fieldSize); isPtrField = true; } else if(fieldType.getContentType().isDerivedFrom( FieldTraits<FieldContainer *>::getType()) == true) { if(fieldType.getClass() == FieldType::ParentPtrField) { rh->skip(fieldSize); isPtrField = false; } else { if(fieldType.getCardinality() == FieldType::SingleField) { ptrFieldIt = readPtrSingleField(fieldId); isPtrField = true; } else if(fieldType.getCardinality() == FieldType::MultiField) { ptrFieldIt = readPtrMultiField(fieldId, fieldSize); isPtrField = true; } } } else { getContainer()->copyFromBin(*rh, fieldMask); isPtrField = false; } return isPtrField; }
/*\return true if no Python error was set, false otherwise */ bool PyFieldAccessHandler::generateCorePythonCode(const std::string& fieldName, bool& getAccess, bool& editAccess, bool& setAccess) { FieldDescriptionBase *desc = _pPythonScript->getType().getFieldDesc(fieldName.c_str()); FieldType::Class classType = desc->getFieldType().getClass(); std::string fieldTypeName(desc->getFieldType().getName()); std::string valueTypeName(fieldTypeName); removeFieldQualifier (valueTypeName); removeRefCountQualifier(valueTypeName); std::string setAccessMethod ("unsupported"); std::string editAccessMethod("unsupported"); std::string getAccessMethod ("unsupported"); switch(classType) { case FieldType::ValueField: { if(desc->isSField()) { setAccessMethod = "setValueSField_" + valueTypeName; getAccessMethod = "getValueSField_" + valueTypeName; // The following types cannot be changed using the // editAccessMethod, as Python does not provide access via a // reference for them. They have to be set with the // setAccessMethod. if(valueTypeName != "Bool" && valueTypeName != "Int32" && valueTypeName != "Int64" && valueTypeName != "UInt32" && valueTypeName != "UInt64" && valueTypeName != "Real32" && valueTypeName != "Real64" && valueTypeName != "Time" && valueTypeName != "String" ) { editAccessMethod = "changeValueSField_" + valueTypeName; } #ifdef OSGPY_DEBUG_CODEGENERATION std::cout << " VALUE single-field" << std::endl; #endif } else { setAccessMethod = "setValueMField_" + valueTypeName; editAccessMethod = "changeValueMField_" + valueTypeName; getAccessMethod = "getValueMField_" + valueTypeName; #ifdef OSGPY_DEBUG_CODEGENERATION std::cout << " VALUE multi-field" << std::endl; #endif } } break; case FieldType::PtrField: { if(desc->isSField()) { setAccessMethod = "setPtrSField"; editAccessMethod = "changePtrSField"; getAccessMethod = "getPtrSField"; #ifdef OSGPY_DEBUG_CODEGENERATION std::cout << " pointer single-field" << std::endl; #endif } else { setAccessMethod = "unsupported"; editAccessMethod = "changePointerMField"; getAccessMethod = "getPointerMField"; #ifdef OSGPY_DEBUG_CODEGENERATION std::cout << " pointer multi-field" << std::endl; #endif } } break; default: { std::string tmp("unknown"); if(classType == FieldType::ChildPtrField) { tmp = "ChildPtrField"; } else if (classType == FieldType::ParentPtrField) { tmp = "ParentPtrField"; } if(desc->isSField()) { std::cerr << " UNSUPPORTED single-field type: " << tmp << std::endl; } else { std::cerr << " UNSUPPORTED multi-field type: " << tmp << std::endl; } assert(false); } } std::string pyCode; if(setAccessMethod != "unsupported") { setAccess = true; const std::string setMethod = "def _set_" + fieldName + "(self, value):\n" " _fieldAccessHandler." + setAccessMethod + "('" + fieldName + "', value)\n"; pyCode += setMethod; #ifdef OSGPY_DEBUG_CODEGENERATION std::cout << " 'set' support: yes" << std::endl; #endif } #ifdef OSGPY_DEBUG_CODEGENERATION else { std::cout << " 'set' support: no" << std::endl; } #endif if(editAccessMethod != "unsupported") { editAccess = true; const std::string editMethod = "def _edit_" + fieldName + "(self):\n" " return _fieldAccessHandler." + editAccessMethod + "('" + fieldName + "')\n"; pyCode += editMethod; #ifdef OSGPY_DEBUG_CODEGENERATION std::cout << " 'edit' support: yes" << std::endl; #endif } #ifdef OSGPY_DEBUG_CODEGENERATION else { std::cout << " 'edit' support: no" << std::endl; } #endif if(getAccessMethod != "unsupported") { getAccess = true; const std::string getMethod = "def _get_" + fieldName + "(self):\n" " return _fieldAccessHandler." + getAccessMethod + "('" + fieldName + "')\n"; pyCode += getMethod; #ifdef OSGPY_DEBUG_CODEGENERATION std::cout << " 'get' support: yes" << std::endl; #endif } #ifdef OSGPY_DEBUG_CODEGENERATION else { std::cout << " 'get' support: no" << std::endl; } std::cout << std::endl << "Generated Python glue code:" << std::endl; std::cout << pyCode << std::endl; #endif return(_pPyInterpreter->run(pyCode)); }