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>
49 #include <TopExp_Explorer.hxx>
51 #include <TopoDS_Shape.hxx>
53 IMPLEMENT_STANDARD_RTTIEXT(AIS_SymmetricRelation,AIS_Relation)
55 //=======================================================================
56 //function : AIS_SymmetricRelation
58 //=======================================================================
59 AIS_SymmetricRelation::AIS_SymmetricRelation(const TopoDS_Shape& aSymmTool,
60 const TopoDS_Shape& FirstShape,
61 const TopoDS_Shape& SecondShape,
62 const Handle(Geom_Plane)& aPlane)
66 SetFirstShape(FirstShape);
67 SetSecondShape(SecondShape);
69 myPosition = aPlane->Pln().Location();
72 //=======================================================================
75 //=======================================================================
76 void AIS_SymmetricRelation::Compute(const Handle(PrsMgr_PresentationManager3d)&,
77 const Handle(Prs3d_Presentation)& aprs,
78 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 // throw Standard_NotImplemented("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)&,
137 const Handle(Geom_Transformation)&,
138 const Handle(Prs3d_Presentation)&)
140 throw Standard_NotImplemented("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_Curve) geom_axis, extcurve;
157 Standard_Boolean isinfinite,isonplane;
158 if (!AIS::ComputeGeometry(TopoDS::Edge(myTool),
165 Handle(Geom_Line) geom_line = Handle(Geom_Line)::DownCast (geom_axis);
166 gp_Lin laxis (geom_line->Lin());
168 if(myFShape.ShapeType() != TopAbs_VERTEX){
169 BRepAdaptor_Curve cu1(TopoDS::Edge(myFShape));
171 if(cu1.GetType() == GeomAbs_Line) {
172 // gp_Lin L1 (myFAttach,myFDirAttach);
173 gp_Pnt PjAttachPnt1 = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis);
174 gp_Pnt PjOffSetPnt = ElCLib::Value(ElCLib::Parameter(laxis,myPosition),laxis);
175 Standard_Real h = fabs(PjOffSetPnt.Distance(PjAttachPnt1)/cos(myAxisDirAttach.Angle(myFDirAttach)));
176 gp_Vec VL1(myFDirAttach);
177 gp_Vec VLa(PjAttachPnt1,PjOffSetPnt);
178 Standard_Real scal = VL1.Dot(VLa);
179 if(scal < 0) VL1.Reverse();
181 gp_Pnt P1 = myFAttach.Translated(VL1);
182 gp_Pnt ProjAxis = ElCLib::Value(ElCLib::Parameter(laxis,P1),laxis);
183 gp_Vec v(P1,ProjAxis);
184 gp_Pnt P2 = ProjAxis.Translated(v);
188 if (!P1.IsEqual(P2,Precision::Confusion())) {
189 L3 = gce_MakeLin(P1,P2);
192 L3 = gce_MakeLin(P1,myFDirAttach);
193 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
194 Handle(Select3D_SensitiveBox) box =
195 new Select3D_SensitiveBox(own,
201 myPosition.Z()+size);
204 Standard_Real parmin,parmax,parcur;
205 parmin = ElCLib::Parameter(L3,P1);
208 parcur = ElCLib::Parameter(L3,P2);
209 parmin = Min(parmin,parcur);
210 parmax = Max(parmax,parcur);
212 parcur = ElCLib::Parameter(L3,myPosition);
213 parmin = Min(parmin,parcur);
214 parmax = Max(parmax,parcur);
216 gp_Pnt PointMin = ElCLib::Value(parmin,L3);
217 gp_Pnt PointMax = ElCLib::Value(parmax,L3);
219 if (!PointMin.IsEqual(PointMax,Precision::Confusion())) {
220 seg = new Select3D_SensitiveSegment(own,
225 if (!myFAttach.IsEqual(P1,Precision::Confusion())) {
226 seg = new Select3D_SensitiveSegment(own,
231 if (!mySAttach.IsEqual(P2,Precision::Confusion())) {
232 seg = new Select3D_SensitiveSegment(own,
239 //=======================Pour les arcs======================
240 if(cu1.GetType() == GeomAbs_Circle) {
241 Handle(Geom_Curve) aGeomCurve = BRep_Tool::Curve(TopoDS::Edge(myFShape),F,L);
242 Handle(Geom_Circle) geom_circ1 = Handle(Geom_Circle)::DownCast (aGeomCurve) ;
243 // Handle(Geom_Circle) geom_circ1 = (const Handle(Geom_Circle)&) BRep_Tool::Curve(TopoDS::Edge(myFShape),F,L);
244 gp_Circ circ1(geom_circ1->Circ());
245 gp_Pnt OffsetPnt(myPosition.X(),myPosition.Y(),myPosition.Z());
246 gp_Pnt Center1 = circ1.Location();
247 gp_Pnt ProjOffsetPoint = ElCLib::Value(ElCLib::Parameter(laxis,OffsetPnt),laxis);
248 gp_Pnt ProjCenter1 = ElCLib::Value(ElCLib::Parameter(laxis,Center1),laxis);
249 gp_Vec Vp(ProjCenter1,Center1);
250 if (Vp.Magnitude() <= Precision::Confusion()) Vp = gp_Vec(laxis.Direction())^myPlane->Pln().Position().Direction();
251 Standard_Real Dt,R,h;
252 Dt = ProjCenter1.Distance(ProjOffsetPoint);
256 gp_Vec Vout(ProjCenter1,ProjOffsetPoint);
257 ProjOffsetPoint = ProjCenter1.Translated(Vout.Divided(Vout.Magnitude()).Multiplied(Dt));
258 OffsetPnt = ProjOffsetPoint;
260 h = Sqrt(R*R - Dt*Dt);
261 gp_Pnt P1 = ProjOffsetPoint.Translated(Vp.Added(Vp.Divided(Vp.Magnitude()).Multiplied(h)));
262 gp_Vec v(P1,ProjOffsetPoint);
263 gp_Pnt P2 = ProjOffsetPoint.Translated(v);
266 if (!P1.IsEqual(P2,Precision::Confusion())) {
267 L3 = gce_MakeLin(P1,P2);
270 L3 = gce_MakeLin(P1,laxis.Direction());
271 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
272 Handle(Select3D_SensitiveBox) box =
273 new Select3D_SensitiveBox(own,
279 myPosition.Z()+size);
282 Standard_Real parmin,parmax,parcur;
283 parmin = ElCLib::Parameter(L3,P1);
286 parcur = ElCLib::Parameter(L3,P2);
287 parmin = Min(parmin,parcur);
288 parmax = Max(parmax,parcur);
290 parcur = ElCLib::Parameter(L3,myPosition);
291 parmin = Min(parmin,parcur);
292 parmax = Max(parmax,parcur);
294 gp_Pnt PointMin = ElCLib::Value(parmin,L3);
295 gp_Pnt PointMax = ElCLib::Value(parmax,L3);
297 if (!PointMin.IsEqual(PointMax,Precision::Confusion())) {
298 seg = new Select3D_SensitiveSegment(own,
305 //=======================Pour les points======================
307 if (myFAttach.IsEqual(mySAttach,Precision::Confusion())) {
308 seg = new Select3D_SensitiveSegment(own,myPosition,myFAttach);
312 gp_Pnt ProjOffsetPoint = ElCLib::Value(ElCLib::Parameter(laxis,myPosition),laxis);
313 gp_Pnt ProjAttachmentPoint1 = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis);
314 gp_Vec PjAtt1_Att1(ProjAttachmentPoint1,myFAttach);
315 gp_Pnt P1 = ProjOffsetPoint.Translated(PjAtt1_Att1);
316 gp_Pnt P2 = ProjOffsetPoint.Translated(PjAtt1_Att1.Reversed());
319 if (!P1.IsEqual(P2,Precision::Confusion())) {
320 L3 = gce_MakeLin(P1,P2);
323 L3 = gce_MakeLin(P1,myFDirAttach);
324 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
325 Handle(Select3D_SensitiveBox) box =
326 new Select3D_SensitiveBox(own,
332 myPosition.Z()+size);
335 Standard_Real parmin,parmax,parcur;
336 parmin = ElCLib::Parameter(L3,P1);
339 parcur = ElCLib::Parameter(L3,P2);
340 parmin = Min(parmin,parcur);
341 parmax = Max(parmax,parcur);
343 parcur = ElCLib::Parameter(L3,myPosition);
344 parmin = Min(parmin,parcur);
345 parmax = Max(parmax,parcur);
347 gp_Pnt PointMin = ElCLib::Value(parmin,L3);
348 gp_Pnt PointMax = ElCLib::Value(parmax,L3);
350 if (!PointMin.IsEqual(PointMax,Precision::Confusion())) {
351 seg = new Select3D_SensitiveSegment(own,PointMin,PointMax);
354 if (!myFAttach.IsEqual(P1,Precision::Confusion())) {
355 seg = new Select3D_SensitiveSegment(own,myFAttach,P1);
358 if (!mySAttach.IsEqual(P2,Precision::Confusion())) {
359 seg = new Select3D_SensitiveSegment(own,mySAttach,P2);
366 //=======================================================================
367 //function : ComputeTwoFacesSymmetric
369 //=======================================================================
370 void AIS_SymmetricRelation::ComputeTwoFacesSymmetric(const Handle(Prs3d_Presentation)&)
374 //=======================================================================
375 //function : ComputeTwoEdgesSymmetric
377 //=======================================================================
378 void AIS_SymmetricRelation::ComputeTwoEdgesSymmetric(const Handle(Prs3d_Presentation)& aprs)
380 BRepAdaptor_Curve cu1(TopoDS::Edge(myFShape));
381 if (cu1.GetType() != GeomAbs_Line && cu1.GetType() != GeomAbs_Circle) return;
382 BRepAdaptor_Curve cu2(TopoDS::Edge(mySShape));
383 if (cu2.GetType() != GeomAbs_Line && cu2.GetType() != GeomAbs_Circle) return;
384 // gp_Pnt pint3d,ptat11,ptat12,ptat21,ptat22;
385 gp_Pnt ptat11,ptat12,ptat21,ptat22;
386 Handle(Geom_Curve) geom1,geom2;
387 Standard_Boolean isInfinite1,isInfinite2;
388 Handle(Geom_Curve) extCurv;
389 if (!AIS::ComputeGeometry(TopoDS::Edge(myFShape),
390 TopoDS::Edge(mySShape),
399 isInfinite1,isInfinite2,
403 aprs->SetInfiniteState((isInfinite1 || isInfinite2) && (myExtShape !=0));
404 Handle(Geom_Curve) geom_axis,extcurve;
406 Standard_Boolean isinfinite,isonplane;
407 if (!AIS::ComputeGeometry(TopoDS::Edge(myTool),
414 Handle(Geom_Line) geom_line = Handle(Geom_Line)::DownCast (geom_axis);
415 gp_Lin laxis (geom_line->Lin());
416 myAxisDirAttach = laxis.Direction();
418 if(cu1.GetType() == GeomAbs_Line){
419 Handle(Geom_Line) geom_lin1 (Handle(Geom_Line)::DownCast (geom1));
420 gp_Lin l1(geom_lin1->Lin());
421 myFDirAttach = l1.Direction();
424 if(cu1.GetType() == GeomAbs_Circle){
425 Handle(Geom_Circle) geom_cir1 (Handle(Geom_Circle)::DownCast (geom1));
426 gp_Circ c(geom_cir1->Circ());
430 // recherche points attache
431 gp_Pnt ProjOffset = ElCLib::Value(ElCLib::Parameter(laxis,myPosition),laxis);
433 /*//----------------------------------------------------
434 //Quand on fait la symetrie de 2 edges consecutifs:
442 //----------------------------------------------------
444 Standard_Boolean idem = Standard_False;
445 if (isInfinite1 && isInfinite2) { // geom1 et geom2 sont des lignes
446 const gp_Lin& line2 = Handle(Geom_Line)::DownCast (geom2)->Lin();
447 if (myAutomaticPosition) {
448 myFAttach = Handle(Geom_Line)::DownCast (geom1)->Lin().Location();
449 mySAttach = ElCLib::Value(ElCLib::Parameter(line2,myFAttach),line2);
452 const gp_Lin& line1 = Handle(Geom_Line)::DownCast (geom1)->Lin();
453 myFAttach = ElCLib::Value(ElCLib::Parameter(line1,myPosition),line1);
454 mySAttach = ElCLib::Value(ElCLib::Parameter(line2,myFAttach),line2);
457 else if (!isInfinite1 && !isInfinite2) {
458 if (ptat11.IsEqual(ptat21,Precision::Confusion())) {
461 idem = Standard_True;
463 if (ptat11.IsEqual(ptat22,Precision::Confusion())) {
466 idem = Standard_True;
468 if (ptat12.IsEqual(ptat21,Precision::Confusion())) {
471 idem = Standard_True;
473 if (ptat12.IsEqual(ptat22,Precision::Confusion())) {
476 idem = Standard_True;
479 if( ProjOffset.SquareDistance(ptat11) > ProjOffset.SquareDistance(ptat12)) myFAttach = ptat12;
480 else myFAttach = ptat11;
482 if (ProjOffset.SquareDistance(ptat21) > ProjOffset.SquareDistance(ptat22)) mySAttach = ptat22;
483 else mySAttach = ptat21;
486 else if (isInfinite1) {// geom1 et geom2 sont des lignes
488 const gp_Lin& line1 = Handle(Geom_Line)::DownCast (geom1)->Lin();
489 myFAttach = ElCLib::Value(ElCLib::Parameter(line1,mySAttach),line1);
491 else if (isInfinite2) {// geom1 et geom2 sont des lignes
493 const gp_Lin& line2 = Handle(Geom_Line)::DownCast (geom2)->Lin();
494 mySAttach = ElCLib::Value(ElCLib::Parameter(line2,myFAttach),line2);
497 if( !myArrowSizeIsDefined )
498 myArrowSize = myFAttach.Distance(mySAttach)/50.;
499 //----------------------------------------------------
501 //----------------------------------------------------
502 // Si myFAttach <> mySAttach et PjFAttach = myFAttach
503 //----------------------------------------------------
504 gp_Pnt PjFAttach = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis);
506 if (PjFAttach.IsEqual(myFAttach,Precision::Confusion())){
507 Handle(Geom_Line) geom_lin2 (Handle(Geom_Line)::DownCast (geom2));
508 gp_Lin l2(geom_lin2->Lin());
509 myFDirAttach = l2.Direction();
511 PntTempo = myFAttach;
512 myFAttach = mySAttach;
513 mySAttach = PntTempo;
514 PjFAttach = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis);
517 //----------------------------------------------------
520 if (myAutomaticPosition) {
521 //gp_Pnt PjFAttach = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis);
522 // offset pour eviter confusion Edge et Dimension
523 gp_Vec offset(myAxisDirAttach);
524 offset = offset * myArrowSize * (-5);
525 gp_Vec Vt(myFAttach, PjFAttach);
526 gp_Pnt curpos = PjFAttach.Translated(offset.Added(Vt.Multiplied(.15)));
530 gp_Pnt Pj1 = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis);
531 gp_Pnt Pj2 = ElCLib::Value(ElCLib::Parameter(laxis,mySAttach),laxis);
532 if ((myFAttach.SquareDistance(Pj1)+mySAttach.SquareDistance(Pj2)) <= Precision::Confusion()) myArrowSize = 0.;
533 Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect();
534 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
535 arr->SetLength(myArrowSize);
536 arr = la->ArrowAspect();
537 arr->SetLength(myArrowSize);
538 if(cu1.GetType() == GeomAbs_Line)
539 DsgPrs_SymmetricPresentation::Add(aprs,
547 if(cu1.GetType() == GeomAbs_Circle)
548 DsgPrs_SymmetricPresentation::Add(aprs,
555 if ( (myExtShape != 0) && !extCurv.IsNull()) {
557 if ( myExtShape == 1 ) {
562 ComputeProjEdgePresentation(aprs,TopoDS::Edge(myFShape),geom1,pf,pl);
569 ComputeProjEdgePresentation(aprs,TopoDS::Edge(mySShape),geom2,pf,pl);
574 //=======================================================================
575 //function : ComputeTwoVertexsSymmetric
577 //=======================================================================
578 void AIS_SymmetricRelation::ComputeTwoVerticesSymmetric(const Handle(Prs3d_Presentation)& aprs)
580 if(myFShape.ShapeType() != TopAbs_VERTEX || mySShape.ShapeType() != TopAbs_VERTEX) return;
581 Handle(Geom_Curve) geom_axis,extcurve;
583 Standard_Boolean isinfinite,isonplane;
584 if (!AIS::ComputeGeometry(TopoDS::Edge(myTool),
591 Standard_Boolean isOnPlane1, isOnPlane2;
593 AIS::ComputeGeometry(TopoDS::Vertex(myFShape), myFAttach, myPlane, isOnPlane1);
594 AIS::ComputeGeometry(TopoDS::Vertex(mySShape), mySAttach, myPlane, isOnPlane2);
596 if( !myArrowSizeIsDefined )
597 myArrowSize = myFAttach.Distance(mySAttach)/50.;
599 if (isOnPlane1 && isOnPlane2)
601 else if ( isOnPlane1 && !isOnPlane2)
603 else if (!isOnPlane1 && isOnPlane2)
608 Handle(Geom_Line) geom_line = Handle(Geom_Line)::DownCast (geom_axis);
609 gp_Lin laxis (geom_line->Lin());
610 myAxisDirAttach = laxis.Direction();
612 // recherche points attache
614 if (myAutomaticPosition) {
615 gp_Pnt PjFAttach = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis);
616 // offset pour eviter confusion Edge et Dimension
617 gp_Vec offset(myAxisDirAttach);
618 offset = offset * myArrowSize * (-5);
619 gp_Vec Vt(myFAttach, PjFAttach);
620 gp_Pnt curpos = PjFAttach.Translated(offset.Added(Vt.Multiplied(.15)));
623 if (2*(myFAttach.Distance(mySAttach)) <= Precision::Confusion()) myArrowSize = 0.;
624 Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect();
625 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
626 arr->SetLength(myArrowSize);
627 arr = la->ArrowAspect();
628 arr->SetLength(myArrowSize);
629 DsgPrs_SymmetricPresentation::Add(aprs,
635 if ( myExtShape == 1)
636 ComputeProjVertexPresentation(aprs,TopoDS::Vertex(myFShape),myFAttach);
637 else if ( myExtShape == 2)
638 ComputeProjVertexPresentation(aprs,TopoDS::Vertex(mySShape),mySAttach);