Commit | Line | Data |
---|---|---|
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 | |
18 | #include <AIS.hxx> | |
42cf5bc1 | 19 | #include <AIS_IdenticRelation.hxx> |
7fd59977 | 20 | #include <AIS_Shape.hxx> |
7fd59977 | 21 | #include <BRep_Tool.hxx> |
7fd59977 | 22 | #include <DsgPrs_IdenticPresentation.hxx> |
7fd59977 | 23 | #include <ElCLib.hxx> |
7fd59977 | 24 | #include <Geom_Circle.hxx> |
42cf5bc1 | 25 | #include <Geom_Ellipse.hxx> |
7fd59977 | 26 | #include <Geom_Line.hxx> |
27 | #include <Geom_Plane.hxx> | |
42cf5bc1 | 28 | #include <Geom_Transformation.hxx> |
7fd59977 | 29 | #include <Geom_TrimmedCurve.hxx> |
42cf5bc1 | 30 | #include <GeomAPI_ProjectPointOnCurve.hxx> |
31 | #include <gp_Dir.hxx> | |
32 | #include <gp_Pln.hxx> | |
33 | #include <gp_Pnt.hxx> | |
34 | #include <gp_Vec.hxx> | |
7fd59977 | 35 | #include <Precision.hxx> |
7fd59977 | 36 | #include <Prs3d_Drawer.hxx> |
37 | #include <Prs3d_LineAspect.hxx> | |
42cf5bc1 | 38 | #include <Prs3d_Presentation.hxx> |
39 | #include <Prs3d_Projector.hxx> | |
7fd59977 | 40 | #include <Select3D_SensitiveCurve.hxx> |
41 | #include <Select3D_SensitiveSegment.hxx> | |
42 | #include <SelectMgr_EntityOwner.hxx> | |
f751596e | 43 | #include <SelectMgr_Selection.hxx> |
42cf5bc1 | 44 | #include <Standard_NotImplemented.hxx> |
45 | #include <Standard_Type.hxx> | |
7fd59977 | 46 | #include <TCollection_ExtendedString.hxx> |
42cf5bc1 | 47 | #include <TColStd_ListIteratorOfListOfTransient.hxx> |
7fd59977 | 48 | #include <TopAbs.hxx> |
49 | #include <TopExp.hxx> | |
50 | #include <TopoDS.hxx> | |
51 | #include <TopoDS_Edge.hxx> | |
42cf5bc1 | 52 | #include <TopoDS_Shape.hxx> |
7fd59977 | 53 | #include <TopoDS_Vertex.hxx> |
54 | #include <TopoDS_Wire.hxx> | |
55 | #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx> | |
56 | #include <TopTools_ListIteratorOfListOfShape.hxx> | |
57 | ||
92efcf78 | 58 | IMPLEMENT_STANDARD_RTTIEXT(AIS_IdenticRelation,AIS_Relation) |
59 | ||
7fd59977 | 60 | // jfa 15/10/2000 |
7fd59977 | 61 | static Standard_Real Modulo2PI(const Standard_Real ANGLE) |
62 | { | |
c6541a0c D |
63 | if ( ANGLE < 0 ) return Modulo2PI(ANGLE + 2*M_PI); |
64 | else if ( ANGLE >= 2*M_PI ) return Modulo2PI(ANGLE - 2*M_PI); | |
7fd59977 | 65 | return ANGLE; |
66 | } | |
67 | ||
68 | static Standard_Boolean IsEqual2PI(const Standard_Real angle1, | |
69 | const Standard_Real angle2, const Standard_Real precision) | |
70 | { | |
71 | Standard_Real diff = Abs(angle1-angle2); | |
72 | if ( diff < precision ) return Standard_True; | |
c6541a0c | 73 | else if ( Abs(diff-2*M_PI) < precision ) return Standard_True; |
7fd59977 | 74 | return Standard_False; |
75 | } | |
76 | // jfa 15/10/2000 end | |
77 | ||
78 | //======================================================================= | |
79 | //function : AIS_Sort | |
80 | //purpose : sort an array of parameters <tab1> in increasing order | |
81 | // updates <tab2> and <tab3> according to <tab1> | |
82 | //======================================================================= | |
83 | static void AIS_Sort(Standard_Real tab1[4], | |
84 | gp_Pnt tab2[4], | |
85 | Standard_Integer tab3[4]) | |
86 | { | |
87 | Standard_Boolean found = Standard_True; | |
88 | Standard_Real cur; gp_Pnt cur1; Standard_Integer cur2; | |
89 | ||
90 | while (found) { | |
91 | found = Standard_False; | |
92 | for (Standard_Integer i=0; i< 3; i++) { | |
93 | if (tab1[i+1] < tab1[i]) { | |
94 | found = Standard_True; | |
95 | cur = tab1[i]; cur1 = tab2[i]; cur2 = tab3[i]; | |
96 | tab1[i] = tab1[i+1]; tab2[i] = tab2[i+1]; tab3[i] = tab3[i+1]; | |
97 | tab1[i+1] = cur; tab2[i+1] = cur1; tab3[i+1] = cur2; | |
98 | } | |
99 | } | |
100 | } | |
101 | } | |
102 | ||
103 | //======================================================================= | |
104 | //function : ConnectedEdges | |
105 | //purpose : | |
106 | //======================================================================= | |
107 | static Standard_Boolean ConnectedEdges(const TopoDS_Wire& WIRE, | |
108 | const TopoDS_Vertex& V, | |
109 | TopoDS_Edge& E1, | |
110 | TopoDS_Edge& E2) | |
111 | { | |
112 | TopTools_IndexedDataMapOfShapeListOfShape vertexMap; | |
113 | TopExp::MapShapesAndAncestors (WIRE,TopAbs_VERTEX,TopAbs_EDGE,vertexMap); | |
114 | ||
115 | Standard_Boolean found(Standard_False); | |
116 | TopoDS_Vertex theVertex; | |
117 | for (Standard_Integer i=1; i<=vertexMap.Extent() && !found; i++) { | |
118 | if (vertexMap.FindKey(i).IsSame(V)) { | |
119 | theVertex = TopoDS::Vertex(vertexMap.FindKey(i)); | |
120 | found = Standard_True; | |
121 | } | |
122 | } | |
123 | if (!found) { | |
124 | E1.Nullify(); | |
125 | E2.Nullify(); | |
126 | return Standard_False; | |
127 | } | |
128 | ||
129 | TopTools_ListIteratorOfListOfShape iterator(vertexMap.FindFromKey(theVertex)); | |
130 | if (iterator.More()) { | |
131 | E1 = TopoDS::Edge(iterator.Value()); | |
132 | iterator.Next(); | |
133 | } | |
134 | else { | |
135 | E1.Nullify(); | |
136 | return Standard_False; | |
137 | } | |
138 | ||
139 | if (iterator.More()) { | |
140 | E2 = TopoDS::Edge(iterator.Value()); | |
141 | iterator.Next(); | |
142 | } | |
143 | else { | |
144 | E2.Nullify(); | |
145 | return Standard_False; | |
146 | } | |
147 | ||
148 | if (iterator.More()) { | |
149 | E1.Nullify(); | |
150 | E2.Nullify(); | |
151 | return Standard_False; | |
152 | } | |
153 | return Standard_True; | |
154 | } | |
155 | ||
156 | // jfa 16/10/2000 | |
157 | //======================================================================= | |
158 | //function : ComputeAttach | |
159 | //purpose : Compute a point on the arc of <thecirc> | |
160 | // between <aFAttach> and <aSAttach> | |
161 | // corresponding to <aPosition> | |
162 | // Returns result into <aPosition> | |
163 | // Note : This function is to be used only in the case of circles. | |
164 | // The <aPosition> parameter is in/out. | |
165 | //======================================================================= | |
166 | static Standard_Boolean ComputeAttach(const gp_Circ& thecirc, | |
167 | const gp_Pnt& aFAttach, | |
168 | const gp_Pnt& aSAttach, | |
169 | gp_Pnt& aPosition) | |
170 | { | |
171 | gp_Pnt curpos = aPosition; | |
172 | ||
173 | // Case of confusion between the current position and the center | |
174 | // of the circle -> we move the current position | |
175 | Standard_Real confusion (Precision::Confusion()); | |
176 | gp_Pnt aCenter = thecirc.Location(); | |
177 | if ( aCenter.Distance(curpos) <= confusion ) | |
178 | { | |
179 | gp_Vec vprec(aCenter, aFAttach); | |
180 | vprec.Normalize(); | |
181 | curpos.Translate(vprec*1e-5); | |
182 | } | |
183 | ||
184 | Standard_Real pcurpos = ElCLib::Parameter(thecirc,curpos); | |
185 | Standard_Real pFAttach = ElCLib::Parameter(thecirc,aFAttach); | |
186 | Standard_Real pSAttach = ElCLib::Parameter(thecirc,aSAttach); | |
187 | ||
188 | Standard_Real pSAttachM = pSAttach; | |
189 | Standard_Real deltap = pSAttachM - pFAttach; | |
190 | if ( deltap < 0 ) | |
191 | { | |
c6541a0c D |
192 | deltap += 2 * M_PI; |
193 | pSAttachM += 2 * M_PI; | |
7fd59977 | 194 | } |
195 | pSAttachM -= pFAttach; | |
196 | ||
c6541a0c | 197 | Standard_Real pmiddleout = pSAttachM/2.0 + M_PI; |
7fd59977 | 198 | |
199 | Standard_Real pcurpos1 = pcurpos; | |
200 | // define where curpos lays | |
201 | if ( pcurpos1 < pFAttach ) | |
202 | { | |
c6541a0c | 203 | pcurpos1 = pcurpos1 + 2 * M_PI - pFAttach; |
7fd59977 | 204 | if ( pcurpos1 > pSAttachM ) // out |
205 | { | |
206 | if ( pcurpos1 > pmiddleout ) pcurpos = pFAttach; | |
207 | else pcurpos = pSAttach; | |
208 | } | |
209 | } | |
210 | else if ( pcurpos1 > (pFAttach + deltap) ) // out | |
211 | { | |
212 | pcurpos1 -= pFAttach; | |
213 | if ( pcurpos1 > pmiddleout ) pcurpos = pFAttach; | |
214 | else pcurpos = pSAttach; | |
215 | } | |
216 | ||
217 | aPosition = ElCLib::Value(pcurpos,thecirc); | |
218 | return Standard_True; | |
219 | } | |
220 | ||
221 | //======================================================================= | |
222 | //function : ComputeAttach | |
223 | //purpose : Compute a point on the arc of ellipse <theEll> | |
224 | // between <aFAttach> and <aSAttach> | |
225 | // corresponding to <aPosition> | |
226 | // Returns result into <aPosition> | |
227 | // Note : This function is to be used only in the case of ellipses. | |
228 | // The <aPosition> parameter is in/out. | |
229 | //======================================================================= | |
230 | static Standard_Boolean ComputeAttach(const gp_Elips& theEll, | |
231 | const gp_Pnt& aFAttach, | |
232 | const gp_Pnt& aSAttach, | |
233 | gp_Pnt& aPosition) | |
234 | { | |
235 | gp_Pnt curpos = aPosition; | |
236 | ||
237 | // Case of confusion between the current position and the center | |
238 | // of the circle -> we move the current position | |
239 | Standard_Real confusion (Precision::Confusion()); | |
240 | gp_Pnt aCenter = theEll.Location(); | |
241 | if ( aCenter.Distance(curpos) <= confusion ) | |
242 | { | |
243 | gp_Vec vprec(aCenter, aFAttach); | |
244 | vprec.Normalize(); | |
245 | curpos.Translate(vprec*1e-5); | |
246 | } | |
247 | ||
248 | // for ellipses it's not good Standard_Real pcurpos = ElCLib::Parameter(theEll,curpos); | |
249 | Handle(Geom_Ellipse) theEllg = new Geom_Ellipse(theEll); | |
250 | GeomAPI_ProjectPointOnCurve aProj (curpos, theEllg); | |
251 | Standard_Real pcurpos = aProj.LowerDistanceParameter(); | |
252 | ||
253 | Standard_Real pFAttach = ElCLib::Parameter(theEll,aFAttach); | |
254 | Standard_Real pSAttach = ElCLib::Parameter(theEll,aSAttach); | |
255 | ||
256 | Standard_Real pSAttachM = pSAttach; | |
257 | Standard_Real deltap = pSAttachM - pFAttach; | |
258 | if ( deltap < 0 ) | |
259 | { | |
c6541a0c D |
260 | deltap += 2 * M_PI; |
261 | pSAttachM += 2 * M_PI; | |
7fd59977 | 262 | } |
263 | pSAttachM -= pFAttach; | |
264 | ||
c6541a0c | 265 | Standard_Real pmiddleout = pSAttachM/2.0 + M_PI; |
7fd59977 | 266 | |
267 | Standard_Real pcurpos1 = pcurpos; | |
268 | // define where curpos lays | |
269 | if ( pcurpos1 < pFAttach ) | |
270 | { | |
c6541a0c | 271 | pcurpos1 = pcurpos1 + 2 * M_PI - pFAttach; |
7fd59977 | 272 | if ( pcurpos1 > pSAttachM ) // out |
273 | { | |
274 | if ( pcurpos1 > pmiddleout ) pcurpos = pFAttach; | |
275 | else pcurpos = pSAttach; | |
276 | } | |
277 | } | |
278 | else if ( pcurpos1 > (pFAttach + deltap) ) // out | |
279 | { | |
280 | pcurpos1 -= pFAttach; | |
281 | if ( pcurpos1 > pmiddleout ) pcurpos = pFAttach; | |
282 | else pcurpos = pSAttach; | |
283 | } | |
284 | ||
285 | aPosition = ElCLib::Value(pcurpos,theEll); | |
286 | return Standard_True; | |
287 | } | |
288 | // jfa 16/10/2000 end | |
289 | ||
290 | //======================================================================= | |
291 | //function : AIS_IdenticRelation | |
292 | //purpose : | |
293 | //======================================================================= | |
294 | AIS_IdenticRelation::AIS_IdenticRelation(const TopoDS_Shape& FirstShape, | |
295 | const TopoDS_Shape& SecondShape, | |
296 | const Handle(Geom_Plane)& aPlane) | |
297 | :isCircle(Standard_False) | |
298 | { | |
299 | myFShape = FirstShape; | |
300 | mySShape = SecondShape; | |
301 | myPlane = aPlane; | |
302 | } | |
303 | ||
304 | //======================================================================= | |
305 | //function : Compute | |
306 | //purpose : | |
307 | //======================================================================= | |
308 | void AIS_IdenticRelation::Compute(const Handle(PrsMgr_PresentationManager3d)&, | |
309 | const Handle(Prs3d_Presentation)& aprs, | |
310 | const Standard_Integer) | |
311 | { | |
312 | aprs->Clear(); | |
313 | ||
314 | switch ( myFShape.ShapeType() ) { | |
315 | ||
316 | case TopAbs_VERTEX: | |
317 | { | |
318 | switch ( mySShape.ShapeType() ) { | |
319 | case TopAbs_VERTEX: | |
320 | { | |
321 | ComputeTwoVerticesPresentation(aprs); | |
322 | } | |
323 | break; | |
324 | case TopAbs_EDGE: | |
325 | { | |
326 | ComputeOneEdgeOVertexPresentation(aprs); | |
327 | } | |
328 | break; | |
329 | default: | |
330 | break; | |
331 | } | |
332 | } | |
333 | break; | |
334 | ||
335 | case TopAbs_EDGE: | |
336 | { | |
337 | switch ( mySShape.ShapeType() ) { | |
338 | case TopAbs_VERTEX: | |
339 | { | |
340 | ComputeOneEdgeOVertexPresentation(aprs); | |
341 | } | |
342 | break; | |
343 | case TopAbs_EDGE: | |
344 | { | |
345 | ComputeTwoEdgesPresentation(aprs); | |
346 | } | |
347 | break; | |
348 | default: | |
349 | break; | |
350 | } | |
351 | } | |
352 | break; | |
353 | default: break; | |
354 | } | |
355 | } | |
356 | ||
357 | //======================================================================= | |
358 | //function : Compute | |
359 | //purpose : | |
360 | //======================================================================= | |
361 | void AIS_IdenticRelation::Compute(const Handle(Prs3d_Projector)& aProjector, | |
362 | const Handle(Prs3d_Presentation)& aPresentation) | |
363 | { | |
364 | // Standard_NotImplemented::Raise("AIS_IdenticRelation::Compute(const Handle(Prs3d_Projector)&,const Handle(Prs3d_Presentation)&)"); | |
365 | PrsMgr_PresentableObject::Compute( aProjector , aPresentation ) ; | |
366 | } | |
367 | ||
857ffd5e | 368 | void AIS_IdenticRelation::Compute(const Handle(Prs3d_Projector)& aProjector, const Handle(Geom_Transformation)& aTransformation, const Handle(Prs3d_Presentation)& aPresentation) |
7fd59977 | 369 | { |
857ffd5e | 370 | // Standard_NotImplemented::Raise("AIS_IdenticRelation::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)"); |
7fd59977 | 371 | PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation ) ; |
372 | } | |
373 | ||
374 | //======================================================================= | |
375 | //function : ComputeSelection | |
376 | //purpose : function used to compute the selection associated to the | |
377 | // "identic" presentation | |
378 | // note : if we are in the case of lines, we create a segment between | |
379 | // myFAttach and mySAttach. In the case of Circles, we create | |
81bba717 | 380 | // an arc of circle between the sames points. We Add a segment |
7fd59977 | 381 | // to link Position to its projection on the curve described |
382 | // before. | |
383 | //======================================================================= | |
384 | ||
385 | void AIS_IdenticRelation::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, | |
386 | const Standard_Integer) | |
387 | { | |
388 | Handle(SelectMgr_EntityOwner) own = new SelectMgr_EntityOwner(this,7); | |
389 | ||
390 | Handle(Select3D_SensitiveSegment) seg; | |
391 | // attachement point of the segment linking position to the curve | |
392 | gp_Pnt attach; | |
393 | Standard_Real confusion (Precision::Confusion()); | |
394 | ||
395 | if ( myFAttach.IsEqual(mySAttach, confusion) ) | |
396 | { | |
397 | attach = myFAttach; | |
398 | } | |
399 | else | |
400 | { | |
401 | // jfa 24/10/2000 | |
402 | if ( myFShape.ShapeType() == TopAbs_EDGE ) | |
403 | { | |
404 | Handle(Geom_Curve) curv1,curv2; | |
405 | gp_Pnt firstp1,lastp1,firstp2,lastp2; | |
406 | Standard_Boolean isInfinite1,isInfinite2; | |
407 | Handle(Geom_Curve) extCurv; | |
408 | if ( !AIS::ComputeGeometry(TopoDS::Edge(myFShape),TopoDS::Edge(mySShape), | |
409 | myExtShape,curv1,curv2, | |
410 | firstp1,lastp1,firstp2,lastp2, | |
411 | extCurv,isInfinite1,isInfinite2,myPlane) ) return; | |
412 | ||
413 | if ( isCircle ) // case of Circles | |
414 | { | |
c5f3a425 | 415 | Handle(Geom_Circle) thecirc = Handle(Geom_Circle)::DownCast (curv1); |
7fd59977 | 416 | Standard_Real udeb = ElCLib::Parameter(thecirc->Circ(),myFAttach); |
417 | Standard_Real ufin = ElCLib::Parameter(thecirc->Circ(),mySAttach); | |
543a9964 | 418 | Handle(Geom_Curve) thecu = new Geom_TrimmedCurve(thecirc,udeb,ufin); |
7fd59977 | 419 | |
420 | Handle(Select3D_SensitiveCurve) scurv = new Select3D_SensitiveCurve(own, thecu); | |
421 | aSelection->Add(scurv); | |
422 | ||
423 | attach = myPosition; | |
424 | ComputeAttach(thecirc->Circ(),myFAttach,mySAttach,attach); | |
425 | } | |
426 | else if ( curv1->IsInstance(STANDARD_TYPE(Geom_Ellipse)) ) // case of ellipses | |
427 | { | |
c5f3a425 | 428 | Handle(Geom_Ellipse) theEll = Handle(Geom_Ellipse)::DownCast (curv1); |
7fd59977 | 429 | |
430 | Standard_Real udeb = ElCLib::Parameter(theEll->Elips(),myFAttach); | |
431 | Standard_Real ufin = ElCLib::Parameter(theEll->Elips(),mySAttach); | |
543a9964 | 432 | Handle(Geom_Curve) thecu = new Geom_TrimmedCurve(theEll,udeb,ufin); |
7fd59977 | 433 | |
434 | Handle(Select3D_SensitiveCurve) scurv = new Select3D_SensitiveCurve(own, thecu); | |
435 | aSelection->Add(scurv); | |
436 | ||
437 | attach = myPosition; | |
438 | ComputeAttach(theEll->Elips(),myFAttach,mySAttach,attach); | |
439 | } | |
440 | else if ( curv1->IsInstance(STANDARD_TYPE(Geom_Line)) ) // case of Lines | |
441 | { | |
442 | seg = new Select3D_SensitiveSegment(own, myFAttach, mySAttach); | |
443 | aSelection->Add(seg); | |
444 | ||
81bba717 | 445 | //attach = projection of Position() on the curve; |
7fd59977 | 446 | gp_Vec v1 (myFAttach, mySAttach); |
447 | gp_Vec v2 (myFAttach, myPosition); | |
448 | if ( v1.IsParallel(v2, Precision::Angular()) ) | |
449 | { | |
450 | attach = mySAttach; | |
451 | } | |
452 | else | |
453 | { | |
454 | gp_Lin ll (myFAttach, gp_Dir(v1)); | |
455 | attach = ElCLib::Value(ElCLib::Parameter(ll,myPosition), ll); | |
456 | } | |
457 | } | |
458 | else return; | |
459 | } | |
460 | // else if ( myFShape.ShapeType() == TopAbs_VERTEX ) | |
461 | // { | |
462 | // } | |
463 | // jfa 24/10/2000 end | |
464 | } | |
465 | ||
466 | // Creation of the segment linking the attachement point with the | |
467 | // position | |
468 | if ( !attach.IsEqual(myPosition, confusion) ) | |
469 | { | |
470 | seg = new Select3D_SensitiveSegment(own, attach, myPosition); | |
471 | aSelection->Add(seg); | |
472 | } | |
473 | } | |
474 | ||
475 | //======================================================================= | |
476 | //function : ComputeTwoEdgesPresentation | |
477 | //purpose : | |
478 | //======================================================================= | |
479 | void AIS_IdenticRelation::ComputeTwoEdgesPresentation(const Handle(Prs3d_Presentation)& aPrs) | |
480 | { | |
481 | Handle(Geom_Curve) curv1,curv2; | |
482 | gp_Pnt firstp1,lastp1,firstp2,lastp2; | |
483 | Standard_Boolean isInfinite1,isInfinite2; | |
484 | ||
485 | Handle(Geom_Curve) extCurv; | |
486 | if (!AIS::ComputeGeometry(TopoDS::Edge(myFShape), | |
487 | TopoDS::Edge(mySShape), | |
488 | myExtShape, | |
489 | curv1, | |
490 | curv2, | |
491 | firstp1, | |
492 | lastp1, | |
493 | firstp2, | |
494 | lastp2, | |
495 | extCurv, | |
496 | isInfinite1,isInfinite2, | |
497 | myPlane)) | |
498 | return; | |
499 | aPrs->SetInfiniteState((isInfinite1 || isInfinite2) && myExtShape != 0); | |
500 | ||
501 | // Treatement of the case of lines | |
502 | if ( curv1->IsInstance(STANDARD_TYPE(Geom_Line)) && curv2->IsInstance(STANDARD_TYPE(Geom_Line)) ) { | |
503 | // we take the line curv1 like support | |
504 | Handle(Geom_Line) thelin; | |
c5f3a425 | 505 | if (isInfinite1 && !isInfinite2) thelin = Handle(Geom_Line)::DownCast (curv2); |
506 | else if (!isInfinite1 && isInfinite2) thelin = Handle(Geom_Line)::DownCast (curv1); | |
507 | else thelin = Handle(Geom_Line)::DownCast (curv1); | |
7fd59977 | 508 | ComputeTwoLinesPresentation(aPrs, thelin, firstp1, lastp1, firstp2, lastp2, isInfinite1, isInfinite2); |
509 | } | |
510 | ||
511 | // Treatement of the case of circles | |
512 | else if ( curv1->IsInstance(STANDARD_TYPE(Geom_Circle)) && curv2->IsInstance(STANDARD_TYPE(Geom_Circle)) ) { | |
513 | //gp_Pnt curpos; | |
81bba717 | 514 | isCircle = Standard_True; // useful for ComputeSelection |
c5f3a425 | 515 | Handle(Geom_Circle) thecirc (Handle(Geom_Circle)::DownCast (curv1)); |
7fd59977 | 516 | ComputeTwoCirclesPresentation(aPrs, thecirc, firstp1, lastp1, firstp2, lastp2); |
517 | } | |
518 | ||
519 | // jfa 10/10/2000 | |
520 | // Treatement of the case of ellipses | |
521 | else if ( curv1->IsInstance(STANDARD_TYPE(Geom_Ellipse)) && curv2->IsInstance(STANDARD_TYPE(Geom_Ellipse)) ) | |
522 | { | |
c5f3a425 | 523 | Handle(Geom_Ellipse) theEll (Handle(Geom_Ellipse)::DownCast (curv1)); |
7fd59977 | 524 | ComputeTwoEllipsesPresentation(aPrs, theEll, firstp1, lastp1, firstp2, lastp2); |
525 | } | |
526 | // jfa 10/10/2000 end | |
527 | else | |
528 | return; | |
529 | ||
81bba717 | 530 | // Calculate presentation of projected edges |
7fd59977 | 531 | if ( (myExtShape != 0) && !extCurv.IsNull()) { |
532 | if (myExtShape == 1 ) | |
533 | ComputeProjEdgePresentation(aPrs, TopoDS::Edge(myFShape), curv1, firstp1, lastp1); | |
534 | else | |
535 | ComputeProjEdgePresentation(aPrs, TopoDS::Edge(mySShape), curv2, firstp2, lastp2); | |
536 | } | |
537 | } | |
538 | ||
539 | //======================================================================= | |
540 | //function : ComputeTwoLinesPresentation | |
541 | //purpose : Compute the presentation of the 'identic' constraint | |
542 | // between two lines ( which are equal) | |
543 | //input : <thelin> : the | |
544 | // <firstp1>: first extremity of the 1st curve of the constraint | |
545 | // <lastp1> : last extremity of the 1st curve of the constraint | |
546 | // <firstp2>: first extremity of the 2nd curve of the constraint | |
547 | // <lastp2> :last extremity of the 2nd curve of the constraint | |
548 | //======================================================================= | |
549 | void AIS_IdenticRelation::ComputeTwoLinesPresentation(const Handle(Prs3d_Presentation)& aPrs, | |
550 | const Handle(Geom_Line)& thelin, | |
551 | gp_Pnt& firstp1, | |
552 | gp_Pnt& lastp1, | |
553 | gp_Pnt& firstp2, | |
554 | gp_Pnt& lastp2, | |
555 | const Standard_Boolean isInfinite1, | |
556 | const Standard_Boolean isInfinite2) | |
557 | { | |
558 | if (isInfinite1 && isInfinite2) { | |
559 | if ( myAutomaticPosition ) { | |
560 | myFAttach = mySAttach = thelin->Lin().Location(); | |
561 | gp_Pnt curpos; | |
562 | gp_Pln pln(myPlane->Pln()); | |
563 | gp_Dir dir(pln.XAxis().Direction()); | |
564 | gp_Vec transvec = gp_Vec(dir)*myArrowSize; | |
565 | curpos = myFAttach.Translated(transvec);; | |
566 | myPosition = curpos; | |
567 | myAutomaticPosition = Standard_True; | |
568 | } | |
569 | else { | |
570 | myFAttach = mySAttach = ElCLib::Value(ElCLib::Parameter(thelin->Lin(),myPosition),thelin->Lin()); | |
571 | } | |
572 | TCollection_ExtendedString vals(" =="); | |
573 | DsgPrs_IdenticPresentation::Add(aPrs, | |
574 | myDrawer, | |
575 | vals, | |
576 | myFAttach, | |
577 | myPosition); | |
578 | } | |
579 | else { | |
580 | // Computation of the parameters of the 4 points on the line <thelin> | |
581 | Standard_Real pf1, pf2, pl1, pl2; | |
582 | ||
583 | pf1 = ElCLib::Parameter(thelin->Lin(), firstp1); | |
584 | pl1 = ElCLib::Parameter(thelin->Lin(), lastp1); | |
585 | ||
586 | pf2 = ElCLib::Parameter(thelin->Lin(), firstp2); | |
587 | pl2 = ElCLib::Parameter(thelin->Lin(), lastp2); | |
588 | ||
589 | if (isInfinite1) { | |
590 | pf1 = pf2; | |
591 | pl1 = pl2; | |
592 | firstp1 = firstp2; | |
593 | lastp1 = lastp2; | |
594 | } | |
595 | else if (isInfinite2) { | |
596 | pf2 = pf1; | |
597 | pl2 = pl1; | |
598 | firstp2 = firstp1; | |
599 | lastp2 = lastp1; | |
600 | } | |
601 | ||
602 | Standard_Real tabRang1[4]; // array taht contains the parameters of the 4 points | |
603 | // ordered by increasing abscisses. | |
604 | ||
605 | gp_Pnt tabRang2[4]; // array containing the points corresponding to the | |
606 | // parameters in tabRang1 | |
607 | ||
608 | Standard_Integer tabRang3[4]; // array containing the number of the curve( 1 or 2) | |
609 | // of which belongs each point of tabRang2 | |
610 | ||
611 | // Filling of the arrays | |
612 | tabRang1[0] = pf1; tabRang2[0] = firstp1; tabRang3[0] = 1; | |
613 | tabRang1[1] = pf2; tabRang2[1] = firstp2; tabRang3[1] = 2; | |
614 | tabRang1[2] = pl1; tabRang2[2] = lastp1; tabRang3[2] = 1; | |
615 | tabRang1[3] = pl2; tabRang2[3] = lastp2; tabRang3[3] = 2; | |
616 | ||
617 | // Sort of the array of parameters (tabRang1) | |
618 | AIS_Sort(tabRang1, tabRang2, tabRang3); | |
619 | ||
620 | // Computation of myFAttach and mySAttach according to the | |
621 | // position of the 2 linear edges | |
622 | gp_Pnt curpos; | |
623 | gp_Pnt middle; | |
624 | ||
625 | if ( (tabRang1[0] == tabRang1[1]) && (tabRang1[2] == tabRang1[3]) ) { | |
626 | middle.SetXYZ((tabRang2[1].XYZ() + tabRang2[2].XYZ())/2. ); | |
627 | Standard_Real pmiddle = (tabRang1[1] + tabRang1[2]) / 2.; | |
628 | Standard_Real delta = (tabRang1[3] - tabRang1[0])/ 5.; | |
629 | myFAttach = ElCLib::Value(pmiddle-delta, thelin->Lin()); | |
630 | mySAttach = ElCLib::Value(pmiddle+delta, thelin->Lin()); | |
631 | } | |
632 | ||
633 | else if ( tabRang1[1] == tabRang1[2] ) { | |
634 | middle = tabRang2[1]; | |
635 | Standard_Real delta1 = tabRang1[1] - tabRang1[0]; | |
636 | Standard_Real delta2 = tabRang1[3] - tabRang1[2]; | |
637 | if ( delta1 > delta2 ) delta1 = delta2; | |
638 | myFAttach = ElCLib::Value(tabRang1[1]-delta1/2., thelin->Lin()); | |
639 | mySAttach = ElCLib::Value(tabRang1[1]+delta1/2., thelin->Lin()); | |
640 | } | |
641 | ||
642 | // Case of 2 disconnected segments -> the symbol completes the gap | |
643 | // between the 2 edges | |
644 | //-------------------------------- | |
645 | else if ( (tabRang3[0] == tabRang3[1]) && (tabRang1[1] != tabRang1[2])) { | |
646 | middle.SetXYZ((tabRang2[1].XYZ() + tabRang2[2].XYZ())/2. ); | |
647 | myFAttach = tabRang2[1]; | |
648 | mySAttach = tabRang2[2]; | |
649 | } | |
650 | else if ( (tabRang3[0] != tabRang3[1]) | |
651 | && (tabRang3[1] != tabRang3[2]) // Intersection | |
652 | && (tabRang1[1] != tabRang1[2]) ) { | |
653 | middle.SetXYZ((tabRang2[1].XYZ() + tabRang2[2].XYZ())/2. ); | |
654 | myFAttach = tabRang2[1]; | |
655 | mySAttach = tabRang2[2]; | |
656 | } | |
657 | else { // Inclusion | |
658 | myFAttach.SetXYZ((tabRang2[0].XYZ() + tabRang2[1].XYZ())/2. ); | |
659 | mySAttach.SetXYZ((tabRang2[1].XYZ() + tabRang2[2].XYZ())/2. ); | |
660 | middle.SetXYZ( (myFAttach.XYZ() + mySAttach.XYZ() )/2.); | |
661 | } | |
662 | ||
663 | ||
664 | if ( myAutomaticPosition ) { | |
665 | ||
666 | gp_Vec vtrans(myFAttach, mySAttach); | |
667 | vtrans.Normalize(); | |
668 | vtrans.Cross(gp_Vec(myPlane->Pln().Axis().Direction())); | |
669 | vtrans *= ComputeSegSize(); | |
670 | curpos = middle.Translated(vtrans); | |
671 | myPosition = curpos; | |
672 | myAutomaticPosition = Standard_True; | |
673 | } | |
674 | ||
675 | else { | |
676 | ||
677 | curpos = myPosition; | |
678 | Standard_Real pcurpos = ElCLib::Parameter(thelin->Lin() ,curpos); | |
679 | Standard_Real dist = thelin->Lin().Distance(curpos); | |
680 | gp_Pnt proj = ElCLib::Value( pcurpos, thelin->Lin()); | |
681 | gp_Vec trans; | |
682 | Standard_Real confusion(Precision::Confusion()); | |
683 | if ( dist >= confusion ) { | |
684 | trans = gp_Vec(proj, curpos); | |
685 | trans.Normalize(); | |
686 | } | |
687 | Standard_Real pf = ElCLib::Parameter(thelin->Lin() ,myFAttach); | |
688 | Standard_Real pl = ElCLib::Parameter(thelin->Lin() ,mySAttach); | |
689 | if ( pcurpos <= pf ) { | |
690 | pcurpos = pf + 1e-5; | |
691 | curpos = ElCLib::Value( pcurpos, thelin->Lin()); | |
692 | if ( dist >= confusion ) curpos.Translate(trans*dist); | |
693 | } | |
694 | else if ( pcurpos >= pl ) { | |
695 | pcurpos = pl - 1e-5; | |
696 | curpos = ElCLib::Value( pcurpos, thelin->Lin()); | |
697 | if ( dist >= confusion ) curpos.Translate(trans*dist); | |
698 | } | |
699 | SetPosition(curpos); | |
700 | } | |
701 | ||
702 | // Display of the presentation | |
703 | TCollection_ExtendedString vals(" =="); | |
704 | DsgPrs_IdenticPresentation::Add(aPrs, | |
705 | myDrawer, | |
706 | vals, | |
707 | myFAttach, | |
708 | mySAttach, | |
709 | curpos); | |
710 | } | |
711 | } | |
712 | ||
713 | // jfa 17/10/2000 | |
714 | //======================================================================= | |
715 | //function : ComputeTwoCirclesPresentation | |
716 | //purpose : Compute the presentation of the 'identic' constraint | |
717 | // between two circles ( which are equal) | |
718 | //input : <thecirc>: the circle | |
719 | // <firstp1>: first extremity of the 1st curve of the constraint | |
720 | // <lastp1> : last extremity of the 1st curve of the constraint | |
721 | // <firstp2>: first extremity of the 2nd curve of the constraint | |
722 | // <lastp2> :last extremity of the 2nd curve of the constraint | |
723 | //======================================================================= | |
724 | void AIS_IdenticRelation::ComputeTwoCirclesPresentation(const Handle(Prs3d_Presentation)& aPrs, | |
725 | const Handle(Geom_Circle)& thecirc, | |
726 | const gp_Pnt& firstp1, | |
727 | const gp_Pnt& lastp1, | |
728 | const gp_Pnt& firstp2, | |
729 | const gp_Pnt& lastp2) | |
730 | { | |
731 | Standard_Real confusion (Precision::Confusion()); | |
732 | ||
733 | // Searching of complete circles | |
734 | Standard_Boolean circ1complete = (firstp1.IsEqual(lastp1, confusion)); | |
735 | Standard_Boolean circ2complete = (firstp2.IsEqual(lastp2, confusion)); | |
736 | ||
737 | myCenter = thecirc->Location(); | |
738 | Standard_Real aSegSize = thecirc->Radius()/5.0; | |
c6541a0c | 739 | Standard_Real rad = M_PI / 5.0; |
7fd59977 | 740 | |
741 | // I. Case of 2 complete circles | |
742 | if ( circ1complete && circ2complete ) | |
743 | { | |
744 | if (myAutomaticPosition) | |
745 | { | |
746 | Standard_Real pfirst1 = ElCLib::Parameter(thecirc->Circ(), firstp1); | |
747 | myFAttach = ElCLib::Value(Modulo2PI(pfirst1-rad), thecirc->Circ()); | |
748 | mySAttach = ElCLib::Value(Modulo2PI(pfirst1+rad), thecirc->Circ()); | |
749 | ||
750 | gp_Pnt curpos = ElCLib::Value(pfirst1,thecirc->Circ()); | |
751 | gp_Vec vtrans(myCenter, curpos); | |
752 | vtrans.Normalize(); | |
753 | vtrans *= aSegSize; | |
754 | curpos.Translate(vtrans); | |
755 | myPosition = curpos; | |
756 | } | |
757 | else ComputeNotAutoCircPresentation(thecirc); | |
758 | } | |
759 | ||
760 | // II. Case of one complete circle and one arc | |
761 | else if ( (circ1complete && !circ2complete) || (!circ1complete && circ2complete) ) | |
762 | { | |
763 | gp_Pnt firstp, lastp; | |
764 | if ( circ1complete && !circ2complete) | |
765 | { | |
766 | firstp = firstp2; | |
767 | lastp = lastp2; | |
768 | } | |
769 | else | |
770 | { | |
771 | firstp = firstp1; | |
772 | lastp = lastp1; | |
773 | } | |
774 | ||
775 | if (myAutomaticPosition) | |
776 | { | |
777 | ComputeAutoArcPresentation(thecirc, firstp, lastp); | |
778 | } | |
779 | else | |
780 | { | |
781 | ComputeNotAutoArcPresentation(thecirc, firstp, lastp); | |
782 | } | |
783 | } | |
784 | ||
785 | // III and IV. Case of two arcs | |
786 | else if ( !circ1complete && !circ2complete ) | |
787 | { | |
788 | // We project all the points on the circle | |
789 | Standard_Real pf1, pf2, pl1, pl2; | |
790 | pf1 = ElCLib::Parameter(thecirc->Circ(), firstp1); | |
791 | pf2 = ElCLib::Parameter(thecirc->Circ(), firstp2); | |
792 | pl1 = ElCLib::Parameter(thecirc->Circ(), lastp1); | |
793 | pl2 = ElCLib::Parameter(thecirc->Circ(), lastp2); | |
794 | ||
795 | // III. Arcs with common ends | |
796 | // III.1. First of one and last of another | |
797 | if ( IsEqual2PI(pl1,pf2,confusion) || IsEqual2PI(pf1,pl2,confusion) ) | |
798 | { | |
799 | gp_Pnt curpos(0.,0.,0.); | |
800 | Standard_Real att=0.; | |
801 | if ( IsEqual2PI(pl1,pf2,confusion) ) | |
802 | { | |
803 | att = pl1; | |
804 | curpos = lastp1; | |
805 | } | |
806 | else if ( IsEqual2PI(pf1,pl2,confusion) ) | |
807 | { | |
808 | att = pf1; | |
809 | curpos = firstp1; | |
810 | } | |
811 | Standard_Real maxrad = Min(Modulo2PI(pl1 - pf1),Modulo2PI(pl2 - pf2))*3/4; | |
812 | if ( rad > maxrad ) rad = maxrad; | |
813 | Standard_Real pFAttach = Modulo2PI(att - rad); | |
814 | Standard_Real pSAttach = Modulo2PI(att + rad); | |
815 | myFAttach = ElCLib::Value(pFAttach, thecirc->Circ()); | |
816 | mySAttach = ElCLib::Value(pSAttach, thecirc->Circ()); | |
817 | if ( myAutomaticPosition ) | |
818 | { | |
819 | gp_Vec vtrans(myCenter,curpos); | |
820 | vtrans.Normalize(); | |
821 | vtrans *= aSegSize; | |
822 | curpos.Translate(vtrans); | |
823 | myPosition = curpos; | |
824 | } | |
825 | } | |
826 | // III.2. Two first or two last | |
827 | else if ( IsEqual2PI(pf1,pf2,confusion) || IsEqual2PI(pl1,pl2,confusion) ) | |
828 | { | |
829 | Standard_Real l1 = Modulo2PI(pl1 - pf1); | |
830 | Standard_Real l2 = Modulo2PI(pl2 - pf2); | |
831 | gp_Pnt firstp,lastp; | |
832 | if ( l1 < l2 ) | |
833 | { | |
834 | firstp = firstp1; | |
835 | lastp = lastp1; | |
836 | } | |
837 | else | |
838 | { | |
839 | firstp = firstp2; | |
840 | lastp = lastp2; | |
841 | } | |
842 | ||
843 | if ( myAutomaticPosition ) | |
844 | { | |
845 | ComputeAutoArcPresentation(thecirc, firstp, lastp); | |
846 | } | |
847 | else | |
848 | { | |
849 | ComputeNotAutoArcPresentation(thecirc, firstp, lastp); | |
850 | } | |
851 | } | |
852 | // IV. All others arcs (without common ends) | |
853 | else | |
854 | { | |
855 | // order the parameters; first will be pf1 | |
856 | Standard_Real pl1m = Modulo2PI(pl1 - pf1); | |
857 | Standard_Real pf2m = Modulo2PI(pf2 - pf1); | |
858 | Standard_Real pl2m = Modulo2PI(pl2 - pf1); | |
859 | ||
860 | Standard_Boolean case1 = Standard_False; | |
861 | // 1 - not intersecting arcs | |
862 | // 2 - intersecting arcs, but one doesn't contain another | |
863 | // 3a - first arc contains the second one | |
864 | // 3b - second arc contains the first one | |
865 | // 4 - two intersections | |
866 | ||
867 | gp_Pnt firstp, lastp; | |
868 | ||
869 | if ( pl1m < pf2m ) // 1 or 2b or 3b | |
870 | { | |
871 | if ( pl1m < pl2m ) // 1 or 3b | |
872 | { | |
873 | if ( pl2m < pf2m ) // 3b | |
874 | { | |
875 | firstp = firstp1; | |
876 | lastp = lastp1; | |
877 | } | |
878 | else // 1 | |
879 | { | |
880 | case1 = Standard_True; | |
881 | Standard_Real deltap1 = Modulo2PI(pf1 - pl2); | |
882 | Standard_Real deltap2 = Modulo2PI(pf2 - pl1); | |
883 | if ( ((deltap1 < deltap2) && (deltap1 < 2*rad)) || | |
884 | ((deltap2 < deltap1) && (deltap2 > 2*rad)) ) // deltap2 | |
885 | { | |
886 | firstp = lastp1; | |
887 | lastp = firstp2; | |
888 | } | |
889 | else // deltap1 | |
890 | { | |
891 | firstp = lastp2; | |
892 | lastp = firstp1; | |
893 | } | |
894 | } | |
895 | } | |
896 | else // 2b | |
897 | { | |
898 | firstp = firstp1; | |
899 | lastp = lastp2; | |
900 | } | |
901 | } | |
902 | else // 2a or 3a or 4 | |
903 | { | |
904 | if ( pl1m < pl2m ) // 2a | |
905 | { | |
906 | firstp = firstp2; | |
907 | lastp = lastp1; | |
908 | } | |
909 | else // 3a or 4 | |
910 | { | |
911 | if ( pl2m > pf2m ) // 3a | |
912 | { | |
913 | firstp = firstp2; | |
914 | lastp = lastp2; | |
915 | } | |
916 | else // 4 | |
917 | { | |
918 | Standard_Real deltap1 = Modulo2PI(pl1 - pf2); | |
919 | Standard_Real deltap2 = Modulo2PI(pl2 - pf1); | |
920 | if ( ((deltap1 < deltap2) && (deltap1 < 2*rad)) || | |
921 | ((deltap2 < deltap1) && (deltap2 > 2*rad)) ) // deltap2 | |
922 | { | |
923 | firstp = firstp1; | |
924 | lastp = lastp2; | |
925 | } | |
926 | else // deltap1 | |
927 | { | |
928 | firstp = firstp2; | |
929 | lastp = lastp1; | |
930 | } | |
931 | } | |
932 | } | |
933 | } | |
934 | ||
935 | if ( myAutomaticPosition ) | |
936 | { | |
937 | ComputeAutoArcPresentation(thecirc,firstp,lastp,case1); | |
938 | } | |
939 | else | |
940 | { | |
941 | if ( case1 ) | |
942 | { | |
943 | myFAttach = firstp; | |
944 | mySAttach = lastp; | |
945 | } | |
946 | else ComputeNotAutoArcPresentation(thecirc, firstp, lastp); | |
947 | } | |
948 | } | |
949 | } | |
950 | ||
951 | // Display of the presentation | |
952 | TCollection_ExtendedString vals(" =="); | |
953 | gp_Pnt attach = myPosition; | |
954 | ComputeAttach(thecirc->Circ(),myFAttach,mySAttach,attach); | |
955 | DsgPrs_IdenticPresentation::Add(aPrs, | |
956 | myDrawer, | |
957 | vals, | |
958 | myPlane->Pln().Position().Ax2(), | |
959 | myCenter, | |
960 | myFAttach, | |
961 | mySAttach, | |
962 | myPosition, | |
963 | attach); | |
964 | } | |
965 | ||
966 | //======================================================================= | |
967 | //function : ComputeAutoArcPresentation | |
968 | //purpose : Compute the presentation of the constraint where we are | |
969 | // not in the case of dragging. | |
970 | //======================================================================= | |
971 | void AIS_IdenticRelation::ComputeAutoArcPresentation(const Handle(Geom_Circle)& thecirc, | |
972 | const gp_Pnt& firstp, | |
973 | const gp_Pnt& lastp, | |
974 | const Standard_Boolean isstatic) | |
975 | { | |
976 | Standard_Real aSegSize = thecirc->Radius()/5.0; | |
c6541a0c | 977 | Standard_Real rad = M_PI / 5.0; |
7fd59977 | 978 | |
979 | Standard_Real pFA = ElCLib::Parameter(thecirc->Circ(),firstp); | |
980 | Standard_Real pSA = ElCLib::Parameter(thecirc->Circ(),lastp); | |
981 | Standard_Real maxrad = Modulo2PI(pSA - pFA)/2.0; | |
982 | ||
983 | if ( (rad > maxrad) || isstatic ) rad = maxrad; | |
984 | Standard_Real pmiddle = Modulo2PI(pFA + Modulo2PI(pSA - pFA)/2.0); | |
985 | ||
986 | myFAttach = ElCLib::Value(Modulo2PI(pmiddle - rad),thecirc->Circ()); | |
987 | mySAttach = ElCLib::Value(Modulo2PI(pmiddle + rad),thecirc->Circ()); | |
988 | ||
989 | gp_Pnt curpos = ElCLib::Value(pmiddle,thecirc->Circ()); | |
990 | gp_Vec vtrans(myCenter, curpos); | |
991 | vtrans.Normalize(); | |
992 | vtrans *= aSegSize; | |
993 | myPosition = curpos.Translated(vtrans); | |
994 | } | |
995 | ||
996 | //======================================================================= | |
997 | //function : ComputeNotAutoCircPresentation | |
998 | //purpose : Compute the presentation of the constraint where we are | |
999 | // in the case of dragging. | |
1000 | // Note : This function is to be used only in the case of full circles. | |
1001 | // The symbol of the constraint moves together with arc | |
1002 | // representing the constraint around all the circle. | |
1003 | //======================================================================= | |
1004 | void AIS_IdenticRelation::ComputeNotAutoCircPresentation(const Handle(Geom_Circle)& thecirc) | |
1005 | { | |
1006 | gp_Pnt curpos = myPosition; | |
1007 | ||
1008 | Handle(Geom_Circle) cirNotAuto = new Geom_Circle(thecirc->Circ()); | |
1009 | ||
1010 | // Case of confusion between the current position and the center | |
1011 | // of the circle -> we move the current position | |
1012 | Standard_Real confusion (Precision::Confusion()); | |
1013 | if ( myCenter.Distance(curpos) <= confusion ) | |
1014 | { | |
1015 | gp_Vec vprec(myCenter, myFAttach); | |
1016 | vprec.Normalize(); | |
1017 | curpos.Translate(vprec*1e-5); | |
1018 | } | |
1019 | ||
c6541a0c | 1020 | Standard_Real rad = M_PI / 5.0; |
7fd59977 | 1021 | Standard_Real pcurpos = ElCLib::Parameter(cirNotAuto->Circ(),curpos); |
1022 | Standard_Real pFAttach = pcurpos - rad; | |
1023 | Standard_Real pSAttach = pcurpos + rad; | |
1024 | myFAttach = ElCLib::Value(pFAttach,cirNotAuto->Circ()); | |
1025 | mySAttach = ElCLib::Value(pSAttach,cirNotAuto->Circ()); | |
1026 | } | |
1027 | ||
1028 | //======================================================================= | |
1029 | //function : ComputeNotAutoArcPresentation | |
1030 | //purpose : Compute the presentation of the constraint where we are | |
1031 | // in the case of dragging. | |
1032 | // Note : This function is to be used only in the case of circles. | |
1033 | // The symbol of the constraint moves only between myFAttach | |
1034 | // and mySAttach. | |
1035 | //======================================================================= | |
1036 | void AIS_IdenticRelation::ComputeNotAutoArcPresentation(const Handle(Geom_Circle)& thecirc, | |
1037 | const gp_Pnt& pntfirst, | |
1038 | const gp_Pnt& pntlast) | |
1039 | { | |
1040 | gp_Pnt curpos = myPosition; | |
1041 | ||
1042 | gp_Circ cirNotAuto = thecirc->Circ(); | |
1043 | ||
1044 | Standard_Real pFPnt = ElCLib::Parameter(cirNotAuto, pntfirst); | |
1045 | Standard_Real pSPnt = ElCLib::Parameter(cirNotAuto, pntlast); | |
1046 | Standard_Real deltap = Modulo2PI(pSPnt - pFPnt)/2.0; | |
1047 | ||
c6541a0c | 1048 | Standard_Real rad = M_PI / 5; |
7fd59977 | 1049 | if ( deltap < rad ) |
1050 | { | |
1051 | myFAttach = pntfirst; | |
1052 | mySAttach = pntlast; | |
1053 | } | |
1054 | else | |
1055 | { | |
1056 | gp_Pnt aFPnt = ElCLib::Value(Modulo2PI(pFPnt + rad), cirNotAuto); | |
1057 | gp_Pnt aSPnt = ElCLib::Value(Modulo2PI(pSPnt - rad), cirNotAuto); | |
1058 | ||
1059 | ComputeAttach(cirNotAuto,aFPnt,aSPnt,curpos); | |
1060 | ||
1061 | Standard_Real pcurpos = ElCLib::Parameter(cirNotAuto,curpos); | |
1062 | myFAttach = ElCLib::Value(pcurpos - rad, cirNotAuto); | |
1063 | mySAttach = ElCLib::Value(pcurpos + rad, cirNotAuto); | |
1064 | } | |
1065 | } | |
1066 | // jfa 17/10/2000 end | |
1067 | ||
1068 | // jfa 18/10/2000 | |
1069 | //======================================================================= | |
1070 | //function : ComputeTwoEllipsesPresentation | |
1071 | //purpose : Compute the presentation of the 'identic' constraint | |
1072 | // between two ellipses (which are equal) | |
1073 | //input : <theEll>: the ellipse | |
1074 | // <firstp1>: first extremity of the 1st curve of the constraint | |
1075 | // <lastp1> : last extremity of the 1st curve of the constraint | |
1076 | // <firstp2>: first extremity of the 2nd curve of the constraint | |
1077 | // <lastp2> :last extremity of the 2nd curve of the constraint | |
1078 | //======================================================================= | |
1079 | void AIS_IdenticRelation::ComputeTwoEllipsesPresentation(const Handle(Prs3d_Presentation)& aPrs, | |
1080 | const Handle(Geom_Ellipse)& theEll, | |
1081 | const gp_Pnt& firstp1, | |
1082 | const gp_Pnt& lastp1, | |
1083 | const gp_Pnt& firstp2, | |
1084 | const gp_Pnt& lastp2) | |
1085 | { | |
1086 | Standard_Real confusion (Precision::Confusion()); | |
1087 | ||
1088 | // Searching of complete ellipses | |
1089 | Standard_Boolean circ1complete = (firstp1.IsEqual(lastp1, confusion)); | |
1090 | Standard_Boolean circ2complete = (firstp2.IsEqual(lastp2, confusion)); | |
1091 | ||
1092 | myCenter = theEll->Location(); | |
1093 | Standard_Real aSegSize = theEll->MajorRadius()/5.0; | |
c6541a0c | 1094 | Standard_Real rad = M_PI / 5.0; |
7fd59977 | 1095 | |
1096 | // I. Case of 2 complete ellipses | |
1097 | if ( circ1complete && circ2complete ) | |
1098 | { | |
1099 | if (myAutomaticPosition) | |
1100 | { | |
1101 | Standard_Real pfirst1 = ElCLib::Parameter(theEll->Elips(), firstp1); | |
1102 | myFAttach = ElCLib::Value(Modulo2PI(pfirst1-rad), theEll->Elips()); | |
1103 | mySAttach = ElCLib::Value(Modulo2PI(pfirst1+rad), theEll->Elips()); | |
1104 | ||
1105 | gp_Pnt curpos = ElCLib::Value(pfirst1,theEll->Elips()); | |
1106 | gp_Vec vtrans(myCenter, curpos); | |
1107 | vtrans.Normalize(); | |
1108 | vtrans *= aSegSize; | |
1109 | curpos.Translate(vtrans); | |
1110 | myPosition = curpos; | |
1111 | } | |
1112 | else ComputeNotAutoElipsPresentation(theEll); | |
1113 | } | |
1114 | ||
1115 | // II. Case of one complete circle and one arc | |
1116 | else if ( (circ1complete && !circ2complete) || (!circ1complete && circ2complete) ) | |
1117 | { | |
1118 | gp_Pnt firstp, lastp; | |
1119 | if ( circ1complete && !circ2complete) | |
1120 | { | |
1121 | firstp = firstp2; | |
1122 | lastp = lastp2; | |
1123 | } | |
1124 | else | |
1125 | { | |
1126 | firstp = firstp1; | |
1127 | lastp = lastp1; | |
1128 | } | |
1129 | ||
1130 | if (myAutomaticPosition) | |
1131 | { | |
1132 | ComputeAutoArcPresentation(theEll, firstp, lastp); | |
1133 | } | |
1134 | else | |
1135 | { | |
1136 | ComputeNotAutoArcPresentation(theEll, firstp, lastp); | |
1137 | } | |
1138 | } | |
1139 | ||
1140 | // III and IV. Case of two arcs | |
1141 | else if ( !circ1complete && !circ2complete ) | |
1142 | { | |
1143 | // We project all the points on the circle | |
1144 | Standard_Real pf1, pf2, pl1, pl2; | |
1145 | pf1 = ElCLib::Parameter(theEll->Elips(), firstp1); | |
1146 | pf2 = ElCLib::Parameter(theEll->Elips(), firstp2); | |
1147 | pl1 = ElCLib::Parameter(theEll->Elips(), lastp1); | |
1148 | pl2 = ElCLib::Parameter(theEll->Elips(), lastp2); | |
1149 | ||
1150 | // III. Arcs with common ends | |
1151 | // III.1. First of one and last of another | |
1152 | if ( IsEqual2PI(pl1,pf2,confusion) || IsEqual2PI(pf1,pl2,confusion) ) | |
1153 | { | |
1154 | gp_Pnt curpos; | |
1155 | Standard_Real att=0.; | |
1156 | if ( IsEqual2PI(pl1,pf2,confusion) ) | |
1157 | { | |
1158 | att = pl1; | |
1159 | curpos = lastp1; | |
1160 | } | |
1161 | else if ( IsEqual2PI(pf1,pl2,confusion) ) | |
1162 | { | |
1163 | att = pf1; | |
1164 | curpos = firstp1; | |
1165 | } | |
1166 | Standard_Real maxrad = Min(Modulo2PI(pl1 - pf1),Modulo2PI(pl2 - pf2))*3/4; | |
1167 | if ( rad > maxrad ) rad = maxrad; | |
1168 | Standard_Real pFAttach = Modulo2PI(att - rad); | |
1169 | Standard_Real pSAttach = Modulo2PI(att + rad); | |
1170 | myFAttach = ElCLib::Value(pFAttach, theEll->Elips()); | |
1171 | mySAttach = ElCLib::Value(pSAttach, theEll->Elips()); | |
1172 | if ( myAutomaticPosition ) | |
1173 | { | |
1174 | gp_Vec vtrans(myCenter,curpos); | |
1175 | vtrans.Normalize(); | |
1176 | vtrans *= aSegSize; | |
1177 | curpos.Translate(vtrans); | |
1178 | myPosition = curpos; | |
1179 | } | |
1180 | } | |
1181 | // III.2. Two first or two last | |
1182 | else if ( IsEqual2PI(pf1,pf2,confusion) || IsEqual2PI(pl1,pl2,confusion) ) | |
1183 | { | |
1184 | Standard_Real l1 = Modulo2PI(pl1 - pf1); | |
1185 | Standard_Real l2 = Modulo2PI(pl2 - pf2); | |
1186 | gp_Pnt firstp,lastp; | |
1187 | if ( l1 < l2 ) | |
1188 | { | |
1189 | firstp = firstp1; | |
1190 | lastp = lastp1; | |
1191 | } | |
1192 | else | |
1193 | { | |
1194 | firstp = firstp2; | |
1195 | lastp = lastp2; | |
1196 | } | |
1197 | ||
1198 | if ( myAutomaticPosition ) | |
1199 | { | |
1200 | ComputeAutoArcPresentation(theEll, firstp, lastp); | |
1201 | } | |
1202 | else | |
1203 | { | |
1204 | ComputeNotAutoArcPresentation(theEll, firstp, lastp); | |
1205 | } | |
1206 | } | |
1207 | // IV. All others arcs (without common ends) | |
1208 | else | |
1209 | { | |
1210 | // order the parameters; first will be pf1 | |
1211 | Standard_Real pl1m = Modulo2PI(pl1 - pf1); | |
1212 | Standard_Real pf2m = Modulo2PI(pf2 - pf1); | |
1213 | Standard_Real pl2m = Modulo2PI(pl2 - pf1); | |
1214 | ||
1215 | Standard_Boolean case1 = Standard_False; | |
1216 | // 1 - not intersecting arcs | |
1217 | // 2 - intersecting arcs, but one doesn't contain another | |
1218 | // 3a - first arc contains the second one | |
1219 | // 3b - second arc contains the first one | |
1220 | // 4 - two intersections | |
1221 | ||
1222 | gp_Pnt firstp, lastp; | |
1223 | ||
1224 | if ( pl1m < pf2m ) // 1 or 2b or 3b | |
1225 | { | |
1226 | if ( pl1m < pl2m ) // 1 or 3b | |
1227 | { | |
1228 | if ( pl2m < pf2m ) // 3b | |
1229 | { | |
1230 | firstp = firstp1; | |
1231 | lastp = lastp1; | |
1232 | } | |
1233 | else // 1 | |
1234 | { | |
1235 | case1 = Standard_True; | |
1236 | Standard_Real deltap1 = Modulo2PI(pf1 - pl2); | |
1237 | Standard_Real deltap2 = Modulo2PI(pf2 - pl1); | |
1238 | if ( ((deltap1 < deltap2) && (deltap1 < 2*rad)) || | |
1239 | ((deltap2 < deltap1) && (deltap2 > 2*rad)) ) // deltap2 | |
1240 | { | |
1241 | firstp = lastp1; | |
1242 | lastp = firstp2; | |
1243 | } | |
1244 | else // deltap1 | |
1245 | { | |
1246 | firstp = lastp2; | |
1247 | lastp = firstp1; | |
1248 | } | |
1249 | } | |
1250 | } | |
1251 | else // 2b | |
1252 | { | |
1253 | firstp = firstp1; | |
1254 | lastp = lastp2; | |
1255 | } | |
1256 | } | |
1257 | else // 2a or 3a or 4 | |
1258 | { | |
1259 | if ( pl1m < pl2m ) // 2a | |
1260 | { | |
1261 | firstp = firstp2; | |
1262 | lastp = lastp1; | |
1263 | } | |
1264 | else // 3a or 4 | |
1265 | { | |
1266 | if ( pl2m > pf2m ) // 3a | |
1267 | { | |
1268 | firstp = firstp2; | |
1269 | lastp = lastp2; | |
1270 | } | |
1271 | else // 4 | |
1272 | { | |
1273 | Standard_Real deltap1 = Modulo2PI(pl1 - pf2); | |
1274 | Standard_Real deltap2 = Modulo2PI(pl2 - pf1); | |
1275 | if ( ((deltap1 < deltap2) && (deltap1 < 2*rad)) || | |
1276 | ((deltap2 < deltap1) && (deltap2 > 2*rad)) ) // deltap2 | |
1277 | { | |
1278 | firstp = firstp1; | |
1279 | lastp = lastp2; | |
1280 | } | |
1281 | else // deltap1 | |
1282 | { | |
1283 | firstp = firstp2; | |
1284 | lastp = lastp1; | |
1285 | } | |
1286 | } | |
1287 | } | |
1288 | } | |
1289 | ||
1290 | if ( myAutomaticPosition ) | |
1291 | { | |
1292 | ComputeAutoArcPresentation(theEll,firstp,lastp,case1); | |
1293 | } | |
1294 | else | |
1295 | { | |
1296 | if ( case1 ) | |
1297 | { | |
1298 | myFAttach = firstp; | |
1299 | mySAttach = lastp; | |
1300 | } | |
1301 | else ComputeNotAutoArcPresentation(theEll, firstp, lastp); | |
1302 | } | |
1303 | } | |
1304 | } | |
1305 | ||
1306 | // Display of the presentation | |
1307 | TCollection_ExtendedString vals(" =="); | |
1308 | gp_Pnt attach = myPosition; | |
1309 | ComputeAttach(theEll->Elips(),myFAttach,mySAttach,attach); | |
1310 | DsgPrs_IdenticPresentation::Add(aPrs, | |
1311 | myDrawer, | |
1312 | vals, | |
1313 | theEll->Elips(), | |
1314 | myFAttach, | |
1315 | mySAttach, | |
1316 | myPosition, | |
1317 | attach); | |
1318 | } | |
1319 | ||
1320 | //======================================================================= | |
1321 | //function : ComputeAutoArcPresentation | |
1322 | //purpose : Compute the presentation of the constraint where we are | |
1323 | // not in the case of dragging. | |
1324 | //======================================================================= | |
1325 | void AIS_IdenticRelation::ComputeAutoArcPresentation(const Handle(Geom_Ellipse)& theEll, | |
1326 | const gp_Pnt& firstp, | |
1327 | const gp_Pnt& lastp, | |
1328 | const Standard_Boolean isstatic) | |
1329 | { | |
1330 | Standard_Real aSegSize = theEll->MajorRadius()/5.0; | |
c6541a0c | 1331 | Standard_Real rad = M_PI / 5.0; |
7fd59977 | 1332 | |
1333 | gp_Elips anEll = theEll->Elips(); | |
1334 | ||
1335 | Standard_Real pFA = ElCLib::Parameter(anEll,firstp); | |
1336 | Standard_Real pSA = ElCLib::Parameter(anEll,lastp); | |
1337 | Standard_Real maxrad = Modulo2PI(pSA - pFA)/2.0; | |
1338 | ||
1339 | if ( (rad > maxrad) || isstatic ) rad = maxrad; | |
1340 | Standard_Real pmiddle = Modulo2PI(pFA + Modulo2PI(pSA - pFA)/2.0); | |
1341 | ||
1342 | myFAttach = ElCLib::Value(Modulo2PI(pmiddle - rad),anEll); | |
1343 | mySAttach = ElCLib::Value(Modulo2PI(pmiddle + rad),anEll); | |
1344 | ||
1345 | gp_Pnt curpos = ElCLib::Value(pmiddle,anEll); | |
1346 | gp_Vec vtrans(myCenter, curpos); | |
1347 | vtrans.Normalize(); | |
1348 | vtrans *= aSegSize; | |
1349 | myPosition = curpos.Translated(vtrans); | |
1350 | } | |
1351 | ||
1352 | //======================================================================= | |
1353 | //function : ComputeNotAutoElipsPresentation | |
1354 | //purpose : Compute the presentation of the constraint where we are | |
1355 | // in the case of dragging. | |
1356 | // Note : This function is to be used only in the case of ellipses. | |
1357 | // The symbol of the constraint moves only between myFAttach | |
1358 | // and mySAttach. | |
1359 | //======================================================================= | |
1360 | void AIS_IdenticRelation::ComputeNotAutoElipsPresentation(const Handle(Geom_Ellipse)& theEll) | |
1361 | { | |
1362 | gp_Pnt curpos = myPosition; | |
1363 | ||
1364 | gp_Elips anEll = theEll->Elips(); | |
1365 | ||
1366 | // Case of confusion between the current position and the center | |
1367 | // of the ellipse -> we move the current position | |
1368 | Standard_Real confusion (Precision::Confusion()); | |
1369 | if ( myCenter.Distance(curpos) <= confusion ) | |
1370 | { | |
1371 | gp_Vec vprec(myCenter, myFAttach); | |
1372 | vprec.Normalize(); | |
1373 | curpos.Translate(vprec*1e-5); | |
1374 | } | |
1375 | ||
c6541a0c | 1376 | Standard_Real rad = M_PI / 5.0; |
7fd59977 | 1377 | // Standard_Real pcurpos = ElCLib::Parameter(anEll,curpos); |
1378 | GeomAPI_ProjectPointOnCurve aProj (curpos, theEll); | |
1379 | Standard_Real pcurpos = aProj.LowerDistanceParameter(); | |
1380 | ||
1381 | Standard_Real pFAttach = pcurpos - rad; | |
1382 | Standard_Real pSAttach = pcurpos + rad; | |
1383 | myFAttach = ElCLib::Value(pFAttach,anEll); | |
1384 | mySAttach = ElCLib::Value(pSAttach,anEll); | |
1385 | } | |
1386 | ||
1387 | //======================================================================= | |
1388 | //function : ComputeNotAutoArcPresentation | |
1389 | //purpose : Compute the presentation of the constraint where we are | |
1390 | // in the case of dragging. | |
1391 | // Note : This function is to be used only in the case of ellipses. | |
1392 | // The symbol of the constraint moves only between myFAttach | |
1393 | // and mySAttach. | |
1394 | //======================================================================= | |
1395 | void AIS_IdenticRelation::ComputeNotAutoArcPresentation(const Handle(Geom_Ellipse)& theEll, | |
1396 | const gp_Pnt& pntfirst, | |
1397 | const gp_Pnt& pntlast) | |
1398 | { | |
1399 | gp_Pnt curpos = myPosition; | |
1400 | ||
1401 | gp_Elips anEll = theEll->Elips(); | |
1402 | ||
1403 | Standard_Real pFPnt = ElCLib::Parameter(anEll, pntfirst); | |
1404 | Standard_Real pSPnt = ElCLib::Parameter(anEll, pntlast); | |
1405 | Standard_Real deltap = Modulo2PI(pSPnt - pFPnt)/2.0; | |
1406 | ||
c6541a0c | 1407 | Standard_Real rad = M_PI / 5; |
7fd59977 | 1408 | if ( deltap < rad ) |
1409 | { | |
1410 | myFAttach = pntfirst; | |
1411 | mySAttach = pntlast; | |
1412 | } | |
1413 | else | |
1414 | { | |
1415 | gp_Pnt aFPnt = ElCLib::Value(Modulo2PI(pFPnt + rad), anEll); | |
1416 | gp_Pnt aSPnt = ElCLib::Value(Modulo2PI(pSPnt - rad), anEll); | |
1417 | ||
1418 | ComputeAttach(anEll,aFPnt,aSPnt,curpos); | |
1419 | ||
1420 | // Standard_Real pcurpos = ElCLib::Parameter(anEll,curpos); | |
1421 | GeomAPI_ProjectPointOnCurve aProj (curpos, theEll); | |
1422 | Standard_Real pcurpos = aProj.LowerDistanceParameter(); | |
1423 | ||
1424 | myFAttach = ElCLib::Value(pcurpos - rad, anEll); | |
1425 | mySAttach = ElCLib::Value(pcurpos + rad, anEll); | |
1426 | } | |
1427 | } | |
1428 | // jfa 18/10/2000 end | |
1429 | ||
1430 | //======================================================================= | |
1431 | //function : ComputeTwoVerticesPresentation | |
1432 | //purpose : | |
1433 | //======================================================================= | |
1434 | void AIS_IdenticRelation::ComputeTwoVerticesPresentation(const Handle(Prs3d_Presentation)& aPrs) | |
1435 | { | |
1436 | Standard_Boolean isOnPlane1, isOnPlane2; | |
1437 | const TopoDS_Vertex& FVertex = TopoDS::Vertex(myFShape); | |
1438 | const TopoDS_Vertex& SVertex = TopoDS::Vertex(mySShape); | |
1439 | ||
1440 | AIS::ComputeGeometry(FVertex, myFAttach, myPlane, isOnPlane1); | |
1441 | AIS::ComputeGeometry(SVertex, mySAttach, myPlane, isOnPlane2); | |
1442 | ||
1443 | if (isOnPlane1 && isOnPlane2) | |
1444 | myExtShape = 0; | |
1445 | else if ( isOnPlane1 && !isOnPlane2) | |
1446 | myExtShape = 2; | |
1447 | else if (!isOnPlane1 && isOnPlane2) | |
1448 | myExtShape = 1; | |
1449 | else | |
1450 | return ; | |
1451 | ||
1452 | ||
1453 | // The attachement points are the points themselves that must be | |
1454 | //identical | |
1455 | myFAttach = BRep_Tool::Pnt(FVertex); | |
1456 | mySAttach = myFAttach; | |
1457 | ||
1458 | gp_Pnt curpos; | |
1459 | if (myAutomaticPosition) | |
1460 | { | |
1461 | //Computation of the size of the symbol | |
1462 | Standard_Real symbsize = ComputeSegSize(); | |
1463 | if (symbsize <= Precision::Confusion()) symbsize = 1.; | |
1464 | symbsize*=5; | |
1465 | // Computation of the direction of the segment of the presentation | |
1466 | // we take the median of the edges connected to vertices | |
1467 | gp_Dir dF, dS; | |
1468 | gp_Dir myDir; | |
1469 | TColStd_ListIteratorOfListOfTransient it(Users()); | |
1470 | if (it.More()) | |
1471 | { | |
c5f3a425 | 1472 | Handle(AIS_Shape) USER (Handle(AIS_Shape)::DownCast(it.Value())); |
7fd59977 | 1473 | if (!USER.IsNull()) |
1474 | { | |
1475 | const TopoDS_Shape& SH =USER->Shape(); | |
1476 | if ( (!SH.IsNull()) && (SH.ShapeType() == TopAbs_WIRE) ) | |
1477 | { | |
1478 | const TopoDS_Wire& WIRE = TopoDS::Wire(USER->Shape()); | |
1479 | Standard_Boolean done = ComputeDirection(WIRE,FVertex,dF); | |
1480 | if (!done) return; | |
1481 | done = ComputeDirection(WIRE,SVertex,dS); | |
1482 | if (!done) return; | |
1483 | } | |
1484 | else return; | |
1485 | } | |
1486 | else return; | |
1487 | ||
1488 | // computation of the segment direction like average | |
1489 | // of the 2 computed directions. | |
1490 | if ( dF.IsParallel(dS, Precision::Angular()) ) | |
1491 | { | |
1492 | myDir = dF.Crossed(myPlane->Pln().Axis().Direction()); | |
1493 | } | |
1494 | else | |
1495 | { | |
1496 | myDir.SetXYZ(dF.XYZ() + dS.XYZ()); | |
1497 | } | |
1498 | curpos = myFAttach.Translated(gp_Vec(myDir)*symbsize) ; | |
1499 | } | |
1500 | // jfa 11/10/2000 | |
1501 | else | |
1502 | { | |
1503 | curpos = myFAttach; | |
1504 | } | |
1505 | // jfa 11/10/2000 end | |
1506 | ||
1507 | myPosition = curpos; | |
1508 | myAutomaticPosition = Standard_False; | |
1509 | } | |
1510 | else | |
1511 | { | |
1512 | curpos = myPosition; | |
1513 | } | |
1514 | ||
1515 | // Presentation computation | |
1516 | TCollection_ExtendedString vals(" ++"); | |
1517 | DsgPrs_IdenticPresentation::Add(aPrs, | |
1518 | myDrawer, | |
1519 | vals, | |
1520 | myFAttach, | |
1521 | curpos); | |
81bba717 | 1522 | // Calculate the projection of vertex |
7fd59977 | 1523 | if ( myExtShape == 1) |
1524 | ComputeProjVertexPresentation(aPrs,FVertex,myFAttach); | |
1525 | else if ( myExtShape == 2) | |
1526 | ComputeProjVertexPresentation(aPrs,SVertex,mySAttach); | |
1527 | } | |
1528 | ||
1529 | ||
1530 | ||
1531 | //======================================================================= | |
1532 | //function : ComputeSegSize | |
1533 | //purpose : | |
1534 | //======================================================================= | |
1535 | Standard_Real AIS_IdenticRelation::ComputeSegSize() const | |
1536 | { | |
1537 | return 1.; | |
1538 | } | |
1539 | ||
1540 | //======================================================================= | |
1541 | //function : ComputeDirection | |
1542 | //purpose : Compute a direction according to the different geometric | |
1543 | // elements connected to the vertex <VERT>, in way to not have | |
81bba717 | 1544 | // overlap between the symbol and them. |
7fd59977 | 1545 | //======================================================================= |
1546 | Standard_Boolean AIS_IdenticRelation::ComputeDirection(const TopoDS_Wire& aWire, | |
1547 | const TopoDS_Vertex& VERT, | |
1548 | gp_Dir& dF) const | |
1549 | { | |
1550 | // we take the median of the edges connected to vertices | |
1551 | TopoDS_Edge edg1,edg2; | |
1552 | ConnectedEdges(aWire,VERT,edg1,edg2); | |
1553 | ||
1554 | if ( edg1.IsNull() && edg2.IsNull() ) { | |
1555 | return Standard_False; | |
1556 | } | |
1557 | ||
1558 | Handle(Geom_Curve) curv1,curv2; | |
1559 | gp_Pnt firstp1,lastp1,firstp2,lastp2; | |
1560 | ||
1561 | // Case with 2 edges connected to the vertex <VERT> | |
1562 | if ( !edg1.IsNull() && !edg2.IsNull() ) { | |
1563 | if ( !AIS::ComputeGeometry(edg1,edg2, | |
1564 | curv1,curv2, | |
1565 | firstp1, lastp1, | |
1566 | firstp2, lastp2,myPlane)) | |
1567 | return Standard_False; | |
1568 | ||
1569 | gp_Dir d1, d2; | |
1570 | if ( curv1->IsInstance(STANDARD_TYPE(Geom_Circle)) ) { | |
c5f3a425 | 1571 | d1 = ComputeCircleDirection(Handle(Geom_Circle)::DownCast (curv1), VERT); |
7fd59977 | 1572 | } |
1573 | else if (curv1->IsInstance(STANDARD_TYPE(Geom_Line)) ) { | |
c5f3a425 | 1574 | d1 = ComputeLineDirection(Handle(Geom_Line)::DownCast (curv1), firstp1); |
7fd59977 | 1575 | } |
1576 | else | |
1577 | return Standard_False; | |
1578 | ||
1579 | if ( curv2->IsInstance(STANDARD_TYPE(Geom_Circle)) ) { | |
c5f3a425 | 1580 | d2 = ComputeCircleDirection( Handle(Geom_Circle)::DownCast (curv2), VERT); |
7fd59977 | 1581 | } |
1582 | else if (curv2->IsInstance(STANDARD_TYPE(Geom_Line)) ) { | |
c5f3a425 | 1583 | d2 =ComputeLineDirection( Handle(Geom_Line)::DownCast (curv2), firstp2); |
7fd59977 | 1584 | } |
1585 | else | |
1586 | return Standard_False; | |
1587 | ||
1588 | if ( !d1.IsParallel(d2, Precision::Angular() )) | |
1589 | dF.SetXYZ( (d1.XYZ() + d2.XYZ())/2 ); | |
1590 | else { | |
1591 | dF= d1.Crossed(myPlane->Pln().Axis().Direction()); | |
1592 | } | |
1593 | } | |
1594 | ||
1595 | // Case where <VERT> is at an extremity of a wire. | |
1596 | else { | |
1597 | TopoDS_Edge VEdge; | |
1598 | if ( !edg1.IsNull() ) | |
1599 | VEdge = edg1; | |
1600 | else if (!edg2.IsNull() ) | |
1601 | VEdge = edg2; | |
1602 | else | |
1603 | return Standard_False; | |
1604 | ||
1605 | if ( !AIS::ComputeGeometry(VEdge, curv1, firstp1, lastp1) ) | |
1606 | return Standard_False; | |
1607 | if ( curv1->IsInstance(STANDARD_TYPE(Geom_Circle)) ) { | |
c5f3a425 | 1608 | dF = ComputeCircleDirection( Handle(Geom_Circle)::DownCast (curv1), VERT); |
7fd59977 | 1609 | } |
1610 | else if (curv1->IsInstance(STANDARD_TYPE(Geom_Line)) ) { | |
c5f3a425 | 1611 | dF = ComputeLineDirection( Handle(Geom_Line)::DownCast (curv1), firstp1); |
7fd59977 | 1612 | } |
1613 | else | |
1614 | return Standard_False; | |
1615 | } | |
1616 | ||
1617 | return Standard_True; | |
1618 | } | |
1619 | ||
1620 | //======================================================================= | |
1621 | //function : ComputeLineDirection | |
1622 | //purpose : | |
1623 | //======================================================================= | |
1624 | gp_Dir AIS_IdenticRelation::ComputeLineDirection(const Handle(Geom_Line)& lin, | |
1625 | const gp_Pnt& firstP) const | |
1626 | { | |
1627 | gp_Dir dir; | |
1628 | dir = lin->Lin().Direction(); | |
1629 | if ( !myFAttach.IsEqual(firstP, Precision::Confusion()) ) | |
1630 | dir.Reverse(); | |
1631 | return dir; | |
1632 | } | |
1633 | ||
1634 | //======================================================================= | |
1635 | //function : ComputeCircleDirection | |
1636 | //purpose : | |
1637 | //======================================================================= | |
1638 | gp_Dir AIS_IdenticRelation::ComputeCircleDirection(const Handle(Geom_Circle)& circ, | |
1639 | const TopoDS_Vertex& VERT) const | |
1640 | { | |
1641 | gp_Vec V(circ->Location(),BRep_Tool::Pnt(VERT)); | |
1642 | return gp_Dir(V); | |
1643 | } | |
1644 | ||
1645 | //======================================================================= | |
1646 | //function : ComputeOneEdgeOVertexPresentation | |
1647 | //purpose : | |
1648 | //======================================================================= | |
1649 | void AIS_IdenticRelation::ComputeOneEdgeOVertexPresentation(const Handle(Prs3d_Presentation)& aPrs) | |
1650 | { | |
1651 | TopoDS_Vertex V; | |
1652 | TopoDS_Edge E; | |
1653 | Standard_Integer numedge; | |
1654 | ||
1655 | if (myFShape.ShapeType() == TopAbs_VERTEX) { | |
1656 | V = TopoDS::Vertex(myFShape); | |
1657 | E = TopoDS::Edge(mySShape); | |
81bba717 | 1658 | numedge = 2;// edge = 2nd shape |
7fd59977 | 1659 | } |
1660 | else { | |
1661 | V = TopoDS::Vertex(mySShape); | |
1662 | E = TopoDS::Edge(myFShape); | |
81bba717 | 1663 | numedge = 1; // edge = 1st shape |
7fd59977 | 1664 | } |
1665 | gp_Pnt ptonedge1,ptonedge2; | |
1666 | Handle(Geom_Curve) aCurve; | |
1667 | Handle(Geom_Curve) extCurv; | |
1668 | Standard_Boolean isInfinite; | |
1669 | Standard_Boolean isOnPlanEdge, isOnPlanVertex; | |
1670 | if (!AIS::ComputeGeometry(E,aCurve,ptonedge1,ptonedge2,extCurv,isInfinite,isOnPlanEdge,myPlane)) | |
1671 | return; | |
1672 | aPrs->SetInfiniteState(isInfinite); | |
1673 | AIS::ComputeGeometry(V, myFAttach, myPlane, isOnPlanVertex); | |
1674 | ||
81bba717 | 1675 | // only the curve can be projected |
7fd59977 | 1676 | if (!isOnPlanEdge && !isOnPlanVertex) return; |
1677 | ||
1678 | if (!isOnPlanEdge) { | |
1679 | if (numedge == 1) myExtShape = 1; | |
1680 | else myExtShape = 2; | |
1681 | } | |
1682 | else if (!isOnPlanVertex) { | |
1683 | if (numedge == 1) myExtShape = 2; | |
1684 | else myExtShape = 1; | |
1685 | } | |
1686 | // The attachement points are the point | |
1687 | myFAttach = BRep_Tool::Pnt(V); | |
1688 | mySAttach = myFAttach; | |
1689 | ||
1690 | gp_Pnt curpos; | |
1691 | if (myAutomaticPosition) { | |
1692 | //Computation of the size of the symbol | |
1693 | Standard_Real symbsize = ComputeSegSize(); | |
1694 | symbsize*=5; | |
1695 | // Computation of the direction of the segment of the presentation | |
1696 | // we take the median of the edges connected to vertices | |
1697 | gp_Dir myDir; | |
1698 | if ( aCurve->IsKind(STANDARD_TYPE(Geom_Line))) { | |
c5f3a425 | 1699 | myDir = Handle(Geom_Line)::DownCast (aCurve)->Lin().Direction(); |
7fd59977 | 1700 | myDir.Cross(myPlane->Pln().Axis().Direction()); |
1701 | } | |
1702 | else if (aCurve->IsKind(STANDARD_TYPE(Geom_Circle))) { | |
c5f3a425 | 1703 | Handle(Geom_Circle) CIR = Handle(Geom_Circle)::DownCast (aCurve); |
7fd59977 | 1704 | myDir.SetXYZ(myFAttach.XYZ() - CIR->Location().XYZ()); |
1705 | } | |
1706 | // jfa 10/10/2000 | |
1707 | else if (aCurve->IsKind(STANDARD_TYPE(Geom_Ellipse))) { | |
c5f3a425 | 1708 | Handle(Geom_Ellipse) CIR = Handle(Geom_Ellipse)::DownCast (aCurve); |
7fd59977 | 1709 | myDir.SetXYZ(myFAttach.XYZ() - CIR->Location().XYZ()); |
1710 | } | |
1711 | // jfa 10/10/2000 end | |
1712 | ||
1713 | curpos = myFAttach.Translated(gp_Vec(myDir)*symbsize) ; | |
1714 | myPosition = curpos; | |
1715 | myAutomaticPosition = Standard_True; | |
1716 | } | |
1717 | else { | |
1718 | curpos = myPosition; | |
1719 | } | |
1720 | ||
1721 | // Presentation computation | |
1722 | TCollection_ExtendedString vals(" -+-"); | |
1723 | DsgPrs_IdenticPresentation::Add(aPrs, | |
1724 | myDrawer, | |
1725 | vals, | |
1726 | myFAttach, | |
1727 | curpos); | |
1728 | if (myExtShape != 0) { | |
81bba717 | 1729 | if (!extCurv.IsNull()) { // the edge is not in the WP |
c5f3a425 | 1730 | ComputeProjEdgePresentation(aPrs,E,Handle(Geom_Line)::DownCast (aCurve),ptonedge1,ptonedge2); |
7fd59977 | 1731 | } |
1732 | } | |
1733 | } |