1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

0027818: Visualization - provide an interface to define highlight presentation properties

- introduces a wrapper for setting up highlight properties: Graphic3d_HighlightStyle;
- API of all methods that use highlight or selection color is changed to deal with Graphic3d_HighlightStyle;
- highlight in shading mode now supports transparency, implemented via blending;
- transparency for selection can also be set, but implementing custom entity owners with additional presentation on application level;
- methods PrsMgr_PresentationManager::Highlight, PrsMgr_PresentationManager::BoundBox that highlight object with hard-coded color are removed;
- deprecated methods of SelectMgr_EntityOwner, that use presentation manager's highlight method, were removed;
- methods of IsHilighted AIS context with selection color checks were replaced;
- added API to store dynamic and selection highlight to Prs3d_Drawer class;
- customization of dynamic and selection highlight for particular objects is now available through SelectMgr_SelectableObject::HilightAttributes();
- AIS_InteractiveContext highlight methods were updated to support individual highlight styles of interactive objects;
- introduced new command - vselprops, that allows to customize global selection and highlight properties like autoactivation, pixel tolerance and colors;
- Draw Harness commands vautoactivatesel and vselprecision were removed, use vselprops instead;
- fixed bug in command's parser;
- test case for issue #27818
This commit is contained in:
vpa
2016-09-28 12:43:17 +03:00
committed by kgv
parent 3a9b5dc86a
commit 8e5fb5eabc
69 changed files with 1381 additions and 1002 deletions

View File

@@ -735,47 +735,6 @@ static int VDir (Draw_Interpretor& theDI,
return 0;
}
//==============================================================================
//function : VSelPrecision
//purpose : To set the selection tolerance value
//Draw arg : Selection tolerance value (real value determining the width and
// height of selecting frustum bases). Without arguments the function
// just prints current tolerance.
//==============================================================================
static int VSelPrecision(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
if( argc > 2 )
{
di << "Wrong parameters! Must be: " << argv[0] << " [-unset] [tolerance]\n";
return 1;
}
Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext();
if( aContext.IsNull() )
return 1;
if( argc == 1 )
{
Standard_Real aPixelTolerance = aContext->PixelTolerance();
di << "Pixel tolerance : " << aPixelTolerance << "\n";
}
else if (argc == 2)
{
TCollection_AsciiString anArg = TCollection_AsciiString (argv[1]);
anArg.LowerCase();
if (anArg == "-unset")
{
aContext->SetPixelTolerance (-1);
}
else
{
aContext->SetPixelTolerance (anArg.IntegerValue());
}
}
return 0;
}
//! Auxiliary enumeration
enum ViewerTest_StereoPair
{
@@ -2918,32 +2877,33 @@ static int VDisplayAll (Draw_Interpretor& ,
return 0;
}
//! Auxiliary method to find presentation
inline Handle(PrsMgr_Presentation) findPresentation (const Handle(AIS_InteractiveContext)& theCtx,
const Handle(AIS_InteractiveObject)& theIO,
const Standard_Integer theMode)
//! Auxiliary method to check if presentation exists
inline Standard_Integer checkMode (const Handle(AIS_InteractiveContext)& theCtx,
const Handle(AIS_InteractiveObject)& theIO,
const Standard_Integer theMode)
{
if (theIO.IsNull())
if (theIO.IsNull() || theCtx.IsNull())
{
return Handle(PrsMgr_Presentation)();
return -1;
}
if (theMode != -1)
{
if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode))
{
return theCtx->MainPrsMgr()->Presentation (theIO, theMode);
return theMode;
}
}
else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode()))
{
return theCtx->MainPrsMgr()->Presentation (theIO, theIO->DisplayMode());
return theIO->DisplayMode();
}
else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode()))
{
return theCtx->MainPrsMgr()->Presentation (theIO, theCtx->DisplayMode());
return theCtx->DisplayMode();
}
return Handle(PrsMgr_Presentation)();
return -1;
}
enum ViewerTest_BndAction
@@ -2954,28 +2914,36 @@ enum ViewerTest_BndAction
};
//! Auxiliary method to print bounding box of presentation
inline void bndPresentation (Draw_Interpretor& theDI,
const Handle(PrsMgr_Presentation)& thePrs,
const TCollection_AsciiString& theName,
const ViewerTest_BndAction theAction)
inline void bndPresentation (Draw_Interpretor& theDI,
const Handle(PrsMgr_PresentationManager)& theMgr,
const Handle(AIS_InteractiveObject)& theObj,
const Standard_Integer theDispMode,
const TCollection_AsciiString& theName,
const ViewerTest_BndAction theAction,
const Handle(Graphic3d_HighlightStyle)& theStyle)
{
switch (theAction)
{
case BndAction_Hide:
{
thePrs->Presentation()->GraphicUnHighlight();
theMgr->Unhighlight (theObj, theDispMode);
break;
}
case BndAction_Show:
{
Handle(Graphic3d_Structure) aPrs (thePrs->Presentation());
aPrs->CStructure()->HighlightColor = Quantity_NOC_GRAY99;
aPrs->CStructure()->HighlightWithBndBox (aPrs, Standard_True);
theMgr->Color (theObj, theStyle, theDispMode);
break;
}
case BndAction_Print:
{
Bnd_Box aBox = thePrs->Presentation()->MinMaxValues();
Bnd_Box aBox;
for (PrsMgr_Presentations::Iterator aPrsIter (theObj->Presentations()); aPrsIter.More(); aPrsIter.Next())
{
if (aPrsIter.Value().Mode() != theDispMode)
continue;
aBox = aPrsIter.Value().Presentation()->Presentation()->MinMaxValues();
}
gp_Pnt aMin = aBox.CornerMin();
gp_Pnt aMax = aBox.CornerMax();
theDI << theName << "\n"
@@ -3005,6 +2973,8 @@ int VBounding (Draw_Interpretor& theDI,
ViewerTest_BndAction anAction = BndAction_Show;
Standard_Integer aMode = -1;
Handle(Graphic3d_HighlightStyle) aStyle;
Standard_Integer anArgIter = 1;
for (; anArgIter < theArgNb; ++anArgIter)
{
@@ -3037,6 +3007,10 @@ int VBounding (Draw_Interpretor& theDI,
}
}
if (anAction == BndAction_Show)
aStyle = new Graphic3d_HighlightStyle (Aspect_TOHM_BOUNDBOX, Quantity_NOC_GRAY99, 0.0);
Standard_Integer aHighlightedMode = -1;
if (anArgIter < theArgNb)
{
// has a list of names
@@ -3050,13 +3024,13 @@ int VBounding (Draw_Interpretor& theDI,
}
Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
if (aPrs.IsNull())
aHighlightedMode = checkMode (aCtx, anIO, aMode);
if (aHighlightedMode == -1)
{
std::cout << "Error: presentation " << aName << " does not exist\n";
std::cout << "Error: object " << aName << " has no presentation with mode " << aMode << std::endl;
return 1;
}
bndPresentation (theDI, aPrs, aName, anAction);
bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, aName, anAction, aStyle);
}
}
else if (aCtx->NbSelected() > 0)
@@ -3065,10 +3039,11 @@ int VBounding (Draw_Interpretor& theDI,
for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected())
{
Handle(AIS_InteractiveObject) anIO = aCtx->SelectedInteractive();
Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
if (!aPrs.IsNull())
aHighlightedMode = checkMode (aCtx, anIO, aMode);
if (aHighlightedMode != -1)
{
bndPresentation (theDI, aPrs, GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction);
bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode,
GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction, aStyle);
}
}
}
@@ -3079,10 +3054,10 @@ int VBounding (Draw_Interpretor& theDI,
anIter.More(); anIter.Next())
{
Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1());
Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode);
if (!aPrs.IsNull())
aHighlightedMode = checkMode (aCtx, anIO, aMode);
if (aHighlightedMode != -1)
{
bndPresentation (theDI, aPrs, anIter.Key2(), anAction);
bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, anIter.Key2(), anAction, aStyle);
}
}
}
@@ -5540,51 +5515,6 @@ static Standard_Integer VLoadSelection (Draw_Interpretor& /*theDi*/,
return 0;
}
//==============================================================================
//function : VAutoActivateSelection
//purpose : Activates or deactivates auto computation of selection
//==============================================================================
static int VAutoActivateSelection (Draw_Interpretor& theDi,
Standard_Integer theArgNb,
const char** theArgVec)
{
if (theArgNb > 2)
{
std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n";
return 1;
}
Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext();
if (aCtx.IsNull())
{
ViewerTest::ViewerInit();
aCtx = ViewerTest::GetAISContext();
}
if (theArgNb == 1)
{
TCollection_AsciiString aSelActivationString;
if (aCtx->GetAutoActivateSelection())
{
aSelActivationString.Copy ("ON");
}
else
{
aSelActivationString.Copy ("OFF");
}
theDi << "Auto activation of selection is: " << aSelActivationString << "\n";
}
else
{
Standard_Boolean toActivate = Draw::Atoi (theArgVec[1]) != 0;
aCtx->SetAutoActivateSelection (toActivate);
}
return 0;
}
//==============================================================================
//function : ViewerTest::Commands
//purpose : Add all the viewer command in the Draw_Interpretor
@@ -5828,12 +5758,6 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands)
"vsensera : erase active entities",
__FILE__,VClearSensi,group);
theCommands.Add("vselprecision",
"vselprecision [-unset] [tolerance_value]"
"\n\t\t Manages selection precision or prints current value if no parameter is passed."
"\n\t\t -unset - restores default selection tolerance behavior, based on individual entity tolerance",
__FILE__,VSelPrecision,group);
theCommands.Add("vperf",
"vperf: vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)"
"\n\t\t: Tests the animation of an object along a predefined trajectory.",
@@ -5944,12 +5868,6 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands)
"\n\t\t: -local - open local context before selection computation",
__FILE__, VLoadSelection, group);
theCommands.Add ("vautoactivatesel",
"vautoactivatesel [0|1] : manage or display the option to automatically"
"\n\t\t: activate selection for newly displayed objects"
"\n\t\t: [0|1] - turn off | on auto activation of selection",
__FILE__, VAutoActivateSelection, group);
theCommands.Add("vbsdf", "vbsdf [name] [options]"
"\nAdjusts parameters of material BSDF:"
"\n -help : Shows this message"

View File

@@ -95,7 +95,7 @@ void ViewerTest_CmdParser::Parse (Standard_Integer theArgsNb, const char** theAr
for (Standard_Integer anIter = 1; anIter < theArgsNb; ++anIter)
{
if (theArgVec[anIter][0] == '-')
if (theArgVec[anIter][0] == '-' && !std::isdigit (theArgVec[anIter][1]))
{
std::string anOptionName (&theArgVec[anIter][1]);
std::transform (anOptionName.begin(), anOptionName.end(), anOptionName.begin(), ::tolower);

View File

@@ -40,7 +40,7 @@ public:
}
//! Adds option to available option list. Several names may be provided if separated with '|'.
void AddOption (const std::string& theOptionNames, const std::string& theOptionDescription);
void AddOption (const std::string& theOptionNames, const std::string& theOptionDescription = "");
//! Prints help message based on provided command and options descriptions.
void Help();

View File

@@ -9025,6 +9025,133 @@ static int VManipulator (Draw_Interpretor& theDi,
return 0;
}
//===============================================================================================
//function : parseColor
//purpose :
//===============================================================================================
static Standard_Boolean parseColor (ViewerTest_CmdParser& theParser,
const std::string& theOptionName,
Quantity_Color& theColor)
{
std::string aColorArg = theParser.Arg (theOptionName, 0);
if (std::isdigit (aColorArg[0]))
{
Graphic3d_Vec3d aColor = theParser.ArgVec3d (theOptionName);
if (aColor.x() < 0.0 || aColor.x() > 1.0
|| aColor.y() < 0.0 || aColor.y() > 1.0
|| aColor.z() < 0.0 || aColor.z() > 1.0)
{
std::cerr << "Error: RGB color values should be within range 0..1!\n";
return Standard_False;
}
theColor.SetValues (aColor.x(), aColor.y(), aColor.z(), Quantity_TOC_RGB);
}
else
{
Quantity_NameOfColor aName = Quantity_NOC_BLACK;
if (!Quantity_Color::ColorFromName (aColorArg.c_str(), aName))
{
std::cerr << "Name: " << theParser.Arg (theOptionName, 0)
<< " does not correspond to any color in Quantity_NameOfColor!"
<< std::endl;
return Standard_False;
}
theColor.SetValues (aName);
}
return Standard_True;
}
//===============================================================================================
//function : VSelectionProperties
//purpose :
//===============================================================================================
static int VSelectionProperties (Draw_Interpretor& theDi,
Standard_Integer theArgsNb,
const char** theArgVec)
{
const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
if (aCtx.IsNull())
{
std::cerr << "No active viewer!\n";
return 1;
}
ViewerTest_CmdParser aCmd;
aCmd.AddOption ("autoActivate");
aCmd.AddOption ("pixTol");
aCmd.AddOption ("selColor");
aCmd.AddOption ("hiColor");
aCmd.AddOption ("selTransp");
aCmd.AddOption ("hiTransp");
aCmd.AddOption ("print");
aCmd.Parse (theArgsNb, theArgVec);
if (aCmd.HasOption ("help"))
{
theDi.PrintHelp (theArgVec[0]);
return 0;
}
if (aCmd.HasOption ("autoActivate", 1, Standard_False))
{
aCtx->SetAutoActivateSelection (aCmd.ArgBool ("autoActivate"));
}
if (aCmd.HasOption ("pixTol", 1, Standard_False))
{
aCtx->SetPixelTolerance (aCmd.ArgInt ("pixTol"));
}
Handle(Graphic3d_HighlightStyle)& aHiStyle = aCtx->ChangeHighlightStyle();
Handle(Graphic3d_HighlightStyle)& aSelStyle = aCtx->ChangeSelectionStyle();
Standard_Boolean toRedraw = Standard_False;
if (aCmd.HasOption ("selColor"))
{
Quantity_Color aNewColor;
if (!parseColor (aCmd, "selColor", aNewColor))
return 1;
aSelStyle->SetColor (aNewColor);
toRedraw = Standard_True;
}
if (aCmd.HasOption ("hiColor"))
{
Quantity_Color aNewColor;
if (!parseColor (aCmd, "hiColor", aNewColor))
return 1;
aHiStyle->SetColor (aNewColor);
}
if (aCmd.HasOption ("selTransp"))
{
aSelStyle->SetTransparency (aCmd.ArgFloat ("selTransp"));
toRedraw = Standard_True;
}
if (aCmd.HasOption ("hiTransp"))
{
aHiStyle->SetTransparency (aCmd.ArgFloat ("hiTransp"));
}
if (aCmd.HasOption ("print") || theArgsNb == 1)
{
theDi << "Auto-activation : " << (aCtx->GetAutoActivateSelection() ? "On" : "Off") << "\n";
theDi << "Selection pixel tolerance : " << aCtx->MainSelector()->PixelTolerance() << "\n";
theDi << "Selection color : " << Quantity_Color::StringName (aCtx->SelectionStyle()->Color().Name()) << "\n";
theDi << "Dynamic highlight color : " << Quantity_Color::StringName (aCtx->HighlightStyle()->Color().Name()) << "\n";
theDi << "Selection transparency : " << aCtx->SelectionStyle()->Transparency() << "\n";
theDi << "Dynamic highlight transparency : " << aCtx->HighlightStyle()->Transparency() << "\n";
}
if (aCtx->NbSelected() != 0 && toRedraw)
{
aCtx->HilightSelected (Standard_True);
}
return 0;
}
//=======================================================================
//function : ViewerCommands
//purpose :
@@ -9583,6 +9710,18 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
"\n '-zoomable {0|1}' - set zoom persistence",
__FILE__, VManipulator, group);
theCommands.Add("vselprops",
"\n vselprops [options]"
"\n Customizes selection and dynamic highlight parameters for the whole interactive context:"
"\n -autoActivate {0|1} : disables|enables default computation and activation of global selection mode"
"\n -pixTol value : sets up pixel tolerance"
"\n -selColor {name|r g b} : sets selection color"
"\n -hiColor {name|r g b} : sets dynamic highlight color"
"\n -selTransp value : sets transparency coefficient for selection"
"\n -hiTransp value : sets transparency coefficient for dynamic highlight"
"\n -print : prints current state of all mentioned parameters",
__FILE__, VSelectionProperties, group);
#if defined(_WIN32)
theCommands.Add("vprogressive",
"vprogressive",