0031456: Visualization - move out Dimensions and Relations from package AIS to PrsDims
[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>
27#include <gp_Pln.hxx>
28#include <Prs3d_ArrowAspect.hxx>
29#include <Prs3d_DimensionAspect.hxx>
60bf98ae 30#include <Prs3d_DimensionUnits.hxx>
6262338c 31#include <Prs3d_Drawer.hxx>
a6eb515f 32#include <Prs3d_LineAspect.hxx>
33#include <Prs3d_Presentation.hxx>
34#include <Prs3d_TextAspect.hxx>
a6eb515f 35#include <SelectMgr_EntityOwner.hxx>
36#include <Standard.hxx>
37#include <TCollection_ExtendedString.hxx>
fe83e1ea 38#include <TColgp_HSequenceOfPnt.hxx>
0499eb06 39#include <TopoDS_Edge.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
787ff240 45DEFINE_STANDARD_HANDLE(PrsDim_Dimension, AIS_InteractiveObject)
a6eb515f 46
787ff240 47//! PrsDim_Dimension is a base class for 2D presentations of linear (length, diameter, radius)
60bf98ae 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.
787ff240 133//! The component highlighting in these selection modes is provided by PrsDim_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).
787ff240 166class PrsDim_Dimension : public AIS_InteractiveObject
a6eb515f 167{
787ff240 168 DEFINE_STANDARD_RTTIEXT(PrsDim_Dimension, AIS_InteractiveObject)
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
73ddbb9a 204 enum ValueType
205 {
206 ValueType_Computed,
207 ValueType_CustomReal,
208 ValueType_CustomText
209 };
210
a6eb515f 211public:
d7bffd44 212
fe83e1ea 213 //! Specifies supported presentation compute modes.
214 //! Used to compute only parts of presentation for
215 //! advanced highlighting.
216 enum ComputeMode
217 {
218 ComputeMode_All = 0, //!< "0" is reserved as neutral mode
219 ComputeMode_Line = 1, //!< corresponds to selection mode
220 ComputeMode_Text = 2 //!< corresponds to selection mode
221 };
222
223public:
224
60bf98ae 225 //! Constructor with default parameters values.
226 //! @param theType [in] the type of dimension.
787ff240 227 Standard_EXPORT PrsDim_Dimension (const PrsDim_KindOfDimension theType);
a6eb515f 228
60bf98ae 229 //! Gets dimension measurement value. If the value to display is not
230 //! specified by user, then the dimension object is responsible to
231 //! compute it on its own in model space coordinates.
232 //! @return the dimension value (in model units) which is used
233 //! during display of the presentation.
234 Standard_Real GetValue() const
235 {
73ddbb9a 236 return myValueType == ValueType_CustomReal ? myCustomValue : ComputeValue();
237 }
238
239 //! Sets computed dimension value. Resets custom value mode if it was set.
240 void SetComputedValue ()
241 {
242 myValueType = ValueType_Computed;
60bf98ae 243 }
a6eb515f 244
60bf98ae 245 //! Sets user-defined dimension value.
246 //! The user-defined dimension value is specified in model space,
247 //! and affect by unit conversion during the display.
248 //! @param theValue [in] the user-defined value to display.
249 Standard_EXPORT void SetCustomValue (const Standard_Real theValue);
250
73ddbb9a 251 //! Sets user-defined dimension value.
252 //! Unit conversion during the display is not applyed.
253 //! @param theValue [in] the user-defined value to display.
254 Standard_EXPORT void SetCustomValue (const TCollection_ExtendedString& theValue);
255
256 //! Gets user-defined dimension value.
257 //! @return dimension value string.
787ff240 258 const TCollection_ExtendedString& GetCustomValue() const { return myCustomStringValue; }
73ddbb9a 259
60bf98ae 260 //! Get the dimension plane in which the 2D dimension presentation is computed.
261 //! By default, if plane is not defined by user, it is computed automatically
262 //! after dimension geometry is computed.
263 //! If computed dimension geometry (points) can't be placed on the user-defined
af203d54 264 //! plane, dimension geometry was set as invalid (validity flag is set to false)
265 //! and dimension presentation will not be computed.
60bf98ae 266 //! If user-defined plane allow geometry placement on it, it will be used for
267 //! computing of the dimension presentation.
268 //! @return dimension plane used for presentation computing.
787ff240 269 const gp_Pln& GetPlane() const { return myPlane; }
60bf98ae 270
271 //! Geometry type defines type of shapes on which the dimension is to be built.
272 //! @return type of geometry on which the dimension will be built.
487bf1ce 273 Standard_Integer GetGeometryType () const { return myGeometryType; }
60bf98ae 274
275 //! Sets user-defined plane where the 2D dimension presentation will be placed.
276 //! Checks validity of this plane if geometry has been set already.
277 //! Validity of the plane is checked according to the geometry set
278 //! and has different criteria for different kinds of dimensions.
279 Standard_EXPORT virtual void SetCustomPlane (const gp_Pln& thePlane);
280
281 //! Unsets user-defined plane. Therefore the plane for dimension will be
282 //! computed automatically.
0f57ab75 283 void UnsetCustomPlane() { myIsPlaneCustom = Standard_False; }
a6eb515f 284
af203d54 285 //! @return TRUE if text position is set by user with method SetTextPosition().
286 Standard_Boolean IsTextPositionCustom() const
287 {
288 return myIsTextPositionFixed;
289 }
290
291 //! Fixes the absolute text position and adjusts flyout, plane and text alignment
292 //! according to it. Updates presentation if the text position is valid.
293 //! ATTENTION! It does not change vertical text alignment.
294 //! @param theTextPos [in] the point of text position.
295 virtual void SetTextPosition (const gp_Pnt& /*theTextPos*/) { }
296
297 //! Computes absolute text position from dimension parameters
298 //! (flyout, plane and text alignment).
787ff240 299 virtual gp_Pnt GetTextPosition () const { return gp_Pnt(); }
af203d54 300
60bf98ae 301public:
a6eb515f 302
303 //! Gets the dimension aspect from AIS object drawer.
304 //! Dimension aspect contains aspects of line, text and arrows for dimension presentation.
60bf98ae 305 Handle(Prs3d_DimensionAspect) DimensionAspect() const
306 {
307 return myDrawer->DimensionAspect();
308 }
a6eb515f 309
60bf98ae 310 //! Sets new dimension aspect for the interactive object drawer.
311 //! The dimension aspect provides dynamic properties which are generally
312 //! used during computation of dimension presentations.
313 Standard_EXPORT void SetDimensionAspect (const Handle(Prs3d_DimensionAspect)& theDimensionAspect);
a6eb515f 314
60bf98ae 315 //! @return the kind of dimension.
787ff240 316 PrsDim_KindOfDimension KindOfDimension() const { return myKindOfDimension; }
a6eb515f 317
60bf98ae 318 //! @return the kind of interactive.
787ff240 319 virtual AIS_KindOfInteractive Type() const Standard_OVERRIDE { return AIS_KOI_Dimension; }
a6eb515f 320
321 //! Returns true if the class of objects accepts the display mode theMode.
60bf98ae 322 //! The interactive context can have a default mode of representation for
323 //! the set of Interactive Objects. This mode may not be accepted by object.
79104795 324 virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE
60bf98ae 325 {
326 return theMode == ComputeMode_All;
327 }
d7bffd44 328
60bf98ae 329public:
d7bffd44 330
60bf98ae 331 //! @return dimension special symbol display options.
787ff240 332 PrsDim_DisplaySpecialSymbol DisplaySpecialSymbol() const { return myDisplaySpecialSymbol; }
d7bffd44 333
60bf98ae 334 //! Specifies whether to display special symbol or not.
787ff240 335 Standard_EXPORT void SetDisplaySpecialSymbol (const PrsDim_DisplaySpecialSymbol theDisplaySpecSymbol);
d7bffd44 336
60bf98ae 337 //! @return special symbol.
338 Standard_ExtCharacter SpecialSymbol() const
339 {
340 return mySpecialSymbol;
341 }
d7bffd44 342
60bf98ae 343 //! Specifies special symbol.
344 Standard_EXPORT void SetSpecialSymbol (const Standard_ExtCharacter theSpecialSymbol);
d7bffd44 345
60bf98ae 346 Standard_EXPORT virtual const TCollection_AsciiString& GetDisplayUnits() const;
d7bffd44 347
60bf98ae 348 Standard_EXPORT virtual const TCollection_AsciiString& GetModelUnits() const;
d7bffd44 349
0f57ab75 350 virtual void SetDisplayUnits (const TCollection_AsciiString& /*theUnits*/) { }
d7bffd44 351
0f57ab75 352 virtual void SetModelUnits (const TCollection_AsciiString& /*theUnits*/) { }
d7bffd44 353
af203d54 354 //! Unsets user defined text positioning and enables text positioning
355 //! by other parameters: text alignment, extension size, flyout and custom plane.
356 Standard_EXPORT void UnsetFixedTextPosition();
357
60bf98ae 358public:
d7bffd44 359
60bf98ae 360 //! Returns selection tolerance for text2d:
361 //! For 2d text selection detection sensitive point with tolerance is used
362 //! Important! Only for 2d text.
363 Standard_Real SelToleranceForText2d() const
364 {
365 return mySelToleranceForText2d;
366 }
d7bffd44 367
a6eb515f 368 //! Sets selection tolerance for text2d:
369 //! For 2d text selection detection sensitive point with tolerance is used
370 //! to change this tolerance use this method
60bf98ae 371 //! Important! Only for 2d text.
372 Standard_EXPORT void SetSelToleranceForText2d (const Standard_Real theTol);
d7bffd44 373
60bf98ae 374 //! @return flyout value for dimension.
375 Standard_Real GetFlyout() const
376 {
377 return myFlyout;
378 }
d7bffd44 379
60bf98ae 380 //! Sets flyout value for dimension.
62b6361a 381 Standard_EXPORT void SetFlyout (const Standard_Real theFlyout);
d7bffd44 382
60bf98ae 383 //! Check that the input geometry for dimension is valid and the
af203d54 384 //! presentation can be successfully computed.
60bf98ae 385 //! @return TRUE if dimension geometry is ok.
91b16a64 386 virtual Standard_Boolean IsValid() const
d7bffd44 387 {
91b16a64 388 return myIsGeometryValid && CheckPlane (GetPlane());
d7bffd44 389 }
390
a6eb515f 391protected:
d7bffd44 392
60bf98ae 393 Standard_EXPORT Standard_Real ValueToDisplayUnits() const;
a6eb515f 394
60bf98ae 395 //! Get formatted value string and its model space width.
396 //! @param theWidth [out] the model space with of the string.
397 //! @return formatted dimension value string.
398 Standard_EXPORT TCollection_ExtendedString GetValueString (Standard_Real& theWidth) const;
a6eb515f 399
400 //! Performs drawing of 2d or 3d arrows on the working plane
60bf98ae 401 //! @param theLocation [in] the location of the arrow tip.
402 //! @param theDirection [in] the direction from the tip to the bottom of the arrow.
403 Standard_EXPORT void DrawArrow (const Handle(Prs3d_Presentation)& thePresentation,
a6eb515f 404 const gp_Pnt& theLocation,
405 const gp_Dir& theDirection);
406
407 //! Performs drawing of 2d or 3d text on the working plane
60bf98ae 408 //! @param theTextPos [in] the position of the text label.
409 //! @param theTestDir [in] the direction of the text label.
410 //! @param theText [in] the text label string.
411 //! @param theLabelPosition [in] the text label vertical and horizontal positioning option
412 //! respectively to the main dimension line.
a6eb515f 413 //! @return text width relative to the dimension working plane. For 2d text this value will be zero.
7c65581d 414 Standard_EXPORT void drawText (const Handle(Prs3d_Presentation)& thePresentation,
fe83e1ea 415 const gp_Pnt& theTextPos,
416 const gp_Dir& theTextDir,
417 const TCollection_ExtendedString& theText,
418 const Standard_Integer theLabelPosition);
a6eb515f 419
420 //! Performs computing of dimension linear extension with text
d7bffd44 421 //! @param thePresentation [in] the presentation to fill with graphical primitives.
422 //! @param theExtensionSize [in] the size of extension line.
423 //! @param theExtensionStart [in] the point where extension line connects to dimension.
424 //! @param theExtensionDir [in] the direction of extension line.
fe83e1ea 425 //! @param theLabelString [in] the string with value.
426 //! @param theLabelWidth [in] the geometrical width computed for value string.
d7bffd44 427 //! @param theMode [in] the display mode.
428 //! @param theLabelPosition [in] position flags for the text label.
60bf98ae 429 Standard_EXPORT void DrawExtension (const Handle(Prs3d_Presentation)& thePresentation,
d7bffd44 430 const Standard_Real theExtensionSize,
431 const gp_Pnt& theExtensionStart,
432 const gp_Dir& theExtensionDir,
fe83e1ea 433 const TCollection_ExtendedString& theLabelString,
434 const Standard_Real theLabelWidth,
435 const Standard_Integer theMode,
d7bffd44 436 const Standard_Integer theLabelPosition);
a6eb515f 437
60bf98ae 438 //! Performs computing of linear dimension (for length, diameter, radius and so on).
439 //! Please note that this method uses base dimension properties, like working plane
440 //! flyout length, drawer attributes.
441 //! @param thePresentation [in] the presentation to fill with primitives.
442 //! @param theMode [in] the presentation compute mode.
443 //! @param theFirstPoint [in] the first attach point of linear dimension.
444 //! @param theSecondPoint [in] the second attach point of linear dimension.
445 //! @param theIsOneSide [in] specifies whether the dimension has only one flyout line.
446 Standard_EXPORT void DrawLinearDimension (const Handle(Prs3d_Presentation)& thePresentation,
fe83e1ea 447 const Standard_Integer theMode,
60bf98ae 448 const gp_Pnt& theFirstPoint,
449 const gp_Pnt& theSecondPoint,
450 const Standard_Boolean theIsOneSide = Standard_False);
451
948c552a 452 //! Computes points bounded the flyout line for linear dimension.
453 //! @param theFirstPoint [in] the first attach point of linear dimension.
454 //! @param theSecondPoint [in] the second attach point of linear dimension.
455 //! @param theLineBegPoint [out] the first attach point of linear dimension.
456 //! @param theLineEndPoint [out] the second attach point of linear dimension.
457 Standard_EXPORT virtual void ComputeFlyoutLinePoints (const gp_Pnt& theFirstPoint, const gp_Pnt& theSecondPoint,
458 gp_Pnt& theLineBegPoint, gp_Pnt& theLineEndPoint);
459
60bf98ae 460 //! Compute selection sensitives for linear dimension flyout lines (length, diameter, radius).
461 //! Please note that this method uses base dimension properties: working plane and flyout length.
462 //! @param theSelection [in] the selection structure to fill with selection primitives.
463 //! @param theOwner [in] the selection entity owner.
464 //! @param theFirstPoint [in] the first attach point of linear dimension.
465 //! @param theSecondPoint [in] the second attach point of linear dimension.
466 Standard_EXPORT void ComputeLinearFlyouts (const Handle(SelectMgr_Selection)& theSelection,
467 const Handle(SelectMgr_EntityOwner)& theOwner,
468 const gp_Pnt& theFirstPoint,
469 const gp_Pnt& theSecondPoint);
470
60bf98ae 471
472 //! Performs initialization of circle and middle arc point from the passed
473 //! shape which is assumed to contain circular geometry.
474 //! @param theShape [in] the shape to explore.
475 //! @param theCircle [out] the circle geometry.
476 //! @param theMiddleArcPoint [out] the middle point of the arc.
477 //! @param theIsClosed [out] returns TRUE if the geometry is closed circle.
478 //! @return TRUE if the the circle is successfully got from the input shape.
479 Standard_EXPORT Standard_Boolean InitCircularDimension (const TopoDS_Shape& theShape,
480 gp_Circ& theCircle,
481 gp_Pnt& theMiddleArcPoint,
482 Standard_Boolean& theIsClosed);
af203d54 483
484 //! Produce points for triangular arrow face.
485 //! @param thePeakPnt [in] the arrow peak position.
486 //! @param theDirection [in] the arrow direction.
487 //! @param thePlane [in] the face plane.
488 //! @param theArrowLength [in] the length of arrow.
489 //! @param theArrowAngle [in] the angle of arrow.
490 //! @param theSidePnt1 [out] the first side point.
491 //! @param theSidePnt2 [out] the second side point.
492 Standard_EXPORT void PointsForArrow (const gp_Pnt& thePeakPnt,
493 const gp_Dir& theDirection,
494 const gp_Dir& thePlane,
495 const Standard_Real theArrowLength,
496 const Standard_Real theArrowAngle,
497 gp_Pnt& theSidePnt1,
498 gp_Pnt& theSidePnt2);
499
500 //! Compute point of text position for dimension parameters
501 //! for linear kinds of dimensions (length, radius, diameter).
502 Standard_EXPORT gp_Pnt GetTextPositionForLinear (const gp_Pnt& theFirstPoint,
503 const gp_Pnt& theSecondPoint,
504 const Standard_Boolean theIsOneSide = Standard_False) const;
505
506 //! Fits text alignment relatively to the dimension line.
507 //! @param theFirstPoint [in] the first attachment point.
508 //! @param theSecondPoint [in] the second attachment point.
509 //! @param theIsOneSide [in] is the arrow displayed only on the one side of the dimension.
510 //! @param theHorizontalTextPos [in] the text horizontal position (alignment).
511 //! @param theLabelPosition [out] the label position, contains bits that defines
512 //! vertical and horizontal alignment. (for internal usage in count text position)
513 //! @param theIsArrowExternal [out] is the arrows external,
514 //! if arrow orientation in the dimension aspect is Prs3d_DAO_Fit, it fits arrow
515 //! orientation automatically.
91b16a64 516 Standard_EXPORT void FitTextAlignmentForLinear (const gp_Pnt& theFirstPoint,
517 const gp_Pnt& theSecondPoint,
518 const Standard_Boolean theIsOneSide,
519 const Prs3d_DimensionTextHorizontalPosition& theHorizontalTextPos,
520 Standard_Integer& theLabelPosition,
521 Standard_Boolean& theIsArrowsExternal) const;
af203d54 522
523 //! Adjusts aspect parameters according the text position:
524 //! extension size, vertical text alignment and flyout.
af203d54 525 //! @param theTextPos [in] the user defined 3d point of text position
526 //! @param theFirstPoint [in] the first point of linear measurement.
527 //! @param theSecondPoint [in] the second point of linear measurement.
528 //! @param theExtensionSize [out] the adjusted extension size
529 //! @param theAlignment [out] the horizontal label alignment.
91b16a64 530 //! @param theFlyout [out] the adjusted value of flyout.
531 //! @param thePlane [out] the new plane that contains theTextPos and attachment points.
532 //! @param theIsPlaneOld [out] shows if new plane is computed.
533 Standard_EXPORT Standard_Boolean AdjustParametersForLinear (const gp_Pnt& theTextPos,
534 const gp_Pnt& theFirstPoint,
535 const gp_Pnt& theSecondPoint,
536 Standard_Real& theExtensionSize,
537 Prs3d_DimensionTextHorizontalPosition& theAlignment,
538 Standard_Real& theFlyout,
539 gp_Pln& thePlane,
540 Standard_Boolean& theIsPlaneOld) const;
60bf98ae 541
0499eb06 542protected: //! @name Static auxilliary methods for geometry extraction
543
544 //! If it is possible extracts circle from planar face.
545 //! @param theFace [in] the planar face
546 //! @param theCurve [out] the circular curve
547 //! @param theFirstPoint [out] the point of the first parameter of the circlular curve
548 //! @param theSecondPoint [out] the point of the last parameter of the circlular curve
549 //! @return TRUE in case of successful circle extraction
550 static Standard_Boolean CircleFromPlanarFace (const TopoDS_Face& theFace,
551 Handle(Geom_Curve)& theCurve,
552 gp_Pnt& theFirstPoint,
553 gp_Pnt& theLastPoint);
554
555 //! If it is possible extracts circle from the edge.
556 //! @param theEdge [in] input edge to extract circle from
557 //! @param theCircle [out] circle
558 //! @param theFirstPoint [out] the point of the first parameter of the circlular curve
559 //! @param theSecondPoint [out] the point of the last parameter of the circlular curve
560 //! @return TRUE in case of successful circle extraction.
561 static Standard_Boolean CircleFromEdge (const TopoDS_Edge& theEdge,
562 gp_Circ& theCircle,
563 gp_Pnt& theFirstPoint,
564 gp_Pnt& theLastPoint);
565
60bf98ae 566protected: //! @name Behavior to implement
567
60bf98ae 568 //! Override this method to check if user-defined plane
569 //! is valid for the dimension geometry.
570 //! @param thePlane [in] the working plane for positioning every
571 //! dimension in the application.
572 //! @return true is the plane is suitable for building dimension
573 //! with computed dimension geometry.
574 virtual Standard_Boolean CheckPlane (const gp_Pln& /*thePlane*/) const { return Standard_True; }
575
576 //! Override this method to computed value of dimension.
577 //! @return value from the measured geometry.
578 virtual Standard_Real ComputeValue() const
579 {
580 return 0.0;
581 }
a6eb515f 582
60bf98ae 583 //! Override this method to compute selection primitives for
584 //! flyout lines (if the dimension provides it).
585 //! This callback is a only a part of base selection
586 //! computation routine.
587 virtual void ComputeFlyoutSelection (const Handle(SelectMgr_Selection)&,
588 const Handle(SelectMgr_EntityOwner)&) {}
fe83e1ea 589
a6eb515f 590
60bf98ae 591 //! Base procedure of computing selection (based on selection geometry data).
592 //! @param theSelection [in] the selection structure to will with primitives.
593 //! @param theMode [in] the selection mode.
594 Standard_EXPORT virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
79104795 595 const Standard_Integer theMode) Standard_OVERRIDE;
a6eb515f 596
fe83e1ea 597protected: //! @name Selection geometry
a6eb515f 598
fe83e1ea 599 //! Selection geometry of dimension presentation. The structure is filled with data
600 //! during compute of presentation, then this data is used to generate selection
601 //! sensitives when computing selection.
602 struct SelectionGeometry
a6eb515f 603 {
fe83e1ea 604 //! Arrows are represented by directed triangles.
605 struct Arrow
606 {
607 gp_Pnt Position;
608 gp_Dir Direction;
609 };
610 typedef NCollection_Sequence<gp_Pnt> Curve;
611 typedef NCollection_Handle<Curve> HCurve;
612 typedef NCollection_Handle<Arrow> HArrow;
613 typedef NCollection_Sequence<HCurve> SeqOfCurves;
614 typedef NCollection_Sequence<HArrow> SeqOfArrows;
615
616 gp_Pnt TextPos; //!< Center of text label.
617 gp_Dir TextDir; //!< Direction of text label.
618 Standard_Real TextWidth; //!< Width of text label.
619 Standard_Real TextHeight; //!< Height of text label.
620 SeqOfCurves DimensionLine; //!< Sequence of points for composing the segments of dimension line.
621 SeqOfArrows Arrows; //!< Sequence of arrow geometries.
91b16a64 622 Standard_Boolean IsComputed; //!< Shows if the selection geometry was filled.
fe83e1ea 623
624 public:
625
626 //! Clear geometry of sensitives for the specified compute mode.
627 //! @param theMode [in] the compute mode to clear.
628 void Clear (const Standard_Integer theMode)
629 {
630 if (theMode == ComputeMode_All || theMode == ComputeMode_Line)
631 {
632 DimensionLine.Clear();
633 Arrows.Clear();
634 }
635
636 if (theMode == ComputeMode_All || theMode == ComputeMode_Text)
637 {
638 TextPos = gp::Origin();
639 TextDir = gp::DX();
640 TextWidth = 0.0;
641 TextHeight = 0.0;
642 }
91b16a64 643
644 IsComputed = Standard_False;
fe83e1ea 645 }
646
af203d54 647 //! Add new curve entry and return the reference to populate it.
fe83e1ea 648 Curve& NewCurve()
649 {
650 DimensionLine.Append( new Curve );
651 HCurve& aLastCurve = DimensionLine.ChangeLast();
652 return *aLastCurve;
653 }
654
af203d54 655 //! Add new arrow entry and return the reference to populate it.
fe83e1ea 656 Arrow& NewArrow()
657 {
658 Arrows.Append( new Arrow );
659 HArrow& aLastArrow = Arrows.ChangeLast();
660 return *aLastArrow;
661 }
662 } mySelectionGeom;
663
664 Standard_Real mySelToleranceForText2d; //!< Sensitive point tolerance for 2d text selection.
d7bffd44 665
60bf98ae 666protected: //! @name Value properties
d7bffd44 667
73ddbb9a 668 ValueType myValueType; //! type of value (computed or user-defined)
60bf98ae 669 Standard_Real myCustomValue; //!< Value of the dimension (computed or user-defined).
73ddbb9a 670
671 TCollection_ExtendedString myCustomStringValue; //!< Value of the dimension (computed or user-defined).
d7bffd44 672
af203d54 673protected: //! @name Fixed text position properties
674
675 gp_Pnt myFixedTextPosition; //!< Stores text position fixed by user.
676 Standard_Boolean myIsTextPositionFixed; //!< Is the text label position fixed by user.
677
60bf98ae 678protected: //! @name Units properties
d7bffd44 679
787ff240 680 Standard_ExtCharacter mySpecialSymbol; //!< Special symbol.
681 PrsDim_DisplaySpecialSymbol myDisplaySpecialSymbol; //!< Special symbol display options.
d7bffd44 682
60bf98ae 683protected: //! @name Geometrical properties
d7bffd44 684
60bf98ae 685 GeometryType myGeometryType; //!< defines type of shapes on which the dimension is to be built.
d7bffd44 686
91b16a64 687 gp_Pln myPlane; //!< Plane where dimension will be built (computed or user defined).
688 Standard_Boolean myIsPlaneCustom; //!< Is plane defined by user (otherwise it will be computed automatically).
689 Standard_Real myFlyout; //!< Flyout distance.
690 Standard_Boolean myIsGeometryValid; //!< Is dimension geometry properly defined.
d7bffd44 691
a6eb515f 692private:
d7bffd44 693
787ff240 694 PrsDim_KindOfDimension myKindOfDimension;
a6eb515f 695};
60bf98ae 696
787ff240 697#endif // _PrsDim_Dimension_HeaderFile