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.
19 #include <AIS_EqualRadiusRelation.hxx>
20 #include <BRepAdaptor_Curve.hxx>
21 #include <DsgPrs_EqualRadiusPresentation.hxx>
23 #include <Geom_Circle.hxx>
24 #include <Geom_Plane.hxx>
25 #include <Geom_Transformation.hxx>
26 #include <GeomAPI_ProjectPointOnSurf.hxx>
27 #include <gp_Circ.hxx>
28 #include <Precision.hxx>
29 #include <Prs3d_ArrowAspect.hxx>
30 #include <Prs3d_DimensionAspect.hxx>
31 #include <Prs3d_Drawer.hxx>
32 #include <Prs3d_Presentation.hxx>
33 #include <Prs3d_Projector.hxx>
34 #include <Select3D_SensitiveBox.hxx>
35 #include <Select3D_SensitiveSegment.hxx>
36 #include <SelectMgr_EntityOwner.hxx>
37 #include <SelectMgr_Selection.hxx>
38 #include <Standard_NotImplemented.hxx>
39 #include <Standard_Type.hxx>
41 #include <TopoDS_Edge.hxx>
43 IMPLEMENT_STANDARD_RTTIEXT(AIS_EqualRadiusRelation,AIS_Relation)
45 //=======================================================================
46 //function : AIS_EqualRadiusRelation
48 //=======================================================================
49 AIS_EqualRadiusRelation::AIS_EqualRadiusRelation( const TopoDS_Edge& aFirstEdge,
50 const TopoDS_Edge& aSecondEdge,
51 const Handle( Geom_Plane )& aPlane )
54 myFShape = aFirstEdge;
55 mySShape = aSecondEdge;
59 //=======================================================================
62 //=======================================================================
64 void AIS_EqualRadiusRelation::Compute( const Handle( PrsMgr_PresentationManager3d )&,
65 const Handle( Prs3d_Presentation )& aPresentation,
66 const Standard_Integer )
68 BRepAdaptor_Curve FirstCurve( TopoDS::Edge( myFShape ) ), SecondCurve( TopoDS::Edge( mySShape ) );
70 Standard_Real FirstPar1 = FirstCurve.FirstParameter(), LastPar1 = FirstCurve.LastParameter(),
71 FirstPar2 = SecondCurve.FirstParameter(), LastPar2 = SecondCurve.LastParameter();
73 Handle( Geom_Curve ) FirstProjCurve = FirstCurve.Curve().Curve(),
74 SecondProjCurve = SecondCurve.Curve().Curve();
75 gp_Pnt FirstPoint1, LastPoint1, FirstPoint2, LastPoint2;
76 Standard_Boolean isFirstOnPlane, isSecondOnPlane;
78 AIS::ComputeGeomCurve( FirstProjCurve, FirstPar1, LastPar1, FirstPoint1, LastPoint1, myPlane, isFirstOnPlane );
79 AIS::ComputeGeomCurve( SecondProjCurve, FirstPar2, LastPar2, FirstPoint2, LastPoint2, myPlane, isSecondOnPlane );
82 ComputeProjEdgePresentation( aPresentation, TopoDS::Edge( myFShape ), FirstProjCurve, FirstPoint1, LastPoint1 );
83 if (! isSecondOnPlane)
84 ComputeProjEdgePresentation( aPresentation, TopoDS::Edge( mySShape ), SecondProjCurve, FirstPoint2, LastPoint2 );
86 gp_Circ FirstCirc = (Handle( Geom_Circle )::DownCast( FirstProjCurve ))->Circ();
87 gp_Circ SecondCirc = (Handle( Geom_Circle )::DownCast( SecondProjCurve ))->Circ();
89 myFirstCenter = FirstCirc.Location();
90 mySecondCenter = SecondCirc.Location();
93 if (myAutomaticPosition)
95 myFirstPoint = ElCLib::Value( (FirstPar1 + LastPar1)*0.5, FirstCirc );
96 mySecondPoint = ElCLib::Value( (FirstPar2 + LastPar2)*0.5, SecondCirc );
99 Standard_Real aPar = ElCLib::Parameter(FirstCirc, myFirstPoint);
100 if (IntegerPart(0.5*LastPar1/M_PI) != 0 && aPar < FirstPar1 )
101 aPar +=2*M_PI*IntegerPart(0.5*LastPar1/M_PI);
102 Standard_Real aRadius = FirstCirc.Radius();
104 if (Abs(myFirstPoint.Distance(myFirstCenter) - aRadius) >= Precision::Confusion())
105 myFirstPoint = ElCLib::Value(aPar, FirstCirc);
106 if ( FirstPoint1.Distance(LastPoint1) > Precision::Confusion()){
107 //check where is myFirstPoint
108 if (aPar > LastPar1 || aPar < FirstPar1)
110 //myFirstPoint is out of Arc of FirstCircle
111 if (FirstPoint1.Distance(myFirstPoint)< LastPoint1.Distance(myFirstPoint))
112 myFirstPoint = FirstPoint1;
114 myFirstPoint = LastPoint1;
119 aPar = ElCLib::Parameter(SecondCirc, mySecondPoint);
120 if (IntegerPart(0.5*LastPar2/M_PI) != 0 && aPar < FirstPar2 )
121 aPar +=2*M_PI*IntegerPart(0.5*LastPar2/M_PI);
123 aRadius = SecondCirc.Radius();
124 if (Abs(mySecondPoint.Distance(mySecondCenter) - aRadius) >= Precision::Confusion())
125 mySecondPoint = ElCLib::Value(aPar, SecondCirc);
126 if (FirstPoint2.Distance(LastPoint2) > Precision::Confusion()){
127 if (aPar > LastPar2 || aPar < FirstPar2)
128 { //mySecondPoint is out of Arc of mySecondCircle
129 if (FirstPoint2.Distance(mySecondPoint)< LastPoint2.Distance(mySecondPoint))
130 mySecondPoint = FirstPoint2;
132 mySecondPoint = LastPoint2;
136 if( !myArrowSizeIsDefined )
137 myArrowSize = (Min(myFirstCenter.Distance(myFirstPoint),
138 mySecondCenter.Distance(mySecondPoint)))*0.05;
140 Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect();
141 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
142 arr->SetLength(myArrowSize);
146 DsgPrs_EqualRadiusPresentation::Add(aPresentation, myDrawer,
147 myFirstCenter, mySecondCenter, myFirstPoint, mySecondPoint, myPlane );
150 //=======================================================================
152 //purpose : to avoid warning at compilation (SUN)
153 //=======================================================================
155 void AIS_EqualRadiusRelation::Compute( const Handle( Prs3d_Projector )& /*aProjector*/,
156 const Handle( Prs3d_Presentation )& /*aPresentation*/)
158 // throw Standard_NotImplemented("AIS_EqualRadiusRelation::Compute( const Handle( Prs3d_Projector )&,const Handle( Prs3d_Presentation )& )");
159 // PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
162 //=======================================================================
165 //=======================================================================
167 void AIS_EqualRadiusRelation::Compute(const Handle(Prs3d_Projector)& aProjector,
168 const Handle(Geom_Transformation)& aTransformation,
169 const Handle(Prs3d_Presentation)& aPresentation)
171 // throw Standard_NotImplemented("AIS_EqualRadiusRelation::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)");
172 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
175 //=======================================================================
176 //function : ComputeSelection
178 //=======================================================================
180 void AIS_EqualRadiusRelation::ComputeSelection( const Handle( SelectMgr_Selection )& aSelection,
181 const Standard_Integer )
183 Handle( SelectMgr_EntityOwner ) own = new SelectMgr_EntityOwner( this, 7 );
184 Handle( Select3D_SensitiveSegment ) seg;
186 seg = new Select3D_SensitiveSegment( own, myFirstCenter, myFirstPoint );
187 aSelection->Add( seg );
189 if(!myAutomaticPosition)
190 ComputeRadiusPosition();
192 seg = new Select3D_SensitiveSegment( own, mySecondCenter, mySecondPoint );
193 aSelection->Add( seg );
195 seg = new Select3D_SensitiveSegment( own, myFirstCenter, mySecondCenter );
196 aSelection->Add( seg );
200 gp_Pnt Middle( (myFirstCenter.XYZ() + mySecondCenter.XYZ())*0.5 );
202 Standard_Real SmallDist = .001;
203 //Should be changed as the domain of small lines could be changed.
204 Handle( Select3D_SensitiveBox ) box = new Select3D_SensitiveBox(own,
205 Middle.X() - SmallDist,
206 Middle.Y() - SmallDist,
207 Middle.Z() - SmallDist,
208 Middle.X() + SmallDist,
209 Middle.Y() + SmallDist,
210 Middle.Z() + SmallDist );
211 aSelection->Add(box);
214 //=================================================================
215 //function : ComputeRadiusPosition
217 //=================================================================
218 void AIS_EqualRadiusRelation::ComputeRadiusPosition()
220 if (myAutomaticPosition ||
221 myFirstCenter.Distance(myPosition) < Precision::Confusion() ||
222 mySecondCenter.Distance(myPosition) < Precision::Confusion())
227 //project myPosition to the plane of constraint
228 GeomAPI_ProjectPointOnSurf aProj(myPosition, myPlane);
229 aPosition = aProj.NearestPoint();
231 Standard_Real aDist1 = myFirstPoint.Distance(aPosition);
232 Standard_Real aDist2 = mySecondPoint.Distance(aPosition);
236 Standard_Real Rad1 = myFirstPoint.Distance(myFirstCenter);
237 const gp_Dir aNewDir1(aPosition.XYZ() - myFirstCenter.XYZ());
238 const gp_Vec aTVec (aNewDir1.XYZ()*Rad1);
239 myFirstPoint = myFirstCenter.Translated(aTVec);
242 Standard_Real Rad2 = mySecondPoint.Distance(mySecondCenter);
243 const gp_Dir aNewDir2(aPosition.XYZ() - mySecondCenter.XYZ());
244 gp_Vec aTVec (aNewDir2.XYZ()*Rad2);
245 mySecondPoint = mySecondCenter.Translated(aTVec);