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