0024448: Possible copy-paste bug in IGESGeom_SplineCurve.cxx
[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
fe83e1ea 22#include <AIS_DimensionSelectionMode.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>
fe83e1ea 41#include <TColgp_HSequenceOfPnt.hxx>
a6eb515f 42#include <TopoDS_Face.hxx>
43#include <TopoDS_Shape.hxx>
fe83e1ea 44#include <NCollection_Sequence.hxx>
45#include <NCollection_Handle.hxx>
a6eb515f 46
47DEFINE_STANDARD_HANDLE(AIS_Dimension, AIS_InteractiveObject)
48
49class AIS_Dimension : public AIS_InteractiveObject
50{
d7bffd44 51protected:
52
53 // Specifies supported at base level horizontal and vertical
54 // label positions for drawing extension lines and centered text.
55 enum LabelPosition
56 {
57 LabelPosition_None = 0x00,
58
59 LabelPosition_Left = 0x01,
60 LabelPosition_Right = 0x02,
61 LabelPosition_HCenter = 0x04,
62 LabelPosition_HMask = LabelPosition_Left | LabelPosition_Right | LabelPosition_HCenter,
63
64 LabelPosition_Above = 0x10,
65 LabelPosition_Below = 0x20,
66 LabelPosition_VCenter = 0x40,
67 LabelPosition_VMask = LabelPosition_Above | LabelPosition_Below | LabelPosition_VCenter
68 };
69
a6eb515f 70public:
d7bffd44 71
fe83e1ea 72 //! Specifies supported presentation compute modes.
73 //! Used to compute only parts of presentation for
74 //! advanced highlighting.
75 enum ComputeMode
76 {
77 ComputeMode_All = 0, //!< "0" is reserved as neutral mode
78 ComputeMode_Line = 1, //!< corresponds to selection mode
79 ComputeMode_Text = 2 //!< corresponds to selection mode
80 };
81
82public:
83
a6eb515f 84 //! Constructor with default parameters values
d7bffd44 85 Standard_EXPORT AIS_Dimension();
86
a6eb515f 87 //! Gets dimension value
d7bffd44 88 Standard_EXPORT Standard_Real GetValue() const;
a6eb515f 89
90 //! Sets dimension value
91 //! Attention! This method is used ONLY to set custom value.
92 //! To set value internally, use <myValue>.
93 Standard_EXPORT void SetCustomValue (const Standard_Real theValue);
94
95 //! Gets working plane.
96 Standard_EXPORT const gp_Pln& GetWorkingPlane() const;
97
98 //! Sets working plane.
99 Standard_EXPORT void SetWorkingPlane (const gp_Pln& thePlane);
100
a6eb515f 101 Standard_EXPORT void SetFirstPoint (const gp_Pnt& thePoint);
102
103 Standard_EXPORT void SetSecondPoint (const gp_Pnt& thePoint);
104
105 Standard_EXPORT void SetFirstShape (const TopoDS_Shape& theFirstShape);
106
107 Standard_EXPORT void SetSecondShape (const TopoDS_Shape& theSecondShape);
108
109 //! Gets the dimension aspect from AIS object drawer.
110 //! Dimension aspect contains aspects of line, text and arrows for dimension presentation.
111 Standard_EXPORT Handle(Prs3d_DimensionAspect) DimensionAspect() const;
112
113 //! Sets new length aspect in the interactive object drawer.
114 Standard_EXPORT void SetDimensionAspect (const Handle(Prs3d_DimensionAspect)& theDimensionAspect);
115
116 //! Returns the kind of dimension
117 Standard_EXPORT AIS_KindOfDimension KindOfDimension() const;
118
119 //! Returns the kind of interactive
120 Standard_EXPORT virtual AIS_KindOfInteractive Type() const;
121
122 //! Sets the kind of dimension
123 Standard_EXPORT virtual void SetKindOfDimension (const AIS_KindOfDimension theKindOfDimension);
124
125 //! Returns true if the class of objects accepts the display mode theMode.
126 //! The interactive context can have a default mode of
127 //! representation for the set of Interactive Objects. This
128 //! mode may not be accepted by object
d7bffd44 129 Standard_EXPORT virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const;
130
a6eb515f 131 // Selection computing if it is needed here
132 Standard_EXPORT virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
133 const Standard_Integer theMode);
d7bffd44 134
a6eb515f 135 //! Reset working plane to default.
136 Standard_EXPORT void ResetWorkingPlane();
d7bffd44 137
a6eb515f 138 //! specifies dimension special symbol display options
139 Standard_EXPORT void SetDisplaySpecialSymbol (const AIS_DisplaySpecialSymbol theDisplaySpecSymbol);
d7bffd44 140
a6eb515f 141 //! shows dimension special symbol display options
142 Standard_EXPORT AIS_DisplaySpecialSymbol DisplaySpecialSymbol() const;
d7bffd44 143
a6eb515f 144 //! specifies special symbol
145 Standard_EXPORT void SetSpecialSymbol (const Standard_ExtCharacter theSpecialSymbol);
d7bffd44 146
a6eb515f 147 //! returns special symbol
148 Standard_EXPORT Standard_ExtCharacter SpecialSymbol() const;
d7bffd44 149
a6eb515f 150 //! shows if Units are to be displayed along with dimension value
151 Standard_EXPORT Standard_Boolean IsUnitsDisplayed() const;
d7bffd44 152
fe83e1ea 153 //! sets to display units along with the dimension value or no
a6eb515f 154 Standard_EXPORT void MakeUnitsDisplayed (const Standard_Boolean toDisplayUnits);
d7bffd44 155
a6eb515f 156 //! returns the current type of units
157 Standard_EXPORT TCollection_AsciiString UnitsQuantity() const;
d7bffd44 158
a6eb515f 159 //! sets the current type of units
160 Standard_EXPORT void SetUnitsQuantity (const TCollection_AsciiString& theUnitsQuantity);
d7bffd44 161
a6eb515f 162 //! returns the current model units
163 Standard_EXPORT TCollection_AsciiString ModelUnits() const;
d7bffd44 164
a6eb515f 165 //! sets the current model units
166 Standard_EXPORT void SetModelUnits (const TCollection_AsciiString& theUnits);
d7bffd44 167
a6eb515f 168 //! returns the current display units
169 Standard_EXPORT TCollection_AsciiString DisplayUnits() const;
d7bffd44 170
a6eb515f 171 //! sets the current display units
172 Standard_EXPORT void SetDisplayUnits (const TCollection_AsciiString& theUnits);
d7bffd44 173
a6eb515f 174 //! Important! Only for 3d text </br>
175 //! 3d text is oriented relative to the attachment points order </br>
176 //! By default, text direction vector is oriented from the first attachment point </br>
177 //! to the second one. This method checks if text direction is to be default or </br>
178 //! should be reversed.
179 Standard_EXPORT Standard_Boolean IsTextReversed() const;
d7bffd44 180
a6eb515f 181 //! Important! Only for 3d text
182 //! 3d text is oriented relative to the attachment points order </br>
183 //! By default, text direction vector is oriented from the first attachment point </br>
184 //! to the second one. This method sets value that shows if text direction </br>
185 //! should be reversed or not.
186 Standard_EXPORT void MakeTextReversed (const Standard_Boolean isTextReversed);
d7bffd44 187
a6eb515f 188 //! Sets selection tolerance for text2d:
189 //! For 2d text selection detection sensitive point with tolerance is used
190 //! to change this tolerance use this method
191 //! Important! Only for 2d text
192 Standard_EXPORT void SetSelToleranceForText2d (const Standard_Real theTol);
d7bffd44 193
a6eb515f 194 //! Returns selection tolerance for text2d:
195 //! For 2d text selection detection sensitive point with tolerance is used
196 //! Important! Only for 2d text
197 Standard_EXPORT Standard_Real SelToleranceForText2d() const;
d7bffd44 198
62b6361a 199 //! Sets flyout size for dimension.
200 Standard_EXPORT void SetFlyout (const Standard_Real theFlyout);
d7bffd44 201
62b6361a 202 //! @return flyout size for dimension.
d7bffd44 203 Standard_Real GetFlyout() const
204 {
205 return myFlyout;
206 }
207
208public:
a6eb515f 209
210 DEFINE_STANDARD_RTTI(AIS_Dimension)
211
212protected:
d7bffd44 213
a6eb515f 214 Standard_EXPORT void getTextWidthAndString (Quantity_Length& theWidth,
215 TCollection_ExtendedString& theString) const;
216
217 Standard_EXPORT Standard_Real valueToDisplayUnits();
218
219 //! Reset working plane to default.
220 Standard_EXPORT void resetWorkingPlane (const gp_Pln& theNewDefaultPlane);
221
222 //! Count default plane
223 Standard_EXPORT virtual void countDefaultPlane();
224
225 //! Computes dimension value in display units
226 Standard_EXPORT virtual void computeValue();
227
228 //! Performs drawing of 2d or 3d arrows on the working plane
229 Standard_EXPORT void drawArrow (const Handle(Prs3d_Presentation)& thePresentation,
230 const gp_Pnt& theLocation,
231 const gp_Dir& theDirection);
232
233 //! Performs drawing of 2d or 3d text on the working plane
234 //! @return text width relative to the dimension working plane. For 2d text this value will be zero.
fe83e1ea 235 Standard_EXPORT void drawText (const Handle(Prs3d_Presentation)& thePresentation,
236 const gp_Pnt& theTextPos,
237 const gp_Dir& theTextDir,
238 const TCollection_ExtendedString& theText,
239 const Standard_Integer theLabelPosition);
a6eb515f 240
241 //! Performs computing of dimension linear extension with text
d7bffd44 242 //! @param thePresentation [in] the presentation to fill with graphical primitives.
243 //! @param theExtensionSize [in] the size of extension line.
244 //! @param theExtensionStart [in] the point where extension line connects to dimension.
245 //! @param theExtensionDir [in] the direction of extension line.
fe83e1ea 246 //! @param theLabelString [in] the string with value.
247 //! @param theLabelWidth [in] the geometrical width computed for value string.
d7bffd44 248 //! @param theMode [in] the display mode.
249 //! @param theLabelPosition [in] position flags for the text label.
250 Standard_EXPORT void drawExtension (const Handle(Prs3d_Presentation)& thePresentation,
251 const Standard_Real theExtensionSize,
252 const gp_Pnt& theExtensionStart,
253 const gp_Dir& theExtensionDir,
fe83e1ea 254 const TCollection_ExtendedString& theLabelString,
255 const Standard_Real theLabelWidth,
256 const Standard_Integer theMode,
d7bffd44 257 const Standard_Integer theLabelPosition);
a6eb515f 258
259 //! Performs computing of linear dimension (for length, diameter, radius and so on)
260 Standard_EXPORT void drawLinearDimension (const Handle(Prs3d_Presentation)& thePresentation,
fe83e1ea 261 const Standard_Integer theMode,
a6eb515f 262 const Standard_Boolean isOneSideDimension = Standard_False);
263
264 //! If it's possible computes circle from planar face
265 Standard_EXPORT Standard_Boolean circleFromPlanarFace (const TopoDS_Face& theFace,
266 Handle(Geom_Curve)& theCurve,
267 gp_Pnt & theFirstPoint,
268 gp_Pnt & theLastPoint);
269
270 //! Performs initialization of circle and points from given shape
271 //! (for radius, diameter and so on)
272 Standard_EXPORT Standard_Boolean initCircularDimension (const TopoDS_Shape& theShape,
273 gp_Circ& theCircle,
274 gp_Pnt& theMiddleArcPoint,
275 gp_Pnt& theOppositeDiameterPoint);
276 Standard_EXPORT Standard_Boolean isComputed() const;
277
278 Standard_EXPORT void setComputed (Standard_Boolean isComputed);
279
a6eb515f 280 Standard_EXPORT void resetGeom();
281
62b6361a 282 //! Fills sensitive entity for flyouts and adds it to the selection.
283 Standard_EXPORT virtual void computeFlyoutSelection (const Handle(SelectMgr_Selection)& theSelection,
fe83e1ea 284 const Handle(SelectMgr_EntityOwner)& theOwner);
285
286 //! Produce points for triangular arrow face.
287 //! @param thePeakPnt [in] the arrow peak position.
288 //! @param theDirection [in] the arrow direction.
289 //! @param thePlane [in] the face plane.
290 //! @param theArrowLength [in] the length of arrow.
291 //! @param theArrowAngle [in] the angle of arrow.
292 //! @param thePeakPnt [in] the arrow peak point.
293 //! @param theSidePnt1 [in] the first side point.
294 //! @param theSidePnt2 [in] the second side point.
295 Standard_EXPORT void PointsForArrow (const gp_Pnt& thePeakPnt,
296 const gp_Dir& theDirection,
297 const gp_Dir& thePlane,
298 const Standard_Real theArrowLength,
299 const Standard_Real theArrowAngle,
300 gp_Pnt& theSidePnt1,
301 gp_Pnt& theSidePnt2);
a6eb515f 302
d7bffd44 303protected: //! @name Working plane properties
a6eb515f 304
305 //! Dimension default plane
306 gp_Pln myDefaultPlane;
d7bffd44 307
a6eb515f 308 //! Shows if working plane is set custom
309 Standard_Boolean myIsWorkingPlaneCustom;
310
d7bffd44 311protected: //! @name Value properties
a6eb515f 312
313 //! Dimension value which is displayed with dimension lines
314 Standard_Real myValue;
d7bffd44 315
a6eb515f 316 //! Shows if the value is set by user and is no need to count it automatically
317 Standard_Boolean myIsValueCustom;
318
d7bffd44 319protected: // !@name Units properties
a6eb515f 320
321 //! The quantity of units for the value computation
322 TCollection_AsciiString myUnitsQuantity;
d7bffd44 323
a6eb515f 324 //! Units of the model
325 TCollection_AsciiString myModelUnits;
d7bffd44 326
a6eb515f 327 //! Units in which the displayed value will be converted
328 TCollection_AsciiString myDisplayUnits;
d7bffd44 329
a6eb515f 330 //! Determines if units is to be displayed along with the value
331 Standard_Boolean myToDisplayUnits;
d7bffd44 332
a6eb515f 333 //! Special symbol for some kind of dimensions (for diameter, radius and so on)
334 Standard_ExtCharacter mySpecialSymbol;
d7bffd44 335
a6eb515f 336 //! Special symbol display options
337 AIS_DisplaySpecialSymbol myDisplaySpecialSymbol;
338
fe83e1ea 339protected: //! @name Selection geometry
a6eb515f 340
fe83e1ea 341 //! Selection geometry of dimension presentation. The structure is filled with data
342 //! during compute of presentation, then this data is used to generate selection
343 //! sensitives when computing selection.
344 struct SelectionGeometry
a6eb515f 345 {
fe83e1ea 346 //! Arrows are represented by directed triangles.
347 struct Arrow
348 {
349 gp_Pnt Position;
350 gp_Dir Direction;
351 };
352 typedef NCollection_Sequence<gp_Pnt> Curve;
353 typedef NCollection_Handle<Curve> HCurve;
354 typedef NCollection_Handle<Arrow> HArrow;
355 typedef NCollection_Sequence<HCurve> SeqOfCurves;
356 typedef NCollection_Sequence<HArrow> SeqOfArrows;
357
358 gp_Pnt TextPos; //!< Center of text label.
359 gp_Dir TextDir; //!< Direction of text label.
360 Standard_Real TextWidth; //!< Width of text label.
361 Standard_Real TextHeight; //!< Height of text label.
362 SeqOfCurves DimensionLine; //!< Sequence of points for composing the segments of dimension line.
363 SeqOfArrows Arrows; //!< Sequence of arrow geometries.
364
365 public:
366
367 //! Clear geometry of sensitives for the specified compute mode.
368 //! @param theMode [in] the compute mode to clear.
369 void Clear (const Standard_Integer theMode)
370 {
371 if (theMode == ComputeMode_All || theMode == ComputeMode_Line)
372 {
373 DimensionLine.Clear();
374 Arrows.Clear();
375 }
376
377 if (theMode == ComputeMode_All || theMode == ComputeMode_Text)
378 {
379 TextPos = gp::Origin();
380 TextDir = gp::DX();
381 TextWidth = 0.0;
382 TextHeight = 0.0;
383 }
384 }
385
386 //! Add new curve entry and return the referenece to populate it.
387 Curve& NewCurve()
388 {
389 DimensionLine.Append( new Curve );
390 HCurve& aLastCurve = DimensionLine.ChangeLast();
391 return *aLastCurve;
392 }
393
394 //! Add new arrow entry and return the referenece to populate it.
395 Arrow& NewArrow()
396 {
397 Arrows.Append( new Arrow );
398 HArrow& aLastArrow = Arrows.ChangeLast();
399 return *aLastArrow;
400 }
401 } mySelectionGeom;
402
403 Standard_Real mySelToleranceForText2d; //!< Sensitive point tolerance for 2d text selection.
404 Standard_Boolean myIsComputed; //!< Shows if the presentation and selection was computed.
d7bffd44 405
fe83e1ea 406protected:
a6eb515f 407
408 //! Shows if text is inverted
409 Standard_Boolean myIsTextReversed;
d7bffd44 410
a6eb515f 411 //! Points that are base for dimension.
412 //! My first point of dimension attach (belongs to shape for which dimension is computed)
413 gp_Pnt myFirstPoint;
d7bffd44 414
a6eb515f 415 //! My second point of dimension attach (belongs to shape for which dimension is computed)
416 gp_Pnt mySecondPoint;
d7bffd44 417
a6eb515f 418 //! Shows if attach points are initialized correctly
419 Standard_Boolean myIsInitialized;
d7bffd44 420
a6eb515f 421 //! First shape (can be vertex, edge or face)
422 TopoDS_Shape myFirstShape;
d7bffd44 423
a6eb515f 424 //! Second shape (can be vertex, edge or face)
425 TopoDS_Shape mySecondShape;
d7bffd44 426
a6eb515f 427 //! Number of shapes
428 Standard_Integer myShapesNumber;
d7bffd44 429
62b6361a 430 //! Defines flyout lines and direction
431 //! Flyout direction in the working plane.
432 //! Can be negative, or positive and is defined by the sign of myFlyout value.
433 //! The direction vector is counting using the working plane.
434 //! myFlyout value defined the size of flyout.
435 Standard_Real myFlyout;
d7bffd44 436
a6eb515f 437private:
d7bffd44 438
a6eb515f 439 //! Type of dimension
440 AIS_KindOfDimension myKindOfDimension;
d7bffd44 441
a6eb515f 442 //! Dimension working plane, is equal to <myDefaultPlane> if it can be computed automatically.
443 gp_Pln myWorkingPlane;
a6eb515f 444};
445#endif