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 do
683 {
684 aSFString.append( 1, '\n' );
685
686 if( !getRawLine() )
687 {
688 std::ostringstream ostr;
689 ostr << "invalid VRML1 file at lines " << ifline << "--" << m_fileline;
690 ostr << "; could not find end of string\n";
691 m_error = ostr.str();
692
693 return false;
694 }
695 } while( m_buf.empty() );
696 }
697
698 if( '\\' == m_buf[m_bufpos] )
699 {
700 if( isesc )
701 {
702 aSFString.append( 1, '\n' );
703 isesc = false;
704 }
705 else
706 {
707 isesc = true;
708 }
709
710 continue;
711 }
712 else if( '"' == m_buf[m_bufpos] )
713 {
714 if( isesc )
715 aSFString.append( 1, '"' );
716 else
717 break;
718 }
719 else
720 {
721 aSFString.append( 1, m_buf[m_bufpos] );
722 }
723
724 // ensure that the backslash escape cannot extend beyond the first character
725 isesc = false;
726 }
727
728 ++m_bufpos;
729
730 return true;
731}
732
733
734bool WRLPROC::ReadSFBool( bool& aSFBool )
735{
736 if( !EatSpace() )
737 return false;
738
739 size_t fileline = m_fileline;
740 size_t linepos = m_bufpos;
741 std::string tmp;
742
743 if( !ReadGlob( tmp ) )
744 return false;
745
746 if( !tmp.compare( "0" ) )
747 {
748 aSFBool = false;
749 }
750 else if( !tmp.compare( "1" ) )
751 {
752 aSFBool = true;
753 }
754 else if( !tmp.compare( "TRUE" ) )
755 {
756 aSFBool = true;
757 }
758 else if( !tmp.compare( "FALSE" ) )
759 {
760 aSFBool = false;
761 }
762 else
763 {
764 std::ostringstream ostr;
765 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
766 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
767 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
768 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
769 ostr << " * [INFO] expected one of 0, 1, TRUE, FALSE but got '" << tmp << "'\n";
770 m_error = ostr.str();
771
772 return false;
773 }
774
775 return true;
776}
777
778
780{
781 if( !m_file )
782 {
783 m_error = "no open file";
784 return false;
785 }
786
787 size_t fileline = m_fileline;
788 size_t linepos = m_bufpos;
789
790 if( !ReadSFVec3f( aSFColor ) )
791 return false;
792
793 if( aSFColor.x < 0.0 || aSFColor.x > 1.0 || aSFColor.y < 0.0 || aSFColor.y > 1.0
794 || aSFColor.z < 0.0 || aSFColor.z > 1.0 )
795 {
796 std::ostringstream ostr;
797 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
798 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
799 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
800 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
801 ostr << " * [INFO] invalid RGB value in color triplet";
802 m_error = ostr.str();
803
804 return false;
805 }
806
807 return true;
808}
809
810
811bool WRLPROC::ReadSFFloat( float& aSFFloat )
812{
813 if( !m_file )
814 {
815 m_error = "no open file";
816 return false;
817 }
818
819 aSFFloat = 0.0;
820
821 size_t fileline = m_fileline;
822 size_t linepos = m_bufpos;
823
824 while( true )
825 {
826 if( !EatSpace() )
827 return false;
828
829 // if the text is the start of a comment block, clear the buffer and loop
830 if( '#' == m_buf[m_bufpos] )
831 m_buf.clear();
832 else
833 break;
834 }
835
836 std::string tmp;
837
838 if( !ReadGlob( tmp ) )
839 {
840 std::ostringstream ostr;
841 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
842 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
843 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
844 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
845 ostr << " * [INFO] " << m_error;
846 m_error = ostr.str();
847
848 return false;
849 }
850
851 std::istringstream istr;
852 istr.str( tmp );
853 istr >> aSFFloat;
854
855 if( istr.fail() || !istr.eof() )
856 {
857 std::ostringstream ostr;
858 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
859 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
860 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
861 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
862 ostr << " * [INFO] invalid character in SFFloat";
863 m_error = ostr.str();
864
865 return false;
866 }
867
868 return true;
869}
870
871
872bool WRLPROC::ReadSFInt( int& aSFInt32 )
873{
874 if( !m_file )
875 {
876 m_error = "no open file";
877 return false;
878 }
879
880 aSFInt32 = 0;
881 size_t fileline = m_fileline;
882 size_t linepos = m_bufpos;
883
884 while( true )
885 {
886 if( !EatSpace() )
887 return false;
888
889 // if the text is the start of a comment block, clear the buffer and loop
890 if( '#' == m_buf[m_bufpos] )
891 m_buf.clear();
892 else
893 break;
894 }
895
896 std::string tmp;
897
898 if( !ReadGlob( tmp ) )
899 {
900 std::ostringstream ostr;
901 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
902 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
903 ostr << " * [INFO] line " << fileline<< ", char " << linepos << " -- ";
904 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
905 ostr << " * [INFO] " << m_error;
906 m_error = ostr.str();
907
908 return false;
909 }
910
911 if( tmp.find( "0x" ) != std::string::npos )
912 {
913 // Rules: "0x" + "0-9, A-F" - VRML is case sensitive but in
914 // this instance we do no enforce case.
915 std::stringstream sstr;
916 sstr << std::hex << tmp;
917 sstr >> aSFInt32;
918 return true;
919 }
920
921 std::istringstream istr;
922 istr.str( tmp );
923 istr >> aSFInt32;
924
925 if( istr.fail() || !istr.eof() )
926 {
927 std::ostringstream ostr;
928 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
929 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
930 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
931 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
932 ostr << " * [INFO] invalid character in SFInt";
933 m_error = ostr.str();
934
935 return false;
936 }
937
938 return true;
939}
940
941
943{
944 if( !m_file )
945 {
946 m_error = "no open file";
947 return false;
948 }
949
950 aSFRotation.x = 0.0;
951 aSFRotation.y = 0.0;
952 aSFRotation.z = 1.0;
953 aSFRotation.w = 0.0;
954
955 size_t fileline = m_fileline;
956 size_t linepos = m_bufpos;
957
958 while( true )
959 {
960 if( !EatSpace() )
961 return false;
962
963 // if the text is the start of a comment block, clear the buffer and loop
964 if( '#' == m_buf[m_bufpos] )
965 m_buf.clear();
966 else
967 break;
968 }
969
970 std::string tmp;
971 float trot[4];
972
973 for( int i = 0; i < 4; ++i )
974 {
975 if( !ReadGlob( tmp ) )
976 {
977 std::ostringstream ostr;
978 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
979 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
980 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
981 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
982 ostr << " * [INFO] " << m_error;
983 m_error = ostr.str();
984
985 return false;
986 }
987
988 std::istringstream istr;
989 istr.str( tmp );
990 istr >> trot[i];
991
992 if( istr.fail() || !istr.eof() )
993 {
994 std::ostringstream ostr;
995 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
996 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
997 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
998 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
999 ostr << " * [INFO] invalid character in space delimited quartet";
1000 m_error = ostr.str();
1001
1002 return false;
1003 }
1004
1005 }
1006
1007 aSFRotation.x = trot[0];
1008 aSFRotation.y = trot[1];
1009 aSFRotation.z = trot[2];
1010 aSFRotation.w = trot[3];
1011
1012 return true;
1013}
1014
1015
1017{
1018 if( !m_file )
1019 {
1020 m_error = "no open file";
1021 return false;
1022 }
1023
1024 aSFVec2f.x = 0.0;
1025 aSFVec2f.y = 0.0;
1026
1027 size_t fileline = m_fileline;
1028 size_t linepos = m_bufpos;
1029
1030 while( true )
1031 {
1032 if( !EatSpace() )
1033 return false;
1034
1035 // if the text is the start of a comment block, clear the buffer and loop
1036 if( '#' == m_buf[m_bufpos] )
1037 m_buf.clear();
1038 else
1039 break;
1040 }
1041
1042 std::string tmp;
1043
1044 float tcol[2];
1045
1046 for( int i = 0; i < 2; ++i )
1047 {
1048 if( !ReadGlob( tmp ) )
1049 {
1050 std::ostringstream ostr;
1051 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1052 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1053 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1054 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1055 ostr << " * [INFO] " << m_error;
1056 m_error = ostr.str();
1057
1058 return false;
1059 }
1060
1061 std::istringstream istr;
1062 istr.str( tmp );
1063 istr >> tcol[i];
1064
1065 if( istr.fail() || !istr.eof() )
1066 {
1067 std::ostringstream ostr;
1068 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1069 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1070 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1071 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1072 ostr << " * [INFO] invalid character in space delimited pair";
1073 m_error = ostr.str();
1074
1075 return false;
1076 }
1077
1078 }
1079
1080 aSFVec2f.x = tcol[0];
1081 aSFVec2f.y = tcol[1];
1082
1083 return true;
1084}
1085
1086
1088{
1089 if( !m_file )
1090 {
1091 m_error = "no open file";
1092 return false;
1093 }
1094
1095 aSFVec3f.x = 0.0;
1096 aSFVec3f.y = 0.0;
1097 aSFVec3f.z = 0.0;
1098
1099 size_t fileline = m_fileline;
1100 size_t linepos = m_bufpos;
1101
1102 while( true )
1103 {
1104 if( !EatSpace() )
1105 return false;
1106
1107 // if the text is the start of a comment block, clear the buffer and loop
1108 if( '#' == m_buf[m_bufpos] )
1109 m_buf.clear();
1110 else
1111 break;
1112 }
1113
1114 std::string tmp;
1115
1116 float tcol[3];
1117
1118 for( int i = 0; i < 3; ++i )
1119 {
1120 if( !ReadGlob( tmp ) )
1121 {
1122 std::ostringstream ostr;
1123 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1124 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1125 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1126 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1127 ostr << " * [INFO] " << m_error;
1128 m_error = ostr.str();
1129
1130 return false;
1131 }
1132
1133 // ignore any commas
1134 if( !EatSpace() )
1135 return false;
1136
1137 if( ',' == m_buf[m_bufpos] )
1138 Pop();
1139
1140 std::istringstream istr;
1141 istr.str( tmp );
1142 istr >> tcol[i];
1143
1144 if( istr.fail() || !istr.eof() )
1145 {
1146 std::ostringstream ostr;
1147 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1148 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1149 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1150 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1151 ostr << " * [INFO] invalid character in space delimited triplet";
1152 m_error = ostr.str();
1153
1154 return false;
1155 }
1156
1157 }
1158
1159 aSFVec3f.x = tcol[0];
1160 aSFVec3f.y = tcol[1];
1161 aSFVec3f.z = tcol[2];
1162
1163 return true;
1164}
1165
1166
1167bool WRLPROC::ReadMFString( std::vector< std::string >& aMFString )
1168{
1169 aMFString.clear();
1170 size_t fileline = m_fileline;
1171 size_t linepos = m_bufpos;
1172
1173 if( !m_file )
1174 {
1175 m_error = "no open file";
1176 return false;
1177 }
1178
1179 while( true )
1180 {
1181 if( !EatSpace() )
1182 return false;
1183
1184 // if the text is the start of a comment block, clear the buffer and loop
1185 if( '#' == m_buf[m_bufpos] )
1186 m_buf.clear();
1187 else
1188 break;
1189 }
1190
1191 std::string lstr;
1192
1193 if( m_buf[m_bufpos] != '[' )
1194 {
1195 if( !ReadString( lstr ) )
1196 {
1197 std::ostringstream ostr;
1198 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1199 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1200 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1201 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1202 ostr << " * [INFO] " << m_error;
1203 m_error = ostr.str();
1204
1205 return false;
1206 }
1207
1208 if( m_bufpos >= m_buf.size() && !EatSpace() )
1209 {
1210 std::ostringstream ostr;
1211 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1212 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1213 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1214 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1215 ostr << " * [INFO] could not check characters after the string";
1216 m_error = ostr.str();
1217
1218 return false;
1219 }
1220
1221 if( ',' == m_buf[m_bufpos] )
1222 Pop();
1223
1224 aMFString.push_back( lstr );
1225 return true;
1226 }
1227
1228 ++m_bufpos;
1229
1230 while( true )
1231 {
1232 if( !ReadString( lstr ) )
1233 {
1234 std::ostringstream ostr;
1235 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1236 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1237 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1238 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1239 ostr << " * [INFO] " << m_error;
1240 m_error = ostr.str();
1241
1242 return false;
1243 }
1244
1245 if( !EatSpace() )
1246 {
1247 std::ostringstream ostr;
1248 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1249 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1250 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1251 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1252 ostr << " * [INFO] could not check characters after the string";
1253 m_error = ostr.str();
1254
1255 return false;
1256 }
1257
1258 if( ',' == m_buf[m_bufpos] )
1259 Pop();
1260
1261 aMFString.push_back( lstr );
1262
1263 if( !EatSpace() )
1264 {
1265 std::ostringstream ostr;
1266 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1267 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1268 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1269 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1270 ostr << " * [INFO] problems encountered while reading list";
1271 m_error = ostr.str();
1272
1273 return false;
1274 }
1275
1276 if( ']' == m_buf[m_bufpos] )
1277 break;
1278
1279 }
1280
1281 ++m_bufpos;
1282 return true;
1283}
1284
1285
1286bool WRLPROC::ReadMFColor( std::vector< WRLVEC3F >& aMFColor )
1287{
1288 aMFColor.clear();
1289 size_t fileline = m_fileline;
1290 size_t linepos = m_bufpos;
1291
1292 if( !m_file )
1293 {
1294 m_error = "no open file";
1295 return false;
1296 }
1297
1298 WRLVEC3F lcolor;
1299
1300 while( true )
1301 {
1302 if( !EatSpace() )
1303 return false;
1304
1305 // if the text is the start of a comment block, clear the buffer and loop
1306 if( '#' == m_buf[m_bufpos] )
1307 m_buf.clear();
1308 else
1309 break;
1310 }
1311
1312 if( m_buf[m_bufpos] != '[' )
1313 {
1314 if( !ReadSFColor( lcolor ) )
1315 {
1316 std::ostringstream ostr;
1317 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1318 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1319 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1320 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1321 ostr << " * [INFO] " << m_error;
1322 m_error = ostr.str();
1323
1324 return false;
1325 }
1326
1327 if( !EatSpace() )
1328 {
1329 std::ostringstream ostr;
1330 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1331 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1332 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1333 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1334 ostr << " * [INFO] could not check characters after the string";
1335 m_error = ostr.str();
1336
1337 return false;
1338 }
1339
1340 if( ',' == m_buf[m_bufpos] )
1341 Pop();
1342
1343 aMFColor.push_back( lcolor );
1344 return true;
1345 }
1346
1347 ++m_bufpos;
1348
1349 while( true )
1350 {
1351 if( !EatSpace() )
1352 return false;
1353
1354 if( ']' == m_buf[m_bufpos] )
1355 break;
1356
1357 if( !ReadSFColor( lcolor ) )
1358 {
1359 std::ostringstream ostr;
1360 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1361 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1362 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1363 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1364 ostr << " * [INFO] " << m_error;
1365 m_error = ostr.str();
1366
1367 return false;
1368 }
1369
1370 aMFColor.push_back( lcolor );
1371
1372 if( !EatSpace() )
1373 {
1374 std::ostringstream ostr;
1375 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1376 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1377 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1378 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1379 ostr << " * [INFO] could not check characters after the string";
1380 m_error = ostr.str();
1381
1382 return false;
1383 }
1384
1385 if( ']' == m_buf[m_bufpos] )
1386 break;
1387
1388 if( ',' == m_buf[m_bufpos] )
1389 Pop();
1390
1391 }
1392
1393 ++m_bufpos;
1394 return true;
1395}
1396
1397
1398bool WRLPROC::ReadMFFloat( std::vector< float >& aMFFloat )
1399{
1400 aMFFloat.clear();
1401 size_t fileline = m_fileline;
1402 size_t linepos = m_bufpos;
1403
1404 if( !m_file )
1405 {
1406 m_error = "no open file";
1407 return false;
1408 }
1409
1410 float temp;
1411
1412 while( true )
1413 {
1414 if( !EatSpace() )
1415 return false;
1416
1417 // if the text is the start of a comment block, clear the buffer and loop
1418 if( '#' == m_buf[m_bufpos] )
1419 m_buf.clear();
1420 else
1421 break;
1422 }
1423
1424 if( m_buf[m_bufpos] != '[' )
1425 {
1426 if( !ReadSFFloat( temp ) )
1427 {
1428 std::ostringstream ostr;
1429 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1430 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1431 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1432 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1433 ostr << " * [INFO] " << m_error;
1434 m_error = ostr.str();
1435
1436 return false;
1437 }
1438
1439 if( !EatSpace() )
1440 {
1441 std::ostringstream ostr;
1442 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1443 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1444 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1445 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1446 ostr << " * [INFO] could not check characters after the string";
1447 m_error = ostr.str();
1448
1449 return false;
1450 }
1451
1452 if( ',' == m_buf[m_bufpos] )
1453 Pop();
1454
1455 aMFFloat.push_back( temp );
1456 return true;
1457 }
1458
1459 ++m_bufpos;
1460
1461 while( true )
1462 {
1463 if( !EatSpace() )
1464 return false;
1465
1466 if( ']' == m_buf[m_bufpos] )
1467 break;
1468
1469 if( !ReadSFFloat( temp ) )
1470 {
1471 std::ostringstream ostr;
1472 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1473 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1474 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1475 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1476 ostr << " * [INFO] " << m_error;
1477 m_error = ostr.str();
1478
1479 return false;
1480 }
1481
1482 aMFFloat.push_back( temp );
1483
1484 if( !EatSpace() )
1485 {
1486 std::ostringstream ostr;
1487 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1488 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1489 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1490 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1491 ostr << " * [INFO] could not check characters after the string";
1492 m_error = ostr.str();
1493
1494 return false;
1495 }
1496
1497 if( ']' == m_buf[m_bufpos] )
1498 break;
1499
1500 if( ',' == m_buf[m_bufpos] )
1501 Pop();
1502 }
1503
1504 ++m_bufpos;
1505 return true;
1506}
1507
1508
1509bool WRLPROC::ReadMFInt( std::vector< int >& aMFInt32 )
1510{
1511 aMFInt32.clear();
1512 size_t fileline = m_fileline;
1513 size_t linepos = m_bufpos;
1514
1515 if( !m_file )
1516 {
1517 m_error = "no open file";
1518 return false;
1519 }
1520
1521 int temp;
1522
1523 while( true )
1524 {
1525 if( !EatSpace() )
1526 return false;
1527
1528 // if the text is the start of a comment block, clear the buffer and loop
1529 if( '#' == m_buf[m_bufpos] )
1530 m_buf.clear();
1531 else
1532 break;
1533 }
1534
1535 if( m_buf[m_bufpos] != '[' )
1536 {
1537 if( !ReadSFInt( temp ) )
1538 {
1539 std::ostringstream ostr;
1540 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1541 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1542 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1543 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1544 ostr << " * [INFO] " << m_error;
1545 m_error = ostr.str();
1546
1547 return false;
1548 }
1549
1550 if( !EatSpace() )
1551 {
1552 std::ostringstream ostr;
1553 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1554 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1555 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1556 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1557 ostr << " * [INFO] could not check characters after the string";
1558 m_error = ostr.str();
1559
1560 return false;
1561 }
1562
1563 if( ',' == m_buf[m_bufpos] )
1564 Pop();
1565
1566 aMFInt32.push_back( temp );
1567 return true;
1568 }
1569
1570 ++m_bufpos;
1571
1572 while( true )
1573 {
1574 if( !EatSpace() )
1575 return false;
1576
1577 if( ']' == m_buf[m_bufpos] )
1578 break;
1579
1580 if( !ReadSFInt( temp ) )
1581 {
1582 std::ostringstream ostr;
1583 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1584 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1585 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1586 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1587 ostr << " * [INFO] " << m_error;
1588 m_error = ostr.str();
1589
1590 return false;
1591 }
1592
1593 aMFInt32.push_back( temp );
1594
1595 if( !EatSpace() )
1596 {
1597 std::ostringstream ostr;
1598 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1599 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1600 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1601 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1602 ostr << " * [INFO] could not check characters after the string";
1603 m_error = ostr.str();
1604
1605 return false;
1606 }
1607
1608 if( ']' == m_buf[m_bufpos] )
1609 break;
1610
1611 if( ',' == m_buf[m_bufpos] )
1612 Pop();
1613
1614 }
1615
1616 ++m_bufpos;
1617 return true;
1618}
1619
1620
1621bool WRLPROC::ReadMFRotation( std::vector< WRLROTATION >& aMFRotation )
1622{
1623 aMFRotation.clear();
1624 size_t fileline = m_fileline;
1625 size_t linepos = m_bufpos;
1626
1627 if( !m_file )
1628 {
1629 m_error = "no open file";
1630 return false;
1631 }
1632
1633 WRLROTATION lrot;
1634
1635 while( true )
1636 {
1637 if( !EatSpace() )
1638 return false;
1639
1640 // if the text is the start of a comment block, clear the buffer and loop
1641 if( '#' == m_buf[m_bufpos] )
1642 m_buf.clear();
1643 else
1644 break;
1645 }
1646
1647 if( m_buf[m_bufpos] != '[' )
1648 {
1649 if( !ReadSFRotation( lrot ) )
1650 {
1651 std::ostringstream ostr;
1652 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1653 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1654 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1655 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1656 ostr << " * [INFO] " << m_error;
1657 m_error = ostr.str();
1658
1659 return false;
1660 }
1661
1662 if( !EatSpace() )
1663 {
1664 std::ostringstream ostr;
1665 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1666 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1667 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1668 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1669 ostr << " * [INFO] could not check characters after the string";
1670 m_error = ostr.str();
1671
1672 return false;
1673 }
1674
1675 if( ',' == m_buf[m_bufpos] )
1676 Pop();
1677
1678 aMFRotation.push_back( lrot );
1679 return true;
1680 }
1681
1682 ++m_bufpos;
1683
1684 while( true )
1685 {
1686 if( !EatSpace() )
1687 return false;
1688
1689 if( ']' == m_buf[m_bufpos] )
1690 break;
1691
1692 if( !ReadSFRotation( lrot ) )
1693 {
1694 std::ostringstream ostr;
1695 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1696 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1697 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1698 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1699 ostr << " * [INFO] " << m_error;
1700 m_error = ostr.str();
1701
1702 return false;
1703 }
1704
1705 aMFRotation.push_back( lrot );
1706
1707 if( !EatSpace() )
1708 {
1709 std::ostringstream ostr;
1710 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1711 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1712 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1713 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1714 ostr << " * [INFO] could not check characters after the string";
1715 m_error = ostr.str();
1716
1717 return false;
1718 }
1719
1720 if( ']' == m_buf[m_bufpos] )
1721 break;
1722
1723 if( ',' == m_buf[m_bufpos] )
1724 Pop();
1725
1726 }
1727
1728 ++m_bufpos;
1729 return true;
1730}
1731
1732
1733bool WRLPROC::ReadMFVec2f( std::vector< WRLVEC2F >& aMFVec2f )
1734{
1735 aMFVec2f.clear();
1736 size_t fileline = m_fileline;
1737 size_t linepos = m_bufpos;
1738
1739 if( !m_file )
1740 {
1741 m_error = "no open file";
1742 return false;
1743 }
1744
1745 WRLVEC2F lvec2f;
1746
1747 while( true )
1748 {
1749 if( !EatSpace() )
1750 return false;
1751
1752 // if the text is the start of a comment block, clear the buffer and loop
1753 if( '#' == m_buf[m_bufpos] )
1754 m_buf.clear();
1755 else
1756 break;
1757 }
1758
1759 if( m_buf[m_bufpos] != '[' )
1760 {
1761 if( !ReadSFVec2f( lvec2f ) )
1762 {
1763 std::ostringstream ostr;
1764 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1765 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1766 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1767 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1768 ostr << " * [INFO] " << m_error;
1769 m_error = ostr.str();
1770
1771 return false;
1772 }
1773
1774 if( !EatSpace() )
1775 {
1776 std::ostringstream ostr;
1777 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1778 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1779 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1780 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1781 ostr << " * [INFO] could not check characters after the string";
1782 m_error = ostr.str();
1783
1784 return false;
1785 }
1786
1787 if( ',' == m_buf[m_bufpos] )
1788 Pop();
1789
1790 aMFVec2f.push_back( lvec2f );
1791 return true;
1792 }
1793
1794 ++m_bufpos;
1795
1796 while( true )
1797 {
1798 if( !EatSpace() )
1799 return false;
1800
1801 if( ']' == m_buf[m_bufpos] )
1802 break;
1803
1804 if( !ReadSFVec2f( lvec2f ) )
1805 {
1806 std::ostringstream ostr;
1807 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1808 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1809 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1810 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1811 ostr << " * [INFO] " << m_error;
1812 m_error = ostr.str();
1813
1814 return false;
1815 }
1816
1817 aMFVec2f.push_back( lvec2f );
1818
1819 if( !EatSpace() )
1820 {
1821 std::ostringstream ostr;
1822 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1823 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1824 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1825 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1826 ostr << " * [INFO] could not check characters after the string";
1827 m_error = ostr.str();
1828
1829 return false;
1830 }
1831
1832 if( ']' == m_buf[m_bufpos] )
1833 break;
1834
1835 if( ',' == m_buf[m_bufpos] )
1836 Pop();
1837 }
1838
1839 ++m_bufpos;
1840 return true;
1841}
1842
1843
1844bool WRLPROC::ReadMFVec3f( std::vector< WRLVEC3F >& aMFVec3f )
1845{
1846 aMFVec3f.clear();
1847 size_t fileline = m_fileline;
1848 size_t linepos = m_bufpos;
1849
1850 if( !m_file )
1851 {
1852 m_error = "no open file";
1853 return false;
1854 }
1855
1856 WRLVEC3F lvec3f;
1857
1858 while( true )
1859 {
1860 if( !EatSpace() )
1861 return false;
1862
1863 // if the text is the start of a comment block, clear the buffer and loop
1864 if( '#' == m_buf[m_bufpos] )
1865 m_buf.clear();
1866 else
1867 break;
1868 }
1869
1870 if( m_buf[m_bufpos] != '[' )
1871 {
1872 if( !ReadSFVec3f( lvec3f ) )
1873 {
1874 std::ostringstream ostr;
1875 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1876 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1877 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1878 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1879 ostr << " * [INFO] " << m_error;
1880 m_error = ostr.str();
1881
1882 return false;
1883 }
1884
1885 if( !EatSpace() )
1886 {
1887 std::ostringstream ostr;
1888 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1889 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1890 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1891 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1892 ostr << " * [INFO] could not check characters after the string";
1893 m_error = ostr.str();
1894
1895 return false;
1896 }
1897
1898 if( ',' == m_buf[m_bufpos] )
1899 Pop();
1900
1901 aMFVec3f.push_back( lvec3f );
1902 return true;
1903 }
1904
1905 ++m_bufpos;
1906
1907 while( true )
1908 {
1909 if( !EatSpace() )
1910 return false;
1911
1912 if( ']' == m_buf[m_bufpos] )
1913 break;
1914
1915 if( !ReadSFVec3f( lvec3f ) )
1916 {
1917 std::ostringstream ostr;
1918 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1919 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1920 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1921 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1922 ostr << " * [INFO] " << m_error;
1923 m_error = ostr.str();
1924
1925 return false;
1926 }
1927
1928 aMFVec3f.push_back( lvec3f );
1929
1930 if( !EatSpace() )
1931 {
1932 std::ostringstream ostr;
1933 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
1934 ostr << " * [INFO] failed on file '" << m_filename << "'\n";
1935 ostr << " * [INFO] line " << fileline << ", char " << linepos << " -- ";
1936 ostr << "line " << m_fileline << ", char " << m_bufpos << "\n";
1937 ostr << " * [INFO] could not check characters after the string";
1938 m_error = ostr.str();
1939
1940 return false;
1941 }
1942
1943 if( !EatSpace() )
1944 return false;
1945
1946 if( ']' == m_buf[m_bufpos] )
1947 break;
1948
1949 if( ',' == m_buf[m_bufpos] )
1950 Pop();
1951
1952 }
1953
1954 ++m_bufpos;
1955 return true;
1956}
1957
1958
1959bool WRLPROC::eof( void )
1960{
1961 return m_eof;
1962}
1963
1964
1965std::string WRLPROC::GetError( void )
1966{
1967 return m_error;
1968}
1969
1970
1971bool WRLPROC::GetFilePosData( size_t& line, size_t& column )
1972{
1973 if( !m_file )
1974 {
1975 line = 0;
1976 column = 0;
1977 return false;
1978 }
1979
1980 line = m_fileline;
1981 column = m_bufpos;
1982
1983 return true;
1984}
1985
1986
1987std::string WRLPROC::GetFilePosition() const
1988{
1989 std::ostringstream retv;
1990
1991 if( !m_file )
1992 retv << "no file loaded to provide file position information";
1993 else
1994 retv << "at line " << m_fileline << ", column " << m_bufpos;
1995
1996 return retv.str();
1997}
1998
1999
2000std::string WRLPROC::GetFileName( void )
2001{
2002 if( !m_file )
2003 {
2004 m_error = "no open file";
2005 return "";
2006 }
2007
2008 return std::string( m_file->Source().ToUTF8() );
2009}
2010
2011
2012char WRLPROC::Peek( void )
2013{
2014 if( !m_file )
2015 {
2016 std::ostringstream ostr;
2017 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
2018 ostr << " * [BUG] no open file";
2019 m_error = ostr.str();
2020 return '\0';
2021 }
2022
2023 if( !EatSpace() )
2024 {
2025 if( m_error.empty() )
2026 {
2027 std::ostringstream ostr;
2028 ostr << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "\n";
2029 ostr << " * [INFO] failed to read data from file\n";
2030 m_error = ostr.str();
2031 }
2032
2033 return '\0';
2034 }
2035
2036 return m_buf[m_bufpos];
2037}
2038
2039
2040void WRLPROC::Pop( void )
2041{
2042 if( m_bufpos < m_buf.size() )
2043 ++m_bufpos;
2044}
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:872
bool ReadMFString(std::vector< std::string > &aMFString)
Definition wrlproc.cpp:1167
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:2040
bool ReadSFFloat(float &aSFFloat)
Definition wrlproc.cpp:811
char Peek(void)
Definition wrlproc.cpp:2012
std::string GetFileName(void)
Definition wrlproc.cpp:2000
bool EatSpace(void)
Definition wrlproc.cpp:193
WRLPROC(VRML_LINE_READER *aLineReader)
Definition wrlproc.cpp:63
bool ReadSFColor(WRLVEC3F &aSFColor)
Definition wrlproc.cpp:779
bool ReadSFVec2f(WRLVEC2F &aSFVec2f)
Definition wrlproc.cpp:1016
WRLVERSION GetVRMLType(void)
Definition wrlproc.cpp:232
bool ReadMFInt(std::vector< int > &aMFInt32)
Definition wrlproc.cpp:1509
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:1398
bool GetFilePosData(size_t &line, size_t &column)
Definition wrlproc.cpp:1971
bool getRawLine(void)
Definition wrlproc.cpp:144
std::string GetError(void)
Definition wrlproc.cpp:1965
bool ReadMFVec2f(std::vector< WRLVEC2F > &aMFVec2f)
Definition wrlproc.cpp:1733
std::string m_badchars
Definition wrlproc.h:113
bool ReadSFBool(bool &aSFBool)
Definition wrlproc.cpp:734
std::string m_filedir
Definition wrlproc.h:115
unsigned int m_bufpos
Definition wrlproc.h:109
bool eof(void)
Definition wrlproc.cpp:1959
bool ReadMFRotation(std::vector< WRLROTATION > &aMFRotation)
Definition wrlproc.cpp:1621
bool ReadMFVec3f(std::vector< WRLVEC3F > &aMFVec3f)
Definition wrlproc.cpp:1844
bool ReadName(std::string &aName)
Definition wrlproc.cpp:291
bool m_eof
Definition wrlproc.h:107
std::string GetFilePosition() const
Definition wrlproc.cpp:1987
bool DiscardNode(void)
Definition wrlproc.cpp:370
bool ReadMFColor(std::vector< WRLVEC3F > &aMFColor)
Definition wrlproc.cpp:1286
std::string m_buf
Definition wrlproc.h:106
bool ReadSFRotation(WRLROTATION &aSFRotation)
Definition wrlproc.cpp:942
bool ReadSFVec3f(WRLVEC3F &aSFVec3f)
Definition wrlproc.cpp:1087
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