1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-05-26 11:05:31 +03:00

0028954: Visualization - implement interactive object for camera manipulations

This commit is contained in:
aba 2017-09-08 19:03:18 +03:00 committed by ema
parent 1e25daebc7
commit 78dbfeb083
8 changed files with 3613 additions and 0 deletions

2076
src/AIS/AIS_ViewCube.cxx Normal file

File diff suppressed because it is too large Load Diff

1044
src/AIS/AIS_ViewCube.hxx Normal file

File diff suppressed because it is too large Load Diff

View File

@ -180,3 +180,5 @@ AIS_TypeOfAxis.hxx
AIS_TypeOfDist.hxx
AIS_TypeOfIso.hxx
AIS_TypeOfPlane.hxx
AIS_ViewCube.hxx
AIS_ViewCube.cxx

View File

@ -26,6 +26,7 @@
#include <AIS_InteractiveObject.hxx>
#include <AIS_ListOfInteractive.hxx>
#include <AIS_ListIteratorOfListOfInteractive.hxx>
#include <AIS_ViewCube.hxx>
#include <DBRep.hxx>
#include <Draw_ProgressIndicator.hxx>
#include <Graphic3d_ArrayOfPolylines.hxx>
@ -233,6 +234,25 @@ Standard_EXPORT Handle(AIS_Manipulator) GetActiveAISManipulator()
return NULL;
}
typedef NCollection_DataMap<Handle(V3d_View), Handle(AIS_ViewCube)> ViewerTest_MapOfViewCube;
Standard_EXPORT ViewerTest_MapOfViewCube& MapOfViewCube()
{
static ViewerTest_MapOfViewCube aViewMap;
return aViewMap;
}
Standard_EXPORT Handle(AIS_ViewCube) ActiveViewCube()
{
Handle(AIS_ViewCube) aCube;
if (MapOfViewCube().Find (ViewerTest::CurrentView(), aCube))
{
return aCube;
}
return NULL;
}
//==============================================================================
#ifdef _WIN32
@ -11486,6 +11506,215 @@ static int VDumpSelectionImage (Draw_Interpretor& /*theDi*/,
return 0;
}
//===============================================================================================
//function : VViewCube
//purpose :
//===============================================================================================
static int VViewCube (Draw_Interpretor& theDi,
Standard_Integer theArgsNb,
const char** theArgVec)
{
if (theArgsNb < 2)
{
std::cout << "Syntax error: wrong number arguments for '" << theArgVec[0] << "'\n";
return 1;
}
const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
const Handle(V3d_View)& aView = ViewerTest::CurrentView();
if (aContext.IsNull() || aView.IsNull())
{
std::cout << "Error: no active view.\n";
return 1;
}
ViewerTest_AutoUpdater anUpdateTool (aContext, aView);
Standard_Integer anArgIter = 1;
for (; anArgIter < theArgsNb; ++anArgIter)
{
anUpdateTool.parseRedrawMode (theArgVec[anArgIter]);
}
Handle(AIS_ViewCube) aViewCube;
ViewerTest_CmdParser aCmd;
aCmd.AddDescription ("vviewcube Name [options]. Commmand manages View Cube object:");
aCmd.AddOption ("enable", "enables view cube");
aCmd.AddOption ("disable", "disables view cube");
aCmd.AddOption ("remove", "removes view cube presentation from context and view");
aCmd.AddOption ("remove", "removes view cube presentation from context and view");
aCmd.AddOption ("reset", "reset geomertical and visual attributes");
aCmd.AddOption ("size", "... size - set size of View Cube");
aCmd.AddOption ("adaptsize", " - adapt all another parameters to input size");
aCmd.AddOption ("color", "... r g b - set color of View Cube ");
aCmd.AddOption ("boxcolor", "... r g b - set box color of view cube");
aCmd.AddOption ("arrowcolor", "... r g b - set arrow color of view cube");
aCmd.AddOption ("textcolor", "... r g b - set side text color of view cube");
aCmd.AddOption ("innercolor", "... r g b - set inner box color of view cube");
aCmd.AddOption ("arrowangle", "... value - set pointer angle of arrows in radians");
aCmd.AddOption ("arrowlength", "... value - set length of arrows");
aCmd.AddOption ("arrowpadding", "... value - set padding between axis and arrows");
aCmd.AddOption ("transparency", "... [0;1] - set transparency of object");
aCmd.AddOption ("boxtransparency", "... [0;1] - set transparency of box in View Cube");
aCmd.AddOption ("arrowtransparency", "... [0;1] - set transparency of arrows in View Cube");
aCmd.AddOption ("font", "... string - set font name");
aCmd.AddOption ("fontheight", "... value - set font height");
aCmd.AddOption ("boxpadding", "... value - set padding between box sides");
aCmd.AddOption ("axispadding", "... value - set padding between box and arrows");
aCmd.AddOption ("cornerradius", "... value - set radius of side corners in [0;0.5] (0-50% of box side size)");
aCmd.AddOption ("hideedges", " - hide edges of View Cube");
aCmd.AddOption ("showedges", " - show edges of View Cube");
aCmd.AddOption ("hidevertices", " - hide vertices ov View Cube");
aCmd.AddOption ("showvertices", " - show vertices ov View Cube");
aCmd.AddOption ("position", "... PixX PixY - 2D position of View Cube from top left corner");
aCmd.Parse (theArgsNb, theArgVec);
if (aCmd.HasOption ("help"))
{
theDi.PrintHelp (theArgVec[0]);
return 0;
}
// Get current view cube entity
aViewCube = ActiveViewCube();
if (aViewCube.IsNull())
{
aViewCube = new AIS_ViewCube();
MapOfViewCube().Bind (aView, aViewCube);
aViewCube->SetAutoTransform (Standard_True);
}
if (aCmd.HasOption ("color"))
{
aViewCube->SetColor (Quantity_Color (aCmd.ArgVec3f ("color")));
}
if (aCmd.HasOption ("boxcolor"))
{
aViewCube->SetBoxColor (Quantity_Color (aCmd.ArgVec3f ("boxcolor")));
}
if (aCmd.HasOption ("arrowcolor"))
{
aViewCube->SetArrowColor (Quantity_Color (aCmd.ArgVec3f ("arrowcolor")));
}
if (aCmd.HasOption ("textcolor"))
{
aViewCube->SetTextColor (Quantity_Color (aCmd.ArgVec3f ("textcolor")));
}
if (aCmd.HasOption ("innercolor"))
{
aViewCube->SetInnerColor (Quantity_Color (aCmd.ArgVec3f ("innercolor")));
}
if (aCmd.HasOption ("arrowangle"))
{
aViewCube->SetArrowAngle (aCmd.ArgDouble ("arrowangle") * M_PI / 180.0);
}
if (aCmd.HasOption ("arrowlength"))
{
aViewCube->SetArrowLength (aCmd.ArgDouble ("arrowlength"));
}
if (aCmd.HasOption ("arrowpadding"))
{
aViewCube->SetArrowPadding (aCmd.ArgDouble ("arrowpadding"));
}
if (aCmd.HasOption ("transparency"))
{
aViewCube->SetTransparency (aCmd.ArgDouble ("transparency"));
}
if (aCmd.HasOption ("boxtransparency"))
{
aViewCube->SetBoxTransparency (aCmd.ArgDouble ("boxtransparency"));
}
if (aCmd.HasOption ("arrowtransparency"))
{
aViewCube->SetArrowTransparency (aCmd.ArgDouble ("arrowtransparency"));
}
if (aCmd.HasOption ("font"))
{
aViewCube->SetFont (aCmd.Arg ("font", 0).c_str());
}
if (aCmd.HasOption ("fontheight"))
{
aViewCube->SetFontHeight (aCmd.ArgDouble ("fontheight", 0));
}
if (aCmd.HasOption ("boxpadding"))
{
aViewCube->SetBoxPadding (aCmd.ArgDouble ("boxpadding"));
}
if (aCmd.HasOption ("axispadding"))
{
aViewCube->SetAxisPadding (aCmd.ArgDouble ("axispadding"));
}
if (aCmd.HasOption ("cornerradius"))
{
aViewCube->SetCornerRadius (aCmd.ArgDouble ("cornerradius"));
}
if (aCmd.HasOption ("hideedges"))
{
aViewCube->SetDrawEdges (Standard_False);
}
if (aCmd.HasOption ("showedges"))
{
aViewCube->SetDrawEdges (Standard_True);
}
if (aCmd.HasOption ("hidevertices"))
{
aViewCube->SetDrawVertices (Standard_False);
}
if (aCmd.HasOption ("showvertices"))
{
aViewCube->SetDrawVertices (Standard_True);
}
if (aCmd.HasOption ("position", 2))
{
aViewCube->SetPosition (Graphic3d_Vec2i (aCmd.ArgInt ("position", 0), aCmd.ArgInt ("position", 1)),
aView);
}
if (aCmd.HasOption ("size"))
{
aViewCube->SetSize (aCmd.ArgDouble ("size", 0), aCmd.HasOption ("adaptsize"));
}
if (aCmd.HasOption ("reset"))
{
aViewCube->Reset();
}
// Enable View Cube for current view
if (aCmd.HasOption ("enable") && !aContext->IsDisplayed (aViewCube))
{
aContext->MainSelector()->SetPickClosest (Standard_False);
if (aViewCube->View().IsNull())
{
aViewCube->SetView (aView);
aViewCube->AddTo (aContext, aView);
}
else
{
aViewCube->Show();
}
}
else if (aCmd.HasOption ("disable") && aContext->IsDisplayed (aViewCube))
{
ViewerTest::GetAISContext()->MainSelector()->SetPickClosest (Standard_True);
aViewCube->Hide();
}
else if (aCmd.HasOption ("remove") && aContext->IsDisplayed (aViewCube))
{
ViewerTest::GetAISContext()->MainSelector()->SetPickClosest (Standard_True);
MapOfViewCube().UnBind (aViewCube->View());
aContext->Remove (aViewCube, Standard_False);
}
else
{
TColStd_ListOfInteger aModes;
aViewCube->ToBeUpdated (aModes);
if (!aModes.IsEmpty())
{
aContext->Redisplay (aViewCube, Standard_False);
}
}
return 0;
}
//=======================================================================
//function : ViewerCommands
//purpose :
@ -12181,4 +12410,39 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
"vprogressive",
__FILE__, VProgressiveMode, group);
#endif
theCommands.Add ("vviewcube",
"\n vviewcube [-enable|-disable]"
"\n Warning: after end pf test please call vviewcube -remove, otherwise View Cube will hold down active view from closing"
"\n tool to create and manage interactive view manipualtion object for active view."
"\n Options: "
"\n '-enable|disable' display/erase view cube with defined visual options"
"\n '-reset reset geomertical and visual attributes'"
"\n '-size Value' adjust position when attaching"
"\n '-adaptSize' call with -size to adapt all part to size of 3D box"
"\n 'remove' removes view cube presentation from context and view"
"\n 'size Size' set size of View Cube"
"\n 'color R G B' set color of View Cube in limits [0;1]"
"\n 'boxcolor R G B' set box color of view cube in limits [0;1]"
"\n 'arrowcolor R G B' set arrow color of view cube in limits [0;1]"
"\n 'textcolor R G B' set color of side text of view cube in limits [0;1]"
"\n 'innercolor R G B' set inner box color of view cube in limits [0;1]"
"\n 'arrowangle Value' set pointer angle of arrows in radians"
"\n 'arrowlength Value' set length of arrows"
"\n 'arrowpadding Value' set padding between axis and arrows"
"\n 'transparency [0;1]' set transparency of object"
"\n 'boxtransparency [0;1]' set transparency of box in View Cube"
"\n 'arrowtransparency [0;1]' set transparency of arrows in View Cube"
"\n 'font Name' set font name"
"\n 'fontheight value' set font height"
"\n 'boxpadding Value' set padding between box sides"
"\n 'axispadding Value' set padding between box and arrows"
"\n 'cornerradius Value' set radius of corners of sides"
"\n 'hideedges' hide edges of View Cube"
"\n 'showedges' show edges of View Cube"
"\n 'hidevertices' hide vertices ov View Cube"
"\n 'showvertices' show vertices ov View Cube"
"\n 'position XPix YPix' 2D position of View Cube from top left corner",
__FILE__, VViewCube, group);
}

View File

@ -0,0 +1,64 @@
puts "=================================="
puts "AIS_ViewCube - display and erase with default settings"
puts "=================================="
set anImage1 $imagedir/${casename}_1.png
set anImage2 $imagedir/${casename}_2.png
set anImage3 $imagedir/${casename}_3.png
set anImage4 $imagedir/${casename}_4.png
vclear
vclose ALL
vinit
# -------------------------------------
# create helper object
# -------------------------------------
box aBox1 15 20 70
vdisplay aBox1 -dispMode 1
vaxo
vfit
# -------------------------------------
# display view cube object
# -------------------------------------
vviewcube -enable -size 70 -adaptsize -position 120 250
vmoveto 118 230
if {[vreadpixel 118 230 name] != "DARKTURQUOISE 1"} {
puts "ERROR: Highlighting of view cube side is wrong."
}
vmoveto 0 0
vdump $anImage1
# -------------------------------------
# Check side
# -------------------------------------
vselect 125 200
if {[vreadpixel 115 233 name] != "GRAY95 1"} {
puts "ERROR: Display of view cube is wrong."
}
if {[vreadpixel 190 136 name] != "IVORY 1"} {
puts "ERROR: Position of TOP camera is wrong."
}
vdump $anImage2
# -------------------------------------
# Check edge
# -------------------------------------
vselect 163 242
if {[vreadpixel 141 234 name] != "GRAY76 1"} {
puts "ERROR: Position of TOP-RIGHT camera is wrong."
}
vdump $anImage3
# -------------------------------------
# Check vertex
# -------------------------------------
vselect 121 213
if {[vreadpixel 120 250 name] != "GRAY95 1"} {
puts "ERROR: Position of TOP-RIGHT-BACK camera is wrong."
}
vdump $anImage4
vviewcube -remove
vclear

46
tests/v3d/viewcube/move Normal file
View File

@ -0,0 +1,46 @@
puts "=================================="
puts "AIS_ViewCube - check positioning of View Cube"
puts "=================================="
set anImage1 $imagedir/${casename}_1.png
set anImage2 $imagedir/${casename}_2.png
set anImage3 $imagedir/${casename}_3.png
set anImage4 $imagedir/${casename}_4.png
vclear
vclose ALL
vinit
# -------------------------------------
# display view cube object
# -------------------------------------
vviewcube -enable -size 70 -adaptsize
# -------------------------------------
# check positioning of view cube object
# -------------------------------------
if {[vreadpixel 96 285 name] != "GRAY68 1"} {
puts "ERROR: Bottom left View Cube fails."
}
vdump $anImage1
vviewcube -position 200 200
if {[vreadpixel 200 176 name] != "GRAY68 1"} {
puts "ERROR: Center View Cube fails."
}
vdump $anImage2
vviewcube -position 310 100
if {[vreadpixel 310 73 name] != "GRAY68 1"} {
puts "ERROR: Top right View Cube fails."
}
vdump $anImage3
vviewcube -position 140 240
if {[vreadpixel 140 217 name] != "GRAY68 1"} {
puts "ERROR: Custom View Cube fails."
}
vdump $anImage4
vviewcube -remove
vclear

33
tests/v3d/viewcube/part Normal file
View File

@ -0,0 +1,33 @@
puts "====================================="
puts "AIS_ViewCube - test custom appearance"
puts "====================================="
set anImage1 $imagedir/${casename}_1.png
set anImage2 $imagedir/${casename}_2.png
set anImage3 $imagedir/${casename}_3.png
vclear
vclose ALL
vinit
vviewcube -enable -hideedges
if {[vreadpixel 186 236 name] != "BLACK 1"} {
puts "ERROR: Invalid display of View Cube without edges."
}
vdump $anImage1
vviewcube -showedges -hidevertices
if {[vreadpixel 150 258 name] != "BLACK 0"} {
puts "ERROR: Invalid display of View Cube without vertices."
}
vdump $anImage2
vviewcube -hideedges -hidevertices
if {[vreadpixel 186 236 name] != "BLACK 1" || [vreadpixel 150 258 name] != "BLACK 0"} {
puts "ERROR: Invalid display of View Cube without edges & vertices."
}
vdump $anImage3
vviewcube -remove
vclear

84
tests/v3d/viewcube/style Normal file
View File

@ -0,0 +1,84 @@
puts "=================================="
puts "AIS_ViewCube - display custom styled View Cube"
puts "=================================="
set anImage1 $imagedir/${casename}_1.png
set anImage2 $imagedir/${casename}_2.png
set anImage3 $imagedir/${casename}_3.png
set anImage4 $imagedir/${casename}_4.png
set anImage5 $imagedir/${casename}_5.png
set anImage6 $imagedir/${casename}_6.png
set anImage7 $imagedir/${casename}_7.png
vclear
vclose ALL
vinit
# -------------------------------------
# Color
# -------------------------------------
vviewcube -enable -boxcolor 0.69 0.88 1 -arrowcolor 0 0.4 0.54 -textcolor 0 0.4 0.54
if {[vreadpixel 118 273 name] != "LIGHTSLATEGRAY 1" || [vreadpixel 270 260 name] != "GRAY15 0.24705882352941178"} {
puts "ERROR: Errors in changing View Cube colors."
}
vdump $anImage1
# -------------------------------------
# Transparency
# -------------------------------------
vviewcube -reset
vviewcube -transparency 0.5
if {[vreadpixel 118 273 name] != "GRAY17 0.37254901960784315" || [vreadpixel 270 260 name] != "GRAY48 0.24705882352941178"} {
puts "ERROR: Errors in changing View Cube common transparency."
}
vdump $anImage2
vviewcube -reset
vviewcube -boxtransparency 0.4 -arrowtransparency 0.2
if {[vreadpixel 118 273 name] != "GRAY16 0.50588235294117645" || [vreadpixel 270 260 name] != "GRAY76 0.63921568627450975"} {
puts "ERROR: Errors in changing View Cube separate transparency."
}
vdump $anImage3
# -------------------------------------
# Arrows
# -------------------------------------
vviewcube -reset
vviewcube -arrowangle 30 -arrowlength 30
if {[vreadpixel 270 268 name] != "BLACK 0" || [vreadpixel 291 259 name] != "GRAY48 0.24705882352941178"} {
puts "ERROR: Errors in changing View Cube arrow style."
}
vdump $anImage4
# -------------------------------------
# Font
# -------------------------------------
vviewcube -reset
vviewcube -font "Impact" -fontheight 16
if {[vreadpixel 151 198 name] != "BLACK 1" || [vreadpixel 168 391 name] != "RED 1"} {
puts "ERROR: Errors in changing View Cube font."
}
vdump $anImage5
# -------------------------------------
# Padding
# -------------------------------------
vviewcube -reset
vviewcube -boxpadding 10 -axispadding 20 -arrowpadding 10
if {[vreadpixel 71 263 name] != "BLACK 0" || [vreadpixel 37 266 name] != "BLUE2 1"} {
puts "ERROR: Errors in changing View Cube padding."
}
vdump $anImage6
# -------------------------------------
# Corner radius
# -------------------------------------
vviewcube -reset
vviewcube -cornerradius 0.2
vdump $anImage7
vviewcube -remove
vclear