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 //=======================================================================
153 //purpose : to avoid warning
154 //=======================================================================
156 void AIS_MinRadiusDimension::Compute(const Handle(PrsMgr_PresentationManager2d)& aPresentationManager,
157 const Handle(Graphic2d_GraphicObject)& aPresentation,
158 const Standard_Integer aMode)
160 // Standard_NotImplemented::Raise("AIS_MinRadiusDimension::Compute(const Handle(PrsMgr_PresentationManager2d)& aPresentationManager, const Handle(Graphic2d_GraphicObject)& aPresentation, const Standard_Integer aMode)");
161 PrsMgr_PresentableObject::Compute( aPresentationManager ,aPresentation,aMode) ;
164 //=======================================================================
167 //=======================================================================
169 void AIS_MinRadiusDimension::Compute(const Handle_Prs3d_Projector& aProjector,
170 const Handle_Geom_Transformation& aTransformation,
171 const Handle_Prs3d_Presentation& aPresentation)
173 // Standard_NotImplemented::Raise("AIS_MinRadiusDimension::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
174 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
177 //=======================================================================
178 //function : ComputeEllipse
180 //=======================================================================
182 void AIS_MinRadiusDimension::ComputeEllipse(const Handle(Prs3d_Presentation)& aPresentation)
185 Handle(Prs3d_LengthAspect) la = myDrawer->LengthAspect();
186 Handle(Prs3d_ArrowAspect) arr = la->Arrow1Aspect();
190 if( !myArrowSizeIsDefined ) {
191 myArrowSize = Min(myArrowSize,myVal/5.);
193 arr->SetLength(myArrowSize);
195 if (myVal/5. > myArrowSize) {
196 arr->SetLength(myArrowSize);
199 arr->SetLength(myVal/5.);
203 Standard_Real U;//,V;
204 gp_Pnt curPos, Center;
205 Center = myEllipse.Location();
206 if( myAutomaticPosition )
209 myEndOfArrow = myApexP;
210 myAutomaticPosition = Standard_True;
213 myPosition = AIS::TranslatePointToBound(myPosition, gp_Dir(gp_Vec( Center, myPosition )),
217 else //!AutomaticPosition
220 gp_Lin L1(myEllipse.YAxis());
221 U = ElCLib::Parameter ( L1, curPos );
222 curPos = ElCLib::Value (U, L1);
223 if (curPos.Distance(myApexP) < curPos.Distance(myApexN))
224 myEndOfArrow = myApexP ;
226 myEndOfArrow = myApexN ;
231 DsgPrs_EllipseRadiusPresentation::Add(aPresentation, myDrawer, myVal, myText, curPos,
232 myEndOfArrow, Center, Standard_False, mySymbolPrs);
236 //=======================================================================
237 //function : ComputeArcOfEllipse
239 //=======================================================================
241 void AIS_MinRadiusDimension::ComputeArcOfEllipse(const Handle(Prs3d_Presentation)& aPresentation)
244 Handle(Prs3d_LengthAspect) la = myDrawer->LengthAspect();
245 Handle(Prs3d_ArrowAspect) arr = la->Arrow1Aspect();
249 if( !myArrowSizeIsDefined ) {
250 myArrowSize = Min(myArrowSize,myVal/5.);
252 arr->SetLength(myArrowSize);
254 if (myVal/5. > myArrowSize) {
255 arr->SetLength(myArrowSize);
258 arr->SetLength(myVal/5.);
263 gp_Pnt curPos, Center;
264 Center = myEllipse.Location();
265 Standard_Boolean IsInDomain = Standard_True;
266 if( myAutomaticPosition )
268 myEndOfArrow = AIS::NearestApex(myEllipse, myApexP, myApexN,
269 myFirstPar, myLastPar, IsInDomain);
271 myAutomaticPosition = Standard_True;
273 myPosition = AIS::TranslatePointToBound(myPosition, gp_Dir(gp_Vec( Center, myPosition )),
278 else //!AutomaticPosition
281 gp_Lin L1(myEllipse.YAxis());
282 par = ElCLib::Parameter ( L1, curPos );
283 curPos = ElCLib::Value (par, L1);
284 if (curPos.Distance(myApexP) < curPos.Distance(myApexN))
285 myEndOfArrow = myApexP ;
287 myEndOfArrow = myApexN ;
288 par = ElCLib::Parameter ( myEllipse, myEndOfArrow );
289 IsInDomain = AIS::InDomain(myFirstPar, myLastPar, par);
293 Standard_Real parStart =0.;
296 if(AIS::DistanceFromApex (myEllipse, myEndOfArrow, myFirstPar) <
297 AIS::DistanceFromApex (myEllipse, myEndOfArrow, myLastPar))
298 parStart = myFirstPar;
300 parStart = myLastPar;
305 DsgPrs_EllipseRadiusPresentation::Add(aPresentation, myDrawer, myVal, myText, myEllipse,
306 curPos, myEndOfArrow, Center, parStart, IsInDomain,
307 Standard_True, mySymbolPrs);
309 DsgPrs_EllipseRadiusPresentation::Add(aPresentation, myDrawer, myVal, myText, myOffsetCurve,
310 curPos, myEndOfArrow, Center, parStart, IsInDomain,
311 Standard_True, mySymbolPrs);
315 //=======================================================================
316 //function : ComputeSelection
318 //=======================================================================
320 void AIS_MinRadiusDimension::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
321 const Standard_Integer /*aMode*/)
324 gp_Pnt center = myEllipse.Location();
325 gp_Pnt AttachmentPoint = myPosition;
326 Standard_Real dist = center.Distance(AttachmentPoint);
327 Standard_Real aRadius = myVal;
328 //Standard_Real inside = Standard_False;
330 if (dist > aRadius) pt1 = AttachmentPoint;
333 Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
334 Handle(Select3D_SensitiveSegment)
335 seg = new Select3D_SensitiveSegment(own, center , pt1);
336 aSelection->Add(seg);
339 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
340 Handle( Select3D_SensitiveBox ) box = new Select3D_SensitiveBox( own,
344 AttachmentPoint.X()+size,
345 AttachmentPoint.Y()+size,
346 AttachmentPoint.Z()+size);
347 aSelection->Add(box);
353 Standard_Real parEnd = ElCLib::Parameter ( myEllipse, myEndOfArrow );
354 if(!AIS::InDomain(myFirstPar, myLastPar, parEnd))
356 Standard_Real parStart, par;
357 if(AIS::DistanceFromApex (myEllipse, myEndOfArrow, myFirstPar) <
358 AIS::DistanceFromApex (myEllipse, myEndOfArrow, myLastPar))
362 gp_Vec Vapex(center, ElCLib::Value( parEnd, myEllipse )) ;
363 gp_Vec Vpnt (center, ElCLib::Value( par, myEllipse )) ;
364 gp_Dir dir(Vpnt ^ Vapex);
365 if(myEllipse.Position().Direction().IsOpposite( dir, Precision::Angular())) {
371 Handle(Geom_TrimmedCurve)TrimCurve;
374 Handle(Geom_Curve) aCurve = myOffsetCurve;
375 TrimCurve = new Geom_TrimmedCurve( aCurve, parStart, parEnd );
379 Handle(Geom_Ellipse) Ellipse = new Geom_Ellipse( myEllipse );
380 TrimCurve = new Geom_TrimmedCurve( Ellipse, parStart, parEnd );
382 Handle( Select3D_SensitiveCurve ) SensArc;
383 SensArc = new Select3D_SensitiveCurve( own, TrimCurve );
384 aSelection->Add( SensArc );