Replacing french comments by english one
[occt.git] / src / AIS / AIS_ConcentricRelation.cxx
1 // File:        AIS_ConcentricRelation.cdl
2 // Created:     Tue Dec  5 15:09:04 1996
3 // Author:      Flore Lantheaume/Odile Olivier
4 //              <ODL>
5
6 #include <Standard_NotImplemented.hxx>
7
8 #include <AIS_ConcentricRelation.ixx>
9
10 #include <SelectMgr_EntityOwner.hxx>
11 #include <Select3D_SensitiveCircle.hxx>
12 #include <Select3D_SensitiveSegment.hxx>
13
14 #include <DsgPrs_ConcentricPresentation.hxx>
15
16 #include <TopoDS.hxx>
17
18 #include <BRepAdaptor_Curve.hxx>
19
20 #include <GeomAbs_CurveType.hxx>
21 #include <Geom_Circle.hxx>
22 #include <gp_Dir.hxx>
23 #include <gp_Vec.hxx>
24 #include <gp_Ax2.hxx>
25 #include <gp_Ax1.hxx>
26 #include <gp_Pnt.hxx>
27 #include <gp_Pln.hxx>
28
29 #include <TopoDS_Vertex.hxx>
30 #include <AIS.hxx>
31
32 //=======================================================================
33 //function : Constructor
34 //purpose  : 
35 //=======================================================================
36
37 AIS_ConcentricRelation::AIS_ConcentricRelation(
38         const TopoDS_Shape& aFShape, 
39         const TopoDS_Shape& aSShape, 
40         const Handle(Geom_Plane)& aPlane)
41 {
42   myFShape = aFShape;
43   mySShape = aSShape;
44   myPlane = aPlane;
45   myDir = aPlane->Pln().Axis().Direction();
46 }
47
48 //=======================================================================
49 //function : Compute
50 //purpose  : 
51 //=======================================================================
52 void AIS_ConcentricRelation::Compute(const Handle(PrsMgr_PresentationManager3d)&, 
53                                      const Handle(Prs3d_Presentation)& aPresentation, 
54                                      const Standard_Integer)
55 {
56   aPresentation->Clear();
57
58   TopAbs_ShapeEnum type2(mySShape.ShapeType());
59   aPresentation->SetInfiniteState(Standard_True);
60   switch (myFShape.ShapeType()) {
61   case TopAbs_EDGE: 
62     {
63       if (type2 == TopAbs_EDGE) ComputeTwoEdgesConcentric(aPresentation);
64       else if (type2 == TopAbs_VERTEX) ComputeEdgeVertexConcentric(aPresentation);
65     }
66   break;
67   
68   case TopAbs_VERTEX: 
69     {
70       if (type2 == TopAbs_VERTEX) ComputeTwoVerticesConcentric(aPresentation);
71       else if (type2 == TopAbs_EDGE) ComputeEdgeVertexConcentric(aPresentation);      
72     }
73   break;
74   default: {return;}
75   }  
76 }
77
78 void AIS_ConcentricRelation::Compute(const Handle_Prs3d_Projector& aProjector, const Handle_Geom_Transformation& aTransformation, const Handle_Prs3d_Presentation& aPresentation)
79 {
80 // Standard_NotImplemented::Raise("AIS_ConcentricRelation::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
81   PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ;
82 }
83
84 //=======================================================================
85 //function : ComputeTwoEdgesConcentric
86 //purpose  : 
87 //=======================================================================
88 void AIS_ConcentricRelation::ComputeEdgeVertexConcentric(const Handle(Prs3d_Presentation)& aPresentation)
89 {
90   TopoDS_Edge E;
91   TopoDS_Vertex V;
92   if (myFShape.ShapeType() == TopAbs_EDGE) {
93     E = TopoDS::Edge(myFShape);
94     V = TopoDS::Vertex(mySShape);
95   }
96   else {
97     E = TopoDS::Edge(myFShape);
98     V = TopoDS::Vertex(mySShape);
99   }
100   gp_Pnt p1,p2;
101   Handle(Geom_Curve) C;
102   Handle(Geom_Curve) extCurv;
103   Standard_Boolean isInfinite;
104   Standard_Boolean isOnPlanEdge, isOnPlanVertex;
105   if (!AIS::ComputeGeometry(E,C,p1,p2,extCurv,isInfinite,isOnPlanEdge,myPlane)) return;
106   gp_Pnt P;
107   AIS::ComputeGeometry(V,P, myPlane, isOnPlanVertex);
108
109   const Handle(Geom_Circle)& CIRCLE = (Handle(Geom_Circle)&) C;
110   myCenter = CIRCLE->Location();
111   myRad = Min(CIRCLE->Radius()/5.,15.);
112   gp_Dir vec(p1.XYZ() - myCenter.XYZ() );
113   gp_Vec vectrans(vec);
114   myPnt = myCenter.Translated(vectrans.Multiplied(myRad));
115   DsgPrs_ConcentricPresentation::Add(aPresentation,myDrawer,myCenter,myRad,myDir,myPnt);
116   if (!isOnPlanEdge) AIS::ComputeProjEdgePresentation(aPresentation,myDrawer,E,CIRCLE,p1,p2);
117   if (!isOnPlanVertex) AIS::ComputeProjVertexPresentation(aPresentation,myDrawer,V,P);
118 }
119
120 //=======================================================================
121 //function : ComputeTwoEdgesConcentric
122 //purpose  : 
123 //=======================================================================
124 void AIS_ConcentricRelation::ComputeTwoVerticesConcentric(const Handle(Prs3d_Presentation)& aPresentation)
125 {
126   TopoDS_Vertex V1,V2;
127   V1 = TopoDS::Vertex(myFShape);
128   V2 = TopoDS::Vertex(myFShape);  
129   Standard_Boolean isOnPlanVertex1(Standard_True),isOnPlanVertex2(Standard_True);
130   gp_Pnt P1,P2;
131   AIS::ComputeGeometry(V1,P1, myPlane,isOnPlanVertex1);
132   AIS::ComputeGeometry(V2,P2, myPlane,isOnPlanVertex2);
133   myCenter = P1;
134   myRad    = 15.;
135   gp_Dir vec(myPlane->Pln().Position().XDirection());
136   gp_Vec vectrans(vec);
137   myPnt = myCenter.Translated(vectrans.Multiplied(myRad));
138   DsgPrs_ConcentricPresentation::Add(aPresentation,myDrawer,myCenter,myRad,myDir,myPnt);
139   if (!isOnPlanVertex1) AIS::ComputeProjVertexPresentation(aPresentation,myDrawer,V1,P1);
140   if (!isOnPlanVertex1) AIS::ComputeProjVertexPresentation(aPresentation,myDrawer,V2,P2);
141 }
142
143 //=======================================================================
144 //function : ComputeTwoEdgesConcentric
145 //purpose  : 
146 //=======================================================================
147 void AIS_ConcentricRelation::ComputeTwoEdgesConcentric(const Handle(Prs3d_Presentation)& aPresentation)
148 {
149   BRepAdaptor_Curve curv1(TopoDS::Edge(myFShape));
150   BRepAdaptor_Curve curv2(TopoDS::Edge(mySShape));
151   
152   gp_Pnt ptat11,ptat12,ptat21,ptat22;
153   Handle(Geom_Curve) geom1,geom2;
154   Standard_Boolean isInfinite1,isInfinite2;
155   Handle(Geom_Curve) extCurv;
156   if (!AIS::ComputeGeometry(TopoDS::Edge(myFShape),
157                             TopoDS::Edge(mySShape),
158                             myExtShape,
159                             geom1,
160                             geom2,
161                             ptat11,
162                             ptat12,
163                             ptat21,
164                             ptat22,
165                             extCurv,
166                             isInfinite1,isInfinite2,
167                             myPlane)) {
168     return;
169   }
170   
171   const Handle(Geom_Circle)& gcirc1 = (Handle(Geom_Circle)&) geom1;
172   const Handle(Geom_Circle)& gcirc2 = (Handle(Geom_Circle)&) geom2;
173   
174   myCenter = gcirc1->Location();
175   
176   // choose the radius equal to 1/5 of the smallest radius of 
177   // 2 circles. Limit is imposed ( 0.02 by chance)
178   Standard_Real rad1 = gcirc1->Radius();
179   Standard_Real rad2 = gcirc2->Radius();
180   myRad = (rad1 > rad2 ) ? rad2 : rad1;
181   myRad /= 5;
182   if (myRad > 15.) myRad =15.;
183   
184   
185   //Calculate a point of circle of radius myRad
186   gp_Dir vec(ptat11.XYZ() - myCenter.XYZ() );
187   gp_Vec vectrans(vec);
188   myPnt = myCenter.Translated(vectrans.Multiplied(myRad));
189   
190   DsgPrs_ConcentricPresentation::Add(aPresentation,
191                                      myDrawer,
192                                      myCenter,
193                                      myRad,
194                                      myDir,
195                                      myPnt);
196   if ( (myExtShape != 0) &&  !extCurv.IsNull()) {
197     gp_Pnt pf, pl;
198     if ( myExtShape == 1 ) {
199       if (!isInfinite1) {
200         pf = ptat11; 
201         pl = ptat12;
202       }
203       ComputeProjEdgePresentation(aPresentation,TopoDS::Edge(myFShape),gcirc1,pf,pl);
204     }
205     else {
206       if (!isInfinite2) {
207         pf = ptat21; 
208         pl = ptat22;
209       }
210       ComputeProjEdgePresentation(aPresentation,TopoDS::Edge(mySShape),gcirc2,pf,pl);
211     }
212   }
213 }
214
215 //=======================================================================
216 //function : Compute
217 //purpose  : to avoid warning
218 //=======================================================================
219
220 void AIS_ConcentricRelation::Compute(const Handle(Prs3d_Projector)&, 
221                                      const Handle(Prs3d_Presentation)&)
222 {
223 }
224
225 //=======================================================================
226 //function : Compute
227 //purpose  : to avoid warning
228 //=======================================================================
229
230 void AIS_ConcentricRelation::Compute(const Handle(PrsMgr_PresentationManager2d)&, 
231                                      const Handle(Graphic2d_GraphicObject)&,
232                                      const Standard_Integer)
233 {
234 }
235
236 //=======================================================================
237 //function : ComputeSelection
238 //purpose  : 
239 //=======================================================================
240
241 void AIS_ConcentricRelation::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, 
242                                               const Standard_Integer)
243 {
244   Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7);
245   
246   //Creation of 2 sensitive circles
247      // the greater
248   gp_Ax2 ax(myCenter, myDir);
249   Handle(Geom_Circle) Circ = new Geom_Circle(ax, myRad) ;
250   Handle(Select3D_SensitiveCircle) 
251     sensit = new Select3D_SensitiveCircle (own,
252                                            Circ);
253   aSelection->Add(sensit);
254      // the smaller
255   Circ->SetRadius(myRad/2);
256   sensit = new Select3D_SensitiveCircle (own,
257                                          Circ);
258   aSelection->Add(sensit);
259
260   //Creation of 2 segments sensitive for the cross
261   Handle(Select3D_SensitiveSegment) seg;
262   gp_Pnt otherPnt = myPnt.Mirrored(myCenter);
263   seg = new Select3D_SensitiveSegment(own,
264                                       otherPnt,
265                                       myPnt);
266   aSelection->Add(seg);
267
268   gp_Ax1 RotateAxis(myCenter, myDir);
269   gp_Pnt FPnt = myCenter.Rotated(RotateAxis, PI/2);
270   gp_Pnt SPnt = myCenter.Rotated(RotateAxis, -PI/2);
271   seg = new Select3D_SensitiveSegment(own,
272                                       FPnt,
273                                       SPnt);
274   aSelection->Add(seg);
275
276 }
277