0024023: Revamp the OCCT Handle -- ambiguity
[occt.git] / src / AIS / AIS_EqualRadiusRelation.cxx
CommitLineData
b311480e 1// Created on: 1998-01-20
2// Created by: Julia GERASIMOVA
3// Copyright (c) 1998-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
7fd59977 17#include <Standard_NotImplemented.hxx>
18
19#include <AIS_EqualRadiusRelation.ixx>
20
21#include <AIS.hxx>
22#include <DsgPrs_EqualRadiusPresentation.hxx>
23#include <BRepAdaptor_Curve.hxx>
24#include <TopoDS.hxx>
25#include <gp_Circ.hxx>
26#include <Geom_Circle.hxx>
27#include <ElCLib.hxx>
28#include <SelectMgr_EntityOwner.hxx>
f751596e 29#include <SelectMgr_Selection.hxx>
7fd59977 30#include <Select3D_SensitiveSegment.hxx>
31#include <Select3D_SensitiveBox.hxx>
32#include <Precision.hxx>
33#include <GeomAPI_ProjectPointOnSurf.hxx>
a6eb515f 34#include <Prs3d_DimensionAspect.hxx>
7fd59977 35#include <Prs3d_ArrowAspect.hxx>
6262338c 36#include <Prs3d_Drawer.hxx>
7fd59977 37
38//=======================================================================
39//function : AIS_EqualRadiusRelation
40//purpose :
41//=======================================================================
42
43AIS_EqualRadiusRelation::AIS_EqualRadiusRelation( const TopoDS_Edge& aFirstEdge,
44 const TopoDS_Edge& aSecondEdge,
45 const Handle( Geom_Plane )& aPlane )
46 :AIS_Relation()
47{
48 myFShape = aFirstEdge;
49 mySShape = aSecondEdge;
50 myPlane = aPlane;
51}
52
53//=======================================================================
54//function : Compute
55//purpose :
56//=======================================================================
57
58void AIS_EqualRadiusRelation::Compute( const Handle( PrsMgr_PresentationManager3d )&,
59 const Handle( Prs3d_Presentation )& aPresentation,
60 const Standard_Integer )
61{
62 aPresentation->Clear();
63
64 BRepAdaptor_Curve FirstCurve( TopoDS::Edge( myFShape ) ), SecondCurve( TopoDS::Edge( mySShape ) );
65
66 Standard_Real FirstPar1 = FirstCurve.FirstParameter(), LastPar1 = FirstCurve.LastParameter(),
67 FirstPar2 = SecondCurve.FirstParameter(), LastPar2 = SecondCurve.LastParameter();
68
69 Handle( Geom_Curve ) FirstProjCurve = FirstCurve.Curve().Curve(),
70 SecondProjCurve = SecondCurve.Curve().Curve();
71 gp_Pnt FirstPoint1, LastPoint1, FirstPoint2, LastPoint2;
72 Standard_Boolean isFirstOnPlane, isSecondOnPlane;
73
74 AIS::ComputeGeomCurve( FirstProjCurve, FirstPar1, LastPar1, FirstPoint1, LastPoint1, myPlane, isFirstOnPlane );
75 AIS::ComputeGeomCurve( SecondProjCurve, FirstPar2, LastPar2, FirstPoint2, LastPoint2, myPlane, isSecondOnPlane );
76
77 if (!isFirstOnPlane)
78 ComputeProjEdgePresentation( aPresentation, TopoDS::Edge( myFShape ), FirstProjCurve, FirstPoint1, LastPoint1 );
79 if (! isSecondOnPlane)
80 ComputeProjEdgePresentation( aPresentation, TopoDS::Edge( mySShape ), SecondProjCurve, FirstPoint2, LastPoint2 );
81
82 gp_Circ FirstCirc = (Handle( Geom_Circle )::DownCast( FirstProjCurve ))->Circ();
83 gp_Circ SecondCirc = (Handle( Geom_Circle )::DownCast( SecondProjCurve ))->Circ();
84
85 myFirstCenter = FirstCirc.Location();
86 mySecondCenter = SecondCirc.Location();
87
88 //ota -- begin --
89 if (myAutomaticPosition)
90 {
91 myFirstPoint = ElCLib::Value( (FirstPar1 + LastPar1)*0.5, FirstCirc );
92 mySecondPoint = ElCLib::Value( (FirstPar2 + LastPar2)*0.5, SecondCirc );
93 }
94 else {
95 Standard_Real aPar = ElCLib::Parameter(FirstCirc, myFirstPoint);
c6541a0c
D
96 if (IntegerPart(0.5*LastPar1/M_PI) != 0 && aPar < FirstPar1 )
97 aPar +=2*M_PI*IntegerPart(0.5*LastPar1/M_PI);
7fd59977 98 Standard_Real aRadius = FirstCirc.Radius();
99
100 if (Abs(myFirstPoint.Distance(myFirstCenter) - aRadius) >= Precision::Confusion())
101 myFirstPoint = ElCLib::Value(aPar, FirstCirc);
102 if ( FirstPoint1.Distance(LastPoint1) > Precision::Confusion()){
103 //check where is myFirstPoint
104 if (aPar > LastPar1 || aPar < FirstPar1)
105 {
106 //myFirstPoint is out of Arc of FirstCircle
107 if (FirstPoint1.Distance(myFirstPoint)< LastPoint1.Distance(myFirstPoint))
108 myFirstPoint = FirstPoint1;
109 else
110 myFirstPoint = LastPoint1;
111 }
112 }
113
114
115 aPar = ElCLib::Parameter(SecondCirc, mySecondPoint);
c6541a0c
D
116 if (IntegerPart(0.5*LastPar2/M_PI) != 0 && aPar < FirstPar2 )
117 aPar +=2*M_PI*IntegerPart(0.5*LastPar2/M_PI);
7fd59977 118
119 aRadius = SecondCirc.Radius();
120 if (Abs(mySecondPoint.Distance(mySecondCenter) - aRadius) >= Precision::Confusion())
121 mySecondPoint = ElCLib::Value(aPar, SecondCirc);
122 if (FirstPoint2.Distance(LastPoint2) > Precision::Confusion()){
123 if (aPar > LastPar2 || aPar < FirstPar2)
124 { //mySecondPoint is out of Arc of mySecondCircle
125 if (FirstPoint2.Distance(mySecondPoint)< LastPoint2.Distance(mySecondPoint))
126 mySecondPoint = FirstPoint2;
127 else
128 mySecondPoint = LastPoint2;
129 }
130 }
131 }
7fd59977 132 if( !myArrowSizeIsDefined )
7fd59977 133 myArrowSize = (Min(myFirstCenter.Distance(myFirstPoint),
134 mySecondCenter.Distance(mySecondPoint)))*0.05;
135
a6eb515f 136 Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect();
137 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
7fd59977 138 arr->SetLength(myArrowSize);
139
140 //ota -- end --
141
142 DsgPrs_EqualRadiusPresentation::Add(aPresentation, myDrawer,
143 myFirstCenter, mySecondCenter, myFirstPoint, mySecondPoint, myPlane );
144}
145
146//=======================================================================
147//function : Compute
148//purpose : to avoid warning at compilation (SUN)
149//=======================================================================
150
151void AIS_EqualRadiusRelation::Compute( const Handle( Prs3d_Projector )& /*aProjector*/,
152 const Handle( Prs3d_Presentation )& /*aPresentation*/)
153{
154// Standard_NotImplemented::Raise("AIS_EqualRadiusRelation::Compute( const Handle( Prs3d_Projector )&,const Handle( Prs3d_Presentation )& )");
155// PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
156}
157
158//=======================================================================
159//function : Compute
7fd59977 160//purpose :
161//=======================================================================
162
857ffd5e 163void AIS_EqualRadiusRelation::Compute(const Handle(Prs3d_Projector)& aProjector,
164 const Handle(Geom_Transformation)& aTransformation,
165 const Handle(Prs3d_Presentation)& aPresentation)
7fd59977 166{
857ffd5e 167// Standard_NotImplemented::Raise("AIS_EqualRadiusRelation::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)");
7fd59977 168 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
169}
170
171//=======================================================================
172//function : ComputeSelection
173//purpose :
174//=======================================================================
175
176void AIS_EqualRadiusRelation::ComputeSelection( const Handle( SelectMgr_Selection )& aSelection,
177 const Standard_Integer )
178{
179 Handle( SelectMgr_EntityOwner ) own = new SelectMgr_EntityOwner( this, 7 );
180 Handle( Select3D_SensitiveSegment ) seg;
181
182 seg = new Select3D_SensitiveSegment( own, myFirstCenter, myFirstPoint );
183 aSelection->Add( seg );
184
185 if(!myAutomaticPosition)
186 ComputeRadiusPosition();
187
188 seg = new Select3D_SensitiveSegment( own, mySecondCenter, mySecondPoint );
189 aSelection->Add( seg );
190
191 seg = new Select3D_SensitiveSegment( own, myFirstCenter, mySecondCenter );
192 aSelection->Add( seg );
193
194
195 // Two small lines
196 gp_Pnt Middle( (myFirstCenter.XYZ() + mySecondCenter.XYZ())*0.5 );
197
198 Standard_Real SmallDist = .001;
199 //Should be changed as the domain of small lines could be changed.
200 Handle( Select3D_SensitiveBox ) box = new Select3D_SensitiveBox(own,
201 Middle.X() - SmallDist,
202 Middle.Y() - SmallDist,
203 Middle.Z() - SmallDist,
204 Middle.X() + SmallDist,
205 Middle.Y() + SmallDist,
206 Middle.Z() + SmallDist );
207 aSelection->Add(box);
208}
209
210//=================================================================
211//function : ComputeRadiusPosition
212//purpose :
213//=================================================================
214void AIS_EqualRadiusRelation::ComputeRadiusPosition()
215{
216 if (myAutomaticPosition ||
217 myFirstCenter.Distance(myPosition) < Precision::Confusion() ||
218 mySecondCenter.Distance(myPosition) < Precision::Confusion())
219 return;
220
221 gp_Pnt aPosition;
222
223 //project myPosition to the plane of constraint
224 GeomAPI_ProjectPointOnSurf aProj(myPosition, myPlane);
225 aPosition = aProj.NearestPoint();
226
227 Standard_Real aDist1 = myFirstPoint.Distance(aPosition);
228 Standard_Real aDist2 = mySecondPoint.Distance(aPosition);
229
230 if(aDist1<aDist2)
231 {
232 Standard_Real Rad1 = myFirstPoint.Distance(myFirstCenter);
233 const gp_Dir aNewDir1(aPosition.XYZ() - myFirstCenter.XYZ());
234 const gp_Vec aTVec (aNewDir1.XYZ()*Rad1);
235 myFirstPoint = myFirstCenter.Translated(aTVec);
236 }
237 else {
238 Standard_Real Rad2 = mySecondPoint.Distance(mySecondCenter);
239 const gp_Dir aNewDir2(aPosition.XYZ() - mySecondCenter.XYZ());
240 gp_Vec aTVec (aNewDir2.XYZ()*Rad2);
241 mySecondPoint = mySecondCenter.Translated(aTVec);
242 }
243
244}
245