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 SoSFBox2i32 SoSFBox2i32.h Inventor/fields/SoSFBox2i32.h
35 \brief The SoSFBox2i32 class is a container for an SbBox2i32 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/SoSFBox2i32.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(SoSFBox2i32, SbBox2i32, const SbBox2i32 &);
60
61 // *************************************************************************
62
63 // Override from parent class.
64 void
initClass(void)65 SoSFBox2i32::initClass(void)
66 {
67 SO_SFIELD_INTERNAL_INIT_CLASS(SoSFBox2i32);
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 SoSFBox2i32::readValue(SoInput * in)
78 {
79 int32_t min[2];
80 int32_t 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 SoSFBox2i32");
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 SoSFBox2i32::writeValue(SoOutput * out) const
94 {
95 int32_t min[2];
96 int32_t max[2];
97 SbBox2i32 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(int32_t xmin,int32_t ymin,int32_t xmax,int32_t ymax)117 SoSFBox2i32::setValue(int32_t xmin, int32_t ymin, int32_t xmax, int32_t ymax)
118 {
119 this->setValue(SbBox2i32(xmin, ymin, xmax, ymax));
120 }
121
122
123 /*!
124 Set value of vector.
125 */
126 void
setValue(const SbVec2i32 & minvec,const SbVec2i32 & maxvec)127 SoSFBox2i32::setValue(const SbVec2i32 & minvec, const SbVec2i32 & maxvec)
128 {
129 this->setValue(SbBox2i32(minvec, maxvec));
130 }
131
132
133 /*!
134 Set value of vector.
135 */
136 void
getValue(SbBox2i32 & box) const137 SoSFBox2i32::getValue(SbBox2i32 & 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 SoSFBox2i32 field;
149 BOOST_CHECK_MESSAGE(SoSFBox2i32::getClassTypeId() != SoType::badType(),
150 "SoSFBox2i32 class not initialized");
151 BOOST_CHECK_MESSAGE(field.getTypeId() != SoType::badType(),
152 "missing class initialization");
153 }
154
155 #endif // COIN_TEST_SUITE
156