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