b311480e |
1 | // Created on: 1997-03-03 |
2 | // Created by: Jean-Pierre COMBE |
3 | // Copyright (c) 1997-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
7fd59977 |
17 | |
7fd59977 |
18 | #include <AIS.hxx> |
42cf5bc1 |
19 | #include <AIS_SymmetricRelation.hxx> |
7fd59977 |
20 | #include <BRep_Tool.hxx> |
7fd59977 |
21 | #include <BRepAdaptor_Curve.hxx> |
42cf5bc1 |
22 | #include <BRepAdaptor_Surface.hxx> |
23 | #include <DsgPrs_SymmetricPresentation.hxx> |
7fd59977 |
24 | #include <ElCLib.hxx> |
42cf5bc1 |
25 | #include <gce_MakeLin.hxx> |
26 | #include <Geom_Circle.hxx> |
27 | #include <Geom_Line.hxx> |
28 | #include <Geom_Plane.hxx> |
29 | #include <Geom_Transformation.hxx> |
7fd59977 |
30 | #include <gp_Ax1.hxx> |
31 | #include <gp_Ax2.hxx> |
42cf5bc1 |
32 | #include <gp_Circ.hxx> |
33 | #include <gp_Dir.hxx> |
34 | #include <gp_Lin.hxx> |
35 | #include <gp_Pln.hxx> |
36 | #include <gp_Pnt.hxx> |
7fd59977 |
37 | #include <Precision.hxx> |
7fd59977 |
38 | #include <Prs3d_ArrowAspect.hxx> |
a6eb515f |
39 | #include <Prs3d_DimensionAspect.hxx> |
42cf5bc1 |
40 | #include <Prs3d_Drawer.hxx> |
41 | #include <Prs3d_Presentation.hxx> |
42 | #include <Prs3d_Projector.hxx> |
43 | #include <Select3D_SensitiveBox.hxx> |
44 | #include <Select3D_SensitiveSegment.hxx> |
45 | #include <SelectMgr_EntityOwner.hxx> |
46 | #include <SelectMgr_Selection.hxx> |
47 | #include <Standard_NotImplemented.hxx> |
48 | #include <Standard_Type.hxx> |
49 | #include <TopExp_Explorer.hxx> |
50 | #include <TopoDS.hxx> |
51 | #include <TopoDS_Shape.hxx> |
7fd59977 |
52 | |
92efcf78 |
53 | IMPLEMENT_STANDARD_RTTIEXT(AIS_SymmetricRelation,AIS_Relation) |
54 | |
7fd59977 |
55 | //======================================================================= |
56 | //function : AIS_SymmetricRelation |
57 | //purpose : |
58 | //======================================================================= |
59 | AIS_SymmetricRelation::AIS_SymmetricRelation(const TopoDS_Shape& aSymmTool, |
60 | const TopoDS_Shape& FirstShape, |
61 | const TopoDS_Shape& SecondShape, |
62 | const Handle(Geom_Plane)& aPlane) |
63 | :AIS_Relation(), |
64 | myTool(aSymmTool) |
65 | { |
66 | SetFirstShape(FirstShape); |
67 | SetSecondShape(SecondShape); |
68 | SetPlane(aPlane); |
69 | myPosition = aPlane->Pln().Location(); |
70 | } |
71 | |
72 | //======================================================================= |
73 | //function : Compute |
74 | //purpose : |
75 | //======================================================================= |
76 | void AIS_SymmetricRelation::Compute(const Handle(PrsMgr_PresentationManager3d)&, |
77 | const Handle(Prs3d_Presentation)& aprs, |
78 | const Standard_Integer) |
79 | { |
80 | aprs->Clear(); |
81 | |
82 | switch (myFShape.ShapeType()) { |
83 | case TopAbs_FACE : |
84 | { |
85 | // cas symetrie entre deux faces |
86 | ComputeTwoFacesSymmetric(aprs); |
87 | } |
88 | break; |
89 | case TopAbs_EDGE : |
90 | { |
91 | // cas symetrie entre deux edges |
92 | ComputeTwoEdgesSymmetric(aprs); |
93 | } |
94 | break; |
95 | case TopAbs_VERTEX : |
96 | { |
97 | // cas symetrie entre deux vertexs |
98 | ComputeTwoVerticesSymmetric(aprs); |
99 | } |
100 | break; |
101 | default: |
102 | break; |
103 | } |
104 | if (myTool.ShapeType() == TopAbs_EDGE) { |
105 | Handle(Geom_Curve) aCurve,extcurve; |
106 | gp_Pnt p1,p2; |
107 | Standard_Boolean isinfinite,isonplane; |
108 | if (AIS::ComputeGeometry(TopoDS::Edge(myTool), |
109 | aCurve,p1,p2, |
110 | extcurve, |
111 | isinfinite, |
112 | isonplane, |
113 | myPlane)) { |
114 | if (!extcurve.IsNull()) { |
115 | gp_Pnt pf, pl; |
116 | if (!isinfinite) { |
117 | pf = p1; |
118 | pl = p2; |
119 | } |
120 | if (isinfinite) aprs->SetInfiniteState(Standard_True); |
121 | ComputeProjEdgePresentation(aprs,TopoDS::Edge(myTool),aCurve,pf,pl); |
122 | } |
123 | } |
124 | } |
125 | } |
126 | |
127 | //======================================================================= |
128 | //function : Compute |
129 | //purpose : to avoid warning at compilation (SUN) |
130 | //======================================================================= |
131 | void AIS_SymmetricRelation::Compute(const Handle(Prs3d_Projector)& /*aProjector*/, |
132 | const Handle(Prs3d_Presentation)& /*aPresentation*/) |
133 | { |
134 | // Standard_NotImplemented::Raise("AIS_SymmetricRelation::Compute(const Handle(Prs3d_Projector)&,const Handle(Prs3d_Presentation)&)"); |
135 | // PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ; |
136 | } |
137 | |
857ffd5e |
138 | void AIS_SymmetricRelation::Compute(const Handle(Prs3d_Projector)& aProjector, |
139 | const Handle(Geom_Transformation)& aTransformation, |
140 | const Handle(Prs3d_Presentation)& aPresentation) |
7fd59977 |
141 | { |
857ffd5e |
142 | Standard_NotImplemented::Raise("AIS_SymmetricRelation::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)"); |
7fd59977 |
143 | PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ; |
144 | } |
145 | |
146 | //======================================================================= |
147 | //function : ComputeSelection |
148 | //purpose : |
149 | //======================================================================= |
150 | void AIS_SymmetricRelation::ComputeSelection(const Handle(SelectMgr_Selection)& aSel, |
151 | const Standard_Integer) |
152 | { |
153 | Handle(Select3D_SensitiveSegment) seg; |
154 | Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7); |
155 | Standard_Real F,L; |
156 | |
aa00364d |
157 | Handle(Geom_Curve) geom_axis, extcurve; |
7fd59977 |
158 | gp_Pnt p1,p2; |
159 | Standard_Boolean isinfinite,isonplane; |
160 | if (!AIS::ComputeGeometry(TopoDS::Edge(myTool), |
161 | geom_axis,p1,p2, |
162 | extcurve, |
163 | isinfinite, |
164 | isonplane, |
165 | myPlane)) return; |
166 | |
aa00364d |
167 | Handle(Geom_Line) geom_line = Handle(Geom_Line)::DownCast (geom_axis); |
168 | gp_Lin laxis (geom_line->Lin()); |
7fd59977 |
169 | |
170 | if(myFShape.ShapeType() != TopAbs_VERTEX){ |
171 | BRepAdaptor_Curve cu1(TopoDS::Edge(myFShape)); |
172 | |
173 | if(cu1.GetType() == GeomAbs_Line) { |
174 | // gp_Lin L1 (myFAttach,myFDirAttach); |
175 | gp_Pnt PjAttachPnt1 = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis); |
176 | gp_Pnt PjOffSetPnt = ElCLib::Value(ElCLib::Parameter(laxis,myPosition),laxis); |
177 | Standard_Real h = fabs(PjOffSetPnt.Distance(PjAttachPnt1)/cos(myAxisDirAttach.Angle(myFDirAttach))); |
178 | gp_Vec VL1(myFDirAttach); |
179 | gp_Vec VLa(PjAttachPnt1,PjOffSetPnt); |
180 | Standard_Real scal = VL1.Dot(VLa); |
181 | if(scal < 0) VL1.Reverse(); |
182 | VL1.Multiply(h); |
183 | gp_Pnt P1 = myFAttach.Translated(VL1); |
184 | gp_Pnt ProjAxis = ElCLib::Value(ElCLib::Parameter(laxis,P1),laxis); |
185 | gp_Vec v(P1,ProjAxis); |
186 | gp_Pnt P2 = ProjAxis.Translated(v); |
187 | |
188 | gp_Lin L3; |
189 | |
190 | if (!P1.IsEqual(P2,Precision::Confusion())) { |
191 | L3 = gce_MakeLin(P1,P2); |
192 | } |
193 | else { |
194 | L3 = gce_MakeLin(P1,myFDirAttach); |
195 | Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6)); |
196 | Handle(Select3D_SensitiveBox) box = |
197 | new Select3D_SensitiveBox(own, |
198 | myPosition.X(), |
199 | myPosition.Y(), |
200 | myPosition.Z(), |
201 | myPosition.X()+size, |
202 | myPosition.Y()+size, |
203 | myPosition.Z()+size); |
204 | aSel->Add(box); |
205 | } |
206 | Standard_Real parmin,parmax,parcur; |
207 | parmin = ElCLib::Parameter(L3,P1); |
208 | parmax = parmin; |
209 | |
210 | parcur = ElCLib::Parameter(L3,P2); |
211 | parmin = Min(parmin,parcur); |
212 | parmax = Max(parmax,parcur); |
213 | |
214 | parcur = ElCLib::Parameter(L3,myPosition); |
215 | parmin = Min(parmin,parcur); |
216 | parmax = Max(parmax,parcur); |
217 | |
218 | gp_Pnt PointMin = ElCLib::Value(parmin,L3); |
219 | gp_Pnt PointMax = ElCLib::Value(parmax,L3); |
220 | |
221 | if (!PointMin.IsEqual(PointMax,Precision::Confusion())) { |
222 | seg = new Select3D_SensitiveSegment(own, |
223 | PointMin, |
224 | PointMax); |
225 | aSel->Add(seg); |
226 | } |
227 | if (!myFAttach.IsEqual(P1,Precision::Confusion())) { |
228 | seg = new Select3D_SensitiveSegment(own, |
229 | myFAttach, |
230 | P1); |
231 | aSel->Add(seg); |
232 | } |
233 | if (!mySAttach.IsEqual(P2,Precision::Confusion())) { |
234 | seg = new Select3D_SensitiveSegment(own, |
235 | mySAttach, |
236 | P2); |
237 | aSel->Add(seg); |
238 | } |
239 | } |
240 | |
241 | //=======================Pour les arcs====================== |
242 | if(cu1.GetType() == GeomAbs_Circle) { |
7fd59977 |
243 | Handle(Geom_Curve) aGeomCurve = BRep_Tool::Curve(TopoDS::Edge(myFShape),F,L); |
c5f3a425 |
244 | Handle(Geom_Circle) geom_circ1 = Handle(Geom_Circle)::DownCast (aGeomCurve) ; |
7fd59977 |
245 | // Handle(Geom_Circle) geom_circ1 = (const Handle(Geom_Circle)&) BRep_Tool::Curve(TopoDS::Edge(myFShape),F,L); |
246 | gp_Circ circ1(geom_circ1->Circ()); |
247 | gp_Pnt OffsetPnt(myPosition.X(),myPosition.Y(),myPosition.Z()); |
248 | gp_Pnt Center1 = circ1.Location(); |
249 | gp_Pnt ProjOffsetPoint = ElCLib::Value(ElCLib::Parameter(laxis,OffsetPnt),laxis); |
250 | gp_Pnt ProjCenter1 = ElCLib::Value(ElCLib::Parameter(laxis,Center1),laxis); |
251 | gp_Vec Vp(ProjCenter1,Center1); |
252 | if (Vp.Magnitude() <= Precision::Confusion()) Vp = gp_Vec(laxis.Direction())^myPlane->Pln().Position().Direction(); |
253 | Standard_Real Dt,R,h; |
254 | Dt = ProjCenter1.Distance(ProjOffsetPoint); |
255 | R = circ1.Radius(); |
256 | if (Dt > .999*R) { |
257 | Dt = .999*R; |
258 | gp_Vec Vout(ProjCenter1,ProjOffsetPoint); |
259 | ProjOffsetPoint = ProjCenter1.Translated(Vout.Divided(Vout.Magnitude()).Multiplied(Dt)); |
260 | OffsetPnt = ProjOffsetPoint; |
261 | } |
262 | h = Sqrt(R*R - Dt*Dt); |
263 | gp_Pnt P1 = ProjOffsetPoint.Translated(Vp.Added(Vp.Divided(Vp.Magnitude()).Multiplied(h))); |
264 | gp_Vec v(P1,ProjOffsetPoint); |
265 | gp_Pnt P2 = ProjOffsetPoint.Translated(v); |
266 | |
267 | gp_Lin L3; |
268 | if (!P1.IsEqual(P2,Precision::Confusion())) { |
269 | L3 = gce_MakeLin(P1,P2); |
270 | } |
271 | else { |
272 | L3 = gce_MakeLin(P1,laxis.Direction()); |
273 | Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6)); |
274 | Handle(Select3D_SensitiveBox) box = |
275 | new Select3D_SensitiveBox(own, |
276 | myPosition.X(), |
277 | myPosition.Y(), |
278 | myPosition.Z(), |
279 | myPosition.X()+size, |
280 | myPosition.Y()+size, |
281 | myPosition.Z()+size); |
282 | aSel->Add(box); |
283 | } |
284 | Standard_Real parmin,parmax,parcur; |
285 | parmin = ElCLib::Parameter(L3,P1); |
286 | parmax = parmin; |
287 | |
288 | parcur = ElCLib::Parameter(L3,P2); |
289 | parmin = Min(parmin,parcur); |
290 | parmax = Max(parmax,parcur); |
291 | |
292 | parcur = ElCLib::Parameter(L3,myPosition); |
293 | parmin = Min(parmin,parcur); |
294 | parmax = Max(parmax,parcur); |
295 | |
296 | gp_Pnt PointMin = ElCLib::Value(parmin,L3); |
297 | gp_Pnt PointMax = ElCLib::Value(parmax,L3); |
298 | |
299 | if (!PointMin.IsEqual(PointMax,Precision::Confusion())) { |
300 | seg = new Select3D_SensitiveSegment(own, |
301 | PointMin, |
302 | PointMax); |
303 | aSel->Add(seg); |
304 | } |
305 | } |
306 | } |
307 | //=======================Pour les points====================== |
308 | else { |
309 | if (myFAttach.IsEqual(mySAttach,Precision::Confusion())) { |
310 | seg = new Select3D_SensitiveSegment(own,myPosition,myFAttach); |
311 | aSel->Add(seg); |
312 | } |
313 | else{ |
314 | gp_Pnt ProjOffsetPoint = ElCLib::Value(ElCLib::Parameter(laxis,myPosition),laxis); |
315 | gp_Pnt ProjAttachmentPoint1 = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis); |
316 | gp_Vec PjAtt1_Att1(ProjAttachmentPoint1,myFAttach); |
317 | gp_Pnt P1 = ProjOffsetPoint.Translated(PjAtt1_Att1); |
318 | gp_Pnt P2 = ProjOffsetPoint.Translated(PjAtt1_Att1.Reversed()); |
319 | gp_Lin L3; |
320 | |
321 | if (!P1.IsEqual(P2,Precision::Confusion())) { |
322 | L3 = gce_MakeLin(P1,P2); |
323 | } |
324 | else { |
325 | L3 = gce_MakeLin(P1,myFDirAttach); |
326 | Standard_Real size(Min(myVal/100.+1.e-6,myArrowSize+1.e-6)); |
327 | Handle(Select3D_SensitiveBox) box = |
328 | new Select3D_SensitiveBox(own, |
329 | myPosition.X(), |
330 | myPosition.Y(), |
331 | myPosition.Z(), |
332 | myPosition.X()+size, |
333 | myPosition.Y()+size, |
334 | myPosition.Z()+size); |
335 | aSel->Add(box); |
336 | } |
337 | Standard_Real parmin,parmax,parcur; |
338 | parmin = ElCLib::Parameter(L3,P1); |
339 | parmax = parmin; |
340 | |
341 | parcur = ElCLib::Parameter(L3,P2); |
342 | parmin = Min(parmin,parcur); |
343 | parmax = Max(parmax,parcur); |
344 | |
345 | parcur = ElCLib::Parameter(L3,myPosition); |
346 | parmin = Min(parmin,parcur); |
347 | parmax = Max(parmax,parcur); |
348 | |
349 | gp_Pnt PointMin = ElCLib::Value(parmin,L3); |
350 | gp_Pnt PointMax = ElCLib::Value(parmax,L3); |
351 | |
352 | if (!PointMin.IsEqual(PointMax,Precision::Confusion())) { |
353 | seg = new Select3D_SensitiveSegment(own,PointMin,PointMax); |
354 | aSel->Add(seg); |
355 | } |
356 | if (!myFAttach.IsEqual(P1,Precision::Confusion())) { |
357 | seg = new Select3D_SensitiveSegment(own,myFAttach,P1); |
358 | aSel->Add(seg); |
359 | } |
360 | if (!mySAttach.IsEqual(P2,Precision::Confusion())) { |
361 | seg = new Select3D_SensitiveSegment(own,mySAttach,P2); |
362 | aSel->Add(seg); |
363 | } |
364 | } |
365 | } |
366 | } |
367 | |
368 | //======================================================================= |
369 | //function : ComputeTwoFacesSymmetric |
370 | //purpose : |
371 | //======================================================================= |
372 | void AIS_SymmetricRelation::ComputeTwoFacesSymmetric(const Handle(Prs3d_Presentation)&) |
373 | { |
374 | } |
375 | |
376 | //======================================================================= |
377 | //function : ComputeTwoEdgesSymmetric |
378 | //purpose : |
379 | //======================================================================= |
380 | void AIS_SymmetricRelation::ComputeTwoEdgesSymmetric(const Handle(Prs3d_Presentation)& aprs) |
381 | { |
382 | BRepAdaptor_Curve cu1(TopoDS::Edge(myFShape)); |
383 | if (cu1.GetType() != GeomAbs_Line && cu1.GetType() != GeomAbs_Circle) return; |
384 | BRepAdaptor_Curve cu2(TopoDS::Edge(mySShape)); |
385 | if (cu2.GetType() != GeomAbs_Line && cu2.GetType() != GeomAbs_Circle) return; |
386 | // gp_Pnt pint3d,ptat11,ptat12,ptat21,ptat22; |
387 | gp_Pnt ptat11,ptat12,ptat21,ptat22; |
388 | Handle(Geom_Curve) geom1,geom2; |
389 | Standard_Boolean isInfinite1,isInfinite2; |
390 | Handle(Geom_Curve) extCurv; |
391 | if (!AIS::ComputeGeometry(TopoDS::Edge(myFShape), |
392 | TopoDS::Edge(mySShape), |
393 | myExtShape, |
394 | geom1, |
395 | geom2, |
396 | ptat11, |
397 | ptat12, |
398 | ptat21, |
399 | ptat22, |
400 | extCurv, |
401 | isInfinite1,isInfinite2, |
402 | myPlane)) { |
403 | return; |
404 | } |
405 | aprs->SetInfiniteState((isInfinite1 || isInfinite2) && (myExtShape !=0)); |
aa00364d |
406 | Handle(Geom_Curve) geom_axis,extcurve; |
7fd59977 |
407 | gp_Pnt p1,p2; |
408 | Standard_Boolean isinfinite,isonplane; |
409 | if (!AIS::ComputeGeometry(TopoDS::Edge(myTool), |
410 | geom_axis,p1,p2, |
411 | extcurve, |
412 | isinfinite, |
413 | isonplane, |
414 | myPlane)) return; |
415 | |
aa00364d |
416 | Handle(Geom_Line) geom_line = Handle(Geom_Line)::DownCast (geom_axis); |
417 | gp_Lin laxis (geom_line->Lin()); |
7fd59977 |
418 | myAxisDirAttach = laxis.Direction(); |
419 | |
420 | if(cu1.GetType() == GeomAbs_Line){ |
c5f3a425 |
421 | Handle(Geom_Line) geom_lin1 (Handle(Geom_Line)::DownCast (geom1)); |
7fd59977 |
422 | gp_Lin l1(geom_lin1->Lin()); |
423 | myFDirAttach = l1.Direction(); |
424 | } |
425 | gp_Circ circ; |
426 | if(cu1.GetType() == GeomAbs_Circle){ |
c5f3a425 |
427 | Handle(Geom_Circle) geom_cir1 (Handle(Geom_Circle)::DownCast (geom1)); |
7fd59977 |
428 | gp_Circ c(geom_cir1->Circ()); |
429 | circ = c; |
430 | } |
431 | |
432 | // recherche points attache |
433 | gp_Pnt ProjOffset = ElCLib::Value(ElCLib::Parameter(laxis,myPosition),laxis); |
434 | |
435 | /*//---------------------------------------------------- |
436 | //Quand on fait la symetrie de 2 edges consecutifs: |
437 | // |
438 | // :<-- Axe |
439 | // : |
440 | // /:\ |
441 | // Edge n --->/ : \ |
442 | // / : \<-- Edge n+1 |
443 | // : |
444 | //---------------------------------------------------- |
445 | */ |
446 | Standard_Boolean idem = Standard_False; |
447 | if (isInfinite1 && isInfinite2) { // geom1 et geom2 sont des lignes |
c5f3a425 |
448 | const gp_Lin& line2 = Handle(Geom_Line)::DownCast (geom2)->Lin(); |
7fd59977 |
449 | if (myAutomaticPosition) { |
c5f3a425 |
450 | myFAttach = Handle(Geom_Line)::DownCast (geom1)->Lin().Location(); |
7fd59977 |
451 | mySAttach = ElCLib::Value(ElCLib::Parameter(line2,myFAttach),line2); |
452 | } |
453 | else { |
c5f3a425 |
454 | const gp_Lin& line1 = Handle(Geom_Line)::DownCast (geom1)->Lin(); |
7fd59977 |
455 | myFAttach = ElCLib::Value(ElCLib::Parameter(line1,myPosition),line1); |
456 | mySAttach = ElCLib::Value(ElCLib::Parameter(line2,myFAttach),line2); |
457 | } |
458 | } |
459 | else if (!isInfinite1 && !isInfinite2) { |
460 | if (ptat11.IsEqual(ptat21,Precision::Confusion())) { |
461 | myFAttach = ptat12; |
462 | mySAttach = ptat22; |
463 | idem = Standard_True; |
464 | } |
465 | if (ptat11.IsEqual(ptat22,Precision::Confusion())) { |
466 | myFAttach = ptat12; |
467 | mySAttach = ptat21; |
468 | idem = Standard_True; |
469 | } |
470 | if (ptat12.IsEqual(ptat21,Precision::Confusion())) { |
471 | myFAttach = ptat11; |
472 | mySAttach = ptat22; |
473 | idem = Standard_True; |
474 | } |
475 | if (ptat12.IsEqual(ptat22,Precision::Confusion())) { |
476 | myFAttach = ptat11; |
477 | mySAttach = ptat21; |
478 | idem = Standard_True; |
479 | } |
480 | if(!idem){ |
481 | if( ProjOffset.SquareDistance(ptat11) > ProjOffset.SquareDistance(ptat12)) myFAttach = ptat12; |
482 | else myFAttach = ptat11; |
483 | |
484 | if (ProjOffset.SquareDistance(ptat21) > ProjOffset.SquareDistance(ptat22)) mySAttach = ptat22; |
485 | else mySAttach = ptat21; |
486 | } |
487 | } |
488 | else if (isInfinite1) {// geom1 et geom2 sont des lignes |
489 | mySAttach = ptat21; |
c5f3a425 |
490 | const gp_Lin& line1 = Handle(Geom_Line)::DownCast (geom1)->Lin(); |
7fd59977 |
491 | myFAttach = ElCLib::Value(ElCLib::Parameter(line1,mySAttach),line1); |
492 | } |
493 | else if (isInfinite2) {// geom1 et geom2 sont des lignes |
494 | myFAttach = ptat11; |
c5f3a425 |
495 | const gp_Lin& line2 = Handle(Geom_Line)::DownCast (geom2)->Lin(); |
7fd59977 |
496 | mySAttach = ElCLib::Value(ElCLib::Parameter(line2,myFAttach),line2); |
497 | } |
498 | |
7fd59977 |
499 | if( !myArrowSizeIsDefined ) |
7fd59977 |
500 | myArrowSize = myFAttach.Distance(mySAttach)/50.; |
501 | //---------------------------------------------------- |
502 | |
503 | //---------------------------------------------------- |
504 | // Si myFAttach <> mySAttach et PjFAttach = myFAttach |
505 | //---------------------------------------------------- |
506 | gp_Pnt PjFAttach = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis); |
507 | |
508 | if (PjFAttach.IsEqual(myFAttach,Precision::Confusion())){ |
c5f3a425 |
509 | Handle(Geom_Line) geom_lin2 (Handle(Geom_Line)::DownCast (geom2)); |
7fd59977 |
510 | gp_Lin l2(geom_lin2->Lin()); |
511 | myFDirAttach = l2.Direction(); |
512 | gp_Pnt PntTempo; |
513 | PntTempo = myFAttach; |
514 | myFAttach = mySAttach; |
515 | mySAttach = PntTempo; |
516 | PjFAttach = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis); |
517 | } |
518 | |
519 | //---------------------------------------------------- |
520 | // gp_Pnt curpos; |
521 | |
522 | if (myAutomaticPosition) { |
523 | //gp_Pnt PjFAttach = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis); |
524 | // offset pour eviter confusion Edge et Dimension |
525 | gp_Vec offset(myAxisDirAttach); |
526 | offset = offset * myArrowSize * (-5); |
527 | gp_Vec Vt(myFAttach, PjFAttach); |
528 | gp_Pnt curpos = PjFAttach.Translated(offset.Added(Vt.Multiplied(.15))); |
529 | myPosition = curpos; |
530 | } |
531 | |
532 | gp_Pnt Pj1 = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis); |
533 | gp_Pnt Pj2 = ElCLib::Value(ElCLib::Parameter(laxis,mySAttach),laxis); |
534 | if ((myFAttach.SquareDistance(Pj1)+mySAttach.SquareDistance(Pj2)) <= Precision::Confusion()) myArrowSize = 0.; |
a6eb515f |
535 | Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect(); |
536 | Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect(); |
7fd59977 |
537 | arr->SetLength(myArrowSize); |
a6eb515f |
538 | arr = la->ArrowAspect(); |
7fd59977 |
539 | arr->SetLength(myArrowSize); |
540 | if(cu1.GetType() == GeomAbs_Line) |
541 | DsgPrs_SymmetricPresentation::Add(aprs, |
542 | myDrawer, |
543 | myFAttach, |
544 | mySAttach, |
545 | myFDirAttach, |
546 | laxis, |
547 | myPosition); |
548 | |
549 | if(cu1.GetType() == GeomAbs_Circle) |
550 | DsgPrs_SymmetricPresentation::Add(aprs, |
551 | myDrawer, |
552 | myFAttach, |
553 | mySAttach, |
554 | circ, |
555 | laxis, |
556 | myPosition); |
557 | if ( (myExtShape != 0) && !extCurv.IsNull()) { |
558 | gp_Pnt pf, pl; |
559 | if ( myExtShape == 1 ) { |
560 | if (!isInfinite1) { |
561 | pf = ptat11; |
562 | pl = ptat12; |
563 | } |
564 | ComputeProjEdgePresentation(aprs,TopoDS::Edge(myFShape),geom1,pf,pl); |
565 | } |
566 | else { |
567 | if (!isInfinite2) { |
568 | pf = ptat21; |
569 | pl = ptat22; |
570 | } |
571 | ComputeProjEdgePresentation(aprs,TopoDS::Edge(mySShape),geom2,pf,pl); |
572 | } |
573 | } |
574 | } |
575 | |
576 | //======================================================================= |
577 | //function : ComputeTwoVertexsSymmetric |
578 | //purpose : |
579 | //======================================================================= |
580 | void AIS_SymmetricRelation::ComputeTwoVerticesSymmetric(const Handle(Prs3d_Presentation)& aprs) |
581 | { |
582 | if(myFShape.ShapeType() != TopAbs_VERTEX || mySShape.ShapeType() != TopAbs_VERTEX) return; |
aa00364d |
583 | Handle(Geom_Curve) geom_axis,extcurve; |
7fd59977 |
584 | gp_Pnt p1,p2; |
585 | Standard_Boolean isinfinite,isonplane; |
586 | if (!AIS::ComputeGeometry(TopoDS::Edge(myTool), |
587 | geom_axis,p1,p2, |
588 | extcurve, |
589 | isinfinite, |
590 | isonplane, |
591 | myPlane)) return; |
592 | |
593 | Standard_Boolean isOnPlane1, isOnPlane2; |
594 | |
595 | AIS::ComputeGeometry(TopoDS::Vertex(myFShape), myFAttach, myPlane, isOnPlane1); |
596 | AIS::ComputeGeometry(TopoDS::Vertex(mySShape), mySAttach, myPlane, isOnPlane2); |
597 | |
7fd59977 |
598 | if( !myArrowSizeIsDefined ) |
7fd59977 |
599 | myArrowSize = myFAttach.Distance(mySAttach)/50.; |
600 | |
601 | if (isOnPlane1 && isOnPlane2) |
602 | myExtShape = 0; |
603 | else if ( isOnPlane1 && !isOnPlane2) |
604 | myExtShape = 2; |
605 | else if (!isOnPlane1 && isOnPlane2) |
606 | myExtShape = 1; |
607 | else |
608 | return ; |
aa00364d |
609 | |
610 | Handle(Geom_Line) geom_line = Handle(Geom_Line)::DownCast (geom_axis); |
611 | gp_Lin laxis (geom_line->Lin()); |
7fd59977 |
612 | myAxisDirAttach = laxis.Direction(); |
613 | |
614 | // recherche points attache |
615 | // gp_Pnt curpos; |
616 | if (myAutomaticPosition) { |
617 | gp_Pnt PjFAttach = ElCLib::Value(ElCLib::Parameter(laxis,myFAttach),laxis); |
618 | // offset pour eviter confusion Edge et Dimension |
619 | gp_Vec offset(myAxisDirAttach); |
620 | offset = offset * myArrowSize * (-5); |
621 | gp_Vec Vt(myFAttach, PjFAttach); |
622 | gp_Pnt curpos = PjFAttach.Translated(offset.Added(Vt.Multiplied(.15))); |
623 | myPosition = curpos; |
624 | } |
625 | if (2*(myFAttach.Distance(mySAttach)) <= Precision::Confusion()) myArrowSize = 0.; |
a6eb515f |
626 | Handle(Prs3d_DimensionAspect) la = myDrawer->DimensionAspect(); |
627 | Handle(Prs3d_ArrowAspect) arr = la->ArrowAspect(); |
7fd59977 |
628 | arr->SetLength(myArrowSize); |
a6eb515f |
629 | arr = la->ArrowAspect(); |
7fd59977 |
630 | arr->SetLength(myArrowSize); |
631 | DsgPrs_SymmetricPresentation::Add(aprs, |
632 | myDrawer, |
633 | myFAttach, |
634 | mySAttach, |
635 | laxis, |
636 | myPosition); |
637 | if ( myExtShape == 1) |
638 | ComputeProjVertexPresentation(aprs,TopoDS::Vertex(myFShape),myFAttach); |
639 | else if ( myExtShape == 2) |
640 | ComputeProjVertexPresentation(aprs,TopoDS::Vertex(mySShape),mySAttach); |
641 | } |
642 | |
643 | |
644 | |
645 | |
646 | |
647 | |