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.
17 #include <Standard_NotImplemented.hxx>
19 #include <AIS_SymmetricRelation.ixx>
21 #include <AIS_Drawer.hxx>
23 #include <gce_MakeLin.hxx>
24 #include <SelectMgr_EntityOwner.hxx>
25 #include <Select3D_SensitiveSegment.hxx>
26 #include <Select3D_SensitiveBox.hxx>
27 #include <Precision.hxx>
29 #include <BRep_Tool.hxx>
30 #include <BRepAdaptor_Surface.hxx>
31 #include <BRepAdaptor_Curve.hxx>
33 #include <gp_Circ.hxx>
41 #include <Geom_Plane.hxx>
42 #include <Geom_Line.hxx>
43 #include <Geom_Circle.hxx>
44 #include <TopExp_Explorer.hxx>
46 #include <Precision.hxx>
47 #include <Prs3d_Drawer.hxx>
48 #include <Prs3d_ArrowAspect.hxx>
49 #include <Prs3d_DimensionAspect.hxx>
51 #include <DsgPrs_SymmetricPresentation.hxx>
53 //=======================================================================
54 //function : AIS_SymmetricRelation
56 //=======================================================================
57 AIS_SymmetricRelation::AIS_SymmetricRelation(const TopoDS_Shape& aSymmTool,
58 const TopoDS_Shape& FirstShape,
59 const TopoDS_Shape& SecondShape,
60 const Handle(Geom_Plane)& aPlane)
64 SetFirstShape(FirstShape);
65 SetSecondShape(SecondShape);
67 myPosition = aPlane->Pln().Location();
70 //=======================================================================
73 //=======================================================================
74 void AIS_SymmetricRelation::Compute(const Handle(PrsMgr_PresentationManager3d)&,
75 const Handle(Prs3d_Presentation)& aprs,
76 const Standard_Integer)
80 switch (myFShape.ShapeType()) {
83 // cas symetrie entre deux faces
84 ComputeTwoFacesSymmetric(aprs);
89 // cas symetrie entre deux edges
90 ComputeTwoEdgesSymmetric(aprs);
95 // cas symetrie entre deux vertexs
96 ComputeTwoVerticesSymmetric(aprs);
102 if (myTool.ShapeType() == TopAbs_EDGE) {
103 Handle(Geom_Curve) aCurve,extcurve;
105 Standard_Boolean isinfinite,isonplane;
106 if (AIS::ComputeGeometry(TopoDS::Edge(myTool),
112 if (!extcurve.IsNull()) {
118 if (isinfinite) aprs->SetInfiniteState(Standard_True);
119 ComputeProjEdgePresentation(aprs,TopoDS::Edge(myTool),aCurve,pf,pl);
125 //=======================================================================
127 //purpose : to avoid warning at compilation (SUN)
128 //=======================================================================
129 void AIS_SymmetricRelation::Compute(const Handle(Prs3d_Projector)& /*aProjector*/,
130 const Handle(Prs3d_Presentation)& /*aPresentation*/)
132 // Standard_NotImplemented::Raise("AIS_SymmetricRelation::Compute(const Handle(Prs3d_Projector)&,const Handle(Prs3d_Presentation)&)");
133 // PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
136 void AIS_SymmetricRelation::Compute(const Handle(Prs3d_Projector)& aProjector,
137 const Handle(Geom_Transformation)& aTransformation,
138 const Handle(Prs3d_Presentation)& aPresentation)
140 Standard_NotImplemented::Raise("AIS_SymmetricRelation::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)");
141 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
144 //=======================================================================
145 //function : ComputeSelection
147 //=======================================================================
148 void AIS_SymmetricRelation::ComputeSelection(const Handle(SelectMgr_Selection)& aSel,
149 const Standard_Integer)
151 Handle(Select3D_SensitiveSegment) seg;
152 Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
155 Handle(Geom_Line) geom_axis,extcurve;
157 Standard_Boolean isinfinite,isonplane;
158 if (!AIS::ComputeGeometry(TopoDS::Edge(myTool),
165 gp_Lin laxis (geom_axis->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 BRep_Tool::Curve(TopoDS::Edge(myFShape),F,L);
241 // Handle(Geom_Circle) geom_circ1 = (Handle(Geom_Circle)&) BRep_Tool::Curve(TopoDS::Edge(myFShape),F,L);
243 Handle(Geom_Curve) aGeomCurve = BRep_Tool::Curve(TopoDS::Edge(myFShape),F,L);
244 Handle(Geom_Circle) geom_circ1 = (Handle(Geom_Circle)&) aGeomCurve ;
245 // Handle(Geom_Circle) geom_circ1 = (const Handle(Geom_Circle)&) BRep_Tool::Curve(TopoDS::Edge(myFShape),F,L);
246 gp_Circ circ1(geom_circ1->Circ());
247 gp_Pnt OffsetPnt(myPosition.X(),myPosition.Y(),myPosition.Z());
248 gp_Pnt Center1 = circ1.Location();
249 gp_Pnt ProjOffsetPoint = ElCLib::Value(ElCLib::Parameter(laxis,OffsetPnt),laxis);
250 gp_Pnt ProjCenter1 = ElCLib::Value(ElCLib::Parameter(laxis,Center1),laxis);
251 gp_Vec Vp(ProjCenter1,Center1);
252 if (Vp.Magnitude() <= Precision::Confusion()) Vp = gp_Vec(laxis.Direction())^myPlane->Pln().Position().Direction();
253 Standard_Real Dt,R,h;
254 Dt = ProjCenter1.Distance(ProjOffsetPoint);
258 gp_Vec Vout(ProjCenter1,ProjOffsetPoint);
259 ProjOffsetPoint = ProjCenter1.Translated(Vout.Divided(Vout.Magnitude()).Multiplied(Dt));
260 OffsetPnt = ProjOffsetPoint;
262 h = Sqrt(R*R - Dt*Dt);
263 gp_Pnt P1 = ProjOffsetPoint.Translated(Vp.Added(Vp.Divided(Vp.Magnitude()).Multiplied(h)));
264 gp_Vec v(P1,ProjOffsetPoint);
265 gp_Pnt P2 = ProjOffsetPoint.Translated(v);
268 if (!P1.IsEqual(P2,Precision::Confusion())) {
269 L3 = gce_MakeLin(P1,P2);
272 L3 = gce_MakeLin(P1,laxis.Direction());
273 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
274 Handle(Select3D_SensitiveBox) box =
275 new Select3D_SensitiveBox(own,
281 myPosition.Z()+size);
284 Standard_Real parmin,parmax,parcur;
285 parmin = ElCLib::Parameter(L3,P1);
288 parcur = ElCLib::Parameter(L3,P2);
289 parmin = Min(parmin,parcur);
290 parmax = Max(parmax,parcur);
292 parcur = ElCLib::Parameter(L3,myPosition);
293 parmin = Min(parmin,parcur);
294 parmax = Max(parmax,parcur);
296 gp_Pnt PointMin = ElCLib::Value(parmin,L3);
297 gp_Pnt PointMax = ElCLib::Value(parmax,L3);
299 if (!PointMin.IsEqual(PointMax,Precision::Confusion())) {
300 seg = new Select3D_SensitiveSegment(own,
307 //=======================Pour les points======================
309 if (myFAttach.IsEqual(mySAttach,Precision::Confusion())) {
310 seg = new Select3D_SensitiveSegment(own,myPosition,myFAttach);
314 gp_Pnt ProjOffsetPoint = ElCLib::Value(ElCLib::Parameter(laxis,myPosition),laxis);
315 gp_Pnt ProjAttachmentPoint1 = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis);
316 gp_Vec PjAtt1_Att1(ProjAttachmentPoint1,myFAttach);
317 gp_Pnt P1 = ProjOffsetPoint.Translated(PjAtt1_Att1);
318 gp_Pnt P2 = ProjOffsetPoint.Translated(PjAtt1_Att1.Reversed());
321 if (!P1.IsEqual(P2,Precision::Confusion())) {
322 L3 = gce_MakeLin(P1,P2);
325 L3 = gce_MakeLin(P1,myFDirAttach);
326 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
327 Handle(Select3D_SensitiveBox) box =
328 new Select3D_SensitiveBox(own,
334 myPosition.Z()+size);
337 Standard_Real parmin,parmax,parcur;
338 parmin = ElCLib::Parameter(L3,P1);
341 parcur = ElCLib::Parameter(L3,P2);
342 parmin = Min(parmin,parcur);
343 parmax = Max(parmax,parcur);
345 parcur = ElCLib::Parameter(L3,myPosition);
346 parmin = Min(parmin,parcur);
347 parmax = Max(parmax,parcur);
349 gp_Pnt PointMin = ElCLib::Value(parmin,L3);
350 gp_Pnt PointMax = ElCLib::Value(parmax,L3);
352 if (!PointMin.IsEqual(PointMax,Precision::Confusion())) {
353 seg = new Select3D_SensitiveSegment(own,PointMin,PointMax);
356 if (!myFAttach.IsEqual(P1,Precision::Confusion())) {
357 seg = new Select3D_SensitiveSegment(own,myFAttach,P1);
360 if (!mySAttach.IsEqual(P2,Precision::Confusion())) {
361 seg = new Select3D_SensitiveSegment(own,mySAttach,P2);
368 //=======================================================================
369 //function : ComputeTwoFacesSymmetric
371 //=======================================================================
372 void AIS_SymmetricRelation::ComputeTwoFacesSymmetric(const Handle(Prs3d_Presentation)&)
376 //=======================================================================
377 //function : ComputeTwoEdgesSymmetric
379 //=======================================================================
380 void AIS_SymmetricRelation::ComputeTwoEdgesSymmetric(const Handle(Prs3d_Presentation)& aprs)
382 BRepAdaptor_Curve cu1(TopoDS::Edge(myFShape));
383 if (cu1.GetType() != GeomAbs_Line && cu1.GetType() != GeomAbs_Circle) return;
384 BRepAdaptor_Curve cu2(TopoDS::Edge(mySShape));
385 if (cu2.GetType() != GeomAbs_Line && cu2.GetType() != GeomAbs_Circle) return;
386 // gp_Pnt pint3d,ptat11,ptat12,ptat21,ptat22;
387 gp_Pnt ptat11,ptat12,ptat21,ptat22;
388 Handle(Geom_Curve) geom1,geom2;
389 Standard_Boolean isInfinite1,isInfinite2;
390 Handle(Geom_Curve) extCurv;
391 if (!AIS::ComputeGeometry(TopoDS::Edge(myFShape),
392 TopoDS::Edge(mySShape),
401 isInfinite1,isInfinite2,
405 aprs->SetInfiniteState((isInfinite1 || isInfinite2) && (myExtShape !=0));
406 Handle(Geom_Line) geom_axis,extcurve;
408 Standard_Boolean isinfinite,isonplane;
409 if (!AIS::ComputeGeometry(TopoDS::Edge(myTool),
416 gp_Lin laxis (geom_axis->Lin());
417 myAxisDirAttach = laxis.Direction();
419 if(cu1.GetType() == GeomAbs_Line){
420 const Handle(Geom_Line)& geom_lin1 = (Handle(Geom_Line)&) geom1;
421 gp_Lin l1(geom_lin1->Lin());
422 myFDirAttach = l1.Direction();
425 if(cu1.GetType() == GeomAbs_Circle){
426 const Handle(Geom_Circle)& geom_cir1 = (Handle(Geom_Circle)&) geom1;
427 gp_Circ c(geom_cir1->Circ());
431 // recherche points attache
432 gp_Pnt ProjOffset = ElCLib::Value(ElCLib::Parameter(laxis,myPosition),laxis);
434 /*//----------------------------------------------------
435 //Quand on fait la symetrie de 2 edges consecutifs:
443 //----------------------------------------------------
445 Standard_Boolean idem = Standard_False;
446 if (isInfinite1 && isInfinite2) { // geom1 et geom2 sont des lignes
447 const gp_Lin& line2 = ((Handle(Geom_Line)&) geom2)->Lin();
448 if (myAutomaticPosition) {
449 myFAttach = ((Handle(Geom_Line)&) geom1)->Lin().Location();
450 mySAttach = ElCLib::Value(ElCLib::Parameter(line2,myFAttach),line2);
453 const gp_Lin& line1 = ((Handle(Geom_Line)&) geom1)->Lin();
454 myFAttach = ElCLib::Value(ElCLib::Parameter(line1,myPosition),line1);
455 mySAttach = ElCLib::Value(ElCLib::Parameter(line2,myFAttach),line2);
458 else if (!isInfinite1 && !isInfinite2) {
459 if (ptat11.IsEqual(ptat21,Precision::Confusion())) {
462 idem = Standard_True;
464 if (ptat11.IsEqual(ptat22,Precision::Confusion())) {
467 idem = Standard_True;
469 if (ptat12.IsEqual(ptat21,Precision::Confusion())) {
472 idem = Standard_True;
474 if (ptat12.IsEqual(ptat22,Precision::Confusion())) {
477 idem = Standard_True;
480 if( ProjOffset.SquareDistance(ptat11) > ProjOffset.SquareDistance(ptat12)) myFAttach = ptat12;
481 else myFAttach = ptat11;
483 if (ProjOffset.SquareDistance(ptat21) > ProjOffset.SquareDistance(ptat22)) mySAttach = ptat22;
484 else mySAttach = ptat21;
487 else if (isInfinite1) {// geom1 et geom2 sont des lignes
489 const gp_Lin& line1 = ((Handle(Geom_Line)&) geom1)->Lin();
490 myFAttach = ElCLib::Value(ElCLib::Parameter(line1,mySAttach),line1);
492 else if (isInfinite2) {// geom1 et geom2 sont des lignes
494 const gp_Lin& line2 = ((Handle(Geom_Line)&) geom2)->Lin();
495 mySAttach = ElCLib::Value(ElCLib::Parameter(line2,myFAttach),line2);
498 if( !myArrowSizeIsDefined )
499 myArrowSize = myFAttach.Distance(mySAttach)/50.;
500 //----------------------------------------------------
502 //----------------------------------------------------
503 // Si myFAttach <> mySAttach et PjFAttach = myFAttach
504 //----------------------------------------------------
505 gp_Pnt PjFAttach = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis);
507 if (PjFAttach.IsEqual(myFAttach,Precision::Confusion())){
508 const Handle(Geom_Line)& geom_lin2 = (Handle(Geom_Line)&) geom2;
509 gp_Lin l2(geom_lin2->Lin());
510 myFDirAttach = l2.Direction();
512 PntTempo = myFAttach;
513 myFAttach = mySAttach;
514 mySAttach = PntTempo;
515 PjFAttach = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis);
518 //----------------------------------------------------
521 if (myAutomaticPosition) {
522 //gp_Pnt PjFAttach = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis);
523 // offset pour eviter confusion Edge et Dimension
524 gp_Vec offset(myAxisDirAttach);
525 offset = offset * myArrowSize * (-5);
526 gp_Vec Vt(myFAttach, PjFAttach);
527 gp_Pnt curpos = PjFAttach.Translated(offset.Added(Vt.Multiplied(.15)));
531 gp_Pnt Pj1 = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis);
532 gp_Pnt Pj2 = ElCLib::Value(ElCLib::Parameter(laxis,mySAttach),laxis);
533 if ((myFAttach.SquareDistance(Pj1)+mySAttach.SquareDistance(Pj2)) <= Precision::Confusion()) myArrowSize = 0.;
534 Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect();
535 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
536 arr->SetLength(myArrowSize);
537 arr = la->ArrowAspect();
538 arr->SetLength(myArrowSize);
539 if(cu1.GetType() == GeomAbs_Line)
540 DsgPrs_SymmetricPresentation::Add(aprs,
548 if(cu1.GetType() == GeomAbs_Circle)
549 DsgPrs_SymmetricPresentation::Add(aprs,
556 if ( (myExtShape != 0) && !extCurv.IsNull()) {
558 if ( myExtShape == 1 ) {
563 ComputeProjEdgePresentation(aprs,TopoDS::Edge(myFShape),geom1,pf,pl);
570 ComputeProjEdgePresentation(aprs,TopoDS::Edge(mySShape),geom2,pf,pl);
575 //=======================================================================
576 //function : ComputeTwoVertexsSymmetric
578 //=======================================================================
579 void AIS_SymmetricRelation::ComputeTwoVerticesSymmetric(const Handle(Prs3d_Presentation)& aprs)
581 if(myFShape.ShapeType() != TopAbs_VERTEX || mySShape.ShapeType() != TopAbs_VERTEX) return;
582 Handle(Geom_Line) geom_axis,extcurve;
584 Standard_Boolean isinfinite,isonplane;
585 if (!AIS::ComputeGeometry(TopoDS::Edge(myTool),
592 Standard_Boolean isOnPlane1, isOnPlane2;
594 AIS::ComputeGeometry(TopoDS::Vertex(myFShape), myFAttach, myPlane, isOnPlane1);
595 AIS::ComputeGeometry(TopoDS::Vertex(mySShape), mySAttach, myPlane, isOnPlane2);
597 if( !myArrowSizeIsDefined )
598 myArrowSize = myFAttach.Distance(mySAttach)/50.;
600 if (isOnPlane1 && isOnPlane2)
602 else if ( isOnPlane1 && !isOnPlane2)
604 else if (!isOnPlane1 && isOnPlane2)
608 gp_Lin laxis (geom_axis->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);