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