1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-04 18:06:22 +03:00

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
This commit is contained in:
san 2014-08-21 11:29:57 +04:00 committed by bugmaster
parent 0304f71151
commit 53b15292f1
12 changed files with 284 additions and 55 deletions

View File

@ -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 <b>Prs3d_VDM_Isolated</b> mode.
-- Switching to <b>Prs3d_VDM_Isolated</b> mode makes all shape's vertices visible.
-- To inherit this parameter from the global drawer instance ("the link") when it is present,
-- <b>Prs3d_VDM_Inherited</b> 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 <b>Prs3d_VDM_Inherited</b>.
-- 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

View File

@ -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();}

View File

@ -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();

View File

@ -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.

View File

@ -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 <b>Prs3d_VDM_Standalone</b> mode.
-- Switching to <b>Prs3d_VDM_Standalone</b> mode makes all shape's vertices visible.
-- To inherit this parameter from the global drawer instance ("the link") when it is present,
-- <b>Prs3d_VDM_Inherited</b> 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;

View File

@ -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;}

View File

@ -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);

View File

@ -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 <Prs3d_ShapeTool.ixx>
#include <BRepTools.hxx>
@ -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);
TopExp::MapShapesAndAncestors (theShape,TopAbs_EDGE,TopAbs_FACE, myEdgeMap);
#ifndef OCC215
// find vertices not under ancestors.
TopAbs_ShapeEnum E = TheShape.ShapeType();
// 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());
}
}
else
{
// Extracting isolated vertices
for (anExpl.Init (theShape, TopAbs_VERTEX, TopAbs_EDGE); anExpl.More(); anExpl.Next())
{
myVertexMap.Add (anExpl.Current());
}
// 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);
}
}
}
#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();
}
/*
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();
}
*/
//xt
edges.Next();
}
#endif
}
//=======================================================================

View File

@ -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())
{

View File

@ -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());

View File

@ -133,6 +133,7 @@
#include <BRepExtrema_ExtPC.hxx>
#include <BRepExtrema_ExtPF.hxx>
#include <Prs3d_VertexDrawMode.hxx>
#include <Prs3d_LineAspect.hxx>
#include <Prs3d_PointAspect.hxx>
@ -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);
}

54
tests/bugs/vis/bug25099 Normal file
View File

@ -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