From 778cd667866a3dfd3163316424864e05ef8dff93 Mon Sep 17 00:00:00 2001 From: kgv Date: Mon, 19 Sep 2016 23:40:07 +0300 Subject: [PATCH] 0027860: Visualization - clean up Transformation Persistence API Graphic3d_Camera::TransformMatrices redundant NCollection_Handle usage has been replaced with validity flags. Graphic3d_TransModeFlags now defined as enumeration, not integer bit flags. Graphic3d_TMF_PanPers and Graphic3d_TMF_FullPers have been removed. Graphic3d_TMF_ZoomRotatePers has been introduced. Graphic3d_TransformPers is now inherits Standard_Transient. Graphic3d_TransformPers now defines dedicated constructors for 3D persistence (zoom / rotate) and 2D persistence (2d / trihedron). 2D persistence now supports dedicated values for X and Y offsets. The corner is now specified by enumeration Aspect_TypeOfTriedronPosition instead of indirect interpretation of anchor point values. Fixed handling of Graphic3d_TMF_ZoomRotatePers (combination of Graphic3d_TMF_RotatePers + Graphic3d_TMF_ZoomPers). PrsMgr_PresentableObject, Graphic3d_CStructure now hold Handle(Graphic3d_TransformPers) instead of a value. Method ::SetTransformPersistence(), ::TransformPersistence() now works with Handle(Graphic3d_TransformPers). Old methods have been marked deprecated. --- dox/dev_guides/upgrade/upgrade.md | 9 +- samples/mfc/standard/Common/OCC_BaseView.cpp | 2 +- .../Common/Primitive/Sample2D_Face.cpp | 4 +- src/AIS/AIS_InteractiveContext.cxx | 6 +- src/AIS/AIS_InteractiveContext.hxx | 13 +- src/AIS/AIS_Manipulator.cxx | 26 +- src/AIS/AIS_Manipulator.hxx | 16 +- src/AIS/AIS_MultipleConnectedInteractive.cxx | 15 +- src/AIS/AIS_MultipleConnectedInteractive.hxx | 13 +- src/AIS/AIS_RubberBand.cxx | 6 +- src/AIS/AIS_TextLabel.cxx | 6 +- src/Aspect/Aspect_TypeOfTriedronPosition.hxx | 39 +- src/Graphic3d/FILES | 2 +- src/Graphic3d/Graphic3d_CStructure.hxx | 9 +- src/Graphic3d/Graphic3d_CView.cxx | 12 +- src/Graphic3d/Graphic3d_Camera.cxx | 48 ++- src/Graphic3d/Graphic3d_Camera.hxx | 63 +-- src/Graphic3d/Graphic3d_Structure.cxx | 44 +- src/Graphic3d/Graphic3d_Structure.hxx | 26 +- src/Graphic3d/Graphic3d_Structure.lxx | 32 -- src/Graphic3d/Graphic3d_TransModeFlags.hxx | 21 +- src/Graphic3d/Graphic3d_TransformPers.cxx | 53 +++ src/Graphic3d/Graphic3d_TransformPers.hxx | 398 ++++++++++++------ src/MeshVS/MeshVS_Mesh.cxx | 4 +- src/NCollection/NCollection_Mat4.hxx | 10 +- .../OpenGl_BVHClipPrimitiveTrsfPersSet.cxx | 5 +- src/OpenGl/OpenGl_BackgroundArray.cxx | 13 +- src/OpenGl/OpenGl_GraduatedTrihedron.cxx | 9 +- src/OpenGl/OpenGl_Layer.cxx | 45 +- src/OpenGl/OpenGl_Structure.cxx | 21 +- src/OpenGl/OpenGl_Structure.hxx | 4 +- src/OpenGl/OpenGl_StructureShadow.cxx | 2 +- src/OpenGl/OpenGl_View.cxx | 4 +- src/PrsMgr/PrsMgr_PresentableObject.cxx | 62 ++- src/PrsMgr/PrsMgr_PresentableObject.hxx | 43 +- src/QABugs/QABugs_11.cxx | 5 +- src/SelectMgr/SelectMgr_SelectableObject.cxx | 24 +- .../SelectMgr_SelectableObjectSet.cxx | 6 +- .../SelectMgr_SelectableObjectSet.hxx | 4 +- src/SelectMgr/SelectMgr_ViewerSelector.cxx | 10 +- src/StdSelect/StdSelect_BRepOwner.cxx | 4 +- src/StdSelect/StdSelect_ViewerSelector3d.cxx | 10 +- src/StdSelect/StdSelect_ViewerSelector3d.hxx | 2 +- src/V3d/V3d_View.cxx | 2 +- src/ViewerTest/ViewerTest.cxx | 214 +++++++--- src/ViewerTest/ViewerTest_ObjectCommands.cxx | 22 +- src/ViewerTest/ViewerTest_ViewerCommands.cxx | 7 +- tests/bugs/vis/bug23120 | 2 +- tests/bugs/vis/bug25783_1 | 20 +- tests/bugs/vis/bug26149 | 20 +- tests/bugs/vis/bug26344 | 40 +- tests/bugs/vis/bug27739 | 6 +- tests/v3d/glsl/tiles | 22 +- 53 files changed, 860 insertions(+), 645 deletions(-) delete mode 100644 src/Graphic3d/Graphic3d_Structure.lxx create mode 100644 src/Graphic3d/Graphic3d_TransformPers.cxx diff --git a/dox/dev_guides/upgrade/upgrade.md b/dox/dev_guides/upgrade/upgrade.md index 58db74b63e..740b5dfd1b 100644 --- a/dox/dev_guides/upgrade/upgrade.md +++ b/dox/dev_guides/upgrade/upgrade.md @@ -1034,10 +1034,17 @@ Thus the recommended way to generate vector image of a 3D model or scene is to u @subsection upgrade_710_trsfpers Transformation persistence -The behavior of transformation persistence flags Graphic3d_TMF_ZoomPers and Graphic3d_TMF_TriedronPers have been changed to be consistent with textured fixed-size 2D text. +The behavior of transformation persistence flags *Graphic3d_TMF_ZoomPers* and *Graphic3d_TMF_TriedronPers* have been changed to be consistent with textured fixed-size 2D text. Object with these flags is considered to be defined in pixel units, and presentation is no more scaled depending on view height. Applications that need to scale such objects depending on viewport size should update them manually. +Flags *Graphic3d_TMF_PanPers* and *Graphic3d_TMF_FullPers* has been removed. +*Graphic3d_TMF_TriedronPers* or *Graphic3d_TMF_2d* can be used instead depending on context. + +*Graphic3d_TransModeFlags* is not an integer bitmask anymore - enumeration values should be specified instead. +Several transformation persistence methods in PrsMgr_PresentableObject have been marked deprecated. +Transformation persistence should be defined using directly Graphic3d_TransformPers constructor and passed by a handle, not value. + @subsection upgrade_710_removed Removed features The following obsolete features have been removed: diff --git a/samples/mfc/standard/Common/OCC_BaseView.cpp b/samples/mfc/standard/Common/OCC_BaseView.cpp index b03d65116c..1f5853a163 100755 --- a/samples/mfc/standard/Common/OCC_BaseView.cpp +++ b/samples/mfc/standard/Common/OCC_BaseView.cpp @@ -17,7 +17,7 @@ OCC_BaseView::OCC_BaseView() myCurZoom (0.0), myRect (new AIS_RubberBand (Quantity_Color(Quantity_NOC_WHITE), Aspect_TOL_SOLID, 1.0) ) { - myRect->SetTransformPersistence (Graphic3d_TMF_2d, gp_Pnt(-1, -1, 0)); + myRect->SetTransformPersistence (new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER)); if (myRect->ZLayer() != Graphic3d_ZLayerId_TopOSD) { myRect->SetZLayer (Graphic3d_ZLayerId_TopOSD); diff --git a/samples/mfc/standard/Common/Primitive/Sample2D_Face.cpp b/samples/mfc/standard/Common/Primitive/Sample2D_Face.cpp index d2e227a9f0..264de85a3d 100755 --- a/samples/mfc/standard/Common/Primitive/Sample2D_Face.cpp +++ b/samples/mfc/standard/Common/Primitive/Sample2D_Face.cpp @@ -267,7 +267,7 @@ void Sample2D_Face::HilightSelected Handle(Graphic3d_AspectLine3d) aLineAspect = new Graphic3d_AspectLine3d(Quantity_NOC_ANTIQUEWHITE, Aspect_TOL_SOLID,2); if( HasPresentation() ) - aSelectionPrs->SetTransformPersistence( Presentation()->TransformPersistenceMode(), Presentation()->TransformPersistencePoint() ); + aSelectionPrs->SetTransformPersistence (Presentation()->TransformPersistence()); Standard_Integer aLength = theOwners.Length(); Handle (SelectMgr_EntityOwner) anOwner; @@ -337,7 +337,7 @@ void Sample2D_Face::HilightOwnerWithColor ( const Handle(PrsMgr_PresentationMana Handle( Prs3d_Presentation ) aHighlightPrs; aHighlightPrs = GetHilightPresentation( thePM ); if( HasPresentation() ) - aHighlightPrs->SetTransformPersistence( Presentation()->TransformPersistenceMode(), Presentation()->TransformPersistencePoint() ); + aHighlightPrs->SetTransformPersistence (Presentation()->TransformPersistence()); if(theOwner.IsNull()) return; aHighlightPrs->Clear(); diff --git a/src/AIS/AIS_InteractiveContext.cxx b/src/AIS/AIS_InteractiveContext.cxx index a55caec2b5..60404c11c6 100644 --- a/src/AIS/AIS_InteractiveContext.cxx +++ b/src/AIS/AIS_InteractiveContext.cxx @@ -2932,11 +2932,9 @@ void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView, //purpose : //======================================================================= void AIS_InteractiveContext::SetTransformPersistence (const Handle(AIS_InteractiveObject)& theObject, - const Graphic3d_TransModeFlags& theFlag, - const gp_Pnt& thePoint) + const Handle(Graphic3d_TransformPers)& theTrsfPers) { - theObject->SetTransformPersistence (theFlag, thePoint); - + theObject->SetTransformPersistence (theTrsfPers); if (!myObjects.IsBound (theObject)) { return; diff --git a/src/AIS/AIS_InteractiveContext.hxx b/src/AIS/AIS_InteractiveContext.hxx index 148ec6a467..5ea8735162 100644 --- a/src/AIS/AIS_InteractiveContext.hxx +++ b/src/AIS/AIS_InteractiveContext.hxx @@ -599,9 +599,16 @@ public: Standard_EXPORT void Status (const Handle(AIS_InteractiveObject)& anObj, TCollection_ExtendedString& astatus) const; //! Sets transform persistence. - Standard_EXPORT void SetTransformPersistence (const Handle(AIS_InteractiveObject)& theObj, - const Graphic3d_TransModeFlags& theFlag, - const gp_Pnt& thePoint = gp_Pnt (0.0, 0.0, 0.0)); + Standard_EXPORT void SetTransformPersistence (const Handle(AIS_InteractiveObject)& theObject, + const Handle(Graphic3d_TransformPers)& theTrsfPers); + + Standard_DEPRECATED("This method is deprecated - SetTransformPersistence() taking Graphic3d_TransformPers should be called instead") + void SetTransformPersistence (const Handle(AIS_InteractiveObject)& theObj, + const Graphic3d_TransModeFlags& theFlag, + const gp_Pnt& thePoint = gp_Pnt (0.0, 0.0, 0.0)) + { + SetTransformPersistence (theObj, Graphic3d_TransformPers::FromDeprecatedParams (theFlag, thePoint)); + } //! Updates the current viewer, the viewer in Neutral Point. //! Objects selected when there is no open local context diff --git a/src/AIS/AIS_Manipulator.cxx b/src/AIS/AIS_Manipulator.cxx index 370ec76a44..2bd71c1cbd 100644 --- a/src/AIS/AIS_Manipulator.cxx +++ b/src/AIS/AIS_Manipulator.cxx @@ -651,10 +651,11 @@ void AIS_Manipulator::updateTransformation() if (myIsZoomPersistentMode) { - if (!(GetTransformPersistenceMode () == Graphic3d_TMF_ZoomPers - && GetTransformPersistencePoint().IsEqual (myPosition.Location(), 0.))) + if (TransformPersistence().IsNull() + || TransformPersistence()->Mode() != Graphic3d_TMF_ZoomPers + || !TransformPersistence()->AnchorPoint().IsEqual (myPosition.Location(), 0.0)) { - setTransformPersistence (Graphic3d_TMF_ZoomPers, myPosition.Location()); + setTransformPersistence (new Graphic3d_TransformPers (Graphic3d_TMF_ZoomPers, myPosition.Location())); } } } @@ -734,7 +735,7 @@ void AIS_Manipulator::SetZoomPersistence (const Standard_Boolean theToEnable) if (!theToEnable) { - setTransformPersistence (Graphic3d_TMF_None, gp::Origin()); + setTransformPersistence (Handle(Graphic3d_TransformPers)()); } updateTransformation(); @@ -742,28 +743,28 @@ void AIS_Manipulator::SetZoomPersistence (const Standard_Boolean theToEnable) //======================================================================= //function : SetTransformPersistence -//purpose : +//purpose : //======================================================================= -void AIS_Manipulator::SetTransformPersistence (const Graphic3d_TransModeFlags& theFlag, const gp_Pnt& thePoint) +void AIS_Manipulator::SetTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers) { Standard_ASSERT_RETURN (!myIsZoomPersistentMode, "AIS_Manipulator::SetTransformPersistence: " - "Custom settings are not supported by this class in ZoomPersistence mode",); + "Custom settings are not allowed by this class in ZoomPersistence mode",); - setTransformPersistence (theFlag, thePoint); + setTransformPersistence (theTrsfPers); } //======================================================================= //function : setTransformPersistence //purpose : //======================================================================= -void AIS_Manipulator::setTransformPersistence (const Graphic3d_TransModeFlags& theFlag, const gp_Pnt& thePoint) +void AIS_Manipulator::setTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers) { - AIS_InteractiveObject::SetTransformPersistence (theFlag, thePoint); + AIS_InteractiveObject::SetTransformPersistence (theTrsfPers); for (Standard_Integer anIt = 0; anIt < 3; ++anIt) { - myAxes[anIt].SetTransformPersistence (theFlag, thePoint); + myAxes[anIt].SetTransformPersistence (theTrsfPers); } } @@ -814,8 +815,7 @@ void AIS_Manipulator::Compute (const Handle(PrsMgr_PresentationManager3d)& thePr anAspectAx->SetColor (myAxes[anIt].Color()); aGroup->SetGroupPrimitivesAspect (anAspectAx->Aspect()); myAxes[anIt].Compute (thePrsMgr, thePrs, anAspectAx); - myAxes[anIt].SetTransformPersistence (GetTransformPersistenceMode(), - GetTransformPersistencePoint()); + myAxes[anIt].SetTransformPersistence (TransformPersistence()); } updateTransformation(); diff --git a/src/AIS/AIS_Manipulator.hxx b/src/AIS/AIS_Manipulator.hxx index 15d7c5c6b0..358ee17e20 100644 --- a/src/AIS/AIS_Manipulator.hxx +++ b/src/AIS/AIS_Manipulator.hxx @@ -250,7 +250,7 @@ public: //! @name Configuration of graphical transformations //! silently does nothing in release mode. //! @warning revise use of AdjustSize argument of of \sa AttachToObjects method //! when enabling zoom persistence. - Standard_EXPORT virtual void SetTransformPersistence (const Graphic3d_TransModeFlags& theFlag, const gp_Pnt& thePoint) Standard_OVERRIDE; + Standard_EXPORT virtual void SetTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers) Standard_OVERRIDE; //! Redefines local transformation management method to inform user of inproper use. //! @warning this interactive object does not support setting custom local transformation, @@ -347,7 +347,7 @@ protected: Standard_EXPORT void adjustSize (const Bnd_Box& theBox); - Standard_EXPORT void setTransformPersistence (const Graphic3d_TransModeFlags& theFlag, const gp_Pnt& thePoint); + Standard_EXPORT void setTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers); protected: //! @name Auxilliary classes to fill presentation with proper primitives @@ -489,28 +489,24 @@ protected: //! @name Auxilliary classes to fill presentation with proper primiti const gp_Ax1& Position() const { return myPosition; } - void SetTransformPersistence (const Graphic3d_TransModeFlags& theFlags, const gp_Pnt& thePoint) + void SetTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers) { if (!myHighlightTranslator.IsNull()) { - myHighlightTranslator->SetTransformPersistence (theFlags, thePoint); + myHighlightTranslator->SetTransformPersistence (theTrsfPers); } if (!myHighlightScaler.IsNull()) { - myHighlightScaler->SetTransformPersistence (theFlags, thePoint); + myHighlightScaler->SetTransformPersistence (theTrsfPers); } if (!myHighlightRotator.IsNull()) { - myHighlightRotator->SetTransformPersistence (theFlags, thePoint); + myHighlightRotator->SetTransformPersistence (theTrsfPers); } } - Graphic3d_TransModeFlags GetTransformPersistenceMode() const { return myHighlightTranslator->TransformPersistenceMode(); } - - gp_Pnt GetTransformPersistencePoint() const { return myHighlightTranslator->TransformPersistencePoint(); } - void Transform (const Handle(Geom_Transformation)& theTransformation) { if (!myHighlightTranslator.IsNull()) diff --git a/src/AIS/AIS_MultipleConnectedInteractive.cxx b/src/AIS/AIS_MultipleConnectedInteractive.cxx index ed5cc6f377..087b82460d 100644 --- a/src/AIS/AIS_MultipleConnectedInteractive.cxx +++ b/src/AIS/AIS_MultipleConnectedInteractive.cxx @@ -195,8 +195,7 @@ Standard_Integer AIS_MultipleConnectedInteractive::Signature() const //======================================================================= Handle(AIS_InteractiveObject) AIS_MultipleConnectedInteractive::Connect (const Handle(AIS_InteractiveObject)& theAnotherObj, const gp_Trsf& theTransformation, - const Graphic3d_TransModeFlags& theTrsfPersFlag, - const gp_Pnt& theTrsfPersPoint) + const Handle(Graphic3d_TransformPers)& theTrsfPers) { if (myAssemblyOwner.IsNull()) myAssemblyOwner = new SelectMgr_EntityOwner (this); @@ -234,9 +233,9 @@ Handle(AIS_InteractiveObject) AIS_MultipleConnectedInteractive::Connect (const H } anObjectToAdd->SetLocalTransformation (theTransformation); - if (theTrsfPersFlag != Graphic3d_TMF_None) + if (!theTrsfPers.IsNull()) { - anObjectToAdd->SetTransformPersistence (theTrsfPersFlag, theTrsfPersPoint); + anObjectToAdd->SetTransformPersistence (theTrsfPers); } AddChild (anObjectToAdd); return anObjectToAdd; @@ -248,9 +247,7 @@ Handle(AIS_InteractiveObject) AIS_MultipleConnectedInteractive::Connect (const H //======================================================================= Handle(AIS_InteractiveObject) AIS_MultipleConnectedInteractive::Connect (const Handle(AIS_InteractiveObject)& theAnotherObj) { - return Connect (theAnotherObj, theAnotherObj->LocalTransformation(), - theAnotherObj->GetTransformPersistenceMode(), - theAnotherObj->GetTransformPersistencePoint()); + return Connect (theAnotherObj, theAnotherObj->LocalTransformation(), theAnotherObj->TransformPersistence()); } //======================================================================= @@ -260,9 +257,7 @@ Handle(AIS_InteractiveObject) AIS_MultipleConnectedInteractive::Connect (const H Handle(AIS_InteractiveObject) AIS_MultipleConnectedInteractive::Connect (const Handle(AIS_InteractiveObject)& theAnotherObj, const gp_Trsf& theTransformation) { - return Connect (theAnotherObj, theTransformation, - theAnotherObj->GetTransformPersistenceMode(), - theAnotherObj->GetTransformPersistencePoint()); + return Connect (theAnotherObj, theTransformation, theAnotherObj->TransformPersistence()); } //======================================================================= diff --git a/src/AIS/AIS_MultipleConnectedInteractive.hxx b/src/AIS/AIS_MultipleConnectedInteractive.hxx index c22b5bd774..b90e5051cc 100644 --- a/src/AIS/AIS_MultipleConnectedInteractive.hxx +++ b/src/AIS/AIS_MultipleConnectedInteractive.hxx @@ -66,7 +66,18 @@ public: //! Establishes the connection between the Connected Interactive Object, theInteractive, and its reference. //! Locates instance in theLocation and applies specified transformation persistence mode. //! @return created instance object (AIS_ConnectedInteractive or AIS_MultipleConnectedInteractive) - Standard_EXPORT virtual Handle(AIS_InteractiveObject) Connect (const Handle(AIS_InteractiveObject)& theInteractive, const gp_Trsf& theLocation, const Graphic3d_TransModeFlags& theTrsfPersFlag, const gp_Pnt& theTrsfPersPoint); + Standard_EXPORT virtual Handle(AIS_InteractiveObject) Connect (const Handle(AIS_InteractiveObject)& theInteractive, + const gp_Trsf& theLocation, + const Handle(Graphic3d_TransformPers)& theTrsfPers); + + Standard_DEPRECATED("This method is deprecated - Connect() taking Graphic3d_TransformPers should be called instead") + Handle(AIS_InteractiveObject) Connect (const Handle(AIS_InteractiveObject)& theInteractive, + const gp_Trsf& theLocation, + const Graphic3d_TransModeFlags& theTrsfPersFlag, + const gp_Pnt& theTrsfPersPoint) + { + return Connect (theInteractive, theLocation, Graphic3d_TransformPers::FromDeprecatedParams (theTrsfPersFlag, theTrsfPersPoint)); + } Standard_EXPORT virtual AIS_KindOfInteractive Type() const Standard_OVERRIDE; diff --git a/src/AIS/AIS_RubberBand.cxx b/src/AIS/AIS_RubberBand.cxx index b9ccdb3f1b..b822316486 100644 --- a/src/AIS/AIS_RubberBand.cxx +++ b/src/AIS/AIS_RubberBand.cxx @@ -47,7 +47,7 @@ AIS_RubberBand::AIS_RubberBand() myDrawer->ShadingAspect()->SetTransparency (1.0); myDrawer->ShadingAspect()->SetColor (Quantity_NOC_WHITE); - SetTransformPersistence (Graphic3d_TMF_2d, gp_Pnt(-1, -1, 0)); + SetTransformPersistence (new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER)); SetZLayer (Graphic3d_ZLayerId_TopOSD); } @@ -66,7 +66,7 @@ AIS_RubberBand::AIS_RubberBand (const Quantity_Color& theLineColor, myDrawer->ShadingAspect()->SetTransparency (1.0); myDrawer->ShadingAspect()->SetColor (Quantity_NOC_WHITE); - SetTransformPersistence (Graphic3d_TMF_2d, gp_Pnt(-1, -1, 0)); + SetTransformPersistence (new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER)); SetZLayer (Graphic3d_ZLayerId_TopOSD); } @@ -87,7 +87,7 @@ AIS_RubberBand::AIS_RubberBand (const Quantity_Color& theLineColor, myDrawer->ShadingAspect()->Aspect()->SetInteriorStyle (Aspect_IS_SOLID); myDrawer->ShadingAspect()->SetTransparency (theTransparency); - SetTransformPersistence (Graphic3d_TMF_2d, gp_Pnt(-1, -1, 0)); + SetTransformPersistence (new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER)); SetZLayer (Graphic3d_ZLayerId_TopOSD); } diff --git a/src/AIS/AIS_TextLabel.cxx b/src/AIS/AIS_TextLabel.cxx index 9066b18c50..5ba7e3773e 100644 --- a/src/AIS/AIS_TextLabel.cxx +++ b/src/AIS/AIS_TextLabel.cxx @@ -284,10 +284,12 @@ void AIS_TextLabel::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePr aCenterOfLabel.ChangeCoord() -= myOrientation3D.XDirection().XYZ() * aWidth * 0.5; } - if (!anAsp->Aspect()->GetTextZoomable()) + if (!anAsp->Aspect()->GetTextZoomable() + && (TransformPersistence().IsNull() + || TransformPersistence()->Mode() == Graphic3d_TMF_ZoomPers)) { anAsp->Aspect()->SetTextZoomable (Standard_True); - SetTransformPersistence (GetTransformPersistenceMode() | Graphic3d_TMF_ZoomPers, aPosition); + SetTransformPersistence (new Graphic3d_TransformPers (Graphic3d_TMF_ZoomPers, aPosition)); aPosition = gp::Origin(); } diff --git a/src/Aspect/Aspect_TypeOfTriedronPosition.hxx b/src/Aspect/Aspect_TypeOfTriedronPosition.hxx index cbc875aeb5..987e95e08a 100644 --- a/src/Aspect/Aspect_TypeOfTriedronPosition.hxx +++ b/src/Aspect/Aspect_TypeOfTriedronPosition.hxx @@ -16,31 +16,24 @@ #ifndef _Aspect_TypeOfTriedronPosition_HeaderFile #define _Aspect_TypeOfTriedronPosition_HeaderFile -//! Definition of the Triedron position in the views -//! -//! TOTP_CENTER at the center of the view -//! TOTP_LEFT_LOWER at the left lower corner -//! TOTP_LEFT_UPPER at the left upper corner -//! TOTP_RIGHT_LOWER at the right lower corner -//! TOTP_RIGHT_UPPER at the right upper corner -//! TOTP_01 to TOTP_10 not yet implemented. +//! Definition of the Trihedron position in the views. +//! It is defined as a bitmask to simplify handling vertical and horizontal alignment independently. enum Aspect_TypeOfTriedronPosition { -Aspect_TOTP_CENTER, -Aspect_TOTP_LEFT_LOWER, -Aspect_TOTP_LEFT_UPPER, -Aspect_TOTP_RIGHT_LOWER, -Aspect_TOTP_RIGHT_UPPER, -Aspect_TOTP_01, -Aspect_TOTP_02, -Aspect_TOTP_03, -Aspect_TOTP_04, -Aspect_TOTP_05, -Aspect_TOTP_06, -Aspect_TOTP_07, -Aspect_TOTP_08, -Aspect_TOTP_09, -Aspect_TOTP_10 + Aspect_TOTP_CENTER = 0x0000, //!< at the center of the view + Aspect_TOTP_TOP = 0x0001, //!< at the middle of the top side + Aspect_TOTP_BOTTOM = 0x0002, //!< at the middle of the bottom side + Aspect_TOTP_LEFT = 0x0004, //!< at the middle of the left side + Aspect_TOTP_RIGHT = 0x0008, //!< at the middle of the right side + Aspect_TOTP_LEFT_LOWER = Aspect_TOTP_BOTTOM + | Aspect_TOTP_LEFT, //!< at the left lower corner + Aspect_TOTP_LEFT_UPPER = Aspect_TOTP_TOP + | Aspect_TOTP_LEFT, //!< at the left upper corner + Aspect_TOTP_RIGHT_LOWER = Aspect_TOTP_BOTTOM + | Aspect_TOTP_RIGHT, //!< at the right lower corner + Aspect_TOTP_RIGHT_UPPER = Aspect_TOTP_TOP + | Aspect_TOTP_RIGHT, //!< at the right upper corner + }; #endif // _Aspect_TypeOfTriedronPosition_HeaderFile diff --git a/src/Graphic3d/FILES b/src/Graphic3d/FILES index 59ed3159f2..6d6274f99b 100755 --- a/src/Graphic3d/FILES +++ b/src/Graphic3d/FILES @@ -98,7 +98,6 @@ Graphic3d_SortType.hxx Graphic3d_StereoMode.hxx Graphic3d_Structure.cxx Graphic3d_Structure.hxx -Graphic3d_Structure.lxx Graphic3d_Structure.pxx Graphic3d_StructureDefinitionError.hxx Graphic3d_StructureManager.cxx @@ -126,6 +125,7 @@ Graphic3d_TextureRoot.cxx Graphic3d_TextureRoot.hxx Graphic3d_TransformError.hxx Graphic3d_TransformPers.hxx +Graphic3d_TransformPers.cxx Graphic3d_TransformUtils.hxx Graphic3d_TransModeFlags.hxx Graphic3d_TypeOfAnswer.hxx diff --git a/src/Graphic3d/Graphic3d_CStructure.hxx b/src/Graphic3d/Graphic3d_CStructure.hxx index ae7bd3331c..bbfeb655da 100644 --- a/src/Graphic3d/Graphic3d_CStructure.hxx +++ b/src/Graphic3d/Graphic3d_CStructure.hxx @@ -46,6 +46,12 @@ public: return myGroups; } + //! Return transformation persistence. + const Handle(Graphic3d_TransformPers)& TransformPersistence() const { return myTrsfPers; } + + //! Set transformation persistence. + void SetTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers) { myTrsfPers = theTrsfPers; } + //! @return associated clip planes const Handle(Graphic3d_SequenceOfHClipPlane)& ClipPlanes() const { @@ -143,8 +149,6 @@ public: unsigned IsMutable : 1; unsigned Is2dText : 1; - Graphic3d_TransformPers TransformPersistence; - protected: //! Create empty structure. @@ -155,6 +159,7 @@ protected: Handle(Graphic3d_GraphicDriver) myGraphicDriver; Graphic3d_SequenceOfGroup myGroups; Graphic3d_BndBox4f myBndBox; + Handle(Graphic3d_TransformPers) myTrsfPers; Handle(Graphic3d_SequenceOfHClipPlane) myClipPlanes; public: diff --git a/src/Graphic3d/Graphic3d_CView.cxx b/src/Graphic3d/Graphic3d_CView.cxx index dbbd5d0000..047d5bf3e8 100644 --- a/src/Graphic3d/Graphic3d_CView.cxx +++ b/src/Graphic3d/Graphic3d_CView.cxx @@ -530,14 +530,12 @@ Bnd_Box Graphic3d_CView::MinMaxValues (const Graphic3d_MapOfStructure& theSet, } // "FitAll" operation ignores object with transform persistence parameter - if (aStructure->TransformPersistence().Flags != Graphic3d_TMF_None) + if (!aStructure->TransformPersistence().IsNull()) { // Panning and 2d persistence apply changes to projection or/and its translation components. // It makes them incompatible with z-fitting algorithm. Ignored by now. - if (!theToIgnoreInfiniteFlag || - (aStructure->TransformPersistence().Flags & Graphic3d_TMF_2d) || - (aStructure->TransformPersistence().Flags & Graphic3d_TMF_PanPers) || - (aStructure->TransformPersistence().Flags & Graphic3d_TMF_TriedronPers)) + if (!theToIgnoreInfiniteFlag + || aStructure->TransformPersistence()->IsTrihedronOr2d()) { continue; } @@ -550,11 +548,11 @@ Bnd_Box Graphic3d_CView::MinMaxValues (const Graphic3d_MapOfStructure& theSet, continue; } - if (aStructure->TransformPersistence().Flags != Graphic3d_TMF_None) + if (!aStructure->TransformPersistence().IsNull()) { const Graphic3d_Mat4d& aProjectionMat = aCamera->ProjectionMatrix(); const Graphic3d_Mat4d& aWorldViewMat = aCamera->OrientationMatrix(); - aStructure->TransformPersistence().Apply (aCamera, aProjectionMat, aWorldViewMat, aWinWidth, aWinHeight, aBox); + aStructure->TransformPersistence()->Apply (aCamera, aProjectionMat, aWorldViewMat, aWinWidth, aWinHeight, aBox); } // To prevent float overflow at camera parameters calculation and further diff --git a/src/Graphic3d/Graphic3d_Camera.cxx b/src/Graphic3d/Graphic3d_Camera.cxx index 754af59094..f9f5c034c2 100644 --- a/src/Graphic3d/Graphic3d_Camera.cxx +++ b/src/Graphic3d/Graphic3d_Camera.cxx @@ -74,6 +74,7 @@ Graphic3d_Camera::Graphic3d_Camera() myAxialScale (1.0, 1.0, 1.0), myProjType (Projection_Orthographic), myFOVy (45.0), + myFOVyTan (Tan (DTR_HALF * 45.0)), myZNear (DEFAULT_ZNEAR), myZFar (DEFAULT_ZFAR), myAspect (1.0), @@ -271,7 +272,7 @@ void Graphic3d_Camera::SetScale (const Standard_Real theScale) case Projection_MonoLeftEye : case Projection_MonoRightEye : { - Standard_Real aDistance = theScale * 0.5 / Tan(DTR_HALF * myFOVy); + Standard_Real aDistance = theScale * 0.5 / myFOVyTan; SetDistance (aDistance); } @@ -298,7 +299,7 @@ Standard_Real Graphic3d_Camera::Scale() const // case Projection_MonoLeftEye : // case Projection_MonoRightEye : default : - return Distance() * 2.0 * Tan (DTR_HALF * myFOVy); + return Distance() * 2.0 * myFOVyTan; } } @@ -344,6 +345,7 @@ void Graphic3d_Camera::SetFOVy (const Standard_Real theFOVy) } myFOVy = theFOVy; + myFOVyTan = Tan(DTR_HALF * myFOVy); InvalidateProjection(); } @@ -646,7 +648,7 @@ gp_Pnt Graphic3d_Camera::ConvertView2World (const gp_Pnt& thePnt) const gp_XYZ Graphic3d_Camera::ViewDimensions (const Standard_Real theZValue) const { // view plane dimensions - Standard_Real aSize = IsOrthographic() ? myScale : (2.0 * theZValue * Tan (DTR_HALF * myFOVy)); + Standard_Real aSize = IsOrthographic() ? myScale : (2.0 * theZValue * myFOVyTan); Standard_Real aSizeX, aSizeY; if (myAspect > 1.0) { @@ -719,7 +721,7 @@ void Graphic3d_Camera::Frustum (gp_Pln& theLeft, // ======================================================================= const Graphic3d_Mat4d& Graphic3d_Camera::OrientationMatrix() const { - return *UpdateOrientation (myMatricesD).Orientation; + return UpdateOrientation (myMatricesD).Orientation; } // ======================================================================= @@ -728,7 +730,7 @@ const Graphic3d_Mat4d& Graphic3d_Camera::OrientationMatrix() const // ======================================================================= const Graphic3d_Mat4& Graphic3d_Camera::OrientationMatrixF() const { - return *UpdateOrientation (myMatricesF).Orientation; + return UpdateOrientation (myMatricesF).Orientation; } // ======================================================================= @@ -737,7 +739,7 @@ const Graphic3d_Mat4& Graphic3d_Camera::OrientationMatrixF() const // ======================================================================= const Graphic3d_Mat4d& Graphic3d_Camera::ProjectionMatrix() const { - return *UpdateProjection (myMatricesD).MProjection; + return UpdateProjection (myMatricesD).MProjection; } // ======================================================================= @@ -746,7 +748,7 @@ const Graphic3d_Mat4d& Graphic3d_Camera::ProjectionMatrix() const // ======================================================================= const Graphic3d_Mat4& Graphic3d_Camera::ProjectionMatrixF() const { - return *UpdateProjection (myMatricesF).MProjection; + return UpdateProjection (myMatricesF).MProjection; } // ======================================================================= @@ -755,7 +757,7 @@ const Graphic3d_Mat4& Graphic3d_Camera::ProjectionMatrixF() const // ======================================================================= const Graphic3d_Mat4d& Graphic3d_Camera::ProjectionStereoLeft() const { - return *UpdateProjection (myMatricesD).LProjection; + return UpdateProjection (myMatricesD).LProjection; } // ======================================================================= @@ -764,7 +766,7 @@ const Graphic3d_Mat4d& Graphic3d_Camera::ProjectionStereoLeft() const // ======================================================================= const Graphic3d_Mat4& Graphic3d_Camera::ProjectionStereoLeftF() const { - return *UpdateProjection (myMatricesF).LProjection; + return UpdateProjection (myMatricesF).LProjection; } // ======================================================================= @@ -773,7 +775,7 @@ const Graphic3d_Mat4& Graphic3d_Camera::ProjectionStereoLeftF() const // ======================================================================= const Graphic3d_Mat4d& Graphic3d_Camera::ProjectionStereoRight() const { - return *UpdateProjection (myMatricesD).RProjection; + return UpdateProjection (myMatricesD).RProjection; } // ======================================================================= @@ -782,7 +784,7 @@ const Graphic3d_Mat4d& Graphic3d_Camera::ProjectionStereoRight() const // ======================================================================= const Graphic3d_Mat4& Graphic3d_Camera::ProjectionStereoRightF() const { - return *UpdateProjection (myMatricesF).RProjection; + return UpdateProjection (myMatricesF).RProjection; } // ======================================================================= @@ -813,8 +815,8 @@ Graphic3d_Camera::TransformMatrices& } else { - aDXHalf = aZNear * Elem_t (Tan (DTR_HALF * myFOVy)); - aDYHalf = aZNear * Elem_t (Tan (DTR_HALF * myFOVy)); + aDXHalf = aZNear * Elem_t (myFOVyTan); + aDYHalf = aZNear * Elem_t (myFOVyTan); } if (anAspect > 1.0) @@ -854,19 +856,19 @@ Graphic3d_Camera::TransformMatrices& switch (myProjType) { case Projection_Orthographic : - OrthoProj (aLeft, aRight, aBot, aTop, aZNear, aZFar, *theMatrices.MProjection); + OrthoProj (aLeft, aRight, aBot, aTop, aZNear, aZFar, theMatrices.MProjection); break; case Projection_Perspective : - PerspectiveProj (aLeft, aRight, aBot, aTop, aZNear, aZFar, *theMatrices.MProjection); + PerspectiveProj (aLeft, aRight, aBot, aTop, aZNear, aZFar, theMatrices.MProjection); break; case Projection_MonoLeftEye : { StereoEyeProj (aLeft, aRight, aBot, aTop, aZNear, aZFar, aIOD, aFocus, - Standard_True, *theMatrices.MProjection); - *theMatrices.LProjection = *theMatrices.MProjection; + Standard_True, theMatrices.MProjection); + theMatrices.LProjection = theMatrices.MProjection; break; } @@ -874,24 +876,24 @@ Graphic3d_Camera::TransformMatrices& { StereoEyeProj (aLeft, aRight, aBot, aTop, aZNear, aZFar, aIOD, aFocus, - Standard_False, *theMatrices.MProjection); - *theMatrices.RProjection = *theMatrices.MProjection; + Standard_False, theMatrices.MProjection); + theMatrices.RProjection = theMatrices.MProjection; break; } case Projection_Stereo : { - PerspectiveProj (aLeft, aRight, aBot, aTop, aZNear, aZFar, *theMatrices.MProjection); + PerspectiveProj (aLeft, aRight, aBot, aTop, aZNear, aZFar, theMatrices.MProjection); StereoEyeProj (aLeft, aRight, aBot, aTop, aZNear, aZFar, aIOD, aFocus, Standard_True, - *theMatrices.LProjection); + theMatrices.LProjection); StereoEyeProj (aLeft, aRight, aBot, aTop, aZNear, aZFar, aIOD, aFocus, Standard_False, - *theMatrices.RProjection); + theMatrices.RProjection); break; } } @@ -930,7 +932,7 @@ Graphic3d_Camera::TransformMatrices& static_cast (myAxialScale.Y()), static_cast (myAxialScale.Z())); - LookOrientation (anEye, aCenter, anUp, anAxialScale, *theMatrices.Orientation); + LookOrientation (anEye, aCenter, anUp, anAxialScale, theMatrices.Orientation); return theMatrices; // for inline accessors } diff --git a/src/Graphic3d/Graphic3d_Camera.hxx b/src/Graphic3d/Graphic3d_Camera.hxx index fe9e44b658..bc710d3230 100644 --- a/src/Graphic3d/Graphic3d_Camera.hxx +++ b/src/Graphic3d/Graphic3d_Camera.hxx @@ -22,8 +22,6 @@ #include #include -#include - #include #include @@ -45,46 +43,50 @@ private: template struct TransformMatrices { + + //! Default constructor. + TransformMatrices() : myIsOrientationValid (Standard_False), myIsProjectionValid (Standard_False) {} + + //! Initialize orientation. void InitOrientation() { - Orientation = new NCollection_Mat4(); + myIsOrientationValid = Standard_True; + Orientation.InitIdentity(); } + //! Initialize projection. void InitProjection() { - MProjection = new NCollection_Mat4(); - LProjection = new NCollection_Mat4(); - RProjection = new NCollection_Mat4(); + myIsProjectionValid = Standard_True; + MProjection.InitIdentity(); + LProjection.InitIdentity(); + RProjection.InitIdentity(); } - void ResetOrientation() - { - Orientation.Nullify(); - } + //! Invalidate orientation. + void ResetOrientation() { myIsOrientationValid = Standard_False; } - void ResetProjection() - { - MProjection.Nullify(); - LProjection.Nullify(); - RProjection.Nullify(); - } + //! Invalidate projection. + void ResetProjection() { myIsProjectionValid = Standard_False; } - Standard_Boolean IsOrientationValid() - { - return !Orientation.IsNull(); - } + //! Return true if Orientation was not invalidated. + Standard_Boolean IsOrientationValid() const { return myIsOrientationValid; } - Standard_Boolean IsProjectionValid() - { - return !MProjection.IsNull() && - !LProjection.IsNull() && - !RProjection.IsNull(); - } + //! Return true if Projection was not invalidated. + Standard_Boolean IsProjectionValid() const { return myIsProjectionValid; } + + public: + + NCollection_Mat4 Orientation; + NCollection_Mat4 MProjection; + NCollection_Mat4 LProjection; + NCollection_Mat4 RProjection; + + private: + + Standard_Boolean myIsOrientationValid; + Standard_Boolean myIsProjectionValid; - NCollection_Handle< NCollection_Mat4 > Orientation; - NCollection_Handle< NCollection_Mat4 > MProjection; - NCollection_Handle< NCollection_Mat4 > LProjection; - NCollection_Handle< NCollection_Mat4 > RProjection; }; public: @@ -637,6 +639,7 @@ private: Projection myProjType; //!< Projection type used for rendering. Standard_Real myFOVy; //!< Field Of View in y axis. + Standard_Real myFOVyTan; //!< Field Of View as Tan(DTR_HALF * myFOVy) Standard_Real myZNear; //!< Distance to near clipping plane. Standard_Real myZFar; //!< Distance to far clipping plane. Standard_Real myAspect; //!< Width to height display ratio. diff --git a/src/Graphic3d/Graphic3d_Structure.cxx b/src/Graphic3d/Graphic3d_Structure.cxx index c08ed0258f..1c51cef632 100644 --- a/src/Graphic3d/Graphic3d_Structure.cxx +++ b/src/Graphic3d/Graphic3d_Structure.cxx @@ -1103,46 +1103,14 @@ Standard_Integer Graphic3d_Structure::Identification() const //function : SetTransformPersistence //purpose : //============================================================================= -void Graphic3d_Structure::SetTransformPersistence (const Graphic3d_TransModeFlags& theFlag) +void Graphic3d_Structure::SetTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers) { - SetTransformPersistence (theFlag, gp_Pnt (0.0, 0.0, 0.0)); -} - -//============================================================================= -//function : SetTransformPersistence -//purpose : -//============================================================================= -void Graphic3d_Structure::SetTransformPersistence (const Graphic3d_TransModeFlags& theFlag, - const gp_Pnt& thePoint) -{ - if (IsDeleted()) return; - - myCStructure->TransformPersistence.Flags = theFlag; - myCStructure->TransformPersistence.Point.x() = thePoint.X(); - myCStructure->TransformPersistence.Point.y() = thePoint.Y(); - myCStructure->TransformPersistence.Point.z() = thePoint.Z(); -} - -//============================================================================= -//function : TransformPersistenceMode -//purpose : -//============================================================================= -Graphic3d_TransModeFlags Graphic3d_Structure::TransformPersistenceMode() const -{ - return myCStructure->TransformPersistence.Flags; -} + if (IsDeleted()) + { + return; + } -//============================================================================= -//function : TransformPersistencePoint -//purpose : -//============================================================================= -gp_Pnt Graphic3d_Structure::TransformPersistencePoint() const -{ - gp_Pnt aPnt (0.0, 0.0, 0.0); - aPnt.SetX (myCStructure->TransformPersistence.Point.x()); - aPnt.SetY (myCStructure->TransformPersistence.Point.y()); - aPnt.SetZ (myCStructure->TransformPersistence.Point.z()); - return aPnt; + myCStructure->SetTransformPersistence (theTrsfPers); } //============================================================================= diff --git a/src/Graphic3d/Graphic3d_Structure.hxx b/src/Graphic3d/Graphic3d_Structure.hxx index 5bf3474d05..e99a3f6882 100644 --- a/src/Graphic3d/Graphic3d_Structure.hxx +++ b/src/Graphic3d/Graphic3d_Structure.hxx @@ -377,20 +377,12 @@ public: //! Returns the transformation associated with //! the structure . Standard_EXPORT void Transform (TColStd_Array2OfReal& AMatrix) const; - - //! Modifies the current modelling transform persistence (pan, zoom or rotate) - Standard_EXPORT void SetTransformPersistence (const Graphic3d_TransModeFlags& AFlag, const gp_Pnt& APoint); - - Standard_EXPORT void SetTransformPersistence (const Graphic3d_TransModeFlags& AFlag); - - //! Get the current modelling transform persistence (pan, zoom or rotate) - Standard_EXPORT Graphic3d_TransModeFlags TransformPersistenceMode() const; - - //! Get the current point of relative modelling transform persistence - Standard_EXPORT gp_Pnt TransformPersistencePoint() const; + + //! Modifies the current transform persistence (pan, zoom or rotate) + Standard_EXPORT void SetTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers); //! @return transform persistence of the presentable object. - const Graphic3d_TransformPers& TransformPersistence() const; + const Handle(Graphic3d_TransformPers)& TransformPersistence() const { return myCStructure->TransformPersistence(); } //! Sets if the structure location has mutable nature (content or location will be changed regularly). Standard_EXPORT void SetMutable (const Standard_Boolean theIsMutable); @@ -439,7 +431,7 @@ public: Standard_EXPORT static Graphic3d_Vertex Transforms (const TColStd_Array2OfReal& ATrsf, const Graphic3d_Vertex& Coord); //! Returns the low-level structure - const Handle(Graphic3d_CStructure)& CStructure() const; + const Handle(Graphic3d_CStructure)& CStructure() const { return myCStructure; } friend class Graphic3d_Group; @@ -505,14 +497,6 @@ protected: Standard_Address myOwner; Graphic3d_TypeOfStructure myVisual; - }; - -#include - - - - - #endif // _Graphic3d_Structure_HeaderFile diff --git a/src/Graphic3d/Graphic3d_Structure.lxx b/src/Graphic3d/Graphic3d_Structure.lxx deleted file mode 100644 index 7fd5ec20b0..0000000000 --- a/src/Graphic3d/Graphic3d_Structure.lxx +++ /dev/null @@ -1,32 +0,0 @@ -// Created on: 2014-03-23 -// Created by: Kirill Gavrilov -// Copyright (c) 2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -// ======================================================================= -// function : CStructure -// purpose : Returns the low-level structure -// ======================================================================= -inline const Handle(Graphic3d_CStructure)& Graphic3d_Structure::CStructure() const -{ - return myCStructure; -} - -// ======================================================================= -// function : TransformPersistence -// purpose : -// ======================================================================= -inline const Graphic3d_TransformPers& Graphic3d_Structure::TransformPersistence() const -{ - return myCStructure->TransformPersistence; -} diff --git a/src/Graphic3d/Graphic3d_TransModeFlags.hxx b/src/Graphic3d/Graphic3d_TransModeFlags.hxx index f7e2512f1c..550851f896 100644 --- a/src/Graphic3d/Graphic3d_TransModeFlags.hxx +++ b/src/Graphic3d/Graphic3d_TransModeFlags.hxx @@ -16,17 +16,16 @@ #ifndef Graphic3d_TRANS_MODE_FLAGS_HXX #define Graphic3d_TRANS_MODE_FLAGS_HXX -typedef Standard_Integer Graphic3d_TransModeFlags; - -enum { - Graphic3d_TMF_None = 0x0000, - Graphic3d_TMF_PanPers = 0x0001, - Graphic3d_TMF_ZoomPers = 0x0002, - Graphic3d_TMF_RotatePers = 0x0008, - Graphic3d_TMF_TriedronPers = 0x0020, - Graphic3d_TMF_2d = 0x0040, - Graphic3d_TMF_FullPers = Graphic3d_TMF_PanPers | Graphic3d_TMF_ZoomPers | Graphic3d_TMF_RotatePers +//! Transform Persistence Mode defining whether to lock in object position, rotation and / or zooming relative to camera position. +enum Graphic3d_TransModeFlags +{ + Graphic3d_TMF_None = 0x0000, //!< no persistence attributes (normal 3D object) + Graphic3d_TMF_ZoomPers = 0x0002, //!< object does not resize + Graphic3d_TMF_RotatePers = 0x0008, //!< object does not rotate; + Graphic3d_TMF_TriedronPers = 0x0020, //!< object behaves like trihedron - it is fixed at the corner of view and does not resizing (but rotating) + Graphic3d_TMF_2d = 0x0040, //!< object is defined in 2D screen coordinates (pixels) and does not resize, pan and rotate + Graphic3d_TMF_ZoomRotatePers = Graphic3d_TMF_ZoomPers + | Graphic3d_TMF_RotatePers //!< object doesn't resize and rotate }; - #endif diff --git a/src/Graphic3d/Graphic3d_TransformPers.cxx b/src/Graphic3d/Graphic3d_TransformPers.cxx new file mode 100644 index 0000000000..d171a7d890 --- /dev/null +++ b/src/Graphic3d/Graphic3d_TransformPers.cxx @@ -0,0 +1,53 @@ +// Copyright (c) 2016 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include + +IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_TransformPers, Standard_Transient) + +// ======================================================================= +// function : FromDeprecatedParams +// purpose : +// ======================================================================= +Handle(Graphic3d_TransformPers) Graphic3d_TransformPers::FromDeprecatedParams (Graphic3d_TransModeFlags theFlag, + const gp_Pnt& thePoint) +{ + Handle(Graphic3d_TransformPers) aTrsfPers; + if (Graphic3d_TransformPers::IsZoomOrRotate (theFlag)) + { + aTrsfPers = new Graphic3d_TransformPers (theFlag, thePoint); + } + else if (Graphic3d_TransformPers::IsTrihedronOr2d (theFlag)) + { + Standard_Integer aCorner = Aspect_TOTP_CENTER; + const Graphic3d_Vec2i anOffset (Standard_Integer(thePoint.Z()), Standard_Integer(thePoint.Z())); + if (thePoint.X() > 0.0) + { + aCorner |= Aspect_TOTP_RIGHT; + } + else if (thePoint.X() < 0.0) + { + aCorner |= Aspect_TOTP_LEFT; + } + if (thePoint.Y() > 0.0) + { + aCorner |= Aspect_TOTP_TOP; + } + else if (thePoint.Y() < 0.0) + { + aCorner |= Aspect_TOTP_BOTTOM; + } + aTrsfPers = new Graphic3d_TransformPers (theFlag, Aspect_TypeOfTriedronPosition(aCorner), anOffset); + } + return aTrsfPers; +} diff --git a/src/Graphic3d/Graphic3d_TransformPers.hxx b/src/Graphic3d/Graphic3d_TransformPers.hxx index 3ad72c1ee2..7e6afc6c41 100644 --- a/src/Graphic3d/Graphic3d_TransformPers.hxx +++ b/src/Graphic3d/Graphic3d_TransformPers.hxx @@ -16,31 +16,197 @@ #ifndef _Graphic3d_TransformPers_HeaderFile #define _Graphic3d_TransformPers_HeaderFile +#include #include #include #include #include #include +#include #include -#include + +DEFINE_STANDARD_HANDLE(Graphic3d_TransformPers, Standard_Transient) //! Class for keeping and computing transformation persistence. -class Graphic3d_TransformPers +//! Note that instance of this class can not define +//! no transformation persistence Graphic3d_TMF_None - NULL handle should be used for this purpose. +class Graphic3d_TransformPers : public Standard_Transient { + DEFINE_STANDARD_RTTIEXT(Graphic3d_TransformPers, Standard_Transient) public: - DEFINE_STANDARD_ALLOC + //! Return true if specified mode is zoom/rotate transformation persistence. + static Standard_Boolean IsZoomOrRotate (Graphic3d_TransModeFlags theMode) + { + return (theMode & (Graphic3d_TMF_ZoomPers | Graphic3d_TMF_RotatePers)) != 0; + } + + //! Return true if specified mode is 2d/trihedron transformation persistence. + static Standard_Boolean IsTrihedronOr2d (Graphic3d_TransModeFlags theMode) + { + return (theMode & (Graphic3d_TMF_TriedronPers | Graphic3d_TMF_2d)) != 0; + } - //! Default constructor. - Graphic3d_TransformPers() - : Flags (Graphic3d_TMF_None), - Point (0.0, 0.0, 0.0) {} + //! Create Graphic3d_TransformPers instance from deprecated parameters set + //! decoding 2D corner + offset parameters from 3D point. + Standard_EXPORT static Handle(Graphic3d_TransformPers) FromDeprecatedParams (Graphic3d_TransModeFlags theFlag, + const gp_Pnt& thePoint); + +public: + + //! Set transformation persistence. + Graphic3d_TransformPers (const Graphic3d_TransModeFlags theMode) + : myMode (theMode) + { + if (IsZoomOrRotate (theMode)) + { + SetPersistence (theMode, gp_Pnt(0.0, 0.0, 0.0)); + } + else if (IsTrihedronOr2d (theMode)) + { + SetPersistence (theMode, Aspect_TOTP_LEFT_LOWER, Graphic3d_Vec2i (0, 0)); + } + else + { + Standard_ProgramError::Raise ("Graphic3d_TransformPers::SetPersistence(), wrong persistence mode."); + } + } + + //! Set Zoom/Rotate transformation persistence with an anchor 3D point. + //! Throws an exception if persistence mode is not Graphic3d_TMF_ZoomPers, Graphic3d_TMF_ZoomRotatePers or Graphic3d_TMF_RotatePers. + Graphic3d_TransformPers (const Graphic3d_TransModeFlags theMode, + const gp_Pnt& thePnt) + : myMode (Graphic3d_TMF_None) + { + SetPersistence (theMode, thePnt); + } + + //! Set 2d/trihedron transformation persistence with a corner and 2D offset. + //! Throws an exception if persistence mode is not Graphic3d_TMF_TriedronPers or Graphic3d_TMF_2d. + //! The offset is a positive displacement from the view corner in pixels. + Graphic3d_TransformPers (const Graphic3d_TransModeFlags theMode, + const Aspect_TypeOfTriedronPosition theCorner, + const Graphic3d_Vec2i& theOffset = Graphic3d_Vec2i (0, 0)) + : myMode (Graphic3d_TMF_None) + { + SetPersistence (theMode, theCorner, theOffset); + } + + //! Return true for Graphic3d_TMF_ZoomPers, Graphic3d_TMF_ZoomRotatePers or Graphic3d_TMF_RotatePers modes. + Standard_Boolean IsZoomOrRotate() const { return IsZoomOrRotate (myMode); } + + //! Return true for Graphic3d_TMF_TriedronPers and Graphic3d_TMF_2d modes. + Standard_Boolean IsTrihedronOr2d() const { return IsTrihedronOr2d (myMode); } //! Transformation persistence mode flags. - Graphic3d_TransModeFlags Flags; + Graphic3d_TransModeFlags Mode() const { return myMode; } - //! Reference point for transformation. - Graphic3d_Vec3d Point; + //! Transformation persistence mode flags. + Graphic3d_TransModeFlags Flags() const { return myMode; } + + //! Set Zoom/Rotate transformation persistence with an anchor 3D point. + //! Throws an exception if persistence mode is not Graphic3d_TMF_ZoomPers, Graphic3d_TMF_ZoomRotatePers or Graphic3d_TMF_RotatePers. + void SetPersistence (const Graphic3d_TransModeFlags theMode, + const gp_Pnt& thePnt) + { + if (!IsZoomOrRotate (theMode)) + { + Standard_ProgramError::Raise ("Graphic3d_TransformPers::SetPersistence(), wrong persistence mode."); + } + + myMode = theMode; + myParams.Params3d.PntX = thePnt.X(); + myParams.Params3d.PntY = thePnt.Y(); + myParams.Params3d.PntZ = thePnt.Z(); + } + + //! Set 2d/trihedron transformation persistence with a corner and 2D offset. + //! Throws an exception if persistence mode is not Graphic3d_TMF_TriedronPers or Graphic3d_TMF_2d. + void SetPersistence (const Graphic3d_TransModeFlags theMode, + const Aspect_TypeOfTriedronPosition theCorner, + const Graphic3d_Vec2i& theOffset) + { + if (!IsTrihedronOr2d (theMode)) + { + Standard_ProgramError::Raise ("Graphic3d_TransformPers::SetPersistence(), wrong persistence mode."); + } + + myMode = theMode; + myParams.Params2d.Corner = theCorner; + myParams.Params2d.OffsetX = theOffset.x(); + myParams.Params2d.OffsetY = theOffset.y(); + } + +public: + + //! Return the anchor point for zoom/rotate transformation persistence. + gp_Pnt AnchorPoint() const + { + if (!IsZoomOrRotate()) + { + Standard_ProgramError::Raise ("Graphic3d_TransformPers::AnchorPoint(), wrong persistence mode."); + } + + return gp_Pnt (myParams.Params3d.PntX, myParams.Params3d.PntY, myParams.Params3d.PntZ); + } + + //! Set the anchor point for zoom/rotate transformation persistence. + void SetAnchorPoint (const gp_Pnt& thePnt) + { + if (!IsZoomOrRotate()) + { + Standard_ProgramError::Raise ("Graphic3d_TransformPers::SetAnchorPoint(), wrong persistence mode."); + } + + myParams.Params3d.PntX = thePnt.X(); + myParams.Params3d.PntY = thePnt.Y(); + myParams.Params3d.PntZ = thePnt.Z(); + } + + //! Return the corner for 2d/trihedron transformation persistence. + Aspect_TypeOfTriedronPosition Corner2d() const + { + if (!IsTrihedronOr2d()) + { + Standard_ProgramError::Raise ("Graphic3d_TransformPers::Corner2d(), wrong persistence mode."); + } + + return myParams.Params2d.Corner; + } + + //! Set the corner for 2d/trihedron transformation persistence. + void SetCorner2d (const Aspect_TypeOfTriedronPosition thePos) + { + if (!IsTrihedronOr2d()) + { + Standard_ProgramError::Raise ("Graphic3d_TransformPers::SetCorner2d(), wrong persistence mode."); + } + + myParams.Params2d.Corner = thePos; + } + + //! Return the offset from the corner for 2d/trihedron transformation persistence. + Graphic3d_Vec2i Offset2d() const + { + if (!IsTrihedronOr2d()) + { + Standard_ProgramError::Raise ("Graphic3d_TransformPers::Offset2d(), wrong persistence mode."); + } + + return Graphic3d_Vec2i (myParams.Params2d.OffsetX, myParams.Params2d.OffsetY); + } + + //! Set the offset from the corner for 2d/trihedron transformation persistence. + void SetOffset2d (const Graphic3d_Vec2i& theOffset) + { + if (!IsTrihedronOr2d()) + { + Standard_ProgramError::Raise ("Graphic3d_TransformPers::SetOffset2d(), wrong persistence mode."); + } + + myParams.Params2d.OffsetX = theOffset.x(); + myParams.Params2d.OffsetY = theOffset.y(); + } public: @@ -98,16 +264,37 @@ public: //! @param theViewportHeight viewport height template void Apply (const Handle(Graphic3d_Camera)& theCamera, - NCollection_Mat4& theProjection, + const NCollection_Mat4& theProjection, NCollection_Mat4& theWorldView, const Standard_Integer theViewportWidth, const Standard_Integer theViewportHeight) const; - //! Return true if transformation persistence alters projection matrix. - bool AltersProjectionMatrix() const +private: + + //! 3D anchor point for zoom/rotate transformation persistence. + struct PersParams3d { - return (Flags & Graphic3d_TMF_PanPers) != 0; - } + Standard_Real PntX; + Standard_Real PntY; + Standard_Real PntZ; + }; + + //! 2d/trihedron transformation persistence parameters. + struct PersParams2d + { + Standard_Integer OffsetX; + Standard_Integer OffsetY; + Aspect_TypeOfTriedronPosition Corner; + }; + +private: + + Graphic3d_TransModeFlags myMode; //!< Transformation persistence mode flags + union + { + PersParams3d Params3d; + PersParams2d Params2d; + } myParams; }; @@ -117,20 +304,26 @@ public: // ======================================================================= template void Graphic3d_TransformPers::Apply (const Handle(Graphic3d_Camera)& theCamera, - NCollection_Mat4& theProjection, + const NCollection_Mat4& theProjection, NCollection_Mat4& theWorldView, const Standard_Integer theViewportWidth, const Standard_Integer theViewportHeight) const { (void )theViewportWidth; - if (Flags == Graphic3d_TMF_None + (void )theProjection; + if (myMode == Graphic3d_TMF_None || theViewportHeight == 0) { return; } + // use total size when tiling is active const Standard_Integer aVPSizeY = theCamera->Tile().IsValid() ? theCamera->Tile().TotalSize.y() : theViewportHeight; - if (Flags == Graphic3d_TMF_TriedronPers) + + // a small enough jitter compensation offset + // to avoid image dragging within single pixel in corner cases + const Standard_Real aJitterComp = 0.001; + if (myMode == Graphic3d_TMF_TriedronPers) { // reset Z focus for trihedron persistence const Standard_Real aFocus = theCamera->IsOrthographic() @@ -142,41 +335,43 @@ void Graphic3d_TransformPers::Apply (const Handle(Graphic3d_Camera)& theCamera, // scale factor to pixels const gp_XYZ aViewDim = theCamera->ViewDimensions (aFocus); const Standard_Real aScale = Abs(aViewDim.Y()) / Standard_Real(aVPSizeY); - - // offset from the corner - const Standard_Real anOffset = Point.z() * aScale; - const gp_Dir aForward (theCamera->Center().XYZ() - theCamera->Eye().XYZ()); gp_XYZ aCenter = theCamera->Center().XYZ() + aForward.XYZ() * (aFocus - theCamera->Distance()); - if (Point.x() != 0.0) + if ((myParams.Params2d.Corner & (Aspect_TOTP_LEFT | Aspect_TOTP_RIGHT)) != 0) { - const gp_Dir aSide = aForward.Crossed (theCamera->Up()); - if (Point.x() > 0.0) + const Standard_Real anOffsetX = (Standard_Real(myParams.Params2d.OffsetX) + aJitterComp) * aScale; + const gp_Dir aSide = aForward.Crossed (theCamera->Up()); + const gp_XYZ aDeltaX = aSide.XYZ() * (Abs(aViewDim.X()) * 0.5 - anOffsetX); + if ((myParams.Params2d.Corner & Aspect_TOTP_RIGHT) != 0) { - aCenter += aSide.XYZ() * (Abs(aViewDim.X()) * 0.5 - anOffset); + aCenter += aDeltaX; } else { - aCenter -= aSide.XYZ() * (Abs(aViewDim.X()) * 0.5 - anOffset); + aCenter -= aDeltaX; } } - if (Point.y() != 0.0) + if ((myParams.Params2d.Corner & (Aspect_TOTP_TOP | Aspect_TOTP_BOTTOM)) != 0) { - if (Point.y() > 0.0) + const Standard_Real anOffsetY = (Standard_Real(myParams.Params2d.OffsetY) + aJitterComp) * aScale; + const gp_XYZ aDeltaY = theCamera->Up().XYZ() * (Abs(aViewDim.Y()) * 0.5 - anOffsetY); + if ((myParams.Params2d.Corner & Aspect_TOTP_TOP) != 0) { - aCenter += theCamera->Up().XYZ() * (Abs(aViewDim.Y()) * 0.5 - anOffset); + aCenter += aDeltaY; } else { - aCenter -= theCamera->Up().XYZ() * (Abs(aViewDim.Y()) * 0.5 - anOffset); + aCenter -= aDeltaY; } } - Graphic3d_TransformUtils::Translate (theWorldView, T(aCenter.X()), T(aCenter.Y()), T(aCenter.Z())); - Graphic3d_TransformUtils::Scale (theWorldView, T(aScale), T(aScale), T(aScale)); + NCollection_Mat4 aWorldView = theCamera->OrientationMatrix(); + Graphic3d_TransformUtils::Translate (aWorldView, aCenter.X(), aCenter.Y(), aCenter.Z()); + Graphic3d_TransformUtils::Scale (aWorldView, aScale, aScale, aScale); + theWorldView.ConvertFrom (aWorldView); return; } - else if (Flags == Graphic3d_TMF_2d) + else if (myMode == Graphic3d_TMF_2d) { const Standard_Real aFocus = theCamera->IsOrthographic() ? theCamera->Distance() @@ -188,18 +383,18 @@ void Graphic3d_TransformPers::Apply (const Handle(Graphic3d_Camera)& theCamera, const gp_XYZ aViewDim = theCamera->ViewDimensions (aFocus); const Standard_Real aScale = Abs(aViewDim.Y()) / Standard_Real(aVPSizeY); gp_XYZ aCenter (0.0, 0.0, -aFocus); - if (Point.x() != 0.0) + if ((myParams.Params2d.Corner & (Aspect_TOTP_LEFT | Aspect_TOTP_RIGHT)) != 0) { - aCenter.SetX (-aViewDim.X() * 0.5 + Point.z() * aScale); - if (Point.x() > 0.0) + aCenter.SetX (-aViewDim.X() * 0.5 + (Standard_Real(myParams.Params2d.OffsetX) + aJitterComp) * aScale); + if ((myParams.Params2d.Corner & Aspect_TOTP_RIGHT) != 0) { aCenter.SetX (-aCenter.X()); } } - if (Point.y() != 0.0) + if ((myParams.Params2d.Corner & (Aspect_TOTP_TOP | Aspect_TOTP_BOTTOM)) != 0) { - aCenter.SetY (-aViewDim.Y() * 0.5 + Point.z() * aScale); - if (Point.y() > 0.0) + aCenter.SetY (-aViewDim.Y() * 0.5 + (Standard_Real(myParams.Params2d.OffsetY) + aJitterComp) * aScale); + if ((myParams.Params2d.Corner & Aspect_TOTP_TOP) != 0) { aCenter.SetY (-aCenter.Y()); } @@ -210,92 +405,42 @@ void Graphic3d_TransformPers::Apply (const Handle(Graphic3d_Camera)& theCamera, Graphic3d_TransformUtils::Scale (theWorldView, T(aScale), T(aScale), T(aScale)); return; } - + else { // Compute reference point for transformation in untransformed projection space. - NCollection_Vec4 aRefPoint (static_cast (Point.x()), - static_cast (Point.y()), - static_cast (Point.z()), + NCollection_Vec4 aRefPoint (static_cast (myParams.Params3d.PntX), + static_cast (myParams.Params3d.PntY), + static_cast (myParams.Params3d.PntZ), static_cast (1.0)); - NCollection_Vec4 aRefPointProj; - if ((Flags & Graphic3d_TMF_PanPers) != Graphic3d_TMF_PanPers) - { - aRefPointProj = theProjection * (theWorldView * aRefPoint); - aRefPointProj /= aRefPointProj.w(); - } - - // Prevent zooming. - if ((Flags & Graphic3d_TMF_ZoomPers) != 0) - { - const T aSize = static_cast (1.0); - const Standard_Integer aViewport[4] = { 0, 0, theViewportHeight, theViewportHeight }; - NCollection_Mat4 aWorldView; - aWorldView.InitIdentity(); - - NCollection_Vec3 aWinCoordsRefPoint; - Graphic3d_TransformUtils::Project (static_cast (Point.x()), - static_cast (Point.y()), - static_cast (Point.z()), - theWorldView, theProjection, aViewport, - aWinCoordsRefPoint.x(), aWinCoordsRefPoint.y(), aWinCoordsRefPoint.z()); - - NCollection_Vec3 anUnProj1; - Graphic3d_TransformUtils::UnProject (aWinCoordsRefPoint.x(), aWinCoordsRefPoint.y(), aWinCoordsRefPoint.z(), - aWorldView, theProjection, aViewport, - anUnProj1.x(), anUnProj1.y(), anUnProj1.z()); - - NCollection_Vec3 anUnProj2; - Graphic3d_TransformUtils::UnProject (aWinCoordsRefPoint.x(), aWinCoordsRefPoint.y() + aSize, aWinCoordsRefPoint.z(), - aWorldView, theProjection, aViewport, - anUnProj2.x(), anUnProj2.y(), anUnProj2.z()); - - const T aScale = (anUnProj2.y() - anUnProj1.y()) / aSize; - - Graphic3d_TransformUtils::Scale (theWorldView, aScale, aScale, aScale); - } - - // Prevent translation by nullifying translation component. - if ((Flags & Graphic3d_TMF_PanPers) != 0) - { - theWorldView .SetValue (0, 3, static_cast (0.0)); - theWorldView .SetValue (1, 3, static_cast (0.0)); - theWorldView .SetValue (2, 3, static_cast (0.0)); - theProjection.SetValue (0, 3, static_cast (0.0)); - theProjection.SetValue (1, 3, static_cast (0.0)); - theProjection.SetValue (2, 3, static_cast (0.0)); - } - // Prevent rotation by nullifying rotation component. - if (Flags & Graphic3d_TMF_RotatePers) + Graphic3d_TransformUtils::Translate (theWorldView, aRefPoint.x(), aRefPoint.y(), aRefPoint.z()); + if ((myMode & Graphic3d_TMF_RotatePers) != 0) { - theWorldView.SetValue (0, 0, static_cast (1.0)); - theWorldView.SetValue (1, 0, static_cast (0.0)); - theWorldView.SetValue (2, 0, static_cast (0.0)); - - theWorldView.SetValue (0, 1, static_cast (0.0)); - theWorldView.SetValue (1, 1, static_cast (1.0)); - theWorldView.SetValue (2, 1, static_cast (0.0)); - - theWorldView.SetValue (0, 2, static_cast (0.0)); - theWorldView.SetValue (1, 2, static_cast (0.0)); - theWorldView.SetValue (2, 2, static_cast (1.0)); + // lock rotation by nullifying rotation component + theWorldView.SetValue (0, 0, static_cast (1)); + theWorldView.SetValue (1, 0, static_cast (0)); + theWorldView.SetValue (2, 0, static_cast (0)); + + theWorldView.SetValue (0, 1, static_cast (0)); + theWorldView.SetValue (1, 1, static_cast (1)); + theWorldView.SetValue (2, 1, static_cast (0)); + + theWorldView.SetValue (0, 2, static_cast (0)); + theWorldView.SetValue (1, 2, static_cast (0)); + theWorldView.SetValue (2, 2, static_cast (1)); } - if ((Flags & Graphic3d_TMF_PanPers) != Graphic3d_TMF_PanPers) + if ((myMode & Graphic3d_TMF_ZoomPers) != 0) { - NCollection_Mat4 anUnviewMat; - - if (!(theProjection * theWorldView).Inverted (anUnviewMat)) - { - Standard_ProgramError::Raise ("Graphic3d_TransformPers::Apply, can not inverse world view projection matrix."); - } - - // Move to reference point location in transformed view projection space. - aRefPoint = anUnviewMat * aRefPointProj; - aRefPoint /= aRefPoint.w(); - - Graphic3d_TransformUtils::Translate (theWorldView, aRefPoint.x(), aRefPoint.y(), aRefPoint.z()); + // lock zooming + gp_Vec aVecToEye (theCamera->Direction()); + gp_Vec aVecToObj (theCamera->Eye(), gp_Pnt (myParams.Params3d.PntX, myParams.Params3d.PntY, myParams.Params3d.PntZ)); + const Standard_Real aFocus = aVecToObj.Dot (aVecToEye); + const gp_XYZ aViewDim = theCamera->ViewDimensions (aFocus); + const Standard_Real aScale = Abs(aViewDim.Y()) / Standard_Real(aVPSizeY); + Graphic3d_TransformUtils::Scale (theWorldView, T(aScale), T(aScale), T(aScale)); } + return; } } @@ -384,26 +529,13 @@ NCollection_Mat4 Graphic3d_TransformPers::Compute (const Handle(Graphic3d_Cam const Standard_Integer theViewportWidth, const Standard_Integer theViewportHeight) const { - if (Flags == Graphic3d_TMF_None) + if (myMode == Graphic3d_TMF_None) { return NCollection_Mat4(); } - NCollection_Mat4 aProjection (theProjection); - NCollection_Mat4 aWorldView (theWorldView); + NCollection_Mat4 aWorldView (theWorldView); NCollection_Mat4 anUnviewMat; - if (AltersProjectionMatrix()) - { - // destructive transformation persistence which directly modifies projection matrix - if (!(theProjection * theWorldView).Inverted (anUnviewMat)) - { - return NCollection_Mat4(); - } - - Apply (theCamera, aProjection, aWorldView, theViewportWidth, theViewportHeight); - return anUnviewMat * (aProjection * aWorldView); - } - if (!theWorldView.Inverted (anUnviewMat)) { return NCollection_Mat4(); @@ -411,7 +543,7 @@ NCollection_Mat4 Graphic3d_TransformPers::Compute (const Handle(Graphic3d_Cam // compute only world-view matrix difference to avoid floating point instability // caused by projection matrix modifications outside of this algorithm (e.g. by Z-fit) - Apply (theCamera, aProjection, aWorldView, theViewportWidth, theViewportHeight); + Apply (theCamera, theProjection, aWorldView, theViewportWidth, theViewportHeight); return anUnviewMat * aWorldView; } diff --git a/src/MeshVS/MeshVS_Mesh.cxx b/src/MeshVS/MeshVS_Mesh.cxx index e8fb5be733..a1a911cf20 100644 --- a/src/MeshVS/MeshVS_Mesh.cxx +++ b/src/MeshVS/MeshVS_Mesh.cxx @@ -929,7 +929,7 @@ void MeshVS_Mesh::HilightSelected ( const Handle(PrsMgr_PresentationManager3d)& aSelectionPrs = GetSelectPresentation( thePM ); if( HasPresentation() ) - aSelectionPrs->SetTransformPersistence( Presentation()->TransformPersistenceMode(), Presentation()->TransformPersistencePoint() ); + aSelectionPrs->SetTransformPersistence (Presentation()->TransformPersistence()); //---------------- // It is very important to call this parent method, because it check whether @@ -1083,7 +1083,7 @@ void MeshVS_Mesh::HilightOwnerWithColor ( const Handle(PrsMgr_PresentationManage //new functionality if( HasPresentation() ) - aHilightPrs->SetTransformPersistence( Presentation()->TransformPersistenceMode(), Presentation()->TransformPersistencePoint() ); + aHilightPrs->SetTransformPersistence (Presentation()->TransformPersistence()); //---------------- const Standard_Boolean isMeshEntityOwner = Owner->IsKind ( STANDARD_TYPE ( MeshVS_MeshEntityOwner ) ); diff --git a/src/NCollection/NCollection_Mat4.hxx b/src/NCollection/NCollection_Mat4.hxx index 9481fcf72c..0f74844847 100755 --- a/src/NCollection/NCollection_Mat4.hxx +++ b/src/NCollection/NCollection_Mat4.hxx @@ -410,16 +410,20 @@ public: return true; } - // Converts NCollection_Mat4 with different element type. + //! Take values from NCollection_Mat4 with a different element type with type conversion. template - void Convert (const NCollection_Mat4& theOther) + void ConvertFrom (const NCollection_Mat4& theFrom) { for (int anIdx = 0; anIdx < 16; ++anIdx) { - myMat[anIdx] = static_cast (theOther.myMat[anIdx]); + myMat[anIdx] = static_cast (theFrom.myMat[anIdx]); } } + //! Take values from NCollection_Mat4 with a different element type with type conversion. + template + void Convert (const NCollection_Mat4& theFrom) { ConvertFrom (theFrom); } + //! Maps plain C array to matrix type. static NCollection_Mat4& Map (Element_t* theData) { diff --git a/src/OpenGl/OpenGl_BVHClipPrimitiveTrsfPersSet.cxx b/src/OpenGl/OpenGl_BVHClipPrimitiveTrsfPersSet.cxx index c1c880a37a..158aef24de 100644 --- a/src/OpenGl/OpenGl_BVHClipPrimitiveTrsfPersSet.cxx +++ b/src/OpenGl/OpenGl_BVHClipPrimitiveTrsfPersSet.cxx @@ -155,7 +155,10 @@ const NCollection_Handle >& HBndBox4f aBoundingBox = new Graphic3d_BndBox4f; *aBoundingBox = aStructure->BoundingBox(); - aStructure->TransformPersistence.Apply (theCamera, theProjectionMatrix, theWorldViewMatrix, theViewportWidth, theViewportHeight, *aBoundingBox); + if (!aStructure->TransformPersistence().IsNull()) + { + aStructure->TransformPersistence()->Apply (theCamera, theProjectionMatrix, theWorldViewMatrix, theViewportWidth, theViewportHeight, *aBoundingBox); + } myStructBoxes.Add (aBoundingBox); } diff --git a/src/OpenGl/OpenGl_BackgroundArray.cxx b/src/OpenGl/OpenGl_BackgroundArray.cxx index 0dce18bb4d..b49b4d97a5 100644 --- a/src/OpenGl/OpenGl_BackgroundArray.cxx +++ b/src/OpenGl/OpenGl_BackgroundArray.cxx @@ -27,6 +27,7 @@ // ======================================================================= OpenGl_BackgroundArray::OpenGl_BackgroundArray (const Graphic3d_TypeOfBackground theType) : OpenGl_PrimitiveArray (NULL, Graphic3d_TOPA_TRIANGLESTRIPS, NULL, NULL, NULL), + myTrsfPers (Graphic3d_TMF_2d, theType == Graphic3d_TOB_TEXTURE ? Aspect_TOTP_CENTER : Aspect_TOTP_LEFT_LOWER), myType (theType), myFillMethod (Aspect_FM_NONE), myViewWidth (0), @@ -41,18 +42,6 @@ OpenGl_BackgroundArray::OpenGl_BackgroundArray (const Graphic3d_TypeOfBackground myGradientParams.color1 = OpenGl_Vec4 (0.0f, 0.0f, 0.0f, 1.0f); myGradientParams.color2 = OpenGl_Vec4 (0.0f, 0.0f, 0.0f, 1.0f); myGradientParams.type = Aspect_GFM_NONE; - - myTrsfPers.Flags = Graphic3d_TMF_2d; - if (myType == Graphic3d_TOB_TEXTURE) - { - myTrsfPers.Point.x() = 0.0; - myTrsfPers.Point.y() = 0.0; - } - else - { - myTrsfPers.Point.x() = -1.0; - myTrsfPers.Point.y() = -1.0; - } } // ======================================================================= diff --git a/src/OpenGl/OpenGl_GraduatedTrihedron.cxx b/src/OpenGl/OpenGl_GraduatedTrihedron.cxx index 655043aecc..48469d7ff5 100755 --- a/src/OpenGl/OpenGl_GraduatedTrihedron.cxx +++ b/src/OpenGl/OpenGl_GraduatedTrihedron.cxx @@ -411,12 +411,9 @@ void OpenGl_GraduatedTrihedron::renderAxis (const Handle(OpenGl_Workspace)& theW // Render arrow OpenGl_Vec3 anArrowVec = myMin + anAxis.Direction * (myMax - myMin); - Graphic3d_TransformPers aTransMode; - aTransMode.Flags = Graphic3d_TMF_ZoomPers; - aTransMode.Point.x() = anArrowVec.x(); - aTransMode.Point.y() = anArrowVec.y(); - aTransMode.Point.z() = anArrowVec.z(); - + Graphic3d_TransformPers aTransMode (Graphic3d_TMF_ZoomPers, gp_Pnt (Standard_Real(anArrowVec.x()), + Standard_Real(anArrowVec.y()), + Standard_Real(anArrowVec.z()))); const OpenGl_Mat4& aProjection = aContext->ProjectionState.Current(); const OpenGl_Mat4& aWorldView = aContext->WorldViewState.Current(); const Standard_Integer aWidth = theWorkspace->Width(); diff --git a/src/OpenGl/OpenGl_Layer.cxx b/src/OpenGl/OpenGl_Layer.cxx index 54b9f0f645..e73975b19d 100644 --- a/src/OpenGl/OpenGl_Layer.cxx +++ b/src/OpenGl/OpenGl_Layer.cxx @@ -68,7 +68,7 @@ void OpenGl_Layer::Add (const OpenGl_Structure* theStruct, } else if (!isForChangePriority) { - if (theStruct->TransformPersistence.Flags == Graphic3d_TMF_None) + if (theStruct->TransformPersistence().IsNull()) { myBVHPrimitives.Add (theStruct); } @@ -198,14 +198,15 @@ Graphic3d_BndBox4f OpenGl_Layer::BoundingBox (const Standard_Integer th // "FitAll" operation ignores object with transform persistence parameter // but adds transform persistence point in a bounding box of layer (only zoom pers. objects). - if (aStructure->TransformPersistence.Flags != Graphic3d_TMF_None) + if (!aStructure->TransformPersistence().IsNull()) { if (!theToIncludeAuxiliary - && (aStructure->TransformPersistence.Flags & Graphic3d_TMF_ZoomPers) != 0) + && aStructure->TransformPersistence()->IsZoomOrRotate()) { - BVH_Vec4f aTPPoint (static_cast (aStructure->TransformPersistence.Point.x()), - static_cast (aStructure->TransformPersistence.Point.y()), - static_cast (aStructure->TransformPersistence.Point.z()), + const gp_Pnt anAnchor = aStructure->TransformPersistence()->AnchorPoint(); + BVH_Vec4f aTPPoint (static_cast (anAnchor.X()), + static_cast (anAnchor.Y()), + static_cast (anAnchor.Z()), 1.0f); myBoundingBox[aBoxId].Combine (aTPPoint); @@ -214,7 +215,7 @@ Graphic3d_BndBox4f OpenGl_Layer::BoundingBox (const Standard_Integer th // Panning and 2d persistence apply changes to projection or/and its translation components. // It makes them incompatible with z-fitting algorithm. Ignored by now. else if (!theToIncludeAuxiliary - || (aStructure->TransformPersistence.Flags & (Graphic3d_TMF_2d | Graphic3d_TMF_PanPers | Graphic3d_TMF_TriedronPers)) != 0) + || aStructure->TransformPersistence()->IsTrihedronOr2d()) { continue; } @@ -233,14 +234,9 @@ Graphic3d_BndBox4f OpenGl_Layer::BoundingBox (const Standard_Integer th aBox = centerOfinfiniteBndBox (aBox); } - if (aStructure->TransformPersistence.Flags != Graphic3d_TMF_None) + if (!aStructure->TransformPersistence().IsNull()) { - aStructure->TransformPersistence.Apply (theCamera, - aProjectionMat, - aWorldViewMat, - theWindowWidth, - theWindowHeight, - aBox); + aStructure->TransformPersistence()->Apply (theCamera, aProjectionMat, aWorldViewMat, theWindowWidth, theWindowHeight, aBox); } // skip too big boxes to prevent float overflow at camera parameters calculation @@ -269,7 +265,8 @@ Graphic3d_BndBox4f OpenGl_Layer::BoundingBox (const Standard_Integer th { continue; } - else if ((aStructure->TransformPersistence.Flags & (Graphic3d_TMF_TriedronPers | Graphic3d_TMF_2d)) == 0) + else if (aStructure->TransformPersistence().IsNull() + || !aStructure->TransformPersistence()->IsTrihedronOr2d()) { continue; } @@ -280,12 +277,7 @@ Graphic3d_BndBox4f OpenGl_Layer::BoundingBox (const Standard_Integer th continue; } - aStructure->TransformPersistence.Apply (theCamera, - aProjectionMat, - aWorldViewMat, - theWindowWidth, - theWindowHeight, - aBox); + aStructure->TransformPersistence()->Apply (theCamera, aProjectionMat, aWorldViewMat, theWindowWidth, theWindowHeight, aBox); if (!isInfiniteBndBox (aBox)) { aResBox.Combine (aBox); @@ -321,7 +313,8 @@ Standard_Real OpenGl_Layer::considerZoomPersistenceObjects (const Standard_Integ { OpenGl_Structure* aStructure = const_cast (aStructures.FindKey (aStructIdx)); if (!aStructure->IsVisible (theViewId) - || (aStructure->TransformPersistence.Flags & Graphic3d_TMF_ZoomPers) == 0) + || aStructure->TransformPersistence().IsNull() + || !aStructure->TransformPersistence()->IsZoomOrRotate()) { continue; } @@ -332,7 +325,7 @@ Standard_Real OpenGl_Layer::considerZoomPersistenceObjects (const Standard_Integ continue; } - aStructure->TransformPersistence.Apply (theCamera, aProjectionMat, aWorldViewMat, theWindowWidth, theWindowHeight, aBox); + aStructure->TransformPersistence()->Apply (theCamera, aProjectionMat, aWorldViewMat, theWindowWidth, theWindowHeight, aBox); const BVH_Vec4f& aCornerMin = aBox.CornerMin(); const BVH_Vec4f& aCornerMax = aBox.CornerMax(); @@ -372,9 +365,7 @@ Standard_Real OpenGl_Layer::considerZoomPersistenceObjects (const Standard_Integ continue; } - const gp_Pnt aTPPoint (aStructure->TransformPersistence.Point.x(), - aStructure->TransformPersistence.Point.y(), - aStructure->TransformPersistence.Point.z()); + const gp_Pnt aTPPoint = aStructure->TransformPersistence()->AnchorPoint(); gp_Pnt aConvertedTPPoint = theCamera->Project (aTPPoint); aConvertedTPPoint.SetZ (0.0); @@ -473,7 +464,7 @@ void OpenGl_Layer::updateBVH() const aStruct->MarkAsNotCulled(); myAlwaysRenderedMap.Add (aStruct); } - else if (aStruct->TransformPersistence.Flags == Graphic3d_TMF_None) + else if (aStruct->TransformPersistence().IsNull()) { myBVHPrimitives.Add (aStruct); } diff --git a/src/OpenGl/OpenGl_Structure.cxx b/src/OpenGl/OpenGl_Structure.cxx index 2b1b9e364a..0921824a92 100644 --- a/src/OpenGl/OpenGl_Structure.cxx +++ b/src/OpenGl/OpenGl_Structure.cxx @@ -471,18 +471,14 @@ void OpenGl_Structure::Render (const Handle(OpenGl_Workspace) &theWorkspace) con } #endif - if (TransformPersistence.Flags) + if (!myTrsfPers.IsNull()) { - OpenGl_Mat4 aProjection = aCtx->ProjectionState.Current(); - OpenGl_Mat4 aWorldView = aCtx->WorldViewState.Current(); - TransformPersistence.Apply (theWorkspace->View()->Camera(), aProjection, aWorldView, - aCtx->Viewport()[2], aCtx->Viewport()[3]); + OpenGl_Mat4 aWorldView = aCtx->WorldViewState.Current(); + myTrsfPers->Apply (theWorkspace->View()->Camera(), aCtx->ProjectionState.Current(), aWorldView, + aCtx->Viewport()[2], aCtx->Viewport()[3]); - aCtx->ProjectionState.Push(); aCtx->WorldViewState.Push(); - aCtx->ProjectionState.SetCurrent (aProjection); aCtx->WorldViewState.SetCurrent (aWorldView); - aCtx->ApplyProjectionMatrix(); #if !defined(GL_ES_VERSION_2_0) if (!aCtx->IsGlNormalizeEnabled() @@ -526,8 +522,7 @@ void OpenGl_Structure::Render (const Handle(OpenGl_Workspace) &theWorkspace) con if (aCtx->Clipping().IsClippingOrCappingOn()) { const Graphic3d_BndBox4f& aBBox = BoundingBox(); - if (TransformPersistence.Flags == Graphic3d_TMF_TriedronPers - || TransformPersistence.Flags == Graphic3d_TMF_2d + if ((!myTrsfPers.IsNull() && myTrsfPers->IsTrihedronOr2d()) || (!myClipPlanes.IsNull() && myClipPlanes->ToOverrideGlobal())) { aCtx->ChangeClipping().DisableGlobal (aCtx); @@ -537,7 +532,7 @@ void OpenGl_Structure::Render (const Handle(OpenGl_Workspace) &theWorkspace) con // Set of clipping planes that do not intersect the structure, // and thus can be disabled to improve rendering performance if (aBBox.IsValid() - && TransformPersistence.Flags == Graphic3d_TMF_None) + && myTrsfPers.IsNull()) { for (OpenGl_ClippingIterator aPlaneIt (aCtx->Clipping()); aPlaneIt.More(); aPlaneIt.Next()) { @@ -617,11 +612,9 @@ void OpenGl_Structure::Render (const Handle(OpenGl_Workspace) &theWorkspace) con // Restore local transformation aCtx->ModelWorldState.Pop(); aCtx->SetGlNormalizeEnabled (anOldGlNormalize); - if (TransformPersistence.Flags) + if (!myTrsfPers.IsNull()) { - aCtx->ProjectionState.Pop(); aCtx->WorldViewState.Pop(); - aCtx->ApplyProjectionMatrix(); } // Restore highlight color diff --git a/src/OpenGl/OpenGl_Structure.hxx b/src/OpenGl/OpenGl_Structure.hxx index 68147108cd..ed82a470c5 100644 --- a/src/OpenGl/OpenGl_Structure.hxx +++ b/src/OpenGl/OpenGl_Structure.hxx @@ -145,9 +145,7 @@ public: || IsForHighlight || IsMutable || Is2dText - || (TransformPersistence.Flags & Graphic3d_TMF_2d) != 0 - || (TransformPersistence.Flags & Graphic3d_TMF_PanPers) != 0 - || (TransformPersistence.Flags & Graphic3d_TMF_TriedronPers) != 0; + || (!myTrsfPers.IsNull() && myTrsfPers->IsTrihedronOr2d()); } //! This method releases GL resources without actual elements destruction. diff --git a/src/OpenGl/OpenGl_StructureShadow.cxx b/src/OpenGl/OpenGl_StructureShadow.cxx index 0f7277be66..b17b4442a6 100644 --- a/src/OpenGl/OpenGl_StructureShadow.cxx +++ b/src/OpenGl/OpenGl_StructureShadow.cxx @@ -38,7 +38,7 @@ OpenGl_StructureShadow::OpenGl_StructureShadow (const Handle(Graphic3d_Structure UpdateTransformation(); myInstancedStructure = const_cast (myParent->InstancedStructure()); - TransformPersistence = myParent->TransformPersistence; + myTrsfPers = myParent->TransformPersistence(); // reuse instanced structure API myInstancedStructure = myParent.operator->(); diff --git a/src/OpenGl/OpenGl_View.cxx b/src/OpenGl/OpenGl_View.cxx index 9873043808..5a4bbc3711 100644 --- a/src/OpenGl/OpenGl_View.cxx +++ b/src/OpenGl/OpenGl_View.cxx @@ -576,9 +576,7 @@ Graphic3d_BndBox4f OpenGl_View::ZLayerBoundingBox (const Graphic3d_ZLayerId Graphic3d_BndBox4f aBox2d (Graphic3d_Vec4 (0.0f, 0.0f, 0.0f, 0.0f), Graphic3d_Vec4 (float(theWindowWidth), float(theWindowHeight), 0.0f, 0.0f)); - Graphic3d_TransformPers aTrsfPers; - aTrsfPers.Flags = Graphic3d_TMF_2d; - aTrsfPers.Point = Graphic3d_Vec3d(-1.0, -1.0, 0.0); + Graphic3d_TransformPers aTrsfPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER); aTrsfPers.Apply (theCamera, aProjectionMat, aWorldViewMat, diff --git a/src/PrsMgr/PrsMgr_PresentableObject.cxx b/src/PrsMgr/PrsMgr_PresentableObject.cxx index c2ff8c8d4c..ca7a5ec7fc 100644 --- a/src/PrsMgr/PrsMgr_PresentableObject.cxx +++ b/src/PrsMgr/PrsMgr_PresentableObject.cxx @@ -14,6 +14,7 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. +#include #include #include @@ -24,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -74,7 +74,7 @@ void PrsMgr_PresentableObject::Fill (const Handle(PrsMgr_PresentationManager)& t Compute (thePrsMgr, aStruct3d, theMode); UpdateTransformation (aStruct3d); aStruct3d->SetClipPlanes (myClipPlanes); - aStruct3d->SetTransformPersistence (GetTransformPersistenceMode(), GetTransformPersistencePoint()); + aStruct3d->SetTransformPersistence (TransformPersistence()); } //======================================================================= @@ -306,20 +306,16 @@ void PrsMgr_PresentableObject::UpdateTransformation(const Handle(Prs3d_Presentat //function : SetTransformPersistence //purpose : //======================================================================= -void PrsMgr_PresentableObject::SetTransformPersistence (const Graphic3d_TransModeFlags& theFlag, - const gp_Pnt& thePoint) +void PrsMgr_PresentableObject::SetTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers) { - myTransformPersistence.Flags = theFlag; - myTransformPersistence.Point.x() = thePoint.X(); - myTransformPersistence.Point.y() = thePoint.Y(); - myTransformPersistence.Point.z() = thePoint.Z(); + myTransformPersistence = theTrsfPers; for (Standard_Integer aPrsIter = 1; aPrsIter <= myPresentations.Length(); ++aPrsIter) { const Handle(PrsMgr_Presentation)& aPrs3d = myPresentations (aPrsIter).Presentation(); if (!aPrs3d.IsNull() && !aPrs3d->Presentation().IsNull()) { - aPrs3d->Presentation()->SetTransformPersistence (theFlag, thePoint); + aPrs3d->Presentation()->SetTransformPersistence (myTransformPersistence); aPrs3d->Presentation()->ReCompute(); } } @@ -327,22 +323,44 @@ void PrsMgr_PresentableObject::SetTransformPersistence (const Graphic3d_TransMod //======================================================================= //function : GetTransformPersistence -//purpose : -//======================================================================= -Graphic3d_TransModeFlags PrsMgr_PresentableObject::GetTransformPersistenceMode() const -{ - return myTransformPersistence.Flags; -} - -//======================================================================= -//function : GetTransformPersistence -//purpose : +//purpose : //======================================================================= gp_Pnt PrsMgr_PresentableObject::GetTransformPersistencePoint() const { - return gp_Pnt (myTransformPersistence.Point.x(), - myTransformPersistence.Point.y(), - myTransformPersistence.Point.z()); + if (myTransformPersistence.IsNull()) + { + return gp_Pnt(); + } + else if (myTransformPersistence->IsZoomOrRotate()) + { + return myTransformPersistence->AnchorPoint(); + } + else if (!myTransformPersistence->IsTrihedronOr2d()) + { + return gp_Pnt(); + } + + Standard_Real anX = 0.0; + if ((myTransformPersistence->Corner2d() & Aspect_TOTP_RIGHT) != 0) + { + anX = 1.0; + } + else if ((myTransformPersistence->Corner2d() & Aspect_TOTP_LEFT) != 0) + { + anX = -1.0; + } + + Standard_Real anY = 0.0; + if ((myTransformPersistence->Corner2d() & Aspect_TOTP_TOP) != 0) + { + anY = 1.0; + } + else if ((myTransformPersistence->Corner2d() & Aspect_TOTP_BOTTOM) != 0) + { + anY = -1.0; + } + + return gp_Pnt (anX, anY, myTransformPersistence->Offset2d().x()); } //======================================================================= diff --git a/src/PrsMgr/PrsMgr_PresentableObject.hxx b/src/PrsMgr/PrsMgr_PresentableObject.hxx index 9b7a2eeda8..da8466f223 100644 --- a/src/PrsMgr/PrsMgr_PresentableObject.hxx +++ b/src/PrsMgr/PrsMgr_PresentableObject.hxx @@ -78,37 +78,48 @@ public: //! Returns information on whether the object accepts display in HLR mode or not. PrsMgr_TypeOfPresentation3d TypeOfPresentation3d() const { return myTypeOfPresentation3d; } + //! @return transform persistence of the presentable object. + const Handle(Graphic3d_TransformPers)& TransformPersistence() const { return myTransformPersistence; } + + //! Sets up Transform Persistence for this object. + Standard_EXPORT virtual void SetTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers); + //! Sets up Transform Persistence Mode for this object. //! This function used to lock in object position, rotation and / or zooming relative to camera position. - //! Object will be drawn in the origin setted by APoint parameter (except Graphic3d_TMF_TriedronPers flag - //! - see description later). aFlag should be: + //! Object will be drawn in the origin setted by thePoint parameter (except Graphic3d_TMF_TriedronPers flag + //! - see description later). theMode should be: //! - Graphic3d_TMF_None - no persistence attributes (reset); - //! - Graphic3d_TMF_PanPers - object doesn't move; //! - Graphic3d_TMF_ZoomPers - object doesn't resize; //! - Graphic3d_TMF_RotatePers - object doesn't rotate; - //! - Graphic3d_TMF_FullPers - pan, zoom and rotate transform persistence; - //! - Graphic3d_TMF_TriedronPers - object behaves like trihedron; - //! - combination (Graphic3d_TMF_PanPers | Graphic3d_TMF_ZoomPers); - //! - combination (Graphic3d_TMF_PanPers | Graphic3d_TMF_RotatePers); - //! - combination (Graphic3d_TMF_ZoomPers | Graphic3d_TMF_RotatePers). - //! If Graphic3d_TMF_TriedronPers or Graphic3d_TMF_2d persistence mode selected APoint coordinates X and Y means: + //! - Graphic3d_TMF_ZoomRotatePers - object doesn't resize and rotate; + //! - Graphic3d_TMF_RotatePers - object doesn't rotate; + //! - Graphic3d_TMF_TriedronPers - object behaves like trihedron. + //! If Graphic3d_TMF_TriedronPers or Graphic3d_TMF_2d persistence mode selected thePoint coordinates X and Y means: //! - X = 0.0, Y = 0.0 - center of view window; //! - X > 0.0, Y > 0.0 - right upper corner of view window; //! - X > 0.0, Y < 0.0 - right lower corner of view window; //! - X < 0.0, Y > 0.0 - left upper corner of view window; //! - X < 0.0, Y < 0.0 - left lower corner of view window. //! And Z coordinate defines the gap from border of view window (except center position). - Standard_EXPORT virtual void SetTransformPersistence (const Graphic3d_TransModeFlags& aFlag, const gp_Pnt& APoint = gp_Pnt (0.0, 0.0, 0.0)); + Standard_DEPRECATED("This method is deprecated - SetTransformPersistence() taking Graphic3d_TransformPers should be called instead") + void SetTransformPersistence (const Graphic3d_TransModeFlags theMode, const gp_Pnt& thePoint = gp_Pnt (0.0, 0.0, 0.0)) + { + SetTransformPersistence (Graphic3d_TransformPers::FromDeprecatedParams (theMode, thePoint)); + } //! Gets Transform Persistence Mode for this object - Standard_EXPORT Graphic3d_TransModeFlags GetTransformPersistenceMode() const; - + Standard_DEPRECATED("This method is deprecated - TransformPersistence() should be called instead") + Graphic3d_TransModeFlags GetTransformPersistenceMode() const + { + return myTransformPersistence.IsNull() + ? Graphic3d_TMF_None + : myTransformPersistence->Mode(); + } + //! Gets point of transform persistence for this object + Standard_DEPRECATED("This method is deprecated - TransformPersistence() should be called instead") Standard_EXPORT gp_Pnt GetTransformPersistencePoint() const; - //! @return transform persistence of the presentable object. - const Graphic3d_TransformPers& TransformPersistence() const { return myTransformPersistence; } - Standard_EXPORT void SetTypeOfPresentation (const PrsMgr_TypeOfPresentation3d aType); //! flags the Prs of mode to be Updated. @@ -289,7 +300,7 @@ protected: private: - Graphic3d_TransformPers myTransformPersistence; + Handle(Graphic3d_TransformPers) myTransformPersistence; PrsMgr_PresentableObjectPointer myParent; gp_Trsf myLocalTransformation; gp_Trsf myTransformation; diff --git a/src/QABugs/QABugs_11.cxx b/src/QABugs/QABugs_11.cxx index fc6890bb7f..6029068aaf 100644 --- a/src/QABugs/QABugs_11.cxx +++ b/src/QABugs/QABugs_11.cxx @@ -4556,9 +4556,10 @@ static Standard_Integer OCC12584 (Draw_Interpretor& di, Standard_Integer argc, c { aCS->SetZLayer (Graphic3d_ZLayerId_TopOSD); } - if (aCS->GetTransformPersistenceMode() != Graphic3d_TMF_2d) + if (aCS->TransformPersistence().IsNull() + || aCS->TransformPersistence()->Mode() != Graphic3d_TMF_2d) { - aContext->SetTransformPersistence (aCS, Graphic3d_TMF_2d, gp_Pnt (-1,-1,0)); + aContext->SetTransformPersistence (aCS, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER)); } Standard_Integer aWinWidth, aWinHeight; V->Window()->Size (aWinWidth, aWinHeight); diff --git a/src/SelectMgr/SelectMgr_SelectableObject.cxx b/src/SelectMgr/SelectMgr_SelectableObject.cxx index c7af451374..8b18242bb4 100644 --- a/src/SelectMgr/SelectMgr_SelectableObject.cxx +++ b/src/SelectMgr/SelectMgr_SelectableObject.cxx @@ -348,14 +348,13 @@ void SelectMgr_SelectableObject::SetAutoHilight ( const Standard_Boolean newAuto //function : GetHilightPresentation //purpose : //======================================================================= -Handle(Prs3d_Presentation) SelectMgr_SelectableObject::GetHilightPresentation( const Handle(PrsMgr_PresentationManager3d)& TheMgr ) +Handle(Prs3d_Presentation) SelectMgr_SelectableObject::GetHilightPresentation (const Handle(PrsMgr_PresentationManager3d)& theMgr) { - if( myHilightPrs.IsNull() && !TheMgr.IsNull() ) - { - myHilightPrs = new Prs3d_Presentation( TheMgr->StructureManager() ); - myHilightPrs->SetTransformPersistence( GetTransformPersistenceMode(), - GetTransformPersistencePoint() ); - } + if (myHilightPrs.IsNull() && !theMgr.IsNull()) + { + myHilightPrs = new Prs3d_Presentation (theMgr->StructureManager()); + myHilightPrs->SetTransformPersistence (TransformPersistence()); + } return myHilightPrs; } @@ -365,13 +364,14 @@ Handle(Prs3d_Presentation) SelectMgr_SelectableObject::GetHilightPresentation( c //function : GetSelectPresentation //purpose : //======================================================================= -Handle(Prs3d_Presentation) SelectMgr_SelectableObject::GetSelectPresentation( const Handle(PrsMgr_PresentationManager3d)& TheMgr ) +Handle(Prs3d_Presentation) SelectMgr_SelectableObject::GetSelectPresentation (const Handle(PrsMgr_PresentationManager3d)& theMgr) { - if( mySelectionPrs.IsNull() && !TheMgr.IsNull() ) { - mySelectionPrs = new Prs3d_Presentation( TheMgr->StructureManager() ); - mySelectionPrs->SetTransformPersistence( GetTransformPersistenceMode(), - GetTransformPersistencePoint() ); + if (mySelectionPrs.IsNull() && !theMgr.IsNull()) + { + mySelectionPrs = new Prs3d_Presentation (theMgr->StructureManager()); + mySelectionPrs->SetTransformPersistence (TransformPersistence()); } + return mySelectionPrs; } diff --git a/src/SelectMgr/SelectMgr_SelectableObjectSet.cxx b/src/SelectMgr/SelectMgr_SelectableObjectSet.cxx index 6aa38decef..763980c7ef 100644 --- a/src/SelectMgr/SelectMgr_SelectableObjectSet.cxx +++ b/src/SelectMgr/SelectMgr_SelectableObjectSet.cxx @@ -125,14 +125,14 @@ namespace Bnd_Box aBoundingBox; anObject->BoundingBox (aBoundingBox); - if (aBoundingBox.IsVoid()) + if (aBoundingBox.IsVoid() + || anObject->TransformPersistence().IsNull()) { myBoundings.Add (new Select3D_HBndBox3d()); } else { - anObject->TransformPersistence().Apply ( - theCamera, theProjectionMat, theWorldViewMat, theWidth, theHeight, aBoundingBox); + anObject->TransformPersistence()->Apply (theCamera, theProjectionMat, theWorldViewMat, theWidth, theHeight, aBoundingBox); const gp_Pnt aMin = aBoundingBox.CornerMin(); const gp_Pnt aMax = aBoundingBox.CornerMax(); diff --git a/src/SelectMgr/SelectMgr_SelectableObjectSet.hxx b/src/SelectMgr/SelectMgr_SelectableObjectSet.hxx index 770f182d44..978337cf8f 100644 --- a/src/SelectMgr/SelectMgr_SelectableObjectSet.hxx +++ b/src/SelectMgr/SelectMgr_SelectableObjectSet.hxx @@ -184,11 +184,11 @@ private: //! Returns an appropriate subset of theObject given depending on its persistence type. Standard_Integer appropriateSubset (const Handle(SelectMgr_SelectableObject)& theObject) { - if (!theObject->TransformPersistence().Flags) + if (theObject->TransformPersistence().IsNull()) { return SelectMgr_SelectableObjectSet::BVHSubset_3d; } - else if (theObject->TransformPersistence().Flags & Graphic3d_TMF_2d) + else if (theObject->TransformPersistence()->Mode() == Graphic3d_TMF_2d) { return SelectMgr_SelectableObjectSet::BVHSubset_2dPersistent; } diff --git a/src/SelectMgr/SelectMgr_ViewerSelector.cxx b/src/SelectMgr/SelectMgr_ViewerSelector.cxx index 0f162e9079..84d50631da 100644 --- a/src/SelectMgr/SelectMgr_ViewerSelector.cxx +++ b/src/SelectMgr/SelectMgr_ViewerSelector.cxx @@ -171,8 +171,7 @@ void SelectMgr_ViewerSelector::checkOverlap (const Handle(SelectBasics_Sensitive if (!anOwner.IsNull()) { aSelectable = anOwner->Selectable(); - if (aSelectable->TransformPersistence().Flags == Graphic3d_TMF_TriedronPers - || aSelectable->TransformPersistence().Flags == Graphic3d_TMF_2d + if ((!aSelectable->TransformPersistence().IsNull() && aSelectable->TransformPersistence()->IsTrihedronOr2d()) || (!aSelectable->ClipPlanes().IsNull() && aSelectable->ClipPlanes()->ToOverrideGlobal())) { theMgr.SetViewClippingEnabled (Standard_False); @@ -289,17 +288,16 @@ void SelectMgr_ViewerSelector::traverseObject (const Handle(SelectMgr_Selectable gp_GTrsf aInversedTrsf; - if (theObject->HasTransformation() || theObject->TransformPersistence().Flags) + if (theObject->HasTransformation() || !theObject->TransformPersistence().IsNull()) { - if (!theObject->TransformPersistence().Flags) + if (theObject->TransformPersistence().IsNull()) { aInversedTrsf = theObject->InversedTransformation(); } else { gp_GTrsf aTPers; - Graphic3d_Mat4d aMat = theObject->TransformPersistence().Compute ( - theCamera, theProjectionMat, theWorldViewMat, theViewportWidth, theViewportHeight); + Graphic3d_Mat4d aMat = theObject->TransformPersistence()->Compute (theCamera, theProjectionMat, theWorldViewMat, theViewportWidth, theViewportHeight); aTPers.SetValue (1, 1, aMat.GetValue (0, 0)); aTPers.SetValue (1, 2, aMat.GetValue (0, 1)); diff --git a/src/StdSelect/StdSelect_BRepOwner.cxx b/src/StdSelect/StdSelect_BRepOwner.cxx index 2654518ef2..1606886005 100644 --- a/src/StdSelect/StdSelect_BRepOwner.cxx +++ b/src/StdSelect/StdSelect_BRepOwner.cxx @@ -114,7 +114,7 @@ void StdSelect_BRepOwner::Hilight(const Handle(PrsMgr_PresentationManager)& PM, if (!aSel.IsNull()) { myPrsSh->SetZLayer (aSel->ZLayer()); - myPrsSh->SetTransformPersistence (aSel->GetTransformPersistenceMode(), aSel->GetTransformPersistencePoint()); + myPrsSh->SetTransformPersistence (aSel->TransformPersistence()); } // highlight and set layer @@ -177,7 +177,7 @@ void StdSelect_BRepOwner::HilightWithColor(const Handle(PrsMgr_PresentationManag if (!aSel.IsNull()) { myPrsSh->SetZLayer (aSel->ZLayer()); - myPrsSh->SetTransformPersistence (aSel->GetTransformPersistenceMode(), aSel->GetTransformPersistencePoint()); + myPrsSh->SetTransformPersistence (aSel->TransformPersistence()); } // highlight with color and set layer diff --git a/src/StdSelect/StdSelect_ViewerSelector3d.cxx b/src/StdSelect/StdSelect_ViewerSelector3d.cxx index 67840be3f4..6b29cf708c 100644 --- a/src/StdSelect/StdSelect_ViewerSelector3d.cxx +++ b/src/StdSelect/StdSelect_ViewerSelector3d.cxx @@ -195,7 +195,7 @@ void StdSelect_ViewerSelector3d::DisplaySensitive (const Handle(V3d_View)& theVi { if (anObj->CurrentSelection()->GetSelectionState() == SelectMgr_SOS_Activated) { - computeSensitivePrs (aStruct, anObj->CurrentSelection(), anObj->Transformation(), Graphic3d_TransformPers()); + computeSensitivePrs (aStruct, anObj->CurrentSelection(), anObj->Transformation(), Handle(Graphic3d_TransformPers)()); } } @@ -247,7 +247,7 @@ void StdSelect_ViewerSelector3d::DisplaySensitive (const Handle(SelectMgr_Select Handle(Graphic3d_Structure) aStruct = new Graphic3d_Structure (theView->Viewer()->StructureManager()); - computeSensitivePrs (aStruct, theSel, theTrsf, Graphic3d_TransformPers()); + computeSensitivePrs (aStruct, theSel, theTrsf, Handle(Graphic3d_TransformPers)()); myStructs.Append (aStruct); myStructs.Last()->SetDisplayPriority (10); @@ -263,11 +263,9 @@ void StdSelect_ViewerSelector3d::DisplaySensitive (const Handle(SelectMgr_Select void StdSelect_ViewerSelector3d::computeSensitivePrs (const Handle(Graphic3d_Structure)& theStructure, const Handle(SelectMgr_Selection)& theSel, const gp_Trsf& theLoc, - const Graphic3d_TransformPers& theTransPers) + const Handle(Graphic3d_TransformPers)& theTrsfPers) { - theStructure->SetTransformPersistence (theTransPers.Flags, gp_Pnt (theTransPers.Point.x(), - theTransPers.Point.y(), - theTransPers.Point.z())); + theStructure->SetTransformPersistence (theTrsfPers); Handle(Graphic3d_Group) aSensGroup = theStructure->NewGroup(); diff --git a/src/StdSelect/StdSelect_ViewerSelector3d.hxx b/src/StdSelect/StdSelect_ViewerSelector3d.hxx index 37ac0072dd..48c428322d 100644 --- a/src/StdSelect/StdSelect_ViewerSelector3d.hxx +++ b/src/StdSelect/StdSelect_ViewerSelector3d.hxx @@ -88,7 +88,7 @@ protected: Standard_EXPORT void computeSensitivePrs (const Handle(Graphic3d_Structure)& theStructure, const Handle(SelectMgr_Selection)& theSel, const gp_Trsf& theLoc, - const Graphic3d_TransformPers& theTransPers); + const Handle(Graphic3d_TransformPers)& theTrsfPers); //! Update z-layers order map. Standard_EXPORT void updateZLayers (const Handle(V3d_View)& theView); diff --git a/src/V3d/V3d_View.cxx b/src/V3d/V3d_View.cxx index 668d78e71f..a01ab03502 100644 --- a/src/V3d/V3d_View.cxx +++ b/src/V3d/V3d_View.cxx @@ -2126,7 +2126,7 @@ void V3d_View::Gravity (Standard_Real& theX, } // skip transformation-persistent objects - if (aStruct->TransformPersistence().Flags != Graphic3d_TMF_None) + if (!aStruct->TransformPersistence().IsNull()) { continue; } diff --git a/src/ViewerTest/ViewerTest.cxx b/src/ViewerTest/ViewerTest.cxx index a342d1ab95..113dbfda6c 100644 --- a/src/ViewerTest/ViewerTest.cxx +++ b/src/ViewerTest/ViewerTest.cxx @@ -3385,27 +3385,24 @@ Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, //! Auxiliary method to parse transformation persistence flags inline Standard_Boolean parseTrsfPersFlag (const TCollection_AsciiString& theFlagString, - Standard_Integer& theFlags) + Graphic3d_TransModeFlags& theFlags) { - if (theFlagString == "pan") + if (theFlagString == "zoom") { - theFlags |= Graphic3d_TMF_PanPers; - } - else if (theFlagString == "zoom") - { - theFlags |= Graphic3d_TMF_ZoomPers; + theFlags = Graphic3d_TMF_ZoomPers; } else if (theFlagString == "rotate") { - theFlags |= Graphic3d_TMF_RotatePers; + theFlags = Graphic3d_TMF_RotatePers; } - else if (theFlagString == "trihedron") + else if (theFlagString == "zoomrotate") { - theFlags = Graphic3d_TMF_TriedronPers; + theFlags = Graphic3d_TMF_ZoomRotatePers; } - else if (theFlagString == "full") + else if (theFlagString == "trihedron" + || theFlagString == "triedron") { - theFlags = Graphic3d_TMF_FullPers; + theFlags = Graphic3d_TMF_TriedronPers; } else if (theFlagString == "none") { @@ -3419,6 +3416,66 @@ inline Standard_Boolean parseTrsfPersFlag (const TCollection_AsciiString& theFla return Standard_True; } +//! Auxiliary method to parse transformation persistence flags +inline Standard_Boolean parseTrsfPersCorner (const TCollection_AsciiString& theString, + Aspect_TypeOfTriedronPosition& theCorner) +{ + TCollection_AsciiString aString (theString); + aString.LowerCase(); + if (aString == "center") + { + theCorner = Aspect_TOTP_CENTER; + } + else if (aString == "top" + || aString == "upper") + { + theCorner = Aspect_TOTP_TOP; + } + else if (aString == "bottom" + || aString == "lower") + { + theCorner = Aspect_TOTP_BOTTOM; + } + else if (aString == "left") + { + theCorner = Aspect_TOTP_LEFT; + } + else if (aString == "right") + { + theCorner = Aspect_TOTP_RIGHT; + } + else if (aString == "topleft" + || aString == "leftupper" + || aString == "upperleft") + { + theCorner = Aspect_TOTP_LEFT_UPPER; + } + else if (aString == "bottomleft" + || aString == "leftlower" + || aString == "lowerleft") + { + theCorner = Aspect_TOTP_LEFT_LOWER; + } + else if (aString == "topright" + || aString == "rightupper" + || aString == "upperright") + { + theCorner = Aspect_TOTP_RIGHT_UPPER; + } + else if (aString == "bottomright" + || aString == "lowerright" + || aString == "rightlower") + { + theCorner = Aspect_TOTP_RIGHT_LOWER; + } + else + { + return Standard_False; + } + + return Standard_True; +} + //============================================================================== //function : VDisplay2 //author : ege @@ -3451,8 +3508,7 @@ static int VDisplay2 (Draw_Interpretor& theDI, Standard_Integer anObjDispMode = -2; Standard_Integer anObjHighMode = -2; Standard_Boolean toSetTrsfPers = Standard_False; - Graphic3d_TransModeFlags aTrsfPersFlags = Graphic3d_TMF_None; - gp_Pnt aTPPosition; + Handle(Graphic3d_TransformPers) aTrsfPers; TColStd_SequenceOfAsciiString aNamesOfDisplayIO; AIS_DisplayStatus aDispStatus = AIS_DS_None; Standard_Integer toDisplayInView = Standard_False; @@ -3528,51 +3584,71 @@ static int VDisplay2 (Draw_Interpretor& theDI, else if (aNameCase == "-3d") { toSetTrsfPers = Standard_True; - aTrsfPersFlags = Graphic3d_TMF_None; + aTrsfPers.Nullify(); } - else if (aNameCase == "-2d") + else if (aNameCase == "-2d" + || aNameCase == "-trihedron" + || aNameCase == "-triedron") { toSetTrsfPers = Standard_True; - aTrsfPersFlags = Graphic3d_TMF_2d; + aTrsfPers = new Graphic3d_TransformPers (aNameCase == "-2d" ? Graphic3d_TMF_2d : Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER); + + if (anArgIter + 1 < theArgNb) + { + Aspect_TypeOfTriedronPosition aCorner = Aspect_TOTP_CENTER; + if (parseTrsfPersCorner (theArgVec[anArgIter + 1], aCorner)) + { + ++anArgIter; + aTrsfPers->SetCorner2d (aCorner); + + if (anArgIter + 2 < theArgNb) + { + TCollection_AsciiString anX (theArgVec[anArgIter + 1]); + TCollection_AsciiString anY (theArgVec[anArgIter + 2]); + if (anX.IsIntegerValue() + && anY.IsIntegerValue()) + { + anArgIter += 2; + aTrsfPers->SetOffset2d (Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue())); + } + } + } + } } else if (aNameCase == "-trsfpers" || aNameCase == "-pers") { - if (++anArgIter >= theArgNb) + if (++anArgIter >= theArgNb + || !aTrsfPers.IsNull()) { std::cerr << "Error: wrong syntax at " << aName << ".\n"; return 1; } toSetTrsfPers = Standard_True; - aTrsfPersFlags = Graphic3d_TMF_None; + Graphic3d_TransModeFlags aTrsfPersFlags = Graphic3d_TMF_None; TCollection_AsciiString aPersFlags (theArgVec [anArgIter]); aPersFlags.LowerCase(); - for (Standard_Integer aParserPos = aPersFlags.Search ("|");; aParserPos = aPersFlags.Search ("|")) + if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags)) { - if (aParserPos == -1) - { - if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags)) - { - std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n"; - return 1; - } - break; - } + std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n"; + return 1; + } - TCollection_AsciiString anOtherFlags = aPersFlags.Split (aParserPos - 1); - if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags)) - { - std::cerr << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << ".\n"; - return 1; - } - aPersFlags = anOtherFlags; + if (aTrsfPersFlags == Graphic3d_TMF_TriedronPers) + { + aTrsfPers = new Graphic3d_TransformPers (Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER); + } + else if (aTrsfPersFlags != Graphic3d_TMF_None) + { + aTrsfPers = new Graphic3d_TransformPers (aTrsfPersFlags, gp_Pnt()); } } else if (aNameCase == "-trsfperspos" || aNameCase == "-perspos") { - if (anArgIter + 2 >= theArgNb) + if (anArgIter + 2 >= theArgNb + || aTrsfPers.IsNull()) { std::cerr << "Error: wrong syntax at " << aName << ".\n"; return 1; @@ -3581,8 +3657,8 @@ static int VDisplay2 (Draw_Interpretor& theDI, TCollection_AsciiString aX (theArgVec[++anArgIter]); TCollection_AsciiString aY (theArgVec[++anArgIter]); TCollection_AsciiString aZ = "0"; - if (!aX.IsIntegerValue() - || !aY.IsIntegerValue()) + if (!aX.IsRealValue() + || !aY.IsRealValue()) { std::cerr << "Error: wrong syntax at " << aName << ".\n"; return 1; @@ -3590,13 +3666,22 @@ static int VDisplay2 (Draw_Interpretor& theDI, if (anArgIter + 1 < theArgNb) { TCollection_AsciiString aTemp = theArgVec[anArgIter + 1]; - if (aTemp.IsIntegerValue()) + if (aTemp.IsRealValue()) { aZ = aTemp; ++anArgIter; } } - aTPPosition.SetCoord (aX.IntegerValue(), aY.IntegerValue(), aZ.IntegerValue()); + + const gp_Pnt aPnt (aX.RealValue(), aY.RealValue(), aZ.RealValue()); + if (aTrsfPers->IsZoomOrRotate()) + { + aTrsfPers->SetAnchorPoint (aPnt); + } + else if (aTrsfPers->IsTrihedronOr2d()) + { + aTrsfPers = Graphic3d_TransformPers::FromDeprecatedParams (aTrsfPers->Mode(), aPnt); + } } else if (aNameCase == "-layer") { @@ -3672,7 +3757,7 @@ static int VDisplay2 (Draw_Interpretor& theDI, } if (toSetTrsfPers) { - aCtx->SetTransformPersistence (aShape, aTrsfPersFlags, aTPPosition); + aCtx->SetTransformPersistence (aShape, aTrsfPers); } if (anObjDispMode != -2) { @@ -3726,7 +3811,7 @@ static int VDisplay2 (Draw_Interpretor& theDI, } if (toSetTrsfPers) { - aCtx->SetTransformPersistence (aShape, aTrsfPersFlags, aTPPosition); + aCtx->SetTransformPersistence (aShape, aTrsfPers); } if (anObjDispMode != -2) { @@ -5523,7 +5608,11 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands) theCommands.Add("vdisplay", "vdisplay [-noupdate|-update] [-local] [-mutable] [-neutral]" - "\n\t\t: [-trsfPers {pan|zoom|rotate|trihedron|full|none}=none] [-trsfPersPos X Y [Z]] [-3d|-2d]" + "\n\t\t: [-trsfPers {zoom|rotate|zoomRotate|none}=none]" + "\n\t\t: [-trsfPersPos X Y [Z]] [-3d]" + "\n\t\t: [-2d|-trihedron [{top|bottom|left|right|topLeft" + "\n\t\t: |topRight|bottomLeft|bottomRight}" + "\n\t\t: [offsetX offsetY]]]" "\n\t\t: [-dispMode mode] [-highMode mode]" "\n\t\t: [-layer index] [-top|-topmost|-overlay|-underlay]" "\n\t\t: [-redisplay]" @@ -5532,21 +5621,28 @@ void ViewerTest::Commands(Draw_Interpretor& theCommands) "\n\t\t: Option -local enables displaying of objects in local" "\n\t\t: selection context. Local selection context will be opened" "\n\t\t: if there is not any." - "\n\t\t: -noupdate suppresses viewer redraw call." - "\n\t\t: -mutable enables optimizations for mutable objects." - "\n\t\t: -neutral draws objects in main viewer." - "\n\t\t: -layer sets z-layer for objects. It can use -overlay|-underlay|-top|-topmost instead of -layer index for the default z-layers." - "\n\t\t: -top draws objects on top of main presentations but below topmost." - "\n\t\t: -topmost draws in overlay for 3D presentations with independent Depth." - "\n\t\t: -overlay draws objects in overlay for 2D presentations (On-Screen-Display)." - "\n\t\t: -underlay draws objects in underlay for 2D presentations (On-Screen-Display)." - "\n\t\t: -selectable|-noselect controls selection of objects." - "\n\t\t: -trsfPers sets a transform persistence flags. Flag 'full' is pan, zoom and rotate." - "\n\t\t: -trsfPersPos sets an anchor point for transform persistence." - "\n\t\t: -2d displays object in screen coordinates (DY looks up)." - "\n\t\t: -dispmode sets display mode for objects." - "\n\t\t: -highmode sets hilight mode for objects." - "\n\t\t: -redisplay recomputes presentation of objects.", + "\n\t\t: -noupdate Suppresses viewer redraw call." + "\n\t\t: -mutable Enables optimizations for mutable objects." + "\n\t\t: -neutral Draws objects in main viewer." + "\n\t\t: -layer Sets z-layer for objects." + "\n\t\t: Alternatively -overlay|-underlay|-top|-topmost" + "\n\t\t: options can be used for the default z-layers." + "\n\t\t: -top Draws object on top of main presentations" + "\n\t\t: but below topmost." + "\n\t\t: -topmost Draws in overlay for 3D presentations." + "\n\t\t: with independent Depth." + "\n\t\t: -overlay Draws objects in overlay for 2D presentations." + "\n\t\t: (On-Screen-Display)" + "\n\t\t: -underlay Draws objects in underlay for 2D presentations." + "\n\t\t: (On-Screen-Display)" + "\n\t\t: -selectable|-noselect Controls selection of objects." + "\n\t\t: -trsfPers Sets a transform persistence flags." + "\n\t\t: -trsfPersPos Sets an anchor point for transform persistence." + "\n\t\t: -2d Displays object in screen coordinates." + "\n\t\t: (DY looks up)" + "\n\t\t: -dispmode Sets display mode for objects." + "\n\t\t: -highmode Sets hilight mode for objects." + "\n\t\t: -redisplay Recomputes presentation of objects.", __FILE__, VDisplay2, group); theCommands.Add ("vupdate", diff --git a/src/ViewerTest/ViewerTest_ObjectCommands.cxx b/src/ViewerTest/ViewerTest_ObjectCommands.cxx index 1cad752d8a..15a7f9fcad 100644 --- a/src/ViewerTest/ViewerTest_ObjectCommands.cxx +++ b/src/ViewerTest/ViewerTest_ObjectCommands.cxx @@ -139,11 +139,6 @@ #include #include -#if defined(_MSC_VER) -# define _CRT_SECURE_NO_DEPRECATE -# pragma warning (disable:4996) -#endif - extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(); extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName, const Handle(AIS_InteractiveObject)& theAISObj, @@ -2508,11 +2503,9 @@ static int VDrawText (Draw_Interpretor& theDI, aTextPrs->SetText (aText); - Graphic3d_TransModeFlags aTrsfPersFlags = Graphic3d_TMF_None; - gp_Pnt aTPPosition; + Handle(Graphic3d_TransformPers) aTrsfPers; Aspect_TypeOfDisplayText aDisplayType = Aspect_TODT_NORMAL; - Standard_Boolean aHasPlane = Standard_False; gp_Dir aNormal; gp_Dir aDirection; @@ -2799,7 +2792,7 @@ static int VDrawText (Draw_Interpretor& theDI, } else if (aParam == "-2d") { - aTrsfPersFlags = Graphic3d_TMF_2d; + aTrsfPers = new Graphic3d_TransformPers (Graphic3d_TMF_2d); } else if (aParam == "-trsfperspos" || aParam == "-perspos") @@ -2828,7 +2821,8 @@ static int VDrawText (Draw_Interpretor& theDI, ++anArgIt; } } - aTPPosition.SetCoord (aX.IntegerValue(), aY.IntegerValue(), aZ.IntegerValue()); + + aTrsfPers = Graphic3d_TransformPers::FromDeprecatedParams (Graphic3d_TMF_2d, gp_Pnt (aX.IntegerValue(), aY.IntegerValue(), aZ.IntegerValue())); } else { @@ -2844,18 +2838,18 @@ static int VDrawText (Draw_Interpretor& theDI, aTextPrs->SetDisplayType (aDisplayType); - if (aTrsfPersFlags != Graphic3d_TMF_None) + if (!aTrsfPers.IsNull()) { - aContext->SetTransformPersistence (aTextPrs, aTrsfPersFlags, aTPPosition); + aContext->SetTransformPersistence (aTextPrs, aTrsfPers); aTextPrs->SetZLayer(Graphic3d_ZLayerId_TopOSD); if (aTextPrs->Position().Z() != 0) { aTextPrs->SetPosition (gp_Pnt(aTextPrs->Position().X(), aTextPrs->Position().Y(), 0)); } } - else if (aTrsfPersFlags != aTextPrs->TransformPersistence().Flags) + else if (!aTextPrs->TransformPersistence().IsNull()) { - aContext->SetTransformPersistence (aTextPrs, aTrsfPersFlags); + aContext->SetTransformPersistence (aTextPrs, Handle(Graphic3d_TransformPers)()); } ViewerTest::Display (aName, aTextPrs, Standard_False); return 0; diff --git a/src/ViewerTest/ViewerTest_ViewerCommands.cxx b/src/ViewerTest/ViewerTest_ViewerCommands.cxx index 6992046e1f..844b1fb79b 100644 --- a/src/ViewerTest/ViewerTest_ViewerCommands.cxx +++ b/src/ViewerTest/ViewerTest_ViewerCommands.cxx @@ -3478,9 +3478,10 @@ static int VColorScale (Draw_Interpretor& theDI, { aCS->SetZLayer (Graphic3d_ZLayerId_TopOSD); } - if (aCS->GetTransformPersistenceMode() != Graphic3d_TMF_2d) + if (aCS->TransformPersistence().IsNull() + || aCS->TransformPersistence()->Mode() != Graphic3d_TMF_2d) { - aContext->SetTransformPersistence (aCS, Graphic3d_TMF_2d, gp_Pnt (-1.0, -1.0, 0.0)); + aContext->SetTransformPersistence (aCS, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER)); } Standard_Real aMinRange = aCS->GetMin(); @@ -4746,7 +4747,7 @@ static int VLayerLine(Draw_Interpretor& di, Standard_Integer argc, const char** aLineType, aWidth, aTransparency); - aContext->SetTransformPersistence (aLine, Graphic3d_TMF_2d, gp_Pnt (-1.0, -1.0, 0.0)); + aContext->SetTransformPersistence (aLine, new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER)); aLine->SetZLayer (Graphic3d_ZLayerId_TopOSD); aLine->SetToUpdate(); aContext->Display (aLine, Standard_True); diff --git a/tests/bugs/vis/bug23120 b/tests/bugs/vis/bug23120 index 9b8cc7ad9e..d75da7e2db 100755 --- a/tests/bugs/vis/bug23120 +++ b/tests/bugs/vis/bug23120 @@ -10,7 +10,7 @@ box b1 10 20 30 box b2 10 20 30 ttranslate b2 50 50 0 vinit -vdisplay b1 -trsfPers trihedron +vdisplay b1 -trihedron center vdisplay b2 vfit diff --git a/tests/bugs/vis/bug25783_1 b/tests/bugs/vis/bug25783_1 index 4f9623a8bb..de8509fc23 100644 --- a/tests/bugs/vis/bug25783_1 +++ b/tests/bugs/vis/bug25783_1 @@ -12,32 +12,32 @@ vaxo # display polyline in overlay text2brep tcc "Center" -font SansFont -height 30 -vdisplay tcc -2d -osd +vdisplay tcc -2d center -osd polyline lcc -50 -50 0 -50 50 0 50 50 0 50 0 0 0 -50 0 -50 -50 0 -vdisplay lcc -2d -overlay +vdisplay lcc -2d center -overlay # display polyline in overlay in the bottom left corner of the view text2brep tbl "Bottom-Left" -font SansFont -height 30 -vdisplay tbl -2d -trsfPersPos -1 -1 5 -osd +vdisplay tbl -2d bottomLeft 5 5 -osd polyline lbl 0 0 0 0 100 0 100 100 0 100 50 0 50 0 0 0 0 0 -vdisplay lbl -2d -trsfPersPos -1 -1 3 -overlay +vdisplay lbl -2d bottomLeft 3 3 -overlay # display polyline in overlay in the top left corner of the view text2brep ttl "Top-Left" -font SansFont -height 30 -pos -27 0 0 -vdisplay ttl -2d -trsfPersPos -1 1 30 -osd +vdisplay ttl -2d topLeft 30 30 -osd polyline ltl 0 -100 0 0 0 0 100 0 0 100 -50 0 50 -100 0 0 -100 0 -vdisplay ltl -2d -trsfPersPos -1 1 3 -overlay +vdisplay ltl -2d topLeft 3 3 -overlay # display polyline in overlay in the top right corner of the view text2brep ttr "Top-Right" -font SansFont -height 30 -pos -100 0 0 -vdisplay ttr -2d -trsfPersPos 1 1 30 -osd +vdisplay ttr -2d topRight 30 30 -osd polyline ltr -100 -100 0 -100 0 0 0 0 0 0 -50 0 -50 -100 0 -100 -100 0 -vdisplay ltr -2d -trsfPersPos 1 1 3 -overlay +vdisplay ltr -2d topRight 3 3 -overlay # display polyline in overlay in the bottom right corner of the view text2brep tbr "Bottom-Right" -font SansFont -height 30 -pos -165 0 0 -vdisplay tbr -2d -trsfPersPos 1 -1 5 -osd +vdisplay tbr -2d bottomRight 5 5 -osd polyline lbr -100 0 0 -100 100 0 0 100 0 0 50 0 -50 0 0 -100 0 0 -vdisplay lbr -2d -trsfPersPos 1 -1 3 -overlay +vdisplay lbr -2d bottomRight 3 3 -overlay vdump ${imagedir}/${casename}.png diff --git a/tests/bugs/vis/bug26149 b/tests/bugs/vis/bug26149 index 19e096e85c..d5b5a598da 100644 --- a/tests/bugs/vis/bug26149 +++ b/tests/bugs/vis/bug26149 @@ -11,29 +11,29 @@ vclear vaxo text2brep tcc "Center" -font SansFont -height 30 -vdisplay tcc -2d -underlay +vdisplay tcc -2d center -underlay polyline lcc -50 -50 0 -50 50 0 50 50 0 50 0 0 0 -50 0 -50 -50 0 -vdisplay lcc -2d -underlay +vdisplay lcc -2d center -underlay text2brep tbl "Bottom-Left" -font SansFont -height 30 -vdisplay tbl -2d -trsfPersPos -1 -1 5 -underlay +vdisplay tbl -2d bottomLeft 5 5 -underlay polyline lbl 0 0 0 0 100 0 100 100 0 100 50 0 50 0 0 0 0 0 -vdisplay lbl -2d -trsfPersPos -1 -1 3 -underlay +vdisplay lbl -2d bottomLeft 3 3 -underlay text2brep ttl "Top-Left" -font SansFont -height 30 -pos -27 0 0 -vdisplay ttl -2d -trsfPersPos -1 1 30 -underlay +vdisplay ttl -2d topLeft 30 30 -underlay polyline ltl 0 -100 0 0 0 0 100 0 0 100 -50 0 50 -100 0 0 -100 0 -vdisplay ltl -2d -trsfPersPos -1 1 3 -underlay +vdisplay ltl -2d topLeft 3 3 -underlay text2brep ttr "Top-Right" -font SansFont -height 30 -pos -100 0 0 -vdisplay ttr -2d -trsfPersPos 1 1 30 -underlay +vdisplay ttr -2d topRight 30 30 -underlay polyline ltr -100 -100 0 -100 0 0 0 0 0 0 -50 0 -50 -100 0 -100 -100 0 -vdisplay ltr -2d -trsfPersPos 1 1 3 -underlay +vdisplay ltr -2d topRight 3 3 -underlay text2brep tbr "Bottom-Right" -font SansFont -height 30 -pos -165 0 0 -vdisplay tbr -2d -trsfPersPos 1 -1 5 -underlay +vdisplay tbr -2d bottomRight 5 5 -underlay polyline lbr -100 0 0 -100 100 0 0 100 0 0 50 0 -50 0 0 -100 0 0 -vdisplay lbr -2d -trsfPersPos 1 -1 3 -underlay +vdisplay lbr -2d bottomRight 3 3 -underlay box b 1 2 3 vdisplay b diff --git a/tests/bugs/vis/bug26344 b/tests/bugs/vis/bug26344 index 7ea8a20e0c..d96000a25c 100644 --- a/tests/bugs/vis/bug26344 +++ b/tests/bugs/vis/bug26344 @@ -13,18 +13,18 @@ vinit View1 w=409 h=409 vtrihedron tri vpan 50 50 -box b1 25 25 25 -box b2 25 25 25 -box b3 100 100 100 -box b4 100 100 100 -box b5 100 100 100 +box bz1 25 25 25 +box bz2 25 25 25 +box br 100 100 100 +box bzr 50 25 20 +box bt 100 100 100 # 1) Zoom persistence -vpoint p1 200 200 200 +vpoint pz 200 200 200 -vdisplay b1 -dispMode 1 -highMode 1 -trsfPers zoom -trsfPersPos 200 200 200 -vdisplay b2 -dispMode 1 -highMode 1 -trsfPers zoom -trsfPersPos 200 200 200 -vsetlocation b2 -25 -25 -25 +vdisplay bz1 -dispMode 1 -highMode 1 -trsfPers zoom -trsfPersPos 200 200 200 +vdisplay bz2 -dispMode 1 -highMode 1 -trsfPers zoom -trsfPersPos 200 200 200 +vsetlocation bz2 -25 -25 -25 vselect 0 0 vselect 387 77 @@ -36,8 +36,9 @@ if { [vreadpixel 387 77 rgb name] != "GRAY66" || [vreadpixel 352 96 rgb name] != # 2) Rotate persistence -vdisplay b3 -dispMode 1 -highMode 1 -trsfPers rotate -trsfPersPos -200 -200 -200 -vsetmaterial b3 PLASTIC +vpoint pr -200 -200 -200 +vdisplay br -dispMode 1 -highMode 1 -trsfPers rotate -trsfPersPos -200 -200 -200 +vsetmaterial br PLASTIC vselect 0 0 vselect 160 200 if { [vreadpixel 160 180 rgb name] != "WHITE" } { puts "Error picking rotate persistence object" } @@ -46,19 +47,22 @@ vselect 0 0 vselect 130 230 190 170 if { [vreadpixel 160 180 rgb name] != "WHITE" } { puts "Error selecting rotate persistence object" } -# 3) Pan persistence +# 3) Zoom + Rotate persistence -vdisplay b4 -dispMode 1 -highMode 1 -trsfPers pan +vpoint pzr -200 100 0 +vdisplay bzr -dispMode 1 -highMode 1 -trsfPers zoomRotate -trsfPersPos -200 100 0 + +vsetmaterial bzr PLASTIC vselect 0 0 -vselect 233 188 -if { [vreadpixel 233 188 rgb name] != "GRAY66" } { puts "Error picking pan persistence object" } +vselect 250 90 +if { [vreadpixel 250 90 rgb name] != "WHITE" } { puts "Error picking zoom-rotate persistence object" } vselect 0 0 -vselect 200 230 270 140 -if { [vreadpixel 233 188 rgb name] != "GRAY66" } { puts "Error selecting pan persistence object" } +vselect 200 70 286 110 +if { [vreadpixel 250 90 rgb name] != "WHITE" } { puts "Error selecting zoom-rotate persistence object" } # 4) Trihedron persistence -vdisplay b5 -dispMode 1 -highMode 1 -trsfPers trihedron -trsfPersPos -1 -1 62 +vdisplay bt -dispMode 1 -highMode 1 -trsfPers trihedron -trsfPersPos -1 -1 62 vselect 0 0 vselect 132 300 if { [vreadpixel 132 300 rgb name] != "GRAY66" } { puts "Error picking trihedron persistence object" } diff --git a/tests/bugs/vis/bug27739 b/tests/bugs/vis/bug27739 index 91afe26362..2b33d24e40 100644 --- a/tests/bugs/vis/bug27739 +++ b/tests/bugs/vis/bug27739 @@ -22,9 +22,9 @@ box box2d_loc 100 100 1 box box_zoom 100 100 100 vdisplay box3d -dispMode 1 -highMode 0 -vdisplay box2d -dispMode 1 -highMode 1 -2d -vdisplay box2d_pos -dispMode 1 -highMode 1 -2d -trsfPersPos -1 -1 -vdisplay box2d_loc -dispMode 1 -highMode 1 -2d +vdisplay box2d -dispMode 1 -highMode 1 -2d center +vdisplay box2d_pos -dispMode 1 -highMode 1 -2d bottomLeft +vdisplay box2d_loc -dispMode 1 -highMode 1 -2d center vdisplay box_zoom -dispMode 1 -highMode 0 -trsfPers zoom vdisplay box2d vsetlocation box2d_loc 100 0 0 diff --git a/tests/v3d/glsl/tiles b/tests/v3d/glsl/tiles index d8906c9cc3..099c79a17d 100644 --- a/tests/v3d/glsl/tiles +++ b/tests/v3d/glsl/tiles @@ -30,36 +30,36 @@ vzlayer add 1 vzlayer enable 1 depthclear vtrihedron trh -vdisplay -noupdate trh -layer 1 -trsfPers trihedron -trsfPersPos 1 1 100 +vdisplay -noupdate trh -layer 1 -trihedron topRight 100 100 text2brep tcc "Center" -font $aLabelFont -height 30 -pos -40 0 0 -vdisplay -noupdate tcc -2d -layer 1 -dispMode 1 +vdisplay -noupdate tcc -2d center -layer 1 -dispMode 1 polyline lcc -50 -50 0 -50 50 0 50 50 0 50 0 0 0 -50 0 -50 -50 0 -vdisplay -noupdate lcc -2d -layer 1 +vdisplay -noupdate lcc -2d center -layer 1 vsetwidth -noupdate lcc 2 text2brep tbl "Bottom-Left" -font $aLabelFont -height 30 -pos 0 3 5 -vdisplay -noupdate tbl -2d -layer 1 -trsfPersPos -1 -1 -dispMode 1 +vdisplay -noupdate tbl -2d bottomLeft -layer 1 -dispMode 1 polyline lbl 0 0 0 0 100 0 100 100 0 100 50 0 50 0 0 0 0 0 -vdisplay -noupdate lbl -2d -layer 1 -trsfPersPos -1 -1 +vdisplay -noupdate lbl -2d bottomLeft -layer 1 vsetwidth -noupdate lbl 2 text2brep ttl "Top-Left" -font $aLabelFont -height 30 -pos 0 -30 0 -vdisplay -noupdate ttl -2d -layer 1 -trsfPersPos -1 1 -dispMode 1 +vdisplay -noupdate ttl -2d topLeft -layer 1 -dispMode 1 polyline ltl 0 -100 0 0 0 0 100 0 0 100 -50 0 50 -100 0 0 -100 0 -vdisplay -noupdate ltl -2d -layer 1 -trsfPersPos -1 1 +vdisplay -noupdate ltl -2d topLeft -layer 1 vsetwidth -noupdate ltl 2 text2brep ttr "Top-Right" -font $aLabelFont -height 30 -pos -130 -30 0 -vdisplay -noupdate ttr -2d -layer 1 -trsfPersPos 1 1 -dispMode 1 +vdisplay -noupdate ttr -2d topRight -layer 1 -dispMode 1 polyline ltr -100 -100 0 -100 0 0 0 0 0 0 -50 0 -50 -100 0 -100 -100 0 -vdisplay -noupdate ltr -2d -layer 1 -trsfPersPos 1 1 +vdisplay -noupdate ltr -2d topRight -layer 1 vsetwidth -noupdate ltr 2 text2brep tbr "Bottom-Right" -font $aLabelFont -height 30 -pos -180 3 0 -vdisplay -noupdate tbr -2d -layer 1 -trsfPersPos 1 -1 -dispMode 1 +vdisplay -noupdate tbr -2d bottomRight -layer 1 -dispMode 1 polyline lbr -100 0 0 -100 100 0 0 100 0 0 50 0 -50 0 0 -100 0 0 -vdisplay -noupdate lbr -2d -layer 1 -trsfPersPos 1 -1 +vdisplay -noupdate lbr -2d bottomRight -layer 1 vsetwidth -noupdate lbr 2 vdrawtext t2 "Label" -pos 1 0 1 -font $aLabelFont -- 2.20.1