0026343: Visualization - Zoom persistent text with 3D orientation
[occt.git] / src / AIS / AIS_TextLabel.cxx
CommitLineData
29e2c6d2 1// Created on: 2014-11-10
2// Copyright (c) 2014 OPEN CASCADE SAS
3//
4// This file is part of Open CASCADE Technology software library.
5//
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.
11//
12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
14
15#include <AIS_TextLabel.hxx>
16
17#include <Graphic3d_AspectText3d.hxx>
18
19#include <Prs3d_Text.hxx>
20#include <Prs3d_TextAspect.hxx>
21
22#include <Select3D_SensitivePoint.hxx>
23#include <SelectMgr_Selection.hxx>
24#include <SelectMgr_EntityOwner.hxx>
25
29e2c6d2 26
27//=======================================================================
28//function : AIS_TextLabel
29//purpose :
30//=======================================================================
31AIS_TextLabel::AIS_TextLabel()
ce01ec26 32: myText ("?"),
33 myFont ("Courier"),
34 myFontAspect (Font_FA_Regular),
35 myHasOrientation3D (Standard_False)
29e2c6d2 36{
37 myDrawer->SetTextAspect (new Prs3d_TextAspect());
38
39 SetDisplayMode (0);
40}
41
42//=======================================================================
43//function : SetColor
44//purpose :
45//=======================================================================
46void AIS_TextLabel::SetColor (const Quantity_Color& theColor)
47{
48 hasOwnColor = Standard_True;
49 myOwnColor = theColor;
50 myDrawer->TextAspect()->SetColor (theColor);
51}
52
53//=======================================================================
54//function : SetColor
55//purpose :
56//=======================================================================
57void AIS_TextLabel::SetColor (const Quantity_NameOfColor theColor)
58{
59 SetColor (Quantity_Color (theColor));
60}
61
62//=======================================================================
63//function : SetText
64//purpose :
65//=======================================================================
66void AIS_TextLabel::SetText (const TCollection_ExtendedString& theText)
67{
68 myText = theText;
69}
70
71//=======================================================================
72//function : SetPosition
73//purpose :
74//=======================================================================
75void AIS_TextLabel::SetPosition (const gp_Pnt& thePosition)
76{
ce01ec26 77 myOrientation3D.SetLocation (thePosition);
29e2c6d2 78}
79
80//=======================================================================
81//function : SetHJustification
82//purpose :
83//=======================================================================
84void AIS_TextLabel::SetHJustification (const Graphic3d_HorizontalTextAlignment theHJust)
85{
86 myDrawer->TextAspect()->SetHorizontalJustification (theHJust);
87}
88
89//=======================================================================
90//function : SetVJustification
91//purpose : Setup vertical justification.
92//=======================================================================
93void AIS_TextLabel::SetVJustification (const Graphic3d_VerticalTextAlignment theVJust)
94{
95 myDrawer->TextAspect()->SetVerticalJustification (theVJust);
96}
97
98//=======================================================================
99//function : SetAngle
100//purpose :
101//=======================================================================
102void AIS_TextLabel::SetAngle (const Standard_Real theAngle)
103{
104 myDrawer->TextAspect()->Aspect()->SetTextAngle (theAngle * 180.0 / M_PI);
105}
106
107//=======================================================================
108//function : SetZoom
109//purpose :
110//=======================================================================
111void AIS_TextLabel::SetZoomable (const Standard_Boolean theIsZoomable)
112{
113 myDrawer->TextAspect()->Aspect()->SetTextZoomable (theIsZoomable);
114}
115
116//=======================================================================
117//function : SetHeight
118//purpose :
119//=======================================================================
120void AIS_TextLabel::SetHeight (const Standard_Real theHeight)
121{
122 myDrawer->TextAspect()->SetHeight (theHeight);
123}
124
125//=======================================================================
126//function : SetAngle
127//purpose :
128//=======================================================================
129void AIS_TextLabel::SetFontAspect (const Font_FontAspect theFontAspect)
130{
131 myDrawer->TextAspect()->Aspect()->SetTextFontAspect (theFontAspect);
132}
133
134//=======================================================================
135//function : SetFont
136//purpose :
137//=======================================================================
138void AIS_TextLabel::SetFont (Standard_CString theFont)
139{
140 myFont = theFont;
141 myDrawer->TextAspect()->SetFont (myFont.ToCString());
142}
143
ce01ec26 144//=======================================================================
145//function : SetOrientation3D
146//purpose :
147//=======================================================================
148void AIS_TextLabel::SetOrientation3D (const gp_Ax2& theOrientation)
149{
150 myHasOrientation3D = Standard_True;
151 myOrientation3D = theOrientation;
152}
153
154//=======================================================================
155//function : UnsetOrientation3D
156//purpose :
157//=======================================================================
158void AIS_TextLabel::UnsetOrientation3D ()
159{
160 myHasOrientation3D = Standard_False;
161}
162
163//=======================================================================
164//function : Position
165//purpose :
166//=======================================================================
167const gp_Pnt& AIS_TextLabel::Position() const
168{
169 return myOrientation3D.Location();
170}
171
172//=======================================================================
173//function : Orientation3D
174//purpose :
175//=======================================================================
176const gp_Ax2& AIS_TextLabel::Orientation3D() const
177{
178 return myOrientation3D;
179}
180
181//=======================================================================
182//function : HasOrientation3D()
183//purpose :
184//=======================================================================
185Standard_Boolean AIS_TextLabel::HasOrientation3D() const
186{
187 return myHasOrientation3D;
188}
189
61b0191c 190//=======================================================================
191//function : SetDisplayType
192//purpose :
193//=======================================================================
194void AIS_TextLabel::SetDisplayType (const Aspect_TypeOfDisplayText theDisplayType)
195{
196 myDrawer->TextAspect()->Aspect()->SetDisplayType(theDisplayType);
197}
198
199//=======================================================================
200//function : SetColorSubTitle
201//purpose :
202//=======================================================================
203void AIS_TextLabel::SetColorSubTitle (const Quantity_Color& theColor)
204{
205 myDrawer->TextAspect()->Aspect()->SetColorSubTitle(theColor);
206}
207
29e2c6d2 208//=======================================================================
209//function : Compute
210//purpose :
211//=======================================================================
212void AIS_TextLabel::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePrsMgr*/,
213 const Handle(Prs3d_Presentation)& thePrs,
214 const Standard_Integer theMode)
215{
216 switch (theMode)
217 {
218 case 0:
219 {
220 Handle(Prs3d_TextAspect) anAsp = myDrawer->TextAspect();
ce01ec26 221
222 if (myHasOrientation3D)
223 {
224 Prs3d_Text::Draw (thePrs, anAsp, myText, myOrientation3D);
225 }
226 else
227 {
228 Prs3d_Text::Draw (thePrs, anAsp, myText, Position());
229 }
230
29e2c6d2 231 break;
232 }
233 }
234}
235
236//=======================================================================
237//function : ComputeSelection
238//purpose :
239//=======================================================================
240void AIS_TextLabel::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
241 const Standard_Integer theMode)
242{
243 switch (theMode)
244 {
245 case 0:
246 {
247 Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this, 10);
ce01ec26 248 Handle(Select3D_SensitivePoint) aSensitivePoint = new Select3D_SensitivePoint (anEntityOwner, Position());
29e2c6d2 249 theSelection->Add (aSensitivePoint);
250 break;
251 }
252 }
253}