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.
17 #include <Standard_NotImplemented.hxx>
19 #include <AIS_ConcentricRelation.ixx>
21 #include <SelectMgr_EntityOwner.hxx>
22 #include <Select3D_SensitiveCircle.hxx>
23 #include <Select3D_SensitiveSegment.hxx>
25 #include <DsgPrs_ConcentricPresentation.hxx>
29 #include <BRepAdaptor_Curve.hxx>
31 #include <GeomAbs_CurveType.hxx>
32 #include <Geom_Circle.hxx>
40 #include <TopoDS_Vertex.hxx>
43 //=======================================================================
44 //function : Constructor
46 //=======================================================================
48 AIS_ConcentricRelation::AIS_ConcentricRelation(
49 const TopoDS_Shape& aFShape,
50 const TopoDS_Shape& aSShape,
51 const Handle(Geom_Plane)& aPlane)
56 myDir = aPlane->Pln().Axis().Direction();
59 //=======================================================================
62 //=======================================================================
63 void AIS_ConcentricRelation::Compute(const Handle(PrsMgr_PresentationManager3d)&,
64 const Handle(Prs3d_Presentation)& aPresentation,
65 const Standard_Integer)
67 aPresentation->Clear();
69 TopAbs_ShapeEnum type2(mySShape.ShapeType());
70 aPresentation->SetInfiniteState(Standard_True);
71 switch (myFShape.ShapeType()) {
74 if (type2 == TopAbs_EDGE) ComputeTwoEdgesConcentric(aPresentation);
75 else if (type2 == TopAbs_VERTEX) ComputeEdgeVertexConcentric(aPresentation);
81 if (type2 == TopAbs_VERTEX) ComputeTwoVerticesConcentric(aPresentation);
82 else if (type2 == TopAbs_EDGE) ComputeEdgeVertexConcentric(aPresentation);
89 void AIS_ConcentricRelation::Compute(const Handle(Prs3d_Projector)& aProjector, const Handle(Geom_Transformation)& aTransformation, const Handle(Prs3d_Presentation)& aPresentation)
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 ) ;
95 //=======================================================================
96 //function : ComputeTwoEdgesConcentric
98 //=======================================================================
99 void AIS_ConcentricRelation::ComputeEdgeVertexConcentric(const Handle(Prs3d_Presentation)& aPresentation)
103 if (myFShape.ShapeType() == TopAbs_EDGE) {
104 E = TopoDS::Edge(myFShape);
105 V = TopoDS::Vertex(mySShape);
108 E = TopoDS::Edge(mySShape);
109 V = TopoDS::Vertex(myFShape);
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;
118 AIS::ComputeGeometry(V,P, myPlane, isOnPlanVertex);
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);
131 //=======================================================================
132 //function : ComputeTwoEdgesConcentric
134 //=======================================================================
135 void AIS_ConcentricRelation::ComputeTwoVerticesConcentric(const Handle(Prs3d_Presentation)& aPresentation)
138 V1 = TopoDS::Vertex(myFShape);
139 V2 = TopoDS::Vertex(myFShape);
140 Standard_Boolean isOnPlanVertex1(Standard_True),isOnPlanVertex2(Standard_True);
142 AIS::ComputeGeometry(V1,P1, myPlane,isOnPlanVertex1);
143 AIS::ComputeGeometry(V2,P2, myPlane,isOnPlanVertex2);
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);
151 if (!isOnPlanVertex2) AIS::ComputeProjVertexPresentation(aPresentation,myDrawer,V2,P2);
154 //=======================================================================
155 //function : ComputeTwoEdgesConcentric
157 //=======================================================================
158 void AIS_ConcentricRelation::ComputeTwoEdgesConcentric(const Handle(Prs3d_Presentation)& aPresentation)
160 BRepAdaptor_Curve curv1(TopoDS::Edge(myFShape));
161 BRepAdaptor_Curve curv2(TopoDS::Edge(mySShape));
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),
177 isInfinite1,isInfinite2,
182 const Handle(Geom_Circle)& gcirc1 = (Handle(Geom_Circle)&) geom1;
183 const Handle(Geom_Circle)& gcirc2 = (Handle(Geom_Circle)&) geom2;
185 myCenter = gcirc1->Location();
187 // choose the radius equal to 1/5 of the smallest radius of
188 // 2 circles. Limit is imposed ( 0.02 by chance)
189 Standard_Real rad1 = gcirc1->Radius();
190 Standard_Real rad2 = gcirc2->Radius();
191 myRad = (rad1 > rad2 ) ? rad2 : rad1;
193 if (myRad > 15.) myRad =15.;
196 //Calculate a point of circle of radius myRad
197 gp_Dir vec(ptat11.XYZ() - myCenter.XYZ() );
198 gp_Vec vectrans(vec);
199 myPnt = myCenter.Translated(vectrans.Multiplied(myRad));
201 DsgPrs_ConcentricPresentation::Add(aPresentation,
207 if ( (myExtShape != 0) && !extCurv.IsNull()) {
209 if ( myExtShape == 1 ) {
214 ComputeProjEdgePresentation(aPresentation,TopoDS::Edge(myFShape),gcirc1,pf,pl);
221 ComputeProjEdgePresentation(aPresentation,TopoDS::Edge(mySShape),gcirc2,pf,pl);
226 //=======================================================================
228 //purpose : to avoid warning
229 //=======================================================================
231 void AIS_ConcentricRelation::Compute(const Handle(Prs3d_Projector)&,
232 const Handle(Prs3d_Presentation)&)
236 //=======================================================================
237 //function : ComputeSelection
239 //=======================================================================
241 void AIS_ConcentricRelation::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
242 const Standard_Integer)
244 Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
246 //Creation of 2 sensitive circles
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,
253 aSelection->Add(sensit);
255 Circ->SetRadius(myRad/2);
256 sensit = new Select3D_SensitiveCircle (own,
258 aSelection->Add(sensit);
260 //Creation of 2 segments sensitive for the cross
261 Handle(Select3D_SensitiveSegment) seg;
262 gp_Pnt otherPnt = myPnt.Mirrored(myCenter);
263 seg = new Select3D_SensitiveSegment(own,
266 aSelection->Add(seg);
268 gp_Ax1 RotateAxis(myCenter, myDir);
269 gp_Pnt FPnt = myCenter.Rotated(RotateAxis, M_PI/2);
270 gp_Pnt SPnt = myCenter.Rotated(RotateAxis, -M_PI/2);
271 seg = new Select3D_SensitiveSegment(own,
274 aSelection->Add(seg);