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