0026596: Visualization - hidden twice times structure should not be selectable
[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>
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//=======================================================================
42AIS_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 54AIS_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 66AIS_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 79AIS_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 93AIS_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 105void 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//=======================================================================
124void 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 140void 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//=======================================================================
150void 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//=======================================================================
160void 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//=======================================================================
189Standard_Boolean AIS_LengthDimension::CheckPlane (const gp_Pln& thePlane) const
190{
191 if (!thePlane.Contains (myFirstPoint, Precision::Confusion()) &&
192 !thePlane.Contains (mySecondPoint, Precision::Confusion()))
193 {
194 return Standard_False;
195 }
196
197 return Standard_True;
198}
199
200//=======================================================================
201//function : ComputePlane
202//purpose :
203//=======================================================================
204gp_Pln AIS_LengthDimension::ComputePlane (const gp_Dir& theAttachDir) const
205{
206 if (!IsValidPoints (myFirstPoint, mySecondPoint))
207 {
208 return gp_Pln();
209 }
210
211 gp_Pnt aThirdPoint (myFirstPoint.Translated (gp_Vec(theAttachDir)));
212 gce_MakePln aPlaneConstrustor (myFirstPoint, mySecondPoint, aThirdPoint);
213 return aPlaneConstrustor.Value();
214}
215
216//=======================================================================
217//function : GetModelUnits
218//purpose :
219//=======================================================================
220const TCollection_AsciiString& AIS_LengthDimension::GetModelUnits() const
221{
222 return myDrawer->DimLengthModelUnits();
7fd59977 223}
224
225//=======================================================================
60bf98ae 226//function : GetDisplayUnits
227//purpose :
7fd59977 228//=======================================================================
60bf98ae 229const TCollection_AsciiString& AIS_LengthDimension::GetDisplayUnits() const
230{
231 return myDrawer->DimLengthDisplayUnits();
232}
233
234//=======================================================================
235//function : SetModelUnits
236//purpose :
237//=======================================================================
238void AIS_LengthDimension::SetModelUnits (const TCollection_AsciiString& theUnits)
239{
240 myDrawer->SetDimLengthModelUnits (theUnits);
241}
242
243//=======================================================================
244//function : SetDisplayUnits
245//purpose :
246//=======================================================================
247void AIS_LengthDimension::SetDisplayUnits (const TCollection_AsciiString& theUnits)
248{
249 myDrawer->SetDimLengthDisplayUnits (theUnits);
250}
7fd59977 251
60bf98ae 252//=======================================================================
253//function : ComputeValue
254//purpose :
255//=======================================================================
256Standard_Real AIS_LengthDimension::ComputeValue() const
257{
258 return IsValid() ? myFirstPoint.Distance (mySecondPoint) : 0.0;
259}
260
261//=======================================================================
262//function : Compute
263//purpose :
264//=======================================================================
265void AIS_LengthDimension::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePM*/,
266 const Handle(Prs3d_Presentation)& thePresentation,
267 const Standard_Integer theMode)
268{
269 thePresentation->Clear();
270 mySelectionGeom.Clear (theMode);
271
272 if (!IsValid())
273 {
274 return;
275 }
276
277 DrawLinearDimension (thePresentation, theMode, myFirstPoint, mySecondPoint);
278}
279
280//=======================================================================
281//function : ComputeFlyoutSelection
282//purpose :
283//=======================================================================
284void AIS_LengthDimension::ComputeFlyoutSelection (const Handle(SelectMgr_Selection)& theSelection,
285 const Handle(SelectMgr_EntityOwner)& theEntityOwner)
286{
287 if (!IsValid())
288 {
289 return;
290 }
291
292 ComputeLinearFlyouts (theSelection, theEntityOwner, myFirstPoint, mySecondPoint);
293}
294
295//=======================================================================
296//function : IsValidPoints
297//purpose :
298//=======================================================================
299Standard_Boolean AIS_LengthDimension::IsValidPoints (const gp_Pnt& theFirstPoint,
300 const gp_Pnt& theSecondPoint) const
301{
302 return theFirstPoint.Distance (theSecondPoint) > Precision::Confusion();
303}
304
305//=======================================================================
306//function : InitTwoEdgesLength
307//purpose : Initialization of dimension between two linear edges
308//=======================================================================
309Standard_Boolean AIS_LengthDimension::InitTwoEdgesLength (const TopoDS_Edge& theFirstEdge,
d7bffd44 310 const TopoDS_Edge& theSecondEdge,
311 gp_Dir& theDirAttach)
7fd59977 312{
a6eb515f 313 BRepAdaptor_Curve aFirstCurveAdapt (theFirstEdge);
314 if (aFirstCurveAdapt.GetType() != GeomAbs_Line)
60bf98ae 315 {
a6eb515f 316 return Standard_False;
60bf98ae 317 }
318
a6eb515f 319 BRepAdaptor_Curve aSecondCurveAdapt (theSecondEdge);
320 if (aSecondCurveAdapt.GetType() != GeomAbs_Line)
60bf98ae 321 {
a6eb515f 322 return Standard_False;
60bf98ae 323 }
a6eb515f 324
60bf98ae 325 Handle(Geom_Curve) aFirstCurve;
326 Handle(Geom_Curve) aSecondCurve;
327
328 gp_Pnt aPoint11 (gp::Origin());
329 gp_Pnt aPoint12 (gp::Origin());
330 gp_Pnt aPoint21 (gp::Origin());
331 gp_Pnt aPoint22 (gp::Origin());
332 Standard_Boolean isFirstInfinite = Standard_False;
333 Standard_Boolean isSecondInfinite = Standard_False;
334
335 if (!AIS::ComputeGeometry (theFirstEdge, theSecondEdge,
336 aFirstCurve, aSecondCurve,
337 aPoint11, aPoint12,
338 aPoint21, aPoint22,
339 isFirstInfinite,
340 isSecondInfinite))
a6eb515f 341 {
60bf98ae 342 return Standard_False;
a6eb515f 343 }
60bf98ae 344
345 const Handle(Geom_Line) aFirstLine = Handle(Geom_Line)::DownCast (aFirstCurve);
346 const Handle(Geom_Line) aSecondLine = Handle(Geom_Line)::DownCast (aSecondCurve);
347
348 if (!aFirstLine->Lin().Direction().IsParallel (aSecondLine->Lin().Direction(),Precision::Angular()))
a6eb515f 349 {
60bf98ae 350 return Standard_False;
7fd59977 351 }
60bf98ae 352
353 theDirAttach = aFirstLine->Lin().Direction();
354
355 gp_Pnt aPoint;
356
a6eb515f 357 if (!isFirstInfinite)
358 {
60bf98ae 359 if (AIS::Nearest (aSecondCurve, aPoint11, aPoint21, aPoint22, aPoint))
360 {
a6eb515f 361 myFirstPoint = aPoint11;
60bf98ae 362 mySecondPoint = aPoint;
363 return IsValidPoints (myFirstPoint, mySecondPoint);
364 }
365 else if (AIS::Nearest (aSecondCurve, aPoint12, aPoint21, aPoint22, aPoint))
366 {
367 myFirstPoint = aPoint12;
368 mySecondPoint = aPoint;
369 return IsValidPoints (myFirstPoint, mySecondPoint);
370 }
7fd59977 371 }
372
a6eb515f 373 if (!isSecondInfinite)
374 {
60bf98ae 375 if (AIS::Nearest (aFirstCurve, aPoint21, aPoint11, aPoint12, aPoint))
376 {
377 myFirstPoint = aPoint;
a6eb515f 378 mySecondPoint = aPoint21;
60bf98ae 379 return IsValidPoints (myFirstPoint, mySecondPoint);
380 }
381 if (AIS::Nearest (aFirstCurve, aPoint22, aPoint11, aPoint12, aPoint))
382 {
383 myFirstPoint = aPoint;
384 mySecondPoint = aPoint22;
385 return IsValidPoints (myFirstPoint, mySecondPoint);
386 }
a6eb515f 387 }
7fd59977 388
60bf98ae 389 GeomAPI_ExtremaCurveCurve anExtrema (aFirstCurve, aSecondCurve);
390 anExtrema.NearestPoints (myFirstPoint, mySecondPoint);
391 return IsValidPoints (myFirstPoint, mySecondPoint);
7fd59977 392}
393
7fd59977 394//=======================================================================
60bf98ae 395//function : InitEdgeVertexLength
a6eb515f 396//purpose : for first edge and second vertex shapes
7fd59977 397//=======================================================================
60bf98ae 398Standard_Boolean AIS_LengthDimension::InitEdgeVertexLength (const TopoDS_Edge& theEdge,
399 const TopoDS_Vertex& theVertex,
400 gp_Dir& theEdgeDir,
d7bffd44 401 Standard_Boolean isInfinite)
7fd59977 402{
60bf98ae 403 gp_Pnt anEdgePoint1 (gp::Origin());
404 gp_Pnt anEdgePoint2 (gp::Origin());
a6eb515f 405 Handle(Geom_Curve) aCurve;
60bf98ae 406
407 if (!AIS::ComputeGeometry (theEdge, aCurve, anEdgePoint1, anEdgePoint2, isInfinite))
408 {
a6eb515f 409 return Standard_False;
60bf98ae 410 }
411
412 myFirstPoint = BRep_Tool::Pnt (theVertex);
a6eb515f 413
c5f3a425 414 Handle(Geom_Line) aGeomLine (Handle(Geom_Line)::DownCast (aCurve));
a6eb515f 415 const gp_Lin& aLin = aGeomLine->Lin();
416
60bf98ae 417 // Get direction of edge to build plane automatically.
418 theEdgeDir = aLin.Direction();
a6eb515f 419
60bf98ae 420 mySecondPoint = AIS::Nearest (aLin, myFirstPoint);
a6eb515f 421
60bf98ae 422 return IsValidPoints (myFirstPoint, mySecondPoint);
7fd59977 423}
424
7fd59977 425//=======================================================================
60bf98ae 426//function : InitEdgeFaceLength
7fd59977 427//purpose :
428//=======================================================================
60bf98ae 429Standard_Boolean AIS_LengthDimension::InitEdgeFaceLength (const TopoDS_Edge& theEdge,
a6eb515f 430 const TopoDS_Face& theFace,
60bf98ae 431 gp_Dir& theEdgeDir)
7fd59977 432{
60bf98ae 433 Handle(Geom_Curve) aCurve;
434 gp_Pnt aFirstPoint, aSecondPoint;
435 Standard_Boolean isInfinite = Standard_False;
436
437 if (!AIS::ComputeGeometry (theEdge, aCurve, aFirstPoint, aSecondPoint, isInfinite))
a6eb515f 438 {
60bf98ae 439 return Standard_False;
7fd59977 440 }
60bf98ae 441 theEdgeDir = gce_MakeDir (aFirstPoint, aSecondPoint);
442 gp_Pln aPlane;
443 Handle(Geom_Surface) aSurface;
444 AIS_KindOfSurface aSurfType;
445 Standard_Real anOffset;
7fd59977 446
60bf98ae 447 if (!AIS::GetPlaneFromFace (theFace, aPlane, aSurface, aSurfType, anOffset))
a6eb515f 448 {
60bf98ae 449 return Standard_False;
7fd59977 450 }
7fd59977 451
60bf98ae 452 GeomAPI_ExtremaCurveSurface aDistAdaptor (aCurve, aSurface);
fe83e1ea 453
60bf98ae 454 aDistAdaptor.NearestPoints (myFirstPoint, mySecondPoint);
455
456 return IsValidPoints (myFirstPoint, mySecondPoint);
7fd59977 457}
458
459//=======================================================================
60bf98ae 460//function : InitTwoShapesPoints
a6eb515f 461//purpose : Initialization of two points where dimension layouts
462// will be attached
7fd59977 463//=======================================================================
60bf98ae 464Standard_Boolean AIS_LengthDimension::InitTwoShapesPoints (const TopoDS_Shape& theFirstShape,
465 const TopoDS_Shape& theSecondShape,
466 gp_Pln& theComputedPlane,
467 Standard_Boolean& theIsPlaneComputed)
7fd59977 468{
60bf98ae 469 theIsPlaneComputed = Standard_False;
a6eb515f 470 gp_Dir aDirAttach;
471 Standard_Boolean isInfinite = Standard_False;
60bf98ae 472 Standard_Boolean isSuccess = Standard_False;
a6eb515f 473 switch (theFirstShape.ShapeType())
474 {
60bf98ae 475 case TopAbs_FACE:
7fd59977 476 {
a6eb515f 477 // Initialization for face
478 gp_Pln aFirstPlane;
479 Handle(Geom_Surface) aFirstSurface;
480 AIS_KindOfSurface aFirstSurfKind;
481 Standard_Real aFirstOffset;
60bf98ae 482
a6eb515f 483 TopoDS_Face aFirstFace = TopoDS::Face (theFirstShape);
a6eb515f 484
60bf98ae 485 AIS::InitFaceLength (TopoDS::Face (theFirstShape),
486 aFirstPlane,
487 aFirstSurface,
488 aFirstSurfKind,
489 aFirstOffset);
490
491 if (theSecondShape.ShapeType() == TopAbs_FACE)
a6eb515f 492 {
493 // Initialization for face
60bf98ae 494 myGeometryType = GeometryType_Faces;
a6eb515f 495 gp_Pln aSecondPlane;
496 Handle(Geom_Surface) aSecondSurface;
497 AIS_KindOfSurface aSecondSurfKind;
498 Standard_Real aSecondOffset;
60bf98ae 499
a6eb515f 500 TopoDS_Face aSecondFace = TopoDS::Face (theSecondShape);
60bf98ae 501
502 AIS::InitFaceLength (aSecondFace,
503 aSecondPlane,
504 aSecondSurface,
505 aSecondSurfKind,
506 aSecondOffset);
507
a6eb515f 508 if (aFirstSurfKind == AIS_KOS_Plane)
7fd59977 509 {
60bf98ae 510 if (!aFirstPlane.Axis().Direction().IsParallel (aSecondPlane.Axis().Direction(), Precision::Angular()))
511 {
512 return Standard_False;
513 }
514
a6eb515f 515 TopExp_Explorer anExplorer (theFirstShape, TopAbs_VERTEX);
60bf98ae 516
a6eb515f 517 // In case of infinite planes
518 if (!anExplorer.More())
60bf98ae 519 {
a6eb515f 520 myFirstPoint = aFirstPlane.Location();
60bf98ae 521 }
522 else
523 {
524 myFirstPoint = BRep_Tool::Pnt (TopoDS::Vertex (anExplorer.Current()));
525 }
526
a6eb515f 527 mySecondPoint = AIS::ProjectPointOnPlane (myFirstPoint, aSecondPlane);
528
a6eb515f 529 Quantity_Parameter anU, aV;
530 ElSLib::Parameters (aSecondPlane, mySecondPoint, anU, aV);
60bf98ae 531
a6eb515f 532 BRepTopAdaptor_FClass2d aClassifier (aSecondFace, Precision::Confusion());
533 TopAbs_State aState = aClassifier.Perform (gp_Pnt2d (anU, aV), Standard_False);
60bf98ae 534
a6eb515f 535 if (aState == TopAbs_OUT || aState == TopAbs_UNKNOWN)
536 {
60bf98ae 537 mySecondPoint = AIS::Nearest (aSecondFace, myFirstPoint);
538 }
539
540 isSuccess = IsValidPoints (myFirstPoint, mySecondPoint);
541 if (isSuccess)
542 {
543 theComputedPlane = ComputePlane (aFirstPlane.Position().XDirection());
544 theIsPlaneComputed = Standard_True;
a6eb515f 545 }
7fd59977 546 }
a6eb515f 547 else // curvilinear faces
7fd59977 548 {
60bf98ae 549 Standard_Real aU1Min, aV1Min, aU1Max, aV1Max;
550 Standard_Real aU2Min, aV2Min, aU2Max, aV2Max;
551 BRepTools::UVBounds (aFirstFace, aU1Min, aU1Max, aV1Min, aV1Max);
552 BRepTools::UVBounds (aSecondFace, aU2Min, aU2Max, aV2Min, aV2Max);
553
554 GeomAPI_ExtremaSurfaceSurface anExtrema (aFirstSurface, aSecondSurface,
555 aU1Min, aU1Max, aV1Min, aV1Max,
556 aU2Min, aU2Max, aV2Min, aV2Max);
557
558 Standard_Real aU1, aV1, aU2, aV2;
559 anExtrema.LowerDistanceParameters (aU1, aV1, aU2, aV2);
560 myFirstPoint = BRep_Tool::Surface (aFirstFace)->Value (aU1, aV1);
561 mySecondPoint = BRep_Tool::Surface (aSecondFace)->Value (aU2, aV2);
562
563 // Adjust automatic plane
564 gp_Ax2 aLocalAxes (myFirstPoint, gce_MakeDir (myFirstPoint, mySecondPoint));
565 aDirAttach = gce_MakeDir (aLocalAxes.XDirection ());
566
567 // Check points
568 isSuccess = IsValidPoints (myFirstPoint, mySecondPoint);
569 if (isSuccess)
570 {
571 theComputedPlane = ComputePlane (aDirAttach);
572 theIsPlaneComputed = Standard_True;
573 }
7fd59977 574 }
60bf98ae 575
576 return isSuccess && IsValidPoints (myFirstPoint, mySecondPoint);
a6eb515f 577 }
578 else if (theFirstShape.ShapeType() == TopAbs_EDGE)
579 {
60bf98ae 580 myGeometryType = GeometryType_EdgeFace;
581 isSuccess = InitEdgeFaceLength (TopoDS::Edge (theFirstShape),
a6eb515f 582 TopoDS::Face (theSecondShape),
583 aDirAttach);
60bf98ae 584
585 if (isSuccess)
586 {
587 theComputedPlane = ComputePlane (aDirAttach);
588 theIsPlaneComputed = Standard_True;
589 }
590
591 return isSuccess;
a6eb515f 592 }
7fd59977 593 }
a6eb515f 594 break;
60bf98ae 595
596 case TopAbs_EDGE:
7fd59977 597 {
a6eb515f 598 if (theSecondShape.ShapeType() == TopAbs_VERTEX)
599 {
60bf98ae 600 myGeometryType = GeometryType_EdgeVertex;
601 isSuccess = InitEdgeVertexLength (TopoDS::Edge (theFirstShape),
602 TopoDS::Vertex (theSecondShape),
603 aDirAttach,
604 isInfinite);
605
606 if (isSuccess)
607 {
608 theComputedPlane = ComputePlane (aDirAttach);
609 theIsPlaneComputed = Standard_True;
610 }
611
612 return isSuccess;
a6eb515f 613 }
614 else if (theSecondShape.ShapeType() == TopAbs_EDGE)
615 {
60bf98ae 616 myGeometryType = GeometryType_Edges;
617 isSuccess = InitTwoEdgesLength (TopoDS::Edge (theFirstShape),
618 TopoDS::Edge (theSecondShape),
619 aDirAttach);
620
621 if (isSuccess)
622 {
623 theComputedPlane = ComputePlane (aDirAttach);
624 theIsPlaneComputed = Standard_True;
625 }
626
627 return isSuccess;
a6eb515f 628 }
7fd59977 629 }
a6eb515f 630 break;
60bf98ae 631
632 case TopAbs_VERTEX:
7fd59977 633 {
a6eb515f 634 if (theSecondShape.ShapeType() == TopAbs_VERTEX)
635 {
60bf98ae 636 myGeometryType = GeometryType_Points;
637 myFirstPoint = BRep_Tool::Pnt (TopoDS::Vertex (theFirstShape));
a6eb515f 638 mySecondPoint = BRep_Tool::Pnt (TopoDS::Vertex (theSecondShape));
60bf98ae 639
640 return IsValidPoints (myFirstPoint, mySecondPoint);
a6eb515f 641 }
642 else if (theSecondShape.ShapeType() == TopAbs_EDGE)
643 {
60bf98ae 644 myGeometryType = GeometryType_EdgeVertex;
645 Standard_Boolean isSuccess = InitEdgeVertexLength (TopoDS::Edge(theSecondShape),
646 TopoDS::Vertex(theFirstShape),
647 aDirAttach,
648 isInfinite);
649 if (isSuccess)
650 {
651 theComputedPlane = ComputePlane (aDirAttach);
652 theIsPlaneComputed = Standard_True;
653 }
654
655 return isSuccess;
a6eb515f 656 }
7fd59977 657 }
a6eb515f 658 break;
60bf98ae 659
660 case TopAbs_COMPOUND:
661 case TopAbs_COMPSOLID:
662 case TopAbs_SOLID:
663 case TopAbs_SHELL:
664 case TopAbs_WIRE:
665 case TopAbs_SHAPE:
666 break;
a6eb515f 667 }
60bf98ae 668
669 return Standard_False;
7fd59977 670}
671
672//=======================================================================
60bf98ae 673//function : InitOneShapePoints
a6eb515f 674//purpose : Initialization of two points where dimension layouts
675// will be attached
676// Attention: 1) <theShape> can be only the edge in currect implementation
677// 2) No length for infinite edge
7fd59977 678//=======================================================================
60bf98ae 679Standard_Boolean AIS_LengthDimension::InitOneShapePoints (const TopoDS_Shape& theShape)
7fd59977 680{
60bf98ae 681 if (theShape.ShapeType() != TopAbs_EDGE)
a6eb515f 682 {
a6eb515f 683 return Standard_False;
60bf98ae 684 }
7fd59977 685
60bf98ae 686 TopoDS_Edge anEdge = TopoDS::Edge (theShape);
7fd59977 687
60bf98ae 688 BRepAdaptor_Curve aBrepCurve(anEdge);
689 Standard_Real aFirst = aBrepCurve.FirstParameter();
690 Standard_Real aLast = aBrepCurve.LastParameter();
fe83e1ea 691
60bf98ae 692 if (aBrepCurve.GetType() != GeomAbs_Line)
a6eb515f 693 {
60bf98ae 694 return Standard_False;
7fd59977 695 }
d7bffd44 696
60bf98ae 697 Standard_Boolean isInfinite = (Precision::IsInfinite (aFirst) || Precision::IsInfinite (aLast));
698 if (isInfinite)
d7bffd44 699 {
60bf98ae 700 return Standard_False;
d7bffd44 701 }
7fd59977 702
60bf98ae 703 myFirstPoint = aBrepCurve.Value (aBrepCurve.FirstParameter());
704 mySecondPoint = aBrepCurve.Value (aBrepCurve.LastParameter());
7fd59977 705
60bf98ae 706 return IsValidPoints (myFirstPoint, mySecondPoint);
7fd59977 707}
af203d54 708
709//=======================================================================
710//function : GetTextPosition
711//purpose :
712//=======================================================================
713const gp_Pnt AIS_LengthDimension::GetTextPosition() const
714{
715 if (IsTextPositionCustom())
716 {
717 return myFixedTextPosition;
718 }
719
720 // Counts text position according to the dimension parameters
721 return GetTextPositionForLinear (myFirstPoint, mySecondPoint);
722}
723
724//=======================================================================
725//function : SetTextPosition
726//purpose :
727//=======================================================================
728void AIS_LengthDimension::SetTextPosition (const gp_Pnt& theTextPos)
729{
91b16a64 730 if (!IsValid())
af203d54 731 {
732 return;
733 }
734
735 myIsTextPositionFixed = Standard_True;
736 myFixedTextPosition = theTextPos;
737
738 SetToUpdate();
739}