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 SoSFBox2f SoSFBox2f.h Inventor/fields/SoSFBox2f.h
35 \brief The SoSFBox2f class is a container for an SbBox2f vector.
36
37 \ingroup fields
38
39 This field is used where nodes, engines or other field containers
40 needs to store a box.
41
42 \COIN_CLASS_EXTENSION
43 \since Coin 2.5
44 */
45
46 // *************************************************************************
47
48 #include <Inventor/fields/SoSFBox2f.h>
49
50 #include <Inventor/SoInput.h>
51 #include <Inventor/SoOutput.h>
52 #include <Inventor/errors/SoDebugError.h>
53 #include <Inventor/errors/SoReadError.h>
54
55 #include "fields/SoSubFieldP.h"
56
57 // *************************************************************************
58
59 SO_SFIELD_SOURCE(SoSFBox2f, SbBox2f, const SbBox2f &);
60
61 // *************************************************************************
62
63 // Override from parent class.
64 void
initClass(void)65 SoSFBox2f::initClass(void)
66 {
67 SO_SFIELD_INTERNAL_INIT_CLASS(SoSFBox2f);
68 }
69
70 // No need to document readValue() and writeValue() here, as the
71 // necessary information is provided by the documentation of the
72 // parent classes.
73 #ifndef DOXYGEN_SKIP_THIS
74
75
76 SbBool
readValue(SoInput * in)77 SoSFBox2f::readValue(SoInput * in)
78 {
79 float min[2];
80 float max[2];
81 if (!in->read(min[0]) ||
82 !in->read(min[1]) ||
83 !in->read(max[0]) ||
84 !in->read(max[1])) {
85 SoReadError::post(in, "Couldn't read SoSFBox2f");
86 return FALSE;
87 }
88 this->setValue(min[0], min[1], max[0], max[1]);
89 return TRUE;
90 }
91
92 void
writeValue(SoOutput * out) const93 SoSFBox2f::writeValue(SoOutput * out) const
94 {
95 float min[2];
96 float max[2];
97 SbBox2f b = this->getValue();
98 b.getBounds(min[0], min[1], max[0], max[1]);
99
100 out->write(min[0]);
101 if (!out->isBinary()) out->write(' ');
102 out->write(min[1]);
103 if (!out->isBinary()) out->write(' ');
104 out->write(max[0]);
105 if (!out->isBinary()) out->write(' ');
106 out->write(max[1]);
107 }
108
109 #endif // DOXYGEN_SKIP_THIS
110
111 // *************************************************************************
112
113 /*!
114 Set value of vector.
115 */
116 void
setValue(float xmin,float ymin,float xmax,float ymax)117 SoSFBox2f::setValue(float xmin, float ymin, float xmax, float ymax)
118 {
119 this->setValue(SbBox2f(xmin, ymin, xmax, ymax));
120 }
121
122
123 /*!
124 Set value of vector.
125 */
126 void
setValue(const SbVec2f & minvec,const SbVec2f & maxvec)127 SoSFBox2f::setValue(const SbVec2f & minvec, const SbVec2f & maxvec)
128 {
129 this->setValue(SbBox2f(minvec, maxvec));
130 }
131
132
133 /*!
134 Set value of vector.
135 */
136 void
getValue(SbBox2f & box) const137 SoSFBox2f::getValue(SbBox2f & box) const
138 {
139 box = value;
140 }
141
142 // *************************************************************************
143
144 #ifdef COIN_TEST_SUITE
145
BOOST_AUTO_TEST_CASE(initialized)146 BOOST_AUTO_TEST_CASE(initialized)
147 {
148 SoSFBox2f field;
149 BOOST_CHECK_MESSAGE(SoSFBox2f::getClassTypeId() != SoType::badType(),
150 "SoSFBox2f class not initialized");
151 BOOST_CHECK_MESSAGE(field.getTypeId() != SoType::badType(),
152 "missing class initialization");
153 }
154
155 #endif // COIN_TEST_SUITE
156