//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());
//=======================================================================
void AIS_TextLabel::SetPosition (const gp_Pnt& thePosition)
{
- myPosition = thePosition;
+ myOrientation3D.SetLocation (thePosition);
}
//=======================================================================
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 :
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;
}
}
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;
}
#include <AIS_InteractiveObject.hxx>
#include <gp_Pnt.hxx>
+#include <gp_Ax2.hxx>
#include <Graphic3d_VerticalTextAlignment.hxx>
#include <Graphic3d_HorizontalTextAlignment.hxx>
#include <Font_FontAspect.hxx>
//! 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);
//! 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.
protected:
TCollection_ExtendedString myText;
- gp_Pnt myPosition;
TCollection_AsciiString myFont;
Font_FontAspect myFontAspect;
+ gp_Ax2 myOrientation3D;
+ Standard_Boolean myHasOrientation3D;
public:
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<Standard_ShortReal> (theOrientation.Location().X()),
+ static_cast<Standard_ShortReal> (theOrientation.Location().Y()),
+ static_cast<Standard_ShortReal> (theOrientation.Location().Z()),
+ 1.0f));
+ }
+ Update();
+}
+
// =======================================================================
// function : Text
// purpose :
#include <Graphic3d_BoundBuffer.hxx>
#include <Standard_Address.hxx>
#include <Graphic3d_GroupAspect.hxx>
+#include <gp_Ax2.hxx>
+#include <TCollection_ExtendedString.hxx>
class Graphic3d_Structure;
class Graphic3d_GroupDefinitionError;
class Standard_OutOfRange;
-class TCollection_ExtendedString;
class Graphic3d_ArrayOfPrimitives;
-class gp_Ax2;
class Graphic3d_Group;
//!
//! 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
{
//! 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 <theText> at orientation <theOrientation> 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 <theText> at orientation <theOrientation> 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);
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 :
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,
#include <OpenGl_ShaderStates.hxx>
#include <OpenGl_Text.hxx>
#include <OpenGl_Workspace.hxx>
+#include <OpenGl_View.hxx>
#include <Font_FontMgr.hxx>
#include <Graphic3d_TransformUtils.hxx>
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;
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<Standard_ShortReal> (aPoint.X()),
+ static_cast<Standard_ShortReal> (aPoint.Y()),
+ static_cast<Standard_ShortReal> (aPoint.Z()));
+}
+
// =======================================================================
// function : SetPosition
// purpose :
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)
{
const OpenGl_Vec3 theDVec) const
{
OpenGl_Mat4d aModViewMat;
+ OpenGl_Mat4d aProjectMat;
+
+ if (myHasPlane)
+ {
+ aProjectMat = myProjMatrix * myOrientationMatrix;
+ }
+ else
+ {
+ aProjectMat = myProjMatrix;
+ }
if (myIs2d)
{
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<GLdouble> (aModViewMat, anObjX, anObjY, anObjZ);
- Graphic3d_TransformUtils::Rotate<GLdouble> (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<GLdouble> (aModViewMat, anObjX, anObjY, anObjZ);
+ Graphic3d_TransformUtils::Rotate<GLdouble> (aModViewMat, theTextAspect.Angle(), 0.0, 0.0, 1.0);
+ }
if (!theTextAspect.IsZoomable())
{
theCtx->WorldViewState.SetCurrent<Standard_Real> (aModViewMat);
theCtx->ApplyWorldViewMatrix();
+ if (!myIs2d)
+ {
+ theCtx->ProjectionState.SetCurrent<Standard_Real> (aProjectMat);
+ theCtx->ApplyProjectionMatrix();
+ }
+
if (!theCtx->ActiveProgram().IsNull())
{
// Upload updated state to shader program
if (!myIs2d)
{
glGetIntegerv (GL_VIEWPORT, myViewport);
- myProjMatrix.Convert (theCtx->ProjectionState.Current());
Graphic3d_TransformUtils::Project<Standard_Real> (myPoint.x(),
myPoint.y(),
setupMatrix (thePrintCtx, theCtx, theTextAspect, OpenGl_Vec3 (0.0f, 0.0f, 0.0f));
drawText (thePrintCtx, theCtx, theTextAspect);
+ if (!myIs2d)
+ {
+ theCtx->ProjectionState.SetCurrent<Standard_Real> (myProjMatrix);
+ theCtx->ApplyProjectionMatrix();
+ }
+
#if !defined(GL_ES_VERSION_2_0)
if (theCtx->core11 != NULL)
{
#include <Graphic3d_HorizontalTextAlignment.hxx>
#include <Graphic3d_VerticalTextAlignment.hxx>
+#include <gp_Ax2.hxx>
+
class OpenGl_PrinterContext;
//! Text rendering
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,
mutable OpenGl_Mat4d myProjMatrix;
mutable OpenGl_Mat4d myModelMatrix;
+ mutable OpenGl_Mat4d myOrientationMatrix;
mutable GLint myViewport[4];
mutable GLdouble myWinX;
mutable GLdouble myWinY;
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:
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());
+}
#include <Prs3d_Drawer.hxx>
#include <Prs3d_TextAspect.hxx>
+#include <gp_Ax2.hxx>
+
class Prs3d_Presentation;
class TCollection_ExtendedString;
class gp_Pnt;
//! 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.
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]);
return 1;
}
- gp_Pnt aPos;
aPos.SetX (Draw::Atof (theArgVec[++anArgIt]));
aPos.SetY (Draw::Atof (theArgVec[++anArgIt]));
aPos.SetZ (Draw::Atof (theArgVec[++anArgIt]));
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")
{
}
}
+ 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)
"\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);
001 export
002 fonts
+003 text3d
\ No newline at end of file
--- /dev/null
+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