diff --git a/src/ViewerTest/ViewerTest_ObjectCommands.cxx b/src/ViewerTest/ViewerTest_ObjectCommands.cxx index 2dab66760d..37a9fb588f 100755 --- a/src/ViewerTest/ViewerTest_ObjectCommands.cxx +++ b/src/ViewerTest/ViewerTest_ObjectCommands.cxx @@ -3757,156 +3757,115 @@ static Standard_Integer VConnectShape(Draw_Interpretor& /*di*/, return 0; } +namespace +{ + //! Checks if theMode is already turned on for theObj. + static Standard_Boolean InList (const Handle(AIS_InteractiveContext)& theAISContext, + const Handle(AIS_InteractiveObject)& theObj, + const Standard_Integer theMode) + { + TColStd_ListOfInteger anActiveModes; + theAISContext->ActivatedModes (theObj, anActiveModes); + for (TColStd_ListIteratorOfListOfInteger aModeIt (anActiveModes); aModeIt.More(); aModeIt.Next()) + { + if (aModeIt.Value() == theMode) + { + return Standard_True; + } + } + return Standard_False; + } +}; + //=============================================================================================== //function : VSetSelectionMode //purpose : Sets input selection mode for input object or for all displayed objects //Draw arg : vselmode [object] mode On/Off (1/0) //=============================================================================================== - -// function : InList -// purpose : checks if theMode is already turned on for theObj -Standard_Boolean InList(Handle(AIS_InteractiveContext) theAISContext, - Handle(AIS_InteractiveObject) theObj, - Standard_Integer theMode) -{ - TColStd_ListOfInteger anArray; - theAISContext->ActivatedModes(theObj, anArray); - TColStd_ListIteratorOfListOfInteger anIt(anArray); - for(; anIt.More(); anIt.Next()) - { - if(anIt.Value() == theMode) - return Standard_True; - } - return Standard_False; -} - -static Standard_Integer VSetSelectionMode(Draw_Interpretor& /*di*/, - Standard_Integer argc, - const char ** argv) +static Standard_Integer VSetSelectionMode (Draw_Interpretor& /*di*/, + Standard_Integer theArgc, + const char** theArgv) { // Check errors Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext(); - if(anAISContext.IsNull()) + if (anAISContext.IsNull()) { - std::cout << "Call vinit before!\n"; - return 1; // TCL_ERROR + std::cerr << "Call vinit before!\n"; + return 1; } - // Check the arguments - if(argc != 3 && argc != 4) + // Check the arguments + if (theArgc != 3 && theArgc != 4) { - std::cout << "vselmode error : expects at least 2 arguments.\n" - << "Type help "<< argv[0] <<" for more information."; - return 1; // TCL_ERROR + std::cerr << "vselmode error : expects at least 2 arguments.\n" + << "Type help "<< theArgv[0] <<" for more information."; + return 1; } - Handle(AIS_InteractiveObject) anObj; - - // Set new selection mode for all objects in context - if(argc == 3) + // get objects to change selection mode + AIS_ListOfInteractive aTargetIOs; + if (theArgc == 3) { - // Get arguments - Standard_Integer aMode = Draw::Atoi(argv[1]); - Standard_Boolean isTurnOn = Draw::Atoi(argv[2]); - - // Get all displayed objects - AIS_ListOfInteractive anObjList; - anAISContext->DisplayedObjects(anObjList); - AIS_ListIteratorOfListOfInteractive anObjIter; - - if(aMode == 0) - { - if(anAISContext->HasOpenedContext()) - anAISContext->CloseLocalContext(); - } - - // Turn on aMode - if(aMode != 0 && isTurnOn) - { - if(!anAISContext->HasOpenedContext()) - { - anAISContext->OpenLocalContext(); - for(anObjIter.Initialize(anObjList); anObjIter.More(); anObjIter.Next()) - { - anAISContext->Activate(anObjIter.Value(), aMode); - } - } - else - { - for(anObjIter.Initialize(anObjList); anObjIter.More(); anObjIter.Next()) - { - anObj = anObjIter.Value(); - if(!InList(anAISContext, anObj, aMode)) - anAISContext->Activate(anObj, aMode); - } - } - } - - // Turn off aMode - if(aMode != 0 && !isTurnOn) - { - if(anAISContext->HasOpenedContext()) - { - for(anObjIter.Initialize(anObjList); anObjIter.More(); anObjIter.Next()) - { - anObj = anObjIter.Value(); - if(InList(anAISContext, anObj, aMode)) - anAISContext->Deactivate(anObj, aMode); - } - } - } + anAISContext->DisplayedObjects (aTargetIOs); } - - // Set new selection mode for named object else { - // Get argumnets - Standard_Integer aMode = Draw::Atoi(argv[2]); - Standard_Boolean isTurnOn = Draw::Atoi(argv[3]); - TCollection_AsciiString aName(argv[1]); - // Check if there is an object with given name in context - if(GetMapOfAIS().IsBound2(aName)) + const TCollection_AsciiString aNameIO (theArgv[1]); + if (GetMapOfAIS().IsBound2 (aNameIO)) { - anObj = Handle(AIS_InteractiveObject):: - DownCast(GetMapOfAIS().Find2(aName)); - if(anObj.IsNull()) + Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aNameIO)); + if (anIO.IsNull()) { - std::cout << "vselmode error : object name is used for non AIS viewer\n"; - return 1; // TCL_ERROR + std::cerr << "vselmode error : object name is used for non AIS viewer\n"; + return 1; } + aTargetIOs.Append (anIO); + } + } + + const Standard_Integer aSelectionMode = Draw::Atoi (theArgc == 3 ? theArgv[1] : theArgv[2]); + const Standard_Boolean toTurnOn = Draw::Atoi (theArgc == 3 ? theArgv[2] : theArgv[3]); + if (aSelectionMode == 0 && anAISContext->HasOpenedContext()) + { + anAISContext->CloseLocalContext(); + } + + if (aSelectionMode != 0 && toTurnOn) // Turn on specified mode + { + if (!anAISContext->HasOpenedContext()) + { + anAISContext->OpenLocalContext (Standard_False); } - if(aMode == 0) + for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next()) { - if(anAISContext->HasOpenedContext()) - anAISContext->CloseLocalContext(); - } - // Turn on aMode - if(aMode != 0 && isTurnOn) - { - if(!anAISContext->HasOpenedContext()) + const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value(); + if (!InList (anAISContext, anIO, aSelectionMode)) { - anAISContext->OpenLocalContext(); - anAISContext->Activate(anObj, aMode); - } - else - { - if(!InList(anAISContext, anObj, aMode)) - anAISContext->Activate(anObj, aMode); - } - } - - // Turn off aMode - if(aMode != 0 && !isTurnOn) - { - if(anAISContext->HasOpenedContext()) - { - if(InList(anAISContext, anObj, aMode)) - anAISContext->Deactivate(anObj, aMode); + anAISContext->Load (anIO, -1, Standard_True); + anAISContext->Activate (anIO, aSelectionMode); } } } + + if (aSelectionMode != 0 && !toTurnOn) // Turn off specified mode + { + if (!anAISContext->HasOpenedContext()) + { + return 0; + } + + for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next()) + { + const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value(); + if (InList (anAISContext, anIO, aSelectionMode)) + { + anAISContext->Deactivate (anIO, aSelectionMode); + } + } + } + return 0; } diff --git a/tests/bugs/vis/bug24293 b/tests/bugs/vis/bug24293 index 98049f1524..5673646259 100644 --- a/tests/bugs/vis/bug24293 +++ b/tests/bugs/vis/bug24293 @@ -5,9 +5,7 @@ puts "" ####################################################################### # Dimension flyout lines don't belong to the dimension sensitive entity. ####################################################################### -pload VISUALIZATION - -vinit +vinit View1 vpoint lengthP1 0 0 0 vpoint lengthP2 10 10 10 vdimension length name=dim1 plane=xoy lengthP1 lengthP2 diff --git a/tests/bugs/vis/bug24374 b/tests/bugs/vis/bug24374 index f5d8696675..a963a658ac 100644 --- a/tests/bugs/vis/bug24374 +++ b/tests/bugs/vis/bug24374 @@ -5,8 +5,6 @@ puts "" ####################################################################### # Flipping affects highlight presentation of dimension ####################################################################### -pload ALL -pload QAcommands box b 100 100 100 explode b e vdisplay b @@ -14,11 +12,12 @@ vdisplay b_9 vdimension length name=dim1 b_9 text=3d plane=zox vdisplay dim1 vselmode b 2 1 +vselmode dim1 2 1 vfit -vmoveto 110 352 +vmoveto 140 370 -set x_coord 161 -set y_coord 372 +set x_coord 140 +set y_coord 370 checkcolor $x_coord $y_coord 0 1 1 if { $stat != 1 } { diff --git a/tests/bugs/vis/bug24396 b/tests/bugs/vis/bug24396 new file mode 100644 index 0000000000..5dd2cfa43f --- /dev/null +++ b/tests/bugs/vis/bug24396 @@ -0,0 +1,71 @@ +puts "============" +puts "CR24396" +puts "============" +puts "" +####################################################################### +# "vselmode" - disable auto loading of objects into Local Context +####################################################################### + +set trihedron_axis_pick_x 29 +set trihedron_axis_pick_y 56 + +set trihedron_axis_check_x 29 +set trihedron_axis_check_y 79 + +set trihedron_point_pick_x 29 +set trihedron_point_pick_y 305 + +set trihedron_point_check_x 24 +set trihedron_point_check_y 305 + +vinit View1 +vclear +vaxo +vtrihedron tri +box b 10 10 10 +vdisplay b +vselmode b 1 1 +vfit + +# --------------------------------------------------- # +# check that there is no selection of trihedron axis # +# --------------------------------------------------- # + +vmoveto $trihedron_axis_pick_x $trihedron_axis_pick_y + +checkcolor $trihedron_axis_pick_x $trihedron_axis_pick_y 0 0 0 + +if { $stat != 1 } { + puts "Error : The trihedron should not be highlighted." +} + +vselmode b 0 0 +vselmode 0 0 +verase b +vselmode 1 1 + +# ----------------------------------------------- # +# check that selection of trihedron point is ok # +# ----------------------------------------------- # + +vmoveto $trihedron_point_pick_x $trihedron_point_pick_y + +checkcolor $trihedron_point_check_x $trihedron_point_check_y 0 1 1 + +if { $stat != 1 } { + puts "Error : The trihedron point highlight is incorrect." +} + +# --------------------------------------------------------- # +# check that there is still no selection of trihedron axis # +# --------------------------------------------------------- # + +vmoveto $trihedron_axis_pick_x $trihedron_axis_pick_y + +checkcolor $trihedron_axis_pick_x $trihedron_axis_pick_y 0 0 0 + +if { $stat != 1 } { + puts "Error : The trihedron should not be highlighted." +} + +set only_screen 1