Integration of OCCT 6.5.0 from SVN
[occt.git] / src / TPrsStd / TPrsStd_ConstraintTools.cxx
CommitLineData
7fd59977 1// File: TPrsStd_ConstraintTools.cxx
2// Language: C++
3// Version: Euclid Designer 2.0
4// Purpose: Update AIS object from a TDataXtd_Constraint.
5// Modified Mon 30 10:15:43 1998 by SZY
6// <szy@philipox.nnov.matra-dtv.fr>
7
8
9#include <TPrsStd_ConstraintTools.ixx>
10
11#include <stdio.h>
12#include <UnitsAPI.hxx>
13#include <TCollection_ExtendedString.hxx>
14
15#include <TNaming_Tool.hxx>
16#include <TNaming_Iterator.hxx>
17#include <TNaming_NamedShape.hxx>
18#include <TDF_Label.hxx>
19#include <TDataStd_Real.hxx>
20#include <TDataStd_Name.hxx>
21#include <TDataXtd_Geometry.hxx>
22#include <TDF_Reference.hxx>
23
24
25#include <AIS_OffsetDimension.hxx>
26#include <AIS_LengthDimension.hxx>
27#include <AIS_ParallelRelation.hxx>
28#include <AIS_TangentRelation.hxx>
29#include <AIS_IdenticRelation.hxx>
30#include <AIS_AngleDimension.hxx>
31#include <AIS_RadiusDimension.hxx>
32#include <AIS_DiameterDimension.hxx>
33#include <AIS_FixRelation.hxx>
34#include <AIS_PerpendicularRelation.hxx>
35#include <AIS_ConcentricRelation.hxx>
36#include <AIS_SymmetricRelation.hxx>
37#include <AIS_MidPointRelation.hxx>
38#include <AIS_InteractiveContext.hxx>
39#include <AIS_Drawer.hxx>
40#include <AIS_EqualRadiusRelation.hxx>
41#include <AIS_EqualDistanceRelation.hxx>
42#include <AIS_MinRadiusDimension.hxx>
43#include <AIS_MaxRadiusDimension.hxx>
44
45#include <TopoDS.hxx>
46#include <TopoDS_Edge.hxx>
47#include <TopoDS_Shape.hxx>
48#include <TopoDS_Face.hxx>
49#include <TopoDS_Vertex.hxx>
50#include <TopExp.hxx>
51#include <TopExp_Explorer.hxx>
52
53#include <BRep_Tool.hxx>
54#include <BRep_Builder.hxx>
55#include <BRepBuilderAPI_MakeFace.hxx>
56#include <BRepAdaptor_Curve.hxx>
57#include <BRepAdaptor_Surface.hxx>
58
59#include <GeomAbs_SurfaceType.hxx>
60#include <Geom_Geometry.hxx>
61#include <Geom_Line.hxx>
62#include <Geom_Plane.hxx>
63#include <Geom_CartesianPoint.hxx>
64#include <Geom_Circle.hxx>
65#include <gp_Pln.hxx>
66#include <gp_Dir.hxx>
67#include <gp_Ax1.hxx>
68#include <gp_Lin.hxx>
69#include <gp_Pnt.hxx>
70#include <gp_Cylinder.hxx>
71#include <gp_Cone.hxx>
72#include <gp_Torus.hxx>
73#include <GC_MakePlane.hxx>
74
75#include <Precision.hxx>
76#include <IntAna_QuadQuadGeo.hxx>
77
78#include <Standard_ProgramError.hxx>
79#include <Standard_ErrorHandler.hxx>
80
81#include <TopTools_IndexedMapOfShape.hxx>
82
83#define BUC60846
84
85static Standard_Boolean CheckShapesPair(const TopoDS_Shape& , const TopoDS_Shape& ); //ota
86
87//=======================================================================
88//function : static NullifyAIS
89//purpose :
90//=======================================================================
91static void NullifyAIS ( Handle(AIS_InteractiveObject)& anais)
92{
93 if (anais.IsNull()) return;
94 anais.Nullify();
95}
96
97
98
99//=======================================================================
100//function : static FindExternalShape
101//purpose :
102//=======================================================================
103static void FindExternalShape(const Handle(TDataXtd_Constraint)& aConst,
104 Standard_Integer& extShape)
105{
106 extShape = 0;
107 const TDF_Label& L = aConst->Label();
108 if (!aConst->GetGeometry(1)->Label().IsDescendant(L)) extShape = 1;
109 else if (!aConst->GetGeometry(2)->Label().IsDescendant(L)) extShape = 2;
110}
111
112//=======================================================================
113//function : static GetGoodShape for planar constraint
114//purpose :
115//=======================================================================
116static void GetGoodShape(TopoDS_Shape& shape)
117{
118 switch (shape.ShapeType()) {
119 case TopAbs_EDGE:
120 case TopAbs_VERTEX: { return; }
121 default:
122 {
123 TopExp_Explorer EXP(shape,TopAbs_EDGE);
124 if (EXP.More()) {
125 shape = EXP.Current();
126 return;
127 }
128 else {
129 EXP.Init(shape,TopAbs_VERTEX);
130 if (EXP.More()) shape = EXP.Current();
131 }
132 }
133 }
134}
135
136// Pour le cas ou S est un compound
137static Standard_Boolean IsFace (const TopoDS_Shape& S)
138{
139 Standard_Boolean findface = Standard_False;
140 TopExp_Explorer EXP (S,TopAbs_FACE);
141 if (EXP.More()) findface = Standard_True;
142 return findface;
143}
144
145static TopoDS_Face GetFace (const TopoDS_Shape& S)
146{
147 TopoDS_Face F;
148 TopExp_Explorer EXP (S,TopAbs_FACE);
149 if (EXP.More()) F = TopoDS::Face (EXP.Current());
150 return F;
151}
152
153static TopoDS_Edge GetEdge (const TopoDS_Shape& S)
154{
155 TopoDS_Edge E;
156 TopExp_Explorer EXP (S, TopAbs_EDGE);
157 if (EXP.More()) E = TopoDS::Edge (EXP.Current());
158 return E;
159}
160
161
162
163//=======================================================================
164//Function : ComputeAndTextValue
165//purpose :
166//=======================================================================
167void TPrsStd_ConstraintTools::ComputeTextAndValue(const Handle(TDataXtd_Constraint)& aConst,
168 Standard_Real& val,
169 TCollection_ExtendedString& txt,
170 const Standard_Boolean anIsAngle )
171{
172 Standard_Real outvalue;
173 const Handle(TDataStd_Real)& VAL = aConst->GetValue();
174 val = VAL->Get();
175 if(anIsAngle){
176 outvalue = UnitsAPI::CurrentFromLS(Abs(val),"PLANE ANGLE");
177 }
178 else {
179 outvalue = UnitsAPI::CurrentFromLS(val,"LENGTH");
180 }
181 char res[1000];
182 sprintf(res,"%g",outvalue);
183 txt = TCollection_ExtendedString(res);
184
185 if (VAL->IsCaptured()) {
186 Handle(TDF_Reference) ref;
187 VAL->Label().FindAttribute(TDF_Reference::GetID(),ref);
188 Handle(TDataStd_Name) name;
189 const TDF_Label& L = ref->Get();
190 if (ref->Get().FindAttribute(TDataStd_Name::GetID(),name)) {
191 TCollection_ExtendedString fullname;
192 Handle(TDataStd_Name) Fathername;
193 if (L.Father().FindAttribute(TDataStd_Name::GetID(),Fathername)) {
194 fullname = Fathername->Get() + TCollection_ExtendedString(".") + name->Get();
195 }
196 else fullname = name->Get();
197 txt = fullname + TCollection_ExtendedString("=") + txt;
198 }
199 }
200}
201
202
203//=======================================================================
204//function : UpdateOnlyValue
205//purpose :
206//=======================================================================
207
208void TPrsStd_ConstraintTools::UpdateOnlyValue(const Handle(TDataXtd_Constraint)& aConst,
209 const Handle(AIS_InteractiveObject)& anAIS)
210{
211 if (anAIS.IsNull()) return;
212 if (!aConst->IsDimension()) return;
213 Standard_Real val;
214 TCollection_ExtendedString txt;
215 TPrsStd_ConstraintTools:: ComputeTextAndValue(aConst,val,txt,aConst->GetType() == TDataXtd_ANGLE);
216 Handle(AIS_Relation) rel = Handle(AIS_Relation)::DownCast(anAIS);
217 if (!rel.IsNull()) rel->SetText(txt);
218}
219
220
221//=======================================================================
222//function : ComputeDistance
223//purpose : Build an AIS_LengtDimension.
224//=======================================================================
225void TPrsStd_ConstraintTools::ComputeDistance (const Handle(TDataXtd_Constraint)& aConst,
226 Handle(AIS_InteractiveObject)& anAIS)
227{
228 Standard_Integer nbgeom = aConst->NbGeometries();
229 if (nbgeom < 2) {
230#ifdef DEB
231 cout << "TPrsStd_ConstraintTools::ComputeDistance: at least 2 geometries are needed" << endl;
232#endif
233 NullifyAIS(anAIS);
234 return;
235 }
236 TopoDS_Shape shape1,shape2,shape3 ;
237 Handle(Geom_Geometry) ageom3;
238 Standard_Boolean is_planar(aConst->IsPlanar()),is_directed(Standard_False);
239 AIS_TypeOfDist typedist = AIS_TOD_Unknown;
240
241 // Get shapes and geometry
242 if (is_planar) {
243 if (nbgeom == 2)
244 GetShapesAndGeom (aConst,shape1,shape2,ageom3);
245 else
246 GetShapesAndGeom (aConst,shape1,shape2,shape3,ageom3);
247 }
248 else
249 GetTwoShapes (aConst,shape1,shape2);
250
251 if (shape1.IsNull() || shape2.IsNull()) {
252#ifdef DEB
253 cout << "TPrsStd_ConstraintTools::ComputeDistance : null shape" << endl;
254#endif
255 NullifyAIS(anAIS);
256 return;
257 }
258
259 Handle(Geom_Plane) aplane;
260 if (is_planar) {
261 if (nbgeom != 2) {
262 is_directed = !shape3.IsNull();
263 if (!is_directed) {
264#ifdef DEB
265 cout << "TPrsStd_ConstraintTools::ComputeDistance : null shape" << endl;
266#endif
267 NullifyAIS(anAIS);
268 return;
269 }
270 }
271
272 GetGoodShape (shape1);
273 GetGoodShape (shape2);
274
275 aplane = Handle(Geom_Plane)::DownCast(ageom3);
276 if (aplane.IsNull()) {
277#ifdef DEB
278 cout << "TPrsStd_ConstraintTools::ComputeDistance : null plane" << endl;
279#endif
280 NullifyAIS(anAIS);
281 return;
282 }
283
284 if (is_directed) {
285 GetGoodShape(shape3);
286 const TopoDS_Edge& E = TopoDS::Edge(shape3);
287 BRepAdaptor_Curve CURVE(E);
288 Handle_Geom_Geometry aGeomGeometry = CURVE.Curve().Curve()->Transformed(CURVE.Trsf()) ;
289 gp_Dir Dir = ((Handle(Geom_Line)&) aGeomGeometry)->Lin().Direction();
290 gp_Dir xdir(aplane->Pln().Position().XDirection());
291 if (Dir.IsParallel(xdir,Precision::Confusion()))
292 typedist = AIS_TOD_Horizontal;
293 else
294 typedist = AIS_TOD_Vertical;
295 }
296 }
297
298 Standard_Real val1;
299 TCollection_ExtendedString txt;
300 ComputeTextAndValue(aConst,val1,txt,Standard_False);
301
302 // Arguments de l'AIS
303 Standard_Boolean isface = IsFace(shape1) && IsFace(shape2);
304 Standard_Boolean isedgeface = (shape1.ShapeType () == TopAbs_FACE &&
305 shape2.ShapeType () == TopAbs_EDGE);
306 Standard_Boolean is2vertices =(shape1.ShapeType () == TopAbs_VERTEX && //addition 1
307 shape2.ShapeType () == TopAbs_VERTEX);
308 if (!isface && !is_planar && !is2vertices) {
309 // Recherche arguments pouvant convenir
310 if (shape1.ShapeType() == shape2.ShapeType()) {
311 TopoDS_Vertex v1,v2,v3,v4;
312 if (shape1.ShapeType() == TopAbs_EDGE) {
313 TopExp::Vertices (TopoDS::Edge(shape1),v1,v2);
314 TopExp::Vertices (TopoDS::Edge(shape2),v3,v4);
315 }
316 else
317 if (shape1.ShapeType() == TopAbs_WIRE) {
318 TopExp::Vertices (TopoDS::Wire(shape1),v1,v2);
319 TopExp::Vertices (TopoDS::Wire(shape2),v3,v4);
320 }
321 shape1 = v1;
322 gp_Pnt P1 = BRep_Tool::Pnt(v1);
323 gp_Pnt P2 = BRep_Tool::Pnt(v3), P3 = BRep_Tool::Pnt(v4);
324 if (P1.Distance(P2) < P1.Distance(P3)) {
325 shape2 = v3;
326 gp_Ax2 ax2 (P1, gp_Dir (P2.XYZ() - P1.XYZ()));
327 aplane = new Geom_Plane (P1,ax2.XDirection());
328 }
329 else {
330 shape2 = v4;
331 gp_Ax2 ax2 (P1, gp_Dir (P3.XYZ() - P1.XYZ()));
332 aplane = new Geom_Plane (P1,ax2.XDirection());
333 }
334 }
335 else {
336 if (!isedgeface) {
337 NullifyAIS(anAIS);
338 return;
339 }
340 }
341 }
342
343 // Update de l'AIS
344 Handle(AIS_LengthDimension) ais;
345 Standard_Boolean SaveDrw = Standard_False;
346 Handle(AIS_Drawer) aDrawer;
347
348 if (!anAIS.IsNull()) {
349 ais = Handle(AIS_LengthDimension)::DownCast(anAIS);
350 }
351
352 if (ais.IsNull()) {
353 if (is2vertices) { //addition 2
354 gp_Pnt P1 = BRep_Tool::Pnt( TopoDS::Vertex(shape1) );
355 gp_Pnt P2 = BRep_Tool::Pnt( TopoDS::Vertex(shape2) );
356 gp_Pnt P3(P1.Y()-1., P2.X()+1., 0.);
357 GC_MakePlane mkPlane(P1, P2, P3);
358 ais = new AIS_LengthDimension (shape1, shape2, mkPlane.Value(), val1,txt);
359 }
360 else if (isface) {
361 ais = new AIS_LengthDimension (GetFace(shape1),GetFace(shape2),val1,txt);
362 }
363 else if (isedgeface) {
364 ais = new AIS_LengthDimension (GetFace(shape1),GetEdge(shape2),val1,txt);
365 }
366 else {
367 ais = new AIS_LengthDimension (shape1,shape2,aplane,val1,txt);
368 }
369 if( SaveDrw ) ais->SetAttributes(aDrawer);
370 }
371 else {
372 if (isface) {
373 ais->SetFirstShape (GetFace(shape1));
374 ais->SetSecondShape (GetFace(shape2));
375 }
376 else {
377 ais->SetFirstShape (shape1);
378 ais->SetSecondShape (shape2);
379 }
380 if (is2vertices) { //addition 3
381 gp_Pnt P1 = BRep_Tool::Pnt( TopoDS::Vertex(shape1) );
382 gp_Pnt P2 = BRep_Tool::Pnt( TopoDS::Vertex(shape2) );
383 gp_Pnt P3(P1.Y()-1., P2.X()+1., 0.);
384 GC_MakePlane mkPlane(P1, P2, P3);
385 ais->SetPlane( mkPlane.Value() );
386 }
387
388 ais->SetValue (val1);
389 ais->SetText (txt);
390 }
391
392 if (is_planar) {
393 Standard_Integer extShape (0);
394#ifndef BUC60846
395 FindExternalShape (aConst,extShape);
396#endif
397 ais->SetPlane (aplane);
398 ais->SetTypeOfDist (typedist);
399 ais->SetExtShape (extShape);
400 }
401 anAIS = ais;
402}
403
404//=======================================================================
405//function : ComputePerpendicular
406//purpose :
407//=======================================================================
408void TPrsStd_ConstraintTools::ComputePerpendicular(const Handle(TDataXtd_Constraint)& aConst,
409 Handle(AIS_InteractiveObject)& anAIS)
410{
411 Standard_Integer nbgeom = aConst->NbGeometries();
412 if (nbgeom < 2) {
413#ifdef DEB
414 cout << "TPrsStd_ConstraintTools::ComputePerpendicular: at leat two constraintes are needed" << endl;
415#endif
416 NullifyAIS(anAIS);
417 return;
418 }
419
420 TopoDS_Shape shape1,shape2 ;
421 Handle(Geom_Geometry) ageom3;
422 Standard_Boolean is_planar(aConst->IsPlanar());
423
424 if (is_planar) GetShapesAndGeom(aConst,shape1,shape2,ageom3);
425 else GetTwoShapes(aConst,shape1,shape2);
426 if (shape1.IsNull() || shape2.IsNull()) {
427#ifdef DEB
428 cout << "TPrsStd_ConstraintTools::ComputePerpendicular : null shape" << endl;
429#endif
430 NullifyAIS(anAIS);
431 return;
432 }
433 GetGoodShape(shape1);
434 GetGoodShape(shape2);
435 // Update de l'AIS
436 Handle(AIS_PerpendicularRelation) ais;
437 if (anAIS.IsNull()) ais = new AIS_PerpendicularRelation(shape1,shape2);
438 else {
439 ais = Handle(AIS_PerpendicularRelation)::DownCast(anAIS);
440 if (ais.IsNull()) {
441 ais = new AIS_PerpendicularRelation(shape1,shape2);
442 }
443 else {
444 ais->SetFirstShape(shape1);
445 ais->SetSecondShape(shape2);
446 }
447 }
448
449 if (is_planar) {
450 Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom3);
451 if (aplane.IsNull()) {
452#ifdef DEB
453 cout << "TPrsStd_ConstraintTools::ComputePerpendicular: nul plane" << endl;
454#endif
455 NullifyAIS(anAIS);
456 return;
457 }
458 ais->SetPlane(aplane);
459 }
460 anAIS = ais;
461}
462
463//=======================================================================
464//function : ComputeParallel
465//purpose :
466//=======================================================================
467void TPrsStd_ConstraintTools::ComputeParallel(const Handle(TDataXtd_Constraint)& aConst,
468 Handle(AIS_InteractiveObject)& anAIS)
469{
470 Standard_Integer nbgeom = aConst->NbGeometries();
471 if (nbgeom < 2) {
472#ifdef DEB
473 cout << "TPrsStd_ConstraintTools::ComputeParallel: at least 2 constraintes are needed" << endl;
474#endif
475 NullifyAIS(anAIS);
476 return;
477 }
478
479 if (!aConst->IsPlanar()) {
480#ifdef DEB
481 cout << "TPrsStd_ConstraintTools::ComputeParallel: must be a planar constraint" << endl;
482#endif
483 NullifyAIS(anAIS);
484 return;
485 }
486
487 TopoDS_Shape shape1,shape2 ;
488 Handle(Geom_Geometry) ageom3;
489
490 GetShapesAndGeom(aConst,shape1,shape2,ageom3);
491 if (shape1.IsNull() || shape2.IsNull()) {
492#ifdef DEB
493 cout << "TPrsStd_ConstraintTools::ComputeParallel : null shape" << endl;
494#endif
495 NullifyAIS(anAIS);
496 return;
497 }
498 Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom3);
499 if (aplane.IsNull()) {
500#ifdef DEB
501 cout << "TPrsStd_ConstraintTools::ComputeParallel: nul plane" << endl;
502#endif
503 NullifyAIS(anAIS);
504 return;
505 }
506 // Update de l'AIS
507 GetGoodShape(shape1);
508 GetGoodShape(shape2);
509 Handle(AIS_ParallelRelation) ais;
510 if (anAIS.IsNull()) ais = new AIS_ParallelRelation(shape1,shape2,aplane);
511 else {
512 ais = Handle(AIS_ParallelRelation)::DownCast(anAIS);
513 if (ais.IsNull()) {
514 ais = new AIS_ParallelRelation(shape1,shape2,aplane);
515 }
516 else {
517 ais->SetFirstShape(shape1);
518 ais->SetSecondShape(shape2);
519 ais->SetPlane(aplane);
520 }
521 }
522 anAIS = ais;
523}
524//=======================================================================
525//function : ComputeSymmetry
526//purpose :
527//=======================================================================
528void TPrsStd_ConstraintTools::ComputeSymmetry(const Handle(TDataXtd_Constraint)& aConst,
529 Handle(AIS_InteractiveObject)& anAIS)
530{
531 Standard_Integer nbgeom = aConst->NbGeometries();
532 if (nbgeom < 3) {
533#ifdef DEB
534 cout << "TPrsStd_ConstraintTools::ComputeSymmetry: at least 3 constraintes are needed" << endl;
535#endif
536 NullifyAIS(anAIS);
537 return;
538 }
539
540 Standard_Boolean is_planar(aConst->IsPlanar());
541 if (!is_planar) {
542#ifdef DEB
543 cout << "TPrsStd_ConstraintTools::ComputeSymmetry: must be a planar constraint" << endl;
544#endif
545 NullifyAIS(anAIS);
546 return;
547 }
548
549 TopoDS_Shape shape1,shape2,shape3 ;
550 Handle(Geom_Geometry) ageom3;
551 GetShapesAndGeom(aConst,shape1,shape2,shape3,ageom3);
552
553 if (shape1.IsNull() || shape2.IsNull() || shape3.IsNull()) {
554#ifdef DEB
555 cout << "TPrsStd_ConstraintTools::ComputeSymmetry : null shape" << endl;
556#endif
557 NullifyAIS(anAIS);
558 return;
559 }
560 GetGoodShape(shape1);
561 GetGoodShape(shape2);
562 GetGoodShape(shape3);
563 Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom3);
564 if (aplane.IsNull()) {
565#ifdef DEB
566 cout << "TPrsStd_ConstraintTools::ComputeSymmetry: null plane" << endl;
567#endif
568 NullifyAIS(anAIS);
569 return;
570 }
571 // Update de l'AIS
572 Handle(AIS_SymmetricRelation) ais;
573 if (anAIS.IsNull()) ais = new AIS_SymmetricRelation(shape3,shape1,shape2,aplane);
574 else {
575 ais = Handle(AIS_SymmetricRelation)::DownCast(anAIS);
576 if (ais.IsNull()) {
577 ais = new AIS_SymmetricRelation(shape3,shape1,shape2,aplane);
578 }
579 else {
580 ais->SetFirstShape(shape1);
581 ais->SetSecondShape(shape2);
582 ais->SetPlane(aplane);
583 ais->SetTool(shape3);
584 }
585 }
586 anAIS = ais;
587}
588
589//=======================================================================
590//function : ComputeMidPoint
591//purpose :
592//=======================================================================
593void TPrsStd_ConstraintTools::ComputeMidPoint(const Handle(TDataXtd_Constraint)& aConst,
594 Handle(AIS_InteractiveObject)& anAIS)
595{
596 Standard_Integer nbgeom = aConst->NbGeometries();
597 if (nbgeom < 3)
598 {
599#ifdef DEB
600 cout << "TPrsStd_ConstraintTools::ComputeSymmetry: at least 3 constraints are needed" << endl;
601#endif
602 NullifyAIS(anAIS);
603 return;
604 }
605
606 Standard_Boolean is_planar(aConst->IsPlanar());
607 if ( !is_planar )
608 {
609#ifdef DEB
610 cout << "TPrsStd_ConstraintTools::ComputeSymmetry: must be a planar constraint" << endl;
611#endif
612 NullifyAIS(anAIS);
613 return;
614 }
615
616 TopoDS_Shape shape1,shape2,shape3;
617 Handle(Geom_Geometry) ageom3;
618 GetShapesAndGeom(aConst,shape1,shape2,shape3,ageom3);
619
620 if (shape1.IsNull() || shape2.IsNull() || shape3.IsNull())
621 {
622#ifdef DEB
623 cout << "TPrsStd_ConstraintTools::ComputeSymmetry : null shape" << endl;
624#endif
625 NullifyAIS(anAIS);
626 return;
627 }
628 GetGoodShape(shape1);
629 GetGoodShape(shape2);
630 GetGoodShape(shape3);
631
632 Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom3);
633 if (aplane.IsNull())
634 {
635#ifdef DEB
636 cout << "TPrsStd_ConstraintTools::ComputeSymmetry: null plane" << endl;
637#endif
638 NullifyAIS(anAIS);
639 return;
640 }
641
642 // Update de l'AIS
643 Handle(AIS_MidPointRelation) ais;
644 if ( anAIS.IsNull() ) ais = new AIS_MidPointRelation(shape3,shape1,shape2,aplane);
645 else
646 {
647 ais = Handle(AIS_MidPointRelation)::DownCast(anAIS);
648 if (ais.IsNull())
649 {
650 ais = new AIS_MidPointRelation(shape3,shape1,shape2,aplane);
651 }
652 else
653 {
654 ais->SetFirstShape(shape1);
655 ais->SetSecondShape(shape2);
656 ais->SetPlane(aplane);
657 ais->SetTool(shape3);
658 }
659 }
660 anAIS = ais;
661}
662
663//=======================================================================
664//function : ComputeTangent
665//purpose :
666//=======================================================================
667void TPrsStd_ConstraintTools::ComputeTangent (const Handle(TDataXtd_Constraint)& aConst,
668 Handle(AIS_InteractiveObject)& anAIS)
669{
670 Standard_Integer nbgeom = aConst->NbGeometries();
671 if (nbgeom < 2) {
672#ifdef DEB
673 cout << "TPrsStd_ConstraintTools::ComputeTangent: at leat two constraintes are needed" << endl;
674#endif
675 NullifyAIS(anAIS);
676 return;
677 }
678 if (!aConst->IsPlanar()) {
679#ifdef DEB
680 cout << "TPrsStd_ConstraintTools::ComputeTangent: must be a planar constraint" << endl;
681#endif
682 NullifyAIS(anAIS);
683 return;
684 }
685 TopoDS_Shape shape1,shape2 ;
686 Handle(Geom_Geometry) ageom3;
687
688 GetShapesAndGeom(aConst,shape1,shape2,ageom3);
689 if (shape1.IsNull() || shape2.IsNull()) {
690#ifdef DEB
691 cout << "TPrsStd_ConstraintTools::ComputeTangent : null shape" << endl;
692#endif
693 NullifyAIS(anAIS);
694 return;
695 }
696 GetGoodShape(shape1);
697 GetGoodShape(shape2);
698 Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom3);
699 if (aplane.IsNull()) {
700#ifdef DEB
701 cout << "TPrsStd_ConstraintTools::ComputeTangent: nul plane" << endl;
702#endif
703 NullifyAIS(anAIS);
704 return;
705 }
706 // Update de l'AIS
707 Handle(AIS_TangentRelation) ais;
708 if (anAIS.IsNull())
709 {
710 ais = new AIS_TangentRelation(shape1,shape2,aplane);
711 ais->SetArrowSize(10000000); // jfa 9/10/2000
712 }
713 else
714 {
715 ais = Handle(AIS_TangentRelation)::DownCast(anAIS);
716 if (ais.IsNull())
717 {
718 ais = new AIS_TangentRelation(shape1,shape2,aplane);
719 ais->SetArrowSize(10000000); // jfa 9/10/2000
720 }
721 else
722 {
723 ais->SetFirstShape(shape1);
724 ais->SetSecondShape(shape2);
725 ais->SetPlane(aplane);
726 ais->SetArrowSize(10000000); // jfa 9/10/2000
727 }
728 }
729 anAIS = ais;
730}
731
732//=======================================================================
733//function : ComputeAngleForOneFace
734//purpose : computes AngleDimension for one-conical-face case
735//=======================================================================
736void TPrsStd_ConstraintTools::ComputeAngleForOneFace (const Handle(TDataXtd_Constraint)& aConst,
737 Handle(AIS_InteractiveObject)& anAIS)
738{
739
740 TopoDS_Shape shape;
741 Handle(Geom_Geometry) ageom3;
742
743 GetOneShape( aConst, shape );
744 if (shape.IsNull() ) {
745#ifdef DEB
746 cout << "TPrsStd_ConstraintTools::ComputeAngleForOneFace : null shape" << endl;
747#endif
748 NullifyAIS(anAIS);
749 return;
750 }
751
752 Standard_Real val1;
753 TCollection_ExtendedString txt;
754 TPrsStd_ConstraintTools::ComputeTextAndValue (aConst,val1,txt,Standard_True);
755
756// Unused :
757#ifdef DEB
758 Standard_Boolean isface(shape.ShapeType()==TopAbs_FACE);
759#endif
760
761 Handle(AIS_AngleDimension) ais;
762 TopoDS_Face face;
763 if (!anAIS.IsNull()) {
764 ais = Handle(AIS_AngleDimension)::DownCast(anAIS);
765 if(ais.IsNull()) {
766 face = TopoDS::Face( shape );
767 ais = new AIS_AngleDimension ( face, val1, txt);
768 }
769 else {
770 ais->SetConeFace(TopoDS::Face( shape ));
771 ais->SetValue(val1);
772 ais->SetText(txt);
773 }
774 }
775 else {
776 face = TopoDS::Face( shape );
777 ais = new AIS_AngleDimension ( face, val1, txt);
778 }
779
780// Unused :
781#ifdef DEB
782 Standard_Integer ExtShape(0);
783#endif
784
785 anAIS = ais;
786}
787
788//====================================================================
789static Standard_Boolean CheckIsShapeCompound(TopoDS_Shape& shape, TopoDS_Face& aFace)
790{
791 if (shape.ShapeType() == TopAbs_COMPOUND) {
792 TopTools_IndexedMapOfShape aFaceMap;
793 TopExp::MapShapes(shape, TopAbs_FACE, aFaceMap);
794 for(Standard_Integer i = 1;i <= aFaceMap.Extent();i++)
795 {
796 aFace = TopoDS::Face(aFaceMap.FindKey(i));
797 if(!aFace.IsNull()) {
798 shape = aFace;
799 return (Standard_True);
800 }
801 }
802 }
803#ifdef DEB
804 cout << "TPrsStd::Compute angle : Shape is not Compound or is Null" <<endl;
805#endif
806 return (Standard_False);
807}
808//=======================================================================
809//function : ComputeAngle
810//purpose :
811//=======================================================================
812void TPrsStd_ConstraintTools::ComputeAngle (const Handle(TDataXtd_Constraint)& aConst,
813 Handle(AIS_InteractiveObject)& anAIS)
814{
815 Standard_Integer nbgeom = aConst->NbGeometries();
816 if (nbgeom < 2) {
817 if( nbgeom == 1 ) { ComputeAngleForOneFace( aConst, anAIS ); return; }
818#ifdef DEB
819 cout << "TPrsStd_ConstraintTools::ComputeAngle: at least 2 constraints are needed" << endl;
820#endif
821 NullifyAIS(anAIS);
822 return;
823 }
824
825 TopoDS_Shape shape1,shape2 ;
826 Handle(Geom_Geometry) ageom3;
827
828 GetShapesAndGeom (aConst,shape1,shape2,ageom3);
829 if (shape1.IsNull() || shape2.IsNull()) {
830#ifdef DEB
831 cout << "TPrsStd_ConstraintTools::ComputeAngle : null shape" << endl;
832#endif
833 NullifyAIS(anAIS);
834 return;
835 }
836
837 Standard_Boolean isCurvilinear = Standard_False;
838 if (ageom3.IsNull()) {
839 // on essaie de le calculer
840
841 TopoDS_Face aFace;
842 if (shape1.ShapeType() == TopAbs_WIRE) {
843 BRepBuilderAPI_MakeFace MkF (TopoDS::Wire(shape1),Standard_True);
844 if (MkF.IsDone()) {
845 aFace = MkF.Face();
846 shape1 = aFace;
847 }
848 }
849 else
850 if (shape1.ShapeType() == TopAbs_FACE)
851 aFace = TopoDS::Face(shape1);
852 else
853 if(!CheckIsShapeCompound(shape1, aFace)) {
854#ifdef DEB
855 cout << "Compute angle : Geom type = " << shape1.ShapeType()
856 << " non traite"<<endl;
857#endif
858 NullifyAIS(anAIS);
859 return;
860 }
861
862 gp_Ax1 anax1aFace1;
863 gp_Pln aPlnaFace1;
864
865 BRepAdaptor_Surface aSurfaFace (aFace);
866 GeomAbs_SurfaceType aTypeaFace = aSurfaFace.GetType();
867 if (aTypeaFace == GeomAbs_Plane) {
868 aPlnaFace1 = aSurfaFace.Plane();
869 anax1aFace1 = aPlnaFace1.Axis(); // Normale au plan
870 } else if (aTypeaFace == GeomAbs_Cylinder) {
871 gp_Cylinder aCylaFace = aSurfaFace.Cylinder();
872 anax1aFace1 = aCylaFace.Axis();
873 } else if (aTypeaFace == GeomAbs_Cone) {
874 gp_Cone aCone = aSurfaFace.Cone();
875 anax1aFace1 = aCone.Axis();
876 } else if (aTypeaFace == GeomAbs_Torus) {
877 gp_Torus aTore = aSurfaFace.Torus();
878 anax1aFace1 = aTore.Axis();
879 } else {
880#ifdef DEB
881 cout<<"Compute angle"<<aTypeaFace<<" non traite"<<endl;
882#endif
883 NullifyAIS(anAIS);
884 return;
885 }
886
887 gp_Ax1 anax1aFace2;
888 gp_Pln aPlnaFace2;
889 if (shape2.ShapeType() == TopAbs_WIRE) {
890 BRepBuilderAPI_MakeFace MkF (TopoDS::Wire(shape2),Standard_True);
891 if (MkF.IsDone()) {
892 aFace = MkF.Face();
893 shape2 = aFace;
894 }
895 }
896 else
897 if (shape2.ShapeType() == TopAbs_FACE)
898 aFace = TopoDS::Face(shape2);
899 else
900 if(!CheckIsShapeCompound(shape2, aFace)) {
901#ifdef DEB
902 cout << "Compute angle : Geom type = " << shape2.ShapeType()
903 << " non traite"<<endl;
904#endif
905 NullifyAIS(anAIS);
906 return;
907 }
908
909 aSurfaFace.Initialize(aFace);
910 aTypeaFace = aSurfaFace.GetType();
911 if (aTypeaFace == GeomAbs_Plane) {
912 aPlnaFace2 = aSurfaFace.Plane();
913 anax1aFace2 = aPlnaFace2.Axis(); // Normale au plan
914 } else if (aTypeaFace == GeomAbs_Cylinder) {
915 gp_Cylinder aCylaFace = aSurfaFace.Cylinder();
916 anax1aFace2 = aCylaFace.Axis();
917 } else if (aTypeaFace == GeomAbs_Cone) {
918 gp_Cone aCone = aSurfaFace.Cone();
919 anax1aFace2 = aCone.Axis();
920 } else if (aTypeaFace == GeomAbs_Torus) {
921 gp_Torus aTore = aSurfaFace.Torus();
922 anax1aFace2 = aTore.Axis();
923 } else {
924#ifdef DEB
925 cout << "Compute angle " << aTypeaFace << " non traite"<<endl;
926#endif
927 NullifyAIS(anAIS);
928 return;
929 }
930
931 if (aTypeaFace==GeomAbs_Plane) {
932 if (!anax1aFace1.IsParallel(anax1aFace2, Precision::Angular())) {
933
934 IntAna_QuadQuadGeo IntersectPlane (aPlnaFace1, aPlnaFace2, Precision::Angular(), Precision::Angular());
935 if (IntersectPlane.IsDone() &&
936 (IntersectPlane.TypeInter() != IntAna_Empty)) {
937 gp_Lin aLine = IntersectPlane.Line(1);
938 Handle(Geom_Line) computedgeom3 = new Geom_Line (aLine);
939 ageom3 = computedgeom3;
940 } else {
941#ifdef DEB
942 cout<<"Compute angle insertection of planes failed"<<endl;
943#endif
944 NullifyAIS(anAIS);
945 return;
946 }
947 } else {
948
949#ifdef DEB
950 cout<<"Compute angle faces are //"<<endl;
951#endif
952 NullifyAIS(anAIS);
953 return;
954 }
955 } else {
956 // Curvilinear faces...
957 isCurvilinear = Standard_True;
958 }
959 } // endif (ageom3.IsNull())
960
961
962 Standard_Boolean isplan(Standard_False);
963
964 if (!isCurvilinear) {
965 if (ageom3->IsKind(STANDARD_TYPE(Geom_Plane))) isplan = Standard_True;
966 else if (ageom3->IsKind(STANDARD_TYPE(Geom_Line))) isplan = Standard_False;
967 else {
968#ifdef DEB
969 cout << "TPrsStd_ConstraintTools::ComputeAngle: unknown 3rd arg " << endl;
970#endif
971 NullifyAIS(anAIS);
972 return;
973 }
974 }
975 Standard_Real val1;
976 TCollection_ExtendedString txt;
977 ComputeTextAndValue (aConst,val1,txt,Standard_True);
978
979 Standard_Boolean toCreate (Standard_True);
980 Standard_Boolean isface(shape1.ShapeType()==TopAbs_FACE);
981
982 Handle(AIS_AngleDimension) ais;
983 if (!anAIS.IsNull()) {
984 ais = Handle(AIS_AngleDimension)::DownCast(anAIS);
985 if( ais.IsNull() ) {
986 toCreate = Standard_True;
987 }
988 else toCreate = Standard_False;
989 }
990
991 Standard_Integer ExtShape(0);
992 if (toCreate) {
993 // Creation de l'AIS
994 if (isplan) {
995 if(!isface) {
996 FindExternalShape(aConst,ExtShape);
997 GetGoodShape(shape1);
998 GetGoodShape(shape2);
999 ais = new AIS_AngleDimension (TopoDS::Edge(shape1),
1000 TopoDS::Edge(shape2),
1001 (Handle(Geom_Plane)&) ageom3,val1,txt);
1002 ais->SetExtShape(ExtShape);
1003 }
1004 }
1005 else {
1006 if (isCurvilinear) {
1007 ais = new AIS_AngleDimension (TopoDS::Face(shape1),
1008 TopoDS::Face(shape2),val1,txt);
1009 }
1010 else if (isface) {
1011 ais = new AIS_AngleDimension (TopoDS::Face(shape1),
1012 TopoDS::Face(shape2),
1013 ((Handle(Geom_Line)&) ageom3)->Position(),val1,txt);
1014 }
1015 }
1016 }
1017 else {
1018 // Update de l'AIS
1019 if (isplan) {
1020 GetGoodShape(shape1);
1021 GetGoodShape(shape2);
1022 }
1023 ais->SetFirstShape(shape1);
1024 ais->SetSecondShape(shape2);
1025 ais->SetValue(val1);
1026 ais->SetText(txt);
1027 if (isplan)
1028 ais->SetPlane ((Handle(Geom_Plane)&) ageom3);
1029 else if (!isCurvilinear)
1030 ais->SetAxis (((Handle(Geom_Line)&) ageom3)->Position());
1031 }
1032 anAIS = ais;
1033}
1034
1035
1036//=======================================================================
1037//function : ComputeConcentric
1038//purpose :
1039//=======================================================================
1040void TPrsStd_ConstraintTools::ComputeConcentric(const Handle(TDataXtd_Constraint)& aConst,
1041 Handle(AIS_InteractiveObject)& anAIS)
1042{
1043 Standard_Integer nbgeom = aConst->NbGeometries();
1044 if (nbgeom < 2) {
1045 Standard_ProgramError::Raise ("TPrsStd_ConstraintTools::ComputeConcentric: at least 2 constraintes are needed");
1046 }
1047 if (!aConst->IsPlanar()) {
1048#ifdef DEB
1049 cout << "TPrsStd_ConstraintTools::ComputeConcentric: must be a planar constraint" << endl;
1050#endif
1051 NullifyAIS(anAIS);
1052 return;
1053 }
1054 TopoDS_Shape shape1,shape2 ;
1055 Handle(Geom_Geometry) ageom3;
1056
1057 GetShapesAndGeom(aConst,shape1,shape2,ageom3);
1058 if (shape1.IsNull() || shape2.IsNull()) {
1059#ifdef DEB
1060 cout << "TPrsStd_ConstraintTools::ComputeConcentric : null shape" << endl;
1061#endif
1062 NullifyAIS(anAIS);
1063 return;
1064 }
1065
1066 GetGoodShape(shape1);
1067 GetGoodShape(shape2);
1068
1069//ota : to allow concentric constraint display between vertex and edge
1070 if (shape1.ShapeType() != TopAbs_EDGE && shape2.ShapeType() != TopAbs_EDGE) {
1071#ifdef DEB
1072 cout << "TPrsStd_ConstraintTools::ComputeConcentric: concentric between two vertexes : NOT DISPLAYED" << endl;;
1073#endif
1074 NullifyAIS(anAIS);
1075 return;
1076 }
1077
1078 Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom3);
1079 if (aplane.IsNull()) {
1080#ifdef DEB
1081 cout << "TPrsStd_ConstraintTools::ComputeConcentric: nul plane" << endl;;
1082#endif
1083 NullifyAIS(anAIS);
1084 return;
1085 }
1086 // Update de l'AIS
1087 Handle(AIS_ConcentricRelation) ais;
1088 if (!anAIS.IsNull()) {
1089 ais = Handle(AIS_ConcentricRelation)::DownCast(anAIS);
1090 if (ais.IsNull()) {
1091 ais = new AIS_ConcentricRelation (shape1,shape2,aplane);
1092 }
1093 else {
1094 ais->SetFirstShape(shape1);
1095 ais->SetSecondShape(shape2);
1096 ais->SetPlane(aplane);
1097 }
1098 }
1099 else {
1100 ais = new AIS_ConcentricRelation (shape1,shape2,aplane);
1101 }
1102
1103 anAIS = ais;
1104}
1105
1106//=======================================================================
1107//function : ComputeRadius
1108//purpose :
1109//=======================================================================
1110void TPrsStd_ConstraintTools::ComputeRadius (const Handle(TDataXtd_Constraint)& aConst,
1111 Handle(AIS_InteractiveObject)& anAIS)
1112{
1113 Standard_Integer nbgeom = aConst->NbGeometries();
1114 if (nbgeom < 1) {
1115#ifdef DEB
1116 cout << "TPrsStd_ConstraintTools::ComputeRadius: at least one constrainte is needed" << endl;
1117#endif
1118 NullifyAIS(anAIS);
1119 return;
1120 }
1121
1122 TopoDS_Shape shape1 ;
1123 GetOneShape (aConst,shape1);
1124 if (shape1.IsNull()) {
1125#ifdef DEB
1126 cout << "TPrsStd_ConstraintTools::ComputeRadius: null shape" << endl;
1127#endif
1128 NullifyAIS(anAIS);
1129 return;
1130 }
1131
1132 // POP on teste si ce n'est pas un compound
1133 if (shape1.ShapeType()==TopAbs_COMPOUND ||
1134 shape1.ShapeType()==TopAbs_COMPSOLID ||
1135 shape1.ShapeType()==TopAbs_SOLID ||
1136 shape1.ShapeType()==TopAbs_SHELL ) {
1137#ifdef DEB
1138 cout << "TPrsStd_ConstraintTools::ComputeRadius: not good shape" << endl;
1139#endif
1140 NullifyAIS(anAIS);
1141 return;
1142 }
1143
1144 if (IsFace(shape1))
1145 shape1 = GetFace(shape1);
1146
1147 Standard_Real val1;
1148 TCollection_ExtendedString txt;
1149 ComputeTextAndValue(aConst,val1,txt,Standard_False);
1150
1151 // Update de l'AIS
1152// Unused :
1153#ifdef DEB
1154 Standard_Boolean tocreate = Standard_True;
1155#endif
1156 Standard_Boolean isplanar(aConst->IsPlanar());
1157 if (isplanar) GetGoodShape(shape1);
1158
1159 Handle(AIS_RadiusDimension) ais;
1160 if (!anAIS.IsNull()) {
1161 ais = Handle(AIS_RadiusDimension)::DownCast(anAIS);
1162 if (ais.IsNull()) {
1163 ais = new AIS_RadiusDimension (shape1,val1,txt);
1164 }
1165 else {
1166 ais->SetValue(val1);
1167 ais->SetFirstShape(shape1);
1168 ais->SetText(txt);
1169 }
1170 }
1171 else ais = new AIS_RadiusDimension (shape1,val1,txt);
1172
1173 if (isplanar) {
1174 Handle(Geom_Geometry) ageom2;
1175 GetGeom(aConst,ageom2);
1176 Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom2);
1177 if (aplane.IsNull()) {
1178#ifdef DEB
1179 cout << "TPrsStd_ConstraintTools::ComputeRadius: nul plane" << endl;
1180#endif
1181 NullifyAIS(anAIS);
1182 return;
1183 }
1184 ais->SetPlane(aplane);
1185 ais->SetDrawFromCenter(Standard_False);
1186 }
1187 anAIS = ais;
1188}
1189// ota -- begin --
1190//=======================================================================
1191//function : ComputeMinRadius
1192//purpose :
1193//=======================================================================
1194void TPrsStd_ConstraintTools::ComputeMinRadius (const Handle(TDataXtd_Constraint)& aConst,
1195 Handle(AIS_InteractiveObject)& anAIS)
1196{
1197 Standard_Integer nbgeom = aConst->NbGeometries();
1198 if (nbgeom < 1) {
1199#ifdef DEB
1200 cout << "TPrsStd_ConstraintTools::ComputeMinRadius: at least one constrainte is needed" << endl;
1201#endif
1202 NullifyAIS(anAIS);
1203 return;
1204 }
1205
1206 TopoDS_Shape shape1 ;
1207 GetOneShape (aConst,shape1);
1208 if (shape1.IsNull()) {
1209#ifdef DEB
1210 cout << "TPrsStd_ConstraintTools::ComputeMinradius: null shape" << endl;
1211#endif
1212 NullifyAIS(anAIS);
1213 return;
1214 }
1215
1216 // POP on teste si ce n'est pas un compound
1217 if (shape1.ShapeType()==TopAbs_COMPOUND ||
1218 shape1.ShapeType()==TopAbs_COMPSOLID ||
1219 shape1.ShapeType()==TopAbs_SOLID ||
1220 shape1.ShapeType()==TopAbs_SHELL ) {
1221#ifdef DEB
1222 cout << "TPrsStd_ConstraintTools::ComputeMinRadius: not good shape" << endl;
1223#endif
1224 NullifyAIS(anAIS);
1225 return;
1226 }
1227
1228 if (IsFace(shape1))
1229 shape1 = GetFace(shape1);
1230
1231 Standard_Real val1;
1232 TCollection_ExtendedString txt;
1233 ComputeTextAndValue(aConst,val1,txt,Standard_False);
1234
1235 // Update de l'AIS
1236// Unused :
1237#ifdef DEB
1238 Standard_Boolean tocreate = Standard_True;
1239#endif
1240 Standard_Boolean isplanar(aConst->IsPlanar());
1241 if (isplanar) GetGoodShape(shape1);
1242
1243 Handle(AIS_MinRadiusDimension) ais;
1244 if (!anAIS.IsNull()) {
1245 ais = Handle(AIS_MinRadiusDimension)::DownCast(anAIS);
1246 if (ais.IsNull()) {
1247 ais = new AIS_MinRadiusDimension (shape1,val1,txt);
1248 }
1249 else {
1250 ais->SetValue(val1);
1251 ais->SetFirstShape(shape1);
1252 ais->SetText(txt);
1253 }
1254 }
1255 else ais = new AIS_MinRadiusDimension (shape1,val1,txt);
1256
1257 if (isplanar) {
1258 Handle(Geom_Geometry) ageom2;
1259 GetGeom(aConst,ageom2);
1260 Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom2);
1261 if (aplane.IsNull()) {
1262#ifdef DEB
1263 cout << "TPrsStd_ConstraintTools::ComputeMinRadius: nul plane" << endl;
1264#endif
1265 NullifyAIS(anAIS);
1266 return;
1267 }
1268 ais->SetPlane(aplane);
1269 }
1270 anAIS = ais;
1271}
1272
1273//=======================================================================
1274//function : ComputeMaxRadius
1275//purpose :
1276//=======================================================================
1277void TPrsStd_ConstraintTools::ComputeMaxRadius (const Handle(TDataXtd_Constraint)& aConst,
1278 Handle(AIS_InteractiveObject)& anAIS)
1279{
1280 Standard_Integer nbgeom = aConst->NbGeometries();
1281 if (nbgeom < 1) {
1282#ifdef DEB
1283 cout << "TPrsStd_ConstraintTools::ComputeMaxRadius: at least one constrainte is needed" << endl;
1284#endif
1285 NullifyAIS(anAIS);
1286 return;
1287 }
1288
1289 TopoDS_Shape shape1 ;
1290 GetOneShape (aConst,shape1);
1291 if (shape1.IsNull()) {
1292#ifdef DEB
1293 cout << "TPrsStd_ConstraintTools::ComputeMaxradius: null shape" << endl;
1294#endif
1295 NullifyAIS(anAIS);
1296 return;
1297 }
1298
1299 // POP on teste si ce n'est pas un compound
1300 if (shape1.ShapeType()==TopAbs_COMPOUND ||
1301 shape1.ShapeType()==TopAbs_COMPSOLID ||
1302 shape1.ShapeType()==TopAbs_SOLID ||
1303 shape1.ShapeType()==TopAbs_SHELL ) {
1304#ifdef DEB
1305 cout << "TPrsStd_ConstraintTools::ComputeMaxRadius: not good shape" << endl;
1306#endif
1307 NullifyAIS(anAIS);
1308 return;
1309 }
1310
1311 if (IsFace(shape1))
1312 shape1 = GetFace(shape1);
1313
1314 Standard_Real val1;
1315 TCollection_ExtendedString txt;
1316 ComputeTextAndValue(aConst,val1,txt,Standard_False);
1317
1318 // Update de l'AIS
1319// Unused :
1320#ifdef DEB
1321 Standard_Boolean tocreate = Standard_True;
1322#endif
1323 Standard_Boolean isplanar(aConst->IsPlanar());
1324 if (isplanar) GetGoodShape(shape1);
1325
1326 Handle(AIS_MaxRadiusDimension) ais;
1327 if (!anAIS.IsNull()) {
1328 ais = Handle(AIS_MaxRadiusDimension)::DownCast(anAIS);
1329 if (ais.IsNull()) {
1330 ais = new AIS_MaxRadiusDimension (shape1,val1,txt);
1331 }
1332 else {
1333 ais->SetValue(val1);
1334 ais->SetFirstShape(shape1);
1335 ais->SetText(txt);
1336 }
1337 }
1338 else ais = new AIS_MaxRadiusDimension (shape1,val1,txt);
1339
1340 if (isplanar) {
1341 Handle(Geom_Geometry) ageom2;
1342 GetGeom(aConst,ageom2);
1343 Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom2);
1344 if (aplane.IsNull()) {
1345#ifdef DEB
1346 cout << "TPrsStd_ConstraintTools::ComputeMaxRadius: nul plane" << endl;
1347#endif
1348 NullifyAIS(anAIS);
1349 return;
1350 }
1351 ais->SetPlane(aplane);
1352 }
1353 anAIS = ais;
1354}
1355
1356//=======================================================================
1357//function : ComputeEqualDistance
1358//purpose :
1359//=======================================================================
1360void TPrsStd_ConstraintTools::ComputeEqualDistance(const Handle(TDataXtd_Constraint)& aConst,
1361 Handle(AIS_InteractiveObject)& anAIS)
1362{
1363 Standard_Integer nbgeom = aConst->NbGeometries();
1364 if (nbgeom < 4) {
1365 cout << "TPrsStd_ConstraintTools::ComputeEqual: at least four geometries are needed" << endl;;
1366 NullifyAIS(anAIS);
1367 return;
1368 }
1369 TopoDS_Shape aShape1, aShape2, aShape3, aShape4;
1370 Handle(Geom_Geometry) aGeom;
1371 GetShapesAndGeom(aConst, aShape1, aShape2, aShape3, aShape4, aGeom);
1372 if (aShape1.IsNull()||aShape2.IsNull()||
1373 aShape3.IsNull()||aShape4.IsNull()) {
1374#ifdef DEB
1375 cout << "TPrsStd_ConstraintTools::ComputeEqualDistance : null shape" << endl;
1376#endif
1377 NullifyAIS(anAIS);
1378 return;
1379 }
1380
1381 GetGoodShape(aShape1);
1382 GetGoodShape(aShape2);
1383 GetGoodShape(aShape3);
1384 GetGoodShape(aShape4);
1385
1386 if (!CheckShapesPair(aShape1, aShape2) ||
1387 !CheckShapesPair(aShape3, aShape4)){
1388#ifdef DEB
1389 cout << "TPrsStd_ConstraintTools::ComputeEqualDistance : at least one pair of shapes is incorrect"<<endl;
1390#endif
1391 NullifyAIS(anAIS);
1392 return;
1393 }
1394
1395 //Get the plane
1396 Standard_Boolean IsPlanar(aConst->IsPlanar());
1397 Handle(Geom_Plane) aPlane ;
1398 if(IsPlanar) aPlane = Handle(Geom_Plane)::DownCast(aGeom) ;
1399
1400 if (!IsPlanar || aPlane.IsNull()) {
1401 //create the plane
1402#ifdef DEB
1403 cout<< "The constraint plane is not assigned "<< endl;
1404#endif
1405 NullifyAIS(anAIS);
1406 return;
1407 }
1408
1409 //Update AIS
1410 Handle(AIS_EqualDistanceRelation) ais;
1411 if (!anAIS.IsNull()) {
1412 {
1413 ais = Handle(AIS_EqualDistanceRelation)::DownCast(anAIS);
1414
1415 if (ais.IsNull())
1416 ais = new AIS_EqualDistanceRelation(aShape1, aShape2, aShape3, aShape4, aPlane);
1417
1418 else {
1419 ais->SetFirstShape(aShape1);
1420 ais->SetSecondShape(aShape2);
1421 ais->SetShape3(aShape3);
1422 ais->SetShape4(aShape4);
1423 ais->SetPlane(aPlane);
1424 }
1425 }
1426 }
1427 else ais = new AIS_EqualDistanceRelation(aShape1, aShape2, aShape3, aShape4, aPlane);
1428
1429 anAIS = ais;
1430
1431 return;
1432}
1433
1434//======================================================================
1435// function : CheckShapesPair
1436// purpose : checks the types of two shapes.
1437// If the types aShape1 and aShape2 are EDGE - EDGE,
1438// or EDGE - VERTEX,
1439// or VERTEX - VERTEX,
1440// or CIRCLE - CIRCLE,
1441// or CIRCLE - VERTEX,
1442// then function returns TRUE, otherwise FALSE.
1443//======================================================================
1444static Standard_Boolean CheckShapesPair(const TopoDS_Shape& aShape1,
1445 const TopoDS_Shape& aShape2)
1446{
1447 //Check whether the shapes form a correct pair.
1448 if (aShape1.ShapeType() == TopAbs_EDGE && aShape2.ShapeType() == TopAbs_EDGE)
1449 {
1450 BRepAdaptor_Curve aCurve1(TopoDS::Edge(aShape1));
1451 BRepAdaptor_Curve aCurve2(TopoDS::Edge(aShape2));
1452 if (aCurve1.GetType() == GeomAbs_Line && aCurve2.GetType() == GeomAbs_Line)
1453 { //Are lines parallel ?
1454 gp_Dir aDir1 = aCurve1.Line().Direction();
1455 gp_Dir aDir2 = aCurve2.Line().Direction();
1456 if (!(aDir1.IsParallel(aDir2, Precision::Confusion()))) {
1457#ifdef DEB
1458 cout << " Lines are not parallel"<<endl;
1459#endif
1460 return Standard_False;
1461 }
1462 }
1463 else if (aCurve1.GetType() == GeomAbs_Circle && aCurve2.GetType() == GeomAbs_Circle)
1464 {
1465 gp_Pnt aCntr1 = aCurve1.Circle().Location(); //get the circle center
1466 gp_Pnt aCntr2 = aCurve2.Circle().Location(); //get the circle center
1467 if (!aCntr1.IsEqual(aCntr2,Precision::Confusion())){
1468#ifdef DEB
1469 cout << " Circles are not concentric"<<endl;
1470#endif
1471 return Standard_False;
1472 }
1473 }
1474 else {
1475#ifdef DEB
1476 cout << "Incorrect pair of curves "<<endl;
1477#endif
1478 return Standard_False;
1479 }
1480 }
1481 else if ( aShape1.ShapeType() != TopAbs_VERTEX || aShape2.ShapeType() != TopAbs_VERTEX)
1482 {
1483 gp_Pnt aPnt;
1484 BRepAdaptor_Curve aCurve;
1485 if ( aShape1.ShapeType() == TopAbs_VERTEX) {
1486 aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape1));
1487 aCurve.Initialize(TopoDS::Edge(aShape2));
1488 }
1489 else {
1490 aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape2));
1491 aCurve.Initialize(TopoDS::Edge(aShape1));
1492 }
1493 if ( aCurve.GetType() == GeomAbs_Circle)
1494 {
1495 gp_Pnt aCntr = aCurve.Circle().Location();
1496 if (!aCntr.IsEqual(aPnt, Precision::Confusion())){
1497#ifdef DEB
1498 cout << " The point doesn't coincide with the circle center"<<endl;
1499#endif
1500 return Standard_False;
1501 }
1502 }
1503 }
1504 return Standard_True;
1505}
1506
1507//=======================================================================
1508//function : ComputeEqualRadius
1509//purpose :
1510//=======================================================================
1511void TPrsStd_ConstraintTools::ComputeEqualRadius(const Handle(TDataXtd_Constraint)& aConst,
1512 Handle(AIS_InteractiveObject)& anAIS)
1513{
1514 Standard_Integer nbgeom = aConst->NbGeometries();
1515 if (nbgeom < 2) {
1516#ifdef DEB
1517 cout << "TPrsStd_ConstraintTools::ComputeEqualRadius: at least two geometries are needed" << endl;;
1518#endif
1519 NullifyAIS(anAIS);
1520 return;
1521 }
1522 TopoDS_Shape shape1, shape2;
1523 Handle(Geom_Geometry) ageom3;
1524
1525 GetShapesAndGeom(aConst, shape1, shape2, ageom3);
1526 if (shape1.IsNull()||shape2.IsNull()) {
1527#ifdef DEB
1528 cout << "TPrsStd_ConstraintTools::ComputeEqualRadius : null shape" << endl;
1529#endif
1530 NullifyAIS(anAIS);
1531 return;
1532 }
1533
1534 // Update AIS
1535 Standard_Boolean IsPlanar(aConst->IsPlanar());
1536
1537 GetGoodShape(shape1);
1538 GetGoodShape(shape2);
1539 const TopoDS_Edge edge1 = TopoDS::Edge(shape1);
1540 const TopoDS_Edge edge2 = TopoDS::Edge(shape2);
1541 Handle(Geom_Plane) aplane ;
1542
1543 if (IsPlanar) aplane = Handle(Geom_Plane)::DownCast(ageom3) ;
1544
1545 if (!IsPlanar || aplane.IsNull()) {
1546 // check are the planes of edge1 and edge2 coincident
1547 BRepAdaptor_Curve aCurve( edge1 );
1548 Handle( Geom_Curve ) aProjCurve = aCurve.Curve().Curve();
1549 gp_Circ aCircle = (Handle( Geom_Circle )::DownCast( aProjCurve ))->Circ();
1550 gp_Ax3 anAx31(aCircle.Position()); //get the circle axis
1551 // get the circle plane
1552 Handle(Geom_Plane) aPlane1 = new Geom_Plane (anAx31);
1553
1554 aCurve.Initialize(edge2);
1555 aProjCurve = aCurve.Curve().Curve();
1556 aCircle = (Handle( Geom_Circle )::DownCast( aProjCurve ))->Circ();
1557 gp_Ax3 anAx32(aCircle.Position()); //get the circle axis
1558 // get the circle plane
1559 Handle(Geom_Plane) aPlane2 = new Geom_Plane (anAx32);
1560
1561 Standard_Real A, B, C ,D1, D2;
1562 aPlane1->Coefficients(A, B, C, D1);//Get normalized coefficients
1563 aPlane2->Coefficients(A, B, C, D2);//Get normalized coefficients
1564 const gp_Dir& aDir1 = anAx31.Direction();
1565 const gp_Dir& aDir2 = anAx32.Direction();
1566
1567 if(Abs(D1 - D2) < Precision::Confusion() &&
1568 aDir1.IsParallel(aDir2, Precision::Confusion()))
1569 aplane = aPlane2;
1570 else {
1571#ifdef DEB
1572 cout << "TPrsStd_ConstraintTools::ComputeRadiusRelation: nul plane" << endl;
1573#endif
1574 NullifyAIS(anAIS);
1575 return;
1576 }
1577 }
1578 Handle(AIS_EqualRadiusRelation) ais;
1579 if (!anAIS.IsNull()) {
1580 ais = Handle(AIS_EqualRadiusRelation)::DownCast(anAIS);
1581
1582 if (ais.IsNull()) {
1583 ais = new AIS_EqualRadiusRelation(edge1, edge2, aplane);
1584 }
1585 else {
1586 ais->SetFirstShape(shape1);
1587 ais->SetSecondShape(shape2);
1588 ais->SetPlane(aplane);
1589 }
1590 }
1591 else {
1592 ais = new AIS_EqualRadiusRelation(edge1, edge2, aplane);
1593 }
1594
1595 anAIS = ais;
1596}
1597//ota -- end --
1598
1599//=======================================================================
1600//function : ComputeDiameter
1601//purpose :
1602//=======================================================================
1603void TPrsStd_ConstraintTools::ComputeDiameter(const Handle(TDataXtd_Constraint)& aConst,
1604 Handle(AIS_InteractiveObject)& anAIS)
1605{
1606 Standard_Integer nbgeom = aConst->NbGeometries();
1607 if (nbgeom < 1) {
1608#ifdef DEB
1609 cout << "TPrsStd_ConstraintTools::ComputeDiameter: at least one constrainte is needed" << endl;;
1610#endif
1611 NullifyAIS(anAIS);
1612 return;
1613 }
1614 TopoDS_Shape shape1 ;
1615
1616 GetOneShape(aConst,shape1);
1617 if (shape1.IsNull()) {
1618#ifdef DEB
1619 cout << "TPrsStd_ConstraintTools::ComputeDiameter : null shape" << endl;
1620#endif
1621 NullifyAIS(anAIS);
1622 return;
1623 }
1624 Standard_Real val1;
1625 TCollection_ExtendedString txt;
1626 ComputeTextAndValue(aConst,val1,txt,Standard_False);
1627
1628 // Update de l'AIS
1629 Standard_Boolean IsPlanar(aConst->IsPlanar());
1630 if (IsPlanar) GetGoodShape(shape1);
1631 Handle(AIS_DiameterDimension) ais;
1632 if (!anAIS.IsNull()) {
1633 ais = Handle(AIS_DiameterDimension)::DownCast(anAIS);
1634 if (ais.IsNull()) {
1635 ais = new AIS_DiameterDimension (shape1,val1,txt);
1636 }
1637 else {
1638 ais->SetFirstShape(shape1);
1639 ais->SetValue(val1);
1640 ais->SetText(txt);
1641 }
1642 }
1643 else ais = new AIS_DiameterDimension (shape1,val1,txt);
1644
1645 if (IsPlanar) {
1646 Handle(Geom_Geometry) ageom2;
1647 GetGeom(aConst,ageom2);
1648 Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom2);
1649 if (aplane.IsNull()) {
1650#ifdef DEB
1651 cout << "TPrsStd_ConstraintTools::ComputeDiameter: nul plane" << endl;
1652#endif
1653 NullifyAIS(anAIS);
1654 return;
1655 }
1656 ais->SetPlane(aplane);
1657 }
1658 anAIS = ais;
1659}
1660
1661
1662//=======================================================================
1663//function : ComputeFix
1664//purpose :
1665//=======================================================================
1666void TPrsStd_ConstraintTools::ComputeFix(const Handle(TDataXtd_Constraint)& aConst,
1667 Handle(AIS_InteractiveObject)& anAIS)
1668{
1669 Standard_Integer nbgeom = aConst->NbGeometries();
1670 if (nbgeom < 1) {
1671#ifdef DEB
1672 cout << "TPrsStd_ConstraintTools::ComputeFix: at least one constrainte is needed" << endl;;
1673#endif
1674 NullifyAIS(anAIS);
1675 return;
1676 }
1677 if (!aConst->IsPlanar()) {
1678#ifdef DEB
1679 cout << "TPrsStd_ConstraintTools::ComputeFix: must be a planar constraint" << endl;;
1680#endif
1681 NullifyAIS(anAIS);
1682 return;
1683 }
1684
1685 TopoDS_Shape shape1 ;
1686 Handle(Geom_Geometry) ageom2;
1687
1688 GetOneShape(aConst,shape1);
1689 if (shape1.IsNull()) {
1690#ifdef DEB
1691 cout << "TPrsStd_ConstraintTools::ComputeFix : null shape" << endl;
1692#endif
1693 NullifyAIS(anAIS);
1694 return;
1695 }
1696 GetGoodShape(shape1);
1697 GetGeom(aConst,ageom2);
1698 Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom2);
1699 if (aplane.IsNull()) {
1700#ifdef DEB
1701 cout << "TPrsStd_ConstraintTools::ComputeFix: nul plane" << endl;
1702#endif
1703 NullifyAIS(anAIS);
1704 return;
1705 }
1706 // Update de l'AIS
1707 Handle(AIS_FixRelation) ais;
1708 if (!anAIS.IsNull()) {
1709 ais = Handle(AIS_FixRelation)::DownCast(anAIS);
1710 if (ais.IsNull()) {
1711 ais = new AIS_FixRelation (shape1,aplane);
1712 }
1713 else {
1714 ais->SetFirstShape(shape1);
1715 ais->SetPlane(aplane);
1716 }
1717 }
1718 else ais = new AIS_FixRelation (shape1,aplane);
1719
1720 anAIS = ais;
1721}
1722
1723//=======================================================================
1724//function : ComputeOffset
1725//purpose :
1726//=======================================================================
1727void TPrsStd_ConstraintTools::ComputeOffset (const Handle(TDataXtd_Constraint)& aConst,
1728 Handle(AIS_InteractiveObject)& anAIS)
1729{
1730 // Get plane for planar constraint
1731 Standard_Boolean is_planar (aConst->IsPlanar());
1732 Handle(Geom_Plane) aplane;
1733 if (is_planar) {
1734 GetGeom (aConst,aplane);
1735 if (aplane.IsNull()) {
1736#ifdef DEB
1737 cout << "TPrsStd_ConstraintTools::ComputeOffset: null plane" << endl;
1738#endif
1739 NullifyAIS(anAIS);
1740 return;
1741 }
1742 }
1743
1744 // Get shapes
1745 TopoDS_Shape S1, S2;
1746 Standard_Integer nbgeom = aConst->NbGeometries();
1747 if (nbgeom == 1) {
1748 Handle(TNaming_NamedShape) ageom1 = aConst->GetGeometry(1);
1749 // c'est une shape qui contient les faces generees par les faces d'origines
1750 TNaming_Iterator It (ageom1);
1751 if (It.More()) {
1752 S1 = It.OldShape();
1753 S2 = It.NewShape();
1754 }
1755 }
1756 else
1757 if (nbgeom == 2) {
1758 // Get geometry of the constraint
1759 GetTwoShapes (aConst,S1,S2);
1760 }
1761
1762 if (S1.IsNull() || S2.IsNull()) {
1763#ifdef DEB
1764 cout << "TPrsStd_ConstraintTools::ComputeOffset: null shape" << endl;
1765#endif
1766 NullifyAIS(anAIS);
1767 return;
1768 }
1769
1770
1771 Standard_Real val1;
1772 TCollection_ExtendedString txt;
1773 Handle(AIS_LengthDimension) ais;
1774 //Handle(AIS_Drawer) aDrawer;
1775 Standard_Boolean NotNull = Standard_False;
1776
1777 if (nbgeom == 1) {
1778
1779 ComputeTextAndValue (aConst,val1,txt,Standard_False);
1780
1781 if (!anAIS.IsNull()) {
1782 ais = Handle(AIS_LengthDimension)::DownCast(anAIS);
1783 NotNull = Standard_True;
1784 }
1785
1786 if (S1.ShapeType() == TopAbs_FACE && S2.ShapeType() == TopAbs_FACE) {
1787 if (ais.IsNull()) {
1788 ais = new AIS_LengthDimension (TopoDS::Face(S1),TopoDS::Face(S2),
1789 val1,txt);
1790 }
1791 else {
1792 ais->SetFirstShape(S1);
1793 ais->SetSecondShape(S2);
1794 ais->SetValue(val1);
1795 ais->SetText(txt);
1796 }
1797
1798 if (is_planar) ais->SetPlane (aplane);
1799 anAIS = ais;
1800 return;
1801 }
1802 else
1803 if (S1.ShapeType() == TopAbs_EDGE && S2.ShapeType() == TopAbs_EDGE) {
1804 // Find a plane for the dimension
1805 TopoDS_Edge OE = TopoDS::Edge(S1);
1806 BRepAdaptor_Curve CURVE(OE);
1807 if (CURVE.GetType() == GeomAbs_Line) {
1808 // Works only with line !!
1809//#ifndef DEB
1810 Handle_Geom_Geometry aGeomGeometry = CURVE.Curve().Curve()->Transformed(CURVE.Trsf()) ;
1811 gp_Lin OLin = ((Handle(Geom_Line)&) aGeomGeometry)->Lin();
1812//#else
1813// gp_Lin OLin = ((Handle(Geom_Line)&) CURVE.Curve().Curve()->Transformed(CURVE.Trsf()))->Lin();
1814//#endif
1815 TopoDS_Edge NE = TopoDS::Edge(S2);
1816 CURVE.Initialize (NE);
1817//#ifndef DEB
1818 aGeomGeometry = CURVE.Curve().Curve()->Transformed(CURVE.Trsf()) ;
1819 gp_Lin NLin = ((Handle(Geom_Line)&)aGeomGeometry)->Lin();
1820//#else
1821// gp_Lin NLin = ((Handle(Geom_Line)&) CURVE.Curve().Curve()->Transformed(CURVE.Trsf()))->Lin();
1822//#endif
1823 gp_Dir TDir (NLin.Location().XYZ() - OLin.Location().XYZ());
1824 aplane = new Geom_Plane (NLin.Location(),NLin.Direction()^TDir);
1825
1826 if (ais.IsNull()) {
1827 ais = new AIS_LengthDimension (S1,S2,aplane,val1,txt);
1828 }
1829 else {
1830 ais->SetFirstShape(S1);
1831 ais->SetSecondShape(S2);
1832 ais->SetValue(val1);
1833 ais->SetText(txt);
1834 ais->SetPlane(aplane);
1835 }
1836 anAIS = ais;
1837 return;
1838 }
1839 else
1840 if (CURVE.GetType() == GeomAbs_Circle) {
1841//#ifndef DEB
1842 Handle_Geom_Geometry aGeomGeometry = CURVE.Curve().Curve()->Transformed(CURVE.Trsf()) ;
1843 gp_Ax1 ax = ((Handle(Geom_Circle)&) aGeomGeometry)->Circ().Axis();
1844//#else
1845// gp_Ax1 ax = ((Handle(Geom_Circle)&) CURVE.Curve().Curve()->Transformed(CURVE.Trsf()))->Circ().Axis();
1846//#endif
1847 aplane = new Geom_Plane (ax.Location(),ax.Direction());
1848 is_planar = Standard_True;
1849 }
1850 }
1851 }
1852
1853
1854 if (!is_planar) {
1855 if (S1.ShapeType() == TopAbs_COMPOUND &&
1856 S2.ShapeType() == TopAbs_COMPOUND) {
1857 // Resultat d'un offset - on reconstruit un wire pour determiner un plan
1858 TopoDS_Wire w1;
1859 BRep_Builder B;
1860 B.MakeWire (w1);
1861 TopExp_Explorer exp (S1,TopAbs_EDGE);
1862 for (;exp.More();exp.Next())
1863 B.Add (w1,exp.Current());
1864
1865 BRepBuilderAPI_MakeFace MkF (w1,Standard_True);
1866 if (MkF.IsDone()) {
1867//#ifndef DEB
1868 Handle_Geom_Surface aGeomSurface = BRep_Tool::Surface(MkF.Face());
1869 aplane = (Handle(Geom_Plane)&) aGeomSurface ;
1870//#else
1871// aplane = ((Handle(Geom_Plane)&) BRep_Tool::Surface(MkF.Face()));
1872//#endif
1873 is_planar = Standard_True;
1874 }
1875 }
1876 }
1877
1878 if (is_planar) {
1879 ComputeTextAndValue (aConst,val1,txt,Standard_False);
1880 TopExp_Explorer EXP1 (S1,TopAbs_VERTEX);
1881 S1 = EXP1.Current();
1882 gp_Pnt P = BRep_Tool::Pnt(TopoDS::Vertex(S1));
1883
1884 TopoDS_Vertex nearest;
1885 Standard_Real dist(RealLast());
1886
1887 for (TopExp_Explorer EXP2(S2,TopAbs_VERTEX); EXP2.More(); EXP2.Next()) {
1888 const TopoDS_Vertex& current = TopoDS::Vertex(EXP2.Current());
1889 gp_Pnt curpnt = BRep_Tool::Pnt(current);
1890 Standard_Real curdist = P.SquareDistance(curpnt);
1891 if (curdist < dist) {
1892 nearest= current;
1893 dist = curdist;
1894 }
1895 }
1896 S2 = nearest;
1897 if( !anAIS.IsNull() ) NotNull = Standard_True;
1898 ais = Handle(AIS_LengthDimension)::DownCast(anAIS);
1899 if (ais.IsNull()) {
1900 ais = new AIS_LengthDimension (S1,S2,aplane,val1,txt);
1901 }
1902 else {
1903 ais->SetFirstShape (S1);
1904 ais->SetSecondShape (S2);
1905 ais->SetValue(val1);
1906 ais->SetText(txt);
1907 ais->SetPlane(aplane);
1908 }
1909 anAIS = ais;
1910 return;
1911 }
1912
1913#ifdef DEB
1914 cout << "TPrsStd_ConstraintTools::ComputeOffset: Case not implemented" << endl;
1915#endif
1916 NullifyAIS(anAIS);
1917}
1918
1919
1920//=======================================================================
1921//function : ComputePlacement
1922//purpose :
1923//=======================================================================
1924void TPrsStd_ConstraintTools::ComputePlacement
1925(const Handle(TDataXtd_Constraint)& aConst,
1926 Handle(AIS_InteractiveObject)& anAIS)
1927{
1928 Standard_Integer nbgeom = aConst->NbGeometries();
1929 if (nbgeom < 2)
1930 Standard_ProgramError::Raise
1931 ("TPrsStd_ConstraintTools::ComputePlacement: at leat two constraints are needed");
1932
1933 TopoDS_Shape shape1,shape2 ;
1934 GetTwoShapes(aConst,shape1,shape2);
1935 if (shape1.IsNull() || shape2.IsNull()) {
1936#ifdef DEB
1937 cout << "TPrsStd_ConstraintTools::ComputePlacement: nul shape" << endl;
1938#endif
1939 NullifyAIS(anAIS);
1940 return;
1941 }
1942
1943 Standard_Real val1=0.0;
1944 TCollection_ExtendedString txt= " ";
1945 if (aConst->IsDimension()) {
1946 ComputeTextAndValue(aConst,val1,txt,Standard_False);
1947 }
1948 // Update de l'AIS
1949 Handle(AIS_OffsetDimension) ais;
1950 if (anAIS.IsNull()) {
1951 ais = new AIS_OffsetDimension(GetFace(shape1),GetFace(shape2),val1,txt);
1952 ais->SetArrowSize(val1/20.);
1953 } else {
1954 ais = Handle(AIS_OffsetDimension)::DownCast(anAIS);
1955 if (ais.IsNull()) {
1956 ais = new AIS_OffsetDimension(GetFace(shape1),GetFace(shape2),val1,txt);
1957 ais->SetArrowSize(val1/20.);
1958 } else {
1959 ais->SetFirstShape(GetFace(shape1));
1960 ais->SetSecondShape(GetFace(shape2));
1961 ais->SetValue(val1);
1962 ais->SetText(txt);
1963 ais->SetArrowSize(val1/20.);
1964 }
1965 }
1966 if (GetFace(shape1).IsNull() || GetFace(shape2).IsNull()) ais.Nullify();
1967 anAIS = ais;
1968}
1969
1970//=======================================================================
1971//function : ComputeOthers
1972//purpose :
1973//=======================================================================
1974void TPrsStd_ConstraintTools::ComputeOthers
1975(const Handle(TDataXtd_Constraint)& aConst,
1976 Handle(AIS_InteractiveObject)& anAIS)
1977{
1978}
1979
1980//=======================================================================
1981//function : GetOneShape
1982//purpose :
1983//=======================================================================
1984void TPrsStd_ConstraintTools::GetOneShape
1985(const Handle(TDataXtd_Constraint)& aConst,
1986 TopoDS_Shape& aShape)
1987{
1988 const Handle(TNaming_NamedShape)& ageom1 = aConst->GetGeometry(1);
1989 if (!ageom1.IsNull()) aShape = TNaming_Tool::CurrentShape(ageom1);
1990}
1991
1992//=======================================================================
1993//function : GetTwoShapes
1994//purpose :
1995//=======================================================================
1996void TPrsStd_ConstraintTools::GetTwoShapes
1997(const Handle(TDataXtd_Constraint)& aConst,
1998 TopoDS_Shape& aShape1,
1999 TopoDS_Shape& aShape2)
2000{
2001 const Handle(TNaming_NamedShape)& ageom1 = aConst->GetGeometry(1);
2002 if (!ageom1.IsNull()) aShape1 = TNaming_Tool::CurrentShape(aConst->GetGeometry(1));
2003 const Handle(TNaming_NamedShape)& ageom2 = aConst->GetGeometry(2);
2004 if (!ageom2.IsNull()) aShape2 = TNaming_Tool::CurrentShape(aConst->GetGeometry(2));
2005}
2006
2007//=======================================================================
2008//function : GetShapesAndGeom
2009//purpose :
2010//=======================================================================
2011void TPrsStd_ConstraintTools::GetShapesAndGeom
2012(const Handle(TDataXtd_Constraint)& aConst,
2013 TopoDS_Shape& aShape1,
2014 TopoDS_Shape& aShape2,
2015 Handle(Geom_Geometry)& aGeom)
2016{
2017 GetTwoShapes(aConst,aShape1,aShape2);
2018 GetGeom(aConst,aGeom);
2019}
2020
2021//=======================================================================
2022//function : GetShapesAndGeom
2023//purpose :
2024//=======================================================================
2025void TPrsStd_ConstraintTools::GetShapesAndGeom
2026(const Handle(TDataXtd_Constraint)& aConst,
2027 TopoDS_Shape& aShape1,
2028 TopoDS_Shape& aShape2,
2029 TopoDS_Shape& aShape3,
2030 Handle(Geom_Geometry)& aGeom)
2031{
2032 GetTwoShapes(aConst,aShape1,aShape2);
2033 const Handle(TNaming_NamedShape)& ageom3 = aConst->GetGeometry(3);//ota: GetGeometry(2) was
2034 if (!ageom3.IsNull()) aShape3 = TNaming_Tool::CurrentShape(aConst->GetGeometry(3));
2035 GetGeom(aConst,aGeom);
2036}
2037
2038//=======================================================================
2039//function : GetShapesAndGeom
2040//purpose :
2041//=======================================================================
2042void TPrsStd_ConstraintTools::GetShapesAndGeom
2043 (const Handle(TDataXtd_Constraint)& aConst,
2044 TopoDS_Shape& aShape1,
2045 TopoDS_Shape& aShape2,
2046 TopoDS_Shape& aShape3,
2047 TopoDS_Shape& aShape4,
2048 Handle(Geom_Geometry)& aGeom)
2049{
2050 GetTwoShapes(aConst,aShape1, aShape2 );
2051 const Handle(TNaming_NamedShape)& ageom3 = aConst->GetGeometry(3);
2052 if (!ageom3.IsNull()) aShape3 = TNaming_Tool::CurrentShape(aConst->GetGeometry(3));
2053 const Handle(TNaming_NamedShape)& ageom4 = aConst->GetGeometry(4);
2054 if (!ageom4.IsNull()) aShape4 = TNaming_Tool::CurrentShape(aConst->GetGeometry(4));
2055 GetGeom(aConst,aGeom);
2056}
2057
2058//=======================================================================
2059//function : ComputeCoincident
2060//purpose :
2061//=======================================================================
2062void TPrsStd_ConstraintTools::ComputeCoincident(const Handle(TDataXtd_Constraint)& aConst,
2063 Handle(AIS_InteractiveObject)& anAIS)
2064{
2065 Standard_Integer nbgeom = aConst->NbGeometries();
2066 if (nbgeom < 2) {
2067#ifdef DEB
2068 cout << "TPrsStd_ConstraintTools::ComputeCoincident: at leat two constraintes are needed" << endl;
2069#endif
2070 NullifyAIS(anAIS);
2071 return;
2072 }
2073
2074 if (!aConst->IsPlanar()) {
2075#ifdef DEB
2076 cout << "TPrsStd_ConstraintTools::ComputeCoincident: must be a planar constraint" << endl;
2077#endif
2078 anAIS.Nullify() ;
2079 return;
2080 }
2081
2082 TopoDS_Shape shape1,shape2 ;
2083 Handle(Geom_Plane) aplane;
2084 GetShapesAndGeom(aConst,shape1,shape2,aplane);
2085 if (shape1.IsNull() || shape2.IsNull()) {
2086#ifdef DEB
2087 cout << "TPrsStd_ConstraintTools::ComputeCoincident: nul shape" << endl;
2088#endif
2089 NullifyAIS(anAIS);
2090 return;
2091 }
2092
2093 GetGoodShape(shape1);
2094 GetGoodShape(shape2);
2095 if (aplane.IsNull()) {
2096#ifdef DEB
2097 cout << "TPrsStd_ConstraintTools::ComputeCoincident: nul plane" << endl;
2098#endif
2099 NullifyAIS(anAIS);
2100 return;
2101 }
2102
2103 // Update de l'AIS
2104 Handle(AIS_IdenticRelation) ais;
2105 if (anAIS.IsNull()) ais = new AIS_IdenticRelation(shape1,shape2,aplane);
2106 else {
2107 ais = Handle(AIS_IdenticRelation)::DownCast(anAIS);
2108 if (ais.IsNull()) {
2109 ais = new AIS_IdenticRelation(shape1,shape2,aplane);
2110 }
2111 else {
2112 ais->SetFirstShape(shape1);
2113 ais->SetSecondShape(shape2);
2114 ais->SetPlane(aplane);
2115 }
2116 }
2117 anAIS = ais;
2118}
2119
2120//=======================================================================
2121//function : ComputeRound
2122//purpose :
2123//=======================================================================
2124void TPrsStd_ConstraintTools::ComputeRound(const Handle(TDataXtd_Constraint)& aConst,
2125 Handle(AIS_InteractiveObject)& anAIS)
2126{
2127 Standard_Integer nbgeom = aConst->NbGeometries();
2128 if (nbgeom < 1) {
2129#ifdef DEB
2130 cout << "TPrsStd_ConstraintTools::ComputeRound: at leat one geometry is needed" << endl;
2131#endif
2132 NullifyAIS(anAIS);
2133 return;
2134 }
2135 TopoDS_Shape shape1;
2136 GetOneShape (aConst,shape1);
2137 if (shape1.IsNull()) {
2138#ifdef DEB
2139 cout << "TPrsStd_ConstraintTools::ComputePlacement: nul shape" << endl;
2140#endif
2141 NullifyAIS(anAIS);
2142 return;
2143 }
2144
2145 Standard_Real val1;
2146 TCollection_ExtendedString txt;
2147 ComputeTextAndValue(aConst,val1,txt,Standard_False);
2148
2149 // Update de l'AIS
2150 Handle(AIS_RadiusDimension) ais;
2151
2152 {
2153 try {
2154 OCC_CATCH_SIGNALS
2155 if (anAIS.IsNull()) ais =
2156 new AIS_RadiusDimension(shape1,val1,txt);
2157 else {
2158 ais = Handle(AIS_RadiusDimension)::DownCast(anAIS);
2159 if (ais.IsNull()) {
2160 ais = new AIS_RadiusDimension(shape1,val1,txt);
2161 }
2162 else {
2163 ais->SetValue(val1);
2164 ais->SetText(txt);
2165 ais->SetFirstShape(shape1);
2166 }
2167 }
2168 }
2169 catch(Standard_Failure) {
2170 ais.Nullify();
2171 }
2172 }
2173 anAIS = ais;
2174}
2175
2176//=======================================================================
2177//function : GetGeom
2178//purpose :
2179//=======================================================================
2180void TPrsStd_ConstraintTools::GetGeom(const Handle(TDataXtd_Constraint)& aConst,
2181 Handle(Geom_Geometry)& aGeom)
2182{
2183 Handle(TNaming_NamedShape) atgeom = aConst->GetPlane();
2184 if (atgeom.IsNull()) {
2185#ifdef DEB
2186 cout<<"TPrsStd_ConstraintTools::GetGeom : aConst->GetPlane().IsNull()"<<endl;
2187#endif
2188 return;
2189 }
2190 gp_Pln aplane;
2191 gp_Lin anaxis;
2192 gp_Pnt apoint;
2193
2194 TDF_Label label = atgeom->Label();
2195
2196 Handle(TNaming_NamedShape) NS;
2197 if(label.FindAttribute(TNaming_NamedShape::GetID(),NS)){
2198 TopoDS_Shape s = TNaming_Tool::GetShape(NS);
2199 if(s.IsNull()) return;
2200 }
2201
2202 if (TDataXtd_Geometry::Plane(label,aplane)) aGeom = new Geom_Plane(aplane);
2203 else if (TDataXtd_Geometry::Line(label,anaxis)) aGeom = new Geom_Line(anaxis);
2204 else if (TDataXtd_Geometry::Point(label,apoint)) aGeom = new Geom_CartesianPoint(apoint);
2205#ifdef DEB
2206 else {
2207 cout << "TPrsStd_ConstraintTools::GetGeom no geom on label " << endl;
2208 }
2209#endif
2210}
2211