0024288: Provide flipping text for AIS_Dimensions
[occt.git] / src / AIS / AIS_Dimension.hxx
CommitLineData
a6eb515f 1// Copyright (c) 1998-1999 Matra Datavision
2// Copyright (c) 1999-2013 OPEN CASCADE SAS
3//
4// The content of this file is subject to the Open CASCADE Technology Public
5// License Version 6.5 (the "License"). You may not use the content of this file
6// except in compliance with the License. Please obtain a copy of the License
7// at http://www.opencascade.org and read it completely before using this file.
8//
9// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11//
12// The Original Code and all software distributed under the License is
13// distributed on an "AS IS" basis, without warranty of any kind, and the
14// Initial Developer hereby disclaims all such warranties, including without
15// limitation, any warranties of merchantability, fitness for a particular
16// purpose or non-infringement. Please see the License for the specific terms
17// and conditions governing the rights and limitations under the License.
18
19#ifndef _AIS_Dimension_Headerfile
20#define _AIS_Dimension_Headerfile
21
22#include <AIS_DimensionDisplayMode.hxx>
62b6361a 23#include <AIS_DimensionOwner.hxx>
a6eb515f 24#include <AIS_DisplaySpecialSymbol.hxx>
25#include <AIS_InteractiveObject.hxx>
26#include <AIS_KindOfInteractive.hxx>
27#include <AIS_KindOfDimension.hxx>
28#include <AIS_KindOfSurface.hxx>
29#include <Bnd_Box.hxx>
30#include <Geom_Curve.hxx>
31#include <gp_Pln.hxx>
32#include <Prs3d_ArrowAspect.hxx>
33#include <Prs3d_DimensionAspect.hxx>
34#include <Prs3d_LineAspect.hxx>
35#include <Prs3d_Presentation.hxx>
36#include <Prs3d_TextAspect.hxx>
37#include <Prs3d_VerticalTextAlignment.hxx>
38#include <Select3D_ListOfSensitive.hxx>
39#include <SelectMgr_EntityOwner.hxx>
40#include <Standard.hxx>
41#include <TCollection_ExtendedString.hxx>
42#include <TColgp_HArray1OfPnt.hxx>
43#include <TopoDS_Face.hxx>
44#include <TopoDS_Shape.hxx>
45
46DEFINE_STANDARD_HANDLE(AIS_Dimension, AIS_InteractiveObject)
47
48class AIS_Dimension : public AIS_InteractiveObject
49{
50public:
51 //! Constructor with default parameters values
52 Standard_EXPORT AIS_Dimension (const Standard_Real theExtensionSize = 1.0);
53 //! Constructor to set aspect of dimension
54 Standard_EXPORT AIS_Dimension (const Handle(Prs3d_DimensionAspect)& theAspect,
55 const Standard_Real theExtensionSize = 1.0);
56 //! Gets dimension value
57 Standard_EXPORT Standard_Real GetValue () const;
58
59 //! Sets dimension value
60 //! Attention! This method is used ONLY to set custom value.
61 //! To set value internally, use <myValue>.
62 Standard_EXPORT void SetCustomValue (const Standard_Real theValue);
63
64 //! Gets working plane.
65 Standard_EXPORT const gp_Pln& GetWorkingPlane() const;
66
67 //! Sets working plane.
68 Standard_EXPORT void SetWorkingPlane (const gp_Pln& thePlane);
69
70 //! Sets extension size.
71 Standard_EXPORT void SetExtensionSize (const Standard_Real theExtensionSize);
72
73 //! Gets extension size.
74 Standard_EXPORT Standard_Real GetExtensionSize() const;
75
76 Standard_EXPORT void SetFirstPoint (const gp_Pnt& thePoint);
77
78 Standard_EXPORT void SetSecondPoint (const gp_Pnt& thePoint);
79
80 Standard_EXPORT void SetFirstShape (const TopoDS_Shape& theFirstShape);
81
82 Standard_EXPORT void SetSecondShape (const TopoDS_Shape& theSecondShape);
83
84 //! Gets the dimension aspect from AIS object drawer.
85 //! Dimension aspect contains aspects of line, text and arrows for dimension presentation.
86 Standard_EXPORT Handle(Prs3d_DimensionAspect) DimensionAspect() const;
87
88 //! Sets new length aspect in the interactive object drawer.
89 Standard_EXPORT void SetDimensionAspect (const Handle(Prs3d_DimensionAspect)& theDimensionAspect);
90
91 //! Returns the kind of dimension
92 Standard_EXPORT AIS_KindOfDimension KindOfDimension() const;
93
94 //! Returns the kind of interactive
95 Standard_EXPORT virtual AIS_KindOfInteractive Type() const;
96
97 //! Sets the kind of dimension
98 Standard_EXPORT virtual void SetKindOfDimension (const AIS_KindOfDimension theKindOfDimension);
99
100 //! Returns true if the class of objects accepts the display mode theMode.
101 //! The interactive context can have a default mode of
102 //! representation for the set of Interactive Objects. This
103 //! mode may not be accepted by object
104 Standard_EXPORT virtual Standard_Boolean AcceptDisplayMode(const Standard_Integer theMode) const;
105 // Selection computing if it is needed here
106 Standard_EXPORT virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
107 const Standard_Integer theMode);
108 //! Reset working plane to default.
109 Standard_EXPORT void ResetWorkingPlane();
110 //! specifies dimension special symbol display options
111 Standard_EXPORT void SetDisplaySpecialSymbol (const AIS_DisplaySpecialSymbol theDisplaySpecSymbol);
112 //! shows dimension special symbol display options
113 Standard_EXPORT AIS_DisplaySpecialSymbol DisplaySpecialSymbol() const;
114 //! specifies special symbol
115 Standard_EXPORT void SetSpecialSymbol (const Standard_ExtCharacter theSpecialSymbol);
116 //! returns special symbol
117 Standard_EXPORT Standard_ExtCharacter SpecialSymbol() const;
118 //! shows if Units are to be displayed along with dimension value
119 Standard_EXPORT Standard_Boolean IsUnitsDisplayed() const;
120 //! sets to display units along with the dimansion value or no
121 Standard_EXPORT void MakeUnitsDisplayed (const Standard_Boolean toDisplayUnits);
122 //! returns the current type of units
123 Standard_EXPORT TCollection_AsciiString UnitsQuantity() const;
124 //! sets the current type of units
125 Standard_EXPORT void SetUnitsQuantity (const TCollection_AsciiString& theUnitsQuantity);
126 //! returns the current model units
127 Standard_EXPORT TCollection_AsciiString ModelUnits() const;
128 //! sets the current model units
129 Standard_EXPORT void SetModelUnits (const TCollection_AsciiString& theUnits);
130 //! returns the current display units
131 Standard_EXPORT TCollection_AsciiString DisplayUnits() const;
132 //! sets the current display units
133 Standard_EXPORT void SetDisplayUnits (const TCollection_AsciiString& theUnits);
134 //! sets the text offset: distance from attach point to the text on the extension
135 //! in case if text isn't in center of the dimension line
136 Standard_EXPORT void SetTextOffset (const Standard_Real theOffset);
137 //! returns the text offset: distance from attach point to the text on the extension
138 //! in case if text isn't in center of the dimension line
139 Standard_EXPORT Standard_Real TextOffset() const;
140 //! Important! Only for 3d text </br>
141 //! 3d text is oriented relative to the attachment points order </br>
142 //! By default, text direction vector is oriented from the first attachment point </br>
143 //! to the second one. This method checks if text direction is to be default or </br>
144 //! should be reversed.
145 Standard_EXPORT Standard_Boolean IsTextReversed() const;
146 //! Important! Only for 3d text
147 //! 3d text is oriented relative to the attachment points order </br>
148 //! By default, text direction vector is oriented from the first attachment point </br>
149 //! to the second one. This method sets value that shows if text direction </br>
150 //! should be reversed or not.
151 Standard_EXPORT void MakeTextReversed (const Standard_Boolean isTextReversed);
152 //! Sets selection tolerance for text2d:
153 //! For 2d text selection detection sensitive point with tolerance is used
154 //! to change this tolerance use this method
155 //! Important! Only for 2d text
156 Standard_EXPORT void SetSelToleranceForText2d (const Standard_Real theTol);
157 //! Returns selection tolerance for text2d:
158 //! For 2d text selection detection sensitive point with tolerance is used
159 //! Important! Only for 2d text
160 Standard_EXPORT Standard_Real SelToleranceForText2d() const;
62b6361a 161 //! Sets flyout size for dimension.
162 Standard_EXPORT void SetFlyout (const Standard_Real theFlyout);
163 //! @return flyout size for dimension.
164 Standard_EXPORT Standard_Real GetFlyout () const;
a6eb515f 165
166 DEFINE_STANDARD_RTTI(AIS_Dimension)
167
168protected:
169 Standard_EXPORT void getTextWidthAndString (Quantity_Length& theWidth,
170 TCollection_ExtendedString& theString) const;
171
172 Standard_EXPORT Standard_Real valueToDisplayUnits();
173
174 //! Reset working plane to default.
175 Standard_EXPORT void resetWorkingPlane (const gp_Pln& theNewDefaultPlane);
176
177 //! Count default plane
178 Standard_EXPORT virtual void countDefaultPlane();
179
180 //! Computes dimension value in display units
181 Standard_EXPORT virtual void computeValue();
182
183 //! Performs drawing of 2d or 3d arrows on the working plane
184 Standard_EXPORT void drawArrow (const Handle(Prs3d_Presentation)& thePresentation,
185 const gp_Pnt& theLocation,
186 const gp_Dir& theDirection);
187
188 //! Performs drawing of 2d or 3d text on the working plane
189 //! @return text width relative to the dimension working plane. For 2d text this value will be zero.
190 Standard_EXPORT Standard_Real drawText (const Handle(Prs3d_Presentation)& thePresentation,
191 const gp_Dir& theTextDir,
192 const TCollection_ExtendedString theText,
193 const AIS_DimensionDisplayMode theMode);
194
195 //! Performs computing of dimension linear extension with text
196 Standard_EXPORT virtual void drawExtensionWithText (const Handle(Prs3d_Presentation)& thePresentation,
197 const gp_Pnt& theStartPoint,
198 const gp_Lin& theDimensionLine,
199 const TCollection_ExtendedString& theValueString,
200 const AIS_DimensionDisplayMode theMode);
201
202 //! Performs computing of linear dimension (for length, diameter, radius and so on)
203 Standard_EXPORT void drawLinearDimension (const Handle(Prs3d_Presentation)& thePresentation,
204 const gp_Pnt& theFirstAttach,
205 const gp_Pnt& theSecondAttach,
206 const AIS_DimensionDisplayMode theMode,
207 const Standard_Boolean isOneSideDimension = Standard_False);
208
209 //! If it's possible computes circle from planar face
210 Standard_EXPORT Standard_Boolean circleFromPlanarFace (const TopoDS_Face& theFace,
211 Handle(Geom_Curve)& theCurve,
212 gp_Pnt & theFirstPoint,
213 gp_Pnt & theLastPoint);
214
215 //! Performs initialization of circle and points from given shape
216 //! (for radius, diameter and so on)
217 Standard_EXPORT Standard_Boolean initCircularDimension (const TopoDS_Shape& theShape,
218 gp_Circ& theCircle,
219 gp_Pnt& theMiddleArcPoint,
220 gp_Pnt& theOppositeDiameterPoint);
221 Standard_EXPORT Standard_Boolean isComputed() const;
222
223 Standard_EXPORT void setComputed (Standard_Boolean isComputed);
224
225 Standard_EXPORT gp_Pnt textPosition() const;
226
227 Standard_EXPORT void setTextPosition (const gp_Pnt thePosition);
228
229 Standard_EXPORT void resetGeom();
230
62b6361a 231 //! Fills sensitive entity for flyouts and adds it to the selection.
232 Standard_EXPORT virtual void computeFlyoutSelection (const Handle(SelectMgr_Selection)& theSelection,
233 const Handle(AIS_DimensionOwner)& theOwner);
a6eb515f 234 // Fields
235protected:
236
237 /// WORKING PLANE PROPERTIES
238
239 //! Dimension default plane
240 gp_Pln myDefaultPlane;
241 //! Shows if working plane is set custom
242 Standard_Boolean myIsWorkingPlaneCustom;
243
244 /// VALUE PROPERTIES
245
246 //! Dimension value which is displayed with dimension lines
247 Standard_Real myValue;
248 //! Shows if the value is set by user and is no need to count it automatically
249 Standard_Boolean myIsValueCustom;
250
251 /// UNITS PROPERTIES
252
253 //! The quantity of units for the value computation
254 TCollection_AsciiString myUnitsQuantity;
255 //! Units of the model
256 TCollection_AsciiString myModelUnits;
257 //! Units in which the displayed value will be converted
258 TCollection_AsciiString myDisplayUnits;
259 //! Determines if units is to be displayed along with the value
260 Standard_Boolean myToDisplayUnits;
261 //! Special symbol for some kind of dimensions (for diameter, radius and so on)
262 Standard_ExtCharacter mySpecialSymbol;
263 //! Special symbol display options
264 AIS_DisplaySpecialSymbol myDisplaySpecialSymbol;
265
266 /// GEOMETRY PROPERTIES
267
268 //! Geometry of dimensions, needs for advanced selection
269 //! Geometry is computed in Compute() method and is used
270 //! in ComputeSelection() method.
271 //! If it is computed successfully, myIsComputed = Standard_True.
272 //! to check computing result use IsComputed() method
273 struct DimensionGeom
274 {
275 //! Text position
276 gp_Pnt myTextPosition;
277 //! Text bounding box, stored for advanced selection
278 Bnd_Box myTextBndBox;
279 //! Sensitive point tolerance for 2d text selection
280 Standard_Real mySelToleranceForText2d;
281 //! For advanced dimension line selection
282 Select3D_ListOfSensitive mySensitiveSegments;
283 //! Shows if attachment points were computed
284 Standard_Boolean myIsComputed;
285 public:
286 DimensionGeom ()
287 : myIsComputed (Standard_False)
288 { }
289 };
290
291 //! Shows if text is inverted
292 Standard_Boolean myIsTextReversed;
293 //! Determines distance from attach point to the text on the extension
294 //! in case if text isn't in center of the dimension line
295 Standard_Real myTextOffset;
296 //! Points that are base for dimension.
297 //! My first point of dimension attach (belongs to shape for which dimension is computed)
298 gp_Pnt myFirstPoint;
299 //! My second point of dimension attach (belongs to shape for which dimension is computed)
300 gp_Pnt mySecondPoint;
301 //! Shows if attach points are initialized correctly
302 Standard_Boolean myIsInitialized;
303 //! First shape (can be vertex, edge or face)
304 TopoDS_Shape myFirstShape;
305 //! Second shape (can be vertex, edge or face)
306 TopoDS_Shape mySecondShape;
307 //! Number of shapes
308 Standard_Integer myShapesNumber;
62b6361a 309 //! Defines flyout lines and direction
310 //! Flyout direction in the working plane.
311 //! Can be negative, or positive and is defined by the sign of myFlyout value.
312 //! The direction vector is counting using the working plane.
313 //! myFlyout value defined the size of flyout.
314 Standard_Real myFlyout;
a6eb515f 315 //! Geometry of dimensions, needs for advanced selection
316 //! Geometry is computed in Compute() method and is used
317 //! in ComputeSelection() method.
318 //! If it is computed successfully, myIsComputed = Standard_True.
319 //! to check computing result use IsComputed() method
320 DimensionGeom myGeom;
321private:
322 //! Type of dimension
323 AIS_KindOfDimension myKindOfDimension;
324 //! Dimension working plane, is equal to <myDefaultPlane> if it can be computed automatically.
325 gp_Pln myWorkingPlane;
326 //! Extension size in model measure units.
327 //! No inclined or curved extension line is now supported.
328 Standard_Real myExtensionSize;
329};
330#endif