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 aPresentation->Clear();
70 BRepAdaptor_Curve FirstCurve( TopoDS::Edge( myFShape ) ), SecondCurve( TopoDS::Edge( mySShape ) );
72 Standard_Real FirstPar1 = FirstCurve.FirstParameter(), LastPar1 = FirstCurve.LastParameter(),
73 FirstPar2 = SecondCurve.FirstParameter(), LastPar2 = SecondCurve.LastParameter();
75 Handle( Geom_Curve ) FirstProjCurve = FirstCurve.Curve().Curve(),
76 SecondProjCurve = SecondCurve.Curve().Curve();
77 gp_Pnt FirstPoint1, LastPoint1, FirstPoint2, LastPoint2;
78 Standard_Boolean isFirstOnPlane, isSecondOnPlane;
80 AIS::ComputeGeomCurve( FirstProjCurve, FirstPar1, LastPar1, FirstPoint1, LastPoint1, myPlane, isFirstOnPlane );
81 AIS::ComputeGeomCurve( SecondProjCurve, FirstPar2, LastPar2, FirstPoint2, LastPoint2, myPlane, isSecondOnPlane );
84 ComputeProjEdgePresentation( aPresentation, TopoDS::Edge( myFShape ), FirstProjCurve, FirstPoint1, LastPoint1 );
85 if (! isSecondOnPlane)
86 ComputeProjEdgePresentation( aPresentation, TopoDS::Edge( mySShape ), SecondProjCurve, FirstPoint2, LastPoint2 );
88 gp_Circ FirstCirc = (Handle( Geom_Circle )::DownCast( FirstProjCurve ))->Circ();
89 gp_Circ SecondCirc = (Handle( Geom_Circle )::DownCast( SecondProjCurve ))->Circ();
91 myFirstCenter = FirstCirc.Location();
92 mySecondCenter = SecondCirc.Location();
95 if (myAutomaticPosition)
97 myFirstPoint = ElCLib::Value( (FirstPar1 + LastPar1)*0.5, FirstCirc );
98 mySecondPoint = ElCLib::Value( (FirstPar2 + LastPar2)*0.5, SecondCirc );
101 Standard_Real aPar = ElCLib::Parameter(FirstCirc, myFirstPoint);
102 if (IntegerPart(0.5*LastPar1/M_PI) != 0 && aPar < FirstPar1 )
103 aPar +=2*M_PI*IntegerPart(0.5*LastPar1/M_PI);
104 Standard_Real aRadius = FirstCirc.Radius();
106 if (Abs(myFirstPoint.Distance(myFirstCenter) - aRadius) >= Precision::Confusion())
107 myFirstPoint = ElCLib::Value(aPar, FirstCirc);
108 if ( FirstPoint1.Distance(LastPoint1) > Precision::Confusion()){
109 //check where is myFirstPoint
110 if (aPar > LastPar1 || aPar < FirstPar1)
112 //myFirstPoint is out of Arc of FirstCircle
113 if (FirstPoint1.Distance(myFirstPoint)< LastPoint1.Distance(myFirstPoint))
114 myFirstPoint = FirstPoint1;
116 myFirstPoint = LastPoint1;
121 aPar = ElCLib::Parameter(SecondCirc, mySecondPoint);
122 if (IntegerPart(0.5*LastPar2/M_PI) != 0 && aPar < FirstPar2 )
123 aPar +=2*M_PI*IntegerPart(0.5*LastPar2/M_PI);
125 aRadius = SecondCirc.Radius();
126 if (Abs(mySecondPoint.Distance(mySecondCenter) - aRadius) >= Precision::Confusion())
127 mySecondPoint = ElCLib::Value(aPar, SecondCirc);
128 if (FirstPoint2.Distance(LastPoint2) > Precision::Confusion()){
129 if (aPar > LastPar2 || aPar < FirstPar2)
130 { //mySecondPoint is out of Arc of mySecondCircle
131 if (FirstPoint2.Distance(mySecondPoint)< LastPoint2.Distance(mySecondPoint))
132 mySecondPoint = FirstPoint2;
134 mySecondPoint = LastPoint2;
138 if( !myArrowSizeIsDefined )
139 myArrowSize = (Min(myFirstCenter.Distance(myFirstPoint),
140 mySecondCenter.Distance(mySecondPoint)))*0.05;
142 Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect();
143 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
144 arr->SetLength(myArrowSize);
148 DsgPrs_EqualRadiusPresentation::Add(aPresentation, myDrawer,
149 myFirstCenter, mySecondCenter, myFirstPoint, mySecondPoint, myPlane );
152 //=======================================================================
154 //purpose : to avoid warning at compilation (SUN)
155 //=======================================================================
157 void AIS_EqualRadiusRelation::Compute( const Handle( Prs3d_Projector )& /*aProjector*/,
158 const Handle( Prs3d_Presentation )& /*aPresentation*/)
160 // Standard_NotImplemented::Raise("AIS_EqualRadiusRelation::Compute( const Handle( Prs3d_Projector )&,const Handle( Prs3d_Presentation )& )");
161 // PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
164 //=======================================================================
167 //=======================================================================
169 void AIS_EqualRadiusRelation::Compute(const Handle(Prs3d_Projector)& aProjector,
170 const Handle(Geom_Transformation)& aTransformation,
171 const Handle(Prs3d_Presentation)& aPresentation)
173 // Standard_NotImplemented::Raise("AIS_EqualRadiusRelation::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)");
174 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
177 //=======================================================================
178 //function : ComputeSelection
180 //=======================================================================
182 void AIS_EqualRadiusRelation::ComputeSelection( const Handle( SelectMgr_Selection )& aSelection,
183 const Standard_Integer )
185 Handle( SelectMgr_EntityOwner ) own = new SelectMgr_EntityOwner( this, 7 );
186 Handle( Select3D_SensitiveSegment ) seg;
188 seg = new Select3D_SensitiveSegment( own, myFirstCenter, myFirstPoint );
189 aSelection->Add( seg );
191 if(!myAutomaticPosition)
192 ComputeRadiusPosition();
194 seg = new Select3D_SensitiveSegment( own, mySecondCenter, mySecondPoint );
195 aSelection->Add( seg );
197 seg = new Select3D_SensitiveSegment( own, myFirstCenter, mySecondCenter );
198 aSelection->Add( seg );
202 gp_Pnt Middle( (myFirstCenter.XYZ() + mySecondCenter.XYZ())*0.5 );
204 Standard_Real SmallDist = .001;
205 //Should be changed as the domain of small lines could be changed.
206 Handle( Select3D_SensitiveBox ) box = new Select3D_SensitiveBox(own,
207 Middle.X() - SmallDist,
208 Middle.Y() - SmallDist,
209 Middle.Z() - SmallDist,
210 Middle.X() + SmallDist,
211 Middle.Y() + SmallDist,
212 Middle.Z() + SmallDist );
213 aSelection->Add(box);
216 //=================================================================
217 //function : ComputeRadiusPosition
219 //=================================================================
220 void AIS_EqualRadiusRelation::ComputeRadiusPosition()
222 if (myAutomaticPosition ||
223 myFirstCenter.Distance(myPosition) < Precision::Confusion() ||
224 mySecondCenter.Distance(myPosition) < Precision::Confusion())
229 //project myPosition to the plane of constraint
230 GeomAPI_ProjectPointOnSurf aProj(myPosition, myPlane);
231 aPosition = aProj.NearestPoint();
233 Standard_Real aDist1 = myFirstPoint.Distance(aPosition);
234 Standard_Real aDist2 = mySecondPoint.Distance(aPosition);
238 Standard_Real Rad1 = myFirstPoint.Distance(myFirstCenter);
239 const gp_Dir aNewDir1(aPosition.XYZ() - myFirstCenter.XYZ());
240 const gp_Vec aTVec (aNewDir1.XYZ()*Rad1);
241 myFirstPoint = myFirstCenter.Translated(aTVec);
244 Standard_Real Rad2 = mySecondPoint.Distance(mySecondCenter);
245 const gp_Dir aNewDir2(aPosition.XYZ() - mySecondCenter.XYZ());
246 gp_Vec aTVec (aNewDir2.XYZ()*Rad2);
247 mySecondPoint = mySecondCenter.Translated(aTVec);