06c7e071f20f80993e634aea29c10db3e31563c7
[occt.git] / src / AIS / AIS_RadiusDimension.cxx
1 // Created on: 1996-12-05
2 // Created by: Jean-Pierre COMBE/Odile Olivier/Serguei 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_RadiusDimension.hxx>
22
23 #include <AIS.hxx>
24 #include <AIS_Drawer.hxx>
25 #include <ElCLib.hxx>
26 #include <gce_MakeDir.hxx>
27 #include <Graphic3d_ArrayOfSegments.hxx>
28 #include <Graphic3d_Group.hxx>
29 #include <PrsMgr_PresentationManager3d.hxx>
30 #include <Prs3d_Root.hxx>
31
32 IMPLEMENT_STANDARD_HANDLE(AIS_RadiusDimension, AIS_Dimension)
33 IMPLEMENT_STANDARD_RTTIEXT(AIS_RadiusDimension, AIS_Dimension)
34
35 //=======================================================================
36 //function : Constructor
37 //purpose  : 
38 //=======================================================================
39
40 AIS_RadiusDimension::AIS_RadiusDimension (const gp_Circ& theCircle)
41 : AIS_Dimension(),
42   myCircle (theCircle)
43 {
44   myFirstPoint = ElCLib::Value(0, myCircle);
45   mySecondPoint = theCircle.Location();
46   myIsInitialized = Standard_True;
47   SetSpecialSymbol ('R');
48   SetDisplaySpecialSymbol (AIS_DSS_Before);
49   SetKindOfDimension (AIS_KOD_RADIUS);
50   SetFlyout (0.0);
51 }
52
53 //=======================================================================
54 //function : Constructor
55 //purpose  : 
56 //=======================================================================
57
58 AIS_RadiusDimension::AIS_RadiusDimension (const gp_Circ& theCircle,
59                                           const gp_Pnt& theAttachPoint)
60 : AIS_Dimension(),
61   myCircle (theCircle)
62 {
63   myFirstPoint = theAttachPoint;
64   mySecondPoint = theCircle.Location();
65   myIsInitialized = Standard_True;
66   SetSpecialSymbol ('R');
67   SetDisplaySpecialSymbol (AIS_DSS_Before);
68   SetKindOfDimension (AIS_KOD_RADIUS);
69   SetFlyout (0.0);
70 }
71
72 //=======================================================================
73 //function : Constructor
74 //purpose  :
75 //=======================================================================
76
77 AIS_RadiusDimension::AIS_RadiusDimension (const TopoDS_Shape& theShape)
78 : AIS_Dimension ()
79 {
80   myFirstShape = theShape;
81   myIsInitialized = Standard_False;
82   SetSpecialSymbol ('R');
83   SetDisplaySpecialSymbol (AIS_DSS_Before);
84   SetKindOfDimension (AIS_KOD_RADIUS);
85   SetFlyout (0.0);
86 }
87
88 //=======================================================================
89 //function : Compute
90 //purpose  : 
91 //=======================================================================
92
93 void AIS_RadiusDimension::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePM*/,
94                                    const Handle(Prs3d_Presentation)& thePresentation,
95                                    const Standard_Integer theMode)
96 {
97   thePresentation->Clear();
98
99   Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect();
100   Prs3d_Root::CurrentGroup (thePresentation)->SetPrimitivesAspect (aDimensionAspect->LineAspect()->Aspect());
101
102   if (!myIsInitialized)
103   {
104     gp_Pnt aLastPoint;
105     if (!initCircularDimension (myFirstShape, myCircle,
106       myFirstPoint, aLastPoint))
107       return;
108     else
109     {
110       mySecondPoint = myCircle.Location();
111       myIsInitialized = Standard_True;
112     }
113   }
114
115   if (!myIsWorkingPlaneCustom)
116   {
117     countDefaultPlane();
118   }
119
120   drawLinearDimension (thePresentation, (AIS_DimensionDisplayMode)theMode, Standard_True);
121 }
122
123 //=======================================================================
124 //function : computeValue
125 //purpose  : 
126 //=======================================================================
127
128 void AIS_RadiusDimension::computeValue ()
129 {
130   myValue = myFirstPoint.Distance (mySecondPoint);
131   AIS_Dimension::computeValue ();
132 }
133
134 //=======================================================================
135 //function : countDefaultPlane
136 //purpose  : 
137 //=======================================================================
138
139 void AIS_RadiusDimension::countDefaultPlane ()
140 {
141   // Compute normal of the default plane.
142   gp_Vec aVec1(mySecondPoint, myFirstPoint),
143          aVec2(mySecondPoint, ElCLib::Value(M_PI_2, myCircle));
144   myDefaultPlane = gp_Pln(myCircle.Location(), aVec1^aVec2);
145   // Set computed value to <myWorkingPlane>
146   ResetWorkingPlane ();
147 }