1 // Created on: 1998-01-23
2 // Created by: Sergey ZARITCHNY
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
22 #define BUC60915 //GG 05/06/01 Enable to compute the requested arrow size
23 // if any in all dimensions.
25 #include <Standard_NotImplemented.hxx>
27 #include <AIS_MaxRadiusDimension.ixx>
28 #include <AIS_EllipseRadiusDimension.hxx>
29 #include <TCollection_ExtendedString.hxx>
31 #include <Prs3d_LengthAspect.hxx>
32 #include <Prs3d_ArrowAspect.hxx>
33 #include <Prs3d_Drawer.hxx>
34 #include <Prs3d_TextAspect.hxx>
35 #include <Prs3d_Text.hxx>
37 #include <Select3D_SensitiveSegment.hxx>
38 #include <Select3D_SensitiveCurve.hxx>
39 #include <Select3D_SensitiveBox.hxx>
40 #include <SelectMgr_EntityOwner.hxx>
47 #include <BRepAdaptor_Surface.hxx>
48 #include <BRepAdaptor_Curve.hxx>
50 #include <Geom_Ellipse.hxx>
51 #include <Geom_TrimmedCurve.hxx>
52 #include <Geom_Plane.hxx>
53 #include <Geom_Surface.hxx>
54 #include <Geom_CylindricalSurface.hxx>
55 #include <Geom_SurfaceOfRevolution.hxx>
56 #include <Geom_CylindricalSurface.hxx>
57 #include <Geom_SurfaceOfLinearExtrusion.hxx>
67 #include <AIS_Drawer.hxx>
69 #include <Precision.hxx>
70 #include <DsgPrs_EllipseRadiusPresentation.hxx>
72 //=======================================================================
73 //function : AIS_MaxRadiusDimension
75 //=======================================================================
77 AIS_MaxRadiusDimension::AIS_MaxRadiusDimension(const TopoDS_Shape& aShape,
78 const Standard_Real aVal,
79 const TCollection_ExtendedString& aText)
80 :AIS_EllipseRadiusDimension(aShape, aText)
83 mySymbolPrs = DsgPrs_AS_LASTAR;
84 myAutomaticPosition = Standard_True;
85 myArrowSize = myVal / 100.;
88 //=======================================================================
89 //function : AIS_MaxRadiusDimension
91 //=======================================================================
93 AIS_MaxRadiusDimension::AIS_MaxRadiusDimension(const TopoDS_Shape& aShape,
94 const Standard_Real aVal,
95 const TCollection_ExtendedString& aText,
96 const gp_Pnt& aPosition,
97 const DsgPrs_ArrowSide aSymbolPrs,
98 const Standard_Real anArrowSize)
99 :AIS_EllipseRadiusDimension(aShape, aText)
102 mySymbolPrs = aSymbolPrs;
103 myPosition = aPosition;
104 myAutomaticPosition = Standard_False;
106 SetArrowSize( anArrowSize );
108 myArrowSize = anArrowSize;
112 //=======================================================================
115 //=======================================================================
117 void AIS_MaxRadiusDimension::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
118 const Handle(Prs3d_Presentation)& aPresentation,
119 const Standard_Integer /*aMode*/)
121 aPresentation->Clear();
123 // if( myAutomaticPosition )
124 {//ota : recompute in any case
126 myEllipse.SetMajorRadius(myVal);
127 gp_Vec v1(myEllipse.XAxis().Direction());
129 myApexP = myEllipse.Location().Translated(v1);
130 myApexN = myEllipse.Location().Translated(-v1);
132 if(myIsAnArc) ComputeArcOfEllipse(aPresentation);
134 ComputeEllipse(aPresentation);
137 //=======================================================================
139 //purpose : to avoid warning
140 //=======================================================================
142 void AIS_MaxRadiusDimension::Compute(const Handle(Prs3d_Projector)& aProjector,
143 const Handle(Prs3d_Presentation)& aPresentation)
145 // Standard_NotImplemented::Raise("AIS_MaxRadiusDimension::Compute(const Handle(Prs3d_Projector)& aProjector, const Handle(Prs3d_Presentation)& aPresentation)");
146 PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
149 //=======================================================================
151 //purpose : to avoid warning
152 //=======================================================================
154 void AIS_MaxRadiusDimension::Compute(const Handle(PrsMgr_PresentationManager2d)& aPresentationManager,
155 const Handle(Graphic2d_GraphicObject)& aPresentation,
156 const Standard_Integer aMode)
158 // Standard_NotImplemented::Raise("AIS_MaxRadiusDimension::Compute(const Handle(PrsMgr_PresentationManager2d)& aPresentationManager, const Handle(Graphic2d_GraphicObject)& aPresentation, const Standard_Integer aMode)");
159 PrsMgr_PresentableObject::Compute( aPresentationManager ,aPresentation,aMode) ;
162 //=======================================================================
165 //=======================================================================
167 void AIS_MaxRadiusDimension::Compute(const Handle_Prs3d_Projector& aProjector,
168 const Handle_Geom_Transformation& aTransformation,
169 const Handle_Prs3d_Presentation& aPresentation)
171 // Standard_NotImplemented::Raise("AIS_MaxRadiusDimension::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
172 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
176 //=======================================================================
177 //function : ComputeEllipse
179 //=======================================================================
181 void AIS_MaxRadiusDimension::ComputeEllipse(const Handle(Prs3d_Presentation)& aPresentation)
184 Handle(Prs3d_LengthAspect) la = myDrawer->LengthAspect();
185 Handle(Prs3d_ArrowAspect) arr = la->Arrow1Aspect();
189 if( !myArrowSizeIsDefined ) {
190 myArrowSize = Min(myArrowSize,myVal / 5.);
192 arr->SetLength(myArrowSize);
194 if (myVal / 5. > myArrowSize) {
195 arr->SetLength(myArrowSize);
198 arr->SetLength(myVal / 5.);
202 Standard_Real U;//,V;
203 gp_Pnt curPos, Center;
204 Center = myEllipse.Location();
205 if( myAutomaticPosition )
208 myEndOfArrow = myApexP;
209 myAutomaticPosition = Standard_True;
212 myPosition = AIS::TranslatePointToBound(myPosition, gp_Dir(gp_Vec( Center, myPosition )),
216 else //!AutomaticPosition
219 gp_Lin L1(myEllipse.XAxis());
220 U = ElCLib::Parameter ( L1, curPos );
221 curPos = ElCLib::Value (U, L1);
222 if (curPos.Distance(myApexP) < curPos.Distance(myApexN))
223 myEndOfArrow = myApexP ;
225 myEndOfArrow = myApexN ;
229 DsgPrs_EllipseRadiusPresentation::Add(aPresentation, myDrawer, myVal, myText, curPos,
230 myEndOfArrow, Center, Standard_True, mySymbolPrs);
234 //=======================================================================
235 //function : ComputeArcOfEllipse
237 //=======================================================================
239 void AIS_MaxRadiusDimension::ComputeArcOfEllipse(const Handle(Prs3d_Presentation)& aPresentation)
242 Handle(Prs3d_LengthAspect) la = myDrawer->LengthAspect();
243 Handle(Prs3d_ArrowAspect) arr = la->Arrow1Aspect();
247 if( !myArrowSizeIsDefined ) {
248 myArrowSize = Min(myArrowSize,myVal / 5.);
250 arr->SetLength(myArrowSize);
252 if (myVal / 5. > myArrowSize) {
253 arr->SetLength(myArrowSize);
256 arr->SetLength(myVal / 5.);
261 gp_Pnt curPos, Center;
262 Center = myEllipse.Location();
263 Standard_Boolean IsInDomain = Standard_True;
264 if( myAutomaticPosition )
266 myEndOfArrow = AIS::NearestApex(myEllipse, myApexP, myApexN,
267 myFirstPar, myLastPar, IsInDomain);
269 myAutomaticPosition = Standard_True;
271 myPosition = AIS::TranslatePointToBound(myPosition, gp_Dir(gp_Vec( Center, myPosition )),
275 else //!AutomaticPosition
278 // ElSLib::Parameters ( myPlane->Pln(), curPos, U, V );
279 // curPos = ElSLib::Value (U, V, myPlane->Pln());
280 gp_Lin L1(myEllipse.XAxis());
281 par = ElCLib::Parameter ( L1, curPos );
282 curPos = ElCLib::Value (par, L1);
283 if (curPos.Distance(myApexP) < curPos.Distance(myApexN))
284 myEndOfArrow = myApexP ;
286 myEndOfArrow = myApexN ;
287 par = ElCLib::Parameter ( myEllipse, myEndOfArrow );
288 IsInDomain = AIS::InDomain( myFirstPar, myLastPar, par );
292 // Standard_Real parEnd = ElCLib::Parameter ( myEllipse, myEndOfArrow );
293 Standard_Real parStart = 0.;
296 if(AIS::DistanceFromApex (myEllipse, myEndOfArrow, myFirstPar) <
297 AIS::DistanceFromApex (myEllipse, myEndOfArrow, myLastPar))
298 parStart = myFirstPar;
300 parStart = myLastPar;
303 DsgPrs_EllipseRadiusPresentation::Add(aPresentation, myDrawer, myVal, myText, myEllipse,
304 curPos, myEndOfArrow, Center, parStart, IsInDomain,
305 Standard_True, mySymbolPrs);
307 DsgPrs_EllipseRadiusPresentation::Add(aPresentation, myDrawer, myVal, myText, myOffsetCurve,
308 curPos, myEndOfArrow, Center, parStart, IsInDomain,
309 Standard_True, mySymbolPrs);
312 //=======================================================================
313 //function : ComputeSelection
315 //=======================================================================
317 void AIS_MaxRadiusDimension::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
318 const Standard_Integer /*aMode*/)
321 gp_Pnt center = myEllipse.Location();
322 gp_Pnt AttachmentPoint = myPosition;
323 Standard_Real dist = center.Distance(AttachmentPoint);
324 Standard_Real aRadius = myVal;
325 //Standard_Real inside = Standard_False;
327 if (dist > aRadius) pt1 = AttachmentPoint;
330 Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
331 Handle(Select3D_SensitiveSegment)
332 seg = new Select3D_SensitiveSegment(own, center , pt1);
333 aSelection->Add(seg);
336 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
337 Handle( Select3D_SensitiveBox ) box = new Select3D_SensitiveBox( own,
341 AttachmentPoint.X()+size,
342 AttachmentPoint.Y()+size,
343 AttachmentPoint.Z()+size);
344 aSelection->Add(box);
350 Standard_Real parEnd = ElCLib::Parameter ( myEllipse, myEndOfArrow );
351 if(!AIS::InDomain(myFirstPar, myLastPar, parEnd))
353 Standard_Real parStart, par;
354 if(AIS::DistanceFromApex (myEllipse, myEndOfArrow, myFirstPar) <
355 AIS::DistanceFromApex (myEllipse, myEndOfArrow, myLastPar))
359 gp_Vec Vapex(center, ElCLib::Value( parEnd, myEllipse )) ;
360 gp_Vec Vpnt (center, ElCLib::Value( par, myEllipse )) ;
361 gp_Dir dir(Vpnt ^ Vapex);
362 if(myEllipse.Position().Direction().IsOpposite( dir, Precision::Angular())) {
369 Handle(Geom_TrimmedCurve)TrimCurve;
372 Handle(Geom_Curve) aCurve = myOffsetCurve;
373 TrimCurve = new Geom_TrimmedCurve( aCurve, parStart, parEnd );
377 Handle(Geom_Ellipse) Ellipse = new Geom_Ellipse( myEllipse );
378 TrimCurve = new Geom_TrimmedCurve( Ellipse, parStart, parEnd );
380 Handle( Select3D_SensitiveCurve ) SensArc;
381 SensArc = new Select3D_SensitiveCurve( own, TrimCurve );
382 aSelection->Add( SensArc );