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 SoProfileCoordinateElement Inventor/elements/SoProfileCoordinateElement.h
35 \brief The SoProfileCoordinateElement class is yet to be documented.
36
37 \ingroup elements
38
39 FIXME: write doc.
40 */
41
42 #include <Inventor/elements/SoProfileCoordinateElement.h>
43
44 #include "tidbitsp.h"
45 #include "SbBasicP.h"
46
47 #include <cassert>
48
49 #include <Inventor/nodes/SoNode.h>
50
51 SbVec2f * SoProfileCoordinateElement::initdefaultcoords = NULL;
52
53 /*!
54 \var SoProfileCoordinateElement::numCoords
55
56 FIXME: write doc.
57 */
58
59 /*!
60 \var SoProfileCoordinateElement::coords2
61
62 FIXME: write doc.
63 */
64
65 /*!
66 \var SoProfileCoordinateElement::coords3
67
68 FIXME: write doc.
69 */
70
71 /*!
72 \var SoProfileCoordinateElement::coordsAre2D
73
74 FIXME: write doc.
75 */
76
77 SO_ELEMENT_SOURCE(SoProfileCoordinateElement);
78
79 // doc from parent
80 void
initClass(void)81 SoProfileCoordinateElement::initClass(void)
82 {
83 SO_ELEMENT_INIT_CLASS(SoProfileCoordinateElement, inherited);
84
85 SoProfileCoordinateElement::initdefaultcoords = new SbVec2f(0.0f, 0.0f);
86
87 coin_atexit(reinterpret_cast<coin_atexit_f *>(SoProfileCoordinateElement::clean), CC_ATEXIT_NORMAL);
88 }
89
90 void
clean(void)91 SoProfileCoordinateElement::clean(void)
92 {
93 delete SoProfileCoordinateElement::initdefaultcoords;
94 }
95
96 /*!
97 The destructor.
98 */
~SoProfileCoordinateElement(void)99 SoProfileCoordinateElement::~SoProfileCoordinateElement(void)
100 {
101 }
102
103 // doc from parent
104 void
init(SoState * state)105 SoProfileCoordinateElement::init(SoState * state)
106 {
107 inherited::init(state);
108 this->numCoords = 1;
109 this->coords2 = SoProfileCoordinateElement::initdefaultcoords;
110 this->coords3 = NULL;
111 this->coordsAre2D = TRUE;
112 }
113
114
115 /*!
116 Sets the profile coordinates.
117 */
118 void
set2(SoState * const state,SoNode * const node,const int32_t numCoords,const SbVec2f * const coords)119 SoProfileCoordinateElement::set2(SoState * const state,
120 SoNode * const node,
121 const int32_t numCoords,
122 const SbVec2f * const coords)
123 {
124 assert(numCoords >= 0);
125 SoProfileCoordinateElement * element =
126 coin_safe_cast<SoProfileCoordinateElement *>
127 (getElement(state, classStackIndex, NULL));
128 if (element) {
129 element->numCoords = numCoords;
130 element->coords2 = coords;
131 element->coords3 = NULL;
132 element->coordsAre2D = TRUE;
133 element->nodeId = node->getNodeId();
134 }
135 }
136
137 /*!
138 Sets the profile coordinates.
139 */
140 void
set3(SoState * const state,SoNode * const node,const int32_t numCoords,const SbVec3f * const coords)141 SoProfileCoordinateElement::set3(SoState * const state,
142 SoNode * const node,
143 const int32_t numCoords,
144 const SbVec3f * const coords)
145 {
146 assert(numCoords >= 0);
147 SoProfileCoordinateElement * element =
148 coin_safe_cast<SoProfileCoordinateElement *>
149 (getElement(state, classStackIndex, NULL));
150 if (element) {
151 element->numCoords = numCoords;
152 element->coords2 = NULL;
153 element->coords3 = coords;
154 element->coordsAre2D = FALSE;
155 element->nodeId = node->getNodeId();
156 }
157 }
158
159 /*!
160 Returns the current element.
161 */
162 const SoProfileCoordinateElement *
getInstance(SoState * const state)163 SoProfileCoordinateElement::getInstance(SoState * const state)
164 {
165 return coin_assert_cast<const SoProfileCoordinateElement *>
166 (SoElement::getConstElement(state, classStackIndex));
167 }
168
169 /*!
170 Returns the number of profile coordinates in this element.
171 */
172 int32_t
getNum(void) const173 SoProfileCoordinateElement::getNum(void) const
174 {
175 return this->numCoords;
176 }
177
178 /*!
179 Returns the \a index'th 2D coordinate.
180 \sa is2D()
181 */
182 const SbVec2f &
get2(const int index) const183 SoProfileCoordinateElement::get2(const int index) const
184 {
185 assert(index >= 0 && index < this->numCoords);
186 assert(this->coordsAre2D);
187 return this->coords2[ index ];
188 }
189
190 /*!
191 Returns the \a index'th 3D coordinate.
192 \sa is2D()
193 */
194 const SbVec3f &
get3(const int index) const195 SoProfileCoordinateElement::get3(const int index) const
196 {
197 assert(index >= 0 && index < this->numCoords);
198 assert(! this->coordsAre2D);
199 return this->coords3[ index ];
200 }
201
202 /*!
203 Returns if this element contains 2D coordinates.
204 */
205 SbBool
is2D(void) const206 SoProfileCoordinateElement::is2D(void) const
207 {
208 return this->coordsAre2D;
209 }
210
211 /*!
212 Returns the default 2D coordinate.
213 */
214 SbVec2f
getDefault2(void)215 SoProfileCoordinateElement::getDefault2(void)
216 {
217 return SbVec2f(0.0f, 0.0f);
218 }
219
220 /*!
221 Returns the default 3D coordinate.
222 */
223 SbVec3f
getDefault3(void)224 SoProfileCoordinateElement::getDefault3(void)
225 {
226 return SbVec3f(0.0f, 0.0f, 1.0f);
227 }
228
229 /*!
230 Returns a pointer to the 2D coordinates.
231 */
232 const SbVec2f *
getArrayPtr2(void) const233 SoProfileCoordinateElement::getArrayPtr2(void) const
234 {
235 return this->coords2;
236 }
237
238 /*!
239 Returns a pointer to the 3D coordinates.
240 */
241 const SbVec3f *
getArrayPtr3(void) const242 SoProfileCoordinateElement::getArrayPtr3(void) const
243 {
244 return this->coords3;
245 }
246