0024624: Lost word in license statement in source files
[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
a6eb515f 37IMPLEMENT_STANDARD_HANDLE(AIS_LengthDimension, AIS_Dimension)
38IMPLEMENT_STANDARD_RTTIEXT(AIS_LengthDimension, AIS_Dimension)
7fd59977 39
40//=======================================================================
41//function : Constructor
60bf98ae 42//purpose : Dimension between two faces
43//=======================================================================
44AIS_LengthDimension::AIS_LengthDimension (const TopoDS_Face& theFirstFace,
45 const TopoDS_Face& theSecondFace)
46: AIS_Dimension (AIS_KOD_LENGTH)
47{
48 SetMeasuredGeometry (theFirstFace, theSecondFace);
49 SetFlyout (15.0);
50}
51
52//=======================================================================
53//function : Constructor
54//purpose : Dimension between two shape
7fd59977 55//=======================================================================
60bf98ae 56AIS_LengthDimension::AIS_LengthDimension (const TopoDS_Face& theFace,
57 const TopoDS_Edge& theEdge)
58: AIS_Dimension (AIS_KOD_LENGTH)
59{
60 SetMeasuredGeometry (theFace, theEdge);
61 SetFlyout (15.0);
62}
7fd59977 63
60bf98ae 64//=======================================================================
65//function : Constructor
66//purpose : Dimension between two points
67//=======================================================================
a6eb515f 68AIS_LengthDimension::AIS_LengthDimension (const gp_Pnt& theFirstPoint,
69 const gp_Pnt& theSecondPoint,
60bf98ae 70 const gp_Pln& thePlane)
71: AIS_Dimension (AIS_KOD_LENGTH)
7fd59977 72{
60bf98ae 73 SetMeasuredGeometry (theFirstPoint, theSecondPoint, thePlane);
d7bffd44 74 SetFlyout (15.0);
7fd59977 75}
76
7fd59977 77//=======================================================================
78//function : Constructor
a6eb515f 79//purpose : Dimension between two shape
7fd59977 80//=======================================================================
a6eb515f 81AIS_LengthDimension::AIS_LengthDimension (const TopoDS_Shape& theFirstShape,
82 const TopoDS_Shape& theSecondShape,
60bf98ae 83 const gp_Pln& thePlane)
84: AIS_Dimension (AIS_KOD_LENGTH)
7fd59977 85{
60bf98ae 86 SetCustomPlane (thePlane);
87 SetMeasuredShapes (theFirstShape, theSecondShape);
d7bffd44 88 SetFlyout (15.0);
7fd59977 89}
90
91//=======================================================================
92//function : Constructor
a6eb515f 93//purpose : Dimension of one edge
7fd59977 94//=======================================================================
a6eb515f 95AIS_LengthDimension::AIS_LengthDimension (const TopoDS_Edge& theEdge,
60bf98ae 96 const gp_Pln& thePlane)
97: AIS_Dimension (AIS_KOD_LENGTH)
7fd59977 98{
60bf98ae 99 SetMeasuredGeometry (theEdge, thePlane);
d7bffd44 100 SetFlyout (15.0);
7fd59977 101}
102
7fd59977 103//=======================================================================
60bf98ae 104//function : SetMeasuredGeometry
105//purpose :
7fd59977 106//=======================================================================
60bf98ae 107void AIS_LengthDimension::SetMeasuredGeometry (const gp_Pnt& theFirstPoint,
108 const gp_Pnt& theSecondPoint,
109 const gp_Pln& thePlane)
110{
111 myFirstPoint = theFirstPoint;
112 mySecondPoint = theSecondPoint;
113 myFirstShape = BRepLib_MakeVertex (myFirstPoint);
114 mySecondShape = BRepLib_MakeVertex (mySecondPoint);
115 myGeometryType = GeometryType_Points;
116 SetCustomPlane (thePlane);
117 myIsValid = IsValidPoints (theFirstPoint, theSecondPoint) && CheckPlane (myPlane);
118
119 SetToUpdate();
120}
7fd59977 121
60bf98ae 122//=======================================================================
123//function : SetMeasuredGeometry
124//purpose :
125//=======================================================================
126void AIS_LengthDimension::SetMeasuredGeometry (const TopoDS_Edge& theEdge,
127 const gp_Pln& thePlane)
7fd59977 128{
60bf98ae 129 myFirstShape = theEdge;
130 mySecondShape = TopoDS_Shape();
131 myGeometryType = GeometryType_Edge;
132 SetCustomPlane (thePlane);
133 myIsValid = InitOneShapePoints (myFirstShape) && CheckPlane (myPlane);
134
135 SetToUpdate();
7fd59977 136}
137
138//=======================================================================
60bf98ae 139//function : SetMeasuredGeometry
140//purpose :
7fd59977 141//=======================================================================
60bf98ae 142void AIS_LengthDimension::SetMeasuredGeometry (const TopoDS_Face& theFirstFace,
143 const TopoDS_Face& theSecondFace)
144{
145 SetMeasuredShapes (theFirstFace, theSecondFace);
146}
7fd59977 147
60bf98ae 148//=======================================================================
149//function : SetMeasuredGeometry
150//purpose :
151//=======================================================================
152void AIS_LengthDimension::SetMeasuredGeometry (const TopoDS_Face& theFace,
153 const TopoDS_Edge& theEdge)
7fd59977 154{
60bf98ae 155 SetMeasuredShapes (theFace, theEdge);
156}
157
158//=======================================================================
159//function : SetMeasuredShapes
160//purpose :
161//=======================================================================
162void AIS_LengthDimension::SetMeasuredShapes (const TopoDS_Shape& theFirstShape,
163 const TopoDS_Shape& theSecondShape)
164{
165 gp_Pln aComputedPlane;
166 Standard_Boolean isPlaneReturned = Standard_False;
167 myFirstShape = theFirstShape;
168 mySecondShape = theSecondShape;
169 myIsValid = InitTwoShapesPoints (myFirstShape, mySecondShape, aComputedPlane, isPlaneReturned);
170
171 if (myIsValid && !myIsPlaneCustom)
172 {
173 if (isPlaneReturned)
174 {
175 myPlane = aComputedPlane;
176 }
177 else
178 {
179 myIsValid = Standard_False;
180 }
181 }
182
183 myIsValid &= CheckPlane (myPlane);
184
185 SetToUpdate();
186}
187
188//=======================================================================
189//function : CheckPlane
190//purpose :
191//=======================================================================
192Standard_Boolean AIS_LengthDimension::CheckPlane (const gp_Pln& thePlane) const
193{
194 if (!thePlane.Contains (myFirstPoint, Precision::Confusion()) &&
195 !thePlane.Contains (mySecondPoint, Precision::Confusion()))
196 {
197 return Standard_False;
198 }
199
200 return Standard_True;
201}
202
203//=======================================================================
204//function : ComputePlane
205//purpose :
206//=======================================================================
207gp_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//=======================================================================
223const TCollection_AsciiString& AIS_LengthDimension::GetModelUnits() const
224{
225 return myDrawer->DimLengthModelUnits();
7fd59977 226}
227
228//=======================================================================
60bf98ae 229//function : GetDisplayUnits
230//purpose :
7fd59977 231//=======================================================================
60bf98ae 232const TCollection_AsciiString& AIS_LengthDimension::GetDisplayUnits() const
233{
234 return myDrawer->DimLengthDisplayUnits();
235}
236
237//=======================================================================
238//function : SetModelUnits
239//purpose :
240//=======================================================================
241void AIS_LengthDimension::SetModelUnits (const TCollection_AsciiString& theUnits)
242{
243 myDrawer->SetDimLengthModelUnits (theUnits);
244}
245
246//=======================================================================
247//function : SetDisplayUnits
248//purpose :
249//=======================================================================
250void AIS_LengthDimension::SetDisplayUnits (const TCollection_AsciiString& theUnits)
251{
252 myDrawer->SetDimLengthDisplayUnits (theUnits);
253}
7fd59977 254
60bf98ae 255//=======================================================================
256//function : ComputeValue
257//purpose :
258//=======================================================================
259Standard_Real AIS_LengthDimension::ComputeValue() const
260{
261 return IsValid() ? myFirstPoint.Distance (mySecondPoint) : 0.0;
262}
263
264//=======================================================================
265//function : Compute
266//purpose :
267//=======================================================================
268void 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//=======================================================================
287void 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//=======================================================================
302Standard_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//=======================================================================
312Standard_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 401Standard_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
417 const Handle(Geom_Line)& aGeomLine = (Handle(Geom_Line)&) aCurve;
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 432Standard_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 467Standard_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;
648 Standard_Boolean isSuccess = InitEdgeVertexLength (TopoDS::Edge(theSecondShape),
649 TopoDS::Vertex(theFirstShape),
650 aDirAttach,
651 isInfinite);
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 682Standard_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//=======================================================================
716const 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//=======================================================================
731void AIS_LengthDimension::SetTextPosition (const gp_Pnt& theTextPos)
732{
733 if (!myIsValid)
734 {
735 return;
736 }
737
738 myIsTextPositionFixed = Standard_True;
739 myFixedTextPosition = theTextPos;
740
741 SetToUpdate();
742}