/*! Set the Coin event manager for the widget. */ void QuarterWidget::setSoEventManager(SoEventManager * manager) { bool carrydata = false; SoNode * scene = NULL; SoCamera * camera = NULL; SbViewportRegion vp; if (PRIVATE(this)->soeventmanager && (manager != NULL)) { scene = PRIVATE(this)->soeventmanager->getSceneGraph(); camera = PRIVATE(this)->soeventmanager->getCamera(); vp = PRIVATE(this)->soeventmanager->getViewportRegion(); carrydata = true; } // ref before deleting the old scene manager to avoid that the nodes are deleted if (scene) scene->ref(); if (camera) camera->ref(); if (PRIVATE(this)->initialsoeventmanager) { delete PRIVATE(this)->soeventmanager; PRIVATE(this)->initialsoeventmanager = false; } PRIVATE(this)->soeventmanager = manager; if (carrydata) { PRIVATE(this)->soeventmanager->setSceneGraph(scene); PRIVATE(this)->soeventmanager->setCamera(camera); PRIVATE(this)->soeventmanager->setViewportRegion(vp); } if (scene) scene->unref(); if (camera) camera->unref(); }
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; } } }
SoNode *ReadString(char* string) { SoNode *node; SoInput in; in.setBuffer(string, strlen(string)); node = SoDB::readAll(&in); node->ref(); return node; }
Py::Object ViewProviderPy::getRootNode(void) const { try { SoNode* node = getViewProviderPtr()->getRoot(); PyObject* Ptr = Base::Interpreter().createSWIGPointerObj("pivy.coin","SoSeparator *", node, 1); node->ref(); return Py::Object(Ptr, true); } catch (const Base::Exception& e) { throw Py::Exception(e.what()); } }
void SoXipImageOverlayManager::addOverlays() { const SoNode** nodes = overlays.getValues(0); for( int i = 0; i < overlays.getNum(); ++ i ) { const SoXipShapeList* shapeList = (const SoXipShapeList *) nodes[i]; if( !shapeList->isOfType( SoXipShapeList::getClassTypeId() ) ) { SoDebugError::post( __FILE__, "Child not supported" ); return ; } int sliceIndex; if( sscanf( shapeList->label.getValue().getString(), "%d", &sliceIndex ) != 1 ) { SoDebugError::post( __FILE__, "Invalid label found '%s'", shapeList->label.getValue().getString() ); return ; } SoXipShapeList* sliceShapeList = mSliceMap[ sliceIndex ]; if( !sliceShapeList ) { sliceShapeList = new SoXipShapeList; sliceShapeList->label.setValue( SbString( sliceIndex ) ); mShapeSwitch->addChild( sliceShapeList ); mSliceMap[ sliceIndex ] = sliceShapeList; } int numShapes = shapeList->getNumChildren(); for( int i = 0; i < numShapes; ++ i ) { // Copy to string to force removing of the connections SoNode* copyNode = shapeList->getChild (i)->copy(); copyNode->ref(); SbString str = XipOverlayUtils::saveNodeToString( copyNode ); copyNode->unref(); // Reload copy node from this string SoNode* readNode = XipOverlayUtils::loadNodeFromString( str.getString(), str.getLength() ); ((SoXipShape *) readNode)->updateGeometries(); sliceShapeList->addChild( readNode ); } } }
Py::Object View3DInventorViewerPy::getSceneGraph(const Py::Tuple& args) { if (!PyArg_ParseTuple(args.ptr(), "")) throw Py::Exception(); try { SoNode* scene = _viewer->getSceneGraph(); PyObject* proxy = 0; proxy = Base::Interpreter().createSWIGPointerObj("pivy.coin", "SoSeparator *", (void*)scene, 1); scene->ref(); return Py::Object(proxy, true); } catch (const Base::Exception& e) { throw Py::Exception(e.what()); } }
/*! * Applies a change to the scene. After redo() parentIndex contains a new child. * \sa undo(). */ void CmdPaste::redo( ) { SoBaseKit* coinParent = static_cast< SoBaseKit* > ( m_parentInstance-> GetNode() ); if( !m_sceneModel->Paste( m_pasteType, *coinParent, *m_coinChild, m_row ) ) return; SoNode* newNode = m_parentInstance->children[m_row]->GetNode(); newNode->ref(); int count = 0; QString newName = m_oldNodeName; while ( !m_sceneModel->SetNodeName( newNode, newName ) ) { count++; newName = QString( "%1_copy%2").arg( m_oldNodeName, QString::number( count) ); } }
void SoXtMaterialList::selectionCallback(// private int materialid) { materialid--; // get index SoXtMaterialDirectory * data = common->getMaterialDirectory(); assert(materialid >= 0 && materialid < data->groups[data->current]->numMaterials); const char * materialdata = data->groups[data->current]->materials[materialid]->data; SoInput reader; if (data->flags & SOXT_BUILTIN_MATERIALS) { reader.setBuffer((void *) materialdata, strlen(materialdata)); } else { if (! reader.openFile(materialdata, FALSE)) { SoDebugError::postWarning("SoXtMaterialList::selectionCallback", "could not open file: \"%s\"", materialdata); return; } } SoNode * material = NULL; if (! SoDB::read(&reader, material)) { SoDebugError::postWarning("SoXtMaterialList::selectionCallback", "failed to read material"); return; } if (! material) { SoDebugError::postWarning("SoXtMaterialList::selectionCallback", "read returned no data"); return; } material->ref(); if (! material->isOfType(SoMaterial::getClassTypeId())) { SoDebugError::postWarning("SoXtMaterialList::selectionCallback", "not a material node!"); material->unref(); return; } common->invokeCallbacks((SoMaterial *) material); material->unref(); } // selectionCallback()
/*! Make a duplicate of this node and return a pointer to the duplicate. If this node is a group node, children are also copied and we return a pointer to the root of a full copy of the subgraph rooted here. If \a copyconnections is \c TRUE, we also copy the connections to fields within this node (and ditto for any children and children's children etc). Note that this function has been made virtual in Coin, which is not the case in the original Open Inventor API. We may change this method back into being non-virtual again for major Coin versions after this, as it was made virtual more or less by mistake. So please don't write application code that depends on SoNode::copy() being virtual. The reason this method should not be virtual is because this is \e not the function the application programmer should override in extension nodes if she needs some special behavior during a copy operation (like copying the value of internal data not exposed as fields). For that purpose, override the copyContents() method. Your overridden copyContents() method should then \e both copy internal data aswell as calling the parent superclass' copyContents() method for automatically handling of fields and other common data. */ SoNode * SoNode::copy(SbBool copyconnections) const { // FIXME: "de-virtualize" this method for next major Coin release? // See method documentation above. 20011220 mortene. SoFieldContainer::initCopyDict(); SoNode * cp = this->addToCopyDict(); // ref() to make sure the copy is not destructed while copying cp->ref(); // Call findCopy() to have copyContents() run only once. #if COIN_DEBUG SoNode * cp2 = (SoNode *)SoFieldContainer::findCopy(this, copyconnections); assert(cp == cp2); #else // COIN_DEBUG (void) SoFieldContainer::findCopy(this, copyconnections); #endif SoFieldContainer::copyDone(); // unrefNoDelete() so that we return a copy with reference count 0 cp->unrefNoDelete(); return cp; }
osgDB::ReaderWriter::WriteResult ReaderWriterIV::writeNode(const osg::Node& node, const std::string& fileName, const osgDB::ReaderWriter::Options* /*options*/) const { // accept extension std::string ext = osgDB::getLowerCaseFileExtension(fileName); if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED; bool useVRML1 = !isInventorExtension(osgDB::getFileExtension(fileName)); OSG_NOTICE << "osgDB::ReaderWriterIV::writeNode() Writing file " << fileName.data() << std::endl; // Convert OSG graph to Inventor graph ConvertToInventor osg2iv; osg2iv.setVRML1Conversion(useVRML1); (const_cast<osg::Node*>(&node))->accept(osg2iv); SoNode *ivRoot = osg2iv.getIvSceneGraph(); if (ivRoot == NULL) return WriteResult::ERROR_IN_WRITING_FILE; ivRoot->ref(); // Change prefix according to VRML spec: // Node names must not begin with a digit, and must not contain spaces or // control characters, single or double quote characters, backslashes, curly braces, // the sharp (#) character, the plus (+) character or the period character. if (useVRML1) SoBase::setInstancePrefix("_"); // Write Inventor graph to file SoOutput out; out.setHeaderString((useVRML1) ? "#VRML V1.0 ascii" : "#Inventor V2.1 ascii"); if (!out.openFile(fileName.c_str())) return WriteResult::ERROR_IN_WRITING_FILE; SoWriteAction wa(&out); wa.apply(ivRoot); ivRoot->unref(); return WriteResult::FILE_SAVED; }
void SoDebug::writeField(SoField *field) // //////////////////////////////////////////////////////////////////////// { SoFieldContainer *fc = field->getContainer(); SbName fieldName; fc->getFieldName(field, fieldName); printf("Field name is: %s\n", fieldName.getString()); if (fc->isOfType(SoNode::getClassTypeId())) { printf("Field is part of node:\n"); SoNode *node = (SoNode *)fc; node->ref(); SoWriteAction wa; wa.apply(node); node->unrefNoDelete(); } }
SoNode * SoUnknownNode::addToCopyDict() const // //////////////////////////////////////////////////////////////////////// { // If this node is already in the dictionary, nothing else to do SoNode *copy = (SoNode *) checkCopy(this); if (copy == NULL) { // Create and add a new instance to the dictionary copy = new SoUnknownNode; copy->ref(); addCopy(this, copy); // Adds a ref() copy->unrefNoDelete(); // Recurse on children, if any for (int i = 0; i < hiddenChildren.getLength(); i++) hiddenChildren[i]->addToCopyDict(); } return copy; }
void SoUnknownNode::write(SoWriteAction *action) // //////////////////////////////////////////////////////////////////////// { int i; SbBool saveNotify = enableNotify(FALSE); // Remember alternateRep, if set: SoNode *alternateRep = NULL; if (hasChildren) { if (getNumChildren() != 0) { alternateRep = getChild(0); alternateRep->ref(); } // Add hiddenChildren to regular child list temporarily: removeAllChildren(); for (i = 0; i < hiddenChildren.getLength(); i++) { addChild(hiddenChildren[i]); } // Now write: SoGroup::write(action); removeAllChildren(); } else { SoNode::write(action); } if (alternateRep != NULL) { addChild(alternateRep); alternateRep->unref(); } enableNotify(saveNotify); }
int main(int argc, char ** argv) { fprintf(stderr, "ivcp v0.1\n"); SoDB::init(); SoNodeKit::init(); SoInteraction::init(); if (argc != 3 ) { fprintf(stdout, "Usage: %s infile outfile\n", argv[0]); return 0; } SoInput * in = new SoInput; if (!in->openFile(argv[1])) { fprintf(stderr, "error: could not open file '%s'\n", argv[1]); delete in; SoDB::cleanup(); return -1; } SoNode * scene = SoDB::readAll(in); if (!scene) { fprintf(stderr, "error: could not read file '%s'\n", argv[1]); delete in; SoDB::cleanup(); return -1; } FileType inputFileType; if (in->isFileVRML1()) inputFileType = VRML1; else if (in->isFileVRML2()) inputFileType = VRML2; else inputFileType = INVENTOR; delete in; scene->ref(); SoNode * firstChild = static_cast<SoSeparator*>(scene)->getNumChildren()? static_cast<SoSeparator*>(scene)->getChild(0) :NULL; if (firstChild && firstChild->isOfType(SoForeignFileKit::getClassTypeId())) { SoForeignFileKit * kit = (SoForeignFileKit *) firstChild; if (kit->canWriteScene() ) { SoNode * subscene = NULL; kit->writeScene(subscene); if (!subscene ) { return -1; } subscene->ref(); scene->unref(); scene = subscene; } } SoOutput * out = new SoOutput; if (!out->openFile(argv[2])) { fprintf(stderr, "error: could not open file '%s' for writing\n"); scene->unref(); delete out; SoDB::cleanup(); return -1; } switch (inputFileType) { case VRML1: out->setHeaderString("#VRML V1.0 ascii"); break; case VRML2: out->setHeaderString("#VRML V2.0 utf8"); } SoWriteAction wa(out); wa.apply(scene); out->closeFile(); delete out; scene->unref(); // with actions on the stack, cleanup can't be called... // SoDB::cleanup(); return 0; }