Coin  4.0.3
Coin3D core library
Loading...
Searching...
No Matches
SoSubKit.h
1#ifndef COIN_SOSUBKIT_H
2#define COIN_SOSUBKIT_H
3
4/**************************************************************************\
5 * Copyright (c) Kongsberg Oil & Gas Technologies AS
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met:
11 *
12 * Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 *
15 * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * Neither the name of the copyright holder nor the names of its
20 * contributors may be used to endorse or promote products derived from
21 * this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34\**************************************************************************/
35
36#include <Inventor/nodes/SoSubNode.h>
37#include <Inventor/fields/SoSFNode.h>
38#include <Inventor/nodekits/SoNodekitCatalog.h>
39#include <Inventor/C/tidbits.h>
40
41#ifndef COIN_INTERNAL
42// Include this header file for better Open Inventor compatibility.
43#include <Inventor/nodekits/SoNodeKitListPart.h>
44#endif // !COIN_INTERNAL
45
46
47// FIXME: document all the macros, as they are part of the public
48// API. 20011024 mortene.
49
50#define PRIVATE_KIT_HEADER(_kitclass_) \
51public: \
52 static const SoNodekitCatalog * getClassNodekitCatalog(void); \
53 virtual const SoNodekitCatalog * getNodekitCatalog(void) const; \
54 \
55protected: \
56 static const SoNodekitCatalog ** getClassNodekitCatalogPtr(void); \
57 \
58private: \
59 static SoNodekitCatalog * classcatalog; \
60 static const SoNodekitCatalog ** parentcatalogptr; \
61 static void atexit_cleanupkit(void)
62
63#define SO_KIT_HEADER(_kitclass_) \
64 SO_NODE_HEADER(_kitclass_); \
65 PRIVATE_KIT_HEADER(_kitclass_)
66
67#define SO_KIT_ABSTRACT_HEADER(_kitclass_) \
68 SO_NODE_ABSTRACT_HEADER(_kitclass_); \
69 PRIVATE_KIT_HEADER(_kitclass_)
70
71#define SO_KIT_CATALOG_ENTRY_HEADER(_entry_) \
72protected: SoSFNode _entry_
73
74
75#define PRIVATE_KIT_SOURCE(_class_) \
76SoNodekitCatalog * _class_::classcatalog = NULL; \
77const SoNodekitCatalog ** _class_::parentcatalogptr = NULL; \
78 \
79
82 \
83const SoNodekitCatalog * \
84_class_::getClassNodekitCatalog(void) \
85{ \
86 return _class_::classcatalog; \
87} \
88 \
89
92 \
93const SoNodekitCatalog * \
94_class_::getNodekitCatalog(void) const \
95{ \
96 return _class_::classcatalog; \
97} \
98 \
99
102 \
103const SoNodekitCatalog ** \
104_class_::getClassNodekitCatalogPtr(void) \
105{ \
106 return const_cast<const class SoNodekitCatalog **>(&_class_::classcatalog); \
107} \
108 \
109void \
110_class_::atexit_cleanupkit(void) \
111{ \
112 delete _class_::classcatalog; \
113 _class_::classcatalog = NULL; \
114 _class_::parentcatalogptr = NULL; \
115}
116
117#define SO_KIT_SOURCE(_class_) \
118SO_NODE_SOURCE(_class_) \
119PRIVATE_KIT_SOURCE(_class_)
120
121#define SO_KIT_ABSTRACT_SOURCE(_class_) \
122SO_NODE_ABSTRACT_SOURCE(_class_); \
123PRIVATE_KIT_SOURCE(_class_)
124
125#define SO_KIT_IS_FIRST_INSTANCE() \
126 SO_NODE_IS_FIRST_INSTANCE()
127
128#define SO_KIT_INIT_CLASS(_class_, _parentclass_, _parentname_) \
129 do { \
130 SO_NODE_INIT_CLASS(_class_, _parentclass_, _parentname_); \
131 _class_::parentcatalogptr = _parentclass_::getClassNodekitCatalogPtr(); \
132 } WHILE_0
133
134#define SO_KIT_INIT_ABSTRACT_CLASS(_class_, _parentclass_, _parentname_) \
135 do { \
136 SO_NODE_INIT_ABSTRACT_CLASS(_class_, _parentclass_, _parentname_); \
137 _class_::parentcatalogptr = _parentclass_::getClassNodekitCatalogPtr(); \
138 } WHILE_0
139
140
141#define SO_KIT_CONSTRUCTOR(_class_) \
142 do { \
143 SO_NODE_CONSTRUCTOR(_class_); \
144 SoBase::staticDataLock(); \
145 if (_class_::classcatalog == NULL) { \
146 SoType mytype = SoType::fromName(SO__QUOTE(_class_)); \
147 _class_::classcatalog = (*_class_::parentcatalogptr)->clone(mytype); \
148 cc_coin_atexit_static_internal(_class_::atexit_cleanupkit); \
149 } \
150 SoBase::staticDataUnlock(); \
151 } WHILE_0
152
153
154
155#define SO_KIT_ADD_CATALOG_ENTRY(_part_, _partclass_, _isdefnull_ , _parent_, _sibling_, _ispublic_) \
156 do { \
157 classcatalog->addEntry(SO__QUOTE(_part_), \
158 SoType::fromName(SO__QUOTE(_partclass_)), \
159 SoType::fromName(SO__QUOTE(_partclass_)), \
160 _isdefnull_, \
161 SO__QUOTE(_parent_), \
162 SO__QUOTE(_sibling_), \
163 FALSE, \
164 SoType::badType(), \
165 SoType::badType(), \
166 _ispublic_); \
167 SO_NODE_ADD_FIELD(_part_,(NULL)); \
168 } WHILE_0
169
170
171
172#define SO_KIT_ADD_CATALOG_LIST_ENTRY(_part_, _containertype_, _isdefnull_, _parent_, _sibling_, _itemtype_, _ispublic_) \
173 do { \
174 classcatalog->addEntry(SO__QUOTE(_part_), \
175 SoNodeKitListPart::getClassTypeId(), \
176 SoNodeKitListPart::getClassTypeId(), \
177 _isdefnull_, \
178 SO__QUOTE(_parent_), \
179 SO__QUOTE(_sibling_), \
180 TRUE, \
181 _containertype_::getClassTypeId(), \
182 _itemtype_::getClassTypeId(), \
183 _ispublic_); \
184 SO_NODE_ADD_FIELD(_part_,(NULL)); \
185 } WHILE_0
186
187
188
189#define SO_KIT_ADD_CATALOG_ABSTRACT_ENTRY(_part_, _class_, _defaultclass_, _isdefnull_, _parent_, _sibling_, _ispublic_) \
190 do { \
191 classcatalog->addEntry(SO__QUOTE(_part_), \
192 _class_::getClassTypeId(), \
193 _defaultclass_::getClassTypeId(), \
194 _isdefnull_, \
195 SO__QUOTE(_parent_), \
196 SO__QUOTE(_sibling_), \
197 FALSE, \
198 SoType::badType(), \
199 SoType::badType(), \
200 _ispublic_); \
201 SO_NODE_ADD_FIELD(_part_,(NULL)); \
202 } WHILE_0
203
204
205
206#define SO_KIT_ADD_LIST_ITEM_TYPE(_part_, _listitemtype_) \
207 do { \
208 classcatalog->addListItemType(SO__QUOTE(_part_), \
209 _listitemtype_::getClassTypeId()); \
210 } WHILE_0
211
212
213#define SO_KIT_INIT_INSTANCE() \
214 this->createFieldList(); \
215 this->createDefaultParts()
216
217#define SO_KIT_ADD_FIELD(_fieldname_, _defvalue_) \
218 SO_NODE_ADD_FIELD(_fieldname_, _defvalue_)
219
220// New for Coin-3
221#define SO_KIT_ADD_EMPTY_MFIELD(_fieldname_) \
222 SO_NODE_ADD_EMPTY_MFIELD(_fieldname_)
223
224#define SO_KIT_DEFINE_ENUM_VALUE(_enumtype_, _enumvalue_) \
225 SO_NODE_DEFINE_ENUM_VALUE(_enumtype_, _enumvalue_)
226
227#define SO_KIT_SET_MF_ENUM_TYPE(_fieldname_, _enumtype_) \
228 SO_NODE_SET_MF_ENUM_TYPE(_fieldname_, _enumtype_)
229
230#define SO_KIT_SET_SF_ENUM_TYPE(_fieldname_, _enumtype_) \
231 SO_NODE_SET_SF_ENUM_TYPE(_fieldname_, _enumtype_)
232
233#define SO_KIT_CHANGE_ENTRY_TYPE(_part_, _newpartclassname_, _newdefaultpartclassname_) \
234 do { \
235 classcatalog->narrowTypes(SO__QUOTE(_part_), \
236 SoType::fromName(SO__QUOTE(_newpartclassname_)), \
237 SoType::fromName(SO__QUOTE(_newdefaultpartclassname_))); \
238 } WHILE_0
239
240
241#define SO_KIT_CHANGE_NULL_BY_DEFAULT(_part_, _newnullbydefault_) \
242 do { \
243 classcatalog->setNullByDefault(SO__QUOTE(_part_), _newnullbydefault_); \
244 } WHILE_0
245
246#endif // !COIN_SOSUBKIT_H