1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
|
/**************************************************************************\
*
* This file is part of the Coin 3D visualization library.
* Copyright (C) by Kongsberg Oil & Gas Technologies.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* ("GPL") version 2 as published by the Free Software Foundation.
* See the file LICENSE.GPL at the root directory of this source
* distribution for additional information about the GNU GPL.
*
* For using Coin with software that can not be combined with the GNU
* GPL, and for taking advantage of the additional benefits of our
* support services, please contact Kongsberg Oil & Gas Technologies
* about acquiring a Coin Professional Edition License.
*
* See http://www.coin3d.org/ for more information.
*
* Kongsberg Oil & Gas Technologies, Bygdoy Alle 5, 0257 Oslo, NORWAY.
* http://www.sim.no/ sales@sim.no coin-support@coin3d.org
*
\**************************************************************************/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif // HAVE_CONFIG_H
#ifdef HAVE_VRML97
/*!
\class SoVRMLGeometry SoVRMLGeometry.h Inventor/VRMLnodes/SoVRMLGeometry.h
\brief The SoVRMLGeometry class is a superclass for VRML shapes.
*/
#include <Inventor/VRMLnodes/SoVRMLGeometry.h>
#include <Inventor/VRMLnodes/SoVRMLParent.h>
#include <Inventor/VRMLnodes/SoVRMLMacros.h>
#include <Inventor/elements/SoGLShapeHintsElement.h>
#include <Inventor/elements/SoOverrideElement.h>
#include <Inventor/fields/SoSFNode.h>
#include <Inventor/misc/SoChildList.h>
#include <Inventor/actions/SoSearchAction.h>
#ifdef HAVE_THREADS
#include <Inventor/threads/SbMutex.h>
#endif // HAVE_THREADS
#include "nodes/SoSubNodeP.h"
// *************************************************************************
class SoVRMLGeometryP {
public:
SoChildList * childlist;
SbBool childlistvalid;
#ifdef COIN_THREADSAFE
SbMutex childlistmutex;
void lockChildList(void) { this->childlistmutex.lock(); }
void unlockChildList(void) { this->childlistmutex.unlock(); }
#else // !COIN_THREADSAFE
void lockChildList(void) { }
void unlockChildList(void) { }
#endif // !COIN_THREADSAFE
};
#define PRIVATE(thisp) ((thisp)->pimpl)
// *************************************************************************
SO_NODE_ABSTRACT_SOURCE(SoVRMLGeometry);
// *************************************************************************
// Doc in parent
void
SoVRMLGeometry::initClass(void)
{
SO_NODE_INTERNAL_INIT_ABSTRACT_CLASS(SoVRMLGeometry, SO_VRML97_NODE_TYPE);
}
/*!
Constructor.
*/
SoVRMLGeometry::SoVRMLGeometry(void)
{
PRIVATE(this) = new SoVRMLGeometryP;
// supply a NULL-pointer as parent, since notifications will be
// handled by the fields that actually contain the node(s)
PRIVATE(this)->childlist = new SoChildList(NULL);
PRIVATE(this)->childlistvalid = FALSE;
SO_VRMLNODE_INTERNAL_CONSTRUCTOR(SoVRMLGeometry);
}
/*!
Destructor.
*/
SoVRMLGeometry::~SoVRMLGeometry()
{
delete PRIVATE(this)->childlist;
delete PRIVATE(this);
}
// Doc in parent
SbBool
SoVRMLGeometry::shouldGLRender(SoGLRenderAction * action)
{
return inherited::shouldGLRender(action);
}
/*!
Convenience method that updates the shape hints element.
*/
void
SoVRMLGeometry::setupShapeHints(SoState * state, const SbBool ccw, const SbBool solid)
{
if (!(SoOverrideElement::getFlags(state) & SoOverrideElement::SHAPE_HINTS)) {
SoShapeHintsElement::set(state, this,
ccw ? SoShapeHintsElement::COUNTERCLOCKWISE : SoShapeHintsElement::CLOCKWISE,
solid ? SoShapeHintsElement::SOLID : SoShapeHintsElement::UNKNOWN_SHAPE_TYPE,
SoShapeHintsElement::FACE_TYPE_AS_IS);
}
}
// Doc in parent
SoChildList *
SoVRMLGeometry::getChildren(void) const
{
if (!PRIVATE(this)->childlistvalid) {
// this is not 100% thread safe. The assumption is that no nodes
// will be added or removed while a scene graph is being
// traversed. For Coin, this is an ok assumption.
PRIVATE(this)->lockChildList();
// test again after we've locked
if (!PRIVATE(this)->childlistvalid) {
SoVRMLGeometry * thisp = (SoVRMLGeometry*) this;
SoVRMLParent::updateChildList(thisp, *(PRIVATE(thisp)->childlist));
PRIVATE(thisp)->childlistvalid = TRUE;
}
PRIVATE(this)->unlockChildList();
}
return PRIVATE(this)->childlist;
}
// Doc in parent
void
SoVRMLGeometry::search(SoSearchAction * action)
{
SoNode::search(action);
if (action->isFound() || this->getChildren() == NULL) return;
int numindices;
const int * indices;
if (action->getPathCode(numindices, indices) == SoAction::IN_PATH) {
this->getChildren()->traverseInPath(action, numindices, indices);
}
else {
this->getChildren()->traverse(action); // traverse all children
}
}
// Doc in parent
void
SoVRMLGeometry::notify(SoNotList * list)
{
SoField * f = list->getLastField();
if (f && f->getTypeId() == SoSFNode::getClassTypeId()) {
PRIVATE(this)->childlistvalid = FALSE;
}
inherited::notify(list);
}
// Doc in parent
void
SoVRMLGeometry::copyContents(const SoFieldContainer * from,
SbBool copyConn)
{
inherited::copyContents(from, copyConn);
PRIVATE(this)->childlistvalid = FALSE;
PRIVATE(this)->childlist->truncate(0);
}
#undef PRIVATE
#endif // HAVE_VRML97
|