KiCad PCB EDA Suite
Loading...
Searching...
No Matches
wrlproc.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2015 Cirilo Bernardo <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#include <iostream>
22#include <sstream>
23#include <wx/string.h>
24#include <wx/log.h>
25#include "wrlproc.h"
26#include <wx_filename.h>
27
28#define GETLINE \
29 do \
30 { \
31 try \
32 { \
33 char* cp = m_file->ReadLine(); \
34 \
35 if( nullptr == cp ) \
36 { \
37 m_eof = true; \
38 m_buf.clear(); \
39 } \
40 else \
41 { \
42 m_buf = cp; \
43 m_bufpos = 0; \
44 } \
45 \
46 m_fileline = m_file->LineNumber(); \
47 } \
48 catch( ... ) \
49 { \
50 m_error = " * [INFO] input line too long"; \
51 m_eof = true; \
52 m_buf.clear(); \
53 } \
54 } while( 0 )
55
56
58{
60 m_eof = false;
61 m_fileline = 0;
62 m_bufpos = 0;
63 m_file = aLineReader;
64
65 if( nullptr == aLineReader )
66 {
67 m_eof = true;
68 return;
69 }
70
71 m_error.clear();
72 wxString tname = m_file->GetSource();
73 m_filename = tname.ToUTF8();
74 wxFileName fn( tname );
75
76 if( fn.IsRelative() )
77 fn.Normalize( FN_NORMALIZE_FLAGS | wxPATH_NORM_ENV_VARS );
78
79 m_filedir = fn.GetPathWithSep().ToUTF8();
80
81 m_buf.clear();
82 GETLINE;
83
84 if( m_eof )
85 return;
86
87 if( m_buf.compare( 0, 16, "#VRML V1.0 ascii" ) == 0 )
88 {
90 // nothing < 0x20, and no:
91 // single or double quote
92 // backslash
93 // curly brace
94 // plus
95 // period
96 m_badchars = "\"'\\{}+.";
97 return;
98 }
99
100 if( m_buf.compare( 0, 15, "#VRML V2.0 utf8" ) == 0 )
101 {
103 // nothing < 0x20, and no:
104 // single or double quotes
105 // sharp (#)
106 // plus
107 // minus
108 // comma
109 // period
110 // square brackets []
111 // curly braces {}
112 // backslash
113 // NOTE: badchars should include '-' but due to my bad model naming scheme
114 // in the VRML model generator, I have allowed '-'. Other VRML parsers seem to
115 // accept '-'. FreeCAD produces names with '+' in them so '+' has been allowed
116 // as well; '+' is not even valid for VRML1.
117 //m_badchars = "'\"#,.+-[]\\{}";
118 m_badchars = "'\"#,.[]\\{}";
119 return;
120 }
121
122 m_buf.clear();
124 m_eof = true;
125
126 m_error = "not a valid VRML file: '";
127 m_error.append( m_filename );
128 m_error.append( 1, '\'' );
129 m_badchars.clear();
130}
131
132
136
137
139{
140 m_error.clear();
141
142 if( !m_file )
143 {
144 m_error = "no open file";
145 return false;
146 }
147
148 if( m_bufpos >= m_buf.size() )
149 m_buf.clear();
150
151 if( !m_buf.empty() )
152 return true;
153
154 if( m_eof )
155 return false;
156
157 GETLINE;
158
159 if( m_eof && m_buf.empty() )
160 return false;
161
162 // strip the EOL characters
163 while( !m_buf.empty() && ( *m_buf.rbegin() == '\r' || *m_buf.rbegin() == '\n' ) )
164 m_buf.erase( --m_buf.end() );
165
166 if( WRLVERSION::VRML_V1 == m_fileVersion && !m_buf.empty() )
167 {
168 std::string::iterator sS = m_buf.begin();
169 std::string::iterator eS = m_buf.end();
170
171 while( sS != eS )
172 {
173 if( ( ( *sS ) & 0x80 ) )
174 {
175 m_error = " non-ASCII character sequence in VRML1 file";
176 return false;
177 }
178
179 ++sS;
180 }
181 }
182
183 return true;
184}
185
186
188{
189 if( !m_file )
190 {
191 m_error = "no open file";
192 return false;
193 }
194
195 if( m_bufpos >= m_buf.size() )
196 m_buf.clear();
197
198RETRY:
199 while( m_buf.empty() && !m_eof )
200 getRawLine();
201
202 // buffer may be empty if we have reached EOF or encountered IO errors
203 if( m_buf.empty() )
204 return false;
205
206 // eliminate leading white space (including control characters and comments)
207 while( m_bufpos < m_buf.size() )
208 {
209 if( m_buf[m_bufpos] > 0x20 )
210 break;
211
212 ++m_bufpos;
213 }
214
215 if( m_bufpos == m_buf.size() || '#' == m_buf[m_bufpos] )
216 {
217 // lines consisting entirely of white space are not unusual
218 m_buf.clear();
219 goto RETRY;
220 }
221
222 return true;
223}
224
225
227{
228 return m_fileVersion;
229}
230
231
232const char* WRLPROC::GetParentDir( void )
233{
234 if( m_filedir.empty() )
235 return nullptr;
236
237 return m_filedir.c_str();
238}
239
240
241bool WRLPROC::ReadGlob( std::string& aGlob )
242{
243 aGlob.clear();
244
245 if( !m_file )
246 {
247 m_error = "no open file";
248 return false;
249 }
250
251 while( true )
252 {
253 if( !EatSpace() )
254 return false;
255
256 // if the text is the start of a comment block, clear the buffer and loop
257 if( '#' == m_buf[m_bufpos] )
258 m_buf.clear();
259 else
260 break;
261 }
262
263 size_t ssize = m_buf.size();
264
265 while( m_bufpos < ssize && m_buf[m_bufpos] > 0x20 )
266 {
267 if( ',' == m_buf[m_bufpos] )
268 {
269 // the comma is a special instance of blank space
270 ++m_bufpos;
271 return true;
272 }
273
274 if( '{' == m_buf[m_bufpos] || '}' == m_buf[m_bufpos]
275 || '[' == m_buf[m_bufpos] || ']' == m_buf[m_bufpos] )
276 return true;
277
278 aGlob.append( 1, m_buf[m_bufpos++] );
279 }
280
281 return true;
282}
283
284
285bool WRLPROC::ReadName( std::string& aName )
286{
287 aName.clear();
288
289 if( !m_file )
290 {
291 m_error = "no open file";
292 return false;
293 }
294
295 while( true )
296 {
297 if( !EatSpace() )
298 return false;
299
300 // if the text is the start of a comment block, clear the buffer and loop
301 if( '#' == m_buf[m_bufpos] )
302 m_buf.clear();
303 else
304 break;
305 }
306
307 size_t ssize = m_buf.size();
308
309 while( m_bufpos < ssize && m_buf[m_bufpos] > 0x20 )
310 {
311 if( '[' == m_buf[m_bufpos] || '{' == m_buf[m_bufpos]
312 || ']' == m_buf[m_bufpos] || '}' == m_buf[m_bufpos]
313 || '.' == m_buf[m_bufpos] || '#' == m_buf[m_bufpos]
314 || ',' == m_buf[m_bufpos] )
315 {
316 if( !aName.empty() )
317 {
318 return true;
319 }
320 else
321 {
322 std::ostringstream ostr;
323 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
324 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
325 ostr << " * [INFO] line " << m_fileline << ", column " << m_bufpos;
326 ostr << " -- invalid name";
327 m_error = ostr.str();
328
329 return false;
330 }
331 }
332
333 if( m_badchars.find( m_buf[m_bufpos] ) != std::string::npos )
334 {
335 std::ostringstream ostr;
336 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
337 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
338 ostr << " * [INFO] line " << m_fileline << ", column " << m_bufpos;
339 ostr << " -- invalid character in name";
340 m_error = ostr.str();
341
342 return false;
343 }
344
345 if( aName.empty() && m_buf[m_bufpos] >= '0' && m_buf[m_bufpos] <= '9' )
346 {
347 std::ostringstream ostr;
348 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
349 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
350 ostr << " * [INFO] line " << m_fileline << ", column " << m_bufpos;
351 ostr << " -- name must not start with a digit";
352 m_error = ostr.str();
353
354 return false;
355 }
356
357 aName.append( 1, m_buf[m_bufpos++] );
358 }
359
360 return true;
361}
362
363
365{
366 if( !m_file )
367 {
368 m_error = "no open file";
369 return false;
370 }
371
372 if( !EatSpace() )
373 {
374 std::ostringstream ostr;
375 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
376 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
377 ostr << " * [INFO] " << m_error;
378 m_error = ostr.str();
379
380 return false;
381 }
382
383 if( '{' != m_buf[m_bufpos] )
384 {
385 std::ostringstream ostr;
386 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
387 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
388 ostr << " * [INFO] expecting character '{' at line " << m_fileline;
389 ostr << ", column " << m_bufpos;
390 m_error = ostr.str();
391
392 wxLogTrace( traceVrmlPlugin, "%s\n", m_error.c_str() );
393
394 return false;
395 }
396
397 size_t fileline = m_fileline;
398 size_t linepos = m_bufpos;
399
400 ++m_bufpos;
401 size_t lvl = 1;
402 std::string tmp;
403
404 while( lvl > 0 )
405 {
406 if( !EatSpace() )
407 {
408 std::ostringstream ostr;
409 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
410 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
411 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
412 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
413 ostr << " * [INFO] " << m_error;
414 m_error = ostr.str();
415
416 return false;
417 }
418
419 // comments must be skipped
420 if( '#' == m_buf[m_bufpos] )
421 {
422 m_bufpos = 0;
423 m_buf.clear();
424 continue;
425 }
426
427 if( '{' == m_buf[m_bufpos] )
428 {
429 ++m_bufpos;
430 ++lvl;
431 continue;
432 }
433
434 if( '}' == m_buf[m_bufpos] )
435 {
436 ++m_bufpos;
437 --lvl;
438 continue;
439 }
440
441 // note: if we have a ']' we must skip it and test the next non-blank character;
442 // this ensures that we don't miss a '}' in cases where the braces are not
443 // separated by space. if we had proceeded to ReadGlob() we could have had a problem.
444 if( ']' == m_buf[m_bufpos] || '[' == m_buf[m_bufpos] )
445 {
446 ++m_bufpos;
447 continue;
448 }
449
450 // strings are handled as a special case since they may contain
451 // control characters and braces
452 if( '"' == m_buf[m_bufpos] )
453 {
454 if( !ReadString( tmp ) )
455 {
456 std::ostringstream ostr;
457 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
458 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
459 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
460 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
461 ostr << " * [INFO] " << m_error;
462 m_error = ostr.str();
463
464 return false;
465 }
466 }
467
468 // everything at this point can be read and discarded via ReadGlob()
469 if( !ReadGlob( tmp ) )
470 {
471 std::ostringstream ostr;
472 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
473 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
474 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
475 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
476 ostr << " * [INFO] " << m_error;
477 m_error = ostr.str();
478
479 return false;
480 }
481 }
482
483 return true;
484}
485
486
488{
489 if( !m_file )
490 {
491 m_error = "no open file";
492 return false;
493 }
494
495 if( !EatSpace() )
496 {
497 std::ostringstream ostr;
498 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
499 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
500 ostr << " * [INFO] " << m_error;
501 m_error = ostr.str();
502
503 return false;
504 }
505
506 if( '[' != m_buf[m_bufpos] )
507 {
508 std::ostringstream ostr;
509 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
510 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
511 ostr << " * [INFO] expecting character '[' at line " << m_fileline;
512 ostr << ", column " << m_bufpos;
513 m_error = ostr.str();
514
515 return false;
516 }
517
518 size_t fileline = m_fileline;
519 size_t linepos = m_bufpos;
520
521 ++m_bufpos;
522 size_t lvl = 1;
523 std::string tmp;
524
525 while( lvl > 0 )
526 {
527 if( !EatSpace() )
528 {
529 std::ostringstream ostr;
530 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
531 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
532 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
533 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
534 ostr << " * [INFO] " << m_error;
535 m_error = ostr.str();
536
537 return false;
538 }
539
540 // comments must be skipped
541 if( '#' == m_buf[m_bufpos] )
542 {
543 m_bufpos = 0;
544 m_buf.clear();
545 continue;
546 }
547
548 if( '[' == m_buf[m_bufpos] )
549 {
550 ++m_bufpos;
551 ++lvl;
552 continue;
553 }
554
555 if( ']' == m_buf[m_bufpos] )
556 {
557 ++m_bufpos;
558 --lvl;
559 continue;
560 }
561
562 // note: if we have a '}' we must skip it and test the next non-blank character;
563 // this ensures that we don't miss a ']' in cases where the braces are not
564 // separated by space. if we had proceeded to ReadGlob() we could have had a problem.
565 if( '}' == m_buf[m_bufpos] || '{' == m_buf[m_bufpos] )
566 {
567 ++m_bufpos;
568 continue;
569 }
570
571 // strings are handled as a special case since they may contain
572 // control characters and braces
573 if( '"' == m_buf[m_bufpos] )
574 {
575 if( !ReadString( tmp ) )
576 {
577 std::ostringstream ostr;
578 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
579 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
580 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
581 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
582 ostr << " * [INFO] " << m_error;
583 m_error = ostr.str();
584
585 return false;
586 }
587 }
588
589 // everything at this point can be read and discarded via ReadGlob()
590 if( !ReadGlob( tmp ) )
591 {
592 std::ostringstream ostr;
593 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
594 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
595 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
596 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
597 ostr << " * [INFO] " << m_error;
598 m_error = ostr.str();
599
600 return false;
601 }
602 }
603
604 return false;
605}
606
607
608bool WRLPROC::ReadString( std::string& aSFString )
609{
610 // In VRML1 a string may be unquoted provided there are no space characters
611 // In VRML2 all strings must be quoted
612 aSFString.clear();
613
614 if( !m_file )
615 {
616 m_error = "no open file";
617 return false;
618 }
619
620 // remember the line number in case of errors
621 size_t ifline = m_fileline;
622
623 while( true )
624 {
625 if( !EatSpace() )
626 {
627 std::ostringstream ostr;
628 ostr << "invalid VRML file; expecting string at line " << ifline <<
629 " but found nothing";
630 m_error = ostr.str();
631
632 return false;
633 }
634
635 // if the text is the start of a comment block, clear the buffer and loop
636 if( '#' == m_buf[m_bufpos] )
637 m_buf.clear();
638 else
639 break;
640 }
641
643 {
644 m_error = "invalid VRML2 file (string not quoted)";
645 return false;
646 }
647
648 ifline = m_fileline;
649
650 if( '"' != m_buf[m_bufpos] )
651 {
652 if( !ReadGlob( aSFString ) )
653 {
654 std::ostringstream ostr;
655 ostr << "invalid VRML1 file at lines " << ifline << "--" << m_fileline;
656
657 if( !m_error.empty() )
658 ostr << " : " << m_error;
659
660 m_error = ostr.str();
661
662 return false;
663 }
664
665 return true;
666 }
667
668 bool isesc = false; // true if an escape character was found
669
670 while( true )
671 {
672 ++m_bufpos;
673
674 if( m_bufpos >= m_buf.size() )
675 {
676 aSFString.append( 1, '\n' );
677
678 if( !getRawLine() )
679 {
680 std::ostringstream ostr;
681 ostr << "invalid VRML1 file at lines " << ifline << "--" << m_fileline;
682 ostr << "; could not find end of string\n";
683 m_error = ostr.str();
684
685 return false;
686 }
687 }
688
689 if( '\\' == m_buf[m_bufpos] )
690 {
691 if( isesc )
692 {
693 aSFString.append( 1, '\n' );
694 isesc = false;
695 }
696 else
697 {
698 isesc = true;
699 }
700
701 continue;
702 }
703 else if( '"' == m_buf[m_bufpos] )
704 {
705 if( isesc )
706 aSFString.append( 1, '"' );
707 else
708 break;
709 }
710 else
711 {
712 aSFString.append( 1, m_buf[m_bufpos] );
713 }
714
715 // ensure that the backslash escape cannot extend beyond the first character
716 isesc = false;
717 }
718
719 ++m_bufpos;
720
721 return true;
722}
723
724
725bool WRLPROC::ReadSFBool( bool& aSFBool )
726{
727 if( !EatSpace() )
728 return false;
729
730 size_t fileline = m_fileline;
731 size_t linepos = m_bufpos;
732 std::string tmp;
733
734 if( !ReadGlob( tmp ) )
735 return false;
736
737 if( !tmp.compare( "0" ) )
738 {
739 aSFBool = false;
740 }
741 else if( !tmp.compare( "1" ) )
742 {
743 aSFBool = true;
744 }
745 else if( !tmp.compare( "TRUE" ) )
746 {
747 aSFBool = true;
748 }
749 else if( !tmp.compare( "FALSE" ) )
750 {
751 aSFBool = false;
752 }
753 else
754 {
755 std::ostringstream ostr;
756 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
757 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
758 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
759 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
760 ostr << " * [INFO] expected one of 0, 1, TRUE, FALSE but got '" << tmp << "'\n";
761 m_error = ostr.str();
762
763 return false;
764 }
765
766 return true;
767}
768
769
771{
772 if( !m_file )
773 {
774 m_error = "no open file";
775 return false;
776 }
777
778 size_t fileline = m_fileline;
779 size_t linepos = m_bufpos;
780
781 if( !ReadSFVec3f( aSFColor ) )
782 return false;
783
784 if( aSFColor.x < 0.0 || aSFColor.x > 1.0 || aSFColor.y < 0.0 || aSFColor.y > 1.0
785 || aSFColor.z < 0.0 || aSFColor.z > 1.0 )
786 {
787 std::ostringstream ostr;
788 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
789 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
790 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
791 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
792 ostr << " * [INFO] invalid RGB value in color triplet";
793 m_error = ostr.str();
794
795 return false;
796 }
797
798 return true;
799}
800
801
802bool WRLPROC::ReadSFFloat( float& aSFFloat )
803{
804 if( !m_file )
805 {
806 m_error = "no open file";
807 return false;
808 }
809
810 aSFFloat = 0.0;
811
812 size_t fileline = m_fileline;
813 size_t linepos = m_bufpos;
814
815 while( true )
816 {
817 if( !EatSpace() )
818 return false;
819
820 // if the text is the start of a comment block, clear the buffer and loop
821 if( '#' == m_buf[m_bufpos] )
822 m_buf.clear();
823 else
824 break;
825 }
826
827 std::string tmp;
828
829 if( !ReadGlob( tmp ) )
830 {
831 std::ostringstream ostr;
832 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
833 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
834 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
835 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
836 ostr << " * [INFO] " << m_error;
837 m_error = ostr.str();
838
839 return false;
840 }
841
842 std::istringstream istr;
843 istr.str( tmp );
844 istr >> aSFFloat;
845
846 if( istr.fail() || !istr.eof() )
847 {
848 std::ostringstream ostr;
849 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
850 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
851 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
852 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
853 ostr << " * [INFO] invalid character in SFFloat";
854 m_error = ostr.str();
855
856 return false;
857 }
858
859 return true;
860}
861
862
863bool WRLPROC::ReadSFInt( int& aSFInt32 )
864{
865 if( !m_file )
866 {
867 m_error = "no open file";
868 return false;
869 }
870
871 aSFInt32 = 0;
872 size_t fileline = m_fileline;
873 size_t linepos = m_bufpos;
874
875 while( true )
876 {
877 if( !EatSpace() )
878 return false;
879
880 // if the text is the start of a comment block, clear the buffer and loop
881 if( '#' == m_buf[m_bufpos] )
882 m_buf.clear();
883 else
884 break;
885 }
886
887 std::string tmp;
888
889 if( !ReadGlob( tmp ) )
890 {
891 std::ostringstream ostr;
892 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
893 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
894 ostr << " * [INFO] line " << fileline<< ", char " << linepos << " -- ";
895 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
896 ostr << " * [INFO] " << m_error;
897 m_error = ostr.str();
898
899 return false;
900 }
901
902 if( tmp.find( "0x" ) != std::string::npos )
903 {
904 // Rules: "0x" + "0-9, A-F" - VRML is case sensitive but in
905 // this instance we do no enforce case.
906 std::stringstream sstr;
907 sstr << std::hex << tmp;
908 sstr >> aSFInt32;
909 return true;
910 }
911
912 std::istringstream istr;
913 istr.str( tmp );
914 istr >> aSFInt32;
915
916 if( istr.fail() || !istr.eof() )
917 {
918 std::ostringstream ostr;
919 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
920 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
921 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
922 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
923 ostr << " * [INFO] invalid character in SFInt";
924 m_error = ostr.str();
925
926 return false;
927 }
928
929 return true;
930}
931
932
934{
935 if( !m_file )
936 {
937 m_error = "no open file";
938 return false;
939 }
940
941 aSFRotation.x = 0.0;
942 aSFRotation.y = 0.0;
943 aSFRotation.z = 1.0;
944 aSFRotation.w = 0.0;
945
946 size_t fileline = m_fileline;
947 size_t linepos = m_bufpos;
948
949 while( true )
950 {
951 if( !EatSpace() )
952 return false;
953
954 // if the text is the start of a comment block, clear the buffer and loop
955 if( '#' == m_buf[m_bufpos] )
956 m_buf.clear();
957 else
958 break;
959 }
960
961 std::string tmp;
962 float trot[4];
963
964 for( int i = 0; i < 4; ++i )
965 {
966 if( !ReadGlob( tmp ) )
967 {
968 std::ostringstream ostr;
969 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
970 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
971 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
972 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
973 ostr << " * [INFO] " << m_error;
974 m_error = ostr.str();
975
976 return false;
977 }
978
979 std::istringstream istr;
980 istr.str( tmp );
981 istr >> trot[i];
982
983 if( istr.fail() || !istr.eof() )
984 {
985 std::ostringstream ostr;
986 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
987 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
988 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
989 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
990 ostr << " * [INFO] invalid character in space delimited quartet";
991 m_error = ostr.str();
992
993 return false;
994 }
995
996 }
997
998 aSFRotation.x = trot[0];
999 aSFRotation.y = trot[1];
1000 aSFRotation.z = trot[2];
1001 aSFRotation.w = trot[3];
1002
1003 return true;
1004}
1005
1006
1008{
1009 if( !m_file )
1010 {
1011 m_error = "no open file";
1012 return false;
1013 }
1014
1015 aSFVec2f.x = 0.0;
1016 aSFVec2f.y = 0.0;
1017
1018 size_t fileline = m_fileline;
1019 size_t linepos = m_bufpos;
1020
1021 while( true )
1022 {
1023 if( !EatSpace() )
1024 return false;
1025
1026 // if the text is the start of a comment block, clear the buffer and loop
1027 if( '#' == m_buf[m_bufpos] )
1028 m_buf.clear();
1029 else
1030 break;
1031 }
1032
1033 std::string tmp;
1034
1035 float tcol[2];
1036
1037 for( int i = 0; i < 2; ++i )
1038 {
1039 if( !ReadGlob( tmp ) )
1040 {
1041 std::ostringstream ostr;
1042 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1043 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1044 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1045 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1046 ostr << " * [INFO] " << m_error;
1047 m_error = ostr.str();
1048
1049 return false;
1050 }
1051
1052 std::istringstream istr;
1053 istr.str( tmp );
1054 istr >> tcol[i];
1055
1056 if( istr.fail() || !istr.eof() )
1057 {
1058 std::ostringstream ostr;
1059 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1060 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1061 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1062 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1063 ostr << " * [INFO] invalid character in space delimited pair";
1064 m_error = ostr.str();
1065
1066 return false;
1067 }
1068
1069 }
1070
1071 aSFVec2f.x = tcol[0];
1072 aSFVec2f.y = tcol[1];
1073
1074 return true;
1075}
1076
1077
1079{
1080 if( !m_file )
1081 {
1082 m_error = "no open file";
1083 return false;
1084 }
1085
1086 aSFVec3f.x = 0.0;
1087 aSFVec3f.y = 0.0;
1088 aSFVec3f.z = 0.0;
1089
1090 size_t fileline = m_fileline;
1091 size_t linepos = m_bufpos;
1092
1093 while( true )
1094 {
1095 if( !EatSpace() )
1096 return false;
1097
1098 // if the text is the start of a comment block, clear the buffer and loop
1099 if( '#' == m_buf[m_bufpos] )
1100 m_buf.clear();
1101 else
1102 break;
1103 }
1104
1105 std::string tmp;
1106
1107 float tcol[3];
1108
1109 for( int i = 0; i < 3; ++i )
1110 {
1111 if( !ReadGlob( tmp ) )
1112 {
1113 std::ostringstream ostr;
1114 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1115 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1116 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1117 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1118 ostr << " * [INFO] " << m_error;
1119 m_error = ostr.str();
1120
1121 return false;
1122 }
1123
1124 // ignore any commas
1125 if( !EatSpace() )
1126 return false;
1127
1128 if( ',' == m_buf[m_bufpos] )
1129 Pop();
1130
1131 std::istringstream istr;
1132 istr.str( tmp );
1133 istr >> tcol[i];
1134
1135 if( istr.fail() || !istr.eof() )
1136 {
1137 std::ostringstream ostr;
1138 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1139 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1140 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1141 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1142 ostr << " * [INFO] invalid character in space delimited triplet";
1143 m_error = ostr.str();
1144
1145 return false;
1146 }
1147
1148 }
1149
1150 aSFVec3f.x = tcol[0];
1151 aSFVec3f.y = tcol[1];
1152 aSFVec3f.z = tcol[2];
1153
1154 return true;
1155}
1156
1157
1158bool WRLPROC::ReadMFString( std::vector< std::string >& aMFString )
1159{
1160 aMFString.clear();
1161 size_t fileline = m_fileline;
1162 size_t linepos = m_bufpos;
1163
1164 if( !m_file )
1165 {
1166 m_error = "no open file";
1167 return false;
1168 }
1169
1170 while( true )
1171 {
1172 if( !EatSpace() )
1173 return false;
1174
1175 // if the text is the start of a comment block, clear the buffer and loop
1176 if( '#' == m_buf[m_bufpos] )
1177 m_buf.clear();
1178 else
1179 break;
1180 }
1181
1182 std::string lstr;
1183
1184 if( m_buf[m_bufpos] != '[' )
1185 {
1186 if( !ReadString( lstr ) )
1187 {
1188 std::ostringstream ostr;
1189 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1190 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1191 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1192 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1193 ostr << " * [INFO] " << m_error;
1194 m_error = ostr.str();
1195
1196 return false;
1197 }
1198
1199 if( m_bufpos >= m_buf.size() && !EatSpace() )
1200 {
1201 std::ostringstream ostr;
1202 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1203 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1204 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1205 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1206 ostr << " * [INFO] could not check characters after the string";
1207 m_error = ostr.str();
1208
1209 return false;
1210 }
1211
1212 if( ',' == m_buf[m_bufpos] )
1213 Pop();
1214
1215 aMFString.push_back( lstr );
1216 return true;
1217 }
1218
1219 ++m_bufpos;
1220
1221 while( true )
1222 {
1223 if( !ReadString( lstr ) )
1224 {
1225 std::ostringstream ostr;
1226 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1227 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1228 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1229 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1230 ostr << " * [INFO] " << m_error;
1231 m_error = ostr.str();
1232
1233 return false;
1234 }
1235
1236 if( !EatSpace() )
1237 {
1238 std::ostringstream ostr;
1239 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1240 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1241 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1242 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1243 ostr << " * [INFO] could not check characters after the string";
1244 m_error = ostr.str();
1245
1246 return false;
1247 }
1248
1249 if( ',' == m_buf[m_bufpos] )
1250 Pop();
1251
1252 aMFString.push_back( lstr );
1253
1254 if( !EatSpace() )
1255 {
1256 std::ostringstream ostr;
1257 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1258 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1259 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1260 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1261 ostr << " * [INFO] problems encountered while reading list";
1262 m_error = ostr.str();
1263
1264 return false;
1265 }
1266
1267 if( ']' == m_buf[m_bufpos] )
1268 break;
1269
1270 }
1271
1272 ++m_bufpos;
1273 return true;
1274}
1275
1276
1277bool WRLPROC::ReadMFColor( std::vector< WRLVEC3F >& aMFColor )
1278{
1279 aMFColor.clear();
1280 size_t fileline = m_fileline;
1281 size_t linepos = m_bufpos;
1282
1283 if( !m_file )
1284 {
1285 m_error = "no open file";
1286 return false;
1287 }
1288
1289 WRLVEC3F lcolor;
1290
1291 while( true )
1292 {
1293 if( !EatSpace() )
1294 return false;
1295
1296 // if the text is the start of a comment block, clear the buffer and loop
1297 if( '#' == m_buf[m_bufpos] )
1298 m_buf.clear();
1299 else
1300 break;
1301 }
1302
1303 if( m_buf[m_bufpos] != '[' )
1304 {
1305 if( !ReadSFColor( lcolor ) )
1306 {
1307 std::ostringstream ostr;
1308 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1309 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1310 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1311 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1312 ostr << " * [INFO] " << m_error;
1313 m_error = ostr.str();
1314
1315 return false;
1316 }
1317
1318 if( !EatSpace() )
1319 {
1320 std::ostringstream ostr;
1321 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1322 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1323 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1324 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1325 ostr << " * [INFO] could not check characters after the string";
1326 m_error = ostr.str();
1327
1328 return false;
1329 }
1330
1331 if( ',' == m_buf[m_bufpos] )
1332 Pop();
1333
1334 aMFColor.push_back( lcolor );
1335 return true;
1336 }
1337
1338 ++m_bufpos;
1339
1340 while( true )
1341 {
1342 if( !EatSpace() )
1343 return false;
1344
1345 if( ']' == m_buf[m_bufpos] )
1346 break;
1347
1348 if( !ReadSFColor( lcolor ) )
1349 {
1350 std::ostringstream ostr;
1351 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1352 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1353 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1354 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1355 ostr << " * [INFO] " << m_error;
1356 m_error = ostr.str();
1357
1358 return false;
1359 }
1360
1361 aMFColor.push_back( lcolor );
1362
1363 if( !EatSpace() )
1364 {
1365 std::ostringstream ostr;
1366 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1367 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1368 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1369 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1370 ostr << " * [INFO] could not check characters after the string";
1371 m_error = ostr.str();
1372
1373 return false;
1374 }
1375
1376 if( ']' == m_buf[m_bufpos] )
1377 break;
1378
1379 if( ',' == m_buf[m_bufpos] )
1380 Pop();
1381
1382 }
1383
1384 ++m_bufpos;
1385 return true;
1386}
1387
1388
1389bool WRLPROC::ReadMFFloat( std::vector< float >& aMFFloat )
1390{
1391 aMFFloat.clear();
1392 size_t fileline = m_fileline;
1393 size_t linepos = m_bufpos;
1394
1395 if( !m_file )
1396 {
1397 m_error = "no open file";
1398 return false;
1399 }
1400
1401 float temp;
1402
1403 while( true )
1404 {
1405 if( !EatSpace() )
1406 return false;
1407
1408 // if the text is the start of a comment block, clear the buffer and loop
1409 if( '#' == m_buf[m_bufpos] )
1410 m_buf.clear();
1411 else
1412 break;
1413 }
1414
1415 if( m_buf[m_bufpos] != '[' )
1416 {
1417 if( !ReadSFFloat( temp ) )
1418 {
1419 std::ostringstream ostr;
1420 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1421 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1422 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1423 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1424 ostr << " * [INFO] " << m_error;
1425 m_error = ostr.str();
1426
1427 return false;
1428 }
1429
1430 if( !EatSpace() )
1431 {
1432 std::ostringstream ostr;
1433 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1434 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1435 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1436 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1437 ostr << " * [INFO] could not check characters after the string";
1438 m_error = ostr.str();
1439
1440 return false;
1441 }
1442
1443 if( ',' == m_buf[m_bufpos] )
1444 Pop();
1445
1446 aMFFloat.push_back( temp );
1447 return true;
1448 }
1449
1450 ++m_bufpos;
1451
1452 while( true )
1453 {
1454 if( !EatSpace() )
1455 return false;
1456
1457 if( ']' == m_buf[m_bufpos] )
1458 break;
1459
1460 if( !ReadSFFloat( temp ) )
1461 {
1462 std::ostringstream ostr;
1463 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1464 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1465 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1466 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1467 ostr << " * [INFO] " << m_error;
1468 m_error = ostr.str();
1469
1470 return false;
1471 }
1472
1473 aMFFloat.push_back( temp );
1474
1475 if( !EatSpace() )
1476 {
1477 std::ostringstream ostr;
1478 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1479 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1480 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1481 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1482 ostr << " * [INFO] could not check characters after the string";
1483 m_error = ostr.str();
1484
1485 return false;
1486 }
1487
1488 if( ']' == m_buf[m_bufpos] )
1489 break;
1490
1491 if( ',' == m_buf[m_bufpos] )
1492 Pop();
1493 }
1494
1495 ++m_bufpos;
1496 return true;
1497}
1498
1499
1500bool WRLPROC::ReadMFInt( std::vector< int >& aMFInt32 )
1501{
1502 aMFInt32.clear();
1503 size_t fileline = m_fileline;
1504 size_t linepos = m_bufpos;
1505
1506 if( !m_file )
1507 {
1508 m_error = "no open file";
1509 return false;
1510 }
1511
1512 int temp;
1513
1514 while( true )
1515 {
1516 if( !EatSpace() )
1517 return false;
1518
1519 // if the text is the start of a comment block, clear the buffer and loop
1520 if( '#' == m_buf[m_bufpos] )
1521 m_buf.clear();
1522 else
1523 break;
1524 }
1525
1526 if( m_buf[m_bufpos] != '[' )
1527 {
1528 if( !ReadSFInt( temp ) )
1529 {
1530 std::ostringstream ostr;
1531 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1532 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1533 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1534 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1535 ostr << " * [INFO] " << m_error;
1536 m_error = ostr.str();
1537
1538 return false;
1539 }
1540
1541 if( !EatSpace() )
1542 {
1543 std::ostringstream ostr;
1544 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1545 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1546 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1547 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1548 ostr << " * [INFO] could not check characters after the string";
1549 m_error = ostr.str();
1550
1551 return false;
1552 }
1553
1554 if( ',' == m_buf[m_bufpos] )
1555 Pop();
1556
1557 aMFInt32.push_back( temp );
1558 return true;
1559 }
1560
1561 ++m_bufpos;
1562
1563 while( true )
1564 {
1565 if( !EatSpace() )
1566 return false;
1567
1568 if( ']' == m_buf[m_bufpos] )
1569 break;
1570
1571 if( !ReadSFInt( temp ) )
1572 {
1573 std::ostringstream ostr;
1574 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1575 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1576 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1577 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1578 ostr << " * [INFO] " << m_error;
1579 m_error = ostr.str();
1580
1581 return false;
1582 }
1583
1584 aMFInt32.push_back( temp );
1585
1586 if( !EatSpace() )
1587 {
1588 std::ostringstream ostr;
1589 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1590 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1591 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1592 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1593 ostr << " * [INFO] could not check characters after the string";
1594 m_error = ostr.str();
1595
1596 return false;
1597 }
1598
1599 if( ']' == m_buf[m_bufpos] )
1600 break;
1601
1602 if( ',' == m_buf[m_bufpos] )
1603 Pop();
1604
1605 }
1606
1607 ++m_bufpos;
1608 return true;
1609}
1610
1611
1612bool WRLPROC::ReadMFRotation( std::vector< WRLROTATION >& aMFRotation )
1613{
1614 aMFRotation.clear();
1615 size_t fileline = m_fileline;
1616 size_t linepos = m_bufpos;
1617
1618 if( !m_file )
1619 {
1620 m_error = "no open file";
1621 return false;
1622 }
1623
1624 WRLROTATION lrot;
1625
1626 while( true )
1627 {
1628 if( !EatSpace() )
1629 return false;
1630
1631 // if the text is the start of a comment block, clear the buffer and loop
1632 if( '#' == m_buf[m_bufpos] )
1633 m_buf.clear();
1634 else
1635 break;
1636 }
1637
1638 if( m_buf[m_bufpos] != '[' )
1639 {
1640 if( !ReadSFRotation( lrot ) )
1641 {
1642 std::ostringstream ostr;
1643 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1644 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1645 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1646 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1647 ostr << " * [INFO] " << m_error;
1648 m_error = ostr.str();
1649
1650 return false;
1651 }
1652
1653 if( !EatSpace() )
1654 {
1655 std::ostringstream ostr;
1656 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1657 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1658 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1659 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1660 ostr << " * [INFO] could not check characters after the string";
1661 m_error = ostr.str();
1662
1663 return false;
1664 }
1665
1666 if( ',' == m_buf[m_bufpos] )
1667 Pop();
1668
1669 aMFRotation.push_back( lrot );
1670 return true;
1671 }
1672
1673 ++m_bufpos;
1674
1675 while( true )
1676 {
1677 if( !EatSpace() )
1678 return false;
1679
1680 if( ']' == m_buf[m_bufpos] )
1681 break;
1682
1683 if( !ReadSFRotation( lrot ) )
1684 {
1685 std::ostringstream ostr;
1686 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1687 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1688 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1689 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1690 ostr << " * [INFO] " << m_error;
1691 m_error = ostr.str();
1692
1693 return false;
1694 }
1695
1696 aMFRotation.push_back( lrot );
1697
1698 if( !EatSpace() )
1699 {
1700 std::ostringstream ostr;
1701 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1702 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1703 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1704 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1705 ostr << " * [INFO] could not check characters after the string";
1706 m_error = ostr.str();
1707
1708 return false;
1709 }
1710
1711 if( ']' == m_buf[m_bufpos] )
1712 break;
1713
1714 if( ',' == m_buf[m_bufpos] )
1715 Pop();
1716
1717 }
1718
1719 ++m_bufpos;
1720 return true;
1721}
1722
1723
1724bool WRLPROC::ReadMFVec2f( std::vector< WRLVEC2F >& aMFVec2f )
1725{
1726 aMFVec2f.clear();
1727 size_t fileline = m_fileline;
1728 size_t linepos = m_bufpos;
1729
1730 if( !m_file )
1731 {
1732 m_error = "no open file";
1733 return false;
1734 }
1735
1736 WRLVEC2F lvec2f;
1737
1738 while( true )
1739 {
1740 if( !EatSpace() )
1741 return false;
1742
1743 // if the text is the start of a comment block, clear the buffer and loop
1744 if( '#' == m_buf[m_bufpos] )
1745 m_buf.clear();
1746 else
1747 break;
1748 }
1749
1750 if( m_buf[m_bufpos] != '[' )
1751 {
1752 if( !ReadSFVec2f( lvec2f ) )
1753 {
1754 std::ostringstream ostr;
1755 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1756 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1757 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1758 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1759 ostr << " * [INFO] " << m_error;
1760 m_error = ostr.str();
1761
1762 return false;
1763 }
1764
1765 if( !EatSpace() )
1766 {
1767 std::ostringstream ostr;
1768 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1769 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1770 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1771 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1772 ostr << " * [INFO] could not check characters after the string";
1773 m_error = ostr.str();
1774
1775 return false;
1776 }
1777
1778 if( ',' == m_buf[m_bufpos] )
1779 Pop();
1780
1781 aMFVec2f.push_back( lvec2f );
1782 return true;
1783 }
1784
1785 ++m_bufpos;
1786
1787 while( true )
1788 {
1789 if( !EatSpace() )
1790 return false;
1791
1792 if( ']' == m_buf[m_bufpos] )
1793 break;
1794
1795 if( !ReadSFVec2f( lvec2f ) )
1796 {
1797 std::ostringstream ostr;
1798 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1799 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1800 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1801 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1802 ostr << " * [INFO] " << m_error;
1803 m_error = ostr.str();
1804
1805 return false;
1806 }
1807
1808 aMFVec2f.push_back( lvec2f );
1809
1810 if( !EatSpace() )
1811 {
1812 std::ostringstream ostr;
1813 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1814 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1815 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1816 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1817 ostr << " * [INFO] could not check characters after the string";
1818 m_error = ostr.str();
1819
1820 return false;
1821 }
1822
1823 if( ']' == m_buf[m_bufpos] )
1824 break;
1825
1826 if( ',' == m_buf[m_bufpos] )
1827 Pop();
1828 }
1829
1830 ++m_bufpos;
1831 return true;
1832}
1833
1834
1835bool WRLPROC::ReadMFVec3f( std::vector< WRLVEC3F >& aMFVec3f )
1836{
1837 aMFVec3f.clear();
1838 size_t fileline = m_fileline;
1839 size_t linepos = m_bufpos;
1840
1841 if( !m_file )
1842 {
1843 m_error = "no open file";
1844 return false;
1845 }
1846
1847 WRLVEC3F lvec3f;
1848
1849 while( true )
1850 {
1851 if( !EatSpace() )
1852 return false;
1853
1854 // if the text is the start of a comment block, clear the buffer and loop
1855 if( '#' == m_buf[m_bufpos] )
1856 m_buf.clear();
1857 else
1858 break;
1859 }
1860
1861 if( m_buf[m_bufpos] != '[' )
1862 {
1863 if( !ReadSFVec3f( lvec3f ) )
1864 {
1865 std::ostringstream ostr;
1866 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1867 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1868 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1869 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1870 ostr << " * [INFO] " << m_error;
1871 m_error = ostr.str();
1872
1873 return false;
1874 }
1875
1876 if( !EatSpace() )
1877 {
1878 std::ostringstream ostr;
1879 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1880 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1881 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1882 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1883 ostr << " * [INFO] could not check characters after the string";
1884 m_error = ostr.str();
1885
1886 return false;
1887 }
1888
1889 if( ',' == m_buf[m_bufpos] )
1890 Pop();
1891
1892 aMFVec3f.push_back( lvec3f );
1893 return true;
1894 }
1895
1896 ++m_bufpos;
1897
1898 while( true )
1899 {
1900 if( !EatSpace() )
1901 return false;
1902
1903 if( ']' == m_buf[m_bufpos] )
1904 break;
1905
1906 if( !ReadSFVec3f( lvec3f ) )
1907 {
1908 std::ostringstream ostr;
1909 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1910 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1911 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1912 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1913 ostr << " * [INFO] " << m_error;
1914 m_error = ostr.str();
1915
1916 return false;
1917 }
1918
1919 aMFVec3f.push_back( lvec3f );
1920
1921 if( !EatSpace() )
1922 {
1923 std::ostringstream ostr;
1924 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1925 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1926 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1927 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1928 ostr << " * [INFO] could not check characters after the string";
1929 m_error = ostr.str();
1930
1931 return false;
1932 }
1933
1934 if( !EatSpace() )
1935 return false;
1936
1937 if( ']' == m_buf[m_bufpos] )
1938 break;
1939
1940 if( ',' == m_buf[m_bufpos] )
1941 Pop();
1942
1943 }
1944
1945 ++m_bufpos;
1946 return true;
1947}
1948
1949
1950bool WRLPROC::eof( void )
1951{
1952 return m_eof;
1953}
1954
1955
1956std::string WRLPROC::GetError( void )
1957{
1958 return m_error;
1959}
1960
1961
1962bool WRLPROC::GetFilePosData( size_t& line, size_t& column )
1963{
1964 if( !m_file )
1965 {
1966 line = 0;
1967 column = 0;
1968 return false;
1969 }
1970
1971 line = m_fileline;
1972 column = m_bufpos;
1973
1974 return true;
1975}
1976
1977
1978std::string WRLPROC::GetFilePosition() const
1979{
1980 std::ostringstream retv;
1981
1982 if( !m_file )
1983 retv << "no file loaded to provide file position information";
1984 else
1985 retv << "at line " << m_fileline << ", column " << m_bufpos;
1986
1987 return retv.str();
1988}
1989
1990
1991std::string WRLPROC::GetFileName( void )
1992{
1993 if( !m_file )
1994 {
1995 m_error = "no open file";
1996 return "";
1997 }
1998
1999 return std::string( m_file->GetSource().ToUTF8() );
2000}
2001
2002
2003char WRLPROC::Peek( void )
2004{
2005 if( !m_file )
2006 {
2007 std::ostringstream ostr;
2008 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
2009 ostr << " * [BUG] no open file";
2010 m_error = ostr.str();
2011 return '\0';
2012 }
2013
2014 if( !EatSpace() )
2015 {
2016 if( m_error.empty() )
2017 {
2018 std::ostringstream ostr;
2019 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
2020 ostr << " * [INFO] failed to read data from file\n";
2021 m_error = ostr.str();
2022 }
2023
2024 return '\0';
2025 }
2026
2027 return m_buf[m_bufpos];
2028}
2029
2030
2031void WRLPROC::Pop( void )
2032{
2033 if( m_bufpos < m_buf.size() )
2034 ++m_bufpos;
2035}
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Definition richio.h:62
WRLVERSION m_fileVersion
Definition wrlproc.h:110
bool DiscardList(void)
Definition wrlproc.cpp:487
bool ReadGlob(std::string &aGlob)
Definition wrlproc.cpp:241
bool ReadSFInt(int &aSFInt32)
Definition wrlproc.cpp:863
bool ReadMFString(std::vector< std::string > &aMFString)
Definition wrlproc.cpp:1158
bool ReadString(std::string &aSFString)
Definition wrlproc.cpp:608
unsigned int m_fileline
Definition wrlproc.h:107
std::string m_error
Definition wrlproc.h:111
void Pop(void)
Definition wrlproc.cpp:2031
bool ReadSFFloat(float &aSFFloat)
Definition wrlproc.cpp:802
char Peek(void)
Definition wrlproc.cpp:2003
std::string GetFileName(void)
Definition wrlproc.cpp:1991
bool EatSpace(void)
Definition wrlproc.cpp:187
bool ReadSFColor(WRLVEC3F &aSFColor)
Definition wrlproc.cpp:770
bool ReadSFVec2f(WRLVEC2F &aSFVec2f)
Definition wrlproc.cpp:1007
WRLVERSION GetVRMLType(void)
Definition wrlproc.cpp:226
bool ReadMFInt(std::vector< int > &aMFInt32)
Definition wrlproc.cpp:1500
std::string m_filename
Definition wrlproc.h:113
const char * GetParentDir(void)
Definition wrlproc.cpp:232
bool ReadMFFloat(std::vector< float > &aMFFloat)
Definition wrlproc.cpp:1389
bool GetFilePosData(size_t &line, size_t &column)
Definition wrlproc.cpp:1962
bool getRawLine(void)
Definition wrlproc.cpp:138
std::string GetError(void)
Definition wrlproc.cpp:1956
bool ReadMFVec2f(std::vector< WRLVEC2F > &aMFVec2f)
Definition wrlproc.cpp:1724
std::string m_badchars
Definition wrlproc.h:112
bool ReadSFBool(bool &aSFBool)
Definition wrlproc.cpp:725
std::string m_filedir
Definition wrlproc.h:114
LINE_READER * m_file
Definition wrlproc.h:104
unsigned int m_bufpos
Definition wrlproc.h:108
bool eof(void)
Definition wrlproc.cpp:1950
bool ReadMFRotation(std::vector< WRLROTATION > &aMFRotation)
Definition wrlproc.cpp:1612
bool ReadMFVec3f(std::vector< WRLVEC3F > &aMFVec3f)
Definition wrlproc.cpp:1835
bool ReadName(std::string &aName)
Definition wrlproc.cpp:285
bool m_eof
Definition wrlproc.h:106
std::string GetFilePosition() const
Definition wrlproc.cpp:1978
bool DiscardNode(void)
Definition wrlproc.cpp:364
bool ReadMFColor(std::vector< WRLVEC3F > &aMFColor)
Definition wrlproc.cpp:1277
std::string m_buf
Definition wrlproc.h:105
bool ReadSFRotation(WRLROTATION &aSFRotation)
Definition wrlproc.cpp:933
WRLPROC(LINE_READER *aLineReader)
Definition wrlproc.cpp:57
bool ReadSFVec3f(WRLVEC3F &aSFVec3f)
Definition wrlproc.cpp:1078
const wxChar *const traceVrmlPlugin
Flag to enable VRML plugin trace output.
Definition vrml.cpp:59
#define GETLINE
Definition wrlproc.cpp:28
defines the basic input class for VRML
WRLVERSION
Definition wrltypes.h:40
@ VRML_INVALID
Definition wrltypes.h:41
glm::vec4 WRLROTATION
Definition wrltypes.h:185
glm::vec2 WRLVEC2F
Definition wrltypes.h:183
glm::vec3 WRLVEC3F
Definition wrltypes.h:184
#define FN_NORMALIZE_FLAGS
Default flags to pass to wxFileName::Normalize().
Definition wx_filename.h:35