1 // Created on: 1996-12-05
2 // Created by: Flore Lantheaume/Odile Olivier
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
22 #include <Standard_NotImplemented.hxx>
24 #include <AIS_ConcentricRelation.ixx>
26 #include <SelectMgr_EntityOwner.hxx>
27 #include <Select3D_SensitiveCircle.hxx>
28 #include <Select3D_SensitiveSegment.hxx>
30 #include <DsgPrs_ConcentricPresentation.hxx>
34 #include <BRepAdaptor_Curve.hxx>
36 #include <GeomAbs_CurveType.hxx>
37 #include <Geom_Circle.hxx>
45 #include <TopoDS_Vertex.hxx>
48 //=======================================================================
49 //function : Constructor
51 //=======================================================================
53 AIS_ConcentricRelation::AIS_ConcentricRelation(
54 const TopoDS_Shape& aFShape,
55 const TopoDS_Shape& aSShape,
56 const Handle(Geom_Plane)& aPlane)
61 myDir = aPlane->Pln().Axis().Direction();
64 //=======================================================================
67 //=======================================================================
68 void AIS_ConcentricRelation::Compute(const Handle(PrsMgr_PresentationManager3d)&,
69 const Handle(Prs3d_Presentation)& aPresentation,
70 const Standard_Integer)
72 aPresentation->Clear();
74 TopAbs_ShapeEnum type2(mySShape.ShapeType());
75 aPresentation->SetInfiniteState(Standard_True);
76 switch (myFShape.ShapeType()) {
79 if (type2 == TopAbs_EDGE) ComputeTwoEdgesConcentric(aPresentation);
80 else if (type2 == TopAbs_VERTEX) ComputeEdgeVertexConcentric(aPresentation);
86 if (type2 == TopAbs_VERTEX) ComputeTwoVerticesConcentric(aPresentation);
87 else if (type2 == TopAbs_EDGE) ComputeEdgeVertexConcentric(aPresentation);
94 void AIS_ConcentricRelation::Compute(const Handle_Prs3d_Projector& aProjector, const Handle_Geom_Transformation& aTransformation, const Handle_Prs3d_Presentation& aPresentation)
96 // Standard_NotImplemented::Raise("AIS_ConcentricRelation::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
97 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
100 //=======================================================================
101 //function : ComputeTwoEdgesConcentric
103 //=======================================================================
104 void AIS_ConcentricRelation::ComputeEdgeVertexConcentric(const Handle(Prs3d_Presentation)& aPresentation)
108 if (myFShape.ShapeType() == TopAbs_EDGE) {
109 E = TopoDS::Edge(myFShape);
110 V = TopoDS::Vertex(mySShape);
113 E = TopoDS::Edge(mySShape);
114 V = TopoDS::Vertex(myFShape);
117 Handle(Geom_Curve) C;
118 Handle(Geom_Curve) extCurv;
119 Standard_Boolean isInfinite;
120 Standard_Boolean isOnPlanEdge, isOnPlanVertex;
121 if (!AIS::ComputeGeometry(E,C,p1,p2,extCurv,isInfinite,isOnPlanEdge,myPlane)) return;
123 AIS::ComputeGeometry(V,P, myPlane, isOnPlanVertex);
125 const Handle(Geom_Circle)& CIRCLE = (Handle(Geom_Circle)&) C;
126 myCenter = CIRCLE->Location();
127 myRad = Min(CIRCLE->Radius()/5.,15.);
128 gp_Dir vec(p1.XYZ() - myCenter.XYZ() );
129 gp_Vec vectrans(vec);
130 myPnt = myCenter.Translated(vectrans.Multiplied(myRad));
131 DsgPrs_ConcentricPresentation::Add(aPresentation,myDrawer,myCenter,myRad,myDir,myPnt);
132 if (!isOnPlanEdge) AIS::ComputeProjEdgePresentation(aPresentation,myDrawer,E,CIRCLE,p1,p2);
133 if (!isOnPlanVertex) AIS::ComputeProjVertexPresentation(aPresentation,myDrawer,V,P);
136 //=======================================================================
137 //function : ComputeTwoEdgesConcentric
139 //=======================================================================
140 void AIS_ConcentricRelation::ComputeTwoVerticesConcentric(const Handle(Prs3d_Presentation)& aPresentation)
143 V1 = TopoDS::Vertex(myFShape);
144 V2 = TopoDS::Vertex(myFShape);
145 Standard_Boolean isOnPlanVertex1(Standard_True),isOnPlanVertex2(Standard_True);
147 AIS::ComputeGeometry(V1,P1, myPlane,isOnPlanVertex1);
148 AIS::ComputeGeometry(V2,P2, myPlane,isOnPlanVertex2);
151 gp_Dir vec(myPlane->Pln().Position().XDirection());
152 gp_Vec vectrans(vec);
153 myPnt = myCenter.Translated(vectrans.Multiplied(myRad));
154 DsgPrs_ConcentricPresentation::Add(aPresentation,myDrawer,myCenter,myRad,myDir,myPnt);
155 if (!isOnPlanVertex1) AIS::ComputeProjVertexPresentation(aPresentation,myDrawer,V1,P1);
156 if (!isOnPlanVertex2) AIS::ComputeProjVertexPresentation(aPresentation,myDrawer,V2,P2);
159 //=======================================================================
160 //function : ComputeTwoEdgesConcentric
162 //=======================================================================
163 void AIS_ConcentricRelation::ComputeTwoEdgesConcentric(const Handle(Prs3d_Presentation)& aPresentation)
165 BRepAdaptor_Curve curv1(TopoDS::Edge(myFShape));
166 BRepAdaptor_Curve curv2(TopoDS::Edge(mySShape));
168 gp_Pnt ptat11,ptat12,ptat21,ptat22;
169 Handle(Geom_Curve) geom1,geom2;
170 Standard_Boolean isInfinite1,isInfinite2;
171 Handle(Geom_Curve) extCurv;
172 if (!AIS::ComputeGeometry(TopoDS::Edge(myFShape),
173 TopoDS::Edge(mySShape),
182 isInfinite1,isInfinite2,
187 const Handle(Geom_Circle)& gcirc1 = (Handle(Geom_Circle)&) geom1;
188 const Handle(Geom_Circle)& gcirc2 = (Handle(Geom_Circle)&) geom2;
190 myCenter = gcirc1->Location();
192 // choose the radius equal to 1/5 of the smallest radius of
193 // 2 circles. Limit is imposed ( 0.02 by chance)
194 Standard_Real rad1 = gcirc1->Radius();
195 Standard_Real rad2 = gcirc2->Radius();
196 myRad = (rad1 > rad2 ) ? rad2 : rad1;
198 if (myRad > 15.) myRad =15.;
201 //Calculate a point of circle of radius myRad
202 gp_Dir vec(ptat11.XYZ() - myCenter.XYZ() );
203 gp_Vec vectrans(vec);
204 myPnt = myCenter.Translated(vectrans.Multiplied(myRad));
206 DsgPrs_ConcentricPresentation::Add(aPresentation,
212 if ( (myExtShape != 0) && !extCurv.IsNull()) {
214 if ( myExtShape == 1 ) {
219 ComputeProjEdgePresentation(aPresentation,TopoDS::Edge(myFShape),gcirc1,pf,pl);
226 ComputeProjEdgePresentation(aPresentation,TopoDS::Edge(mySShape),gcirc2,pf,pl);
231 //=======================================================================
233 //purpose : to avoid warning
234 //=======================================================================
236 void AIS_ConcentricRelation::Compute(const Handle(Prs3d_Projector)&,
237 const Handle(Prs3d_Presentation)&)
241 //=======================================================================
243 //purpose : to avoid warning
244 //=======================================================================
246 void AIS_ConcentricRelation::Compute(const Handle(PrsMgr_PresentationManager2d)&,
247 const Handle(Graphic2d_GraphicObject)&,
248 const Standard_Integer)
252 //=======================================================================
253 //function : ComputeSelection
255 //=======================================================================
257 void AIS_ConcentricRelation::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
258 const Standard_Integer)
260 Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
262 //Creation of 2 sensitive circles
264 gp_Ax2 ax(myCenter, myDir);
265 Handle(Geom_Circle) Circ = new Geom_Circle(ax, myRad) ;
266 Handle(Select3D_SensitiveCircle)
267 sensit = new Select3D_SensitiveCircle (own,
269 aSelection->Add(sensit);
271 Circ->SetRadius(myRad/2);
272 sensit = new Select3D_SensitiveCircle (own,
274 aSelection->Add(sensit);
276 //Creation of 2 segments sensitive for the cross
277 Handle(Select3D_SensitiveSegment) seg;
278 gp_Pnt otherPnt = myPnt.Mirrored(myCenter);
279 seg = new Select3D_SensitiveSegment(own,
282 aSelection->Add(seg);
284 gp_Ax1 RotateAxis(myCenter, myDir);
285 gp_Pnt FPnt = myCenter.Rotated(RotateAxis, M_PI/2);
286 gp_Pnt SPnt = myCenter.Rotated(RotateAxis, -M_PI/2);
287 seg = new Select3D_SensitiveSegment(own,
290 aSelection->Add(seg);