I need to introduce some 3d text in the Interactive context, Can anyone tell me how to do this? I've been trying to obtain the text from Graphic3d_Group::Text, but I don't know how to introduce the text in my scene.
Thanks
Hugues
2005-07-08 13:37
Hi,
To do this, one means is to inherit from AIS_InteractiveObject and redefine `Compute' routines.
Here is the InteractiveText class I defined, I use it when I want to display text. Indentation of the code is messed in this post, and there is also classes you probably won't have (like Point3D, Integer, Real, QString if you don't work with Qt). But it is easily adaptable.
The header file:
# include "geometry/3d/Point3D.hpp"
# include <qstring.h>
# include <AIS_InteractiveObject.hxx>
# include <Handle_Graphic2d_GraphicObject.hxx>
# include <Handle_Prs3d_Presentation.hxx>
# include <Handle_Prs3d_Projector.hxx>
# include <Handle_PrsMgr_PresentationManager2d.hxx>
# include <Handle_PrsMgr_PresentationManager3d.hxx>
# include <Handle_SelectMgr_Selection.hxx>
# include <Standard_DefineHandle.hxx>
# include <Standard_Macro.hxx>
/*! \class InteractiveText
* \brief Interactive items specialized in the displaying of texts.
*/
DEFINE_STANDARD_HANDLE (InteractiveText, AIS_InteractiveObject)
class InteractiveText : public AIS_InteractiveObject
{
// ------------------- Initialization and Deletion ---------------------
public:
//! Construct a default instance of InteractiveText.
InteractiveText ();
//! Construct a fully initialized instance of InteractiveText.
InteractiveText (const QString& text, const Point3D& pos,
Real angle = 0, Real slant = 0,
Integer color_id = 1, Integer font_id = 1,
Real scale = 0.1);
//! Destruct the instance and free any allocated resources.
virtual ~InteractiveText ();
DEFINE_STANDARD_RTTI (InteractiveText)
// ----------------------------- Access --------------------------------
public:
//! Position of the text displayed.
const Point3D& position () const
{
return _position;
}
//! Text displated by the current InteractiveText object.
QString text () const
{
return _text;
}
//! User friendly string of the instance.
virtual QString to_string () const
{
return _text;
}
IMPLEMENT_STANDARD_HANDLE (InteractiveText, AIS_InteractiveObject)
IMPLEMENT_STANDARD_RTTI (InteractiveText, AIS_InteractiveObject)
//
// Foreach ancestors, we add a IMPLEMENT_STANDARD_SUPERTYPE and
// a IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_ENTRY macro.
// We must respect the order: from the direct ancestor class
// to the base class.
//
IMPLEMENT_STANDARD_TYPE (InteractiveText)
IMPLEMENT_STANDARD_SUPERTYPE (AIS_InteractiveObject)
IMPLEMENT_STANDARD_SUPERTYPE (SelectMgr_SelectableObject)
IMPLEMENT_STANDARD_SUPERTYPE (PrsMgr_PresentableObject)
IMPLEMENT_STANDARD_SUPERTYPE (MMgt_TShared)
IMPLEMENT_STANDARD_SUPERTYPE (Standard_Transient)
IMPLEMENT_STANDARD_SUPERTYPE_ARRAY ()
IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_ENTRY (AIS_InteractiveObject)
IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_ENTRY (SelectMgr_SelectableObject)
IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_ENTRY (PrsMgr_PresentableObject)
IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_ENTRY (MMgt_TShared)
IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_ENTRY (Standard_Transient)
IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_END ()
IMPLEMENT_STANDARD_TYPE_END (InteractiveText)
Is it possible to set this text as a constant info text for the viewer. Such that it is displayed at a fixed position in the lower left corner of the window ? What do I have to do to achieve this ?
Hugues
2005-07-11 13:43
If you are building the GUI with Qt, this can easily be achieved by redefining the procedure `paintEvent' in the widget responsible of the 3D view display.
Use a QPainter object to draw the text at the desired position/color.
viviana
2005-07-18 16:09
Hi,
I tried something like this:
...
Standard_Real angle=0, slant=0, scale=0.1;
Standard_Integer color_id = 1, font_id=1, mode=1;
Point3D pos(0,0,0);
const QString text1( "This is a Sphere" );
and it compiles o.k. but when I am going to execute the program a segmentation fault appears.
P.D. I declared Compute() as public so I could use it.
Help please!!!
Hugues
2005-07-18 18:39
Hi,
Just use InteractiveText objects as InteractiveObject ones, i.e. inside an interactive context. You do not need to declare presentation managers, the interactive context will do this for you.
So assuming you have an initialized 3D view attached to an AIS_InteractiveContext, just do :
That's all. Note you should replace occurences of Point3D by gp_Pnt, i.e. the native OCC class for 3D points. Point3D is a class I defined that you can get rid of.
viviana
2005-07-19 17:41
Thank you very much.
viviana
2005-07-22 15:53
Hi,
I would like to display some 3D text with color, angle, font and color attributes, I have change some variables in the new InteractiveText, but the text appears just like before, I also looked in the OCC help about Display() but nothing related.
Thanks in advance for your help.
viviana
2005-07-22 16:00
I suposse... I have to use Prs3D_TextAspect in some way???
aPresentation= new Prs3d_Presentation(aContext->CurrentViewer()->Viewer());
Handle(Prs3d_TextAspect) aTextAspect= new Prs3d_TextAspect();
aTextAspect->SetFont(Graphic3d_NOF_ASCII_COMPLEX);
because the parameter of Prs3d_Presentation is a Graphic3d_StructureManager not a viewer() like you wrote before...anyway, I did that but a segmentation fault appears, any suggestions?
HELP PLEASE!!!
thank you.
Denis TEISSANDIER
2005-07-27 09:20
I can not answer this question.
I never use the Prs3d_Text class like that.
I always use an AIS_InteractiveContext to manage my wiewer with one V3d_Viewer.
The Graphic3d_StructureManager is the root class of Visual3d_ViewManager. I always instanciate the Visual3d_ViewManager like that :
AIS_InteractiveContext aContext;
---------
---------
aPresentation= new Prs3d_Presentation(aContext->CurrentViewer()->Viewer());
Denis
cheng
2008-10-21 13:55
If the text is chinese or other text? How to do this?