0024023: Revamp the OCCT Handle -- ambiguity
[occt.git] / src / AIS / AIS_ConcentricRelation.cxx
CommitLineData
b311480e 1// Created on: 1996-12-05
2// Created by: Flore Lantheaume/Odile Olivier
3// Copyright (c) 1996-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
17#include <Standard_NotImplemented.hxx>
18
19#include <AIS_ConcentricRelation.ixx>
20
21#include <SelectMgr_EntityOwner.hxx>
f751596e 22#include <SelectMgr_Selection.hxx>
7fd59977 23#include <Select3D_SensitiveCircle.hxx>
24#include <Select3D_SensitiveSegment.hxx>
25
26#include <DsgPrs_ConcentricPresentation.hxx>
27
28#include <TopoDS.hxx>
29
30#include <BRepAdaptor_Curve.hxx>
31
32#include <GeomAbs_CurveType.hxx>
33#include <Geom_Circle.hxx>
34#include <gp_Dir.hxx>
35#include <gp_Vec.hxx>
36#include <gp_Ax2.hxx>
37#include <gp_Ax1.hxx>
38#include <gp_Pnt.hxx>
39#include <gp_Pln.hxx>
40
41#include <TopoDS_Vertex.hxx>
42#include <AIS.hxx>
43
44//=======================================================================
45//function : Constructor
46//purpose :
47//=======================================================================
48
49AIS_ConcentricRelation::AIS_ConcentricRelation(
50 const TopoDS_Shape& aFShape,
51 const TopoDS_Shape& aSShape,
52 const Handle(Geom_Plane)& aPlane)
53{
54 myFShape = aFShape;
55 mySShape = aSShape;
56 myPlane = aPlane;
57 myDir = aPlane->Pln().Axis().Direction();
58}
59
60//=======================================================================
61//function : Compute
62//purpose :
63//=======================================================================
64void AIS_ConcentricRelation::Compute(const Handle(PrsMgr_PresentationManager3d)&,
65 const Handle(Prs3d_Presentation)& aPresentation,
66 const Standard_Integer)
67{
68 aPresentation->Clear();
69
70 TopAbs_ShapeEnum type2(mySShape.ShapeType());
71 aPresentation->SetInfiniteState(Standard_True);
72 switch (myFShape.ShapeType()) {
73 case TopAbs_EDGE:
74 {
75 if (type2 == TopAbs_EDGE) ComputeTwoEdgesConcentric(aPresentation);
76 else if (type2 == TopAbs_VERTEX) ComputeEdgeVertexConcentric(aPresentation);
77 }
78 break;
79
80 case TopAbs_VERTEX:
81 {
82 if (type2 == TopAbs_VERTEX) ComputeTwoVerticesConcentric(aPresentation);
83 else if (type2 == TopAbs_EDGE) ComputeEdgeVertexConcentric(aPresentation);
84 }
85 break;
86 default: {return;}
87 }
88}
89
857ffd5e 90void AIS_ConcentricRelation::Compute(const Handle(Prs3d_Projector)& aProjector, const Handle(Geom_Transformation)& aTransformation, const Handle(Prs3d_Presentation)& aPresentation)
7fd59977 91{
857ffd5e 92// Standard_NotImplemented::Raise("AIS_ConcentricRelation::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)");
7fd59977 93 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
94}
95
96//=======================================================================
97//function : ComputeTwoEdgesConcentric
98//purpose :
99//=======================================================================
100void AIS_ConcentricRelation::ComputeEdgeVertexConcentric(const Handle(Prs3d_Presentation)& aPresentation)
101{
102 TopoDS_Edge E;
103 TopoDS_Vertex V;
104 if (myFShape.ShapeType() == TopAbs_EDGE) {
105 E = TopoDS::Edge(myFShape);
106 V = TopoDS::Vertex(mySShape);
107 }
108 else {
53aa7b32
P
109 E = TopoDS::Edge(mySShape);
110 V = TopoDS::Vertex(myFShape);
7fd59977 111 }
112 gp_Pnt p1,p2;
113 Handle(Geom_Curve) C;
114 Handle(Geom_Curve) extCurv;
115 Standard_Boolean isInfinite;
116 Standard_Boolean isOnPlanEdge, isOnPlanVertex;
117 if (!AIS::ComputeGeometry(E,C,p1,p2,extCurv,isInfinite,isOnPlanEdge,myPlane)) return;
118 gp_Pnt P;
119 AIS::ComputeGeometry(V,P, myPlane, isOnPlanVertex);
120
c5f3a425 121 Handle(Geom_Circle) CIRCLE (Handle(Geom_Circle)::DownCast (C));
7fd59977 122 myCenter = CIRCLE->Location();
123 myRad = Min(CIRCLE->Radius()/5.,15.);
124 gp_Dir vec(p1.XYZ() - myCenter.XYZ() );
125 gp_Vec vectrans(vec);
126 myPnt = myCenter.Translated(vectrans.Multiplied(myRad));
127 DsgPrs_ConcentricPresentation::Add(aPresentation,myDrawer,myCenter,myRad,myDir,myPnt);
128 if (!isOnPlanEdge) AIS::ComputeProjEdgePresentation(aPresentation,myDrawer,E,CIRCLE,p1,p2);
129 if (!isOnPlanVertex) AIS::ComputeProjVertexPresentation(aPresentation,myDrawer,V,P);
130}
131
132//=======================================================================
133//function : ComputeTwoEdgesConcentric
134//purpose :
135//=======================================================================
136void AIS_ConcentricRelation::ComputeTwoVerticesConcentric(const Handle(Prs3d_Presentation)& aPresentation)
137{
138 TopoDS_Vertex V1,V2;
139 V1 = TopoDS::Vertex(myFShape);
140 V2 = TopoDS::Vertex(myFShape);
141 Standard_Boolean isOnPlanVertex1(Standard_True),isOnPlanVertex2(Standard_True);
142 gp_Pnt P1,P2;
143 AIS::ComputeGeometry(V1,P1, myPlane,isOnPlanVertex1);
144 AIS::ComputeGeometry(V2,P2, myPlane,isOnPlanVertex2);
145 myCenter = P1;
146 myRad = 15.;
147 gp_Dir vec(myPlane->Pln().Position().XDirection());
148 gp_Vec vectrans(vec);
149 myPnt = myCenter.Translated(vectrans.Multiplied(myRad));
150 DsgPrs_ConcentricPresentation::Add(aPresentation,myDrawer,myCenter,myRad,myDir,myPnt);
151 if (!isOnPlanVertex1) AIS::ComputeProjVertexPresentation(aPresentation,myDrawer,V1,P1);
b804b20e 152 if (!isOnPlanVertex2) AIS::ComputeProjVertexPresentation(aPresentation,myDrawer,V2,P2);
7fd59977 153}
154
155//=======================================================================
156//function : ComputeTwoEdgesConcentric
157//purpose :
158//=======================================================================
159void AIS_ConcentricRelation::ComputeTwoEdgesConcentric(const Handle(Prs3d_Presentation)& aPresentation)
160{
161 BRepAdaptor_Curve curv1(TopoDS::Edge(myFShape));
162 BRepAdaptor_Curve curv2(TopoDS::Edge(mySShape));
163
164 gp_Pnt ptat11,ptat12,ptat21,ptat22;
165 Handle(Geom_Curve) geom1,geom2;
166 Standard_Boolean isInfinite1,isInfinite2;
167 Handle(Geom_Curve) extCurv;
168 if (!AIS::ComputeGeometry(TopoDS::Edge(myFShape),
169 TopoDS::Edge(mySShape),
170 myExtShape,
171 geom1,
172 geom2,
173 ptat11,
174 ptat12,
175 ptat21,
176 ptat22,
177 extCurv,
178 isInfinite1,isInfinite2,
179 myPlane)) {
180 return;
181 }
182
c5f3a425 183 Handle(Geom_Circle) gcirc1 (Handle(Geom_Circle)::DownCast (geom1));
184 Handle(Geom_Circle) gcirc2 (Handle(Geom_Circle)::DownCast (geom2));
7fd59977 185
186 myCenter = gcirc1->Location();
187
81bba717 188 // choose the radius equal to 1/5 of the smallest radius of
189 // 2 circles. Limit is imposed ( 0.02 by chance)
7fd59977 190 Standard_Real rad1 = gcirc1->Radius();
191 Standard_Real rad2 = gcirc2->Radius();
192 myRad = (rad1 > rad2 ) ? rad2 : rad1;
193 myRad /= 5;
194 if (myRad > 15.) myRad =15.;
195
196
81bba717 197 //Calculate a point of circle of radius myRad
7fd59977 198 gp_Dir vec(ptat11.XYZ() - myCenter.XYZ() );
199 gp_Vec vectrans(vec);
200 myPnt = myCenter.Translated(vectrans.Multiplied(myRad));
201
202 DsgPrs_ConcentricPresentation::Add(aPresentation,
203 myDrawer,
204 myCenter,
205 myRad,
206 myDir,
207 myPnt);
208 if ( (myExtShape != 0) && !extCurv.IsNull()) {
209 gp_Pnt pf, pl;
210 if ( myExtShape == 1 ) {
211 if (!isInfinite1) {
212 pf = ptat11;
213 pl = ptat12;
214 }
215 ComputeProjEdgePresentation(aPresentation,TopoDS::Edge(myFShape),gcirc1,pf,pl);
216 }
217 else {
218 if (!isInfinite2) {
219 pf = ptat21;
220 pl = ptat22;
221 }
222 ComputeProjEdgePresentation(aPresentation,TopoDS::Edge(mySShape),gcirc2,pf,pl);
223 }
224 }
225}
226
227//=======================================================================
228//function : Compute
229//purpose : to avoid warning
230//=======================================================================
231
232void AIS_ConcentricRelation::Compute(const Handle(Prs3d_Projector)&,
233 const Handle(Prs3d_Presentation)&)
234{
235}
236
237//=======================================================================
7fd59977 238//function : ComputeSelection
239//purpose :
240//=======================================================================
241
242void AIS_ConcentricRelation::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
243 const Standard_Integer)
244{
245 Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
246
81bba717 247 //Creation of 2 sensitive circles
248 // the greater
7fd59977 249 gp_Ax2 ax(myCenter, myDir);
250 Handle(Geom_Circle) Circ = new Geom_Circle(ax, myRad) ;
251 Handle(Select3D_SensitiveCircle)
252 sensit = new Select3D_SensitiveCircle (own,
253 Circ);
254 aSelection->Add(sensit);
81bba717 255 // the smaller
7fd59977 256 Circ->SetRadius(myRad/2);
257 sensit = new Select3D_SensitiveCircle (own,
258 Circ);
259 aSelection->Add(sensit);
260
81bba717 261 //Creation of 2 segments sensitive for the cross
7fd59977 262 Handle(Select3D_SensitiveSegment) seg;
263 gp_Pnt otherPnt = myPnt.Mirrored(myCenter);
264 seg = new Select3D_SensitiveSegment(own,
265 otherPnt,
266 myPnt);
267 aSelection->Add(seg);
268
269 gp_Ax1 RotateAxis(myCenter, myDir);
c6541a0c
D
270 gp_Pnt FPnt = myCenter.Rotated(RotateAxis, M_PI/2);
271 gp_Pnt SPnt = myCenter.Rotated(RotateAxis, -M_PI/2);
7fd59977 272 seg = new Select3D_SensitiveSegment(own,
273 FPnt,
274 SPnt);
275 aSelection->Add(seg);
276
277}
278