b311480e |
1 | // Created on: 1998-01-23 |
2 | // Created by: Sergey ZARITCHNY |
3 | // Copyright (c) 1998-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
7fd59977 |
17 | |
42cf5bc1 |
18 | #include <AIS.hxx> |
7fd59977 |
19 | #include <AIS_EllipseRadiusDimension.hxx> |
42cf5bc1 |
20 | #include <AIS_MaxRadiusDimension.hxx> |
21 | #include <BRepAdaptor_Curve.hxx> |
22 | #include <BRepAdaptor_Surface.hxx> |
23 | #include <DsgPrs_EllipseRadiusPresentation.hxx> |
7fd59977 |
24 | #include <ElCLib.hxx> |
25 | #include <ElSLib.hxx> |
42cf5bc1 |
26 | #include <Geom_CylindricalSurface.hxx> |
7fd59977 |
27 | #include <Geom_Ellipse.hxx> |
c04c30b3 |
28 | #include <Geom_OffsetCurve.hxx> |
7fd59977 |
29 | #include <Geom_Plane.hxx> |
30 | #include <Geom_Surface.hxx> |
7fd59977 |
31 | #include <Geom_SurfaceOfLinearExtrusion.hxx> |
42cf5bc1 |
32 | #include <Geom_SurfaceOfRevolution.hxx> |
33 | #include <Geom_Transformation.hxx> |
34 | #include <Geom_TrimmedCurve.hxx> |
7fd59977 |
35 | #include <gp_Ax1.hxx> |
36 | #include <gp_Dir.hxx> |
42cf5bc1 |
37 | #include <gp_Lin.hxx> |
38 | #include <gp_Pln.hxx> |
39 | #include <gp_Pnt.hxx> |
7fd59977 |
40 | #include <gp_Vec.hxx> |
7fd59977 |
41 | #include <Precision.hxx> |
42cf5bc1 |
42 | #include <Prs3d_ArrowAspect.hxx> |
43 | #include <Prs3d_DimensionAspect.hxx> |
44 | #include <Prs3d_Drawer.hxx> |
45 | #include <Prs3d_Presentation.hxx> |
46 | #include <Prs3d_Projector.hxx> |
47 | #include <Prs3d_Text.hxx> |
48 | #include <Prs3d_TextAspect.hxx> |
49 | #include <Select3D_SensitiveBox.hxx> |
50 | #include <Select3D_SensitiveCurve.hxx> |
51 | #include <Select3D_SensitiveSegment.hxx> |
52 | #include <SelectMgr_EntityOwner.hxx> |
53 | #include <SelectMgr_Selection.hxx> |
54 | #include <Standard_ConstructionError.hxx> |
55 | #include <Standard_NotImplemented.hxx> |
56 | #include <Standard_Type.hxx> |
57 | #include <TCollection_ExtendedString.hxx> |
58 | #include <TopoDS.hxx> |
59 | #include <TopoDS_Shape.hxx> |
7fd59977 |
60 | |
92efcf78 |
61 | IMPLEMENT_STANDARD_RTTIEXT(AIS_MaxRadiusDimension,AIS_EllipseRadiusDimension) |
62 | |
7fd59977 |
63 | //======================================================================= |
64 | //function : AIS_MaxRadiusDimension |
65 | //purpose : |
66 | //======================================================================= |
7fd59977 |
67 | AIS_MaxRadiusDimension::AIS_MaxRadiusDimension(const TopoDS_Shape& aShape, |
68 | const Standard_Real aVal, |
69 | const TCollection_ExtendedString& aText) |
70 | :AIS_EllipseRadiusDimension(aShape, aText) |
71 | { |
72 | myVal = aVal; |
73 | mySymbolPrs = DsgPrs_AS_LASTAR; |
74 | myAutomaticPosition = Standard_True; |
75 | myArrowSize = myVal / 100.; |
76 | } |
77 | |
78 | //======================================================================= |
79 | //function : AIS_MaxRadiusDimension |
80 | //purpose : |
81 | //======================================================================= |
82 | |
83 | AIS_MaxRadiusDimension::AIS_MaxRadiusDimension(const TopoDS_Shape& aShape, |
84 | const Standard_Real aVal, |
85 | const TCollection_ExtendedString& aText, |
86 | const gp_Pnt& aPosition, |
87 | const DsgPrs_ArrowSide aSymbolPrs, |
88 | const Standard_Real anArrowSize) |
89 | :AIS_EllipseRadiusDimension(aShape, aText) |
90 | { |
91 | myVal = aVal; |
92 | mySymbolPrs = aSymbolPrs; |
93 | myPosition = aPosition; |
94 | myAutomaticPosition = Standard_False; |
7fd59977 |
95 | SetArrowSize( anArrowSize ); |
7fd59977 |
96 | } |
97 | |
98 | //======================================================================= |
99 | //function : Compute |
100 | //purpose : |
101 | //======================================================================= |
102 | |
103 | void AIS_MaxRadiusDimension::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/, |
104 | const Handle(Prs3d_Presentation)& aPresentation, |
105 | const Standard_Integer /*aMode*/) |
106 | { |
107 | aPresentation->Clear(); |
108 | |
109 | // if( myAutomaticPosition ) |
110 | {//ota : recompute in any case |
111 | ComputeGeometry(); |
112 | myEllipse.SetMajorRadius(myVal); |
113 | gp_Vec v1(myEllipse.XAxis().Direction()); |
114 | v1 *=myVal; |
115 | myApexP = myEllipse.Location().Translated(v1); |
116 | myApexN = myEllipse.Location().Translated(-v1); |
117 | } |
118 | if(myIsAnArc) ComputeArcOfEllipse(aPresentation); |
119 | else |
120 | ComputeEllipse(aPresentation); |
121 | } |
122 | |
123 | //======================================================================= |
124 | //function : Compute |
125 | //purpose : to avoid warning |
126 | //======================================================================= |
127 | |
128 | void AIS_MaxRadiusDimension::Compute(const Handle(Prs3d_Projector)& aProjector, |
129 | const Handle(Prs3d_Presentation)& aPresentation) |
130 | { |
131 | // Standard_NotImplemented::Raise("AIS_MaxRadiusDimension::Compute(const Handle(Prs3d_Projector)& aProjector, const Handle(Prs3d_Presentation)& aPresentation)"); |
132 | PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ; |
133 | } |
134 | |
7fd59977 |
135 | //======================================================================= |
136 | //function : Compute |
137 | //purpose : |
138 | //======================================================================= |
139 | |
857ffd5e |
140 | void AIS_MaxRadiusDimension::Compute(const Handle(Prs3d_Projector)& aProjector, |
141 | const Handle(Geom_Transformation)& aTransformation, |
142 | const Handle(Prs3d_Presentation)& aPresentation) |
7fd59977 |
143 | { |
857ffd5e |
144 | // Standard_NotImplemented::Raise("AIS_MaxRadiusDimension::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)"); |
7fd59977 |
145 | PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ; |
146 | } |
147 | |
148 | |
149 | //======================================================================= |
150 | //function : ComputeEllipse |
151 | //purpose : |
152 | //======================================================================= |
153 | |
154 | void AIS_MaxRadiusDimension::ComputeEllipse(const Handle(Prs3d_Presentation)& aPresentation) |
155 | { |
156 | |
a6eb515f |
157 | Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect(); |
158 | Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect(); |
7fd59977 |
159 | |
160 | // size |
7fd59977 |
161 | if( !myArrowSizeIsDefined ) { |
162 | myArrowSize = Min(myArrowSize,myVal / 5.); |
163 | } |
164 | arr->SetLength(myArrowSize); |
7fd59977 |
165 | |
166 | Standard_Real U;//,V; |
167 | gp_Pnt curPos, Center; |
168 | Center = myEllipse.Location(); |
169 | if( myAutomaticPosition ) |
170 | { |
171 | myPosition = Center; |
172 | myEndOfArrow = myApexP; |
173 | myAutomaticPosition = Standard_True; |
174 | |
175 | if ( myIsSetBndBox ) |
176 | myPosition = AIS::TranslatePointToBound(myPosition, gp_Dir(gp_Vec( Center, myPosition )), |
177 | myBndBox ); |
178 | curPos = myPosition; |
179 | } |
180 | else //!AutomaticPosition |
181 | { |
182 | curPos = myPosition; |
183 | gp_Lin L1(myEllipse.XAxis()); |
184 | U = ElCLib::Parameter ( L1, curPos ); |
185 | curPos = ElCLib::Value (U, L1); |
186 | if (curPos.Distance(myApexP) < curPos.Distance(myApexN)) |
187 | myEndOfArrow = myApexP ; |
188 | else |
189 | myEndOfArrow = myApexN ; |
190 | } |
191 | |
192 | // Presenatation |
193 | DsgPrs_EllipseRadiusPresentation::Add(aPresentation, myDrawer, myVal, myText, curPos, |
194 | myEndOfArrow, Center, Standard_True, mySymbolPrs); |
195 | |
196 | } |
197 | |
198 | //======================================================================= |
199 | //function : ComputeArcOfEllipse |
200 | //purpose : |
201 | //======================================================================= |
202 | |
203 | void AIS_MaxRadiusDimension::ComputeArcOfEllipse(const Handle(Prs3d_Presentation)& aPresentation) |
204 | { |
205 | |
a6eb515f |
206 | Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect(); |
207 | Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect(); |
7fd59977 |
208 | |
209 | // size |
7fd59977 |
210 | if( !myArrowSizeIsDefined ) { |
211 | myArrowSize = Min(myArrowSize,myVal / 5.); |
212 | } |
213 | arr->SetLength(myArrowSize); |
7fd59977 |
214 | |
215 | Standard_Real par; |
216 | gp_Pnt curPos, Center; |
217 | Center = myEllipse.Location(); |
218 | Standard_Boolean IsInDomain = Standard_True; |
219 | if( myAutomaticPosition ) |
220 | { |
221 | myEndOfArrow = AIS::NearestApex(myEllipse, myApexP, myApexN, |
222 | myFirstPar, myLastPar, IsInDomain); |
223 | myPosition = Center; |
224 | myAutomaticPosition = Standard_True; |
225 | if ( myIsSetBndBox ) |
226 | myPosition = AIS::TranslatePointToBound(myPosition, gp_Dir(gp_Vec( Center, myPosition )), |
227 | myBndBox ); |
228 | curPos = myPosition; |
229 | } |
230 | else //!AutomaticPosition |
231 | { |
232 | curPos = myPosition; |
233 | // ElSLib::Parameters ( myPlane->Pln(), curPos, U, V ); |
234 | // curPos = ElSLib::Value (U, V, myPlane->Pln()); |
235 | gp_Lin L1(myEllipse.XAxis()); |
236 | par = ElCLib::Parameter ( L1, curPos ); |
237 | curPos = ElCLib::Value (par, L1); |
238 | if (curPos.Distance(myApexP) < curPos.Distance(myApexN)) |
239 | myEndOfArrow = myApexP ; |
240 | else |
241 | myEndOfArrow = myApexN ; |
242 | par = ElCLib::Parameter ( myEllipse, myEndOfArrow ); |
243 | IsInDomain = AIS::InDomain( myFirstPar, myLastPar, par ); |
244 | myPosition = curPos; |
245 | } |
246 | |
247 | // Standard_Real parEnd = ElCLib::Parameter ( myEllipse, myEndOfArrow ); |
248 | Standard_Real parStart = 0.; |
249 | if( !IsInDomain ) |
250 | { |
251 | if(AIS::DistanceFromApex (myEllipse, myEndOfArrow, myFirstPar) < |
252 | AIS::DistanceFromApex (myEllipse, myEndOfArrow, myLastPar)) |
253 | parStart = myFirstPar; |
254 | else |
255 | parStart = myLastPar; |
256 | } |
257 | if(!myIsOffset) |
258 | DsgPrs_EllipseRadiusPresentation::Add(aPresentation, myDrawer, myVal, myText, myEllipse, |
259 | curPos, myEndOfArrow, Center, parStart, IsInDomain, |
260 | Standard_True, mySymbolPrs); |
261 | else |
262 | DsgPrs_EllipseRadiusPresentation::Add(aPresentation, myDrawer, myVal, myText, myOffsetCurve, |
263 | curPos, myEndOfArrow, Center, parStart, IsInDomain, |
264 | Standard_True, mySymbolPrs); |
265 | } |
266 | |
267 | //======================================================================= |
268 | //function : ComputeSelection |
269 | //purpose : |
270 | //======================================================================= |
271 | |
272 | void AIS_MaxRadiusDimension::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, |
273 | const Standard_Integer /*aMode*/) |
274 | { |
275 | |
276 | gp_Pnt center = myEllipse.Location(); |
277 | gp_Pnt AttachmentPoint = myPosition; |
278 | Standard_Real dist = center.Distance(AttachmentPoint); |
279 | Standard_Real aRadius = myVal; |
280 | //Standard_Real inside = Standard_False; |
281 | gp_Pnt pt1; |
282 | if (dist > aRadius) pt1 = AttachmentPoint; |
283 | else |
284 | pt1 = myEndOfArrow; |
285 | Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7); |
286 | Handle(Select3D_SensitiveSegment) |
287 | seg = new Select3D_SensitiveSegment(own, center , pt1); |
288 | aSelection->Add(seg); |
289 | |
290 | // Text |
291 | Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6)); |
292 | Handle( Select3D_SensitiveBox ) box = new Select3D_SensitiveBox( own, |
293 | AttachmentPoint.X(), |
294 | AttachmentPoint.Y(), |
295 | AttachmentPoint.Z(), |
296 | AttachmentPoint.X()+size, |
297 | AttachmentPoint.Y()+size, |
298 | AttachmentPoint.Z()+size); |
299 | aSelection->Add(box); |
300 | |
301 | // Arc of Ellipse |
302 | if(myIsAnArc) |
303 | { |
304 | |
305 | Standard_Real parEnd = ElCLib::Parameter ( myEllipse, myEndOfArrow ); |
306 | if(!AIS::InDomain(myFirstPar, myLastPar, parEnd)) |
307 | { |
308 | Standard_Real parStart, par; |
309 | if(AIS::DistanceFromApex (myEllipse, myEndOfArrow, myFirstPar) < |
310 | AIS::DistanceFromApex (myEllipse, myEndOfArrow, myLastPar)) |
311 | par = myFirstPar; |
312 | else |
313 | par = myLastPar; |
314 | gp_Vec Vapex(center, ElCLib::Value( parEnd, myEllipse )) ; |
315 | gp_Vec Vpnt (center, ElCLib::Value( par, myEllipse )) ; |
316 | gp_Dir dir(Vpnt ^ Vapex); |
317 | if(myEllipse.Position().Direction().IsOpposite( dir, Precision::Angular())) { |
318 | parStart = parEnd; |
319 | parEnd = par; |
320 | } |
321 | else |
322 | parStart = par; |
323 | |
c04c30b3 |
324 | Handle(Geom_Curve)TrimCurve; |
7fd59977 |
325 | if(myIsOffset) |
326 | { |
327 | Handle(Geom_Curve) aCurve = myOffsetCurve; |
328 | TrimCurve = new Geom_TrimmedCurve( aCurve, parStart, parEnd ); |
329 | } |
330 | else |
331 | { |
332 | Handle(Geom_Ellipse) Ellipse = new Geom_Ellipse( myEllipse ); |
333 | TrimCurve = new Geom_TrimmedCurve( Ellipse, parStart, parEnd ); |
334 | } |
335 | Handle( Select3D_SensitiveCurve ) SensArc; |
336 | SensArc = new Select3D_SensitiveCurve( own, TrimCurve ); |
337 | aSelection->Add( SensArc ); |
338 | } |
339 | } |
340 | |
341 | } |