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