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