From 53b15292f1ae7d116d4d27987634ef603757d8e9 Mon Sep 17 00:00:00 2001 From: san Date: Thu, 21 Aug 2014 11:29:57 +0400 Subject: [PATCH] 0025099: Visualization - Option to show vertices of a shape Option to display all vertices of a shape by AIS_Shape implemented in addition to the old behavior (when only isolated vertices were drawn). Eliminate new compiler warning --- src/AIS/AIS_Drawer.cdl | 23 +++- src/AIS/AIS_Drawer.cxx | 13 +++ src/AIS/AIS_Drawer.lxx | 5 + src/Prs3d/Prs3d.cdl | 6 ++ src/Prs3d/Prs3d_Drawer.cdl | 19 +++- src/Prs3d/Prs3d_Drawer.cxx | 13 +++ src/Prs3d/Prs3d_ShapeTool.cdl | 8 +- src/Prs3d/Prs3d_ShapeTool.cxx | 73 +++++-------- src/Prs3d/Prs3d_WFShape.cxx | 2 +- src/StdPrs/StdPrs_ShadedShape.cxx | 14 ++- src/ViewerTest/ViewerTest_ObjectCommands.cxx | 105 +++++++++++++++++++ tests/bugs/vis/bug25099 | 54 ++++++++++ 12 files changed, 282 insertions(+), 53 deletions(-) create mode 100644 tests/bugs/vis/bug25099 diff --git a/src/AIS/AIS_Drawer.cdl b/src/AIS/AIS_Drawer.cdl index e04b215297..bda1a86e5f 100644 --- a/src/AIS/AIS_Drawer.cdl +++ b/src/AIS/AIS_Drawer.cdl @@ -59,6 +59,7 @@ uses PlaneAngle from Quantity, Length from Quantity, DimensionUnits from Prs3d, + VertexDrawMode from Prs3d, AsciiString from TCollection, TypeOfHLR from Prs3d, Ax2 from gp @@ -424,9 +425,27 @@ is HasPointAspect (me) returns Boolean from Standard ---Purpose: Returns true if the Drawer has a point aspect setting active. is static; - ---C++: inline - + ---C++: inline + + SetVertexDrawMode(me: mutable; theMode: VertexDrawMode from Prs3d) + ---Purpose: Sets the mode of visualization of vertices by AIS_Shape and helper algorithms. + -- By default, only isolated vertices not belonging to any face are drawn, + -- that corresponds to Prs3d_VDM_Isolated mode. + -- Switching to Prs3d_VDM_Isolated mode makes all shape's vertices visible. + -- To inherit this parameter from the global drawer instance ("the link") when it is present, + -- Prs3d_VDM_Inherited value should be used. + is redefined static; + + VertexDrawMode(me) returns VertexDrawMode from Prs3d + ---Purpose: Returns the current mode of visualization of vertices of a TopoDS_Shape instance. + is redefined static; + IsOwnVertexDrawMode(me) returns Boolean from Standard; + ---Purpose: Returns true if the vertex draw mode is not equal to Prs3d_VDM_Inherited. + -- This means that individual vertex draw mode value (i.e. not inherited from the global + -- drawer) is used for a specific interactive object. + ---C++: inline + -- Attributes for the faces: -- ShadingAspect (me:mutable) returns ShadingAspect from Prs3d diff --git a/src/AIS/AIS_Drawer.cxx b/src/AIS/AIS_Drawer.cxx index df2ea40096..bf263cfb40 100644 --- a/src/AIS/AIS_Drawer.cxx +++ b/src/AIS/AIS_Drawer.cxx @@ -32,6 +32,7 @@ AIS_Drawer::AIS_Drawer() SetMaximalParameterValue (500000.0); myLink->SetMaximalParameterValue (500000.0); SetTypeOfHLR (Prs3d_TOH_NotSet); + SetVertexDrawMode (Prs3d_VDM_Inherited); } Aspect_TypeOfDeflection AIS_Drawer::TypeOfDeflection () const @@ -197,6 +198,18 @@ Handle (Prs3d_ArrowAspect) AIS_Drawer::ArrowAspect() Handle (Prs3d_PointAspect) AIS_Drawer::PointAspect() {return myPointAspect.IsNull()? myLink->PointAspect () : myPointAspect;} +void AIS_Drawer::SetVertexDrawMode (const Prs3d_VertexDrawMode theMode) +{ + // Assuming that myLink always exists --> Prs3d_VDM_Inherited value is acceptable. + // So we simply store the new mode, as opposed to Prs3d_Drawer::SetVertexDrawMode() + myVertexDrawMode = theMode; +} + +Prs3d_VertexDrawMode AIS_Drawer::VertexDrawMode () const +{ + return IsOwnVertexDrawMode() ? myVertexDrawMode : myLink->VertexDrawMode(); +} + Standard_Boolean AIS_Drawer::DrawHiddenLine () const {return myLink->DrawHiddenLine();} diff --git a/src/AIS/AIS_Drawer.lxx b/src/AIS/AIS_Drawer.lxx index aab6b9bd23..84643f6ae6 100644 --- a/src/AIS/AIS_Drawer.lxx +++ b/src/AIS/AIS_Drawer.lxx @@ -119,6 +119,11 @@ inline Standard_Boolean AIS_Drawer::HasPointAspect() const return !myPointAspect.IsNull(); } +inline Standard_Boolean AIS_Drawer::IsOwnVertexDrawMode() const +{ + return (myVertexDrawMode != Prs3d_VDM_Inherited); +} + inline Standard_Boolean AIS_Drawer::HasDatumAspect() const { return !myDatumAspect.IsNull(); diff --git a/src/Prs3d/Prs3d.cdl b/src/Prs3d/Prs3d.cdl index 41bfa79da8..6a33d3ec4f 100644 --- a/src/Prs3d/Prs3d.cdl +++ b/src/Prs3d/Prs3d.cdl @@ -92,6 +92,12 @@ is -- DAO_Fit - arrows oriented inside if value label with arrowtips fit the dimension line, -- otherwise - externally + enumeration VertexDrawMode is VDM_Isolated, VDM_All, VDM_Inherited; + ---Purpose: Describes supported modes of visualization of the shape's vertices: + -- VDM_Isolated - only isolated vertices (not belonging to a face) are displayed. + -- VDM_All - all vertices of the shape are displayed. + -- VDM_Inherited - the global settings are inherited and applied to the shape's presentation. + class Presentation; ---Category: Aspect classes. diff --git a/src/Prs3d/Prs3d_Drawer.cdl b/src/Prs3d/Prs3d_Drawer.cdl index d84ee1f499..1bdfaab7df 100644 --- a/src/Prs3d/Prs3d_Drawer.cdl +++ b/src/Prs3d/Prs3d_Drawer.cdl @@ -44,6 +44,7 @@ uses Length from Quantity, TypeOfHLR from Prs3d, DimensionUnits from Prs3d, + VertexDrawMode from Prs3d, AsciiString from TCollection, Ax2 from gp @@ -340,8 +341,8 @@ is is virtual; LineArrowDraw(me) returns Boolean from Standard - ---Purpose: Sets LineArrowDraw on or off by setting the - -- parameter OnOff to true or false. + ---Purpose: Returns True if drawing an arrow at the end of each edge is enabled + -- and False otherwise (the default). is virtual; ArrowAspect(me:mutable) returns ArrowAspect from Prs3d @@ -363,6 +364,19 @@ is SetPointAspect(me:mutable; anAspect: PointAspect from Prs3d) is virtual; --- Purpose: Sets the parameter anAspect for display attributes of points + + SetVertexDrawMode(me: mutable; theMode: VertexDrawMode from Prs3d) + ---Purpose: Sets the mode of visualization of vertices of a TopoDS_Shape instance. + -- By default, only stand-alone vertices (not belonging topologically to an edge) are drawn, + -- that corresponds to Prs3d_VDM_Standalone mode. + -- Switching to Prs3d_VDM_Standalone mode makes all shape's vertices visible. + -- To inherit this parameter from the global drawer instance ("the link") when it is present, + -- Prs3d_VDM_Inherited value should be used. + is virtual; + + VertexDrawMode(me) returns VertexDrawMode from Prs3d + ---Purpose: Returns the current mode of visualization of vertices of a TopoDS_Shape instance. + is virtual; ShadingAspect (me:mutable) returns ShadingAspect from Prs3d is virtual; @@ -564,6 +578,7 @@ fields myHLRAngle: Real from Standard is protected; myPointAspect: PointAspect from Prs3d is protected; + myVertexDrawMode: VertexDrawMode from Prs3d is protected; myPlaneAspect: PlaneAspect from Prs3d is protected; myArrowAspect: ArrowAspect from Prs3d is protected; myLineDrawArrow: Boolean from Standard is protected; diff --git a/src/Prs3d/Prs3d_Drawer.cxx b/src/Prs3d/Prs3d_Drawer.cxx index 1a08a2bc4f..f4c63f9dbc 100644 --- a/src/Prs3d/Prs3d_Drawer.cxx +++ b/src/Prs3d/Prs3d_Drawer.cxx @@ -33,6 +33,7 @@ Prs3d_Drawer::Prs3d_Drawer() myHLRDeviationCoefficient (0.02), myDeviationAngle (12.0 * M_PI / 180.0), myHLRAngle (20.0 * M_PI / 180.0), + myVertexDrawMode (Prs3d_VDM_Isolated), myLineDrawArrow (Standard_False), myDrawHiddenLine (Standard_False), myFaceBoundaryDraw (Standard_False), @@ -335,6 +336,18 @@ void Prs3d_Drawer::SetPointAspect ( const Handle(Prs3d_PointAspect)& anAspect) { myPointAspect = anAspect; } +void Prs3d_Drawer::SetVertexDrawMode (const Prs3d_VertexDrawMode theMode) +{ + // Prs3d_VDM_Inherited value is allowed at AIS_Drawer level. + // Replacing it by Prs3d_VDM_Isolated to avoid unpredictable behavior. + myVertexDrawMode = (theMode == Prs3d_VDM_Inherited ? Prs3d_VDM_Isolated : theMode); +} + +Prs3d_VertexDrawMode Prs3d_Drawer::VertexDrawMode () const +{ + return myVertexDrawMode; +} + Standard_Boolean Prs3d_Drawer::DrawHiddenLine () const {return myDrawHiddenLine;} void Prs3d_Drawer::EnableDrawHiddenLine () {myDrawHiddenLine=Standard_True;} diff --git a/src/Prs3d/Prs3d_ShapeTool.cdl b/src/Prs3d/Prs3d_ShapeTool.cdl index b6f4e78303..91faa3c69e 100644 --- a/src/Prs3d/Prs3d_ShapeTool.cdl +++ b/src/Prs3d/Prs3d_ShapeTool.cdl @@ -36,7 +36,13 @@ uses is - Create ( TheShape: Shape from TopoDS) returns ShapeTool from Prs3d; + Create ( theShape : Shape from TopoDS; + theAllVertices: Boolean from Standard = Standard_False) + ---Purpose: Constructs the tool and initializes it using theShape and theAllVertices + -- (optional) arguments. By default, only isolated and internal vertices are considered, + -- however if theAllVertices argument is equal to True, all shape's vertices are taken into account. + returns ShapeTool from Prs3d; + InitFace (me: in out); MoreFace (me) returns Boolean from Standard; NextFace (me: in out); diff --git a/src/Prs3d/Prs3d_ShapeTool.cxx b/src/Prs3d/Prs3d_ShapeTool.cxx index 01ec325600..cb67429d5b 100644 --- a/src/Prs3d/Prs3d_ShapeTool.cxx +++ b/src/Prs3d/Prs3d_ShapeTool.cxx @@ -14,9 +14,6 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#define OCC215 //SAV: 01/04/02 vertex exploring is done for all types of shape. -#define OCC598 //SAV: 22/10/02 searching for internal vertices. - #include #include @@ -41,56 +38,44 @@ //purpose : //======================================================================= -Prs3d_ShapeTool::Prs3d_ShapeTool(const TopoDS_Shape& TheShape): - myShape (TheShape) +Prs3d_ShapeTool::Prs3d_ShapeTool (const TopoDS_Shape& theShape, + const Standard_Boolean theAllVertices) +: myShape (theShape) { myEdgeMap.Clear(); myVertexMap.Clear(); - TopExp::MapShapesAndAncestors(TheShape,TopAbs_EDGE,TopAbs_FACE,myEdgeMap); - -#ifndef OCC215 - // find vertices not under ancestors. - TopAbs_ShapeEnum E = TheShape.ShapeType(); - + TopExp::MapShapesAndAncestors (theShape,TopAbs_EDGE,TopAbs_FACE, myEdgeMap); - // this check were done to reduce the number of selectable objects - // in a local context. By now, there's no noticeable performance improvement. - if (E != TopAbs_SOLID && E != TopAbs_SHELL) -#endif + TopExp_Explorer anExpl; + if (theAllVertices) + { + for (anExpl.Init (theShape, TopAbs_VERTEX); anExpl.More(); anExpl.Next()) { - TopExp_Explorer ex(TheShape,TopAbs_VERTEX, TopAbs_EDGE); - while (ex.More()) { - const TopoDS_Shape& aV=ex.Current(); - myVertexMap.Add(aV); - ex.Next(); - } + myVertexMap.Add (anExpl.Current()); } -#ifdef OCC598 - TopExp_Explorer edges( TheShape, TopAbs_EDGE ); - while( edges.More() ) { - //xf - const TopoDS_Shape& aE= edges.Current(); - TopoDS_Iterator aIt(aE, Standard_False, Standard_True); - while( aIt.More() ) { - const TopoDS_Shape& aV=aIt.Value(); - if (aV.Orientation()==TopAbs_INTERNAL) { - myVertexMap.Add(aV); - } - aIt.Next(); + } + else + { + // Extracting isolated vertices + for (anExpl.Init (theShape, TopAbs_VERTEX, TopAbs_EDGE); anExpl.More(); anExpl.Next()) + { + myVertexMap.Add (anExpl.Current()); } - /* - TopExp_Explorer vertices( edges.Current(), TopAbs_VERTEX ); - while( vertices.More() ) { - TopoDS_Vertex current = TopoDS::Vertex( vertices.Current() ); - if ( current.Orientation() == TopAbs_INTERNAL ) - myVertexMap.Add( current ); - vertices.Next(); + + // Extracting internal vertices + for (anExpl.Init (theShape, TopAbs_EDGE); anExpl.More(); anExpl.Next()) + { + TopoDS_Iterator aIt (anExpl.Current(), Standard_False, Standard_True); + for (; aIt.More(); aIt.Next()) + { + const TopoDS_Shape& aV = aIt.Value(); + if (aV.Orientation() == TopAbs_INTERNAL) + { + myVertexMap.Add (aV); + } + } } - */ - //xt - edges.Next(); } -#endif } //======================================================================= diff --git a/src/Prs3d/Prs3d_WFShape.cxx b/src/Prs3d/Prs3d_WFShape.cxx index 990ab47edc..4ab7990e52 100755 --- a/src/Prs3d/Prs3d_WFShape.cxx +++ b/src/Prs3d/Prs3d_WFShape.cxx @@ -142,7 +142,7 @@ void Prs3d_WFShape::Add (const Handle (Prs3d_Presentation)& thePresentation, return; } - Prs3d_ShapeTool aTool (theShape); + Prs3d_ShapeTool aTool (theShape, theDrawer->VertexDrawMode() == Prs3d_VDM_All); TopTools_ListOfShape aLFree, aLUnFree, aLWire; for (aTool.InitCurve(); aTool.MoreCurve(); aTool.NextCurve()) { diff --git a/src/StdPrs/StdPrs_ShadedShape.cxx b/src/StdPrs/StdPrs_ShadedShape.cxx index 084b1ad107..b2e1decd96 100644 --- a/src/StdPrs/StdPrs_ShadedShape.cxx +++ b/src/StdPrs/StdPrs_ShadedShape.cxx @@ -61,7 +61,9 @@ namespace const TopoDS_Shape& theShape, const Handle (Prs3d_Drawer)& theDrawer) { - if (theShape.ShapeType() != TopAbs_COMPOUND) + Standard_Boolean aDrawAllVerticesFlag = (theDrawer->VertexDrawMode() == Prs3d_VDM_All); + + if (!aDrawAllVerticesFlag && theShape.ShapeType() != TopAbs_COMPOUND) { return; } @@ -74,6 +76,11 @@ namespace return; } + // We have to create a compound and collect all subshapes not drawn by the shading algo. + // This includes: + // - isolated edges + // - isolated vertices, if aDrawAllVerticesFlag == Standard_False + // - all shape's vertices, if aDrawAllVerticesFlag == Standard_True TopoDS_Compound aCompoundWF; BRep_Builder aBuilder; aBuilder.MakeCompound (aCompoundWF); @@ -85,8 +92,9 @@ namespace hasElement = Standard_True; aBuilder.Add (aCompoundWF, aShapeIter.Current()); } - // isolated vertices - for (aShapeIter.Init (theShape, TopAbs_VERTEX, TopAbs_EDGE); aShapeIter.More(); aShapeIter.Next()) + // isolated or all vertices + aShapeIter.Init (theShape, TopAbs_VERTEX, aDrawAllVerticesFlag ? TopAbs_SHAPE : TopAbs_EDGE); + for (; aShapeIter.More(); aShapeIter.Next()) { hasElement = Standard_True; aBuilder.Add (aCompoundWF, aShapeIter.Current()); diff --git a/src/ViewerTest/ViewerTest_ObjectCommands.cxx b/src/ViewerTest/ViewerTest_ObjectCommands.cxx index 30368bb693..8e05ff422d 100644 --- a/src/ViewerTest/ViewerTest_ObjectCommands.cxx +++ b/src/ViewerTest/ViewerTest_ObjectCommands.cxx @@ -133,6 +133,7 @@ #include #include +#include #include #include @@ -5209,6 +5210,102 @@ static int VUnsetEdgeType (Draw_Interpretor& theDI, return 0; } + +//======================================================================= +//function : VVertexMode +//purpose : Switches vertex display mode for AIS_Shape or displays the current value +//======================================================================= + +static int VVertexMode (Draw_Interpretor& theDI, + Standard_Integer theArgNum, + const char** theArgs) +{ + Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); + if (aContext.IsNull()) + { + std::cout << "Error: no view available, call 'vinit' before!" << std::endl; + return 1; + } + + // No arguments --> print the current default vertex draw mode + if (theArgNum == 1) + { + Prs3d_VertexDrawMode aCurrMode = aContext->DefaultDrawer()->VertexDrawMode(); + theDI << "Default vertex draw mode: " << (aCurrMode == Prs3d_VDM_Isolated ? "'isolated'" : "'all'") << "\n"; + return 0; + } + + // -set argument --> change the default vertex draw mode and the mode for all displayed or given object(s) + TCollection_AsciiString aParam (theArgs[1]); + if (aParam == "-set") + { + if (theArgNum == 2) + { + std::cout << "Error: '-set' option not followed by the mode and optional object name(s)" << std::endl; + std::cout << "Type 'help vvertexmode' for usage hints" << std::endl; + return 1; + } + + TCollection_AsciiString aModeStr (theArgs[2]); + Prs3d_VertexDrawMode aNewMode = + aModeStr == "isolated" ? Prs3d_VDM_Isolated : + (aModeStr == "all" ? Prs3d_VDM_All : + Prs3d_VDM_Inherited); + + Standard_Boolean aRedrawNeeded = Standard_False; + AIS_ListOfInteractive anObjs; + + // No object(s) specified -> use all displayed + if (theArgNum == 3) + { + theDI << "Setting the default vertex draw mode and updating all displayed objects...\n"; + aContext->DisplayedObjects (anObjs); + aContext->DefaultDrawer()->SetVertexDrawMode (aNewMode); + aRedrawNeeded = Standard_True; + } + + Handle(AIS_InteractiveObject) anObject; + for (Standard_Integer aCount = 3; aCount < theArgNum; aCount++) + { + TCollection_AsciiString aName (theArgs[aCount]); + if (!GetMapOfAIS().IsBound2 (aName)) + { + theDI << "Warning: wrong object name ignored - " << theArgs[0] << "\n"; + continue; + } + anObject = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(aName)); + anObjs.Append (anObject); + } + + for (AIS_ListIteratorOfListOfInteractive anIt (anObjs); anIt.More(); anIt.Next()) + { + anObject = anIt.Value(); + anObject->Attributes()->SetVertexDrawMode (aNewMode); + aContext->Redisplay (anObject, Standard_False); + aRedrawNeeded = Standard_True; + } + + if (aRedrawNeeded) + ViewerTest::CurrentView()->Redraw(); + + return 0; + } + + if (theArgNum > 2) + { + std::cout << "Error: invalid number of arguments" << std::endl; + std::cout << "Type 'help vvertexmode' for usage hints" << std::endl; + return 1; + } + + // One argument (object name) --> print the current vertex draw mode for the object + Handle(AIS_InteractiveObject) anObject = + Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aParam)); + Prs3d_VertexDrawMode aCurrMode = anObject->Attributes()->VertexDrawMode(); + theDI << "Object's vertex draw mode: " << (aCurrMode == Prs3d_VDM_Isolated ? "'isolated'" : "'all'") << "\n"; + return 0; +} + //======================================================================= //function : ObjectsCommands //purpose : @@ -5378,4 +5475,12 @@ void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands) "vunsetedgetype ShapeName [-force]" "\n\t\t: Unsets edges type and color for input shape", __FILE__, VUnsetEdgeType, group); + + theCommands.Add ("vvertexmode", + "vvertexmode [name | -set {isolated | all | inherited} [name1 name2 ...]]\n" + "vvertexmode - prints the default vertex draw mode\n" + "vvertexmode name - prints the vertex draw mode of the given object\n" + "vvertexmode -set {isolated | all | inherited} - sets the default vertex draw mode and updates the mode for all displayed objects\n" + "vvertexmode -set {isolated | all | inherited} name1 name2 ... - sets the vertex draw mode for the specified object(s)\n", + __FILE__, VVertexMode, group); } diff --git a/tests/bugs/vis/bug25099 b/tests/bugs/vis/bug25099 new file mode 100644 index 0000000000..99e2232e3e --- /dev/null +++ b/tests/bugs/vis/bug25099 @@ -0,0 +1,54 @@ +puts "============" +puts "CR25099" +puts "============" +puts "" +####################################################################### +# Test vertex draw modes +####################################################################### + +vinit View1 + +# Checking that the default behavior is not impacted by the vertex draw mode +vertex v1 0 -1 0 +vertex v2 0 -1 5 +vertex v3 -1 -1 0 +vertex v4 -1 -1 5 +edge e v3 v4 +box b1 1 2 3 +box b2 3 4 2 +compound v1 v2 v3 v4 e b1 c +vdisplay c; vfit +vvertexmode +vdump $imagedir/${casename}_default_wf_isolated.png + +vsetdispmode c 1 +vdump $imagedir/${casename}_default_shading_isolated.png + +# Changing default vertex draw mode to 'all vertices' +vclear +vvertexmode -set all +vdisplay c +vvertexmode +vdump $imagedir/${casename}_default_wf_all1.png + +# Newly displayed objects should inherit the default vertex draw mode +vdisplay b2; vfit +vvertexmode b2 +vdump $imagedir/${casename}_default_wf_all2.png + +# Checking the new mode in shading +vsetdispmode 1 +vdump $imagedir/${casename}_default_shading_all.png + +# Set individual vertex draw mode for an objects +vvertexmode -set isolated b2 +vvertexmode b2 +vdump $imagedir/${casename}_individual.png + +# Reset individual vertex draw mode using 'inherited' value +vvertexmode -set inherited b2 +# The next line should report 'all' (inherited from the default drawer) +vvertexmode b2 +vdump $imagedir/${casename}_inherited.png + + -- 2.20.1