1 // Created on: 1998-01-20
2 // Created by: Julia GERASIMOVA
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 #include <Standard_NotImplemented.hxx>
19 #include <AIS_EqualRadiusRelation.ixx>
22 #include <DsgPrs_EqualRadiusPresentation.hxx>
23 #include <BRepAdaptor_Curve.hxx>
25 #include <gp_Circ.hxx>
26 #include <Geom_Circle.hxx>
28 #include <SelectMgr_EntityOwner.hxx>
29 #include <Select3D_SensitiveSegment.hxx>
30 #include <Select3D_SensitiveBox.hxx>
31 #include <Precision.hxx>
32 #include <GeomAPI_ProjectPointOnSurf.hxx>
33 #include <Prs3d_DimensionAspect.hxx>
34 #include <Prs3d_ArrowAspect.hxx>
35 #include <Prs3d_Drawer.hxx>
37 //=======================================================================
38 //function : AIS_EqualRadiusRelation
40 //=======================================================================
42 AIS_EqualRadiusRelation::AIS_EqualRadiusRelation( const TopoDS_Edge& aFirstEdge,
43 const TopoDS_Edge& aSecondEdge,
44 const Handle( Geom_Plane )& aPlane )
47 myFShape = aFirstEdge;
48 mySShape = aSecondEdge;
52 //=======================================================================
55 //=======================================================================
57 void AIS_EqualRadiusRelation::Compute( const Handle( PrsMgr_PresentationManager3d )&,
58 const Handle( Prs3d_Presentation )& aPresentation,
59 const Standard_Integer )
61 aPresentation->Clear();
63 BRepAdaptor_Curve FirstCurve( TopoDS::Edge( myFShape ) ), SecondCurve( TopoDS::Edge( mySShape ) );
65 Standard_Real FirstPar1 = FirstCurve.FirstParameter(), LastPar1 = FirstCurve.LastParameter(),
66 FirstPar2 = SecondCurve.FirstParameter(), LastPar2 = SecondCurve.LastParameter();
68 Handle( Geom_Curve ) FirstProjCurve = FirstCurve.Curve().Curve(),
69 SecondProjCurve = SecondCurve.Curve().Curve();
70 gp_Pnt FirstPoint1, LastPoint1, FirstPoint2, LastPoint2;
71 Standard_Boolean isFirstOnPlane, isSecondOnPlane;
73 AIS::ComputeGeomCurve( FirstProjCurve, FirstPar1, LastPar1, FirstPoint1, LastPoint1, myPlane, isFirstOnPlane );
74 AIS::ComputeGeomCurve( SecondProjCurve, FirstPar2, LastPar2, FirstPoint2, LastPoint2, myPlane, isSecondOnPlane );
77 ComputeProjEdgePresentation( aPresentation, TopoDS::Edge( myFShape ), FirstProjCurve, FirstPoint1, LastPoint1 );
78 if (! isSecondOnPlane)
79 ComputeProjEdgePresentation( aPresentation, TopoDS::Edge( mySShape ), SecondProjCurve, FirstPoint2, LastPoint2 );
81 gp_Circ FirstCirc = (Handle( Geom_Circle )::DownCast( FirstProjCurve ))->Circ();
82 gp_Circ SecondCirc = (Handle( Geom_Circle )::DownCast( SecondProjCurve ))->Circ();
84 myFirstCenter = FirstCirc.Location();
85 mySecondCenter = SecondCirc.Location();
88 if (myAutomaticPosition)
90 myFirstPoint = ElCLib::Value( (FirstPar1 + LastPar1)*0.5, FirstCirc );
91 mySecondPoint = ElCLib::Value( (FirstPar2 + LastPar2)*0.5, SecondCirc );
94 Standard_Real aPar = ElCLib::Parameter(FirstCirc, myFirstPoint);
95 if (IntegerPart(0.5*LastPar1/M_PI) != 0 && aPar < FirstPar1 )
96 aPar +=2*M_PI*IntegerPart(0.5*LastPar1/M_PI);
97 Standard_Real aRadius = FirstCirc.Radius();
99 if (Abs(myFirstPoint.Distance(myFirstCenter) - aRadius) >= Precision::Confusion())
100 myFirstPoint = ElCLib::Value(aPar, FirstCirc);
101 if ( FirstPoint1.Distance(LastPoint1) > Precision::Confusion()){
102 //check where is myFirstPoint
103 if (aPar > LastPar1 || aPar < FirstPar1)
105 //myFirstPoint is out of Arc of FirstCircle
106 if (FirstPoint1.Distance(myFirstPoint)< LastPoint1.Distance(myFirstPoint))
107 myFirstPoint = FirstPoint1;
109 myFirstPoint = LastPoint1;
114 aPar = ElCLib::Parameter(SecondCirc, mySecondPoint);
115 if (IntegerPart(0.5*LastPar2/M_PI) != 0 && aPar < FirstPar2 )
116 aPar +=2*M_PI*IntegerPart(0.5*LastPar2/M_PI);
118 aRadius = SecondCirc.Radius();
119 if (Abs(mySecondPoint.Distance(mySecondCenter) - aRadius) >= Precision::Confusion())
120 mySecondPoint = ElCLib::Value(aPar, SecondCirc);
121 if (FirstPoint2.Distance(LastPoint2) > Precision::Confusion()){
122 if (aPar > LastPar2 || aPar < FirstPar2)
123 { //mySecondPoint is out of Arc of mySecondCircle
124 if (FirstPoint2.Distance(mySecondPoint)< LastPoint2.Distance(mySecondPoint))
125 mySecondPoint = FirstPoint2;
127 mySecondPoint = LastPoint2;
131 if( !myArrowSizeIsDefined )
132 myArrowSize = (Min(myFirstCenter.Distance(myFirstPoint),
133 mySecondCenter.Distance(mySecondPoint)))*0.05;
135 Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect();
136 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
137 arr->SetLength(myArrowSize);
141 DsgPrs_EqualRadiusPresentation::Add(aPresentation, myDrawer,
142 myFirstCenter, mySecondCenter, myFirstPoint, mySecondPoint, myPlane );
145 //=======================================================================
147 //purpose : to avoid warning at compilation (SUN)
148 //=======================================================================
150 void AIS_EqualRadiusRelation::Compute( const Handle( Prs3d_Projector )& /*aProjector*/,
151 const Handle( Prs3d_Presentation )& /*aPresentation*/)
153 // Standard_NotImplemented::Raise("AIS_EqualRadiusRelation::Compute( const Handle( Prs3d_Projector )&,const Handle( Prs3d_Presentation )& )");
154 // PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
157 //=======================================================================
160 //=======================================================================
162 void AIS_EqualRadiusRelation::Compute(const Handle(Prs3d_Projector)& aProjector,
163 const Handle(Geom_Transformation)& aTransformation,
164 const Handle(Prs3d_Presentation)& aPresentation)
166 // Standard_NotImplemented::Raise("AIS_EqualRadiusRelation::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)");
167 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
170 //=======================================================================
171 //function : ComputeSelection
173 //=======================================================================
175 void AIS_EqualRadiusRelation::ComputeSelection( const Handle( SelectMgr_Selection )& aSelection,
176 const Standard_Integer )
178 Handle( SelectMgr_EntityOwner ) own = new SelectMgr_EntityOwner( this, 7 );
179 Handle( Select3D_SensitiveSegment ) seg;
181 seg = new Select3D_SensitiveSegment( own, myFirstCenter, myFirstPoint );
182 aSelection->Add( seg );
184 if(!myAutomaticPosition)
185 ComputeRadiusPosition();
187 seg = new Select3D_SensitiveSegment( own, mySecondCenter, mySecondPoint );
188 aSelection->Add( seg );
190 seg = new Select3D_SensitiveSegment( own, myFirstCenter, mySecondCenter );
191 aSelection->Add( seg );
195 gp_Pnt Middle( (myFirstCenter.XYZ() + mySecondCenter.XYZ())*0.5 );
197 Standard_Real SmallDist = .001;
198 //Should be changed as the domain of small lines could be changed.
199 Handle( Select3D_SensitiveBox ) box = new Select3D_SensitiveBox(own,
200 Middle.X() - SmallDist,
201 Middle.Y() - SmallDist,
202 Middle.Z() - SmallDist,
203 Middle.X() + SmallDist,
204 Middle.Y() + SmallDist,
205 Middle.Z() + SmallDist );
206 aSelection->Add(box);
209 //=================================================================
210 //function : ComputeRadiusPosition
212 //=================================================================
213 void AIS_EqualRadiusRelation::ComputeRadiusPosition()
215 if (myAutomaticPosition ||
216 myFirstCenter.Distance(myPosition) < Precision::Confusion() ||
217 mySecondCenter.Distance(myPosition) < Precision::Confusion())
222 //project myPosition to the plane of constraint
223 GeomAPI_ProjectPointOnSurf aProj(myPosition, myPlane);
224 aPosition = aProj.NearestPoint();
226 Standard_Real aDist1 = myFirstPoint.Distance(aPosition);
227 Standard_Real aDist2 = mySecondPoint.Distance(aPosition);
231 Standard_Real Rad1 = myFirstPoint.Distance(myFirstCenter);
232 const gp_Dir aNewDir1(aPosition.XYZ() - myFirstCenter.XYZ());
233 const gp_Vec aTVec (aNewDir1.XYZ()*Rad1);
234 myFirstPoint = myFirstCenter.Translated(aTVec);
237 Standard_Real Rad2 = mySecondPoint.Distance(mySecondCenter);
238 const gp_Dir aNewDir2(aPosition.XYZ() - mySecondCenter.XYZ());
239 gp_Vec aTVec (aNewDir2.XYZ()*Rad2);
240 mySecondPoint = mySecondCenter.Translated(aTVec);