From: aba Date: Thu, 7 Apr 2016 08:50:33 +0000 (+0300) Subject: 0027359: Visualization - add support of flipping for textured text X-Git-Tag: V7_0_winwerth~87 X-Git-Url: http://git.dev.opencascade.org/gitweb/?p=occt.git;a=commitdiff_plain;h=3f1eb0abf9ccfb64bcfb9284664324e5313cf8e8 0027359: Visualization - add support of flipping for textured text Added option for OpenGl_Text to use previous model-view state. Added interface to enable this option in Prs3d_Text Added option to enable flipping in AIS_NameLabel Eliminated warning --- diff --git a/src/AIS/AIS_TextLabel.cxx b/src/AIS/AIS_TextLabel.cxx index 94462acdfc..8c35450142 100644 --- a/src/AIS/AIS_TextLabel.cxx +++ b/src/AIS/AIS_TextLabel.cxx @@ -14,7 +14,12 @@ #include +#include +#include +#include +#include #include +#include #include #include @@ -23,6 +28,8 @@ #include #include +#include + IMPLEMENT_STANDARD_RTTIEXT(AIS_TextLabel,AIS_InteractiveObject) @@ -34,7 +41,8 @@ AIS_TextLabel::AIS_TextLabel() : myText ("?"), myFont ("Courier"), myFontAspect (Font_FA_Regular), - myHasOrientation3D (Standard_False) + myHasOrientation3D (Standard_False), + myHasFlipping (Standard_False) { myDrawer->SetTextAspect (new Prs3d_TextAspect()); @@ -181,7 +189,7 @@ const gp_Ax2& AIS_TextLabel::Orientation3D() const } //======================================================================= -//function : HasOrientation3D() +//function : HasOrientation3D //purpose : //======================================================================= Standard_Boolean AIS_TextLabel::HasOrientation3D() const @@ -189,6 +197,24 @@ Standard_Boolean AIS_TextLabel::HasOrientation3D() const return myHasOrientation3D; } +//======================================================================= +//function : SetFlipping +//purpose : +//======================================================================= +void AIS_TextLabel::SetFlipping (const Standard_Boolean theIsFlipping) +{ + myHasFlipping = theIsFlipping; +} + +//======================================================================= +//function : HasFlipping +//purpose : +//======================================================================= +Standard_Boolean AIS_TextLabel::HasFlipping() const +{ + return myHasFlipping; +} + //======================================================================= //function : SetDisplayType //purpose : @@ -207,6 +233,7 @@ void AIS_TextLabel::SetColorSubTitle (const Quantity_Color& theColor) myDrawer->TextAspect()->Aspect()->SetColorSubTitle(theColor); } +#include //======================================================================= //function : Compute //purpose : @@ -220,10 +247,67 @@ void AIS_TextLabel::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePr case 0: { Handle(Prs3d_TextAspect) anAsp = myDrawer->TextAspect(); + gp_Pnt aPosition = Position(); if (myHasOrientation3D) { - Prs3d_Text::Draw (thePrs, anAsp, myText, myOrientation3D); + Standard_Boolean isInit = Standard_False; + if (myHasFlipping) + { + // Get width and height of text + Font_FTFont aFont; + Quantity_Color aColor; + Standard_CString aName; + Standard_Real anExpFactor; + Standard_Real aSpace; + + anAsp->Aspect()->Values (aColor, aName, anExpFactor, aSpace); + unsigned int aResolution = GetContext()->CurrentViewer()->DefaultRenderingParams().Resolution; + if (aFont.Init (aName, anAsp->Aspect()->GetTextFontAspect(), (unsigned int)anAsp->Height(), aResolution)) + { + isInit = Standard_True; + const NCollection_String aText ((Standard_Utf16Char* )myText.ToExtString()); + Font_Rect aBndBox = aFont.BoundingBox (aText, anAsp->HorizontalJustification(), anAsp->VerticalJustification()); + Standard_Real aWidth = Abs (aBndBox.Width()); + Standard_Real aHeight = Abs (aBndBox.Height()); + gp_Pnt aCenterOfLabel = aPosition; + + if (anAsp->VerticalJustification() == Graphic3d_VTA_BOTTOM) + { + aCenterOfLabel.ChangeCoord() += myOrientation3D.YDirection().XYZ() * aHeight * 0.5; + } + else if (anAsp->VerticalJustification() == Graphic3d_VTA_TOP) + { + aCenterOfLabel.ChangeCoord() -= myOrientation3D.YDirection().XYZ() * aHeight * 0.5; + } + if (anAsp->HorizontalJustification() == Graphic3d_HTA_LEFT) + { + aCenterOfLabel.ChangeCoord() += myOrientation3D.XDirection().XYZ() * aWidth * 0.5; + } + else if (anAsp->HorizontalJustification() == Graphic3d_HTA_RIGHT) + { + aCenterOfLabel.ChangeCoord() -= myOrientation3D.XDirection().XYZ() * aWidth * 0.5; + } + + if (!anAsp->Aspect()->GetTextZoomable()) + { + anAsp->Aspect()->SetTextZoomable (Standard_True); + SetTransformPersistence (GetTransformPersistenceMode() | Graphic3d_TMF_ZoomPers, aPosition); + aPosition = gp::Origin(); + } + + gp_Ax2 aFlippingAxes (aCenterOfLabel, myOrientation3D.Direction(), myOrientation3D.XDirection()); + Prs3d_Root::CurrentGroup (thePrs)->SetFlippingOptions (Standard_True, aFlippingAxes); + } + } + + gp_Ax2 anOrientation = myOrientation3D; + anOrientation.SetLocation (aPosition); + Prs3d_Text::Draw (thePrs, anAsp, myText, myOrientation3D, !myHasFlipping); + if (myHasFlipping && isInit) + { + Prs3d_Root::CurrentGroup (thePrs)->SetFlippingOptions (Standard_False, gp_Ax2()); + } } else { diff --git a/src/AIS/AIS_TextLabel.hxx b/src/AIS/AIS_TextLabel.hxx index 33cd6d7a85..3293c95572 100644 --- a/src/AIS/AIS_TextLabel.hxx +++ b/src/AIS/AIS_TextLabel.hxx @@ -80,6 +80,10 @@ public: //! Returns true if the current text placement mode uses text orientation in the model 3D space. Standard_EXPORT Standard_Boolean HasOrientation3D() const; + Standard_EXPORT void SetFlipping (const Standard_Boolean theIsFlipping); + + Standard_EXPORT Standard_Boolean HasFlipping() const; + //! Define the display type of the text. //! //! TODT_NORMAL Default display. Text only. @@ -111,6 +115,7 @@ protected: Font_FontAspect myFontAspect; gp_Ax2 myOrientation3D; Standard_Boolean myHasOrientation3D; + Standard_Boolean myHasFlipping; public: diff --git a/src/Graphic3d/Graphic3d_Group.cxx b/src/Graphic3d/Graphic3d_Group.cxx index 6b13361c53..3324956ac2 100644 --- a/src/Graphic3d/Graphic3d_Group.cxx +++ b/src/Graphic3d/Graphic3d_Group.cxx @@ -1149,7 +1149,8 @@ void Graphic3d_Group::Text (const TCollection_ExtendedString& theText, const Graphic3d_TextPath theTP, const Graphic3d_HorizontalTextAlignment theHTA, const Graphic3d_VerticalTextAlignment theVTA, - const Standard_Boolean theToEvalMinMax) + const Standard_Boolean theToEvalMinMax, + const Standard_Boolean theHasOwnAnchor) { const NCollection_String aText ((Standard_Utf16Char*)(theText.ToExtString())); Text (aText.ToCString(), @@ -1159,7 +1160,8 @@ void Graphic3d_Group::Text (const TCollection_ExtendedString& theText, theTP, theHTA, theVTA, - theToEvalMinMax); + theToEvalMinMax, + theHasOwnAnchor); } // ======================================================================= @@ -1173,7 +1175,8 @@ void Graphic3d_Group::Text (const Standard_CString /*theText*/, const Graphic3d_TextPath /*theTp*/, const Graphic3d_HorizontalTextAlignment /*theHta*/, const Graphic3d_VerticalTextAlignment /*theVta*/, - const Standard_Boolean theToEvalMinMax) + const Standard_Boolean theToEvalMinMax, + const Standard_Boolean /*theHasOwnAnchor*/) { if (IsDeleted()) { diff --git a/src/Graphic3d/Graphic3d_Group.hxx b/src/Graphic3d/Graphic3d_Group.hxx index 277c0d8e24..1207b927a8 100644 --- a/src/Graphic3d/Graphic3d_Group.hxx +++ b/src/Graphic3d/Graphic3d_Group.hxx @@ -226,7 +226,8 @@ public: const Graphic3d_TextPath theTp, const Graphic3d_HorizontalTextAlignment theHTA, const Graphic3d_VerticalTextAlignment theVTA, - const Standard_Boolean theToEvalMinMax = Standard_True); + const Standard_Boolean theToEvalMinMax = Standard_True, + const Standard_Boolean theHasOwnAnchor = Standard_True); //! Creates the string at orientation in 3D space. Standard_EXPORT virtual void Text (const TCollection_ExtendedString& theText, @@ -236,7 +237,8 @@ public: const Graphic3d_TextPath theTp, const Graphic3d_HorizontalTextAlignment theHTA, const Graphic3d_VerticalTextAlignment theVTA, - const Standard_Boolean theToEvalMinMax = Standard_True); + const Standard_Boolean theToEvalMinMax = Standard_True, + const Standard_Boolean theHasOwnAnchor = Standard_True); //! Adds an array of primitives for display diff --git a/src/OpenGl/OpenGl_Group.cxx b/src/OpenGl/OpenGl_Group.cxx index 84d3466182..bd8d918ab3 100644 --- a/src/OpenGl/OpenGl_Group.cxx +++ b/src/OpenGl/OpenGl_Group.cxx @@ -243,7 +243,8 @@ void OpenGl_Group::Text (const Standard_CString theTextUtf, const Graphic3d_TextPath theTp, const Graphic3d_HorizontalTextAlignment theHTA, const Graphic3d_VerticalTextAlignment theVTA, - const Standard_Boolean theToEvalMinMax) + const Standard_Boolean theToEvalMinMax, + const Standard_Boolean theHasOwnAnchor) { if (IsDeleted()) { @@ -257,7 +258,7 @@ void OpenGl_Group::Text (const Standard_CString theTextUtf, aParams.HAlign = theHTA; aParams.VAlign = theVTA; - OpenGl_Text* aText = new OpenGl_Text (theTextUtf, theOrientation, aParams); + OpenGl_Text* aText = new OpenGl_Text (theTextUtf, theOrientation, aParams, theHasOwnAnchor != Standard_False); AddElement (aText); @@ -268,7 +269,8 @@ void OpenGl_Group::Text (const Standard_CString theTextUtf, theTp, theHTA, theVTA, - theToEvalMinMax); + theToEvalMinMax, + theHasOwnAnchor); } diff --git a/src/OpenGl/OpenGl_Group.hxx b/src/OpenGl/OpenGl_Group.hxx index af592d49fb..ec711d3fb1 100644 --- a/src/OpenGl/OpenGl_Group.hxx +++ b/src/OpenGl/OpenGl_Group.hxx @@ -85,7 +85,8 @@ public: const Graphic3d_TextPath theTp, const Graphic3d_HorizontalTextAlignment theHTA, const Graphic3d_VerticalTextAlignment theVTA, - const Standard_Boolean theToEvalMinMax) Standard_OVERRIDE; + const Standard_Boolean theToEvalMinMax, + const Standard_Boolean theHasOwnAnchor = Standard_True) Standard_OVERRIDE; //! Add flipping element Standard_EXPORT virtual void SetFlippingOptions (const Standard_Boolean theIsEnabled, diff --git a/src/OpenGl/OpenGl_Text.cxx b/src/OpenGl/OpenGl_Text.cxx index bf3b4d20bc..74552a1242 100644 --- a/src/OpenGl/OpenGl_Text.cxx +++ b/src/OpenGl/OpenGl_Text.cxx @@ -149,7 +149,8 @@ OpenGl_Text::OpenGl_Text() myScaleHeight (1.0f), myPoint (0.0f, 0.0f, 0.0f), myIs2d (false), - myHasPlane (false) + myHasPlane (false), + myHasAnchorPoint (true) { myParams.Height = 10; myParams.HAlign = Graphic3d_HTA_LEFT; @@ -172,7 +173,8 @@ OpenGl_Text::OpenGl_Text (const Standard_Utf8Char* theText, myString (theText), myPoint (thePoint), myIs2d (false), - myHasPlane (false) + myHasPlane (false), + myHasAnchorPoint (true) { // } @@ -183,7 +185,8 @@ OpenGl_Text::OpenGl_Text (const Standard_Utf8Char* theText, // ======================================================================= OpenGl_Text::OpenGl_Text (const Standard_Utf8Char* theText, const gp_Ax2& theOrientation, - const OpenGl_TextParam& theParams) + const OpenGl_TextParam& theParams, + const bool theHasOwnAnchor) : myWinX (0.0), myWinY (0.0), myWinZ (0.0), @@ -193,7 +196,8 @@ OpenGl_Text::OpenGl_Text (const Standard_Utf8Char* theText, myString (theText), myIs2d (false), myOrientation (theOrientation), - myHasPlane (true) + myHasPlane (true), + myHasAnchorPoint (theHasOwnAnchor) { const gp_Pnt& aPoint = theOrientation.Location(); myPoint = OpenGl_Vec3 (static_cast (aPoint.X()), @@ -479,8 +483,7 @@ void OpenGl_Text::setupMatrix (const Handle(OpenGl_PrinterContext)& thePrintCtx, { OpenGl_Mat4d aModViewMat; OpenGl_Mat4d aProjectMat; - - if (myHasPlane) + if (myHasPlane && myHasAnchorPoint) { aProjectMat = myProjMatrix * myOrientationMatrix; } @@ -516,10 +519,21 @@ void OpenGl_Text::setupMatrix (const Handle(OpenGl_PrinterContext)& thePrintCtx, const gp_Dir& aVectorUp = myOrientation.Direction(); const gp_Dir& aVectorRight = myOrientation.YDirection(); - aModViewMat.SetColumn (3, OpenGl_Vec3d (anObjX, anObjY, anObjZ)); aModViewMat.SetColumn (2, OpenGl_Vec3d (aVectorUp.X(), aVectorUp.Y(), aVectorUp.Z())); aModViewMat.SetColumn (1, OpenGl_Vec3d (aVectorRight.X(), aVectorRight.Y(), aVectorRight.Z())); aModViewMat.SetColumn (0, OpenGl_Vec3d (aVectorDir.X(), aVectorDir.Y(), aVectorDir.Z())); + + if (!myHasAnchorPoint) + { + OpenGl_Mat4d aPosMat; + aPosMat.SetColumn (3, OpenGl_Vec3d (myPoint.x(), myPoint.y(), myPoint.z())); + aPosMat *= aModViewMat; + aModViewMat.SetColumn (3, aPosMat.GetColumn (3)); + } + else + { + aModViewMat.SetColumn (3, OpenGl_Vec3d (anObjX, anObjY, anObjZ)); + } } else { @@ -549,7 +563,16 @@ void OpenGl_Text::setupMatrix (const Handle(OpenGl_PrinterContext)& thePrintCtx, } } - theCtx->WorldViewState.SetCurrent (aModViewMat); + if (myHasPlane && !myHasAnchorPoint) + { + OpenGl_Mat4d aCurrentWorldViewMat; + aCurrentWorldViewMat.Convert (theCtx->WorldViewState.Current()); + theCtx->WorldViewState.SetCurrent (aCurrentWorldViewMat * aModViewMat); + } + else + { + theCtx->WorldViewState.SetCurrent (aModViewMat); + } theCtx->ApplyWorldViewMatrix(); if (!myIs2d) @@ -758,7 +781,18 @@ void OpenGl_Text::render (const Handle(OpenGl_PrinterContext)& thePrintCtx, myExportHeight = 1.0f; myScaleHeight = 1.0f; - theCtx->WorldViewState.Push(); + if (myHasPlane && !myHasAnchorPoint) + { + OpenGl_Mat4d aWorldViewMat; + aWorldViewMat.Convert (theCtx->WorldViewState.Current()); + theCtx->WorldViewState.Push(); + theCtx->WorldViewState.SetCurrent (aWorldViewMat); + theCtx->ApplyWorldViewMatrix(); + } + else + { + theCtx->WorldViewState.Push(); + } myModelMatrix.Convert (theCtx->WorldViewState.Current() * theCtx->ModelWorldState.Current()); diff --git a/src/OpenGl/OpenGl_Text.hxx b/src/OpenGl/OpenGl_Text.hxx index 6615698bed..224db5958c 100755 --- a/src/OpenGl/OpenGl_Text.hxx +++ b/src/OpenGl/OpenGl_Text.hxx @@ -46,7 +46,8 @@ public: //! Creates new text in 3D space. Standard_EXPORT OpenGl_Text (const Standard_Utf8Char* theText, const gp_Ax2& theOrientation, - const OpenGl_TextParam& theParams); + const OpenGl_TextParam& theParams, + const bool theHasOwnAnchor = true); //! Setup new string and position Standard_EXPORT void Init (const Handle(OpenGl_Context)& theCtx, @@ -168,6 +169,7 @@ protected: bool myIs2d; gp_Ax2 myOrientation; //!< Text orientation in 3D space. bool myHasPlane; //!< Check if text have orientation in 3D space. + bool myHasAnchorPoint; //!< Shows if it has own attach point public: diff --git a/src/Prs3d/Prs3d_Text.cxx b/src/Prs3d/Prs3d_Text.cxx index 797b9da063..a3bca420b0 100644 --- a/src/Prs3d/Prs3d_Text.cxx +++ b/src/Prs3d/Prs3d_Text.cxx @@ -66,7 +66,8 @@ void Prs3d_Text::Draw ( void Prs3d_Text::Draw (const Handle(Prs3d_Presentation)& thePresentation, const Handle(Prs3d_TextAspect)& theAspect, const TCollection_ExtendedString& theText, - const gp_Ax2& theOrientation) + const gp_Ax2& theOrientation, + const Standard_Boolean theHasOwnAnchor) { Prs3d_Root::CurrentGroup (thePresentation)->SetPrimitivesAspect (theAspect->Aspect()); Prs3d_Root::CurrentGroup (thePresentation)->Text (theText, @@ -75,5 +76,7 @@ void Prs3d_Text::Draw (const Handle(Prs3d_Presentation)& thePresentation, theAspect->Angle(), theAspect->Orientation(), theAspect->HorizontalJustification(), - theAspect->VerticalJustification()); + theAspect->VerticalJustification(), + Standard_True, + theHasOwnAnchor); } diff --git a/src/Prs3d/Prs3d_Text.hxx b/src/Prs3d/Prs3d_Text.hxx index 87634a4cce..411861810e 100644 --- a/src/Prs3d/Prs3d_Text.hxx +++ b/src/Prs3d/Prs3d_Text.hxx @@ -54,7 +54,8 @@ public: Standard_EXPORT static void Draw (const Handle(Prs3d_Presentation)& thePresentation, const Handle(Prs3d_TextAspect)& theAspect, const TCollection_ExtendedString& theText, - const gp_Ax2& theOrientation); + const gp_Ax2& theOrientation, + const Standard_Boolean theHasOwnAnchor = Standard_True); //! Defines the display of the text aText at the point //! AttachmentPoint. diff --git a/src/ViewerTest/ViewerTest_ObjectCommands.cxx b/src/ViewerTest/ViewerTest_ObjectCommands.cxx index 01af7825fa..dfe1ff9a34 100644 --- a/src/ViewerTest/ViewerTest_ObjectCommands.cxx +++ b/src/ViewerTest/ViewerTest_ObjectCommands.cxx @@ -2727,6 +2727,10 @@ static int VDrawText (Draw_Interpretor& theDI, aHasPlane = Standard_True; } + else if (aParam == "-flipping") + { + aTextPrs->SetFlipping (Standard_True); + } else if (aParam == "-disptype" || aParam == "-displaytype") { @@ -6410,6 +6414,7 @@ void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands) "\n\t\t: [-subcolor {R G B|name}=white]" "\n\t\t: [-noupdate]" "\n\t\t: [-plane NormX NormY NormZ DirX DirY DirZ]" + "\n\t\t: [-flipping]" "\n\t\t: Display text label at specified position.", __FILE__, VDrawText, group); diff --git a/tests/bugs/vis/bug27359 b/tests/bugs/vis/bug27359 new file mode 100644 index 0000000000..033d3252f8 --- /dev/null +++ b/tests/bugs/vis/bug27359 @@ -0,0 +1,43 @@ +puts "========" +puts "OCC27359" +puts "========" +puts "" +################################################################## +puts "Visualization - add support of flipping for textured text" +################################################################## + +set anImage1 $imagedir/${casename}_1.png +set anImage2 $imagedir/${casename}_2.png +set anImage3 $imagedir/${casename}_3.png +set m_pi 3,14 +set m_pi2 1,57 + +vfont add [locate_data_file DejaVuSans.ttf] SansFont + +vinit +vclear +vright + +set x 10 +set y 50 +set z 30 + +box b $x $y $z +vdisplay b +vtrihedron t + +vdrawtext t0 "top left text\n on yoz" -pos $x 0 0 -color green -height 30 -plane 1 0 0 0 1 0 -flipping -valign top -halign left -font SansFont +vdrawtext t2 "center text" -pos 0 $y/2 $z/2 -color red -height 30 -plane 1 0 0 0 1 0 -flipping -valign center -halign center -font SansFont + +vfit +vright +vdump $anImage1 + +vrotate $m_pi 0 0 +vfit +vdump $anImage2 + +vright +vrotate 0 $m_pi 0 +vfit +vdump $anImage3 \ No newline at end of file