1 // Created on: 1997-03-03
2 // Created by: Jean-Pierre COMBE
3 // Copyright (c) 1997-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_SymmetricRelation.hxx>
20 #include <BRep_Tool.hxx>
21 #include <BRepAdaptor_Curve.hxx>
22 #include <BRepAdaptor_Surface.hxx>
23 #include <DsgPrs_SymmetricPresentation.hxx>
25 #include <gce_MakeLin.hxx>
26 #include <Geom_Circle.hxx>
27 #include <Geom_Line.hxx>
28 #include <Geom_Plane.hxx>
29 #include <Geom_Transformation.hxx>
32 #include <gp_Circ.hxx>
37 #include <Precision.hxx>
38 #include <Prs3d_ArrowAspect.hxx>
39 #include <Prs3d_DimensionAspect.hxx>
40 #include <Prs3d_Drawer.hxx>
41 #include <Prs3d_Presentation.hxx>
42 #include <Prs3d_Projector.hxx>
43 #include <Select3D_SensitiveBox.hxx>
44 #include <Select3D_SensitiveSegment.hxx>
45 #include <SelectMgr_EntityOwner.hxx>
46 #include <SelectMgr_Selection.hxx>
47 #include <Standard_NotImplemented.hxx>
48 #include <Standard_Type.hxx>
50 #include <TopoDS_Shape.hxx>
52 IMPLEMENT_STANDARD_RTTIEXT(AIS_SymmetricRelation,AIS_Relation)
54 //=======================================================================
55 //function : AIS_SymmetricRelation
57 //=======================================================================
58 AIS_SymmetricRelation::AIS_SymmetricRelation(const TopoDS_Shape& aSymmTool,
59 const TopoDS_Shape& FirstShape,
60 const TopoDS_Shape& SecondShape,
61 const Handle(Geom_Plane)& aPlane)
65 SetFirstShape(FirstShape);
66 SetSecondShape(SecondShape);
68 myPosition = aPlane->Pln().Location();
71 //=======================================================================
74 //=======================================================================
75 void AIS_SymmetricRelation::Compute(const Handle(PrsMgr_PresentationManager3d)&,
76 const Handle(Prs3d_Presentation)& aprs,
77 const Standard_Integer)
79 switch (myFShape.ShapeType()) {
82 // cas symetrie entre deux faces
83 ComputeTwoFacesSymmetric(aprs);
88 // cas symetrie entre deux edges
89 ComputeTwoEdgesSymmetric(aprs);
94 // cas symetrie entre deux vertexs
95 ComputeTwoVerticesSymmetric(aprs);
101 if (myTool.ShapeType() == TopAbs_EDGE) {
102 Handle(Geom_Curve) aCurve,extcurve;
104 Standard_Boolean isinfinite,isonplane;
105 if (AIS::ComputeGeometry(TopoDS::Edge(myTool),
111 if (!extcurve.IsNull()) {
117 if (isinfinite) aprs->SetInfiniteState(Standard_True);
118 ComputeProjEdgePresentation(aprs,TopoDS::Edge(myTool),aCurve,pf,pl);
124 //=======================================================================
126 //purpose : to avoid warning at compilation (SUN)
127 //=======================================================================
128 void AIS_SymmetricRelation::Compute(const Handle(Prs3d_Projector)& /*aProjector*/,
129 const Handle(Prs3d_Presentation)& /*aPresentation*/)
131 // throw Standard_NotImplemented("AIS_SymmetricRelation::Compute(const Handle(Prs3d_Projector)&,const Handle(Prs3d_Presentation)&)");
132 // PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
135 void AIS_SymmetricRelation::Compute(const Handle(Prs3d_Projector)&,
136 const Handle(Geom_Transformation)&,
137 const Handle(Prs3d_Presentation)&)
139 throw Standard_NotImplemented("AIS_SymmetricRelation::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)");
140 // PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
143 //=======================================================================
144 //function : ComputeSelection
146 //=======================================================================
147 void AIS_SymmetricRelation::ComputeSelection(const Handle(SelectMgr_Selection)& aSel,
148 const Standard_Integer)
150 Handle(Select3D_SensitiveSegment) seg;
151 Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
154 Handle(Geom_Curve) geom_axis, extcurve;
156 Standard_Boolean isinfinite,isonplane;
157 if (!AIS::ComputeGeometry(TopoDS::Edge(myTool),
164 Handle(Geom_Line) geom_line = Handle(Geom_Line)::DownCast (geom_axis);
165 gp_Lin laxis (geom_line->Lin());
167 if(myFShape.ShapeType() != TopAbs_VERTEX){
168 BRepAdaptor_Curve cu1(TopoDS::Edge(myFShape));
170 if(cu1.GetType() == GeomAbs_Line) {
171 // gp_Lin L1 (myFAttach,myFDirAttach);
172 gp_Pnt PjAttachPnt1 = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis);
173 gp_Pnt PjOffSetPnt = ElCLib::Value(ElCLib::Parameter(laxis,myPosition),laxis);
174 Standard_Real h = fabs(PjOffSetPnt.Distance(PjAttachPnt1)/cos(myAxisDirAttach.Angle(myFDirAttach)));
175 gp_Vec VL1(myFDirAttach);
176 gp_Vec VLa(PjAttachPnt1,PjOffSetPnt);
177 Standard_Real scal = VL1.Dot(VLa);
178 if(scal < 0) VL1.Reverse();
180 gp_Pnt P1 = myFAttach.Translated(VL1);
181 gp_Pnt ProjAxis = ElCLib::Value(ElCLib::Parameter(laxis,P1),laxis);
182 gp_Vec v(P1,ProjAxis);
183 gp_Pnt P2 = ProjAxis.Translated(v);
187 if (!P1.IsEqual(P2,Precision::Confusion())) {
188 L3 = gce_MakeLin(P1,P2);
191 L3 = gce_MakeLin(P1,myFDirAttach);
192 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
193 Handle(Select3D_SensitiveBox) box =
194 new Select3D_SensitiveBox(own,
200 myPosition.Z()+size);
203 Standard_Real parmin,parmax,parcur;
204 parmin = ElCLib::Parameter(L3,P1);
207 parcur = ElCLib::Parameter(L3,P2);
208 parmin = Min(parmin,parcur);
209 parmax = Max(parmax,parcur);
211 parcur = ElCLib::Parameter(L3,myPosition);
212 parmin = Min(parmin,parcur);
213 parmax = Max(parmax,parcur);
215 gp_Pnt PointMin = ElCLib::Value(parmin,L3);
216 gp_Pnt PointMax = ElCLib::Value(parmax,L3);
218 if (!PointMin.IsEqual(PointMax,Precision::Confusion())) {
219 seg = new Select3D_SensitiveSegment(own,
224 if (!myFAttach.IsEqual(P1,Precision::Confusion())) {
225 seg = new Select3D_SensitiveSegment(own,
230 if (!mySAttach.IsEqual(P2,Precision::Confusion())) {
231 seg = new Select3D_SensitiveSegment(own,
238 //=======================Pour les arcs======================
239 if(cu1.GetType() == GeomAbs_Circle) {
240 Handle(Geom_Curve) aGeomCurve = BRep_Tool::Curve(TopoDS::Edge(myFShape),F,L);
241 Handle(Geom_Circle) geom_circ1 = Handle(Geom_Circle)::DownCast (aGeomCurve) ;
242 // Handle(Geom_Circle) geom_circ1 = (const Handle(Geom_Circle)&) BRep_Tool::Curve(TopoDS::Edge(myFShape),F,L);
243 gp_Circ circ1(geom_circ1->Circ());
244 gp_Pnt OffsetPnt(myPosition.X(),myPosition.Y(),myPosition.Z());
245 gp_Pnt Center1 = circ1.Location();
246 gp_Pnt ProjOffsetPoint = ElCLib::Value(ElCLib::Parameter(laxis,OffsetPnt),laxis);
247 gp_Pnt ProjCenter1 = ElCLib::Value(ElCLib::Parameter(laxis,Center1),laxis);
248 gp_Vec Vp(ProjCenter1,Center1);
249 if (Vp.Magnitude() <= Precision::Confusion()) Vp = gp_Vec(laxis.Direction())^myPlane->Pln().Position().Direction();
250 Standard_Real Dt,R,h;
251 Dt = ProjCenter1.Distance(ProjOffsetPoint);
255 gp_Vec Vout(ProjCenter1,ProjOffsetPoint);
256 ProjOffsetPoint = ProjCenter1.Translated(Vout.Divided(Vout.Magnitude()).Multiplied(Dt));
257 OffsetPnt = ProjOffsetPoint;
259 h = Sqrt(R*R - Dt*Dt);
260 gp_Pnt P1 = ProjOffsetPoint.Translated(Vp.Added(Vp.Divided(Vp.Magnitude()).Multiplied(h)));
261 gp_Vec v(P1,ProjOffsetPoint);
262 gp_Pnt P2 = ProjOffsetPoint.Translated(v);
265 if (!P1.IsEqual(P2,Precision::Confusion())) {
266 L3 = gce_MakeLin(P1,P2);
269 L3 = gce_MakeLin(P1,laxis.Direction());
270 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
271 Handle(Select3D_SensitiveBox) box =
272 new Select3D_SensitiveBox(own,
278 myPosition.Z()+size);
281 Standard_Real parmin,parmax,parcur;
282 parmin = ElCLib::Parameter(L3,P1);
285 parcur = ElCLib::Parameter(L3,P2);
286 parmin = Min(parmin,parcur);
287 parmax = Max(parmax,parcur);
289 parcur = ElCLib::Parameter(L3,myPosition);
290 parmin = Min(parmin,parcur);
291 parmax = Max(parmax,parcur);
293 gp_Pnt PointMin = ElCLib::Value(parmin,L3);
294 gp_Pnt PointMax = ElCLib::Value(parmax,L3);
296 if (!PointMin.IsEqual(PointMax,Precision::Confusion())) {
297 seg = new Select3D_SensitiveSegment(own,
304 //=======================Pour les points======================
306 if (myFAttach.IsEqual(mySAttach,Precision::Confusion())) {
307 seg = new Select3D_SensitiveSegment(own,myPosition,myFAttach);
311 gp_Pnt ProjOffsetPoint = ElCLib::Value(ElCLib::Parameter(laxis,myPosition),laxis);
312 gp_Pnt ProjAttachmentPoint1 = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis);
313 gp_Vec PjAtt1_Att1(ProjAttachmentPoint1,myFAttach);
314 gp_Pnt P1 = ProjOffsetPoint.Translated(PjAtt1_Att1);
315 gp_Pnt P2 = ProjOffsetPoint.Translated(PjAtt1_Att1.Reversed());
318 if (!P1.IsEqual(P2,Precision::Confusion())) {
319 L3 = gce_MakeLin(P1,P2);
322 L3 = gce_MakeLin(P1,myFDirAttach);
323 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
324 Handle(Select3D_SensitiveBox) box =
325 new Select3D_SensitiveBox(own,
331 myPosition.Z()+size);
334 Standard_Real parmin,parmax,parcur;
335 parmin = ElCLib::Parameter(L3,P1);
338 parcur = ElCLib::Parameter(L3,P2);
339 parmin = Min(parmin,parcur);
340 parmax = Max(parmax,parcur);
342 parcur = ElCLib::Parameter(L3,myPosition);
343 parmin = Min(parmin,parcur);
344 parmax = Max(parmax,parcur);
346 gp_Pnt PointMin = ElCLib::Value(parmin,L3);
347 gp_Pnt PointMax = ElCLib::Value(parmax,L3);
349 if (!PointMin.IsEqual(PointMax,Precision::Confusion())) {
350 seg = new Select3D_SensitiveSegment(own,PointMin,PointMax);
353 if (!myFAttach.IsEqual(P1,Precision::Confusion())) {
354 seg = new Select3D_SensitiveSegment(own,myFAttach,P1);
357 if (!mySAttach.IsEqual(P2,Precision::Confusion())) {
358 seg = new Select3D_SensitiveSegment(own,mySAttach,P2);
365 //=======================================================================
366 //function : ComputeTwoFacesSymmetric
368 //=======================================================================
369 void AIS_SymmetricRelation::ComputeTwoFacesSymmetric(const Handle(Prs3d_Presentation)&)
373 //=======================================================================
374 //function : ComputeTwoEdgesSymmetric
376 //=======================================================================
377 void AIS_SymmetricRelation::ComputeTwoEdgesSymmetric(const Handle(Prs3d_Presentation)& aprs)
379 BRepAdaptor_Curve cu1(TopoDS::Edge(myFShape));
380 if (cu1.GetType() != GeomAbs_Line && cu1.GetType() != GeomAbs_Circle) return;
381 BRepAdaptor_Curve cu2(TopoDS::Edge(mySShape));
382 if (cu2.GetType() != GeomAbs_Line && cu2.GetType() != GeomAbs_Circle) return;
383 // gp_Pnt pint3d,ptat11,ptat12,ptat21,ptat22;
384 gp_Pnt ptat11,ptat12,ptat21,ptat22;
385 Handle(Geom_Curve) geom1,geom2;
386 Standard_Boolean isInfinite1,isInfinite2;
387 Handle(Geom_Curve) extCurv;
388 if (!AIS::ComputeGeometry(TopoDS::Edge(myFShape),
389 TopoDS::Edge(mySShape),
398 isInfinite1,isInfinite2,
402 aprs->SetInfiniteState((isInfinite1 || isInfinite2) && (myExtShape !=0));
403 Handle(Geom_Curve) geom_axis,extcurve;
405 Standard_Boolean isinfinite,isonplane;
406 if (!AIS::ComputeGeometry(TopoDS::Edge(myTool),
413 Handle(Geom_Line) geom_line = Handle(Geom_Line)::DownCast (geom_axis);
414 gp_Lin laxis (geom_line->Lin());
415 myAxisDirAttach = laxis.Direction();
417 if(cu1.GetType() == GeomAbs_Line){
418 Handle(Geom_Line) geom_lin1 (Handle(Geom_Line)::DownCast (geom1));
419 gp_Lin l1(geom_lin1->Lin());
420 myFDirAttach = l1.Direction();
423 if(cu1.GetType() == GeomAbs_Circle){
424 Handle(Geom_Circle) geom_cir1 (Handle(Geom_Circle)::DownCast (geom1));
425 gp_Circ c(geom_cir1->Circ());
429 // recherche points attache
430 gp_Pnt ProjOffset = ElCLib::Value(ElCLib::Parameter(laxis,myPosition),laxis);
432 /*//----------------------------------------------------
433 //Quand on fait la symetrie de 2 edges consecutifs:
441 //----------------------------------------------------
443 Standard_Boolean idem = Standard_False;
444 if (isInfinite1 && isInfinite2) { // geom1 et geom2 sont des lignes
445 const gp_Lin& line2 = Handle(Geom_Line)::DownCast (geom2)->Lin();
446 if (myAutomaticPosition) {
447 myFAttach = Handle(Geom_Line)::DownCast (geom1)->Lin().Location();
448 mySAttach = ElCLib::Value(ElCLib::Parameter(line2,myFAttach),line2);
451 const gp_Lin& line1 = Handle(Geom_Line)::DownCast (geom1)->Lin();
452 myFAttach = ElCLib::Value(ElCLib::Parameter(line1,myPosition),line1);
453 mySAttach = ElCLib::Value(ElCLib::Parameter(line2,myFAttach),line2);
456 else if (!isInfinite1 && !isInfinite2) {
457 if (ptat11.IsEqual(ptat21,Precision::Confusion())) {
460 idem = Standard_True;
462 if (ptat11.IsEqual(ptat22,Precision::Confusion())) {
465 idem = Standard_True;
467 if (ptat12.IsEqual(ptat21,Precision::Confusion())) {
470 idem = Standard_True;
472 if (ptat12.IsEqual(ptat22,Precision::Confusion())) {
475 idem = Standard_True;
478 if( ProjOffset.SquareDistance(ptat11) > ProjOffset.SquareDistance(ptat12)) myFAttach = ptat12;
479 else myFAttach = ptat11;
481 if (ProjOffset.SquareDistance(ptat21) > ProjOffset.SquareDistance(ptat22)) mySAttach = ptat22;
482 else mySAttach = ptat21;
485 else if (isInfinite1) {// geom1 et geom2 sont des lignes
487 const gp_Lin& line1 = Handle(Geom_Line)::DownCast (geom1)->Lin();
488 myFAttach = ElCLib::Value(ElCLib::Parameter(line1,mySAttach),line1);
490 else if (isInfinite2) {// geom1 et geom2 sont des lignes
492 const gp_Lin& line2 = Handle(Geom_Line)::DownCast (geom2)->Lin();
493 mySAttach = ElCLib::Value(ElCLib::Parameter(line2,myFAttach),line2);
496 if( !myArrowSizeIsDefined )
497 myArrowSize = myFAttach.Distance(mySAttach)/50.;
498 //----------------------------------------------------
500 //----------------------------------------------------
501 // Si myFAttach <> mySAttach et PjFAttach = myFAttach
502 //----------------------------------------------------
503 gp_Pnt PjFAttach = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis);
505 if (PjFAttach.IsEqual(myFAttach,Precision::Confusion())){
506 Handle(Geom_Line) geom_lin2 (Handle(Geom_Line)::DownCast (geom2));
507 gp_Lin l2(geom_lin2->Lin());
508 myFDirAttach = l2.Direction();
510 PntTempo = myFAttach;
511 myFAttach = mySAttach;
512 mySAttach = PntTempo;
513 PjFAttach = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis);
516 //----------------------------------------------------
519 if (myAutomaticPosition) {
520 //gp_Pnt PjFAttach = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis);
521 // offset pour eviter confusion Edge et Dimension
522 gp_Vec offset(myAxisDirAttach);
523 offset = offset * myArrowSize * (-5);
524 gp_Vec Vt(myFAttach, PjFAttach);
525 gp_Pnt curpos = PjFAttach.Translated(offset.Added(Vt.Multiplied(.15)));
529 gp_Pnt Pj1 = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis);
530 gp_Pnt Pj2 = ElCLib::Value(ElCLib::Parameter(laxis,mySAttach),laxis);
531 if ((myFAttach.SquareDistance(Pj1)+mySAttach.SquareDistance(Pj2)) <= Precision::Confusion()) myArrowSize = 0.;
532 Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect();
533 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
534 arr->SetLength(myArrowSize);
535 arr = la->ArrowAspect();
536 arr->SetLength(myArrowSize);
537 if(cu1.GetType() == GeomAbs_Line)
538 DsgPrs_SymmetricPresentation::Add(aprs,
546 if(cu1.GetType() == GeomAbs_Circle)
547 DsgPrs_SymmetricPresentation::Add(aprs,
554 if ( (myExtShape != 0) && !extCurv.IsNull()) {
556 if ( myExtShape == 1 ) {
561 ComputeProjEdgePresentation(aprs,TopoDS::Edge(myFShape),geom1,pf,pl);
568 ComputeProjEdgePresentation(aprs,TopoDS::Edge(mySShape),geom2,pf,pl);
573 //=======================================================================
574 //function : ComputeTwoVertexsSymmetric
576 //=======================================================================
577 void AIS_SymmetricRelation::ComputeTwoVerticesSymmetric(const Handle(Prs3d_Presentation)& aprs)
579 if(myFShape.ShapeType() != TopAbs_VERTEX || mySShape.ShapeType() != TopAbs_VERTEX) return;
580 Handle(Geom_Curve) geom_axis,extcurve;
582 Standard_Boolean isinfinite,isonplane;
583 if (!AIS::ComputeGeometry(TopoDS::Edge(myTool),
590 Standard_Boolean isOnPlane1, isOnPlane2;
592 AIS::ComputeGeometry(TopoDS::Vertex(myFShape), myFAttach, myPlane, isOnPlane1);
593 AIS::ComputeGeometry(TopoDS::Vertex(mySShape), mySAttach, myPlane, isOnPlane2);
595 if( !myArrowSizeIsDefined )
596 myArrowSize = myFAttach.Distance(mySAttach)/50.;
598 if (isOnPlane1 && isOnPlane2)
600 else if ( isOnPlane1 && !isOnPlane2)
602 else if (!isOnPlane1 && isOnPlane2)
607 Handle(Geom_Line) geom_line = Handle(Geom_Line)::DownCast (geom_axis);
608 gp_Lin laxis (geom_line->Lin());
609 myAxisDirAttach = laxis.Direction();
611 // recherche points attache
613 if (myAutomaticPosition) {
614 gp_Pnt PjFAttach = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis);
615 // offset pour eviter confusion Edge et Dimension
616 gp_Vec offset(myAxisDirAttach);
617 offset = offset * myArrowSize * (-5);
618 gp_Vec Vt(myFAttach, PjFAttach);
619 gp_Pnt curpos = PjFAttach.Translated(offset.Added(Vt.Multiplied(.15)));
622 if (2*(myFAttach.Distance(mySAttach)) <= Precision::Confusion()) myArrowSize = 0.;
623 Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect();
624 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
625 arr->SetLength(myArrowSize);
626 arr = la->ArrowAspect();
627 arr->SetLength(myArrowSize);
628 DsgPrs_SymmetricPresentation::Add(aprs,
634 if ( myExtShape == 1)
635 ComputeProjVertexPresentation(aprs,TopoDS::Vertex(myFShape),myFAttach);
636 else if ( myExtShape == 2)
637 ComputeProjVertexPresentation(aprs,TopoDS::Vertex(mySShape),mySAttach);