ef31b023a3c005bd8bd016795547ae9bb20fbdb9
[occt.git] / src / AIS / AIS_DiameterDimension.cxx
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
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
21 #include <AIS_DiameterDimension.hxx>
22 #include <AIS.hxx>
23 #include <AIS_Drawer.hxx>
24 #include <ElCLib.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>
30
31 IMPLEMENT_STANDARD_HANDLE(AIS_DiameterDimension, AIS_Dimension)
32 IMPLEMENT_STANDARD_RTTIEXT(AIS_DiameterDimension, AIS_Dimension)
33
34 namespace
35 {
36   static const Standard_ExtCharacter THE_DIAMETER_SYMBOL (0x00D8);
37 };
38
39 //=======================================================================
40 //function : Constructor
41 //purpose  : 
42 //=======================================================================
43
44 AIS_DiameterDimension::AIS_DiameterDimension(const gp_Circ& theCircle)
45 : AIS_Dimension(),
46   myCircle (theCircle)
47 {
48   SetKindOfDimension(AIS_KOD_DIAMETER);
49   myIsInitialized = Standard_True;
50   SetSpecialSymbol (THE_DIAMETER_SYMBOL);
51   SetDisplaySpecialSymbol (AIS_DSS_Before);
52   SetFlyout (0.0);
53   // Count attach points
54   myFirstPoint = ElCLib::Value (0, myCircle);
55   mySecondPoint = myFirstPoint.Translated (gp_Vec(myFirstPoint, theCircle.Location())*2);
56 }
57
58 //=======================================================================
59 //function : Constructor
60 //purpose  : 
61 //=======================================================================
62
63 AIS_DiameterDimension::AIS_DiameterDimension(const gp_Circ& theCircle, const gp_Pnt& theAttachPoint)
64 : AIS_Dimension(),
65   myCircle (theCircle)
66 {
67   SetKindOfDimension (AIS_KOD_DIAMETER);
68   SetSpecialSymbol (THE_DIAMETER_SYMBOL);
69   SetDisplaySpecialSymbol (AIS_DSS_Before);
70   SetFlyout (0.0);
71   myFirstPoint = theAttachPoint;
72   // Count the second point
73   if (Abs(myFirstPoint.Distance (theCircle.Location()) - theCircle.Radius()) < Precision::Confusion())
74   {
75     mySecondPoint = myFirstPoint.Translated(gp_Vec(myFirstPoint, theCircle.Location())*2);
76   }
77   else
78   {
79     myFirstPoint = ElCLib::Value(0, myCircle);
80     mySecondPoint = myFirstPoint.Translated(gp_Vec(myFirstPoint, theCircle.Location())*2);
81   }
82   myIsInitialized = Standard_True;
83 }
84
85 //=======================================================================
86 //function : Constructor
87 //purpose  : Universal constructor for diameter dimension of shape
88 //=======================================================================
89
90 AIS_DiameterDimension::AIS_DiameterDimension (const TopoDS_Shape& theShape)
91 : AIS_Dimension ()
92 {
93   SetKindOfDimension (AIS_KOD_DIAMETER);
94   SetSpecialSymbol (THE_DIAMETER_SYMBOL);
95   SetDisplaySpecialSymbol (AIS_DSS_Before);
96   SetFlyout (0.0);
97   myFirstShape = theShape;
98   myIsInitialized = Standard_False;
99 }
100
101 //=======================================================================
102 //function : Compute
103 //purpose  : 
104 //=======================================================================
105
106 void AIS_DiameterDimension::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePM*/,
107                                      const Handle(Prs3d_Presentation)& thePresentation, 
108                                      const Standard_Integer theMode)
109 {
110   thePresentation->Clear();
111
112   Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect();
113   Prs3d_Root::CurrentGroup (thePresentation)->SetPrimitivesAspect (aDimensionAspect->LineAspect()->Aspect());
114
115   if (!myIsInitialized)
116   {
117     if (!initCircularDimension (myFirstShape, myCircle,
118                                myFirstPoint, mySecondPoint))
119       return;
120     else
121       myIsInitialized = Standard_True;
122   }
123
124   if (!myIsWorkingPlaneCustom)
125   {
126    countDefaultPlane();
127   }
128
129   drawLinearDimension (thePresentation, (AIS_DimensionDisplayMode)theMode);
130 }
131
132 //=======================================================================
133 //function : computeValue
134 //purpose  : 
135 //=======================================================================
136
137 void AIS_DiameterDimension::computeValue ()
138 {
139   myValue = myFirstPoint.Distance (mySecondPoint);
140   AIS_Dimension::computeValue();
141 }
142
143 //=======================================================================
144 //function : countDefaultPlane
145 //purpose  : 
146 //=======================================================================
147
148 void AIS_DiameterDimension::countDefaultPlane ()
149 {
150   // Compute normal of the default plane.
151   //gp_Vec aVec1(mySecondPoint, myFirstPoint),
152   //       aVec2(mySecondPoint, ElCLib::Value(M_PI_2, myCircle));
153   myDefaultPlane = gp_Pln(gp_Ax3(myCircle.Position()));
154   // Set computed value to <myWorkingPlane>
155   ResetWorkingPlane ();
156 }