Open Inventor Reference
MeVis/ThirdParty/Sources/Inventor/inventor/lib/nodekits/include/Inventor/nodekits/SoSubKit.h
Go to the documentation of this file.
00001 /*
00002  *
00003  *  Copyright (C) 2000 Silicon Graphics, Inc.  All Rights Reserved. 
00004  *
00005  *  This library is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU Lesser General Public
00007  *  License as published by the Free Software Foundation; either
00008  *  version 2.1 of the License, or (at your option) any later version.
00009  *
00010  *  This library is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  *  Lesser General Public License for more details.
00014  *
00015  *  Further, this software is distributed without any warranty that it is
00016  *  free of the rightful claim of any third person regarding infringement
00017  *  or the like.  Any license provided herein, whether implied or
00018  *  otherwise, applies only to this software file.  Patent licenses, if
00019  *  any, provided herein do not apply to combinations of this program with
00020  *  other software, or any other product whatsoever.
00021  * 
00022  *  You should have received a copy of the GNU Lesser General Public
00023  *  License along with this library; if not, write to the Free Software
00024  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025  *
00026  *  Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
00027  *  Mountain View, CA  94043, or:
00028  * 
00029  *  http://www.sgi.com 
00030  * 
00031  *  For further information regarding this notice, see: 
00032  * 
00033  *  http://oss.sgi.com/projects/GenInfo/NoticeExplan/
00034  *
00035  */
00036 
00037 
00038 /*
00039  * Copyright (C) 1990,91   Silicon Graphics, Inc.
00040  *
00041  _______________________________________________________________________
00042  ______________  S I L I C O N   G R A P H I C S   I N C .  ____________
00043  |
00044  |   $Revision: 1.1.1.1 $
00045  |
00046  |   Description:
00047  |      This file defines some macros that implement things common to
00048  |      many subclasses of SoBaseKit. They may be used to make SoBaseKit
00049  |      subclassing easier. In all of the macros:
00050  |      "className" refers to the name of the baseKit subclass.
00051  |      "partName"  refers to the name of a part in the nodekit catalog.
00052  |      "partClassName" refers to the class to which a part in the 
00053  |                      the nodekit catalog belongs. 
00054  |
00055  | NOTE TO DEVELOPERS:
00056  |     For info about the structure of any nodekit:
00057  |     [1] compile: /usr/share/src/Inventor/samples/ivNodeKitStructure
00058  |     [2] type:    ivNodeKitStructure nodekitClassName.
00059  |     [3] The program prints a diagram of the scene graph and a table with 
00060  |         information about each part.
00061  |
00062  |
00063  |   Defined macros:
00064  |
00065  |      Within class header:
00066  |              SO_KIT_HEADER(className)
00067  |              SO_KIT_CATALOG_ENTRY_HEADER(partName)
00068  |
00069  |      Within class source:
00070  |          At file scope:
00071  |              SO_KIT_SOURCE(className)
00072  |
00073  |          Class initialization:
00074  |              SO_KIT_INIT_CLASS(className,parentClass,parentPrintClass)
00075  |
00076  |          Constructor initialization:
00077  |              SO_KIT_CONSTRUCTOR(className)
00078  |              SO_KIT_ADD_CATALOG_ENTRY(partName, partClassName, nullByDefault, |                     parentName, rightName, isPublicPart )
00079  |              SO_KIT_ADD_CATALOG_ABSTRACT_ENTRY(partName, partClassName, 
00080  |                     defaultPartClassName, nullByDefault, 
00081  |                     parentName,  rightName, isPublicPart )
00082  |              SO_KIT_ADD_CATALOG_LIST_ENTRY(partName, listContainerClassName, 
00083  |                     nullByDefault, parentName, rightName, 
00084  |                     listItemClassName, isPublicPart )
00085  |              SO_KIT_ADD_LIST_ITEM_TYPE(partName, newListItemClassName )
00086  |              SO_KIT_CHANGE_ENTRY_TYPE(partName, newPartClassName, 
00087  |                     newDefaultPartClassName)
00088  |              SO_KIT_CHANGE_NULL_BY_DEFAULT(partName, newNullByDefault)
00089  |
00090  |              SO_KIT_INIT_INSTANCE()
00091  |
00092  |              SO_KIT_ADD_FIELD(fieldMember,(defaultValue))
00093  |              SO_KIT_DEFINE_ENUM_VALUE(enumType,enumValue)
00094  |              SO_KIT_IS_FIRST_INSTANCE()      //!< a boolean value
00095  |              SO_KIT_SET_SF_ENUM_TYPE(fieldName,enumType)
00096  |              SO_KIT_SET_MF_ENUM_TYPE(fieldName,enumType)
00097  |
00098  |   Author(s)          : Paul Isaacs, Paul S. Strauss
00099  |
00100  ______________  S I L I C O N   G R A P H I C S   I N C .  ____________
00101  _______________________________________________________________________
00102  */
00103 
00107 #include <Inventor/nodekits/SoBaseKit.h>
00108 
00109 #ifndef  _SO_SUB_KIT_
00110 #define  _SO_SUB_KIT_
00111 
00112 
00113 #include <Inventor/nodes/SoNode.h>
00114 #include <Inventor/fields/SoSFNode.h>
00115 #include <Inventor/nodekits/SoNodekitCatalog.h>
00116 #include <Inventor/nodekits/SoNodeKitListPart.h>
00117 
00123 
00129 
00130 #define SO__KIT_CATALOG_HEADER(className)                                     \
00131   private:                                                                    \
00132     static SoNodekitCatalog *nodekitCatalog; /* design of this class */       \
00133     static const SoNodekitCatalog **parentNodekitCatalogPtr;/* parent design */\
00134   public:                                                                     \
00135     static const SoNodekitCatalog *getClassNodekitCatalog()                   \
00136         { return nodekitCatalog; }                                            \
00137     /* Returns an SoNodekitCatalog for the node */                            \
00138     virtual const SoNodekitCatalog *getNodekitCatalog() const;                \
00139   protected:                                                                  \
00140     static const SoNodekitCatalog **getClassNodekitCatalogPtr()               \
00141         { return (const SoNodekitCatalog **)&nodekitCatalog; }
00142 
00143 #define SO_KIT_HEADER(className)                                              \
00144     SO_NODE_HEADER(className);                                                \
00145     SO__KIT_CATALOG_HEADER(className)
00146 
00147 
00154 
00155 #define SO_KIT_CATALOG_ENTRY_HEADER(partName)                                 \
00156   protected:                                                                  \
00157     SoSFNode partName
00158 
00159 
00164 
00169 
00170 #define SO__KIT_CATALOG_VARS(className)                                        \
00171 SoNodekitCatalog   *className::nodekitCatalog = NULL;                          \
00172 const SoNodekitCatalog   **className::parentNodekitCatalogPtr = NULL
00173 
00178 
00179 #define SO__KIT_CATALOG_METHODS(className)                                    \
00180 const SoNodekitCatalog *                                                      \
00181 className::getNodekitCatalog() const                                          \
00182 {                                                                             \
00183     return nodekitCatalog;                                                    \
00184 }
00185 
00191 
00192 #define SO_KIT_SOURCE(className)                                              \
00193     SO_NODE_SOURCE(className);                                                \
00194     SO__KIT_CATALOG_VARS(className);                                          \
00195     SO__KIT_CATALOG_METHODS(className)
00196 
00201 #define SO__KIT_INIT_CLASS(className,classPrintName,parentClass) {            \
00202     SO__NODE_INIT_CLASS(className,classPrintName,parentClass);                \
00203     int _value_false= 0;                                                      \
00204     do {                                                                      \
00205         parentNodekitCatalogPtr = parentClass::getClassNodekitCatalogPtr();   \
00206     } while (_value_false);                                                   \
00207     }
00208 
00218 
00219 #define SO_KIT_INIT_CLASS(className,parentClass,parentPrintClass) {           \
00220     SO_NODE_INIT_CLASS(className,parentClass,parentPrintClass);               \
00221     int _value_false= 0;                                                      \
00222     do {                                                                      \
00223         parentNodekitCatalogPtr = parentClass::getClassNodekitCatalogPtr();   \
00224     } while (_value_false);                                                   \
00225     }
00226 
00237 
00238 #define SO__KIT_INHERIT_CATALOG(className) {                                  \
00239     /* get a copy of the catalog from the base class */                       \
00240     int _value_false= 0;                                                      \
00241     do {                                                                      \
00242         if (firstInstance)                                                    \
00243             if (parentNodekitCatalogPtr == NULL)  /* only true in SoBaseKit */\
00244                 nodekitCatalog = new SoNodekitCatalog;                        \
00245             else                                                              \
00246                 nodekitCatalog                                                \
00247               =(*parentNodekitCatalogPtr)->clone(SoType::fromName(SO__QUOTE(className)));\
00248     } while (_value_false);                                                   \
00249     }
00250 
00255 
00256 #define SO_KIT_CONSTRUCTOR(className)                                         \
00257     SO_NODE_CONSTRUCTOR(className);                                           \
00258     SO__KIT_INHERIT_CATALOG(className)
00259 
00260 #define SO_KIT_IS_FIRST_INSTANCE()                                            \
00261     SO_NODE_IS_FIRST_INSTANCE()
00262 
00263 #define SO_KIT_ADD_FIELD(fieldName,defValue)                                  \
00264     SO_NODE_ADD_FIELD(fieldName,defValue)
00265 
00266 #define SO_KIT_DEFINE_ENUM_VALUE(enumType,enumValue)                          \
00267     SO_NODE_DEFINE_ENUM_VALUE(enumType,enumValue)
00268 
00269 #define SO_KIT_SET_MF_ENUM_TYPE(fieldName, enumType)                          \
00270     SO_NODE_SET_MF_ENUM_TYPE(fieldName, enumType)
00271 
00272 #define SO_KIT_SET_SF_ENUM_TYPE(fieldName, enumType)                          \
00273     SO_NODE_SET_SF_ENUM_TYPE(fieldName, enumType)
00274 
00334 
00335 #define SO_KIT_ADD_CATALOG_ENTRY(partName, partClassName, nullByDefault,      \
00336                   parentName, rightName, isPublicPart )                       \
00337    SO_KIT_ADD_FIELD(partName,(NULL));                                         \
00338    if (firstInstance && !nodekitCatalog->addEntry(SO__QUOTE(partName),        \
00339                     SoType::fromName(SO__QUOTE(partClassName)),               \
00340                     SoType::fromName(SO__QUOTE(partClassName)), nullByDefault,\
00341                     SO__QUOTE(parentName),                                    \
00342                     SO__QUOTE(rightName), FALSE, SoType::badType(),           \
00343                     SoType::badType(), isPublicPart  ))                       \
00344         catalogError()
00345 
00346 
00383 
00384 #define SO_KIT_ADD_CATALOG_ABSTRACT_ENTRY(partName, partClassName,            \
00385                   defaultPartClassName, nullByDefault, parentName,            \
00386                   rightName, isPublicPart )                                   \
00387    SO_KIT_ADD_FIELD(partName,(NULL));                                         \
00388    if (firstInstance && !nodekitCatalog->addEntry(SO__QUOTE(partName),        \
00389                     SoType::fromName(SO__QUOTE(partClassName)),               \
00390                     SoType::fromName(SO__QUOTE(defaultPartClassName)), nullByDefault,\
00391                     SO__QUOTE(parentName), SO__QUOTE(rightName), FALSE,       \
00392                     SoType::badType(), SoType::badType(), isPublicPart  ))    \
00393         catalogError()
00394 
00434 
00435 #define SO_KIT_ADD_CATALOG_LIST_ENTRY(partName, listContainerClassName,       \
00436       nullByDefault, parentName, rightName, listItemClassName, isPublicPart ) \
00437     SO_KIT_ADD_FIELD(partName,(NULL));                                        \
00438     if (firstInstance && !nodekitCatalog->addEntry(SO__QUOTE(partName),       \
00439                   SoNodeKitListPart::getClassTypeId(),                        \
00440                   SoNodeKitListPart::getClassTypeId(), nullByDefault,         \
00441                   SO__QUOTE(parentName), SO__QUOTE(rightName), TRUE,          \
00442                   SoType::fromName(SO__QUOTE(listContainerClassName)),        \
00443                   SoType::fromName(SO__QUOTE(listItemClassName)), isPublicPart)) \
00444         catalogError()
00445 
00471 
00472 #define SO_KIT_ADD_LIST_ITEM_TYPE(partName, newListItemClassName )          \
00473     if (firstInstance) nodekitCatalog->addListItemType(SO__QUOTE(partName), \
00474           SoType::fromName(SO__QUOTE(newListItemClassName)) )
00475 
00517 
00518 #define SO_KIT_CHANGE_ENTRY_TYPE(partName, newPartClassName,                \
00519                                  newDefaultPartClassName)                   \
00520    if (firstInstance) nodekitCatalog->narrowTypes(SO__QUOTE(partName),      \
00521            SoType::fromName(SO__QUOTE(newPartClassName)),                     \
00522            SoType::fromName(SO__QUOTE(newDefaultPartClassName)))
00523 
00532 #define SO_KIT_CHANGE_NULL_BY_DEFAULT(partName, newNullByDefault)             \
00533    if (firstInstance) nodekitCatalog->setNullByDefault(SO__QUOTE(partName),   \
00534         newNullByDefault)
00535 
00548 #define SO_KIT_INIT_INSTANCE()   \
00549    createNodekitPartsList(); \
00550    createDefaultParts()
00551 
00552 
00553 #endif /* _SO_SUB_KIT_ */