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 |
68 | IMPLEMENT_STANDARD_HANDLE(AIS_RadiusDimension, AIS_Dimension) |
69 | IMPLEMENT_STANDARD_RTTIEXT(AIS_RadiusDimension, AIS_Dimension) |
7fd59977 |
70 | |
71 | //======================================================================= |
72 | //function : Constructor |
73 | //purpose : |
74 | //======================================================================= |
a6eb515f |
75 | |
76 | AIS_RadiusDimension::AIS_RadiusDimension (const gp_Circ& theCircle) |
77 | : AIS_Dimension(), |
78 | myFlyout (0.0), |
79 | myCircle (theCircle) |
7fd59977 |
80 | { |
a6eb515f |
81 | myFirstPoint = ElCLib::Value(0, myCircle); |
82 | mySecondPoint = theCircle.Location(); |
83 | myIsInitialized = Standard_True; |
84 | SetSpecialSymbol ('R'); |
85 | SetDisplaySpecialSymbol (AIS_DSS_Before); |
86 | SetKindOfDimension(AIS_KOD_RADIUS); |
87 | } |
88 | |
89 | AIS_RadiusDimension::AIS_RadiusDimension (const gp_Circ& theCircle, |
90 | const gp_Pnt& theAttachPoint) |
91 | : AIS_Dimension(), |
92 | myFlyout (0.0), |
93 | myCircle (theCircle) |
94 | { |
95 | myFirstPoint = theAttachPoint; |
96 | mySecondPoint = theCircle.Location(); |
97 | myIsInitialized = Standard_True; |
98 | SetSpecialSymbol ('R'); |
99 | SetDisplaySpecialSymbol (AIS_DSS_Before); |
100 | SetKindOfDimension (AIS_KOD_RADIUS); |
7fd59977 |
101 | } |
102 | |
103 | //======================================================================= |
104 | //function : Constructor |
a6eb515f |
105 | //purpose : |
7fd59977 |
106 | //======================================================================= |
a6eb515f |
107 | |
108 | AIS_RadiusDimension::AIS_RadiusDimension (const TopoDS_Shape& theShape) |
109 | : AIS_Dimension (), |
110 | myFlyout (0.0) |
7fd59977 |
111 | { |
a6eb515f |
112 | myFirstShape = theShape; |
113 | myIsInitialized = Standard_False; |
114 | SetSpecialSymbol ('R'); |
115 | SetDisplaySpecialSymbol (AIS_DSS_Before); |
116 | SetKindOfDimension (AIS_KOD_RADIUS); |
7fd59977 |
117 | } |
118 | |
119 | //======================================================================= |
a6eb515f |
120 | //function : Constructor |
7fd59977 |
121 | //purpose : |
122 | //======================================================================= |
a6eb515f |
123 | |
124 | AIS_RadiusDimension::AIS_RadiusDimension (const gp_Circ& theCircle, |
125 | const Handle(Prs3d_DimensionAspect)& theDimensionAspect, |
126 | const Standard_Real theExtensionSize/* = 1.0*/) |
127 | |
128 | : AIS_Dimension (theDimensionAspect,theExtensionSize), |
129 | myFlyout (0.0), |
130 | myCircle (theCircle) |
7fd59977 |
131 | { |
a6eb515f |
132 | myFirstPoint = ElCLib::Value(0, myCircle); |
133 | mySecondPoint = theCircle.Location(); |
134 | SetSpecialSymbol ('R'); |
135 | SetDisplaySpecialSymbol (AIS_DSS_Before); |
136 | SetKindOfDimension (AIS_KOD_RADIUS); |
7fd59977 |
137 | } |
138 | |
139 | //======================================================================= |
a6eb515f |
140 | //function : Constructor |
7fd59977 |
141 | //purpose : |
142 | //======================================================================= |
a6eb515f |
143 | |
144 | AIS_RadiusDimension::AIS_RadiusDimension (const gp_Circ& theCircle, |
145 | const gp_Pnt& theAttachPoint, |
146 | const Handle(Prs3d_DimensionAspect)& theDimensionAspect, |
147 | const Standard_Real theExtensionSize/* = 1.0*/) |
148 | : AIS_Dimension (theDimensionAspect,theExtensionSize), |
149 | myFlyout (0.0), |
150 | myCircle (theCircle) |
7fd59977 |
151 | { |
a6eb515f |
152 | myFirstPoint = theAttachPoint; |
153 | mySecondPoint = theCircle.Location(); |
154 | SetSpecialSymbol ('R'); |
155 | SetDisplaySpecialSymbol (AIS_DSS_Before); |
156 | SetKindOfDimension (AIS_KOD_RADIUS); |
7fd59977 |
157 | } |
158 | |
159 | //======================================================================= |
160 | //function : Compute |
161 | //purpose : |
162 | //======================================================================= |
7fd59977 |
163 | |
a6eb515f |
164 | void AIS_RadiusDimension::Compute(const Handle(PrsMgr_PresentationManager3d)& /*thePM*/, |
165 | const Handle(Prs3d_Presentation)& thePresentation, |
166 | const Standard_Integer theMode) |
167 | { |
168 | thePresentation->Clear(); |
169 | |
170 | Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect(); |
171 | Prs3d_Root::CurrentGroup (thePresentation)->SetPrimitivesAspect (aDimensionAspect->LineAspect()->Aspect()); |
172 | |
173 | if (!myIsInitialized) |
174 | { |
175 | gp_Pnt aLastPoint; |
176 | if (!initCircularDimension (myFirstShape, myCircle, |
177 | myFirstPoint, aLastPoint)) |
178 | return; |
179 | else |
180 | { |
181 | mySecondPoint = myCircle.Location(); |
182 | myIsInitialized = Standard_True; |
183 | } |
184 | } |
185 | if (!myIsWorkingPlaneCustom) |
186 | countDefaultPlane(); |
187 | |
188 | //Count flyout direction |
189 | gp_Ax1 aWorkingPlaneNormal = GetWorkingPlane().Axis(); |
190 | gp_Dir aTargetPointsVector = gce_MakeDir (myFirstPoint, mySecondPoint); |
191 | // Count a flyout direction vector. |
192 | gp_Dir aFlyoutVector = aWorkingPlaneNormal.Direction()^aTargetPointsVector; |
193 | gp_Ax3 aLocalSystem (myFirstPoint, aTargetPointsVector, aFlyoutVector); |
194 | |
195 | // Create lines for layouts |
196 | gp_Lin aLine1 (myFirstPoint, aFlyoutVector); |
197 | gp_Lin aLine2 (mySecondPoint, aFlyoutVector); |
198 | |
199 | // Get flyout end points |
200 | gp_Pnt aFlyoutEnd1 = ElCLib::Value (ElCLib::Parameter (aLine1, myFirstPoint) + GetFlyout(), aLine1); |
201 | gp_Pnt aFlyoutEnd2 = ElCLib::Value (ElCLib::Parameter (aLine2, mySecondPoint) + GetFlyout(), aLine2); |
202 | |
203 | // Add layout lines to graphic group |
204 | // Common to all type of dimension placement. |
205 | if (theMode == 0) |
206 | { |
207 | Handle(Graphic3d_ArrayOfSegments) aPrimSegments = new Graphic3d_ArrayOfSegments(4); |
208 | aPrimSegments->AddVertex (myFirstPoint); |
209 | aPrimSegments->AddVertex (aFlyoutEnd1); |
210 | |
211 | aPrimSegments->AddVertex (mySecondPoint); |
212 | aPrimSegments->AddVertex (aFlyoutEnd2); |
213 | |
214 | Prs3d_Root::CurrentGroup (thePresentation)->AddPrimitiveArray (aPrimSegments); |
215 | } |
216 | |
217 | drawLinearDimension (thePresentation, aFlyoutEnd1, aFlyoutEnd2, (AIS_DimensionDisplayMode)theMode, Standard_True); |
7fd59977 |
218 | } |
219 | |
220 | //======================================================================= |
a6eb515f |
221 | //function : computeValue |
222 | //purpose : |
7fd59977 |
223 | //======================================================================= |
a6eb515f |
224 | |
225 | void AIS_RadiusDimension::computeValue () |
7fd59977 |
226 | { |
a6eb515f |
227 | myValue = myFirstPoint.Distance (mySecondPoint); |
228 | AIS_Dimension::computeValue (); |
7fd59977 |
229 | } |
230 | |
7fd59977 |
231 | //======================================================================= |
a6eb515f |
232 | //function : countDefaultPlane |
7fd59977 |
233 | //purpose : |
234 | //======================================================================= |
235 | |
a6eb515f |
236 | void AIS_RadiusDimension::countDefaultPlane () |
7fd59977 |
237 | { |
a6eb515f |
238 | // Compute normal of the default plane. |
239 | gp_Vec aVec1(mySecondPoint, myFirstPoint), |
240 | aVec2(mySecondPoint, ElCLib::Value(M_PI_2, myCircle)); |
241 | myDefaultPlane = gp_Pln(myCircle.Location(), aVec1^aVec2); |
242 | // Set computed value to <myWorkingPlane> |
243 | ResetWorkingPlane (); |
7fd59977 |
244 | } |
245 | |
246 | //======================================================================= |
a6eb515f |
247 | //function : SetFlyout |
7fd59977 |
248 | //purpose : |
249 | //======================================================================= |
a6eb515f |
250 | |
251 | void AIS_RadiusDimension::SetFlyout (const Standard_Real theFlyout) |
7fd59977 |
252 | { |
a6eb515f |
253 | myFlyout = theFlyout; |
7fd59977 |
254 | } |
255 | |
256 | //======================================================================= |
a6eb515f |
257 | //function : GetFlyout |
7fd59977 |
258 | //purpose : |
259 | //======================================================================= |
260 | |
a6eb515f |
261 | Standard_Real AIS_RadiusDimension::GetFlyout () const |
7fd59977 |
262 | { |
a6eb515f |
263 | return myFlyout; |
264 | } |