1 // Created on: 1996-12-05
2 // Created by: Jacques MINOT/Odile Olivier/Sergey ZARITCHNY
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and / or modify it
9 // under the terms of the GNU Lesser General Public version 2.1 as published
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <AIS_DiameterDimension.hxx>
20 #include <BRepLib_MakeEdge.hxx>
22 #include <GeomAPI_IntCS.hxx>
23 #include <Geom_Circle.hxx>
24 #include <Geom_Plane.hxx>
25 #include <gce_MakeDir.hxx>
26 #include <Standard_ProgramError.hxx>
28 IMPLEMENT_STANDARD_HANDLE (AIS_DiameterDimension, AIS_Dimension)
29 IMPLEMENT_STANDARD_RTTIEXT (AIS_DiameterDimension, AIS_Dimension)
33 static const Standard_ExtCharacter THE_DIAMETER_SYMBOL (0x00D8);
36 //=======================================================================
37 //function : Constructor
39 //=======================================================================
40 AIS_DiameterDimension::AIS_DiameterDimension (const gp_Circ& theCircle)
41 : AIS_Dimension (AIS_KOD_DIAMETER)
43 SetMeasuredGeometry (theCircle);
44 SetSpecialSymbol (THE_DIAMETER_SYMBOL);
45 SetDisplaySpecialSymbol (AIS_DSS_Before);
49 //=======================================================================
50 //function : Constructor
52 //=======================================================================
53 AIS_DiameterDimension::AIS_DiameterDimension (const gp_Circ& theCircle,
54 const gp_Pln& thePlane)
55 : AIS_Dimension (AIS_KOD_DIAMETER)
57 SetCustomPlane (thePlane);
58 SetMeasuredGeometry (theCircle);
59 SetSpecialSymbol (THE_DIAMETER_SYMBOL);
60 SetDisplaySpecialSymbol (AIS_DSS_Before);
64 //=======================================================================
65 //function : Constructor
67 //=======================================================================
68 AIS_DiameterDimension::AIS_DiameterDimension (const TopoDS_Shape& theShape)
69 : AIS_Dimension (AIS_KOD_DIAMETER)
71 SetMeasuredGeometry (theShape);
72 SetSpecialSymbol (THE_DIAMETER_SYMBOL);
73 SetDisplaySpecialSymbol (AIS_DSS_Before);
77 //=======================================================================
78 //function : Constructor
80 //=======================================================================
81 AIS_DiameterDimension::AIS_DiameterDimension (const TopoDS_Shape& theShape,
82 const gp_Pln& thePlane)
83 : AIS_Dimension (AIS_KOD_DIAMETER)
85 SetCustomPlane (thePlane);
86 SetMeasuredGeometry (theShape);
87 SetSpecialSymbol (THE_DIAMETER_SYMBOL);
88 SetDisplaySpecialSymbol (AIS_DSS_Before);
92 //=======================================================================
93 //function : AnchorPoint
95 //=======================================================================
96 gp_Pnt AIS_DiameterDimension::AnchorPoint()
103 return myAnchorPoint;
106 //=======================================================================
107 //function : SetMeasuredGeometry
109 //=======================================================================
110 void AIS_DiameterDimension::SetMeasuredGeometry (const gp_Circ& theCircle)
112 myCircle = theCircle;
113 myGeometryType = GeometryType_Edge;
114 myShape = BRepLib_MakeEdge (theCircle);
115 myAnchorPoint = gp::Origin();
116 myIsValid = IsValidCircle (myCircle);
118 if (myIsValid && myIsPlaneCustom)
120 ComputeAnchorPoint();
122 else if (!myIsPlaneCustom)
125 myAnchorPoint = ElCLib::Value (0.0, myCircle);
128 myIsValid &= CheckPlane (myPlane);
133 //=======================================================================
134 //function : SetMeasuredGeometry
136 //=======================================================================
137 void AIS_DiameterDimension::SetMeasuredGeometry (const TopoDS_Shape& theShape)
139 gp_Pnt aDummyPnt (gp::Origin());
140 Standard_Boolean isClosed = Standard_False;
142 myGeometryType = GeometryType_UndefShapes;
144 myAnchorPoint = gp::Origin();
145 myIsValid = InitCircularDimension (theShape, myCircle, aDummyPnt, isClosed)
146 && IsValidCircle (myCircle)
149 if (myIsValid && myIsPlaneCustom)
151 ComputeAnchorPoint();
153 else if (!myIsPlaneCustom)
156 myAnchorPoint = ElCLib::Value (0.0, myCircle);
159 myIsValid &= CheckPlane (myPlane);
164 //=======================================================================
165 //function : CheckPlane
167 //=======================================================================
168 Standard_Boolean AIS_DiameterDimension::CheckPlane (const gp_Pln& thePlane) const
170 // Check if the circle center point belongs to plane.
171 if (!thePlane.Contains (myCircle.Location(), Precision::Confusion()))
173 return Standard_False;
176 return Standard_True;
179 //=======================================================================
180 //function : ComputePlane
182 //=======================================================================
183 void AIS_DiameterDimension::ComputePlane()
190 myPlane = gp_Pln (gp_Ax3 (myCircle.Position()));
193 //=======================================================================
194 //function : ComputeAnchorPoint
196 //=======================================================================
197 void AIS_DiameterDimension::ComputeAnchorPoint()
199 // Anchor point is an intersection of dimension plane and circle.
200 Handle(Geom_Circle) aCircle = new Geom_Circle (myCircle);
201 Handle(Geom_Plane) aPlane = new Geom_Plane (myPlane);
202 GeomAPI_IntCS anIntersector (aCircle, aPlane);
203 if (!anIntersector.IsDone())
205 myIsValid = Standard_False;
209 // The circle lays on the plane.
210 if (anIntersector.NbPoints() != 2)
212 myAnchorPoint = ElCLib::Value (0.0, myCircle);
213 myIsValid = Standard_True;
217 gp_Pnt aFirstPoint = anIntersector.Point (1);
218 gp_Pnt aSecondPoint = anIntersector.Point (2);
220 // Choose one of two intersection points that stands with
221 // positive direction of flyout.
222 // An anchor point is supposed to be the left attachment point.
223 gp_Dir aFirstDir = gce_MakeDir (aFirstPoint, myCircle.Location());
224 gp_Dir aDir = myPlane.Axis().Direction() ^ aFirstDir;
225 myAnchorPoint = (gp_Vec (aDir) * gp_Vec(myCircle.Position().Direction()) > 0.0)
231 //=======================================================================
232 //function : GetModelUnits
234 //=======================================================================
235 const TCollection_AsciiString& AIS_DiameterDimension::GetModelUnits() const
237 return myDrawer->DimLengthModelUnits();
240 //=======================================================================
241 //function : GetDisplayUnits
243 //=======================================================================
244 const TCollection_AsciiString& AIS_DiameterDimension::GetDisplayUnits() const
246 return myDrawer->DimLengthDisplayUnits();
249 //=======================================================================
250 //function : SetModelUnits
252 //=======================================================================
253 void AIS_DiameterDimension::SetModelUnits (const TCollection_AsciiString& theUnits)
255 myDrawer->SetDimLengthModelUnits (theUnits);
258 //=======================================================================
259 //function : SetDisplayUnits
261 //=======================================================================
262 void AIS_DiameterDimension::SetDisplayUnits (const TCollection_AsciiString& theUnits)
264 myDrawer->SetDimLengthDisplayUnits (theUnits);
267 //=======================================================================
268 //function : ComputeValue
270 //=======================================================================
271 Standard_Real AIS_DiameterDimension::ComputeValue() const
278 return myCircle.Radius() * 2.0;
281 //=======================================================================
284 //=======================================================================
285 void AIS_DiameterDimension::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePM*/,
286 const Handle(Prs3d_Presentation)& thePresentation,
287 const Standard_Integer theMode)
289 thePresentation->Clear();
290 mySelectionGeom.Clear (theMode);
297 gp_Pnt aFirstPnt (gp::Origin());
298 gp_Pnt aSecondPnt (gp::Origin());
299 ComputeSidePoints (myCircle, GetPlane(), aFirstPnt, aSecondPnt);
301 DrawLinearDimension (thePresentation, theMode, aFirstPnt, aSecondPnt);
304 //=======================================================================
305 //function : ComputeFlyoutSelection
307 //=======================================================================
308 void AIS_DiameterDimension::ComputeFlyoutSelection (const Handle(SelectMgr_Selection)& theSelection,
309 const Handle(SelectMgr_EntityOwner)& theEntityOwner)
316 gp_Pnt aFirstPnt (gp::Origin());
317 gp_Pnt aSecondPnt (gp::Origin());
318 ComputeSidePoints (myCircle, GetPlane(), aFirstPnt, aSecondPnt);
320 ComputeLinearFlyouts (theSelection, theEntityOwner, aFirstPnt, aSecondPnt);
323 //=======================================================================
324 //function : ComputeSidePoints
326 //=======================================================================
327 void AIS_DiameterDimension::ComputeSidePoints (const gp_Circ& /*theCircle*/,
328 const gp_Pln& /*thePlane*/,
330 gp_Pnt& theSecondPnt)
332 theFirstPnt = AnchorPoint();
334 gp_Vec aRadiusVector (myCircle.Location(), theFirstPnt);
335 theSecondPnt = myCircle.Location().Translated (-aRadiusVector);
338 //=======================================================================
339 //function : IsValidCircle
341 //=======================================================================
342 Standard_Boolean AIS_DiameterDimension::IsValidCircle (const gp_Circ& theCircle) const
344 return (theCircle.Radius() * 2.0) > Precision::Confusion();
347 //=======================================================================
348 //function : IsValidAnchor
350 //=======================================================================
351 Standard_Boolean AIS_DiameterDimension::IsValidAnchor (const gp_Circ& theCircle,
352 const gp_Pnt& theAnchor) const
354 gp_Pln aCirclePlane (theCircle.Location(), theCircle.Axis().Direction());
355 Standard_Real anAnchorDist = theAnchor.Distance (theCircle.Location());
356 Standard_Real aRadius = myCircle.Radius();
358 return Abs (anAnchorDist - aRadius) > Precision::Confusion()
359 && aCirclePlane.Contains (theAnchor, Precision::Confusion());