0024293: Dimension extensions don't belong to the dimension sensitive entity: compute...
[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 // Modified     Mon 12-january-98
22 //              <ODL>, <SZY>
23
24
25 #define BUC60915        //GG 05/06/01 Enable to compute the requested arrow size
26 //                      if any in all dimensions.
27 #include <AIS_DiameterDimension.hxx>
28
29 #include <Adaptor3d_HCurve.hxx>
30 #include <AIS.hxx>
31 #include <AIS_Drawer.hxx>
32 #include <AIS_DimensionOwner.hxx>
33 #include <DsgPrs_DiameterPresentation.hxx>
34 #include <DsgPrs_RadiusPresentation.hxx>
35 #include <ElCLib.hxx>
36 #include <ElSLib.hxx>
37 #include <GC_MakeCircle.hxx>
38 #include <gce_MakeDir.hxx>
39 #include <Geom_Plane.hxx>
40 #include <gp_Pln.hxx>
41 #include <gp_Pnt.hxx>
42 #include <gp_Lin.hxx>
43 #include <gp_Ax1.hxx>
44 #include <gp_Dir.hxx>
45 #include <gp_Vec.hxx>
46 #include <Graphic3d_ArrayOfSegments.hxx>
47 #include <Graphic3d_Group.hxx>
48 #include <PrsMgr_PresentationManager3d.hxx>
49 #include <Prs3d_DimensionAspect.hxx>
50 #include <Prs3d_ArrowAspect.hxx>
51 #include <Prs3d_Drawer.hxx>
52 #include <Prs3d_TextAspect.hxx>
53 #include <Prs3d_Text.hxx>
54 #include <Prs3d_Root.hxx>
55 #include <Precision.hxx>
56 #include <Select3D_SensitiveSegment.hxx>
57 #include <Select3D_SensitiveBox.hxx>
58 #include <SelectMgr_EntityOwner.hxx>
59 #include <Standard_Macro.hxx>
60 #include <TopoDS.hxx>
61 #include <TopoDS_Shape.hxx>
62 #include <TCollection_ExtendedString.hxx>
63
64 IMPLEMENT_STANDARD_HANDLE(AIS_DiameterDimension, AIS_Dimension)
65 IMPLEMENT_STANDARD_RTTIEXT(AIS_DiameterDimension, AIS_Dimension)
66
67 //=======================================================================
68 //function : Constructor
69 //purpose  : 
70 //=======================================================================
71
72 AIS_DiameterDimension::AIS_DiameterDimension(const gp_Circ& theCircle)
73 : AIS_Dimension(),
74   myCircle (theCircle)
75 {
76   SetKindOfDimension(AIS_KOD_DIAMETER);
77   myIsInitialized = Standard_True;
78   SetSpecialSymbol (0x00D8);
79   SetDisplaySpecialSymbol (AIS_DSS_Before);
80   // Count attach points
81   myFirstPoint = ElCLib::Value (0, myCircle);
82   mySecondPoint = myFirstPoint.Translated (gp_Vec(myFirstPoint, theCircle.Location())*2);
83 }
84
85 //=======================================================================
86 //function : Constructor
87 //purpose  : 
88 //=======================================================================
89
90 AIS_DiameterDimension::AIS_DiameterDimension(const gp_Circ& theCircle, const gp_Pnt& theAttachPoint)
91 : AIS_Dimension(),
92   myCircle (theCircle)
93 {
94   SetKindOfDimension(AIS_KOD_DIAMETER);
95   SetSpecialSymbol (0x00D8);
96   SetDisplaySpecialSymbol (AIS_DSS_Before);
97   myFirstPoint = theAttachPoint;
98   // Count the second point
99   if (Abs(myFirstPoint.Distance (theCircle.Location()) - theCircle.Radius()) < Precision::Confusion())
100   {
101     mySecondPoint = myFirstPoint.Translated(gp_Vec(myFirstPoint, theCircle.Location())*2);
102   }
103   else
104   {
105     myFirstPoint = ElCLib::Value(0, myCircle);
106     mySecondPoint = myFirstPoint.Translated(gp_Vec(myFirstPoint, theCircle.Location())*2);
107   }
108   myIsInitialized = Standard_True;
109 }
110
111 //=======================================================================
112 //function : Constructor
113 //purpose  : 
114 //=======================================================================
115
116 AIS_DiameterDimension::AIS_DiameterDimension (const gp_Circ& theCircle,
117                                               const Handle(Prs3d_DimensionAspect)& theDimensionStyle,
118                                               const Standard_Real theExtensionSize /*= 1.0*/)
119 : AIS_Dimension (theExtensionSize),
120   myCircle (theCircle)
121 {
122   SetKindOfDimension(AIS_KOD_DIAMETER);
123   SetSpecialSymbol (0x00D8);
124   SetDisplaySpecialSymbol(AIS_DSS_Before);
125   myDrawer->SetDimensionAspect(theDimensionStyle);
126   myIsInitialized = Standard_True;
127 }
128
129 //=======================================================================
130 //function : Constructor
131 //purpose  : Universal constructor for diameter dimension of shape
132 //=======================================================================
133
134 AIS_DiameterDimension::AIS_DiameterDimension (const TopoDS_Shape& theShape)
135 : AIS_Dimension ()
136 {
137   SetKindOfDimension(AIS_KOD_DIAMETER);
138   SetSpecialSymbol (0x00D8);
139   SetDisplaySpecialSymbol(AIS_DSS_Before);
140   myFirstShape = theShape;
141   myIsInitialized = Standard_False;
142 }
143
144 //=======================================================================
145 //function : Compute
146 //purpose  : 
147 //=======================================================================
148
149 void AIS_DiameterDimension::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePM*/,
150                                      const Handle(Prs3d_Presentation)& thePresentation, 
151                                      const Standard_Integer theMode)
152 {
153   thePresentation->Clear();
154
155   Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect();
156   Prs3d_Root::CurrentGroup (thePresentation)->SetPrimitivesAspect (aDimensionAspect->LineAspect()->Aspect());
157
158   if (!myIsInitialized)
159   {
160     if (!initCircularDimension (myFirstShape, myCircle,
161                                myFirstPoint, mySecondPoint))
162       return;
163     else
164       myIsInitialized = Standard_True;
165   }
166   if (!myIsWorkingPlaneCustom)
167    countDefaultPlane();
168
169   //Count flyout direction
170   gp_Ax1 aWorkingPlaneNormal = GetWorkingPlane().Axis();
171   gp_Dir aTargetPointsVector = gce_MakeDir (myFirstPoint, mySecondPoint);
172   // Count a flyout direction vector.
173   gp_Dir aFlyoutVector = aWorkingPlaneNormal.Direction()^aTargetPointsVector;
174
175   // Create lines for layouts
176   gp_Lin aLine1 (myFirstPoint, aFlyoutVector);
177   gp_Lin aLine2 (mySecondPoint, aFlyoutVector);
178
179   // Get flyout end points
180   gp_Pnt aFlyoutEnd1 = ElCLib::Value (ElCLib::Parameter (aLine1, myFirstPoint) + GetFlyout(), aLine1);
181   gp_Pnt aFlyoutEnd2 = ElCLib::Value (ElCLib::Parameter (aLine2, mySecondPoint) + GetFlyout(), aLine2);
182
183     // Add layout lines to graphic group
184   // Common to all type of dimension placement.
185   if (theMode == 0)
186   {
187     Handle(Graphic3d_ArrayOfSegments) aPrimSegments = new Graphic3d_ArrayOfSegments(4);
188     aPrimSegments->AddVertex (myFirstPoint);
189     aPrimSegments->AddVertex (aFlyoutEnd1);
190
191     aPrimSegments->AddVertex (mySecondPoint);
192     aPrimSegments->AddVertex (aFlyoutEnd2);
193
194     Prs3d_Root::CurrentGroup (thePresentation)->AddPrimitiveArray (aPrimSegments);
195   }
196
197   drawLinearDimension (thePresentation, aFlyoutEnd1, aFlyoutEnd2, (AIS_DimensionDisplayMode)theMode);
198 }
199
200 //=======================================================================
201 //function : computeValue
202 //purpose  : 
203 //=======================================================================
204
205 void AIS_DiameterDimension::computeValue ()
206 {
207   myValue = myFirstPoint.Distance (mySecondPoint);
208   AIS_Dimension::computeValue();
209 }
210
211 //=======================================================================
212 //function : countDefaultPlane
213 //purpose  : 
214 //=======================================================================
215
216 void AIS_DiameterDimension::countDefaultPlane ()
217 {
218   // Compute normal of the default plane.
219   //gp_Vec aVec1(mySecondPoint, myFirstPoint),
220   //       aVec2(mySecondPoint, ElCLib::Value(M_PI_2, myCircle));
221   myDefaultPlane = gp_Pln(gp_Ax3(myCircle.Position()));
222   // Set computed value to <myWorkingPlane>
223   ResetWorkingPlane ();
224 }