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.
17 #include <Standard_NotImplemented.hxx>
19 #include <AIS_PerpendicularRelation.ixx>
23 #include <BRepBuilderAPI_MakeFace.hxx>
24 #include <BRepAdaptor_Surface.hxx>
25 #include <BRep_Tool.hxx>
27 #include <DsgPrs_PerpenPresentation.hxx>
31 #include <Geom2d_Line.hxx>
32 #include <GeomAPI.hxx>
33 #include <Geom_Line.hxx>
34 #include <Geom_Line.hxx>
35 #include <Geom_Plane.hxx>
37 #include <IntAna2d_AnaIntersection.hxx>
38 #include <IntAna2d_IntPoint.hxx>
40 #include <Precision.hxx>
42 #include <Select3D_SensitiveSegment.hxx>
43 #include <SelectMgr_EntityOwner.hxx>
44 #include <SelectMgr_Selection.hxx>
47 #include <TopoDS_Edge.hxx>
48 #include <TopoDS_Face.hxx>
49 #include <TopoDS_Vertex.hxx>
51 #include <gce_MakeDir.hxx>
55 #include <gp_Pnt2d.hxx>
56 #include <gp_Trsf.hxx>
58 #include <Geom_Ellipse.hxx>
60 //=======================================================================
61 //function : Constructor
62 //purpose : TwoEdgesPerpendicular
63 //=======================================================================
64 AIS_PerpendicularRelation::AIS_PerpendicularRelation(const TopoDS_Shape& aFShape,
65 const TopoDS_Shape& aSShape,
66 const Handle(Geom_Plane)& aPlane)
74 //=======================================================================
75 //function : Constructor
76 //purpose : TwoFacesPerpendicular
77 //=======================================================================
78 AIS_PerpendicularRelation::AIS_PerpendicularRelation(const TopoDS_Shape& aFShape,
79 const TopoDS_Shape& aSShape)
86 //=======================================================================
89 //=======================================================================
90 void AIS_PerpendicularRelation::Compute(const Handle(PrsMgr_PresentationManager3d)&,
91 const Handle(Prs3d_Presentation)& aPresentation,
92 const Standard_Integer)
94 aPresentation->Clear();
96 if (myFShape.ShapeType() == mySShape.ShapeType()) {
97 switch (myFShape.ShapeType()) {
100 // cas perpendiculaire entre deux faces
101 ComputeTwoFacesPerpendicular(aPresentation);
106 // cas perpendiculaire entre deux edges
107 ComputeTwoEdgesPerpendicular(aPresentation);
114 // Cas pas traite - Edge/Face
117 //=======================================================================
119 //purpose : to avoid warning
120 //=======================================================================
121 void AIS_PerpendicularRelation::Compute(const Handle(Prs3d_Projector)& aProjector,
122 const Handle(Prs3d_Presentation)& aPresentation)
124 // Standard_NotImplemented::Raise("AIS_PerpendicularRelation::Compute(const Handle(Prs3d_Projector)&,const Handle(Prs3d_Presentation)&)");
125 PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
128 void AIS_PerpendicularRelation::Compute(const Handle(Prs3d_Projector)& aProjector, const Handle(Geom_Transformation)& aTransformation, const Handle(Prs3d_Presentation)& aPresentation)
130 // Standard_NotImplemented::Raise("AIS_PerpendicularRelation::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)");
131 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
134 //=======================================================================
135 //function : ComputeSelection
137 //=======================================================================
138 void AIS_PerpendicularRelation::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
139 const Standard_Integer)
141 Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
142 const gp_Pnt& pos = myPosition;
143 Handle(Select3D_SensitiveSegment) seg;
144 Standard_Boolean ok1(Standard_False),ok2(Standard_False);
146 if (!myFAttach.IsEqual(pos,Precision::Confusion())) {
147 seg = new Select3D_SensitiveSegment(own,
150 aSelection->Add(seg);
153 if (!mySAttach.IsEqual(myPosition,Precision::Confusion())) {
154 seg = new Select3D_SensitiveSegment(own,
157 aSelection->Add(seg);
162 gp_Vec vec1(gce_MakeDir(pos,myFAttach));
163 gp_Vec vec2(gce_MakeDir(pos,mySAttach));
164 Standard_Real dist1(pos.Distance(myFAttach));
165 Standard_Real dist2(pos.Distance(mySAttach));
171 gp_Pnt pAx11 = pos.Translated(vec1);
172 gp_Pnt pAx22 = pos.Translated(vec2);
173 gp_Pnt p_symb = pAx22.Translated(vec1);
174 seg = new Select3D_SensitiveSegment(own,pAx11,p_symb);
175 aSelection->Add(seg);
176 seg = new Select3D_SensitiveSegment(own,p_symb,pAx22);
177 aSelection->Add(seg);
181 //=======================================================================
182 //function : ComputeTwoFacesPerpendicular
184 //=======================================================================
185 void AIS_PerpendicularRelation::ComputeTwoFacesPerpendicular
186 (const Handle(Prs3d_Presentation)& /*aPresentation*/)
190 //=======================================================================
191 //function : ComputeTwoEdgesPerpendicular
193 //=======================================================================
194 void AIS_PerpendicularRelation::ComputeTwoEdgesPerpendicular(const Handle(Prs3d_Presentation)& aPresentation)
197 Handle(Geom_Curve) geom1,geom2;
198 gp_Pnt pint3d,p1,p2,pAx1,pAx2,ptat11,ptat12,ptat21,ptat22;
199 Standard_Boolean isInfinite1,isInfinite2;
200 Handle(Geom_Curve) extCurv;
201 if ( !AIS::ComputeGeometry(TopoDS::Edge(myFShape),TopoDS::Edge(mySShape),
204 ptat11,ptat12,ptat21,ptat22,
206 isInfinite1,isInfinite2,
209 Standard_Boolean interOut1(Standard_False),interOut2(Standard_False);
211 Handle(Geom_Line) geom_lin1;
212 Handle(Geom_Line) geom_lin2;
213 if ( geom1->IsInstance(STANDARD_TYPE(Geom_Ellipse)) )
215 Handle(Geom_Ellipse) geom_el (Handle(Geom_Ellipse)::DownCast (geom1));
216 // construct lines through focuses
217 gp_Ax1 elAx = geom_el->XAxis();
219 geom_lin1 = new Geom_Line(ll);
220 Standard_Real focex = geom_el->MajorRadius() - geom_el->Focal()/2.0;
221 gp_Vec transvec = gp_Vec(elAx.Direction())*focex;
222 ptat11 = geom_el->Focus1().Translated(transvec);
223 ptat12 = geom_el->Focus2().Translated(-transvec);
224 interOut1 = Standard_True;
226 else if ( geom1->IsInstance(STANDARD_TYPE(Geom_Line)) )
228 geom_lin1 = Handle(Geom_Line)::DownCast (geom1);
232 if (geom2->IsInstance(STANDARD_TYPE(Geom_Ellipse)))
234 Handle(Geom_Ellipse) geom_el (Handle(Geom_Ellipse)::DownCast (geom2));
235 // construct lines through focuses
236 gp_Ax1 elAx = geom_el->XAxis();
238 geom_lin2 = new Geom_Line(ll);
239 Standard_Real focex = geom_el->MajorRadius() - geom_el->Focal()/2.0;
240 gp_Vec transvec = gp_Vec(elAx.Direction())*focex;
241 ptat21 = geom_el->Focus1().Translated(transvec);
242 ptat22 = geom_el->Focus2().Translated(-transvec);
243 interOut2 = Standard_True;
245 else if ( geom2->IsInstance(STANDARD_TYPE(Geom_Line)) )
247 geom_lin2 = Handle(Geom_Line)::DownCast (geom2);
252 BRepBuilderAPI_MakeFace makeface (myPlane->Pln());
253 TopoDS_Face face (makeface.Face());
254 BRepAdaptor_Surface adp (makeface.Face());
256 // 2d lines => projection of 3d on current plane
257 Handle(Geom2d_Curve) aGeom2dCurve = GeomAPI::To2d(geom_lin1,myPlane->Pln());
258 Handle(Geom2d_Line) lin1_2d = Handle(Geom2d_Line)::DownCast (aGeom2dCurve) ;
259 aGeom2dCurve = GeomAPI::To2d(geom_lin2,myPlane->Pln());
260 Handle(Geom2d_Line) lin2_2d = Handle(Geom2d_Line)::DownCast (aGeom2dCurve) ;
261 IntAna2d_AnaIntersection inter(lin1_2d->Lin2d(),lin2_2d->Lin2d());
262 if (!inter.IsDone()) return;
263 if (!inter.NbPoints()) return;
265 gp_Pnt2d pint(inter.Point(1).Value());
266 pint3d = adp.Value(pint.X(),pint.Y());
269 // recherche points attache
270 Standard_Real par1,par2,curpar,pmin,pmax;//,dist,sign;
271 Standard_Real length(0.);
273 if ( isInfinite1 && isInfinite2 )
275 Standard_Real curpar1 = ElCLib::Parameter(geom_lin1->Lin(),pint3d);
276 Standard_Real curpar2 = ElCLib::Parameter(geom_lin2->Lin(),pint3d);
279 myFAttach = ElCLib::Value(curpar1+par1,geom_lin1->Lin());
280 mySAttach = ElCLib::Value(curpar2+par2,geom_lin2->Lin());
284 Standard_Boolean lengthComputed (Standard_False);
287 curpar = ElCLib::Parameter(geom_lin1->Lin(),pint3d);
288 par1 = ElCLib::Parameter(geom_lin1->Lin(),ptat11);
289 par2 = ElCLib::Parameter(geom_lin1->Lin(),ptat12);
290 pmin = Min(par1,par2);
291 pmax = Max(par1,par2);
293 if ( myPosition.SquareDistance(ptat11) > myPosition.SquareDistance(ptat12) )
297 if ( (curpar < pmin) || (curpar > pmax) )
299 interOut1 = Standard_True;
301 if ( !isInfinite2 ) length = 2.*Min(ptat11.Distance(ptat12),ptat21.Distance(ptat22))/5.;
302 else length = 2.*ptat11.Distance(ptat12)/5.;
303 lengthComputed = Standard_True;
304 gp_Vec vec1 (gce_MakeDir(myPosition,p1));
305 vec1.Multiply(length);
306 pAx1 = myPosition.Translated(vec1);
311 curpar = ElCLib::Parameter(geom_lin2->Lin(),pint3d);
312 par1 = ElCLib::Parameter(geom_lin2->Lin(),ptat21);
313 par2 = ElCLib::Parameter(geom_lin2->Lin(),ptat22);
314 pmin = Min(par1,par2);
315 pmax = Max(par1,par2);
317 if ( myPosition.SquareDistance(ptat21) > myPosition.SquareDistance(ptat22) ) p2 = ptat21;
319 if ( (curpar < pmin) || (curpar > pmax) )
321 interOut2 = Standard_True;
323 gp_Vec vec2 (gce_MakeDir(myPosition,p2));
324 if ( !lengthComputed )
326 if ( !isInfinite1 ) length = 2.*Min(ptat11.Distance(ptat12),ptat21.Distance(ptat22))/5.;
327 else length = 2.*ptat21.Distance(ptat22)/5.;
329 vec2.Multiply(length);
330 pAx2 = myPosition.Translated(vec2);
336 gp_Vec vec1(geom_lin1->Lin().Direction());
337 vec1.Multiply(length);
338 myFAttach = myPosition.Translated(vec1);
343 gp_Vec vec2(geom_lin2->Lin().Direction());
344 vec2.Multiply(length);
345 mySAttach = myPosition.Translated(vec2);
348 DsgPrs_PerpenPresentation::Add(aPresentation,myDrawer,
352 interOut1,interOut2);
354 if ( (myExtShape != 0) && !extCurv.IsNull()) {
356 if ( myExtShape == 1 ) {
361 aPresentation->SetInfiniteState(isInfinite1);
362 ComputeProjEdgePresentation(aPresentation,TopoDS::Edge(myFShape),geom_lin1,pf,pl);
369 aPresentation->SetInfiniteState(isInfinite2);
370 ComputeProjEdgePresentation(aPresentation,TopoDS::Edge(mySShape),geom_lin2,pf,pl);