0031459: Visualization, AIS_TextLabel - add missing getters
[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
18#include <AIS.hxx>
42cf5bc1 19#include <AIS_EqualRadiusRelation.hxx>
7fd59977 20#include <BRepAdaptor_Curve.hxx>
42cf5bc1 21#include <DsgPrs_EqualRadiusPresentation.hxx>
7fd59977 22#include <ElCLib.hxx>
42cf5bc1 23#include <Geom_Circle.hxx>
24#include <Geom_Plane.hxx>
25#include <Geom_Transformation.hxx>
7fd59977 26#include <GeomAPI_ProjectPointOnSurf.hxx>
42cf5bc1 27#include <gp_Circ.hxx>
28#include <Precision.hxx>
7fd59977 29#include <Prs3d_ArrowAspect.hxx>
42cf5bc1 30#include <Prs3d_DimensionAspect.hxx>
6262338c 31#include <Prs3d_Drawer.hxx>
42cf5bc1 32#include <Prs3d_Presentation.hxx>
42cf5bc1 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>
39#include <TopoDS.hxx>
40#include <TopoDS_Edge.hxx>
7fd59977 41
92efcf78 42IMPLEMENT_STANDARD_RTTIEXT(AIS_EqualRadiusRelation,AIS_Relation)
43
7fd59977 44//=======================================================================
45//function : AIS_EqualRadiusRelation
46//purpose :
47//=======================================================================
7fd59977 48AIS_EqualRadiusRelation::AIS_EqualRadiusRelation( const TopoDS_Edge& aFirstEdge,
49 const TopoDS_Edge& aSecondEdge,
50 const Handle( Geom_Plane )& aPlane )
51 :AIS_Relation()
52{
53 myFShape = aFirstEdge;
54 mySShape = aSecondEdge;
55 myPlane = aPlane;
56}
57
58//=======================================================================
59//function : Compute
60//purpose :
61//=======================================================================
62
63void AIS_EqualRadiusRelation::Compute( const Handle( PrsMgr_PresentationManager3d )&,
64 const Handle( Prs3d_Presentation )& aPresentation,
65 const Standard_Integer )
66{
7fd59977 67 BRepAdaptor_Curve FirstCurve( TopoDS::Edge( myFShape ) ), SecondCurve( TopoDS::Edge( mySShape ) );
68
69 Standard_Real FirstPar1 = FirstCurve.FirstParameter(), LastPar1 = FirstCurve.LastParameter(),
70 FirstPar2 = SecondCurve.FirstParameter(), LastPar2 = SecondCurve.LastParameter();
71
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;
76
77 AIS::ComputeGeomCurve( FirstProjCurve, FirstPar1, LastPar1, FirstPoint1, LastPoint1, myPlane, isFirstOnPlane );
78 AIS::ComputeGeomCurve( SecondProjCurve, FirstPar2, LastPar2, FirstPoint2, LastPoint2, myPlane, isSecondOnPlane );
79
80 if (!isFirstOnPlane)
81 ComputeProjEdgePresentation( aPresentation, TopoDS::Edge( myFShape ), FirstProjCurve, FirstPoint1, LastPoint1 );
82 if (! isSecondOnPlane)
83 ComputeProjEdgePresentation( aPresentation, TopoDS::Edge( mySShape ), SecondProjCurve, FirstPoint2, LastPoint2 );
84
85 gp_Circ FirstCirc = (Handle( Geom_Circle )::DownCast( FirstProjCurve ))->Circ();
86 gp_Circ SecondCirc = (Handle( Geom_Circle )::DownCast( SecondProjCurve ))->Circ();
87
88 myFirstCenter = FirstCirc.Location();
89 mySecondCenter = SecondCirc.Location();
90
91 //ota -- begin --
92 if (myAutomaticPosition)
93 {
94 myFirstPoint = ElCLib::Value( (FirstPar1 + LastPar1)*0.5, FirstCirc );
95 mySecondPoint = ElCLib::Value( (FirstPar2 + LastPar2)*0.5, SecondCirc );
96 }
97 else {
98 Standard_Real aPar = ElCLib::Parameter(FirstCirc, myFirstPoint);
c6541a0c
D
99 if (IntegerPart(0.5*LastPar1/M_PI) != 0 && aPar < FirstPar1 )
100 aPar +=2*M_PI*IntegerPart(0.5*LastPar1/M_PI);
7fd59977 101 Standard_Real aRadius = FirstCirc.Radius();
102
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)
108 {
109 //myFirstPoint is out of Arc of FirstCircle
110 if (FirstPoint1.Distance(myFirstPoint)< LastPoint1.Distance(myFirstPoint))
111 myFirstPoint = FirstPoint1;
112 else
113 myFirstPoint = LastPoint1;
114 }
115 }
116
117
118 aPar = ElCLib::Parameter(SecondCirc, mySecondPoint);
c6541a0c
D
119 if (IntegerPart(0.5*LastPar2/M_PI) != 0 && aPar < FirstPar2 )
120 aPar +=2*M_PI*IntegerPart(0.5*LastPar2/M_PI);
7fd59977 121
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;
130 else
131 mySecondPoint = LastPoint2;
132 }
133 }
134 }
7fd59977 135 if( !myArrowSizeIsDefined )
7fd59977 136 myArrowSize = (Min(myFirstCenter.Distance(myFirstPoint),
137 mySecondCenter.Distance(mySecondPoint)))*0.05;
138
a6eb515f 139 Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect();
140 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
7fd59977 141 arr->SetLength(myArrowSize);
142
143 //ota -- end --
144
145 DsgPrs_EqualRadiusPresentation::Add(aPresentation, myDrawer,
146 myFirstCenter, mySecondCenter, myFirstPoint, mySecondPoint, myPlane );
147}
148
149//=======================================================================
7fd59977 150//function : ComputeSelection
151//purpose :
152//=======================================================================
153
154void AIS_EqualRadiusRelation::ComputeSelection( const Handle( SelectMgr_Selection )& aSelection,
155 const Standard_Integer )
156{
157 Handle( SelectMgr_EntityOwner ) own = new SelectMgr_EntityOwner( this, 7 );
158 Handle( Select3D_SensitiveSegment ) seg;
159
160 seg = new Select3D_SensitiveSegment( own, myFirstCenter, myFirstPoint );
161 aSelection->Add( seg );
162
163 if(!myAutomaticPosition)
164 ComputeRadiusPosition();
165
166 seg = new Select3D_SensitiveSegment( own, mySecondCenter, mySecondPoint );
167 aSelection->Add( seg );
168
169 seg = new Select3D_SensitiveSegment( own, myFirstCenter, mySecondCenter );
170 aSelection->Add( seg );
171
172
173 // Two small lines
174 gp_Pnt Middle( (myFirstCenter.XYZ() + mySecondCenter.XYZ())*0.5 );
175
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);
186}
187
188//=================================================================
189//function : ComputeRadiusPosition
190//purpose :
191//=================================================================
192void AIS_EqualRadiusRelation::ComputeRadiusPosition()
193{
194 if (myAutomaticPosition ||
195 myFirstCenter.Distance(myPosition) < Precision::Confusion() ||
196 mySecondCenter.Distance(myPosition) < Precision::Confusion())
197 return;
198
199 gp_Pnt aPosition;
200
201 //project myPosition to the plane of constraint
202 GeomAPI_ProjectPointOnSurf aProj(myPosition, myPlane);
203 aPosition = aProj.NearestPoint();
204
205 Standard_Real aDist1 = myFirstPoint.Distance(aPosition);
206 Standard_Real aDist2 = mySecondPoint.Distance(aPosition);
207
208 if(aDist1<aDist2)
209 {
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);
214 }
215 else {
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);
220 }
221
222}
223