Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1996-12-05 |
2 | // Created by: Jacques MINOT/Odile Olivier/Sergey 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 | // Modified Mon 12-january-98 |
7fd59977 | 22 | // <ODL>, <SZY> |
23 | ||
24 | ||
25 | #define BUC60915 //GG 05/06/01 Enable to compute the requested arrow size | |
26 | // if any in all dimensions. | |
27 | ||
28 | #include <Standard_NotImplemented.hxx> | |
29 | ||
30 | #include <AIS_DiameterDimension.ixx> | |
31 | #include <AIS_DimensionOwner.hxx> | |
32 | #include <DsgPrs_DiameterPresentation.hxx> | |
33 | #include <DsgPrs_RadiusPresentation.hxx> | |
34 | ||
35 | #include <TCollection_ExtendedString.hxx> | |
36 | ||
37 | #include <Prs3d_LengthAspect.hxx> | |
38 | #include <Prs3d_ArrowAspect.hxx> | |
39 | #include <Prs3d_Drawer.hxx> | |
40 | #include <Prs3d_TextAspect.hxx> | |
41 | #include <Prs3d_Text.hxx> | |
42 | ||
43 | #include <Select3D_SensitiveSegment.hxx> | |
44 | #include <Select3D_SensitiveBox.hxx> | |
45 | #include <SelectMgr_EntityOwner.hxx> | |
46 | ||
47 | #include <ElCLib.hxx> | |
48 | #include <ElSLib.hxx> | |
49 | ||
50 | #include <TopoDS.hxx> | |
51 | ||
52 | #include <BRepAdaptor_Surface.hxx> | |
53 | #include <BRepAdaptor_Curve.hxx> | |
54 | #include <Adaptor3d_HCurve.hxx> | |
55 | ||
56 | #include <Geom_Circle.hxx> | |
57 | #include <Geom_TrimmedCurve.hxx> | |
58 | #include <Geom_Plane.hxx> | |
59 | #include <Geom_Surface.hxx> | |
60 | #include <Geom_CylindricalSurface.hxx> | |
61 | #include <Geom_SurfaceOfRevolution.hxx> | |
62 | #include <Geom_CylindricalSurface.hxx> | |
63 | #include <Geom_SurfaceOfLinearExtrusion.hxx> | |
64 | ||
65 | #include <gp_Pln.hxx> | |
66 | #include <gp_Pnt.hxx> | |
67 | #include <gp_Lin.hxx> | |
68 | #include <gp_Ax1.hxx> | |
69 | #include <gp_Dir.hxx> | |
70 | #include <gp_Vec.hxx> | |
71 | ||
72 | #include <AIS.hxx> | |
73 | #include <AIS_Drawer.hxx> | |
74 | ||
75 | #include <GC_MakeCircle.hxx> | |
76 | ||
77 | #include <Precision.hxx> | |
78 | ||
79 | #include <TopExp_Explorer.hxx> | |
80 | ||
81 | //======================================================================= | |
82 | //function : Constructor | |
83 | //purpose : | |
84 | //======================================================================= | |
85 | ||
86 | AIS_DiameterDimension::AIS_DiameterDimension(const TopoDS_Shape& aShape, | |
87 | const Standard_Real aVal, | |
88 | const TCollection_ExtendedString& aText) | |
89 | :AIS_Relation(), | |
90 | myDiamSymbol(Standard_True) | |
91 | { | |
92 | myPosition = gp_Pnt(0.,0.,0.); | |
93 | myFShape = aShape; | |
94 | myVal = aVal; | |
95 | myText = aText; | |
96 | mySymbolPrs = DsgPrs_AS_LASTAR; | |
97 | myAutomaticPosition = Standard_True; | |
98 | myArrowSize = myVal / 100.; | |
99 | } | |
100 | ||
101 | //======================================================================= | |
102 | //function : Constructor | |
103 | //purpose : | |
104 | //======================================================================= | |
105 | ||
106 | AIS_DiameterDimension::AIS_DiameterDimension(const TopoDS_Shape& aShape, | |
107 | const Standard_Real aVal, | |
108 | const TCollection_ExtendedString& aText, | |
109 | const gp_Pnt& aPosition, | |
110 | const DsgPrs_ArrowSide aSymbolPrs, | |
111 | const Standard_Boolean aDiamSymbol, | |
112 | const Standard_Real anArrowSize) | |
113 | :AIS_Relation(), | |
114 | myDiamSymbol(aDiamSymbol) | |
115 | { | |
116 | myFShape = aShape; | |
117 | myVal = aVal; | |
118 | myText = aText; | |
119 | mySymbolPrs = aSymbolPrs; | |
120 | myPosition = aPosition; | |
121 | myAutomaticPosition = Standard_False; | |
122 | #ifdef BUC60915 | |
123 | SetArrowSize( anArrowSize ); | |
124 | #else | |
125 | myArrowSize = anArrowSize; | |
126 | #endif | |
127 | } | |
128 | ||
129 | //======================================================================= | |
130 | //function : Compute | |
131 | //purpose : | |
132 | //======================================================================= | |
133 | ||
134 | void AIS_DiameterDimension::Compute( | |
135 | const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/, | |
136 | const Handle(Prs3d_Presentation)& aPresentation, | |
137 | const Standard_Integer /*aMode*/) | |
138 | { | |
139 | aPresentation->Clear(); | |
140 | ||
141 | switch (myFShape.ShapeType()) { | |
142 | case TopAbs_FACE : | |
143 | { | |
144 | // compute one face case | |
145 | ComputeOneFaceDiameter (aPresentation); | |
146 | break; | |
147 | } | |
148 | case TopAbs_EDGE: | |
149 | { | |
150 | ComputeOneEdgeDiameter (aPresentation); | |
151 | break; | |
152 | } | |
153 | default: | |
154 | break; | |
155 | } | |
156 | ||
157 | } | |
158 | ||
159 | //======================================================================= | |
160 | //function : Compute | |
161 | //purpose : to avoid warning | |
162 | //======================================================================= | |
163 | ||
164 | void AIS_DiameterDimension::Compute(const Handle(Prs3d_Projector)& aProjector, | |
165 | const Handle(Prs3d_Presentation)& aPresentation) | |
166 | { | |
167 | // Standard_NotImplemented::Raise("AIS_DiameterDimension::Compute(const Handle(Prs3d_Projector)& aProjector, const Handle(Prs3d_Presentation)& aPresentation)"); | |
168 | PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ; | |
169 | } | |
170 | ||
171 | //======================================================================= | |
172 | //function : Compute | |
173 | //purpose : to avoid warning | |
174 | //======================================================================= | |
175 | ||
176 | void AIS_DiameterDimension::Compute(const Handle(PrsMgr_PresentationManager2d)& aPresentationManager, | |
177 | const Handle(Graphic2d_GraphicObject)& aPresentation, | |
178 | const Standard_Integer aMode) | |
179 | { | |
180 | // Standard_NotImplemented::Raise("AIS_DiameterDimension::Compute(const Handle(PrsMgr_PresentationManager2d)& aPresentationManager, const Handle(Graphic2d_GraphicObject)& aPresentation, const Standard_Integer aMode)"); | |
181 | PrsMgr_PresentableObject::Compute( aPresentationManager ,aPresentation,aMode) ; | |
182 | } | |
183 | ||
184 | void AIS_DiameterDimension::Compute(const Handle_Prs3d_Projector& aProjector, const Handle_Geom_Transformation& aTransformation, const Handle_Prs3d_Presentation& aPresentation) | |
185 | { | |
186 | // Standard_NotImplemented::Raise("AIS_DiameterDimension::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)"); | |
187 | PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ; | |
188 | } | |
189 | ||
190 | //======================================================================= | |
191 | //function : ComputeSelection | |
192 | //purpose : | |
193 | //======================================================================= | |
194 | ||
195 | void AIS_DiameterDimension::ComputeSelection( | |
196 | const Handle(SelectMgr_Selection)& aSelection, | |
197 | const Standard_Integer /*aMode*/) | |
198 | { | |
199 | Handle(AIS_DimensionOwner) own = new AIS_DimensionOwner(this,7); | |
200 | own->SetShape(myFShape); | |
201 | ||
202 | if (!myIsAnArc) { | |
203 | gp_Pnt AttachmentPoint = myPosition; | |
204 | Standard_Real parat = ElCLib::Parameter(myCircle,AttachmentPoint); | |
205 | gp_Pnt ptoncirc = ElCLib::Value (parat,myCircle); | |
206 | ||
207 | // ligne de cote | |
208 | ||
209 | gp_Pnt center = myCircle.Location(); | |
210 | gp_Vec vecrap (ptoncirc,center); | |
211 | ||
212 | Standard_Real dist = center.Distance(AttachmentPoint); | |
213 | Standard_Real aRadius = myCircle.Radius(); | |
214 | Standard_Real inside = Standard_False; | |
215 | ||
216 | gp_Pnt pt1 = AttachmentPoint; | |
217 | if (dist < aRadius) { | |
218 | pt1 = ptoncirc; | |
219 | dist = aRadius; | |
220 | inside = Standard_True; | |
221 | } | |
222 | vecrap.Normalize(); | |
223 | vecrap *= (dist+aRadius); | |
224 | gp_Pnt OppositePoint = pt1.Translated(vecrap); | |
225 | ||
226 | if ( pt1.Distance(OppositePoint)>=Precision::Confusion()) { | |
227 | Handle(Select3D_SensitiveSegment) | |
228 | seg = new Select3D_SensitiveSegment(own,pt1 ,OppositePoint); | |
229 | aSelection->Add(seg); | |
230 | } | |
231 | } | |
232 | else | |
233 | ComputeArcSelection(aSelection); | |
234 | ||
235 | // Text | |
236 | Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6)); | |
237 | Handle( Select3D_SensitiveBox ) box = new Select3D_SensitiveBox( own, | |
238 | myPosition.X(), | |
239 | myPosition.Y(), | |
240 | myPosition.Z(), | |
241 | myPosition.X() + size, | |
242 | myPosition.Y() + size, | |
243 | myPosition.Z() + size); | |
244 | aSelection->Add(box); | |
245 | } | |
246 | //========================================================================== | |
247 | // function : ComputeArcSelection | |
248 | // purpose : | |
249 | // | |
250 | //========================================================================== | |
251 | ||
252 | void AIS_DiameterDimension::ComputeArcSelection(const Handle(SelectMgr_Selection)& aSelection) | |
253 | { | |
254 | ||
255 | Standard_Real fpara; | |
256 | Standard_Real lpara; | |
257 | fpara = myFirstPar; | |
258 | lpara = myLastPar; | |
259 | ||
260 | Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7); | |
261 | gp_Pnt theCenter = myCircle.Location(); | |
c6541a0c D |
262 | while (lpara > 2*M_PI) { |
263 | fpara -= 2*M_PI; | |
264 | lpara -= 2*M_PI; | |
7fd59977 | 265 | } |
266 | Standard_Real parat = ElCLib::Parameter(myCircle,myPosition); | |
267 | Standard_Boolean otherside(Standard_False); | |
268 | gp_Pnt attpoint = myPosition; | |
269 | ||
270 | if (!AIS::InDomain(fpara,lpara,parat)) { | |
c6541a0c D |
271 | Standard_Real otherpar = parat + M_PI; |
272 | if (otherpar > 2*M_PI) otherpar -= 2*M_PI; | |
7fd59977 | 273 | if (AIS::InDomain(fpara,lpara,otherpar)) { |
274 | parat = otherpar; | |
275 | otherside = Standard_True; | |
276 | } | |
277 | else { | |
278 | Standard_Real ecartpar = Min(Abs(fpara-parat), | |
279 | Abs(lpara-parat)); | |
280 | Standard_Real ecartoth = Min(Abs(fpara-otherpar), | |
281 | Abs(lpara-otherpar)); | |
282 | if (ecartpar <= ecartoth) { | |
283 | if (parat < fpara) parat = fpara; | |
284 | else parat = lpara; | |
285 | } | |
286 | else { | |
287 | otherside = Standard_True; | |
288 | if (otherpar < fpara) parat = fpara; | |
289 | else parat = lpara; | |
290 | } | |
291 | gp_Pnt ptdir = ElCLib::Value(parat,myCircle); | |
292 | gp_Lin lsup(theCenter, | |
293 | gp_Dir(ptdir.XYZ()-theCenter.XYZ())); | |
294 | Standard_Real parpos = ElCLib::Parameter(lsup,myPosition); | |
295 | attpoint = ElCLib::Value(parpos,lsup); | |
296 | } | |
297 | } | |
298 | gp_Pnt ptoncirc = ElCLib::Value(parat,myCircle); | |
299 | gp_Lin L (theCenter,gp_Dir(attpoint.XYZ()-theCenter.XYZ())); | |
300 | gp_Pnt firstpoint = attpoint; | |
301 | gp_Pnt drawtopoint = ptoncirc; | |
302 | ||
303 | if (!otherside) { | |
304 | Standard_Real uatt = ElCLib::Parameter(L,attpoint); | |
305 | Standard_Real uptc = ElCLib::Parameter(L,ptoncirc); | |
306 | if (Abs(uatt) > Abs(uptc)) { | |
307 | drawtopoint = theCenter; | |
308 | } | |
309 | else { | |
310 | firstpoint = theCenter; | |
311 | } | |
312 | } | |
313 | ||
314 | Handle(Select3D_SensitiveSegment) seg = new Select3D_SensitiveSegment(own,firstpoint,drawtopoint); | |
315 | aSelection->Add(seg); | |
316 | } | |
317 | ||
318 | //======================================================================= | |
319 | //function : ComputeOneFaceDiameter | |
320 | //purpose : | |
321 | //======================================================================= | |
322 | ||
323 | void AIS_DiameterDimension::ComputeOneFaceDiameter( | |
324 | const Handle(Prs3d_Presentation)& aPresentation) | |
325 | { | |
326 | //cout<<"AIS_DiameterDimension::ComputeOneFaceDiameter"<<endl; | |
327 | ||
328 | gp_Pln aPln; | |
329 | Handle( Geom_Surface ) aBasisSurf; | |
330 | AIS_KindOfSurface aSurfType; | |
331 | Standard_Real Offset; | |
332 | if( myAutomaticPosition ) | |
333 | AIS::GetPlaneFromFace( TopoDS::Face( myFShape), | |
334 | aPln, | |
335 | aBasisSurf, | |
336 | aSurfType, | |
337 | Offset ) ; | |
338 | ||
339 | if ( aSurfType == AIS_KOS_Plane ) | |
340 | ComputeOnePlanarFaceDiameter( aPresentation ); | |
341 | else | |
342 | ComputeOneCylFaceDiameter( aPresentation, aSurfType, aBasisSurf ); | |
343 | ||
344 | } | |
345 | ||
346 | ||
347 | //======================================================================= | |
348 | //function : ComputeOneCylFaceDiameter | |
349 | //purpose : | |
350 | //======================================================================= | |
351 | ||
352 | void AIS_DiameterDimension::ComputeOneCylFaceDiameter | |
353 | (const Handle(Prs3d_Presentation)& aPresentation, | |
354 | const AIS_KindOfSurface aSurfType, | |
355 | const Handle( Geom_Surface )& aBasisSurf ) | |
356 | { | |
357 | gp_Pnt curPos; | |
358 | if( myAutomaticPosition ) | |
359 | { | |
360 | BRepAdaptor_Surface surf1(TopoDS::Face(myFShape)); | |
361 | Standard_Real uFirst, uLast, vFirst, vLast; | |
362 | uFirst = surf1.FirstUParameter(); | |
363 | uLast = surf1.LastUParameter(); | |
364 | vFirst = surf1.FirstVParameter(); | |
365 | vLast = surf1.LastVParameter(); | |
366 | Standard_Real uMid = (uFirst + uLast)*0.5; | |
367 | Standard_Real vMid = (vFirst + vLast)*0.5; | |
368 | surf1.D0(uMid, vMid, curPos); | |
369 | Handle( Adaptor3d_HCurve ) BasisCurve; | |
370 | //Standard_Real Param; | |
371 | Standard_Boolean ExpectedType = Standard_False; | |
372 | if (aSurfType == AIS_KOS_Cylinder) | |
373 | { | |
374 | ExpectedType = Standard_True; | |
375 | } | |
376 | else | |
377 | if (aSurfType == AIS_KOS_Revolution) | |
378 | { | |
379 | BasisCurve = surf1.BasisCurve(); | |
380 | if (BasisCurve->GetType() == GeomAbs_Line) | |
381 | ExpectedType = Standard_True; | |
382 | } | |
383 | else if (aSurfType == AIS_KOS_Extrusion) | |
384 | { | |
385 | BasisCurve = surf1.BasisCurve(); | |
386 | if ( BasisCurve->GetType() == GeomAbs_Circle ) | |
387 | ExpectedType = Standard_True; | |
388 | } | |
389 | if(!ExpectedType) { | |
390 | Standard_ConstructionError::Raise("AIS:: Not expected type of surface") ; | |
391 | return; | |
392 | } | |
393 | // | |
394 | Handle(Geom_Curve) aCurve; | |
395 | aCurve = aBasisSurf->VIso(vMid); | |
396 | if (aCurve->DynamicType() == STANDARD_TYPE(Geom_Circle)) | |
397 | { | |
398 | myCircle = Handle(Geom_Circle)::DownCast(aCurve)->Circ();//gp_Circ | |
399 | } | |
400 | else if (aCurve->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve)) { | |
401 | Handle(Geom_TrimmedCurve) tCurve = Handle(Geom_TrimmedCurve)::DownCast(aCurve); | |
402 | aCurve = tCurve->BasisCurve(); | |
403 | uFirst = tCurve->FirstParameter(); | |
404 | uLast = tCurve->LastParameter(); | |
405 | if (aCurve->DynamicType() == STANDARD_TYPE(Geom_Circle)) | |
406 | myCircle = Handle(Geom_Circle)::DownCast(aCurve)->Circ();//gp_Circ | |
407 | } | |
408 | else { | |
409 | // compute a circle from 3 points on "aCurve" | |
410 | gp_Pnt P1, P2; | |
411 | surf1.D0(uFirst, vMid, P1); | |
412 | surf1.D0(uLast, vMid, P2); | |
413 | GC_MakeCircle mkCirc(P1, curPos, P2); | |
414 | myCircle = mkCirc.Value()->Circ(); | |
415 | } | |
416 | myCircle.SetRadius(myVal/2.); | |
417 | myPlane = new Geom_Plane(gp_Pln(gp_Ax3(myCircle.Position())));//gp_Circ | |
418 | gp_Vec v1(myCircle.Location(), curPos); | |
419 | v1.Normalize(); | |
420 | v1 = v1 * myVal*1.2; | |
421 | myPosition = myCircle.Location().Translated(v1); | |
422 | // IsArc ? | |
423 | gp_Pnt p1, p2; | |
424 | p1 = ElCLib::Value (uFirst, myCircle); | |
425 | p2 = ElCLib::Value (uLast, myCircle); | |
426 | if ( p1.IsEqual(p2, Precision::Confusion()) ) | |
427 | myIsAnArc = Standard_False; | |
428 | else myIsAnArc = Standard_True; | |
429 | myFirstPar = uFirst; | |
430 | myLastPar = uLast; | |
431 | // myPosition = curPos; | |
432 | myAutomaticPosition = Standard_True; | |
433 | if ( myIsSetBndBox ) | |
434 | myPosition = AIS::TranslatePointToBound( myPosition, gp_Dir( gp_Vec( myCircle.Location(), | |
435 | myPosition ) ), myBndBox ); | |
436 | } | |
437 | else { // !AutomaticPosition | |
438 | curPos = myPosition; | |
439 | curPos = AIS::ProjectPointOnPlane( curPos, myPlane->Pln() ); | |
440 | myPosition = curPos; | |
441 | } | |
442 | ||
443 | Handle(Prs3d_LengthAspect) la = myDrawer->LengthAspect(); | |
444 | Handle(Prs3d_ArrowAspect) arr = la->Arrow1Aspect(); | |
445 | ||
446 | // size | |
447 | #ifdef BUC60915 | |
448 | if( !myArrowSizeIsDefined ) { | |
449 | myArrowSize = Min(myArrowSize,myCircle.Radius()/5.); | |
450 | } | |
451 | arr->SetLength(myArrowSize); | |
452 | #else | |
453 | if (myCircle.Radius()/5. > myArrowSize) { | |
454 | arr->SetLength(myArrowSize); | |
455 | } | |
456 | else { | |
457 | arr->SetLength(myCircle.Radius()/5.); | |
458 | } | |
459 | #endif | |
460 | ||
461 | //cout<<"AIS_DiameterDimension:: add Prs"<<endl; | |
462 | if( myIsAnArc ) | |
463 | DsgPrs_DiameterPresentation::Add(aPresentation, myDrawer, myText, myPosition, | |
464 | myCircle, myFirstPar, myLastPar, mySymbolPrs, myDiamSymbol); | |
465 | else | |
466 | DsgPrs_DiameterPresentation::Add(aPresentation, myDrawer, myText, myPosition, | |
467 | myCircle, DsgPrs_AS_BOTHAR, myDiamSymbol); | |
468 | ||
469 | ||
470 | } | |
471 | ||
472 | ||
473 | //======================================================================= | |
474 | //function : ComputeCircleDiameter | |
475 | //purpose : | |
476 | //======================================================================= | |
477 | ||
478 | void AIS_DiameterDimension::ComputeCircleDiameter(const Handle(Prs3d_Presentation)& aPresentation) | |
479 | { | |
480 | gp_Pnt center = myCircle.Location(); | |
481 | Standard_Real rad = myCircle.Radius(); | |
482 | gp_Pnt curpos; | |
483 | ||
484 | if (myAutomaticPosition) { | |
485 | // we compute 1 point on the circle | |
486 | myPlane = new Geom_Plane(gp_Pln(gp_Ax3(myCircle.Position())));//gp_Circ | |
487 | gp_Dir xdir = myCircle.XAxis().Direction(); | |
488 | Standard_Real deport = rad *1.2; | |
489 | curpos = center.Translated( gp_Vec(xdir)*deport ); | |
490 | SetPosition (curpos);// myPosition = curpos | |
491 | myAutomaticPosition = Standard_True; | |
492 | if (myIsSetBndBox) | |
493 | myPosition = AIS::TranslatePointToBound( myPosition, gp_Dir( gp_Vec( myCircle.Location(), | |
494 | myPosition ) ), myBndBox ); | |
495 | } | |
496 | else { | |
497 | curpos = myPosition; | |
498 | // VRO (2007-05-17) inserted this IF. | |
499 | if (myPlane.IsNull()) | |
500 | myPlane = new Geom_Plane(gp_Pln(gp_Ax3(myCircle.Position()))); | |
501 | myPosition = AIS::ProjectPointOnPlane( curpos, myPlane->Pln() ); | |
502 | } | |
503 | ||
504 | // size | |
505 | Handle(Prs3d_LengthAspect) LA = myDrawer->LengthAspect(); | |
506 | Handle(Prs3d_ArrowAspect) arr = LA->Arrow1Aspect(); | |
507 | ||
508 | #ifdef BUC60915 | |
509 | if( !myArrowSizeIsDefined ) { | |
510 | myArrowSize = Min(myArrowSize,myCircle.Radius()/5.); | |
511 | } | |
512 | arr->SetLength(myArrowSize); | |
513 | #else | |
514 | if (myCircle.Radius()/5. > myArrowSize) { | |
515 | arr->SetLength(myArrowSize); | |
516 | } | |
517 | else { | |
518 | arr->SetLength(myCircle.Radius()/5.); | |
519 | } | |
520 | #endif | |
521 | ||
522 | DsgPrs_DiameterPresentation::Add(aPresentation, myDrawer, myText, myPosition, myCircle, | |
523 | DsgPrs_AS_BOTHAR, myDiamSymbol ); | |
524 | ||
525 | } | |
526 | ||
527 | //========================================================================== | |
528 | // function : ComputeArcDiameter | |
529 | // purpose : | |
530 | // | |
531 | //========================================================================== | |
532 | ||
533 | void AIS_DiameterDimension::ComputeArcDiameter( | |
534 | const Handle(Prs3d_Presentation)& aPresentation, | |
535 | const gp_Pnt& pfirst, | |
536 | const gp_Pnt& pend) | |
537 | { | |
538 | ||
539 | gp_Pnt center = myCircle.Location(); | |
540 | Standard_Real rad = myCircle.Radius(); | |
541 | ||
542 | gp_Pnt curpos; | |
543 | Standard_Real parfirst, parend; | |
544 | ||
545 | parfirst = ElCLib::Parameter(myCircle, pfirst); | |
546 | parend = ElCLib::Parameter(myCircle, pend); | |
547 | myFirstPar = parfirst; | |
548 | myLastPar = parend; | |
549 | if ( parfirst > parend) { | |
c6541a0c | 550 | parfirst -= 2*M_PI; |
7fd59977 | 551 | } |
552 | if (myAutomaticPosition) { | |
553 | Standard_Real pcurpos = (parfirst + parend)/2.; | |
554 | curpos = ElCLib::Value(pcurpos, myCircle); | |
555 | myPlane = new Geom_Plane(gp_Pln(gp_Ax3(myCircle.Position())));//gp_Circ | |
556 | gp_Dir vdir(gp_Vec(myCircle.Location(),curpos)); | |
557 | Standard_Real deport = rad * 1.2; | |
558 | curpos = center.Translated( gp_Vec(vdir)*deport ); | |
559 | ||
560 | SetPosition (curpos); | |
561 | myAutomaticPosition = Standard_True; | |
562 | ||
563 | if ( myIsSetBndBox ) | |
564 | myPosition = AIS::TranslatePointToBound( myPosition, gp_Dir( gp_Vec( myCircle.Location(), | |
565 | myPosition ) ), myBndBox ); | |
566 | ||
567 | } | |
568 | else { | |
569 | curpos = myPosition; | |
570 | myPosition = AIS::ProjectPointOnPlane( curpos, myPlane->Pln() ); | |
571 | } | |
572 | ||
573 | // size | |
574 | ||
575 | Handle(Prs3d_LengthAspect) LA = myDrawer->LengthAspect(); | |
576 | Handle(Prs3d_ArrowAspect) arr = LA->Arrow1Aspect(); | |
577 | ||
578 | #ifdef BUC60915 | |
579 | if( !myArrowSizeIsDefined ) { | |
580 | myArrowSize = Min(myArrowSize,myCircle.Radius()/5.); | |
581 | } | |
582 | arr->SetLength(myArrowSize); | |
583 | #else | |
584 | if (myCircle.Radius()/5. > myArrowSize) { | |
585 | arr->SetLength(myArrowSize); | |
586 | } | |
587 | else { | |
588 | arr->SetLength(myCircle.Radius()/5.); | |
589 | } | |
590 | #endif | |
591 | ||
592 | // Display | |
593 | DsgPrs_DiameterPresentation::Add (aPresentation, myDrawer, myText, myPosition, myCircle, | |
594 | parfirst, parend, mySymbolPrs, myDiamSymbol); | |
595 | ||
596 | } | |
597 | ||
598 | ||
599 | //========================================================================== | |
600 | // function : ComputeOneEdgeDiameter | |
601 | // purpose : | |
602 | // | |
603 | //========================================================================== | |
604 | ||
605 | void AIS_DiameterDimension::ComputeOneEdgeDiameter(const Handle(Prs3d_Presentation)& aPresentation) | |
606 | { | |
607 | gp_Pnt ptfirst,ptend; | |
608 | Handle(Geom_Curve) curv; | |
609 | if (!AIS::ComputeGeometry(TopoDS::Edge(myFShape),curv,ptfirst,ptend)) return; | |
610 | ||
611 | Handle(Geom_Circle) circ = Handle(Geom_Circle)::DownCast(curv); | |
612 | if ( circ.IsNull()) return; | |
613 | ||
614 | myCircle = circ->Circ(); | |
615 | myCircle.SetRadius(myVal/2.); | |
616 | if ( ptfirst.IsEqual(ptend, Precision::Confusion()) ) { | |
617 | myIsAnArc = Standard_False; | |
618 | ComputeCircleDiameter(aPresentation); | |
619 | } | |
620 | else { | |
621 | myIsAnArc = Standard_True; | |
622 | ComputeArcDiameter(aPresentation,ptfirst,ptend ); | |
623 | } | |
624 | } | |
625 | ||
626 | //=================================================================== | |
627 | //function : CircleFromPlanarFace | |
628 | //purpose : if possible computes circle from planar face | |
629 | //======================================================================= | |
630 | static Standard_Boolean CircleFromPlanarFace(const TopoDS_Face& aFace, | |
631 | Handle(Geom_Curve)& aCurve, | |
632 | gp_Pnt & ptfirst, gp_Pnt & ptend) | |
633 | { | |
634 | TopExp_Explorer ExploEd( aFace, TopAbs_EDGE ); | |
635 | for ( ; ExploEd.More(); ExploEd.Next()) | |
636 | { | |
637 | TopoDS_Edge curedge = TopoDS::Edge( ExploEd.Current() ); | |
638 | if (AIS::ComputeGeometry(curedge, aCurve, ptfirst, ptend)) | |
639 | if(aCurve->IsInstance(STANDARD_TYPE(Geom_Circle)) && | |
640 | !Handle(Geom_Circle)::DownCast(aCurve).IsNull()) | |
641 | return Standard_True; | |
642 | } | |
643 | return Standard_False; | |
644 | } | |
645 | ||
646 | //======================================================================= | |
647 | //function : ComputeOnePlanarFaceDiameter | |
648 | //purpose : | |
649 | //======================================================================= | |
650 | ||
651 | void AIS_DiameterDimension::ComputeOnePlanarFaceDiameter(const Handle(Prs3d_Presentation)& aPresentation) | |
652 | { | |
653 | gp_Pnt curPos ; | |
654 | #ifndef DEB | |
655 | Standard_Real parfirst =0., parend =0.; | |
656 | #else | |
657 | Standard_Real parfirst, parend; | |
658 | #endif | |
659 | if (myAutomaticPosition) { | |
660 | Handle(Geom_Curve) curv; | |
661 | gp_Pnt ptfirst,ptend; | |
662 | ||
663 | if( !CircleFromPlanarFace( TopoDS::Face( myFShape ), curv, ptfirst, ptend) ) { | |
664 | Standard_ConstructionError::Raise("AIS:: Curve is not a circle or is Null") ; | |
665 | return; | |
666 | } | |
667 | ||
668 | myCircle = Handle(Geom_Circle)::DownCast(curv)->Circ(); | |
669 | if ( ptfirst.IsEqual(ptend, Precision::Confusion()) ) | |
670 | myIsAnArc = Standard_False; | |
671 | else | |
672 | myIsAnArc = Standard_True; | |
673 | myCircle.SetRadius(myVal/2.);// | |
674 | BRepAdaptor_Surface surfAlgo (TopoDS::Face(myFShape)); | |
675 | myPlane = new Geom_Plane(gp_Pln(gp_Ax3(myCircle.Position())));//gp_Circ | |
676 | gp_Pnt center = myCircle.Location(); | |
677 | Standard_Real rad = myCircle.Radius(); | |
678 | Standard_Real deport = rad * 1.2; | |
679 | if(! myIsAnArc ) { // Circle | |
680 | gp_Dir xdir = myCircle.XAxis().Direction(); | |
681 | curPos = center.Translated( gp_Vec(xdir)*deport ); | |
682 | } | |
683 | else { // Arc | |
684 | parfirst = ElCLib::Parameter(myCircle, ptfirst); | |
685 | parend = ElCLib::Parameter(myCircle, ptend); | |
686 | if ( parfirst > parend) { | |
c6541a0c | 687 | parfirst -= 2*M_PI; |
7fd59977 | 688 | } |
689 | Standard_Real parcurPos = (parfirst + parend) * 0.5; | |
690 | curPos = ElCLib::Value(parcurPos, myCircle); | |
691 | gp_Vec v1( center, curPos ); | |
692 | v1.Normalize(); | |
693 | curPos = center.Translated( v1 * deport ); | |
694 | } | |
695 | myFirstPar = parfirst; | |
696 | myLastPar = parend; | |
697 | myPosition = curPos; | |
698 | myAutomaticPosition = Standard_True; | |
699 | if ( myIsSetBndBox ) | |
700 | myPosition = AIS::TranslatePointToBound( myPosition, gp_Dir( gp_Vec( myCircle.Location(), | |
701 | myPosition ) ), myBndBox ); | |
702 | } else | |
703 | { | |
704 | // !myAutomaticPosition | |
705 | // Project point on the plane of face | |
706 | curPos = myPosition; | |
707 | curPos = AIS::ProjectPointOnPlane( curPos, myPlane->Pln() ); | |
708 | myPosition = curPos; | |
709 | } | |
710 | ||
711 | ||
712 | Handle(Prs3d_LengthAspect) la = myDrawer->LengthAspect(); | |
713 | Handle(Prs3d_ArrowAspect) arr = la->Arrow1Aspect(); | |
714 | ||
715 | // size | |
716 | #ifdef BUC60915 | |
717 | if( !myArrowSizeIsDefined ) { | |
718 | myArrowSize = Min(myArrowSize,myCircle.Radius()/5.); | |
719 | } | |
720 | arr->SetLength(myArrowSize); | |
721 | #else | |
722 | if (myCircle.Radius()/5. > myArrowSize) { | |
723 | arr->SetLength(myArrowSize); | |
724 | } | |
725 | else { | |
726 | arr->SetLength(myCircle.Radius()/5.); | |
727 | } | |
728 | #endif | |
729 | ||
730 | if(! myIsAnArc ) | |
731 | DsgPrs_DiameterPresentation::Add(aPresentation, myDrawer, myText, myPosition, | |
732 | myCircle, DsgPrs_AS_BOTHAR, myDiamSymbol); | |
733 | else | |
734 | DsgPrs_DiameterPresentation::Add(aPresentation, myDrawer, myText, myPosition, | |
735 | myCircle, myFirstPar, myLastPar, mySymbolPrs, myDiamSymbol ); | |
736 | } | |
737 |