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