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