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