1 // Copyright (c) 1998-1999 Matra Datavision
2 // Copyright (c) 1999-2013 OPEN CASCADE SAS
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.
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.
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.
19 #ifndef _AIS_Dimension_Headerfile
20 #define _AIS_Dimension_Headerfile
22 #include <AIS_DimensionDisplayMode.hxx>
23 #include <AIS_DisplaySpecialSymbol.hxx>
24 #include <AIS_InteractiveObject.hxx>
25 #include <AIS_KindOfInteractive.hxx>
26 #include <AIS_KindOfDimension.hxx>
27 #include <AIS_KindOfSurface.hxx>
28 #include <Bnd_Box.hxx>
29 #include <Geom_Curve.hxx>
31 #include <Prs3d_ArrowAspect.hxx>
32 #include <Prs3d_DimensionAspect.hxx>
33 #include <Prs3d_LineAspect.hxx>
34 #include <Prs3d_Presentation.hxx>
35 #include <Prs3d_TextAspect.hxx>
36 #include <Prs3d_VerticalTextAlignment.hxx>
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>
45 DEFINE_STANDARD_HANDLE(AIS_Dimension, AIS_InteractiveObject)
47 class AIS_Dimension : public AIS_InteractiveObject
50 //! Constructor with default parameters values
51 Standard_EXPORT AIS_Dimension (const Standard_Real theExtensionSize = 1.0);
52 //! Constructor to set aspect of dimension
53 Standard_EXPORT AIS_Dimension (const Handle(Prs3d_DimensionAspect)& theAspect,
54 const Standard_Real theExtensionSize = 1.0);
55 //! Gets dimension value
56 Standard_EXPORT Standard_Real GetValue () const;
58 //! Sets dimension value
59 //! Attention! This method is used ONLY to set custom value.
60 //! To set value internally, use <myValue>.
61 Standard_EXPORT void SetCustomValue (const Standard_Real theValue);
63 //! Gets working plane.
64 Standard_EXPORT const gp_Pln& GetWorkingPlane() const;
66 //! Sets working plane.
67 Standard_EXPORT void SetWorkingPlane (const gp_Pln& thePlane);
69 //! Sets extension size.
70 Standard_EXPORT void SetExtensionSize (const Standard_Real theExtensionSize);
72 //! Gets extension size.
73 Standard_EXPORT Standard_Real GetExtensionSize() const;
75 Standard_EXPORT void SetFirstPoint (const gp_Pnt& thePoint);
77 Standard_EXPORT void SetSecondPoint (const gp_Pnt& thePoint);
79 Standard_EXPORT void SetFirstShape (const TopoDS_Shape& theFirstShape);
81 Standard_EXPORT void SetSecondShape (const TopoDS_Shape& theSecondShape);
83 //! Gets the dimension aspect from AIS object drawer.
84 //! Dimension aspect contains aspects of line, text and arrows for dimension presentation.
85 Standard_EXPORT Handle(Prs3d_DimensionAspect) DimensionAspect() const;
87 //! Sets new length aspect in the interactive object drawer.
88 Standard_EXPORT void SetDimensionAspect (const Handle(Prs3d_DimensionAspect)& theDimensionAspect);
90 //! Returns the kind of dimension
91 Standard_EXPORT AIS_KindOfDimension KindOfDimension() const;
93 //! Returns the kind of interactive
94 Standard_EXPORT virtual AIS_KindOfInteractive Type() const;
96 //! Sets the kind of dimension
97 Standard_EXPORT virtual void SetKindOfDimension (const AIS_KindOfDimension theKindOfDimension);
99 //! Returns true if the class of objects accepts the display mode theMode.
100 //! The interactive context can have a default mode of
101 //! representation for the set of Interactive Objects. This
102 //! mode may not be accepted by object
103 Standard_EXPORT virtual Standard_Boolean AcceptDisplayMode(const Standard_Integer theMode) const;
104 // Selection computing if it is needed here
105 Standard_EXPORT virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
106 const Standard_Integer theMode);
107 //! Reset working plane to default.
108 Standard_EXPORT void ResetWorkingPlane();
109 //! specifies dimension special symbol display options
110 Standard_EXPORT void SetDisplaySpecialSymbol (const AIS_DisplaySpecialSymbol theDisplaySpecSymbol);
111 //! shows dimension special symbol display options
112 Standard_EXPORT AIS_DisplaySpecialSymbol DisplaySpecialSymbol() const;
113 //! specifies special symbol
114 Standard_EXPORT void SetSpecialSymbol (const Standard_ExtCharacter theSpecialSymbol);
115 //! returns special symbol
116 Standard_EXPORT Standard_ExtCharacter SpecialSymbol() const;
117 //! shows if Units are to be displayed along with dimension value
118 Standard_EXPORT Standard_Boolean IsUnitsDisplayed() const;
119 //! sets to display units along with the dimansion value or no
120 Standard_EXPORT void MakeUnitsDisplayed (const Standard_Boolean toDisplayUnits);
121 //! returns the current type of units
122 Standard_EXPORT TCollection_AsciiString UnitsQuantity() const;
123 //! sets the current type of units
124 Standard_EXPORT void SetUnitsQuantity (const TCollection_AsciiString& theUnitsQuantity);
125 //! returns the current model units
126 Standard_EXPORT TCollection_AsciiString ModelUnits() const;
127 //! sets the current model units
128 Standard_EXPORT void SetModelUnits (const TCollection_AsciiString& theUnits);
129 //! returns the current display units
130 Standard_EXPORT TCollection_AsciiString DisplayUnits() const;
131 //! sets the current display units
132 Standard_EXPORT void SetDisplayUnits (const TCollection_AsciiString& theUnits);
133 //! sets the text offset: distance from attach point to the text on the extension
134 //! in case if text isn't in center of the dimension line
135 Standard_EXPORT void SetTextOffset (const Standard_Real theOffset);
136 //! returns the text offset: distance from attach point to the text on the extension
137 //! in case if text isn't in center of the dimension line
138 Standard_EXPORT Standard_Real TextOffset() const;
139 //! Important! Only for 3d text </br>
140 //! 3d text is oriented relative to the attachment points order </br>
141 //! By default, text direction vector is oriented from the first attachment point </br>
142 //! to the second one. This method checks if text direction is to be default or </br>
143 //! should be reversed.
144 Standard_EXPORT Standard_Boolean IsTextReversed() const;
145 //! Important! Only for 3d text
146 //! 3d text is oriented relative to the attachment points order </br>
147 //! By default, text direction vector is oriented from the first attachment point </br>
148 //! to the second one. This method sets value that shows if text direction </br>
149 //! should be reversed or not.
150 Standard_EXPORT void MakeTextReversed (const Standard_Boolean isTextReversed);
151 //! Sets selection tolerance for text2d:
152 //! For 2d text selection detection sensitive point with tolerance is used
153 //! to change this tolerance use this method
154 //! Important! Only for 2d text
155 Standard_EXPORT void SetSelToleranceForText2d (const Standard_Real theTol);
156 //! Returns selection tolerance for text2d:
157 //! For 2d text selection detection sensitive point with tolerance is used
158 //! Important! Only for 2d text
159 Standard_EXPORT Standard_Real SelToleranceForText2d() const;
162 DEFINE_STANDARD_RTTI(AIS_Dimension)
165 Standard_EXPORT void getTextWidthAndString (Quantity_Length& theWidth,
166 TCollection_ExtendedString& theString) const;
168 Standard_EXPORT Standard_Real valueToDisplayUnits();
170 //! Reset working plane to default.
171 Standard_EXPORT void resetWorkingPlane (const gp_Pln& theNewDefaultPlane);
173 //! Count default plane
174 Standard_EXPORT virtual void countDefaultPlane();
176 //! Computes dimension value in display units
177 Standard_EXPORT virtual void computeValue();
179 //! Performs drawing of 2d or 3d arrows on the working plane
180 Standard_EXPORT void drawArrow (const Handle(Prs3d_Presentation)& thePresentation,
181 const gp_Pnt& theLocation,
182 const gp_Dir& theDirection);
184 //! Performs drawing of 2d or 3d text on the working plane
185 //! @return text width relative to the dimension working plane. For 2d text this value will be zero.
186 Standard_EXPORT Standard_Real drawText (const Handle(Prs3d_Presentation)& thePresentation,
187 const gp_Dir& theTextDir,
188 const TCollection_ExtendedString theText,
189 const AIS_DimensionDisplayMode theMode);
191 //! Performs computing of dimension linear extension with text
192 Standard_EXPORT virtual void drawExtensionWithText (const Handle(Prs3d_Presentation)& thePresentation,
193 const gp_Pnt& theStartPoint,
194 const gp_Lin& theDimensionLine,
195 const TCollection_ExtendedString& theValueString,
196 const AIS_DimensionDisplayMode theMode);
198 //! Performs computing of linear dimension (for length, diameter, radius and so on)
199 Standard_EXPORT void drawLinearDimension (const Handle(Prs3d_Presentation)& thePresentation,
200 const gp_Pnt& theFirstAttach,
201 const gp_Pnt& theSecondAttach,
202 const AIS_DimensionDisplayMode theMode,
203 const Standard_Boolean isOneSideDimension = Standard_False);
205 //! If it's possible computes circle from planar face
206 Standard_EXPORT Standard_Boolean circleFromPlanarFace (const TopoDS_Face& theFace,
207 Handle(Geom_Curve)& theCurve,
208 gp_Pnt & theFirstPoint,
209 gp_Pnt & theLastPoint);
211 //! Performs initialization of circle and points from given shape
212 //! (for radius, diameter and so on)
213 Standard_EXPORT Standard_Boolean initCircularDimension (const TopoDS_Shape& theShape,
215 gp_Pnt& theMiddleArcPoint,
216 gp_Pnt& theOppositeDiameterPoint);
217 Standard_EXPORT Standard_Boolean isComputed() const;
219 Standard_EXPORT void setComputed (Standard_Boolean isComputed);
221 Standard_EXPORT gp_Pnt textPosition() const;
223 Standard_EXPORT void setTextPosition (const gp_Pnt thePosition);
225 Standard_EXPORT void resetGeom();
230 /// WORKING PLANE PROPERTIES
232 //! Dimension default plane
233 gp_Pln myDefaultPlane;
234 //! Shows if working plane is set custom
235 Standard_Boolean myIsWorkingPlaneCustom;
239 //! Dimension value which is displayed with dimension lines
240 Standard_Real myValue;
241 //! Shows if the value is set by user and is no need to count it automatically
242 Standard_Boolean myIsValueCustom;
246 //! The quantity of units for the value computation
247 TCollection_AsciiString myUnitsQuantity;
248 //! Units of the model
249 TCollection_AsciiString myModelUnits;
250 //! Units in which the displayed value will be converted
251 TCollection_AsciiString myDisplayUnits;
252 //! Determines if units is to be displayed along with the value
253 Standard_Boolean myToDisplayUnits;
254 //! Special symbol for some kind of dimensions (for diameter, radius and so on)
255 Standard_ExtCharacter mySpecialSymbol;
256 //! Special symbol display options
257 AIS_DisplaySpecialSymbol myDisplaySpecialSymbol;
259 /// GEOMETRY PROPERTIES
261 //! Geometry of dimensions, needs for advanced selection
262 //! Geometry is computed in Compute() method and is used
263 //! in ComputeSelection() method.
264 //! If it is computed successfully, myIsComputed = Standard_True.
265 //! to check computing result use IsComputed() method
269 gp_Pnt myTextPosition;
270 //! Text bounding box, stored for advanced selection
271 Bnd_Box myTextBndBox;
272 //! Sensitive point tolerance for 2d text selection
273 Standard_Real mySelToleranceForText2d;
274 //! For advanced dimension line selection
275 Select3D_ListOfSensitive mySensitiveSegments;
276 //! Shows if attachment points were computed
277 Standard_Boolean myIsComputed;
280 : myIsComputed (Standard_False)
284 //! Shows if text is inverted
285 Standard_Boolean myIsTextReversed;
286 //! Determines distance from attach point to the text on the extension
287 //! in case if text isn't in center of the dimension line
288 Standard_Real myTextOffset;
289 //! Points that are base for dimension.
290 //! My first point of dimension attach (belongs to shape for which dimension is computed)
292 //! My second point of dimension attach (belongs to shape for which dimension is computed)
293 gp_Pnt mySecondPoint;
294 //! Shows if attach points are initialized correctly
295 Standard_Boolean myIsInitialized;
296 //! First shape (can be vertex, edge or face)
297 TopoDS_Shape myFirstShape;
298 //! Second shape (can be vertex, edge or face)
299 TopoDS_Shape mySecondShape;
301 Standard_Integer myShapesNumber;
302 //! Geometry of dimensions, needs for advanced selection
303 //! Geometry is computed in Compute() method and is used
304 //! in ComputeSelection() method.
305 //! If it is computed successfully, myIsComputed = Standard_True.
306 //! to check computing result use IsComputed() method
307 DimensionGeom myGeom;
309 //! Type of dimension
310 AIS_KindOfDimension myKindOfDimension;
311 //! Dimension working plane, is equal to <myDefaultPlane> if it can be computed automatically.
312 gp_Pln myWorkingPlane;
313 //! Extension size in model measure units.
314 //! No inclined or curved extension line is now supported.
315 Standard_Real myExtensionSize;