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 /*!
34   \class SoInteraction SoInteraction.h Inventor/SoInteraction.h
35   \brief The SoInteraction class takes care of initalizing internal classes.
36 
37   \ingroup general
38 
39   SoInteraction is present for the sole purpose of providing an
40   interface to the initialization methods of the classes in Coin which
41   are somehow related to user interaction, like the draggers and
42   manipulators.
43 
44   It is unlikely that the application programmer should need to worry
45   about this class, as SoInteraction::init() is called by the GUI
46   specific initialization methods.
47 
48  */
49 
50 #include <Inventor/SoInteraction.h>
51 
52 #ifdef HAVE_CONFIG_H
53 #include "config.h"
54 #endif // HAVE_CONFIG_H
55 
56 #include <Inventor/SoDB.h>
57 #include <Inventor/nodes/SoAntiSquish.h>
58 #include <Inventor/nodes/SoExtSelection.h>
59 #include <Inventor/nodes/SoSurroundScale.h>
60 
61 #include <Inventor/nodekits/SoNodeKit.h>
62 #ifdef HAVE_NODEKITS
63 #include <Inventor/nodekits/SoInteractionKit.h>
64 #endif // HAVE_NODEKITS
65 
66 #ifdef HAVE_DRAGGERS
67 #include <Inventor/draggers/SoDragger.h>
68 #endif // HAVE_DRAGGERS
69 
70 #ifdef HAVE_MANIPULATORS
71 #include <Inventor/manips/SoCenterballManip.h>
72 #include <Inventor/manips/SoClipPlaneManip.h>
73 #include <Inventor/manips/SoDirectionalLightManip.h>
74 #include <Inventor/manips/SoHandleBoxManip.h>
75 #include <Inventor/manips/SoJackManip.h>
76 #include <Inventor/manips/SoPointLightManip.h>
77 #include <Inventor/manips/SoSpotLightManip.h>
78 #include <Inventor/manips/SoTabBoxManip.h>
79 #include <Inventor/manips/SoTrackballManip.h>
80 #include <Inventor/manips/SoTransformBoxManip.h>
81 #include <Inventor/manips/SoTransformerManip.h>
82 #endif // HAVE_MANIPULATORS
83 
84 #include "tidbitsp.h"
85 
86 static SbBool interaction_isinitialized = FALSE;
87 
interaction_cleanup(void)88 static void interaction_cleanup(void)
89 {
90   interaction_isinitialized = FALSE;
91 }
92 
93 /*!
94   Calls the initClass() method of these classes: SoAntiSquish,
95   SoSelection, SoExtSelection, SoSurroundScale, SoInteractionKit,
96   SoDragger, SoClipPlaneManip, SoDirectionalLightManip,
97   SoPointLightManip, SoSpotLightManip, SoTransformManip,
98   SoCenterballManip, SoHandleBoxManip, SoJackManip, SoTabBoxManip,
99   SoTrackballManip, SoTransformBoxManip, SoTransformerManip.
100 
101   Note that this method calls SoDB::init() and SoNodeKit::init() to
102   make sure all classes that the interaction functionality depends on
103   have been initialized.
104 
105 
106   Application programmers should usually not have to invoke this method
107   directly from application code, as it is indirectly called from the
108   GUI-binding libraries' init()-functions.  Only if you are using your own
109   GUI-binding (and not one of Kongsberg Oil & Gas Technologies's SoQt, SoGtk,
110   SoXt, SoWin, Sc21 etc. libraries) do you have to explicitly call
111   SoInteraction::init().
112 
113   \code
114   int main(int argc, char ** argv )
115   {
116     // SoQt::init() calls SoDB::init(), SoNodeKit::init() and
117     // SoInteraction::init().
118     QWidget * window = SoQt::init( argv[0] );
119 
120     SoSeparator * root = make_scenegraph();
121     root->ref();
122     /// [... etc ...] ///
123   \endcode
124 
125  */
126 void
init(void)127 SoInteraction::init(void)
128 {
129   if (interaction_isinitialized) return;
130 
131   if (!SoDB::isInitialized()) SoDB::init();
132 
133   SoAntiSquish::initClass();
134   SoSelection::initClass();
135   SoExtSelection::initClass();
136   SoSurroundScale::initClass();
137 
138   SoNodeKit::init();
139 #ifdef HAVE_NODEKITS
140   SoInteractionKit::initClass();
141 #endif // HAVE_NODEKITS
142 
143 #ifdef HAVE_DRAGGERS
144   SoDragger::initClass();
145 #endif // HAVE_DRAGGERS
146 
147 #ifdef HAVE_MANIPULATORS
148   SoClipPlaneManip::initClass();
149   SoDirectionalLightManip::initClass();
150   SoPointLightManip::initClass();
151   SoSpotLightManip::initClass();
152   SoTransformManip::initClass();
153   SoCenterballManip::initClass();
154   SoHandleBoxManip::initClass();
155   SoJackManip::initClass();
156   SoTabBoxManip::initClass();
157   SoTrackballManip::initClass();
158   SoTransformBoxManip::initClass();
159   SoTransformerManip::initClass();
160 #endif // HAVE_MANIPULATORS
161 
162   interaction_isinitialized = TRUE;
163   coin_atexit((coin_atexit_f*)interaction_cleanup, CC_ATEXIT_NORMAL);
164 }
165