//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 : Set3dOrientation
+//purpose :
+//=======================================================================
+void AIS_TextLabel::SetOrientation3D (const gp_Ax2& theOrientation)
+{
+ myHasOrientation3D = Standard_True;
+ myOrientation3D = theOrientation;
+}
+
+//=======================================================================
+//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 : Compute
//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 font.
Standard_EXPORT void SetFont (Standard_CString theFont);
+ //! Setup orientation 3D.
+ Standard_EXPORT void SetOrientation3D (const gp_Ax2& theOrientation);
+
+ //! Returns position.
+ Standard_EXPORT const gp_Pnt& Position() const;
+
+ //! Returns orientation 3D.
+ Standard_EXPORT const gp_Ax2& Orientation3D() const;
+
+ //! Returns true if current text placement in 3D.
+ Standard_EXPORT Standard_Boolean HasOrientation3D() const;
+
private:
//! Compute
protected:
TCollection_ExtendedString myText;
- gp_Pnt myPosition;
TCollection_AsciiString myFont;
Font_FontAspect myFontAspect;
+ gp_Ax2 myOrientation3D;
+ Standard_Boolean myHasOrientation3D;
public:
--
-- 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.
---Warning:
---References:
-- AAngle : Orientation of the text
-- (with respect to the horizontal).
---Category: Methods to create Text
-
+
Text ( me : mutable;
AText : ExtendedString from TCollection;
APoint : Vertex from Graphic3d;
-- AHta : HTA_LEFT
-- AVta : VTA_BOTTOM
---Category: Methods to create Text
-
+
+ Text (me : mutable;
+ theTextUtf : CString from Standard;
+ theOrientation : Ax2 from gp;
+ theHeight : Real from Standard;
+ theAngle : PlaneAngle from Quantity;
+ theTp : TextPath from Graphic3d;
+ theHTA : HorizontalTextAlignment from Graphic3d;
+ theVTA : VerticalTextAlignment from Graphic3d;
+ theToEvalMinMax : Boolean from Standard = Standard_True) is virtual;
+ ---Level: Public
+ ---Purpose: Creates the string <theText> at orientation <theOrientation> in 3D space.
+ ---Category: Methods to create Text
+
+ Text (me : mutable;
+ theText : ExtendedString from TCollection;
+ theOrientation : Ax2 from gp;
+ theHeight : Real from Standard;
+ theAngle : PlaneAngle from Quantity;
+ theTp : TextPath from Graphic3d;
+ theHTA : HorizontalTextAlignment from Graphic3d;
+ theVTA : VerticalTextAlignment from Graphic3d;
+ theToEvalMinMax : Boolean from Standard = Standard_True) is static;
+ ---Level: Internal
+ ---Purpose: Creates the string <theText> at orientation <theOrientation> in 3D space.
+ ---Category: Methods to create Text
+
---------------------------------------
---Category: Methods to create Triangle
---------------------------------------
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 :
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_Text.hxx>
#include <OpenGl_Utils.hxx>
#include <OpenGl_Workspace.hxx>
+#include <OpenGl_View.hxx>
#include <Font_FontMgr.hxx>
#include <TCollection_HAsciiString.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),
+ myOrientation (theOrientation),
+ myIs2d (false),
+ 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);
- OpenGl_Utils::Translate<GLdouble> (aModViewMat, anObjX, anObjY, anObjZ);
- OpenGl_Utils::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
+ {
+ OpenGl_Utils::Translate<GLdouble> (aModViewMat, anObjX, anObjY, anObjZ);
+ OpenGl_Utils::Rotate<GLdouble> (aModViewMat, theTextAspect.Angle(), 0.0, 0.0, 1.0);
+ }
+
if (!theTextAspect.IsZoomable())
{
#ifdef _WIN32
theCtx->WorldViewState.SetCurrent<Standard_Real> (aModViewMat);
theCtx->ApplyWorldViewMatrix();
+ theCtx->ProjectionState.SetCurrent<Standard_Real> (aProjectMat);
+ theCtx->ApplyProjectionMatrix();
+
if (!theCtx->ActiveProgram().IsNull())
{
// Upload updated state to shader program
{
aFontFt = new Font_FTFont (NULL);
- if (aFontFt->Init (aRequestedFont->FontPath()->ToCString(), theHeight))
+ // 96 is default resolution (dpi) for display devices like the screen.
+ // Support of adaptive calculation of the resolution is necessary.
+ if (aFontFt->Init (aRequestedFont->FontPath()->ToCString(), theHeight, 96))
{
aFont = new OpenGl_Font (aFontFt, theKey);
if (!aFont->Init (theCtx))
if (!myIs2d)
{
glGetIntegerv (GL_VIEWPORT, myViewport);
- myProjMatrix.Convert (theCtx->ProjectionState.Current());
OpenGl_Utils::Project<Standard_Real> (myPoint.x(),
myPoint.y(),
setupMatrix (thePrintCtx, theCtx, theTextAspect, OpenGl_Vec3 (0.0f, 0.0f, 0.0f));
drawText (thePrintCtx, theCtx, theTextAspect);
+ 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 Handle(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:
Pnt from gp,
Drawer from Prs3d,
TextAspect from Prs3d,
- ExtendedString from TCollection
+ ExtendedString from TCollection,
+ Ax2 from gp
is
Draw(myclass; aPresentation: Presentation from Prs3d;
-- static void Draw (const Handle(Prs3d_Presentation)&
-- aPresentation, const Handle(Prs3d_TextAspect)&
-- anAspect, const TCollection_ExtendedString& aText,
- -- const gp_Pnt& AttachmentPoint);
+ -- const gp_Pnt& AttachmentPoint);
+
+ Draw(myclass;
+ thePresentation : Presentation from Prs3d;
+ theAspect : TextAspect from Prs3d;
+ theText : ExtendedString from TCollection;
+ theOrientation : Ax2 from gp);
+ ---Purpose: Defines the display of the text theText at the orientation 3d space.
Draw(myclass; aPresentation: Presentation from Prs3d;
anAspect: TextAspect from Prs3d;
Standard_Real x,y,z;
AttachmentPoint.Coord(x,y,z);
-
-// POP Graphic3d_Grup accepte de l'extended
Prs3d_Root::CurrentGroup(aPresentation)->Text(
-// TCollection_AsciiString(aText).ToCString(),
- aText,
- Graphic3d_Vertex(x,y,z),
+ aText,
+ Graphic3d_Vertex(x,y,z),
anAspect->Height(),
anAspect->Angle(),
anAspect->Orientation(),
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());
+}
SetVerticalJustification(me: mutable; aJustification: VerticalTextAlignment from Graphic3d);
--- Purpose: Sets the vertical alignment of text.
-
+
SetOrientation(me: mutable; anOrientation: TextPath from Graphic3d);
- ---Purpose: Sets the orientation of text.
-
+ ---Purpose: Sets the orientation of text.
+
HorizontalJustification(me) returns HorizontalTextAlignment from Graphic3d;
--- Purpose: Returns the horizontal alignment of the text.
-- The range of values includes:
-- - half
-- - base
-- - bottom
-
+
Orientation(me) returns TextPath from Graphic3d;
--- Purpose: Returns the orientation of the text.
-- Text can be displayed in the following directions:
-- - up
-- - down
-- - left, or
- -- - right
-
+ -- - right
+
Aspect(me) returns AspectText3d from Graphic3d;
---Purpose: Returns the purely textual attributes used in the display of text.
-- These include:
myHeight: Real from Standard;
myHorizontalJustification: HorizontalTextAlignment from Graphic3d;
myVerticalJustification: VerticalTextAlignment from Graphic3d;
- myOrientation: TextPath from Graphic3d;
+ myOrientation: TextPath from Graphic3d;
end TextAspect from Prs3d;
myHeight(16.),
myHorizontalJustification(Graphic3d_HTA_LEFT),
myVerticalJustification(Graphic3d_VTA_BOTTOM),
- myOrientation(Graphic3d_TP_RIGHT) {
+ myOrientation(Graphic3d_TP_RIGHT)
+{
myTextAspect = new Graphic3d_AspectText3d (
Quantity_Color(Quantity_NOC_YELLOW),
aTextPrs->SetText (aText);
+
+ 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
{
std::cout << "Error: unknown argument '" << aParam << "'\n";
}
}
+ if (aHasPlane)
+ {
+ aTextPrs->SetOrientation3D (gp_Ax2 (aPos, aNormal, aDirection));
+ }
+
ViewerTest::Display (aName, aTextPrs, Standard_False);
return 0;
}
"\n\t\t: [-aspect {regular|bold|italic|bolditalic}=regular]"
"\n\t\t: [-font font=Times]"
"\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 "0026149: "
+puts ""
+puts "==========="
+
+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 in plane yOz" -pos $x 0 $z -color green -height 20 -plane 1 0 0 0 1 0 -valign top
+vdrawtext t1 "Bottom text in plane yOz" -pos 0 $y 0 -color green -height 20 -plane -1 0 0 0 -1 0 -valign bottom
+
+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
+
+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
+
+vfit
+
+vdump ${imagedir}/${casename}.png