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 <Select3D_SensitiveSegment.hxx>
42 #include <SelectMgr_EntityOwner.hxx>
43 #include <SelectMgr_Selection.hxx>
44 #include <Standard_NotImplemented.hxx>
45 #include <Standard_Type.hxx>
47 #include <TopoDS_Edge.hxx>
48 #include <TopoDS_Face.hxx>
49 #include <TopoDS_Shape.hxx>
50 #include <TopoDS_Vertex.hxx>
52 IMPLEMENT_STANDARD_RTTIEXT(AIS_PerpendicularRelation,AIS_Relation)
54 //=======================================================================
55 //function : Constructor
56 //purpose : TwoEdgesPerpendicular
57 //=======================================================================
58 AIS_PerpendicularRelation::AIS_PerpendicularRelation(const TopoDS_Shape& aFShape,
59 const TopoDS_Shape& aSShape,
60 const Handle(Geom_Plane)& aPlane)
68 //=======================================================================
69 //function : Constructor
70 //purpose : TwoFacesPerpendicular
71 //=======================================================================
72 AIS_PerpendicularRelation::AIS_PerpendicularRelation(const TopoDS_Shape& aFShape,
73 const TopoDS_Shape& aSShape)
80 //=======================================================================
83 //=======================================================================
84 void AIS_PerpendicularRelation::Compute(const Handle(PrsMgr_PresentationManager3d)&,
85 const Handle(Prs3d_Presentation)& aPresentation,
86 const Standard_Integer)
88 if (myFShape.ShapeType() == mySShape.ShapeType()) {
89 switch (myFShape.ShapeType()) {
92 // cas perpendiculaire entre deux faces
93 ComputeTwoFacesPerpendicular(aPresentation);
98 // cas perpendiculaire entre deux edges
99 ComputeTwoEdgesPerpendicular(aPresentation);
106 // Cas pas traite - Edge/Face
109 //=======================================================================
110 //function : ComputeSelection
112 //=======================================================================
113 void AIS_PerpendicularRelation::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
114 const Standard_Integer)
116 Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
117 const gp_Pnt& pos = myPosition;
118 Handle(Select3D_SensitiveSegment) seg;
119 Standard_Boolean ok1(Standard_False),ok2(Standard_False);
121 if (!myFAttach.IsEqual(pos,Precision::Confusion())) {
122 seg = new Select3D_SensitiveSegment(own,
125 aSelection->Add(seg);
128 if (!mySAttach.IsEqual(myPosition,Precision::Confusion())) {
129 seg = new Select3D_SensitiveSegment(own,
132 aSelection->Add(seg);
137 gp_Vec vec1(gce_MakeDir(pos,myFAttach));
138 gp_Vec vec2(gce_MakeDir(pos,mySAttach));
139 Standard_Real dist1(pos.Distance(myFAttach));
140 Standard_Real dist2(pos.Distance(mySAttach));
146 gp_Pnt pAx11 = pos.Translated(vec1);
147 gp_Pnt pAx22 = pos.Translated(vec2);
148 gp_Pnt p_symb = pAx22.Translated(vec1);
149 seg = new Select3D_SensitiveSegment(own,pAx11,p_symb);
150 aSelection->Add(seg);
151 seg = new Select3D_SensitiveSegment(own,p_symb,pAx22);
152 aSelection->Add(seg);
156 //=======================================================================
157 //function : ComputeTwoFacesPerpendicular
159 //=======================================================================
160 void AIS_PerpendicularRelation::ComputeTwoFacesPerpendicular
161 (const Handle(Prs3d_Presentation)& /*aPresentation*/)
165 //=======================================================================
166 //function : ComputeTwoEdgesPerpendicular
168 //=======================================================================
169 void AIS_PerpendicularRelation::ComputeTwoEdgesPerpendicular(const Handle(Prs3d_Presentation)& aPresentation)
172 Handle(Geom_Curve) geom1,geom2;
173 gp_Pnt pint3d,p1,p2,pAx1,pAx2,ptat11,ptat12,ptat21,ptat22;
174 Standard_Boolean isInfinite1,isInfinite2;
175 Handle(Geom_Curve) extCurv;
176 if ( !AIS::ComputeGeometry(TopoDS::Edge(myFShape),TopoDS::Edge(mySShape),
179 ptat11,ptat12,ptat21,ptat22,
181 isInfinite1,isInfinite2,
184 Standard_Boolean interOut1(Standard_False),interOut2(Standard_False);
186 Handle(Geom_Line) geom_lin1;
187 Handle(Geom_Line) geom_lin2;
188 if ( geom1->IsInstance(STANDARD_TYPE(Geom_Ellipse)) )
190 Handle(Geom_Ellipse) geom_el (Handle(Geom_Ellipse)::DownCast (geom1));
191 // construct lines through focuses
192 gp_Ax1 elAx = geom_el->XAxis();
194 geom_lin1 = new Geom_Line(ll);
195 Standard_Real focex = geom_el->MajorRadius() - geom_el->Focal()/2.0;
196 gp_Vec transvec = gp_Vec(elAx.Direction())*focex;
197 ptat11 = geom_el->Focus1().Translated(transvec);
198 ptat12 = geom_el->Focus2().Translated(-transvec);
199 interOut1 = Standard_True;
201 else if ( geom1->IsInstance(STANDARD_TYPE(Geom_Line)) )
203 geom_lin1 = Handle(Geom_Line)::DownCast (geom1);
207 if (geom2->IsInstance(STANDARD_TYPE(Geom_Ellipse)))
209 Handle(Geom_Ellipse) geom_el (Handle(Geom_Ellipse)::DownCast (geom2));
210 // construct lines through focuses
211 gp_Ax1 elAx = geom_el->XAxis();
213 geom_lin2 = new Geom_Line(ll);
214 Standard_Real focex = geom_el->MajorRadius() - geom_el->Focal()/2.0;
215 gp_Vec transvec = gp_Vec(elAx.Direction())*focex;
216 ptat21 = geom_el->Focus1().Translated(transvec);
217 ptat22 = geom_el->Focus2().Translated(-transvec);
218 interOut2 = Standard_True;
220 else if ( geom2->IsInstance(STANDARD_TYPE(Geom_Line)) )
222 geom_lin2 = Handle(Geom_Line)::DownCast (geom2);
227 BRepBuilderAPI_MakeFace makeface (myPlane->Pln());
228 TopoDS_Face face (makeface.Face());
229 BRepAdaptor_Surface adp (makeface.Face());
231 // 2d lines => projection of 3d on current plane
232 Handle(Geom2d_Curve) aGeom2dCurve = GeomAPI::To2d(geom_lin1,myPlane->Pln());
233 Handle(Geom2d_Line) lin1_2d = Handle(Geom2d_Line)::DownCast (aGeom2dCurve) ;
234 aGeom2dCurve = GeomAPI::To2d(geom_lin2,myPlane->Pln());
235 Handle(Geom2d_Line) lin2_2d = Handle(Geom2d_Line)::DownCast (aGeom2dCurve) ;
236 IntAna2d_AnaIntersection inter(lin1_2d->Lin2d(),lin2_2d->Lin2d());
237 if (!inter.IsDone()) return;
238 if (!inter.NbPoints()) return;
240 gp_Pnt2d pint(inter.Point(1).Value());
241 pint3d = adp.Value(pint.X(),pint.Y());
244 // recherche points attache
245 Standard_Real par1,par2,curpar,pmin,pmax;//,dist,sign;
246 Standard_Real length(0.);
248 if ( isInfinite1 && isInfinite2 )
250 Standard_Real curpar1 = ElCLib::Parameter(geom_lin1->Lin(),pint3d);
251 Standard_Real curpar2 = ElCLib::Parameter(geom_lin2->Lin(),pint3d);
254 myFAttach = ElCLib::Value(curpar1+par1,geom_lin1->Lin());
255 mySAttach = ElCLib::Value(curpar2+par2,geom_lin2->Lin());
259 Standard_Boolean lengthComputed (Standard_False);
262 curpar = ElCLib::Parameter(geom_lin1->Lin(),pint3d);
263 par1 = ElCLib::Parameter(geom_lin1->Lin(),ptat11);
264 par2 = ElCLib::Parameter(geom_lin1->Lin(),ptat12);
265 pmin = Min(par1,par2);
266 pmax = Max(par1,par2);
268 if ( myPosition.SquareDistance(ptat11) > myPosition.SquareDistance(ptat12) )
272 if ( (curpar < pmin) || (curpar > pmax) )
274 interOut1 = Standard_True;
276 if ( !isInfinite2 ) length = 2.*Min(ptat11.Distance(ptat12),ptat21.Distance(ptat22))/5.;
277 else length = 2.*ptat11.Distance(ptat12)/5.;
278 lengthComputed = Standard_True;
279 gp_Vec vec1 (gce_MakeDir(myPosition,p1));
280 vec1.Multiply(length);
281 pAx1 = myPosition.Translated(vec1);
286 curpar = ElCLib::Parameter(geom_lin2->Lin(),pint3d);
287 par1 = ElCLib::Parameter(geom_lin2->Lin(),ptat21);
288 par2 = ElCLib::Parameter(geom_lin2->Lin(),ptat22);
289 pmin = Min(par1,par2);
290 pmax = Max(par1,par2);
292 if ( myPosition.SquareDistance(ptat21) > myPosition.SquareDistance(ptat22) ) p2 = ptat21;
294 if ( (curpar < pmin) || (curpar > pmax) )
296 interOut2 = Standard_True;
298 gp_Vec vec2 (gce_MakeDir(myPosition,p2));
299 if ( !lengthComputed )
301 if ( !isInfinite1 ) length = 2.*Min(ptat11.Distance(ptat12),ptat21.Distance(ptat22))/5.;
302 else length = 2.*ptat21.Distance(ptat22)/5.;
304 vec2.Multiply(length);
305 pAx2 = myPosition.Translated(vec2);
311 gp_Vec vec1(geom_lin1->Lin().Direction());
312 vec1.Multiply(length);
313 myFAttach = myPosition.Translated(vec1);
318 gp_Vec vec2(geom_lin2->Lin().Direction());
319 vec2.Multiply(length);
320 mySAttach = myPosition.Translated(vec2);
323 DsgPrs_PerpenPresentation::Add(aPresentation,myDrawer,
327 interOut1,interOut2);
329 if ( (myExtShape != 0) && !extCurv.IsNull()) {
331 if ( myExtShape == 1 ) {
336 aPresentation->SetInfiniteState(isInfinite1);
337 ComputeProjEdgePresentation(aPresentation,TopoDS::Edge(myFShape),geom_lin1,pf,pl);
344 aPresentation->SetInfiniteState(isInfinite2);
345 ComputeProjEdgePresentation(aPresentation,TopoDS::Edge(mySShape),geom_lin2,pf,pl);