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-2012 OPEN CASCADE SAS
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.
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.
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.
21 #include <AIS_DiameterDimension.hxx>
23 #include <AIS_Drawer.hxx>
25 #include <gce_MakeDir.hxx>
26 #include <Graphic3d_ArrayOfSegments.hxx>
27 #include <Graphic3d_Group.hxx>
28 #include <PrsMgr_PresentationManager3d.hxx>
29 #include <Prs3d_Root.hxx>
31 IMPLEMENT_STANDARD_HANDLE(AIS_DiameterDimension, AIS_Dimension)
32 IMPLEMENT_STANDARD_RTTIEXT(AIS_DiameterDimension, AIS_Dimension)
36 static const Standard_ExtCharacter THE_DIAMETER_SYMBOL (0x00D8);
39 //=======================================================================
40 //function : Constructor
42 //=======================================================================
44 AIS_DiameterDimension::AIS_DiameterDimension(const gp_Circ& theCircle)
48 SetKindOfDimension(AIS_KOD_DIAMETER);
49 myIsInitialized = Standard_True;
50 SetSpecialSymbol (THE_DIAMETER_SYMBOL);
51 SetDisplaySpecialSymbol (AIS_DSS_Before);
53 // Count attach points
54 myFirstPoint = ElCLib::Value (0, myCircle);
55 mySecondPoint = myFirstPoint.Translated (gp_Vec(myFirstPoint, theCircle.Location())*2);
58 //=======================================================================
59 //function : Constructor
61 //=======================================================================
63 AIS_DiameterDimension::AIS_DiameterDimension(const gp_Circ& theCircle, const gp_Pnt& theAttachPoint)
67 SetKindOfDimension (AIS_KOD_DIAMETER);
68 SetSpecialSymbol (THE_DIAMETER_SYMBOL);
69 SetDisplaySpecialSymbol (AIS_DSS_Before);
71 myFirstPoint = theAttachPoint;
72 // Count the second point
73 if (Abs(myFirstPoint.Distance (theCircle.Location()) - theCircle.Radius()) < Precision::Confusion())
75 mySecondPoint = myFirstPoint.Translated(gp_Vec(myFirstPoint, theCircle.Location())*2);
79 myFirstPoint = ElCLib::Value(0, myCircle);
80 mySecondPoint = myFirstPoint.Translated(gp_Vec(myFirstPoint, theCircle.Location())*2);
82 myIsInitialized = Standard_True;
85 //=======================================================================
86 //function : Constructor
87 //purpose : Universal constructor for diameter dimension of shape
88 //=======================================================================
90 AIS_DiameterDimension::AIS_DiameterDimension (const TopoDS_Shape& theShape)
93 SetKindOfDimension (AIS_KOD_DIAMETER);
94 SetSpecialSymbol (THE_DIAMETER_SYMBOL);
95 SetDisplaySpecialSymbol (AIS_DSS_Before);
97 myFirstShape = theShape;
98 myIsInitialized = Standard_False;
101 //=======================================================================
104 //=======================================================================
106 void AIS_DiameterDimension::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePM*/,
107 const Handle(Prs3d_Presentation)& thePresentation,
108 const Standard_Integer theMode)
110 thePresentation->Clear();
111 mySelectionGeom.Clear (theMode);
113 Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect();
114 Prs3d_Root::CurrentGroup (thePresentation)->SetPrimitivesAspect (aDimensionAspect->LineAspect()->Aspect());
116 if (!myIsInitialized)
118 if (!initCircularDimension (myFirstShape, myCircle,
119 myFirstPoint, mySecondPoint))
122 myIsInitialized = Standard_True;
125 if (!myIsWorkingPlaneCustom)
130 drawLinearDimension (thePresentation, theMode);
133 //=======================================================================
134 //function : computeValue
136 //=======================================================================
138 void AIS_DiameterDimension::computeValue ()
140 myValue = myFirstPoint.Distance (mySecondPoint);
141 AIS_Dimension::computeValue();
144 //=======================================================================
145 //function : countDefaultPlane
147 //=======================================================================
149 void AIS_DiameterDimension::countDefaultPlane ()
151 // Compute normal of the default plane.
152 //gp_Vec aVec1(mySecondPoint, myFirstPoint),
153 // aVec2(mySecondPoint, ElCLib::Value(M_PI_2, myCircle));
154 myDefaultPlane = gp_Pln(gp_Ax3(myCircle.Position()));
155 // Set computed value to <myWorkingPlane>
156 ResetWorkingPlane ();