60bf98ae |
1 | // Created on: 2013-11-11 |
2 | // Created by: Anastasia BORISOVA |
d5f74e42 |
3 | // Copyright (c) 2013-2014 OPEN CASCADE SAS |
a6eb515f |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
a6eb515f |
6 | // |
d5f74e42 |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
a6eb515f |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
a6eb515f |
15 | |
a6eb515f |
16 | #include <AIS_Dimension.hxx> |
d7bffd44 |
17 | |
18 | #include <AIS.hxx> |
a6eb515f |
19 | #include <AIS_DimensionOwner.hxx> |
a6eb515f |
20 | #include <Adaptor3d_HCurve.hxx> |
21 | #include <BRepAdaptor_Curve.hxx> |
22 | #include <BRepAdaptor_Surface.hxx> |
a6eb515f |
23 | #include <BRepBndLib.hxx> |
60bf98ae |
24 | #include <Bnd_Box.hxx> |
a6eb515f |
25 | #include <ElCLib.hxx> |
26 | #include <Font_BRepFont.hxx> |
ac84fcf6 |
27 | #include <Font_BRepTextBuilder.hxx> |
a6eb515f |
28 | #include <GC_MakeCircle.hxx> |
af203d54 |
29 | #include <Geom_Line.hxx> |
fe83e1ea |
30 | #include <GeomAdaptor_Curve.hxx> |
a6eb515f |
31 | #include <Geom_Circle.hxx> |
a6eb515f |
32 | #include <Geom_TrimmedCurve.hxx> |
33 | #include <gce_MakeDir.hxx> |
34 | #include <gce_MakeLin.hxx> |
af203d54 |
35 | #include <gce_MakePln.hxx> |
a6eb515f |
36 | #include <Graphic3d_ArrayOfSegments.hxx> |
37 | #include <Graphic3d_ArrayOfTriangles.hxx> |
38 | #include <Graphic3d_AspectLine3d.hxx> |
39 | #include <Graphic3d_AspectFillArea3d.hxx> |
40 | #include <Graphic3d_AspectText3d.hxx> |
41 | #include <Graphic3d_Group.hxx> |
42 | #include <PrsMgr_PresentationManager3d.hxx> |
43 | #include <Prs3d_Arrow.hxx> |
44 | #include <Prs3d_ArrowAspect.hxx> |
45 | #include <Prs3d_Drawer.hxx> |
46 | #include <Prs3d_LineAspect.hxx> |
47 | #include <Prs3d_Presentation.hxx> |
48 | #include <Prs3d_Root.hxx> |
49 | #include <Prs3d_ShadingAspect.hxx> |
50 | #include <Prs3d_Text.hxx> |
51 | #include <SelectMgr_EntityOwner.hxx> |
52 | #include <SelectMgr_Selection.hxx> |
53 | #include <SelectMgr_SequenceOfOwner.hxx> |
a6eb515f |
54 | #include <Select3D_SensitiveCircle.hxx> |
55 | #include <Select3D_SensitiveGroup.hxx> |
fe83e1ea |
56 | #include <Select3D_SensitiveCurve.hxx> |
a6eb515f |
57 | #include <Select3D_SensitiveSegment.hxx> |
fe83e1ea |
58 | #include <Select3D_SensitiveTriangle.hxx> |
51f8f60c |
59 | #include <Select3D_SensitiveTriangulation.hxx> |
60 | #include <Poly_Array1OfTriangle.hxx> |
61 | #include <Poly_Triangulation.hxx> |
a6eb515f |
62 | #include <Standard_CString.hxx> |
af203d54 |
63 | #include <Standard_ProgramError.hxx> |
a6eb515f |
64 | #include <StdPrs_ShadedShape.hxx> |
65 | #include <StdPrs_WFShape.hxx> |
66 | #include <TCollection_AsciiString.hxx> |
67 | #include <TCollection_ExtendedString.hxx> |
68 | #include <TopExp_Explorer.hxx> |
69 | #include <TopoDS.hxx> |
0499eb06 |
70 | #include <TopoDS_Edge.hxx> |
a6eb515f |
71 | #include <TopoDS_Vertex.hxx> |
72 | #include <Units.hxx> |
73 | #include <Units_UnitsDictionary.hxx> |
74 | #include <UnitsAPI.hxx> |
75 | #include <UnitsAPI_SystemUnits.hxx> |
76 | |
a6eb515f |
77 | |
92efcf78 |
78 | IMPLEMENT_STANDARD_RTTIEXT(AIS_Dimension,AIS_InteractiveObject) |
79 | |
d7bffd44 |
80 | namespace |
a6eb515f |
81 | { |
fe83e1ea |
82 | // default text strings |
d7bffd44 |
83 | static const TCollection_ExtendedString THE_EMPTY_LABEL; |
60bf98ae |
84 | static const TCollection_AsciiString THE_UNDEFINED_UNITS; |
fe83e1ea |
85 | |
86 | // default text margin and resolution |
87 | static const Standard_Real THE_3D_TEXT_MARGIN = 0.1; |
88 | static const unsigned int THE_2D_TEXT_RESOLUTION = 72; |
89 | |
90 | // default selection priorities |
91 | static const Standard_Integer THE_NEUTRAL_SEL_PRIORITY = 5; |
92 | static const Standard_Integer THE_LOCAL_SEL_PRIORITY = 6; |
a3f6f591 |
93 | } |
a6eb515f |
94 | |
95 | //======================================================================= |
96 | //function : Constructor |
97 | //purpose : |
98 | //======================================================================= |
60bf98ae |
99 | AIS_Dimension::AIS_Dimension (const AIS_KindOfDimension theType) |
cbff1e55 |
100 | : AIS_InteractiveObject (), |
101 | mySelToleranceForText2d(0.0), |
102 | myCustomValue (0.0), |
103 | myIsValueCustom (Standard_False), |
104 | myIsTextPositionFixed (Standard_False), |
105 | mySpecialSymbol (' '), |
a6eb515f |
106 | myDisplaySpecialSymbol (AIS_DSS_No), |
cbff1e55 |
107 | myGeometryType (GeometryType_UndefShapes), |
108 | myIsPlaneCustom (Standard_False), |
109 | myFlyout (0.0), |
110 | myIsGeometryValid (Standard_False), |
111 | myKindOfDimension (theType) |
a6eb515f |
112 | { |
a6eb515f |
113 | } |
114 | |
115 | //======================================================================= |
60bf98ae |
116 | //function : SetCustomValue |
117 | //purpose : |
a6eb515f |
118 | //======================================================================= |
60bf98ae |
119 | void AIS_Dimension::SetCustomValue (const Standard_Real theValue) |
a6eb515f |
120 | { |
60bf98ae |
121 | if (myIsValueCustom && myCustomValue == theValue) |
122 | { |
123 | return; |
124 | } |
a6eb515f |
125 | |
60bf98ae |
126 | myIsValueCustom = Standard_True; |
127 | |
128 | myCustomValue = theValue; |
129 | |
130 | SetToUpdate(); |
a6eb515f |
131 | } |
132 | |
133 | //======================================================================= |
60bf98ae |
134 | //function : GetPlane |
a6eb515f |
135 | //purpose : |
136 | //======================================================================= |
60bf98ae |
137 | const gp_Pln& AIS_Dimension::GetPlane() const |
a6eb515f |
138 | { |
60bf98ae |
139 | return myPlane; |
a6eb515f |
140 | } |
141 | |
a6eb515f |
142 | //======================================================================= |
60bf98ae |
143 | //function : SetUserPlane |
a6eb515f |
144 | //purpose : |
145 | //======================================================================= |
60bf98ae |
146 | void AIS_Dimension::SetCustomPlane (const gp_Pln& thePlane) |
a6eb515f |
147 | { |
60bf98ae |
148 | myPlane = thePlane; |
149 | myIsPlaneCustom = Standard_True; |
150 | |
91b16a64 |
151 | // Disable fixed (custom) text position |
af203d54 |
152 | UnsetFixedTextPosition(); |
153 | |
60bf98ae |
154 | // Check validity if geometry has been set already. |
91b16a64 |
155 | if (IsValid()) |
60bf98ae |
156 | { |
60bf98ae |
157 | SetToUpdate(); |
158 | } |
a6eb515f |
159 | } |
160 | |
161 | //======================================================================= |
60bf98ae |
162 | //function : SetDimensionAspect |
163 | //purpose : |
a6eb515f |
164 | //======================================================================= |
60bf98ae |
165 | void AIS_Dimension::SetDimensionAspect (const Handle(Prs3d_DimensionAspect)& theDimensionAspect) |
a6eb515f |
166 | { |
60bf98ae |
167 | myDrawer->SetDimensionAspect (theDimensionAspect); |
168 | |
169 | SetToUpdate(); |
a6eb515f |
170 | } |
171 | |
172 | //======================================================================= |
60bf98ae |
173 | //function : SetDisplaySpecialSymbol |
174 | //purpose : |
a6eb515f |
175 | //======================================================================= |
60bf98ae |
176 | void AIS_Dimension::SetDisplaySpecialSymbol (const AIS_DisplaySpecialSymbol theDisplaySpecSymbol) |
a6eb515f |
177 | { |
60bf98ae |
178 | if (myDisplaySpecialSymbol == theDisplaySpecSymbol) |
179 | { |
180 | return; |
181 | } |
182 | |
183 | myDisplaySpecialSymbol = theDisplaySpecSymbol; |
184 | |
185 | SetToUpdate(); |
a6eb515f |
186 | } |
187 | |
188 | //======================================================================= |
60bf98ae |
189 | //function : SetSpecialSymbol |
a6eb515f |
190 | //purpose : |
191 | //======================================================================= |
60bf98ae |
192 | void AIS_Dimension::SetSpecialSymbol (const Standard_ExtCharacter theSpecialSymbol) |
a6eb515f |
193 | { |
60bf98ae |
194 | if (mySpecialSymbol == theSpecialSymbol) |
195 | { |
196 | return; |
197 | } |
198 | |
199 | mySpecialSymbol = theSpecialSymbol; |
200 | |
201 | SetToUpdate(); |
a6eb515f |
202 | } |
203 | |
204 | //======================================================================= |
60bf98ae |
205 | //function : SetSelToleranceForText2d |
206 | //purpose : |
a6eb515f |
207 | //======================================================================= |
60bf98ae |
208 | void AIS_Dimension::SetSelToleranceForText2d (const Standard_Real theTol) |
a6eb515f |
209 | { |
60bf98ae |
210 | if (mySelToleranceForText2d == theTol) |
211 | { |
212 | return; |
213 | } |
214 | |
215 | mySelToleranceForText2d = theTol; |
216 | |
217 | SetToUpdate(); |
a6eb515f |
218 | } |
219 | |
220 | //======================================================================= |
60bf98ae |
221 | //function : SetFlyout |
222 | //purpose : |
a6eb515f |
223 | //======================================================================= |
60bf98ae |
224 | void AIS_Dimension::SetFlyout (const Standard_Real theFlyout) |
a6eb515f |
225 | { |
60bf98ae |
226 | if (myFlyout == theFlyout) |
227 | { |
228 | return; |
229 | } |
a6eb515f |
230 | |
60bf98ae |
231 | myFlyout = theFlyout; |
232 | |
af203d54 |
233 | // Disable fixed text position |
234 | UnsetFixedTextPosition(); |
235 | |
60bf98ae |
236 | SetToUpdate(); |
237 | } |
a6eb515f |
238 | |
239 | //======================================================================= |
60bf98ae |
240 | //function : GetDisplayUnits |
241 | //purpose : |
a6eb515f |
242 | //======================================================================= |
60bf98ae |
243 | const TCollection_AsciiString& AIS_Dimension::GetDisplayUnits() const |
a6eb515f |
244 | { |
60bf98ae |
245 | return THE_UNDEFINED_UNITS; |
a6eb515f |
246 | } |
247 | |
248 | //======================================================================= |
60bf98ae |
249 | //function : GetModelUnits |
250 | //purpose : |
a6eb515f |
251 | //======================================================================= |
60bf98ae |
252 | const TCollection_AsciiString& AIS_Dimension::GetModelUnits() const |
a6eb515f |
253 | { |
60bf98ae |
254 | return THE_UNDEFINED_UNITS; |
a6eb515f |
255 | } |
256 | |
257 | //======================================================================= |
60bf98ae |
258 | //function : ValueToDisplayUnits |
259 | //purpose : |
a6eb515f |
260 | //======================================================================= |
60bf98ae |
261 | Standard_Real AIS_Dimension::ValueToDisplayUnits() const |
a6eb515f |
262 | { |
60bf98ae |
263 | return UnitsAPI::AnyToAny (GetValue(), |
264 | GetModelUnits().ToCString(), |
265 | GetDisplayUnits().ToCString()); |
a6eb515f |
266 | } |
267 | |
268 | //======================================================================= |
60bf98ae |
269 | //function : GetValueString |
a6eb515f |
270 | //purpose : |
271 | //======================================================================= |
60bf98ae |
272 | TCollection_ExtendedString AIS_Dimension::GetValueString (Standard_Real& theWidth) const |
a6eb515f |
273 | { |
60bf98ae |
274 | // format value string using "sprintf" |
275 | TCollection_AsciiString aFormatStr = myDrawer->DimensionAspect()->ValueStringFormat(); |
a6eb515f |
276 | |
60bf98ae |
277 | char aFmtBuffer[256]; |
278 | sprintf (aFmtBuffer, aFormatStr.ToCString(), ValueToDisplayUnits()); |
279 | TCollection_ExtendedString aValueStr = TCollection_ExtendedString (aFmtBuffer); |
a6eb515f |
280 | |
60bf98ae |
281 | // add units to values string |
282 | if (myDrawer->DimensionAspect()->IsUnitsDisplayed()) |
a6eb515f |
283 | { |
60bf98ae |
284 | aValueStr += " "; |
285 | aValueStr += TCollection_ExtendedString (GetDisplayUnits()); |
a6eb515f |
286 | } |
60bf98ae |
287 | |
288 | switch (myDisplaySpecialSymbol) |
a6eb515f |
289 | { |
60bf98ae |
290 | case AIS_DSS_Before : aValueStr.Insert (1, mySpecialSymbol); break; |
291 | case AIS_DSS_After : aValueStr.Insert (aValueStr.Length() + 1, mySpecialSymbol); break; |
292 | case AIS_DSS_No : break; |
a6eb515f |
293 | } |
294 | |
d7bffd44 |
295 | // Get text style parameters |
b6472664 |
296 | Handle(Prs3d_TextAspect) aTextAspect = myDrawer->DimensionAspect()->TextAspect(); |
60bf98ae |
297 | NCollection_Utf8String anUTFString = (Standard_Utf16Char* )aValueStr.ToExtString(); |
fe83e1ea |
298 | |
d7bffd44 |
299 | theWidth = 0.0; |
fe83e1ea |
300 | |
301 | if (myDrawer->DimensionAspect()->IsText3d()) |
302 | { |
303 | // text width produced by BRepFont |
b6472664 |
304 | Font_BRepFont aFont (aTextAspect->Aspect()->Font().ToCString(), |
305 | aTextAspect->Aspect()->GetTextFontAspect(), |
306 | aTextAspect->Height()); |
fe83e1ea |
307 | |
308 | for (NCollection_Utf8Iter anIter = anUTFString.Iterator(); *anIter != 0; ) |
309 | { |
310 | Standard_Utf32Char aCurrChar = *anIter; |
311 | Standard_Utf32Char aNextChar = *(++anIter); |
312 | theWidth += aFont.AdvanceX (aCurrChar, aNextChar); |
313 | } |
314 | } |
315 | else |
d7bffd44 |
316 | { |
fe83e1ea |
317 | // Text width for 1:1 scale 2D case |
60bf98ae |
318 | Handle(Font_FTFont) aFont = new Font_FTFont(); |
b6472664 |
319 | aFont->Init (aTextAspect->Aspect()->Font().ToCString(), |
320 | aTextAspect->Aspect()->GetTextFontAspect(), |
321 | (const unsigned int)aTextAspect->Height(), |
322 | THE_2D_TEXT_RESOLUTION); |
fe83e1ea |
323 | |
324 | for (NCollection_Utf8Iter anIter = anUTFString.Iterator(); *anIter != 0; ) |
325 | { |
326 | Standard_Utf32Char aCurrChar = *anIter; |
327 | Standard_Utf32Char aNextChar = *(++anIter); |
328 | theWidth += (Standard_Real) aFont->AdvanceX (aCurrChar, aNextChar); |
329 | } |
d7bffd44 |
330 | } |
60bf98ae |
331 | |
332 | return aValueStr; |
a6eb515f |
333 | } |
334 | |
335 | //======================================================================= |
60bf98ae |
336 | //function : DrawArrow |
a6eb515f |
337 | //purpose : |
338 | //======================================================================= |
60bf98ae |
339 | void AIS_Dimension::DrawArrow (const Handle(Prs3d_Presentation)& thePresentation, |
a6eb515f |
340 | const gp_Pnt& theLocation, |
341 | const gp_Dir& theDirection) |
342 | { |
343 | Prs3d_Root::NewGroup (thePresentation); |
fe83e1ea |
344 | |
345 | Quantity_Length aLength = myDrawer->DimensionAspect()->ArrowAspect()->Length(); |
346 | Standard_Real anAngle = myDrawer->DimensionAspect()->ArrowAspect()->Angle(); |
a6eb515f |
347 | |
348 | if (myDrawer->DimensionAspect()->IsArrows3d()) |
349 | { |
350 | Prs3d_Arrow::Draw (thePresentation, |
351 | theLocation, |
d7bffd44 |
352 | theDirection, |
fe83e1ea |
353 | anAngle, |
354 | aLength); |
b6472664 |
355 | |
356 | Prs3d_Root::CurrentGroup (thePresentation)->SetGroupPrimitivesAspect (myDrawer->DimensionAspect()->ArrowAspect()->Aspect()); |
a6eb515f |
357 | } |
358 | else |
359 | { |
fe83e1ea |
360 | gp_Pnt aLeftPoint (gp::Origin()); |
361 | gp_Pnt aRightPoint (gp::Origin()); |
60bf98ae |
362 | const gp_Dir& aPlane = GetPlane().Axis().Direction(); |
fe83e1ea |
363 | |
364 | PointsForArrow (theLocation, theDirection, aPlane, aLength, anAngle, aLeftPoint, aRightPoint); |
365 | |
a6eb515f |
366 | Handle(Graphic3d_ArrayOfTriangles) anArrow = new Graphic3d_ArrayOfTriangles(3); |
a6eb515f |
367 | |
368 | anArrow->AddVertex (aLeftPoint); |
369 | anArrow->AddVertex (theLocation); |
370 | anArrow->AddVertex (aRightPoint); |
371 | |
372 | // Set aspect for arrow triangles |
a6eb515f |
373 | Graphic3d_MaterialAspect aShadeMat (Graphic3d_NOM_DEFAULT); |
374 | aShadeMat.SetReflectionModeOff (Graphic3d_TOR_AMBIENT); |
375 | aShadeMat.SetReflectionModeOff (Graphic3d_TOR_DIFFUSE); |
376 | aShadeMat.SetReflectionModeOff (Graphic3d_TOR_SPECULAR); |
d7bffd44 |
377 | |
378 | Handle(Prs3d_ShadingAspect) aShadingStyle = new Prs3d_ShadingAspect(); |
b6472664 |
379 | aShadingStyle->SetColor (myDrawer->DimensionAspect()->ArrowAspect()->Aspect()->Color()); |
d7bffd44 |
380 | aShadingStyle->SetMaterial (aShadeMat); |
381 | |
382 | Prs3d_Root::CurrentGroup (thePresentation)->SetPrimitivesAspect (aShadingStyle->Aspect()); |
383 | Prs3d_Root::CurrentGroup (thePresentation)->AddPrimitiveArray (anArrow); |
a6eb515f |
384 | } |
fe83e1ea |
385 | |
386 | SelectionGeometry::Arrow& aSensitiveArrow = mySelectionGeom.NewArrow(); |
387 | aSensitiveArrow.Position = theLocation; |
388 | aSensitiveArrow.Direction = theDirection; |
a6eb515f |
389 | } |
390 | |
391 | //======================================================================= |
7c65581d |
392 | //function : drawText |
393 | //purpose : |
a6eb515f |
394 | //======================================================================= |
7c65581d |
395 | void AIS_Dimension::drawText (const Handle(Prs3d_Presentation)& thePresentation, |
fe83e1ea |
396 | const gp_Pnt& theTextPos, |
397 | const gp_Dir& theTextDir, |
398 | const TCollection_ExtendedString& theText, |
399 | const Standard_Integer theLabelPosition) |
a6eb515f |
400 | { |
a6eb515f |
401 | if (myDrawer->DimensionAspect()->IsText3d()) |
402 | { |
fe83e1ea |
403 | // getting font parameters |
b6472664 |
404 | Handle(Prs3d_TextAspect) aTextAspect = myDrawer->DimensionAspect()->TextAspect(); |
405 | Quantity_Color aColor = aTextAspect->Aspect()->Color(); |
406 | Font_FontAspect aFontAspect = aTextAspect->Aspect()->GetTextFontAspect(); |
407 | Standard_Real aFontHeight = aTextAspect->Height(); |
a6eb515f |
408 | |
fe83e1ea |
409 | // creating TopoDS_Shape for text |
b6472664 |
410 | Font_BRepFont aFont (aTextAspect->Aspect()->Font().ToCString(), |
411 | aFontAspect, aFontHeight); |
fe83e1ea |
412 | NCollection_Utf8String anUTFString = (Standard_Utf16Char* )theText.ToExtString(); |
ac84fcf6 |
413 | |
414 | Font_BRepTextBuilder aBuilder; |
415 | TopoDS_Shape aTextShape = aBuilder.Perform (aFont, anUTFString); |
a6eb515f |
416 | |
fe83e1ea |
417 | // compute text width with kerning |
418 | Standard_Real aTextWidth = 0.0; |
419 | Standard_Real aTextHeight = aFont.Ascender() + aFont.Descender(); |
d7bffd44 |
420 | |
fe83e1ea |
421 | for (NCollection_Utf8Iter anIter = anUTFString.Iterator(); *anIter != 0; ) |
422 | { |
423 | Standard_Utf32Char aCurrChar = *anIter; |
424 | Standard_Utf32Char aNextChar = *(++anIter); |
425 | aTextWidth += aFont.AdvanceX (aCurrChar, aNextChar); |
426 | } |
427 | |
428 | // formating text position in XOY plane |
d7bffd44 |
429 | Standard_Integer aHLabelPos = theLabelPosition & LabelPosition_HMask; |
430 | Standard_Integer aVLabelPos = theLabelPosition & LabelPosition_VMask; |
431 | |
432 | gp_Dir aTextDir (aHLabelPos == LabelPosition_Left ? -theTextDir : theTextDir); |
433 | |
434 | // compute label offsets |
fe83e1ea |
435 | Standard_Real aMarginSize = aFontHeight * THE_3D_TEXT_MARGIN; |
d7bffd44 |
436 | Standard_Real aCenterHOffset = 0.0; |
437 | Standard_Real aCenterVOffset = 0.0; |
438 | switch (aHLabelPos) |
a6eb515f |
439 | { |
d7bffd44 |
440 | case LabelPosition_HCenter : aCenterHOffset = 0.0; break; |
441 | case LabelPosition_Right : aCenterHOffset = aTextWidth / 2.0 + aMarginSize; break; |
442 | case LabelPosition_Left : aCenterHOffset = -aTextWidth / 2.0 - aMarginSize; break; |
a6eb515f |
443 | } |
d7bffd44 |
444 | switch (aVLabelPos) |
a6eb515f |
445 | { |
d7bffd44 |
446 | case LabelPosition_VCenter : aCenterVOffset = 0.0; break; |
447 | case LabelPosition_Above : aCenterVOffset = aTextHeight / 2.0 + aMarginSize; break; |
448 | case LabelPosition_Below : aCenterVOffset = -aTextHeight / 2.0 - aMarginSize; break; |
a6eb515f |
449 | } |
d7bffd44 |
450 | |
451 | // compute shape offset transformation |
fe83e1ea |
452 | Standard_Real aShapeHOffset = aCenterHOffset - aTextWidth / 2.0; |
d7bffd44 |
453 | Standard_Real aShapeVOffset = aCenterVOffset - aTextHeight / 2.0; |
454 | |
fe83e1ea |
455 | // center shape in its bounding box (suppress border spacing added by FT_Font) |
456 | Bnd_Box aShapeBnd; |
457 | BRepBndLib::AddClose (aTextShape, aShapeBnd); |
458 | |
459 | Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax; |
460 | aShapeBnd.Get (aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); |
461 | |
462 | Standard_Real aXalign = aTextWidth * 0.5 - (aXmax + aXmin) * 0.5; |
463 | Standard_Real aYalign = aTextHeight * 0.5 - (aYmax + aYmin) * 0.5; |
464 | aShapeHOffset += aXalign; |
465 | aShapeVOffset += aYalign; |
466 | |
d7bffd44 |
467 | gp_Trsf anOffsetTrsf; |
468 | anOffsetTrsf.SetTranslation (gp::Origin(), gp_Pnt (aShapeHOffset, aShapeVOffset, 0.0)); |
469 | aTextShape.Move (anOffsetTrsf); |
a6eb515f |
470 | |
fe83e1ea |
471 | // transform text to myWorkingPlane coordinate system |
60bf98ae |
472 | gp_Ax3 aTextCoordSystem (theTextPos, GetPlane().Axis().Direction(), aTextDir); |
d7bffd44 |
473 | gp_Trsf aTextPlaneTrsf; |
474 | aTextPlaneTrsf.SetTransformation (aTextCoordSystem, gp_Ax3 (gp::XOY())); |
475 | aTextShape.Move (aTextPlaneTrsf); |
a6eb515f |
476 | |
fe83e1ea |
477 | // set text flipping anchors |
d7bffd44 |
478 | gp_Trsf aCenterOffsetTrsf; |
479 | gp_Pnt aCenterOffset (aCenterHOffset, aCenterVOffset, 0.0); |
480 | aCenterOffsetTrsf.SetTranslation (gp::Origin(), aCenterOffset); |
481 | |
fe83e1ea |
482 | gp_Pnt aCenterOfLabel (gp::Origin()); |
483 | aCenterOfLabel.Transform (aCenterOffsetTrsf); |
484 | aCenterOfLabel.Transform (aTextPlaneTrsf); |
d7bffd44 |
485 | |
60bf98ae |
486 | gp_Ax2 aFlippingAxes (aCenterOfLabel, GetPlane().Axis().Direction(), aTextDir); |
d7bffd44 |
487 | Prs3d_Root::CurrentGroup (thePresentation)->SetFlippingOptions (Standard_True, aFlippingAxes); |
488 | |
fe83e1ea |
489 | // draw text |
a6eb515f |
490 | if (myDrawer->DimensionAspect()->IsTextShaded()) |
491 | { |
492 | // Setting text shading and color parameters |
d2dfbc4d |
493 | if (!myDrawer->HasOwnShadingAspect()) |
494 | { |
495 | myDrawer->SetShadingAspect (new Prs3d_ShadingAspect()); |
496 | } |
497 | |
a6eb515f |
498 | Graphic3d_MaterialAspect aShadeMat (Graphic3d_NOM_DEFAULT); |
499 | aShadeMat.SetReflectionModeOff (Graphic3d_TOR_AMBIENT); |
500 | aShadeMat.SetReflectionModeOff (Graphic3d_TOR_DIFFUSE); |
501 | aShadeMat.SetReflectionModeOff (Graphic3d_TOR_SPECULAR); |
502 | myDrawer->ShadingAspect()->Aspect()->SetInteriorColor (aColor); |
503 | myDrawer->ShadingAspect()->Aspect()->SetBackInteriorColor (aColor); |
504 | myDrawer->ShadingAspect()->SetMaterial (aShadeMat); |
505 | |
fe83e1ea |
506 | // drawing text |
a6eb515f |
507 | StdPrs_ShadedShape::Add (thePresentation, aTextShape, myDrawer); |
508 | } |
509 | else |
510 | { |
d2dfbc4d |
511 | // Setting color for text |
512 | if (!myDrawer->HasOwnFreeBoundaryAspect()) |
513 | { |
514 | myDrawer->SetFreeBoundaryAspect (new Prs3d_LineAspect (aColor, Aspect_TOL_SOLID, 1.0)); |
515 | } |
516 | |
a6eb515f |
517 | myDrawer->FreeBoundaryAspect()->Aspect()->SetColor (aColor); |
d2dfbc4d |
518 | |
fe83e1ea |
519 | // drawing text |
a6eb515f |
520 | StdPrs_WFShape::Add (thePresentation, aTextShape, myDrawer); |
521 | } |
d7bffd44 |
522 | Prs3d_Root::CurrentGroup (thePresentation)->SetFlippingOptions (Standard_False, gp_Ax2()); |
523 | |
fe83e1ea |
524 | mySelectionGeom.TextPos = aCenterOfLabel; |
525 | mySelectionGeom.TextDir = aTextDir; |
526 | mySelectionGeom.TextWidth = aTextWidth + aMarginSize * 2.0; |
527 | mySelectionGeom.TextHeight = aTextHeight; |
528 | |
529 | return; |
a6eb515f |
530 | } |
531 | |
fe83e1ea |
532 | // generate primitives for 2D text |
d7bffd44 |
533 | myDrawer->DimensionAspect()->TextAspect()->Aspect()->SetDisplayType (Aspect_TODT_DIMENSION); |
534 | |
535 | Prs3d_Text::Draw (thePresentation, |
536 | myDrawer->DimensionAspect()->TextAspect(), |
537 | theText, |
fe83e1ea |
538 | theTextPos); |
d7bffd44 |
539 | |
fe83e1ea |
540 | mySelectionGeom.TextPos = theTextPos; |
541 | mySelectionGeom.TextDir = theTextDir; |
542 | mySelectionGeom.TextWidth = 0.0; |
543 | mySelectionGeom.TextHeight = 0.0; |
a6eb515f |
544 | } |
545 | |
d7bffd44 |
546 | //======================================================================= |
60bf98ae |
547 | //function : DrawExtension |
a6eb515f |
548 | //purpose : |
549 | //======================================================================= |
60bf98ae |
550 | void AIS_Dimension::DrawExtension (const Handle(Prs3d_Presentation)& thePresentation, |
d7bffd44 |
551 | const Standard_Real theExtensionSize, |
552 | const gp_Pnt& theExtensionStart, |
553 | const gp_Dir& theExtensionDir, |
fe83e1ea |
554 | const TCollection_ExtendedString& theLabelString, |
555 | const Standard_Real theLabelWidth, |
556 | const Standard_Integer theMode, |
d7bffd44 |
557 | const Standard_Integer theLabelPosition) |
a6eb515f |
558 | { |
fe83e1ea |
559 | // reference line for extension starting at its connection point |
560 | gp_Lin anExtensionLine (theExtensionStart, theExtensionDir); |
a6eb515f |
561 | |
fe83e1ea |
562 | Standard_Boolean hasLabel = theLabelString.Length() > 0; |
fe83e1ea |
563 | if (hasLabel && (theMode == ComputeMode_All || theMode == ComputeMode_Text)) |
a6eb515f |
564 | { |
d7bffd44 |
565 | // compute text primitives; get its model width |
fe83e1ea |
566 | gp_Pnt aTextPos = ElCLib::Value (theExtensionSize, anExtensionLine); |
60bf98ae |
567 | gp_Dir aTextDir = theExtensionDir; |
fe83e1ea |
568 | |
7c65581d |
569 | drawText (thePresentation, |
fe83e1ea |
570 | aTextPos, |
571 | aTextDir, |
572 | theLabelString, |
573 | theLabelPosition); |
a6eb515f |
574 | } |
575 | |
fe83e1ea |
576 | if (theMode != ComputeMode_All && theMode != ComputeMode_Line) |
a6eb515f |
577 | { |
d7bffd44 |
578 | return; |
a6eb515f |
579 | } |
580 | |
fe83e1ea |
581 | Standard_Boolean isShortLine = !myDrawer->DimensionAspect()->IsText3d() |
582 | || theLabelPosition & LabelPosition_VCenter; |
583 | |
d7bffd44 |
584 | // compute graphical primitives and sensitives for extension line |
585 | gp_Pnt anExtStart = theExtensionStart; |
fe83e1ea |
586 | gp_Pnt anExtEnd = !hasLabel || isShortLine |
587 | ? ElCLib::Value (theExtensionSize, anExtensionLine) |
588 | : ElCLib::Value (theExtensionSize + theLabelWidth, anExtensionLine); |
d7bffd44 |
589 | |
fe83e1ea |
590 | // add graphical primitives |
d7bffd44 |
591 | Handle(Graphic3d_ArrayOfSegments) anExtPrimitive = new Graphic3d_ArrayOfSegments (2); |
592 | anExtPrimitive->AddVertex (anExtStart); |
593 | anExtPrimitive->AddVertex (anExtEnd); |
594 | |
fe83e1ea |
595 | // add selection primitives |
596 | SelectionGeometry::Curve& aSensitiveCurve = mySelectionGeom.NewCurve(); |
597 | aSensitiveCurve.Append (anExtStart); |
598 | aSensitiveCurve.Append (anExtEnd); |
a6eb515f |
599 | |
fe83e1ea |
600 | if (!myDrawer->DimensionAspect()->IsText3d() && theMode == ComputeMode_All) |
a6eb515f |
601 | { |
d7bffd44 |
602 | Prs3d_Root::CurrentGroup (thePresentation)->SetStencilTestOptions (Standard_True); |
603 | } |
604 | Handle(Graphic3d_AspectLine3d) aDimensionLineStyle = myDrawer->DimensionAspect()->LineAspect()->Aspect(); |
605 | Prs3d_Root::CurrentGroup (thePresentation)->SetPrimitivesAspect (aDimensionLineStyle); |
606 | Prs3d_Root::CurrentGroup (thePresentation)->AddPrimitiveArray (anExtPrimitive); |
fe83e1ea |
607 | if (!myDrawer->DimensionAspect()->IsText3d() && theMode == ComputeMode_All) |
d7bffd44 |
608 | { |
609 | Prs3d_Root::CurrentGroup (thePresentation)->SetStencilTestOptions (Standard_False); |
a6eb515f |
610 | } |
611 | } |
612 | |
613 | //======================================================================= |
60bf98ae |
614 | //function : DrawLinearDimension |
a6eb515f |
615 | //purpose : |
616 | //======================================================================= |
60bf98ae |
617 | void AIS_Dimension::DrawLinearDimension (const Handle(Prs3d_Presentation)& thePresentation, |
fe83e1ea |
618 | const Standard_Integer theMode, |
60bf98ae |
619 | const gp_Pnt& theFirstPoint, |
620 | const gp_Pnt& theSecondPoint, |
621 | const Standard_Boolean theIsOneSide) |
a6eb515f |
622 | { |
60bf98ae |
623 | // do not build any dimension for equal points |
624 | if (theFirstPoint.IsEqual (theSecondPoint, Precision::Confusion())) |
a6eb515f |
625 | { |
60bf98ae |
626 | Standard_ProgramError::Raise ("Can not build presentation for equal points."); |
a6eb515f |
627 | } |
d7bffd44 |
628 | |
a6eb515f |
629 | Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect(); |
a6eb515f |
630 | |
d7bffd44 |
631 | // For extensions we need to know arrow size, text size and extension size: get it from aspect |
632 | Quantity_Length anArrowLength = aDimensionAspect->ArrowAspect()->Length(); |
633 | Standard_Real anExtensionSize = aDimensionAspect->ExtensionSize(); |
fe83e1ea |
634 | // prepare label string and compute its geometrical width |
635 | Standard_Real aLabelWidth; |
60bf98ae |
636 | TCollection_ExtendedString aLabelString = GetValueString (aLabelWidth); |
a6eb515f |
637 | |
fe83e1ea |
638 | // add margins to cut dimension lines for 3d text |
639 | if (aDimensionAspect->IsText3d()) |
640 | { |
641 | aLabelWidth += aDimensionAspect->TextAspect()->Height() * THE_3D_TEXT_MARGIN * 2.0; |
642 | } |
643 | |
644 | // handle user-defined and automatic arrow placement |
af203d54 |
645 | Standard_Boolean isArrowsExternal = Standard_False; |
646 | Standard_Integer aLabelPosition = LabelPosition_None; |
fe83e1ea |
647 | |
af203d54 |
648 | Prs3d_DimensionTextHorizontalPosition aHorisontalTextPos = aDimensionAspect->TextHorizontalPosition(); |
649 | if (IsTextPositionCustom()) |
650 | { |
91b16a64 |
651 | if (!AdjustParametersForLinear (myFixedTextPosition, theFirstPoint, theSecondPoint, |
652 | anExtensionSize, aHorisontalTextPos, myFlyout, myPlane, myIsPlaneCustom)) |
653 | { |
654 | Standard_ProgramError::Raise ("Can not adjust plane to the custom label position."); |
655 | } |
a6eb515f |
656 | } |
a6eb515f |
657 | |
af203d54 |
658 | FitTextAlignmentForLinear (theFirstPoint, theSecondPoint, theIsOneSide, aHorisontalTextPos, |
659 | aLabelPosition, isArrowsExternal); |
660 | |
661 | // compute dimension line points |
662 | gp_Ax1 aPlaneNormal = GetPlane().Axis(); |
663 | gp_Dir aTargetPointsVector = gce_MakeDir (theFirstPoint, theSecondPoint); |
664 | |
665 | // compute flyout direction vector |
666 | gp_Dir aFlyoutVector = aPlaneNormal.Direction() ^ aTargetPointsVector; |
667 | |
668 | // create lines for layouts |
669 | gp_Lin aLine1 (theFirstPoint, aFlyoutVector); |
670 | gp_Lin aLine2 (theSecondPoint, aFlyoutVector); |
671 | |
672 | // Get flyout end points |
673 | gp_Pnt aLineBegPoint = ElCLib::Value (ElCLib::Parameter (aLine1, theFirstPoint) + GetFlyout(), aLine1); |
674 | gp_Pnt aLineEndPoint = ElCLib::Value (ElCLib::Parameter (aLine2, theSecondPoint) + GetFlyout(), aLine2); |
675 | |
676 | gp_Lin aDimensionLine = gce_MakeLin (aLineBegPoint, aLineEndPoint); |
677 | |
fe83e1ea |
678 | // compute arrows positions and directions |
d7bffd44 |
679 | gp_Dir aFirstArrowDir = aDimensionLine.Direction().Reversed(); |
680 | gp_Dir aSecondArrowDir = aDimensionLine.Direction(); |
681 | gp_Dir aFirstExtensionDir = aDimensionLine.Direction().Reversed(); |
682 | gp_Dir aSecondExtensionDir = aDimensionLine.Direction(); |
683 | |
684 | gp_Pnt aFirstArrowBegin (0.0, 0.0, 0.0); |
685 | gp_Pnt aFirstArrowEnd (0.0, 0.0, 0.0); |
686 | gp_Pnt aSecondArrowBegin (0.0, 0.0, 0.0); |
687 | gp_Pnt aSecondArrowEnd (0.0, 0.0, 0.0); |
a6eb515f |
688 | |
d7bffd44 |
689 | if (isArrowsExternal) |
a6eb515f |
690 | { |
691 | aFirstArrowDir.Reverse(); |
692 | aSecondArrowDir.Reverse(); |
a6eb515f |
693 | } |
d7bffd44 |
694 | |
695 | aFirstArrowBegin = aLineBegPoint; |
696 | aSecondArrowBegin = aLineEndPoint; |
697 | aFirstArrowEnd = aLineBegPoint.Translated (-gp_Vec (aFirstArrowDir).Scaled (anArrowLength)); |
698 | aSecondArrowEnd = aLineEndPoint.Translated (-gp_Vec (aSecondArrowDir).Scaled (anArrowLength)); |
699 | |
700 | gp_Pnt aCenterLineBegin = isArrowsExternal |
60bf98ae |
701 | ? aLineBegPoint : aFirstArrowEnd; |
d7bffd44 |
702 | |
60bf98ae |
703 | gp_Pnt aCenterLineEnd = isArrowsExternal || theIsOneSide |
d7bffd44 |
704 | ? aLineEndPoint : aSecondArrowEnd; |
705 | |
a6eb515f |
706 | |
d7bffd44 |
707 | switch (aLabelPosition & LabelPosition_HMask) |
a6eb515f |
708 | { |
d7bffd44 |
709 | // ------------------------------------------------------------------------ // |
710 | // CENTER // |
711 | // -------------------------------------------------------------------------// |
d7bffd44 |
712 | case LabelPosition_HCenter: |
a6eb515f |
713 | { |
d7bffd44 |
714 | // add label on dimension or extension line to presentation |
715 | Prs3d_Root::NewGroup (thePresentation); |
a6eb515f |
716 | |
af203d54 |
717 | gp_Pnt aTextPos = IsTextPositionCustom() ? myFixedTextPosition |
718 | : (aCenterLineBegin.XYZ() + aCenterLineEnd.XYZ()) * 0.5; |
60bf98ae |
719 | gp_Dir aTextDir = aDimensionLine.Direction(); |
a6eb515f |
720 | |
fe83e1ea |
721 | // add text primitives |
722 | if (theMode == ComputeMode_All || theMode == ComputeMode_Text) |
a6eb515f |
723 | { |
7c65581d |
724 | drawText (thePresentation, |
fe83e1ea |
725 | aTextPos, |
726 | aTextDir, |
727 | aLabelString, |
728 | aLabelPosition); |
a6eb515f |
729 | } |
d7bffd44 |
730 | |
fe83e1ea |
731 | // add dimension line primitives |
732 | if (theMode == ComputeMode_All || theMode == ComputeMode_Line) |
733 | { |
734 | Standard_Boolean isLineBreak = aDimensionAspect->TextVerticalPosition() == Prs3d_DTVP_Center |
735 | && aDimensionAspect->IsText3d(); |
d7bffd44 |
736 | |
fe83e1ea |
737 | Handle(Graphic3d_ArrayOfSegments) aPrimSegments = new Graphic3d_ArrayOfSegments (isLineBreak ? 4 : 2); |
d7bffd44 |
738 | |
fe83e1ea |
739 | // compute continuous or sectioned main line segments |
740 | if (isLineBreak) |
741 | { |
742 | Standard_Real aPTextPosition = ElCLib::Parameter (aDimensionLine, aTextPos); |
743 | gp_Pnt aSection1Beg = aCenterLineBegin; |
744 | gp_Pnt aSection1End = ElCLib::Value (aPTextPosition - (aLabelWidth * 0.5), aDimensionLine); |
745 | gp_Pnt aSection2Beg = ElCLib::Value (aPTextPosition + (aLabelWidth * 0.5), aDimensionLine); |
746 | gp_Pnt aSection2End = aCenterLineEnd; |
747 | |
748 | aPrimSegments->AddVertex (aSection1Beg); |
749 | aPrimSegments->AddVertex (aSection1End); |
750 | aPrimSegments->AddVertex (aSection2Beg); |
751 | aPrimSegments->AddVertex (aSection2End); |
752 | |
753 | SelectionGeometry::Curve& aLeftSensitiveCurve = mySelectionGeom.NewCurve(); |
754 | SelectionGeometry::Curve& aRightSensitiveCurve = mySelectionGeom.NewCurve(); |
755 | aLeftSensitiveCurve.Append (aSection1Beg); |
756 | aLeftSensitiveCurve.Append (aSection1End); |
757 | aRightSensitiveCurve.Append (aSection2Beg); |
758 | aRightSensitiveCurve.Append (aSection2End); |
759 | } |
760 | else |
761 | { |
762 | aPrimSegments->AddVertex (aCenterLineBegin); |
763 | aPrimSegments->AddVertex (aCenterLineEnd); |
a6eb515f |
764 | |
fe83e1ea |
765 | SelectionGeometry::Curve& aSensitiveCurve = mySelectionGeom.NewCurve(); |
766 | aSensitiveCurve.Append (aCenterLineBegin); |
767 | aSensitiveCurve.Append (aCenterLineEnd); |
768 | } |
a6eb515f |
769 | |
fe83e1ea |
770 | // set text label justification |
771 | Graphic3d_VerticalTextAlignment aTextJustificaton = Graphic3d_VTA_BOTTOM; |
772 | switch (aLabelPosition & LabelPosition_VMask) |
773 | { |
774 | case LabelPosition_Above : |
775 | case LabelPosition_VCenter : aTextJustificaton = Graphic3d_VTA_BOTTOM; break; |
776 | case LabelPosition_Below : aTextJustificaton = Graphic3d_VTA_TOP; break; |
777 | } |
778 | aDimensionAspect->TextAspect()->SetVerticalJustification (aTextJustificaton); |
a6eb515f |
779 | |
fe83e1ea |
780 | // main dimension line, short extension |
781 | if (!aDimensionAspect->IsText3d() && theMode == ComputeMode_All) |
782 | { |
783 | Prs3d_Root::CurrentGroup (thePresentation)->SetStencilTestOptions (Standard_True); |
784 | } |
785 | Prs3d_Root::CurrentGroup (thePresentation)->SetPrimitivesAspect (aDimensionAspect->LineAspect()->Aspect()); |
786 | Prs3d_Root::CurrentGroup (thePresentation)->AddPrimitiveArray (aPrimSegments); |
787 | if (!aDimensionAspect->IsText3d() && theMode == ComputeMode_All) |
788 | { |
789 | Prs3d_Root::CurrentGroup (thePresentation)->SetStencilTestOptions (Standard_False); |
790 | } |
d7bffd44 |
791 | |
fe83e1ea |
792 | // add arrows to presentation |
793 | Prs3d_Root::NewGroup (thePresentation); |
d7bffd44 |
794 | |
60bf98ae |
795 | DrawArrow (thePresentation, aFirstArrowBegin, aFirstArrowDir); |
796 | if (!theIsOneSide) |
fe83e1ea |
797 | { |
60bf98ae |
798 | DrawArrow (thePresentation, aSecondArrowBegin, aSecondArrowDir); |
fe83e1ea |
799 | } |
d7bffd44 |
800 | |
fe83e1ea |
801 | if (!isArrowsExternal) |
802 | { |
803 | break; |
804 | } |
d7bffd44 |
805 | |
fe83e1ea |
806 | // add arrow extension lines to presentation |
807 | Prs3d_Root::NewGroup (thePresentation); |
d7bffd44 |
808 | |
af203d54 |
809 | DrawExtension (thePresentation, aDimensionAspect->ArrowTailSize(), |
fe83e1ea |
810 | aFirstArrowEnd, aFirstExtensionDir, |
811 | THE_EMPTY_LABEL, 0.0, theMode, LabelPosition_None); |
60bf98ae |
812 | if (!theIsOneSide) |
fe83e1ea |
813 | { |
af203d54 |
814 | DrawExtension (thePresentation, aDimensionAspect->ArrowTailSize(), |
fe83e1ea |
815 | aSecondArrowEnd, aSecondExtensionDir, |
816 | THE_EMPTY_LABEL, 0.0, theMode, LabelPosition_None); |
817 | } |
a6eb515f |
818 | } |
1d7ca641 |
819 | |
820 | break; |
a6eb515f |
821 | } |
d7bffd44 |
822 | // ------------------------------------------------------------------------ // |
823 | // LEFT // |
824 | // -------------------------------------------------------------------------// |
825 | |
826 | case LabelPosition_Left: |
a6eb515f |
827 | { |
d7bffd44 |
828 | // add label on dimension or extension line to presentation |
829 | Prs3d_Root::NewGroup (thePresentation); |
a6eb515f |
830 | |
a6eb515f |
831 | // Left extension with the text |
60bf98ae |
832 | DrawExtension (thePresentation, anExtensionSize, |
833 | isArrowsExternal |
834 | ? aFirstArrowEnd |
835 | : aFirstArrowBegin, |
d7bffd44 |
836 | aFirstExtensionDir, |
fe83e1ea |
837 | aLabelString, |
838 | aLabelWidth, |
d7bffd44 |
839 | theMode, |
840 | aLabelPosition); |
841 | |
fe83e1ea |
842 | // add dimension line primitives |
843 | if (theMode == ComputeMode_All || theMode == ComputeMode_Line) |
d7bffd44 |
844 | { |
fe83e1ea |
845 | // add central dimension line |
846 | Prs3d_Root::NewGroup (thePresentation); |
d7bffd44 |
847 | |
fe83e1ea |
848 | // add graphical primitives |
849 | Handle(Graphic3d_ArrayOfSegments) aPrimSegments = new Graphic3d_ArrayOfSegments (2); |
850 | aPrimSegments->AddVertex (aCenterLineBegin); |
851 | aPrimSegments->AddVertex (aCenterLineEnd); |
d7bffd44 |
852 | |
fe83e1ea |
853 | Prs3d_Root::CurrentGroup (thePresentation)->SetPrimitivesAspect (aDimensionAspect->LineAspect()->Aspect()); |
854 | Prs3d_Root::CurrentGroup (thePresentation)->AddPrimitiveArray (aPrimSegments); |
d7bffd44 |
855 | |
fe83e1ea |
856 | // add selection primitives |
857 | SelectionGeometry::Curve& aSensitiveCurve = mySelectionGeom.NewCurve(); |
858 | aSensitiveCurve.Append (aCenterLineBegin); |
859 | aSensitiveCurve.Append (aCenterLineEnd); |
a6eb515f |
860 | |
fe83e1ea |
861 | // add arrows to presentation |
862 | Prs3d_Root::NewGroup (thePresentation); |
a6eb515f |
863 | |
60bf98ae |
864 | DrawArrow (thePresentation, aFirstArrowBegin, aFirstArrowDir); |
865 | if (!theIsOneSide) |
fe83e1ea |
866 | { |
60bf98ae |
867 | DrawArrow (thePresentation, aSecondArrowBegin, aSecondArrowDir); |
fe83e1ea |
868 | } |
d7bffd44 |
869 | |
60bf98ae |
870 | if (!isArrowsExternal || theIsOneSide) |
fe83e1ea |
871 | { |
872 | break; |
873 | } |
d7bffd44 |
874 | |
fe83e1ea |
875 | // add extension lines for external arrows |
876 | Prs3d_Root::NewGroup (thePresentation); |
d7bffd44 |
877 | |
af203d54 |
878 | DrawExtension (thePresentation, aDimensionAspect->ArrowTailSize(), |
fe83e1ea |
879 | aSecondArrowEnd, aSecondExtensionDir, |
880 | THE_EMPTY_LABEL, 0.0, theMode, LabelPosition_None); |
881 | } |
d7bffd44 |
882 | |
a6eb515f |
883 | break; |
884 | } |
d7bffd44 |
885 | // ------------------------------------------------------------------------ // |
886 | // RIGHT // |
887 | // -------------------------------------------------------------------------// |
888 | |
889 | case LabelPosition_Right: |
a6eb515f |
890 | { |
d7bffd44 |
891 | // add label on dimension or extension line to presentation |
892 | Prs3d_Root::NewGroup (thePresentation); |
893 | |
894 | // Right extension with text |
60bf98ae |
895 | DrawExtension (thePresentation, anExtensionSize, |
896 | isArrowsExternal |
897 | ? aSecondArrowEnd |
898 | : aSecondArrowBegin, |
d7bffd44 |
899 | aSecondExtensionDir, |
fe83e1ea |
900 | aLabelString, aLabelWidth, |
d7bffd44 |
901 | theMode, |
902 | aLabelPosition); |
903 | |
fe83e1ea |
904 | if (theMode == ComputeMode_All || theMode == ComputeMode_Line) |
a6eb515f |
905 | { |
fe83e1ea |
906 | // add central dimension line |
907 | Prs3d_Root::NewGroup (thePresentation); |
a6eb515f |
908 | |
fe83e1ea |
909 | // add graphical primitives |
910 | Handle(Graphic3d_ArrayOfSegments) aPrimSegments = new Graphic3d_ArrayOfSegments (2); |
911 | aPrimSegments->AddVertex (aCenterLineBegin); |
912 | aPrimSegments->AddVertex (aCenterLineEnd); |
913 | Prs3d_Root::CurrentGroup (thePresentation)->SetPrimitivesAspect (aDimensionAspect->LineAspect()->Aspect()); |
914 | Prs3d_Root::CurrentGroup (thePresentation)->AddPrimitiveArray (aPrimSegments); |
a6eb515f |
915 | |
fe83e1ea |
916 | // add selection primitives |
917 | SelectionGeometry::Curve& aSensitiveCurve = mySelectionGeom.NewCurve(); |
918 | aSensitiveCurve.Append (aCenterLineBegin); |
919 | aSensitiveCurve.Append (aCenterLineEnd); |
a6eb515f |
920 | |
fe83e1ea |
921 | // add arrows to presentation |
922 | Prs3d_Root::NewGroup (thePresentation); |
d7bffd44 |
923 | |
60bf98ae |
924 | DrawArrow (thePresentation, aSecondArrowBegin, aSecondArrowDir); |
925 | if (!theIsOneSide) |
fe83e1ea |
926 | { |
60bf98ae |
927 | DrawArrow (thePresentation, aFirstArrowBegin, aFirstArrowDir); |
fe83e1ea |
928 | } |
d7bffd44 |
929 | |
60bf98ae |
930 | if (!isArrowsExternal || theIsOneSide) |
fe83e1ea |
931 | { |
932 | break; |
933 | } |
a6eb515f |
934 | |
fe83e1ea |
935 | // add extension lines for external arrows |
936 | Prs3d_Root::NewGroup (thePresentation); |
d7bffd44 |
937 | |
af203d54 |
938 | DrawExtension (thePresentation, aDimensionAspect->ArrowTailSize(), |
fe83e1ea |
939 | aFirstArrowEnd, aFirstExtensionDir, |
940 | THE_EMPTY_LABEL, 0.0, theMode, LabelPosition_None); |
941 | } |
d7bffd44 |
942 | |
a6eb515f |
943 | break; |
944 | } |
945 | } |
946 | |
d7bffd44 |
947 | // add flyout lines to presentation |
fe83e1ea |
948 | if (theMode == ComputeMode_All) |
d7bffd44 |
949 | { |
950 | Prs3d_Root::NewGroup (thePresentation); |
951 | |
952 | Handle(Graphic3d_ArrayOfSegments) aPrimSegments = new Graphic3d_ArrayOfSegments(4); |
60bf98ae |
953 | aPrimSegments->AddVertex (theFirstPoint); |
d7bffd44 |
954 | aPrimSegments->AddVertex (aLineBegPoint); |
955 | |
60bf98ae |
956 | aPrimSegments->AddVertex (theSecondPoint); |
d7bffd44 |
957 | aPrimSegments->AddVertex (aLineEndPoint); |
958 | |
d7bffd44 |
959 | Prs3d_Root::CurrentGroup (thePresentation)->SetPrimitivesAspect (aDimensionAspect->LineAspect()->Aspect()); |
960 | Prs3d_Root::CurrentGroup (thePresentation)->AddPrimitiveArray (aPrimSegments); |
961 | } |
962 | |
91b16a64 |
963 | mySelectionGeom.IsComputed = Standard_True; |
a6eb515f |
964 | } |
965 | |
966 | //======================================================================= |
60bf98ae |
967 | //function : ComputeLinearFlyouts |
968 | //purpose : |
a6eb515f |
969 | //======================================================================= |
60bf98ae |
970 | void AIS_Dimension::ComputeLinearFlyouts (const Handle(SelectMgr_Selection)& theSelection, |
971 | const Handle(SelectMgr_EntityOwner)& theOwner, |
972 | const gp_Pnt& theFirstPoint, |
973 | const gp_Pnt& theSecondPoint) |
a6eb515f |
974 | { |
60bf98ae |
975 | // count flyout direction |
976 | gp_Ax1 aPlaneNormal = GetPlane().Axis(); |
977 | gp_Dir aTargetPointsVector = gce_MakeDir (theFirstPoint, theSecondPoint); |
a6eb515f |
978 | |
60bf98ae |
979 | // count a flyout direction vector. |
980 | gp_Dir aFlyoutVector = aPlaneNormal.Direction() ^ aTargetPointsVector; |
a6eb515f |
981 | |
60bf98ae |
982 | // create lines for layouts |
983 | gp_Lin aLine1 (theFirstPoint, aFlyoutVector); |
984 | gp_Lin aLine2 (theSecondPoint, aFlyoutVector); |
985 | |
986 | // get flyout end points |
987 | gp_Pnt aFlyoutEnd1 = ElCLib::Value (ElCLib::Parameter (aLine1, theFirstPoint) + GetFlyout(), aLine1); |
988 | gp_Pnt aFlyoutEnd2 = ElCLib::Value (ElCLib::Parameter (aLine2, theSecondPoint) + GetFlyout(), aLine2); |
989 | |
990 | // fill sensitive entity for flyouts |
991 | Handle(Select3D_SensitiveGroup) aSensitiveEntity = new Select3D_SensitiveGroup (theOwner); |
992 | aSensitiveEntity->Add (new Select3D_SensitiveSegment (theOwner, theFirstPoint, aFlyoutEnd1)); |
993 | aSensitiveEntity->Add (new Select3D_SensitiveSegment (theOwner, theSecondPoint, aFlyoutEnd2)); |
994 | theSelection->Add (aSensitiveEntity); |
a6eb515f |
995 | } |
996 | |
997 | //======================================================================= |
60bf98ae |
998 | //function : CircleFromPlanarFace |
a6eb515f |
999 | //purpose : if possible computes circle from planar face |
1000 | //======================================================================= |
60bf98ae |
1001 | Standard_Boolean AIS_Dimension::CircleFromPlanarFace (const TopoDS_Face& theFace, |
a6eb515f |
1002 | Handle(Geom_Curve)& theCurve, |
60bf98ae |
1003 | gp_Pnt& theFirstPoint, |
1004 | gp_Pnt& theLastPoint) |
a6eb515f |
1005 | { |
1006 | TopExp_Explorer anIt (theFace, TopAbs_EDGE); |
1007 | for ( ; anIt.More(); anIt.Next()) |
1008 | { |
1009 | TopoDS_Edge aCurEdge = TopoDS::Edge (anIt.Current()); |
1010 | if (AIS::ComputeGeometry (aCurEdge, theCurve, theFirstPoint, theLastPoint)) |
1011 | { |
1012 | if (theCurve->IsInstance (STANDARD_TYPE(Geom_Circle))) |
1013 | { |
1014 | return Standard_True; |
1015 | } |
1016 | } |
1017 | } |
1018 | return Standard_False; |
1019 | } |
1020 | |
0499eb06 |
1021 | //======================================================================= |
1022 | //function : CircleFromEdge |
1023 | //purpose : if possible computes circle from edge |
1024 | //======================================================================= |
1025 | Standard_Boolean AIS_Dimension::CircleFromEdge (const TopoDS_Edge& theEdge, |
1026 | gp_Circ& theCircle, |
1027 | gp_Pnt& theFirstPoint, |
1028 | gp_Pnt& theLastPoint) |
1029 | { |
1030 | BRepAdaptor_Curve anAdaptedCurve (theEdge); |
1031 | switch (anAdaptedCurve.GetType()) |
1032 | { |
1033 | case GeomAbs_Circle: |
1034 | { |
1035 | theCircle = anAdaptedCurve.Circle(); |
1036 | break; |
1037 | } |
1038 | case GeomAbs_Ellipse: |
1039 | { |
1040 | gp_Elips anEll = anAdaptedCurve.Ellipse(); |
1041 | if ((anEll.MinorRadius() - anEll.MajorRadius()) >= Precision::Confusion()) |
1042 | { |
1043 | return Standard_False; |
1044 | } |
1045 | theCircle = gp_Circ(anEll.Position(),anEll.MinorRadius()); |
1046 | break; |
1047 | } |
1048 | case GeomAbs_Line: |
1049 | case GeomAbs_Hyperbola: |
1050 | case GeomAbs_Parabola: |
1051 | case GeomAbs_BezierCurve: |
1052 | case GeomAbs_BSplineCurve: |
1053 | case GeomAbs_OtherCurve: |
1054 | default: |
1055 | return Standard_False; |
1056 | } |
1057 | |
1058 | theFirstPoint = anAdaptedCurve.Value (anAdaptedCurve.FirstParameter()); |
1059 | theLastPoint = anAdaptedCurve.Value (anAdaptedCurve.LastParameter()); |
1060 | return Standard_True; |
1061 | } |
1062 | |
a6eb515f |
1063 | //======================================================================= |
60bf98ae |
1064 | //function : InitCircularDimension |
1065 | //purpose : |
a6eb515f |
1066 | //======================================================================= |
60bf98ae |
1067 | Standard_Boolean AIS_Dimension::InitCircularDimension (const TopoDS_Shape& theShape, |
a6eb515f |
1068 | gp_Circ& theCircle, |
1069 | gp_Pnt& theMiddleArcPoint, |
60bf98ae |
1070 | Standard_Boolean& theIsClosed) |
a6eb515f |
1071 | { |
1072 | gp_Pln aPln; |
1073 | Handle(Geom_Surface) aBasisSurf; |
1074 | AIS_KindOfSurface aSurfType = AIS_KOS_OtherSurface; |
1075 | gp_Pnt aFirstPoint, aLastPoint; |
1076 | Standard_Real anOffset = 0.0; |
1077 | Standard_Real aFirstParam = 0.0; |
1078 | Standard_Real aLastParam = 0.0; |
a6eb515f |
1079 | |
0499eb06 |
1080 | // Discover circular geometry |
1081 | switch (theShape.ShapeType()) |
a6eb515f |
1082 | { |
0499eb06 |
1083 | case TopAbs_FACE: |
a6eb515f |
1084 | { |
0499eb06 |
1085 | AIS::GetPlaneFromFace (TopoDS::Face (theShape), aPln, aBasisSurf, aSurfType, anOffset); |
a6eb515f |
1086 | |
0499eb06 |
1087 | if (aSurfType == AIS_KOS_Plane) |
a6eb515f |
1088 | { |
0499eb06 |
1089 | Handle(Geom_Curve) aCurve; |
1090 | if (!CircleFromPlanarFace (TopoDS::Face (theShape), aCurve, aFirstPoint, aLastPoint)) |
1091 | { |
1092 | return Standard_False; |
1093 | } |
1094 | |
1095 | theCircle = Handle(Geom_Circle)::DownCast (aCurve)->Circ(); |
a6eb515f |
1096 | } |
1097 | else |
1098 | { |
0499eb06 |
1099 | gp_Pnt aCurPos; |
1100 | BRepAdaptor_Surface aSurf1 (TopoDS::Face (theShape)); |
1101 | Standard_Real aFirstU = aSurf1.FirstUParameter(); |
1102 | Standard_Real aLastU = aSurf1.LastUParameter(); |
1103 | Standard_Real aFirstV = aSurf1.FirstVParameter(); |
1104 | Standard_Real aLastV = aSurf1.LastVParameter(); |
1105 | Standard_Real aMidU = (aFirstU + aLastU) * 0.5; |
1106 | Standard_Real aMidV = (aFirstV + aLastV) * 0.5; |
1107 | aSurf1.D0 (aMidU, aMidV, aCurPos); |
1108 | Handle (Adaptor3d_HCurve) aBasisCurve; |
1109 | Standard_Boolean isExpectedType = Standard_False; |
1110 | if (aSurfType == AIS_KOS_Cylinder) |
a6eb515f |
1111 | { |
0499eb06 |
1112 | isExpectedType = Standard_True; |
a6eb515f |
1113 | } |
0499eb06 |
1114 | else |
a6eb515f |
1115 | { |
0499eb06 |
1116 | if (aSurfType == AIS_KOS_Revolution) |
a6eb515f |
1117 | { |
0499eb06 |
1118 | aBasisCurve = aSurf1.BasisCurve(); |
1119 | if (aBasisCurve->GetType() == GeomAbs_Line) |
1120 | { |
1121 | isExpectedType = Standard_True; |
1122 | } |
1123 | } |
1124 | else if (aSurfType == AIS_KOS_Extrusion) |
1125 | { |
1126 | aBasisCurve = aSurf1.BasisCurve(); |
1127 | if (aBasisCurve->GetType() == GeomAbs_Circle) |
1128 | { |
1129 | isExpectedType = Standard_True; |
1130 | } |
a6eb515f |
1131 | } |
1132 | } |
a6eb515f |
1133 | |
0499eb06 |
1134 | if (!isExpectedType) |
1135 | { |
1136 | return Standard_False; |
1137 | } |
60bf98ae |
1138 | |
0499eb06 |
1139 | Handle(Geom_Curve) aCurve = aBasisSurf->VIso(aMidV); |
1140 | if (aCurve->DynamicType() == STANDARD_TYPE (Geom_Circle)) |
a6eb515f |
1141 | { |
0499eb06 |
1142 | theCircle = Handle(Geom_Circle)::DownCast (aCurve)->Circ(); |
1143 | } |
1144 | else if (aCurve->DynamicType() == STANDARD_TYPE (Geom_TrimmedCurve)) |
1145 | { |
1146 | Handle(Geom_TrimmedCurve) aTrimmedCurve = Handle(Geom_TrimmedCurve)::DownCast (aCurve); |
1147 | aFirstU = aTrimmedCurve->FirstParameter(); |
1148 | aLastU = aTrimmedCurve->LastParameter(); |
1149 | if (aTrimmedCurve->BasisCurve()->DynamicType() == STANDARD_TYPE (Geom_Circle)) |
1150 | { |
1151 | theCircle = Handle(Geom_Circle)::DownCast(aTrimmedCurve->BasisCurve())->Circ(); |
1152 | } |
1153 | } |
1154 | else |
1155 | { |
1156 | // Compute a circle from 3 points on "aCurve" |
1157 | gp_Pnt aP1, aP2; |
1158 | aSurf1.D0 (aFirstU, aMidV, aP1); |
1159 | aSurf1.D0 (aLastU, aMidV, aP2); |
1160 | GC_MakeCircle aMkCirc (aP1, aCurPos, aP2); |
1161 | theCircle = aMkCirc.Value()->Circ(); |
a6eb515f |
1162 | } |
a6eb515f |
1163 | |
0499eb06 |
1164 | aFirstPoint = ElCLib::Value (aFirstU, theCircle); |
1165 | aLastPoint = ElCLib::Value (aLastU, theCircle); |
1166 | } |
1167 | break; |
a6eb515f |
1168 | } |
0499eb06 |
1169 | case TopAbs_WIRE: |
a6eb515f |
1170 | { |
0499eb06 |
1171 | TopoDS_Edge anEdge; |
a6eb515f |
1172 | TopExp_Explorer anIt (theShape, TopAbs_EDGE); |
1173 | if (anIt.More()) |
1174 | { |
1175 | anEdge = TopoDS::Edge (anIt.Current()); |
1176 | } |
0499eb06 |
1177 | if (!AIS_Dimension::CircleFromEdge (anEdge, theCircle, aFirstPoint, aLastPoint)) |
1178 | { |
1179 | return Standard_False; |
1180 | } |
1181 | break; |
a6eb515f |
1182 | } |
0499eb06 |
1183 | case TopAbs_EDGE: |
a6eb515f |
1184 | { |
0499eb06 |
1185 | TopoDS_Edge anEdge = TopoDS::Edge (theShape); |
1186 | if (!AIS_Dimension::CircleFromEdge (anEdge, theCircle, aFirstPoint, aLastPoint)) |
1187 | { |
1188 | return Standard_False; |
1189 | } |
1190 | break; |
a6eb515f |
1191 | } |
0499eb06 |
1192 | case TopAbs_COMPOUND: |
1193 | case TopAbs_COMPSOLID: |
1194 | case TopAbs_SOLID: |
1195 | case TopAbs_SHELL: |
1196 | case TopAbs_VERTEX: |
1197 | case TopAbs_SHAPE: |
1198 | default: |
a6eb515f |
1199 | return Standard_False; |
a6eb515f |
1200 | } |
60bf98ae |
1201 | |
1202 | theIsClosed = aFirstPoint.IsEqual (aLastPoint, Precision::Confusion()); |
1203 | |
a6eb515f |
1204 | gp_Pnt aCenter = theCircle.Location(); |
60bf98ae |
1205 | |
1206 | if (theIsClosed) // Circle |
a6eb515f |
1207 | { |
a6eb515f |
1208 | gp_Dir anXDir = theCircle.XAxis().Direction(); |
1209 | theMiddleArcPoint = aCenter.Translated (gp_Vec (anXDir) * theCircle.Radius()); |
a6eb515f |
1210 | } |
60bf98ae |
1211 | else // Arc |
a6eb515f |
1212 | { |
a6eb515f |
1213 | aFirstParam = ElCLib::Parameter (theCircle, aFirstPoint); |
1214 | aLastParam = ElCLib::Parameter (theCircle, aLastPoint); |
1215 | if (aFirstParam > aLastParam) |
1216 | { |
1217 | aFirstParam -= 2.0 * M_PI; |
1218 | } |
60bf98ae |
1219 | |
a6eb515f |
1220 | Standard_Real aParCurPos = (aFirstParam + aLastParam) * 0.5; |
1221 | gp_Vec aVec = gp_Vec (aCenter, ElCLib::Value (aParCurPos, theCircle)).Normalized () * theCircle.Radius (); |
1222 | theMiddleArcPoint = aCenter.Translated (aVec); |
a6eb515f |
1223 | } |
1224 | |
1225 | return Standard_True; |
1226 | } |
1227 | |
a6eb515f |
1228 | //======================================================================= |
1229 | //function : ComputeSelection |
1230 | //purpose : |
1231 | //======================================================================= |
a6eb515f |
1232 | void AIS_Dimension::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection, |
1233 | const Standard_Integer theMode) |
1234 | { |
91b16a64 |
1235 | if (!mySelectionGeom.IsComputed) |
a6eb515f |
1236 | { |
1237 | return; |
1238 | } |
1239 | |
fe83e1ea |
1240 | AIS_DimensionSelectionMode aSelectionMode = (AIS_DimensionSelectionMode)theMode; |
a6eb515f |
1241 | |
fe83e1ea |
1242 | // init appropriate entity owner |
1243 | Handle(SelectMgr_EntityOwner) aSensitiveOwner; |
a6eb515f |
1244 | |
fe83e1ea |
1245 | switch (aSelectionMode) |
a6eb515f |
1246 | { |
fe83e1ea |
1247 | // neutral selection owner |
1248 | case AIS_DSM_All : |
1249 | aSensitiveOwner = new SelectMgr_EntityOwner (this, THE_NEUTRAL_SEL_PRIORITY); |
1250 | break; |
1251 | |
1252 | // local selection owners |
1253 | case AIS_DSM_Line : |
1254 | case AIS_DSM_Text : |
1255 | aSensitiveOwner = new AIS_DimensionOwner (this, aSelectionMode, THE_LOCAL_SEL_PRIORITY); |
1256 | break; |
a6eb515f |
1257 | } |
fe83e1ea |
1258 | |
1259 | if (aSelectionMode == AIS_DSM_All || aSelectionMode == AIS_DSM_Line) |
a6eb515f |
1260 | { |
fe83e1ea |
1261 | // sensitives for dimension line segments |
1262 | Handle(Select3D_SensitiveGroup) aGroupOfSensitives = new Select3D_SensitiveGroup (aSensitiveOwner); |
1263 | |
1264 | SelectionGeometry::SeqOfCurves::Iterator aCurveIt (mySelectionGeom.DimensionLine); |
1265 | for (; aCurveIt.More(); aCurveIt.Next()) |
1266 | { |
1267 | const SelectionGeometry::HCurve& aCurveData = aCurveIt.Value(); |
1268 | |
1269 | TColgp_Array1OfPnt aSensitivePnts (1, aCurveData->Length()); |
1270 | for (Standard_Integer aPntIt = 1; aPntIt <= aCurveData->Length(); ++aPntIt) |
1271 | { |
1272 | aSensitivePnts.ChangeValue (aPntIt) = aCurveData->Value (aPntIt); |
1273 | } |
1274 | |
1275 | aGroupOfSensitives->Add (new Select3D_SensitiveCurve (aSensitiveOwner, aSensitivePnts)); |
1276 | } |
1277 | |
1278 | Quantity_Length anArrowLength = myDrawer->DimensionAspect()->ArrowAspect()->Length(); |
1279 | Standard_Real anArrowAngle = myDrawer->DimensionAspect()->ArrowAspect()->Angle(); |
1280 | |
1281 | // sensitives for arrows |
1282 | SelectionGeometry::SeqOfArrows::Iterator anArrowIt (mySelectionGeom.Arrows); |
1283 | for (; anArrowIt.More(); anArrowIt.Next()) |
1284 | { |
1285 | const SelectionGeometry::HArrow& anArrow = anArrowIt.Value(); |
1286 | |
1287 | gp_Pnt aSidePnt1 (gp::Origin()); |
1288 | gp_Pnt aSidePnt2 (gp::Origin()); |
60bf98ae |
1289 | const gp_Dir& aPlane = GetPlane().Axis().Direction(); |
fe83e1ea |
1290 | const gp_Pnt& aPeak = anArrow->Position; |
1291 | const gp_Dir& aDir = anArrow->Direction; |
1292 | |
1293 | // compute points for arrow in plane |
1294 | PointsForArrow (aPeak, aDir, aPlane, anArrowLength, anArrowAngle, aSidePnt1, aSidePnt2); |
1295 | |
1296 | aGroupOfSensitives->Add (new Select3D_SensitiveTriangle (aSensitiveOwner, aPeak, aSidePnt1, aSidePnt2)); |
1297 | |
1298 | if (!myDrawer->DimensionAspect()->IsArrows3d()) |
1299 | { |
1300 | continue; |
1301 | } |
1302 | |
1303 | // compute points for orthogonal sensitive plane |
1304 | gp_Dir anOrthoPlane = anArrow->Direction.Crossed (aPlane); |
1305 | |
1306 | PointsForArrow (aPeak, aDir, anOrthoPlane, anArrowLength, anArrowAngle, aSidePnt1, aSidePnt2); |
1307 | |
1308 | aGroupOfSensitives->Add (new Select3D_SensitiveTriangle (aSensitiveOwner, aPeak, aSidePnt1, aSidePnt2)); |
1309 | } |
1310 | |
1311 | theSelection->Add (aGroupOfSensitives); |
a6eb515f |
1312 | } |
fe83e1ea |
1313 | |
1314 | // sensitives for text element |
1315 | if (aSelectionMode == AIS_DSM_All || aSelectionMode == AIS_DSM_Text) |
a6eb515f |
1316 | { |
fe83e1ea |
1317 | Handle(Select3D_SensitiveEntity) aTextSensitive; |
1318 | |
1319 | gp_Ax2 aTextAxes (mySelectionGeom.TextPos, |
60bf98ae |
1320 | GetPlane().Axis().Direction(), |
fe83e1ea |
1321 | mySelectionGeom.TextDir); |
1322 | |
1323 | if (myDrawer->DimensionAspect()->IsText3d()) |
1324 | { |
1325 | // sensitive planar rectangle for text |
1326 | Standard_Real aDx = mySelectionGeom.TextWidth * 0.5; |
1327 | Standard_Real aDy = mySelectionGeom.TextHeight * 0.5; |
1328 | |
1329 | gp_Trsf aLabelPlane; |
1330 | aLabelPlane.SetTransformation (aTextAxes, gp::XOY()); |
1331 | |
51f8f60c |
1332 | TColgp_Array1OfPnt aRectanglePoints(1, 4); |
1333 | aRectanglePoints.ChangeValue(1) = gp_Pnt (-aDx, -aDy, 0.0).Transformed (aLabelPlane); |
1334 | aRectanglePoints.ChangeValue(2) = gp_Pnt (-aDx, aDy, 0.0).Transformed (aLabelPlane); |
1335 | aRectanglePoints.ChangeValue(3) = gp_Pnt ( aDx, aDy, 0.0).Transformed (aLabelPlane); |
1336 | aRectanglePoints.ChangeValue(4) = gp_Pnt ( aDx, -aDy, 0.0).Transformed (aLabelPlane); |
fe83e1ea |
1337 | |
51f8f60c |
1338 | Poly_Array1OfTriangle aTriangles(1, 2); |
1339 | aTriangles.ChangeValue(1) = Poly_Triangle(1, 2, 3); |
1340 | aTriangles.ChangeValue(2) = Poly_Triangle(1, 3, 4); |
1341 | |
1342 | Handle(Poly_Triangulation) aRectanglePoly = |
1343 | new Poly_Triangulation(aRectanglePoints, aTriangles); |
1344 | |
1345 | aTextSensitive = |
1346 | new Select3D_SensitiveTriangulation (aSensitiveOwner, aRectanglePoly, TopLoc_Location(), Standard_True); |
fe83e1ea |
1347 | } |
1348 | else |
1349 | { |
1350 | gp_Circ aTextGeom (aTextAxes, mySelToleranceForText2d != 0.0 |
1351 | ? mySelToleranceForText2d : 1.0); |
1352 | |
1353 | Handle(Geom_Circle) aSensGeom = new Geom_Circle (aTextGeom); |
1354 | |
1355 | aTextSensitive = new Select3D_SensitiveCircle (aSensitiveOwner, aSensGeom, Standard_True); |
1356 | } |
1357 | |
1358 | theSelection->Add (aTextSensitive); |
a6eb515f |
1359 | } |
fe83e1ea |
1360 | |
1361 | // callback for flyout sensitive calculation |
1362 | if (aSelectionMode == AIS_DSM_All) |
d7bffd44 |
1363 | { |
60bf98ae |
1364 | ComputeFlyoutSelection (theSelection, aSensitiveOwner); |
d7bffd44 |
1365 | } |
fe83e1ea |
1366 | } |
1367 | |
1368 | //======================================================================= |
1369 | //function : PointsForArrow |
1370 | //purpose : |
1371 | //======================================================================= |
1372 | void AIS_Dimension::PointsForArrow (const gp_Pnt& thePeakPnt, |
1373 | const gp_Dir& theDirection, |
1374 | const gp_Dir& thePlane, |
1375 | const Standard_Real theArrowLength, |
1376 | const Standard_Real theArrowAngle, |
1377 | gp_Pnt& theSidePnt1, |
1378 | gp_Pnt& theSidePnt2) |
1379 | { |
1380 | gp_Lin anArrowLin (thePeakPnt, theDirection.Reversed()); |
1381 | gp_Pnt anArrowEnd = ElCLib::Value (theArrowLength, anArrowLin); |
1382 | gp_Lin anEdgeLin (anArrowEnd, theDirection.Crossed (thePlane)); |
1383 | |
1384 | Standard_Real anEdgeLength = Tan (theArrowAngle) * theArrowLength; |
a6eb515f |
1385 | |
fe83e1ea |
1386 | theSidePnt1 = ElCLib::Value ( anEdgeLength, anEdgeLin); |
1387 | theSidePnt2 = ElCLib::Value (-anEdgeLength, anEdgeLin); |
a6eb515f |
1388 | } |
af203d54 |
1389 | |
1390 | //======================================================================= |
1391 | //function : GetTextPositionForLinear |
1392 | //purpose : |
1393 | //======================================================================= |
1394 | gp_Pnt AIS_Dimension::GetTextPositionForLinear (const gp_Pnt& theFirstPoint, |
1395 | const gp_Pnt& theSecondPoint, |
1396 | const Standard_Boolean theIsOneSide) const |
1397 | { |
91b16a64 |
1398 | if (!IsValid()) |
af203d54 |
1399 | { |
1400 | return gp::Origin(); |
1401 | } |
1402 | |
1403 | gp_Pnt aTextPosition (gp::Origin()); |
1404 | |
1405 | Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect(); |
1406 | |
1407 | // Get label alignment and arrow orientation. |
1408 | Standard_Integer aLabelPosition = 0; |
1409 | Standard_Boolean isArrowsExternal = Standard_False; |
1410 | FitTextAlignmentForLinear (theFirstPoint, theSecondPoint, theIsOneSide, |
1411 | aDimensionAspect->TextHorizontalPosition(), |
1412 | aLabelPosition, isArrowsExternal); |
1413 | |
1414 | // Compute dimension line points. |
1415 | gp_Dir aPlaneNormal = GetPlane().Axis().Direction(); |
1416 | gp_Vec aTargetPointsVec (theFirstPoint, theSecondPoint); |
1417 | |
1418 | // Compute flyout direction vector |
1419 | gp_Dir aFlyoutVector = aPlaneNormal ^ gp_Dir (aTargetPointsVec); |
1420 | |
1421 | // create lines for layouts |
1422 | gp_Lin aLine1 (theFirstPoint, aFlyoutVector); |
1423 | gp_Lin aLine2 (theSecondPoint, aFlyoutVector); |
1424 | // Get flyout end points |
1425 | gp_Pnt aLineBegPoint = ElCLib::Value (ElCLib::Parameter (aLine1, theFirstPoint) + GetFlyout(), aLine1); |
1426 | gp_Pnt aLineEndPoint = ElCLib::Value (ElCLib::Parameter (aLine2, theSecondPoint) + GetFlyout(), aLine2); |
1427 | |
1428 | // Get text position. |
1429 | switch (aLabelPosition & LabelPosition_HMask) |
1430 | { |
1431 | case LabelPosition_Left: |
1432 | { |
1433 | gp_Dir aTargetPointsDir = gce_MakeDir (theFirstPoint, theSecondPoint); |
1434 | Standard_Real anExtensionSize = aDimensionAspect->ExtensionSize(); |
1435 | |
1436 | Standard_Real anOffset = isArrowsExternal |
1437 | ? anExtensionSize + aDimensionAspect->ArrowAspect()->Length() |
1438 | : anExtensionSize; |
1439 | gp_Vec anExtensionVec = gp_Vec (aTargetPointsDir) * -anOffset; |
1440 | aTextPosition = aLineEndPoint.Translated (anExtensionVec); |
1441 | } |
1442 | break; |
1443 | case LabelPosition_Right: |
1444 | { |
1445 | gp_Dir aTargetPointsDir = gce_MakeDir (theFirstPoint, theSecondPoint); |
1446 | Standard_Real anExtensionSize = aDimensionAspect->ExtensionSize(); |
1447 | |
1448 | Standard_Real anOffset = isArrowsExternal |
1449 | ? anExtensionSize + aDimensionAspect->ArrowAspect()->Length() |
1450 | : anExtensionSize; |
1451 | gp_Vec anExtensionVec = gp_Vec (aTargetPointsDir) * anOffset; |
1452 | aTextPosition = aLineBegPoint.Translated (anExtensionVec); |
1453 | } |
1454 | break; |
1455 | case LabelPosition_HCenter: |
1456 | { |
1457 | aTextPosition = (aLineBegPoint.XYZ() + aLineEndPoint.XYZ()) * 0.5; |
1458 | } |
1459 | break; |
1460 | } |
1461 | |
1462 | return aTextPosition; |
1463 | } |
1464 | |
1465 | //======================================================================= |
91b16a64 |
1466 | //function : AdjustParametersForLinear |
af203d54 |
1467 | //purpose : |
1468 | //======================================================================= |
91b16a64 |
1469 | Standard_Boolean AIS_Dimension::AdjustParametersForLinear (const gp_Pnt& theTextPos, |
1470 | const gp_Pnt& theFirstPoint, |
1471 | const gp_Pnt& theSecondPoint, |
1472 | Standard_Real& theExtensionSize, |
1473 | Prs3d_DimensionTextHorizontalPosition& theAlignment, |
1474 | Standard_Real& theFlyout, |
1475 | gp_Pln& thePlane, |
1476 | Standard_Boolean& theIsPlaneOld) const |
af203d54 |
1477 | { |
1478 | Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect(); |
1479 | Standard_Real anArrowLength = aDimensionAspect->ArrowAspect()->Length(); |
1480 | |
af203d54 |
1481 | gp_Dir aTargetPointsDir = gce_MakeDir (theFirstPoint, theSecondPoint); |
1482 | gp_Vec aTargetPointsVec (theFirstPoint, theSecondPoint); |
1483 | |
91b16a64 |
1484 | // Don't set new plane if the text position lies on the attachment points line. |
1485 | gp_Lin aTargetPointsLin (theFirstPoint, aTargetPointsDir); |
1486 | if (!aTargetPointsLin.Contains (theTextPos, Precision::Confusion())) |
1487 | { |
1488 | //Set new automatic plane. |
1489 | thePlane = gce_MakePln (theTextPos, theFirstPoint, theSecondPoint); |
1490 | theIsPlaneOld = Standard_False; |
1491 | } |
1492 | |
af203d54 |
1493 | // Compute flyout direction vector. |
91b16a64 |
1494 | gp_Dir aPlaneNormal = GetPlane().Axis().Direction(); |
af203d54 |
1495 | gp_Dir aPositiveFlyout = aPlaneNormal ^ aTargetPointsDir; |
1496 | |
91b16a64 |
1497 | // Additional check of collinearity of the plane normal and attachment points vector. |
1498 | if (aPlaneNormal.IsParallel (aTargetPointsDir, Precision::Angular())) |
1499 | { |
1500 | return Standard_False; |
1501 | } |
1502 | |
af203d54 |
1503 | // Set flyout. |
1504 | gp_Vec aFirstToTextVec (theFirstPoint, theTextPos); |
1505 | |
1506 | Standard_Real aCos = aFirstToTextVec.Normalized() * gp_Vec (aTargetPointsDir); |
1507 | |
1508 | gp_Pnt aTextPosProj = theFirstPoint.Translated |
1509 | (gp_Vec (aTargetPointsDir) * aFirstToTextVec.Magnitude() * aCos); |
1510 | |
1511 | // Compute flyout value and direction. |
1512 | gp_Vec aFlyoutVector = gp_Vec (aTextPosProj, theTextPos); |
1513 | |
91b16a64 |
1514 | theFlyout = 0.0; |
1515 | if (aFlyoutVector.Magnitude() > Precision::Confusion()) |
1516 | { |
1517 | theFlyout = gp_Dir (aFlyoutVector).IsOpposite (aPositiveFlyout, Precision::Angular()) |
1518 | ? -aFlyoutVector.Magnitude() |
1519 | : aFlyoutVector.Magnitude(); |
1520 | } |
1521 | |
af203d54 |
1522 | // Compute attach points (through which main dimension line passes). |
1523 | gp_Pnt aFirstAttach = theFirstPoint.Translated (aFlyoutVector); |
1524 | gp_Pnt aSecondAttach = theSecondPoint.Translated (aFlyoutVector); |
1525 | |
91b16a64 |
1526 | // Set horizontal text alignment. |
af203d54 |
1527 | if (aCos < 0.0) |
1528 | { |
1529 | theAlignment = Prs3d_DTHP_Left; |
1530 | |
1531 | Standard_Real aNewExtSize = theTextPos.Distance (aFirstAttach) - anArrowLength; |
1532 | theExtensionSize = aNewExtSize < 0.0 ? 0.0 : aNewExtSize; |
1533 | } |
1534 | else if (aTextPosProj.Distance (theFirstPoint) > theFirstPoint.Distance (theSecondPoint)) |
1535 | { |
1536 | theAlignment = Prs3d_DTHP_Right; |
1537 | |
1538 | Standard_Real aNewExtSize = theTextPos.Distance (aSecondAttach) - anArrowLength; |
1539 | theExtensionSize = aNewExtSize < 0.0 ? 0.0 : aNewExtSize; |
1540 | } |
1541 | else |
1542 | { |
1543 | theAlignment = Prs3d_DTHP_Center; |
1544 | } |
91b16a64 |
1545 | return Standard_True; |
af203d54 |
1546 | } |
1547 | |
1548 | //======================================================================= |
1549 | //function : FitTextAlignmentForLinear |
1550 | //purpose : |
1551 | //======================================================================= |
1552 | void AIS_Dimension::FitTextAlignmentForLinear (const gp_Pnt& theFirstPoint, |
1553 | const gp_Pnt& theSecondPoint, |
1554 | const Standard_Boolean theIsOneSide, |
1555 | const Prs3d_DimensionTextHorizontalPosition& theHorizontalTextPos, |
1556 | Standard_Integer& theLabelPosition, |
1557 | Standard_Boolean& theIsArrowsExternal) const |
1558 | { |
1559 | theLabelPosition = LabelPosition_None; |
1560 | theIsArrowsExternal = Standard_False; |
1561 | |
1562 | // Compute dimension line points |
1563 | gp_Ax1 aPlaneNormal = GetPlane().Axis(); |
1564 | gp_Dir aTargetPointsVector = gce_MakeDir (theFirstPoint, theSecondPoint); |
1565 | |
1566 | // compute flyout direction vector |
1567 | gp_Dir aFlyoutVector = aPlaneNormal.Direction() ^ aTargetPointsVector; |
1568 | |
1569 | // create lines for layouts |
1570 | gp_Lin aLine1 (theFirstPoint, aFlyoutVector); |
1571 | gp_Lin aLine2 (theSecondPoint, aFlyoutVector); |
1572 | |
1573 | // Get flyout end points |
1574 | gp_Pnt aLineBegPoint = ElCLib::Value (ElCLib::Parameter (aLine1, theFirstPoint) + GetFlyout(), aLine1); |
1575 | gp_Pnt aLineEndPoint = ElCLib::Value (ElCLib::Parameter (aLine2, theSecondPoint) + GetFlyout(), aLine2); |
1576 | |
1577 | Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect(); |
1578 | |
af203d54 |
1579 | // For extensions we need to know arrow size, text size and extension size: get it from aspect |
1580 | Quantity_Length anArrowLength = aDimensionAspect->ArrowAspect()->Length(); |
1581 | |
1582 | // prepare label string and compute its geometrical width |
1583 | Standard_Real aLabelWidth; |
1584 | TCollection_ExtendedString aLabelString = GetValueString (aLabelWidth); |
1585 | |
1586 | // Add margins to cut dimension lines for 3d text |
1587 | if (aDimensionAspect->IsText3d()) |
1588 | { |
1589 | aLabelWidth += aDimensionAspect->TextAspect()->Height() * THE_3D_TEXT_MARGIN * 2.0; |
1590 | } |
1591 | |
1592 | // Handle user-defined and automatic arrow placement |
1593 | switch (aDimensionAspect->ArrowOrientation()) |
1594 | { |
1595 | case Prs3d_DAO_External: theIsArrowsExternal = true; break; |
1596 | case Prs3d_DAO_Internal: theIsArrowsExternal = false; break; |
1597 | case Prs3d_DAO_Fit: |
1598 | { |
1599 | // Add margin to ensure a small tail between text and arrow |
1600 | Standard_Real anArrowMargin = aDimensionAspect->IsText3d() |
1601 | ? aDimensionAspect->TextAspect()->Height() * THE_3D_TEXT_MARGIN |
1602 | : 0.0; |
1603 | |
1604 | Standard_Real aDimensionWidth = aLineBegPoint.Distance (aLineEndPoint); |
1605 | Standard_Real anArrowsWidth = theIsOneSide |
1606 | ? anArrowLength + anArrowMargin |
1607 | : (anArrowLength + anArrowMargin) * 2.0; |
1608 | |
1609 | theIsArrowsExternal = aDimensionWidth < aLabelWidth + anArrowsWidth; |
1610 | break; |
1611 | } |
1612 | } |
1613 | |
1614 | // Handle user-defined and automatic text placement |
1615 | switch (theHorizontalTextPos) |
1616 | { |
1617 | case Prs3d_DTHP_Left : theLabelPosition |= LabelPosition_Left; break; |
1618 | case Prs3d_DTHP_Right : theLabelPosition |= LabelPosition_Right; break; |
1619 | case Prs3d_DTHP_Center: theLabelPosition |= LabelPosition_HCenter; break; |
1620 | case Prs3d_DTHP_Fit: |
1621 | { |
1622 | Standard_Real aDimensionWidth = aLineBegPoint.Distance (aLineEndPoint); |
1623 | Standard_Real anArrowsWidth = theIsOneSide ? anArrowLength : 2.0 * anArrowLength; |
1624 | Standard_Real aContentWidth = theIsArrowsExternal ? aLabelWidth : aLabelWidth + anArrowsWidth; |
1625 | |
1626 | theLabelPosition |= aDimensionWidth < aContentWidth ? LabelPosition_Left : LabelPosition_HCenter; |
1627 | break; |
1628 | } |
1629 | } |
1630 | |
1631 | // Handle vertical text placement options |
1632 | switch (aDimensionAspect->TextVerticalPosition()) |
1633 | { |
1634 | case Prs3d_DTVP_Above : theLabelPosition |= LabelPosition_Above; break; |
1635 | case Prs3d_DTVP_Below : theLabelPosition |= LabelPosition_Below; break; |
1636 | case Prs3d_DTVP_Center : theLabelPosition |= LabelPosition_VCenter; break; |
1637 | } |
1638 | } |
1639 | |
1640 | //======================================================================= |
1641 | //function : UnsetFixedTextPosition |
1642 | //purpose : |
1643 | //======================================================================= |
1644 | void AIS_Dimension::UnsetFixedTextPosition() |
1645 | { |
1646 | myIsTextPositionFixed = Standard_False; |
1647 | myFixedTextPosition = gp::Origin(); |
1648 | } |