1 // Created on: 1997-03-03
2 // Created by: Jean-Pierre COMBE
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
22 #define BUC60915 //GG 05/06/01 Enable to compute the requested arrow size
23 // if any in all dimensions.
25 #include <Standard_NotImplemented.hxx>
27 #include <AIS_SymmetricRelation.ixx>
29 #include <AIS_Drawer.hxx>
31 #include <gce_MakeLin.hxx>
32 #include <SelectMgr_EntityOwner.hxx>
33 #include <Select3D_SensitiveSegment.hxx>
34 #include <Select3D_SensitiveBox.hxx>
35 #include <Precision.hxx>
37 #include <BRep_Tool.hxx>
38 #include <BRepAdaptor_Surface.hxx>
39 #include <BRepAdaptor_Curve.hxx>
41 #include <gp_Circ.hxx>
49 #include <Geom_Plane.hxx>
50 #include <Geom_Line.hxx>
51 #include <Geom_Circle.hxx>
52 #include <TopExp_Explorer.hxx>
54 #include <Precision.hxx>
55 #include <Prs3d_Drawer.hxx>
56 #include <Prs3d_ArrowAspect.hxx>
57 #include <Prs3d_LengthAspect.hxx>
59 #include <DsgPrs_SymmetricPresentation.hxx>
61 //=======================================================================
62 //function : AIS_SymmetricRelation
64 //=======================================================================
65 AIS_SymmetricRelation::AIS_SymmetricRelation(const TopoDS_Shape& aSymmTool,
66 const TopoDS_Shape& FirstShape,
67 const TopoDS_Shape& SecondShape,
68 const Handle(Geom_Plane)& aPlane)
72 SetFirstShape(FirstShape);
73 SetSecondShape(SecondShape);
75 myPosition = aPlane->Pln().Location();
78 //=======================================================================
81 //=======================================================================
82 void AIS_SymmetricRelation::Compute(const Handle(PrsMgr_PresentationManager3d)&,
83 const Handle(Prs3d_Presentation)& aprs,
84 const Standard_Integer)
88 switch (myFShape.ShapeType()) {
91 // cas symetrie entre deux faces
92 ComputeTwoFacesSymmetric(aprs);
97 // cas symetrie entre deux edges
98 ComputeTwoEdgesSymmetric(aprs);
103 // cas symetrie entre deux vertexs
104 ComputeTwoVerticesSymmetric(aprs);
110 if (myTool.ShapeType() == TopAbs_EDGE) {
111 Handle(Geom_Curve) aCurve,extcurve;
113 Standard_Boolean isinfinite,isonplane;
114 if (AIS::ComputeGeometry(TopoDS::Edge(myTool),
120 if (!extcurve.IsNull()) {
126 if (isinfinite) aprs->SetInfiniteState(Standard_True);
127 ComputeProjEdgePresentation(aprs,TopoDS::Edge(myTool),aCurve,pf,pl);
133 //=======================================================================
135 //purpose : to avoid warning at compilation (SUN)
136 //=======================================================================
137 void AIS_SymmetricRelation::Compute(const Handle(Prs3d_Projector)& /*aProjector*/,
138 const Handle(Prs3d_Presentation)& /*aPresentation*/)
140 // Standard_NotImplemented::Raise("AIS_SymmetricRelation::Compute(const Handle(Prs3d_Projector)&,const Handle(Prs3d_Presentation)&)");
141 // PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
144 //=======================================================================
146 //purpose : to avoid warning at compilation (SUN)
147 //=======================================================================
148 void AIS_SymmetricRelation::Compute
149 (const Handle(PrsMgr_PresentationManager2d)& /*aPresentationManager2d*/,
150 const Handle(Graphic2d_GraphicObject)& /*aGraphicObject*/,
151 const Standard_Integer /*anInteger*/)
153 // Standard_NotImplemented::Raise("AIS_SymmetricRelation::Compute(const Handle(PrsMgr_PresentationManager2d)&,const Handle(Graphic2d_GraphicObject)&,const Standard_Integer)");
154 // PrsMgr_PresentableObject::Compute( aPresentationManager2d ,aGraphicObject,anInteger) ;
157 void AIS_SymmetricRelation::Compute(const Handle_Prs3d_Projector& aProjector,
158 const Handle_Geom_Transformation& aTransformation,
159 const Handle_Prs3d_Presentation& aPresentation)
161 Standard_NotImplemented::Raise("AIS_SymmetricRelation::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
162 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
165 //=======================================================================
166 //function : ComputeSelection
168 //=======================================================================
169 void AIS_SymmetricRelation::ComputeSelection(const Handle(SelectMgr_Selection)& aSel,
170 const Standard_Integer)
172 Handle(Select3D_SensitiveSegment) seg;
173 Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
176 Handle(Geom_Line) geom_axis,extcurve;
178 Standard_Boolean isinfinite,isonplane;
179 if (!AIS::ComputeGeometry(TopoDS::Edge(myTool),
186 gp_Lin laxis (geom_axis->Lin());
188 if(myFShape.ShapeType() != TopAbs_VERTEX){
189 BRepAdaptor_Curve cu1(TopoDS::Edge(myFShape));
191 if(cu1.GetType() == GeomAbs_Line) {
192 // gp_Lin L1 (myFAttach,myFDirAttach);
193 gp_Pnt PjAttachPnt1 = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis);
194 gp_Pnt PjOffSetPnt = ElCLib::Value(ElCLib::Parameter(laxis,myPosition),laxis);
195 Standard_Real h = fabs(PjOffSetPnt.Distance(PjAttachPnt1)/cos(myAxisDirAttach.Angle(myFDirAttach)));
196 gp_Vec VL1(myFDirAttach);
197 gp_Vec VLa(PjAttachPnt1,PjOffSetPnt);
198 Standard_Real scal = VL1.Dot(VLa);
199 if(scal < 0) VL1.Reverse();
201 gp_Pnt P1 = myFAttach.Translated(VL1);
202 gp_Pnt ProjAxis = ElCLib::Value(ElCLib::Parameter(laxis,P1),laxis);
203 gp_Vec v(P1,ProjAxis);
204 gp_Pnt P2 = ProjAxis.Translated(v);
208 if (!P1.IsEqual(P2,Precision::Confusion())) {
209 L3 = gce_MakeLin(P1,P2);
212 L3 = gce_MakeLin(P1,myFDirAttach);
213 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
214 Handle(Select3D_SensitiveBox) box =
215 new Select3D_SensitiveBox(own,
221 myPosition.Z()+size);
224 Standard_Real parmin,parmax,parcur;
225 parmin = ElCLib::Parameter(L3,P1);
228 parcur = ElCLib::Parameter(L3,P2);
229 parmin = Min(parmin,parcur);
230 parmax = Max(parmax,parcur);
232 parcur = ElCLib::Parameter(L3,myPosition);
233 parmin = Min(parmin,parcur);
234 parmax = Max(parmax,parcur);
236 gp_Pnt PointMin = ElCLib::Value(parmin,L3);
237 gp_Pnt PointMax = ElCLib::Value(parmax,L3);
239 if (!PointMin.IsEqual(PointMax,Precision::Confusion())) {
240 seg = new Select3D_SensitiveSegment(own,
245 if (!myFAttach.IsEqual(P1,Precision::Confusion())) {
246 seg = new Select3D_SensitiveSegment(own,
251 if (!mySAttach.IsEqual(P2,Precision::Confusion())) {
252 seg = new Select3D_SensitiveSegment(own,
259 //=======================Pour les arcs======================
260 if(cu1.GetType() == GeomAbs_Circle) {
261 BRep_Tool::Curve(TopoDS::Edge(myFShape),F,L);
262 // Handle(Geom_Circle) geom_circ1 = (Handle(Geom_Circle)&) BRep_Tool::Curve(TopoDS::Edge(myFShape),F,L);
264 Handle(Geom_Curve) aGeomCurve = BRep_Tool::Curve(TopoDS::Edge(myFShape),F,L);
265 Handle(Geom_Circle) geom_circ1 = (Handle(Geom_Circle)&) aGeomCurve ;
266 // Handle(Geom_Circle) geom_circ1 = (const Handle(Geom_Circle)&) BRep_Tool::Curve(TopoDS::Edge(myFShape),F,L);
267 gp_Circ circ1(geom_circ1->Circ());
268 gp_Pnt OffsetPnt(myPosition.X(),myPosition.Y(),myPosition.Z());
269 gp_Pnt Center1 = circ1.Location();
270 gp_Pnt ProjOffsetPoint = ElCLib::Value(ElCLib::Parameter(laxis,OffsetPnt),laxis);
271 gp_Pnt ProjCenter1 = ElCLib::Value(ElCLib::Parameter(laxis,Center1),laxis);
272 gp_Vec Vp(ProjCenter1,Center1);
273 if (Vp.Magnitude() <= Precision::Confusion()) Vp = gp_Vec(laxis.Direction())^myPlane->Pln().Position().Direction();
274 Standard_Real Dt,R,h;
275 Dt = ProjCenter1.Distance(ProjOffsetPoint);
279 gp_Vec Vout(ProjCenter1,ProjOffsetPoint);
280 ProjOffsetPoint = ProjCenter1.Translated(Vout.Divided(Vout.Magnitude()).Multiplied(Dt));
281 OffsetPnt = ProjOffsetPoint;
283 h = Sqrt(R*R - Dt*Dt);
284 gp_Pnt P1 = ProjOffsetPoint.Translated(Vp.Added(Vp.Divided(Vp.Magnitude()).Multiplied(h)));
285 gp_Vec v(P1,ProjOffsetPoint);
286 gp_Pnt P2 = ProjOffsetPoint.Translated(v);
289 if (!P1.IsEqual(P2,Precision::Confusion())) {
290 L3 = gce_MakeLin(P1,P2);
293 L3 = gce_MakeLin(P1,laxis.Direction());
294 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
295 Handle(Select3D_SensitiveBox) box =
296 new Select3D_SensitiveBox(own,
302 myPosition.Z()+size);
305 Standard_Real parmin,parmax,parcur;
306 parmin = ElCLib::Parameter(L3,P1);
309 parcur = ElCLib::Parameter(L3,P2);
310 parmin = Min(parmin,parcur);
311 parmax = Max(parmax,parcur);
313 parcur = ElCLib::Parameter(L3,myPosition);
314 parmin = Min(parmin,parcur);
315 parmax = Max(parmax,parcur);
317 gp_Pnt PointMin = ElCLib::Value(parmin,L3);
318 gp_Pnt PointMax = ElCLib::Value(parmax,L3);
320 if (!PointMin.IsEqual(PointMax,Precision::Confusion())) {
321 seg = new Select3D_SensitiveSegment(own,
328 //=======================Pour les points======================
330 if (myFAttach.IsEqual(mySAttach,Precision::Confusion())) {
331 seg = new Select3D_SensitiveSegment(own,myPosition,myFAttach);
335 gp_Pnt ProjOffsetPoint = ElCLib::Value(ElCLib::Parameter(laxis,myPosition),laxis);
336 gp_Pnt ProjAttachmentPoint1 = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis);
337 gp_Vec PjAtt1_Att1(ProjAttachmentPoint1,myFAttach);
338 gp_Pnt P1 = ProjOffsetPoint.Translated(PjAtt1_Att1);
339 gp_Pnt P2 = ProjOffsetPoint.Translated(PjAtt1_Att1.Reversed());
342 if (!P1.IsEqual(P2,Precision::Confusion())) {
343 L3 = gce_MakeLin(P1,P2);
346 L3 = gce_MakeLin(P1,myFDirAttach);
347 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
348 Handle(Select3D_SensitiveBox) box =
349 new Select3D_SensitiveBox(own,
355 myPosition.Z()+size);
358 Standard_Real parmin,parmax,parcur;
359 parmin = ElCLib::Parameter(L3,P1);
362 parcur = ElCLib::Parameter(L3,P2);
363 parmin = Min(parmin,parcur);
364 parmax = Max(parmax,parcur);
366 parcur = ElCLib::Parameter(L3,myPosition);
367 parmin = Min(parmin,parcur);
368 parmax = Max(parmax,parcur);
370 gp_Pnt PointMin = ElCLib::Value(parmin,L3);
371 gp_Pnt PointMax = ElCLib::Value(parmax,L3);
373 if (!PointMin.IsEqual(PointMax,Precision::Confusion())) {
374 seg = new Select3D_SensitiveSegment(own,PointMin,PointMax);
377 if (!myFAttach.IsEqual(P1,Precision::Confusion())) {
378 seg = new Select3D_SensitiveSegment(own,myFAttach,P1);
381 if (!mySAttach.IsEqual(P2,Precision::Confusion())) {
382 seg = new Select3D_SensitiveSegment(own,mySAttach,P2);
389 //=======================================================================
390 //function : ComputeTwoFacesSymmetric
392 //=======================================================================
393 void AIS_SymmetricRelation::ComputeTwoFacesSymmetric(const Handle(Prs3d_Presentation)&)
397 //=======================================================================
398 //function : ComputeTwoEdgesSymmetric
400 //=======================================================================
401 void AIS_SymmetricRelation::ComputeTwoEdgesSymmetric(const Handle(Prs3d_Presentation)& aprs)
403 BRepAdaptor_Curve cu1(TopoDS::Edge(myFShape));
404 if (cu1.GetType() != GeomAbs_Line && cu1.GetType() != GeomAbs_Circle) return;
405 BRepAdaptor_Curve cu2(TopoDS::Edge(mySShape));
406 if (cu2.GetType() != GeomAbs_Line && cu2.GetType() != GeomAbs_Circle) return;
407 // gp_Pnt pint3d,ptat11,ptat12,ptat21,ptat22;
408 gp_Pnt ptat11,ptat12,ptat21,ptat22;
409 Handle(Geom_Curve) geom1,geom2;
410 Standard_Boolean isInfinite1,isInfinite2;
411 Handle(Geom_Curve) extCurv;
412 if (!AIS::ComputeGeometry(TopoDS::Edge(myFShape),
413 TopoDS::Edge(mySShape),
422 isInfinite1,isInfinite2,
426 aprs->SetInfiniteState((isInfinite1 || isInfinite2) && (myExtShape !=0));
427 Handle(Geom_Line) geom_axis,extcurve;
429 Standard_Boolean isinfinite,isonplane;
430 if (!AIS::ComputeGeometry(TopoDS::Edge(myTool),
437 gp_Lin laxis (geom_axis->Lin());
438 myAxisDirAttach = laxis.Direction();
440 if(cu1.GetType() == GeomAbs_Line){
441 const Handle(Geom_Line)& geom_lin1 = (Handle(Geom_Line)&) geom1;
442 gp_Lin l1(geom_lin1->Lin());
443 myFDirAttach = l1.Direction();
446 if(cu1.GetType() == GeomAbs_Circle){
447 const Handle(Geom_Circle)& geom_cir1 = (Handle(Geom_Circle)&) geom1;
448 gp_Circ c(geom_cir1->Circ());
452 // recherche points attache
453 gp_Pnt ProjOffset = ElCLib::Value(ElCLib::Parameter(laxis,myPosition),laxis);
455 /*//----------------------------------------------------
456 //Quand on fait la symetrie de 2 edges consecutifs:
464 //----------------------------------------------------
466 Standard_Boolean idem = Standard_False;
467 if (isInfinite1 && isInfinite2) { // geom1 et geom2 sont des lignes
468 const gp_Lin& line2 = ((Handle(Geom_Line)&) geom2)->Lin();
469 if (myAutomaticPosition) {
470 myFAttach = ((Handle(Geom_Line)&) geom1)->Lin().Location();
471 mySAttach = ElCLib::Value(ElCLib::Parameter(line2,myFAttach),line2);
474 const gp_Lin& line1 = ((Handle(Geom_Line)&) geom1)->Lin();
475 myFAttach = ElCLib::Value(ElCLib::Parameter(line1,myPosition),line1);
476 mySAttach = ElCLib::Value(ElCLib::Parameter(line2,myFAttach),line2);
479 else if (!isInfinite1 && !isInfinite2) {
480 if (ptat11.IsEqual(ptat21,Precision::Confusion())) {
483 idem = Standard_True;
485 if (ptat11.IsEqual(ptat22,Precision::Confusion())) {
488 idem = Standard_True;
490 if (ptat12.IsEqual(ptat21,Precision::Confusion())) {
493 idem = Standard_True;
495 if (ptat12.IsEqual(ptat22,Precision::Confusion())) {
498 idem = Standard_True;
501 if( ProjOffset.SquareDistance(ptat11) > ProjOffset.SquareDistance(ptat12)) myFAttach = ptat12;
502 else myFAttach = ptat11;
504 if (ProjOffset.SquareDistance(ptat21) > ProjOffset.SquareDistance(ptat22)) mySAttach = ptat22;
505 else mySAttach = ptat21;
508 else if (isInfinite1) {// geom1 et geom2 sont des lignes
510 const gp_Lin& line1 = ((Handle(Geom_Line)&) geom1)->Lin();
511 myFAttach = ElCLib::Value(ElCLib::Parameter(line1,mySAttach),line1);
513 else if (isInfinite2) {// geom1 et geom2 sont des lignes
515 const gp_Lin& line2 = ((Handle(Geom_Line)&) geom2)->Lin();
516 mySAttach = ElCLib::Value(ElCLib::Parameter(line2,myFAttach),line2);
520 if( !myArrowSizeIsDefined )
522 myArrowSize = myFAttach.Distance(mySAttach)/50.;
523 //----------------------------------------------------
525 //----------------------------------------------------
526 // Si myFAttach <> mySAttach et PjFAttach = myFAttach
527 //----------------------------------------------------
528 gp_Pnt PjFAttach = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis);
530 if (PjFAttach.IsEqual(myFAttach,Precision::Confusion())){
531 const Handle(Geom_Line)& geom_lin2 = (Handle(Geom_Line)&) geom2;
532 gp_Lin l2(geom_lin2->Lin());
533 myFDirAttach = l2.Direction();
535 PntTempo = myFAttach;
536 myFAttach = mySAttach;
537 mySAttach = PntTempo;
538 PjFAttach = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis);
541 //----------------------------------------------------
544 if (myAutomaticPosition) {
545 //gp_Pnt PjFAttach = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis);
546 // offset pour eviter confusion Edge et Dimension
547 gp_Vec offset(myAxisDirAttach);
548 offset = offset * myArrowSize * (-5);
549 gp_Vec Vt(myFAttach, PjFAttach);
550 gp_Pnt curpos = PjFAttach.Translated(offset.Added(Vt.Multiplied(.15)));
554 gp_Pnt Pj1 = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis);
555 gp_Pnt Pj2 = ElCLib::Value(ElCLib::Parameter(laxis,mySAttach),laxis);
556 if ((myFAttach.SquareDistance(Pj1)+mySAttach.SquareDistance(Pj2)) <= Precision::Confusion()) myArrowSize = 0.;
557 Handle(Prs3d_LengthAspect) la = myDrawer->LengthAspect();
558 Handle(Prs3d_ArrowAspect) arr = la->Arrow1Aspect();
559 arr->SetLength(myArrowSize);
560 arr = la->Arrow2Aspect();
561 arr->SetLength(myArrowSize);
562 if(cu1.GetType() == GeomAbs_Line)
563 DsgPrs_SymmetricPresentation::Add(aprs,
571 if(cu1.GetType() == GeomAbs_Circle)
572 DsgPrs_SymmetricPresentation::Add(aprs,
579 if ( (myExtShape != 0) && !extCurv.IsNull()) {
581 if ( myExtShape == 1 ) {
586 ComputeProjEdgePresentation(aprs,TopoDS::Edge(myFShape),geom1,pf,pl);
593 ComputeProjEdgePresentation(aprs,TopoDS::Edge(mySShape),geom2,pf,pl);
598 //=======================================================================
599 //function : ComputeTwoVertexsSymmetric
601 //=======================================================================
602 void AIS_SymmetricRelation::ComputeTwoVerticesSymmetric(const Handle(Prs3d_Presentation)& aprs)
604 if(myFShape.ShapeType() != TopAbs_VERTEX || mySShape.ShapeType() != TopAbs_VERTEX) return;
605 Handle(Geom_Line) geom_axis,extcurve;
607 Standard_Boolean isinfinite,isonplane;
608 if (!AIS::ComputeGeometry(TopoDS::Edge(myTool),
615 Standard_Boolean isOnPlane1, isOnPlane2;
617 AIS::ComputeGeometry(TopoDS::Vertex(myFShape), myFAttach, myPlane, isOnPlane1);
618 AIS::ComputeGeometry(TopoDS::Vertex(mySShape), mySAttach, myPlane, isOnPlane2);
621 if( !myArrowSizeIsDefined )
623 myArrowSize = myFAttach.Distance(mySAttach)/50.;
625 if (isOnPlane1 && isOnPlane2)
627 else if ( isOnPlane1 && !isOnPlane2)
629 else if (!isOnPlane1 && isOnPlane2)
633 gp_Lin laxis (geom_axis->Lin());
634 myAxisDirAttach = laxis.Direction();
636 // recherche points attache
638 if (myAutomaticPosition) {
639 gp_Pnt PjFAttach = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis);
640 // offset pour eviter confusion Edge et Dimension
641 gp_Vec offset(myAxisDirAttach);
642 offset = offset * myArrowSize * (-5);
643 gp_Vec Vt(myFAttach, PjFAttach);
644 gp_Pnt curpos = PjFAttach.Translated(offset.Added(Vt.Multiplied(.15)));
647 if (2*(myFAttach.Distance(mySAttach)) <= Precision::Confusion()) myArrowSize = 0.;
648 Handle(Prs3d_LengthAspect) la = myDrawer->LengthAspect();
649 Handle(Prs3d_ArrowAspect) arr = la->Arrow1Aspect();
650 arr->SetLength(myArrowSize);
651 arr = la->Arrow2Aspect();
652 arr->SetLength(myArrowSize);
653 DsgPrs_SymmetricPresentation::Add(aprs,
659 if ( myExtShape == 1)
660 ComputeProjVertexPresentation(aprs,TopoDS::Vertex(myFShape),myFAttach);
661 else if ( myExtShape == 2)
662 ComputeProjVertexPresentation(aprs,TopoDS::Vertex(mySShape),mySAttach);