Coin Logo http://www.sim.no
http://www.coin3d.org

SoSubAction.h
1#ifndef COIN_SOSUBACTION_H
2#define COIN_SOSUBACTION_H
3
4/**************************************************************************\
5 *
6 * This file is part of the Coin 3D visualization library.
7 * Copyright (C) 1998-2007 by Systems in Motion. All rights reserved.
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * ("GPL") version 2 as published by the Free Software Foundation.
12 * See the file LICENSE.GPL at the root directory of this source
13 * distribution for additional information about the GNU GPL.
14 *
15 * For using Coin with software that can not be combined with the GNU
16 * GPL, and for taking advantage of the additional benefits of our
17 * support services, please contact Systems in Motion about acquiring
18 * a Coin Professional Edition License.
19 *
20 * See http://www.coin3d.org/ for more information.
21 *
22 * Systems in Motion, Postboks 1283, Pirsenteret, 7462 Trondheim, NORWAY.
23 * http://www.sim.no/ sales@sim.no coin-support@coin3d.org
24 *
25\**************************************************************************/
26
27#ifndef COIN_INTERNAL
28// Added to be Inventor compliant.
29#include <Inventor/SbString.h>
30#include <Inventor/actions/SoAction.h>
31#else // !COIN_INTERNAL
32#include <Inventor/SbName.h>
33#include <Inventor/actions/SoSubActionP.h>
34#endif // COIN_INTERNAL
35
36// *************************************************************************
37
38#define SO_ACTION_ADD_METHOD(_nodeclass_, _method_) \
39 do { \
40 addMethod(_nodeclass_::getClassTypeId(), (SoActionMethod)_method_); \
41 } while (0)
42
43// *************************************************************************
44
45#define SO_ACTION_CONSTRUCTOR(_classname_) \
46 do { \
47 _classname_::traversalMethods = this->methods; \
48 } while (0)
49
50// *************************************************************************
51
52#define SO_ACTION_HEADER(_classname_) \
53public: \
54 virtual SoType getTypeId(void) const; \
55 static SoType getClassTypeId(void); \
56 \
57 static void addMethod(const SoType type, SoActionMethod method); \
58 \
59 static void enableElement(const SoType type, const int stackindex); \
60 \
61protected: \
62 virtual const SoEnabledElementsList & getEnabledElements(void) const; \
63 /* These two methods are not available in the original OIV API. */ \
64 /* They have been added as a work-around for Win32 DLL headaches. */ \
65 /* See further explanation below. 20000808 mortene. */ \
66 static SoEnabledElementsList * getClassEnabledElements(void); \
67 static SoActionMethodList * getClassActionMethods(void); \
68 \
69private: \
70 /* The enabledElements and methods variables are protected in */ \
71 /* the original OIV API. This is not such a good idea, since */ \
72 /* exposed static class member variables is a major grievance */ \
73 /* with regard to Win32 DLLs. */ \
74 static void atexit_cleanup(void); \
75 static SoEnabledElementsList * enabledElements; \
76 static SoActionMethodList * methods; \
77 static SoType classTypeId
78
79// *************************************************************************
80
81#define SO_ACTION_SOURCE(_classname_) \
82SoEnabledElementsList * _classname_::enabledElements = NULL; \
83SoActionMethodList * _classname_::methods = NULL; \
84SoEnabledElementsList * _classname_::getClassEnabledElements(void) { return _classname_::enabledElements; } \
85SoActionMethodList * _classname_::getClassActionMethods(void) { return _classname_::methods; } \
86SoType _classname_::classTypeId STATIC_SOTYPE_INIT; \
87SoType _classname_::getClassTypeId(void) { return _classname_::classTypeId; } \
88SoType _classname_::getTypeId(void) const { return _classname_::classTypeId; } \
89const SoEnabledElementsList & _classname_::getEnabledElements(void) const \
90{ \
91 assert(_classname_::enabledElements); \
92 return *_classname_::enabledElements; \
93} \
94void \
95_classname_::addMethod(const SoType type, SoActionMethod method) \
96{ \
97 assert(_classname_::methods); \
98 _classname_::methods->addMethod(type, method); \
99} \
100void \
101_classname_::enableElement(const SoType type, const int stackindex) \
102{ \
103 assert(_classname_::enabledElements); \
104 _classname_::enabledElements->enable(type, stackindex); \
105} \
106void \
107_classname_::atexit_cleanup(void) \
108{ \
109 delete _classname_::enabledElements; \
110 _classname_::enabledElements = NULL; \
111 delete _classname_::methods; \
112 _classname_::methods = NULL; \
113 _classname_::classTypeId STATIC_SOTYPE_INIT; \
114}
115
116// *************************************************************************
117
118#define SO_ACTION_INIT_CLASS(_classname_, _parentclassname_) \
119 do { \
120 assert(_classname_::getClassTypeId() == SoType::badType()); \
121 assert(_parentclassname_::getClassTypeId() != SoType::badType()); \
122 _classname_::classTypeId = SoType::createType(_parentclassname_::getClassTypeId(), SO__QUOTE(_classname_)); \
123 _classname_::enabledElements = new SoEnabledElementsList(_parentclassname_::getClassEnabledElements()); \
124 _classname_::methods = new SoActionMethodList(_parentclassname_::getClassActionMethods()); \
125 } while (0)
126
127#define SO_ACTION_EXIT_CLASS(_class_) \
128 _class_::atexit_cleanup()
129
130// *************************************************************************
131
132#endif // !COIN_SOSUBACTION_H

Copyright © 1998-2007 by Systems in Motion AS. All rights reserved.

Generated on Wed Jul 19 2023 for Coin by Doxygen. 1.9.8