diff --git a/src/AIS/AIS_ViewCube.cxx b/src/AIS/AIS_ViewCube.cxx index 1f45ac2813..fb6b907df0 100644 --- a/src/AIS/AIS_ViewCube.cxx +++ b/src/AIS/AIS_ViewCube.cxx @@ -192,8 +192,10 @@ void AIS_ViewCube::setDefaultAttributes() myDrawer->ArrowAspect()->SetLength (10.0); Graphic3d_MaterialAspect aShadingMaterial; - aShadingMaterial.SetReflectionModeOff (Graphic3d_TOR_SPECULAR); aShadingMaterial.SetMaterialType (Graphic3d_MATERIAL_ASPECT); + aShadingMaterial.SetReflectionModeOff (Graphic3d_TOR_SPECULAR); + aShadingMaterial.SetReflectionModeOff (Graphic3d_TOR_EMISSION); + aShadingMaterial.SetReflectionModeOff (Graphic3d_TOR_DIFFUSE); aShadingMaterial.SetTransparency (0.0); Graphic3d_MaterialAspect aBackMaterial; @@ -230,6 +232,7 @@ void AIS_ViewCube::setDefaultHighlightAttributes() aHighlightMaterial.SetReflectionModeOff (Graphic3d_TOR_SPECULAR); aHighlightMaterial.SetReflectionModeOff (Graphic3d_TOR_EMISSION); aHighlightMaterial.SetMaterialType (Graphic3d_MATERIAL_ASPECT); + myDynHilightDrawer->SetShadingAspect (new Prs3d_ShadingAspect); myDynHilightDrawer->ShadingAspect()->Aspect()->SetInteriorStyle (Aspect_IS_SOLID); myDynHilightDrawer->ShadingAspect()->SetMaterial (aHighlightMaterial); myDynHilightDrawer->ShadingAspect()->SetColor (Quantity_NOC_CYAN1); @@ -304,12 +307,7 @@ Graphic3d_Vec2i AIS_ViewCube::Position() const Standard_Integer aHeight = 0; myView->Window()->Size (aWidth, aHeight); - if (myPosition & Aspect_TOTP_CENTER) - { - return Graphic3d_Vec2i (aWidth / 2, aHeight / 2); - } - - Graphic3d_Vec2i aPosition; + Graphic3d_Vec2i aPosition (aWidth / 2, aHeight / 2); if (myPosition & Aspect_TOTP_TOP) { aPosition.y() = myOffset.y(); @@ -1004,21 +1002,39 @@ void AIS_ViewCube::AddTo (const Handle(AIS_InteractiveContext)& theContext, SetView (theView); theContext->Display (this, 0, 0, Standard_False); + SetViewAffinity (theView); +} + +//======================================================================= +//function : SetViewAffinity +//purpose : +//======================================================================= +void AIS_ViewCube::SetViewAffinity (const Handle(V3d_View)& theView) +{ + const Handle(AIS_InteractiveContext)& aContext = GetContext(); + if (aContext.IsNull()) + { + return; + } // Set view affinity for child object - Handle(Graphic3d_ViewAffinity) anAffinity = GetContext()->CurrentViewer()->StructureManager()->RegisterObject (myFlatPart); + myFlatPart->Presentation()->CStructure()->ViewAffinity = new Graphic3d_ViewAffinity; + myFlatPart->Presentation()->CStructure()->ViewAffinity->SetVisible (Standard_False); + + Handle(Graphic3d_ViewAffinity) anAffinity = aContext->CurrentViewer()->StructureManager()->ObjectAffinity (this); anAffinity->SetVisible (Standard_False); // View Affinity should be applied after Display - for (V3d_ListOfViewIterator aViewIter (theContext->CurrentViewer()->DefinedViewIterator()); aViewIter.More(); aViewIter.Next()) + /*for (V3d_ListOfViewIterator aViewIter (aContext->CurrentViewer()->DefinedViewIterator()); aViewIter.More(); aViewIter.Next()) { - theContext->SetViewAffinity (this, aViewIter.Value(), Standard_False); - aViewIter.Value()->View()->ChangeHiddenObjects()->Add (myFlatPart.get()); - + aContext->SetViewAffinity (this, aViewIter.Value(), Standard_False); } - theContext->SetViewAffinity (this, theView, Standard_True); + aContext->SetViewAffinity (this, theView, Standard_True); + */ + anAffinity->SetVisible (theView->View()->Identification(), Standard_True); - theView->View()->ChangeHiddenObjects()->Remove (myFlatPart.get()); + myFlatPart->Presentation()->CStructure()->ViewAffinity->SetVisible (theView->View()->Identification(), Standard_True); + } //======================================================================= @@ -1170,8 +1186,8 @@ Standard_Boolean AIS_ViewCube::IsAutoTransform() const //purpose : //======================================================================= Standard_Integer AIS_ViewCube::addPart (const Handle(Part)& thePart, - const gp_Dir& theDir, const gp_Dir& theUp, - const Standard_Integer thePriority) + const gp_Dir& theDir, const gp_Dir& theUp, + const Standard_Integer thePriority) { Handle(SelectMgr_EntityOwner) anOwner = new AIS_ViewCubeOwner (this, thePriority); myStates.Add (anOwner, new CameraStateReplace (theDir, theUp)); @@ -1183,8 +1199,8 @@ Standard_Integer AIS_ViewCube::addPart (const Handle(Part)& thePart, //purpose : //======================================================================= Standard_Integer AIS_ViewCube::addPart (const Handle(Part)& thePart, - const Standard_Real theAngleX, const Standard_Real theAngleY, const Standard_Real theAngleZ, - const Standard_Integer thePriority) + const Standard_Real theAngleX, const Standard_Real theAngleY, const Standard_Real theAngleZ, + const Standard_Integer thePriority) { Handle(SelectMgr_EntityOwner) anOwner = new AIS_ViewCubeOwner (this, thePriority); myStates.Add (anOwner, new CameraStateRotate (theAngleX, theAngleY, theAngleZ)); @@ -1252,8 +1268,8 @@ void AIS_ViewCube::setLocalTransformation (const Handle(Geom_Transformation)& /* //purpose : //======================================================================= void AIS_ViewCube::HilightOwnerWithColor (const Handle(PrsMgr_PresentationManager3d)& thePM, - const Handle(Prs3d_Drawer)& theStyle, - const Handle(SelectMgr_EntityOwner)& theOwner) + const Handle(Prs3d_Drawer)& theStyle, + const Handle(SelectMgr_EntityOwner)& theOwner) { if (theOwner.IsNull()) { @@ -1267,6 +1283,18 @@ void AIS_ViewCube::HilightOwnerWithColor (const Handle(PrsMgr_PresentationManage return; } + // Manage view affinity if it is enabled for object + Handle(Graphic3d_ViewAffinity) anAffinity = GetContext()->CurrentViewer()->StructureManager()->ObjectAffinity (this); + if (anAffinity->IsVisible (View()->View()->Identification())) + { + if (aPresentation->CStructure()->ViewAffinity.IsNull()) + { + aPresentation->CStructure()->ViewAffinity = new Graphic3d_ViewAffinity; + } + aPresentation->CStructure()->ViewAffinity->SetVisible (Standard_False); + aPresentation->CStructure()->ViewAffinity->SetVisible (View()->View()->Identification(), Standard_True); + } + aPresentation->Highlight (theStyle); for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (aPresentation->Groups()); aGroupIter.More(); aGroupIter.Next()) @@ -1618,7 +1646,7 @@ void AIS_ViewCube::Side::Display (const Handle(PrsMgr_PresentationManager)& theP aTopRight = aTopLeft.XYZ() + aPosition.XDirection().XYZ() * aSize; aBottomRight = aBottomLeft.XYZ() + aPosition.XDirection().XYZ() * aSize; const Standard_Real aCoef = aSize * 0.5; - gp_Ax2 aTextPosition (aPosition.Translated (gp_Vec (aPosition.XDirection().XYZ() * aCoef + aPosition.YDirection().XYZ() * aCoef + aPosition.Direction().XYZ() * aSize * 0.01))); + gp_Ax2 aTextPosition (aPosition.Translated (gp_Vec (aPosition.XDirection().XYZ() * aCoef + aPosition.YDirection().XYZ() * aCoef + aPosition.Direction().XYZ() * aSize * 0.02))); Handle(Graphic3d_ArrayOfTriangles) anArray; Handle(Poly_Triangulation) aTri; diff --git a/src/AIS/AIS_ViewCube.hxx b/src/AIS/AIS_ViewCube.hxx index 78bc6747e1..00005b2eea 100644 --- a/src/AIS/AIS_ViewCube.hxx +++ b/src/AIS/AIS_ViewCube.hxx @@ -58,12 +58,13 @@ class AIS_ViewCubeFlat; //! Handle(AIS_ViewCube) aViewCube = new AIS_ViewCube(); //! aViewCube->AddTo (aContext, aView); //! @endcode -//! or +//! or it can be just be displayed without iew affinity option (in this case it will be displayed in all views): //! @code -//! aView->SetView (aView); -//! aContext->Display (aViewCube, 0, 0, Standard_False); +//! Handle(AIS_ViewCube) aViewCube = new AIS_ViewCube(); +//! Handle(AIS_InteractiveContext) aContext; +//! aContext->Display (aViewCube, Standard_False); //! @endcode -//! But View Affinity should be taken into account here also. +//! //! View Cube parts are sensitive to detection, or dynamic highlighting (but not selection), and every its owner corresponds to camera transformation. //! So, once one of the owners of View Cube is detected, application is to be call StartTransform (anOwner) and Transform (anOwner) for starting //! animation of transformation. @@ -81,6 +82,9 @@ class AIS_ViewCubeFlat; //! that includes transformation loop. //! This loop allows external actions like application updating. For this purpose AIS_ViewCube has virtual interface onAfterTransform(), //! that is to be redefined on application level. +//! Note that after modification end no highlighting is restored by default. +//! This means that after transformation of box if mouse pointer still points to box, it will not be highlighted. +//! Highlighting restoring of box is to be made on application level with AIS_InteracitveContext::MoveTo() method. //! //! @b Positioning: //! View Cube is attached to one defined point in the view plane. This point of attachment is placed in the center of view @@ -114,6 +118,12 @@ public: //! @param theView [in] 3D view. Standard_EXPORT void AddTo (const Handle(AIS_InteractiveContext)& theContext, const Handle(V3d_View)& theView); + //! Make view cube visible only in the input view + //! @param theView [in] V3d View object + //! @warning This method should be called after View Cube is displayed in context + //! or it will have no effect + Standard_EXPORT void SetViewAffinity (const Handle(V3d_View)& theView); + //! Hide View Cube in view Standard_EXPORT void Hide(); @@ -145,13 +155,18 @@ protected: //! Set default visual attributes Standard_EXPORT void setDefaultAttributes(); + //! Set default dynamic highlight properties Standard_EXPORT void setDefaultHighlightAttributes(); public: //! @name Geometry management API + //! @return position of center of View Cube in terms of 2d trandform persistence. + //! @sa Aspect_TypeOfTriedronPosition, Graphic3d_Vec2i Standard_EXPORT void Position (Aspect_TypeOfTriedronPosition& thePosition, Graphic3d_Vec2i& theOffset); + //! @return position of center of View Cube in screen cooordinates + //! (origin of system if topleft corner). Standard_EXPORT Graphic3d_Vec2i Position() const; //! Set position of center of View Cube in view plane depending on size of view. diff --git a/tests/v3d/viewcube/part b/tests/v3d/viewcube/part index d94673598a..0b9f05346a 100644 --- a/tests/v3d/viewcube/part +++ b/tests/v3d/viewcube/part @@ -11,7 +11,7 @@ vclose ALL vinit vviewcube -enable -hideedges -if {[vreadpixel 186 236 name] != "BLACK 1"} { +if {[vreadpixel 186 236 name] != "BLACK 0"} { puts "ERROR: Invalid display of View Cube without edges." } vdump $anImage1 @@ -24,7 +24,7 @@ vdump $anImage2 vviewcube -hideedges -hidevertices -if {[vreadpixel 186 236 name] != "BLACK 1" || [vreadpixel 150 258 name] != "BLACK 0"} { +if {[vreadpixel 186 236 name] != "BLACK 0" || [vreadpixel 150 258 name] != "BLACK 0"} { puts "ERROR: Invalid display of View Cube without edges & vertices." } vdump $anImage3 diff --git a/tests/v3d/viewcube/style b/tests/v3d/viewcube/style index 46c5db999b..6cb16c0a35 100644 --- a/tests/v3d/viewcube/style +++ b/tests/v3d/viewcube/style @@ -17,7 +17,7 @@ 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"} { +if {[vreadpixel 118 273 name] != "LIGHTSLATEGRAY 1" || [vreadpixel 270 260 name] != "GRAY15 0.24705882370471954"} { puts "ERROR: Errors in changing View Cube colors." } vdump $anImage1 @@ -27,14 +27,14 @@ vdump $anImage1 # ------------------------------------- vviewcube -reset vviewcube -transparency 0.5 -if {[vreadpixel 118 273 name] != "GRAY17 0.37254901960784315" || [vreadpixel 270 260 name] != "GRAY48 0.24705882352941178"} { +if {[vreadpixel 118 273 name] != "GRAY17 0.37254902720451355" || [vreadpixel 270 260 name] != "GRAY48 0.24705882370471954"} { 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"} { +if {[vreadpixel 118 273 name] != "GRAY16 0.5058823823928833" || [vreadpixel 270 260 name] != "GRAY76 0.63921570777893066"} { puts "ERROR: Errors in changing View Cube separate transparency." } vdump $anImage3 @@ -44,7 +44,7 @@ vdump $anImage3 # ------------------------------------- vviewcube -reset vviewcube -arrowangle 30 -arrowlength 30 -if {[vreadpixel 270 268 name] != "BLACK 0" || [vreadpixel 291 259 name] != "GRAY48 0.24705882352941178"} { +if {[vreadpixel 270 268 name] != "BLACK 0" || [vreadpixel 291 259 name] != "GRAY48 0.24705882370471954"} { puts "ERROR: Errors in changing View Cube arrow style." } vdump $anImage4 @@ -54,7 +54,7 @@ vdump $anImage4 # ------------------------------------- vviewcube -reset vviewcube -font "Impact" -fontheight 16 -if {[vreadpixel 151 198 name] != "BLACK 1" || [vreadpixel 168 391 name] != "RED 1"} { +if {[vreadpixel 150 200 name] != "BLACK 0.729411780834198" || [vreadpixel 168 391 name] != "RED 1"} { puts "ERROR: Errors in changing View Cube font." } vdump $anImage5 diff --git a/tests/v3d/viewcube/view b/tests/v3d/viewcube/view new file mode 100644 index 0000000000..c9785657e5 --- /dev/null +++ b/tests/v3d/viewcube/view @@ -0,0 +1,28 @@ +puts "==================================" +puts "AIS_ViewCube - check view affinity" +puts "==================================" + +set anImage1 $imagedir/${casename}_1.png +set anImage2 $imagedir/${casename}_2.png + +vclear +vclose ALL +vinit view1 +vinit view2 + +vviewcube -enable + +if {[vreadpixel 150 220 name] != "GRAY68 1"} { + puts "ERROR: display of View Cube in view2 fails." +} +vdump $anImage1 + +vactivate view1 + +if {[vreadpixel 150 220 name] != "BLACK 0"} { + puts "ERROR: View Cube should not be displayed in view1." +} +vdump $anImage2 + +vactivate view2 +vviewcube -remove \ No newline at end of file diff --git a/tests/v3d/viewcube/view2 b/tests/v3d/viewcube/view2 new file mode 100644 index 0000000000..27c277fa20 --- /dev/null +++ b/tests/v3d/viewcube/view2 @@ -0,0 +1,25 @@ +puts "==================================" +puts "AIS_ViewCube - check view affinity" +puts "==================================" + +set anImage1 $imagedir/${casename}_1.png +set anImage2 $imagedir/${casename}_2.png + +vclear +vclose ALL +vinit view1 + +vviewcube -enable +if {[vreadpixel 150 220 name] != "GRAY68 1"} { + puts "ERROR: display of View Cube in view1 fails." +} +vdump $anImage1 +vviewcube -remove + +vinit view2 +vviewcube -enable +if {[vreadpixel 150 220 name] != "GRAY68 1"} { + puts "ERROR: View Cube should not be displayed in view1." +} +vdump $anImage2 +vviewcube -remove \ No newline at end of file