Open Inventor Reference
SoSubKit.h
Go to the documentation of this file.
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 /*
39  * Copyright (C) 1990,91 Silicon Graphics, Inc.
40  *
41  _______________________________________________________________________
42  ______________ S I L I C O N G R A P H I C S I N C . ____________
43  |
44  | $Revision: 1.1.1.1 $
45  |
46  | Description:
47  | This file defines some macros that implement things common to
48  | many subclasses of SoBaseKit. They may be used to make SoBaseKit
49  | subclassing easier. In all of the macros:
50  | "className" refers to the name of the baseKit subclass.
51  | "partName" refers to the name of a part in the nodekit catalog.
52  | "partClassName" refers to the class to which a part in the
53  | the nodekit catalog belongs.
54  |
55  | NOTE TO DEVELOPERS:
56  | For info about the structure of any nodekit:
57  | [1] compile: /usr/share/src/Inventor/samples/ivNodeKitStructure
58  | [2] type: ivNodeKitStructure nodekitClassName.
59  | [3] The program prints a diagram of the scene graph and a table with
60  | information about each part.
61  |
62  |
63  | Defined macros:
64  |
65  | Within class header:
66  | SO_KIT_HEADER(className)
67  | SO_KIT_CATALOG_ENTRY_HEADER(partName)
68  |
69  | Within class source:
70  | At file scope:
71  | SO_KIT_SOURCE(className)
72  |
73  | Class initialization:
74  | SO_KIT_INIT_CLASS(className,parentClass,parentPrintClass)
75  |
76  | Constructor initialization:
77  | SO_KIT_CONSTRUCTOR(className)
78  | SO_KIT_ADD_CATALOG_ENTRY(partName, partClassName, nullByDefault, | parentName, rightName, isPublicPart )
79  | SO_KIT_ADD_CATALOG_ABSTRACT_ENTRY(partName, partClassName,
80  | defaultPartClassName, nullByDefault,
81  | parentName, rightName, isPublicPart )
82  | SO_KIT_ADD_CATALOG_LIST_ENTRY(partName, listContainerClassName,
83  | nullByDefault, parentName, rightName,
84  | listItemClassName, isPublicPart )
85  | SO_KIT_ADD_LIST_ITEM_TYPE(partName, newListItemClassName )
86  | SO_KIT_CHANGE_ENTRY_TYPE(partName, newPartClassName,
87  | newDefaultPartClassName)
88  | SO_KIT_CHANGE_NULL_BY_DEFAULT(partName, newNullByDefault)
89  |
90  | SO_KIT_INIT_INSTANCE()
91  |
92  | SO_KIT_ADD_FIELD(fieldMember,(defaultValue))
93  | SO_KIT_DEFINE_ENUM_VALUE(enumType,enumValue)
94  | SO_KIT_IS_FIRST_INSTANCE() //!< a boolean value
95  | SO_KIT_SET_SF_ENUM_TYPE(fieldName,enumType)
96  | SO_KIT_SET_MF_ENUM_TYPE(fieldName,enumType)
97  |
98  | Author(s) : Paul Isaacs, Paul S. Strauss
99  |
100  ______________ S I L I C O N G R A P H I C S I N C . ____________
101  _______________________________________________________________________
102  */
103 
108 
109 #ifndef _SO_SUB_KIT_
110 #define _SO_SUB_KIT_
111 
112 
113 #include <Inventor/nodes/SoNode.h>
117 
123 
129 
130 #define SO__KIT_CATALOG_HEADER(className) \
131  private: \
132  static SoNodekitCatalog *nodekitCatalog; /* design of this class */ \
133  static const SoNodekitCatalog **parentNodekitCatalogPtr;/* parent design */\
134  public: \
135  static const SoNodekitCatalog *getClassNodekitCatalog() \
136  { return nodekitCatalog; } \
137  /* Returns an SoNodekitCatalog for the node */ \
138  virtual const SoNodekitCatalog *getNodekitCatalog() const; \
139  protected: \
140  static const SoNodekitCatalog **getClassNodekitCatalogPtr() \
141  { return (const SoNodekitCatalog **)&nodekitCatalog; }
142 
143 #define SO_KIT_HEADER(className) \
144  SO_NODE_HEADER(className); \
145  SO__KIT_CATALOG_HEADER(className)
146 
147 
154 
155 #define SO_KIT_CATALOG_ENTRY_HEADER(partName) \
156  protected: \
157  SoSFNode partName
158 
159 
164 
169 
170 #define SO__KIT_CATALOG_VARS(className) \
171 SoNodekitCatalog *className::nodekitCatalog = NULL; \
172 const SoNodekitCatalog **className::parentNodekitCatalogPtr = NULL
173 
178 
179 #define SO__KIT_CATALOG_METHODS(className) \
180 const SoNodekitCatalog * \
181 className::getNodekitCatalog() const \
182 { \
183  return nodekitCatalog; \
184 }
185 
191 
192 #define SO_KIT_SOURCE(className) \
193  SO_NODE_SOURCE(className); \
194  SO__KIT_CATALOG_VARS(className); \
195  SO__KIT_CATALOG_METHODS(className)
196 
201 #define SO__KIT_INIT_CLASS(className,classPrintName,parentClass) { \
202  SO__NODE_INIT_CLASS(className,classPrintName,parentClass); \
203  int _value_false= 0; \
204  do { \
205  parentNodekitCatalogPtr = parentClass::getClassNodekitCatalogPtr(); \
206  } while (_value_false); \
207  }
208 
218 
219 #define SO_KIT_INIT_CLASS(className,parentClass,parentPrintClass) { \
220  SO_NODE_INIT_CLASS(className,parentClass,parentPrintClass); \
221  int _value_false= 0; \
222  do { \
223  parentNodekitCatalogPtr = parentClass::getClassNodekitCatalogPtr(); \
224  } while (_value_false); \
225  }
226 
237 
238 #define SO__KIT_INHERIT_CATALOG(className) { \
239  /* get a copy of the catalog from the base class */ \
240  int _value_false= 0; \
241  do { \
242  if (firstInstance) { \
243  if (parentNodekitCatalogPtr == nullptr) { /* only true in SoBaseKit */ \
244  nodekitCatalog = new SoNodekitCatalog; \
245  } \
246  else { \
247  nodekitCatalog \
248  =(*parentNodekitCatalogPtr)->clone(SoType::fromName(SO__QUOTE(className))); \
249  } \
250  } \
251  } while (_value_false); \
252  }
253 
258 
259 #define SO_KIT_CONSTRUCTOR(className) \
260  SO_NODE_CONSTRUCTOR(className); \
261  SO__KIT_INHERIT_CATALOG(className)
262 
263 #define SO_KIT_IS_FIRST_INSTANCE() \
264  SO_NODE_IS_FIRST_INSTANCE()
265 
266 #define SO_KIT_ADD_FIELD(fieldName,defValue) \
267  SO_NODE_ADD_FIELD(fieldName,defValue)
268 
269 #define SO_KIT_DEFINE_ENUM_VALUE(enumType,enumValue) \
270  SO_NODE_DEFINE_ENUM_VALUE(enumType,enumValue)
271 
272 #define SO_KIT_SET_MF_ENUM_TYPE(fieldName, enumType) \
273  SO_NODE_SET_MF_ENUM_TYPE(fieldName, enumType)
274 
275 #define SO_KIT_SET_SF_ENUM_TYPE(fieldName, enumType) \
276  SO_NODE_SET_SF_ENUM_TYPE(fieldName, enumType)
277 
337 
338 #define SO_KIT_ADD_CATALOG_ENTRY(partName, partClassName, nullByDefault, \
339  parentName, rightName, isPublicPart ) \
340  SO_KIT_ADD_FIELD(partName,(NULL)); \
341  if (firstInstance && !nodekitCatalog->addEntry(SO__QUOTE(partName), \
342  SoType::fromName(SO__QUOTE(partClassName)), \
343  SoType::fromName(SO__QUOTE(partClassName)), nullByDefault,\
344  SO__QUOTE(parentName), \
345  SO__QUOTE(rightName), FALSE, SoType::badType(), \
346  SoType::badType(), isPublicPart )) \
347  catalogError()
348 
349 
386 
387 #define SO_KIT_ADD_CATALOG_ABSTRACT_ENTRY(partName, partClassName, \
388  defaultPartClassName, nullByDefault, parentName, \
389  rightName, isPublicPart ) \
390  SO_KIT_ADD_FIELD(partName,(NULL)); \
391  if (firstInstance && !nodekitCatalog->addEntry(SO__QUOTE(partName), \
392  SoType::fromName(SO__QUOTE(partClassName)), \
393  SoType::fromName(SO__QUOTE(defaultPartClassName)), nullByDefault,\
394  SO__QUOTE(parentName), SO__QUOTE(rightName), FALSE, \
395  SoType::badType(), SoType::badType(), isPublicPart )) \
396  catalogError()
397 
437 
438 #define SO_KIT_ADD_CATALOG_LIST_ENTRY(partName, listContainerClassName, \
439  nullByDefault, parentName, rightName, listItemClassName, isPublicPart ) \
440  SO_KIT_ADD_FIELD(partName,(NULL)); \
441  if (firstInstance && !nodekitCatalog->addEntry(SO__QUOTE(partName), \
442  SoNodeKitListPart::getClassTypeId(), \
443  SoNodeKitListPart::getClassTypeId(), nullByDefault, \
444  SO__QUOTE(parentName), SO__QUOTE(rightName), TRUE, \
445  SoType::fromName(SO__QUOTE(listContainerClassName)), \
446  SoType::fromName(SO__QUOTE(listItemClassName)), isPublicPart)) \
447  catalogError()
448 
474 
475 #define SO_KIT_ADD_LIST_ITEM_TYPE(partName, newListItemClassName ) \
476  if (firstInstance) nodekitCatalog->addListItemType(SO__QUOTE(partName), \
477  SoType::fromName(SO__QUOTE(newListItemClassName)) )
478 
520 
521 #define SO_KIT_CHANGE_ENTRY_TYPE(partName, newPartClassName, \
522  newDefaultPartClassName) \
523  if (firstInstance) nodekitCatalog->narrowTypes(SO__QUOTE(partName), \
524  SoType::fromName(SO__QUOTE(newPartClassName)), \
525  SoType::fromName(SO__QUOTE(newDefaultPartClassName)))
526 
535 #define SO_KIT_CHANGE_NULL_BY_DEFAULT(partName, newNullByDefault) \
536  if (firstInstance) nodekitCatalog->setNullByDefault(SO__QUOTE(partName), \
537  newNullByDefault)
538 
551 #define SO_KIT_INIT_INSTANCE() \
552  createNodekitPartsList(); \
553  createDefaultParts()
554 
555 
556 #endif /* _SO_SUB_KIT_ */