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_DimensionAspect.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 void AIS_SymmetricRelation::Compute(const Handle_Prs3d_Projector& aProjector,
145 const Handle_Geom_Transformation& aTransformation,
146 const Handle_Prs3d_Presentation& aPresentation)
148 Standard_NotImplemented::Raise("AIS_SymmetricRelation::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
149 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
152 //=======================================================================
153 //function : ComputeSelection
155 //=======================================================================
156 void AIS_SymmetricRelation::ComputeSelection(const Handle(SelectMgr_Selection)& aSel,
157 const Standard_Integer)
159 Handle(Select3D_SensitiveSegment) seg;
160 Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
163 Handle(Geom_Line) geom_axis,extcurve;
165 Standard_Boolean isinfinite,isonplane;
166 if (!AIS::ComputeGeometry(TopoDS::Edge(myTool),
173 gp_Lin laxis (geom_axis->Lin());
175 if(myFShape.ShapeType() != TopAbs_VERTEX){
176 BRepAdaptor_Curve cu1(TopoDS::Edge(myFShape));
178 if(cu1.GetType() == GeomAbs_Line) {
179 // gp_Lin L1 (myFAttach,myFDirAttach);
180 gp_Pnt PjAttachPnt1 = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis);
181 gp_Pnt PjOffSetPnt = ElCLib::Value(ElCLib::Parameter(laxis,myPosition),laxis);
182 Standard_Real h = fabs(PjOffSetPnt.Distance(PjAttachPnt1)/cos(myAxisDirAttach.Angle(myFDirAttach)));
183 gp_Vec VL1(myFDirAttach);
184 gp_Vec VLa(PjAttachPnt1,PjOffSetPnt);
185 Standard_Real scal = VL1.Dot(VLa);
186 if(scal < 0) VL1.Reverse();
188 gp_Pnt P1 = myFAttach.Translated(VL1);
189 gp_Pnt ProjAxis = ElCLib::Value(ElCLib::Parameter(laxis,P1),laxis);
190 gp_Vec v(P1,ProjAxis);
191 gp_Pnt P2 = ProjAxis.Translated(v);
195 if (!P1.IsEqual(P2,Precision::Confusion())) {
196 L3 = gce_MakeLin(P1,P2);
199 L3 = gce_MakeLin(P1,myFDirAttach);
200 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
201 Handle(Select3D_SensitiveBox) box =
202 new Select3D_SensitiveBox(own,
208 myPosition.Z()+size);
211 Standard_Real parmin,parmax,parcur;
212 parmin = ElCLib::Parameter(L3,P1);
215 parcur = ElCLib::Parameter(L3,P2);
216 parmin = Min(parmin,parcur);
217 parmax = Max(parmax,parcur);
219 parcur = ElCLib::Parameter(L3,myPosition);
220 parmin = Min(parmin,parcur);
221 parmax = Max(parmax,parcur);
223 gp_Pnt PointMin = ElCLib::Value(parmin,L3);
224 gp_Pnt PointMax = ElCLib::Value(parmax,L3);
226 if (!PointMin.IsEqual(PointMax,Precision::Confusion())) {
227 seg = new Select3D_SensitiveSegment(own,
232 if (!myFAttach.IsEqual(P1,Precision::Confusion())) {
233 seg = new Select3D_SensitiveSegment(own,
238 if (!mySAttach.IsEqual(P2,Precision::Confusion())) {
239 seg = new Select3D_SensitiveSegment(own,
246 //=======================Pour les arcs======================
247 if(cu1.GetType() == GeomAbs_Circle) {
248 BRep_Tool::Curve(TopoDS::Edge(myFShape),F,L);
249 // Handle(Geom_Circle) geom_circ1 = (Handle(Geom_Circle)&) BRep_Tool::Curve(TopoDS::Edge(myFShape),F,L);
251 Handle(Geom_Curve) aGeomCurve = BRep_Tool::Curve(TopoDS::Edge(myFShape),F,L);
252 Handle(Geom_Circle) geom_circ1 = (Handle(Geom_Circle)&) aGeomCurve ;
253 // Handle(Geom_Circle) geom_circ1 = (const Handle(Geom_Circle)&) BRep_Tool::Curve(TopoDS::Edge(myFShape),F,L);
254 gp_Circ circ1(geom_circ1->Circ());
255 gp_Pnt OffsetPnt(myPosition.X(),myPosition.Y(),myPosition.Z());
256 gp_Pnt Center1 = circ1.Location();
257 gp_Pnt ProjOffsetPoint = ElCLib::Value(ElCLib::Parameter(laxis,OffsetPnt),laxis);
258 gp_Pnt ProjCenter1 = ElCLib::Value(ElCLib::Parameter(laxis,Center1),laxis);
259 gp_Vec Vp(ProjCenter1,Center1);
260 if (Vp.Magnitude() <= Precision::Confusion()) Vp = gp_Vec(laxis.Direction())^myPlane->Pln().Position().Direction();
261 Standard_Real Dt,R,h;
262 Dt = ProjCenter1.Distance(ProjOffsetPoint);
266 gp_Vec Vout(ProjCenter1,ProjOffsetPoint);
267 ProjOffsetPoint = ProjCenter1.Translated(Vout.Divided(Vout.Magnitude()).Multiplied(Dt));
268 OffsetPnt = ProjOffsetPoint;
270 h = Sqrt(R*R - Dt*Dt);
271 gp_Pnt P1 = ProjOffsetPoint.Translated(Vp.Added(Vp.Divided(Vp.Magnitude()).Multiplied(h)));
272 gp_Vec v(P1,ProjOffsetPoint);
273 gp_Pnt P2 = ProjOffsetPoint.Translated(v);
276 if (!P1.IsEqual(P2,Precision::Confusion())) {
277 L3 = gce_MakeLin(P1,P2);
280 L3 = gce_MakeLin(P1,laxis.Direction());
281 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
282 Handle(Select3D_SensitiveBox) box =
283 new Select3D_SensitiveBox(own,
289 myPosition.Z()+size);
292 Standard_Real parmin,parmax,parcur;
293 parmin = ElCLib::Parameter(L3,P1);
296 parcur = ElCLib::Parameter(L3,P2);
297 parmin = Min(parmin,parcur);
298 parmax = Max(parmax,parcur);
300 parcur = ElCLib::Parameter(L3,myPosition);
301 parmin = Min(parmin,parcur);
302 parmax = Max(parmax,parcur);
304 gp_Pnt PointMin = ElCLib::Value(parmin,L3);
305 gp_Pnt PointMax = ElCLib::Value(parmax,L3);
307 if (!PointMin.IsEqual(PointMax,Precision::Confusion())) {
308 seg = new Select3D_SensitiveSegment(own,
315 //=======================Pour les points======================
317 if (myFAttach.IsEqual(mySAttach,Precision::Confusion())) {
318 seg = new Select3D_SensitiveSegment(own,myPosition,myFAttach);
322 gp_Pnt ProjOffsetPoint = ElCLib::Value(ElCLib::Parameter(laxis,myPosition),laxis);
323 gp_Pnt ProjAttachmentPoint1 = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis);
324 gp_Vec PjAtt1_Att1(ProjAttachmentPoint1,myFAttach);
325 gp_Pnt P1 = ProjOffsetPoint.Translated(PjAtt1_Att1);
326 gp_Pnt P2 = ProjOffsetPoint.Translated(PjAtt1_Att1.Reversed());
329 if (!P1.IsEqual(P2,Precision::Confusion())) {
330 L3 = gce_MakeLin(P1,P2);
333 L3 = gce_MakeLin(P1,myFDirAttach);
334 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
335 Handle(Select3D_SensitiveBox) box =
336 new Select3D_SensitiveBox(own,
342 myPosition.Z()+size);
345 Standard_Real parmin,parmax,parcur;
346 parmin = ElCLib::Parameter(L3,P1);
349 parcur = ElCLib::Parameter(L3,P2);
350 parmin = Min(parmin,parcur);
351 parmax = Max(parmax,parcur);
353 parcur = ElCLib::Parameter(L3,myPosition);
354 parmin = Min(parmin,parcur);
355 parmax = Max(parmax,parcur);
357 gp_Pnt PointMin = ElCLib::Value(parmin,L3);
358 gp_Pnt PointMax = ElCLib::Value(parmax,L3);
360 if (!PointMin.IsEqual(PointMax,Precision::Confusion())) {
361 seg = new Select3D_SensitiveSegment(own,PointMin,PointMax);
364 if (!myFAttach.IsEqual(P1,Precision::Confusion())) {
365 seg = new Select3D_SensitiveSegment(own,myFAttach,P1);
368 if (!mySAttach.IsEqual(P2,Precision::Confusion())) {
369 seg = new Select3D_SensitiveSegment(own,mySAttach,P2);
376 //=======================================================================
377 //function : ComputeTwoFacesSymmetric
379 //=======================================================================
380 void AIS_SymmetricRelation::ComputeTwoFacesSymmetric(const Handle(Prs3d_Presentation)&)
384 //=======================================================================
385 //function : ComputeTwoEdgesSymmetric
387 //=======================================================================
388 void AIS_SymmetricRelation::ComputeTwoEdgesSymmetric(const Handle(Prs3d_Presentation)& aprs)
390 BRepAdaptor_Curve cu1(TopoDS::Edge(myFShape));
391 if (cu1.GetType() != GeomAbs_Line && cu1.GetType() != GeomAbs_Circle) return;
392 BRepAdaptor_Curve cu2(TopoDS::Edge(mySShape));
393 if (cu2.GetType() != GeomAbs_Line && cu2.GetType() != GeomAbs_Circle) return;
394 // gp_Pnt pint3d,ptat11,ptat12,ptat21,ptat22;
395 gp_Pnt ptat11,ptat12,ptat21,ptat22;
396 Handle(Geom_Curve) geom1,geom2;
397 Standard_Boolean isInfinite1,isInfinite2;
398 Handle(Geom_Curve) extCurv;
399 if (!AIS::ComputeGeometry(TopoDS::Edge(myFShape),
400 TopoDS::Edge(mySShape),
409 isInfinite1,isInfinite2,
413 aprs->SetInfiniteState((isInfinite1 || isInfinite2) && (myExtShape !=0));
414 Handle(Geom_Line) geom_axis,extcurve;
416 Standard_Boolean isinfinite,isonplane;
417 if (!AIS::ComputeGeometry(TopoDS::Edge(myTool),
424 gp_Lin laxis (geom_axis->Lin());
425 myAxisDirAttach = laxis.Direction();
427 if(cu1.GetType() == GeomAbs_Line){
428 const Handle(Geom_Line)& geom_lin1 = (Handle(Geom_Line)&) geom1;
429 gp_Lin l1(geom_lin1->Lin());
430 myFDirAttach = l1.Direction();
433 if(cu1.GetType() == GeomAbs_Circle){
434 const Handle(Geom_Circle)& geom_cir1 = (Handle(Geom_Circle)&) geom1;
435 gp_Circ c(geom_cir1->Circ());
439 // recherche points attache
440 gp_Pnt ProjOffset = ElCLib::Value(ElCLib::Parameter(laxis,myPosition),laxis);
442 /*//----------------------------------------------------
443 //Quand on fait la symetrie de 2 edges consecutifs:
451 //----------------------------------------------------
453 Standard_Boolean idem = Standard_False;
454 if (isInfinite1 && isInfinite2) { // geom1 et geom2 sont des lignes
455 const gp_Lin& line2 = ((Handle(Geom_Line)&) geom2)->Lin();
456 if (myAutomaticPosition) {
457 myFAttach = ((Handle(Geom_Line)&) geom1)->Lin().Location();
458 mySAttach = ElCLib::Value(ElCLib::Parameter(line2,myFAttach),line2);
461 const gp_Lin& line1 = ((Handle(Geom_Line)&) geom1)->Lin();
462 myFAttach = ElCLib::Value(ElCLib::Parameter(line1,myPosition),line1);
463 mySAttach = ElCLib::Value(ElCLib::Parameter(line2,myFAttach),line2);
466 else if (!isInfinite1 && !isInfinite2) {
467 if (ptat11.IsEqual(ptat21,Precision::Confusion())) {
470 idem = Standard_True;
472 if (ptat11.IsEqual(ptat22,Precision::Confusion())) {
475 idem = Standard_True;
477 if (ptat12.IsEqual(ptat21,Precision::Confusion())) {
480 idem = Standard_True;
482 if (ptat12.IsEqual(ptat22,Precision::Confusion())) {
485 idem = Standard_True;
488 if( ProjOffset.SquareDistance(ptat11) > ProjOffset.SquareDistance(ptat12)) myFAttach = ptat12;
489 else myFAttach = ptat11;
491 if (ProjOffset.SquareDistance(ptat21) > ProjOffset.SquareDistance(ptat22)) mySAttach = ptat22;
492 else mySAttach = ptat21;
495 else if (isInfinite1) {// geom1 et geom2 sont des lignes
497 const gp_Lin& line1 = ((Handle(Geom_Line)&) geom1)->Lin();
498 myFAttach = ElCLib::Value(ElCLib::Parameter(line1,mySAttach),line1);
500 else if (isInfinite2) {// geom1 et geom2 sont des lignes
502 const gp_Lin& line2 = ((Handle(Geom_Line)&) geom2)->Lin();
503 mySAttach = ElCLib::Value(ElCLib::Parameter(line2,myFAttach),line2);
507 if( !myArrowSizeIsDefined )
509 myArrowSize = myFAttach.Distance(mySAttach)/50.;
510 //----------------------------------------------------
512 //----------------------------------------------------
513 // Si myFAttach <> mySAttach et PjFAttach = myFAttach
514 //----------------------------------------------------
515 gp_Pnt PjFAttach = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis);
517 if (PjFAttach.IsEqual(myFAttach,Precision::Confusion())){
518 const Handle(Geom_Line)& geom_lin2 = (Handle(Geom_Line)&) geom2;
519 gp_Lin l2(geom_lin2->Lin());
520 myFDirAttach = l2.Direction();
522 PntTempo = myFAttach;
523 myFAttach = mySAttach;
524 mySAttach = PntTempo;
525 PjFAttach = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis);
528 //----------------------------------------------------
531 if (myAutomaticPosition) {
532 //gp_Pnt PjFAttach = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis);
533 // offset pour eviter confusion Edge et Dimension
534 gp_Vec offset(myAxisDirAttach);
535 offset = offset * myArrowSize * (-5);
536 gp_Vec Vt(myFAttach, PjFAttach);
537 gp_Pnt curpos = PjFAttach.Translated(offset.Added(Vt.Multiplied(.15)));
541 gp_Pnt Pj1 = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis);
542 gp_Pnt Pj2 = ElCLib::Value(ElCLib::Parameter(laxis,mySAttach),laxis);
543 if ((myFAttach.SquareDistance(Pj1)+mySAttach.SquareDistance(Pj2)) <= Precision::Confusion()) myArrowSize = 0.;
544 Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect();
545 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
546 arr->SetLength(myArrowSize);
547 arr = la->ArrowAspect();
548 arr->SetLength(myArrowSize);
549 if(cu1.GetType() == GeomAbs_Line)
550 DsgPrs_SymmetricPresentation::Add(aprs,
558 if(cu1.GetType() == GeomAbs_Circle)
559 DsgPrs_SymmetricPresentation::Add(aprs,
566 if ( (myExtShape != 0) && !extCurv.IsNull()) {
568 if ( myExtShape == 1 ) {
573 ComputeProjEdgePresentation(aprs,TopoDS::Edge(myFShape),geom1,pf,pl);
580 ComputeProjEdgePresentation(aprs,TopoDS::Edge(mySShape),geom2,pf,pl);
585 //=======================================================================
586 //function : ComputeTwoVertexsSymmetric
588 //=======================================================================
589 void AIS_SymmetricRelation::ComputeTwoVerticesSymmetric(const Handle(Prs3d_Presentation)& aprs)
591 if(myFShape.ShapeType() != TopAbs_VERTEX || mySShape.ShapeType() != TopAbs_VERTEX) return;
592 Handle(Geom_Line) geom_axis,extcurve;
594 Standard_Boolean isinfinite,isonplane;
595 if (!AIS::ComputeGeometry(TopoDS::Edge(myTool),
602 Standard_Boolean isOnPlane1, isOnPlane2;
604 AIS::ComputeGeometry(TopoDS::Vertex(myFShape), myFAttach, myPlane, isOnPlane1);
605 AIS::ComputeGeometry(TopoDS::Vertex(mySShape), mySAttach, myPlane, isOnPlane2);
608 if( !myArrowSizeIsDefined )
610 myArrowSize = myFAttach.Distance(mySAttach)/50.;
612 if (isOnPlane1 && isOnPlane2)
614 else if ( isOnPlane1 && !isOnPlane2)
616 else if (!isOnPlane1 && isOnPlane2)
620 gp_Lin laxis (geom_axis->Lin());
621 myAxisDirAttach = laxis.Direction();
623 // recherche points attache
625 if (myAutomaticPosition) {
626 gp_Pnt PjFAttach = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis);
627 // offset pour eviter confusion Edge et Dimension
628 gp_Vec offset(myAxisDirAttach);
629 offset = offset * myArrowSize * (-5);
630 gp_Vec Vt(myFAttach, PjFAttach);
631 gp_Pnt curpos = PjFAttach.Translated(offset.Added(Vt.Multiplied(.15)));
634 if (2*(myFAttach.Distance(mySAttach)) <= Precision::Confusion()) myArrowSize = 0.;
635 Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect();
636 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
637 arr->SetLength(myArrowSize);
638 arr = la->ArrowAspect();
639 arr->SetLength(myArrowSize);
640 DsgPrs_SymmetricPresentation::Add(aprs,
646 if ( myExtShape == 1)
647 ComputeProjVertexPresentation(aprs,TopoDS::Vertex(myFShape),myFAttach);
648 else if ( myExtShape == 2)
649 ComputeProjVertexPresentation(aprs,TopoDS::Vertex(mySShape),mySAttach);