1 // Created on: 1996-12-05
2 // Created by: Flore Lantheaume/Odile Olivier
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
19 #include <AIS_ConcentricRelation.hxx>
20 #include <BRepAdaptor_Curve.hxx>
21 #include <DsgPrs_ConcentricPresentation.hxx>
22 #include <Geom_Circle.hxx>
23 #include <Geom_Plane.hxx>
24 #include <Geom_Transformation.hxx>
25 #include <GeomAbs_CurveType.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>
41 #include <TopoDS_Shape.hxx>
42 #include <TopoDS_Vertex.hxx>
44 IMPLEMENT_STANDARD_RTTIEXT(AIS_ConcentricRelation,AIS_Relation)
46 //=======================================================================
47 //function : Constructor
49 //=======================================================================
50 AIS_ConcentricRelation::AIS_ConcentricRelation(
51 const TopoDS_Shape& aFShape,
52 const TopoDS_Shape& aSShape,
53 const Handle(Geom_Plane)& aPlane)
58 myDir = aPlane->Pln().Axis().Direction();
61 //=======================================================================
64 //=======================================================================
65 void AIS_ConcentricRelation::Compute(const Handle(PrsMgr_PresentationManager3d)&,
66 const Handle(Prs3d_Presentation)& aPresentation,
67 const Standard_Integer)
69 aPresentation->Clear();
71 TopAbs_ShapeEnum type2(mySShape.ShapeType());
72 aPresentation->SetInfiniteState(Standard_True);
73 switch (myFShape.ShapeType()) {
76 if (type2 == TopAbs_EDGE) ComputeTwoEdgesConcentric(aPresentation);
77 else if (type2 == TopAbs_VERTEX) ComputeEdgeVertexConcentric(aPresentation);
83 if (type2 == TopAbs_VERTEX) ComputeTwoVerticesConcentric(aPresentation);
84 else if (type2 == TopAbs_EDGE) ComputeEdgeVertexConcentric(aPresentation);
91 void AIS_ConcentricRelation::Compute(const Handle(Prs3d_Projector)& aProjector, const Handle(Geom_Transformation)& aTransformation, const Handle(Prs3d_Presentation)& aPresentation)
93 // Standard_NotImplemented::Raise("AIS_ConcentricRelation::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)");
94 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
97 //=======================================================================
98 //function : ComputeTwoEdgesConcentric
100 //=======================================================================
101 void AIS_ConcentricRelation::ComputeEdgeVertexConcentric(const Handle(Prs3d_Presentation)& aPresentation)
105 if (myFShape.ShapeType() == TopAbs_EDGE) {
106 E = TopoDS::Edge(myFShape);
107 V = TopoDS::Vertex(mySShape);
110 E = TopoDS::Edge(mySShape);
111 V = TopoDS::Vertex(myFShape);
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;
120 AIS::ComputeGeometry(V,P, myPlane, isOnPlanVertex);
122 Handle(Geom_Circle) CIRCLE (Handle(Geom_Circle)::DownCast (C));
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);
133 //=======================================================================
134 //function : ComputeTwoEdgesConcentric
136 //=======================================================================
137 void AIS_ConcentricRelation::ComputeTwoVerticesConcentric(const Handle(Prs3d_Presentation)& aPresentation)
140 V1 = TopoDS::Vertex(myFShape);
141 V2 = TopoDS::Vertex(myFShape);
142 Standard_Boolean isOnPlanVertex1(Standard_True),isOnPlanVertex2(Standard_True);
144 AIS::ComputeGeometry(V1,P1, myPlane,isOnPlanVertex1);
145 AIS::ComputeGeometry(V2,P2, myPlane,isOnPlanVertex2);
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);
153 if (!isOnPlanVertex2) AIS::ComputeProjVertexPresentation(aPresentation,myDrawer,V2,P2);
156 //=======================================================================
157 //function : ComputeTwoEdgesConcentric
159 //=======================================================================
160 void AIS_ConcentricRelation::ComputeTwoEdgesConcentric(const Handle(Prs3d_Presentation)& aPresentation)
162 BRepAdaptor_Curve curv1(TopoDS::Edge(myFShape));
163 BRepAdaptor_Curve curv2(TopoDS::Edge(mySShape));
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),
179 isInfinite1,isInfinite2,
184 Handle(Geom_Circle) gcirc1 (Handle(Geom_Circle)::DownCast (geom1));
185 Handle(Geom_Circle) gcirc2 (Handle(Geom_Circle)::DownCast (geom2));
187 myCenter = gcirc1->Location();
189 // choose the radius equal to 1/5 of the smallest radius of
190 // 2 circles. Limit is imposed ( 0.02 by chance)
191 Standard_Real rad1 = gcirc1->Radius();
192 Standard_Real rad2 = gcirc2->Radius();
193 myRad = (rad1 > rad2 ) ? rad2 : rad1;
195 if (myRad > 15.) myRad =15.;
198 //Calculate a point of circle of radius myRad
199 gp_Dir vec(ptat11.XYZ() - myCenter.XYZ() );
200 gp_Vec vectrans(vec);
201 myPnt = myCenter.Translated(vectrans.Multiplied(myRad));
203 DsgPrs_ConcentricPresentation::Add(aPresentation,
209 if ( (myExtShape != 0) && !extCurv.IsNull()) {
211 if ( myExtShape == 1 ) {
216 ComputeProjEdgePresentation(aPresentation,TopoDS::Edge(myFShape),gcirc1,pf,pl);
223 ComputeProjEdgePresentation(aPresentation,TopoDS::Edge(mySShape),gcirc2,pf,pl);
228 //=======================================================================
230 //purpose : to avoid warning
231 //=======================================================================
233 void AIS_ConcentricRelation::Compute(const Handle(Prs3d_Projector)&,
234 const Handle(Prs3d_Presentation)&)
238 //=======================================================================
239 //function : ComputeSelection
241 //=======================================================================
243 void AIS_ConcentricRelation::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
244 const Standard_Integer)
246 Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
248 //Creation of 2 sensitive circles
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,
255 aSelection->Add(sensit);
257 Circ->SetRadius(myRad/2);
258 sensit = new Select3D_SensitiveCircle (own,
260 aSelection->Add(sensit);
262 //Creation of 2 segments sensitive for the cross
263 Handle(Select3D_SensitiveSegment) seg;
264 gp_Pnt otherPnt = myPnt.Mirrored(myCenter);
265 seg = new Select3D_SensitiveSegment(own,
268 aSelection->Add(seg);
270 gp_Ax1 RotateAxis(myCenter, myDir);
271 gp_Pnt FPnt = myCenter.Rotated(RotateAxis, M_PI/2);
272 gp_Pnt SPnt = myCenter.Rotated(RotateAxis, -M_PI/2);
273 seg = new Select3D_SensitiveSegment(own,
276 aSelection->Add(seg);