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 #include <Inventor/annex/HardCopy/SoVectorOutput.h>
34
35 #include <Inventor/SbBasic.h>
36
37 #include "tidbitsp.h"
38
39 // *************************************************************************
40
41 /*!
42 \class SoVectorOutput SoVectorOutput.h Inventor/annex/HardCopy/SoVectorOutput.h
43 \brief The SoVectorOutput class is used for setting vector output file.
44
45 \ingroup hardcopy
46
47 SoVectorizeAction will create an SoVectorOutput which will output
48 to stdout by default. SoVectorizeAction::getOutput() can be used to
49 fetch this output, and the user will probably want to set a
50 file to output to.
51
52 \since Coin 2.1
53 \since TGS provides HardCopy support as a separate extension for TGS Inventor.
54 */
55
56 class SoVectorOutputP {
57 public:
58 FILE * fp;
59 SbBool didopen;
60 };
61
62 #define PRIVATE(p) (p->pimpl)
63 #define PUBLIC(p) (p->publ)
64
65 // *************************************************************************
66
67 /*!
68 Constructor. Will make this instance output to \e stdout.
69 */
SoVectorOutput(void)70 SoVectorOutput::SoVectorOutput(void)
71 {
72 PRIVATE(this) = new SoVectorOutputP;
73 PRIVATE(this)->fp = coin_get_stdout();
74 PRIVATE(this)->didopen = FALSE;
75 }
76
77 /*!
78 Destructor. Will close the file opened in openFile().
79 */
~SoVectorOutput()80 SoVectorOutput::~SoVectorOutput()
81 {
82 this->closeFile();
83 delete PRIVATE(this);
84 }
85
86 // *************************************************************************
87
88 /*!
89 Opens \a filename for output. Returns \e FALSE if file could not be
90 opened for writing. If the file already exists, it will be
91 truncated.
92 */
93 SbBool
openFile(const char * filename)94 SoVectorOutput::openFile(const char * filename)
95 {
96 this->closeFile();
97
98 FILE * fp = fopen(filename, "wb");
99 if (fp) {
100 PRIVATE(this)->fp = fp;
101 PRIVATE(this)->didopen = TRUE;
102 }
103 return fp != NULL;
104 }
105
106 /*!
107 Closes the file opened in openFile()
108 */
109 void
closeFile(void)110 SoVectorOutput::closeFile(void)
111 {
112 if (PRIVATE(this)->didopen) {
113 fclose(PRIVATE(this)->fp);
114 PRIVATE(this)->fp = stdout;
115 PRIVATE(this)->didopen = FALSE;
116 }
117 }
118
119 /*!
120 Returns the \e stdio file handle pointer.
121 */
122 FILE *
getFilePointer(void)123 SoVectorOutput::getFilePointer(void)
124 {
125 return PRIVATE(this)->fp;
126 }
127
128 #undef PRIVATE
129 #undef PUBLIC
130