1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2  *
3  * This library is open source and may be redistributed and/or modified under
4  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5  * (at your option) any later version.  The full license is in LICENSE file
6  * included with this distribution, and on the openscenegraph.org website.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * OpenSceneGraph Public License for more details.
12 */
13 
14 //
15 // OpenFlight� loader for OpenSceneGraph
16 //
17 //  Copyright (C) 2005-2007  Brede Johansen
18 //
19 
20 #include <assert.h>
21 #include <osg/Geode>
22 #include <osg/Geometry>
23 #include "Registry.h"
24 #include "Document.h"
25 #include "RecordInputStream.h"
26 
27 namespace flt {
28 
29 
30 
31 /** PushLevel
32 */
33 class PushLevel : public Record
34 {
35     public:
36 
37         PushLevel() {}
38 
39         META_Record(PushLevel)
40 
41         virtual void readRecord(RecordInputStream& /*in*/, Document& document)
42         {
43             document.pushLevel();
44         }
45 
46     protected:
47 
48         virtual ~PushLevel() {}
49 };
50 
51 REGISTER_FLTRECORD(PushLevel, PUSH_LEVEL_OP)
52 
53 
54 
55 /** PophLevel
56 */
57 class PopLevel : public Record
58 {
59     public:
60 
61         PopLevel() {}
62 
63         META_Record(PopLevel)
64 
65         virtual void read(RecordInputStream& /*in*/, Document& document)
66         {
67             PrimaryRecord* parentPrimary = document.getTopOfLevelStack();
68             PrimaryRecord* currentPrimary = document.getCurrentPrimaryRecord();
69 
70             // Call dispose() for primary without push, pop level pair.
71             if (currentPrimary && currentPrimary!=parentPrimary)
72             {
73                 currentPrimary->dispose(document);
74             }
75 
76             // Call dispose() for primary with push, pop level pair.
77             if (parentPrimary)
78             {
79                 parentPrimary->dispose(document);
80             }
81 
82             document.popLevel();
83         }
84 
85     protected:
86 
87         virtual ~PopLevel() {}
88 };
89 
90 REGISTER_FLTRECORD(PopLevel, POP_LEVEL_OP)
91 
92 
93 
94 /** PushSubface
95 */
96 class PushSubface : public Record
97 {
98     public:
99 
100         PushSubface() {}
101 
102         META_Record(PushSubface)
103 
104         virtual void read(RecordInputStream& /*in*/, Document& document)
105         {
106             document.pushSubface();
107         }
108 
109     protected:
110 
111         virtual ~PushSubface() {}
112 };
113 
114 REGISTER_FLTRECORD(PushSubface, PUSH_SUBFACE_OP)
115 
116 
117 
118 /** PopSubface
119 */
120 class PopSubface : public Record
121 {
122     public:
123 
124         PopSubface() {}
125 
126         META_Record(PopSubface)
127 
128         virtual void read(RecordInputStream& /*in*/, Document& document)
129         {
130             document.popSubface();
131         }
132 
133     protected:
134 
135         virtual ~PopSubface() {}
136 };
137 
138 REGISTER_FLTRECORD(PopSubface, POP_SUBFACE_OP)
139 
140 
141 
142 /** PushExtension
143 */
144 class PushExtension : public Record
145 {
146     public:
147 
148         PushExtension() {}
149 
150         META_Record(PushExtension)
151 
152         virtual void read(RecordInputStream& in, Document& document)
153         {
154             readRecord(in,document);
155             document.pushExtension();
156         }
157 
158     protected:
159 
160         virtual ~PushExtension() {}
161 };
162 
163 REGISTER_FLTRECORD(PushExtension, PUSH_EXTENSION_OP)
164 
165 
166 
167 /** PopExtension
168 */
169 class PopExtension : public Record
170 {
171     public:
172 
173         PopExtension() {}
174 
175         META_Record(PopExtension)
176 
177         virtual void read(RecordInputStream& in, Document& document)
178         {
179             readRecord(in,document);
180             document.popExtension();
181         }
182 
183     protected:
184 
185         virtual ~PopExtension() {}
186 };
187 
188 REGISTER_FLTRECORD(PopExtension, POP_EXTENSION_OP)
189 
190 
191 
192 /** PushAttribute - Reserved subtree
193 */
194 class PushAttribute : public Record
195 {
196     public:
197 
198         PushAttribute() {}
199 
200         META_Record(PushAttribute)
201 
202         virtual void read(RecordInputStream& in, Document& document)
203         {
204             readRecord(in,document);
205         }
206 
207     protected:
208 
209         virtual ~PushAttribute() {}
210 };
211 
212 REGISTER_FLTRECORD(PushAttribute, PUSH_ATTRIBUTE_OP)
213 
214 
215 
216 /** PopAttribute
217 */
218 class PopAttribute : public Record
219 {
220     public:
221 
222         PopAttribute() {}
223 
224         META_Record(PopAttribute)
225 
226         virtual void read(RecordInputStream& in, Document& document)
227         {
228             readRecord(in,document);
229         }
230 
231     protected:
232 
233         virtual ~PopAttribute() {}
234 };
235 
236 REGISTER_FLTRECORD(PopAttribute, POP_ATTRIBUTE_OP)
237 
238 
239 
240 } // end namespace
241 
242 
243 
244