mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-14 13:30:48 +03:00
0030623: Draw Harness - support hex color codes within ViewerTest::ParseColor()
ViewerTest::ParseColor() function is improved to be able to parse the following set of input arguments: - "Red Green Blue [Alpha]", where Red, Green, Blue, Alpha must be integers within the range [0, 255] or reals within the range [0.0, 1.0]. Note that "0 0 1" triple is parsed as "0.0 0.0 1.0" and will be interpreted as a blue color. - "ColorName [Alpha]", where ColorName is one of WHITE, BLACK, RED, GREEN, BLUE, etc. (look at Quantity_NameOfColor enumeration for all possible variants). Alpha may be integer or real, as described at the previous list item. - #HHH, [#]HHH[H], [#]HHHHHH[HH], where H is a hexadecimal digit (0 .. 9, a .. f, or A .. F). There are a short hexadecimal RGB, RGBA formats, and a usual RGB[A], respectively.
This commit is contained in:
@@ -95,12 +95,25 @@ public:
|
||||
//! Converts numeric expression, that can involve DRAW
|
||||
//! variables, to real value.
|
||||
Standard_EXPORT static Standard_Real Atof (const Standard_CString Name);
|
||||
|
||||
|
||||
//! Converts the numeric expression, that can involve DRAW variables, to a real value
|
||||
//! @param theExpressionString the strings that containes the expression involving DRAW variables to be parsed
|
||||
//! @param theParsedRealValue a real value that is a result of parsing
|
||||
//! @return true if parsing was successfull, or false otherwise
|
||||
Standard_EXPORT static bool ParseReal (const Standard_CString theExpressionString, Standard_Real& theParsedRealValue);
|
||||
|
||||
//! Converts numeric expression, that can involve DRAW
|
||||
//! variables, to integer value.
|
||||
//! Implemented as cast of Atof() to integer.
|
||||
Standard_EXPORT static Standard_Integer Atoi (const Standard_CString Name);
|
||||
|
||||
|
||||
//! Converts the numeric expression, that can involve DRAW variables, to an integer value
|
||||
//! @param theExpressionString the strings that containes the expression involving DRAW variables to be parsed
|
||||
//! @param theParsedIntegerValue an integer value that is a result of parsing
|
||||
//! @return true if parsing was successfull, or false otherwise
|
||||
Standard_EXPORT static bool ParseInteger (const Standard_CString theExpressionString,
|
||||
Standard_Integer& theParsedIntegerValue);
|
||||
|
||||
//! Returns last graphic selection description.
|
||||
Standard_EXPORT static void LastPick (Standard_Integer& view, Standard_Integer& X, Standard_Integer& Y, Standard_Integer& button);
|
||||
|
||||
|
@@ -1122,9 +1122,10 @@ static Standard_Real Parse(char*& name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Atof
|
||||
//purpose :
|
||||
// function : Atof
|
||||
// purpose :
|
||||
//=======================================================================
|
||||
Standard_Real Draw::Atof(const Standard_CString name)
|
||||
{
|
||||
@@ -1132,6 +1133,7 @@ Standard_Real Draw::Atof(const Standard_CString name)
|
||||
char* n = new char[1+strlen(name)];
|
||||
char* b = n;
|
||||
strcpy(n,name);
|
||||
Draw_ParseFailed = Standard_False;
|
||||
Standard_Real x = Parse(n);
|
||||
while ((*n == ' ') || (*n == '\t')) n++;
|
||||
if (*n) Draw_ParseFailed = Standard_True;
|
||||
@@ -1139,10 +1141,51 @@ Standard_Real Draw::Atof(const Standard_CString name)
|
||||
return x;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// function : ParseReal
|
||||
// purpose :
|
||||
//=======================================================================
|
||||
bool Draw::ParseReal (const Standard_CString theExpressionString, Standard_Real& theParsedRealValue)
|
||||
{
|
||||
const Standard_Real aParsedRealValue = Atof (theExpressionString);
|
||||
if (Draw_ParseFailed)
|
||||
{
|
||||
Draw_ParseFailed = Standard_False;
|
||||
return false;
|
||||
}
|
||||
theParsedRealValue = aParsedRealValue;
|
||||
return true;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// function : Atoi
|
||||
// purpose :
|
||||
//=======================================================================
|
||||
Standard_Integer Draw::Atoi(const Standard_CString name)
|
||||
{
|
||||
return (Standard_Integer ) Draw::Atof(name);
|
||||
return (Standard_Integer) Draw::Atof(name);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// function : ParseInteger
|
||||
// purpose :
|
||||
//=======================================================================
|
||||
bool Draw::ParseInteger (const Standard_CString theExpressionString, Standard_Integer& theParsedIntegerValue)
|
||||
{
|
||||
Standard_Real aParsedRealValue = 0.0;
|
||||
if (!ParseReal (theExpressionString, aParsedRealValue))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
const Standard_Integer aParsedIntegerValue = static_cast<Standard_Integer> (aParsedRealValue);
|
||||
if (static_cast<Standard_Real> (aParsedIntegerValue) != aParsedRealValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
theParsedIntegerValue = aParsedIntegerValue;
|
||||
return true;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Set
|
||||
//purpose : set a TCL var
|
||||
|
Reference in New Issue
Block a user