From ce01ec266044f90c7281d32ac6b16bd832c0a614 Mon Sep 17 00:00:00 2001 From: isk Date: Thu, 3 Sep 2015 10:16:57 +0300 Subject: [PATCH] 0026343: Visualization - Zoom persistent text with 3D orientation --- src/AIS/AIS_TextLabel.cxx | 69 ++++++++++++++++-- src/AIS/AIS_TextLabel.hxx | 22 +++++- src/Graphic3d/Graphic3d_Group.cxx | 53 ++++++++++++++ src/Graphic3d/Graphic3d_Group.hxx | 27 ++++++- src/OpenGl/OpenGl_Group.cxx | 40 ++++++++++ src/OpenGl/OpenGl_Group.hxx | 10 +++ src/OpenGl/OpenGl_Text.cxx | 77 ++++++++++++++++++-- src/OpenGl/OpenGl_Text.hxx | 10 +++ src/Prs3d/Prs3d_Text.cxx | 19 +++++ src/Prs3d/Prs3d_Text.hxx | 9 +++ src/ViewerTest/ViewerTest_ObjectCommands.cxx | 37 +++++++++- tests/3rdparty/grids.list | 1 + tests/3rdparty/text3d/A1 | 30 ++++++++ 13 files changed, 382 insertions(+), 22 deletions(-) create mode 100644 tests/3rdparty/text3d/A1 diff --git a/src/AIS/AIS_TextLabel.cxx b/src/AIS/AIS_TextLabel.cxx index f04c308676..3f2ae73f7e 100644 --- a/src/AIS/AIS_TextLabel.cxx +++ b/src/AIS/AIS_TextLabel.cxx @@ -29,10 +29,10 @@ //purpose : //======================================================================= AIS_TextLabel::AIS_TextLabel() -: myText ("?"), - myPosition (0.0, 0.0, 0.0), - myFont ("Courier"), - myFontAspect (Font_FA_Regular) +: myText ("?"), + myFont ("Courier"), + myFontAspect (Font_FA_Regular), + myHasOrientation3D (Standard_False) { myDrawer->SetTextAspect (new Prs3d_TextAspect()); @@ -74,7 +74,7 @@ void AIS_TextLabel::SetText (const TCollection_ExtendedString& theText) //======================================================================= void AIS_TextLabel::SetPosition (const gp_Pnt& thePosition) { - myPosition = thePosition; + myOrientation3D.SetLocation (thePosition); } //======================================================================= @@ -141,6 +141,52 @@ void AIS_TextLabel::SetFont (Standard_CString theFont) myDrawer->TextAspect()->SetFont (myFont.ToCString()); } +//======================================================================= +//function : SetOrientation3D +//purpose : +//======================================================================= +void AIS_TextLabel::SetOrientation3D (const gp_Ax2& theOrientation) +{ + myHasOrientation3D = Standard_True; + myOrientation3D = theOrientation; +} + +//======================================================================= +//function : UnsetOrientation3D +//purpose : +//======================================================================= +void AIS_TextLabel::UnsetOrientation3D () +{ + myHasOrientation3D = Standard_False; +} + +//======================================================================= +//function : Position +//purpose : +//======================================================================= +const gp_Pnt& AIS_TextLabel::Position() const +{ + return myOrientation3D.Location(); +} + +//======================================================================= +//function : Orientation3D +//purpose : +//======================================================================= +const gp_Ax2& AIS_TextLabel::Orientation3D() const +{ + return myOrientation3D; +} + +//======================================================================= +//function : HasOrientation3D() +//purpose : +//======================================================================= +Standard_Boolean AIS_TextLabel::HasOrientation3D() const +{ + return myHasOrientation3D; +} + //======================================================================= //function : SetDisplayType //purpose : @@ -172,7 +218,16 @@ void AIS_TextLabel::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePr case 0: { Handle(Prs3d_TextAspect) anAsp = myDrawer->TextAspect(); - Prs3d_Text::Draw (thePrs, anAsp, myText, myPosition); + + if (myHasOrientation3D) + { + Prs3d_Text::Draw (thePrs, anAsp, myText, myOrientation3D); + } + else + { + Prs3d_Text::Draw (thePrs, anAsp, myText, Position()); + } + break; } } @@ -190,7 +245,7 @@ void AIS_TextLabel::ComputeSelection (const Handle(SelectMgr_Selection)& theSele case 0: { Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this, 10); - Handle(Select3D_SensitivePoint) aSensitivePoint = new Select3D_SensitivePoint (anEntityOwner, myPosition); + Handle(Select3D_SensitivePoint) aSensitivePoint = new Select3D_SensitivePoint (anEntityOwner, Position()); theSelection->Add (aSensitivePoint); break; } diff --git a/src/AIS/AIS_TextLabel.hxx b/src/AIS/AIS_TextLabel.hxx index 9c81ff2032..f4dedc9ff3 100644 --- a/src/AIS/AIS_TextLabel.hxx +++ b/src/AIS/AIS_TextLabel.hxx @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -43,9 +44,6 @@ public: //! Setup position. Standard_EXPORT void SetPosition (const gp_Pnt& thePosition); - //! Get position. - Standard_EXPORT gp_Pnt GetPosition () {return myPosition;}; - //! Setup horizontal justification. Standard_EXPORT void SetHJustification (const Graphic3d_HorizontalTextAlignment theHJust); @@ -67,6 +65,21 @@ public: //! Setup font. Standard_EXPORT void SetFont (Standard_CString theFont); + //! Setup label orientation in the model 3D space. + Standard_EXPORT void SetOrientation3D (const gp_Ax2& theOrientation); + + //! Reset label orientation in the model 3D space. + Standard_EXPORT void UnsetOrientation3D (); + + //! Returns position. + Standard_EXPORT const gp_Pnt& Position() const; + + //! Returns label orientation in the model 3D space. + Standard_EXPORT const gp_Ax2& Orientation3D() const; + + //! Returns true if the current text placement mode uses text orientation in the model 3D space. + Standard_EXPORT Standard_Boolean HasOrientation3D() const; + //! Define the display type of the text. //! //! TODT_NORMAL Default display. Text only. @@ -94,9 +107,10 @@ private: protected: TCollection_ExtendedString myText; - gp_Pnt myPosition; TCollection_AsciiString myFont; Font_FontAspect myFontAspect; + gp_Ax2 myOrientation3D; + Standard_Boolean myHasOrientation3D; public: diff --git a/src/Graphic3d/Graphic3d_Group.cxx b/src/Graphic3d/Graphic3d_Group.cxx index 6e8cf95e84..b44c6d7794 100644 --- a/src/Graphic3d/Graphic3d_Group.cxx +++ b/src/Graphic3d/Graphic3d_Group.cxx @@ -1163,6 +1163,59 @@ void Graphic3d_Group::Text (const TCollection_ExtendedString& theText, theTp, theHta, theVta, theToEvalMinMax); } +// ======================================================================= +// function : Text +// purpose : +// ======================================================================= +void Graphic3d_Group::Text (const TCollection_ExtendedString& theText, + const gp_Ax2& theOrientation, + const Standard_Real theHeight, + const Quantity_PlaneAngle theAngle, + const Graphic3d_TextPath theTP, + const Graphic3d_HorizontalTextAlignment theHTA, + const Graphic3d_VerticalTextAlignment theVTA, + const Standard_Boolean theToEvalMinMax) +{ + const NCollection_String aText ((Standard_Utf16Char*)(theText.ToExtString())); + Text (aText.ToCString(), + theOrientation, + theHeight, + theAngle, + theTP, + theHTA, + theVTA, + theToEvalMinMax); +} + +// ======================================================================= +// function : Text +// purpose : +// ======================================================================= +void Graphic3d_Group::Text (const Standard_CString /*theText*/, + const gp_Ax2& theOrientation, + const Standard_Real /*theHeight*/, + const Quantity_PlaneAngle /*theAngle*/, + const Graphic3d_TextPath /*theTp*/, + const Graphic3d_HorizontalTextAlignment /*theHta*/, + const Graphic3d_VerticalTextAlignment /*theVta*/, + const Standard_Boolean theToEvalMinMax) +{ + if (IsDeleted()) + { + return; + } + + if (theToEvalMinMax) + { + myStructure->CStructure()->Is2dText = Standard_False; + myBounds.Add (Graphic3d_Vec4 (static_cast (theOrientation.Location().X()), + static_cast (theOrientation.Location().Y()), + static_cast (theOrientation.Location().Z()), + 1.0f)); + } + Update(); +} + // ======================================================================= // function : Text // purpose : diff --git a/src/Graphic3d/Graphic3d_Group.hxx b/src/Graphic3d/Graphic3d_Group.hxx index 7e48241564..3c780cfa6b 100644 --- a/src/Graphic3d/Graphic3d_Group.hxx +++ b/src/Graphic3d/Graphic3d_Group.hxx @@ -46,13 +46,13 @@ #include #include #include +#include +#include class Graphic3d_Structure; class Graphic3d_GroupDefinitionError; class Standard_OutOfRange; -class TCollection_ExtendedString; class Graphic3d_ArrayOfPrimitives; -class gp_Ax2; class Graphic3d_Group; @@ -86,6 +86,8 @@ DEFINE_STANDARD_HANDLE(Graphic3d_Group, MMgt_TShared) //! //! Developers are strongly recommended to take all the above into account when filling Graphic3d_Group //! with aspects and primitives and choose the group usage model beforehand out of application needs. +//! Note that some Graphic3d_Group class virtual methods contain only base implementation +//! that is extended by the descendant class in OpenGl package. class Graphic3d_Group : public MMgt_TShared { @@ -216,6 +218,27 @@ public: //! AVta : VTA_BOTTOM Standard_EXPORT void Text (const TCollection_ExtendedString& AText, const Graphic3d_Vertex& APoint, const Standard_Real AHeight, const Standard_Boolean EvalMinMax = Standard_True); + //! Creates the string at orientation in 3D space. + Standard_EXPORT virtual void Text (const Standard_CString theTextUtf, + const gp_Ax2& theOrientation, + const Standard_Real theHeight, + const Quantity_PlaneAngle theAngle, + const Graphic3d_TextPath theTp, + const Graphic3d_HorizontalTextAlignment theHTA, + const Graphic3d_VerticalTextAlignment theVTA, + const Standard_Boolean theToEvalMinMax = Standard_True); + + //! Creates the string at orientation in 3D space. + Standard_EXPORT virtual void Text (const TCollection_ExtendedString& theText, + const gp_Ax2& theOrientation, + const Standard_Real theHeight, + const Quantity_PlaneAngle theAngle, + const Graphic3d_TextPath theTp, + const Graphic3d_HorizontalTextAlignment theHTA, + const Graphic3d_VerticalTextAlignment theVTA, + const Standard_Boolean theToEvalMinMax = Standard_True); + + //! Adds an array of primitives for display Standard_EXPORT virtual void AddPrimitiveArray (const Graphic3d_TypeOfPrimitiveArray theType, const Handle(Graphic3d_IndexBuffer)& theIndices, const Handle(Graphic3d_Buffer)& theAttribs, const Handle(Graphic3d_BoundBuffer)& theBounds, const Standard_Boolean theToEvalMinMax = Standard_True); diff --git a/src/OpenGl/OpenGl_Group.cxx b/src/OpenGl/OpenGl_Group.cxx index 19bca09c77..162f2d42a6 100644 --- a/src/OpenGl/OpenGl_Group.cxx +++ b/src/OpenGl/OpenGl_Group.cxx @@ -230,6 +230,46 @@ void OpenGl_Group::Text (const Standard_CString theTextUtf, theTp, theHta, theVta, theToEvalMinMax); } +// ======================================================================= +// function : Text +// purpose : +// ======================================================================= +void OpenGl_Group::Text (const Standard_CString theTextUtf, + const gp_Ax2& theOrientation, + const Standard_Real theHeight, + const Quantity_PlaneAngle theAngle, + const Graphic3d_TextPath theTp, + const Graphic3d_HorizontalTextAlignment theHTA, + const Graphic3d_VerticalTextAlignment theVTA, + const Standard_Boolean theToEvalMinMax) +{ + if (IsDeleted()) + { + return; + } + + OpenGl_TextParam aParams; + OpenGl_Structure* aStruct = GlStruct(); + + aParams.Height = int ((theHeight < 2.0) ? aStruct->GlDriver()->DefaultTextHeight() : theHeight); + aParams.HAlign = theHTA; + aParams.VAlign = theVTA; + + OpenGl_Text* aText = new OpenGl_Text (theTextUtf, theOrientation, aParams); + + AddElement (aText); + + Graphic3d_Group::Text (theTextUtf, + theOrientation, + theHeight, + theAngle, + theTp, + theHTA, + theVTA, + theToEvalMinMax); + +} + // ======================================================================= // function : UserDraw // purpose : diff --git a/src/OpenGl/OpenGl_Group.hxx b/src/OpenGl/OpenGl_Group.hxx index 2ed5401cdd..72bdc249a4 100644 --- a/src/OpenGl/OpenGl_Group.hxx +++ b/src/OpenGl/OpenGl_Group.hxx @@ -77,6 +77,16 @@ public: const Graphic3d_VerticalTextAlignment theVta, const Standard_Boolean theToEvalMinMax); + //! Add text element in 3D space. + Standard_EXPORT virtual void Text (const Standard_CString theTextUtf, + const gp_Ax2& theOrientation, + const Standard_Real theHeight, + const Quantity_PlaneAngle theAngle, + const Graphic3d_TextPath theTp, + const Graphic3d_HorizontalTextAlignment theHTA, + const Graphic3d_VerticalTextAlignment theVTA, + const Standard_Boolean theToEvalMinMax) Standard_OVERRIDE; + //! Add UserDraw element using obsolete API Standard_EXPORT virtual void UserDraw (const Standard_Address theObject, const Standard_Boolean theToEvalMinMax, diff --git a/src/OpenGl/OpenGl_Text.cxx b/src/OpenGl/OpenGl_Text.cxx index 5eaaeef664..61462c749e 100644 --- a/src/OpenGl/OpenGl_Text.cxx +++ b/src/OpenGl/OpenGl_Text.cxx @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -146,7 +147,8 @@ OpenGl_Text::OpenGl_Text() myWinZ (0.0f), myScaleHeight (1.0f), myPoint (0.0f, 0.0f, 0.0f), - myIs2d (false) + myIs2d (false), + myHasPlane (false) { myParams.Height = 10; myParams.HAlign = Graphic3d_HTA_LEFT; @@ -168,11 +170,36 @@ OpenGl_Text::OpenGl_Text (const Standard_Utf8Char* theText, myParams (theParams), myString (theText), myPoint (thePoint), - myIs2d (false) + myIs2d (false), + myHasPlane (false) { // } +// ======================================================================= +// function : OpenGl_Text +// purpose : +// ======================================================================= +OpenGl_Text::OpenGl_Text (const Standard_Utf8Char* theText, + const gp_Ax2& theOrientation, + const OpenGl_TextParam& theParams) +: myWinX (0.0), + myWinY (0.0), + myWinZ (0.0), + myScaleHeight (1.0), + myExportHeight (1.0), + myParams (theParams), + myString (theText), + myIs2d (false), + myOrientation (theOrientation), + myHasPlane (true) +{ + const gp_Pnt& aPoint = theOrientation.Location(); + myPoint = OpenGl_Vec3 (static_cast (aPoint.X()), + static_cast (aPoint.Y()), + static_cast (aPoint.Z())); +} + // ======================================================================= // function : SetPosition // purpose : @@ -389,6 +416,9 @@ void OpenGl_Text::Render (const Handle(OpenGl_Workspace)& theWorkspace) const aTextAspect, aTextAspect->ShaderProgramRes (aCtx)); } + myOrientationMatrix = theWorkspace->ActiveView()->Camera()->OrientationMatrix(); + myProjMatrix.Convert (aCtx->ProjectionState.Current()); + // use highlight color or colors from aspect if (theWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT) { @@ -443,6 +473,16 @@ void OpenGl_Text::setupMatrix (const Handle(OpenGl_PrinterContext)& thePrintCtx, const OpenGl_Vec3 theDVec) const { OpenGl_Mat4d aModViewMat; + OpenGl_Mat4d aProjectMat; + + if (myHasPlane) + { + aProjectMat = myProjMatrix * myOrientationMatrix; + } + else + { + aProjectMat = myProjMatrix; + } if (myIs2d) { @@ -459,14 +499,28 @@ void OpenGl_Text::setupMatrix (const Handle(OpenGl_PrinterContext)& thePrintCtx, std::floor (myWinY + theDVec.y()), myWinZ + theDVec.z(), OpenGl_Mat4d::Map (THE_IDENTITY_MATRIX), - OpenGl_Mat4d::Map (myProjMatrix), + OpenGl_Mat4d::Map (aProjectMat), myViewport, anObjX, anObjY, anObjZ); - Graphic3d_TransformUtils::Translate (aModViewMat, anObjX, anObjY, anObjZ); - Graphic3d_TransformUtils::Rotate (aModViewMat, theTextAspect.Angle(), 0.0, 0.0, 1.0); + if (myHasPlane) + { + const gp_Dir& aVectorDir = myOrientation.XDirection(); + 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())); + } + else + { + Graphic3d_TransformUtils::Translate (aModViewMat, anObjX, anObjY, anObjZ); + Graphic3d_TransformUtils::Rotate (aModViewMat, theTextAspect.Angle(), 0.0, 0.0, 1.0); + } if (!theTextAspect.IsZoomable()) { @@ -491,6 +545,12 @@ void OpenGl_Text::setupMatrix (const Handle(OpenGl_PrinterContext)& thePrintCtx, theCtx->WorldViewState.SetCurrent (aModViewMat); theCtx->ApplyWorldViewMatrix(); + if (!myIs2d) + { + theCtx->ProjectionState.SetCurrent (aProjectMat); + theCtx->ApplyProjectionMatrix(); + } + if (!theCtx->ActiveProgram().IsNull()) { // Upload updated state to shader program @@ -692,7 +752,6 @@ void OpenGl_Text::render (const Handle(OpenGl_PrinterContext)& thePrintCtx, if (!myIs2d) { glGetIntegerv (GL_VIEWPORT, myViewport); - myProjMatrix.Convert (theCtx->ProjectionState.Current()); Graphic3d_TransformUtils::Project (myPoint.x(), myPoint.y(), @@ -832,6 +891,12 @@ void OpenGl_Text::render (const Handle(OpenGl_PrinterContext)& thePrintCtx, setupMatrix (thePrintCtx, theCtx, theTextAspect, OpenGl_Vec3 (0.0f, 0.0f, 0.0f)); drawText (thePrintCtx, theCtx, theTextAspect); + if (!myIs2d) + { + theCtx->ProjectionState.SetCurrent (myProjMatrix); + theCtx->ApplyProjectionMatrix(); + } + #if !defined(GL_ES_VERSION_2_0) if (theCtx->core11 != NULL) { diff --git a/src/OpenGl/OpenGl_Text.hxx b/src/OpenGl/OpenGl_Text.hxx index 88c34de090..aa15e1e1dd 100755 --- a/src/OpenGl/OpenGl_Text.hxx +++ b/src/OpenGl/OpenGl_Text.hxx @@ -27,6 +27,8 @@ #include #include +#include + class OpenGl_PrinterContext; //! Text rendering @@ -40,6 +42,11 @@ public: const OpenGl_Vec3& thePoint, const OpenGl_TextParam& theParams); + //! Creates new text in 3D space. + Standard_EXPORT OpenGl_Text (const Standard_Utf8Char* theText, + const gp_Ax2& theOrientation, + const OpenGl_TextParam& theParams); + //! Setup new string and position Standard_EXPORT void Init (const Handle(OpenGl_Context)& theCtx, const Standard_Utf8Char* theText, @@ -139,6 +146,7 @@ protected: mutable OpenGl_Mat4d myProjMatrix; mutable OpenGl_Mat4d myModelMatrix; + mutable OpenGl_Mat4d myOrientationMatrix; mutable GLint myViewport[4]; mutable GLdouble myWinX; mutable GLdouble myWinY; @@ -152,6 +160,8 @@ protected: NCollection_String myString; OpenGl_Vec3 myPoint; bool myIs2d; + gp_Ax2 myOrientation; //!< Text orientation in 3D space. + bool myHasPlane; //!< Check if text have orientation in 3D space. public: diff --git a/src/Prs3d/Prs3d_Text.cxx b/src/Prs3d/Prs3d_Text.cxx index ea4cd5c86c..797b9da063 100644 --- a/src/Prs3d/Prs3d_Text.cxx +++ b/src/Prs3d/Prs3d_Text.cxx @@ -58,3 +58,22 @@ void Prs3d_Text::Draw ( Prs3d_Text::Draw(aPresentation,aDrawer->TextAspect(),aText,AttachmentPoint); } + +// ======================================================================= +// function : Draw +// purpose : +// ======================================================================= +void Prs3d_Text::Draw (const Handle(Prs3d_Presentation)& thePresentation, + const Handle(Prs3d_TextAspect)& theAspect, + const TCollection_ExtendedString& theText, + const gp_Ax2& theOrientation) +{ + Prs3d_Root::CurrentGroup (thePresentation)->SetPrimitivesAspect (theAspect->Aspect()); + Prs3d_Root::CurrentGroup (thePresentation)->Text (theText, + theOrientation, + theAspect->Height(), + theAspect->Angle(), + theAspect->Orientation(), + theAspect->HorizontalJustification(), + theAspect->VerticalJustification()); +} diff --git a/src/Prs3d/Prs3d_Text.hxx b/src/Prs3d/Prs3d_Text.hxx index 193b366710..87634a4cce 100644 --- a/src/Prs3d/Prs3d_Text.hxx +++ b/src/Prs3d/Prs3d_Text.hxx @@ -25,6 +25,8 @@ #include #include +#include + class Prs3d_Presentation; class TCollection_ExtendedString; class gp_Pnt; @@ -46,6 +48,13 @@ public: //! anAspect, const TCollection_ExtendedString& aText, //! const gp_Pnt& AttachmentPoint); Standard_EXPORT static void Draw (const Handle(Prs3d_Presentation)& aPresentation, const Handle(Prs3d_Drawer)& aDrawer, const TCollection_ExtendedString& aText, const gp_Pnt& AttachmentPoint); + + //! Draws theText label with the location and the orientation + //! specified in the model 3D space through theOrientation argument. + Standard_EXPORT static void Draw (const Handle(Prs3d_Presentation)& thePresentation, + const Handle(Prs3d_TextAspect)& theAspect, + const TCollection_ExtendedString& theText, + const gp_Ax2& theOrientation); //! 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 c04dff3fc6..023dad3f37 100644 --- a/src/ViewerTest/ViewerTest_ObjectCommands.cxx +++ b/src/ViewerTest/ViewerTest_ObjectCommands.cxx @@ -2434,6 +2434,12 @@ static int VDrawText (Draw_Interpretor& theDI, gp_Pnt aTPPosition; Aspect_TypeOfDisplayText aDisplayType = Aspect_TODT_NORMAL; + + Standard_Boolean aHasPlane = Standard_False; + gp_Dir aNormal; + gp_Dir aDirection; + gp_Pnt aPos; + for (; anArgIt < theArgsNb; ++anArgIt) { TCollection_AsciiString aParam (theArgVec[anArgIt]); @@ -2452,7 +2458,6 @@ static int VDrawText (Draw_Interpretor& theDI, return 1; } - gp_Pnt aPos; aPos.SetX (Draw::Atof (theArgVec[++anArgIt])); aPos.SetY (Draw::Atof (theArgVec[++anArgIt])); aPos.SetZ (Draw::Atof (theArgVec[++anArgIt])); @@ -2624,6 +2629,26 @@ static int VDrawText (Draw_Interpretor& theDI, aTextPrs->SetFont (theArgVec[anArgIt]); } + else if (aParam == "-plane") + { + if (anArgIt + 6 >= theArgsNb) + { + std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n"; + return 1; + } + + Standard_Real aX = Draw::Atof (theArgVec[++anArgIt]); + Standard_Real aY = Draw::Atof (theArgVec[++anArgIt]); + Standard_Real aZ = Draw::Atof (theArgVec[++anArgIt]); + aNormal.SetCoord (aX, aY, aZ); + + aX = Draw::Atof (theArgVec[++anArgIt]); + aY = Draw::Atof (theArgVec[++anArgIt]); + aZ = Draw::Atof (theArgVec[++anArgIt]); + aDirection.SetCoord (aX, aY, aZ); + + aHasPlane = Standard_True; + } else if (aParam == "-disptype" || aParam == "-displaytype") { @@ -2730,14 +2755,19 @@ static int VDrawText (Draw_Interpretor& theDI, } } + if (aHasPlane) + { + aTextPrs->SetOrientation3D (gp_Ax2 (aPos, aNormal, aDirection)); + } + if (aTrsfPersFlags != Graphic3d_TMF_None) { aTextPrs->SetTransformPersistence (aTrsfPersFlags, aTPPosition); aTextPrs->SetDisplayType (aDisplayType); aTextPrs->SetZLayer(Graphic3d_ZLayerId_TopOSD); - if (aTextPrs->GetPosition().Z() != 0) + if (aTextPrs->Position().Z() != 0) { - aTextPrs->SetPosition (gp_Pnt(aTextPrs->GetPosition().X(), aTextPrs->GetPosition().Y(), 0)); + aTextPrs->SetPosition (gp_Pnt(aTextPrs->Position().X(), aTextPrs->Position().Y(), 0)); } } else if (aTrsfPersFlags != aTextPrs->TransformPersistence().Flags) @@ -6280,6 +6310,7 @@ void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands) "\n\t\t: [-disptype {blend|decal|subtitle|dimension|normal}=normal}" "\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: Display text label at specified position.", __FILE__, VDrawText, group); diff --git a/tests/3rdparty/grids.list b/tests/3rdparty/grids.list index 3cd0a0bf93..358d577b50 100644 --- a/tests/3rdparty/grids.list +++ b/tests/3rdparty/grids.list @@ -1,2 +1,3 @@ 001 export 002 fonts +003 text3d \ No newline at end of file diff --git a/tests/3rdparty/text3d/A1 b/tests/3rdparty/text3d/A1 new file mode 100644 index 0000000000..a20439794b --- /dev/null +++ b/tests/3rdparty/text3d/A1 @@ -0,0 +1,30 @@ +puts "===========" +puts "0026343: Visualization - Zoom persistent text with 3D orientation" +puts "" +puts "===========" + +vfont add [locate_data_file DejaVuSans.ttf] SansFont + +pload ALL +vinit View1 +vclear +vaxo + +set x 10 +set y 50 +set z 30 + +box b $x $y $z +vdisplay b +vtrihedron tri0 + +vdrawtext t0 "Top text on plane yOz" -pos $x 0 $z -color green -height 20 -plane 1 0 0 0 1 0 -valign top -font SansFont +vdrawtext t1 "Bottom text on plane yOz" -pos 0 $y 0 -color green -height 20 -plane -1 0 0 0 -1 0 -valign bottom -font SansFont + +vdrawtext t2 "Some text on the top face" -pos $x/2 $y/2 $z -color red -height 20 -plane 0 0 1 0 1 0 -valign center -halign center -font SansFont + +vdrawtext t3 "First line\nSecond line" -pos $x/2 0 $z/2 -color 0.0 0.0 1.0 -height 20 -plane 0 -1 0 0 0 1 -valign center -halign center -font SansFont + +vfit + +vdump ${imagedir}/${casename}.png