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