#define DEFAULT_FREEBOUNDARY_COLOR Quantity_NOC_GREEN
#define DEFAULT_MATERIAL Graphic3d_NOM_BRASS
+namespace
+{
+
+ const Standard_Integer THE_MAX_INTEGER_COLOR_COMPONENT = 255;
+
+ const Standard_ShortReal THE_MAX_REAL_COLOR_COMPONENT = 1.0f;
+
+ //! Parses string and get an integer color component (only values within range 0 .. 255 are allowed)
+ //! @param theColorComponentString the string representing the color component
+ //! @param theIntegerColorComponent an integer color component that is a result of parsing
+ //! @return true if parsing was successful, or false otherwise
+ static bool parseNumericalColorComponent (const Standard_CString theColorComponentString,
+ Standard_Integer& theIntegerColorComponent)
+ {
+ Standard_Integer anIntegerColorComponent;
+ if (!Draw::ParseInteger (theColorComponentString, anIntegerColorComponent))
+ {
+ return false;
+ }
+ if ((anIntegerColorComponent < 0) || (anIntegerColorComponent > THE_MAX_INTEGER_COLOR_COMPONENT))
+ {
+ return false;
+ }
+ theIntegerColorComponent = anIntegerColorComponent;
+ return true;
+ }
+
+ //! Parses the string and gets a real color component from it (only values within range 0.0 .. 1.0 are allowed)
+ //! @param theColorComponentString the string representing the color component
+ //! @param theRealColorComponent a real color component that is a result of parsing
+ //! @return true if parsing was successful, or false otherwise
+ static bool parseNumericalColorComponent (const Standard_CString theColorComponentString,
+ Standard_ShortReal& theRealColorComponent)
+ {
+ Standard_Real aRealColorComponent;
+ if (!Draw::ParseReal (theColorComponentString, aRealColorComponent))
+ {
+ return false;
+ }
+ const Standard_ShortReal aShortRealColorComponent = static_cast<Standard_ShortReal> (aRealColorComponent);
+ if ((aShortRealColorComponent < 0.0f) || (aShortRealColorComponent > THE_MAX_REAL_COLOR_COMPONENT))
+ {
+ return false;
+ }
+ theRealColorComponent = aShortRealColorComponent;
+ return true;
+ }
+
+ //! Parses the string and gets a real color component from it (integer values 2 .. 255 are scaled to the 0.0 .. 1.0
+ //! range, values 0 and 1 are leaved as they are)
+ //! @param theColorComponentString the string representing the color component
+ //! @param theColorComponent a color component that is a result of parsing
+ //! @return true if parsing was successful, or false otherwise
+ static bool parseColorComponent (const Standard_CString theColorComponentString,
+ Standard_ShortReal& theColorComponent)
+ {
+ Standard_Integer anIntegerColorComponent;
+ if (parseNumericalColorComponent (theColorComponentString, anIntegerColorComponent))
+ {
+ if (anIntegerColorComponent == 1)
+ {
+ theColorComponent = THE_MAX_REAL_COLOR_COMPONENT;
+ }
+ else
+ {
+ theColorComponent = anIntegerColorComponent * 1.0f / THE_MAX_INTEGER_COLOR_COMPONENT;
+ }
+ return true;
+ }
+ return parseNumericalColorComponent (theColorComponentString, theColorComponent);
+ }
+
+ //! Parses the array of strings and gets an integer color (only values within range 0 .. 255 are allowed and at least
+ //! one of components must be greater than 1)
+ //! @tparam TheNumber the type of resulting color vector elements
+ //! @param theNumberOfColorComponents the number of color components
+ //! @param theColorComponentStrings the array of strings representing color components
+ //! @param theNumericalColor a 4-component vector that is a result of parsing
+ //! @return true if parsing was successful, or false otherwise
+ template <typename TheNumber>
+ static bool parseNumericalColor (Standard_Integer& theNumberOfColorComponents,
+ const char* const* const theColorComponentStrings,
+ NCollection_Vec4<TheNumber>& theNumericalColor)
+ {
+ for (Standard_Integer aColorComponentIndex = 0; aColorComponentIndex < theNumberOfColorComponents;
+ ++aColorComponentIndex)
+ {
+ const char* const aColorComponentString = theColorComponentStrings[aColorComponentIndex];
+ TheNumber aNumericalColorComponent;
+ if (parseNumericalColorComponent (aColorComponentString, aNumericalColorComponent))
+ {
+ theNumericalColor[aColorComponentIndex] = aNumericalColorComponent;
+ }
+ else
+ {
+ if (aColorComponentIndex == 3)
+ {
+ theNumberOfColorComponents = 3;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ //! Parses an array of strings and get an integer color (only values within range 0 .. 255 are allowed and at least
+ //! one of components must be greater than 1)
+ //! @param theNumberOfColorComponents the number of color components
+ //! @param theColorComponentStrings the array of strings representing color components
+ //! @param theColor a color that is a result of parsing
+ //! @return true if parsing was successful, or false otherwise
+ static bool parseIntegerColor (Standard_Integer& theNumberOfColorComponents,
+ const char* const* const theColorComponentStrings,
+ Quantity_ColorRGBA& theColor)
+ {
+ const Standard_Integer THE_COLOR_COMPONENT_NOT_PARSED = -1;
+ Graphic3d_Vec4i anIntegerColor (THE_COLOR_COMPONENT_NOT_PARSED);
+ if (!parseNumericalColor (theNumberOfColorComponents, theColorComponentStrings, anIntegerColor))
+ {
+ 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);
+ }
+ theColor = Quantity_ColorRGBA (aRealColor);
+ return true;
+ }
+
+ //! Parses an array of strings and get a real color (only values within range 0.0 .. 1.0 are allowed)
+ //! @param theNumberOfColorComponents the number of color components
+ //! @param theColorComponentStrings the array of strings representing color components
+ //! @param theColor a color that is a result of parsing
+ //! @return true if parsing was successful, or false otherwise
+ static bool parseRealColor (Standard_Integer& theNumberOfColorComponents,
+ const char* const* const theColorComponentStrings,
+ Quantity_ColorRGBA& theColor)
+ {
+ Graphic3d_Vec4 aRealColor (THE_MAX_REAL_COLOR_COMPONENT);
+ if (!parseNumericalColor (theNumberOfColorComponents, theColorComponentStrings, aRealColor))
+ {
+ return false;
+ }
+ theColor = Quantity_ColorRGBA (aRealColor);
+ return true;
+ }
+
+} // namespace
+
//=======================================================================
-//function : GetColorFromName
-//purpose : get the Quantity_NameOfColor from a string
+// function : GetColorFromName
+// purpose : get the Quantity_NameOfColor from a string
//=======================================================================
Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName)
return aColor;
}
-
//=======================================================================
-//function : parseColor
-//purpose :
+// function : parseColor
+// purpose :
//=======================================================================
-Standard_Integer ViewerTest::parseColor (Standard_Integer theArgNb,
- const char** theArgVec,
- Quantity_ColorRGBA& theColor,
- bool theToParseAlpha)
+Standard_Integer ViewerTest::parseColor (const Standard_Integer theArgNb,
+ const char* const* const theArgVec,
+ Quantity_ColorRGBA& theColor,
+ const bool theToParseAlpha)
{
- Quantity_NameOfColor aColor = Quantity_NOC_BLACK;
- if (theArgNb >= 1
- && Quantity_Color::ColorFromName (theArgVec[0], aColor))
+ if ((theArgNb >= 1) && Quantity_ColorRGBA::ColorFromHex (theArgVec[0], theColor, !theToParseAlpha))
+ {
+ return 1;
+ }
+ if (theArgNb >= 1 && Quantity_ColorRGBA::ColorFromName (theArgVec[0], theColor))
{
- theColor = Quantity_ColorRGBA (aColor);
- if (theArgNb >= 2
- && theToParseAlpha)
+ if (theArgNb >= 2 && theToParseAlpha)
{
- const TCollection_AsciiString anAlphaStr (theArgVec[1]);
- if (anAlphaStr.IsRealValue())
+ const Standard_CString anAlphaStr = theArgVec[1];
+ Standard_ShortReal anAlphaComponent;
+ if (parseColorComponent (anAlphaStr, anAlphaComponent))
{
- float anAlpha = (float )anAlphaStr.RealValue();
- if (anAlpha < 0.0f || anAlpha > 1.0f)
- {
- std::cout << "Syntax error: alpha should be within range 0..1!\n";
- return 0;
- }
+ theColor.SetAlpha (anAlphaComponent);
return 2;
}
}
return 1;
}
- else if (theArgNb >= 3)
+ if (theArgNb >= 3)
{
- Graphic3d_Vec4 anRgba (0.0f, 0.0f, 0.0f, 1.0f);
- Standard_Integer aNbComps = Min (theArgNb, theToParseAlpha ? 4 : 3);
- for (int aCompIter = 0; aCompIter < aNbComps; ++aCompIter)
+ const Standard_Integer aNumberOfColorComponentsToParse = Min (theArgNb, theToParseAlpha ? 4 : 3);
+ Standard_Integer aNumberOfColorComponentsParsed = aNumberOfColorComponentsToParse;
+ if (parseIntegerColor (aNumberOfColorComponentsParsed, theArgVec, theColor))
{
- const TCollection_AsciiString anRgbaStr (theArgVec[aCompIter]);
- if (!anRgbaStr.IsRealValue())
- {
- if (aCompIter == 3)
- {
- anRgba.a() = 1.0f;
- aNbComps = 3;
- break;
- }
- return 0;
- }
-
- anRgba[aCompIter] = (float )anRgbaStr.RealValue();
- if (anRgba[aCompIter] < 0.0 || anRgba[aCompIter] > 1.0)
- {
- std::cout << "Error: RGBA color values should be within range 0..1!\n";
- return 0;
- }
+ return aNumberOfColorComponentsParsed;
}
- theColor = Quantity_ColorRGBA (anRgba);
- return aNbComps;
+ if (parseRealColor (aNumberOfColorComponentsParsed, theArgVec, theColor))
+ {
+ return aNumberOfColorComponentsParsed;
+ }
+ return 0;
}
-
return 0;
}
//purpose : To list the displayed object with their attributes
//==============================================================================
static int VDir (Draw_Interpretor& theDI,
- Standard_Integer ,
- const char** )
+ Standard_Integer theNbArgs,
+ const char** theArgVec)
{
- for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS());
- anIter.More(); anIter.Next())
+ TCollection_AsciiString aMatch;
+ Standard_Boolean toFormat = Standard_False;
+ for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
{
- theDI << "\t" << anIter.Key2() << "\n";
+ TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
+ anArgCase.LowerCase();
+ if (anArgCase == "-list"
+ || anArgCase == "-format")
+ {
+ toFormat = Standard_True;
+ }
+ else if (aMatch.IsEmpty())
+ {
+ aMatch = theArgVec[anArgIter];
+ }
+ else
+ {
+ std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n";
+ return 1;
+ }
}
+
+ TCollection_AsciiString aRes;
+ for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next())
+ {
+ if (!aMatch.IsEmpty())
+ {
+ const TCollection_AsciiString aCheck = TCollection_AsciiString ("string match '") + aMatch + "' '" + anIter.Key2() + "'";
+ if (theDI.Eval (aCheck.ToCString()) == 0
+ && *theDI.Result() != '1')
+ {
+ continue;
+ }
+ }
+
+ if (toFormat)
+ {
+ aRes += TCollection_AsciiString("\t") + anIter.Key2() + "\n";
+ }
+ else
+ {
+ aRes += anIter.Key2() + " ";
+ }
+ }
+ theDI.Reset();
+ theDI << aRes;
return 0;
}
Standard_Boolean isContextOnly = Standard_False;
Standard_Boolean toRemoveAll = Standard_False;
Standard_Boolean toPrintInfo = Standard_True;
+ Standard_Boolean toFailOnError = Standard_True;
Standard_Integer anArgIter = 1;
for (; anArgIter < theArgNb; ++anArgIter)
{
toPrintInfo = Standard_False;
}
+ else if (anArg == "-noerror"
+ || anArg == "-nofail")
+ {
+ toFailOnError = Standard_False;
+ }
else if (anUpdateTool.parseRedrawMode (anArg))
{
continue;
{
for (; anArgIter < theArgNb; ++anArgIter)
{
- TCollection_AsciiString aName = theArgVec[anArgIter];
- Handle(AIS_InteractiveObject) anIO;
- if (!GetMapOfAIS().Find2 (aName, anIO))
+ const TCollection_AsciiString aName (theArgVec[anArgIter]);
+ if (aName.Search ("*") != -1)
{
- theDI << aName << " was not bound to some object.\n";
+ for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName aPrsIter (GetMapOfAIS()); aPrsIter.More(); aPrsIter.Next())
+ {
+ if (aPrsIter.Key1()->GetContext() != aCtx)
+ {
+ continue;
+ }
+ const TCollection_AsciiString aCheck = TCollection_AsciiString ("string match '") + aName + "' '" + aPrsIter.Key2() + "'";
+ if (theDI.Eval (aCheck.ToCString()) == 0
+ && *theDI.Result() == '1')
+ {
+ anIONameList.Append (aPrsIter.Key2());
+ }
+ }
+ theDI.Reset();
continue;
}
- if (anIO->GetContext() != aCtx)
+ Handle(AIS_InteractiveObject) anIO;
+ if (!GetMapOfAIS().Find2 (aName, anIO))
{
- theDI << aName << " was not displayed in current context.\n";
- theDI << "Please activate view with this object displayed and try again.\n";
- continue;
+ if (toFailOnError)
+ {
+ std::cout << "Syntax error: '" << aName << "' was not bound to some object.\n";
+ return 1;
+ }
+ }
+ else if (anIO->GetContext() != aCtx)
+ {
+ if (toFailOnError)
+ {
+ std::cout << "Syntax error: '" << aName << "' was not displayed in current context.\n"
+ << "Please activate view with this object displayed and try again.\n";
+ return 1;
+ }
+ }
+ else
+ {
+ anIONameList.Append (aName);
}
-
- anIONameList.Append (aName);
- continue;
}
}
else if (aCtx->NbSelected() > 0)
aCtx->Remove (anIO, Standard_False);
if (toPrintInfo)
{
- theDI << anIter.Value() << " was removed\n";
+ theDI << anIter.Value() << " ";
}
if (!isContextOnly)
{
Standard_Integer anArgIter = 1;
Standard_Boolean toEraseInView = Standard_False;
+ Standard_Boolean toFailOnError = Standard_True;
TColStd_SequenceOfAsciiString aNamesOfEraseIO;
for (; anArgIter < theArgNb; ++anArgIter)
{
{
toEraseInView = Standard_True;
}
+ else if (anArgCase == "-noerror"
+ || anArgCase == "-nofail")
+ {
+ toFailOnError = Standard_False;
+ }
else
{
aNamesOfEraseIO.Append (theArgVec[anArgIter]);
if (!aNamesOfEraseIO.IsEmpty())
{
// Erase named objects
- for (Standard_Integer anIter = 1; anIter <= aNamesOfEraseIO.Length(); ++anIter)
+ NCollection_IndexedDataMap<Handle(AIS_InteractiveObject), TCollection_AsciiString> aPrsList;
+ for (TColStd_SequenceOfAsciiString::Iterator anIter (aNamesOfEraseIO); anIter.More(); anIter.Next())
{
- TCollection_AsciiString aName = aNamesOfEraseIO.Value (anIter);
- Handle(AIS_InteractiveObject) anIO;
- if (!GetMapOfAIS().Find2 (aName, anIO))
+ const TCollection_AsciiString& aName = anIter.Value();
+ if (aName.Search ("*") != -1)
{
- continue;
+ for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName aPrsIter (GetMapOfAIS()); aPrsIter.More(); aPrsIter.Next())
+ {
+ const TCollection_AsciiString aCheck = TCollection_AsciiString ("string match '") + aName + "' '" + aPrsIter.Key2() + "'";
+ if (theDI.Eval (aCheck.ToCString()) == 0
+ && *theDI.Result() == '1')
+ {
+ aPrsList.Add (aPrsIter.Key1(), aPrsIter.Key2());
+ }
+ }
+ theDI.Reset();
}
-
- theDI << aName << " ";
- if (!anIO.IsNull())
+ else
{
- if (toEraseInView)
+ Handle(AIS_InteractiveObject) anIO;
+ if (!GetMapOfAIS().Find2 (aName, anIO))
{
- aCtx->SetViewAffinity (anIO, aView, Standard_False);
+ if (toFailOnError)
+ {
+ std::cout << "Syntax error: '" << aName << "' is not found\n";
+ return 1;
+ }
}
else
{
- aCtx->Erase (anIO, Standard_False);
+ aPrsList.Add (anIO, aName);
}
}
}
+
+ for (NCollection_IndexedDataMap<Handle(AIS_InteractiveObject), TCollection_AsciiString>::Iterator anIter (aPrsList); anIter.More(); anIter.Next())
+ {
+ theDI << anIter.Value() << " ";
+ if (toEraseInView)
+ {
+ aCtx->SetViewAffinity (anIter.Key(), aView, Standard_False);
+ }
+ else
+ {
+ aCtx->Erase (anIter.Key(), Standard_False);
+ }
+ }
}
else if (!toEraseAll && aCtx->NbSelected() > 0)
{
Bnd_Box aBox;
for (PrsMgr_Presentations::Iterator aPrsIter (theObj->Presentations()); aPrsIter.More(); aPrsIter.Next())
{
- if (aPrsIter.Value().Mode() != theDispMode)
+ if (aPrsIter.Value()->Mode() != theDispMode)
continue;
- aBox = aPrsIter.Value().Presentation()->Presentation()->MinMaxValues();
+ aBox = aPrsIter.Value()->MinMaxValues();
}
gp_Pnt aMin = aBox.CornerMin();
gp_Pnt aMax = aBox.CornerMax();
std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
return 1;
}
+ if (theArgNb == 2
+ && TCollection_AsciiString (theArgVec[1]) == "*")
+ {
+ // alias
+ return VDisplayAll (theDI, 1, theArgVec);
+ }
Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
if (aCtx.IsNull())
anObjDispMode = Draw::Atoi (theArgVec [anArgIter]);
}
- else if (aNameCase == "-highmode"
+ else if (aNameCase == "-himode"
+ || aNameCase == "-highmode"
|| aNameCase == "-highlightmode")
{
if (++anArgIter >= theArgNb)
}
if (anObjDispMode != -2)
{
- aShape->SetDisplayMode (anObjDispMode);
+ if (anObjDispMode == -1)
+ {
+ aShape->UnsetDisplayMode();
+ }
+ if (!aShape->AcceptDisplayMode (anObjDispMode))
+ {
+ std::cout << "Syntax error: " << aShape->DynamicType()->Name() << " rejects " << anObjDispMode << " display mode\n";
+ return 1;
+ }
+ else
+ {
+ aShape->SetDisplayMode (anObjDispMode);
+ }
}
if (anObjHighMode != -2)
{
+ if (anObjHighMode != -1
+ && !aShape->AcceptDisplayMode (anObjHighMode))
+ {
+ std::cout << "Syntax error: " << aShape->DynamicType()->Name() << " rejects " << anObjHighMode << " display mode\n";
+ return 1;
+ }
aShape->SetHilightMode (anObjHighMode);
}
const Handle(SelectBasics_SensitiveEntity)& anEntity = aSelector->PickedEntity (aPickIter);
Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anEntity->OwnerId());
Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
- TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
+
+ TCollection_AsciiString aName;
+ GetMapOfAIS().Find1 (anObj, aName);
aName.LeftJustify (20, ' ');
char anInfoStr[512];
Sprintf (anInfoStr,
// handle whole object selection
if (anOwner == anObj->GlobalSelOwner())
{
- TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj);
+ TCollection_AsciiString aName;
+ GetMapOfAIS().Find1 (anObj, aName);
aName.LeftJustify (20, ' ');
theDI << aName << " ";
objInfo (aDetected, anObj, theDI);
ViewerTest_CmdParser aCmd;
- aCmd.AddDescription ("Adjusts parameters of material BSDF:");
+ aCmd.SetDescription ("Adjusts parameters of material BSDF:");
aCmd.AddOption ("print|echo|p", "Prints BSDF");
}
// find object
- TCollection_AsciiString aName (aCmd.Arg ("", 0).c_str());
+ TCollection_AsciiString aName (aCmd.Arg (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, 0).c_str());
Handle(AIS_InteractiveObject) anIObj;
if (!GetMapOfAIS().Find2 (aName, anIObj))
{
__FILE__, VUpdate, group);
theCommands.Add("verase",
- "verase [-noupdate|-update] [-local] [name1] ... [name n]"
+ "verase [-noupdate|-update] [-local] [name1] ... [name n] [-noerror]"
"\n\t\t: Erases selected or named objects."
"\n\t\t: If there are no selected or named objects the whole viewer is erased."
"\n\t\t: Option -local enables erasing of selected or named objects without"
- "\n\t\t: closing local selection context.",
+ "\n\t\t: closing local selection context."
+ "\n\t\t: Option -noerror prevents exception on non-existing objects.",
__FILE__, VErase, group);
theCommands.Add("vremove",
- "vremove [-noupdate|-update] [-context] [-all] [-noinfo] [name1] ... [name n]"
+ "vremove [-noupdate|-update] [-context] [-all] [-noinfo] [name1] ... [name n] [-noerror]"
"or vremove [-context] -all to remove all objects"
"\n\t\t: Removes selected or named objects."
"\n\t\t If -context is in arguments, the objects are not deleted"
"\n\t\t: closing local selection context. Empty local selection context will be"
"\n\t\t: closed."
"\n\t\t: Option -noupdate suppresses viewer redraw call."
- "\n\t\t: Option -noinfo suppresses displaying the list of removed objects.",
+ "\n\t\t: Option -noinfo suppresses displaying the list of removed objects."
+ "\n\t\t: Option -noerror prevents exception on non-existing objects.",
__FILE__, VRemove, group);
theCommands.Add("vdonly",
__FILE__,VDispMode,group);
theCommands.Add("vdir",
- "Lists all objects displayed in 3D viewer",
+ "vdir [mask] [-list]"
+ "\n\t\t: Lists all objects displayed in 3D viewer"
+ "\n\t\t: mask - name filter like prefix*"
+ "\n\t\t: -list - format list with new-line per name; OFF by default",
__FILE__,VDir,group);
#ifdef HAVE_FREEIMAGE