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