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
#include <AIS_TextLabel.hxx>
+#include <AIS_InteractiveContext.hxx>
+#include <Font_FTFont.hxx>
+#include <Font_FontMgr.hxx>
+#include <Font_Rect.hxx>
#include <Graphic3d_AspectText3d.hxx>
+#include <Graphic3d_RenderingParams.hxx>
#include <Prs3d_Text.hxx>
#include <Prs3d_TextAspect.hxx>
#include <SelectMgr_Selection.hxx>
#include <SelectMgr_EntityOwner.hxx>
+#include <V3d_Viewer.hxx>
+
IMPLEMENT_STANDARD_RTTIEXT(AIS_TextLabel,AIS_InteractiveObject)
: myText ("?"),
myFont ("Courier"),
myFontAspect (Font_FA_Regular),
- myHasOrientation3D (Standard_False)
+ myHasOrientation3D (Standard_False),
+ myHasFlipping (Standard_False)
{
myDrawer->SetTextAspect (new Prs3d_TextAspect());
}
//=======================================================================
-//function : HasOrientation3D()
+//function : HasOrientation3D
//purpose :
//=======================================================================
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 :
myDrawer->TextAspect()->Aspect()->SetColorSubTitle(theColor);
}
+#include <Graphic3d_ArrayOfPoints.hxx>
//=======================================================================
//function : Compute
//purpose :
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
{
//! 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.
Font_FontAspect myFontAspect;
gp_Ax2 myOrientation3D;
Standard_Boolean myHasOrientation3D;
+ Standard_Boolean myHasFlipping;
public:
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(),
theTP,
theHTA,
theVTA,
- theToEvalMinMax);
+ theToEvalMinMax,
+ theHasOwnAnchor);
}
// =======================================================================
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())
{
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 <theText> at orientation <theOrientation> in 3D space.
Standard_EXPORT virtual void Text (const TCollection_ExtendedString& theText,
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
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())
{
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);
theTp,
theHTA,
theVTA,
- theToEvalMinMax);
+ theToEvalMinMax,
+ theHasOwnAnchor);
}
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,
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;
myString (theText),
myPoint (thePoint),
myIs2d (false),
- myHasPlane (false)
+ myHasPlane (false),
+ myHasAnchorPoint (true)
{
//
}
// =======================================================================
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),
myString (theText),
myIs2d (false),
myOrientation (theOrientation),
- myHasPlane (true)
+ myHasPlane (true),
+ myHasAnchorPoint (theHasOwnAnchor)
{
const gp_Pnt& aPoint = theOrientation.Location();
myPoint = OpenGl_Vec3 (static_cast<Standard_ShortReal> (aPoint.X()),
{
OpenGl_Mat4d aModViewMat;
OpenGl_Mat4d aProjectMat;
-
- if (myHasPlane)
+ if (myHasPlane && myHasAnchorPoint)
{
aProjectMat = myProjMatrix * myOrientationMatrix;
}
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
{
}
}
- theCtx->WorldViewState.SetCurrent<Standard_Real> (aModViewMat);
+ if (myHasPlane && !myHasAnchorPoint)
+ {
+ OpenGl_Mat4d aCurrentWorldViewMat;
+ aCurrentWorldViewMat.Convert (theCtx->WorldViewState.Current());
+ theCtx->WorldViewState.SetCurrent<Standard_Real> (aCurrentWorldViewMat * aModViewMat);
+ }
+ else
+ {
+ theCtx->WorldViewState.SetCurrent<Standard_Real> (aModViewMat);
+ }
theCtx->ApplyWorldViewMatrix();
if (!myIs2d)
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<Standard_Real> (aWorldViewMat);
+ theCtx->ApplyWorldViewMatrix();
+ }
+ else
+ {
+ theCtx->WorldViewState.Push();
+ }
myModelMatrix.Convert (theCtx->WorldViewState.Current() * theCtx->ModelWorldState.Current());
//! 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,
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:
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,
theAspect->Angle(),
theAspect->Orientation(),
theAspect->HorizontalJustification(),
- theAspect->VerticalJustification());
+ theAspect->VerticalJustification(),
+ Standard_True,
+ theHasOwnAnchor);
}
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.
aHasPlane = Standard_True;
}
+ else if (aParam == "-flipping")
+ {
+ aTextPrs->SetFlipping (Standard_True);
+ }
else if (aParam == "-disptype"
|| aParam == "-displaytype")
{
"\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);
--- /dev/null
+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