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