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