| 1 | /* |
| 2 | * |
| 3 | * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved. |
| 4 | * |
| 5 | * This library is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Lesser General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2.1 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Lesser General Public License for more details. |
| 14 | * |
| 15 | * Further, this software is distributed without any warranty that it is |
| 16 | * free of the rightful claim of any third person regarding infringement |
| 17 | * or the like. Any license provided herein, whether implied or |
| 18 | * otherwise, applies only to this software file. Patent licenses, if |
| 19 | * any, provided herein do not apply to combinations of this program with |
| 20 | * other software, or any other product whatsoever. |
| 21 | * |
| 22 | * You should have received a copy of the GNU Lesser General Public |
| 23 | * License along with this library; if not, write to the Free Software |
| 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 25 | * |
| 26 | * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
| 27 | * Mountain View, CA 94043, or: |
| 28 | * |
| 29 | * http://www.sgi.com |
| 30 | * |
| 31 | * For further information regarding this notice, see: |
| 32 | * |
| 33 | * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ |
| 34 | * |
| 35 | */ |
| 36 | |
| 37 | /* |
| 38 | * Copyright (C) 1990,91 Silicon Graphics, Inc. |
| 39 | * |
| 40 | _______________________________________________________________________ |
| 41 | ______________ S I L I C O N G R A P H I C S I N C . ____________ |
| 42 | | |
| 43 | | $Revision: 1.1.1.1 $ |
| 44 | | |
| 45 | | Classes: |
| 46 | | SoCallback |
| 47 | | |
| 48 | | Author(s) : Paul S. Strauss |
| 49 | | |
| 50 | ______________ S I L I C O N G R A P H I C S I N C . ____________ |
| 51 | _______________________________________________________________________ |
| 52 | */ |
| 53 | |
| 54 | #include <Inventor/actions/SoCallbackAction.h> |
| 55 | #include <Inventor/actions/SoGLRenderAction.h> |
| 56 | #include <Inventor/actions/SoGetBoundingBoxAction.h> |
| 57 | #include <Inventor/actions/SoGetMatrixAction.h> |
| 58 | #include <Inventor/actions/SoHandleEventAction.h> |
| 59 | #include <Inventor/actions/SoRayPickAction.h> |
| 60 | #include <Inventor/actions/SoSearchAction.h> |
| 61 | #include <Inventor/actions/SoWriteAction.h> |
| 62 | #include <Inventor/elements/SoGLCacheContextElement.h> |
| 63 | #include <Inventor/nodes/SoCallback.h> |
| 64 | |
| 65 | SO_NODE_SOURCE(SoCallback); |
| 66 | |
| 67 | //////////////////////////////////////////////////////////////////////// |
| 68 | // |
| 69 | // Description: |
| 70 | // Constructor |
| 71 | // |
| 72 | // Use: public |
| 73 | |
| 74 | SoCallback::SoCallback() |
| 75 | // |
| 76 | //////////////////////////////////////////////////////////////////////// |
| 77 | { |
| 78 | SO_NODE_CONSTRUCTOR(SoCallback); |
| 79 | |
| 80 | isBuiltIn = TRUE; |
| 81 | callbackFunc = NULL; |
| 82 | callbackData = NULL; |
| 83 | } |
| 84 | |
| 85 | //////////////////////////////////////////////////////////////////////// |
| 86 | // |
| 87 | // Description: |
| 88 | // Copies the contents of the given node into this instance. |
| 89 | // |
| 90 | // Use: protected, virtual |
| 91 | |
| 92 | void |
| 93 | SoCallback::copyContents(const SoFieldContainer *fromFC, |
| 94 | SbBool copyConnections) |
| 95 | // |
| 96 | //////////////////////////////////////////////////////////////////////// |
| 97 | { |
| 98 | // Copy the usual stuff |
| 99 | SoNode::copyContents(fromFC, copyConnections); |
| 100 | |
| 101 | // Copy the callback function and data |
| 102 | const SoCallback *fromCB = (const SoCallback *) fromFC; |
| 103 | setCallback(fromCB->callbackFunc, fromCB->callbackData); |
| 104 | } |
| 105 | |
| 106 | //////////////////////////////////////////////////////////////////////// |
| 107 | // |
| 108 | // Description: |
| 109 | // Destructor |
| 110 | // |
| 111 | // Use: private |
| 112 | |
| 113 | SoCallback::~SoCallback() |
| 114 | // |
| 115 | //////////////////////////////////////////////////////////////////////// |
| 116 | { |
| 117 | } |
| 118 | |
| 119 | //////////////////////////////////////////////////////////////////////// |
| 120 | // |
| 121 | // Description: |
| 122 | // Typical action method. |
| 123 | // |
| 124 | // Use: extender |
| 125 | |
| 126 | void |
| 127 | SoCallback::doAction(SoAction *action) |
| 128 | // |
| 129 | //////////////////////////////////////////////////////////////////////// |
| 130 | { |
| 131 | SoType actionType = action->getTypeId(); |
| 132 | SoState *state = action->getState(); |
| 133 | |
| 134 | if (this->callbackFunc != NULL) |
| 135 | (*this->callbackFunc)(this->callbackData, action); |
| 136 | } |
| 137 | |
| 138 | //////////////////////////////////////////////////////////////////////// |
| 139 | // |
| 140 | // Description: |
| 141 | // Does the callback action |
| 142 | // |
| 143 | // Use: extender |
| 144 | |
| 145 | void |
| 146 | SoCallback::callback(SoCallbackAction *action) |
| 147 | // |
| 148 | //////////////////////////////////////////////////////////////////////// |
| 149 | { |
| 150 | SoCallback::doAction(action); |
| 151 | } |
| 152 | |
| 153 | //////////////////////////////////////////////////////////////////////// |
| 154 | // |
| 155 | // Description: |
| 156 | // Does the GL render action |
| 157 | // |
| 158 | // Use: extender |
| 159 | |
| 160 | void |
| 161 | SoCallback::GLRender(SoGLRenderAction *action) |
| 162 | // |
| 163 | //////////////////////////////////////////////////////////////////////// |
| 164 | { |
| 165 | // Ask to be cached, to match Inventor 2.0 default: |
| 166 | SoGLCacheContextElement::shouldAutoCache(action->getState(), TRUE); |
| 167 | |
| 168 | SoCallback::doAction(action); |
| 169 | } |
| 170 | |
| 171 | //////////////////////////////////////////////////////////////////////// |
| 172 | // |
| 173 | // Description: |
| 174 | // Does the get bounding box action |
| 175 | // |
| 176 | // Use: extender |
| 177 | |
| 178 | void |
| 179 | SoCallback::getBoundingBox(SoGetBoundingBoxAction *action) |
| 180 | // |
| 181 | //////////////////////////////////////////////////////////////////////// |
| 182 | { |
| 183 | SoCallback::doAction(action); |
| 184 | } |
| 185 | |
| 186 | //////////////////////////////////////////////////////////////////////// |
| 187 | // |
| 188 | // Description: |
| 189 | // Does the get matrix action |
| 190 | // |
| 191 | // Use: extender |
| 192 | |
| 193 | void |
| 194 | SoCallback::getMatrix(SoGetMatrixAction *action) |
| 195 | // |
| 196 | //////////////////////////////////////////////////////////////////////// |
| 197 | { |
| 198 | SoCallback::doAction(action); |
| 199 | } |
| 200 | |
| 201 | //////////////////////////////////////////////////////////////////////// |
| 202 | // |
| 203 | // Description: |
| 204 | // Does the handle event thing |
| 205 | // |
| 206 | // Use: extender |
| 207 | |
| 208 | void |
| 209 | SoCallback::handleEvent(SoHandleEventAction *action) |
| 210 | // |
| 211 | //////////////////////////////////////////////////////////////////////// |
| 212 | { |
| 213 | SoCallback::doAction(action); |
| 214 | } |
| 215 | |
| 216 | //////////////////////////////////////////////////////////////////////// |
| 217 | // |
| 218 | // Description: |
| 219 | // Pick. |
| 220 | // |
| 221 | // Use: extender |
| 222 | |
| 223 | void |
| 224 | SoCallback::pick(SoPickAction *action) |
| 225 | // |
| 226 | //////////////////////////////////////////////////////////////////////// |
| 227 | { |
| 228 | SoCallback::doAction(action); |
| 229 | } |
| 230 | |
| 231 | //////////////////////////////////////////////////////////////////////// |
| 232 | // |
| 233 | // Description: |
| 234 | // Does search... |
| 235 | // |
| 236 | // Use: extender |
| 237 | |
| 238 | void |
| 239 | SoCallback::search(SoSearchAction *action) |
| 240 | // |
| 241 | //////////////////////////////////////////////////////////////////////// |
| 242 | { |
| 243 | SoCallback::doAction(action); |
| 244 | SoNode::search(action); |
| 245 | } |
| 246 | |
| 247 | //////////////////////////////////////////////////////////////////////// |
| 248 | // |
| 249 | // Description: |
| 250 | // Does the write action |
| 251 | // |
| 252 | // Use: extender |
| 253 | |
| 254 | void |
| 255 | SoCallback::write(SoWriteAction *action) |
| 256 | // |
| 257 | //////////////////////////////////////////////////////////////////////// |
| 258 | { |
| 259 | SoCallback::doAction(action); |
| 260 | SoNode::write(action); |
| 261 | } |