1 // Created on: 1996-12-05
2 // Created by: Jean-Pierre COMBE/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_PerpendicularRelation.hxx>
20 #include <BRep_Tool.hxx>
21 #include <BRepAdaptor_Surface.hxx>
22 #include <BRepBuilderAPI_MakeFace.hxx>
23 #include <DsgPrs_PerpenPresentation.hxx>
25 #include <gce_MakeDir.hxx>
26 #include <Geom2d_Line.hxx>
27 #include <Geom_Ellipse.hxx>
28 #include <Geom_Line.hxx>
29 #include <Geom_Plane.hxx>
30 #include <Geom_Transformation.hxx>
31 #include <GeomAPI.hxx>
34 #include <gp_Pnt2d.hxx>
35 #include <gp_Trsf.hxx>
37 #include <IntAna2d_AnaIntersection.hxx>
38 #include <IntAna2d_IntPoint.hxx>
39 #include <Precision.hxx>
40 #include <Prs3d_Presentation.hxx>
41 #include <Prs3d_Projector.hxx>
42 #include <Select3D_SensitiveSegment.hxx>
43 #include <SelectMgr_EntityOwner.hxx>
44 #include <SelectMgr_Selection.hxx>
45 #include <Standard_NotImplemented.hxx>
46 #include <Standard_Type.hxx>
48 #include <TopoDS_Edge.hxx>
49 #include <TopoDS_Face.hxx>
50 #include <TopoDS_Shape.hxx>
51 #include <TopoDS_Vertex.hxx>
53 IMPLEMENT_STANDARD_RTTIEXT(AIS_PerpendicularRelation,AIS_Relation)
55 //=======================================================================
56 //function : Constructor
57 //purpose : TwoEdgesPerpendicular
58 //=======================================================================
59 AIS_PerpendicularRelation::AIS_PerpendicularRelation(const TopoDS_Shape& aFShape,
60 const TopoDS_Shape& aSShape,
61 const Handle(Geom_Plane)& aPlane)
69 //=======================================================================
70 //function : Constructor
71 //purpose : TwoFacesPerpendicular
72 //=======================================================================
73 AIS_PerpendicularRelation::AIS_PerpendicularRelation(const TopoDS_Shape& aFShape,
74 const TopoDS_Shape& aSShape)
81 //=======================================================================
84 //=======================================================================
85 void AIS_PerpendicularRelation::Compute(const Handle(PrsMgr_PresentationManager3d)&,
86 const Handle(Prs3d_Presentation)& aPresentation,
87 const Standard_Integer)
89 if (myFShape.ShapeType() == mySShape.ShapeType()) {
90 switch (myFShape.ShapeType()) {
93 // cas perpendiculaire entre deux faces
94 ComputeTwoFacesPerpendicular(aPresentation);
99 // cas perpendiculaire entre deux edges
100 ComputeTwoEdgesPerpendicular(aPresentation);
107 // Cas pas traite - Edge/Face
110 //=======================================================================
112 //purpose : to avoid warning
113 //=======================================================================
114 void AIS_PerpendicularRelation::Compute(const Handle(Prs3d_Projector)& aProjector,
115 const Handle(Prs3d_Presentation)& aPresentation)
117 // Standard_NotImplemented::Raise("AIS_PerpendicularRelation::Compute(const Handle(Prs3d_Projector)&,const Handle(Prs3d_Presentation)&)");
118 PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
121 void AIS_PerpendicularRelation::Compute(const Handle(Prs3d_Projector)& aProjector, const Handle(Geom_Transformation)& aTransformation, const Handle(Prs3d_Presentation)& aPresentation)
123 // Standard_NotImplemented::Raise("AIS_PerpendicularRelation::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)");
124 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
127 //=======================================================================
128 //function : ComputeSelection
130 //=======================================================================
131 void AIS_PerpendicularRelation::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
132 const Standard_Integer)
134 Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
135 const gp_Pnt& pos = myPosition;
136 Handle(Select3D_SensitiveSegment) seg;
137 Standard_Boolean ok1(Standard_False),ok2(Standard_False);
139 if (!myFAttach.IsEqual(pos,Precision::Confusion())) {
140 seg = new Select3D_SensitiveSegment(own,
143 aSelection->Add(seg);
146 if (!mySAttach.IsEqual(myPosition,Precision::Confusion())) {
147 seg = new Select3D_SensitiveSegment(own,
150 aSelection->Add(seg);
155 gp_Vec vec1(gce_MakeDir(pos,myFAttach));
156 gp_Vec vec2(gce_MakeDir(pos,mySAttach));
157 Standard_Real dist1(pos.Distance(myFAttach));
158 Standard_Real dist2(pos.Distance(mySAttach));
164 gp_Pnt pAx11 = pos.Translated(vec1);
165 gp_Pnt pAx22 = pos.Translated(vec2);
166 gp_Pnt p_symb = pAx22.Translated(vec1);
167 seg = new Select3D_SensitiveSegment(own,pAx11,p_symb);
168 aSelection->Add(seg);
169 seg = new Select3D_SensitiveSegment(own,p_symb,pAx22);
170 aSelection->Add(seg);
174 //=======================================================================
175 //function : ComputeTwoFacesPerpendicular
177 //=======================================================================
178 void AIS_PerpendicularRelation::ComputeTwoFacesPerpendicular
179 (const Handle(Prs3d_Presentation)& /*aPresentation*/)
183 //=======================================================================
184 //function : ComputeTwoEdgesPerpendicular
186 //=======================================================================
187 void AIS_PerpendicularRelation::ComputeTwoEdgesPerpendicular(const Handle(Prs3d_Presentation)& aPresentation)
190 Handle(Geom_Curve) geom1,geom2;
191 gp_Pnt pint3d,p1,p2,pAx1,pAx2,ptat11,ptat12,ptat21,ptat22;
192 Standard_Boolean isInfinite1,isInfinite2;
193 Handle(Geom_Curve) extCurv;
194 if ( !AIS::ComputeGeometry(TopoDS::Edge(myFShape),TopoDS::Edge(mySShape),
197 ptat11,ptat12,ptat21,ptat22,
199 isInfinite1,isInfinite2,
202 Standard_Boolean interOut1(Standard_False),interOut2(Standard_False);
204 Handle(Geom_Line) geom_lin1;
205 Handle(Geom_Line) geom_lin2;
206 if ( geom1->IsInstance(STANDARD_TYPE(Geom_Ellipse)) )
208 Handle(Geom_Ellipse) geom_el (Handle(Geom_Ellipse)::DownCast (geom1));
209 // construct lines through focuses
210 gp_Ax1 elAx = geom_el->XAxis();
212 geom_lin1 = new Geom_Line(ll);
213 Standard_Real focex = geom_el->MajorRadius() - geom_el->Focal()/2.0;
214 gp_Vec transvec = gp_Vec(elAx.Direction())*focex;
215 ptat11 = geom_el->Focus1().Translated(transvec);
216 ptat12 = geom_el->Focus2().Translated(-transvec);
217 interOut1 = Standard_True;
219 else if ( geom1->IsInstance(STANDARD_TYPE(Geom_Line)) )
221 geom_lin1 = Handle(Geom_Line)::DownCast (geom1);
225 if (geom2->IsInstance(STANDARD_TYPE(Geom_Ellipse)))
227 Handle(Geom_Ellipse) geom_el (Handle(Geom_Ellipse)::DownCast (geom2));
228 // construct lines through focuses
229 gp_Ax1 elAx = geom_el->XAxis();
231 geom_lin2 = new Geom_Line(ll);
232 Standard_Real focex = geom_el->MajorRadius() - geom_el->Focal()/2.0;
233 gp_Vec transvec = gp_Vec(elAx.Direction())*focex;
234 ptat21 = geom_el->Focus1().Translated(transvec);
235 ptat22 = geom_el->Focus2().Translated(-transvec);
236 interOut2 = Standard_True;
238 else if ( geom2->IsInstance(STANDARD_TYPE(Geom_Line)) )
240 geom_lin2 = Handle(Geom_Line)::DownCast (geom2);
245 BRepBuilderAPI_MakeFace makeface (myPlane->Pln());
246 TopoDS_Face face (makeface.Face());
247 BRepAdaptor_Surface adp (makeface.Face());
249 // 2d lines => projection of 3d on current plane
250 Handle(Geom2d_Curve) aGeom2dCurve = GeomAPI::To2d(geom_lin1,myPlane->Pln());
251 Handle(Geom2d_Line) lin1_2d = Handle(Geom2d_Line)::DownCast (aGeom2dCurve) ;
252 aGeom2dCurve = GeomAPI::To2d(geom_lin2,myPlane->Pln());
253 Handle(Geom2d_Line) lin2_2d = Handle(Geom2d_Line)::DownCast (aGeom2dCurve) ;
254 IntAna2d_AnaIntersection inter(lin1_2d->Lin2d(),lin2_2d->Lin2d());
255 if (!inter.IsDone()) return;
256 if (!inter.NbPoints()) return;
258 gp_Pnt2d pint(inter.Point(1).Value());
259 pint3d = adp.Value(pint.X(),pint.Y());
262 // recherche points attache
263 Standard_Real par1,par2,curpar,pmin,pmax;//,dist,sign;
264 Standard_Real length(0.);
266 if ( isInfinite1 && isInfinite2 )
268 Standard_Real curpar1 = ElCLib::Parameter(geom_lin1->Lin(),pint3d);
269 Standard_Real curpar2 = ElCLib::Parameter(geom_lin2->Lin(),pint3d);
272 myFAttach = ElCLib::Value(curpar1+par1,geom_lin1->Lin());
273 mySAttach = ElCLib::Value(curpar2+par2,geom_lin2->Lin());
277 Standard_Boolean lengthComputed (Standard_False);
280 curpar = ElCLib::Parameter(geom_lin1->Lin(),pint3d);
281 par1 = ElCLib::Parameter(geom_lin1->Lin(),ptat11);
282 par2 = ElCLib::Parameter(geom_lin1->Lin(),ptat12);
283 pmin = Min(par1,par2);
284 pmax = Max(par1,par2);
286 if ( myPosition.SquareDistance(ptat11) > myPosition.SquareDistance(ptat12) )
290 if ( (curpar < pmin) || (curpar > pmax) )
292 interOut1 = Standard_True;
294 if ( !isInfinite2 ) length = 2.*Min(ptat11.Distance(ptat12),ptat21.Distance(ptat22))/5.;
295 else length = 2.*ptat11.Distance(ptat12)/5.;
296 lengthComputed = Standard_True;
297 gp_Vec vec1 (gce_MakeDir(myPosition,p1));
298 vec1.Multiply(length);
299 pAx1 = myPosition.Translated(vec1);
304 curpar = ElCLib::Parameter(geom_lin2->Lin(),pint3d);
305 par1 = ElCLib::Parameter(geom_lin2->Lin(),ptat21);
306 par2 = ElCLib::Parameter(geom_lin2->Lin(),ptat22);
307 pmin = Min(par1,par2);
308 pmax = Max(par1,par2);
310 if ( myPosition.SquareDistance(ptat21) > myPosition.SquareDistance(ptat22) ) p2 = ptat21;
312 if ( (curpar < pmin) || (curpar > pmax) )
314 interOut2 = Standard_True;
316 gp_Vec vec2 (gce_MakeDir(myPosition,p2));
317 if ( !lengthComputed )
319 if ( !isInfinite1 ) length = 2.*Min(ptat11.Distance(ptat12),ptat21.Distance(ptat22))/5.;
320 else length = 2.*ptat21.Distance(ptat22)/5.;
322 vec2.Multiply(length);
323 pAx2 = myPosition.Translated(vec2);
329 gp_Vec vec1(geom_lin1->Lin().Direction());
330 vec1.Multiply(length);
331 myFAttach = myPosition.Translated(vec1);
336 gp_Vec vec2(geom_lin2->Lin().Direction());
337 vec2.Multiply(length);
338 mySAttach = myPosition.Translated(vec2);
341 DsgPrs_PerpenPresentation::Add(aPresentation,myDrawer,
345 interOut1,interOut2);
347 if ( (myExtShape != 0) && !extCurv.IsNull()) {
349 if ( myExtShape == 1 ) {
354 aPresentation->SetInfiniteState(isInfinite1);
355 ComputeProjEdgePresentation(aPresentation,TopoDS::Edge(myFShape),geom_lin1,pf,pl);
362 aPresentation->SetInfiniteState(isInfinite2);
363 ComputeProjEdgePresentation(aPresentation,TopoDS::Edge(mySShape),geom_lin2,pf,pl);