0024288: Provide flipping text for AIS_Dimensions
[occt.git] / src / AIS / AIS_RadiusDimension.cxx
CommitLineData
b311480e 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
7fd59977 21#include <Standard_NotImplemented.hxx>
22
a6eb515f 23#include <AIS_RadiusDimension.hxx>
7fd59977 24
a6eb515f 25#include <AIS.hxx>
26#include <AIS_Drawer.hxx>
27#include <AIS_KindOfDimension.hxx>
28#include <Adaptor3d_HCurve.hxx>
29#include <BRep_Tool.hxx>
30#include <BRepAdaptor_Surface.hxx>
31#include <BRepAdaptor_Curve.hxx>
7fd59977 32#include <DsgPrs.hxx>
a6eb515f 33#include <ElCLib.hxx>
34#include <GC_MakeCircle.hxx>
35#include <gce_MakeCirc.hxx>
36#include <gce_MakeDir.hxx>
37#include <gce_MakeLin.hxx>
7fd59977 38#include <Geom_Surface.hxx>
39#include <Geom_Plane.hxx>
40#include <Geom_Circle.hxx>
41#include <Geom_Curve.hxx>
42#include <Geom_TrimmedCurve.hxx>
43#include <Geom_ToroidalSurface.hxx>
44#include <Geom_CylindricalSurface.hxx>
45#include <Geom_SurfaceOfLinearExtrusion.hxx>
7fd59977 46#include <gp_Circ.hxx>
47#include <gp_Pnt.hxx>
48#include <gp_Trsf.hxx>
a6eb515f 49#include <Graphic3d_ArrayOfSegments.hxx>
50#include <Graphic3d_Group.hxx>
7fd59977 51#include <Precision.hxx>
a6eb515f 52#include <PrsMgr_PresentationManager3d.hxx>
53#include <Prs3d_DimensionAspect.hxx>
54#include <Prs3d_ArrowAspect.hxx>
55#include <Prs3d_Drawer.hxx>
56#include <Prs3d_Root.hxx>
57#include <TCollection_AsciiString.hxx>
58#include <TCollection_ExtendedString.hxx>
7fd59977 59#include <TopExp_Explorer.hxx>
60#include <TopAbs_ShapeEnum.hxx>
61#include <TopoDS.hxx>
62#include <TopoDS_Face.hxx>
63#include <TopoDS_Wire.hxx>
64#include <TopoDS_Edge.hxx>
a6eb515f 65#include <TopoDS_Vertex.hxx>
7fd59977 66#include <TopLoc_Location.hxx>
7fd59977 67
a6eb515f 68IMPLEMENT_STANDARD_HANDLE(AIS_RadiusDimension, AIS_Dimension)
69IMPLEMENT_STANDARD_RTTIEXT(AIS_RadiusDimension, AIS_Dimension)
7fd59977 70
71//=======================================================================
72//function : Constructor
73//purpose :
74//=======================================================================
a6eb515f 75
76AIS_RadiusDimension::AIS_RadiusDimension (const gp_Circ& theCircle)
77: AIS_Dimension(),
a6eb515f 78 myCircle (theCircle)
7fd59977 79{
a6eb515f 80 myFirstPoint = ElCLib::Value(0, myCircle);
81 mySecondPoint = theCircle.Location();
82 myIsInitialized = Standard_True;
83 SetSpecialSymbol ('R');
84 SetDisplaySpecialSymbol (AIS_DSS_Before);
85 SetKindOfDimension(AIS_KOD_RADIUS);
86}
87
88AIS_RadiusDimension::AIS_RadiusDimension (const gp_Circ& theCircle,
89 const gp_Pnt& theAttachPoint)
90: AIS_Dimension(),
a6eb515f 91 myCircle (theCircle)
92{
93 myFirstPoint = theAttachPoint;
94 mySecondPoint = theCircle.Location();
95 myIsInitialized = Standard_True;
96 SetSpecialSymbol ('R');
97 SetDisplaySpecialSymbol (AIS_DSS_Before);
98 SetKindOfDimension (AIS_KOD_RADIUS);
7fd59977 99}
100
101//=======================================================================
102//function : Constructor
a6eb515f 103//purpose :
7fd59977 104//=======================================================================
a6eb515f 105
106AIS_RadiusDimension::AIS_RadiusDimension (const TopoDS_Shape& theShape)
62b6361a 107: AIS_Dimension ()
7fd59977 108{
a6eb515f 109 myFirstShape = theShape;
110 myIsInitialized = Standard_False;
111 SetSpecialSymbol ('R');
112 SetDisplaySpecialSymbol (AIS_DSS_Before);
113 SetKindOfDimension (AIS_KOD_RADIUS);
7fd59977 114}
115
116//=======================================================================
a6eb515f 117//function : Constructor
7fd59977 118//purpose :
119//=======================================================================
a6eb515f 120
121AIS_RadiusDimension::AIS_RadiusDimension (const gp_Circ& theCircle,
122 const Handle(Prs3d_DimensionAspect)& theDimensionAspect,
123 const Standard_Real theExtensionSize/* = 1.0*/)
124
125: AIS_Dimension (theDimensionAspect,theExtensionSize),
a6eb515f 126 myCircle (theCircle)
7fd59977 127{
a6eb515f 128 myFirstPoint = ElCLib::Value(0, myCircle);
129 mySecondPoint = theCircle.Location();
130 SetSpecialSymbol ('R');
131 SetDisplaySpecialSymbol (AIS_DSS_Before);
132 SetKindOfDimension (AIS_KOD_RADIUS);
7fd59977 133}
134
135//=======================================================================
a6eb515f 136//function : Constructor
7fd59977 137//purpose :
138//=======================================================================
a6eb515f 139
140AIS_RadiusDimension::AIS_RadiusDimension (const gp_Circ& theCircle,
141 const gp_Pnt& theAttachPoint,
142 const Handle(Prs3d_DimensionAspect)& theDimensionAspect,
143 const Standard_Real theExtensionSize/* = 1.0*/)
144: AIS_Dimension (theDimensionAspect,theExtensionSize),
a6eb515f 145 myCircle (theCircle)
7fd59977 146{
a6eb515f 147 myFirstPoint = theAttachPoint;
148 mySecondPoint = theCircle.Location();
149 SetSpecialSymbol ('R');
150 SetDisplaySpecialSymbol (AIS_DSS_Before);
151 SetKindOfDimension (AIS_KOD_RADIUS);
7fd59977 152}
153
154//=======================================================================
155//function : Compute
156//purpose :
157//=======================================================================
7fd59977 158
62b6361a 159void AIS_RadiusDimension::Compute (const Handle(PrsMgr_PresentationManager3d)& /*thePM*/,
160 const Handle(Prs3d_Presentation)& thePresentation,
161 const Standard_Integer theMode)
a6eb515f 162{
163 thePresentation->Clear();
164
165 Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect();
166 Prs3d_Root::CurrentGroup (thePresentation)->SetPrimitivesAspect (aDimensionAspect->LineAspect()->Aspect());
167
168 if (!myIsInitialized)
169 {
170 gp_Pnt aLastPoint;
171 if (!initCircularDimension (myFirstShape, myCircle,
172 myFirstPoint, aLastPoint))
173 return;
174 else
175 {
176 mySecondPoint = myCircle.Location();
177 myIsInitialized = Standard_True;
178 }
179 }
180 if (!myIsWorkingPlaneCustom)
181 countDefaultPlane();
182
183 //Count flyout direction
184 gp_Ax1 aWorkingPlaneNormal = GetWorkingPlane().Axis();
185 gp_Dir aTargetPointsVector = gce_MakeDir (myFirstPoint, mySecondPoint);
186 // Count a flyout direction vector.
187 gp_Dir aFlyoutVector = aWorkingPlaneNormal.Direction()^aTargetPointsVector;
a6eb515f 188
189 // Create lines for layouts
190 gp_Lin aLine1 (myFirstPoint, aFlyoutVector);
191 gp_Lin aLine2 (mySecondPoint, aFlyoutVector);
192
193 // Get flyout end points
194 gp_Pnt aFlyoutEnd1 = ElCLib::Value (ElCLib::Parameter (aLine1, myFirstPoint) + GetFlyout(), aLine1);
195 gp_Pnt aFlyoutEnd2 = ElCLib::Value (ElCLib::Parameter (aLine2, mySecondPoint) + GetFlyout(), aLine2);
196
197 // Add layout lines to graphic group
198 // Common to all type of dimension placement.
199 if (theMode == 0)
200 {
201 Handle(Graphic3d_ArrayOfSegments) aPrimSegments = new Graphic3d_ArrayOfSegments(4);
202 aPrimSegments->AddVertex (myFirstPoint);
203 aPrimSegments->AddVertex (aFlyoutEnd1);
204
205 aPrimSegments->AddVertex (mySecondPoint);
206 aPrimSegments->AddVertex (aFlyoutEnd2);
207
208 Prs3d_Root::CurrentGroup (thePresentation)->AddPrimitiveArray (aPrimSegments);
209 }
210
211 drawLinearDimension (thePresentation, aFlyoutEnd1, aFlyoutEnd2, (AIS_DimensionDisplayMode)theMode, Standard_True);
7fd59977 212}
213
214//=======================================================================
a6eb515f 215//function : computeValue
216//purpose :
7fd59977 217//=======================================================================
a6eb515f 218
219void AIS_RadiusDimension::computeValue ()
7fd59977 220{
a6eb515f 221 myValue = myFirstPoint.Distance (mySecondPoint);
222 AIS_Dimension::computeValue ();
7fd59977 223}
224
225//=======================================================================
a6eb515f 226//function : countDefaultPlane
7fd59977 227//purpose :
228//=======================================================================
229
a6eb515f 230void AIS_RadiusDimension::countDefaultPlane ()
7fd59977 231{
a6eb515f 232 // Compute normal of the default plane.
233 gp_Vec aVec1(mySecondPoint, myFirstPoint),
234 aVec2(mySecondPoint, ElCLib::Value(M_PI_2, myCircle));
235 myDefaultPlane = gp_Pln(myCircle.Location(), aVec1^aVec2);
236 // Set computed value to <myWorkingPlane>
237 ResetWorkingPlane ();
7fd59977 238}