1 // Created on: 1998-01-23
2 // Created by: Sergey ZARITCHNY
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #define BUC60915 //GG 05/06/01 Enable to compute the requested arrow size
18 // if any in all dimensions.
20 #include <Standard_NotImplemented.hxx>
22 #include <AIS_MaxRadiusDimension.ixx>
23 #include <AIS_EllipseRadiusDimension.hxx>
24 #include <TCollection_ExtendedString.hxx>
26 #include <Prs3d_DimensionAspect.hxx>
27 #include <Prs3d_ArrowAspect.hxx>
28 #include <Prs3d_Drawer.hxx>
29 #include <Prs3d_TextAspect.hxx>
30 #include <Prs3d_Text.hxx>
32 #include <Select3D_SensitiveSegment.hxx>
33 #include <Select3D_SensitiveCurve.hxx>
34 #include <Select3D_SensitiveBox.hxx>
35 #include <SelectMgr_EntityOwner.hxx>
42 #include <BRepAdaptor_Surface.hxx>
43 #include <BRepAdaptor_Curve.hxx>
45 #include <Geom_Ellipse.hxx>
46 #include <Geom_TrimmedCurve.hxx>
47 #include <Geom_Plane.hxx>
48 #include <Geom_Surface.hxx>
49 #include <Geom_CylindricalSurface.hxx>
50 #include <Geom_SurfaceOfRevolution.hxx>
51 #include <Geom_CylindricalSurface.hxx>
52 #include <Geom_SurfaceOfLinearExtrusion.hxx>
62 #include <AIS_Drawer.hxx>
64 #include <Precision.hxx>
65 #include <DsgPrs_EllipseRadiusPresentation.hxx>
67 //=======================================================================
68 //function : AIS_MaxRadiusDimension
70 //=======================================================================
72 AIS_MaxRadiusDimension::AIS_MaxRadiusDimension(const TopoDS_Shape& aShape,
73 const Standard_Real aVal,
74 const TCollection_ExtendedString& aText)
75 :AIS_EllipseRadiusDimension(aShape, aText)
78 mySymbolPrs = DsgPrs_AS_LASTAR;
79 myAutomaticPosition = Standard_True;
80 myArrowSize = myVal / 100.;
83 //=======================================================================
84 //function : AIS_MaxRadiusDimension
86 //=======================================================================
88 AIS_MaxRadiusDimension::AIS_MaxRadiusDimension(const TopoDS_Shape& aShape,
89 const Standard_Real aVal,
90 const TCollection_ExtendedString& aText,
91 const gp_Pnt& aPosition,
92 const DsgPrs_ArrowSide aSymbolPrs,
93 const Standard_Real anArrowSize)
94 :AIS_EllipseRadiusDimension(aShape, aText)
97 mySymbolPrs = aSymbolPrs;
98 myPosition = aPosition;
99 myAutomaticPosition = Standard_False;
101 SetArrowSize( anArrowSize );
103 myArrowSize = anArrowSize;
107 //=======================================================================
110 //=======================================================================
112 void AIS_MaxRadiusDimension::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
113 const Handle(Prs3d_Presentation)& aPresentation,
114 const Standard_Integer /*aMode*/)
116 aPresentation->Clear();
118 // if( myAutomaticPosition )
119 {//ota : recompute in any case
121 myEllipse.SetMajorRadius(myVal);
122 gp_Vec v1(myEllipse.XAxis().Direction());
124 myApexP = myEllipse.Location().Translated(v1);
125 myApexN = myEllipse.Location().Translated(-v1);
127 if(myIsAnArc) ComputeArcOfEllipse(aPresentation);
129 ComputeEllipse(aPresentation);
132 //=======================================================================
134 //purpose : to avoid warning
135 //=======================================================================
137 void AIS_MaxRadiusDimension::Compute(const Handle(Prs3d_Projector)& aProjector,
138 const Handle(Prs3d_Presentation)& aPresentation)
140 // Standard_NotImplemented::Raise("AIS_MaxRadiusDimension::Compute(const Handle(Prs3d_Projector)& aProjector, const Handle(Prs3d_Presentation)& aPresentation)");
141 PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
144 //=======================================================================
147 //=======================================================================
149 void AIS_MaxRadiusDimension::Compute(const Handle(Prs3d_Projector)& aProjector,
150 const Handle(Geom_Transformation)& aTransformation,
151 const Handle(Prs3d_Presentation)& aPresentation)
153 // Standard_NotImplemented::Raise("AIS_MaxRadiusDimension::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)");
154 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
158 //=======================================================================
159 //function : ComputeEllipse
161 //=======================================================================
163 void AIS_MaxRadiusDimension::ComputeEllipse(const Handle(Prs3d_Presentation)& aPresentation)
166 Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect();
167 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
171 if( !myArrowSizeIsDefined ) {
172 myArrowSize = Min(myArrowSize,myVal / 5.);
174 arr->SetLength(myArrowSize);
176 if (myVal / 5. > myArrowSize) {
177 arr->SetLength(myArrowSize);
180 arr->SetLength(myVal / 5.);
184 Standard_Real U;//,V;
185 gp_Pnt curPos, Center;
186 Center = myEllipse.Location();
187 if( myAutomaticPosition )
190 myEndOfArrow = myApexP;
191 myAutomaticPosition = Standard_True;
194 myPosition = AIS::TranslatePointToBound(myPosition, gp_Dir(gp_Vec( Center, myPosition )),
198 else //!AutomaticPosition
201 gp_Lin L1(myEllipse.XAxis());
202 U = ElCLib::Parameter ( L1, curPos );
203 curPos = ElCLib::Value (U, L1);
204 if (curPos.Distance(myApexP) < curPos.Distance(myApexN))
205 myEndOfArrow = myApexP ;
207 myEndOfArrow = myApexN ;
211 DsgPrs_EllipseRadiusPresentation::Add(aPresentation, myDrawer, myVal, myText, curPos,
212 myEndOfArrow, Center, Standard_True, mySymbolPrs);
216 //=======================================================================
217 //function : ComputeArcOfEllipse
219 //=======================================================================
221 void AIS_MaxRadiusDimension::ComputeArcOfEllipse(const Handle(Prs3d_Presentation)& aPresentation)
224 Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect();
225 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
229 if( !myArrowSizeIsDefined ) {
230 myArrowSize = Min(myArrowSize,myVal / 5.);
232 arr->SetLength(myArrowSize);
234 if (myVal / 5. > myArrowSize) {
235 arr->SetLength(myArrowSize);
238 arr->SetLength(myVal / 5.);
243 gp_Pnt curPos, Center;
244 Center = myEllipse.Location();
245 Standard_Boolean IsInDomain = Standard_True;
246 if( myAutomaticPosition )
248 myEndOfArrow = AIS::NearestApex(myEllipse, myApexP, myApexN,
249 myFirstPar, myLastPar, IsInDomain);
251 myAutomaticPosition = Standard_True;
253 myPosition = AIS::TranslatePointToBound(myPosition, gp_Dir(gp_Vec( Center, myPosition )),
257 else //!AutomaticPosition
260 // ElSLib::Parameters ( myPlane->Pln(), curPos, U, V );
261 // curPos = ElSLib::Value (U, V, myPlane->Pln());
262 gp_Lin L1(myEllipse.XAxis());
263 par = ElCLib::Parameter ( L1, curPos );
264 curPos = ElCLib::Value (par, L1);
265 if (curPos.Distance(myApexP) < curPos.Distance(myApexN))
266 myEndOfArrow = myApexP ;
268 myEndOfArrow = myApexN ;
269 par = ElCLib::Parameter ( myEllipse, myEndOfArrow );
270 IsInDomain = AIS::InDomain( myFirstPar, myLastPar, par );
274 // Standard_Real parEnd = ElCLib::Parameter ( myEllipse, myEndOfArrow );
275 Standard_Real parStart = 0.;
278 if(AIS::DistanceFromApex (myEllipse, myEndOfArrow, myFirstPar) <
279 AIS::DistanceFromApex (myEllipse, myEndOfArrow, myLastPar))
280 parStart = myFirstPar;
282 parStart = myLastPar;
285 DsgPrs_EllipseRadiusPresentation::Add(aPresentation, myDrawer, myVal, myText, myEllipse,
286 curPos, myEndOfArrow, Center, parStart, IsInDomain,
287 Standard_True, mySymbolPrs);
289 DsgPrs_EllipseRadiusPresentation::Add(aPresentation, myDrawer, myVal, myText, myOffsetCurve,
290 curPos, myEndOfArrow, Center, parStart, IsInDomain,
291 Standard_True, mySymbolPrs);
294 //=======================================================================
295 //function : ComputeSelection
297 //=======================================================================
299 void AIS_MaxRadiusDimension::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
300 const Standard_Integer /*aMode*/)
303 gp_Pnt center = myEllipse.Location();
304 gp_Pnt AttachmentPoint = myPosition;
305 Standard_Real dist = center.Distance(AttachmentPoint);
306 Standard_Real aRadius = myVal;
307 //Standard_Real inside = Standard_False;
309 if (dist > aRadius) pt1 = AttachmentPoint;
312 Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
313 Handle(Select3D_SensitiveSegment)
314 seg = new Select3D_SensitiveSegment(own, center , pt1);
315 aSelection->Add(seg);
318 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
319 Handle( Select3D_SensitiveBox ) box = new Select3D_SensitiveBox( own,
323 AttachmentPoint.X()+size,
324 AttachmentPoint.Y()+size,
325 AttachmentPoint.Z()+size);
326 aSelection->Add(box);
332 Standard_Real parEnd = ElCLib::Parameter ( myEllipse, myEndOfArrow );
333 if(!AIS::InDomain(myFirstPar, myLastPar, parEnd))
335 Standard_Real parStart, par;
336 if(AIS::DistanceFromApex (myEllipse, myEndOfArrow, myFirstPar) <
337 AIS::DistanceFromApex (myEllipse, myEndOfArrow, myLastPar))
341 gp_Vec Vapex(center, ElCLib::Value( parEnd, myEllipse )) ;
342 gp_Vec Vpnt (center, ElCLib::Value( par, myEllipse )) ;
343 gp_Dir dir(Vpnt ^ Vapex);
344 if(myEllipse.Position().Direction().IsOpposite( dir, Precision::Angular())) {
351 Handle(Geom_TrimmedCurve)TrimCurve;
354 Handle(Geom_Curve) aCurve = myOffsetCurve;
355 TrimCurve = new Geom_TrimmedCurve( aCurve, parStart, parEnd );
359 Handle(Geom_Ellipse) Ellipse = new Geom_Ellipse( myEllipse );
360 TrimCurve = new Geom_TrimmedCurve( Ellipse, parStart, parEnd );
362 Handle( Select3D_SensitiveCurve ) SensArc;
363 SensArc = new Select3D_SensitiveCurve( own, TrimCurve );
364 aSelection->Add( SensArc );