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(); } }
/*! 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; }
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; }