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