0032622: Draw Harness - writebrep "-version 3" is unrecognized
authorkgv <kgv@opencascade.com>
Wed, 13 Oct 2021 18:53:32 +0000 (21:53 +0300)
committersmoskvin <smoskvin@opencascade.com>
Thu, 14 Oct 2021 17:17:11 +0000 (20:17 +0300)
Fixed version range check.
Added description of -normals argument.

src/DBRep/DBRep.cxx
src/DDocStd/DDocStd_ApplicationCommands.cxx

index a13d586..6e2662b 100644 (file)
@@ -1456,12 +1456,7 @@ static Standard_Integer writebrep (Draw_Interpretor& theDI,
     aParam.LowerCase();
     if (aParam == "-binary")
     {
-      isBinaryFormat = Standard_True;
-      if (anArgIter + 1 < theNbArgs
-       && Draw::ParseOnOff (theArgVec[anArgIter + 1], isBinaryFormat))
-      {
-        ++anArgIter;
-      }
+      isBinaryFormat = Draw::ParseOnOffNoIterator (theNbArgs, theArgVec, anArgIter);
     }
     else if (aParam == "-version"
           && anArgIter + 1 < theNbArgs)
@@ -1476,26 +1471,12 @@ static Standard_Integer writebrep (Draw_Interpretor& theDI,
     else if (aParam == "-notriangles"
           || aParam == "-triangles")
     {
-      isWithTriangles = Standard_True;
-      if (anArgIter + 1 < theNbArgs
-       && Draw::ParseOnOff (theArgVec[anArgIter + 1], isWithTriangles))
-      {
-        ++anArgIter;
-      }
-      if (aParam == "-notriangles")
-      {
-        isWithTriangles = !isWithTriangles;
-      }
+      isWithTriangles = Draw::ParseOnOffNoIterator (theNbArgs, theArgVec, anArgIter);
     }
     else if (aParam == "-nonormals"
           || aParam == "-normals")
     {
-      isWithNormals = Standard_True;
-      if (anArgIter + 1 < theNbArgs
-       && Draw::ParseOnOff (theArgVec[anArgIter + 1], isWithNormals))
-      {
-        ++anArgIter;
-      }
+      isWithNormals = Draw::ParseOnOffIterator (theNbArgs, theArgVec, anArgIter);
       if (aParam == "-nonormals")
       {
         isWithNormals = !isWithNormals;
@@ -1530,11 +1511,18 @@ static Standard_Integer writebrep (Draw_Interpretor& theDI,
   Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDI);
   if (isBinaryFormat)
   {
-    if (aVersion > BinTools_FormatVersion_VERSION_3)
+    if (aVersion > BinTools_FormatVersion_UPPER)
     {
       theDI << "Syntax error: unknown format version";
       return 1;
     }
+    if (isWithNormals
+     && aVersion > 0
+     && aVersion < BinTools_FormatVersion_VERSION_4)
+    {
+      theDI << "Error: vertex normals require binary format version 4 or later";
+      return 1;
+    }
 
     BinTools_FormatVersion aBinToolsVersion = aVersion > 0
                                             ? static_cast<BinTools_FormatVersion> (aVersion)
@@ -1547,11 +1535,18 @@ static Standard_Integer writebrep (Draw_Interpretor& theDI,
   }
   else
   {
-    if (aVersion > TopTools_FormatVersion_VERSION_2)
+    if (aVersion > TopTools_FormatVersion_UPPER)
     {
       theDI << "Syntax error: unknown format version";
       return 1;
     }
+    if (isWithNormals
+     && aVersion > 0
+     && aVersion < TopTools_FormatVersion_VERSION_3)
+    {
+      theDI << "Error: vertex normals require ascii format version 3 or later";
+      return 1;
+    }
 
     TopTools_FormatVersion aTopToolsVersion = aVersion > 0
                                             ? static_cast<TopTools_FormatVersion> (aVersion)
@@ -1729,14 +1724,16 @@ void  DBRep::BasicCommands(Draw_Interpretor& theCommands)
                     "\n\t\t   +|-g :  switch on/off graphical mode of Progress Indicator",
                     XProgress,"DE: General");
   theCommands.Add("writebrep",
-                  "writebrep shape filename [-binary=off] [-version Version=4] [-noTriangles=off]"
+                  "writebrep shape filename [-binary {0|1}]=0 [-version Version]=4"
+                  "\n\t\t:                          [-triangles {0|1}]=1 [-normals {0|1}]=0"
                   "\n\t\t: Save the shape in the ASCII (default) or binary format file."
                   "\n\t\t:  -binary  write into the binary format (ASCII when unspecified)"
                   "\n\t\t:  -version a number of format version to save;"
                   "\n\t\t:           ASCII  versions: 1, 2 and 3    (3 for ASCII  when unspecified);"
                   "\n\t\t:           Binary versions: 1, 2, 3 and 4 (4 for Binary when unspecified)."
-                  "\n\t\t:  -noTriangles skip triangulation data (OFF when unspecified)."
-                  "\n\t\t:           Ignored (always written) if face defines only triangulation (no surface).",
+                  "\n\t\t:  -triangles write triangulation data (TRUE when unspecified)."
+                  "\n\t\t:           Ignored (always written) if face defines only triangulation (no surface)."
+                  "\n\t\t:  -normals include vertex normals while writing triangulation data (FALSE when unspecified).",
                   __FILE__, writebrep, g);
   theCommands.Add("readbrep",
                   "readbrep filename shape"
index f0c16d3..9f093fe 100644 (file)
@@ -551,39 +551,44 @@ static Standard_Integer DDocStd_PrintComments (Draw_Interpretor& di,
 }
 
 //=======================================================================
-//function : SetStorageFormatVersion
-//purpose  : 
+//function : DDocStd_StorageFormatVersion
+//purpose  :
 //=======================================================================
-static Standard_Integer DDocStd_SetStorageFormatVersion (Draw_Interpretor& ,
-                                                         Standard_Integer nb,
-                                                         const char** a)
+static Standard_Integer DDocStd_StorageFormatVersion (Draw_Interpretor& theDI,
+                                                      Standard_Integer theNbArgs,
+                                                      const char** theArgVec)
 {  
-  if (nb == 3)
+  if (theNbArgs != 2
+   && theNbArgs != 3)
   {
-    Handle(TDocStd_Document) D;
-    if (!DDocStd::GetDocument(a[1], D)) return 1;
-    const int version = atoi(a[2]);
-    D->ChangeStorageFormatVersion((TDocStd_FormatVersion) version);
-    return 0;
+    theDI << "Syntax error: wrong number of arguments";
+    return 1;
   }
-  return 1;
-}
 
-//=======================================================================
-//function : GetStorageFormatVersion
-//purpose  : 
-//=======================================================================
-static Standard_Integer DDocStd_GetStorageFormatVersion (Draw_Interpretor& di,
-                                                         Standard_Integer nb,
-                                                         const char** a)
-{ 
-  if (nb == 2) {
-    Handle(TDocStd_Document) D;
-    if (!DDocStd::GetDocument(a[1], D)) return 1;
-    di << D->StorageFormatVersion() << "\n";
+  Handle(TDocStd_Document) aDoc;
+  if (!DDocStd::GetDocument (theArgVec[1], aDoc))
+  {
+    theDI << "Syntax error: " << theArgVec[1] << " is not a document";
+    return 1;
+  }
+
+  if (theNbArgs == 2)
+  {
+    theDI << aDoc->StorageFormatVersion() << "\n";
     return 0;
   }
-  return 1;
+
+  Standard_Integer aVerInt = 0;
+  if (!Draw::ParseInteger (theArgVec[2], aVerInt)
+   || aVerInt < TDocStd_FormatVersion_LOWER
+   || aVerInt > TDocStd_FormatVersion_UPPER)
+  {
+    theDI << "Syntax error: unknown version '" << theArgVec[2] << "' (valid range is " << TDocStd_FormatVersion_LOWER << ".." << TDocStd_FormatVersion_UPPER << ")";
+    return 1;
+  }
+
+  aDoc->ChangeStorageFormatVersion ((TDocStd_FormatVersion )aVerInt);
+  return 0;
 }
 
 //=======================================================================
@@ -656,12 +661,17 @@ void DDocStd::ApplicationCommands(Draw_Interpretor& theCommands)
                  "PrintComments Doc",
                  __FILE__, DDocStd_PrintComments, g);
 
+  static const TCollection_AsciiString THE_SET_VER_HELP = TCollection_AsciiString() +
+    "StorageFormatVersion Doc [Version]"
+    "\n\t\t: Print or set storage format version within range " + int(TDocStd_FormatVersion_LOWER) + ".." + int(TDocStd_FormatVersion_UPPER) +
+    "\n\t\t: defined by TDocStd_FormatVersion enumeration.";
+  theCommands.Add("StorageFormatVersion", THE_SET_VER_HELP.ToCString(),
+                  __FILE__, DDocStd_StorageFormatVersion, g);
   theCommands.Add("GetStorageFormatVersion",
-                 "GetStorageFormatVersion Doc"
-          "\nStorage format versions are defined in TDocStd_FormatVersion.hxx file by an enumeration",
-                 __FILE__, DDocStd_GetStorageFormatVersion, g);
+                  "GetStorageFormatVersion Doc"
+                  "\n\t\t: Alias to StorageFormatVersion",
+                             __FILE__, DDocStd_StorageFormatVersion, g);
   theCommands.Add("SetStorageFormatVersion",
-                 "SetStorageFormatVersion Doc Version"
-          "\nStorage format versions are defined in TDocStd_FormatVersion.hxx file by an enumeration",
-                 __FILE__, DDocStd_SetStorageFormatVersion, g);
+                  "\n\t\t: Alias to StorageFormatVersion",
+                  __FILE__, DDocStd_StorageFormatVersion, g);
 }