1 /**************************************************************************\
2  * Copyright (c) Kongsberg Oil & Gas Technologies AS
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * Redistributions of source code must retain the above copyright notice,
10  * this list of conditions and the following disclaimer.
11  *
12  * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * Neither the name of the copyright holder nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 \**************************************************************************/
32 
33 #ifdef HAVE_CONFIG_H
34 #include "config.h"
35 #endif // HAVE_CONFIG_H
36 
37 #ifdef HAVE_NODEKITS
38 
39 /*!
40   \class SoSceneKit SoSceneKit.h Inventor/nodekits/SoSceneKit.h
41   \brief The SoSceneKit class collects node kits needed to set up a scene: camera, light and shapes.
42 
43   \ingroup nodekits
44 
45   \NODEKIT_PRE_DIAGRAM
46 
47   \verbatim
48   CLASS SoSceneKit
49   -->"this"
50         "callbackList"
51   -->   "topSeparator"
52   -->      "cameraList"
53   -->      "lightList"
54   -->      "childList"
55   \endverbatim
56 
57   \NODEKIT_POST_DIAGRAM
58 
59 
60   \NODEKIT_PRE_TABLE
61 
62   \verbatim
63   CLASS SoSceneKit
64   PVT   "this",  SoSceneKit  ---
65         "callbackList",  SoNodeKitListPart [ SoCallback, SoEventCallback ]
66   PVT   "topSeparator",  SoSeparator  ---
67         "cameraList",  SoNodeKitListPart [ SoCameraKit ]
68         "lightList",  SoNodeKitListPart [ SoLightKit ]
69         "childList",  SoNodeKitListPart [ SoShapeKit, SoSeparatorKit ]
70   \endverbatim
71 
72   \NODEKIT_POST_TABLE
73 */
74 
75 #include <Inventor/nodekits/SoSceneKit.h>
76 
77 #include <Inventor/nodekits/SoCameraKit.h>
78 #include <Inventor/nodekits/SoLightKit.h>
79 #include <Inventor/nodekits/SoShapeKit.h>
80 #include <Inventor/nodekits/SoNodeKitListPart.h>
81 #include <Inventor/nodes/SoSeparator.h>
82 #include <Inventor/nodes/SoSwitch.h>
83 #if COIN_DEBUG
84 #include <Inventor/errors/SoDebugError.h>
85 #endif // COIN_DEBUG
86 
87 #include  "nodekits/SoSubKitP.h"
88 
89 SO_KIT_SOURCE(SoSceneKit);
90 
91 
92 /*!
93   Constructor.
94 */
SoSceneKit(void)95 SoSceneKit::SoSceneKit(void)
96 {
97   SO_KIT_INTERNAL_CONSTRUCTOR(SoSceneKit);
98 
99   // Note: we must use "" instead of , , to humour MS VisualC++ 6.
100 
101   SO_KIT_ADD_CATALOG_ENTRY(topSeparator, SoSeparator, TRUE, this, "", FALSE);
102   SO_KIT_ADD_CATALOG_LIST_ENTRY(cameraList, SoSwitch, TRUE, topSeparator, lightList, SoCameraKit, TRUE);
103   SO_KIT_ADD_CATALOG_LIST_ENTRY(lightList, SoGroup, TRUE, topSeparator, childList, SoLightKit, TRUE);
104   SO_KIT_ADD_CATALOG_LIST_ENTRY(childList, SoGroup, TRUE, topSeparator, "", SoShapeKit, TRUE);
105   SO_KIT_ADD_LIST_ITEM_TYPE(childList, SoSeparatorKit);
106 
107   SO_KIT_INIT_INSTANCE();
108 }
109 
110 /*!
111   Destructor.
112 */
~SoSceneKit()113 SoSceneKit::~SoSceneKit()
114 {
115 }
116 
117 // doc from superclass
118 void
initClass(void)119 SoSceneKit::initClass(void)
120 {
121   SO_KIT_INTERNAL_INIT_CLASS(SoSceneKit, SO_FROM_INVENTOR_1);
122 }
123 
124 /*!
125   Returns the index of the current active camera in cameraList.
126 */
127 int
getCameraNumber(void)128 SoSceneKit::getCameraNumber(void)
129 {
130   SoSwitch *sw = (SoSwitch*)this->getContainerNode(SbName("cameraList"));
131   return sw->whichChild.getValue();
132 }
133 
134 /*!
135   Sets the current active camera in cameraList.
136 */
137 void
setCameraNumber(int camnum)138 SoSceneKit::setCameraNumber(int camnum)
139 {
140   SoSwitch *sw = (SoSwitch*)this->getContainerNode(SbName("cameraList"));
141 #if COIN_DEBUG && 1 // debug
142   if (camnum >= sw->getNumChildren()) {
143     SoDebugError::postInfo("SoSceneKit::setCameraNumber",
144                            "camera number %d is too large", camnum);
145     return;
146   }
147 #endif // debug
148   sw->whichChild = camnum;
149 }
150 
151 // Documented in superclass.
152 SbBool
affectsState(void) const153 SoSceneKit::affectsState(void) const
154 {
155   return TRUE;
156 }
157 
158 #endif // HAVE_NODEKITS
159