b311480e |
1 | // Created on: 1996-12-05 |
2 | // Created by: Arnaud BOUZY/Odile Olivier |
3 | // Copyright (c) 1996-1999 Matra Datavision |
a6eb515f |
4 | // Copyright (c) 1999-2013 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
b311480e |
16 | |
a6eb515f |
17 | #include <AIS_LengthDimension.hxx> |
7fd59977 |
18 | |
19 | #include <AIS.hxx> |
a6eb515f |
20 | #include <BRep_Tool.hxx> |
7fd59977 |
21 | #include <BRepAdaptor_Curve.hxx> |
a6eb515f |
22 | #include <BRepLib_MakeVertex.hxx> |
23 | #include <BRepTopAdaptor_FClass2d.hxx> |
60bf98ae |
24 | #include <BRepTools.hxx> |
7fd59977 |
25 | #include <ElCLib.hxx> |
26 | #include <ElSLib.hxx> |
a6eb515f |
27 | #include <gce_MakeDir.hxx> |
60bf98ae |
28 | #include <gce_MakePln.hxx> |
29 | #include <GeomAPI_ExtremaCurveCurve.hxx> |
30 | #include <GeomAPI_ExtremaCurveSurface.hxx> |
31 | #include <GeomAPI_ExtremaSurfaceSurface.hxx> |
32 | #include <Geom_Curve.hxx> |
33 | #include <Geom_Line.hxx> |
7fd59977 |
34 | #include <TopExp.hxx> |
35 | #include <TopExp_Explorer.hxx> |
7fd59977 |
36 | |
7fd59977 |
37 | |
38 | //======================================================================= |
39 | //function : Constructor |
60bf98ae |
40 | //purpose : Dimension between two faces |
41 | //======================================================================= |
42 | AIS_LengthDimension::AIS_LengthDimension (const TopoDS_Face& theFirstFace, |
43 | const TopoDS_Face& theSecondFace) |
44 | : AIS_Dimension (AIS_KOD_LENGTH) |
45 | { |
46 | SetMeasuredGeometry (theFirstFace, theSecondFace); |
47 | SetFlyout (15.0); |
48 | } |
49 | |
50 | //======================================================================= |
51 | //function : Constructor |
52 | //purpose : Dimension between two shape |
7fd59977 |
53 | //======================================================================= |
60bf98ae |
54 | AIS_LengthDimension::AIS_LengthDimension (const TopoDS_Face& theFace, |
55 | const TopoDS_Edge& theEdge) |
56 | : AIS_Dimension (AIS_KOD_LENGTH) |
57 | { |
58 | SetMeasuredGeometry (theFace, theEdge); |
59 | SetFlyout (15.0); |
60 | } |
7fd59977 |
61 | |
60bf98ae |
62 | //======================================================================= |
63 | //function : Constructor |
64 | //purpose : Dimension between two points |
65 | //======================================================================= |
a6eb515f |
66 | AIS_LengthDimension::AIS_LengthDimension (const gp_Pnt& theFirstPoint, |
67 | const gp_Pnt& theSecondPoint, |
60bf98ae |
68 | const gp_Pln& thePlane) |
69 | : AIS_Dimension (AIS_KOD_LENGTH) |
7fd59977 |
70 | { |
60bf98ae |
71 | SetMeasuredGeometry (theFirstPoint, theSecondPoint, thePlane); |
d7bffd44 |
72 | SetFlyout (15.0); |
7fd59977 |
73 | } |
74 | |
7fd59977 |
75 | //======================================================================= |
76 | //function : Constructor |
a6eb515f |
77 | //purpose : Dimension between two shape |
7fd59977 |
78 | //======================================================================= |
a6eb515f |
79 | AIS_LengthDimension::AIS_LengthDimension (const TopoDS_Shape& theFirstShape, |
80 | const TopoDS_Shape& theSecondShape, |
60bf98ae |
81 | const gp_Pln& thePlane) |
82 | : AIS_Dimension (AIS_KOD_LENGTH) |
7fd59977 |
83 | { |
60bf98ae |
84 | SetCustomPlane (thePlane); |
85 | SetMeasuredShapes (theFirstShape, theSecondShape); |
d7bffd44 |
86 | SetFlyout (15.0); |
7fd59977 |
87 | } |
88 | |
89 | //======================================================================= |
90 | //function : Constructor |
a6eb515f |
91 | //purpose : Dimension of one edge |
7fd59977 |
92 | //======================================================================= |
a6eb515f |
93 | AIS_LengthDimension::AIS_LengthDimension (const TopoDS_Edge& theEdge, |
60bf98ae |
94 | const gp_Pln& thePlane) |
95 | : AIS_Dimension (AIS_KOD_LENGTH) |
7fd59977 |
96 | { |
60bf98ae |
97 | SetMeasuredGeometry (theEdge, thePlane); |
d7bffd44 |
98 | SetFlyout (15.0); |
7fd59977 |
99 | } |
100 | |
7fd59977 |
101 | //======================================================================= |
60bf98ae |
102 | //function : SetMeasuredGeometry |
103 | //purpose : |
7fd59977 |
104 | //======================================================================= |
60bf98ae |
105 | void AIS_LengthDimension::SetMeasuredGeometry (const gp_Pnt& theFirstPoint, |
106 | const gp_Pnt& theSecondPoint, |
107 | const gp_Pln& thePlane) |
108 | { |
91b16a64 |
109 | myFirstPoint = theFirstPoint; |
110 | mySecondPoint = theSecondPoint; |
111 | myFirstShape = BRepLib_MakeVertex (myFirstPoint); |
112 | mySecondShape = BRepLib_MakeVertex (mySecondPoint); |
113 | myGeometryType = GeometryType_Points; |
60bf98ae |
114 | SetCustomPlane (thePlane); |
91b16a64 |
115 | myIsGeometryValid = IsValidPoints (theFirstPoint, theSecondPoint); |
60bf98ae |
116 | |
117 | SetToUpdate(); |
118 | } |
7fd59977 |
119 | |
60bf98ae |
120 | //======================================================================= |
121 | //function : SetMeasuredGeometry |
122 | //purpose : |
123 | //======================================================================= |
124 | void AIS_LengthDimension::SetMeasuredGeometry (const TopoDS_Edge& theEdge, |
125 | const gp_Pln& thePlane) |
7fd59977 |
126 | { |
91b16a64 |
127 | myFirstShape = theEdge; |
128 | mySecondShape = TopoDS_Shape(); |
129 | myGeometryType = GeometryType_Edge; |
60bf98ae |
130 | SetCustomPlane (thePlane); |
91b16a64 |
131 | myIsGeometryValid = InitOneShapePoints (myFirstShape); |
60bf98ae |
132 | |
133 | SetToUpdate(); |
7fd59977 |
134 | } |
135 | |
136 | //======================================================================= |
60bf98ae |
137 | //function : SetMeasuredGeometry |
138 | //purpose : |
7fd59977 |
139 | //======================================================================= |
60bf98ae |
140 | void AIS_LengthDimension::SetMeasuredGeometry (const TopoDS_Face& theFirstFace, |
141 | const TopoDS_Face& theSecondFace) |
142 | { |
143 | SetMeasuredShapes (theFirstFace, theSecondFace); |
144 | } |
7fd59977 |
145 | |
60bf98ae |
146 | //======================================================================= |
147 | //function : SetMeasuredGeometry |
148 | //purpose : |
149 | //======================================================================= |
150 | void AIS_LengthDimension::SetMeasuredGeometry (const TopoDS_Face& theFace, |
151 | const TopoDS_Edge& theEdge) |
7fd59977 |
152 | { |
60bf98ae |
153 | SetMeasuredShapes (theFace, theEdge); |
154 | } |
155 | |
156 | //======================================================================= |
157 | //function : SetMeasuredShapes |
158 | //purpose : |
159 | //======================================================================= |
160 | void AIS_LengthDimension::SetMeasuredShapes (const TopoDS_Shape& theFirstShape, |
161 | const TopoDS_Shape& theSecondShape) |
162 | { |
163 | gp_Pln aComputedPlane; |
164 | Standard_Boolean isPlaneReturned = Standard_False; |
60bf98ae |
165 | |
91b16a64 |
166 | myFirstShape = theFirstShape; |
167 | mySecondShape = theSecondShape; |
168 | myIsGeometryValid = InitTwoShapesPoints (myFirstShape, mySecondShape, aComputedPlane, isPlaneReturned); |
169 | |
170 | if (myIsGeometryValid && !myIsPlaneCustom) |
60bf98ae |
171 | { |
172 | if (isPlaneReturned) |
173 | { |
174 | myPlane = aComputedPlane; |
175 | } |
176 | else |
177 | { |
91b16a64 |
178 | myIsGeometryValid = Standard_False; |
60bf98ae |
179 | } |
180 | } |
181 | |
60bf98ae |
182 | SetToUpdate(); |
183 | } |
184 | |
185 | //======================================================================= |
186 | //function : CheckPlane |
187 | //purpose : |
188 | //======================================================================= |
189 | Standard_Boolean AIS_LengthDimension::CheckPlane (const gp_Pln& thePlane) const |
190 | { |
b0804487 |
191 | Standard_Boolean anIsFaultyNormal = |
192 | thePlane.Axis().Direction().IsParallel(gce_MakeDir (myFirstPoint, mySecondPoint), Precision::Angular()); |
193 | |
194 | if ((!thePlane.Contains (myFirstPoint, Precision::Confusion()) && !thePlane.Contains (mySecondPoint, Precision::Confusion())) |
195 | || anIsFaultyNormal) |
60bf98ae |
196 | { |
197 | return Standard_False; |
198 | } |
199 | |
200 | return Standard_True; |
201 | } |
202 | |
203 | //======================================================================= |
204 | //function : ComputePlane |
205 | //purpose : |
206 | //======================================================================= |
207 | gp_Pln AIS_LengthDimension::ComputePlane (const gp_Dir& theAttachDir) const |
208 | { |
209 | if (!IsValidPoints (myFirstPoint, mySecondPoint)) |
210 | { |
211 | return gp_Pln(); |
212 | } |
213 | |
214 | gp_Pnt aThirdPoint (myFirstPoint.Translated (gp_Vec(theAttachDir))); |
215 | gce_MakePln aPlaneConstrustor (myFirstPoint, mySecondPoint, aThirdPoint); |
216 | return aPlaneConstrustor.Value(); |
217 | } |
218 | |
219 | //======================================================================= |
220 | //function : GetModelUnits |
221 | //purpose : |
222 | //======================================================================= |
223 | const TCollection_AsciiString& AIS_LengthDimension::GetModelUnits() const |
224 | { |
225 | return myDrawer->DimLengthModelUnits(); |
7fd59977 |
226 | } |
227 | |
228 | //======================================================================= |
60bf98ae |
229 | //function : GetDisplayUnits |
230 | //purpose : |
7fd59977 |
231 | //======================================================================= |
60bf98ae |
232 | const TCollection_AsciiString& AIS_LengthDimension::GetDisplayUnits() const |
233 | { |
234 | return myDrawer->DimLengthDisplayUnits(); |
235 | } |
236 | |
237 | //======================================================================= |
238 | //function : SetModelUnits |
239 | //purpose : |
240 | //======================================================================= |
241 | void AIS_LengthDimension::SetModelUnits (const TCollection_AsciiString& theUnits) |
242 | { |
243 | myDrawer->SetDimLengthModelUnits (theUnits); |
244 | } |
245 | |
246 | //======================================================================= |
247 | //function : SetDisplayUnits |
248 | //purpose : |
249 | //======================================================================= |
250 | void AIS_LengthDimension::SetDisplayUnits (const TCollection_AsciiString& theUnits) |
251 | { |
252 | myDrawer->SetDimLengthDisplayUnits (theUnits); |
253 | } |
7fd59977 |
254 | |
60bf98ae |
255 | //======================================================================= |
256 | //function : ComputeValue |
257 | //purpose : |
258 | //======================================================================= |
259 | Standard_Real AIS_LengthDimension::ComputeValue() const |
260 | { |
261 | return IsValid() ? myFirstPoint.Distance (mySecondPoint) : 0.0; |
262 | } |
263 | |
264 | //======================================================================= |
265 | //function : Compute |
266 | //purpose : |
267 | //======================================================================= |
268 | void AIS_LengthDimension::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePM*/, |
269 | const Handle(Prs3d_Presentation)& thePresentation, |
270 | const Standard_Integer theMode) |
271 | { |
272 | thePresentation->Clear(); |
273 | mySelectionGeom.Clear (theMode); |
274 | |
275 | if (!IsValid()) |
276 | { |
277 | return; |
278 | } |
279 | |
280 | DrawLinearDimension (thePresentation, theMode, myFirstPoint, mySecondPoint); |
281 | } |
282 | |
283 | //======================================================================= |
284 | //function : ComputeFlyoutSelection |
285 | //purpose : |
286 | //======================================================================= |
287 | void AIS_LengthDimension::ComputeFlyoutSelection (const Handle(SelectMgr_Selection)& theSelection, |
288 | const Handle(SelectMgr_EntityOwner)& theEntityOwner) |
289 | { |
290 | if (!IsValid()) |
291 | { |
292 | return; |
293 | } |
294 | |
295 | ComputeLinearFlyouts (theSelection, theEntityOwner, myFirstPoint, mySecondPoint); |
296 | } |
297 | |
298 | //======================================================================= |
299 | //function : IsValidPoints |
300 | //purpose : |
301 | //======================================================================= |
302 | Standard_Boolean AIS_LengthDimension::IsValidPoints (const gp_Pnt& theFirstPoint, |
303 | const gp_Pnt& theSecondPoint) const |
304 | { |
305 | return theFirstPoint.Distance (theSecondPoint) > Precision::Confusion(); |
306 | } |
307 | |
308 | //======================================================================= |
309 | //function : InitTwoEdgesLength |
310 | //purpose : Initialization of dimension between two linear edges |
311 | //======================================================================= |
312 | Standard_Boolean AIS_LengthDimension::InitTwoEdgesLength (const TopoDS_Edge& theFirstEdge, |
d7bffd44 |
313 | const TopoDS_Edge& theSecondEdge, |
314 | gp_Dir& theDirAttach) |
7fd59977 |
315 | { |
a6eb515f |
316 | BRepAdaptor_Curve aFirstCurveAdapt (theFirstEdge); |
317 | if (aFirstCurveAdapt.GetType() != GeomAbs_Line) |
60bf98ae |
318 | { |
a6eb515f |
319 | return Standard_False; |
60bf98ae |
320 | } |
321 | |
a6eb515f |
322 | BRepAdaptor_Curve aSecondCurveAdapt (theSecondEdge); |
323 | if (aSecondCurveAdapt.GetType() != GeomAbs_Line) |
60bf98ae |
324 | { |
a6eb515f |
325 | return Standard_False; |
60bf98ae |
326 | } |
a6eb515f |
327 | |
60bf98ae |
328 | Handle(Geom_Curve) aFirstCurve; |
329 | Handle(Geom_Curve) aSecondCurve; |
330 | |
331 | gp_Pnt aPoint11 (gp::Origin()); |
332 | gp_Pnt aPoint12 (gp::Origin()); |
333 | gp_Pnt aPoint21 (gp::Origin()); |
334 | gp_Pnt aPoint22 (gp::Origin()); |
335 | Standard_Boolean isFirstInfinite = Standard_False; |
336 | Standard_Boolean isSecondInfinite = Standard_False; |
337 | |
338 | if (!AIS::ComputeGeometry (theFirstEdge, theSecondEdge, |
339 | aFirstCurve, aSecondCurve, |
340 | aPoint11, aPoint12, |
341 | aPoint21, aPoint22, |
342 | isFirstInfinite, |
343 | isSecondInfinite)) |
a6eb515f |
344 | { |
60bf98ae |
345 | return Standard_False; |
a6eb515f |
346 | } |
60bf98ae |
347 | |
348 | const Handle(Geom_Line) aFirstLine = Handle(Geom_Line)::DownCast (aFirstCurve); |
349 | const Handle(Geom_Line) aSecondLine = Handle(Geom_Line)::DownCast (aSecondCurve); |
350 | |
351 | if (!aFirstLine->Lin().Direction().IsParallel (aSecondLine->Lin().Direction(),Precision::Angular())) |
a6eb515f |
352 | { |
60bf98ae |
353 | return Standard_False; |
7fd59977 |
354 | } |
60bf98ae |
355 | |
356 | theDirAttach = aFirstLine->Lin().Direction(); |
357 | |
358 | gp_Pnt aPoint; |
359 | |
a6eb515f |
360 | if (!isFirstInfinite) |
361 | { |
60bf98ae |
362 | if (AIS::Nearest (aSecondCurve, aPoint11, aPoint21, aPoint22, aPoint)) |
363 | { |
a6eb515f |
364 | myFirstPoint = aPoint11; |
60bf98ae |
365 | mySecondPoint = aPoint; |
366 | return IsValidPoints (myFirstPoint, mySecondPoint); |
367 | } |
368 | else if (AIS::Nearest (aSecondCurve, aPoint12, aPoint21, aPoint22, aPoint)) |
369 | { |
370 | myFirstPoint = aPoint12; |
371 | mySecondPoint = aPoint; |
372 | return IsValidPoints (myFirstPoint, mySecondPoint); |
373 | } |
7fd59977 |
374 | } |
375 | |
a6eb515f |
376 | if (!isSecondInfinite) |
377 | { |
60bf98ae |
378 | if (AIS::Nearest (aFirstCurve, aPoint21, aPoint11, aPoint12, aPoint)) |
379 | { |
380 | myFirstPoint = aPoint; |
a6eb515f |
381 | mySecondPoint = aPoint21; |
60bf98ae |
382 | return IsValidPoints (myFirstPoint, mySecondPoint); |
383 | } |
384 | if (AIS::Nearest (aFirstCurve, aPoint22, aPoint11, aPoint12, aPoint)) |
385 | { |
386 | myFirstPoint = aPoint; |
387 | mySecondPoint = aPoint22; |
388 | return IsValidPoints (myFirstPoint, mySecondPoint); |
389 | } |
a6eb515f |
390 | } |
7fd59977 |
391 | |
60bf98ae |
392 | GeomAPI_ExtremaCurveCurve anExtrema (aFirstCurve, aSecondCurve); |
393 | anExtrema.NearestPoints (myFirstPoint, mySecondPoint); |
394 | return IsValidPoints (myFirstPoint, mySecondPoint); |
7fd59977 |
395 | } |
396 | |
7fd59977 |
397 | //======================================================================= |
60bf98ae |
398 | //function : InitEdgeVertexLength |
a6eb515f |
399 | //purpose : for first edge and second vertex shapes |
7fd59977 |
400 | //======================================================================= |
60bf98ae |
401 | Standard_Boolean AIS_LengthDimension::InitEdgeVertexLength (const TopoDS_Edge& theEdge, |
402 | const TopoDS_Vertex& theVertex, |
403 | gp_Dir& theEdgeDir, |
d7bffd44 |
404 | Standard_Boolean isInfinite) |
7fd59977 |
405 | { |
60bf98ae |
406 | gp_Pnt anEdgePoint1 (gp::Origin()); |
407 | gp_Pnt anEdgePoint2 (gp::Origin()); |
a6eb515f |
408 | Handle(Geom_Curve) aCurve; |
60bf98ae |
409 | |
410 | if (!AIS::ComputeGeometry (theEdge, aCurve, anEdgePoint1, anEdgePoint2, isInfinite)) |
411 | { |
a6eb515f |
412 | return Standard_False; |
60bf98ae |
413 | } |
414 | |
415 | myFirstPoint = BRep_Tool::Pnt (theVertex); |
a6eb515f |
416 | |
c5f3a425 |
417 | Handle(Geom_Line) aGeomLine (Handle(Geom_Line)::DownCast (aCurve)); |
a6eb515f |
418 | const gp_Lin& aLin = aGeomLine->Lin(); |
419 | |
60bf98ae |
420 | // Get direction of edge to build plane automatically. |
421 | theEdgeDir = aLin.Direction(); |
a6eb515f |
422 | |
60bf98ae |
423 | mySecondPoint = AIS::Nearest (aLin, myFirstPoint); |
a6eb515f |
424 | |
60bf98ae |
425 | return IsValidPoints (myFirstPoint, mySecondPoint); |
7fd59977 |
426 | } |
427 | |
7fd59977 |
428 | //======================================================================= |
60bf98ae |
429 | //function : InitEdgeFaceLength |
7fd59977 |
430 | //purpose : |
431 | //======================================================================= |
60bf98ae |
432 | Standard_Boolean AIS_LengthDimension::InitEdgeFaceLength (const TopoDS_Edge& theEdge, |
a6eb515f |
433 | const TopoDS_Face& theFace, |
60bf98ae |
434 | gp_Dir& theEdgeDir) |
7fd59977 |
435 | { |
60bf98ae |
436 | Handle(Geom_Curve) aCurve; |
437 | gp_Pnt aFirstPoint, aSecondPoint; |
438 | Standard_Boolean isInfinite = Standard_False; |
439 | |
440 | if (!AIS::ComputeGeometry (theEdge, aCurve, aFirstPoint, aSecondPoint, isInfinite)) |
a6eb515f |
441 | { |
60bf98ae |
442 | return Standard_False; |
7fd59977 |
443 | } |
60bf98ae |
444 | theEdgeDir = gce_MakeDir (aFirstPoint, aSecondPoint); |
445 | gp_Pln aPlane; |
446 | Handle(Geom_Surface) aSurface; |
447 | AIS_KindOfSurface aSurfType; |
448 | Standard_Real anOffset; |
7fd59977 |
449 | |
60bf98ae |
450 | if (!AIS::GetPlaneFromFace (theFace, aPlane, aSurface, aSurfType, anOffset)) |
a6eb515f |
451 | { |
60bf98ae |
452 | return Standard_False; |
7fd59977 |
453 | } |
7fd59977 |
454 | |
60bf98ae |
455 | GeomAPI_ExtremaCurveSurface aDistAdaptor (aCurve, aSurface); |
fe83e1ea |
456 | |
60bf98ae |
457 | aDistAdaptor.NearestPoints (myFirstPoint, mySecondPoint); |
458 | |
459 | return IsValidPoints (myFirstPoint, mySecondPoint); |
7fd59977 |
460 | } |
461 | |
462 | //======================================================================= |
60bf98ae |
463 | //function : InitTwoShapesPoints |
a6eb515f |
464 | //purpose : Initialization of two points where dimension layouts |
465 | // will be attached |
7fd59977 |
466 | //======================================================================= |
60bf98ae |
467 | Standard_Boolean AIS_LengthDimension::InitTwoShapesPoints (const TopoDS_Shape& theFirstShape, |
468 | const TopoDS_Shape& theSecondShape, |
469 | gp_Pln& theComputedPlane, |
470 | Standard_Boolean& theIsPlaneComputed) |
7fd59977 |
471 | { |
60bf98ae |
472 | theIsPlaneComputed = Standard_False; |
a6eb515f |
473 | gp_Dir aDirAttach; |
474 | Standard_Boolean isInfinite = Standard_False; |
60bf98ae |
475 | Standard_Boolean isSuccess = Standard_False; |
a6eb515f |
476 | switch (theFirstShape.ShapeType()) |
477 | { |
60bf98ae |
478 | case TopAbs_FACE: |
7fd59977 |
479 | { |
a6eb515f |
480 | // Initialization for face |
481 | gp_Pln aFirstPlane; |
482 | Handle(Geom_Surface) aFirstSurface; |
483 | AIS_KindOfSurface aFirstSurfKind; |
484 | Standard_Real aFirstOffset; |
60bf98ae |
485 | |
a6eb515f |
486 | TopoDS_Face aFirstFace = TopoDS::Face (theFirstShape); |
a6eb515f |
487 | |
60bf98ae |
488 | AIS::InitFaceLength (TopoDS::Face (theFirstShape), |
489 | aFirstPlane, |
490 | aFirstSurface, |
491 | aFirstSurfKind, |
492 | aFirstOffset); |
493 | |
494 | if (theSecondShape.ShapeType() == TopAbs_FACE) |
a6eb515f |
495 | { |
496 | // Initialization for face |
60bf98ae |
497 | myGeometryType = GeometryType_Faces; |
a6eb515f |
498 | gp_Pln aSecondPlane; |
499 | Handle(Geom_Surface) aSecondSurface; |
500 | AIS_KindOfSurface aSecondSurfKind; |
501 | Standard_Real aSecondOffset; |
60bf98ae |
502 | |
a6eb515f |
503 | TopoDS_Face aSecondFace = TopoDS::Face (theSecondShape); |
60bf98ae |
504 | |
505 | AIS::InitFaceLength (aSecondFace, |
506 | aSecondPlane, |
507 | aSecondSurface, |
508 | aSecondSurfKind, |
509 | aSecondOffset); |
510 | |
a6eb515f |
511 | if (aFirstSurfKind == AIS_KOS_Plane) |
7fd59977 |
512 | { |
60bf98ae |
513 | if (!aFirstPlane.Axis().Direction().IsParallel (aSecondPlane.Axis().Direction(), Precision::Angular())) |
514 | { |
515 | return Standard_False; |
516 | } |
517 | |
a6eb515f |
518 | TopExp_Explorer anExplorer (theFirstShape, TopAbs_VERTEX); |
60bf98ae |
519 | |
a6eb515f |
520 | // In case of infinite planes |
521 | if (!anExplorer.More()) |
60bf98ae |
522 | { |
a6eb515f |
523 | myFirstPoint = aFirstPlane.Location(); |
60bf98ae |
524 | } |
525 | else |
526 | { |
527 | myFirstPoint = BRep_Tool::Pnt (TopoDS::Vertex (anExplorer.Current())); |
528 | } |
529 | |
a6eb515f |
530 | mySecondPoint = AIS::ProjectPointOnPlane (myFirstPoint, aSecondPlane); |
531 | |
a6eb515f |
532 | Quantity_Parameter anU, aV; |
533 | ElSLib::Parameters (aSecondPlane, mySecondPoint, anU, aV); |
60bf98ae |
534 | |
a6eb515f |
535 | BRepTopAdaptor_FClass2d aClassifier (aSecondFace, Precision::Confusion()); |
536 | TopAbs_State aState = aClassifier.Perform (gp_Pnt2d (anU, aV), Standard_False); |
60bf98ae |
537 | |
a6eb515f |
538 | if (aState == TopAbs_OUT || aState == TopAbs_UNKNOWN) |
539 | { |
60bf98ae |
540 | mySecondPoint = AIS::Nearest (aSecondFace, myFirstPoint); |
541 | } |
542 | |
543 | isSuccess = IsValidPoints (myFirstPoint, mySecondPoint); |
544 | if (isSuccess) |
545 | { |
546 | theComputedPlane = ComputePlane (aFirstPlane.Position().XDirection()); |
547 | theIsPlaneComputed = Standard_True; |
a6eb515f |
548 | } |
7fd59977 |
549 | } |
a6eb515f |
550 | else // curvilinear faces |
7fd59977 |
551 | { |
60bf98ae |
552 | Standard_Real aU1Min, aV1Min, aU1Max, aV1Max; |
553 | Standard_Real aU2Min, aV2Min, aU2Max, aV2Max; |
554 | BRepTools::UVBounds (aFirstFace, aU1Min, aU1Max, aV1Min, aV1Max); |
555 | BRepTools::UVBounds (aSecondFace, aU2Min, aU2Max, aV2Min, aV2Max); |
556 | |
557 | GeomAPI_ExtremaSurfaceSurface anExtrema (aFirstSurface, aSecondSurface, |
558 | aU1Min, aU1Max, aV1Min, aV1Max, |
559 | aU2Min, aU2Max, aV2Min, aV2Max); |
560 | |
561 | Standard_Real aU1, aV1, aU2, aV2; |
562 | anExtrema.LowerDistanceParameters (aU1, aV1, aU2, aV2); |
563 | myFirstPoint = BRep_Tool::Surface (aFirstFace)->Value (aU1, aV1); |
564 | mySecondPoint = BRep_Tool::Surface (aSecondFace)->Value (aU2, aV2); |
565 | |
566 | // Adjust automatic plane |
567 | gp_Ax2 aLocalAxes (myFirstPoint, gce_MakeDir (myFirstPoint, mySecondPoint)); |
568 | aDirAttach = gce_MakeDir (aLocalAxes.XDirection ()); |
569 | |
570 | // Check points |
571 | isSuccess = IsValidPoints (myFirstPoint, mySecondPoint); |
572 | if (isSuccess) |
573 | { |
574 | theComputedPlane = ComputePlane (aDirAttach); |
575 | theIsPlaneComputed = Standard_True; |
576 | } |
7fd59977 |
577 | } |
60bf98ae |
578 | |
579 | return isSuccess && IsValidPoints (myFirstPoint, mySecondPoint); |
a6eb515f |
580 | } |
581 | else if (theFirstShape.ShapeType() == TopAbs_EDGE) |
582 | { |
60bf98ae |
583 | myGeometryType = GeometryType_EdgeFace; |
584 | isSuccess = InitEdgeFaceLength (TopoDS::Edge (theFirstShape), |
a6eb515f |
585 | TopoDS::Face (theSecondShape), |
586 | aDirAttach); |
60bf98ae |
587 | |
588 | if (isSuccess) |
589 | { |
590 | theComputedPlane = ComputePlane (aDirAttach); |
591 | theIsPlaneComputed = Standard_True; |
592 | } |
593 | |
594 | return isSuccess; |
a6eb515f |
595 | } |
7fd59977 |
596 | } |
a6eb515f |
597 | break; |
60bf98ae |
598 | |
599 | case TopAbs_EDGE: |
7fd59977 |
600 | { |
a6eb515f |
601 | if (theSecondShape.ShapeType() == TopAbs_VERTEX) |
602 | { |
60bf98ae |
603 | myGeometryType = GeometryType_EdgeVertex; |
604 | isSuccess = InitEdgeVertexLength (TopoDS::Edge (theFirstShape), |
605 | TopoDS::Vertex (theSecondShape), |
606 | aDirAttach, |
607 | isInfinite); |
608 | |
609 | if (isSuccess) |
610 | { |
611 | theComputedPlane = ComputePlane (aDirAttach); |
612 | theIsPlaneComputed = Standard_True; |
613 | } |
614 | |
615 | return isSuccess; |
a6eb515f |
616 | } |
617 | else if (theSecondShape.ShapeType() == TopAbs_EDGE) |
618 | { |
60bf98ae |
619 | myGeometryType = GeometryType_Edges; |
620 | isSuccess = InitTwoEdgesLength (TopoDS::Edge (theFirstShape), |
621 | TopoDS::Edge (theSecondShape), |
622 | aDirAttach); |
623 | |
624 | if (isSuccess) |
625 | { |
626 | theComputedPlane = ComputePlane (aDirAttach); |
627 | theIsPlaneComputed = Standard_True; |
628 | } |
629 | |
630 | return isSuccess; |
a6eb515f |
631 | } |
7fd59977 |
632 | } |
a6eb515f |
633 | break; |
60bf98ae |
634 | |
635 | case TopAbs_VERTEX: |
7fd59977 |
636 | { |
a6eb515f |
637 | if (theSecondShape.ShapeType() == TopAbs_VERTEX) |
638 | { |
60bf98ae |
639 | myGeometryType = GeometryType_Points; |
640 | myFirstPoint = BRep_Tool::Pnt (TopoDS::Vertex (theFirstShape)); |
a6eb515f |
641 | mySecondPoint = BRep_Tool::Pnt (TopoDS::Vertex (theSecondShape)); |
60bf98ae |
642 | |
643 | return IsValidPoints (myFirstPoint, mySecondPoint); |
a6eb515f |
644 | } |
645 | else if (theSecondShape.ShapeType() == TopAbs_EDGE) |
646 | { |
60bf98ae |
647 | myGeometryType = GeometryType_EdgeVertex; |
51740958 |
648 | isSuccess = InitEdgeVertexLength (TopoDS::Edge(theSecondShape), |
649 | TopoDS::Vertex(theFirstShape), |
650 | aDirAttach, |
651 | isInfinite); |
60bf98ae |
652 | if (isSuccess) |
653 | { |
654 | theComputedPlane = ComputePlane (aDirAttach); |
655 | theIsPlaneComputed = Standard_True; |
656 | } |
657 | |
658 | return isSuccess; |
a6eb515f |
659 | } |
7fd59977 |
660 | } |
a6eb515f |
661 | break; |
60bf98ae |
662 | |
663 | case TopAbs_COMPOUND: |
664 | case TopAbs_COMPSOLID: |
665 | case TopAbs_SOLID: |
666 | case TopAbs_SHELL: |
667 | case TopAbs_WIRE: |
668 | case TopAbs_SHAPE: |
669 | break; |
a6eb515f |
670 | } |
60bf98ae |
671 | |
672 | return Standard_False; |
7fd59977 |
673 | } |
674 | |
675 | //======================================================================= |
60bf98ae |
676 | //function : InitOneShapePoints |
a6eb515f |
677 | //purpose : Initialization of two points where dimension layouts |
678 | // will be attached |
679 | // Attention: 1) <theShape> can be only the edge in currect implementation |
680 | // 2) No length for infinite edge |
7fd59977 |
681 | //======================================================================= |
60bf98ae |
682 | Standard_Boolean AIS_LengthDimension::InitOneShapePoints (const TopoDS_Shape& theShape) |
7fd59977 |
683 | { |
60bf98ae |
684 | if (theShape.ShapeType() != TopAbs_EDGE) |
a6eb515f |
685 | { |
a6eb515f |
686 | return Standard_False; |
60bf98ae |
687 | } |
7fd59977 |
688 | |
60bf98ae |
689 | TopoDS_Edge anEdge = TopoDS::Edge (theShape); |
7fd59977 |
690 | |
60bf98ae |
691 | BRepAdaptor_Curve aBrepCurve(anEdge); |
692 | Standard_Real aFirst = aBrepCurve.FirstParameter(); |
693 | Standard_Real aLast = aBrepCurve.LastParameter(); |
fe83e1ea |
694 | |
60bf98ae |
695 | if (aBrepCurve.GetType() != GeomAbs_Line) |
a6eb515f |
696 | { |
60bf98ae |
697 | return Standard_False; |
7fd59977 |
698 | } |
d7bffd44 |
699 | |
60bf98ae |
700 | Standard_Boolean isInfinite = (Precision::IsInfinite (aFirst) || Precision::IsInfinite (aLast)); |
701 | if (isInfinite) |
d7bffd44 |
702 | { |
60bf98ae |
703 | return Standard_False; |
d7bffd44 |
704 | } |
7fd59977 |
705 | |
60bf98ae |
706 | myFirstPoint = aBrepCurve.Value (aBrepCurve.FirstParameter()); |
707 | mySecondPoint = aBrepCurve.Value (aBrepCurve.LastParameter()); |
7fd59977 |
708 | |
60bf98ae |
709 | return IsValidPoints (myFirstPoint, mySecondPoint); |
7fd59977 |
710 | } |
af203d54 |
711 | |
712 | //======================================================================= |
713 | //function : GetTextPosition |
714 | //purpose : |
715 | //======================================================================= |
716 | const gp_Pnt AIS_LengthDimension::GetTextPosition() const |
717 | { |
718 | if (IsTextPositionCustom()) |
719 | { |
720 | return myFixedTextPosition; |
721 | } |
722 | |
723 | // Counts text position according to the dimension parameters |
724 | return GetTextPositionForLinear (myFirstPoint, mySecondPoint); |
725 | } |
726 | |
727 | //======================================================================= |
728 | //function : SetTextPosition |
729 | //purpose : |
730 | //======================================================================= |
731 | void AIS_LengthDimension::SetTextPosition (const gp_Pnt& theTextPos) |
732 | { |
91b16a64 |
733 | if (!IsValid()) |
af203d54 |
734 | { |
735 | return; |
736 | } |
737 | |
738 | myIsTextPositionFixed = Standard_True; |
739 | myFixedTextPosition = theTextPos; |
740 | |
741 | SetToUpdate(); |
742 | } |