From: san Date: Wed, 18 Apr 2012 17:15:49 +0000 (+0400) Subject: 0023115: Polygon offset doesn't applied in Viewer3D sample X-Git-Tag: V6_5_3~4 X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=3ddebf91230733ea43316170b2bafe232ad709fd;p=occt-copy.git 0023115: Polygon offset doesn't applied in Viewer3D sample - AIS_InteractiveObject::SetPolygonOffsets() patched to update all object's groups that has AspectFillArea3d set. - vpolygonoffset DRAW command added. --- diff --git a/src/AIS/AIS_InteractiveObject.cxx b/src/AIS/AIS_InteractiveObject.cxx index b36791e324..3e1724e78d 100755 --- a/src/AIS/AIS_InteractiveObject.cxx +++ b/src/AIS/AIS_InteractiveObject.cxx @@ -57,6 +57,9 @@ #include #include #include +#include +#include +#include #include #include @@ -762,8 +765,26 @@ void AIS_InteractiveObject::SetPolygonOffsets(const Standard_Integer aMode, Handle(PrsMgr_Presentation3d)::DownCast( myPresentations(i).Presentation() ); if ( !aPrs3d.IsNull() ) { aStruct = Handle(Graphic3d_Structure)::DownCast( aPrs3d->Presentation() ); - if( !aStruct.IsNull() ) + if( !aStruct.IsNull() ) { aStruct->SetPrimitivesAspect( myDrawer->ShadingAspect()->Aspect() ); + // Workaround for issue 23115: Need to update also groups, because their + // face aspect ALWAYS overrides the structure's. + const Graphic3d_SequenceOfGroup& aGroups = aStruct->Groups(); + Standard_Integer aGroupIndex = 1, aGroupNb = aGroups.Length(); + for ( ; aGroupIndex <= aGroupNb; aGroupIndex++ ) { + Handle(Graphic3d_Group) aGrp = aGroups.Value(aGroupIndex); + if ( !aGrp.IsNull() && aGrp->IsGroupPrimitivesAspectSet(Graphic3d_ASPECT_FILL_AREA) ) { + Handle(Graphic3d_AspectFillArea3d) aFaceAsp = new Graphic3d_AspectFillArea3d(); + Handle(Graphic3d_AspectLine3d) aLineAsp = new Graphic3d_AspectLine3d(); + Handle(Graphic3d_AspectMarker3d) aPntAsp = new Graphic3d_AspectMarker3d(); + Handle(Graphic3d_AspectText3d) aTextAsp = new Graphic3d_AspectText3d(); + // TODO: Add methods for retrieving individual aspects from Graphic3d_Group + aGrp->GroupPrimitivesAspect(aLineAsp, aTextAsp, aPntAsp, aFaceAsp); + aFaceAsp->SetPolygonOffsets(aMode, aFactor, aUnits); + aGrp->SetGroupPrimitivesAspect(aFaceAsp); + } + } + } } } } diff --git a/src/ViewerTest/ViewerTest_ObjectCommands.cxx b/src/ViewerTest/ViewerTest_ObjectCommands.cxx index 37334eb04b..f496abcea3 100755 --- a/src/ViewerTest/ViewerTest_ObjectCommands.cxx +++ b/src/ViewerTest/ViewerTest_ObjectCommands.cxx @@ -4215,6 +4215,88 @@ static Standard_Integer VObjZLayer (Draw_Interpretor& di, return 0; } +//======================================================================= +//function : VPolygonOffset +//purpose : Set or get polygon offset parameters +//======================================================================= +static Standard_Integer VPolygonOffset(Draw_Interpretor& di, + Standard_Integer argc, + const char ** argv) +{ + Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); + if (aContext.IsNull()) + { + std::cout << argv[0] << " Call 'vinit' before!\n"; + return 1; + } + + if (argc > 2 && argc != 5) + { + std::cout << "Usage : " << argv[0] << " [object [mode factor units]] - sets/gets polygon offset parameters for an object," + "without arguments prints the default values" << std::endl; + return 1; + } + + // find object + Handle(AIS_InteractiveObject) anInterObj; + if (argc >= 2) + { + TCollection_AsciiString aName (argv[1]); + ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); + if (!aMap.IsBound2 (aName)) + { + std::cout << "Use 'vdisplay' before" << std::endl; + return 1; + } + + // find interactive object + Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName); + anInterObj = Handle(AIS_InteractiveObject)::DownCast (anObj); + if (anInterObj.IsNull()) + { + std::cout << "Not an AIS interactive object!" << std::endl; + return 1; + } + } + + Standard_Integer aMode; + Standard_Real aFactor, aUnits; + if (argc == 5) + { + aMode = atoi(argv[2]); + aFactor = atof(argv[3]); + aUnits = atof(argv[4]); + + anInterObj->SetPolygonOffsets(aMode, aFactor, aUnits); + aContext->UpdateCurrentViewer(); + return 0; + } + else if (argc == 2) + { + if (anInterObj->HasPolygonOffsets()) + { + anInterObj->PolygonOffsets(aMode, aFactor, aUnits); + std::cout << "Current polygon offset parameters for " << argv[1] << ":" << std::endl; + std::cout << "\tMode: " << aMode << std::endl; + std::cout << "\tFactor: " << aFactor << std::endl; + std::cout << "\tUnits: " << aUnits << std::endl; + return 0; + } + else + { + std::cout << "Specific polygon offset parameters are not set for " << argv[1] << std::endl; + } + } + + std::cout << "Default polygon offset parameters:" << std::endl; + aContext->DefaultDrawer()->ShadingAspect()->Aspect()->PolygonOffsets(aMode, aFactor, aUnits); + std::cout << "\tMode: " << aMode << std::endl; + std::cout << "\tFactor: " << aFactor << std::endl; + std::cout << "\tUnits: " << aUnits << std::endl; + + return 0; +} + //======================================================================= //function : ObjectsCommands //purpose : @@ -4323,4 +4405,8 @@ void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands) theCommands.Add("vobjzlayer", "vobjzlayer : set/get object [layerid] - set or get z layer id for the interactive object", __FILE__, VObjZLayer, group); + + theCommands.Add("vpolygonoffset", + "vpolygonoffset : [object [mode factor units]] - sets/gets polygon offset parameters for an object, without arguments prints the default values", + __FILE__, VPolygonOffset, group); }