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