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

corrected view cube positioning

This commit is contained in:
aba 2017-09-29 19:18:35 +03:00
parent c31c7ae3ba
commit e8b4130801
6 changed files with 128 additions and 32 deletions

View File

@ -192,8 +192,10 @@ void AIS_ViewCube::setDefaultAttributes()
myDrawer->ArrowAspect()->SetLength (10.0); myDrawer->ArrowAspect()->SetLength (10.0);
Graphic3d_MaterialAspect aShadingMaterial; Graphic3d_MaterialAspect aShadingMaterial;
aShadingMaterial.SetReflectionModeOff (Graphic3d_TOR_SPECULAR);
aShadingMaterial.SetMaterialType (Graphic3d_MATERIAL_ASPECT); aShadingMaterial.SetMaterialType (Graphic3d_MATERIAL_ASPECT);
aShadingMaterial.SetReflectionModeOff (Graphic3d_TOR_SPECULAR);
aShadingMaterial.SetReflectionModeOff (Graphic3d_TOR_EMISSION);
aShadingMaterial.SetReflectionModeOff (Graphic3d_TOR_DIFFUSE);
aShadingMaterial.SetTransparency (0.0); aShadingMaterial.SetTransparency (0.0);
Graphic3d_MaterialAspect aBackMaterial; Graphic3d_MaterialAspect aBackMaterial;
@ -230,6 +232,7 @@ void AIS_ViewCube::setDefaultHighlightAttributes()
aHighlightMaterial.SetReflectionModeOff (Graphic3d_TOR_SPECULAR); aHighlightMaterial.SetReflectionModeOff (Graphic3d_TOR_SPECULAR);
aHighlightMaterial.SetReflectionModeOff (Graphic3d_TOR_EMISSION); aHighlightMaterial.SetReflectionModeOff (Graphic3d_TOR_EMISSION);
aHighlightMaterial.SetMaterialType (Graphic3d_MATERIAL_ASPECT); aHighlightMaterial.SetMaterialType (Graphic3d_MATERIAL_ASPECT);
myDynHilightDrawer->SetShadingAspect (new Prs3d_ShadingAspect);
myDynHilightDrawer->ShadingAspect()->Aspect()->SetInteriorStyle (Aspect_IS_SOLID); myDynHilightDrawer->ShadingAspect()->Aspect()->SetInteriorStyle (Aspect_IS_SOLID);
myDynHilightDrawer->ShadingAspect()->SetMaterial (aHighlightMaterial); myDynHilightDrawer->ShadingAspect()->SetMaterial (aHighlightMaterial);
myDynHilightDrawer->ShadingAspect()->SetColor (Quantity_NOC_CYAN1); myDynHilightDrawer->ShadingAspect()->SetColor (Quantity_NOC_CYAN1);
@ -304,12 +307,7 @@ Graphic3d_Vec2i AIS_ViewCube::Position() const
Standard_Integer aHeight = 0; Standard_Integer aHeight = 0;
myView->Window()->Size (aWidth, aHeight); myView->Window()->Size (aWidth, aHeight);
if (myPosition & Aspect_TOTP_CENTER) Graphic3d_Vec2i aPosition (aWidth / 2, aHeight / 2);
{
return Graphic3d_Vec2i (aWidth / 2, aHeight / 2);
}
Graphic3d_Vec2i aPosition;
if (myPosition & Aspect_TOTP_TOP) if (myPosition & Aspect_TOTP_TOP)
{ {
aPosition.y() = myOffset.y(); aPosition.y() = myOffset.y();
@ -1004,21 +1002,39 @@ void AIS_ViewCube::AddTo (const Handle(AIS_InteractiveContext)& theContext,
SetView (theView); SetView (theView);
theContext->Display (this, 0, 0, Standard_False); 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 // 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); anAffinity->SetVisible (Standard_False);
// View Affinity should be applied after Display // 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); aContext->SetViewAffinity (this, aViewIter.Value(), Standard_False);
aViewIter.Value()->View()->ChangeHiddenObjects()->Add (myFlatPart.get());
} }
theContext->SetViewAffinity (this, theView, Standard_True); aContext->SetViewAffinity (this, theView, Standard_True);
*/
anAffinity->SetVisible (theView->View()->Identification(), 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 : //purpose :
//======================================================================= //=======================================================================
Standard_Integer AIS_ViewCube::addPart (const Handle(Part)& thePart, Standard_Integer AIS_ViewCube::addPart (const Handle(Part)& thePart,
const gp_Dir& theDir, const gp_Dir& theUp, const gp_Dir& theDir, const gp_Dir& theUp,
const Standard_Integer thePriority) const Standard_Integer thePriority)
{ {
Handle(SelectMgr_EntityOwner) anOwner = new AIS_ViewCubeOwner (this, thePriority); Handle(SelectMgr_EntityOwner) anOwner = new AIS_ViewCubeOwner (this, thePriority);
myStates.Add (anOwner, new CameraStateReplace (theDir, theUp)); myStates.Add (anOwner, new CameraStateReplace (theDir, theUp));
@ -1183,8 +1199,8 @@ Standard_Integer AIS_ViewCube::addPart (const Handle(Part)& thePart,
//purpose : //purpose :
//======================================================================= //=======================================================================
Standard_Integer AIS_ViewCube::addPart (const Handle(Part)& thePart, Standard_Integer AIS_ViewCube::addPart (const Handle(Part)& thePart,
const Standard_Real theAngleX, const Standard_Real theAngleY, const Standard_Real theAngleZ, const Standard_Real theAngleX, const Standard_Real theAngleY, const Standard_Real theAngleZ,
const Standard_Integer thePriority) const Standard_Integer thePriority)
{ {
Handle(SelectMgr_EntityOwner) anOwner = new AIS_ViewCubeOwner (this, thePriority); Handle(SelectMgr_EntityOwner) anOwner = new AIS_ViewCubeOwner (this, thePriority);
myStates.Add (anOwner, new CameraStateRotate (theAngleX, theAngleY, theAngleZ)); myStates.Add (anOwner, new CameraStateRotate (theAngleX, theAngleY, theAngleZ));
@ -1252,8 +1268,8 @@ void AIS_ViewCube::setLocalTransformation (const Handle(Geom_Transformation)& /*
//purpose : //purpose :
//======================================================================= //=======================================================================
void AIS_ViewCube::HilightOwnerWithColor (const Handle(PrsMgr_PresentationManager3d)& thePM, void AIS_ViewCube::HilightOwnerWithColor (const Handle(PrsMgr_PresentationManager3d)& thePM,
const Handle(Prs3d_Drawer)& theStyle, const Handle(Prs3d_Drawer)& theStyle,
const Handle(SelectMgr_EntityOwner)& theOwner) const Handle(SelectMgr_EntityOwner)& theOwner)
{ {
if (theOwner.IsNull()) if (theOwner.IsNull())
{ {
@ -1267,6 +1283,18 @@ void AIS_ViewCube::HilightOwnerWithColor (const Handle(PrsMgr_PresentationManage
return; 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); aPresentation->Highlight (theStyle);
for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (aPresentation->Groups()); for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (aPresentation->Groups());
aGroupIter.More(); aGroupIter.Next()) 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; aTopRight = aTopLeft.XYZ() + aPosition.XDirection().XYZ() * aSize;
aBottomRight = aBottomLeft.XYZ() + aPosition.XDirection().XYZ() * aSize; aBottomRight = aBottomLeft.XYZ() + aPosition.XDirection().XYZ() * aSize;
const Standard_Real aCoef = aSize * 0.5; 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(Graphic3d_ArrayOfTriangles) anArray;
Handle(Poly_Triangulation) aTri; Handle(Poly_Triangulation) aTri;

View File

@ -58,12 +58,13 @@ class AIS_ViewCubeFlat;
//! Handle(AIS_ViewCube) aViewCube = new AIS_ViewCube(); //! Handle(AIS_ViewCube) aViewCube = new AIS_ViewCube();
//! aViewCube->AddTo (aContext, aView); //! aViewCube->AddTo (aContext, aView);
//! @endcode //! @endcode
//! or //! or it can be just be displayed without iew affinity option (in this case it will be displayed in all views):
//! @code //! @code
//! aView->SetView (aView); //! Handle(AIS_ViewCube) aViewCube = new AIS_ViewCube();
//! aContext->Display (aViewCube, 0, 0, Standard_False); //! Handle(AIS_InteractiveContext) aContext;
//! aContext->Display (aViewCube, Standard_False);
//! @endcode //! @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. //! 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 //! 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. //! animation of transformation.
@ -81,6 +82,9 @@ class AIS_ViewCubeFlat;
//! that includes transformation loop. //! that includes transformation loop.
//! This loop allows external actions like application updating. For this purpose AIS_ViewCube has virtual interface onAfterTransform(), //! 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. //! 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: //! @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 //! 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. //! @param theView [in] 3D view.
Standard_EXPORT void AddTo (const Handle(AIS_InteractiveContext)& theContext, const Handle(V3d_View)& theView); 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 //! Hide View Cube in view
Standard_EXPORT void Hide(); Standard_EXPORT void Hide();
@ -145,13 +155,18 @@ protected:
//! Set default visual attributes //! Set default visual attributes
Standard_EXPORT void setDefaultAttributes(); Standard_EXPORT void setDefaultAttributes();
//! Set default dynamic highlight properties
Standard_EXPORT void setDefaultHighlightAttributes(); Standard_EXPORT void setDefaultHighlightAttributes();
public: //! @name Geometry management API 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, Standard_EXPORT void Position (Aspect_TypeOfTriedronPosition& thePosition,
Graphic3d_Vec2i& theOffset); 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; Standard_EXPORT Graphic3d_Vec2i Position() const;
//! Set position of center of View Cube in view plane depending on size of view. //! Set position of center of View Cube in view plane depending on size of view.

View File

@ -11,7 +11,7 @@ vclose ALL
vinit vinit
vviewcube -enable -hideedges 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." puts "ERROR: Invalid display of View Cube without edges."
} }
vdump $anImage1 vdump $anImage1
@ -24,7 +24,7 @@ vdump $anImage2
vviewcube -hideedges -hidevertices 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." puts "ERROR: Invalid display of View Cube without edges & vertices."
} }
vdump $anImage3 vdump $anImage3

View File

@ -17,7 +17,7 @@ vinit
# Color # Color
# ------------------------------------- # -------------------------------------
vviewcube -enable -boxcolor 0.69 0.88 1 -arrowcolor 0 0.4 0.54 -textcolor 0 0.4 0.54 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." puts "ERROR: Errors in changing View Cube colors."
} }
vdump $anImage1 vdump $anImage1
@ -27,14 +27,14 @@ vdump $anImage1
# ------------------------------------- # -------------------------------------
vviewcube -reset vviewcube -reset
vviewcube -transparency 0.5 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." puts "ERROR: Errors in changing View Cube common transparency."
} }
vdump $anImage2 vdump $anImage2
vviewcube -reset vviewcube -reset
vviewcube -boxtransparency 0.4 -arrowtransparency 0.2 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." puts "ERROR: Errors in changing View Cube separate transparency."
} }
vdump $anImage3 vdump $anImage3
@ -44,7 +44,7 @@ vdump $anImage3
# ------------------------------------- # -------------------------------------
vviewcube -reset vviewcube -reset
vviewcube -arrowangle 30 -arrowlength 30 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." puts "ERROR: Errors in changing View Cube arrow style."
} }
vdump $anImage4 vdump $anImage4
@ -54,7 +54,7 @@ vdump $anImage4
# ------------------------------------- # -------------------------------------
vviewcube -reset vviewcube -reset
vviewcube -font "Impact" -fontheight 16 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." puts "ERROR: Errors in changing View Cube font."
} }
vdump $anImage5 vdump $anImage5

28
tests/v3d/viewcube/view Normal file
View File

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

25
tests/v3d/viewcube/view2 Normal file
View File

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