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.
23 #include <Standard_NotImplemented.hxx>
25 #include <AIS_IdenticRelation.ixx>
28 #include <AIS_Shape.hxx>
29 #include <AIS_Drawer.hxx>
31 #include <BRep_Tool.hxx>
33 #include <DsgPrs_IdenticPresentation.hxx>
37 #include <Geom_Circle.hxx>
38 #include <Geom_Line.hxx>
39 #include <Geom_Plane.hxx>
40 #include <Geom_TrimmedCurve.hxx>
42 #include <Precision.hxx>
44 #include <Prs3d_Drawer.hxx>
45 #include <Prs3d_LineAspect.hxx>
47 #include <Select3D_SensitiveCurve.hxx>
48 #include <Select3D_SensitiveSegment.hxx>
49 #include <SelectMgr_EntityOwner.hxx>
51 #include <TColStd_ListIteratorOfListOfTransient.hxx>
53 #include <StdPrs_WFDeflectionShape.hxx>
55 #include <TCollection_ExtendedString.hxx>
60 #include <TopoDS_Edge.hxx>
61 #include <TopoDS_Vertex.hxx>
62 #include <TopoDS_Wire.hxx>
63 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
64 #include <TopTools_ListIteratorOfListOfShape.hxx>
72 #include <Geom_Ellipse.hxx>
73 #include <GeomAPI_ProjectPointOnCurve.hxx>
75 static Standard_Real Modulo2PI(const Standard_Real ANGLE)
77 if ( ANGLE < 0 ) return Modulo2PI(ANGLE + 2*M_PI);
78 else if ( ANGLE >= 2*M_PI ) return Modulo2PI(ANGLE - 2*M_PI);
82 static Standard_Boolean IsEqual2PI(const Standard_Real angle1,
83 const Standard_Real angle2, const Standard_Real precision)
85 Standard_Real diff = Abs(angle1-angle2);
86 if ( diff < precision ) return Standard_True;
87 else if ( Abs(diff-2*M_PI) < precision ) return Standard_True;
88 return Standard_False;
92 //=======================================================================
94 //purpose : sort an array of parameters <tab1> in increasing order
95 // updates <tab2> and <tab3> according to <tab1>
96 //=======================================================================
97 static void AIS_Sort(Standard_Real tab1[4],
99 Standard_Integer tab3[4])
101 Standard_Boolean found = Standard_True;
102 Standard_Real cur; gp_Pnt cur1; Standard_Integer cur2;
105 found = Standard_False;
106 for (Standard_Integer i=0; i< 3; i++) {
107 if (tab1[i+1] < tab1[i]) {
108 found = Standard_True;
109 cur = tab1[i]; cur1 = tab2[i]; cur2 = tab3[i];
110 tab1[i] = tab1[i+1]; tab2[i] = tab2[i+1]; tab3[i] = tab3[i+1];
111 tab1[i+1] = cur; tab2[i+1] = cur1; tab3[i+1] = cur2;
117 //=======================================================================
118 //function : ConnectedEdges
120 //=======================================================================
121 static Standard_Boolean ConnectedEdges(const TopoDS_Wire& WIRE,
122 const TopoDS_Vertex& V,
126 TopTools_IndexedDataMapOfShapeListOfShape vertexMap;
127 TopExp::MapShapesAndAncestors (WIRE,TopAbs_VERTEX,TopAbs_EDGE,vertexMap);
129 Standard_Boolean found(Standard_False);
130 TopoDS_Vertex theVertex;
131 for (Standard_Integer i=1; i<=vertexMap.Extent() && !found; i++) {
132 if (vertexMap.FindKey(i).IsSame(V)) {
133 theVertex = TopoDS::Vertex(vertexMap.FindKey(i));
134 found = Standard_True;
140 return Standard_False;
143 TopTools_ListIteratorOfListOfShape iterator(vertexMap.FindFromKey(theVertex));
144 if (iterator.More()) {
145 E1 = TopoDS::Edge(iterator.Value());
150 return Standard_False;
153 if (iterator.More()) {
154 E2 = TopoDS::Edge(iterator.Value());
159 return Standard_False;
162 if (iterator.More()) {
165 return Standard_False;
167 return Standard_True;
171 //=======================================================================
172 //function : ComputeAttach
173 //purpose : Compute a point on the arc of <thecirc>
174 // between <aFAttach> and <aSAttach>
175 // corresponding to <aPosition>
176 // Returns result into <aPosition>
177 // Note : This function is to be used only in the case of circles.
178 // The <aPosition> parameter is in/out.
179 //=======================================================================
180 static Standard_Boolean ComputeAttach(const gp_Circ& thecirc,
181 const gp_Pnt& aFAttach,
182 const gp_Pnt& aSAttach,
185 gp_Pnt curpos = aPosition;
187 // Case of confusion between the current position and the center
188 // of the circle -> we move the current position
189 Standard_Real confusion (Precision::Confusion());
190 gp_Pnt aCenter = thecirc.Location();
191 if ( aCenter.Distance(curpos) <= confusion )
193 gp_Vec vprec(aCenter, aFAttach);
195 curpos.Translate(vprec*1e-5);
198 Standard_Real pcurpos = ElCLib::Parameter(thecirc,curpos);
199 Standard_Real pFAttach = ElCLib::Parameter(thecirc,aFAttach);
200 Standard_Real pSAttach = ElCLib::Parameter(thecirc,aSAttach);
202 Standard_Real pSAttachM = pSAttach;
203 Standard_Real deltap = pSAttachM - pFAttach;
207 pSAttachM += 2 * M_PI;
209 pSAttachM -= pFAttach;
211 Standard_Real pmiddleout = pSAttachM/2.0 + M_PI;
213 Standard_Real pcurpos1 = pcurpos;
214 // define where curpos lays
215 if ( pcurpos1 < pFAttach )
217 pcurpos1 = pcurpos1 + 2 * M_PI - pFAttach;
218 if ( pcurpos1 > pSAttachM ) // out
220 if ( pcurpos1 > pmiddleout ) pcurpos = pFAttach;
221 else pcurpos = pSAttach;
224 else if ( pcurpos1 > (pFAttach + deltap) ) // out
226 pcurpos1 -= pFAttach;
227 if ( pcurpos1 > pmiddleout ) pcurpos = pFAttach;
228 else pcurpos = pSAttach;
231 aPosition = ElCLib::Value(pcurpos,thecirc);
232 return Standard_True;
235 //=======================================================================
236 //function : ComputeAttach
237 //purpose : Compute a point on the arc of ellipse <theEll>
238 // between <aFAttach> and <aSAttach>
239 // corresponding to <aPosition>
240 // Returns result into <aPosition>
241 // Note : This function is to be used only in the case of ellipses.
242 // The <aPosition> parameter is in/out.
243 //=======================================================================
244 static Standard_Boolean ComputeAttach(const gp_Elips& theEll,
245 const gp_Pnt& aFAttach,
246 const gp_Pnt& aSAttach,
249 gp_Pnt curpos = aPosition;
251 // Case of confusion between the current position and the center
252 // of the circle -> we move the current position
253 Standard_Real confusion (Precision::Confusion());
254 gp_Pnt aCenter = theEll.Location();
255 if ( aCenter.Distance(curpos) <= confusion )
257 gp_Vec vprec(aCenter, aFAttach);
259 curpos.Translate(vprec*1e-5);
262 // for ellipses it's not good Standard_Real pcurpos = ElCLib::Parameter(theEll,curpos);
263 Handle(Geom_Ellipse) theEllg = new Geom_Ellipse(theEll);
264 GeomAPI_ProjectPointOnCurve aProj (curpos, theEllg);
265 Standard_Real pcurpos = aProj.LowerDistanceParameter();
267 Standard_Real pFAttach = ElCLib::Parameter(theEll,aFAttach);
268 Standard_Real pSAttach = ElCLib::Parameter(theEll,aSAttach);
270 Standard_Real pSAttachM = pSAttach;
271 Standard_Real deltap = pSAttachM - pFAttach;
275 pSAttachM += 2 * M_PI;
277 pSAttachM -= pFAttach;
279 Standard_Real pmiddleout = pSAttachM/2.0 + M_PI;
281 Standard_Real pcurpos1 = pcurpos;
282 // define where curpos lays
283 if ( pcurpos1 < pFAttach )
285 pcurpos1 = pcurpos1 + 2 * M_PI - pFAttach;
286 if ( pcurpos1 > pSAttachM ) // out
288 if ( pcurpos1 > pmiddleout ) pcurpos = pFAttach;
289 else pcurpos = pSAttach;
292 else if ( pcurpos1 > (pFAttach + deltap) ) // out
294 pcurpos1 -= pFAttach;
295 if ( pcurpos1 > pmiddleout ) pcurpos = pFAttach;
296 else pcurpos = pSAttach;
299 aPosition = ElCLib::Value(pcurpos,theEll);
300 return Standard_True;
302 // jfa 16/10/2000 end
304 //=======================================================================
305 //function : AIS_IdenticRelation
307 //=======================================================================
308 AIS_IdenticRelation::AIS_IdenticRelation(const TopoDS_Shape& FirstShape,
309 const TopoDS_Shape& SecondShape,
310 const Handle(Geom_Plane)& aPlane)
311 :isCircle(Standard_False)
313 myFShape = FirstShape;
314 mySShape = SecondShape;
318 //=======================================================================
321 //=======================================================================
322 void AIS_IdenticRelation::Compute(const Handle(PrsMgr_PresentationManager3d)&,
323 const Handle(Prs3d_Presentation)& aprs,
324 const Standard_Integer)
328 switch ( myFShape.ShapeType() ) {
332 switch ( mySShape.ShapeType() ) {
335 ComputeTwoVerticesPresentation(aprs);
340 ComputeOneEdgeOVertexPresentation(aprs);
351 switch ( mySShape.ShapeType() ) {
354 ComputeOneEdgeOVertexPresentation(aprs);
359 ComputeTwoEdgesPresentation(aprs);
371 //=======================================================================
374 //=======================================================================
375 void AIS_IdenticRelation::Compute(const Handle(Prs3d_Projector)& aProjector,
376 const Handle(Prs3d_Presentation)& aPresentation)
378 // Standard_NotImplemented::Raise("AIS_IdenticRelation::Compute(const Handle(Prs3d_Projector)&,const Handle(Prs3d_Presentation)&)");
379 PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ;
382 void AIS_IdenticRelation::Compute(const Handle_Prs3d_Projector& aProjector, const Handle_Geom_Transformation& aTransformation, const Handle_Prs3d_Presentation& aPresentation)
384 // Standard_NotImplemented::Raise("AIS_IdenticRelation::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
385 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
388 //=======================================================================
389 //function : ComputeSelection
390 //purpose : function used to compute the selection associated to the
391 // "identic" presentation
392 // note : if we are in the case of lines, we create a segment between
393 // myFAttach and mySAttach. In the case of Circles, we create
394 // an arc of circle between the sames points. We Add a segment
395 // to link Position to its projection on the curve described
397 //=======================================================================
399 void AIS_IdenticRelation::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
400 const Standard_Integer)
402 Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
404 Handle(Select3D_SensitiveSegment) seg;
405 // attachement point of the segment linking position to the curve
407 Standard_Real confusion (Precision::Confusion());
409 if ( myFAttach.IsEqual(mySAttach, confusion) )
416 if ( myFShape.ShapeType() == TopAbs_EDGE )
418 Handle(Geom_Curve) curv1,curv2;
419 gp_Pnt firstp1,lastp1,firstp2,lastp2;
420 Standard_Boolean isInfinite1,isInfinite2;
421 Handle(Geom_Curve) extCurv;
422 if ( !AIS::ComputeGeometry(TopoDS::Edge(myFShape),TopoDS::Edge(mySShape),
423 myExtShape,curv1,curv2,
424 firstp1,lastp1,firstp2,lastp2,
425 extCurv,isInfinite1,isInfinite2,myPlane) ) return;
427 if ( isCircle ) // case of Circles
429 Handle(Geom_Circle) thecirc = (Handle(Geom_Circle)&) curv1;
430 Standard_Real udeb = ElCLib::Parameter(thecirc->Circ(),myFAttach);
431 Standard_Real ufin = ElCLib::Parameter(thecirc->Circ(),mySAttach);
432 Handle(Geom_TrimmedCurve) thecu = new Geom_TrimmedCurve(thecirc,udeb,ufin);
434 Handle(Select3D_SensitiveCurve) scurv = new Select3D_SensitiveCurve(own, thecu);
435 aSelection->Add(scurv);
438 ComputeAttach(thecirc->Circ(),myFAttach,mySAttach,attach);
440 else if ( curv1->IsInstance(STANDARD_TYPE(Geom_Ellipse)) ) // case of ellipses
442 Handle(Geom_Ellipse) theEll = (Handle(Geom_Ellipse)&) curv1;
444 Standard_Real udeb = ElCLib::Parameter(theEll->Elips(),myFAttach);
445 Standard_Real ufin = ElCLib::Parameter(theEll->Elips(),mySAttach);
446 Handle(Geom_TrimmedCurve) thecu = new Geom_TrimmedCurve(theEll,udeb,ufin);
448 Handle(Select3D_SensitiveCurve) scurv = new Select3D_SensitiveCurve(own, thecu);
449 aSelection->Add(scurv);
452 ComputeAttach(theEll->Elips(),myFAttach,mySAttach,attach);
454 else if ( curv1->IsInstance(STANDARD_TYPE(Geom_Line)) ) // case of Lines
456 seg = new Select3D_SensitiveSegment(own, myFAttach, mySAttach);
457 aSelection->Add(seg);
459 //attach = projection of Position() on the curve;
460 gp_Vec v1 (myFAttach, mySAttach);
461 gp_Vec v2 (myFAttach, myPosition);
462 if ( v1.IsParallel(v2, Precision::Angular()) )
468 gp_Lin ll (myFAttach, gp_Dir(v1));
469 attach = ElCLib::Value(ElCLib::Parameter(ll,myPosition), ll);
474 // else if ( myFShape.ShapeType() == TopAbs_VERTEX )
477 // jfa 24/10/2000 end
480 // Creation of the segment linking the attachement point with the
482 if ( !attach.IsEqual(myPosition, confusion) )
484 seg = new Select3D_SensitiveSegment(own, attach, myPosition);
485 aSelection->Add(seg);
489 //=======================================================================
490 //function : ComputeTwoEdgesPresentation
492 //=======================================================================
493 void AIS_IdenticRelation::ComputeTwoEdgesPresentation(const Handle(Prs3d_Presentation)& aPrs)
495 Handle(Geom_Curve) curv1,curv2;
496 gp_Pnt firstp1,lastp1,firstp2,lastp2;
497 Standard_Boolean isInfinite1,isInfinite2;
499 Handle(Geom_Curve) extCurv;
500 if (!AIS::ComputeGeometry(TopoDS::Edge(myFShape),
501 TopoDS::Edge(mySShape),
510 isInfinite1,isInfinite2,
513 aPrs->SetInfiniteState((isInfinite1 || isInfinite2) && myExtShape != 0);
515 // Treatement of the case of lines
516 if ( curv1->IsInstance(STANDARD_TYPE(Geom_Line)) && curv2->IsInstance(STANDARD_TYPE(Geom_Line)) ) {
517 // we take the line curv1 like support
518 Handle(Geom_Line) thelin;
519 if (isInfinite1 && !isInfinite2) thelin = (Handle(Geom_Line)&) curv2;
520 else if (!isInfinite1 && isInfinite2) thelin = (Handle(Geom_Line)&) curv1;
521 else thelin = (Handle(Geom_Line)&) curv1;
522 ComputeTwoLinesPresentation(aPrs, thelin, firstp1, lastp1, firstp2, lastp2, isInfinite1, isInfinite2);
525 // Treatement of the case of circles
526 else if ( curv1->IsInstance(STANDARD_TYPE(Geom_Circle)) && curv2->IsInstance(STANDARD_TYPE(Geom_Circle)) ) {
528 isCircle = Standard_True; // useful for ComputeSelection
529 const Handle(Geom_Circle)& thecirc = (Handle(Geom_Circle)&) curv1;
530 ComputeTwoCirclesPresentation(aPrs, thecirc, firstp1, lastp1, firstp2, lastp2);
534 // Treatement of the case of ellipses
535 else if ( curv1->IsInstance(STANDARD_TYPE(Geom_Ellipse)) && curv2->IsInstance(STANDARD_TYPE(Geom_Ellipse)) )
537 const Handle(Geom_Ellipse)& theEll = (Handle(Geom_Ellipse)&) curv1;
538 ComputeTwoEllipsesPresentation(aPrs, theEll, firstp1, lastp1, firstp2, lastp2);
540 // jfa 10/10/2000 end
544 // Calculate presentation of projected edges
545 if ( (myExtShape != 0) && !extCurv.IsNull()) {
546 if (myExtShape == 1 )
547 ComputeProjEdgePresentation(aPrs, TopoDS::Edge(myFShape), curv1, firstp1, lastp1);
549 ComputeProjEdgePresentation(aPrs, TopoDS::Edge(mySShape), curv2, firstp2, lastp2);
553 //=======================================================================
554 //function : ComputeTwoLinesPresentation
555 //purpose : Compute the presentation of the 'identic' constraint
556 // between two lines ( which are equal)
557 //input : <thelin> : the
558 // <firstp1>: first extremity of the 1st curve of the constraint
559 // <lastp1> : last extremity of the 1st curve of the constraint
560 // <firstp2>: first extremity of the 2nd curve of the constraint
561 // <lastp2> :last extremity of the 2nd curve of the constraint
562 //=======================================================================
563 void AIS_IdenticRelation::ComputeTwoLinesPresentation(const Handle(Prs3d_Presentation)& aPrs,
564 const Handle(Geom_Line)& thelin,
569 const Standard_Boolean isInfinite1,
570 const Standard_Boolean isInfinite2)
572 if (isInfinite1 && isInfinite2) {
573 if ( myAutomaticPosition ) {
574 myFAttach = mySAttach = thelin->Lin().Location();
576 gp_Pln pln(myPlane->Pln());
577 gp_Dir dir(pln.XAxis().Direction());
578 gp_Vec transvec = gp_Vec(dir)*myArrowSize;
579 curpos = myFAttach.Translated(transvec);;
581 myAutomaticPosition = Standard_True;
584 myFAttach = mySAttach = ElCLib::Value(ElCLib::Parameter(thelin->Lin(),myPosition),thelin->Lin());
586 TCollection_ExtendedString vals(" ==");
587 DsgPrs_IdenticPresentation::Add(aPrs,
594 // Computation of the parameters of the 4 points on the line <thelin>
595 Standard_Real pf1, pf2, pl1, pl2;
597 pf1 = ElCLib::Parameter(thelin->Lin(), firstp1);
598 pl1 = ElCLib::Parameter(thelin->Lin(), lastp1);
600 pf2 = ElCLib::Parameter(thelin->Lin(), firstp2);
601 pl2 = ElCLib::Parameter(thelin->Lin(), lastp2);
609 else if (isInfinite2) {
616 Standard_Real tabRang1[4]; // array taht contains the parameters of the 4 points
617 // ordered by increasing abscisses.
619 gp_Pnt tabRang2[4]; // array containing the points corresponding to the
620 // parameters in tabRang1
622 Standard_Integer tabRang3[4]; // array containing the number of the curve( 1 or 2)
623 // of which belongs each point of tabRang2
625 // Filling of the arrays
626 tabRang1[0] = pf1; tabRang2[0] = firstp1; tabRang3[0] = 1;
627 tabRang1[1] = pf2; tabRang2[1] = firstp2; tabRang3[1] = 2;
628 tabRang1[2] = pl1; tabRang2[2] = lastp1; tabRang3[2] = 1;
629 tabRang1[3] = pl2; tabRang2[3] = lastp2; tabRang3[3] = 2;
631 // Sort of the array of parameters (tabRang1)
632 AIS_Sort(tabRang1, tabRang2, tabRang3);
634 // Computation of myFAttach and mySAttach according to the
635 // position of the 2 linear edges
639 if ( (tabRang1[0] == tabRang1[1]) && (tabRang1[2] == tabRang1[3]) ) {
640 middle.SetXYZ((tabRang2[1].XYZ() + tabRang2[2].XYZ())/2. );
641 Standard_Real pmiddle = (tabRang1[1] + tabRang1[2]) / 2.;
642 Standard_Real delta = (tabRang1[3] - tabRang1[0])/ 5.;
643 myFAttach = ElCLib::Value(pmiddle-delta, thelin->Lin());
644 mySAttach = ElCLib::Value(pmiddle+delta, thelin->Lin());
647 else if ( tabRang1[1] == tabRang1[2] ) {
648 middle = tabRang2[1];
649 Standard_Real delta1 = tabRang1[1] - tabRang1[0];
650 Standard_Real delta2 = tabRang1[3] - tabRang1[2];
651 if ( delta1 > delta2 ) delta1 = delta2;
652 myFAttach = ElCLib::Value(tabRang1[1]-delta1/2., thelin->Lin());
653 mySAttach = ElCLib::Value(tabRang1[1]+delta1/2., thelin->Lin());
656 // Case of 2 disconnected segments -> the symbol completes the gap
657 // between the 2 edges
658 //--------------------------------
659 else if ( (tabRang3[0] == tabRang3[1]) && (tabRang1[1] != tabRang1[2])) {
660 middle.SetXYZ((tabRang2[1].XYZ() + tabRang2[2].XYZ())/2. );
661 myFAttach = tabRang2[1];
662 mySAttach = tabRang2[2];
664 else if ( (tabRang3[0] != tabRang3[1])
665 && (tabRang3[1] != tabRang3[2]) // Intersection
666 && (tabRang1[1] != tabRang1[2]) ) {
667 middle.SetXYZ((tabRang2[1].XYZ() + tabRang2[2].XYZ())/2. );
668 myFAttach = tabRang2[1];
669 mySAttach = tabRang2[2];
672 myFAttach.SetXYZ((tabRang2[0].XYZ() + tabRang2[1].XYZ())/2. );
673 mySAttach.SetXYZ((tabRang2[1].XYZ() + tabRang2[2].XYZ())/2. );
674 middle.SetXYZ( (myFAttach.XYZ() + mySAttach.XYZ() )/2.);
678 if ( myAutomaticPosition ) {
680 gp_Vec vtrans(myFAttach, mySAttach);
682 vtrans.Cross(gp_Vec(myPlane->Pln().Axis().Direction()));
683 vtrans *= ComputeSegSize();
684 curpos = middle.Translated(vtrans);
686 myAutomaticPosition = Standard_True;
692 Standard_Real pcurpos = ElCLib::Parameter(thelin->Lin() ,curpos);
693 Standard_Real dist = thelin->Lin().Distance(curpos);
694 gp_Pnt proj = ElCLib::Value( pcurpos, thelin->Lin());
696 Standard_Real confusion(Precision::Confusion());
697 if ( dist >= confusion ) {
698 trans = gp_Vec(proj, curpos);
701 Standard_Real pf = ElCLib::Parameter(thelin->Lin() ,myFAttach);
702 Standard_Real pl = ElCLib::Parameter(thelin->Lin() ,mySAttach);
703 if ( pcurpos <= pf ) {
705 curpos = ElCLib::Value( pcurpos, thelin->Lin());
706 if ( dist >= confusion ) curpos.Translate(trans*dist);
708 else if ( pcurpos >= pl ) {
710 curpos = ElCLib::Value( pcurpos, thelin->Lin());
711 if ( dist >= confusion ) curpos.Translate(trans*dist);
716 // Display of the presentation
717 TCollection_ExtendedString vals(" ==");
718 DsgPrs_IdenticPresentation::Add(aPrs,
728 //=======================================================================
729 //function : ComputeTwoCirclesPresentation
730 //purpose : Compute the presentation of the 'identic' constraint
731 // between two circles ( which are equal)
732 //input : <thecirc>: the circle
733 // <firstp1>: first extremity of the 1st curve of the constraint
734 // <lastp1> : last extremity of the 1st curve of the constraint
735 // <firstp2>: first extremity of the 2nd curve of the constraint
736 // <lastp2> :last extremity of the 2nd curve of the constraint
737 //=======================================================================
738 void AIS_IdenticRelation::ComputeTwoCirclesPresentation(const Handle(Prs3d_Presentation)& aPrs,
739 const Handle(Geom_Circle)& thecirc,
740 const gp_Pnt& firstp1,
741 const gp_Pnt& lastp1,
742 const gp_Pnt& firstp2,
743 const gp_Pnt& lastp2)
745 Standard_Real confusion (Precision::Confusion());
747 // Searching of complete circles
748 Standard_Boolean circ1complete = (firstp1.IsEqual(lastp1, confusion));
749 Standard_Boolean circ2complete = (firstp2.IsEqual(lastp2, confusion));
751 myCenter = thecirc->Location();
752 Standard_Real aSegSize = thecirc->Radius()/5.0;
753 Standard_Real rad = M_PI / 5.0;
755 // I. Case of 2 complete circles
756 if ( circ1complete && circ2complete )
758 if (myAutomaticPosition)
760 Standard_Real pfirst1 = ElCLib::Parameter(thecirc->Circ(), firstp1);
761 myFAttach = ElCLib::Value(Modulo2PI(pfirst1-rad), thecirc->Circ());
762 mySAttach = ElCLib::Value(Modulo2PI(pfirst1+rad), thecirc->Circ());
764 gp_Pnt curpos = ElCLib::Value(pfirst1,thecirc->Circ());
765 gp_Vec vtrans(myCenter, curpos);
768 curpos.Translate(vtrans);
771 else ComputeNotAutoCircPresentation(thecirc);
774 // II. Case of one complete circle and one arc
775 else if ( (circ1complete && !circ2complete) || (!circ1complete && circ2complete) )
777 gp_Pnt firstp, lastp;
778 if ( circ1complete && !circ2complete)
789 if (myAutomaticPosition)
791 ComputeAutoArcPresentation(thecirc, firstp, lastp);
795 ComputeNotAutoArcPresentation(thecirc, firstp, lastp);
799 // III and IV. Case of two arcs
800 else if ( !circ1complete && !circ2complete )
802 // We project all the points on the circle
803 Standard_Real pf1, pf2, pl1, pl2;
804 pf1 = ElCLib::Parameter(thecirc->Circ(), firstp1);
805 pf2 = ElCLib::Parameter(thecirc->Circ(), firstp2);
806 pl1 = ElCLib::Parameter(thecirc->Circ(), lastp1);
807 pl2 = ElCLib::Parameter(thecirc->Circ(), lastp2);
809 // III. Arcs with common ends
810 // III.1. First of one and last of another
811 if ( IsEqual2PI(pl1,pf2,confusion) || IsEqual2PI(pf1,pl2,confusion) )
813 gp_Pnt curpos(0.,0.,0.);
814 Standard_Real att=0.;
815 if ( IsEqual2PI(pl1,pf2,confusion) )
820 else if ( IsEqual2PI(pf1,pl2,confusion) )
825 Standard_Real maxrad = Min(Modulo2PI(pl1 - pf1),Modulo2PI(pl2 - pf2))*3/4;
826 if ( rad > maxrad ) rad = maxrad;
827 Standard_Real pFAttach = Modulo2PI(att - rad);
828 Standard_Real pSAttach = Modulo2PI(att + rad);
829 myFAttach = ElCLib::Value(pFAttach, thecirc->Circ());
830 mySAttach = ElCLib::Value(pSAttach, thecirc->Circ());
831 if ( myAutomaticPosition )
833 gp_Vec vtrans(myCenter,curpos);
836 curpos.Translate(vtrans);
840 // III.2. Two first or two last
841 else if ( IsEqual2PI(pf1,pf2,confusion) || IsEqual2PI(pl1,pl2,confusion) )
843 Standard_Real l1 = Modulo2PI(pl1 - pf1);
844 Standard_Real l2 = Modulo2PI(pl2 - pf2);
857 if ( myAutomaticPosition )
859 ComputeAutoArcPresentation(thecirc, firstp, lastp);
863 ComputeNotAutoArcPresentation(thecirc, firstp, lastp);
866 // IV. All others arcs (without common ends)
869 // order the parameters; first will be pf1
870 Standard_Real pl1m = Modulo2PI(pl1 - pf1);
871 Standard_Real pf2m = Modulo2PI(pf2 - pf1);
872 Standard_Real pl2m = Modulo2PI(pl2 - pf1);
874 Standard_Boolean case1 = Standard_False;
875 // 1 - not intersecting arcs
876 // 2 - intersecting arcs, but one doesn't contain another
877 // 3a - first arc contains the second one
878 // 3b - second arc contains the first one
879 // 4 - two intersections
881 gp_Pnt firstp, lastp;
883 if ( pl1m < pf2m ) // 1 or 2b or 3b
885 if ( pl1m < pl2m ) // 1 or 3b
887 if ( pl2m < pf2m ) // 3b
894 case1 = Standard_True;
895 Standard_Real deltap1 = Modulo2PI(pf1 - pl2);
896 Standard_Real deltap2 = Modulo2PI(pf2 - pl1);
897 if ( ((deltap1 < deltap2) && (deltap1 < 2*rad)) ||
898 ((deltap2 < deltap1) && (deltap2 > 2*rad)) ) // deltap2
916 else // 2a or 3a or 4
918 if ( pl1m < pl2m ) // 2a
925 if ( pl2m > pf2m ) // 3a
932 Standard_Real deltap1 = Modulo2PI(pl1 - pf2);
933 Standard_Real deltap2 = Modulo2PI(pl2 - pf1);
934 if ( ((deltap1 < deltap2) && (deltap1 < 2*rad)) ||
935 ((deltap2 < deltap1) && (deltap2 > 2*rad)) ) // deltap2
949 if ( myAutomaticPosition )
951 ComputeAutoArcPresentation(thecirc,firstp,lastp,case1);
960 else ComputeNotAutoArcPresentation(thecirc, firstp, lastp);
965 // Display of the presentation
966 TCollection_ExtendedString vals(" ==");
967 gp_Pnt attach = myPosition;
968 ComputeAttach(thecirc->Circ(),myFAttach,mySAttach,attach);
969 DsgPrs_IdenticPresentation::Add(aPrs,
972 myPlane->Pln().Position().Ax2(),
980 //=======================================================================
981 //function : ComputeAutoArcPresentation
982 //purpose : Compute the presentation of the constraint where we are
983 // not in the case of dragging.
984 //=======================================================================
985 void AIS_IdenticRelation::ComputeAutoArcPresentation(const Handle(Geom_Circle)& thecirc,
986 const gp_Pnt& firstp,
988 const Standard_Boolean isstatic)
990 Standard_Real aSegSize = thecirc->Radius()/5.0;
991 Standard_Real rad = M_PI / 5.0;
993 Standard_Real pFA = ElCLib::Parameter(thecirc->Circ(),firstp);
994 Standard_Real pSA = ElCLib::Parameter(thecirc->Circ(),lastp);
995 Standard_Real maxrad = Modulo2PI(pSA - pFA)/2.0;
997 if ( (rad > maxrad) || isstatic ) rad = maxrad;
998 Standard_Real pmiddle = Modulo2PI(pFA + Modulo2PI(pSA - pFA)/2.0);
1000 myFAttach = ElCLib::Value(Modulo2PI(pmiddle - rad),thecirc->Circ());
1001 mySAttach = ElCLib::Value(Modulo2PI(pmiddle + rad),thecirc->Circ());
1003 gp_Pnt curpos = ElCLib::Value(pmiddle,thecirc->Circ());
1004 gp_Vec vtrans(myCenter, curpos);
1007 myPosition = curpos.Translated(vtrans);
1010 //=======================================================================
1011 //function : ComputeNotAutoCircPresentation
1012 //purpose : Compute the presentation of the constraint where we are
1013 // in the case of dragging.
1014 // Note : This function is to be used only in the case of full circles.
1015 // The symbol of the constraint moves together with arc
1016 // representing the constraint around all the circle.
1017 //=======================================================================
1018 void AIS_IdenticRelation::ComputeNotAutoCircPresentation(const Handle(Geom_Circle)& thecirc)
1020 gp_Pnt curpos = myPosition;
1022 Handle(Geom_Circle) cirNotAuto = new Geom_Circle(thecirc->Circ());
1024 // Case of confusion between the current position and the center
1025 // of the circle -> we move the current position
1026 Standard_Real confusion (Precision::Confusion());
1027 if ( myCenter.Distance(curpos) <= confusion )
1029 gp_Vec vprec(myCenter, myFAttach);
1031 curpos.Translate(vprec*1e-5);
1034 Standard_Real rad = M_PI / 5.0;
1035 Standard_Real pcurpos = ElCLib::Parameter(cirNotAuto->Circ(),curpos);
1036 Standard_Real pFAttach = pcurpos - rad;
1037 Standard_Real pSAttach = pcurpos + rad;
1038 myFAttach = ElCLib::Value(pFAttach,cirNotAuto->Circ());
1039 mySAttach = ElCLib::Value(pSAttach,cirNotAuto->Circ());
1042 //=======================================================================
1043 //function : ComputeNotAutoArcPresentation
1044 //purpose : Compute the presentation of the constraint where we are
1045 // in the case of dragging.
1046 // Note : This function is to be used only in the case of circles.
1047 // The symbol of the constraint moves only between myFAttach
1049 //=======================================================================
1050 void AIS_IdenticRelation::ComputeNotAutoArcPresentation(const Handle(Geom_Circle)& thecirc,
1051 const gp_Pnt& pntfirst,
1052 const gp_Pnt& pntlast)
1054 gp_Pnt curpos = myPosition;
1056 gp_Circ cirNotAuto = thecirc->Circ();
1058 Standard_Real pFPnt = ElCLib::Parameter(cirNotAuto, pntfirst);
1059 Standard_Real pSPnt = ElCLib::Parameter(cirNotAuto, pntlast);
1060 Standard_Real deltap = Modulo2PI(pSPnt - pFPnt)/2.0;
1062 Standard_Real rad = M_PI / 5;
1065 myFAttach = pntfirst;
1066 mySAttach = pntlast;
1070 gp_Pnt aFPnt = ElCLib::Value(Modulo2PI(pFPnt + rad), cirNotAuto);
1071 gp_Pnt aSPnt = ElCLib::Value(Modulo2PI(pSPnt - rad), cirNotAuto);
1073 ComputeAttach(cirNotAuto,aFPnt,aSPnt,curpos);
1075 Standard_Real pcurpos = ElCLib::Parameter(cirNotAuto,curpos);
1076 myFAttach = ElCLib::Value(pcurpos - rad, cirNotAuto);
1077 mySAttach = ElCLib::Value(pcurpos + rad, cirNotAuto);
1080 // jfa 17/10/2000 end
1083 //=======================================================================
1084 //function : ComputeTwoEllipsesPresentation
1085 //purpose : Compute the presentation of the 'identic' constraint
1086 // between two ellipses (which are equal)
1087 //input : <theEll>: the ellipse
1088 // <firstp1>: first extremity of the 1st curve of the constraint
1089 // <lastp1> : last extremity of the 1st curve of the constraint
1090 // <firstp2>: first extremity of the 2nd curve of the constraint
1091 // <lastp2> :last extremity of the 2nd curve of the constraint
1092 //=======================================================================
1093 void AIS_IdenticRelation::ComputeTwoEllipsesPresentation(const Handle(Prs3d_Presentation)& aPrs,
1094 const Handle(Geom_Ellipse)& theEll,
1095 const gp_Pnt& firstp1,
1096 const gp_Pnt& lastp1,
1097 const gp_Pnt& firstp2,
1098 const gp_Pnt& lastp2)
1100 Standard_Real confusion (Precision::Confusion());
1102 // Searching of complete ellipses
1103 Standard_Boolean circ1complete = (firstp1.IsEqual(lastp1, confusion));
1104 Standard_Boolean circ2complete = (firstp2.IsEqual(lastp2, confusion));
1106 myCenter = theEll->Location();
1107 Standard_Real aSegSize = theEll->MajorRadius()/5.0;
1108 Standard_Real rad = M_PI / 5.0;
1110 // I. Case of 2 complete ellipses
1111 if ( circ1complete && circ2complete )
1113 if (myAutomaticPosition)
1115 Standard_Real pfirst1 = ElCLib::Parameter(theEll->Elips(), firstp1);
1116 myFAttach = ElCLib::Value(Modulo2PI(pfirst1-rad), theEll->Elips());
1117 mySAttach = ElCLib::Value(Modulo2PI(pfirst1+rad), theEll->Elips());
1119 gp_Pnt curpos = ElCLib::Value(pfirst1,theEll->Elips());
1120 gp_Vec vtrans(myCenter, curpos);
1123 curpos.Translate(vtrans);
1124 myPosition = curpos;
1126 else ComputeNotAutoElipsPresentation(theEll);
1129 // II. Case of one complete circle and one arc
1130 else if ( (circ1complete && !circ2complete) || (!circ1complete && circ2complete) )
1132 gp_Pnt firstp, lastp;
1133 if ( circ1complete && !circ2complete)
1144 if (myAutomaticPosition)
1146 ComputeAutoArcPresentation(theEll, firstp, lastp);
1150 ComputeNotAutoArcPresentation(theEll, firstp, lastp);
1154 // III and IV. Case of two arcs
1155 else if ( !circ1complete && !circ2complete )
1157 // We project all the points on the circle
1158 Standard_Real pf1, pf2, pl1, pl2;
1159 pf1 = ElCLib::Parameter(theEll->Elips(), firstp1);
1160 pf2 = ElCLib::Parameter(theEll->Elips(), firstp2);
1161 pl1 = ElCLib::Parameter(theEll->Elips(), lastp1);
1162 pl2 = ElCLib::Parameter(theEll->Elips(), lastp2);
1164 // III. Arcs with common ends
1165 // III.1. First of one and last of another
1166 if ( IsEqual2PI(pl1,pf2,confusion) || IsEqual2PI(pf1,pl2,confusion) )
1169 Standard_Real att=0.;
1170 if ( IsEqual2PI(pl1,pf2,confusion) )
1175 else if ( IsEqual2PI(pf1,pl2,confusion) )
1180 Standard_Real maxrad = Min(Modulo2PI(pl1 - pf1),Modulo2PI(pl2 - pf2))*3/4;
1181 if ( rad > maxrad ) rad = maxrad;
1182 Standard_Real pFAttach = Modulo2PI(att - rad);
1183 Standard_Real pSAttach = Modulo2PI(att + rad);
1184 myFAttach = ElCLib::Value(pFAttach, theEll->Elips());
1185 mySAttach = ElCLib::Value(pSAttach, theEll->Elips());
1186 if ( myAutomaticPosition )
1188 gp_Vec vtrans(myCenter,curpos);
1191 curpos.Translate(vtrans);
1192 myPosition = curpos;
1195 // III.2. Two first or two last
1196 else if ( IsEqual2PI(pf1,pf2,confusion) || IsEqual2PI(pl1,pl2,confusion) )
1198 Standard_Real l1 = Modulo2PI(pl1 - pf1);
1199 Standard_Real l2 = Modulo2PI(pl2 - pf2);
1200 gp_Pnt firstp,lastp;
1212 if ( myAutomaticPosition )
1214 ComputeAutoArcPresentation(theEll, firstp, lastp);
1218 ComputeNotAutoArcPresentation(theEll, firstp, lastp);
1221 // IV. All others arcs (without common ends)
1224 // order the parameters; first will be pf1
1225 Standard_Real pl1m = Modulo2PI(pl1 - pf1);
1226 Standard_Real pf2m = Modulo2PI(pf2 - pf1);
1227 Standard_Real pl2m = Modulo2PI(pl2 - pf1);
1229 Standard_Boolean case1 = Standard_False;
1230 // 1 - not intersecting arcs
1231 // 2 - intersecting arcs, but one doesn't contain another
1232 // 3a - first arc contains the second one
1233 // 3b - second arc contains the first one
1234 // 4 - two intersections
1236 gp_Pnt firstp, lastp;
1238 if ( pl1m < pf2m ) // 1 or 2b or 3b
1240 if ( pl1m < pl2m ) // 1 or 3b
1242 if ( pl2m < pf2m ) // 3b
1249 case1 = Standard_True;
1250 Standard_Real deltap1 = Modulo2PI(pf1 - pl2);
1251 Standard_Real deltap2 = Modulo2PI(pf2 - pl1);
1252 if ( ((deltap1 < deltap2) && (deltap1 < 2*rad)) ||
1253 ((deltap2 < deltap1) && (deltap2 > 2*rad)) ) // deltap2
1271 else // 2a or 3a or 4
1273 if ( pl1m < pl2m ) // 2a
1280 if ( pl2m > pf2m ) // 3a
1287 Standard_Real deltap1 = Modulo2PI(pl1 - pf2);
1288 Standard_Real deltap2 = Modulo2PI(pl2 - pf1);
1289 if ( ((deltap1 < deltap2) && (deltap1 < 2*rad)) ||
1290 ((deltap2 < deltap1) && (deltap2 > 2*rad)) ) // deltap2
1304 if ( myAutomaticPosition )
1306 ComputeAutoArcPresentation(theEll,firstp,lastp,case1);
1315 else ComputeNotAutoArcPresentation(theEll, firstp, lastp);
1320 // Display of the presentation
1321 TCollection_ExtendedString vals(" ==");
1322 gp_Pnt attach = myPosition;
1323 ComputeAttach(theEll->Elips(),myFAttach,mySAttach,attach);
1324 DsgPrs_IdenticPresentation::Add(aPrs,
1334 //=======================================================================
1335 //function : ComputeAutoArcPresentation
1336 //purpose : Compute the presentation of the constraint where we are
1337 // not in the case of dragging.
1338 //=======================================================================
1339 void AIS_IdenticRelation::ComputeAutoArcPresentation(const Handle(Geom_Ellipse)& theEll,
1340 const gp_Pnt& firstp,
1341 const gp_Pnt& lastp,
1342 const Standard_Boolean isstatic)
1344 Standard_Real aSegSize = theEll->MajorRadius()/5.0;
1345 Standard_Real rad = M_PI / 5.0;
1347 gp_Elips anEll = theEll->Elips();
1349 Standard_Real pFA = ElCLib::Parameter(anEll,firstp);
1350 Standard_Real pSA = ElCLib::Parameter(anEll,lastp);
1351 Standard_Real maxrad = Modulo2PI(pSA - pFA)/2.0;
1353 if ( (rad > maxrad) || isstatic ) rad = maxrad;
1354 Standard_Real pmiddle = Modulo2PI(pFA + Modulo2PI(pSA - pFA)/2.0);
1356 myFAttach = ElCLib::Value(Modulo2PI(pmiddle - rad),anEll);
1357 mySAttach = ElCLib::Value(Modulo2PI(pmiddle + rad),anEll);
1359 gp_Pnt curpos = ElCLib::Value(pmiddle,anEll);
1360 gp_Vec vtrans(myCenter, curpos);
1363 myPosition = curpos.Translated(vtrans);
1366 //=======================================================================
1367 //function : ComputeNotAutoElipsPresentation
1368 //purpose : Compute the presentation of the constraint where we are
1369 // in the case of dragging.
1370 // Note : This function is to be used only in the case of ellipses.
1371 // The symbol of the constraint moves only between myFAttach
1373 //=======================================================================
1374 void AIS_IdenticRelation::ComputeNotAutoElipsPresentation(const Handle(Geom_Ellipse)& theEll)
1376 gp_Pnt curpos = myPosition;
1378 gp_Elips anEll = theEll->Elips();
1380 // Case of confusion between the current position and the center
1381 // of the ellipse -> we move the current position
1382 Standard_Real confusion (Precision::Confusion());
1383 if ( myCenter.Distance(curpos) <= confusion )
1385 gp_Vec vprec(myCenter, myFAttach);
1387 curpos.Translate(vprec*1e-5);
1390 Standard_Real rad = M_PI / 5.0;
1391 // Standard_Real pcurpos = ElCLib::Parameter(anEll,curpos);
1392 GeomAPI_ProjectPointOnCurve aProj (curpos, theEll);
1393 Standard_Real pcurpos = aProj.LowerDistanceParameter();
1395 Standard_Real pFAttach = pcurpos - rad;
1396 Standard_Real pSAttach = pcurpos + rad;
1397 myFAttach = ElCLib::Value(pFAttach,anEll);
1398 mySAttach = ElCLib::Value(pSAttach,anEll);
1401 //=======================================================================
1402 //function : ComputeNotAutoArcPresentation
1403 //purpose : Compute the presentation of the constraint where we are
1404 // in the case of dragging.
1405 // Note : This function is to be used only in the case of ellipses.
1406 // The symbol of the constraint moves only between myFAttach
1408 //=======================================================================
1409 void AIS_IdenticRelation::ComputeNotAutoArcPresentation(const Handle(Geom_Ellipse)& theEll,
1410 const gp_Pnt& pntfirst,
1411 const gp_Pnt& pntlast)
1413 gp_Pnt curpos = myPosition;
1415 gp_Elips anEll = theEll->Elips();
1417 Standard_Real pFPnt = ElCLib::Parameter(anEll, pntfirst);
1418 Standard_Real pSPnt = ElCLib::Parameter(anEll, pntlast);
1419 Standard_Real deltap = Modulo2PI(pSPnt - pFPnt)/2.0;
1421 Standard_Real rad = M_PI / 5;
1424 myFAttach = pntfirst;
1425 mySAttach = pntlast;
1429 gp_Pnt aFPnt = ElCLib::Value(Modulo2PI(pFPnt + rad), anEll);
1430 gp_Pnt aSPnt = ElCLib::Value(Modulo2PI(pSPnt - rad), anEll);
1432 ComputeAttach(anEll,aFPnt,aSPnt,curpos);
1434 // Standard_Real pcurpos = ElCLib::Parameter(anEll,curpos);
1435 GeomAPI_ProjectPointOnCurve aProj (curpos, theEll);
1436 Standard_Real pcurpos = aProj.LowerDistanceParameter();
1438 myFAttach = ElCLib::Value(pcurpos - rad, anEll);
1439 mySAttach = ElCLib::Value(pcurpos + rad, anEll);
1442 // jfa 18/10/2000 end
1444 //=======================================================================
1445 //function : ComputeTwoVerticesPresentation
1447 //=======================================================================
1448 void AIS_IdenticRelation::ComputeTwoVerticesPresentation(const Handle(Prs3d_Presentation)& aPrs)
1450 Standard_Boolean isOnPlane1, isOnPlane2;
1451 const TopoDS_Vertex& FVertex = TopoDS::Vertex(myFShape);
1452 const TopoDS_Vertex& SVertex = TopoDS::Vertex(mySShape);
1454 AIS::ComputeGeometry(FVertex, myFAttach, myPlane, isOnPlane1);
1455 AIS::ComputeGeometry(SVertex, mySAttach, myPlane, isOnPlane2);
1457 if (isOnPlane1 && isOnPlane2)
1459 else if ( isOnPlane1 && !isOnPlane2)
1461 else if (!isOnPlane1 && isOnPlane2)
1467 // The attachement points are the points themselves that must be
1469 myFAttach = BRep_Tool::Pnt(FVertex);
1470 mySAttach = myFAttach;
1473 if (myAutomaticPosition)
1475 //Computation of the size of the symbol
1476 Standard_Real symbsize = ComputeSegSize();
1477 if (symbsize <= Precision::Confusion()) symbsize = 1.;
1479 // Computation of the direction of the segment of the presentation
1480 // we take the median of the edges connected to vertices
1483 TColStd_ListIteratorOfListOfTransient it(Users());
1486 const Handle(AIS_Shape)& USER = Handle(AIS_Shape)::DownCast(it.Value());
1489 const TopoDS_Shape& SH =USER->Shape();
1490 if ( (!SH.IsNull()) && (SH.ShapeType() == TopAbs_WIRE) )
1492 const TopoDS_Wire& WIRE = TopoDS::Wire(USER->Shape());
1493 Standard_Boolean done = ComputeDirection(WIRE,FVertex,dF);
1495 done = ComputeDirection(WIRE,SVertex,dS);
1502 // computation of the segment direction like average
1503 // of the 2 computed directions.
1504 if ( dF.IsParallel(dS, Precision::Angular()) )
1506 myDir = dF.Crossed(myPlane->Pln().Axis().Direction());
1510 myDir.SetXYZ(dF.XYZ() + dS.XYZ());
1512 curpos = myFAttach.Translated(gp_Vec(myDir)*symbsize) ;
1519 // jfa 11/10/2000 end
1521 myPosition = curpos;
1522 myAutomaticPosition = Standard_False;
1526 curpos = myPosition;
1529 // Presentation computation
1530 TCollection_ExtendedString vals(" ++");
1531 DsgPrs_IdenticPresentation::Add(aPrs,
1536 // Calculate the projection of vertex
1537 if ( myExtShape == 1)
1538 ComputeProjVertexPresentation(aPrs,FVertex,myFAttach);
1539 else if ( myExtShape == 2)
1540 ComputeProjVertexPresentation(aPrs,SVertex,mySAttach);
1545 //=======================================================================
1546 //function : ComputeSegSize
1548 //=======================================================================
1549 Standard_Real AIS_IdenticRelation::ComputeSegSize() const
1554 //=======================================================================
1555 //function : ComputeDirection
1556 //purpose : Compute a direction according to the different geometric
1557 // elements connected to the vertex <VERT>, in way to not have
1558 // overlap between the symbol and them.
1559 //=======================================================================
1560 Standard_Boolean AIS_IdenticRelation::ComputeDirection(const TopoDS_Wire& aWire,
1561 const TopoDS_Vertex& VERT,
1564 // we take the median of the edges connected to vertices
1565 TopoDS_Edge edg1,edg2;
1566 ConnectedEdges(aWire,VERT,edg1,edg2);
1568 if ( edg1.IsNull() && edg2.IsNull() ) {
1569 return Standard_False;
1572 Handle(Geom_Curve) curv1,curv2;
1573 gp_Pnt firstp1,lastp1,firstp2,lastp2;
1575 // Case with 2 edges connected to the vertex <VERT>
1576 if ( !edg1.IsNull() && !edg2.IsNull() ) {
1577 if ( !AIS::ComputeGeometry(edg1,edg2,
1580 firstp2, lastp2,myPlane))
1581 return Standard_False;
1584 if ( curv1->IsInstance(STANDARD_TYPE(Geom_Circle)) ) {
1585 d1 = ComputeCircleDirection((Handle(Geom_Circle)&) curv1, VERT);
1587 else if (curv1->IsInstance(STANDARD_TYPE(Geom_Line)) ) {
1588 d1 = ComputeLineDirection((Handle(Geom_Line)&) curv1, firstp1);
1591 return Standard_False;
1593 if ( curv2->IsInstance(STANDARD_TYPE(Geom_Circle)) ) {
1594 d2 = ComputeCircleDirection( (Handle(Geom_Circle)&) curv2, VERT);
1596 else if (curv2->IsInstance(STANDARD_TYPE(Geom_Line)) ) {
1597 d2 =ComputeLineDirection( (Handle(Geom_Line)&) curv2, firstp2);
1600 return Standard_False;
1602 if ( !d1.IsParallel(d2, Precision::Angular() ))
1603 dF.SetXYZ( (d1.XYZ() + d2.XYZ())/2 );
1605 dF= d1.Crossed(myPlane->Pln().Axis().Direction());
1609 // Case where <VERT> is at an extremity of a wire.
1612 if ( !edg1.IsNull() )
1614 else if (!edg2.IsNull() )
1617 return Standard_False;
1619 if ( !AIS::ComputeGeometry(VEdge, curv1, firstp1, lastp1) )
1620 return Standard_False;
1621 if ( curv1->IsInstance(STANDARD_TYPE(Geom_Circle)) ) {
1622 dF = ComputeCircleDirection( (Handle(Geom_Circle)&) curv1, VERT);
1624 else if (curv1->IsInstance(STANDARD_TYPE(Geom_Line)) ) {
1625 dF = ComputeLineDirection( (Handle(Geom_Line)&) curv1, firstp1);
1628 return Standard_False;
1631 return Standard_True;
1634 //=======================================================================
1635 //function : ComputeLineDirection
1637 //=======================================================================
1638 gp_Dir AIS_IdenticRelation::ComputeLineDirection(const Handle(Geom_Line)& lin,
1639 const gp_Pnt& firstP) const
1642 dir = lin->Lin().Direction();
1643 if ( !myFAttach.IsEqual(firstP, Precision::Confusion()) )
1648 //=======================================================================
1649 //function : ComputeCircleDirection
1651 //=======================================================================
1652 gp_Dir AIS_IdenticRelation::ComputeCircleDirection(const Handle(Geom_Circle)& circ,
1653 const TopoDS_Vertex& VERT) const
1655 gp_Vec V(circ->Location(),BRep_Tool::Pnt(VERT));
1659 //=======================================================================
1660 //function : ComputeOneEdgeOVertexPresentation
1662 //=======================================================================
1663 void AIS_IdenticRelation::ComputeOneEdgeOVertexPresentation(const Handle(Prs3d_Presentation)& aPrs)
1667 Standard_Integer numedge;
1669 if (myFShape.ShapeType() == TopAbs_VERTEX) {
1670 V = TopoDS::Vertex(myFShape);
1671 E = TopoDS::Edge(mySShape);
1672 numedge = 2;// edge = 2nd shape
1675 V = TopoDS::Vertex(mySShape);
1676 E = TopoDS::Edge(myFShape);
1677 numedge = 1; // edge = 1st shape
1679 gp_Pnt ptonedge1,ptonedge2;
1680 Handle(Geom_Curve) aCurve;
1681 Handle(Geom_Curve) extCurv;
1682 Standard_Boolean isInfinite;
1683 Standard_Boolean isOnPlanEdge, isOnPlanVertex;
1684 if (!AIS::ComputeGeometry(E,aCurve,ptonedge1,ptonedge2,extCurv,isInfinite,isOnPlanEdge,myPlane))
1686 aPrs->SetInfiniteState(isInfinite);
1687 AIS::ComputeGeometry(V, myFAttach, myPlane, isOnPlanVertex);
1689 // only the curve can be projected
1690 if (!isOnPlanEdge && !isOnPlanVertex) return;
1692 if (!isOnPlanEdge) {
1693 if (numedge == 1) myExtShape = 1;
1694 else myExtShape = 2;
1696 else if (!isOnPlanVertex) {
1697 if (numedge == 1) myExtShape = 2;
1698 else myExtShape = 1;
1700 // The attachement points are the point
1701 myFAttach = BRep_Tool::Pnt(V);
1702 mySAttach = myFAttach;
1705 if (myAutomaticPosition) {
1706 //Computation of the size of the symbol
1707 Standard_Real symbsize = ComputeSegSize();
1709 // Computation of the direction of the segment of the presentation
1710 // we take the median of the edges connected to vertices
1712 if ( aCurve->IsKind(STANDARD_TYPE(Geom_Line))) {
1713 myDir = ((Handle(Geom_Line)&) aCurve)->Lin().Direction();
1714 myDir.Cross(myPlane->Pln().Axis().Direction());
1716 else if (aCurve->IsKind(STANDARD_TYPE(Geom_Circle))) {
1717 Handle(Geom_Circle) CIR = (Handle(Geom_Circle)&) aCurve;
1718 myDir.SetXYZ(myFAttach.XYZ() - CIR->Location().XYZ());
1721 else if (aCurve->IsKind(STANDARD_TYPE(Geom_Ellipse))) {
1722 Handle(Geom_Ellipse) CIR = (Handle(Geom_Ellipse)&) aCurve;
1723 myDir.SetXYZ(myFAttach.XYZ() - CIR->Location().XYZ());
1725 // jfa 10/10/2000 end
1727 curpos = myFAttach.Translated(gp_Vec(myDir)*symbsize) ;
1728 myPosition = curpos;
1729 myAutomaticPosition = Standard_True;
1732 curpos = myPosition;
1735 // Presentation computation
1736 TCollection_ExtendedString vals(" -+-");
1737 DsgPrs_IdenticPresentation::Add(aPrs,
1742 if (myExtShape != 0) {
1743 if (!extCurv.IsNull()) { // the edge is not in the WP
1744 ComputeProjEdgePresentation(aPrs,E,(Handle(Geom_Line)&) aCurve,ptonedge1,ptonedge2);