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
9 // under the terms of the GNU Lesser General Public 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>
46 #include <TopoDS_Edge.hxx>
47 #include <TopoDS_Face.hxx>
48 #include <TopoDS_Vertex.hxx>
50 #include <gce_MakeDir.hxx>
54 #include <gp_Pnt2d.hxx>
55 #include <gp_Trsf.hxx>
57 #include <Geom_Ellipse.hxx>
59 //=======================================================================
60 //function : Constructor
61 //purpose : TwoEdgesPerpendicular
62 //=======================================================================
63 AIS_PerpendicularRelation::AIS_PerpendicularRelation(const TopoDS_Shape& aFShape,
64 const TopoDS_Shape& aSShape,
65 const Handle(Geom_Plane)& aPlane)
73 //=======================================================================
74 //function : Constructor
75 //purpose : TwoFacesPerpendicular
76 //=======================================================================
77 AIS_PerpendicularRelation::AIS_PerpendicularRelation(const TopoDS_Shape& aFShape,
78 const TopoDS_Shape& aSShape)
85 //=======================================================================
88 //=======================================================================
89 void AIS_PerpendicularRelation::Compute(const Handle(PrsMgr_PresentationManager3d)&,
90 const Handle(Prs3d_Presentation)& aPresentation,
91 const Standard_Integer)
93 aPresentation->Clear();
95 if (myFShape.ShapeType() == mySShape.ShapeType()) {
96 switch (myFShape.ShapeType()) {
99 // cas perpendiculaire entre deux faces
100 ComputeTwoFacesPerpendicular(aPresentation);
105 // cas perpendiculaire entre deux edges
106 ComputeTwoEdgesPerpendicular(aPresentation);
113 // Cas pas traite - Edge/Face
116 //=======================================================================
118 //purpose : to avoid warning
119 //=======================================================================
120 void AIS_PerpendicularRelation::Compute(const Handle(Prs3d_Projector)& aProjector,
121 const Handle(Prs3d_Presentation)& aPresentation)
123 // Standard_NotImplemented::Raise("AIS_PerpendicularRelation::Compute(const Handle(Prs3d_Projector)&,const Handle(Prs3d_Presentation)&)");
124 PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
127 void AIS_PerpendicularRelation::Compute(const Handle_Prs3d_Projector& aProjector, const Handle_Geom_Transformation& aTransformation, const Handle_Prs3d_Presentation& aPresentation)
129 // Standard_NotImplemented::Raise("AIS_PerpendicularRelation::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
130 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
133 //=======================================================================
134 //function : ComputeSelection
136 //=======================================================================
137 void AIS_PerpendicularRelation::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
138 const Standard_Integer)
140 Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
141 const gp_Pnt& pos = myPosition;
142 Handle(Select3D_SensitiveSegment) seg;
143 Standard_Boolean ok1(Standard_False),ok2(Standard_False);
145 if (!myFAttach.IsEqual(pos,Precision::Confusion())) {
146 seg = new Select3D_SensitiveSegment(own,
149 aSelection->Add(seg);
152 if (!mySAttach.IsEqual(myPosition,Precision::Confusion())) {
153 seg = new Select3D_SensitiveSegment(own,
156 aSelection->Add(seg);
161 gp_Vec vec1(gce_MakeDir(pos,myFAttach));
162 gp_Vec vec2(gce_MakeDir(pos,mySAttach));
163 Standard_Real dist1(pos.Distance(myFAttach));
164 Standard_Real dist2(pos.Distance(mySAttach));
170 gp_Pnt pAx11 = pos.Translated(vec1);
171 gp_Pnt pAx22 = pos.Translated(vec2);
172 gp_Pnt p_symb = pAx22.Translated(vec1);
173 seg = new Select3D_SensitiveSegment(own,pAx11,p_symb);
174 aSelection->Add(seg);
175 seg = new Select3D_SensitiveSegment(own,p_symb,pAx22);
176 aSelection->Add(seg);
180 //=======================================================================
181 //function : ComputeTwoFacesPerpendicular
183 //=======================================================================
184 void AIS_PerpendicularRelation::ComputeTwoFacesPerpendicular
185 (const Handle(Prs3d_Presentation)& /*aPresentation*/)
189 //=======================================================================
190 //function : ComputeTwoEdgesPerpendicular
192 //=======================================================================
193 void AIS_PerpendicularRelation::ComputeTwoEdgesPerpendicular(const Handle(Prs3d_Presentation)& aPresentation)
196 Handle(Geom_Curve) geom1,geom2;
197 gp_Pnt pint3d,p1,p2,pAx1,pAx2,ptat11,ptat12,ptat21,ptat22;
198 Standard_Boolean isInfinite1,isInfinite2;
199 Handle(Geom_Curve) extCurv;
200 if ( !AIS::ComputeGeometry(TopoDS::Edge(myFShape),TopoDS::Edge(mySShape),
203 ptat11,ptat12,ptat21,ptat22,
205 isInfinite1,isInfinite2,
208 Standard_Boolean interOut1(Standard_False),interOut2(Standard_False);
210 Handle(Geom_Line) geom_lin1;
211 Handle(Geom_Line) geom_lin2;
212 if ( geom1->IsInstance(STANDARD_TYPE(Geom_Ellipse)) )
214 const Handle(Geom_Ellipse)& geom_el = (Handle(Geom_Ellipse)&) geom1;
215 // construct lines through focuses
216 gp_Ax1 elAx = geom_el->XAxis();
218 geom_lin1 = new Geom_Line(ll);
219 Standard_Real focex = geom_el->MajorRadius() - geom_el->Focal()/2.0;
220 gp_Vec transvec = gp_Vec(elAx.Direction())*focex;
221 ptat11 = geom_el->Focus1().Translated(transvec);
222 ptat12 = geom_el->Focus2().Translated(-transvec);
223 interOut1 = Standard_True;
225 else if ( geom1->IsInstance(STANDARD_TYPE(Geom_Line)) )
227 geom_lin1 = (Handle(Geom_Line)&) geom1;
231 if (geom2->IsInstance(STANDARD_TYPE(Geom_Ellipse)))
233 const Handle(Geom_Ellipse)& geom_el = (Handle(Geom_Ellipse)&) geom2;
234 // construct lines through focuses
235 gp_Ax1 elAx = geom_el->XAxis();
237 geom_lin2 = new Geom_Line(ll);
238 Standard_Real focex = geom_el->MajorRadius() - geom_el->Focal()/2.0;
239 gp_Vec transvec = gp_Vec(elAx.Direction())*focex;
240 ptat21 = geom_el->Focus1().Translated(transvec);
241 ptat22 = geom_el->Focus2().Translated(-transvec);
242 interOut2 = Standard_True;
244 else if ( geom2->IsInstance(STANDARD_TYPE(Geom_Line)) )
246 geom_lin2 = (Handle(Geom_Line)&) geom2;
251 BRepBuilderAPI_MakeFace makeface (myPlane->Pln());
252 TopoDS_Face face (makeface.Face());
253 BRepAdaptor_Surface adp (makeface.Face());
255 // 2d lines => projection of 3d on current plane
256 Handle(Geom2d_Curve) aGeom2dCurve = GeomAPI::To2d(geom_lin1,myPlane->Pln());
257 Handle(Geom2d_Line) lin1_2d = (Handle(Geom2d_Line)&) aGeom2dCurve ;
258 aGeom2dCurve = GeomAPI::To2d(geom_lin2,myPlane->Pln());
259 Handle(Geom2d_Line) lin2_2d = (Handle(Geom2d_Line)&) aGeom2dCurve ;
260 IntAna2d_AnaIntersection inter(lin1_2d->Lin2d(),lin2_2d->Lin2d());
261 if (!inter.IsDone()) return;
262 if (!inter.NbPoints()) return;
264 gp_Pnt2d pint(inter.Point(1).Value());
265 pint3d = adp.Value(pint.X(),pint.Y());
268 // recherche points attache
269 Standard_Real par1,par2,curpar,pmin,pmax;//,dist,sign;
270 Standard_Real length(0.);
272 if ( isInfinite1 && isInfinite2 )
274 Standard_Real curpar1 = ElCLib::Parameter(geom_lin1->Lin(),pint3d);
275 Standard_Real curpar2 = ElCLib::Parameter(geom_lin2->Lin(),pint3d);
278 myFAttach = ElCLib::Value(curpar1+par1,geom_lin1->Lin());
279 mySAttach = ElCLib::Value(curpar2+par2,geom_lin2->Lin());
283 Standard_Boolean lengthComputed (Standard_False);
286 curpar = ElCLib::Parameter(geom_lin1->Lin(),pint3d);
287 par1 = ElCLib::Parameter(geom_lin1->Lin(),ptat11);
288 par2 = ElCLib::Parameter(geom_lin1->Lin(),ptat12);
289 pmin = Min(par1,par2);
290 pmax = Max(par1,par2);
292 if ( myPosition.SquareDistance(ptat11) > myPosition.SquareDistance(ptat12) )
296 if ( (curpar < pmin) || (curpar > pmax) )
298 interOut1 = Standard_True;
300 if ( !isInfinite2 ) length = 2.*Min(ptat11.Distance(ptat12),ptat21.Distance(ptat22))/5.;
301 else length = 2.*ptat11.Distance(ptat12)/5.;
302 lengthComputed = Standard_True;
303 gp_Vec vec1 (gce_MakeDir(myPosition,p1));
304 vec1.Multiply(length);
305 pAx1 = myPosition.Translated(vec1);
310 curpar = ElCLib::Parameter(geom_lin2->Lin(),pint3d);
311 par1 = ElCLib::Parameter(geom_lin2->Lin(),ptat21);
312 par2 = ElCLib::Parameter(geom_lin2->Lin(),ptat22);
313 pmin = Min(par1,par2);
314 pmax = Max(par1,par2);
316 if ( myPosition.SquareDistance(ptat21) > myPosition.SquareDistance(ptat22) ) p2 = ptat21;
318 if ( (curpar < pmin) || (curpar > pmax) )
320 interOut2 = Standard_True;
322 gp_Vec vec2 (gce_MakeDir(myPosition,p2));
323 if ( !lengthComputed )
325 if ( !isInfinite1 ) length = 2.*Min(ptat11.Distance(ptat12),ptat21.Distance(ptat22))/5.;
326 else length = 2.*ptat21.Distance(ptat22)/5.;
328 vec2.Multiply(length);
329 pAx2 = myPosition.Translated(vec2);
335 gp_Vec vec1(geom_lin1->Lin().Direction());
336 vec1.Multiply(length);
337 myFAttach = myPosition.Translated(vec1);
342 gp_Vec vec2(geom_lin2->Lin().Direction());
343 vec2.Multiply(length);
344 mySAttach = myPosition.Translated(vec2);
347 DsgPrs_PerpenPresentation::Add(aPresentation,myDrawer,
351 interOut1,interOut2);
353 if ( (myExtShape != 0) && !extCurv.IsNull()) {
355 if ( myExtShape == 1 ) {
360 aPresentation->SetInfiniteState(isInfinite1);
361 ComputeProjEdgePresentation(aPresentation,TopoDS::Edge(myFShape),geom_lin1,pf,pl);
368 aPresentation->SetInfiniteState(isInfinite2);
369 ComputeProjEdgePresentation(aPresentation,TopoDS::Edge(mySShape),geom_lin2,pf,pl);