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 <PrsDim_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>
31 #include <gp_Circ.hxx>
36 #include <Precision.hxx>
37 #include <Prs3d_ArrowAspect.hxx>
38 #include <Prs3d_DimensionAspect.hxx>
39 #include <Prs3d_Drawer.hxx>
40 #include <Prs3d_Presentation.hxx>
41 #include <Select3D_SensitiveBox.hxx>
42 #include <Select3D_SensitiveSegment.hxx>
43 #include <SelectMgr_EntityOwner.hxx>
44 #include <SelectMgr_Selection.hxx>
45 #include <Standard_NotImplemented.hxx>
47 #include <TopoDS_Shape.hxx>
49 IMPLEMENT_STANDARD_RTTIEXT(PrsDim_SymmetricRelation, PrsDim_Relation)
51 //=======================================================================
52 //function : PrsDim_SymmetricRelation
54 //=======================================================================
55 PrsDim_SymmetricRelation::PrsDim_SymmetricRelation(const TopoDS_Shape& aSymmTool,
56 const TopoDS_Shape& FirstShape,
57 const TopoDS_Shape& SecondShape,
58 const Handle(Geom_Plane)& aPlane)
62 SetFirstShape(FirstShape);
63 SetSecondShape(SecondShape);
65 myPosition = aPlane->Pln().Location();
68 //=======================================================================
71 //=======================================================================
72 void PrsDim_SymmetricRelation::Compute(const Handle(PrsMgr_PresentationManager3d)&,
73 const Handle(Prs3d_Presentation)& aprs,
74 const Standard_Integer)
76 switch (myFShape.ShapeType()) {
79 // cas symetrie entre deux faces
80 ComputeTwoFacesSymmetric(aprs);
85 // cas symetrie entre deux edges
86 ComputeTwoEdgesSymmetric(aprs);
91 // cas symetrie entre deux vertexs
92 ComputeTwoVerticesSymmetric(aprs);
98 if (myTool.ShapeType() == TopAbs_EDGE) {
99 Handle(Geom_Curve) aCurve,extcurve;
101 Standard_Boolean isinfinite,isonplane;
102 if (PrsDim::ComputeGeometry(TopoDS::Edge(myTool),
108 if (!extcurve.IsNull()) {
114 if (isinfinite) aprs->SetInfiniteState(Standard_True);
115 ComputeProjEdgePresentation(aprs,TopoDS::Edge(myTool),aCurve,pf,pl);
121 //=======================================================================
122 //function : ComputeSelection
124 //=======================================================================
125 void PrsDim_SymmetricRelation::ComputeSelection(const Handle(SelectMgr_Selection)& aSel,
126 const Standard_Integer)
128 Handle(Select3D_SensitiveSegment) seg;
129 Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
132 Handle(Geom_Curve) geom_axis, extcurve;
134 Standard_Boolean isinfinite,isonplane;
135 if (!PrsDim::ComputeGeometry(TopoDS::Edge(myTool),
142 Handle(Geom_Line) geom_line = Handle(Geom_Line)::DownCast (geom_axis);
143 gp_Lin laxis (geom_line->Lin());
145 if(myFShape.ShapeType() != TopAbs_VERTEX){
146 BRepAdaptor_Curve cu1(TopoDS::Edge(myFShape));
148 if(cu1.GetType() == GeomAbs_Line) {
149 // gp_Lin L1 (myFAttach,myFDirAttach);
150 gp_Pnt PjAttachPnt1 = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis);
151 gp_Pnt PjOffSetPnt = ElCLib::Value(ElCLib::Parameter(laxis,myPosition),laxis);
152 Standard_Real h = fabs(PjOffSetPnt.Distance(PjAttachPnt1)/cos(myAxisDirAttach.Angle(myFDirAttach)));
153 gp_Vec VL1(myFDirAttach);
154 gp_Vec VLa(PjAttachPnt1,PjOffSetPnt);
155 Standard_Real scal = VL1.Dot(VLa);
156 if(scal < 0) VL1.Reverse();
158 gp_Pnt P1 = myFAttach.Translated(VL1);
159 gp_Pnt ProjAxis = ElCLib::Value(ElCLib::Parameter(laxis,P1),laxis);
160 gp_Vec v(P1,ProjAxis);
161 gp_Pnt P2 = ProjAxis.Translated(v);
165 if (!P1.IsEqual(P2,Precision::Confusion())) {
166 L3 = gce_MakeLin(P1,P2);
169 L3 = gce_MakeLin(P1,myFDirAttach);
170 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
171 Handle(Select3D_SensitiveBox) box =
172 new Select3D_SensitiveBox(own,
178 myPosition.Z()+size);
181 Standard_Real parmin,parmax,parcur;
182 parmin = ElCLib::Parameter(L3,P1);
185 parcur = ElCLib::Parameter(L3,P2);
186 parmin = Min(parmin,parcur);
187 parmax = Max(parmax,parcur);
189 parcur = ElCLib::Parameter(L3,myPosition);
190 parmin = Min(parmin,parcur);
191 parmax = Max(parmax,parcur);
193 gp_Pnt PointMin = ElCLib::Value(parmin,L3);
194 gp_Pnt PointMax = ElCLib::Value(parmax,L3);
196 if (!PointMin.IsEqual(PointMax,Precision::Confusion())) {
197 seg = new Select3D_SensitiveSegment(own,
202 if (!myFAttach.IsEqual(P1,Precision::Confusion())) {
203 seg = new Select3D_SensitiveSegment(own,
208 if (!mySAttach.IsEqual(P2,Precision::Confusion())) {
209 seg = new Select3D_SensitiveSegment(own,
216 //=======================Pour les arcs======================
217 if(cu1.GetType() == GeomAbs_Circle) {
218 Handle(Geom_Curve) aGeomCurve = BRep_Tool::Curve(TopoDS::Edge(myFShape),F,L);
219 Handle(Geom_Circle) geom_circ1 = Handle(Geom_Circle)::DownCast (aGeomCurve) ;
220 // Handle(Geom_Circle) geom_circ1 = (const Handle(Geom_Circle)&) BRep_Tool::Curve(TopoDS::Edge(myFShape),F,L);
221 gp_Circ circ1(geom_circ1->Circ());
222 gp_Pnt OffsetPnt(myPosition.X(),myPosition.Y(),myPosition.Z());
223 gp_Pnt Center1 = circ1.Location();
224 gp_Pnt ProjOffsetPoint = ElCLib::Value(ElCLib::Parameter(laxis,OffsetPnt),laxis);
225 gp_Pnt ProjCenter1 = ElCLib::Value(ElCLib::Parameter(laxis,Center1),laxis);
226 gp_Vec Vp(ProjCenter1,Center1);
227 if (Vp.Magnitude() <= Precision::Confusion()) Vp = gp_Vec(laxis.Direction())^myPlane->Pln().Position().Direction();
228 Standard_Real Dt,R,h;
229 Dt = ProjCenter1.Distance(ProjOffsetPoint);
233 gp_Vec Vout(ProjCenter1,ProjOffsetPoint);
234 ProjOffsetPoint = ProjCenter1.Translated(Vout.Divided(Vout.Magnitude()).Multiplied(Dt));
235 OffsetPnt = ProjOffsetPoint;
237 h = Sqrt(R*R - Dt*Dt);
238 gp_Pnt P1 = ProjOffsetPoint.Translated(Vp.Added(Vp.Divided(Vp.Magnitude()).Multiplied(h)));
239 gp_Vec v(P1,ProjOffsetPoint);
240 gp_Pnt P2 = ProjOffsetPoint.Translated(v);
243 if (!P1.IsEqual(P2,Precision::Confusion())) {
244 L3 = gce_MakeLin(P1,P2);
247 L3 = gce_MakeLin(P1,laxis.Direction());
248 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
249 Handle(Select3D_SensitiveBox) box =
250 new Select3D_SensitiveBox(own,
256 myPosition.Z()+size);
259 Standard_Real parmin,parmax,parcur;
260 parmin = ElCLib::Parameter(L3,P1);
263 parcur = ElCLib::Parameter(L3,P2);
264 parmin = Min(parmin,parcur);
265 parmax = Max(parmax,parcur);
267 parcur = ElCLib::Parameter(L3,myPosition);
268 parmin = Min(parmin,parcur);
269 parmax = Max(parmax,parcur);
271 gp_Pnt PointMin = ElCLib::Value(parmin,L3);
272 gp_Pnt PointMax = ElCLib::Value(parmax,L3);
274 if (!PointMin.IsEqual(PointMax,Precision::Confusion())) {
275 seg = new Select3D_SensitiveSegment(own,
282 //=======================Pour les points======================
284 if (myFAttach.IsEqual(mySAttach,Precision::Confusion())) {
285 seg = new Select3D_SensitiveSegment(own,myPosition,myFAttach);
289 gp_Pnt ProjOffsetPoint = ElCLib::Value(ElCLib::Parameter(laxis,myPosition),laxis);
290 gp_Pnt ProjAttachmentPoint1 = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis);
291 gp_Vec PjAtt1_Att1(ProjAttachmentPoint1,myFAttach);
292 gp_Pnt P1 = ProjOffsetPoint.Translated(PjAtt1_Att1);
293 gp_Pnt P2 = ProjOffsetPoint.Translated(PjAtt1_Att1.Reversed());
296 if (!P1.IsEqual(P2,Precision::Confusion())) {
297 L3 = gce_MakeLin(P1,P2);
300 L3 = gce_MakeLin(P1,myFDirAttach);
301 Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6));
302 Handle(Select3D_SensitiveBox) box =
303 new Select3D_SensitiveBox(own,
309 myPosition.Z()+size);
312 Standard_Real parmin,parmax,parcur;
313 parmin = ElCLib::Parameter(L3,P1);
316 parcur = ElCLib::Parameter(L3,P2);
317 parmin = Min(parmin,parcur);
318 parmax = Max(parmax,parcur);
320 parcur = ElCLib::Parameter(L3,myPosition);
321 parmin = Min(parmin,parcur);
322 parmax = Max(parmax,parcur);
324 gp_Pnt PointMin = ElCLib::Value(parmin,L3);
325 gp_Pnt PointMax = ElCLib::Value(parmax,L3);
327 if (!PointMin.IsEqual(PointMax,Precision::Confusion())) {
328 seg = new Select3D_SensitiveSegment(own,PointMin,PointMax);
331 if (!myFAttach.IsEqual(P1,Precision::Confusion())) {
332 seg = new Select3D_SensitiveSegment(own,myFAttach,P1);
335 if (!mySAttach.IsEqual(P2,Precision::Confusion())) {
336 seg = new Select3D_SensitiveSegment(own,mySAttach,P2);
343 //=======================================================================
344 //function : ComputeTwoFacesSymmetric
346 //=======================================================================
347 void PrsDim_SymmetricRelation::ComputeTwoFacesSymmetric(const Handle(Prs3d_Presentation)&)
351 //=======================================================================
352 //function : ComputeTwoEdgesSymmetric
354 //=======================================================================
355 void PrsDim_SymmetricRelation::ComputeTwoEdgesSymmetric(const Handle(Prs3d_Presentation)& aprs)
357 BRepAdaptor_Curve cu1(TopoDS::Edge(myFShape));
358 if (cu1.GetType() != GeomAbs_Line && cu1.GetType() != GeomAbs_Circle) return;
359 BRepAdaptor_Curve cu2(TopoDS::Edge(mySShape));
360 if (cu2.GetType() != GeomAbs_Line && cu2.GetType() != GeomAbs_Circle) return;
361 // gp_Pnt pint3d,ptat11,ptat12,ptat21,ptat22;
362 gp_Pnt ptat11,ptat12,ptat21,ptat22;
363 Handle(Geom_Curve) geom1,geom2;
364 Standard_Boolean isInfinite1,isInfinite2;
365 Handle(Geom_Curve) extCurv;
366 if (!PrsDim::ComputeGeometry(TopoDS::Edge(myFShape),
367 TopoDS::Edge(mySShape),
376 isInfinite1,isInfinite2,
380 aprs->SetInfiniteState((isInfinite1 || isInfinite2) && (myExtShape !=0));
381 Handle(Geom_Curve) geom_axis,extcurve;
383 Standard_Boolean isinfinite,isonplane;
384 if (!PrsDim::ComputeGeometry(TopoDS::Edge(myTool),
391 Handle(Geom_Line) geom_line = Handle(Geom_Line)::DownCast (geom_axis);
392 gp_Lin laxis (geom_line->Lin());
393 myAxisDirAttach = laxis.Direction();
395 if(cu1.GetType() == GeomAbs_Line){
396 Handle(Geom_Line) geom_lin1 (Handle(Geom_Line)::DownCast (geom1));
397 gp_Lin l1(geom_lin1->Lin());
398 myFDirAttach = l1.Direction();
401 if(cu1.GetType() == GeomAbs_Circle){
402 Handle(Geom_Circle) geom_cir1 (Handle(Geom_Circle)::DownCast (geom1));
403 gp_Circ c(geom_cir1->Circ());
407 // recherche points attache
408 gp_Pnt ProjOffset = ElCLib::Value(ElCLib::Parameter(laxis,myPosition),laxis);
410 /*//----------------------------------------------------
411 //Quand on fait la symetrie de 2 edges consecutifs:
419 //----------------------------------------------------
421 Standard_Boolean idem = Standard_False;
422 if (isInfinite1 && isInfinite2) { // geom1 et geom2 sont des lignes
423 const gp_Lin& line2 = Handle(Geom_Line)::DownCast (geom2)->Lin();
424 if (myAutomaticPosition) {
425 myFAttach = Handle(Geom_Line)::DownCast (geom1)->Lin().Location();
426 mySAttach = ElCLib::Value(ElCLib::Parameter(line2,myFAttach),line2);
429 const gp_Lin& line1 = Handle(Geom_Line)::DownCast (geom1)->Lin();
430 myFAttach = ElCLib::Value(ElCLib::Parameter(line1,myPosition),line1);
431 mySAttach = ElCLib::Value(ElCLib::Parameter(line2,myFAttach),line2);
434 else if (!isInfinite1 && !isInfinite2) {
435 if (ptat11.IsEqual(ptat21,Precision::Confusion())) {
438 idem = Standard_True;
440 if (ptat11.IsEqual(ptat22,Precision::Confusion())) {
443 idem = Standard_True;
445 if (ptat12.IsEqual(ptat21,Precision::Confusion())) {
448 idem = Standard_True;
450 if (ptat12.IsEqual(ptat22,Precision::Confusion())) {
453 idem = Standard_True;
456 if( ProjOffset.SquareDistance(ptat11) > ProjOffset.SquareDistance(ptat12)) myFAttach = ptat12;
457 else myFAttach = ptat11;
459 if (ProjOffset.SquareDistance(ptat21) > ProjOffset.SquareDistance(ptat22)) mySAttach = ptat22;
460 else mySAttach = ptat21;
463 else if (isInfinite1) {// geom1 et geom2 sont des lignes
465 const gp_Lin& line1 = Handle(Geom_Line)::DownCast (geom1)->Lin();
466 myFAttach = ElCLib::Value(ElCLib::Parameter(line1,mySAttach),line1);
468 else if (isInfinite2) {// geom1 et geom2 sont des lignes
470 const gp_Lin& line2 = Handle(Geom_Line)::DownCast (geom2)->Lin();
471 mySAttach = ElCLib::Value(ElCLib::Parameter(line2,myFAttach),line2);
474 if( !myArrowSizeIsDefined )
475 myArrowSize = myFAttach.Distance(mySAttach)/50.;
476 //----------------------------------------------------
478 //----------------------------------------------------
479 // Si myFAttach <> mySAttach et PjFAttach = myFAttach
480 //----------------------------------------------------
481 gp_Pnt PjFAttach = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis);
483 if (PjFAttach.IsEqual(myFAttach,Precision::Confusion())){
484 Handle(Geom_Line) geom_lin2 (Handle(Geom_Line)::DownCast (geom2));
485 gp_Lin l2(geom_lin2->Lin());
486 myFDirAttach = l2.Direction();
488 PntTempo = myFAttach;
489 myFAttach = mySAttach;
490 mySAttach = PntTempo;
491 PjFAttach = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis);
494 //----------------------------------------------------
497 if (myAutomaticPosition) {
498 //gp_Pnt PjFAttach = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis);
499 // offset pour eviter confusion Edge et Dimension
500 gp_Vec offset(myAxisDirAttach);
501 offset = offset * myArrowSize * (-5);
502 gp_Vec Vt(myFAttach, PjFAttach);
503 gp_Pnt curpos = PjFAttach.Translated(offset.Added(Vt.Multiplied(.15)));
507 gp_Pnt Pj1 = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis);
508 gp_Pnt Pj2 = ElCLib::Value(ElCLib::Parameter(laxis,mySAttach),laxis);
509 if ((myFAttach.SquareDistance(Pj1)+mySAttach.SquareDistance(Pj2)) <= Precision::Confusion()) myArrowSize = 0.;
510 Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect();
511 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
512 arr->SetLength(myArrowSize);
513 arr = la->ArrowAspect();
514 arr->SetLength(myArrowSize);
515 if(cu1.GetType() == GeomAbs_Line)
516 DsgPrs_SymmetricPresentation::Add(aprs,
524 if(cu1.GetType() == GeomAbs_Circle)
525 DsgPrs_SymmetricPresentation::Add(aprs,
532 if ( (myExtShape != 0) && !extCurv.IsNull()) {
534 if ( myExtShape == 1 ) {
539 ComputeProjEdgePresentation(aprs,TopoDS::Edge(myFShape),geom1,pf,pl);
546 ComputeProjEdgePresentation(aprs,TopoDS::Edge(mySShape),geom2,pf,pl);
551 //=======================================================================
552 //function : ComputeTwoVertexsSymmetric
554 //=======================================================================
555 void PrsDim_SymmetricRelation::ComputeTwoVerticesSymmetric(const Handle(Prs3d_Presentation)& aprs)
557 if(myFShape.ShapeType() != TopAbs_VERTEX || mySShape.ShapeType() != TopAbs_VERTEX) return;
558 Handle(Geom_Curve) geom_axis,extcurve;
560 Standard_Boolean isinfinite,isonplane;
561 if (!PrsDim::ComputeGeometry(TopoDS::Edge(myTool),
568 Standard_Boolean isOnPlane1, isOnPlane2;
570 PrsDim::ComputeGeometry(TopoDS::Vertex(myFShape), myFAttach, myPlane, isOnPlane1);
571 PrsDim::ComputeGeometry(TopoDS::Vertex(mySShape), mySAttach, myPlane, isOnPlane2);
573 if( !myArrowSizeIsDefined )
574 myArrowSize = myFAttach.Distance(mySAttach)/50.;
576 if (isOnPlane1 && isOnPlane2)
578 else if ( isOnPlane1 && !isOnPlane2)
580 else if (!isOnPlane1 && isOnPlane2)
585 Handle(Geom_Line) geom_line = Handle(Geom_Line)::DownCast (geom_axis);
586 gp_Lin laxis (geom_line->Lin());
587 myAxisDirAttach = laxis.Direction();
589 // recherche points attache
591 if (myAutomaticPosition) {
592 gp_Pnt PjFAttach = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis);
593 // offset pour eviter confusion Edge et Dimension
594 gp_Vec offset(myAxisDirAttach);
595 offset = offset * myArrowSize * (-5);
596 gp_Vec Vt(myFAttach, PjFAttach);
597 gp_Pnt curpos = PjFAttach.Translated(offset.Added(Vt.Multiplied(.15)));
600 if (2*(myFAttach.Distance(mySAttach)) <= Precision::Confusion()) myArrowSize = 0.;
601 Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect();
602 Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect();
603 arr->SetLength(myArrowSize);
604 arr = la->ArrowAspect();
605 arr->SetLength(myArrowSize);
606 DsgPrs_SymmetricPresentation::Add(aprs,
612 if ( myExtShape == 1)
613 ComputeProjVertexPresentation(aprs,TopoDS::Vertex(myFShape),myFAttach);
614 else if ( myExtShape == 2)
615 ComputeProjVertexPresentation(aprs,TopoDS::Vertex(mySShape),mySAttach);