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 | |
a6eb515f |
16 | #include <AIS_Dimension.hxx> |
d7bffd44 |
17 | |
18 | #include <AIS.hxx> |
a6eb515f |
19 | #include <AIS_DimensionOwner.hxx> |
a6eb515f |
20 | #include <Adaptor3d_HCurve.hxx> |
21 | #include <BRepAdaptor_Curve.hxx> |
22 | #include <BRepAdaptor_Surface.hxx> |
a6eb515f |
23 | #include <BRepBndLib.hxx> |
60bf98ae |
24 | #include <Bnd_Box.hxx> |
a6eb515f |
25 | #include <ElCLib.hxx> |
26 | #include <Font_BRepFont.hxx> |
ac84fcf6 |
27 | #include <Font_BRepTextBuilder.hxx> |
a6eb515f |
28 | #include <GC_MakeCircle.hxx> |
af203d54 |
29 | #include <Geom_Line.hxx> |
fe83e1ea |
30 | #include <GeomAdaptor_Curve.hxx> |
a6eb515f |
31 | #include <Geom_Circle.hxx> |
a6eb515f |
32 | #include <Geom_TrimmedCurve.hxx> |
33 | #include <gce_MakeDir.hxx> |
34 | #include <gce_MakeLin.hxx> |
af203d54 |
35 | #include <gce_MakePln.hxx> |
a6eb515f |
36 | #include <Graphic3d_ArrayOfSegments.hxx> |
37 | #include <Graphic3d_ArrayOfTriangles.hxx> |
38 | #include <Graphic3d_AspectLine3d.hxx> |
39 | #include <Graphic3d_AspectFillArea3d.hxx> |
40 | #include <Graphic3d_AspectText3d.hxx> |
41 | #include <Graphic3d_Group.hxx> |
42 | #include <PrsMgr_PresentationManager3d.hxx> |
43 | #include <Prs3d_Arrow.hxx> |
44 | #include <Prs3d_ArrowAspect.hxx> |
45 | #include <Prs3d_Drawer.hxx> |
46 | #include <Prs3d_LineAspect.hxx> |
47 | #include <Prs3d_Presentation.hxx> |
48 | #include <Prs3d_Root.hxx> |
49 | #include <Prs3d_ShadingAspect.hxx> |
50 | #include <Prs3d_Text.hxx> |
51 | #include <SelectMgr_EntityOwner.hxx> |
52 | #include <SelectMgr_Selection.hxx> |
53 | #include <SelectMgr_SequenceOfOwner.hxx> |
a6eb515f |
54 | #include <Select3D_SensitiveCircle.hxx> |
55 | #include <Select3D_SensitiveGroup.hxx> |
fe83e1ea |
56 | #include <Select3D_SensitiveCurve.hxx> |
a6eb515f |
57 | #include <Select3D_SensitiveSegment.hxx> |
fe83e1ea |
58 | #include <Select3D_SensitiveTriangle.hxx> |
51f8f60c |
59 | #include <Select3D_SensitiveTriangulation.hxx> |
60 | #include <Poly_Array1OfTriangle.hxx> |
61 | #include <Poly_Triangulation.hxx> |
a6eb515f |
62 | #include <Standard_CString.hxx> |
af203d54 |
63 | #include <Standard_ProgramError.hxx> |
a6eb515f |
64 | #include <StdPrs_ShadedShape.hxx> |
65 | #include <StdPrs_WFShape.hxx> |
66 | #include <TCollection_AsciiString.hxx> |
67 | #include <TCollection_ExtendedString.hxx> |
68 | #include <TopExp_Explorer.hxx> |
69 | #include <TopoDS.hxx> |
0499eb06 |
70 | #include <TopoDS_Edge.hxx> |
a6eb515f |
71 | #include <TopoDS_Vertex.hxx> |
72 | #include <Units.hxx> |
73 | #include <Units_UnitsDictionary.hxx> |
74 | #include <UnitsAPI.hxx> |
75 | #include <UnitsAPI_SystemUnits.hxx> |
76 | |
a6eb515f |
77 | |
92efcf78 |
78 | IMPLEMENT_STANDARD_RTTIEXT(AIS_Dimension,AIS_InteractiveObject) |
79 | |
d7bffd44 |
80 | namespace |
a6eb515f |
81 | { |
fe83e1ea |
82 | // default text strings |
d7bffd44 |
83 | static const TCollection_ExtendedString THE_EMPTY_LABEL; |
60bf98ae |
84 | static const TCollection_AsciiString THE_UNDEFINED_UNITS; |
fe83e1ea |
85 | |
86 | // default text margin and resolution |
87 | static const Standard_Real THE_3D_TEXT_MARGIN = 0.1; |
88 | static const unsigned int THE_2D_TEXT_RESOLUTION = 72; |
89 | |
90 | // default selection priorities |
91 | static const Standard_Integer THE_NEUTRAL_SEL_PRIORITY = 5; |
92 | static const Standard_Integer THE_LOCAL_SEL_PRIORITY = 6; |
a3f6f591 |
93 | } |
a6eb515f |
94 | |
95 | //======================================================================= |
96 | //function : Constructor |
97 | //purpose : |
98 | //======================================================================= |
60bf98ae |
99 | AIS_Dimension::AIS_Dimension (const AIS_KindOfDimension theType) |
cbff1e55 |
100 | : AIS_InteractiveObject (), |
101 | mySelToleranceForText2d(0.0), |
102 | myCustomValue (0.0), |
103 | myIsValueCustom (Standard_False), |
104 | myIsTextPositionFixed (Standard_False), |
105 | mySpecialSymbol (' '), |
a6eb515f |
106 | myDisplaySpecialSymbol (AIS_DSS_No), |
cbff1e55 |
107 | myGeometryType (GeometryType_UndefShapes), |
108 | myIsPlaneCustom (Standard_False), |
109 | myFlyout (0.0), |
110 | myIsGeometryValid (Standard_False), |
111 | myKindOfDimension (theType) |
a6eb515f |
112 | { |
a6eb515f |
113 | } |
114 | |
115 | //======================================================================= |
60bf98ae |
116 | //function : SetCustomValue |
117 | //purpose : |
a6eb515f |
118 | //======================================================================= |
60bf98ae |
119 | void AIS_Dimension::SetCustomValue (const Standard_Real theValue) |
a6eb515f |
120 | { |
60bf98ae |
121 | if (myIsValueCustom && myCustomValue == theValue) |
122 | { |
123 | return; |
124 | } |
a6eb515f |
125 | |
60bf98ae |
126 | myIsValueCustom = Standard_True; |
127 | |
128 | myCustomValue = theValue; |
129 | |
130 | SetToUpdate(); |
a6eb515f |
131 | } |
132 | |
133 | //======================================================================= |
60bf98ae |
134 | //function : GetPlane |
a6eb515f |
135 | //purpose : |
136 | //======================================================================= |
60bf98ae |
137 | const gp_Pln& AIS_Dimension::GetPlane() const |
a6eb515f |
138 | { |
60bf98ae |
139 | return myPlane; |
a6eb515f |
140 | } |
141 | |
a6eb515f |
142 | //======================================================================= |
60bf98ae |
143 | //function : SetUserPlane |
a6eb515f |
144 | //purpose : |
145 | //======================================================================= |
60bf98ae |
146 | void AIS_Dimension::SetCustomPlane (const gp_Pln& thePlane) |
a6eb515f |
147 | { |
60bf98ae |
148 | myPlane = thePlane; |
149 | myIsPlaneCustom = Standard_True; |
150 | |
91b16a64 |
151 | // Disable fixed (custom) text position |
af203d54 |
152 | UnsetFixedTextPosition(); |
153 | |
60bf98ae |
154 | // Check validity if geometry has been set already. |
91b16a64 |
155 | if (IsValid()) |
60bf98ae |
156 | { |
60bf98ae |
157 | SetToUpdate(); |
158 | } |
a6eb515f |
159 | } |
160 | |
161 | //======================================================================= |
60bf98ae |
162 | //function : SetDimensionAspect |
163 | //purpose : |
a6eb515f |
164 | //======================================================================= |
60bf98ae |
165 | void AIS_Dimension::SetDimensionAspect (const Handle(Prs3d_DimensionAspect)& theDimensionAspect) |
a6eb515f |
166 | { |
60bf98ae |
167 | myDrawer->SetDimensionAspect (theDimensionAspect); |
168 | |
169 | SetToUpdate(); |
a6eb515f |
170 | } |
171 | |
172 | //======================================================================= |
60bf98ae |
173 | //function : SetDisplaySpecialSymbol |
174 | //purpose : |
a6eb515f |
175 | //======================================================================= |
60bf98ae |
176 | void AIS_Dimension::SetDisplaySpecialSymbol (const AIS_DisplaySpecialSymbol theDisplaySpecSymbol) |
a6eb515f |
177 | { |
60bf98ae |
178 | if (myDisplaySpecialSymbol == theDisplaySpecSymbol) |
179 | { |
180 | return; |
181 | } |
182 | |
183 | myDisplaySpecialSymbol = theDisplaySpecSymbol; |
184 | |
185 | SetToUpdate(); |
a6eb515f |
186 | } |
187 | |
188 | //======================================================================= |
60bf98ae |
189 | //function : SetSpecialSymbol |
a6eb515f |
190 | //purpose : |
191 | //======================================================================= |
60bf98ae |
192 | void AIS_Dimension::SetSpecialSymbol (const Standard_ExtCharacter theSpecialSymbol) |
a6eb515f |
193 | { |
60bf98ae |
194 | if (mySpecialSymbol == theSpecialSymbol) |
195 | { |
196 | return; |
197 | } |
198 | |
199 | mySpecialSymbol = theSpecialSymbol; |
200 | |
201 | SetToUpdate(); |
a6eb515f |
202 | } |
203 | |
204 | //======================================================================= |
60bf98ae |
205 | //function : SetSelToleranceForText2d |
206 | //purpose : |
a6eb515f |
207 | //======================================================================= |
60bf98ae |
208 | void AIS_Dimension::SetSelToleranceForText2d (const Standard_Real theTol) |
a6eb515f |
209 | { |
60bf98ae |
210 | if (mySelToleranceForText2d == theTol) |
211 | { |
212 | return; |
213 | } |
214 | |
215 | mySelToleranceForText2d = theTol; |
216 | |
217 | SetToUpdate(); |
a6eb515f |
218 | } |
219 | |
220 | //======================================================================= |
60bf98ae |
221 | //function : SetFlyout |
222 | //purpose : |
a6eb515f |
223 | //======================================================================= |
60bf98ae |
224 | void AIS_Dimension::SetFlyout (const Standard_Real theFlyout) |
a6eb515f |
225 | { |
60bf98ae |
226 | if (myFlyout == theFlyout) |
227 | { |
228 | return; |
229 | } |
a6eb515f |
230 | |
60bf98ae |
231 | myFlyout = theFlyout; |
232 | |
af203d54 |
233 | // Disable fixed text position |
234 | UnsetFixedTextPosition(); |
235 | |
60bf98ae |
236 | SetToUpdate(); |
237 | } |
a6eb515f |
238 | |
239 | //======================================================================= |
60bf98ae |
240 | //function : GetDisplayUnits |
241 | //purpose : |
a6eb515f |
242 | //======================================================================= |
60bf98ae |
243 | const TCollection_AsciiString& AIS_Dimension::GetDisplayUnits() const |
a6eb515f |
244 | { |
60bf98ae |
245 | return THE_UNDEFINED_UNITS; |
a6eb515f |
246 | } |
247 | |
248 | //======================================================================= |
60bf98ae |
249 | //function : GetModelUnits |
250 | //purpose : |
a6eb515f |
251 | //======================================================================= |
60bf98ae |
252 | const TCollection_AsciiString& AIS_Dimension::GetModelUnits() const |
a6eb515f |
253 | { |
60bf98ae |
254 | return THE_UNDEFINED_UNITS; |
a6eb515f |
255 | } |
256 | |
257 | //======================================================================= |
60bf98ae |
258 | //function : ValueToDisplayUnits |
259 | //purpose : |
a6eb515f |
260 | //======================================================================= |
60bf98ae |
261 | Standard_Real AIS_Dimension::ValueToDisplayUnits() const |
a6eb515f |
262 | { |
60bf98ae |
263 | return UnitsAPI::AnyToAny (GetValue(), |
264 | GetModelUnits().ToCString(), |
265 | GetDisplayUnits().ToCString()); |
a6eb515f |
266 | } |
267 | |
268 | //======================================================================= |
60bf98ae |
269 | //function : GetValueString |
a6eb515f |
270 | //purpose : |
271 | //======================================================================= |
60bf98ae |
272 | TCollection_ExtendedString AIS_Dimension::GetValueString (Standard_Real& theWidth) const |
a6eb515f |
273 | { |
60bf98ae |
274 | // format value string using "sprintf" |
275 | TCollection_AsciiString aFormatStr = myDrawer->DimensionAspect()->ValueStringFormat(); |
a6eb515f |
276 | |
60bf98ae |
277 | char aFmtBuffer[256]; |
278 | sprintf (aFmtBuffer, aFormatStr.ToCString(), ValueToDisplayUnits()); |
279 | TCollection_ExtendedString aValueStr = TCollection_ExtendedString (aFmtBuffer); |
a6eb515f |
280 | |
60bf98ae |
281 | // add units to values string |
282 | if (myDrawer->DimensionAspect()->IsUnitsDisplayed()) |
a6eb515f |
283 | { |
60bf98ae |
284 | aValueStr += " "; |
285 | aValueStr += TCollection_ExtendedString (GetDisplayUnits()); |
a6eb515f |
286 | } |
60bf98ae |
287 | |
288 | switch (myDisplaySpecialSymbol) |
a6eb515f |
289 | { |
60bf98ae |
290 | case AIS_DSS_Before : aValueStr.Insert (1, mySpecialSymbol); break; |
291 | case AIS_DSS_After : aValueStr.Insert (aValueStr.Length() + 1, mySpecialSymbol); break; |
292 | case AIS_DSS_No : break; |
a6eb515f |
293 | } |
294 | |
d7bffd44 |
295 | // Get text style parameters |
b6472664 |
296 | Handle(Prs3d_TextAspect) aTextAspect = myDrawer->DimensionAspect()->TextAspect(); |
60bf98ae |
297 | NCollection_Utf8String anUTFString = (Standard_Utf16Char* )aValueStr.ToExtString(); |
fe83e1ea |
298 | |
d7bffd44 |
299 | theWidth = 0.0; |
fe83e1ea |
300 | |
301 | if (myDrawer->DimensionAspect()->IsText3d()) |
302 | { |
303 | // text width produced by BRepFont |
b6472664 |
304 | Font_BRepFont aFont (aTextAspect->Aspect()->Font().ToCString(), |
305 | aTextAspect->Aspect()->GetTextFontAspect(), |
306 | aTextAspect->Height()); |
fe83e1ea |
307 | |
308 | for (NCollection_Utf8Iter anIter = anUTFString.Iterator(); *anIter != 0; ) |
309 | { |
310 | Standard_Utf32Char aCurrChar = *anIter; |
311 | Standard_Utf32Char aNextChar = *(++anIter); |
312 | theWidth += aFont.AdvanceX (aCurrChar, aNextChar); |
313 | } |
314 | } |
315 | else |
d7bffd44 |
316 | { |
fe83e1ea |
317 | // Text width for 1:1 scale 2D case |
60bf98ae |
318 | Handle(Font_FTFont) aFont = new Font_FTFont(); |
b6472664 |
319 | aFont->Init (aTextAspect->Aspect()->Font().ToCString(), |
320 | aTextAspect->Aspect()->GetTextFontAspect(), |
321 | (const unsigned int)aTextAspect->Height(), |
322 | THE_2D_TEXT_RESOLUTION); |
fe83e1ea |
323 | |
324 | for (NCollection_Utf8Iter anIter = anUTFString.Iterator(); *anIter != 0; ) |
325 | { |
326 | Standard_Utf32Char aCurrChar = *anIter; |
327 | Standard_Utf32Char aNextChar = *(++anIter); |
328 | theWidth += (Standard_Real) aFont->AdvanceX (aCurrChar, aNextChar); |
329 | } |
d7bffd44 |
330 | } |
60bf98ae |
331 | |
332 | return aValueStr; |
a6eb515f |
333 | } |
334 | |
335 | //======================================================================= |
60bf98ae |
336 | //function : DrawArrow |
a6eb515f |
337 | //purpose : |
338 | //======================================================================= |
60bf98ae |
339 | void AIS_Dimension::DrawArrow (const Handle(Prs3d_Presentation)& thePresentation, |
a6eb515f |
340 | const gp_Pnt& theLocation, |
341 | const gp_Dir& theDirection) |
342 | { |
4ad142d9 |
343 | Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup (thePresentation); |
fe83e1ea |
344 | |
345 | Quantity_Length aLength = myDrawer->DimensionAspect()->ArrowAspect()->Length(); |
346 | Standard_Real anAngle = myDrawer->DimensionAspect()->ArrowAspect()->Angle(); |
a6eb515f |
347 | |
348 | if (myDrawer->DimensionAspect()->IsArrows3d()) |
349 | { |
4ad142d9 |
350 | Prs3d_Arrow::Draw (aGroup, |
a6eb515f |
351 | theLocation, |
d7bffd44 |
352 | theDirection, |
fe83e1ea |
353 | anAngle, |
354 | aLength); |
4ad142d9 |
355 | aGroup->SetGroupPrimitivesAspect (myDrawer->DimensionAspect()->ArrowAspect()->Aspect()); |
a6eb515f |
356 | } |
357 | else |
358 | { |
fe83e1ea |
359 | gp_Pnt aLeftPoint (gp::Origin()); |
360 | gp_Pnt aRightPoint (gp::Origin()); |
60bf98ae |
361 | const gp_Dir& aPlane = GetPlane().Axis().Direction(); |
fe83e1ea |
362 | |
363 | PointsForArrow (theLocation, theDirection, aPlane, aLength, anAngle, aLeftPoint, aRightPoint); |
364 | |
a6eb515f |
365 | Handle(Graphic3d_ArrayOfTriangles) anArrow = new Graphic3d_ArrayOfTriangles(3); |
a6eb515f |
366 | |
367 | anArrow->AddVertex (aLeftPoint); |
368 | anArrow->AddVertex (theLocation); |
369 | anArrow->AddVertex (aRightPoint); |
370 | |
371 | // Set aspect for arrow triangles |
a6eb515f |
372 | Graphic3d_MaterialAspect aShadeMat (Graphic3d_NOM_DEFAULT); |
373 | aShadeMat.SetReflectionModeOff (Graphic3d_TOR_AMBIENT); |
374 | aShadeMat.SetReflectionModeOff (Graphic3d_TOR_DIFFUSE); |
375 | aShadeMat.SetReflectionModeOff (Graphic3d_TOR_SPECULAR); |
d7bffd44 |
376 | |
377 | Handle(Prs3d_ShadingAspect) aShadingStyle = new Prs3d_ShadingAspect(); |
b6472664 |
378 | aShadingStyle->SetColor (myDrawer->DimensionAspect()->ArrowAspect()->Aspect()->Color()); |
d7bffd44 |
379 | aShadingStyle->SetMaterial (aShadeMat); |
380 | |
4ad142d9 |
381 | aGroup->SetPrimitivesAspect (aShadingStyle->Aspect()); |
382 | aGroup->AddPrimitiveArray (anArrow); |
a6eb515f |
383 | } |
fe83e1ea |
384 | |
385 | SelectionGeometry::Arrow& aSensitiveArrow = mySelectionGeom.NewArrow(); |
386 | aSensitiveArrow.Position = theLocation; |
387 | aSensitiveArrow.Direction = theDirection; |
a6eb515f |
388 | } |
389 | |
390 | //======================================================================= |
7c65581d |
391 | //function : drawText |
392 | //purpose : |
a6eb515f |
393 | //======================================================================= |
7c65581d |
394 | void AIS_Dimension::drawText (const Handle(Prs3d_Presentation)& thePresentation, |
fe83e1ea |
395 | const gp_Pnt& theTextPos, |
396 | const gp_Dir& theTextDir, |
397 | const TCollection_ExtendedString& theText, |
398 | const Standard_Integer theLabelPosition) |
a6eb515f |
399 | { |
a6eb515f |
400 | if (myDrawer->DimensionAspect()->IsText3d()) |
401 | { |
fe83e1ea |
402 | // getting font parameters |
b6472664 |
403 | Handle(Prs3d_TextAspect) aTextAspect = myDrawer->DimensionAspect()->TextAspect(); |
404 | Quantity_Color aColor = aTextAspect->Aspect()->Color(); |
405 | Font_FontAspect aFontAspect = aTextAspect->Aspect()->GetTextFontAspect(); |
406 | Standard_Real aFontHeight = aTextAspect->Height(); |
a6eb515f |
407 | |
fe83e1ea |
408 | // creating TopoDS_Shape for text |
b6472664 |
409 | Font_BRepFont aFont (aTextAspect->Aspect()->Font().ToCString(), |
410 | aFontAspect, aFontHeight); |
fe83e1ea |
411 | NCollection_Utf8String anUTFString = (Standard_Utf16Char* )theText.ToExtString(); |
ac84fcf6 |
412 | |
413 | Font_BRepTextBuilder aBuilder; |
414 | TopoDS_Shape aTextShape = aBuilder.Perform (aFont, anUTFString); |
a6eb515f |
415 | |
fe83e1ea |
416 | // compute text width with kerning |
417 | Standard_Real aTextWidth = 0.0; |
418 | Standard_Real aTextHeight = aFont.Ascender() + aFont.Descender(); |
d7bffd44 |
419 | |
fe83e1ea |
420 | for (NCollection_Utf8Iter anIter = anUTFString.Iterator(); *anIter != 0; ) |
421 | { |
422 | Standard_Utf32Char aCurrChar = *anIter; |
423 | Standard_Utf32Char aNextChar = *(++anIter); |
424 | aTextWidth += aFont.AdvanceX (aCurrChar, aNextChar); |
425 | } |
426 | |
427 | // formating text position in XOY plane |
d7bffd44 |
428 | Standard_Integer aHLabelPos = theLabelPosition & LabelPosition_HMask; |
429 | Standard_Integer aVLabelPos = theLabelPosition & LabelPosition_VMask; |
430 | |
431 | gp_Dir aTextDir (aHLabelPos == LabelPosition_Left ? -theTextDir : theTextDir); |
432 | |
433 | // compute label offsets |
fe83e1ea |
434 | Standard_Real aMarginSize = aFontHeight * THE_3D_TEXT_MARGIN; |
d7bffd44 |
435 | Standard_Real aCenterHOffset = 0.0; |
436 | Standard_Real aCenterVOffset = 0.0; |
437 | switch (aHLabelPos) |
a6eb515f |
438 | { |
d7bffd44 |
439 | case LabelPosition_HCenter : aCenterHOffset = 0.0; break; |
440 | case LabelPosition_Right : aCenterHOffset = aTextWidth / 2.0 + aMarginSize; break; |
441 | case LabelPosition_Left : aCenterHOffset = -aTextWidth / 2.0 - aMarginSize; break; |
a6eb515f |
442 | } |
d7bffd44 |
443 | switch (aVLabelPos) |
a6eb515f |
444 | { |
d7bffd44 |
445 | case LabelPosition_VCenter : aCenterVOffset = 0.0; break; |
446 | case LabelPosition_Above : aCenterVOffset = aTextHeight / 2.0 + aMarginSize; break; |
447 | case LabelPosition_Below : aCenterVOffset = -aTextHeight / 2.0 - aMarginSize; break; |
a6eb515f |
448 | } |
d7bffd44 |
449 | |
450 | // compute shape offset transformation |
fe83e1ea |
451 | Standard_Real aShapeHOffset = aCenterHOffset - aTextWidth / 2.0; |
d7bffd44 |
452 | Standard_Real aShapeVOffset = aCenterVOffset - aTextHeight / 2.0; |
453 | |
fe83e1ea |
454 | // center shape in its bounding box (suppress border spacing added by FT_Font) |
455 | Bnd_Box aShapeBnd; |
456 | BRepBndLib::AddClose (aTextShape, aShapeBnd); |
457 | |
458 | Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax; |
459 | aShapeBnd.Get (aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); |
460 | |
461 | Standard_Real aXalign = aTextWidth * 0.5 - (aXmax + aXmin) * 0.5; |
462 | Standard_Real aYalign = aTextHeight * 0.5 - (aYmax + aYmin) * 0.5; |
463 | aShapeHOffset += aXalign; |
464 | aShapeVOffset += aYalign; |
465 | |
d7bffd44 |
466 | gp_Trsf anOffsetTrsf; |
467 | anOffsetTrsf.SetTranslation (gp::Origin(), gp_Pnt (aShapeHOffset, aShapeVOffset, 0.0)); |
468 | aTextShape.Move (anOffsetTrsf); |
a6eb515f |
469 | |
fe83e1ea |
470 | // transform text to myWorkingPlane coordinate system |
60bf98ae |
471 | gp_Ax3 aTextCoordSystem (theTextPos, GetPlane().Axis().Direction(), aTextDir); |
d7bffd44 |
472 | gp_Trsf aTextPlaneTrsf; |
473 | aTextPlaneTrsf.SetTransformation (aTextCoordSystem, gp_Ax3 (gp::XOY())); |
474 | aTextShape.Move (aTextPlaneTrsf); |
a6eb515f |
475 | |
fe83e1ea |
476 | // set text flipping anchors |
d7bffd44 |
477 | gp_Trsf aCenterOffsetTrsf; |
478 | gp_Pnt aCenterOffset (aCenterHOffset, aCenterVOffset, 0.0); |
479 | aCenterOffsetTrsf.SetTranslation (gp::Origin(), aCenterOffset); |
480 | |
fe83e1ea |
481 | gp_Pnt aCenterOfLabel (gp::Origin()); |
482 | aCenterOfLabel.Transform (aCenterOffsetTrsf); |
483 | aCenterOfLabel.Transform (aTextPlaneTrsf); |
d7bffd44 |
484 | |
60bf98ae |
485 | gp_Ax2 aFlippingAxes (aCenterOfLabel, GetPlane().Axis().Direction(), aTextDir); |
d7bffd44 |
486 | Prs3d_Root::CurrentGroup (thePresentation)->SetFlippingOptions (Standard_True, aFlippingAxes); |
487 | |
fe83e1ea |
488 | // draw text |
a6eb515f |
489 | if (myDrawer->DimensionAspect()->IsTextShaded()) |
490 | { |
491 | // Setting text shading and color parameters |
d2dfbc4d |
492 | if (!myDrawer->HasOwnShadingAspect()) |
493 | { |
494 | myDrawer->SetShadingAspect (new Prs3d_ShadingAspect()); |
495 | } |
496 | |
a6eb515f |
497 | Graphic3d_MaterialAspect aShadeMat (Graphic3d_NOM_DEFAULT); |
498 | aShadeMat.SetReflectionModeOff (Graphic3d_TOR_AMBIENT); |
499 | aShadeMat.SetReflectionModeOff (Graphic3d_TOR_DIFFUSE); |
500 | aShadeMat.SetReflectionModeOff (Graphic3d_TOR_SPECULAR); |
501 | myDrawer->ShadingAspect()->Aspect()->SetInteriorColor (aColor); |
502 | myDrawer->ShadingAspect()->Aspect()->SetBackInteriorColor (aColor); |
503 | myDrawer->ShadingAspect()->SetMaterial (aShadeMat); |
504 | |
fe83e1ea |
505 | // drawing text |
a6eb515f |
506 | StdPrs_ShadedShape::Add (thePresentation, aTextShape, myDrawer); |
507 | } |
508 | else |
509 | { |
d2dfbc4d |
510 | // Setting color for text |
511 | if (!myDrawer->HasOwnFreeBoundaryAspect()) |
512 | { |
513 | myDrawer->SetFreeBoundaryAspect (new Prs3d_LineAspect (aColor, Aspect_TOL_SOLID, 1.0)); |
514 | } |
515 | |
a6eb515f |
516 | myDrawer->FreeBoundaryAspect()->Aspect()->SetColor (aColor); |
d2dfbc4d |
517 | |
fe83e1ea |
518 | // drawing text |
a6eb515f |
519 | StdPrs_WFShape::Add (thePresentation, aTextShape, myDrawer); |
520 | } |
d7bffd44 |
521 | Prs3d_Root::CurrentGroup (thePresentation)->SetFlippingOptions (Standard_False, gp_Ax2()); |
522 | |
fe83e1ea |
523 | mySelectionGeom.TextPos = aCenterOfLabel; |
524 | mySelectionGeom.TextDir = aTextDir; |
525 | mySelectionGeom.TextWidth = aTextWidth + aMarginSize * 2.0; |
526 | mySelectionGeom.TextHeight = aTextHeight; |
527 | |
528 | return; |
a6eb515f |
529 | } |
530 | |
fe83e1ea |
531 | // generate primitives for 2D text |
d7bffd44 |
532 | myDrawer->DimensionAspect()->TextAspect()->Aspect()->SetDisplayType (Aspect_TODT_DIMENSION); |
533 | |
4ad142d9 |
534 | Prs3d_Text::Draw (Prs3d_Root::CurrentGroup (thePresentation), |
d7bffd44 |
535 | myDrawer->DimensionAspect()->TextAspect(), |
536 | theText, |
fe83e1ea |
537 | theTextPos); |
d7bffd44 |
538 | |
fe83e1ea |
539 | mySelectionGeom.TextPos = theTextPos; |
540 | mySelectionGeom.TextDir = theTextDir; |
541 | mySelectionGeom.TextWidth = 0.0; |
542 | mySelectionGeom.TextHeight = 0.0; |
a6eb515f |
543 | } |
544 | |
d7bffd44 |
545 | //======================================================================= |
60bf98ae |
546 | //function : DrawExtension |
a6eb515f |
547 | //purpose : |
548 | //======================================================================= |
60bf98ae |
549 | void AIS_Dimension::DrawExtension (const Handle(Prs3d_Presentation)& thePresentation, |
d7bffd44 |
550 | const Standard_Real theExtensionSize, |
551 | const gp_Pnt& theExtensionStart, |
552 | const gp_Dir& theExtensionDir, |
fe83e1ea |
553 | const TCollection_ExtendedString& theLabelString, |
554 | const Standard_Real theLabelWidth, |
555 | const Standard_Integer theMode, |
d7bffd44 |
556 | const Standard_Integer theLabelPosition) |
a6eb515f |
557 | { |
fe83e1ea |
558 | // reference line for extension starting at its connection point |
559 | gp_Lin anExtensionLine (theExtensionStart, theExtensionDir); |
a6eb515f |
560 | |
fe83e1ea |
561 | Standard_Boolean hasLabel = theLabelString.Length() > 0; |
fe83e1ea |
562 | if (hasLabel && (theMode == ComputeMode_All || theMode == ComputeMode_Text)) |
a6eb515f |
563 | { |
d7bffd44 |
564 | // compute text primitives; get its model width |
fe83e1ea |
565 | gp_Pnt aTextPos = ElCLib::Value (theExtensionSize, anExtensionLine); |
60bf98ae |
566 | gp_Dir aTextDir = theExtensionDir; |
fe83e1ea |
567 | |
7c65581d |
568 | drawText (thePresentation, |
fe83e1ea |
569 | aTextPos, |
570 | aTextDir, |
571 | theLabelString, |
572 | theLabelPosition); |
a6eb515f |
573 | } |
574 | |
fe83e1ea |
575 | if (theMode != ComputeMode_All && theMode != ComputeMode_Line) |
a6eb515f |
576 | { |
d7bffd44 |
577 | return; |
a6eb515f |
578 | } |
579 | |
fe83e1ea |
580 | Standard_Boolean isShortLine = !myDrawer->DimensionAspect()->IsText3d() |
581 | || theLabelPosition & LabelPosition_VCenter; |
582 | |
d7bffd44 |
583 | // compute graphical primitives and sensitives for extension line |
584 | gp_Pnt anExtStart = theExtensionStart; |
fe83e1ea |
585 | gp_Pnt anExtEnd = !hasLabel || isShortLine |
586 | ? ElCLib::Value (theExtensionSize, anExtensionLine) |
587 | : ElCLib::Value (theExtensionSize + theLabelWidth, anExtensionLine); |
d7bffd44 |
588 | |
fe83e1ea |
589 | // add graphical primitives |
d7bffd44 |
590 | Handle(Graphic3d_ArrayOfSegments) anExtPrimitive = new Graphic3d_ArrayOfSegments (2); |
591 | anExtPrimitive->AddVertex (anExtStart); |
592 | anExtPrimitive->AddVertex (anExtEnd); |
593 | |
fe83e1ea |
594 | // add selection primitives |
595 | SelectionGeometry::Curve& aSensitiveCurve = mySelectionGeom.NewCurve(); |
596 | aSensitiveCurve.Append (anExtStart); |
597 | aSensitiveCurve.Append (anExtEnd); |
a6eb515f |
598 | |
fe83e1ea |
599 | if (!myDrawer->DimensionAspect()->IsText3d() && theMode == ComputeMode_All) |
a6eb515f |
600 | { |
d7bffd44 |
601 | Prs3d_Root::CurrentGroup (thePresentation)->SetStencilTestOptions (Standard_True); |
602 | } |
603 | Handle(Graphic3d_AspectLine3d) aDimensionLineStyle = myDrawer->DimensionAspect()->LineAspect()->Aspect(); |
604 | Prs3d_Root::CurrentGroup (thePresentation)->SetPrimitivesAspect (aDimensionLineStyle); |
605 | Prs3d_Root::CurrentGroup (thePresentation)->AddPrimitiveArray (anExtPrimitive); |
fe83e1ea |
606 | if (!myDrawer->DimensionAspect()->IsText3d() && theMode == ComputeMode_All) |
d7bffd44 |
607 | { |
608 | Prs3d_Root::CurrentGroup (thePresentation)->SetStencilTestOptions (Standard_False); |
a6eb515f |
609 | } |
610 | } |
611 | |
612 | //======================================================================= |
60bf98ae |
613 | //function : DrawLinearDimension |
a6eb515f |
614 | //purpose : |
615 | //======================================================================= |
60bf98ae |
616 | void AIS_Dimension::DrawLinearDimension (const Handle(Prs3d_Presentation)& thePresentation, |
fe83e1ea |
617 | const Standard_Integer theMode, |
60bf98ae |
618 | const gp_Pnt& theFirstPoint, |
619 | const gp_Pnt& theSecondPoint, |
620 | const Standard_Boolean theIsOneSide) |
a6eb515f |
621 | { |
60bf98ae |
622 | // do not build any dimension for equal points |
623 | if (theFirstPoint.IsEqual (theSecondPoint, Precision::Confusion())) |
a6eb515f |
624 | { |
60bf98ae |
625 | Standard_ProgramError::Raise ("Can not build presentation for equal points."); |
a6eb515f |
626 | } |
d7bffd44 |
627 | |
a6eb515f |
628 | Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect(); |
a6eb515f |
629 | |
d7bffd44 |
630 | // For extensions we need to know arrow size, text size and extension size: get it from aspect |
631 | Quantity_Length anArrowLength = aDimensionAspect->ArrowAspect()->Length(); |
632 | Standard_Real anExtensionSize = aDimensionAspect->ExtensionSize(); |
fe83e1ea |
633 | // prepare label string and compute its geometrical width |
634 | Standard_Real aLabelWidth; |
60bf98ae |
635 | TCollection_ExtendedString aLabelString = GetValueString (aLabelWidth); |
a6eb515f |
636 | |
fe83e1ea |
637 | // add margins to cut dimension lines for 3d text |
638 | if (aDimensionAspect->IsText3d()) |
639 | { |
640 | aLabelWidth += aDimensionAspect->TextAspect()->Height() * THE_3D_TEXT_MARGIN * 2.0; |
641 | } |
642 | |
643 | // handle user-defined and automatic arrow placement |
af203d54 |
644 | Standard_Boolean isArrowsExternal = Standard_False; |
645 | Standard_Integer aLabelPosition = LabelPosition_None; |
fe83e1ea |
646 | |
af203d54 |
647 | Prs3d_DimensionTextHorizontalPosition aHorisontalTextPos = aDimensionAspect->TextHorizontalPosition(); |
648 | if (IsTextPositionCustom()) |
649 | { |
91b16a64 |
650 | if (!AdjustParametersForLinear (myFixedTextPosition, theFirstPoint, theSecondPoint, |
651 | anExtensionSize, aHorisontalTextPos, myFlyout, myPlane, myIsPlaneCustom)) |
652 | { |
653 | Standard_ProgramError::Raise ("Can not adjust plane to the custom label position."); |
654 | } |
a6eb515f |
655 | } |
a6eb515f |
656 | |
af203d54 |
657 | FitTextAlignmentForLinear (theFirstPoint, theSecondPoint, theIsOneSide, aHorisontalTextPos, |
658 | aLabelPosition, isArrowsExternal); |
659 | |
660 | // compute dimension line points |
661 | gp_Ax1 aPlaneNormal = GetPlane().Axis(); |
662 | gp_Dir aTargetPointsVector = gce_MakeDir (theFirstPoint, theSecondPoint); |
663 | |
664 | // compute flyout direction vector |
665 | gp_Dir aFlyoutVector = aPlaneNormal.Direction() ^ aTargetPointsVector; |
666 | |
667 | // create lines for layouts |
668 | gp_Lin aLine1 (theFirstPoint, aFlyoutVector); |
669 | gp_Lin aLine2 (theSecondPoint, aFlyoutVector); |
670 | |
671 | // Get flyout end points |
672 | gp_Pnt aLineBegPoint = ElCLib::Value (ElCLib::Parameter (aLine1, theFirstPoint) + GetFlyout(), aLine1); |
673 | gp_Pnt aLineEndPoint = ElCLib::Value (ElCLib::Parameter (aLine2, theSecondPoint) + GetFlyout(), aLine2); |
674 | |
675 | gp_Lin aDimensionLine = gce_MakeLin (aLineBegPoint, aLineEndPoint); |
676 | |
fe83e1ea |
677 | // compute arrows positions and directions |
d7bffd44 |
678 | gp_Dir aFirstArrowDir = aDimensionLine.Direction().Reversed(); |
679 | gp_Dir aSecondArrowDir = aDimensionLine.Direction(); |
680 | gp_Dir aFirstExtensionDir = aDimensionLine.Direction().Reversed(); |
681 | gp_Dir aSecondExtensionDir = aDimensionLine.Direction(); |
682 | |
683 | gp_Pnt aFirstArrowBegin (0.0, 0.0, 0.0); |
684 | gp_Pnt aFirstArrowEnd (0.0, 0.0, 0.0); |
685 | gp_Pnt aSecondArrowBegin (0.0, 0.0, 0.0); |
686 | gp_Pnt aSecondArrowEnd (0.0, 0.0, 0.0); |
a6eb515f |
687 | |
d7bffd44 |
688 | if (isArrowsExternal) |
a6eb515f |
689 | { |
690 | aFirstArrowDir.Reverse(); |
691 | aSecondArrowDir.Reverse(); |
a6eb515f |
692 | } |
d7bffd44 |
693 | |
694 | aFirstArrowBegin = aLineBegPoint; |
695 | aSecondArrowBegin = aLineEndPoint; |
696 | aFirstArrowEnd = aLineBegPoint.Translated (-gp_Vec (aFirstArrowDir).Scaled (anArrowLength)); |
697 | aSecondArrowEnd = aLineEndPoint.Translated (-gp_Vec (aSecondArrowDir).Scaled (anArrowLength)); |
698 | |
699 | gp_Pnt aCenterLineBegin = isArrowsExternal |
60bf98ae |
700 | ? aLineBegPoint : aFirstArrowEnd; |
d7bffd44 |
701 | |
60bf98ae |
702 | gp_Pnt aCenterLineEnd = isArrowsExternal || theIsOneSide |
d7bffd44 |
703 | ? aLineEndPoint : aSecondArrowEnd; |
704 | |
a6eb515f |
705 | |
d7bffd44 |
706 | switch (aLabelPosition & LabelPosition_HMask) |
a6eb515f |
707 | { |
d7bffd44 |
708 | // ------------------------------------------------------------------------ // |
709 | // CENTER // |
710 | // -------------------------------------------------------------------------// |
d7bffd44 |
711 | case LabelPosition_HCenter: |
a6eb515f |
712 | { |
d7bffd44 |
713 | // add label on dimension or extension line to presentation |
714 | Prs3d_Root::NewGroup (thePresentation); |
a6eb515f |
715 | |
af203d54 |
716 | gp_Pnt aTextPos = IsTextPositionCustom() ? myFixedTextPosition |
717 | : (aCenterLineBegin.XYZ() + aCenterLineEnd.XYZ()) * 0.5; |
60bf98ae |
718 | gp_Dir aTextDir = aDimensionLine.Direction(); |
a6eb515f |
719 | |
fe83e1ea |
720 | // add text primitives |
721 | if (theMode == ComputeMode_All || theMode == ComputeMode_Text) |
a6eb515f |
722 | { |
7c65581d |
723 | drawText (thePresentation, |
fe83e1ea |
724 | aTextPos, |
725 | aTextDir, |
726 | aLabelString, |
727 | aLabelPosition); |
a6eb515f |
728 | } |
d7bffd44 |
729 | |
fe83e1ea |
730 | // add dimension line primitives |
731 | if (theMode == ComputeMode_All || theMode == ComputeMode_Line) |
732 | { |
733 | Standard_Boolean isLineBreak = aDimensionAspect->TextVerticalPosition() == Prs3d_DTVP_Center |
734 | && aDimensionAspect->IsText3d(); |
d7bffd44 |
735 | |
fe83e1ea |
736 | Handle(Graphic3d_ArrayOfSegments) aPrimSegments = new Graphic3d_ArrayOfSegments (isLineBreak ? 4 : 2); |
d7bffd44 |
737 | |
fe83e1ea |
738 | // compute continuous or sectioned main line segments |
739 | if (isLineBreak) |
740 | { |
741 | Standard_Real aPTextPosition = ElCLib::Parameter (aDimensionLine, aTextPos); |
742 | gp_Pnt aSection1Beg = aCenterLineBegin; |
743 | gp_Pnt aSection1End = ElCLib::Value (aPTextPosition - (aLabelWidth * 0.5), aDimensionLine); |
744 | gp_Pnt aSection2Beg = ElCLib::Value (aPTextPosition + (aLabelWidth * 0.5), aDimensionLine); |
745 | gp_Pnt aSection2End = aCenterLineEnd; |
746 | |
747 | aPrimSegments->AddVertex (aSection1Beg); |
748 | aPrimSegments->AddVertex (aSection1End); |
749 | aPrimSegments->AddVertex (aSection2Beg); |
750 | aPrimSegments->AddVertex (aSection2End); |
751 | |
752 | SelectionGeometry::Curve& aLeftSensitiveCurve = mySelectionGeom.NewCurve(); |
753 | SelectionGeometry::Curve& aRightSensitiveCurve = mySelectionGeom.NewCurve(); |
754 | aLeftSensitiveCurve.Append (aSection1Beg); |
755 | aLeftSensitiveCurve.Append (aSection1End); |
756 | aRightSensitiveCurve.Append (aSection2Beg); |
757 | aRightSensitiveCurve.Append (aSection2End); |
758 | } |
759 | else |
760 | { |
761 | aPrimSegments->AddVertex (aCenterLineBegin); |
762 | aPrimSegments->AddVertex (aCenterLineEnd); |
a6eb515f |
763 | |
fe83e1ea |
764 | SelectionGeometry::Curve& aSensitiveCurve = mySelectionGeom.NewCurve(); |
765 | aSensitiveCurve.Append (aCenterLineBegin); |
766 | aSensitiveCurve.Append (aCenterLineEnd); |
767 | } |
a6eb515f |
768 | |
fe83e1ea |
769 | // set text label justification |
770 | Graphic3d_VerticalTextAlignment aTextJustificaton = Graphic3d_VTA_BOTTOM; |
771 | switch (aLabelPosition & LabelPosition_VMask) |
772 | { |
773 | case LabelPosition_Above : |
774 | case LabelPosition_VCenter : aTextJustificaton = Graphic3d_VTA_BOTTOM; break; |
775 | case LabelPosition_Below : aTextJustificaton = Graphic3d_VTA_TOP; break; |
776 | } |
777 | aDimensionAspect->TextAspect()->SetVerticalJustification (aTextJustificaton); |
a6eb515f |
778 | |
fe83e1ea |
779 | // main dimension line, short extension |
780 | if (!aDimensionAspect->IsText3d() && theMode == ComputeMode_All) |
781 | { |
782 | Prs3d_Root::CurrentGroup (thePresentation)->SetStencilTestOptions (Standard_True); |
783 | } |
784 | Prs3d_Root::CurrentGroup (thePresentation)->SetPrimitivesAspect (aDimensionAspect->LineAspect()->Aspect()); |
785 | Prs3d_Root::CurrentGroup (thePresentation)->AddPrimitiveArray (aPrimSegments); |
786 | if (!aDimensionAspect->IsText3d() && theMode == ComputeMode_All) |
787 | { |
788 | Prs3d_Root::CurrentGroup (thePresentation)->SetStencilTestOptions (Standard_False); |
789 | } |
d7bffd44 |
790 | |
fe83e1ea |
791 | // add arrows to presentation |
792 | Prs3d_Root::NewGroup (thePresentation); |
d7bffd44 |
793 | |
60bf98ae |
794 | DrawArrow (thePresentation, aFirstArrowBegin, aFirstArrowDir); |
795 | if (!theIsOneSide) |
fe83e1ea |
796 | { |
60bf98ae |
797 | DrawArrow (thePresentation, aSecondArrowBegin, aSecondArrowDir); |
fe83e1ea |
798 | } |
d7bffd44 |
799 | |
fe83e1ea |
800 | if (!isArrowsExternal) |
801 | { |
802 | break; |
803 | } |
d7bffd44 |
804 | |
fe83e1ea |
805 | // add arrow extension lines to presentation |
806 | Prs3d_Root::NewGroup (thePresentation); |
d7bffd44 |
807 | |
af203d54 |
808 | DrawExtension (thePresentation, aDimensionAspect->ArrowTailSize(), |
fe83e1ea |
809 | aFirstArrowEnd, aFirstExtensionDir, |
810 | THE_EMPTY_LABEL, 0.0, theMode, LabelPosition_None); |
60bf98ae |
811 | if (!theIsOneSide) |
fe83e1ea |
812 | { |
af203d54 |
813 | DrawExtension (thePresentation, aDimensionAspect->ArrowTailSize(), |
fe83e1ea |
814 | aSecondArrowEnd, aSecondExtensionDir, |
815 | THE_EMPTY_LABEL, 0.0, theMode, LabelPosition_None); |
816 | } |
a6eb515f |
817 | } |
1d7ca641 |
818 | |
819 | break; |
a6eb515f |
820 | } |
d7bffd44 |
821 | // ------------------------------------------------------------------------ // |
822 | // LEFT // |
823 | // -------------------------------------------------------------------------// |
824 | |
825 | case LabelPosition_Left: |
a6eb515f |
826 | { |
d7bffd44 |
827 | // add label on dimension or extension line to presentation |
828 | Prs3d_Root::NewGroup (thePresentation); |
a6eb515f |
829 | |
a6eb515f |
830 | // Left extension with the text |
60bf98ae |
831 | DrawExtension (thePresentation, anExtensionSize, |
832 | isArrowsExternal |
833 | ? aFirstArrowEnd |
834 | : aFirstArrowBegin, |
d7bffd44 |
835 | aFirstExtensionDir, |
fe83e1ea |
836 | aLabelString, |
837 | aLabelWidth, |
d7bffd44 |
838 | theMode, |
839 | aLabelPosition); |
840 | |
fe83e1ea |
841 | // add dimension line primitives |
842 | if (theMode == ComputeMode_All || theMode == ComputeMode_Line) |
d7bffd44 |
843 | { |
fe83e1ea |
844 | // add central dimension line |
845 | Prs3d_Root::NewGroup (thePresentation); |
d7bffd44 |
846 | |
fe83e1ea |
847 | // add graphical primitives |
848 | Handle(Graphic3d_ArrayOfSegments) aPrimSegments = new Graphic3d_ArrayOfSegments (2); |
849 | aPrimSegments->AddVertex (aCenterLineBegin); |
850 | aPrimSegments->AddVertex (aCenterLineEnd); |
d7bffd44 |
851 | |
fe83e1ea |
852 | Prs3d_Root::CurrentGroup (thePresentation)->SetPrimitivesAspect (aDimensionAspect->LineAspect()->Aspect()); |
853 | Prs3d_Root::CurrentGroup (thePresentation)->AddPrimitiveArray (aPrimSegments); |
d7bffd44 |
854 | |
fe83e1ea |
855 | // add selection primitives |
856 | SelectionGeometry::Curve& aSensitiveCurve = mySelectionGeom.NewCurve(); |
857 | aSensitiveCurve.Append (aCenterLineBegin); |
858 | aSensitiveCurve.Append (aCenterLineEnd); |
a6eb515f |
859 | |
fe83e1ea |
860 | // add arrows to presentation |
861 | Prs3d_Root::NewGroup (thePresentation); |
a6eb515f |
862 | |
60bf98ae |
863 | DrawArrow (thePresentation, aFirstArrowBegin, aFirstArrowDir); |
864 | if (!theIsOneSide) |
fe83e1ea |
865 | { |
60bf98ae |
866 | DrawArrow (thePresentation, aSecondArrowBegin, aSecondArrowDir); |
fe83e1ea |
867 | } |
d7bffd44 |
868 | |
60bf98ae |
869 | if (!isArrowsExternal || theIsOneSide) |
fe83e1ea |
870 | { |
871 | break; |
872 | } |
d7bffd44 |
873 | |
fe83e1ea |
874 | // add extension lines for external arrows |
875 | Prs3d_Root::NewGroup (thePresentation); |
d7bffd44 |
876 | |
af203d54 |
877 | DrawExtension (thePresentation, aDimensionAspect->ArrowTailSize(), |
fe83e1ea |
878 | aSecondArrowEnd, aSecondExtensionDir, |
879 | THE_EMPTY_LABEL, 0.0, theMode, LabelPosition_None); |
880 | } |
d7bffd44 |
881 | |
a6eb515f |
882 | break; |
883 | } |
d7bffd44 |
884 | // ------------------------------------------------------------------------ // |
885 | // RIGHT // |
886 | // -------------------------------------------------------------------------// |
887 | |
888 | case LabelPosition_Right: |
a6eb515f |
889 | { |
d7bffd44 |
890 | // add label on dimension or extension line to presentation |
891 | Prs3d_Root::NewGroup (thePresentation); |
892 | |
893 | // Right extension with text |
60bf98ae |
894 | DrawExtension (thePresentation, anExtensionSize, |
895 | isArrowsExternal |
896 | ? aSecondArrowEnd |
897 | : aSecondArrowBegin, |
d7bffd44 |
898 | aSecondExtensionDir, |
fe83e1ea |
899 | aLabelString, aLabelWidth, |
d7bffd44 |
900 | theMode, |
901 | aLabelPosition); |
902 | |
fe83e1ea |
903 | if (theMode == ComputeMode_All || theMode == ComputeMode_Line) |
a6eb515f |
904 | { |
fe83e1ea |
905 | // add central dimension line |
906 | Prs3d_Root::NewGroup (thePresentation); |
a6eb515f |
907 | |
fe83e1ea |
908 | // add graphical primitives |
909 | Handle(Graphic3d_ArrayOfSegments) aPrimSegments = new Graphic3d_ArrayOfSegments (2); |
910 | aPrimSegments->AddVertex (aCenterLineBegin); |
911 | aPrimSegments->AddVertex (aCenterLineEnd); |
912 | Prs3d_Root::CurrentGroup (thePresentation)->SetPrimitivesAspect (aDimensionAspect->LineAspect()->Aspect()); |
913 | Prs3d_Root::CurrentGroup (thePresentation)->AddPrimitiveArray (aPrimSegments); |
a6eb515f |
914 | |
fe83e1ea |
915 | // add selection primitives |
916 | SelectionGeometry::Curve& aSensitiveCurve = mySelectionGeom.NewCurve(); |
917 | aSensitiveCurve.Append (aCenterLineBegin); |
918 | aSensitiveCurve.Append (aCenterLineEnd); |
a6eb515f |
919 | |
fe83e1ea |
920 | // add arrows to presentation |
921 | Prs3d_Root::NewGroup (thePresentation); |
d7bffd44 |
922 | |
60bf98ae |
923 | DrawArrow (thePresentation, aSecondArrowBegin, aSecondArrowDir); |
924 | if (!theIsOneSide) |
fe83e1ea |
925 | { |
60bf98ae |
926 | DrawArrow (thePresentation, aFirstArrowBegin, aFirstArrowDir); |
fe83e1ea |
927 | } |
d7bffd44 |
928 | |
60bf98ae |
929 | if (!isArrowsExternal || theIsOneSide) |
fe83e1ea |
930 | { |
931 | break; |
932 | } |
a6eb515f |
933 | |
fe83e1ea |
934 | // add extension lines for external arrows |
935 | Prs3d_Root::NewGroup (thePresentation); |
d7bffd44 |
936 | |
af203d54 |
937 | DrawExtension (thePresentation, aDimensionAspect->ArrowTailSize(), |
fe83e1ea |
938 | aFirstArrowEnd, aFirstExtensionDir, |
939 | THE_EMPTY_LABEL, 0.0, theMode, LabelPosition_None); |
940 | } |
d7bffd44 |
941 | |
a6eb515f |
942 | break; |
943 | } |
944 | } |
945 | |
d7bffd44 |
946 | // add flyout lines to presentation |
fe83e1ea |
947 | if (theMode == ComputeMode_All) |
d7bffd44 |
948 | { |
949 | Prs3d_Root::NewGroup (thePresentation); |
950 | |
951 | Handle(Graphic3d_ArrayOfSegments) aPrimSegments = new Graphic3d_ArrayOfSegments(4); |
60bf98ae |
952 | aPrimSegments->AddVertex (theFirstPoint); |
d7bffd44 |
953 | aPrimSegments->AddVertex (aLineBegPoint); |
954 | |
60bf98ae |
955 | aPrimSegments->AddVertex (theSecondPoint); |
d7bffd44 |
956 | aPrimSegments->AddVertex (aLineEndPoint); |
957 | |
d7bffd44 |
958 | Prs3d_Root::CurrentGroup (thePresentation)->SetPrimitivesAspect (aDimensionAspect->LineAspect()->Aspect()); |
959 | Prs3d_Root::CurrentGroup (thePresentation)->AddPrimitiveArray (aPrimSegments); |
960 | } |
961 | |
91b16a64 |
962 | mySelectionGeom.IsComputed = Standard_True; |
a6eb515f |
963 | } |
964 | |
965 | //======================================================================= |
60bf98ae |
966 | //function : ComputeLinearFlyouts |
967 | //purpose : |
a6eb515f |
968 | //======================================================================= |
60bf98ae |
969 | void AIS_Dimension::ComputeLinearFlyouts (const Handle(SelectMgr_Selection)& theSelection, |
970 | const Handle(SelectMgr_EntityOwner)& theOwner, |
971 | const gp_Pnt& theFirstPoint, |
972 | const gp_Pnt& theSecondPoint) |
a6eb515f |
973 | { |
60bf98ae |
974 | // count flyout direction |
975 | gp_Ax1 aPlaneNormal = GetPlane().Axis(); |
976 | gp_Dir aTargetPointsVector = gce_MakeDir (theFirstPoint, theSecondPoint); |
a6eb515f |
977 | |
60bf98ae |
978 | // count a flyout direction vector. |
979 | gp_Dir aFlyoutVector = aPlaneNormal.Direction() ^ aTargetPointsVector; |
a6eb515f |
980 | |
60bf98ae |
981 | // create lines for layouts |
982 | gp_Lin aLine1 (theFirstPoint, aFlyoutVector); |
983 | gp_Lin aLine2 (theSecondPoint, aFlyoutVector); |
984 | |
985 | // get flyout end points |
986 | gp_Pnt aFlyoutEnd1 = ElCLib::Value (ElCLib::Parameter (aLine1, theFirstPoint) + GetFlyout(), aLine1); |
987 | gp_Pnt aFlyoutEnd2 = ElCLib::Value (ElCLib::Parameter (aLine2, theSecondPoint) + GetFlyout(), aLine2); |
988 | |
989 | // fill sensitive entity for flyouts |
990 | Handle(Select3D_SensitiveGroup) aSensitiveEntity = new Select3D_SensitiveGroup (theOwner); |
991 | aSensitiveEntity->Add (new Select3D_SensitiveSegment (theOwner, theFirstPoint, aFlyoutEnd1)); |
992 | aSensitiveEntity->Add (new Select3D_SensitiveSegment (theOwner, theSecondPoint, aFlyoutEnd2)); |
993 | theSelection->Add (aSensitiveEntity); |
a6eb515f |
994 | } |
995 | |
996 | //======================================================================= |
60bf98ae |
997 | //function : CircleFromPlanarFace |
a6eb515f |
998 | //purpose : if possible computes circle from planar face |
999 | //======================================================================= |
60bf98ae |
1000 | Standard_Boolean AIS_Dimension::CircleFromPlanarFace (const TopoDS_Face& theFace, |
a6eb515f |
1001 | Handle(Geom_Curve)& theCurve, |
60bf98ae |
1002 | gp_Pnt& theFirstPoint, |
1003 | gp_Pnt& theLastPoint) |
a6eb515f |
1004 | { |
1005 | TopExp_Explorer anIt (theFace, TopAbs_EDGE); |
1006 | for ( ; anIt.More(); anIt.Next()) |
1007 | { |
1008 | TopoDS_Edge aCurEdge = TopoDS::Edge (anIt.Current()); |
1009 | if (AIS::ComputeGeometry (aCurEdge, theCurve, theFirstPoint, theLastPoint)) |
1010 | { |
1011 | if (theCurve->IsInstance (STANDARD_TYPE(Geom_Circle))) |
1012 | { |
1013 | return Standard_True; |
1014 | } |
1015 | } |
1016 | } |
1017 | return Standard_False; |
1018 | } |
1019 | |
0499eb06 |
1020 | //======================================================================= |
1021 | //function : CircleFromEdge |
1022 | //purpose : if possible computes circle from edge |
1023 | //======================================================================= |
1024 | Standard_Boolean AIS_Dimension::CircleFromEdge (const TopoDS_Edge& theEdge, |
1025 | gp_Circ& theCircle, |
1026 | gp_Pnt& theFirstPoint, |
1027 | gp_Pnt& theLastPoint) |
1028 | { |
1029 | BRepAdaptor_Curve anAdaptedCurve (theEdge); |
1030 | switch (anAdaptedCurve.GetType()) |
1031 | { |
1032 | case GeomAbs_Circle: |
1033 | { |
1034 | theCircle = anAdaptedCurve.Circle(); |
1035 | break; |
1036 | } |
1037 | case GeomAbs_Ellipse: |
1038 | { |
1039 | gp_Elips anEll = anAdaptedCurve.Ellipse(); |
1040 | if ((anEll.MinorRadius() - anEll.MajorRadius()) >= Precision::Confusion()) |
1041 | { |
1042 | return Standard_False; |
1043 | } |
1044 | theCircle = gp_Circ(anEll.Position(),anEll.MinorRadius()); |
1045 | break; |
1046 | } |
1047 | case GeomAbs_Line: |
1048 | case GeomAbs_Hyperbola: |
1049 | case GeomAbs_Parabola: |
1050 | case GeomAbs_BezierCurve: |
1051 | case GeomAbs_BSplineCurve: |
1052 | case GeomAbs_OtherCurve: |
1053 | default: |
1054 | return Standard_False; |
1055 | } |
1056 | |
1057 | theFirstPoint = anAdaptedCurve.Value (anAdaptedCurve.FirstParameter()); |
1058 | theLastPoint = anAdaptedCurve.Value (anAdaptedCurve.LastParameter()); |
1059 | return Standard_True; |
1060 | } |
1061 | |
a6eb515f |
1062 | //======================================================================= |
60bf98ae |
1063 | //function : InitCircularDimension |
1064 | //purpose : |
a6eb515f |
1065 | //======================================================================= |
60bf98ae |
1066 | Standard_Boolean AIS_Dimension::InitCircularDimension (const TopoDS_Shape& theShape, |
a6eb515f |
1067 | gp_Circ& theCircle, |
1068 | gp_Pnt& theMiddleArcPoint, |
60bf98ae |
1069 | Standard_Boolean& theIsClosed) |
a6eb515f |
1070 | { |
1071 | gp_Pln aPln; |
1072 | Handle(Geom_Surface) aBasisSurf; |
1073 | AIS_KindOfSurface aSurfType = AIS_KOS_OtherSurface; |
1074 | gp_Pnt aFirstPoint, aLastPoint; |
1075 | Standard_Real anOffset = 0.0; |
1076 | Standard_Real aFirstParam = 0.0; |
1077 | Standard_Real aLastParam = 0.0; |
a6eb515f |
1078 | |
0499eb06 |
1079 | // Discover circular geometry |
1080 | switch (theShape.ShapeType()) |
a6eb515f |
1081 | { |
0499eb06 |
1082 | case TopAbs_FACE: |
a6eb515f |
1083 | { |
0499eb06 |
1084 | AIS::GetPlaneFromFace (TopoDS::Face (theShape), aPln, aBasisSurf, aSurfType, anOffset); |
a6eb515f |
1085 | |
0499eb06 |
1086 | if (aSurfType == AIS_KOS_Plane) |
a6eb515f |
1087 | { |
0499eb06 |
1088 | Handle(Geom_Curve) aCurve; |
1089 | if (!CircleFromPlanarFace (TopoDS::Face (theShape), aCurve, aFirstPoint, aLastPoint)) |
1090 | { |
1091 | return Standard_False; |
1092 | } |
1093 | |
1094 | theCircle = Handle(Geom_Circle)::DownCast (aCurve)->Circ(); |
a6eb515f |
1095 | } |
1096 | else |
1097 | { |
0499eb06 |
1098 | gp_Pnt aCurPos; |
1099 | BRepAdaptor_Surface aSurf1 (TopoDS::Face (theShape)); |
1100 | Standard_Real aFirstU = aSurf1.FirstUParameter(); |
1101 | Standard_Real aLastU = aSurf1.LastUParameter(); |
1102 | Standard_Real aFirstV = aSurf1.FirstVParameter(); |
1103 | Standard_Real aLastV = aSurf1.LastVParameter(); |
1104 | Standard_Real aMidU = (aFirstU + aLastU) * 0.5; |
1105 | Standard_Real aMidV = (aFirstV + aLastV) * 0.5; |
1106 | aSurf1.D0 (aMidU, aMidV, aCurPos); |
1107 | Handle (Adaptor3d_HCurve) aBasisCurve; |
1108 | Standard_Boolean isExpectedType = Standard_False; |
1109 | if (aSurfType == AIS_KOS_Cylinder) |
a6eb515f |
1110 | { |
0499eb06 |
1111 | isExpectedType = Standard_True; |
a6eb515f |
1112 | } |
0499eb06 |
1113 | else |
a6eb515f |
1114 | { |
0499eb06 |
1115 | if (aSurfType == AIS_KOS_Revolution) |
a6eb515f |
1116 | { |
0499eb06 |
1117 | aBasisCurve = aSurf1.BasisCurve(); |
1118 | if (aBasisCurve->GetType() == GeomAbs_Line) |
1119 | { |
1120 | isExpectedType = Standard_True; |
1121 | } |
1122 | } |
1123 | else if (aSurfType == AIS_KOS_Extrusion) |
1124 | { |
1125 | aBasisCurve = aSurf1.BasisCurve(); |
1126 | if (aBasisCurve->GetType() == GeomAbs_Circle) |
1127 | { |
1128 | isExpectedType = Standard_True; |
1129 | } |
a6eb515f |
1130 | } |
1131 | } |
a6eb515f |
1132 | |
0499eb06 |
1133 | if (!isExpectedType) |
1134 | { |
1135 | return Standard_False; |
1136 | } |
60bf98ae |
1137 | |
0499eb06 |
1138 | Handle(Geom_Curve) aCurve = aBasisSurf->VIso(aMidV); |
1139 | if (aCurve->DynamicType() == STANDARD_TYPE (Geom_Circle)) |
a6eb515f |
1140 | { |
0499eb06 |
1141 | theCircle = Handle(Geom_Circle)::DownCast (aCurve)->Circ(); |
1142 | } |
1143 | else if (aCurve->DynamicType() == STANDARD_TYPE (Geom_TrimmedCurve)) |
1144 | { |
1145 | Handle(Geom_TrimmedCurve) aTrimmedCurve = Handle(Geom_TrimmedCurve)::DownCast (aCurve); |
1146 | aFirstU = aTrimmedCurve->FirstParameter(); |
1147 | aLastU = aTrimmedCurve->LastParameter(); |
1148 | if (aTrimmedCurve->BasisCurve()->DynamicType() == STANDARD_TYPE (Geom_Circle)) |
1149 | { |
1150 | theCircle = Handle(Geom_Circle)::DownCast(aTrimmedCurve->BasisCurve())->Circ(); |
1151 | } |
1152 | } |
1153 | else |
1154 | { |
1155 | // Compute a circle from 3 points on "aCurve" |
1156 | gp_Pnt aP1, aP2; |
1157 | aSurf1.D0 (aFirstU, aMidV, aP1); |
1158 | aSurf1.D0 (aLastU, aMidV, aP2); |
1159 | GC_MakeCircle aMkCirc (aP1, aCurPos, aP2); |
1160 | theCircle = aMkCirc.Value()->Circ(); |
a6eb515f |
1161 | } |
a6eb515f |
1162 | |
0499eb06 |
1163 | aFirstPoint = ElCLib::Value (aFirstU, theCircle); |
1164 | aLastPoint = ElCLib::Value (aLastU, theCircle); |
1165 | } |
1166 | break; |
a6eb515f |
1167 | } |
0499eb06 |
1168 | case TopAbs_WIRE: |
a6eb515f |
1169 | { |
0499eb06 |
1170 | TopoDS_Edge anEdge; |
a6eb515f |
1171 | TopExp_Explorer anIt (theShape, TopAbs_EDGE); |
1172 | if (anIt.More()) |
1173 | { |
1174 | anEdge = TopoDS::Edge (anIt.Current()); |
1175 | } |
0499eb06 |
1176 | if (!AIS_Dimension::CircleFromEdge (anEdge, theCircle, aFirstPoint, aLastPoint)) |
1177 | { |
1178 | return Standard_False; |
1179 | } |
1180 | break; |
a6eb515f |
1181 | } |
0499eb06 |
1182 | case TopAbs_EDGE: |
a6eb515f |
1183 | { |
0499eb06 |
1184 | TopoDS_Edge anEdge = TopoDS::Edge (theShape); |
1185 | if (!AIS_Dimension::CircleFromEdge (anEdge, theCircle, aFirstPoint, aLastPoint)) |
1186 | { |
1187 | return Standard_False; |
1188 | } |
1189 | break; |
a6eb515f |
1190 | } |
0499eb06 |
1191 | case TopAbs_COMPOUND: |
1192 | case TopAbs_COMPSOLID: |
1193 | case TopAbs_SOLID: |
1194 | case TopAbs_SHELL: |
1195 | case TopAbs_VERTEX: |
1196 | case TopAbs_SHAPE: |
1197 | default: |
a6eb515f |
1198 | return Standard_False; |
a6eb515f |
1199 | } |
60bf98ae |
1200 | |
1201 | theIsClosed = aFirstPoint.IsEqual (aLastPoint, Precision::Confusion()); |
1202 | |
a6eb515f |
1203 | gp_Pnt aCenter = theCircle.Location(); |
60bf98ae |
1204 | |
1205 | if (theIsClosed) // Circle |
a6eb515f |
1206 | { |
a6eb515f |
1207 | gp_Dir anXDir = theCircle.XAxis().Direction(); |
1208 | theMiddleArcPoint = aCenter.Translated (gp_Vec (anXDir) * theCircle.Radius()); |
a6eb515f |
1209 | } |
60bf98ae |
1210 | else // Arc |
a6eb515f |
1211 | { |
a6eb515f |
1212 | aFirstParam = ElCLib::Parameter (theCircle, aFirstPoint); |
1213 | aLastParam = ElCLib::Parameter (theCircle, aLastPoint); |
1214 | if (aFirstParam > aLastParam) |
1215 | { |
1216 | aFirstParam -= 2.0 * M_PI; |
1217 | } |
60bf98ae |
1218 | |
a6eb515f |
1219 | Standard_Real aParCurPos = (aFirstParam + aLastParam) * 0.5; |
1220 | gp_Vec aVec = gp_Vec (aCenter, ElCLib::Value (aParCurPos, theCircle)).Normalized () * theCircle.Radius (); |
1221 | theMiddleArcPoint = aCenter.Translated (aVec); |
a6eb515f |
1222 | } |
1223 | |
1224 | return Standard_True; |
1225 | } |
1226 | |
a6eb515f |
1227 | //======================================================================= |
1228 | //function : ComputeSelection |
1229 | //purpose : |
1230 | //======================================================================= |
a6eb515f |
1231 | void AIS_Dimension::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection, |
1232 | const Standard_Integer theMode) |
1233 | { |
91b16a64 |
1234 | if (!mySelectionGeom.IsComputed) |
a6eb515f |
1235 | { |
1236 | return; |
1237 | } |
1238 | |
fe83e1ea |
1239 | AIS_DimensionSelectionMode aSelectionMode = (AIS_DimensionSelectionMode)theMode; |
a6eb515f |
1240 | |
fe83e1ea |
1241 | // init appropriate entity owner |
1242 | Handle(SelectMgr_EntityOwner) aSensitiveOwner; |
a6eb515f |
1243 | |
fe83e1ea |
1244 | switch (aSelectionMode) |
a6eb515f |
1245 | { |
fe83e1ea |
1246 | // neutral selection owner |
1247 | case AIS_DSM_All : |
1248 | aSensitiveOwner = new SelectMgr_EntityOwner (this, THE_NEUTRAL_SEL_PRIORITY); |
1249 | break; |
1250 | |
1251 | // local selection owners |
1252 | case AIS_DSM_Line : |
1253 | case AIS_DSM_Text : |
1254 | aSensitiveOwner = new AIS_DimensionOwner (this, aSelectionMode, THE_LOCAL_SEL_PRIORITY); |
1255 | break; |
a6eb515f |
1256 | } |
fe83e1ea |
1257 | |
1258 | if (aSelectionMode == AIS_DSM_All || aSelectionMode == AIS_DSM_Line) |
a6eb515f |
1259 | { |
fe83e1ea |
1260 | // sensitives for dimension line segments |
1261 | Handle(Select3D_SensitiveGroup) aGroupOfSensitives = new Select3D_SensitiveGroup (aSensitiveOwner); |
1262 | |
1263 | SelectionGeometry::SeqOfCurves::Iterator aCurveIt (mySelectionGeom.DimensionLine); |
1264 | for (; aCurveIt.More(); aCurveIt.Next()) |
1265 | { |
1266 | const SelectionGeometry::HCurve& aCurveData = aCurveIt.Value(); |
1267 | |
1268 | TColgp_Array1OfPnt aSensitivePnts (1, aCurveData->Length()); |
1269 | for (Standard_Integer aPntIt = 1; aPntIt <= aCurveData->Length(); ++aPntIt) |
1270 | { |
1271 | aSensitivePnts.ChangeValue (aPntIt) = aCurveData->Value (aPntIt); |
1272 | } |
1273 | |
1274 | aGroupOfSensitives->Add (new Select3D_SensitiveCurve (aSensitiveOwner, aSensitivePnts)); |
1275 | } |
1276 | |
1277 | Quantity_Length anArrowLength = myDrawer->DimensionAspect()->ArrowAspect()->Length(); |
1278 | Standard_Real anArrowAngle = myDrawer->DimensionAspect()->ArrowAspect()->Angle(); |
1279 | |
1280 | // sensitives for arrows |
1281 | SelectionGeometry::SeqOfArrows::Iterator anArrowIt (mySelectionGeom.Arrows); |
1282 | for (; anArrowIt.More(); anArrowIt.Next()) |
1283 | { |
1284 | const SelectionGeometry::HArrow& anArrow = anArrowIt.Value(); |
1285 | |
1286 | gp_Pnt aSidePnt1 (gp::Origin()); |
1287 | gp_Pnt aSidePnt2 (gp::Origin()); |
60bf98ae |
1288 | const gp_Dir& aPlane = GetPlane().Axis().Direction(); |
fe83e1ea |
1289 | const gp_Pnt& aPeak = anArrow->Position; |
1290 | const gp_Dir& aDir = anArrow->Direction; |
1291 | |
1292 | // compute points for arrow in plane |
1293 | PointsForArrow (aPeak, aDir, aPlane, anArrowLength, anArrowAngle, aSidePnt1, aSidePnt2); |
1294 | |
1295 | aGroupOfSensitives->Add (new Select3D_SensitiveTriangle (aSensitiveOwner, aPeak, aSidePnt1, aSidePnt2)); |
1296 | |
1297 | if (!myDrawer->DimensionAspect()->IsArrows3d()) |
1298 | { |
1299 | continue; |
1300 | } |
1301 | |
1302 | // compute points for orthogonal sensitive plane |
1303 | gp_Dir anOrthoPlane = anArrow->Direction.Crossed (aPlane); |
1304 | |
1305 | PointsForArrow (aPeak, aDir, anOrthoPlane, anArrowLength, anArrowAngle, aSidePnt1, aSidePnt2); |
1306 | |
1307 | aGroupOfSensitives->Add (new Select3D_SensitiveTriangle (aSensitiveOwner, aPeak, aSidePnt1, aSidePnt2)); |
1308 | } |
1309 | |
1310 | theSelection->Add (aGroupOfSensitives); |
a6eb515f |
1311 | } |
fe83e1ea |
1312 | |
1313 | // sensitives for text element |
1314 | if (aSelectionMode == AIS_DSM_All || aSelectionMode == AIS_DSM_Text) |
a6eb515f |
1315 | { |
fe83e1ea |
1316 | Handle(Select3D_SensitiveEntity) aTextSensitive; |
1317 | |
1318 | gp_Ax2 aTextAxes (mySelectionGeom.TextPos, |
60bf98ae |
1319 | GetPlane().Axis().Direction(), |
fe83e1ea |
1320 | mySelectionGeom.TextDir); |
1321 | |
1322 | if (myDrawer->DimensionAspect()->IsText3d()) |
1323 | { |
1324 | // sensitive planar rectangle for text |
1325 | Standard_Real aDx = mySelectionGeom.TextWidth * 0.5; |
1326 | Standard_Real aDy = mySelectionGeom.TextHeight * 0.5; |
1327 | |
1328 | gp_Trsf aLabelPlane; |
1329 | aLabelPlane.SetTransformation (aTextAxes, gp::XOY()); |
1330 | |
51f8f60c |
1331 | TColgp_Array1OfPnt aRectanglePoints(1, 4); |
1332 | aRectanglePoints.ChangeValue(1) = gp_Pnt (-aDx, -aDy, 0.0).Transformed (aLabelPlane); |
1333 | aRectanglePoints.ChangeValue(2) = gp_Pnt (-aDx, aDy, 0.0).Transformed (aLabelPlane); |
1334 | aRectanglePoints.ChangeValue(3) = gp_Pnt ( aDx, aDy, 0.0).Transformed (aLabelPlane); |
1335 | aRectanglePoints.ChangeValue(4) = gp_Pnt ( aDx, -aDy, 0.0).Transformed (aLabelPlane); |
fe83e1ea |
1336 | |
51f8f60c |
1337 | Poly_Array1OfTriangle aTriangles(1, 2); |
1338 | aTriangles.ChangeValue(1) = Poly_Triangle(1, 2, 3); |
1339 | aTriangles.ChangeValue(2) = Poly_Triangle(1, 3, 4); |
1340 | |
1341 | Handle(Poly_Triangulation) aRectanglePoly = |
1342 | new Poly_Triangulation(aRectanglePoints, aTriangles); |
1343 | |
1344 | aTextSensitive = |
1345 | new Select3D_SensitiveTriangulation (aSensitiveOwner, aRectanglePoly, TopLoc_Location(), Standard_True); |
fe83e1ea |
1346 | } |
1347 | else |
1348 | { |
1349 | gp_Circ aTextGeom (aTextAxes, mySelToleranceForText2d != 0.0 |
1350 | ? mySelToleranceForText2d : 1.0); |
1351 | |
1352 | Handle(Geom_Circle) aSensGeom = new Geom_Circle (aTextGeom); |
1353 | |
1354 | aTextSensitive = new Select3D_SensitiveCircle (aSensitiveOwner, aSensGeom, Standard_True); |
1355 | } |
1356 | |
1357 | theSelection->Add (aTextSensitive); |
a6eb515f |
1358 | } |
fe83e1ea |
1359 | |
1360 | // callback for flyout sensitive calculation |
1361 | if (aSelectionMode == AIS_DSM_All) |
d7bffd44 |
1362 | { |
60bf98ae |
1363 | ComputeFlyoutSelection (theSelection, aSensitiveOwner); |
d7bffd44 |
1364 | } |
fe83e1ea |
1365 | } |
1366 | |
1367 | //======================================================================= |
1368 | //function : PointsForArrow |
1369 | //purpose : |
1370 | //======================================================================= |
1371 | void AIS_Dimension::PointsForArrow (const gp_Pnt& thePeakPnt, |
1372 | const gp_Dir& theDirection, |
1373 | const gp_Dir& thePlane, |
1374 | const Standard_Real theArrowLength, |
1375 | const Standard_Real theArrowAngle, |
1376 | gp_Pnt& theSidePnt1, |
1377 | gp_Pnt& theSidePnt2) |
1378 | { |
1379 | gp_Lin anArrowLin (thePeakPnt, theDirection.Reversed()); |
1380 | gp_Pnt anArrowEnd = ElCLib::Value (theArrowLength, anArrowLin); |
1381 | gp_Lin anEdgeLin (anArrowEnd, theDirection.Crossed (thePlane)); |
1382 | |
1383 | Standard_Real anEdgeLength = Tan (theArrowAngle) * theArrowLength; |
a6eb515f |
1384 | |
fe83e1ea |
1385 | theSidePnt1 = ElCLib::Value ( anEdgeLength, anEdgeLin); |
1386 | theSidePnt2 = ElCLib::Value (-anEdgeLength, anEdgeLin); |
a6eb515f |
1387 | } |
af203d54 |
1388 | |
1389 | //======================================================================= |
1390 | //function : GetTextPositionForLinear |
1391 | //purpose : |
1392 | //======================================================================= |
1393 | gp_Pnt AIS_Dimension::GetTextPositionForLinear (const gp_Pnt& theFirstPoint, |
1394 | const gp_Pnt& theSecondPoint, |
1395 | const Standard_Boolean theIsOneSide) const |
1396 | { |
91b16a64 |
1397 | if (!IsValid()) |
af203d54 |
1398 | { |
1399 | return gp::Origin(); |
1400 | } |
1401 | |
1402 | gp_Pnt aTextPosition (gp::Origin()); |
1403 | |
1404 | Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect(); |
1405 | |
1406 | // Get label alignment and arrow orientation. |
1407 | Standard_Integer aLabelPosition = 0; |
1408 | Standard_Boolean isArrowsExternal = Standard_False; |
1409 | FitTextAlignmentForLinear (theFirstPoint, theSecondPoint, theIsOneSide, |
1410 | aDimensionAspect->TextHorizontalPosition(), |
1411 | aLabelPosition, isArrowsExternal); |
1412 | |
1413 | // Compute dimension line points. |
1414 | gp_Dir aPlaneNormal = GetPlane().Axis().Direction(); |
1415 | gp_Vec aTargetPointsVec (theFirstPoint, theSecondPoint); |
1416 | |
1417 | // Compute flyout direction vector |
1418 | gp_Dir aFlyoutVector = aPlaneNormal ^ gp_Dir (aTargetPointsVec); |
1419 | |
1420 | // create lines for layouts |
1421 | gp_Lin aLine1 (theFirstPoint, aFlyoutVector); |
1422 | gp_Lin aLine2 (theSecondPoint, aFlyoutVector); |
1423 | // Get flyout end points |
1424 | gp_Pnt aLineBegPoint = ElCLib::Value (ElCLib::Parameter (aLine1, theFirstPoint) + GetFlyout(), aLine1); |
1425 | gp_Pnt aLineEndPoint = ElCLib::Value (ElCLib::Parameter (aLine2, theSecondPoint) + GetFlyout(), aLine2); |
1426 | |
1427 | // Get text position. |
1428 | switch (aLabelPosition & LabelPosition_HMask) |
1429 | { |
1430 | case LabelPosition_Left: |
1431 | { |
1432 | gp_Dir aTargetPointsDir = gce_MakeDir (theFirstPoint, theSecondPoint); |
1433 | Standard_Real anExtensionSize = aDimensionAspect->ExtensionSize(); |
1434 | |
1435 | Standard_Real anOffset = isArrowsExternal |
1436 | ? anExtensionSize + aDimensionAspect->ArrowAspect()->Length() |
1437 | : anExtensionSize; |
1438 | gp_Vec anExtensionVec = gp_Vec (aTargetPointsDir) * -anOffset; |
1439 | aTextPosition = aLineEndPoint.Translated (anExtensionVec); |
1440 | } |
1441 | break; |
1442 | case LabelPosition_Right: |
1443 | { |
1444 | gp_Dir aTargetPointsDir = gce_MakeDir (theFirstPoint, theSecondPoint); |
1445 | Standard_Real anExtensionSize = aDimensionAspect->ExtensionSize(); |
1446 | |
1447 | Standard_Real anOffset = isArrowsExternal |
1448 | ? anExtensionSize + aDimensionAspect->ArrowAspect()->Length() |
1449 | : anExtensionSize; |
1450 | gp_Vec anExtensionVec = gp_Vec (aTargetPointsDir) * anOffset; |
1451 | aTextPosition = aLineBegPoint.Translated (anExtensionVec); |
1452 | } |
1453 | break; |
1454 | case LabelPosition_HCenter: |
1455 | { |
1456 | aTextPosition = (aLineBegPoint.XYZ() + aLineEndPoint.XYZ()) * 0.5; |
1457 | } |
1458 | break; |
1459 | } |
1460 | |
1461 | return aTextPosition; |
1462 | } |
1463 | |
1464 | //======================================================================= |
91b16a64 |
1465 | //function : AdjustParametersForLinear |
af203d54 |
1466 | //purpose : |
1467 | //======================================================================= |
91b16a64 |
1468 | Standard_Boolean AIS_Dimension::AdjustParametersForLinear (const gp_Pnt& theTextPos, |
1469 | const gp_Pnt& theFirstPoint, |
1470 | const gp_Pnt& theSecondPoint, |
1471 | Standard_Real& theExtensionSize, |
1472 | Prs3d_DimensionTextHorizontalPosition& theAlignment, |
1473 | Standard_Real& theFlyout, |
1474 | gp_Pln& thePlane, |
1475 | Standard_Boolean& theIsPlaneOld) const |
af203d54 |
1476 | { |
1477 | Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect(); |
1478 | Standard_Real anArrowLength = aDimensionAspect->ArrowAspect()->Length(); |
1479 | |
af203d54 |
1480 | gp_Dir aTargetPointsDir = gce_MakeDir (theFirstPoint, theSecondPoint); |
1481 | gp_Vec aTargetPointsVec (theFirstPoint, theSecondPoint); |
1482 | |
91b16a64 |
1483 | // Don't set new plane if the text position lies on the attachment points line. |
1484 | gp_Lin aTargetPointsLin (theFirstPoint, aTargetPointsDir); |
1485 | if (!aTargetPointsLin.Contains (theTextPos, Precision::Confusion())) |
1486 | { |
1487 | //Set new automatic plane. |
1488 | thePlane = gce_MakePln (theTextPos, theFirstPoint, theSecondPoint); |
1489 | theIsPlaneOld = Standard_False; |
1490 | } |
1491 | |
af203d54 |
1492 | // Compute flyout direction vector. |
91b16a64 |
1493 | gp_Dir aPlaneNormal = GetPlane().Axis().Direction(); |
af203d54 |
1494 | gp_Dir aPositiveFlyout = aPlaneNormal ^ aTargetPointsDir; |
1495 | |
91b16a64 |
1496 | // Additional check of collinearity of the plane normal and attachment points vector. |
1497 | if (aPlaneNormal.IsParallel (aTargetPointsDir, Precision::Angular())) |
1498 | { |
1499 | return Standard_False; |
1500 | } |
1501 | |
af203d54 |
1502 | // Set flyout. |
1503 | gp_Vec aFirstToTextVec (theFirstPoint, theTextPos); |
1504 | |
1505 | Standard_Real aCos = aFirstToTextVec.Normalized() * gp_Vec (aTargetPointsDir); |
1506 | |
1507 | gp_Pnt aTextPosProj = theFirstPoint.Translated |
1508 | (gp_Vec (aTargetPointsDir) * aFirstToTextVec.Magnitude() * aCos); |
1509 | |
1510 | // Compute flyout value and direction. |
1511 | gp_Vec aFlyoutVector = gp_Vec (aTextPosProj, theTextPos); |
1512 | |
91b16a64 |
1513 | theFlyout = 0.0; |
1514 | if (aFlyoutVector.Magnitude() > Precision::Confusion()) |
1515 | { |
1516 | theFlyout = gp_Dir (aFlyoutVector).IsOpposite (aPositiveFlyout, Precision::Angular()) |
1517 | ? -aFlyoutVector.Magnitude() |
1518 | : aFlyoutVector.Magnitude(); |
1519 | } |
1520 | |
af203d54 |
1521 | // Compute attach points (through which main dimension line passes). |
1522 | gp_Pnt aFirstAttach = theFirstPoint.Translated (aFlyoutVector); |
1523 | gp_Pnt aSecondAttach = theSecondPoint.Translated (aFlyoutVector); |
1524 | |
91b16a64 |
1525 | // Set horizontal text alignment. |
af203d54 |
1526 | if (aCos < 0.0) |
1527 | { |
1528 | theAlignment = Prs3d_DTHP_Left; |
1529 | |
1530 | Standard_Real aNewExtSize = theTextPos.Distance (aFirstAttach) - anArrowLength; |
1531 | theExtensionSize = aNewExtSize < 0.0 ? 0.0 : aNewExtSize; |
1532 | } |
1533 | else if (aTextPosProj.Distance (theFirstPoint) > theFirstPoint.Distance (theSecondPoint)) |
1534 | { |
1535 | theAlignment = Prs3d_DTHP_Right; |
1536 | |
1537 | Standard_Real aNewExtSize = theTextPos.Distance (aSecondAttach) - anArrowLength; |
1538 | theExtensionSize = aNewExtSize < 0.0 ? 0.0 : aNewExtSize; |
1539 | } |
1540 | else |
1541 | { |
1542 | theAlignment = Prs3d_DTHP_Center; |
1543 | } |
91b16a64 |
1544 | return Standard_True; |
af203d54 |
1545 | } |
1546 | |
1547 | //======================================================================= |
1548 | //function : FitTextAlignmentForLinear |
1549 | //purpose : |
1550 | //======================================================================= |
1551 | void AIS_Dimension::FitTextAlignmentForLinear (const gp_Pnt& theFirstPoint, |
1552 | const gp_Pnt& theSecondPoint, |
1553 | const Standard_Boolean theIsOneSide, |
1554 | const Prs3d_DimensionTextHorizontalPosition& theHorizontalTextPos, |
1555 | Standard_Integer& theLabelPosition, |
1556 | Standard_Boolean& theIsArrowsExternal) const |
1557 | { |
1558 | theLabelPosition = LabelPosition_None; |
1559 | theIsArrowsExternal = Standard_False; |
1560 | |
1561 | // Compute dimension line points |
1562 | gp_Ax1 aPlaneNormal = GetPlane().Axis(); |
1563 | gp_Dir aTargetPointsVector = gce_MakeDir (theFirstPoint, theSecondPoint); |
1564 | |
1565 | // compute flyout direction vector |
1566 | gp_Dir aFlyoutVector = aPlaneNormal.Direction() ^ aTargetPointsVector; |
1567 | |
1568 | // create lines for layouts |
1569 | gp_Lin aLine1 (theFirstPoint, aFlyoutVector); |
1570 | gp_Lin aLine2 (theSecondPoint, aFlyoutVector); |
1571 | |
1572 | // Get flyout end points |
1573 | gp_Pnt aLineBegPoint = ElCLib::Value (ElCLib::Parameter (aLine1, theFirstPoint) + GetFlyout(), aLine1); |
1574 | gp_Pnt aLineEndPoint = ElCLib::Value (ElCLib::Parameter (aLine2, theSecondPoint) + GetFlyout(), aLine2); |
1575 | |
1576 | Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect(); |
1577 | |
af203d54 |
1578 | // For extensions we need to know arrow size, text size and extension size: get it from aspect |
1579 | Quantity_Length anArrowLength = aDimensionAspect->ArrowAspect()->Length(); |
1580 | |
1581 | // prepare label string and compute its geometrical width |
1582 | Standard_Real aLabelWidth; |
1583 | TCollection_ExtendedString aLabelString = GetValueString (aLabelWidth); |
1584 | |
1585 | // Add margins to cut dimension lines for 3d text |
1586 | if (aDimensionAspect->IsText3d()) |
1587 | { |
1588 | aLabelWidth += aDimensionAspect->TextAspect()->Height() * THE_3D_TEXT_MARGIN * 2.0; |
1589 | } |
1590 | |
1591 | // Handle user-defined and automatic arrow placement |
1592 | switch (aDimensionAspect->ArrowOrientation()) |
1593 | { |
1594 | case Prs3d_DAO_External: theIsArrowsExternal = true; break; |
1595 | case Prs3d_DAO_Internal: theIsArrowsExternal = false; break; |
1596 | case Prs3d_DAO_Fit: |
1597 | { |
1598 | // Add margin to ensure a small tail between text and arrow |
1599 | Standard_Real anArrowMargin = aDimensionAspect->IsText3d() |
1600 | ? aDimensionAspect->TextAspect()->Height() * THE_3D_TEXT_MARGIN |
1601 | : 0.0; |
1602 | |
1603 | Standard_Real aDimensionWidth = aLineBegPoint.Distance (aLineEndPoint); |
1604 | Standard_Real anArrowsWidth = theIsOneSide |
1605 | ? anArrowLength + anArrowMargin |
1606 | : (anArrowLength + anArrowMargin) * 2.0; |
1607 | |
1608 | theIsArrowsExternal = aDimensionWidth < aLabelWidth + anArrowsWidth; |
1609 | break; |
1610 | } |
1611 | } |
1612 | |
1613 | // Handle user-defined and automatic text placement |
1614 | switch (theHorizontalTextPos) |
1615 | { |
1616 | case Prs3d_DTHP_Left : theLabelPosition |= LabelPosition_Left; break; |
1617 | case Prs3d_DTHP_Right : theLabelPosition |= LabelPosition_Right; break; |
1618 | case Prs3d_DTHP_Center: theLabelPosition |= LabelPosition_HCenter; break; |
1619 | case Prs3d_DTHP_Fit: |
1620 | { |
1621 | Standard_Real aDimensionWidth = aLineBegPoint.Distance (aLineEndPoint); |
1622 | Standard_Real anArrowsWidth = theIsOneSide ? anArrowLength : 2.0 * anArrowLength; |
1623 | Standard_Real aContentWidth = theIsArrowsExternal ? aLabelWidth : aLabelWidth + anArrowsWidth; |
1624 | |
1625 | theLabelPosition |= aDimensionWidth < aContentWidth ? LabelPosition_Left : LabelPosition_HCenter; |
1626 | break; |
1627 | } |
1628 | } |
1629 | |
1630 | // Handle vertical text placement options |
1631 | switch (aDimensionAspect->TextVerticalPosition()) |
1632 | { |
1633 | case Prs3d_DTVP_Above : theLabelPosition |= LabelPosition_Above; break; |
1634 | case Prs3d_DTVP_Below : theLabelPosition |= LabelPosition_Below; break; |
1635 | case Prs3d_DTVP_Center : theLabelPosition |= LabelPosition_VCenter; break; |
1636 | } |
1637 | } |
1638 | |
1639 | //======================================================================= |
1640 | //function : UnsetFixedTextPosition |
1641 | //purpose : |
1642 | //======================================================================= |
1643 | void AIS_Dimension::UnsetFixedTextPosition() |
1644 | { |
1645 | myIsTextPositionFixed = Standard_False; |
1646 | myFixedTextPosition = gp::Origin(); |
1647 | } |