0025740: VrmlData_Scene::WriteArrIndex() writes extra point indices.
[occt.git] / src / VrmlData / VrmlData_Scene.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 25e4400..ff57177
@@ -1,21 +1,17 @@
 // Created on: 2006-05-25
 // Created by: Alexander GRIGORIEV
-// Copyright (c) 2006-2012 OPEN CASCADE SAS
+// Copyright (c) 2006-2014 OPEN CASCADE SAS
 //
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
+// This file is part of Open CASCADE Technology software library.
 //
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
 //
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
 
 #include <VrmlData_Scene.hxx>
 #include <VrmlData_InBuffer.hxx>
@@ -46,6 +42,7 @@
 #include <TopExp_Explorer.hxx>
 #include <BRep_Builder.hxx>
 #include <Precision.hxx>
+#include <Standard_Version.hxx>
 
 #ifdef WNT
 #define _CRT_SECURE_NO_DEPRECATE
@@ -79,7 +76,8 @@ VrmlData_Scene::VrmlData_Scene
     myAutoNameCounter (0)
 {
   myWorldInfo = new VrmlData_WorldInfo (* this);
-  myWorldInfo->AddInfo ("Created by OPEN CASCADE (tm) VrmlData API");
+  Standard_CString anInfo = "Generated by Open CASCADE Technology " OCC_VERSION_STRING;
+  myWorldInfo->AddInfo (anInfo);
   myLstNodes.Append (myWorldInfo);
   myAllNodes.Append (myWorldInfo);
 }
@@ -189,7 +187,7 @@ void VrmlData_Scene::SetVrmlDir (const TCollection_ExtendedString& theDir)
 //purpose  : 
 //=======================================================================
 
-const Handle_VrmlData_WorldInfo& VrmlData_Scene::WorldInfo() const
+const Handle(VrmlData_WorldInfo)& VrmlData_Scene::WorldInfo() const
 {
   return myWorldInfo;
 }
@@ -208,13 +206,17 @@ VrmlData_ErrorStatus VrmlData_Scene::readLine (VrmlData_InBuffer& theBuffer)
     theBuffer.Input.getline (theBuffer.Line, sizeof(theBuffer.Line));
     theBuffer.LineCount++;
     const int stat = theBuffer.Input.rdstate();
-    if (stat & ios::badbit)
+    if (stat & ios::badbit) {
       aStatus = VrmlData_UnrecoverableError;
-    else if (stat & ios::failbit)
-      if (stat & ios::eofbit)
+    }
+    else if (stat & ios::failbit) {
+      if (stat & ios::eofbit) {
         aStatus = VrmlData_EndOfFile;
-      else
+      }
+      else {
         aStatus = VrmlData_GeneralError;
+      }
+    }
     theBuffer.LinePtr = &theBuffer.Line[0];
     theBuffer.IsProcessed = Standard_False;
   }
@@ -449,7 +451,7 @@ VrmlData_ErrorStatus VrmlData_Scene::createNode
   TCollection_AsciiString aName;
 
   // Read the DEF token to assign the node name
-  if (VrmlData_Node::OK(aStatus, ReadLine(theBuffer)))
+  if (VrmlData_Node::OK(aStatus, ReadLine(theBuffer))) {
     if (VRMLDATA_LCOMPARE(theBuffer.LinePtr, "DEF")) {
       if (VrmlData_Node::OK(aStatus, ReadWord (theBuffer, aName)))
         aStatus = ReadLine(theBuffer);
@@ -457,6 +459,7 @@ VrmlData_ErrorStatus VrmlData_Scene::createNode
       theNode.Nullify();
       return aStatus;
     }
+  }
 
   const char * strName = aName.ToCString();
   if (aStatus == VrmlData_StatusOK) {
@@ -517,7 +520,7 @@ VrmlData_ErrorStatus VrmlData_Scene::createNode
       aStatus = ReadWord (theBuffer, aTitle);
       if (isProto) {
         aStatus = ReadLine(theBuffer);
-        if (aStatus == VrmlData_StatusOK)
+        if (aStatus == VrmlData_StatusOK) {
           if (theBuffer.LinePtr[0] != '[')
             aStatus = VrmlData_VrmlFormatError;
           else {
@@ -541,6 +544,7 @@ VrmlData_ErrorStatus VrmlData_Scene::createNode
               }
             }
           }
+        }
       }
       if (aStatus == VrmlData_StatusOK)
         aNode = new VrmlData_UnknownNode(* this,
@@ -550,19 +554,21 @@ VrmlData_ErrorStatus VrmlData_Scene::createNode
   }
   aStatus = ReadLine(theBuffer);
   if (aNode.IsNull() == Standard_False) {
-    if (aNode->Name()[0] != '\0')
+    if (aNode->Name()[0] != '\0') 
       myNamedNodes.Add (aNode);
     if (theType.IsNull() == Standard_False)
       if (aNode->IsKind(theType) == Standard_False)
         aStatus = VrmlData_VrmlFormatError;
   }
-  if (aStatus == VrmlData_StatusOK)
+  if (aStatus == VrmlData_StatusOK) {
     if (theBuffer.LinePtr[0] == '{') {
       theBuffer.LinePtr++;
       theNode = aNode;
       myAllNodes.Append(aNode);
-    } else
+    } else {
       aStatus = VrmlData_VrmlFormatError;
+    }
+  }
   return aStatus;
 }
 
@@ -701,7 +707,7 @@ VrmlData_ErrorStatus VrmlData_Scene::ReadXYZ
                                  Standard_Boolean       isOnlyPos) const
 {
   Standard_Real aVal[3] = {0., 0., 0.};
-  VrmlData_ErrorStatus aStatus;
+  VrmlData_ErrorStatus aStatus = VrmlData_StatusOK;
   for (Standard_Integer i = 0; i < 3; i++) {
     if (!VrmlData_Node::OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
       break;
@@ -718,13 +724,16 @@ VrmlData_ErrorStatus VrmlData_Scene::ReadXYZ
       theBuffer.LinePtr = endptr;
     }
   }
-  if (aStatus == VrmlData_StatusOK)
-    if (isScale)
+  if (aStatus == VrmlData_StatusOK) {
+    if (isScale) {
       theXYZ.SetCoord (aVal[0] * myLinearScale,
                        aVal[1] * myLinearScale,
                        aVal[2] * myLinearScale);
-    else
+    }
+    else {
       theXYZ.SetCoord (aVal[0], aVal[1], aVal[2]);
+    }
+  }
   return aStatus;
 }
 
@@ -740,7 +749,7 @@ VrmlData_ErrorStatus VrmlData_Scene::ReadXY
                                  Standard_Boolean       isOnlyPos) const
 {
   Standard_Real aVal[2] = {0., 0.};
-  VrmlData_ErrorStatus aStatus;
+  VrmlData_ErrorStatus aStatus = VrmlData_StatusOK;
   for (Standard_Integer i = 0; i < 2; i++) {
     if (!VrmlData_Node::OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
       break;
@@ -757,11 +766,12 @@ VrmlData_ErrorStatus VrmlData_Scene::ReadXY
       theBuffer.LinePtr = endptr;
     }
   }
-  if (aStatus == VrmlData_StatusOK)
+  if (aStatus == VrmlData_StatusOK) {
     if (isScale)
       theXY.SetCoord (aVal[0] * myLinearScale, aVal[1] * myLinearScale);
     else
       theXY.SetCoord (aVal[0], aVal[1]);
+  }
   return aStatus;
 }
 
@@ -778,7 +788,7 @@ VrmlData_ErrorStatus VrmlData_Scene::ReadArrIndex
 {
   VrmlData_ErrorStatus aStatus;
   theNBlocks = 0;
-  if (VrmlData_Node::OK(aStatus, ReadLine(theBuffer)))
+  if (VrmlData_Node::OK(aStatus, ReadLine(theBuffer))) {
     if (theBuffer.LinePtr[0] != '[')  // opening bracket
       aStatus = VrmlData_VrmlFormatError;
     else {
@@ -845,6 +855,7 @@ VrmlData_ErrorStatus VrmlData_Scene::ReadArrIndex
         }
       }
     }
+  }
   return aStatus;
 }
 
@@ -887,6 +898,8 @@ VrmlData_ErrorStatus VrmlData_Scene::WriteArrIndex
             char * ptr = &buf[0];
             for (Standard_Integer i = 0; i < nVal; i++) {
               Sprintf (ptr, "%d,", arrVal[i]);
+              if (i == nVal - 1)
+                break;
               ptr = strchr (ptr, ',') + 1;
               if ((ptr - &buf[0]) > (ptrdiff_t)aLineLimit) {
                 WriteLine(buf);
@@ -915,7 +928,7 @@ VrmlData_ErrorStatus VrmlData_Scene::WriteXYZ
                                  const char             * thePostfix) const
 {
   char buf[240];
-  if (IsDummyWrite() == Standard_False)
+  if (IsDummyWrite() == Standard_False) {
     if (isApplyScale && myLinearScale > Precision::Confusion())
       Sprintf (buf, "%.12g %.12g %.12g%s", theXYZ.X() / myLinearScale,
                theXYZ.Y() / myLinearScale, theXYZ.Z() / myLinearScale,
@@ -923,6 +936,7 @@ VrmlData_ErrorStatus VrmlData_Scene::WriteXYZ
     else
       Sprintf (buf, "%.12g %.12g %.12g%s", theXYZ.X(), theXYZ.Y(), theXYZ.Z(),
                thePostfix ? thePostfix : "");
+  }
   return WriteLine (buf);
 }