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 SoMFVec2b SoMFVec2b.h Inventor/fields/SoMFVec2b.h
35 \brief The SoMFVec2b class is a container for SbVec2b vectors.
36
37 \ingroup fields
38
39 This field is used where nodes, engines or other field containers
40 needs to store an array of vectors with two elements.
41
42 This field supports application data sharing through a
43 setValuesPointer() method. See SoMField documentation for
44 information on how to use this function.
45
46 \sa SbVec2b, SoSFVec2b
47 \COIN_CLASS_EXTENSION
48 \since Coin 2.5
49 */
50
51 // *************************************************************************
52
53 #include <Inventor/fields/SoMFVec2b.h>
54
55 #include <cassert>
56
57 #include <Inventor/SoInput.h>
58 #include <Inventor/errors/SoDebugError.h>
59
60 #include "fields/SoSubFieldP.h"
61 #include "fields/shared.h"
62
63 // *************************************************************************
64
65 SO_MFIELD_SOURCE(SoMFVec2b, SbVec2b, SbVec2b);
66
67 SO_MFIELD_SETVALUESPOINTER_SOURCE(SoMFVec2b, SbVec2b, SbVec2b);
68 SO_MFIELD_SETVALUESPOINTER_SOURCE(SoMFVec2b, SbVec2b, int8_t);
69
70 // *************************************************************************
71
72 // Override from parent class.
73 void
initClass(void)74 SoMFVec2b::initClass(void)
75 {
76 SO_MFIELD_INTERNAL_INIT_CLASS(SoMFVec2b);
77 }
78
79 // *************************************************************************
80
81 // No need to document readValue() and writeValue() here, as the
82 // necessary information is provided by the documentation of the
83 // parent classes.
84 #ifndef DOXYGEN_SKIP_THIS
85
86 SbBool
read1Value(SoInput * in,int idx)87 SoMFVec2b::read1Value(SoInput * in, int idx)
88 {
89 assert(idx < this->maxNum);
90 return
91 in->readByte(this->values[idx][0]) &&
92 in->readByte(this->values[idx][1]);
93 }
94
95 void
write1Value(SoOutput * out,int idx) const96 SoMFVec2b::write1Value(SoOutput * out, int idx) const
97 {
98 sosfvec2b_write_value(out, (*this)[idx]);
99 }
100
101 #endif // DOXYGEN_SKIP_THIS
102
103 // *************************************************************************
104
105 /*!
106 Set \a num vector array elements from \a xy, starting at index
107 \a start.
108 */
109 void
setValues(int start,int numarg,const int8_t xy[][2])110 SoMFVec2b::setValues(int start, int numarg, const int8_t xy[][2])
111 {
112 if (start+numarg > this->maxNum) this->allocValues(start+numarg);
113 else if (start+numarg > this->num) this->num = start+numarg;
114
115 for(int i=0; i < numarg; i++) this->values[start+i] = SbVec2b(xy[i]);
116 this->valueChanged();
117 }
118
119 /*!
120 Set the vector at \a idx.
121 */
122 void
set1Value(int idx,int8_t x,int8_t y)123 SoMFVec2b::set1Value(int idx, int8_t x, int8_t y)
124 {
125 this->set1Value(idx, SbVec2b(x, y));
126 }
127
128 /*!
129 Set the vector at \a idx.
130 */
131 void
set1Value(int idx,const int8_t xy[2])132 SoMFVec2b::set1Value(int idx, const int8_t xy[2])
133 {
134 this->set1Value(idx, SbVec2b(xy));
135 }
136
137 /*!
138 Set this field to contain a single vector with the given
139 element values.
140 */
141 void
setValue(int8_t x,int8_t y)142 SoMFVec2b::setValue(int8_t x, int8_t y)
143 {
144 this->setValue(SbVec2b(x, y));
145 }
146
147 /*!
148 Set this field to contain a single vector with the given
149 element values.
150 */
151 void
setValue(const int8_t xy[2])152 SoMFVec2b::setValue(const int8_t xy[2])
153 {
154 if (xy == NULL) this->setNum(0);
155 else this->setValue(SbVec2b(xy));
156 }
157
158 // *************************************************************************
159
160 #ifdef COIN_TEST_SUITE
161
BOOST_AUTO_TEST_CASE(initialized)162 BOOST_AUTO_TEST_CASE(initialized)
163 {
164 SoMFVec2b field;
165 BOOST_CHECK_MESSAGE(field.getTypeId() != SoType::badType(),
166 "missing class initialization");
167 BOOST_CHECK_EQUAL(field.getNum(), 0);
168 }
169
170 #endif // COIN_TEST_SUITE
171