1 // Created on: 2014-11-10
2 // Copyright (c) 2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #include <AIS_TextLabel.hxx>
17 #include <Graphic3d_AspectText3d.hxx>
19 #include <Prs3d_Text.hxx>
20 #include <Prs3d_TextAspect.hxx>
22 #include <Select3D_SensitivePoint.hxx>
23 #include <SelectMgr_Selection.hxx>
24 #include <SelectMgr_EntityOwner.hxx>
27 IMPLEMENT_STANDARD_RTTIEXT(AIS_TextLabel,AIS_InteractiveObject)
29 //=======================================================================
30 //function : AIS_TextLabel
32 //=======================================================================
33 AIS_TextLabel::AIS_TextLabel()
36 myFontAspect (Font_FA_Regular),
37 myHasOrientation3D (Standard_False)
39 myDrawer->SetTextAspect (new Prs3d_TextAspect());
44 //=======================================================================
47 //=======================================================================
48 void AIS_TextLabel::SetColor (const Quantity_Color& theColor)
50 hasOwnColor = Standard_True;
51 myOwnColor = theColor;
52 myDrawer->TextAspect()->SetColor (theColor);
55 //=======================================================================
58 //=======================================================================
59 void AIS_TextLabel::SetColor (const Quantity_NameOfColor theColor)
61 SetColor (Quantity_Color (theColor));
64 //=======================================================================
67 //=======================================================================
68 void AIS_TextLabel::SetText (const TCollection_ExtendedString& theText)
73 //=======================================================================
74 //function : SetPosition
76 //=======================================================================
77 void AIS_TextLabel::SetPosition (const gp_Pnt& thePosition)
79 myOrientation3D.SetLocation (thePosition);
82 //=======================================================================
83 //function : SetHJustification
85 //=======================================================================
86 void AIS_TextLabel::SetHJustification (const Graphic3d_HorizontalTextAlignment theHJust)
88 myDrawer->TextAspect()->SetHorizontalJustification (theHJust);
91 //=======================================================================
92 //function : SetVJustification
93 //purpose : Setup vertical justification.
94 //=======================================================================
95 void AIS_TextLabel::SetVJustification (const Graphic3d_VerticalTextAlignment theVJust)
97 myDrawer->TextAspect()->SetVerticalJustification (theVJust);
100 //=======================================================================
101 //function : SetAngle
103 //=======================================================================
104 void AIS_TextLabel::SetAngle (const Standard_Real theAngle)
106 myDrawer->TextAspect()->Aspect()->SetTextAngle (theAngle * 180.0 / M_PI);
109 //=======================================================================
112 //=======================================================================
113 void AIS_TextLabel::SetZoomable (const Standard_Boolean theIsZoomable)
115 myDrawer->TextAspect()->Aspect()->SetTextZoomable (theIsZoomable);
118 //=======================================================================
119 //function : SetHeight
121 //=======================================================================
122 void AIS_TextLabel::SetHeight (const Standard_Real theHeight)
124 myDrawer->TextAspect()->SetHeight (theHeight);
127 //=======================================================================
128 //function : SetAngle
130 //=======================================================================
131 void AIS_TextLabel::SetFontAspect (const Font_FontAspect theFontAspect)
133 myDrawer->TextAspect()->Aspect()->SetTextFontAspect (theFontAspect);
136 //=======================================================================
139 //=======================================================================
140 void AIS_TextLabel::SetFont (Standard_CString theFont)
143 myDrawer->TextAspect()->SetFont (myFont.ToCString());
146 //=======================================================================
147 //function : SetOrientation3D
149 //=======================================================================
150 void AIS_TextLabel::SetOrientation3D (const gp_Ax2& theOrientation)
152 myHasOrientation3D = Standard_True;
153 myOrientation3D = theOrientation;
156 //=======================================================================
157 //function : UnsetOrientation3D
159 //=======================================================================
160 void AIS_TextLabel::UnsetOrientation3D ()
162 myHasOrientation3D = Standard_False;
165 //=======================================================================
166 //function : Position
168 //=======================================================================
169 const gp_Pnt& AIS_TextLabel::Position() const
171 return myOrientation3D.Location();
174 //=======================================================================
175 //function : Orientation3D
177 //=======================================================================
178 const gp_Ax2& AIS_TextLabel::Orientation3D() const
180 return myOrientation3D;
183 //=======================================================================
184 //function : HasOrientation3D()
186 //=======================================================================
187 Standard_Boolean AIS_TextLabel::HasOrientation3D() const
189 return myHasOrientation3D;
192 //=======================================================================
193 //function : SetDisplayType
195 //=======================================================================
196 void AIS_TextLabel::SetDisplayType (const Aspect_TypeOfDisplayText theDisplayType)
198 myDrawer->TextAspect()->Aspect()->SetDisplayType(theDisplayType);
201 //=======================================================================
202 //function : SetColorSubTitle
204 //=======================================================================
205 void AIS_TextLabel::SetColorSubTitle (const Quantity_Color& theColor)
207 myDrawer->TextAspect()->Aspect()->SetColorSubTitle(theColor);
210 //=======================================================================
213 //=======================================================================
214 void AIS_TextLabel::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePrsMgr*/,
215 const Handle(Prs3d_Presentation)& thePrs,
216 const Standard_Integer theMode)
222 Handle(Prs3d_TextAspect) anAsp = myDrawer->TextAspect();
224 if (myHasOrientation3D)
226 Prs3d_Text::Draw (thePrs, anAsp, myText, myOrientation3D);
230 Prs3d_Text::Draw (thePrs, anAsp, myText, Position());
238 //=======================================================================
239 //function : ComputeSelection
241 //=======================================================================
242 void AIS_TextLabel::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
243 const Standard_Integer theMode)
249 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this, 10);
250 Handle(Select3D_SensitivePoint) aSensitivePoint = new Select3D_SensitivePoint (anEntityOwner, Position());
251 theSelection->Add (aSensitivePoint);