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> |
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 | |
c04c30b3 |
45 | class AIS_Dimension; |
a6eb515f |
46 | DEFINE_STANDARD_HANDLE(AIS_Dimension, AIS_InteractiveObject) |
47 | |
60bf98ae |
48 | //! AIS_Dimension is a base class for 2D presentations of linear (length, diameter, radius) |
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. |
af203d54 |
134 | //! The component highlighting in these selection modes is provided by AIS_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. |
152 | //! ATTENSION! myIsFixedTextPosition fixes all parameters of the set from recomputing inside |
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). |
167 | //! |
a6eb515f |
168 | class AIS_Dimension : public AIS_InteractiveObject |
169 | { |
d7bffd44 |
170 | protected: |
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 |
212 | public: |
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 |
224 | public: |
d7bffd44 |
225 | |
60bf98ae |
226 | //! Constructor with default parameters values. |
227 | //! @param theType [in] the type of dimension. |
228 | Standard_EXPORT AIS_Dimension (const AIS_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. |
253 | //! Unit conversion during the display is not applyed. |
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. |
259 | Standard_EXPORT const TCollection_ExtendedString& GetCustomValue () const; |
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. |
270 | Standard_EXPORT const gp_Pln& GetPlane() const; |
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). |
300 | virtual const gp_Pnt GetTextPosition () const { return gp_Pnt(); } |
301 | |
60bf98ae |
302 | public: |
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. |
317 | AIS_KindOfDimension KindOfDimension() const |
318 | { |
319 | return myKindOfDimension; |
320 | } |
a6eb515f |
321 | |
60bf98ae |
322 | //! @return the kind of interactive. |
79104795 |
323 | virtual AIS_KindOfInteractive Type() const Standard_OVERRIDE |
60bf98ae |
324 | { |
af203d54 |
325 | return AIS_KOI_Dimension; |
60bf98ae |
326 | } |
a6eb515f |
327 | |
328 | //! Returns true if the class of objects accepts the display mode theMode. |
60bf98ae |
329 | //! The interactive context can have a default mode of representation for |
330 | //! the set of Interactive Objects. This mode may not be accepted by object. |
79104795 |
331 | virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE |
60bf98ae |
332 | { |
333 | return theMode == ComputeMode_All; |
334 | } |
d7bffd44 |
335 | |
60bf98ae |
336 | public: |
d7bffd44 |
337 | |
60bf98ae |
338 | //! @return dimension special symbol display options. |
339 | AIS_DisplaySpecialSymbol DisplaySpecialSymbol() const |
340 | { |
341 | return myDisplaySpecialSymbol; |
342 | } |
d7bffd44 |
343 | |
60bf98ae |
344 | //! Specifies whether to display special symbol or not. |
345 | Standard_EXPORT void SetDisplaySpecialSymbol (const AIS_DisplaySpecialSymbol theDisplaySpecSymbol); |
d7bffd44 |
346 | |
60bf98ae |
347 | //! @return special symbol. |
348 | Standard_ExtCharacter SpecialSymbol() const |
349 | { |
350 | return mySpecialSymbol; |
351 | } |
d7bffd44 |
352 | |
60bf98ae |
353 | //! Specifies special symbol. |
354 | Standard_EXPORT void SetSpecialSymbol (const Standard_ExtCharacter theSpecialSymbol); |
d7bffd44 |
355 | |
60bf98ae |
356 | Standard_EXPORT virtual const TCollection_AsciiString& GetDisplayUnits() const; |
d7bffd44 |
357 | |
60bf98ae |
358 | Standard_EXPORT virtual const TCollection_AsciiString& GetModelUnits() const; |
d7bffd44 |
359 | |
0f57ab75 |
360 | virtual void SetDisplayUnits (const TCollection_AsciiString& /*theUnits*/) { } |
d7bffd44 |
361 | |
0f57ab75 |
362 | virtual void SetModelUnits (const TCollection_AsciiString& /*theUnits*/) { } |
d7bffd44 |
363 | |
af203d54 |
364 | //! Unsets user defined text positioning and enables text positioning |
365 | //! by other parameters: text alignment, extension size, flyout and custom plane. |
366 | Standard_EXPORT void UnsetFixedTextPosition(); |
367 | |
60bf98ae |
368 | public: |
d7bffd44 |
369 | |
60bf98ae |
370 | //! Returns selection tolerance for text2d: |
371 | //! For 2d text selection detection sensitive point with tolerance is used |
372 | //! Important! Only for 2d text. |
373 | Standard_Real SelToleranceForText2d() const |
374 | { |
375 | return mySelToleranceForText2d; |
376 | } |
d7bffd44 |
377 | |
a6eb515f |
378 | //! Sets selection tolerance for text2d: |
379 | //! For 2d text selection detection sensitive point with tolerance is used |
380 | //! to change this tolerance use this method |
60bf98ae |
381 | //! Important! Only for 2d text. |
382 | Standard_EXPORT void SetSelToleranceForText2d (const Standard_Real theTol); |
d7bffd44 |
383 | |
60bf98ae |
384 | //! @return flyout value for dimension. |
385 | Standard_Real GetFlyout() const |
386 | { |
387 | return myFlyout; |
388 | } |
d7bffd44 |
389 | |
60bf98ae |
390 | //! Sets flyout value for dimension. |
62b6361a |
391 | Standard_EXPORT void SetFlyout (const Standard_Real theFlyout); |
d7bffd44 |
392 | |
60bf98ae |
393 | //! Check that the input geometry for dimension is valid and the |
af203d54 |
394 | //! presentation can be successfully computed. |
60bf98ae |
395 | //! @return TRUE if dimension geometry is ok. |
91b16a64 |
396 | virtual Standard_Boolean IsValid() const |
d7bffd44 |
397 | { |
91b16a64 |
398 | return myIsGeometryValid && CheckPlane (GetPlane()); |
d7bffd44 |
399 | } |
400 | |
401 | public: |
a6eb515f |
402 | |
92efcf78 |
403 | DEFINE_STANDARD_RTTIEXT(AIS_Dimension,AIS_InteractiveObject) |
a6eb515f |
404 | |
405 | protected: |
d7bffd44 |
406 | |
60bf98ae |
407 | Standard_EXPORT Standard_Real ValueToDisplayUnits() const; |
a6eb515f |
408 | |
60bf98ae |
409 | //! Get formatted value string and its model space width. |
410 | //! @param theWidth [out] the model space with of the string. |
411 | //! @return formatted dimension value string. |
412 | Standard_EXPORT TCollection_ExtendedString GetValueString (Standard_Real& theWidth) const; |
a6eb515f |
413 | |
414 | //! Performs drawing of 2d or 3d arrows on the working plane |
60bf98ae |
415 | //! @param theLocation [in] the location of the arrow tip. |
416 | //! @param theDirection [in] the direction from the tip to the bottom of the arrow. |
417 | Standard_EXPORT void DrawArrow (const Handle(Prs3d_Presentation)& thePresentation, |
a6eb515f |
418 | const gp_Pnt& theLocation, |
419 | const gp_Dir& theDirection); |
420 | |
421 | //! Performs drawing of 2d or 3d text on the working plane |
60bf98ae |
422 | //! @param theTextPos [in] the position of the text label. |
423 | //! @param theTestDir [in] the direction of the text label. |
424 | //! @param theText [in] the text label string. |
425 | //! @param theLabelPosition [in] the text label vertical and horizontal positioning option |
426 | //! respectively to the main dimension line. |
a6eb515f |
427 | //! @return text width relative to the dimension working plane. For 2d text this value will be zero. |
7c65581d |
428 | Standard_EXPORT void drawText (const Handle(Prs3d_Presentation)& thePresentation, |
fe83e1ea |
429 | const gp_Pnt& theTextPos, |
430 | const gp_Dir& theTextDir, |
431 | const TCollection_ExtendedString& theText, |
432 | const Standard_Integer theLabelPosition); |
a6eb515f |
433 | |
434 | //! Performs computing of dimension linear extension with text |
d7bffd44 |
435 | //! @param thePresentation [in] the presentation to fill with graphical primitives. |
436 | //! @param theExtensionSize [in] the size of extension line. |
437 | //! @param theExtensionStart [in] the point where extension line connects to dimension. |
438 | //! @param theExtensionDir [in] the direction of extension line. |
fe83e1ea |
439 | //! @param theLabelString [in] the string with value. |
440 | //! @param theLabelWidth [in] the geometrical width computed for value string. |
d7bffd44 |
441 | //! @param theMode [in] the display mode. |
442 | //! @param theLabelPosition [in] position flags for the text label. |
60bf98ae |
443 | Standard_EXPORT void DrawExtension (const Handle(Prs3d_Presentation)& thePresentation, |
d7bffd44 |
444 | const Standard_Real theExtensionSize, |
445 | const gp_Pnt& theExtensionStart, |
446 | const gp_Dir& theExtensionDir, |
fe83e1ea |
447 | const TCollection_ExtendedString& theLabelString, |
448 | const Standard_Real theLabelWidth, |
449 | const Standard_Integer theMode, |
d7bffd44 |
450 | const Standard_Integer theLabelPosition); |
a6eb515f |
451 | |
60bf98ae |
452 | //! Performs computing of linear dimension (for length, diameter, radius and so on). |
453 | //! Please note that this method uses base dimension properties, like working plane |
454 | //! flyout length, drawer attributes. |
455 | //! @param thePresentation [in] the presentation to fill with primitives. |
456 | //! @param theMode [in] the presentation compute mode. |
457 | //! @param theFirstPoint [in] the first attach point of linear dimension. |
458 | //! @param theSecondPoint [in] the second attach point of linear dimension. |
459 | //! @param theIsOneSide [in] specifies whether the dimension has only one flyout line. |
460 | Standard_EXPORT void DrawLinearDimension (const Handle(Prs3d_Presentation)& thePresentation, |
fe83e1ea |
461 | const Standard_Integer theMode, |
60bf98ae |
462 | const gp_Pnt& theFirstPoint, |
463 | const gp_Pnt& theSecondPoint, |
464 | const Standard_Boolean theIsOneSide = Standard_False); |
465 | |
948c552a |
466 | //! Computes points bounded the flyout line for linear dimension. |
467 | //! @param theFirstPoint [in] the first attach point of linear dimension. |
468 | //! @param theSecondPoint [in] the second attach point of linear dimension. |
469 | //! @param theLineBegPoint [out] the first attach point of linear dimension. |
470 | //! @param theLineEndPoint [out] the second attach point of linear dimension. |
471 | Standard_EXPORT virtual void ComputeFlyoutLinePoints (const gp_Pnt& theFirstPoint, const gp_Pnt& theSecondPoint, |
472 | gp_Pnt& theLineBegPoint, gp_Pnt& theLineEndPoint); |
473 | |
60bf98ae |
474 | //! Compute selection sensitives for linear dimension flyout lines (length, diameter, radius). |
475 | //! Please note that this method uses base dimension properties: working plane and flyout length. |
476 | //! @param theSelection [in] the selection structure to fill with selection primitives. |
477 | //! @param theOwner [in] the selection entity owner. |
478 | //! @param theFirstPoint [in] the first attach point of linear dimension. |
479 | //! @param theSecondPoint [in] the second attach point of linear dimension. |
480 | Standard_EXPORT void ComputeLinearFlyouts (const Handle(SelectMgr_Selection)& theSelection, |
481 | const Handle(SelectMgr_EntityOwner)& theOwner, |
482 | const gp_Pnt& theFirstPoint, |
483 | const gp_Pnt& theSecondPoint); |
484 | |
60bf98ae |
485 | |
486 | //! Performs initialization of circle and middle arc point from the passed |
487 | //! shape which is assumed to contain circular geometry. |
488 | //! @param theShape [in] the shape to explore. |
489 | //! @param theCircle [out] the circle geometry. |
490 | //! @param theMiddleArcPoint [out] the middle point of the arc. |
491 | //! @param theIsClosed [out] returns TRUE if the geometry is closed circle. |
492 | //! @return TRUE if the the circle is successfully got from the input shape. |
493 | Standard_EXPORT Standard_Boolean InitCircularDimension (const TopoDS_Shape& theShape, |
494 | gp_Circ& theCircle, |
495 | gp_Pnt& theMiddleArcPoint, |
496 | Standard_Boolean& theIsClosed); |
af203d54 |
497 | |
498 | //! Produce points for triangular arrow face. |
499 | //! @param thePeakPnt [in] the arrow peak position. |
500 | //! @param theDirection [in] the arrow direction. |
501 | //! @param thePlane [in] the face plane. |
502 | //! @param theArrowLength [in] the length of arrow. |
503 | //! @param theArrowAngle [in] the angle of arrow. |
504 | //! @param theSidePnt1 [out] the first side point. |
505 | //! @param theSidePnt2 [out] the second side point. |
506 | Standard_EXPORT void PointsForArrow (const gp_Pnt& thePeakPnt, |
507 | const gp_Dir& theDirection, |
508 | const gp_Dir& thePlane, |
509 | const Standard_Real theArrowLength, |
510 | const Standard_Real theArrowAngle, |
511 | gp_Pnt& theSidePnt1, |
512 | gp_Pnt& theSidePnt2); |
513 | |
514 | //! Compute point of text position for dimension parameters |
515 | //! for linear kinds of dimensions (length, radius, diameter). |
516 | Standard_EXPORT gp_Pnt GetTextPositionForLinear (const gp_Pnt& theFirstPoint, |
517 | const gp_Pnt& theSecondPoint, |
518 | const Standard_Boolean theIsOneSide = Standard_False) const; |
519 | |
520 | //! Fits text alignment relatively to the dimension line. |
521 | //! @param theFirstPoint [in] the first attachment point. |
522 | //! @param theSecondPoint [in] the second attachment point. |
523 | //! @param theIsOneSide [in] is the arrow displayed only on the one side of the dimension. |
524 | //! @param theHorizontalTextPos [in] the text horizontal position (alignment). |
525 | //! @param theLabelPosition [out] the label position, contains bits that defines |
526 | //! vertical and horizontal alignment. (for internal usage in count text position) |
527 | //! @param theIsArrowExternal [out] is the arrows external, |
528 | //! if arrow orientation in the dimension aspect is Prs3d_DAO_Fit, it fits arrow |
529 | //! orientation automatically. |
91b16a64 |
530 | Standard_EXPORT void FitTextAlignmentForLinear (const gp_Pnt& theFirstPoint, |
531 | const gp_Pnt& theSecondPoint, |
532 | const Standard_Boolean theIsOneSide, |
533 | const Prs3d_DimensionTextHorizontalPosition& theHorizontalTextPos, |
534 | Standard_Integer& theLabelPosition, |
535 | Standard_Boolean& theIsArrowsExternal) const; |
af203d54 |
536 | |
537 | //! Adjusts aspect parameters according the text position: |
538 | //! extension size, vertical text alignment and flyout. |
af203d54 |
539 | //! @param theTextPos [in] the user defined 3d point of text position |
540 | //! @param theFirstPoint [in] the first point of linear measurement. |
541 | //! @param theSecondPoint [in] the second point of linear measurement. |
542 | //! @param theExtensionSize [out] the adjusted extension size |
543 | //! @param theAlignment [out] the horizontal label alignment. |
91b16a64 |
544 | //! @param theFlyout [out] the adjusted value of flyout. |
545 | //! @param thePlane [out] the new plane that contains theTextPos and attachment points. |
546 | //! @param theIsPlaneOld [out] shows if new plane is computed. |
547 | Standard_EXPORT Standard_Boolean AdjustParametersForLinear (const gp_Pnt& theTextPos, |
548 | const gp_Pnt& theFirstPoint, |
549 | const gp_Pnt& theSecondPoint, |
550 | Standard_Real& theExtensionSize, |
551 | Prs3d_DimensionTextHorizontalPosition& theAlignment, |
552 | Standard_Real& theFlyout, |
553 | gp_Pln& thePlane, |
554 | Standard_Boolean& theIsPlaneOld) const; |
60bf98ae |
555 | |
0499eb06 |
556 | protected: //! @name Static auxilliary methods for geometry extraction |
557 | |
558 | //! If it is possible extracts circle from planar face. |
559 | //! @param theFace [in] the planar face |
560 | //! @param theCurve [out] the circular curve |
561 | //! @param theFirstPoint [out] the point of the first parameter of the circlular curve |
562 | //! @param theSecondPoint [out] the point of the last parameter of the circlular curve |
563 | //! @return TRUE in case of successful circle extraction |
564 | static Standard_Boolean CircleFromPlanarFace (const TopoDS_Face& theFace, |
565 | Handle(Geom_Curve)& theCurve, |
566 | gp_Pnt& theFirstPoint, |
567 | gp_Pnt& theLastPoint); |
568 | |
569 | //! If it is possible extracts circle from the edge. |
570 | //! @param theEdge [in] input edge to extract circle from |
571 | //! @param theCircle [out] circle |
572 | //! @param theFirstPoint [out] the point of the first parameter of the circlular curve |
573 | //! @param theSecondPoint [out] the point of the last parameter of the circlular curve |
574 | //! @return TRUE in case of successful circle extraction. |
575 | static Standard_Boolean CircleFromEdge (const TopoDS_Edge& theEdge, |
576 | gp_Circ& theCircle, |
577 | gp_Pnt& theFirstPoint, |
578 | gp_Pnt& theLastPoint); |
579 | |
60bf98ae |
580 | protected: //! @name Behavior to implement |
581 | |
60bf98ae |
582 | //! Override this method to check if user-defined plane |
583 | //! is valid for the dimension geometry. |
584 | //! @param thePlane [in] the working plane for positioning every |
585 | //! dimension in the application. |
586 | //! @return true is the plane is suitable for building dimension |
587 | //! with computed dimension geometry. |
588 | virtual Standard_Boolean CheckPlane (const gp_Pln& /*thePlane*/) const { return Standard_True; } |
589 | |
590 | //! Override this method to computed value of dimension. |
591 | //! @return value from the measured geometry. |
592 | virtual Standard_Real ComputeValue() const |
593 | { |
594 | return 0.0; |
595 | } |
a6eb515f |
596 | |
60bf98ae |
597 | //! Override this method to compute selection primitives for |
598 | //! flyout lines (if the dimension provides it). |
599 | //! This callback is a only a part of base selection |
600 | //! computation routine. |
601 | virtual void ComputeFlyoutSelection (const Handle(SelectMgr_Selection)&, |
602 | const Handle(SelectMgr_EntityOwner)&) {} |
fe83e1ea |
603 | |
a6eb515f |
604 | |
60bf98ae |
605 | //! Base procedure of computing selection (based on selection geometry data). |
606 | //! @param theSelection [in] the selection structure to will with primitives. |
607 | //! @param theMode [in] the selection mode. |
608 | Standard_EXPORT virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection, |
79104795 |
609 | const Standard_Integer theMode) Standard_OVERRIDE; |
a6eb515f |
610 | |
fe83e1ea |
611 | protected: //! @name Selection geometry |
a6eb515f |
612 | |
fe83e1ea |
613 | //! Selection geometry of dimension presentation. The structure is filled with data |
614 | //! during compute of presentation, then this data is used to generate selection |
615 | //! sensitives when computing selection. |
616 | struct SelectionGeometry |
a6eb515f |
617 | { |
fe83e1ea |
618 | //! Arrows are represented by directed triangles. |
619 | struct Arrow |
620 | { |
621 | gp_Pnt Position; |
622 | gp_Dir Direction; |
623 | }; |
624 | typedef NCollection_Sequence<gp_Pnt> Curve; |
625 | typedef NCollection_Handle<Curve> HCurve; |
626 | typedef NCollection_Handle<Arrow> HArrow; |
627 | typedef NCollection_Sequence<HCurve> SeqOfCurves; |
628 | typedef NCollection_Sequence<HArrow> SeqOfArrows; |
629 | |
630 | gp_Pnt TextPos; //!< Center of text label. |
631 | gp_Dir TextDir; //!< Direction of text label. |
632 | Standard_Real TextWidth; //!< Width of text label. |
633 | Standard_Real TextHeight; //!< Height of text label. |
634 | SeqOfCurves DimensionLine; //!< Sequence of points for composing the segments of dimension line. |
635 | SeqOfArrows Arrows; //!< Sequence of arrow geometries. |
91b16a64 |
636 | Standard_Boolean IsComputed; //!< Shows if the selection geometry was filled. |
fe83e1ea |
637 | |
638 | public: |
639 | |
640 | //! Clear geometry of sensitives for the specified compute mode. |
641 | //! @param theMode [in] the compute mode to clear. |
642 | void Clear (const Standard_Integer theMode) |
643 | { |
644 | if (theMode == ComputeMode_All || theMode == ComputeMode_Line) |
645 | { |
646 | DimensionLine.Clear(); |
647 | Arrows.Clear(); |
648 | } |
649 | |
650 | if (theMode == ComputeMode_All || theMode == ComputeMode_Text) |
651 | { |
652 | TextPos = gp::Origin(); |
653 | TextDir = gp::DX(); |
654 | TextWidth = 0.0; |
655 | TextHeight = 0.0; |
656 | } |
91b16a64 |
657 | |
658 | IsComputed = Standard_False; |
fe83e1ea |
659 | } |
660 | |
af203d54 |
661 | //! Add new curve entry and return the reference to populate it. |
fe83e1ea |
662 | Curve& NewCurve() |
663 | { |
664 | DimensionLine.Append( new Curve ); |
665 | HCurve& aLastCurve = DimensionLine.ChangeLast(); |
666 | return *aLastCurve; |
667 | } |
668 | |
af203d54 |
669 | //! Add new arrow entry and return the reference to populate it. |
fe83e1ea |
670 | Arrow& NewArrow() |
671 | { |
672 | Arrows.Append( new Arrow ); |
673 | HArrow& aLastArrow = Arrows.ChangeLast(); |
674 | return *aLastArrow; |
675 | } |
676 | } mySelectionGeom; |
677 | |
678 | Standard_Real mySelToleranceForText2d; //!< Sensitive point tolerance for 2d text selection. |
d7bffd44 |
679 | |
60bf98ae |
680 | protected: //! @name Value properties |
d7bffd44 |
681 | |
73ddbb9a |
682 | ValueType myValueType; //! type of value (computed or user-defined) |
60bf98ae |
683 | Standard_Real myCustomValue; //!< Value of the dimension (computed or user-defined). |
73ddbb9a |
684 | |
685 | TCollection_ExtendedString myCustomStringValue; //!< Value of the dimension (computed or user-defined). |
d7bffd44 |
686 | |
af203d54 |
687 | protected: //! @name Fixed text position properties |
688 | |
689 | gp_Pnt myFixedTextPosition; //!< Stores text position fixed by user. |
690 | Standard_Boolean myIsTextPositionFixed; //!< Is the text label position fixed by user. |
691 | |
60bf98ae |
692 | protected: //! @name Units properties |
d7bffd44 |
693 | |
60bf98ae |
694 | Standard_ExtCharacter mySpecialSymbol; //!< Special symbol. |
695 | AIS_DisplaySpecialSymbol myDisplaySpecialSymbol; //!< Special symbol display options. |
d7bffd44 |
696 | |
60bf98ae |
697 | protected: //! @name Geometrical properties |
d7bffd44 |
698 | |
60bf98ae |
699 | GeometryType myGeometryType; //!< defines type of shapes on which the dimension is to be built. |
d7bffd44 |
700 | |
91b16a64 |
701 | gp_Pln myPlane; //!< Plane where dimension will be built (computed or user defined). |
702 | Standard_Boolean myIsPlaneCustom; //!< Is plane defined by user (otherwise it will be computed automatically). |
703 | Standard_Real myFlyout; //!< Flyout distance. |
704 | Standard_Boolean myIsGeometryValid; //!< Is dimension geometry properly defined. |
d7bffd44 |
705 | |
a6eb515f |
706 | private: |
d7bffd44 |
707 | |
a6eb515f |
708 | AIS_KindOfDimension myKindOfDimension; |
a6eb515f |
709 | }; |
60bf98ae |
710 | |
711 | #endif // _AIS_Dimension_HeaderFile |