1 // Created on: 1998-01-27
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_MinRadiusDimension.ixx>
29 #include <AIS_EllipseRadiusDimension.hxx>
30 #include <TCollection_ExtendedString.hxx>
32 #include <Prs3d_LengthAspect.hxx>
33 #include <Prs3d_ArrowAspect.hxx>
34 #include <Prs3d_Drawer.hxx>
35 #include <Prs3d_TextAspect.hxx>
36 #include <Prs3d_Text.hxx>
38 #include <Select3D_SensitiveSegment.hxx>
39 #include <Select3D_SensitiveCurve.hxx>
40 #include <Select3D_SensitiveBox.hxx>
41 #include <SelectMgr_EntityOwner.hxx>
48 #include <BRepAdaptor_Surface.hxx>
49 #include <BRepAdaptor_Curve.hxx>
51 #include <Geom_Ellipse.hxx>
52 #include <Geom_TrimmedCurve.hxx>
53 #include <Geom_Plane.hxx>
54 #include <Geom_Surface.hxx>
55 #include <Geom_CylindricalSurface.hxx>
56 #include <Geom_SurfaceOfRevolution.hxx>
57 #include <Geom_CylindricalSurface.hxx>
58 #include <Geom_SurfaceOfLinearExtrusion.hxx>
68 #include <AIS_Drawer.hxx>
70 #include <Precision.hxx>
71 #include <DsgPrs_EllipseRadiusPresentation.hxx>
74 //=======================================================================
75 //function : AIS_MinRadiusDimension
77 //=======================================================================
79 AIS_MinRadiusDimension::AIS_MinRadiusDimension(const TopoDS_Shape& aShape,
80 const Standard_Real aVal,
81 const TCollection_ExtendedString& aText)
82 :AIS_EllipseRadiusDimension(aShape, aText)
85 mySymbolPrs = DsgPrs_AS_LASTAR;
86 myAutomaticPosition = Standard_True;
87 myArrowSize = myVal / 100.;
90 //=======================================================================
91 //function : AIS_MinRadiusDimension
93 //=======================================================================
95 AIS_MinRadiusDimension::AIS_MinRadiusDimension(const TopoDS_Shape& aShape,
96 const Standard_Real aVal,
97 const TCollection_ExtendedString& aText,
98 const gp_Pnt& aPosition,
99 const DsgPrs_ArrowSide aSymbolPrs,
100 const Standard_Real anArrowSize)
101 :AIS_EllipseRadiusDimension(aShape, aText)
104 mySymbolPrs = aSymbolPrs;
105 myPosition = aPosition;
106 myAutomaticPosition = Standard_False;
108 SetArrowSize( anArrowSize );
110 myArrowSize = anArrowSize;
114 //=======================================================================
117 //=======================================================================
119 void AIS_MinRadiusDimension::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
120 const Handle(Prs3d_Presentation)& aPresentation,
121 const Standard_Integer /*aMode*/)
123 aPresentation->Clear();
125 // if( myAutomaticPosition )
126 //{ //ota : recompute ellipse always
128 myEllipse.SetMinorRadius(myVal);
129 gp_Vec v1(myEllipse.YAxis().Direction());
131 myApexP = myEllipse.Location().Translated(v1);
132 myApexN = myEllipse.Location().Translated(-v1);
134 if(myIsAnArc) ComputeArcOfEllipse(aPresentation);
136 ComputeEllipse(aPresentation);
139 //=======================================================================
141 //purpose : to avoid warning
142 //=======================================================================
144 void AIS_MinRadiusDimension::Compute(const Handle(Prs3d_Projector)& aProjector,
145 const Handle(Prs3d_Presentation)& aPresentation)
147 // Standard_NotImplemented::Raise("AIS_MinRadiusDimension::Compute(const Handle(Prs3d_Projector)& aProjector, const Handle(Prs3d_Presentation)& aPresentation)");
148 PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
151 //=======================================================================
154 //=======================================================================
156 void AIS_MinRadiusDimension::Compute(const Handle_Prs3d_Projector& aProjector,
157 const Handle_Geom_Transformation& aTransformation,
158 const Handle_Prs3d_Presentation& aPresentation)
160 // Standard_NotImplemented::Raise("AIS_MinRadiusDimension::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
161 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
164 //=======================================================================
165 //function : ComputeEllipse
167 //=======================================================================
169 void AIS_MinRadiusDimension::ComputeEllipse(const Handle(Prs3d_Presentation)& aPresentation)
172 Handle(Prs3d_LengthAspect) la = myDrawer->LengthAspect();
173 Handle(Prs3d_ArrowAspect) arr = la->Arrow1Aspect();
177 if( !myArrowSizeIsDefined ) {
178 myArrowSize = Min(myArrowSize,myVal/5.);
180 arr->SetLength(myArrowSize);
182 if (myVal/5. > myArrowSize) {
183 arr->SetLength(myArrowSize);
186 arr->SetLength(myVal/5.);
190 Standard_Real U;//,V;
191 gp_Pnt curPos, Center;
192 Center = myEllipse.Location();
193 if( myAutomaticPosition )
196 myEndOfArrow = myApexP;
197 myAutomaticPosition = Standard_True;
200 myPosition = AIS::TranslatePointToBound(myPosition, gp_Dir(gp_Vec( Center, myPosition )),
204 else //!AutomaticPosition
207 gp_Lin L1(myEllipse.YAxis());
208 U = ElCLib::Parameter ( L1, curPos );
209 curPos = ElCLib::Value (U, L1);
210 if (curPos.Distance(myApexP) < curPos.Distance(myApexN))
211 myEndOfArrow = myApexP ;
213 myEndOfArrow = myApexN ;
218 DsgPrs_EllipseRadiusPresentation::Add(aPresentation, myDrawer, myVal, myText, curPos,
219 myEndOfArrow, Center, Standard_False, mySymbolPrs);
223 //=======================================================================
224 //function : ComputeArcOfEllipse
226 //=======================================================================
228 void AIS_MinRadiusDimension::ComputeArcOfEllipse(const Handle(Prs3d_Presentation)& aPresentation)
231 Handle(Prs3d_LengthAspect) la = myDrawer->LengthAspect();
232 Handle(Prs3d_ArrowAspect) arr = la->Arrow1Aspect();
236 if( !myArrowSizeIsDefined ) {
237 myArrowSize = Min(myArrowSize,myVal/5.);
239 arr->SetLength(myArrowSize);
241 if (myVal/5. > myArrowSize) {
242 arr->SetLength(myArrowSize);
245 arr->SetLength(myVal/5.);
250 gp_Pnt curPos, Center;
251 Center = myEllipse.Location();
252 Standard_Boolean IsInDomain = Standard_True;
253 if( myAutomaticPosition )
255 myEndOfArrow = AIS::NearestApex(myEllipse, myApexP, myApexN,
256 myFirstPar, myLastPar, IsInDomain);
258 myAutomaticPosition = Standard_True;
260 myPosition = AIS::TranslatePointToBound(myPosition, gp_Dir(gp_Vec( Center, myPosition )),
265 else //!AutomaticPosition
268 gp_Lin L1(myEllipse.YAxis());
269 par = ElCLib::Parameter ( L1, curPos );
270 curPos = ElCLib::Value (par, L1);
271 if (curPos.Distance(myApexP) < curPos.Distance(myApexN))
272 myEndOfArrow = myApexP ;
274 myEndOfArrow = myApexN ;
275 par = ElCLib::Parameter ( myEllipse, myEndOfArrow );
276 IsInDomain = AIS::InDomain(myFirstPar, myLastPar, par);
280 Standard_Real parStart =0.;
283 if(AIS::DistanceFromApex (myEllipse, myEndOfArrow, myFirstPar) <
284 AIS::DistanceFromApex (myEllipse, myEndOfArrow, myLastPar))
285 parStart = myFirstPar;
287 parStart = myLastPar;
292 DsgPrs_EllipseRadiusPresentation::Add(aPresentation, myDrawer, myVal, myText, myEllipse,
293 curPos, myEndOfArrow, Center, parStart, IsInDomain,
294 Standard_True, mySymbolPrs);
296 DsgPrs_EllipseRadiusPresentation::Add(aPresentation, myDrawer, myVal, myText, myOffsetCurve,
297 curPos, myEndOfArrow, Center, parStart, IsInDomain,
298 Standard_True, mySymbolPrs);
302 //=======================================================================
303 //function : ComputeSelection
305 //=======================================================================
307 void AIS_MinRadiusDimension::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
308 const Standard_Integer /*aMode*/)
311 gp_Pnt center = myEllipse.Location();
312 gp_Pnt AttachmentPoint = myPosition;
313 Standard_Real dist = center.Distance(AttachmentPoint);
314 Standard_Real aRadius = myVal;
315 //Standard_Real inside = Standard_False;
317 if (dist > aRadius) pt1 = AttachmentPoint;
320 Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
321 Handle(Select3D_SensitiveSegment)
322 seg = new Select3D_SensitiveSegment(own, center , pt1);
323 aSelection->Add(seg);
326 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
327 Handle( Select3D_SensitiveBox ) box = new Select3D_SensitiveBox( own,
331 AttachmentPoint.X()+size,
332 AttachmentPoint.Y()+size,
333 AttachmentPoint.Z()+size);
334 aSelection->Add(box);
340 Standard_Real parEnd = ElCLib::Parameter ( myEllipse, myEndOfArrow );
341 if(!AIS::InDomain(myFirstPar, myLastPar, parEnd))
343 Standard_Real parStart, par;
344 if(AIS::DistanceFromApex (myEllipse, myEndOfArrow, myFirstPar) <
345 AIS::DistanceFromApex (myEllipse, myEndOfArrow, myLastPar))
349 gp_Vec Vapex(center, ElCLib::Value( parEnd, myEllipse )) ;
350 gp_Vec Vpnt (center, ElCLib::Value( par, myEllipse )) ;
351 gp_Dir dir(Vpnt ^ Vapex);
352 if(myEllipse.Position().Direction().IsOpposite( dir, Precision::Angular())) {
358 Handle(Geom_TrimmedCurve)TrimCurve;
361 Handle(Geom_Curve) aCurve = myOffsetCurve;
362 TrimCurve = new Geom_TrimmedCurve( aCurve, parStart, parEnd );
366 Handle(Geom_Ellipse) Ellipse = new Geom_Ellipse( myEllipse );
367 TrimCurve = new Geom_TrimmedCurve( Ellipse, parStart, parEnd );
369 Handle( Select3D_SensitiveCurve ) SensArc;
370 SensArc = new Select3D_SensitiveCurve( own, TrimCurve );
371 aSelection->Add( SensArc );