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 <Select3D_SensitiveBox.hxx>
34 #include <Select3D_SensitiveSegment.hxx>
35 #include <SelectMgr_EntityOwner.hxx>
36 #include <SelectMgr_Selection.hxx>
37 #include <Standard_NotImplemented.hxx>
38 #include <Standard_Type.hxx>
40 #include <TopoDS_Edge.hxx>
42 IMPLEMENT_STANDARD_RTTIEXT(AIS_EqualRadiusRelation,AIS_Relation)
44 //=======================================================================
45 //function : AIS_EqualRadiusRelation
47 //=======================================================================
48 AIS_EqualRadiusRelation::AIS_EqualRadiusRelation( const TopoDS_Edge& aFirstEdge,
49 const TopoDS_Edge& aSecondEdge,
50 const Handle( Geom_Plane )& aPlane )
53 myFShape = aFirstEdge;
54 mySShape = aSecondEdge;
58 //=======================================================================
61 //=======================================================================
63 void AIS_EqualRadiusRelation::Compute( const Handle( PrsMgr_PresentationManager3d )&,
64 const Handle( Prs3d_Presentation )& aPresentation,
65 const Standard_Integer )
67 BRepAdaptor_Curve FirstCurve( TopoDS::Edge( myFShape ) ), SecondCurve( TopoDS::Edge( mySShape ) );
69 Standard_Real FirstPar1 = FirstCurve.FirstParameter(), LastPar1 = FirstCurve.LastParameter(),
70 FirstPar2 = SecondCurve.FirstParameter(), LastPar2 = SecondCurve.LastParameter();
72 Handle( Geom_Curve ) FirstProjCurve = FirstCurve.Curve().Curve(),
73 SecondProjCurve = SecondCurve.Curve().Curve();
74 gp_Pnt FirstPoint1, LastPoint1, FirstPoint2, LastPoint2;
75 Standard_Boolean isFirstOnPlane, isSecondOnPlane;
77 AIS::ComputeGeomCurve( FirstProjCurve, FirstPar1, LastPar1, FirstPoint1, LastPoint1, myPlane, isFirstOnPlane );
78 AIS::ComputeGeomCurve( SecondProjCurve, FirstPar2, LastPar2, FirstPoint2, LastPoint2, myPlane, isSecondOnPlane );
81 ComputeProjEdgePresentation( aPresentation, TopoDS::Edge( myFShape ), FirstProjCurve, FirstPoint1, LastPoint1 );
82 if (! isSecondOnPlane)
83 ComputeProjEdgePresentation( aPresentation, TopoDS::Edge( mySShape ), SecondProjCurve, FirstPoint2, LastPoint2 );
85 gp_Circ FirstCirc = (Handle( Geom_Circle )::DownCast( FirstProjCurve ))->Circ();
86 gp_Circ SecondCirc = (Handle( Geom_Circle )::DownCast( SecondProjCurve ))->Circ();
88 myFirstCenter = FirstCirc.Location();
89 mySecondCenter = SecondCirc.Location();
92 if (myAutomaticPosition)
94 myFirstPoint = ElCLib::Value( (FirstPar1 + LastPar1)*0.5, FirstCirc );
95 mySecondPoint = ElCLib::Value( (FirstPar2 + LastPar2)*0.5, SecondCirc );
98 Standard_Real aPar = ElCLib::Parameter(FirstCirc, myFirstPoint);
99 if (IntegerPart(0.5*LastPar1/M_PI) != 0 && aPar < FirstPar1 )
100 aPar +=2*M_PI*IntegerPart(0.5*LastPar1/M_PI);
101 Standard_Real aRadius = FirstCirc.Radius();
103 if (Abs(myFirstPoint.Distance(myFirstCenter) - aRadius) >= Precision::Confusion())
104 myFirstPoint = ElCLib::Value(aPar, FirstCirc);
105 if ( FirstPoint1.Distance(LastPoint1) > Precision::Confusion()){
106 //check where is myFirstPoint
107 if (aPar > LastPar1 || aPar < FirstPar1)
109 //myFirstPoint is out of Arc of FirstCircle
110 if (FirstPoint1.Distance(myFirstPoint)< LastPoint1.Distance(myFirstPoint))
111 myFirstPoint = FirstPoint1;
113 myFirstPoint = LastPoint1;
118 aPar = ElCLib::Parameter(SecondCirc, mySecondPoint);
119 if (IntegerPart(0.5*LastPar2/M_PI) != 0 && aPar < FirstPar2 )
120 aPar +=2*M_PI*IntegerPart(0.5*LastPar2/M_PI);
122 aRadius = SecondCirc.Radius();
123 if (Abs(mySecondPoint.Distance(mySecondCenter) - aRadius) >= Precision::Confusion())
124 mySecondPoint = ElCLib::Value(aPar, SecondCirc);
125 if (FirstPoint2.Distance(LastPoint2) > Precision::Confusion()){
126 if (aPar > LastPar2 || aPar < FirstPar2)
127 { //mySecondPoint is out of Arc of mySecondCircle
128 if (FirstPoint2.Distance(mySecondPoint)< LastPoint2.Distance(mySecondPoint))
129 mySecondPoint = FirstPoint2;
131 mySecondPoint = LastPoint2;
135 if( !myArrowSizeIsDefined )
136 myArrowSize = (Min(myFirstCenter.Distance(myFirstPoint),
137 mySecondCenter.Distance(mySecondPoint)))*0.05;
139 Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect();
140 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
141 arr->SetLength(myArrowSize);
145 DsgPrs_EqualRadiusPresentation::Add(aPresentation, myDrawer,
146 myFirstCenter, mySecondCenter, myFirstPoint, mySecondPoint, myPlane );
149 //=======================================================================
150 //function : ComputeSelection
152 //=======================================================================
154 void AIS_EqualRadiusRelation::ComputeSelection( const Handle( SelectMgr_Selection )& aSelection,
155 const Standard_Integer )
157 Handle( SelectMgr_EntityOwner ) own = new SelectMgr_EntityOwner( this, 7 );
158 Handle( Select3D_SensitiveSegment ) seg;
160 seg = new Select3D_SensitiveSegment( own, myFirstCenter, myFirstPoint );
161 aSelection->Add( seg );
163 if(!myAutomaticPosition)
164 ComputeRadiusPosition();
166 seg = new Select3D_SensitiveSegment( own, mySecondCenter, mySecondPoint );
167 aSelection->Add( seg );
169 seg = new Select3D_SensitiveSegment( own, myFirstCenter, mySecondCenter );
170 aSelection->Add( seg );
174 gp_Pnt Middle( (myFirstCenter.XYZ() + mySecondCenter.XYZ())*0.5 );
176 Standard_Real SmallDist = .001;
177 //Should be changed as the domain of small lines could be changed.
178 Handle( Select3D_SensitiveBox ) box = new Select3D_SensitiveBox(own,
179 Middle.X() - SmallDist,
180 Middle.Y() - SmallDist,
181 Middle.Z() - SmallDist,
182 Middle.X() + SmallDist,
183 Middle.Y() + SmallDist,
184 Middle.Z() + SmallDist );
185 aSelection->Add(box);
188 //=================================================================
189 //function : ComputeRadiusPosition
191 //=================================================================
192 void AIS_EqualRadiusRelation::ComputeRadiusPosition()
194 if (myAutomaticPosition ||
195 myFirstCenter.Distance(myPosition) < Precision::Confusion() ||
196 mySecondCenter.Distance(myPosition) < Precision::Confusion())
201 //project myPosition to the plane of constraint
202 GeomAPI_ProjectPointOnSurf aProj(myPosition, myPlane);
203 aPosition = aProj.NearestPoint();
205 Standard_Real aDist1 = myFirstPoint.Distance(aPosition);
206 Standard_Real aDist2 = mySecondPoint.Distance(aPosition);
210 Standard_Real Rad1 = myFirstPoint.Distance(myFirstCenter);
211 const gp_Dir aNewDir1(aPosition.XYZ() - myFirstCenter.XYZ());
212 const gp_Vec aTVec (aNewDir1.XYZ()*Rad1);
213 myFirstPoint = myFirstCenter.Translated(aTVec);
216 Standard_Real Rad2 = mySecondPoint.Distance(mySecondCenter);
217 const gp_Dir aNewDir2(aPosition.XYZ() - mySecondCenter.XYZ());
218 gp_Vec aTVec (aNewDir2.XYZ()*Rad2);
219 mySecondPoint = mySecondCenter.Translated(aTVec);