-- Standard_OutOfRange if AName in not known
-- in the Quantity_NameOfColor enumeration.
+ ColorFromName ( myclass;
+ theName : CString from Standard;
+ theColor : out NameOfColor from Quantity )
+ returns Boolean from Standard;
+ ---Purpose: Finds color from predefined names.
+ -- For example, the name of the color which
+ -- corresponds to "BLACK" is Quantity_NOC_BLACK.
+ -- Returns false if name is unknown.
+
HlsRgb ( myclass;
H, L, S : Parameter from Quantity;
R , G , B : out Parameter from Quantity ) ;
---Purpose: Internal test
---Category: Private methods
---\f
+--
fields
#include <Quantity_Color.ixx>
#include <Quantity_Color_1.hxx>
#include <Standard_OutOfRange.hxx>
+#include <TCollection_AsciiString.hxx>
// for Test method (suite et fin)
#include <string.h>
//-Methods, in order
+Standard_Boolean Quantity_Color::ColorFromName (const Standard_CString theName,
+ Quantity_NameOfColor& theColor)
+{
+ TCollection_AsciiString aName (theName);
+ aName.UpperCase();
+ if (aName.Search("QUANTITY_NOC_") == 1)
+ {
+ aName = aName.SubString (14, aName.Length());
+ }
+
+ for (Standard_Integer anIter = Quantity_NOC_BLACK; anIter <= Quantity_NOC_WHITE; ++anIter)
+ {
+ Standard_CString aColorName = Quantity_Color::StringName (Quantity_NameOfColor (anIter));
+ if (aName == aColorName)
+ {
+ theColor = (Quantity_NameOfColor )anIter;
+ return Standard_True;
+ }
+ }
+ return Standard_False;
+}
+
Quantity_Color::Quantity_Color () {
Quantity_Color::ValuesOf
Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
{
- for (Standard_Integer anIter = Quantity_NOC_BLACK; anIter <= Quantity_NOC_WHITE; ++anIter)
- {
- Standard_CString aColorName = Quantity_Color::StringName (Quantity_NameOfColor (anIter));
- if (strcasecmp (theName, aColorName) == 0)
- {
- return Quantity_NameOfColor (anIter);
- }
- }
-
- return DEFAULT_COLOR;
+ Quantity_NameOfColor aColor = DEFAULT_COLOR;
+ Quantity_Color::ColorFromName (theName, aColor);
+ return aColor;
}
//=======================================================================
return 1;
}
aChangeSet->ToSetColor = 1;
- aChangeSet->Color = ViewerTest::GetColorFromName (aNames.Last().ToCString());
- aNames.Remove (aNames.Length());
+
+ Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
+ Standard_Boolean isOk = Standard_False;
+ if (Quantity_Color::ColorFromName (aNames.Last().ToCString(), aColor))
+ {
+ aChangeSet->Color = aColor;
+ aNames.Remove (aNames.Length());
+ isOk = Standard_True;
+ }
+ else if (aNames.Length() >= 3)
+ {
+ const TCollection_AsciiString anRgbStr[3] =
+ {
+ aNames.Value (aNames.Upper() - 2),
+ aNames.Value (aNames.Upper() - 1),
+ aNames.Value (aNames.Upper() - 0)
+ };
+ isOk = anRgbStr[0].IsRealValue()
+ && anRgbStr[1].IsRealValue()
+ && anRgbStr[2].IsRealValue();
+ if (isOk)
+ {
+ Graphic3d_Vec4d anRgb;
+ anRgb.x() = anRgbStr[0].RealValue();
+ anRgb.y() = anRgbStr[1].RealValue();
+ anRgb.z() = anRgbStr[2].RealValue();
+ if (anRgb.x() < 0.0 || anRgb.x() > 1.0
+ || anRgb.y() < 0.0 || anRgb.y() > 1.0
+ || anRgb.z() < 0.0 || anRgb.z() > 1.0)
+ {
+ std::cout << "Error: RGB color values should be within range 0..1!\n";
+ return 1;
+ }
+ aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
+ aNames.Remove (aNames.Length());
+ aNames.Remove (aNames.Length());
+ aNames.Remove (aNames.Length());
+ }
+ }
+ if (!isOk)
+ {
+ std::cout << "Error: not enough arguments!\n";
+ return 1;
+ }
}
else if (aCmdName == "vunsetcolor")
{
}
else if (anArg == "-setcolor")
{
- if (++anArgIter >= theArgNb)
+ Standard_Integer aNbComps = 0;
+ Standard_Integer aCompIter = anArgIter + 1;
+ for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps)
{
- std::cout << "Error: wrong syntax at " << anArg << "\n";
- return 1;
+ if (theArgVec[aCompIter][0] == '-')
+ {
+ break;
+ }
+ }
+ switch (aNbComps)
+ {
+ case 1:
+ {
+ Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
+ Standard_CString aName = theArgVec[anArgIter + 1];
+ if (!Quantity_Color::ColorFromName (aName, aColor))
+ {
+ std::cout << "Error: unknown color name '" << aName << "'\n";
+ return 1;
+ }
+ aChangeSet->Color = aColor;
+ break;
+ }
+ case 3:
+ {
+ Graphic3d_Vec3d anRgb;
+ anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]);
+ anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]);
+ anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]);
+ if (anRgb.x() < 0.0 || anRgb.x() > 1.0
+ || anRgb.y() < 0.0 || anRgb.y() > 1.0
+ || anRgb.z() < 0.0 || anRgb.z() > 1.0)
+ {
+ std::cout << "Error: RGB color values should be within range 0..1!\n";
+ return 1;
+ }
+ aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB);
+ break;
+ }
+ default:
+ {
+ std::cout << "Error: wrong syntax at " << anArg << "\n";
+ return 1;
+ }
}
aChangeSet->ToSetColor = 1;
- aChangeSet->Color = ViewerTest::GetColorFromName (theArgVec[anArgIter]);
+ anArgIter += aNbComps;
}
else if (anArg == "-unsetcolor")
{
theCommands.Add("vaspects",
"vaspects [-noupdate|-update] [name1 [name2 [...]]]"
- "\n\t\t: [-setcolor ColorName] [-unsetcolor]"
+ "\n\t\t: [-setcolor ColorName] [-setcolor R G B] [-unsetcolor]"
"\n\t\t: [-setmaterial MatName] [-unsetmaterial]"
"\n\t\t: [-settransparency Transp] [-unsettransparency]"
"\n\t\t: [-setwidth LineWidth] [-unsetwidth]"