0030991: Draw Harness - ViewerTest::ParseColor() defines out-of-range alpha component
[occt.git] / src / ViewerTest / ViewerTest.cxx
index 8805ea5..2c16941 100644 (file)
@@ -202,22 +202,17 @@ namespace
   {
     const Standard_Integer THE_COLOR_COMPONENT_NOT_PARSED = -1;
     Graphic3d_Vec4i        anIntegerColor (THE_COLOR_COMPONENT_NOT_PARSED);
-    if (!parseNumericalColor (theNumberOfColorComponents, theColorComponentStrings, anIntegerColor))
+    if (!parseNumericalColor (theNumberOfColorComponents, theColorComponentStrings, anIntegerColor)
+      || anIntegerColor.maxComp() <= 1)
     {
       return false;
     }
-
-    const bool hasColorComponentGreaterThanOne = (anIntegerColor.maxComp() > 1);
     if (anIntegerColor.a() == THE_COLOR_COMPONENT_NOT_PARSED)
     {
       anIntegerColor.a() = THE_MAX_INTEGER_COLOR_COMPONENT;
     }
 
-    Graphic3d_Vec4 aRealColor (anIntegerColor);
-    if (hasColorComponentGreaterThanOne)
-    {
-      aRealColor /= static_cast<Standard_ShortReal> (THE_MAX_INTEGER_COLOR_COMPONENT);
-    }
+    const Graphic3d_Vec4 aRealColor = Graphic3d_Vec4 (anIntegerColor) / static_cast<Standard_ShortReal> (THE_MAX_INTEGER_COLOR_COMPONENT);
     theColor = Quantity_ColorRGBA (aRealColor);
     return true;
   }
@@ -284,11 +279,12 @@ Standard_Integer ViewerTest::parseColor (const Standard_Integer   theArgNb,
   if (theArgNb >= 3)
   {
     const Standard_Integer aNumberOfColorComponentsToParse = Min (theArgNb, theToParseAlpha ? 4 : 3);
-    Standard_Integer       aNumberOfColorComponentsParsed  = aNumberOfColorComponentsToParse;
+    Standard_Integer aNumberOfColorComponentsParsed = aNumberOfColorComponentsToParse;
     if (parseIntegerColor (aNumberOfColorComponentsParsed, theArgVec, theColor))
     {
       return aNumberOfColorComponentsParsed;
     }
+    aNumberOfColorComponentsParsed = aNumberOfColorComponentsToParse;
     if (parseRealColor (aNumberOfColorComponentsParsed, theArgVec, theColor))
     {
       return aNumberOfColorComponentsParsed;
@@ -2282,7 +2278,7 @@ struct ViewerTest_AspectsChangeSet
 //function : VAspects
 //purpose  :
 //==============================================================================
-static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
+static Standard_Integer VAspects (Draw_Interpretor& theDI,
                                   Standard_Integer  theArgNb,
                                   const char**      theArgVec)
 {
@@ -2333,6 +2329,9 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
 
   // parse syntax of legacy commands
   bool toParseAliasArgs = false;
+  Standard_Boolean toDump = 0;
+  Standard_Boolean toCompactDump = 0;
+  Standard_Integer aDumpDepth = -1;
   if (aCmdName == "vsetwidth")
   {
     if (aNames.IsEmpty()
@@ -2366,6 +2365,11 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
       aNames.Remove (aNames.Length());
       isOk = Standard_True;
     }
+    else if (Quantity_Color::ColorFromHex (aNames.Last().ToCString(), aChangeSet->Color))
+    {
+      aNames.Remove (aNames.Length());
+      isOk = Standard_True;
+    }
     else if (aNames.Length() >= 3)
     {
       const char* anArgVec[3] =
@@ -3284,6 +3288,25 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
       aChangeSet->ToSetTypeOfEdge = -1;
       aChangeSet->TypeOfEdge = Aspect_TOL_SOLID;
     }
+    else if (anArg == "-dumpjson")
+    {
+      toDump = Standard_True;
+    }
+    else if (anArg == "-dumpcompact")
+    {
+      toCompactDump = Standard_False;
+      if (++anArgIter >= theArgNb && ViewerTest::ParseOnOff (theArgVec[anArgIter + 1], toCompactDump))
+        ++anArgIter;
+    }
+    else if (anArg == "-dumpdepth")
+    {
+      if (++anArgIter >= theArgNb)
+      {
+        std::cout << "Error: wrong syntax at " << anArg << "\n";
+        return 1;
+      }
+      aDumpDepth = Draw::Atoi (theArgVec[anArgIter]);
+    }
     else
     {
       std::cout << "Error: wrong syntax at " << anArg << "\n";
@@ -3344,6 +3367,16 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
         aCtx->Redisplay (aPrs, Standard_False);
       }
     }
+    if (toDump)
+    {
+      Standard_SStream aStream;
+      aDrawer->DumpJson (aStream, aDumpDepth);
+
+      if (toCompactDump)
+        theDI << Standard_Dump::Text (aStream);
+      else
+        theDI << Standard_Dump::FormatJson (aStream);
+    }
     return 0;
   }
 
@@ -3497,6 +3530,16 @@ static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/,
       {
         aPrs->SynchronizeAspects();
       }
+
+      if (toDump)
+      {
+        Standard_SStream aStream;
+        aDrawer->DumpJson (aStream);
+
+        theDI << aName << ": \n";
+        theDI << Standard_Dump::FormatJson (aStream);
+        theDI << "\n";
+      }
     }
   }
   return 0;
@@ -6619,6 +6662,10 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands)
       "\n\t\t:          [-setDrawEdges {0|1}] [-setEdgeType LineType] [-setEdgeColor R G B] [-setQuadEdges {0|1}]"
       "\n\t\t:          [-setDrawSilhouette {0|1}]"
       "\n\t\t:          [-setAlphaMode {opaque|mask|blend|blendauto} [alphaCutOff=0.5]]"
+      "\n\t\t:          [-dumpJson]"
+      "\n\t\t:          [-dumpCompact {0|1}]"
+      "\n\t\t:          [-dumpDepth depth]"
+      "\n\t\t:          [-freeBoundary {off/on | 0/1}]"
       "\n\t\t: Manage presentation properties of all, selected or named objects."
       "\n\t\t: When -subshapes is specified than following properties will be"
       "\n\t\t: assigned to specified sub-shapes."