0024422: Wrong result done by FaceClassifier algorithm
[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>
a6eb515f 37#include <Select3D_ListOfSensitive.hxx>
38#include <SelectMgr_EntityOwner.hxx>
39#include <Standard.hxx>
40#include <TCollection_ExtendedString.hxx>
41#include <TColgp_HArray1OfPnt.hxx>
42#include <TopoDS_Face.hxx>
43#include <TopoDS_Shape.hxx>
44
45DEFINE_STANDARD_HANDLE(AIS_Dimension, AIS_InteractiveObject)
46
47class AIS_Dimension : public AIS_InteractiveObject
48{
d7bffd44 49protected:
50
51 // Specifies supported at base level horizontal and vertical
52 // label positions for drawing extension lines and centered text.
53 enum LabelPosition
54 {
55 LabelPosition_None = 0x00,
56
57 LabelPosition_Left = 0x01,
58 LabelPosition_Right = 0x02,
59 LabelPosition_HCenter = 0x04,
60 LabelPosition_HMask = LabelPosition_Left | LabelPosition_Right | LabelPosition_HCenter,
61
62 LabelPosition_Above = 0x10,
63 LabelPosition_Below = 0x20,
64 LabelPosition_VCenter = 0x40,
65 LabelPosition_VMask = LabelPosition_Above | LabelPosition_Below | LabelPosition_VCenter
66 };
67
a6eb515f 68public:
d7bffd44 69
a6eb515f 70 //! Constructor with default parameters values
d7bffd44 71 Standard_EXPORT AIS_Dimension();
72
a6eb515f 73 //! Gets dimension value
d7bffd44 74 Standard_EXPORT Standard_Real GetValue() const;
a6eb515f 75
76 //! Sets dimension value
77 //! Attention! This method is used ONLY to set custom value.
78 //! To set value internally, use <myValue>.
79 Standard_EXPORT void SetCustomValue (const Standard_Real theValue);
80
81 //! Gets working plane.
82 Standard_EXPORT const gp_Pln& GetWorkingPlane() const;
83
84 //! Sets working plane.
85 Standard_EXPORT void SetWorkingPlane (const gp_Pln& thePlane);
86
a6eb515f 87 Standard_EXPORT void SetFirstPoint (const gp_Pnt& thePoint);
88
89 Standard_EXPORT void SetSecondPoint (const gp_Pnt& thePoint);
90
91 Standard_EXPORT void SetFirstShape (const TopoDS_Shape& theFirstShape);
92
93 Standard_EXPORT void SetSecondShape (const TopoDS_Shape& theSecondShape);
94
95 //! Gets the dimension aspect from AIS object drawer.
96 //! Dimension aspect contains aspects of line, text and arrows for dimension presentation.
97 Standard_EXPORT Handle(Prs3d_DimensionAspect) DimensionAspect() const;
98
99 //! Sets new length aspect in the interactive object drawer.
100 Standard_EXPORT void SetDimensionAspect (const Handle(Prs3d_DimensionAspect)& theDimensionAspect);
101
102 //! Returns the kind of dimension
103 Standard_EXPORT AIS_KindOfDimension KindOfDimension() const;
104
105 //! Returns the kind of interactive
106 Standard_EXPORT virtual AIS_KindOfInteractive Type() const;
107
108 //! Sets the kind of dimension
109 Standard_EXPORT virtual void SetKindOfDimension (const AIS_KindOfDimension theKindOfDimension);
110
111 //! Returns true if the class of objects accepts the display mode theMode.
112 //! The interactive context can have a default mode of
113 //! representation for the set of Interactive Objects. This
114 //! mode may not be accepted by object
d7bffd44 115 Standard_EXPORT virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const;
116
a6eb515f 117 // Selection computing if it is needed here
118 Standard_EXPORT virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
119 const Standard_Integer theMode);
d7bffd44 120
a6eb515f 121 //! Reset working plane to default.
122 Standard_EXPORT void ResetWorkingPlane();
d7bffd44 123
a6eb515f 124 //! specifies dimension special symbol display options
125 Standard_EXPORT void SetDisplaySpecialSymbol (const AIS_DisplaySpecialSymbol theDisplaySpecSymbol);
d7bffd44 126
a6eb515f 127 //! shows dimension special symbol display options
128 Standard_EXPORT AIS_DisplaySpecialSymbol DisplaySpecialSymbol() const;
d7bffd44 129
a6eb515f 130 //! specifies special symbol
131 Standard_EXPORT void SetSpecialSymbol (const Standard_ExtCharacter theSpecialSymbol);
d7bffd44 132
a6eb515f 133 //! returns special symbol
134 Standard_EXPORT Standard_ExtCharacter SpecialSymbol() const;
d7bffd44 135
a6eb515f 136 //! shows if Units are to be displayed along with dimension value
137 Standard_EXPORT Standard_Boolean IsUnitsDisplayed() const;
d7bffd44 138
a6eb515f 139 //! sets to display units along with the dimansion value or no
140 Standard_EXPORT void MakeUnitsDisplayed (const Standard_Boolean toDisplayUnits);
d7bffd44 141
a6eb515f 142 //! returns the current type of units
143 Standard_EXPORT TCollection_AsciiString UnitsQuantity() const;
d7bffd44 144
a6eb515f 145 //! sets the current type of units
146 Standard_EXPORT void SetUnitsQuantity (const TCollection_AsciiString& theUnitsQuantity);
d7bffd44 147
a6eb515f 148 //! returns the current model units
149 Standard_EXPORT TCollection_AsciiString ModelUnits() const;
d7bffd44 150
a6eb515f 151 //! sets the current model units
152 Standard_EXPORT void SetModelUnits (const TCollection_AsciiString& theUnits);
d7bffd44 153
a6eb515f 154 //! returns the current display units
155 Standard_EXPORT TCollection_AsciiString DisplayUnits() const;
d7bffd44 156
a6eb515f 157 //! sets the current display units
158 Standard_EXPORT void SetDisplayUnits (const TCollection_AsciiString& theUnits);
d7bffd44 159
a6eb515f 160 //! Important! Only for 3d text </br>
161 //! 3d text is oriented relative to the attachment points order </br>
162 //! By default, text direction vector is oriented from the first attachment point </br>
163 //! to the second one. This method checks if text direction is to be default or </br>
164 //! should be reversed.
165 Standard_EXPORT Standard_Boolean IsTextReversed() const;
d7bffd44 166
a6eb515f 167 //! Important! Only for 3d text
168 //! 3d text is oriented relative to the attachment points order </br>
169 //! By default, text direction vector is oriented from the first attachment point </br>
170 //! to the second one. This method sets value that shows if text direction </br>
171 //! should be reversed or not.
172 Standard_EXPORT void MakeTextReversed (const Standard_Boolean isTextReversed);
d7bffd44 173
a6eb515f 174 //! Sets selection tolerance for text2d:
175 //! For 2d text selection detection sensitive point with tolerance is used
176 //! to change this tolerance use this method
177 //! Important! Only for 2d text
178 Standard_EXPORT void SetSelToleranceForText2d (const Standard_Real theTol);
d7bffd44 179
a6eb515f 180 //! Returns selection tolerance for text2d:
181 //! For 2d text selection detection sensitive point with tolerance is used
182 //! Important! Only for 2d text
183 Standard_EXPORT Standard_Real SelToleranceForText2d() const;
d7bffd44 184
62b6361a 185 //! Sets flyout size for dimension.
186 Standard_EXPORT void SetFlyout (const Standard_Real theFlyout);
d7bffd44 187
62b6361a 188 //! @return flyout size for dimension.
d7bffd44 189 Standard_Real GetFlyout() const
190 {
191 return myFlyout;
192 }
193
194public:
a6eb515f 195
196 DEFINE_STANDARD_RTTI(AIS_Dimension)
197
198protected:
d7bffd44 199
a6eb515f 200 Standard_EXPORT void getTextWidthAndString (Quantity_Length& theWidth,
201 TCollection_ExtendedString& theString) const;
202
203 Standard_EXPORT Standard_Real valueToDisplayUnits();
204
205 //! Reset working plane to default.
206 Standard_EXPORT void resetWorkingPlane (const gp_Pln& theNewDefaultPlane);
207
208 //! Count default plane
209 Standard_EXPORT virtual void countDefaultPlane();
210
211 //! Computes dimension value in display units
212 Standard_EXPORT virtual void computeValue();
213
214 //! Performs drawing of 2d or 3d arrows on the working plane
215 Standard_EXPORT void drawArrow (const Handle(Prs3d_Presentation)& thePresentation,
216 const gp_Pnt& theLocation,
217 const gp_Dir& theDirection);
218
219 //! Performs drawing of 2d or 3d text on the working plane
220 //! @return text width relative to the dimension working plane. For 2d text this value will be zero.
221 Standard_EXPORT Standard_Real drawText (const Handle(Prs3d_Presentation)& thePresentation,
222 const gp_Dir& theTextDir,
223 const TCollection_ExtendedString theText,
d7bffd44 224 const AIS_DimensionDisplayMode theMode,
225 const Standard_Integer theLabelPosition);
a6eb515f 226
227 //! Performs computing of dimension linear extension with text
d7bffd44 228 //! @param thePresentation [in] the presentation to fill with graphical primitives.
229 //! @param theExtensionSize [in] the size of extension line.
230 //! @param theExtensionStart [in] the point where extension line connects to dimension.
231 //! @param theExtensionDir [in] the direction of extension line.
232 //! @param theValueString [in] the string with value.
233 //! @param theMode [in] the display mode.
234 //! @param theLabelPosition [in] position flags for the text label.
235 Standard_EXPORT void drawExtension (const Handle(Prs3d_Presentation)& thePresentation,
236 const Standard_Real theExtensionSize,
237 const gp_Pnt& theExtensionStart,
238 const gp_Dir& theExtensionDir,
239 const TCollection_ExtendedString& theValueString,
240 const AIS_DimensionDisplayMode theMode,
241 const Standard_Integer theLabelPosition);
a6eb515f 242
243 //! Performs computing of linear dimension (for length, diameter, radius and so on)
244 Standard_EXPORT void drawLinearDimension (const Handle(Prs3d_Presentation)& thePresentation,
a6eb515f 245 const AIS_DimensionDisplayMode theMode,
246 const Standard_Boolean isOneSideDimension = Standard_False);
247
248 //! If it's possible computes circle from planar face
249 Standard_EXPORT Standard_Boolean circleFromPlanarFace (const TopoDS_Face& theFace,
250 Handle(Geom_Curve)& theCurve,
251 gp_Pnt & theFirstPoint,
252 gp_Pnt & theLastPoint);
253
254 //! Performs initialization of circle and points from given shape
255 //! (for radius, diameter and so on)
256 Standard_EXPORT Standard_Boolean initCircularDimension (const TopoDS_Shape& theShape,
257 gp_Circ& theCircle,
258 gp_Pnt& theMiddleArcPoint,
259 gp_Pnt& theOppositeDiameterPoint);
260 Standard_EXPORT Standard_Boolean isComputed() const;
261
262 Standard_EXPORT void setComputed (Standard_Boolean isComputed);
263
264 Standard_EXPORT gp_Pnt textPosition() const;
265
266 Standard_EXPORT void setTextPosition (const gp_Pnt thePosition);
267
268 Standard_EXPORT void resetGeom();
269
62b6361a 270 //! Fills sensitive entity for flyouts and adds it to the selection.
271 Standard_EXPORT virtual void computeFlyoutSelection (const Handle(SelectMgr_Selection)& theSelection,
272 const Handle(AIS_DimensionOwner)& theOwner);
a6eb515f 273
d7bffd44 274protected: //! @name Working plane properties
a6eb515f 275
276 //! Dimension default plane
277 gp_Pln myDefaultPlane;
d7bffd44 278
a6eb515f 279 //! Shows if working plane is set custom
280 Standard_Boolean myIsWorkingPlaneCustom;
281
d7bffd44 282protected: //! @name Value properties
a6eb515f 283
284 //! Dimension value which is displayed with dimension lines
285 Standard_Real myValue;
d7bffd44 286
a6eb515f 287 //! Shows if the value is set by user and is no need to count it automatically
288 Standard_Boolean myIsValueCustom;
289
d7bffd44 290protected: // !@name Units properties
a6eb515f 291
292 //! The quantity of units for the value computation
293 TCollection_AsciiString myUnitsQuantity;
d7bffd44 294
a6eb515f 295 //! Units of the model
296 TCollection_AsciiString myModelUnits;
d7bffd44 297
a6eb515f 298 //! Units in which the displayed value will be converted
299 TCollection_AsciiString myDisplayUnits;
d7bffd44 300
a6eb515f 301 //! Determines if units is to be displayed along with the value
302 Standard_Boolean myToDisplayUnits;
d7bffd44 303
a6eb515f 304 //! Special symbol for some kind of dimensions (for diameter, radius and so on)
305 Standard_ExtCharacter mySpecialSymbol;
d7bffd44 306
a6eb515f 307 //! Special symbol display options
308 AIS_DisplaySpecialSymbol myDisplaySpecialSymbol;
309
d7bffd44 310protected: //! @name Geometry properties
a6eb515f 311
312 //! Geometry of dimensions, needs for advanced selection
313 //! Geometry is computed in Compute() method and is used
314 //! in ComputeSelection() method.
315 //! If it is computed successfully, myIsComputed = Standard_True.
316 //! to check computing result use IsComputed() method
317 struct DimensionGeom
318 {
319 //! Text position
320 gp_Pnt myTextPosition;
d7bffd44 321
a6eb515f 322 //! Text bounding box, stored for advanced selection
323 Bnd_Box myTextBndBox;
d7bffd44 324
a6eb515f 325 //! Sensitive point tolerance for 2d text selection
326 Standard_Real mySelToleranceForText2d;
d7bffd44 327
a6eb515f 328 //! For advanced dimension line selection
329 Select3D_ListOfSensitive mySensitiveSegments;
d7bffd44 330
a6eb515f 331 //! Shows if attachment points were computed
332 Standard_Boolean myIsComputed;
d7bffd44 333
a6eb515f 334 public:
d7bffd44 335
336 DimensionGeom () : myIsComputed (Standard_False) {}
a6eb515f 337 };
338
339 //! Shows if text is inverted
340 Standard_Boolean myIsTextReversed;
d7bffd44 341
a6eb515f 342 //! Points that are base for dimension.
343 //! My first point of dimension attach (belongs to shape for which dimension is computed)
344 gp_Pnt myFirstPoint;
d7bffd44 345
a6eb515f 346 //! My second point of dimension attach (belongs to shape for which dimension is computed)
347 gp_Pnt mySecondPoint;
d7bffd44 348
a6eb515f 349 //! Shows if attach points are initialized correctly
350 Standard_Boolean myIsInitialized;
d7bffd44 351
a6eb515f 352 //! First shape (can be vertex, edge or face)
353 TopoDS_Shape myFirstShape;
d7bffd44 354
a6eb515f 355 //! Second shape (can be vertex, edge or face)
356 TopoDS_Shape mySecondShape;
d7bffd44 357
a6eb515f 358 //! Number of shapes
359 Standard_Integer myShapesNumber;
d7bffd44 360
62b6361a 361 //! Defines flyout lines and direction
362 //! Flyout direction in the working plane.
363 //! Can be negative, or positive and is defined by the sign of myFlyout value.
364 //! The direction vector is counting using the working plane.
365 //! myFlyout value defined the size of flyout.
366 Standard_Real myFlyout;
d7bffd44 367
a6eb515f 368 //! Geometry of dimensions, needs for advanced selection
369 //! Geometry is computed in Compute() method and is used
370 //! in ComputeSelection() method.
371 //! If it is computed successfully, myIsComputed = Standard_True.
372 //! to check computing result use IsComputed() method
373 DimensionGeom myGeom;
d7bffd44 374
a6eb515f 375private:
d7bffd44 376
a6eb515f 377 //! Type of dimension
378 AIS_KindOfDimension myKindOfDimension;
d7bffd44 379
a6eb515f 380 //! Dimension working plane, is equal to <myDefaultPlane> if it can be computed automatically.
381 gp_Pln myWorkingPlane;
a6eb515f 382};
383#endif