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 <PrsDim_ConcentricRelation.hxx>
20 #include <BRepAdaptor_Curve.hxx>
21 #include <DsgPrs_ConcentricPresentation.hxx>
22 #include <Geom_Circle.hxx>
23 #include <Geom_Plane.hxx>
24 #include <GeomAbs_CurveType.hxx>
31 #include <Prs3d_Presentation.hxx>
32 #include <Select3D_SensitiveCircle.hxx>
33 #include <Select3D_SensitiveSegment.hxx>
34 #include <SelectMgr_EntityOwner.hxx>
35 #include <SelectMgr_Selection.hxx>
36 #include <Standard_NotImplemented.hxx>
38 #include <TopoDS_Shape.hxx>
39 #include <TopoDS_Vertex.hxx>
41 IMPLEMENT_STANDARD_RTTIEXT(PrsDim_ConcentricRelation, PrsDim_Relation)
43 //=======================================================================
44 //function : Constructor
46 //=======================================================================
47 PrsDim_ConcentricRelation::PrsDim_ConcentricRelation(
48 const TopoDS_Shape& aFShape,
49 const TopoDS_Shape& aSShape,
50 const Handle(Geom_Plane)& aPlane)
55 myDir = aPlane->Pln().Axis().Direction();
58 //=======================================================================
61 //=======================================================================
62 void PrsDim_ConcentricRelation::Compute(const Handle(PrsMgr_PresentationManager3d)&,
63 const Handle(Prs3d_Presentation)& aPresentation,
64 const Standard_Integer)
66 TopAbs_ShapeEnum type2(mySShape.ShapeType());
67 aPresentation->SetInfiniteState(Standard_True);
68 switch (myFShape.ShapeType()) {
71 if (type2 == TopAbs_EDGE) ComputeTwoEdgesConcentric(aPresentation);
72 else if (type2 == TopAbs_VERTEX) ComputeEdgeVertexConcentric(aPresentation);
78 if (type2 == TopAbs_VERTEX) ComputeTwoVerticesConcentric(aPresentation);
79 else if (type2 == TopAbs_EDGE) ComputeEdgeVertexConcentric(aPresentation);
86 //=======================================================================
87 //function : ComputeTwoEdgesConcentric
89 //=======================================================================
90 void PrsDim_ConcentricRelation::ComputeEdgeVertexConcentric(const Handle(Prs3d_Presentation)& aPresentation)
94 if (myFShape.ShapeType() == TopAbs_EDGE) {
95 E = TopoDS::Edge(myFShape);
96 V = TopoDS::Vertex(mySShape);
99 E = TopoDS::Edge(mySShape);
100 V = TopoDS::Vertex(myFShape);
103 Handle(Geom_Curve) C;
104 Handle(Geom_Curve) extCurv;
105 Standard_Boolean isInfinite;
106 Standard_Boolean isOnPlanEdge, isOnPlanVertex;
107 if (!PrsDim::ComputeGeometry(E,C,p1,p2,extCurv,isInfinite,isOnPlanEdge,myPlane)) return;
109 PrsDim::ComputeGeometry(V,P, myPlane, isOnPlanVertex);
111 Handle(Geom_Circle) CIRCLE (Handle(Geom_Circle)::DownCast (C));
112 myCenter = CIRCLE->Location();
113 myRad = Min(CIRCLE->Radius()/5.,15.);
114 gp_Dir vec(p1.XYZ() - myCenter.XYZ() );
115 gp_Vec vectrans(vec);
116 myPnt = myCenter.Translated(vectrans.Multiplied(myRad));
117 DsgPrs_ConcentricPresentation::Add(aPresentation,myDrawer,myCenter,myRad,myDir,myPnt);
118 if (!isOnPlanEdge) PrsDim::ComputeProjEdgePresentation(aPresentation,myDrawer,E,CIRCLE,p1,p2);
119 if (!isOnPlanVertex) PrsDim::ComputeProjVertexPresentation(aPresentation,myDrawer,V,P);
122 //=======================================================================
123 //function : ComputeTwoEdgesConcentric
125 //=======================================================================
126 void PrsDim_ConcentricRelation::ComputeTwoVerticesConcentric(const Handle(Prs3d_Presentation)& aPresentation)
129 V1 = TopoDS::Vertex(myFShape);
130 V2 = TopoDS::Vertex(myFShape);
131 Standard_Boolean isOnPlanVertex1(Standard_True),isOnPlanVertex2(Standard_True);
133 PrsDim::ComputeGeometry(V1,P1, myPlane,isOnPlanVertex1);
134 PrsDim::ComputeGeometry(V2,P2, myPlane,isOnPlanVertex2);
137 gp_Dir vec(myPlane->Pln().Position().XDirection());
138 gp_Vec vectrans(vec);
139 myPnt = myCenter.Translated(vectrans.Multiplied(myRad));
140 DsgPrs_ConcentricPresentation::Add(aPresentation,myDrawer,myCenter,myRad,myDir,myPnt);
141 if (!isOnPlanVertex1) PrsDim::ComputeProjVertexPresentation(aPresentation,myDrawer,V1,P1);
142 if (!isOnPlanVertex2) PrsDim::ComputeProjVertexPresentation(aPresentation,myDrawer,V2,P2);
145 //=======================================================================
146 //function : ComputeTwoEdgesConcentric
148 //=======================================================================
149 void PrsDim_ConcentricRelation::ComputeTwoEdgesConcentric(const Handle(Prs3d_Presentation)& aPresentation)
151 BRepAdaptor_Curve curv1(TopoDS::Edge(myFShape));
152 BRepAdaptor_Curve curv2(TopoDS::Edge(mySShape));
154 gp_Pnt ptat11,ptat12,ptat21,ptat22;
155 Handle(Geom_Curve) geom1,geom2;
156 Standard_Boolean isInfinite1,isInfinite2;
157 Handle(Geom_Curve) extCurv;
158 if (!PrsDim::ComputeGeometry(TopoDS::Edge(myFShape), TopoDS::Edge(mySShape),
164 isInfinite1,isInfinite2,
169 Handle(Geom_Circle) gcirc1 (Handle(Geom_Circle)::DownCast (geom1));
170 Handle(Geom_Circle) gcirc2 (Handle(Geom_Circle)::DownCast (geom2));
172 myCenter = gcirc1->Location();
174 // choose the radius equal to 1/5 of the smallest radius of
175 // 2 circles. Limit is imposed ( 0.02 by chance)
176 Standard_Real aRad1 = gcirc1->Radius();
177 Standard_Real aRad2 = gcirc2->Radius();
178 myRad = (aRad1 > aRad2 ) ? aRad2 : aRad1;
180 if (myRad > 15.) myRad =15.;
183 //Calculate a point of circle of radius myRad
184 gp_Dir vec(ptat11.XYZ() - myCenter.XYZ() );
185 gp_Vec vectrans(vec);
186 myPnt = myCenter.Translated(vectrans.Multiplied(myRad));
188 DsgPrs_ConcentricPresentation::Add(aPresentation,
194 if ( (myExtShape != 0) && !extCurv.IsNull()) {
196 if ( myExtShape == 1 ) {
201 ComputeProjEdgePresentation(aPresentation,TopoDS::Edge(myFShape),gcirc1,pf,pl);
208 ComputeProjEdgePresentation(aPresentation,TopoDS::Edge(mySShape),gcirc2,pf,pl);
213 //=======================================================================
214 //function : ComputeSelection
216 //=======================================================================
218 void PrsDim_ConcentricRelation::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
219 const Standard_Integer)
221 Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
223 //Creation of 2 sensitive circles
225 gp_Ax2 ax(myCenter, myDir);
226 Handle(Geom_Circle) Circ = new Geom_Circle(ax, myRad) ;
227 Handle(Select3D_SensitiveCircle)
228 sensit = new Select3D_SensitiveCircle (own,
230 aSelection->Add(sensit);
232 Circ->SetRadius(myRad/2);
233 sensit = new Select3D_SensitiveCircle (own,
235 aSelection->Add(sensit);
237 //Creation of 2 segments sensitive for the cross
238 Handle(Select3D_SensitiveSegment) seg;
239 gp_Pnt otherPnt = myPnt.Mirrored(myCenter);
240 seg = new Select3D_SensitiveSegment(own,
243 aSelection->Add(seg);
245 gp_Ax1 RotateAxis(myCenter, myDir);
246 gp_Pnt FPnt = myCenter.Rotated(RotateAxis, M_PI/2);
247 gp_Pnt SPnt = myCenter.Rotated(RotateAxis, -M_PI/2);
248 seg = new Select3D_SensitiveSegment(own,
251 aSelection->Add(seg);