]> OCCT Git - occt-copy.git/commitdiff
0030991: Draw Harness - ViewerTest::ParseColor() defines out-of-range alpha component
authorkgv <kgv@opencascade.com>
Sat, 21 Sep 2019 14:10:23 +0000 (17:10 +0300)
committerkgv <kgv@opencascade.com>
Sat, 21 Sep 2019 17:40:58 +0000 (20:40 +0300)
ViewerTest::ParseColor() - fixed alpha component defined as 255 for RGB-only input.
Quantity_Color::ColorToHex() now rounds-up float values to closest integer.
Quantity_ColorRGBA::ColorToHex() - added method formatting color into hex with alpha component consistent to Quantity_Color::ColorToHex() for RGB.

vdrawtext command now uses ViewerTest::ParseColor() for parsing color argument, so that it accepts hex.
vreadpixel command now has been extended with -hex argument for printing color in hex format.

Commands XSetColor, XGetColor, XGetShapeColor, XGetAllColors, XAddColor, XRemoveColor, XFindColor,
XUnsetColor, XGetInstanceColor, XSetInstanceColor have been corrected to properly report syntax input errors
and to accept color names and hex (by reusing ViewerTest::ParseColor()).

samples/tcl/materials.tcl
samples/tcl/pathtrace_ball.tcl
samples/tcl/pathtrace_cube.tcl
samples/tcl/pathtrace_materials.tcl
src/Image/Image_AlienPixMap.cxx
src/Quantity/Quantity_Color.hxx
src/Quantity/Quantity_ColorRGBA.hxx
src/ViewerTest/ViewerTest.cxx
src/ViewerTest/ViewerTest_ObjectCommands.cxx
src/ViewerTest/ViewerTest_ViewerCommands.cxx
src/XDEDRAW/XDEDRAW_Colors.cxx

index 2ea7a7ae916e7ea0429601e980c5240c4475041a..e377752465bdc583adcc302d2786d4178fde634e 100644 (file)
@@ -86,3 +86,4 @@ drawObjects 0 ""
 drawObjects 1 red
 drawObjects 2 green
 drawObjects 3 blue1
+vrepaint
index 186bbccadf18ac2e00b558f0d8546602c596d964..b065eaab664318eb7fe8efef841b16715e369fcb 100644 (file)
@@ -75,4 +75,4 @@ vrenderparams -ray -gi -rayDepth 10
 puts "Make several path tracing iterations to refine the picture, please wait..."
 vfps 100
 puts "Done. To improve the image further, or after view manipulations, give command:"
-puts "vfps \[nb_iteratons\]
+puts "vfps \[nb_iteratons\] or vrepaint -continuous"
index 6cd321efdcd8f5ae800c66ef6d650772b549d00d..ad7c88ac047d584d620e5897e41917ad014f9dd8 100644 (file)
@@ -85,4 +85,4 @@ vrenderparams -ray -gi -rayDepth 8
 puts "Make several path tracing iterations to refine the picture, please wait..."
 vfps 100
 puts "Done. To improve the image further, or after view manipulations, give command:"
-puts "vfps \[nb_iteratons\]"
+puts "vfps \[nb_iteratons\] or vrepaint -continuous"
index 8f7d10ce823dce1b531af4055003cb83d786431e..e22344d5f36faf4852321ecd25ace177f2bc2f59 100644 (file)
@@ -223,4 +223,4 @@ vrenderparams -ray -gi -rayDepth 10
 puts "Make several path tracing iterations to refine the picture, please wait..."
 vfps 512
 puts "Done. To improve the image further, or after view manipulations, give command:"
-puts "vfps \[nb_iteratons\]
+puts "vfps \[nb_iteratons\] or vrepaint -continuous"
index b38190195aab0e788f54a06fe5dae8980b9adf60..5d4d8a9b620bf9cc3c20dd3fccfcaeae70bd5b44 100644 (file)
   #include <Standard_WarningsRestore.hxx>
   #undef min
   #undef max
+
+  #ifdef _MSC_VER
+    #pragma comment(lib, "Ole32.lib")
+  #endif
 #endif
 
 #include <Image_AlienPixMap.hxx>
index b221dabdb5830f5a223be4205c159b30b0fcb68e..a5b3ef34d013d946104f35b9831e9cef8f25bddb 100644 (file)
@@ -244,12 +244,14 @@ Standard_Boolean operator == (const Quantity_Color& Other) const
   Standard_EXPORT static bool ColorFromHex (const Standard_CString theHexColorString, Quantity_Color& theColor);
 
   //! Returns hex sRGB string in format "#FFAAFF".
-  static TCollection_AsciiString ColorToHex (const Quantity_Color& theColor)
+  static TCollection_AsciiString ColorToHex (const Quantity_Color& theColor,
+                                             const bool theToPrefixHash = true)
   {
     NCollection_Vec3<Standard_ShortReal> anSRgb = (NCollection_Vec3<Standard_ShortReal> )theColor;
-    NCollection_Vec3<Standard_Integer> anSRgbInt (anSRgb * 255.0f);
+    NCollection_Vec3<Standard_Integer> anSRgbInt (anSRgb * 255.0f + NCollection_Vec3<Standard_ShortReal> (0.5f));
     char aBuff[10];
-    Sprintf (aBuff, "#%02X%02X%02X", anSRgbInt.r(), anSRgbInt.g(), anSRgbInt.b());
+    Sprintf (aBuff, theToPrefixHash ? "#%02X%02X%02X" : "%02X%02X%02X",
+             anSRgbInt.r(), anSRgbInt.g(), anSRgbInt.b());
     return aBuff;
   }
 
index a1e070962683571e8717580d13c22203f580d6cb..cffdbaea23c534fa1512bfac505d5f15b3555491 100644 (file)
@@ -121,6 +121,18 @@ public:
                                             Quantity_ColorRGBA& theColor,
                                             const bool          theAlphaComponentIsOff = false);
 
+  //! Returns hex sRGBA string in format "#RRGGBBAA".
+  static TCollection_AsciiString ColorToHex (const Quantity_ColorRGBA& theColor,
+                                             const bool theToPrefixHash = true)
+  {
+    NCollection_Vec4<Standard_ShortReal> anSRgb = (NCollection_Vec4<Standard_ShortReal> )theColor;
+    NCollection_Vec4<Standard_Integer> anSRgbInt (anSRgb * 255.0f + NCollection_Vec4<Standard_ShortReal> (0.5f));
+    char aBuff[12];
+    Sprintf (aBuff, theToPrefixHash ? "#%02X%02X%02X%02X" : "%02X%02X%02X%02X",
+             anSRgbInt.r(), anSRgbInt.g(), anSRgbInt.b(), anSRgbInt.a());
+    return aBuff;
+  }
+
   //! Dumps the content of me into the stream
   Standard_EXPORT void DumpJson (Standard_OStream& theOStream, const Standard_Integer theDepth = -1) const;
 
index 7e36331147acadc08292779bcf7728540c3f1b37..2c169417ef46a286ac4ba8e2557e8e74ff505543 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;
@@ -2369,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] =
index 653acdbef5df33faa56e27b06ad946b9ee04b770..12c90ad24ee35a1c9b857d5c8d628070a0534e7b 100644 (file)
@@ -2388,42 +2388,17 @@ static int VDrawText (Draw_Interpretor& theDI,
     }
     else if (aParam == "-color")
     {
-      if (anArgIt + 1 >= theArgsNb)
-      {
-        std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
-        return 1;
-      }
-
-      TCollection_AsciiString aColor (theArgVec[anArgIt + 1]);
-      Quantity_NameOfColor aNameOfColor = Quantity_NOC_BLACK;
-      if (Quantity_Color::ColorFromName (aColor.ToCString(), aNameOfColor))
-      {
-        anArgIt += 1;
-        aTextPrs->SetColor (aNameOfColor);
-        continue;
-      }
-      else if (anArgIt + 3 >= theArgsNb)
-      {
-        std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
-        return 1;
-      }
-
-      TCollection_AsciiString aGreen (theArgVec[anArgIt + 2]);
-      TCollection_AsciiString aBlue  (theArgVec[anArgIt + 3]);
-      if (!aColor.IsRealValue()
-       || !aGreen.IsRealValue()
-       || !aBlue.IsRealValue())
+      Quantity_Color aColor;
+      Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgsNb - anArgIt - 1,
+                                                           theArgVec + anArgIt + 1,
+                                                           aColor);
+      if (aNbParsed == 0)
       {
-        std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
+        std::cout << "Syntax error at '" << aParam << "'\n";
         return 1;
       }
-
-      const Graphic3d_Vec3d anRGB (aColor.RealValue(),
-                                   aGreen.RealValue(),
-                                   aBlue.RealValue());
-
-      aTextPrs->SetColor (Quantity_Color (anRGB.r(), anRGB.g(), anRGB.b(), Quantity_TOC_RGB));
-      anArgIt += 3;
+      anArgIt += aNbParsed;
+      aTextPrs->SetColor (aColor);
     }
     else if (aParam == "-halign")
     {
@@ -2598,42 +2573,17 @@ static int VDrawText (Draw_Interpretor& theDI,
     else if (aParam == "-subcolor"
           || aParam == "-subtitlecolor")
     {
-      if (anArgIt + 1 >= theArgsNb)
-      {
-        std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
-        return 1;
-      }
-
-      TCollection_AsciiString aColor (theArgVec[anArgIt + 1]);
-      Quantity_NameOfColor aNameOfColor = Quantity_NOC_BLACK;
-      if (Quantity_Color::ColorFromName (aColor.ToCString(), aNameOfColor))
-      {
-        anArgIt += 1;
-        aTextPrs->SetColorSubTitle (aNameOfColor);
-        continue;
-      }
-      else if (anArgIt + 3 >= theArgsNb)
-      {
-        std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
-        return 1;
-      }
-
-      TCollection_AsciiString aGreen (theArgVec[anArgIt + 2]);
-      TCollection_AsciiString aBlue  (theArgVec[anArgIt + 3]);
-      if (!aColor.IsRealValue()
-       || !aGreen.IsRealValue()
-       || !aBlue.IsRealValue())
+      Quantity_Color aColor;
+      Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgsNb - anArgIt - 1,
+                                                           theArgVec + anArgIt + 1,
+                                                           aColor);
+      if (aNbParsed == 0)
       {
-        std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
+        std::cout << "Syntax error at '" << aParam << "'\n";
         return 1;
       }
-
-      const Graphic3d_Vec3d anRGB (aColor.RealValue(),
-                                   aGreen.RealValue(),
-                                   aBlue.RealValue());
-
-      aTextPrs->SetColorSubTitle (Quantity_Color (anRGB.r(), anRGB.g(), anRGB.b(), Quantity_TOC_RGB));
-      anArgIt += 3;
+      anArgIt += aNbParsed;
+      aTextPrs->SetColorSubTitle (aColor);
     }
     else if (aParam == "-2d")
     {
index a53c8dcfa17385b394d603c503c3fa3d743baa0d..336ecbd3317b0fdf869c5c31ff0973b8d63401b6 100644 (file)
@@ -7042,8 +7042,7 @@ static int VReadPixel (Draw_Interpretor& theDI,
     return 1;
   }
 
-  Standard_Boolean toShowName = Standard_False;
-  Standard_Boolean toShowHls  = Standard_False;
+  bool toShowName = false, toShowHls = false, toShowHex = false;
   for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
   {
     TCollection_AsciiString aParam (theArgVec[anIter]);
@@ -7090,9 +7089,15 @@ static int VReadPixel (Draw_Interpretor& theDI,
     {
       toShowName = Standard_True;
     }
+    else if (aParam == "-hex"
+          || aParam == "hex")
+    {
+      toShowHex = Standard_True;
+    }
     else
     {
       std::cout << "Syntax error at '" << aParam << "'\n";
+      return 1;
     }
   }
 
@@ -7130,6 +7135,17 @@ static int VReadPixel (Draw_Interpretor& theDI,
       theDI << Quantity_Color::StringName (aColor.GetRGB().Name());
     }
   }
+  else if (toShowHex)
+  {
+    if (aBufferType == Graphic3d_BT_RGBA)
+    {
+      theDI << Quantity_ColorRGBA::ColorToHex (aColor);
+    }
+    else
+    {
+      theDI << Quantity_Color::ColorToHex (aColor.GetRGB());
+    }
+  }
   else
   {
     switch (aBufferType)
@@ -13900,7 +13916,7 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
     " with f option returns free memory in bytes",
     __FILE__, VMemGpu, group);
   theCommands.Add ("vreadpixel",
-    "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [-name]"
+    "vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [-name|-hex]"
     " : Read pixel value for active view",
     __FILE__, VReadPixel, group);
   theCommands.Add("diffimage",
index 548789950b0c4dab622c01373269d4f767362e29..228f666fa1ba9a34c464bddd667be46a88e22ccd 100644 (file)
 #include <TDF_Tool.hxx>
 #include <TDocStd_Document.hxx>
 #include <TopoDS_Shape.hxx>
+#include <ViewerTest.hxx>
 #include <XCAFDoc_ColorTool.hxx>
 #include <XCAFDoc_DocumentTool.hxx>
 #include <XCAFDoc_ShapeTool.hxx>
 #include <XDEDRAW_Colors.hxx>
 
+//! Parse XCAFDoc_ColorType enumeration argument.
+static bool parseXDocColorType (const TCollection_AsciiString& theArg,
+                                XCAFDoc_ColorType& theType)
+{
+  TCollection_AsciiString anArgCase (theArg);
+  anArgCase.LowerCase();
+  if (anArgCase == "surf"
+   || anArgCase == "surface"
+   || anArgCase == "s")
+  {
+    theType = XCAFDoc_ColorSurf;
+    return true;
+  }
+  else if (anArgCase == "curve"
+        || anArgCase == "c")
+  {
+    theType = XCAFDoc_ColorCurv;
+    return true;
+  }
+  else if (anArgCase == "gen"
+        || anArgCase == "generic")
+  {
+    theType = XCAFDoc_ColorGen;
+    return true;
+  }
+  return false;
+}
+
 //=======================================================================
 // Section: Work with colors
 //=======================================================================
-static Standard_Integer setColor (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
+static Standard_Integer setColor (Draw_Interpretor& , Standard_Integer argc, const char** argv)
 {
-  if (argc < 6) {
-    di<<"Use: "<<argv[0]<<" Doc {Label|Shape} R G B [alpha] [curve|surf]\n";
+  if (argc < 4)
+  {
+    std::cout << "Syntax error: wrong number of arguments\n";
     return 1;
   }
-  Handle(TDocStd_Document) Doc;   
-  DDocStd::GetDocument(argv[1], Doc);
-  if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
-  
-  TDF_Label aLabel;
-  TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
-  Quantity_Color Col ( Draw::Atof(argv[3]), Draw::Atof(argv[4]), Draw::Atof(argv[5]), Quantity_TOC_RGB );
 
-  Quantity_ColorRGBA aColRGBA;
-  aColRGBA.SetRGB(Col);
-  if (argc > 6 && (argv[6][0] != 's' && argv[6][0] != 'c')) {
-    aColRGBA.SetAlpha((Standard_ShortReal)(Draw::Atof(argv[6])));
+  Handle(TDocStd_Document) aDoc;
+  DDocStd::GetDocument (argv[1], aDoc);
+  if (aDoc.IsNull())
+  {
+    std::cout << "Syntax error: " << argv[1] << " is not a document\n";
+    return 1;
   }
-  
-  Handle(XCAFDoc_ColorTool) myColors = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
-  XCAFDoc_ColorType ctype = XCAFDoc_ColorGen;
-  if (argc > 6) {
-    if (argv[argc - 1][0] == 's')
-      ctype = XCAFDoc_ColorSurf;
-    else if (argv[argc - 1][0] == 'c')
-      ctype = XCAFDoc_ColorCurv;
-  }
-
-  if ( !aLabel.IsNull() ) {
-    myColors->SetColor(aLabel, aColRGBA, ctype);
-  }
-  else {
-    TopoDS_Shape aShape= DBRep::Get(argv[2]);
-    if ( !aShape.IsNull() ) {
-      myColors->SetColor(aShape, aColRGBA, ctype);
+
+  TDF_Label aLabel;
+  TopoDS_Shape aShape;
+  TDF_Tool::Label (aDoc->GetData(), argv[2], aLabel);
+  if (aLabel.IsNull())
+  {
+    aShape = DBRep::Get (argv[2]);
+    if (aShape.IsNull())
+    {
+      std::cout << "Syntax error: " << argv[2] << " is not a label nor shape\n";
+      return 1;
+    }
+  }
+
+  Quantity_ColorRGBA aColor;
+  bool isColorDefined = false;
+  XCAFDoc_ColorType aColType = XCAFDoc_ColorGen;
+  for (Standard_Integer anArgIter = 3; anArgIter < argc; ++anArgIter)
+  {
+    if (parseXDocColorType (argv[anArgIter], aColType))
+    {
+      //
+    }
+    else if (!isColorDefined)
+    {
+      isColorDefined = true;
+      Standard_Integer aNbParsed = ViewerTest::ParseColor (argc - anArgIter,
+                                                           argv + anArgIter,
+                                                           aColor);
+      if (aNbParsed == 0)
+      {
+        std::cout << "Syntax error at '" << argv[anArgIter] << "'\n";
+        return 1;
+      }
+      anArgIter += aNbParsed - 1;
+    }
+    else
+    {
+      std::cout << "Syntax error at '" << argv[anArgIter] << "'\n";
+      return 1;
     }
   }
+  if (!isColorDefined)
+  {
+    std::cout << "Syntax error: wrong number of arguments\n";
+    return 1;
+  }
+
+  Handle(XCAFDoc_ColorTool) aColorTool = XCAFDoc_DocumentTool::ColorTool (aDoc->Main());
+  if (!aLabel.IsNull())
+  {
+    aColorTool->SetColor (aLabel, aColor, aColType);
+  }
+  else if (!aColorTool->SetColor (aShape, aColor, aColType))
+  {
+    std::cout << "Syntax error: " << argv[2] << " is not a label nor shape\n";
+    return 1;
+  }
   return 0;
 }
 
 static Standard_Integer getColor (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
 {
-  if (argc!=3) {
-    di<<"Use: "<<argv[0]<<" Doc Label\n";
+  if (argc != 3)
+  {
+    std::cout << "Syntax error: wrong number of arguments\n";
+    return 1;
+  }
+
+  Handle(TDocStd_Document) aDoc;
+  DDocStd::GetDocument (argv[1], aDoc);
+  if (aDoc.IsNull())
+  {
+    std::cout << "Syntax error: " << argv[1] << " is not a document\n";
     return 1;
   }
-  Handle(TDocStd_Document) Doc;   
-  DDocStd::GetDocument(argv[1], Doc);
-  if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
 
   TDF_Label aLabel;
-  TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
-  Handle(XCAFDoc_ColorTool) myColors = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
-  Quantity_ColorRGBA col;
-  if ( !myColors->GetColor(aLabel, col) ) return 0;
-  
-  if ((1 - col.Alpha()) < Precision::Confusion())
-    di << col.GetRGB().StringName(col.GetRGB().Name());
+  TDF_Tool::Label (aDoc->GetData(), argv[2], aLabel);
+  Handle(XCAFDoc_ColorTool) myColors = XCAFDoc_DocumentTool::ColorTool (aDoc->Main());
+  Quantity_ColorRGBA aColor;
+  if (!myColors->GetColor (aLabel, aColor))
+  {
+    return 0;
+  }
+
+  if ((1.0 - aColor.Alpha()) < Precision::Confusion())
+  {
+    di << aColor.GetRGB().StringName (aColor.GetRGB().Name());
+  }
   else
-    di << col.GetRGB().StringName ( col.GetRGB().Name() ) << " (" << col.Alpha() << ")";
-   
+  {
+    di << aColor.GetRGB().StringName (aColor.GetRGB().Name()) << " (" << aColor.Alpha() << ")";
+  }
   return 0;
 }
 
 static Standard_Integer getShapeColor (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
 {
-  if (argc < 3) {
-    di<<"Use: "<<argv[0]<<" Doc Label [curve|surf]\n";
+  if (argc != 3 && argc != 4)
+  {
+    std::cout << "Syntax error: wrong number of arguments\n";
+    return 1;
+  }
+
+  Handle(TDocStd_Document) aDoc;
+  DDocStd::GetDocument (argv[1], aDoc);
+  if (aDoc.IsNull())
+  {
+    std::cout << "Syntax error: " << argv[1] << " is not a document\n";
     return 1;
   }
-  Handle(TDocStd_Document) Doc;   
-  DDocStd::GetDocument(argv[1], Doc);
-  if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
 
   TDF_Label aLabel;
-  TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
-  if ( aLabel.IsNull() ) {
-    di << " no such label in document\n";
+  TDF_Tool::Label (aDoc->GetData(), argv[2], aLabel);
+  if (aLabel.IsNull())
+  {
+    std::cout << "Syntax error: '" << argv[2] << "' label is not found in the document\n";
     return 1;
   }
 
-  Handle(XCAFDoc_ColorTool) myColors = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
-  const XCAFDoc_ColorType ctype = ( argc <= 3 ? XCAFDoc_ColorGen : ( argv[3][0] == 's' ? XCAFDoc_ColorSurf : XCAFDoc_ColorCurv ) );
+  Handle(XCAFDoc_ColorTool) myColors = XCAFDoc_DocumentTool::ColorTool (aDoc->Main());
+  XCAFDoc_ColorType aColType = XCAFDoc_ColorGen;
+  if (argc > 3 && !parseXDocColorType (argv[3], aColType))
+  {
+    std::cout << "Syntax error: unknown color type '" << argv[3] << "'\n";
+    return 1;
+  }
 
-  Quantity_ColorRGBA col;
-  if ( !myColors->GetColor(aLabel, ctype, col) ) return 0;
+  Quantity_ColorRGBA aColor;
+  if (!myColors->GetColor (aLabel, aColType, aColor))
+  {
+    return 0;
+  }
 
-  if ((1 - col.Alpha()) < Precision::Confusion())
-    di << col.GetRGB().StringName(col.GetRGB().Name());
+  if ((1.0 - aColor.Alpha()) < Precision::Confusion())
+  {
+    di << aColor.GetRGB().StringName(aColor.GetRGB().Name());
+  }
   else
-    di << col.GetRGB().StringName(col.GetRGB().Name()) << " (" << col.Alpha() << ")";
+  {
+    di << aColor.GetRGB().StringName(aColor.GetRGB().Name()) << " (" << aColor.Alpha() << ")";
+  }
 
   return 0;
 }
 
 static Standard_Integer getAllColors (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
 {
-  if (argc!=2) {
-    di<<"Use: "<<argv[0]<<" Doc \n";
+  if (argc != 2)
+  {
+    std::cout << "Syntax error: wrong number of arguments\n";
     return 1;
   }
-  Handle(TDocStd_Document) Doc;
-  DDocStd::GetDocument(argv[1], Doc);
-  if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
 
-  TDF_Label aLabel;
-  Handle(XCAFDoc_ColorTool) myColors = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
-  Quantity_ColorRGBA col;
-  TDF_LabelSequence Labels;
-  myColors->GetColors(Labels);
-  if (Labels.Length() >= 1) {
-    for ( Standard_Integer i = 1; i<= Labels.Length(); i++) {
-      aLabel = Labels.Value(i);
-      if ( !myColors->GetColor(aLabel, col) ) continue;
-      if ((1 - col.Alpha()) < Precision::Confusion())
-        di << col.GetRGB().StringName(col.GetRGB().Name());
+  Handle(TDocStd_Document) aDoc;
+  DDocStd::GetDocument (argv[1], aDoc);
+  if (aDoc.IsNull())
+  {
+    std::cout << "Syntax error: " << argv[1] << " is not a document\n";
+    return 1;
+  }
+
+  Handle(XCAFDoc_ColorTool) aColorTool = XCAFDoc_DocumentTool::ColorTool (aDoc->Main());
+  TDF_LabelSequence aLabels;
+  aColorTool->GetColors (aLabels);
+  if (aLabels.Length() >= 1)
+  {
+    for (TDF_LabelSequence::Iterator aLabIter (aLabels); aLabIter.More(); aLabIter.Next())
+    {
+      Quantity_ColorRGBA aColor;
+      if (!aColorTool->GetColor (aLabIter.Value(), aColor))
+      {
+        continue;
+      }
+      if ((1.0 - aColor.Alpha()) < Precision::Confusion())
+      {
+        di << aColor.GetRGB().StringName (aColor.GetRGB().Name());
+      }
       else
-        di << col.GetRGB().StringName(col.GetRGB().Name()) << " (" << col.Alpha() << ")";
+      {
+        di << aColor.GetRGB().StringName (aColor.GetRGB().Name()) << " (" << aColor.Alpha() << ")";
+      }
       di << " ";
     }
   }
@@ -162,235 +270,351 @@ static Standard_Integer getAllColors (Draw_Interpretor& di, Standard_Integer arg
 
 static Standard_Integer addColor (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
 {
-  if (argc < 5) {
-    di<<"Use: "<<argv[0]<<" DocName R G B [alpha]\n";
+  if (argc < 3)
+  {
+    std::cout << "Syntax error: wrong number of arguments\n";
     return 1;
   }
-  Handle(TDocStd_Document) Doc;   
-  DDocStd::GetDocument(argv[1], Doc);
-  if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
 
-  TDF_Label aLabel;
-  Handle(XCAFDoc_ColorTool) myColors = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
+  Handle(TDocStd_Document) aDoc;
+  DDocStd::GetDocument (argv[1], aDoc);
+  if (aDoc.IsNull())
+  {
+    std::cout << "Syntax error: " << argv[1] << " is not a document\n";
+    return 1;
+  }
 
-  Quantity_Color Col ( Draw::Atof(argv[2]), Draw::Atof(argv[3]), Draw::Atof(argv[4]), Quantity_TOC_RGB );
-  if (argc == 6) {
-    Quantity_ColorRGBA aColRGBA(Col);
-    aColRGBA.SetAlpha((Standard_ShortReal)(Draw::Atof(argv[5])));
-    aLabel = myColors->AddColor(aColRGBA);
+  Quantity_ColorRGBA aColRGBA;
+  Standard_Integer aNbParsed = ViewerTest::ParseColor (argc - 2, argv + 2, aColRGBA);
+  if (aNbParsed != argc - 2)
+  {
+    std::cout << "Syntax error at '" << argv[2] << "'\n";
+    return 1;
   }
-  else 
-    aLabel = myColors->AddColor(Col);
-  
-  TCollection_AsciiString Entry;
-  TDF_Tool::Entry(aLabel, Entry);
-  di << Entry.ToCString();
+
+  TCollection_AsciiString anEntry;
+  Handle(XCAFDoc_ColorTool) aColorTool = XCAFDoc_DocumentTool::ColorTool (aDoc->Main());
+  TDF_Label aLabel = aColorTool->AddColor (aColRGBA);
+  TDF_Tool::Entry (aLabel, anEntry);
+  di << anEntry;
   return 0;
 }
 
-static Standard_Integer removeColor (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
+static Standard_Integer removeColor (Draw_Interpretor& , Standard_Integer argc, const char** argv)
 {
-  if (argc!=3) {
-    di<<"Use: "<<argv[0]<<" DocName Label\n";
+  if (argc != 3)
+  {
+    std::cout << "Syntax error: wrong number of arguments\n";
     return 1;
   }
-  Handle(TDocStd_Document) Doc;   
-  DDocStd::GetDocument(argv[1], Doc);
-  if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
 
+  Handle(TDocStd_Document) aDoc;
   TDF_Label aLabel;
-  TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
-  Handle(XCAFDoc_ColorTool) myColors = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
-  myColors->RemoveColor(aLabel);
-  
+  DDocStd::GetDocument (argv[1], aDoc);
+  if (aDoc.IsNull())
+  {
+    std::cout << "Syntax error: " << argv[1] << " is not a document\n";
+    return 1;
+  }
+  TDF_Tool::Label (aDoc->GetData(), argv[2], aLabel);
+  if (aLabel.IsNull())
+  {
+    std::cout << "Syntax error: " << argv[2] << " label is not found in the document\n";
+    return 1;
+  }
+
+  Handle(XCAFDoc_ColorTool) aColorTool = XCAFDoc_DocumentTool::ColorTool (aDoc->Main());
+  aColorTool->RemoveColor (aLabel);
   return 0;
 }
 
 static Standard_Integer findColor (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
 {
-  if (argc < 5) {
-    di<<"Use: "<<argv[0]<<" DocName R G B [alpha]\n";
+  if (argc < 3)
+  {
+    std::cout << "Syntax error: wrong number of arguments\n";
     return 1;
   }
-  Handle(TDocStd_Document) Doc;   
-  DDocStd::GetDocument(argv[1], Doc);
-  if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
 
-  Handle(XCAFDoc_ColorTool) myColors = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
-  TCollection_AsciiString Entry;
-  Quantity_Color Col(Draw::Atof(argv[2]), Draw::Atof(argv[3]), Draw::Atof(argv[4]), Quantity_TOC_RGB);
-  if (argc == 5) {
-    TDF_Tool::Entry(myColors->FindColor(Col), Entry);
+  Handle(TDocStd_Document) aDoc;
+  DDocStd::GetDocument (argv[1], aDoc);
+  if (aDoc.IsNull())
+  {
+    std::cout << "Syntax error: " << argv[1] << " is not a document\n";
+    return 1;
   }
-  else {
-    Quantity_ColorRGBA aColRGBA(Col);
-    aColRGBA.SetAlpha((Standard_ShortReal)Draw::Atof(argv[5]));
-    TDF_Tool::Entry(myColors->FindColor(aColRGBA), Entry);
+
+  Quantity_ColorRGBA aColRGBA;
+  Standard_Integer aNbParsed = ViewerTest::ParseColor (argc - 2, argv + 2, aColRGBA);
+  if (aNbParsed != argc - 2)
+  {
+    std::cout << "Syntax error at '" << argv[2] << "'\n";
+    return 1;
   }
-  di << Entry.ToCString();
+
+  Handle(XCAFDoc_ColorTool) aColorTool = XCAFDoc_DocumentTool::ColorTool (aDoc->Main());
+  TCollection_AsciiString anEntry;
+  TDF_Tool::Entry (aColorTool->FindColor (aColRGBA), anEntry);
+  di << anEntry;
   return 0;
 }
 
-static Standard_Integer unsetColor (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
+static Standard_Integer unsetColor (Draw_Interpretor& , Standard_Integer argc, const char** argv)
 {
-  if (argc!=4) {
-    di<<"Use: "<<argv[0]<<" DocName {Label|Shape} ColorType\n";
+  if (argc != 4)
+  {
+    std::cout << "Syntax error: wrong number of arguments\n";
+    return 1;
+  }
+
+  Handle(TDocStd_Document) aDoc;
+  DDocStd::GetDocument (argv[1], aDoc);
+  if (aDoc.IsNull())
+  {
+    std::cout << "Syntax error: " << argv[1] << " is not a document\n";
+    return 1;
+  }
+
+  XCAFDoc_ColorType aColType = XCAFDoc_ColorGen;
+  if (!parseXDocColorType (argv[3], aColType))
+  {
+    std::cout << "Syntax error: unknown color type '" << argv[3] << "'\n";
     return 1;
   }
-  Handle(TDocStd_Document) Doc;   
-  DDocStd::GetDocument(argv[1], Doc);
-  if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
 
   TDF_Label aLabel;
-  TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
-  Handle(XCAFDoc_ColorTool) myColors = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
-  if ( !aLabel.IsNull() ) {
-    myColors->UnSetColor(aLabel, argv[3][0] == 's' ? XCAFDoc_ColorSurf : XCAFDoc_ColorCurv);
+  TDF_Tool::Label (aDoc->GetData(), argv[2], aLabel);
+  Handle(XCAFDoc_ColorTool) myColors = XCAFDoc_DocumentTool::ColorTool (aDoc->Main());
+  if (!aLabel.IsNull())
+  {
+    myColors->UnSetColor (aLabel, aColType);
+    return 0;
   }
-  TopoDS_Shape aShape= DBRep::Get(argv[2]);
-  if ( !aShape.IsNull() ) {
-    myColors->UnSetColor(aShape, argv[3][0] == 's' ? XCAFDoc_ColorSurf : XCAFDoc_ColorCurv);
+
+  TopoDS_Shape aShape = DBRep::Get (argv[2]);
+  if (aShape.IsNull())
+  {
+    std::cout << "Syntax error: " << argv[2] << " is not a label nor shape\n";
+    return 1;
   }
+  myColors->UnSetColor (aShape, aColType);
   return 0;
 }
 
-static Standard_Integer setVisibility (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
+static Standard_Integer setVisibility (Draw_Interpretor& , Standard_Integer argc, const char** argv)
 {
-  if (argc<3) {
-    di<<"Use: "<<argv[0]<<"DocName {Lable|Shape} [isvisible(1/0)]\n";
+  if (argc != 3 && argc != 4)
+  {
+    std::cout << "Syntax error: wrong number of arguments\n";
     return 1;
   }
-  Handle(TDocStd_Document) Doc;
-  DDocStd::GetDocument(argv[1], Doc);
-  if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
-  Handle(XCAFDoc_ColorTool) localTool = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
-  Standard_Boolean isvisible = Standard_False;
-  if ( (argc==4) && (Draw::Atoi(argv[3])==1) ) isvisible = Standard_True;
-  
+
+  Handle(TDocStd_Document) aDoc;
   TDF_Label aLabel;
-  TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
-  if ( aLabel.IsNull() ) {
+  DDocStd::GetDocument (argv[1], aDoc);
+  if (aDoc.IsNull())
+  {
+    std::cout << "Syntax error: " << argv[1] << " is not a document\n";
+    return 1;
+  }
+
+  TDF_Tool::Label (aDoc->GetData(), argv[2], aLabel);
+  Handle(XCAFDoc_ColorTool) aColorTool = XCAFDoc_DocumentTool::ColorTool (aDoc->Main());
+  if (aLabel.IsNull())
+  {
     // get label by shape
-    TopoDS_Shape aShape= DBRep::Get(argv[2]);
-    if ( !aShape.IsNull() ) {
-      aLabel = localTool->ShapeTool()->FindShape( aShape, Standard_True );
+    TopoDS_Shape aShape = DBRep::Get (argv[2]);
+    if (!aShape.IsNull())
+    {
+      aLabel = aColorTool->ShapeTool()->FindShape (aShape, Standard_True);
     }
   }
-  if ( aLabel.IsNull() ) {
-    di << " cannot find indicated label in document\n";
+  if (aLabel.IsNull())
+  {
+    std::cout << "Syntax error: " << argv[2] << " is not a label not shape\n";
     return 1;
   }
-  localTool->SetVisibility( aLabel, isvisible );
+
+  Standard_Boolean isVisible = Standard_False;
+  if (argc == 4)
+  {
+    TCollection_AsciiString aVisArg (argv[3]);
+    if (aVisArg == "1")
+    {
+      isVisible = Standard_True;
+    }
+    else if (aVisArg == "0")
+    {
+      isVisible = Standard_False;
+    }
+    else
+    {
+      std::cout << "Syntax error: unknown argument '" << argv[3] << "'\n";
+      return 1;
+    }
+  }
+  aColorTool->SetVisibility (aLabel, isVisible);
   return 0;
 }
 
 static Standard_Integer getVisibility (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
 {
-  if (argc<3) {
-    di<<"Use: "<<argv[0]<<"DocName {Lable|Shape}\n";
+  if (argc != 3)
+  {
+    std::cout << "Syntax error: wrong number of arguments\n";
+    return 1;
+  }
+
+  Handle(TDocStd_Document) aDoc;
+  DDocStd::GetDocument (argv[1], aDoc);
+  if (aDoc.IsNull())
+  {
+    std::cout << "Syntax error: " << argv[1] << " is not a document\n";
     return 1;
   }
-  Handle(TDocStd_Document) Doc;
-  DDocStd::GetDocument(argv[1], Doc);
-  if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
-  Handle(XCAFDoc_ColorTool) localTool = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
+
+  Handle(XCAFDoc_ColorTool) aColorTool = XCAFDoc_DocumentTool::ColorTool (aDoc->Main());
   TDF_Label aLabel;
-  TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
-  if ( aLabel.IsNull() ) {
+  TDF_Tool::Label (aDoc->GetData(), argv[2], aLabel);
+  if (aLabel.IsNull())
+  {
     // get label by shape
-    TopoDS_Shape aShape= DBRep::Get(argv[2]);
-    if ( !aShape.IsNull() ) {
-      aLabel = localTool->ShapeTool()->FindShape( aShape, Standard_True );
+    TopoDS_Shape aShape = DBRep::Get (argv[2]);
+    if (!aShape.IsNull())
+    {
+      aLabel = aColorTool->ShapeTool()->FindShape (aShape, Standard_True);
     }
   }
-  if ( aLabel.IsNull() ) {
-    di << " cannot find indicated label in document\n";
+  if (aLabel.IsNull())
+  {
+    std::cout << "Syntax error: " << argv[2] << " is not a label not shape\n";
     return 1;
   }
-  if (localTool->IsVisible( aLabel) ) di << 1;
-  else di << 0;
+
+  di << (aColorTool->IsVisible (aLabel) ? 1 : 0);
   return 0;
 }
 
 static Standard_Integer getStyledVisibility (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
 {
-  if (argc<3) {
-    di<<"Use: "<<argv[0]<<"DocName Shape\n";
+  if (argc != 3)
+  {
+    std::cout << "Syntax error: wrong number of arguments\n";
     return 1;
   }
-  Handle(TDocStd_Document) Doc;
-  DDocStd::GetDocument(argv[1], Doc);
-  if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
-  Handle(XCAFDoc_ColorTool) localTool = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
-  TopoDS_Shape aShape;
-  aShape = DBRep::Get(argv[2]);
-  if (localTool->IsInstanceVisible( aShape) ) di << 1;
-  else di << 0;
+
+  Handle(TDocStd_Document) aDoc;
+  DDocStd::GetDocument (argv[1], aDoc);
+  TopoDS_Shape aShape = DBRep::Get(argv[2]);
+  if (aDoc.IsNull())
+  {
+    std::cout << "Syntax error: " << argv[1] << " is not a document\n";
+    return 1;
+  }
+  if (aShape.IsNull())
+  {
+    std::cout << "Syntax error: " << argv[2] << " is not a shape\n";
+    return 1;
+  }
+
+  Handle(XCAFDoc_ColorTool) aColorTool = XCAFDoc_DocumentTool::ColorTool (aDoc->Main());
+  di << (aColorTool->IsInstanceVisible (aShape) ? 1 : 0);
   return 0;
 }
 
 static Standard_Integer getStyledcolor (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
 {
-  if (argc<3) {
-    di<<"Use: "<<argv[0]<<" Doc shape colortype(s/c)\n";
+  if (argc != 3 && argc != 4)
+  {
+    std::cout << "Syntax error: wrong number of arguments\n";
     return 1;
   }
-  Handle(TDocStd_Document) Doc;   
-  DDocStd::GetDocument(argv[1], Doc);
-  if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
-  TopoDS_Shape aShape;
-  aShape = DBRep::Get(argv[2]);
-
-  Quantity_ColorRGBA col;
-  XCAFDoc_ColorType type;
-  if ( argv[3] && argv[3][0] == 's' )
-    type = XCAFDoc_ColorSurf;
-  else if ( argv[3] && argv[3][0] == 'c' )
-    type = XCAFDoc_ColorCurv;
-  else
-    type = XCAFDoc_ColorGen;
-  Handle(XCAFDoc_ColorTool) localTool = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
-  if (localTool->GetInstanceColor( aShape, type, col) ) 
+
+  Handle(TDocStd_Document) aDoc;
+  XCAFDoc_ColorType aColType = XCAFDoc_ColorGen;
+  DDocStd::GetDocument (argv[1], aDoc);
+  TopoDS_Shape aShape = DBRep::Get (argv[2]);
+  if (aDoc.IsNull())
+  {
+    std::cout << "Syntax error: " << argv[1] << " is not a document\n";
+    return 1;
+  }
+  if (aShape.IsNull())
+  {
+    std::cout << "Syntax error: " << argv[2] << " is not a shape\n";
+    return 1;
+  }
+  if (argc > 3 && !parseXDocColorType (argv[3], aColType))
+  {
+    std::cout << "Syntax error: unknown color type '" << argv[3] << "'\n";
+    return 1;
+  }
+
+  Handle(XCAFDoc_ColorTool) aColorTool = XCAFDoc_DocumentTool::ColorTool (aDoc->Main());
+  Quantity_ColorRGBA aColor;
+  if (aColorTool->GetInstanceColor (aShape, aColType, aColor))
   {
-    if ((1 - col.Alpha()) < Precision::Confusion())
-      di << col.GetRGB().StringName(col.GetRGB().Name());
+    if ((1.0 - aColor.Alpha()) < Precision::Confusion())
+    {
+      di << aColor.GetRGB().StringName (aColor.GetRGB().Name());
+    }
     else
-      di << col.GetRGB().StringName(col.GetRGB().Name()) << " (" << col.Alpha() << ")";
+    {
+      di << aColor.GetRGB().StringName (aColor.GetRGB().Name()) << " (" << aColor.Alpha() << ")";
+    }
   }
   return 0;
 }
 
-static Standard_Integer setStyledcolor (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
+static Standard_Integer setStyledcolor (Draw_Interpretor& , Standard_Integer argc, const char** argv)
 {
-  if (argc<6) {
-    di<<"Use: "<<argv[0]<<" Doc shape R G B [alpha] type(s/c)\n";
+  if (argc < 3)
+  {
+    std::cout << "Syntax error: wrong number of arguments\n";
     return 1;
   }
-  Handle(TDocStd_Document) Doc;   
-  DDocStd::GetDocument(argv[1], Doc);
-  if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
-  TopoDS_Shape aShape;
-  aShape = DBRep::Get(argv[2]);
 
-  Quantity_Color col ( Draw::Atof(argv[3]), Draw::Atof(argv[4]), Draw::Atof(argv[5]), Quantity_TOC_RGB );
-  Quantity_ColorRGBA aColRGBA;
-  aColRGBA.SetRGB(col);
-  if (argc > 6 && (argv[6][0] != 's' && argv[6][0] != 'c')) {
-    aColRGBA.SetAlpha((Standard_ShortReal)(Draw::Atof(argv[6])));
+  Handle(TDocStd_Document) aDoc;
+  DDocStd::GetDocument (argv[1], aDoc);
+  if (aDoc.IsNull())
+  {
+    std::cout << "Syntax error: " << argv[1] << " is not a document\n";
+    return 1;
+  }
+
+  TopoDS_Shape aShape = DBRep::Get (argv[2]);
+  if (aShape.IsNull())
+  {
+    std::cout << "Syntax error: " << argv[2] << " is not a shape\n";
+    return 1;
   }
 
-  Handle(XCAFDoc_ColorTool) myColors = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
-  XCAFDoc_ColorType ctype = XCAFDoc_ColorGen;
-  if (argc > 6) {
-    if (argv[argc - 1][0] == 's')
-      ctype = XCAFDoc_ColorSurf;
-    else if (argv[argc - 1][0] == 'c')
-      ctype = XCAFDoc_ColorCurv;
+  XCAFDoc_ColorType aColorType = XCAFDoc_ColorGen;
+  Quantity_ColorRGBA aColRGBA;
+  for (Standard_Integer anArgIter = 3; anArgIter < argc; ++anArgIter)
+  {
+    if (parseXDocColorType (argv[anArgIter], aColorType))
+    {
+      //
+    }
+    else
+    {
+      Standard_Integer aNbParsed = ViewerTest::ParseColor (argc - anArgIter,
+                                                           argv + anArgIter,
+                                                           aColRGBA);
+      if (aNbParsed == 0)
+      {
+        std::cout << "Syntax error at '" << argv[anArgIter] << "'\n";
+        return 1;
+      }
+      anArgIter += aNbParsed - 1;
+    }
   }
-  Handle(XCAFDoc_ColorTool) localTool = XCAFDoc_DocumentTool::ColorTool(Doc->Main());
-  if (!localTool->SetInstanceColor(aShape, ctype, aColRGBA))
+
+  Handle(XCAFDoc_ColorTool) aColorTool = XCAFDoc_DocumentTool::ColorTool (aDoc->Main());
+  if (!aColorTool->SetInstanceColor (aShape, aColorType, aColRGBA))
   {
-    di << "cannot set color for the indicated component\n";
+    std::cout << "Error: cannot set color for the indicated component\n";
     return 1;
   }
   return 0;
@@ -415,30 +639,38 @@ void XDEDRAW_Colors::InitCommands(Draw_Interpretor& di)
   //=====================================  
   
   Standard_CString g = "XDE color's commands";
-  
-  di.Add ("XSetColor","Doc {Label|Shape} R G B [alpha] [c|s]\t: Set color [R G B] to shape given by Label, "
+
+  di.Add ("XSetColor","Doc {Label|Shape} R G B [alpha] [{generic|surface|curve}=gen]"
+                      "\t: Set color [R G B] to shape given by Label, "
                       "type of color 's' - for surface, 'c' - for curve (default generic)",
                   __FILE__, setColor, g);
 
-  di.Add ("XGetColor","Doc label \t: Return color defined on label in colortable",
+  di.Add ("XGetColor","Doc label"
+                      "\t: Return color defined on label in colortable",
                   __FILE__, getColor, g);
 
-  di.Add ("XGetShapeColor","Doc Label ColorType \t: Returns color defined by label",
+  di.Add ("XGetShapeColor","Doc Label {generic|surface|curve}"
+                           "\t: Returns color defined by label",
                   __FILE__, getShapeColor, g);
-  
-  di.Add ("XGetAllColors","Doc \t: Print all colors that defined in document",
+
+  di.Add ("XGetAllColors","Doc"
+                          "\t: Print all colors that defined in document",
                   __FILE__, getAllColors, g);
   
-  di.Add ("XAddColor","Doc R G B [alpha]\t: Add color in document to color table",
+  di.Add ("XAddColor","Doc R G B [alpha]"
+                      "\t: Add color in document to color table",
                   __FILE__, addColor, g);
   
-  di.Add ("XRemoveColor","Doc Label \t: Remove color in document from color table",
+  di.Add ("XRemoveColor","Doc Label"
+                         "\t: Remove color in document from color table",
                   __FILE__, removeColor, g);
 
-  di.Add ("XFindColor","Doc R G B [alpha]\t: Find label where indicated color is situated",
+  di.Add ("XFindColor","Doc R G B [alpha]"
+                       "\t: Find label where indicated color is situated",
                   __FILE__, findColor, g);
 
-  di.Add ("XUnsetColor","Doc {Label|Shape} ColorType \t: Unset color ",
+  di.Add ("XUnsetColor","Doc {Label|Shape} {generic|surface|curve}"
+                        "\t: Unset color",
                   __FILE__, unsetColor, g);
   
   di.Add ("XSetObjVisibility","Doc {Label|Shape} (0\1) \t: Set the visibility of shape  ",
@@ -450,10 +682,11 @@ void XDEDRAW_Colors::InitCommands(Draw_Interpretor& di)
   di.Add ("XGetInstanceVisible","Doc Shape \t: Return the visibility of shape ",
                   __FILE__, getStyledVisibility, g);
 
-  di.Add ("XGetInstanceColor","Doc Shape \t: Return the color of component shape ",
+  di.Add ("XGetInstanceColor","Doc Shape [{generic|surface|curve}=gen]"
+                              "\t: Return the color of component shape",
                   __FILE__, getStyledcolor, g);
 
-  di.Add ("XSetInstanceColor","Doc Shape R G B [alpha] type \t: sets color for component of shape if SHUO structure exists already ",
+  di.Add ("XSetInstanceColor","Doc Shape R G B [alpha] [{generic|surface|curve}=gen]"
+                              "\t: sets color for component of shape if SHUO structure exists already",
                   __FILE__, setStyledcolor, g);
-
 }