0026922: Huge performance issue writing data to the output stream
[occt.git] / src / VrmlData / VrmlData_Scene.cxx
1 // Created on: 2006-05-25
2 // Created by: Alexander GRIGORIEV
3 // Copyright (c) 2006-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <VrmlData_Scene.hxx>
17 #include <VrmlData_InBuffer.hxx>
18 #include <VrmlData_Appearance.hxx>
19 #include <VrmlData_Box.hxx>
20 #include <VrmlData_Color.hxx>
21 #include <VrmlData_Cone.hxx>
22 #include <VrmlData_Coordinate.hxx>
23 #include <VrmlData_Cylinder.hxx>
24 #include <VrmlData_DataMapOfShapeAppearance.hxx>
25 #include <VrmlData_Group.hxx>
26 #include <VrmlData_ImageTexture.hxx>
27 #include <VrmlData_InBuffer.hxx>
28 #include <VrmlData_IndexedFaceSet.hxx>
29 #include <VrmlData_IndexedLineSet.hxx>
30 #include <VrmlData_Material.hxx>
31 #include <VrmlData_Normal.hxx>
32 #include <VrmlData_Scene.hxx>
33 #include <VrmlData_ShapeNode.hxx>
34 #include <VrmlData_Sphere.hxx>
35 #include <VrmlData_TextureCoordinate.hxx>
36 #include <VrmlData_UnknownNode.hxx>
37 //#include <VrmlData_WorldInfo.hxx>
38 #include <NCollection_Vector.hxx>
39 #include <TopoDS_TFace.hxx>
40 #include <TopoDS.hxx>
41 #include <TopoDS_Face.hxx>
42 #include <TopExp_Explorer.hxx>
43 #include <BRep_Builder.hxx>
44 #include <Precision.hxx>
45 #include <Standard_Version.hxx>
46 #include <VrmlData_WorldInfo.hxx>
47 #include <VrmlData_Geometry.hxx>
48
49 #ifdef _MSC_VER
50 #define _CRT_SECURE_NO_DEPRECATE
51 #pragma warning (disable:4996)
52 #endif
53
54 static void     dumpNode        (Standard_OStream&              theStream,
55                                  const Handle(VrmlData_Node)&   theNode,
56                                  const TCollection_AsciiString& theIndent);
57
58 static void     dumpNodeHeader  (Standard_OStream&              theStream,
59                                  const TCollection_AsciiString& theIndent,
60                                  const char *                   theType,
61                                  const char *                   theName);
62
63 //=======================================================================
64 //function : VrmlData_Scene
65 //purpose  : Constructor
66 //=======================================================================
67
68 VrmlData_Scene::VrmlData_Scene
69         (const Handle(NCollection_IncAllocator)& theAlloc)
70   : myLinearScale     (1.),
71     myStatus          (VrmlData_StatusOK),
72     myAllocator       (theAlloc.IsNull() ?
73                        new NCollection_IncAllocator : theAlloc.operator->()),
74     myLineError       (0),
75     myOutput          (0L),
76     myIndent          (2),
77     myCurrentIndent   (0),
78     myAutoNameCounter (0)
79 {
80   myWorldInfo = new VrmlData_WorldInfo (* this);
81   Standard_CString anInfo = "Generated by Open CASCADE Technology " OCC_VERSION_STRING;
82   myWorldInfo->AddInfo (anInfo);
83   myLstNodes.Append (myWorldInfo);
84   myAllNodes.Append (myWorldInfo);
85 }
86
87 //=======================================================================
88 //function : AddNode
89 //purpose  : 
90 //=======================================================================
91
92 const Handle(VrmlData_Node)& VrmlData_Scene::AddNode
93                                 (const Handle(VrmlData_Node)& theN,
94                                  const Standard_Boolean       isTopLevel)
95 {
96   if (theN.IsNull() == Standard_False)
97     if (theN->IsKind (STANDARD_TYPE(VrmlData_WorldInfo)) == Standard_False) {
98       myMutex.Lock();
99       const Handle(VrmlData_Node)& aNode =
100         myAllNodes.Append ((&theN->Scene()== this) ? theN : theN->Clone (NULL));
101       // Name is checked for uniqueness. If not, letter 'D' is appended until
102       // the name proves to be unique.
103       if (aNode->Name()[0] != '\0')
104         while (myNamedNodes.Add (aNode) == Standard_False)
105           aNode->setName (aNode->Name(), "D");
106       if (isTopLevel)
107         myLstNodes.Append (aNode);
108       myMutex.Unlock();
109       return aNode;
110     }
111   static Handle(VrmlData_Node) aNullNode;
112   aNullNode.Nullify();
113   return aNullNode;
114 }
115
116 //=======================================================================
117 //function : operator <<
118 //purpose  : Export to text stream (file or else)
119 //=======================================================================
120
121 Standard_OStream& operator << (Standard_OStream&     theOutput,
122                                const VrmlData_Scene& theScene)
123 {
124   VrmlData_Scene& aScene = const_cast <VrmlData_Scene&> (theScene);
125   aScene.myMutex.Lock();
126   aScene.myCurrentIndent = 0;
127   aScene.myLineError = 0;
128   aScene.myOutput = 0L;
129   aScene.myNamedNodesOut.Clear();
130   aScene.myUnnamedNodesOut.Clear();
131   aScene.myAutoNameCounter = 0;
132
133   // Dummy write
134
135   VrmlData_Scene::Iterator anIterD(aScene.myLstNodes);
136   for (; anIterD.More(); anIterD.Next()) {
137     const Handle(VrmlData_Node)& aNode = anIterD.Value();
138     if (aNode.IsNull() == Standard_False) {
139       const VrmlData_ErrorStatus aStatus = aScene.WriteNode (0L, aNode);
140       if (aStatus != VrmlData_StatusOK &&
141           aStatus != VrmlData_NotImplemented)
142         break;
143     }
144   }
145
146   aScene.myOutput = &theOutput;
147   aScene.myNamedNodesOut.Clear();
148   theOutput << "#VRML V2.0 utf8\n\n";
149
150   // Real write
151
152   VrmlData_Scene::Iterator anIter(aScene.myLstNodes);
153   for (; anIter.More(); anIter.Next()) {
154     const Handle(VrmlData_Node)& aNode = anIter.Value();
155     if (aNode.IsNull() == Standard_False) {
156       const VrmlData_ErrorStatus aStatus = aScene.WriteNode (0L, aNode);
157       if (aStatus != VrmlData_StatusOK &&
158           aStatus != VrmlData_NotImplemented)
159         break;
160     }
161   }
162   aScene.myOutput = 0L;
163   aScene.myNamedNodesOut.Clear();
164   aScene.myUnnamedNodesOut.Clear();
165   aScene.myMutex.Unlock();
166   return theOutput;
167 }
168
169 //=======================================================================
170 //function : SetVrmlDir
171 //purpose  : 
172 //=======================================================================
173
174 void VrmlData_Scene::SetVrmlDir (const TCollection_ExtendedString& theDir)
175 {
176   TCollection_ExtendedString& aDir = myVrmlDir.Append (theDir);
177   const Standard_ExtCharacter aTerminator = aDir.Value(aDir.Length());
178   if (aTerminator != Standard_ExtCharacter('\\') &&
179       aTerminator != Standard_ExtCharacter('/'))
180 #ifdef _WIN32
181     aDir += TCollection_ExtendedString ("\\");
182 #else
183     aDir += TCollection_ExtendedString ("/");
184 #endif
185 }
186
187 //=======================================================================
188 //function : WorldInfo
189 //purpose  : 
190 //=======================================================================
191
192 const Handle(VrmlData_WorldInfo)& VrmlData_Scene::WorldInfo() const
193 {
194   return myWorldInfo;
195 }
196
197 //=======================================================================
198 //function : readLine
199 //purpose  : 
200 //=======================================================================
201
202 VrmlData_ErrorStatus VrmlData_Scene::readLine (VrmlData_InBuffer& theBuffer)
203 {
204   VrmlData_ErrorStatus aStatus = VrmlData_StatusOK;
205   if (theBuffer.Input.eof())
206     aStatus = VrmlData_EndOfFile;
207   else {
208     theBuffer.Input.getline (theBuffer.Line, sizeof(theBuffer.Line));
209     theBuffer.LineCount++;
210     const int stat = theBuffer.Input.rdstate();
211     if (stat & ios::badbit) {
212       aStatus = VrmlData_UnrecoverableError;
213     }
214     else if (stat & ios::failbit) {
215       if (stat & ios::eofbit) {
216         aStatus = VrmlData_EndOfFile;
217       }
218       else {
219         aStatus = VrmlData_GeneralError;
220       }
221     }
222     theBuffer.LinePtr = &theBuffer.Line[0];
223     theBuffer.IsProcessed = Standard_False;
224   }
225   return aStatus;
226 }
227
228 //=======================================================================
229 //function : ReadLine
230 //purpose  : 
231 //=======================================================================
232
233 VrmlData_ErrorStatus VrmlData_Scene::ReadLine (VrmlData_InBuffer& theBuffer)
234 {
235   VrmlData_ErrorStatus aStatus (VrmlData_StatusOK); 
236
237   while (aStatus == VrmlData_StatusOK) {
238     // Find the first significant character of the line
239     for (; * theBuffer.LinePtr != '\0'; theBuffer.LinePtr++) {
240       if (* theBuffer.LinePtr != ' ' && * theBuffer.LinePtr != '\t'
241           && * theBuffer.LinePtr != ',')
242       {
243         if (* theBuffer.LinePtr == '\n' || * theBuffer.LinePtr == '\r' ||
244             * theBuffer.LinePtr == '#')
245           // go requesting the next line
246           break;
247         goto nonempty_line;
248       }
249     }
250     // the line is empty here (no significant characters). Read the next one.
251     aStatus = readLine (theBuffer);
252   }
253
254   // error or EOF detected
255   return aStatus;
256
257  nonempty_line:
258   // Try to detect comment
259   if (theBuffer.IsProcessed == Standard_False) {
260     Standard_Boolean isQuoted (Standard_False);
261     Standard_Integer anOffset (0);
262     char * ptr = theBuffer.LinePtr;
263     for (; * ptr != '\0'; ptr++) {
264       if (anOffset)
265         * ptr = ptr[anOffset];
266       if (* ptr == '\n' || * ptr == '\r' || * ptr == '#') {
267         if (isQuoted == Standard_False) {
268           * ptr = '\0';
269           break;
270         }
271       } else if (* ptr == '\\' && isQuoted)
272         ptr[0] = ptr[++anOffset];
273       else if (* ptr == '\"')
274         isQuoted = !isQuoted;
275     }
276     theBuffer.IsProcessed = Standard_True;
277   }
278   return aStatus;
279 }
280
281 //=======================================================================
282 //function : readHeader
283 //purpose  : 
284 //=======================================================================
285
286 VrmlData_ErrorStatus VrmlData_Scene::readHeader (VrmlData_InBuffer& theBuffer)
287 {
288   VrmlData_ErrorStatus aStat = readLine (theBuffer);
289   if (aStat == VrmlData_StatusOK &&
290       !VRMLDATA_LCOMPARE(theBuffer.LinePtr, "#VRML V2.0"))
291     aStat = VrmlData_NotVrmlFile;
292   else 
293     aStat = readLine(theBuffer);
294   return aStat;
295 }
296
297 //=======================================================================
298 //function : operator <<
299 //purpose  : Import from text stream (file or else)
300 //=======================================================================
301
302 VrmlData_Scene& VrmlData_Scene::operator << (Standard_IStream& theInput)
303 {
304   VrmlData_InBuffer aBuffer (theInput);
305   myMutex.Lock();
306   // Read the VRML header
307   myStatus = readHeader (aBuffer);
308   const Handle(VrmlData_UnknownNode) aNullNode= new VrmlData_UnknownNode(*this);
309 //   if (myStatus == StatusOK)
310 //     myStatus = ReadLine (aBuffer);
311   // Read VRML data by nodes
312   for(;;) {
313     if (!VrmlData_Node::OK(myStatus, ReadLine(aBuffer))) {
314       if (myStatus == VrmlData_EndOfFile)
315         myStatus = VrmlData_StatusOK;
316       break;
317     }
318     // this line provides the method ReadNode in the present context
319     Handle(VrmlData_Node) aNode;
320     myStatus = aNullNode->ReadNode (aBuffer, aNode);
321     // Unknown nodes are not stored however they do not generate error
322     if (myStatus != VrmlData_StatusOK)
323       break;
324     if (aNode.IsNull() == Standard_False /*&&
325         !aNode->IsKind (STANDARD_TYPE(VrmlData_UnknownNode))*/)
326     {
327       if (aNode->IsKind (STANDARD_TYPE(VrmlData_WorldInfo)) == Standard_False)
328         myLstNodes.Append (aNode);
329       else if (aNode->IsDefault() == Standard_False) {
330         const Handle(VrmlData_WorldInfo) aInfo =
331           Handle(VrmlData_WorldInfo)::DownCast (aNode);
332         myWorldInfo->SetTitle (aInfo->Title());
333         NCollection_List <const char *>::Iterator anIterInfo =
334           aInfo->InfoIterator();
335         for (; anIterInfo.More(); anIterInfo.Next())
336           myWorldInfo->AddInfo (anIterInfo.Value());
337       }
338     }
339   }
340   if (myStatus != VrmlData_StatusOK)
341     myLineError = aBuffer.LineCount;
342   myMutex.Unlock();
343   return * this;
344 }
345
346 //=======================================================================
347 //function : FindNode
348 //purpose  : 
349 //=======================================================================
350
351 Handle(VrmlData_Node) VrmlData_Scene::FindNode
352                                 (const char                   * theName,
353                                  const Handle(Standard_Type)& /*theType*/) const
354 {
355   Handle(VrmlData_Node) aResult;
356 #ifdef USE_LIST_API
357   Iterator anIter (myAllNodes);
358   for (; anIter.More(); anIter.Next())
359     if (!strcmp (anIter.Value()->Name(), theName)) {
360       aResult = anIter.Value();
361       if (theType.IsNull())
362         break;
363       if (aResult->IsKind(theType))
364         break;
365       aResult.Nullify();
366     }
367 #else
368   const Handle(VrmlData_UnknownNode) aDummyNode = new VrmlData_UnknownNode;
369   aDummyNode->myName = theName;
370   if (myNamedNodes.Contains (aDummyNode))
371     aResult = const_cast<VrmlData_MapOfNode&>(myNamedNodes).Added(aDummyNode);
372 #endif
373   return aResult;
374 }
375
376 //=======================================================================
377 //function : FindNode
378 //purpose  : 
379 //=======================================================================
380
381 Handle(VrmlData_Node) VrmlData_Scene::FindNode
382                                         (const char *   theName,
383                                          gp_Trsf&       theLocation) const
384 {
385   gp_Trsf aLoc;
386   Handle(VrmlData_Node) aResult;
387   Iterator anIter (myLstNodes);
388   for (; anIter.More(); anIter.Next()) {
389     const Handle(VrmlData_Node)& aNode = anIter.Value();
390     if (aNode.IsNull())
391       continue;
392     // Match a top-level node name
393     if (strcmp(aNode->Name(), theName) == 0) {
394       aResult = aNode;
395       theLocation = aLoc;
396       break;
397     }
398     // Try a Group type of node
399     if (aNode->IsKind(STANDARD_TYPE(VrmlData_Group)))
400     {
401       const Handle(VrmlData_Group) aGroup =
402         Handle(VrmlData_Group)::DownCast (aNode);
403       if (aGroup.IsNull() == Standard_False) {
404         aResult = aGroup->FindNode(theName, theLocation);
405         if (aResult.IsNull() == Standard_False)
406           break;
407       }
408     }
409   }
410   return aResult;
411 }
412
413 //=======================================================================
414 //function : ReadWord
415 //purpose  : 
416 //=======================================================================
417
418 VrmlData_ErrorStatus VrmlData_Scene::ReadWord
419                                       (VrmlData_InBuffer&           theBuffer,
420                                        TCollection_AsciiString&     theWord)
421 {
422   VrmlData_ErrorStatus aStatus = ReadLine(theBuffer);
423   if (aStatus == VrmlData_StatusOK) {
424     char * ptr = theBuffer.LinePtr;
425     while (* ptr != '\0' && * ptr != '\n' && * ptr != '\r' &&
426            * ptr != ' '  && * ptr != '\t' && * ptr != '{' && * ptr != '}' &&
427            * ptr != ','  && * ptr != '['  && * ptr != ']')
428       ptr++;
429     const Standard_Integer aLen = Standard_Integer(ptr - theBuffer.LinePtr);
430     if (aLen <= 0)
431       aStatus = VrmlData_StringInputError;
432     else {
433       theWord = TCollection_AsciiString ((Standard_CString)theBuffer.LinePtr,
434                                          aLen);
435       theBuffer.LinePtr = ptr;
436     }
437   }
438   return aStatus;
439 }
440
441 //=======================================================================
442 //function : createNode
443 //purpose  : 
444 //=======================================================================
445
446 VrmlData_ErrorStatus VrmlData_Scene::createNode
447                                       (VrmlData_InBuffer&           theBuffer,
448                                        Handle(VrmlData_Node)&       theNode,
449                                        const Handle(Standard_Type)& theType)
450 {
451   VrmlData_ErrorStatus    aStatus;
452   Handle(VrmlData_Node)   aNode;
453   TCollection_AsciiString aName;
454
455   // Read the DEF token to assign the node name
456   if (VrmlData_Node::OK(aStatus, ReadLine(theBuffer))) {
457     if (VRMLDATA_LCOMPARE(theBuffer.LinePtr, "DEF")) {
458       if (VrmlData_Node::OK(aStatus, ReadWord (theBuffer, aName)))
459         aStatus = ReadLine(theBuffer);
460     } else if (VRMLDATA_LCOMPARE(theBuffer.LinePtr, "NULL")) {
461       theNode.Nullify();
462       return aStatus;
463     }
464   }
465
466   const char * strName = aName.ToCString();
467   if (aStatus == VrmlData_StatusOK) {
468     // create the new node
469     if (VRMLDATA_LCOMPARE(theBuffer.LinePtr, "Appearance"))
470       aNode = new VrmlData_Appearance     (* this, strName);
471     else if (VRMLDATA_LCOMPARE(theBuffer.LinePtr, "Shape"))
472       aNode = new VrmlData_ShapeNode      (* this, strName);
473     else if (VRMLDATA_LCOMPARE(theBuffer.LinePtr, "Box"))
474       aNode = new VrmlData_Box            (* this, strName);
475     else if (VRMLDATA_LCOMPARE(theBuffer.LinePtr, "Color"))
476       aNode = new VrmlData_Color          (* this, strName);
477     else if (VRMLDATA_LCOMPARE(theBuffer.LinePtr, "Cone"))
478       aNode = new VrmlData_Cone           (* this, strName);
479     else if (VRMLDATA_LCOMPARE(theBuffer.LinePtr, "Coordinate")) {
480       aNode = new VrmlData_Coordinate     (* this, strName);
481       
482       // Check for "Coordinate3"
483       if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "3"))
484         theBuffer.LinePtr++;
485     }
486     else if (VRMLDATA_LCOMPARE(theBuffer.LinePtr, "Cylinder"))
487       aNode = new VrmlData_Cylinder       (* this, strName);
488     else if (VRMLDATA_LCOMPARE(theBuffer.LinePtr, "Group"))
489       aNode = new VrmlData_Group          (* this, strName,
490                                            Standard_False);
491     else if (VRMLDATA_LCOMPARE(theBuffer.LinePtr, "Transform"))
492       aNode = new VrmlData_Group          (* this, strName,
493                                            Standard_True);
494     else if (VRMLDATA_LCOMPARE(theBuffer.LinePtr, "Inline"))
495       aNode = new VrmlData_Group          (* this, strName,
496                                            Standard_False);
497     else if (VRMLDATA_LCOMPARE(theBuffer.LinePtr, "Separator"))
498       aNode = new VrmlData_Group          (* this, strName,
499                                            Standard_False);
500     else if (VRMLDATA_LCOMPARE(theBuffer.LinePtr, "Switch"))
501       aNode = new VrmlData_Group          (* this, strName,
502                                            Standard_False);
503     else if (VRMLDATA_LCOMPARE(theBuffer.LinePtr, "ImageTexture"))
504       aNode = new VrmlData_ImageTexture   (* this, strName);
505     else if (VRMLDATA_LCOMPARE(theBuffer.LinePtr, "IndexedFaceSet"))
506       aNode = new VrmlData_IndexedFaceSet (* this, strName);
507     else if (VRMLDATA_LCOMPARE(theBuffer.LinePtr, "IndexedLineSet"))
508       aNode = new VrmlData_IndexedLineSet (* this, strName);
509     else if (VRMLDATA_LCOMPARE(theBuffer.LinePtr, "Material"))
510       aNode = new VrmlData_Material       (* this, strName);
511     else if (VRMLDATA_LCOMPARE(theBuffer.LinePtr, "Normal"))
512       aNode = new VrmlData_Normal         (* this, strName);
513     else if (VRMLDATA_LCOMPARE(theBuffer.LinePtr, "Sphere"))
514       aNode = new VrmlData_Sphere         (* this, strName);
515     else if (VRMLDATA_LCOMPARE(theBuffer.LinePtr, "TextureCoordinate"))
516       aNode = new VrmlData_TextureCoordinate(* this, strName);
517     else if (VRMLDATA_LCOMPARE(theBuffer.LinePtr, "WorldInfo"))
518       aNode = new VrmlData_WorldInfo      (* this, strName);
519     else {
520       void * isProto = VRMLDATA_LCOMPARE(theBuffer.LinePtr, "PROTO");
521       TCollection_AsciiString aTitle;
522       aStatus = ReadWord (theBuffer, aTitle);
523       if (isProto) {
524         aStatus = ReadLine(theBuffer);
525         if (aStatus == VrmlData_StatusOK) {
526           if (theBuffer.LinePtr[0] != '[')
527             aStatus = VrmlData_VrmlFormatError;
528           else {
529             theBuffer.LinePtr++;
530             Standard_Integer aLevelCounter(0);
531    // This loop searches for any opening bracket '['.
532    // Such bracket increments the level counter. A closing bracket decrements
533    // the counter. The loop terminates when the counter becomes negative.
534             while (aLevelCounter >= 0 &&
535                    (aStatus = ReadLine(theBuffer)) == VrmlData_StatusOK) {
536               int aChar;
537               while ((aChar = theBuffer.LinePtr[0]) != '\0') {
538                 theBuffer.LinePtr++;
539                 if        (aChar == '[') {
540                   aLevelCounter++;
541                   break;
542                 } else if (aChar == ']') {
543                   aLevelCounter--;
544                   break;
545                 }
546               }
547             }
548           }
549         }
550       }
551       if (aStatus == VrmlData_StatusOK)
552         aNode = new VrmlData_UnknownNode(* this,
553                                          strName,
554                                          aTitle.ToCString());
555     }
556   }
557   aStatus = ReadLine(theBuffer);
558   if (aNode.IsNull() == Standard_False) {
559     if (aNode->Name()[0] != '\0') 
560       myNamedNodes.Add (aNode);
561     if (theType.IsNull() == Standard_False)
562       if (aNode->IsKind(theType) == Standard_False)
563         aStatus = VrmlData_VrmlFormatError;
564   }
565   if (aStatus == VrmlData_StatusOK) {
566     if (theBuffer.LinePtr[0] == '{') {
567       theBuffer.LinePtr++;
568       theNode = aNode;
569       myAllNodes.Append(aNode);
570     } else {
571       aStatus = VrmlData_VrmlFormatError;
572     }
573   }
574   return aStatus;
575 }
576
577 //=======================================================================
578 //function : operator TopoDS_Shape
579 //purpose  : 
580 //=======================================================================
581
582 VrmlData_Scene::operator TopoDS_Shape () const
583 {
584   TopoDS_Shape aShape;
585   VrmlData_Scene::createShape (aShape, myLstNodes, 0L);
586   return aShape;
587 }
588
589 //=======================================================================
590 //function : GetShape
591 //purpose  : 
592 //=======================================================================
593
594 TopoDS_Shape VrmlData_Scene::GetShape (VrmlData_DataMapOfShapeAppearance& aMap)
595 {
596   TopoDS_Shape aShape;
597   VrmlData_Scene::createShape (aShape, myLstNodes, &aMap);
598   return aShape;
599 }
600
601 //=======================================================================
602 //function : createShape
603 //purpose  : 
604 //=======================================================================
605
606 void VrmlData_Scene::createShape
607                 (TopoDS_Shape&                      outShape,
608                  const VrmlData_ListOfNode&         lstNodes,
609                  VrmlData_DataMapOfShapeAppearance* pMapShapeApp)
610 {
611   TopoDS_Shape aSingleShape;  // used when there is a single ShapeNode
612   Standard_Boolean isSingleShape (Standard_True);
613   BRep_Builder aBuilder;
614   outShape.Nullify();
615   aBuilder.MakeCompound(TopoDS::Compound(outShape));
616   aSingleShape.Orientation(TopAbs_FORWARD);
617
618   Iterator anIter (lstNodes);
619   for (; anIter.More(); anIter.Next()) {
620     // Try a Shape type of node
621     const Handle(VrmlData_ShapeNode) aNodeShape =
622       Handle(VrmlData_ShapeNode)::DownCast (anIter.Value());
623     if (aNodeShape.IsNull() == Standard_False) {
624       const Handle(VrmlData_Geometry) aNodeGeom =
625         Handle(VrmlData_Geometry)::DownCast(aNodeShape->Geometry());
626       if (aNodeGeom.IsNull() == Standard_False) {
627         if (aSingleShape.IsNull() == Standard_False)
628           isSingleShape = Standard_False;
629         const Handle(TopoDS_TShape) aTShape = aNodeGeom->TShape();
630         aSingleShape.TShape(aTShape);
631         if (aSingleShape.IsNull() == Standard_False) {
632           aBuilder.Add (outShape, aSingleShape);
633           if (pMapShapeApp != 0L) {
634             const Handle(VrmlData_Appearance)& anAppearance =
635               aNodeShape->Appearance();
636             if (anAppearance.IsNull() == Standard_False) {
637               // Check if the current topology is a single face
638               if (aTShape->IsKind(STANDARD_TYPE(TopoDS_TFace)))
639                 pMapShapeApp->Bind(aTShape, anAppearance);
640               else {
641                 // This is not a face, explode it in faces and bind each face
642                 TopoDS_Shape aCurShape;
643                 aCurShape.TShape(aTShape);
644                 TopExp_Explorer anExp(aCurShape, TopAbs_FACE);
645                 for (; anExp.More(); anExp.Next()) {
646                   const TopoDS_Face& aFace = TopoDS::Face(anExp.Current());
647                   pMapShapeApp->Bind(aFace.TShape(), anAppearance);
648                 }
649               }
650             }
651           }
652         }
653       }
654       continue;
655     }
656     // Try a Group type of node
657     const Handle(VrmlData_Group) aNodeGroup =
658       Handle(VrmlData_Group)::DownCast (anIter.Value());
659     if (aNodeGroup.IsNull() == Standard_False) {
660       TopoDS_Shape aShape;
661       aNodeGroup->Shape(aShape, pMapShapeApp);
662       if (aShape.IsNull() == Standard_False) {
663         aBuilder.Add (outShape, aShape);
664         isSingleShape = Standard_False;
665       }
666     }
667   }
668   if (isSingleShape)
669     outShape = aSingleShape;
670 }
671
672 //=======================================================================
673 //function : ReadReal
674 //purpose  : 
675 //=======================================================================
676
677 VrmlData_ErrorStatus VrmlData_Scene::ReadReal
678                                 (VrmlData_InBuffer& theBuffer,
679                                  Standard_Real&     theResult,
680                                  Standard_Boolean   isScale,
681                                  Standard_Boolean   isOnlyPositive) const
682 {
683   Standard_Real aResult(0.);
684   VrmlData_ErrorStatus aStatus;
685   if (VrmlData_Node::OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) {
686     char * endptr;
687     aResult = Strtod (theBuffer.LinePtr, &endptr);
688     if (endptr == theBuffer.LinePtr)
689       aStatus = VrmlData_NumericInputError;
690     else if (isOnlyPositive && aResult < 0.001*Precision::Confusion())
691       aStatus = VrmlData_IrrelevantNumber;
692     else {
693       theResult = isScale ? (aResult * myLinearScale) : aResult;
694       theBuffer.LinePtr = endptr;
695     }
696   }
697   return aStatus;
698 }
699
700 //=======================================================================
701 //function : ReadXYZ
702 //purpose  : 
703 //=======================================================================
704
705 VrmlData_ErrorStatus VrmlData_Scene::ReadXYZ
706                                 (VrmlData_InBuffer&     theBuffer,
707                                  gp_XYZ&                theXYZ,
708                                  Standard_Boolean       isScale,
709                                  Standard_Boolean       isOnlyPos) const
710 {
711   Standard_Real aVal[3] = {0., 0., 0.};
712   VrmlData_ErrorStatus aStatus = VrmlData_StatusOK;
713   for (Standard_Integer i = 0; i < 3; i++) {
714     if (!VrmlData_Node::OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
715       break;
716     char * endptr;
717     aVal[i] = Strtod (theBuffer.LinePtr, &endptr);
718     if (endptr == theBuffer.LinePtr) {
719       aStatus = VrmlData_NumericInputError;
720       break;
721     } else {
722       if (isOnlyPos && aVal[i] < 0.001*Precision::Confusion()) {
723         aStatus = VrmlData_IrrelevantNumber;
724         break;
725       }
726       theBuffer.LinePtr = endptr;
727     }
728   }
729   if (aStatus == VrmlData_StatusOK) {
730     if (isScale) {
731       theXYZ.SetCoord (aVal[0] * myLinearScale,
732                        aVal[1] * myLinearScale,
733                        aVal[2] * myLinearScale);
734     }
735     else {
736       theXYZ.SetCoord (aVal[0], aVal[1], aVal[2]);
737     }
738   }
739   return aStatus;
740 }
741
742 //=======================================================================
743 //function : ReadXY
744 //purpose  : 
745 //=======================================================================
746
747 VrmlData_ErrorStatus VrmlData_Scene::ReadXY
748                                 (VrmlData_InBuffer&     theBuffer,
749                                  gp_XY&                 theXY,
750                                  Standard_Boolean       isScale,
751                                  Standard_Boolean       isOnlyPos) const
752 {
753   Standard_Real aVal[2] = {0., 0.};
754   VrmlData_ErrorStatus aStatus = VrmlData_StatusOK;
755   for (Standard_Integer i = 0; i < 2; i++) {
756     if (!VrmlData_Node::OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
757       break;
758     char * endptr;
759     aVal[i] = Strtod (theBuffer.LinePtr, &endptr);
760     if (endptr == theBuffer.LinePtr) {
761       aStatus = VrmlData_NumericInputError;
762       break;
763     } else {
764       if (isOnlyPos && aVal[i] < 0.001*Precision::Confusion()) {
765         aStatus = VrmlData_IrrelevantNumber;
766         break;
767       }
768       theBuffer.LinePtr = endptr;
769     }
770   }
771   if (aStatus == VrmlData_StatusOK) {
772     if (isScale)
773       theXY.SetCoord (aVal[0] * myLinearScale, aVal[1] * myLinearScale);
774     else
775       theXY.SetCoord (aVal[0], aVal[1]);
776   }
777   return aStatus;
778 }
779
780 //=======================================================================
781 //function : ReadArrIndex
782 //purpose  : Read the body of the data node (comma-separated list of int
783 //           multiplets)
784 //=======================================================================
785
786 VrmlData_ErrorStatus VrmlData_Scene::ReadArrIndex
787                                   (VrmlData_InBuffer&         theBuffer,
788                                    const Standard_Integer **& theArray,
789                                    Standard_Size&             theNBlocks) const
790 {
791   VrmlData_ErrorStatus aStatus;
792   theNBlocks = 0;
793   if (VrmlData_Node::OK(aStatus, ReadLine(theBuffer))) {
794     if (theBuffer.LinePtr[0] != '[')  // opening bracket
795       aStatus = VrmlData_VrmlFormatError;
796     else {
797       theBuffer.LinePtr++;
798       NCollection_Vector<const Standard_Integer *> vecIndice;
799       NCollection_Vector<Standard_Integer>         vecInt;
800       Standard_Boolean isMore (Standard_True);
801       long             anIntValue;
802
803       // Loop reading integers from the stream
804       while (isMore && VrmlData_Node::OK(aStatus, ReadLine(theBuffer)))
805       {
806         // closing bracket, in case that it follows a comma
807         if (theBuffer.LinePtr[0] == ']') {
808           theBuffer.LinePtr++;
809           break;
810         }
811         if (!VrmlData_Node::OK(aStatus, VrmlData_Node::ReadInteger(theBuffer,
812                                                                    anIntValue)))
813           break;
814         // Check for valid delimiter (']' or ',') 
815         if (!VrmlData_Node::OK(aStatus, ReadLine(theBuffer)))
816           break;
817         if (theBuffer.LinePtr[0] == ']') {
818           theBuffer.LinePtr++;
819           isMore = Standard_False;
820         }
821         if (anIntValue >= 0)
822           // The input value is a node index, store it in the buffer vector
823           vecInt.Append (static_cast<Standard_Integer> (anIntValue));
824         if ((anIntValue < 0 || isMore == Standard_False)
825             && vecInt.Length() > 0)
826         {
827           const Standard_Integer aLen = vecInt.Length();
828           // The input is the end-of-face, store and close this face
829           Standard_Integer * bufFace = static_cast <Standard_Integer *>
830             (myAllocator->Allocate((aLen+1) * sizeof(Standard_Integer)));
831           if (bufFace == 0L) {
832             aStatus = VrmlData_UnrecoverableError;
833             break;
834           }
835           bufFace[0] = aLen;
836           for (Standard_Integer i = 0; i < aLen; i++)
837             bufFace[i+1] = vecInt(i);
838           vecInt.Clear();
839           vecIndice.Append(bufFace);
840         }
841       }
842       if (aStatus == VrmlData_StatusOK) {
843         const Standard_Size aNbBlocks =
844           static_cast <Standard_Size> (vecIndice.Length());
845         if (aNbBlocks) {
846           const Standard_Integer ** anArray =
847             static_cast <const Standard_Integer **>
848             (myAllocator->Allocate (aNbBlocks * sizeof(Standard_Integer *)));
849           if (anArray == 0L)
850             aStatus = VrmlData_UnrecoverableError;
851           else {
852             for (size_t i = 0; i < aNbBlocks; i++)
853               anArray[i] = vecIndice((Standard_Integer)i);
854             theNBlocks = aNbBlocks;
855             theArray = anArray;
856           } 
857         }
858       }
859     }
860   }
861   return aStatus;
862 }
863
864 //=======================================================================
865 //function : writeArrIndex
866 //purpose  : 
867 //=======================================================================
868
869 VrmlData_ErrorStatus VrmlData_Scene::WriteArrIndex
870                                 (const char *              thePrefix,
871                                  const Standard_Integer ** theArrIndex,
872                                  const Standard_Size       theNbBlocks) const
873 {
874   VrmlData_ErrorStatus aStatus (VrmlData_StatusOK);
875   if (theNbBlocks && (IsDummyWrite() == Standard_False)) {
876     if (VrmlData_Node::OK (aStatus,
877                            WriteLine (thePrefix, "[", 1)))
878     {
879       const size_t aLineLimit = (myCurrentIndent < 41) ? 36 : 100;
880       char buf[256];
881       for (Standard_Size iBlock = 0; iBlock < theNbBlocks; iBlock++) {
882         const Standard_Integer nVal (* theArrIndex[iBlock]);
883         const Standard_Integer * arrVal = theArrIndex[iBlock]+1;
884         switch (nVal) {
885         case 1:
886           Sprintf (buf, "%d,", arrVal[0]);
887           break;
888         case 2:
889           Sprintf (buf, "%d,%d,", arrVal[0], arrVal[1]);
890           break;
891         case 3:
892           Sprintf (buf, "%d,%d,%d,", arrVal[0], arrVal[1], arrVal[2]);
893           break;
894         case 4:
895           Sprintf (buf, "%d,%d,%d,%d,",
896                    arrVal[0], arrVal[1], arrVal[2], arrVal[3]);
897           break;
898         default:
899           if (nVal > 0) {
900             char * ptr = &buf[0];
901             for (Standard_Integer i = 0; i < nVal; i++) {
902               Sprintf (ptr, "%d,", arrVal[i]);
903               if (i == nVal - 1)
904                 break;
905               ptr = strchr (ptr, ',') + 1;
906               if ((ptr - &buf[0]) > (ptrdiff_t)aLineLimit) {
907                 WriteLine(buf);
908                 ptr = &buf[0];
909               }
910             }
911           }
912         }
913         WriteLine (buf, iBlock < theNbBlocks-1 ? "-1," : "-1");
914       }
915       if (aStatus == VrmlData_StatusOK)
916         aStatus = WriteLine ("]", 0L, -1);
917     }
918   }
919   return aStatus;
920 }
921
922 //=======================================================================
923 //function : WriteXYZ
924 //purpose  : 
925 //=======================================================================
926
927 VrmlData_ErrorStatus VrmlData_Scene::WriteXYZ
928                                 (const gp_XYZ&          theXYZ,
929                                  const Standard_Boolean isApplyScale,
930                                  const char             * thePostfix) const
931 {
932   char buf[240];
933   if (IsDummyWrite() == Standard_False) {
934     if (isApplyScale && myLinearScale > Precision::Confusion())
935       Sprintf (buf, "%.12g %.12g %.12g%s", theXYZ.X() / myLinearScale,
936                theXYZ.Y() / myLinearScale, theXYZ.Z() / myLinearScale,
937                thePostfix ? thePostfix : "");
938     else
939       Sprintf (buf, "%.12g %.12g %.12g%s", theXYZ.X(), theXYZ.Y(), theXYZ.Z(),
940                thePostfix ? thePostfix : "");
941   }
942   return WriteLine (buf);
943 }
944
945 //=======================================================================
946 //function : WriteLine
947 //purpose  : write the given string prepending the current indentation
948 //=======================================================================
949
950 VrmlData_ErrorStatus VrmlData_Scene::WriteLine
951                                         (const char             * theLin0,
952                                          const char             * theLin1,
953                                          const Standard_Integer theIndent) const
954 {
955   static const char spaces[] = "                                        "
956                                "                                        ";
957   VrmlData_ErrorStatus& aStatus =
958     const_cast <VrmlData_ErrorStatus&> (myStatus);
959   if (IsDummyWrite())
960     aStatus = VrmlData_StatusOK;
961   else {
962     Standard_Integer& aCurrentIndent =
963       const_cast <Standard_Integer&> (myCurrentIndent);
964     if (theIndent < 0)
965       aCurrentIndent -= myIndent;
966     if (aCurrentIndent < 0)
967       aCurrentIndent = 0;
968     if (theLin0 == 0L && theLin1 == 0L)
969       (* myOutput) << "\n";
970     else {
971       const Standard_Integer nSpaces = Min (aCurrentIndent, sizeof(spaces)-1);
972       (* myOutput) << &spaces[sizeof(spaces)-1 - nSpaces];
973       if (theLin0) {
974         (* myOutput) << theLin0;
975         if (theLin1)
976           (* myOutput) << " " << theLin1;
977       } else
978         (* myOutput) << theLin1;
979       (* myOutput) << "\n";
980     }
981     const int stat = myOutput->rdstate();
982     if (stat & ios::badbit)
983       aStatus = VrmlData_UnrecoverableError;
984     else if (stat & ios::failbit)
985 //       if (stat & ios::eofbit)
986 //         aStatus = VrmlData_EndOfFile;
987 //       else
988       aStatus = VrmlData_GeneralError;
989     if (theIndent > 0)
990       aCurrentIndent += myIndent;
991   }
992   return myStatus;
993 }
994
995 //=======================================================================
996 //function : WriteNode
997 //purpose  : 
998 //=======================================================================
999
1000 VrmlData_ErrorStatus VrmlData_Scene::WriteNode
1001                                 (const char *                 thePrefix,
1002                                  const Handle(VrmlData_Node)& theNode) const
1003 {
1004   VrmlData_ErrorStatus aStatus (VrmlData_StatusOK);
1005   Standard_Boolean isNoName (Standard_False);
1006   if (theNode->Name() == 0L)
1007     isNoName = Standard_True;
1008   else if (theNode->Name()[0] == '\0')
1009     isNoName = Standard_True;
1010
1011   if (theNode.IsNull() == Standard_False)
1012     if (theNode->IsDefault() == Standard_False) {
1013       if (isNoName && IsDummyWrite()) {
1014         // We are in a tentative 'write' session (nothing is written).
1015         // The goal is to identify multiply referred nodes.
1016         Standard_Address addrNode = theNode.operator->();
1017         if (!const_cast<NCollection_Map<Standard_Address>&>(myUnnamedNodesOut)
1018             .Add (addrNode))
1019         {
1020           Handle(VrmlData_UnknownNode) bidNode = new VrmlData_UnknownNode;
1021           char buf[32];
1022           do {
1023             Sprintf (buf, "_%d",
1024                      ++const_cast<Standard_Integer&>(myAutoNameCounter));
1025             bidNode->myName = &buf[0];
1026           } while (myNamedNodes.Contains (bidNode));
1027           // We found the vacant automatic name, let us assign to it.
1028           theNode->setName (&buf[0]);
1029           const_cast<VrmlData_MapOfNode&>(myNamedNodes).Add (theNode);
1030           return aStatus; // do not search under already duplicated node
1031         }
1032       }
1033       if (isNoName)
1034         aStatus = theNode->Write (thePrefix);
1035       else {
1036         // If the node name consists of blank characters, we do not write it
1037         const char * nptr = theNode->Name();
1038         for (; * nptr != '\0'; nptr++)
1039           if (* nptr != ' ' && * nptr != '\t')
1040             break;
1041         if (* nptr == '\0')
1042           aStatus = theNode->Write (thePrefix);
1043         else {
1044           // Name is written under DEF clause
1045           TCollection_AsciiString buf;
1046           if (myNamedNodesOut.Contains (theNode))
1047           {
1048             buf += "USE ";
1049             buf += theNode->Name();
1050             aStatus = WriteLine (thePrefix, buf.ToCString());
1051           } 
1052           else 
1053           {
1054             if (thePrefix)
1055             {
1056               buf += thePrefix;
1057               buf += ' ';
1058             }
1059             buf += "DEF ";
1060             buf += theNode->Name();
1061             aStatus = theNode->Write (buf.ToCString());
1062             const_cast<VrmlData_MapOfNode&>(myNamedNodesOut).Add (theNode);
1063           }
1064         }
1065       }
1066     }
1067   return aStatus;
1068 }
1069
1070 //=======================================================================
1071 //function : Dump
1072 //purpose  : 
1073 //=======================================================================
1074
1075 void VrmlData_Scene::Dump (Standard_OStream& theStream) const
1076 {
1077   theStream << " ===== Diagnostic Dump of a Scene (" << myAllNodes.Extent()
1078             << " nodes)\n";
1079
1080   /*
1081   Iterator anIterA(myAllNodes);
1082   for (; anIterA.More(); anIterA.Next())
1083     dumpNode(theStream, anIterA.Value(), "");
1084   */
1085   Iterator anIter(myLstNodes);
1086   for (; anIter.More(); anIter.Next())
1087     dumpNode(theStream, anIter.Value(), "  ");
1088 }
1089
1090 //=======================================================================
1091 //function : dumpNode
1092 //purpose  : static (local) function
1093 //=======================================================================
1094
1095 void dumpNode (Standard_OStream&                theStream,
1096                const Handle(VrmlData_Node)&     theNode,
1097                const TCollection_AsciiString&   theIndent)
1098 {
1099   if (theNode.IsNull())
1100     return;
1101   TCollection_AsciiString aNewIndent = 
1102     theIndent.IsEmpty() ? theIndent : theIndent + "  "; 
1103   if (theNode->IsKind(STANDARD_TYPE(VrmlData_Appearance))) {
1104     const Handle(VrmlData_Appearance) anAppearance = 
1105       Handle(VrmlData_Appearance)::DownCast (theNode);
1106     dumpNodeHeader (theStream, theIndent, "Appearance", theNode->Name());
1107     if (theIndent.IsEmpty() == Standard_False) {
1108       dumpNode (theStream, anAppearance->Material(), aNewIndent);
1109       dumpNode (theStream, anAppearance->Texture(), aNewIndent);
1110       dumpNode (theStream, anAppearance->TextureTransform(), aNewIndent);
1111     }
1112   } else if (theNode->IsKind(STANDARD_TYPE(VrmlData_ShapeNode))) {
1113     const Handle(VrmlData_ShapeNode) aShape = 
1114       Handle(VrmlData_ShapeNode)::DownCast (theNode);
1115     dumpNodeHeader (theStream, theIndent, "Shape", theNode->Name());
1116     if (theIndent.IsEmpty() == Standard_False) {
1117       dumpNode (theStream, aShape->Appearance(), aNewIndent);
1118       dumpNode (theStream, aShape->Geometry(), aNewIndent);
1119     }
1120   } else if (theNode->IsKind(STANDARD_TYPE(VrmlData_Box)))
1121     dumpNodeHeader (theStream, theIndent, "Box", theNode->Name());
1122   else if (theNode->IsKind(STANDARD_TYPE(VrmlData_Cylinder)))
1123     dumpNodeHeader (theStream, theIndent, "Cylinder", theNode->Name());
1124   else if (theNode->IsKind(STANDARD_TYPE(VrmlData_Sphere)))
1125     dumpNodeHeader (theStream, theIndent, "Sphere", theNode->Name());
1126   else if (theNode->IsKind(STANDARD_TYPE(VrmlData_Cone)))
1127     dumpNodeHeader (theStream, theIndent, "Cone", theNode->Name());
1128   else if (theNode->IsKind(STANDARD_TYPE(VrmlData_Coordinate)))
1129     dumpNodeHeader (theStream, theIndent, "Coordinate", theNode->Name());
1130   else if (theNode->IsKind(STANDARD_TYPE(VrmlData_Group))) {
1131     const Handle(VrmlData_Group) aGroup = 
1132       Handle(VrmlData_Group)::DownCast (theNode);
1133     char buf[64];
1134     Sprintf (buf, "Group (%s)",
1135              aGroup->IsTransform() ? "Transform" : "Group");
1136     dumpNodeHeader (theStream, theIndent, buf, theNode->Name());
1137     if (theIndent.IsEmpty() == Standard_False) {
1138       VrmlData_ListOfNode::Iterator anIter = aGroup->NodeIterator();
1139       for (; anIter.More(); anIter.Next())
1140         dumpNode (theStream, anIter.Value(), aNewIndent);
1141     }
1142   } else if (theNode->IsKind(STANDARD_TYPE(VrmlData_ImageTexture)))
1143     dumpNodeHeader (theStream, theIndent, "ImageTexture", theNode->Name());
1144   else if (theNode->IsKind(STANDARD_TYPE(VrmlData_IndexedFaceSet))) {
1145     const Handle(VrmlData_IndexedFaceSet) aNode =
1146       Handle(VrmlData_IndexedFaceSet)::DownCast(theNode);
1147     const Standard_Integer ** ppDummy; 
1148     const Standard_Size nCoord = aNode->Coordinates()->Length();
1149     const Standard_Size nPoly  = aNode->Polygons (ppDummy);
1150     char buf[80];
1151     Sprintf (buf, "IndexedFaceSet (%" PRIuPTR " vertices, %" PRIuPTR " polygons)",
1152              nCoord, nPoly);
1153
1154     dumpNodeHeader (theStream, theIndent, buf, theNode->Name());
1155   } else if (theNode->IsKind(STANDARD_TYPE(VrmlData_IndexedLineSet))) {
1156     const Handle(VrmlData_IndexedLineSet) aNode =
1157       Handle(VrmlData_IndexedLineSet)::DownCast(theNode);
1158     const Standard_Integer ** ppDummy; 
1159     const Standard_Size nCoord = aNode->Coordinates()->Length();
1160     const Standard_Size nPoly  = aNode->Polygons (ppDummy);
1161
1162     char buf[80];
1163     Sprintf(buf, "IndexedLineSet (%" PRIuPTR " vertices, %" PRIuPTR " polygons)",
1164             nCoord, nPoly);
1165
1166     dumpNodeHeader (theStream, theIndent, buf, theNode->Name());
1167   } else if (theNode->IsKind(STANDARD_TYPE(VrmlData_Material))) {
1168 //     const Handle(VrmlData_Material) aMaterial = 
1169 //       Handle(VrmlData_Material)::DownCast (theNode);
1170     dumpNodeHeader (theStream, theIndent, "Material", theNode->Name());
1171   }
1172   else if (theNode->IsKind(STANDARD_TYPE(VrmlData_Normal)))
1173     dumpNodeHeader (theStream, theIndent, "Normal", theNode->Name());
1174   else if (theNode->IsKind(STANDARD_TYPE(VrmlData_TextureCoordinate)))
1175     dumpNodeHeader (theStream, theIndent, "TextureCoordinate", theNode->Name());
1176   else if (theNode->IsKind(STANDARD_TYPE(VrmlData_WorldInfo)))
1177     dumpNodeHeader (theStream, theIndent, "WorldInfo", theNode->Name());
1178   else if (theNode->IsKind(STANDARD_TYPE(VrmlData_UnknownNode))) {
1179     const Handle(VrmlData_UnknownNode) anUnknown = 
1180       Handle(VrmlData_UnknownNode)::DownCast (theNode);
1181     char buf[64];
1182     Sprintf (buf, "Unknown (%s)", anUnknown->GetTitle().ToCString());
1183     dumpNodeHeader (theStream, theIndent, buf, theNode->Name());
1184   }
1185 }
1186
1187 //=======================================================================
1188 //function : dumpNodeHeader
1189 //purpose  : 
1190 //=======================================================================
1191
1192 void dumpNodeHeader (Standard_OStream&                  theStream,
1193                      const TCollection_AsciiString&     theIndent,
1194                      const char *                       theType,
1195                      const char *                       theName)
1196 {
1197   theStream << theIndent << theType << " node";
1198   if (theName[0] == '\0')
1199     theStream << "\n";
1200   else
1201     theStream << ": \"" << theName << "\"\n";
1202 }