03ad7d01b1107e8cbcc46c3f46a24c79cd44dd67
[occt.git] / src / AIS / AIS_Dimension.hxx
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 #ifndef _AIS_Dimension_HeaderFile
17 #define _AIS_Dimension_HeaderFile
18
19 #include <AIS_DimensionSelectionMode.hxx>
20 #include <AIS_DimensionOwner.hxx>
21 #include <AIS_DisplaySpecialSymbol.hxx>
22 #include <AIS_InteractiveObject.hxx>
23 #include <AIS_KindOfInteractive.hxx>
24 #include <AIS_KindOfDimension.hxx>
25 #include <AIS_KindOfSurface.hxx>
26 #include <Geom_Curve.hxx>
27 #include <gp_Pln.hxx>
28 #include <Prs3d_ArrowAspect.hxx>
29 #include <Prs3d_DimensionAspect.hxx>
30 #include <Prs3d_DimensionUnits.hxx>
31 #include <Prs3d_Drawer.hxx>
32 #include <Prs3d_LineAspect.hxx>
33 #include <Prs3d_Presentation.hxx>
34 #include <Prs3d_TextAspect.hxx>
35 #include <Select3D_ListOfSensitive.hxx>
36 #include <SelectMgr_EntityOwner.hxx>
37 #include <Standard.hxx>
38 #include <TCollection_ExtendedString.hxx>
39 #include <TColgp_HSequenceOfPnt.hxx>
40 #include <TopoDS_Edge.hxx>
41 #include <TopoDS_Face.hxx>
42 #include <TopoDS_Shape.hxx>
43 #include <NCollection_Sequence.hxx>
44 #include <NCollection_Handle.hxx>
45
46 DEFINE_STANDARD_HANDLE(AIS_Dimension, AIS_InteractiveObject)
47
48 //! AIS_Dimension is a base class for 2D presentations of linear (length, diameter, radius)
49 //! and angular dimensions.
50 //!
51 //! The dimensions provide measurement of quantities, such as lengths or plane angles.
52 //! The measurement of dimension "value" is done in model space "as is".
53 //! These "value" are said to be represented in "model units", which can be specified by user.
54 //! During the display the measured value converted from "model units" to "display units".
55 //! The display and model units are stored in common Prs3d_Drawer (drawer of the context)
56 //! to share it between all dimensions.
57 //! The specified by user units are stored in the dimension's drawer.
58 //!
59 //! As a drawing, the dimension is composed from the following components:
60 //! - Attachment (binding) points. The points where the dimension lines attaches to, for
61 //!   length dimensions the distances are measured between these points.
62 //! - Main dimension line. The which extends from the attachment points in "up" direction,
63 //!   and which contains text label on it with value string.
64 //! - Flyouts. The lines connecting the attachment points with main dimension line.
65 //! - Extension. The lines used to extend the main dimension line in the cases when text
66 //!   or arrows do not fit into the main dimension line due to their size.
67 //! - Arrows.
68 //!
69 //! <pre>
70 //!  Linear dimensions:
71 //!
72 //!  extension
73 //!   line                                     arrow
74 //!       -->|------- main dimension line -------|<--
75 //!          |                                   |
76 //!          |flyout                       flyout|
77 //!          |                                   |
78 //!          +-----------------------------------+
79 //! attachment                                attachment
80 //!  point                                       point
81 //!
82 //!  Angular dimensions:
83 //!
84 //!                  extension
85 //!                     line
86 //!                        -->|+++++
87 //!                     arrow |     +++
88 //!                           |        90(deg) - main dimension line
89 //!                    flyout |         +++
90 //!                           |           +
91 //!                           o---flyout---
92 //!                         center         ^ 
93 //!                         point          | extension
94 //!                                          line
95 //! </pre>
96 //!
97 //! Being a 2D drawings, the dimensions are created on imaginary plane, called "dimension plane",
98 //! which can be thought of as reference system of axes (X,Y,N) for constructing the presentation.
99 //!
100 //! The role of axes of the dimension plane is to guide you through the encapsualted automations
101 //! of presentation building to help you understand how is the presentation will look and how it
102 //! will be oriented in model space during construction.
103 //! 
104 //! Orientation of dimension line in model space relatively to the base shapes is defined 
105 //! with the flyouts. Flyouts specify length of flyout lines and their orientation relatively
106 //! to the attachment points on the working plane.
107 //! For linear dimensions: 
108 //!   Direction of flyouts is specified with direction of main dimension line
109 //!   (vector from the first attachment to the second attachment) and the normal of the dimension plane.
110 //!   Positive direction of flyouts is defined by vector multiplication: AttachVector * PlaneNormal.
111 //! For angular dimensions:
112 //!   Flyouts are defined by vectors from the center point to the attachment points.
113 //!   These vectors directions are supposed to be the positive directions of flyouts.
114 //!   Negative flyouts directions means that these vectors should be reversed
115 //!   (and dimension will be built out of the angle constructed with center and two attach points).
116 //!
117 //! The dimension plane can be constructed automatically by application (where possible,
118 //! it depends on the measured geometry).
119 //! It can be also set by user. However, if the user-defined plane does not fit the
120 //! geometry of the dimension (attach points do not belong to it), the dimension could not
121 //! be built.
122 //! If it is not possible to compute automatic plane (for example, in case of length between 
123 //! two points) the user is supposed to specify the custom plane.
124 //!
125 //! Since the dimensions feature automated construction procedures from an arbitrary shapes,
126 //! the interfaces to check the validness are also implemented. Once the measured geometry is
127 //! specified, the one can inquire the validness status by calling "IsValid()" method. If the result
128 //! is TRUE, then all of public parameters should be pre-computed and ready. The presentation
129 //! should be also computable. Otherwise, the parameters may return invalid values. In this case,
130 //! the presentation will not be computed and displayed.
131 //! 
132 //! The dimension support two local selection modes: main dimension line selection and text label
133 //! selection. These modes can be used to develop interactive modification of dimension presentations.
134 //! The component highlighting in these selection modes is provided by AIS_DimensionOwner class.
135 //! Please note that selection is unavailable until the presentation is computed.
136 //! 
137 //! The specific drawing attributes are controlled through Prs3d_DimensionAspect. The one can change
138 //! color, arrows, text and arrow style and specify positioning of value label by setting corresponding
139 //! values to the aspect.
140 //!
141 //! Such set of parameters that consists of:
142 //! - flyout size and direction,
143 //! - user-defined  dimension plane,
144 //! - horizontal and vertical text alignment
145 //! can be uniquely replaced with text position in 3d space. Therefore, there are methods to convert
146 //! this set of parameters to the text position and vice versa:
147 //!
148 //! - If the fixed text position is defined by user, called SetTextPosition (theTextPos) method converts
149 //! this 3d point to the set of parameters including adjusting of the dimension plane (this plane will be
150 //! automatic plane, NOT user-defined one).
151 //! If the fixed text position is set, the flag myIsFixedTextPosition is set to TRUE.
152 //! ATTENSION! myIsFixedTextPosition fixes all parameters of the set from recomputing inside
153 //! SetMeasureGeometry() methods. Parameters in dimension aspect (they are horizontal text position
154 //! and extension size) are adjusted on presentation computing step, user-defined values in
155 //! dimension aspect are not changed.
156 //! But plane and flyout as dimension position parameters are changed by SetTextPosition() method
157 //! according with user-defined text position.
158 //! If parameters from the set are changed by user with calls of setters, it leads to disabling of
159 //! fixed text position (myIsFixedTextPosition is set to FALSE).
160 //! If the fixed text position is set and geometry is changed by user (SetMeasureGeometry() method
161 //! is called) and the geometry doesn't satisfy computed dimension plane, the dimension is not valid.
162 //!
163 //! - If the set of parameters was set by user (may be without the user-defined plane or with it),
164 //! it can be converted to the text position by calling the method GetTextPosition(). In this case
165 //! the text position is NOT fixed, and SetMeasureGeometry() without user-defined plane adjusts
166 //! the automatic plane according input geometry (if it is possible).
167 //!
168 class AIS_Dimension : public AIS_InteractiveObject
169 {
170 protected:
171
172   //! Geometry type defines type of shapes on which the dimension is to be built.
173   //! Some type of geometry allows automatic plane computing and
174   //! can be built without user-defined plane
175   //! Another types can't be built without user-defined plane.
176   enum GeometryType
177   {
178     GeometryType_UndefShapes,
179     GeometryType_Edge,
180     GeometryType_Face,
181     GeometryType_Points,
182     GeometryType_Edges,
183     GeometryType_Faces,
184     GeometryType_EdgeFace,
185     GeometryType_EdgeVertex
186   };
187
188   //! Specifies supported at base level horizontal and vertical
189   //! label positions for drawing extension lines and centered text.
190   enum LabelPosition
191   {
192     LabelPosition_None    = 0x00,
193
194     LabelPosition_Left    = 0x01,
195     LabelPosition_Right   = 0x02,
196     LabelPosition_HCenter = 0x04,
197     LabelPosition_HMask   = LabelPosition_Left | LabelPosition_Right | LabelPosition_HCenter,
198
199     LabelPosition_Above   = 0x10,
200     LabelPosition_Below   = 0x20,
201     LabelPosition_VCenter = 0x40,
202     LabelPosition_VMask   = LabelPosition_Above | LabelPosition_Below | LabelPosition_VCenter
203   };
204
205 public:
206
207   //! Specifies supported presentation compute modes.
208   //! Used to compute only parts of presentation for
209   //! advanced highlighting.
210   enum ComputeMode
211   {
212     ComputeMode_All  = 0, //!< "0" is reserved as neutral mode
213     ComputeMode_Line = 1, //!< corresponds to selection mode
214     ComputeMode_Text = 2  //!< corresponds to selection mode
215   };
216
217 public:
218
219   //! Constructor with default parameters values.
220   //! @param theType [in] the type of dimension.
221   Standard_EXPORT AIS_Dimension (const AIS_KindOfDimension theType);
222
223   //! Gets dimension measurement value. If the value to display is not
224   //! specified by user, then the dimension object is responsible to
225   //! compute it on its own in model space coordinates.
226   //! @return the dimension value (in model units) which is used
227   //! during display of the presentation.
228   Standard_Real GetValue() const
229   {
230     return myIsValueCustom ? myCustomValue : ComputeValue();
231   }
232
233   //! Sets user-defined dimension value.
234   //! The user-defined dimension value is specified in model space,
235   //! and affect by unit conversion during the display.
236   //! @param theValue [in] the user-defined value to display.
237   Standard_EXPORT void SetCustomValue (const Standard_Real theValue);
238
239   //! Get the dimension plane in which the 2D dimension presentation is computed.
240   //! By default, if plane is not defined by user, it is computed automatically
241   //! after dimension geometry is computed.
242   //! If computed dimension geometry (points) can't be placed on the user-defined
243   //! plane, dimension geometry was set as invalid (validity flag is set to false)
244   //! and dimension presentation will not be computed.
245   //! If user-defined plane allow geometry placement on it, it will be used for
246   //! computing of the dimension presentation.
247   //! @return dimension plane used for presentation computing.
248   Standard_EXPORT const gp_Pln& GetPlane() const;
249
250   //! Geometry type defines type of shapes on which the dimension is to be built. 
251   //! @return type of geometry on which the dimension will be built.
252   Standard_EXPORT const Standard_Integer GetGeometryType () const;
253
254   //! Sets user-defined plane where the 2D dimension presentation will be placed.
255   //! Checks validity of this plane if geometry has been set already.
256   //! Validity of the plane is checked according to the geometry set
257   //! and has different criteria for different kinds of dimensions.
258   Standard_EXPORT virtual void SetCustomPlane (const gp_Pln& thePlane);
259
260   //! Unsets user-defined plane. Therefore the plane for dimension will be
261   //! computed automatically.
262   Standard_EXPORT void UnsetCustomPlane() { myIsPlaneCustom = Standard_False; }
263
264   //! @return TRUE if text position is set by user with method SetTextPosition().
265   Standard_Boolean IsTextPositionCustom() const
266   {
267     return myIsTextPositionFixed;
268   }
269
270   //! Fixes the absolute text position and adjusts flyout, plane and text alignment
271   //! according to it. Updates presentation if the text position is valid.
272   //! ATTENTION! It does not change vertical text alignment.
273   //! @param theTextPos [in] the point of text position.
274   virtual void SetTextPosition (const gp_Pnt& /*theTextPos*/) { }
275
276   //! Computes absolute text position from dimension parameters
277   //! (flyout, plane and text alignment).
278   virtual const gp_Pnt GetTextPosition () const { return gp_Pnt(); }
279
280 public:
281
282   //! Gets the dimension aspect from AIS object drawer.
283   //! Dimension aspect contains aspects of line, text and arrows for dimension presentation.
284   Handle(Prs3d_DimensionAspect) DimensionAspect() const
285   {
286     return myDrawer->DimensionAspect();
287   }
288
289   //! Sets new dimension aspect for the interactive object drawer.
290   //! The dimension aspect provides dynamic properties which are generally
291   //! used during computation of dimension presentations.
292   Standard_EXPORT void SetDimensionAspect (const Handle(Prs3d_DimensionAspect)& theDimensionAspect);
293
294   //! @return the kind of dimension.
295   AIS_KindOfDimension KindOfDimension() const
296   {
297     return myKindOfDimension;
298   }
299
300   //! @return the kind of interactive.
301   virtual AIS_KindOfInteractive Type() const
302   {
303     return AIS_KOI_Dimension;
304   }
305
306   //! Returns true if the class of objects accepts the display mode theMode.
307   //! The interactive context can have a default mode of representation for
308   //! the set of Interactive Objects. This mode may not be accepted by object.
309   virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const
310   {
311     return theMode == ComputeMode_All;
312   }
313
314 public:
315
316   //! @return dimension special symbol display options.
317   AIS_DisplaySpecialSymbol DisplaySpecialSymbol() const
318   {
319     return myDisplaySpecialSymbol;
320   }
321
322   //! Specifies whether to display special symbol or not.
323   Standard_EXPORT void SetDisplaySpecialSymbol (const AIS_DisplaySpecialSymbol theDisplaySpecSymbol);
324
325   //! @return special symbol.
326   Standard_ExtCharacter SpecialSymbol() const
327   {
328     return mySpecialSymbol;
329   }
330
331   //! Specifies special symbol.
332   Standard_EXPORT void SetSpecialSymbol (const Standard_ExtCharacter theSpecialSymbol);
333
334   Standard_EXPORT virtual const TCollection_AsciiString& GetDisplayUnits() const;
335
336   Standard_EXPORT virtual const TCollection_AsciiString& GetModelUnits() const;
337
338   Standard_EXPORT virtual void SetDisplayUnits (const TCollection_AsciiString& /*theUnits*/) { }
339
340   Standard_EXPORT virtual void SetModelUnits (const TCollection_AsciiString& /*theUnits*/) { }
341
342   //! Unsets user defined text positioning and enables text positioning
343   //!  by other parameters: text alignment, extension size, flyout and custom plane.
344   Standard_EXPORT void UnsetFixedTextPosition();
345
346 public:
347
348   //! Returns selection tolerance for text2d:
349   //! For 2d text selection detection sensitive point with tolerance is used
350   //! Important! Only for 2d text.
351   Standard_Real SelToleranceForText2d() const
352   {
353     return mySelToleranceForText2d;
354   }
355
356   //! Sets selection tolerance for text2d:
357   //! For 2d text selection detection sensitive point with tolerance is used
358   //! to change this tolerance use this method
359   //! Important! Only for 2d text.
360   Standard_EXPORT void SetSelToleranceForText2d (const Standard_Real theTol);
361
362   //! @return flyout value for dimension.
363   Standard_Real GetFlyout() const
364   {
365     return myFlyout;
366   }
367
368   //! Sets flyout value for dimension.
369   Standard_EXPORT void SetFlyout (const Standard_Real theFlyout);
370
371   //! Check that the input geometry for dimension is valid and the
372   //! presentation can be successfully computed.
373   //! @return TRUE if dimension geometry is ok.
374   virtual Standard_Boolean IsValid() const
375   {
376     return myIsGeometryValid && CheckPlane (GetPlane());
377   }
378
379 public:
380
381   DEFINE_STANDARD_RTTI(AIS_Dimension)
382
383 protected:
384
385   Standard_EXPORT Standard_Real ValueToDisplayUnits() const;
386
387   //! Get formatted value string and its model space width.
388   //! @param theWidth [out] the model space with of the string.
389   //! @return formatted dimension value string.
390   Standard_EXPORT TCollection_ExtendedString GetValueString (Standard_Real& theWidth) const;
391
392   //! Performs drawing of 2d or 3d arrows on the working plane
393   //! @param theLocation [in] the location of the arrow tip.
394   //! @param theDirection [in] the direction from the tip to the bottom of the arrow.
395   Standard_EXPORT void DrawArrow (const Handle(Prs3d_Presentation)& thePresentation,
396                                   const gp_Pnt& theLocation,
397                                   const gp_Dir& theDirection);
398
399   //! Performs drawing of 2d or 3d text on the working plane
400   //! @param theTextPos [in] the position of the text label.
401   //! @param theTestDir [in] the direction of the text label.
402   //! @param theText [in] the text label string.
403   //! @param theLabelPosition [in] the text label vertical and horizontal positioning option
404   //! respectively to the main dimension line. 
405   //! @return text width relative to the dimension working plane. For 2d text this value will be zero.
406   Standard_EXPORT void 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   //! Performs computing of dimension linear extension with text
413   //! @param thePresentation [in] the presentation to fill with graphical primitives.
414   //! @param theExtensionSize [in] the size of extension line.
415   //! @param theExtensionStart [in] the point where extension line connects to dimension.
416   //! @param theExtensionDir [in] the direction of extension line.
417   //! @param theLabelString [in] the string with value.
418   //! @param theLabelWidth [in] the geometrical width computed for value string.
419   //! @param theMode [in] the display mode.
420   //! @param theLabelPosition [in] position flags for the text label.
421   Standard_EXPORT void DrawExtension (const Handle(Prs3d_Presentation)& thePresentation,
422                                       const Standard_Real theExtensionSize,
423                                       const gp_Pnt& theExtensionStart,
424                                       const gp_Dir& theExtensionDir,
425                                       const TCollection_ExtendedString& theLabelString,
426                                       const Standard_Real theLabelWidth,
427                                       const Standard_Integer theMode,
428                                       const Standard_Integer theLabelPosition);
429
430   //! Performs computing of linear dimension (for length, diameter, radius and so on).
431   //! Please note that this method uses base dimension properties, like working plane
432   //! flyout length, drawer attributes.
433   //! @param thePresentation [in] the presentation to fill with primitives.
434   //! @param theMode [in] the presentation compute mode.
435   //! @param theFirstPoint [in] the first attach point of linear dimension.
436   //! @param theSecondPoint [in] the second attach point of linear dimension.
437   //! @param theIsOneSide [in] specifies whether the dimension has only one flyout line.
438   Standard_EXPORT void DrawLinearDimension (const Handle(Prs3d_Presentation)& thePresentation,
439                                             const Standard_Integer theMode,
440                                             const gp_Pnt& theFirstPoint,
441                                             const gp_Pnt& theSecondPoint,
442                                             const Standard_Boolean theIsOneSide = Standard_False);
443
444   //! Compute selection sensitives for linear dimension flyout lines (length, diameter, radius).
445   //! Please note that this method uses base dimension properties: working plane and flyout length.
446   //! @param theSelection [in] the selection structure to fill with selection primitives.
447   //! @param theOwner [in] the selection entity owner.
448   //! @param theFirstPoint [in] the first attach point of linear dimension.
449   //! @param theSecondPoint [in] the second attach point of linear dimension.
450   Standard_EXPORT void ComputeLinearFlyouts (const Handle(SelectMgr_Selection)& theSelection,
451                                              const Handle(SelectMgr_EntityOwner)& theOwner,
452                                              const gp_Pnt& theFirstPoint,
453                                              const gp_Pnt& theSecondPoint);
454
455
456   //! Performs initialization of circle and middle arc point from the passed
457   //! shape which is assumed to contain circular geometry.
458   //! @param theShape [in] the shape to explore.
459   //! @param theCircle [out] the circle geometry.
460   //! @param theMiddleArcPoint [out] the middle point of the arc.
461   //! @param theIsClosed [out] returns TRUE if the geometry is closed circle.
462   //! @return TRUE if the the circle is successfully got from the input shape.
463   Standard_EXPORT Standard_Boolean InitCircularDimension (const TopoDS_Shape& theShape,
464                                                           gp_Circ& theCircle,
465                                                           gp_Pnt& theMiddleArcPoint,
466                                                           Standard_Boolean& theIsClosed);
467  
468   //! Produce points for triangular arrow face.
469   //! @param thePeakPnt [in] the arrow peak position.
470   //! @param theDirection [in] the arrow direction.
471   //! @param thePlane [in] the face plane.
472   //! @param theArrowLength [in] the length of arrow.
473   //! @param theArrowAngle [in] the angle of arrow.
474   //! @param theSidePnt1 [out] the first side point.
475   //! @param theSidePnt2 [out] the second side point.
476   Standard_EXPORT void PointsForArrow (const gp_Pnt& thePeakPnt,
477                                        const gp_Dir& theDirection,
478                                        const gp_Dir& thePlane,
479                                        const Standard_Real theArrowLength,
480                                        const Standard_Real theArrowAngle,
481                                        gp_Pnt& theSidePnt1,
482                                        gp_Pnt& theSidePnt2);
483
484   //! Compute point of text position for dimension parameters
485   //! for linear kinds of dimensions (length, radius, diameter).
486   Standard_EXPORT gp_Pnt GetTextPositionForLinear (const gp_Pnt& theFirstPoint,
487                                                    const gp_Pnt& theSecondPoint,
488                                                    const Standard_Boolean theIsOneSide = Standard_False) const;
489
490   //! Fits text alignment relatively to the dimension line.
491   //! @param theFirstPoint [in] the first attachment point.
492   //! @param theSecondPoint [in] the second attachment point.
493   //! @param theIsOneSide [in] is the arrow displayed only on the one side of the dimension.
494   //! @param theHorizontalTextPos [in] the text horizontal position (alignment).
495   //! @param theLabelPosition [out] the label position, contains bits that defines
496   //! vertical and horizontal alignment. (for internal usage in count text position)
497   //! @param theIsArrowExternal [out] is the arrows external,
498   //! if arrow orientation in the dimension aspect is Prs3d_DAO_Fit, it fits arrow
499   //! orientation automatically.
500   Standard_EXPORT void FitTextAlignmentForLinear (const gp_Pnt& theFirstPoint,
501                                                   const gp_Pnt& theSecondPoint,
502                                                   const Standard_Boolean theIsOneSide,
503                                                   const Prs3d_DimensionTextHorizontalPosition& theHorizontalTextPos,
504                                                   Standard_Integer& theLabelPosition,
505                                                   Standard_Boolean& theIsArrowsExternal) const;
506
507   //! Adjusts aspect parameters according the text position:
508   //! extension size, vertical text alignment and flyout.
509   //! @param theTextPos [in] the user defined 3d point of text position
510   //! @param theFirstPoint [in] the first point of linear measurement.
511   //! @param theSecondPoint [in] the second point of linear measurement.
512   //! @param theExtensionSize [out] the adjusted extension size
513   //! @param theAlignment [out] the horizontal label alignment.
514   //! @param theFlyout [out] the adjusted value of flyout.
515   //! @param thePlane [out] the new plane that contains theTextPos and attachment points.
516   //! @param theIsPlaneOld [out] shows if new plane is computed.
517   Standard_EXPORT Standard_Boolean AdjustParametersForLinear (const gp_Pnt& theTextPos,
518                                                               const gp_Pnt& theFirstPoint,
519                                                               const gp_Pnt& theSecondPoint,
520                                                               Standard_Real& theExtensionSize,
521                                                               Prs3d_DimensionTextHorizontalPosition& theAlignment,
522                                                               Standard_Real& theFlyout,
523                                                               gp_Pln& thePlane,
524                                                               Standard_Boolean& theIsPlaneOld) const;
525
526 protected: //! @name Static auxilliary methods for geometry extraction
527
528   //! If it is possible extracts circle from planar face.
529   //! @param theFace        [in] the planar face
530   //! @param theCurve       [out] the circular curve
531   //! @param theFirstPoint  [out] the point of the first parameter of the circlular curve
532   //! @param theSecondPoint [out] the point of the last parameter of the circlular curve
533   //! @return TRUE in case of successful circle extraction
534   static Standard_Boolean CircleFromPlanarFace (const TopoDS_Face&  theFace,
535                                                 Handle(Geom_Curve)& theCurve,
536                                                 gp_Pnt&             theFirstPoint,
537                                                 gp_Pnt&             theLastPoint);
538
539   //! If it is possible extracts circle from the edge.
540   //! @param theEdge        [in] input edge to extract circle from
541   //! @param theCircle      [out] circle
542   //! @param theFirstPoint  [out] the point of the first parameter of the circlular curve
543   //! @param theSecondPoint [out] the point of the last parameter of the circlular curve
544   //! @return TRUE in case of successful circle extraction.
545   static Standard_Boolean CircleFromEdge (const TopoDS_Edge& theEdge,
546                                           gp_Circ&           theCircle,
547                                           gp_Pnt&            theFirstPoint,
548                                           gp_Pnt&            theLastPoint);
549
550 protected: //! @name Behavior to implement
551
552   //! Override this method to compute automatically dimension plane
553   //! in which the dimension presentation is built.
554   virtual void ComputePlane() { }
555
556   //! Override this method to check if user-defined plane
557   //! is valid for the dimension geometry.
558   //! @param thePlane [in] the working plane for positioning every
559   //! dimension in the application.
560   //! @return true is the plane is suitable for building dimension
561   //! with computed dimension geometry.
562   virtual Standard_Boolean CheckPlane (const gp_Pln& /*thePlane*/) const { return Standard_True; }
563
564   //! Override this method to computed value of dimension.
565   //! @return value from the measured geometry.
566   virtual Standard_Real ComputeValue() const 
567   {
568     return 0.0;
569   }
570
571   //! Override this method to compute selection primitives for
572   //! flyout lines (if the dimension provides it).
573   //! This callback is a only a part of base selection
574   //! computation routine.
575   virtual void ComputeFlyoutSelection (const Handle(SelectMgr_Selection)&,
576                                        const Handle(SelectMgr_EntityOwner)&) {}
577
578
579   //! Base procedure of computing selection (based on selection geometry data).
580   //! @param theSelection [in] the selection structure to will with primitives.
581   //! @param theMode [in] the selection mode.
582   Standard_EXPORT virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
583                                                  const Standard_Integer theMode);
584
585 protected: //! @name Selection geometry
586
587   //! Selection geometry of dimension presentation. The structure is filled with data
588   //! during compute of presentation, then this data is used to generate selection
589   //! sensitives when computing selection.
590   struct SelectionGeometry
591   {
592     //! Arrows are represented by directed triangles.
593     struct Arrow
594     {
595       gp_Pnt Position;
596       gp_Dir Direction;
597     };
598     typedef NCollection_Sequence<gp_Pnt> Curve;
599     typedef NCollection_Handle<Curve>    HCurve;
600     typedef NCollection_Handle<Arrow>    HArrow;
601     typedef NCollection_Sequence<HCurve> SeqOfCurves;
602     typedef NCollection_Sequence<HArrow> SeqOfArrows;
603
604     gp_Pnt           TextPos;            //!< Center of text label.
605     gp_Dir           TextDir;            //!< Direction of text label.
606     Standard_Real    TextWidth;          //!< Width of text label.
607     Standard_Real    TextHeight;         //!< Height of text label.
608     SeqOfCurves      DimensionLine;      //!< Sequence of points for composing the segments of dimension line.
609     SeqOfArrows      Arrows;             //!< Sequence of arrow geometries.
610     Standard_Boolean IsComputed;         //!< Shows if the selection geometry was filled.
611
612   public:
613
614     //! Clear geometry of sensitives for the specified compute mode.
615     //! @param theMode [in] the compute mode to clear.
616     void Clear (const Standard_Integer theMode)
617     {
618       if (theMode == ComputeMode_All || theMode == ComputeMode_Line)
619       {
620         DimensionLine.Clear();
621         Arrows.Clear();
622       }
623
624       if (theMode == ComputeMode_All || theMode == ComputeMode_Text)
625       {
626         TextPos    = gp::Origin();
627         TextDir    = gp::DX();
628         TextWidth  = 0.0;
629         TextHeight = 0.0;
630       }
631
632       IsComputed = Standard_False;
633     }
634
635     //! Add new curve entry and return the reference to populate it.
636     Curve& NewCurve()
637     {
638       DimensionLine.Append( new Curve );
639       HCurve& aLastCurve = DimensionLine.ChangeLast();
640       return *aLastCurve;
641     }
642
643     //! Add new arrow entry and return the reference to populate it.
644     Arrow& NewArrow()
645     {
646       Arrows.Append( new Arrow );
647       HArrow& aLastArrow = Arrows.ChangeLast();
648       return *aLastArrow;
649     }
650   } mySelectionGeom;
651
652   Standard_Real mySelToleranceForText2d; //!< Sensitive point tolerance for 2d text selection.
653
654 protected: //! @name Value properties
655
656   Standard_Real    myCustomValue;   //!< Value of the dimension (computed or user-defined).
657   Standard_Boolean myIsValueCustom; //!< Is user-defined value.
658
659 protected: //! @name Fixed text position properties
660
661   gp_Pnt                  myFixedTextPosition;   //!< Stores text position fixed by user.
662   Standard_Boolean        myIsTextPositionFixed; //!< Is the text label position fixed by user.
663
664 protected: //! @name Units properties
665
666   Standard_ExtCharacter    mySpecialSymbol;        //!< Special symbol.
667   AIS_DisplaySpecialSymbol myDisplaySpecialSymbol; //!< Special symbol display options.
668
669 protected: //! @name Geometrical properties
670
671   GeometryType myGeometryType;  //!< defines type of shapes on which the dimension is to be built. 
672
673   gp_Pln           myPlane;           //!< Plane where dimension will be built (computed or user defined).
674   Standard_Boolean myIsPlaneCustom;   //!< Is plane defined by user (otherwise it will be computed automatically).
675   Standard_Real    myFlyout;          //!< Flyout distance.
676   Standard_Boolean myIsGeometryValid; //!< Is dimension geometry properly defined.
677
678 private:
679
680   AIS_KindOfDimension myKindOfDimension;
681 };
682
683 #endif // _AIS_Dimension_HeaderFile