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