1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
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
20 #include <TPrsStd_ConstraintTools.ixx>
23 #include <UnitsAPI.hxx>
24 #include <TCollection_ExtendedString.hxx>
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>
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_EqualRadiusRelation.hxx>
51 #include <AIS_EqualDistanceRelation.hxx>
52 #include <AIS_MinRadiusDimension.hxx>
53 #include <AIS_MaxRadiusDimension.hxx>
56 #include <TopoDS_Edge.hxx>
57 #include <TopoDS_Shape.hxx>
58 #include <TopoDS_Face.hxx>
59 #include <TopoDS_Vertex.hxx>
61 #include <TopExp_Explorer.hxx>
63 #include <BRep_Tool.hxx>
64 #include <BRep_Builder.hxx>
65 #include <BRepBuilderAPI_MakeFace.hxx>
66 #include <BRepAdaptor_Curve.hxx>
67 #include <BRepAdaptor_Surface.hxx>
69 #include <GeomAbs_SurfaceType.hxx>
70 #include <Geom_Geometry.hxx>
71 #include <Geom_Line.hxx>
72 #include <Geom_Plane.hxx>
73 #include <Geom_CartesianPoint.hxx>
74 #include <Geom_Circle.hxx>
80 #include <gp_Cylinder.hxx>
81 #include <gp_Cone.hxx>
82 #include <gp_Torus.hxx>
83 #include <GC_MakePlane.hxx>
85 #include <Precision.hxx>
86 #include <IntAna_QuadQuadGeo.hxx>
88 #include <Standard_ProgramError.hxx>
89 #include <Standard_ErrorHandler.hxx>
91 #include <TopTools_IndexedMapOfShape.hxx>
92 #include <Prs3d_Drawer.hxx>
93 #include <AIS_Relation.hxx>
95 static Standard_Boolean CheckShapesPair(const TopoDS_Shape& , const TopoDS_Shape& ); //ota
97 //=======================================================================
98 //function : static NullifyAIS
100 //=======================================================================
101 static void NullifyAIS ( Handle(AIS_InteractiveObject)& anais)
103 if (anais.IsNull()) return;
109 //=======================================================================
110 //function : static FindExternalShape
112 //=======================================================================
113 static void FindExternalShape(const Handle(TDataXtd_Constraint)& aConst,
114 Standard_Integer& extShape)
117 const TDF_Label& L = aConst->Label();
118 if (!aConst->GetGeometry(1)->Label().IsDescendant(L)) extShape = 1;
119 else if (!aConst->GetGeometry(2)->Label().IsDescendant(L)) extShape = 2;
122 //=======================================================================
123 //function : static GetGoodShape for planar constraint
125 //=======================================================================
126 static void GetGoodShape(TopoDS_Shape& theShape)
128 switch (theShape.ShapeType())
131 case TopAbs_VERTEX: { return; }
134 TopExp_Explorer anExp (theShape,TopAbs_EDGE);
137 theShape = anExp.Current();
142 anExp.Init (theShape, TopAbs_VERTEX);
145 theShape = anExp.Current();
152 // Pour le cas ou S est un compound
153 static Standard_Boolean IsFace (const TopoDS_Shape& S)
155 Standard_Boolean findface = Standard_False;
156 TopExp_Explorer EXP (S,TopAbs_FACE);
157 if (EXP.More()) findface = Standard_True;
161 static TopoDS_Face GetFace (const TopoDS_Shape& S)
164 TopExp_Explorer EXP (S,TopAbs_FACE);
165 if (EXP.More()) F = TopoDS::Face (EXP.Current());
169 static TopoDS_Edge GetEdge (const TopoDS_Shape& S)
172 TopExp_Explorer EXP (S, TopAbs_EDGE);
173 if (EXP.More()) E = TopoDS::Edge (EXP.Current());
179 //=======================================================================
180 //Function : ComputeAndTextValue
182 //=======================================================================
183 void TPrsStd_ConstraintTools::ComputeTextAndValue(const Handle(TDataXtd_Constraint)& aConst,
185 TCollection_ExtendedString& txt,
186 const Standard_Boolean anIsAngle )
188 Standard_Real outvalue;
189 const Handle(TDataStd_Real)& VAL = aConst->GetValue();
192 outvalue = UnitsAPI::CurrentFromLS(Abs(val),"PLANE ANGLE");
195 outvalue = UnitsAPI::CurrentFromLS(val,"LENGTH");
198 sprintf(res,"%g",outvalue);
199 txt = TCollection_ExtendedString(res);
201 if (VAL->IsCaptured()) {
202 Handle(TDF_Reference) ref;
203 VAL->Label().FindAttribute(TDF_Reference::GetID(),ref);
204 Handle(TDataStd_Name) name;
205 const TDF_Label& L = ref->Get();
206 if (ref->Get().FindAttribute(TDataStd_Name::GetID(),name)) {
207 TCollection_ExtendedString fullname;
208 Handle(TDataStd_Name) Fathername;
209 if (L.Father().FindAttribute(TDataStd_Name::GetID(),Fathername)) {
210 fullname = Fathername->Get() + TCollection_ExtendedString(".") + name->Get();
212 else fullname = name->Get();
213 txt = fullname + TCollection_ExtendedString("=") + txt;
219 //=======================================================================
220 //function : UpdateOnlyValue
222 //=======================================================================
224 void TPrsStd_ConstraintTools::UpdateOnlyValue(const Handle(TDataXtd_Constraint)& aConst,
225 const Handle(AIS_InteractiveObject)& anAIS)
227 if (anAIS.IsNull()) return;
228 if (!aConst->IsDimension()) return;
230 TCollection_ExtendedString txt;
231 TPrsStd_ConstraintTools:: ComputeTextAndValue(aConst,val,txt,aConst->GetType() == TDataXtd_ANGLE);
232 Handle(AIS_Relation) rel = Handle(AIS_Relation)::DownCast(anAIS);
233 if (!rel.IsNull()) rel->SetText(txt);
237 //=======================================================================
238 //function : ComputeDistance
239 //purpose : Build an AIS_LengthDimension.
240 //=======================================================================
241 void TPrsStd_ConstraintTools::ComputeDistance (const Handle(TDataXtd_Constraint)& theConst,
242 Handle(AIS_InteractiveObject)& theAIS)
244 Standard_Integer aGeomNum = theConst->NbGeometries();
246 // Dimension is build on one or two shapes.
247 if (aGeomNum < 1 || aGeomNum > 2)
250 cout << "TPrsStd_ConstraintTools::ComputeDistance: 1 or 2 geometries are needed" << endl;
256 TopoDS_Shape aShape1, aShape2;
257 Handle(Geom_Geometry) aGeom3;
258 Standard_Boolean isPlanar (theConst->IsPlanar());
260 // Get shapes and geometry
263 GetOneShape (theConst, aShape1);
265 if (aShape1.IsNull())
268 cout << "TPrsStd_ConstraintTools::ComputeDistance : null shape" << endl;
276 GetTwoShapes (theConst, aShape1, aShape2);
278 if (aShape1.IsNull() || aShape2.IsNull())
281 cout << "TPrsStd_ConstraintTools::ComputeDistance : null shape" << endl;
288 // Get plane from constraint
289 Handle(Geom_Plane) aPlane;
292 GetGeom (theConst, aGeom3);
294 GetGoodShape (aShape1);
298 GetGoodShape (aShape2);
301 aPlane = Handle(Geom_Plane)::DownCast (aGeom3);
305 Standard_Real aValue;
306 TCollection_ExtendedString aText;
307 ComputeTextAndValue (theConst, aValue, aText,Standard_False);
309 Standard_Boolean isFaces = Standard_False;
310 Standard_Boolean isEdges = Standard_False;
311 Standard_Boolean isEdgeFace = Standard_False;
312 Standard_Boolean isVertices = Standard_False;
313 Standard_Boolean isEdge = Standard_False;
315 Standard_Boolean SaveDrw = Standard_False;
316 Handle(Prs3d_Drawer) aDrawer;
317 Handle(AIS_LengthDimension) aDim;
319 if (!theAIS.IsNull())
321 aDim = Handle(AIS_LengthDimension)::DownCast (theAIS);
324 // Check shapes for AIS dimension
327 if (aShape1.ShapeType () != TopAbs_EDGE)
330 cout << "TPrsStd_ConstraintTools::ComputeDistance : shape should be edge" << endl;
336 isEdge = Standard_True;
340 isFaces = IsFace (aShape1) && IsFace (aShape2);
342 isEdges = (aShape1.ShapeType() == TopAbs_EDGE) && (aShape2.ShapeType() == TopAbs_EDGE);
344 isEdgeFace = ((aShape1.ShapeType() == TopAbs_FACE) && (aShape2.ShapeType() == TopAbs_EDGE))
345 || ((aShape1.ShapeType() == TopAbs_EDGE) && (aShape2.ShapeType() == TopAbs_FACE));
347 isVertices = (aShape1.ShapeType() == TopAbs_VERTEX) && (aShape2.ShapeType() == TopAbs_VERTEX);
349 if (!isPlanar && !isFaces && !isEdges && !isVertices)
351 // Search suitable geometry for dimension
352 if (aShape1.ShapeType() == aShape2.ShapeType())
354 TopoDS_Vertex aV1, aV2, aV3, aV4;
355 if (aShape1.ShapeType() == TopAbs_WIRE)
357 TopExp::Vertices (TopoDS::Wire(aShape1), aV1, aV2);
358 TopExp::Vertices (TopoDS::Wire(aShape2), aV3, aV4);
361 gp_Pnt aP1 = BRep_Tool::Pnt(aV1);
362 gp_Pnt aP2 = BRep_Tool::Pnt(aV3);
363 gp_Pnt aP3 = BRep_Tool::Pnt (aV4);
364 if (aP1.Distance (aP2) < aP1.Distance (aP3))
367 gp_Ax2 ax2 (aP1, gp_Dir (aP2.XYZ() - aP1.XYZ()));
368 aPlane = new Geom_Plane (aP1, ax2.XDirection());
373 gp_Ax2 anAx2 (aP1, gp_Dir (aP3.XYZ() - aP1.XYZ()));
374 aPlane = new Geom_Plane (aP1, anAx2.XDirection());
377 else if (!isEdgeFace)
386 Standard_Boolean isCheckPlane = (aDim.IsNull() && !isFaces) || isPlanar;
387 if ((isVertices || isEdges) && !isPlanar)
389 gp_Pnt aP1, aP2, aP3;
393 aP1 = BRep_Tool::Pnt (TopoDS::Vertex (aShape1));
394 aP2 = BRep_Tool::Pnt (TopoDS::Vertex (aShape2));
395 aP3 = gp_Pnt (aP1.Y() - 1.0, aP2.X() + 1.0, 0.0);
400 TopoDS_Vertex aV1, aV2, aV3, aV4;
401 TopExp::Vertices (TopoDS::Edge(aShape1), aV1, aV2);
402 TopExp::Vertices (TopoDS::Edge(aShape2), aV3, aV4);
403 aP1 = BRep_Tool::Pnt (aV1);
404 aP2 = BRep_Tool::Pnt (aV2);
405 aP3 = BRep_Tool::Pnt (aV3);
408 GC_MakePlane aPlaneMaker (aP1, aP2, aP3);
409 if (aPlaneMaker.IsDone() && !isPlanar)
411 aPlane = aPlaneMaker.Value();
415 if (isCheckPlane && aPlane.IsNull())
418 cout << "TPrsStd_ConstraintTools::ComputeDistance : null plane" << endl;
429 aDim = new AIS_LengthDimension (GetEdge (aShape1), aPlane->Pln());
433 aDim = new AIS_LengthDimension (GetFace (aShape1), GetFace (aShape2));
437 aDim = new AIS_LengthDimension (aShape1, aShape2, aPlane->Pln());
442 aDim->SetAttributes (aDrawer);
449 aDim->SetMeasuredGeometry (GetEdge(aShape1), aPlane->Pln());
453 aDim->SetMeasuredShapes (aShape1, aShape2);
456 aDim->SetCustomValue (aValue);
459 if (!aPlane.IsNull())
461 aDim->SetCustomPlane (aPlane->Pln());
467 //=======================================================================
468 //function : ComputePerpendicular
470 //=======================================================================
471 void TPrsStd_ConstraintTools::ComputePerpendicular(const Handle(TDataXtd_Constraint)& aConst,
472 Handle(AIS_InteractiveObject)& anAIS)
474 Standard_Integer nbgeom = aConst->NbGeometries();
477 cout << "TPrsStd_ConstraintTools::ComputePerpendicular: at leat two constraintes are needed" << endl;
483 TopoDS_Shape shape1,shape2 ;
484 Handle(Geom_Geometry) ageom3;
485 Standard_Boolean is_planar(aConst->IsPlanar());
487 if (is_planar) GetShapesAndGeom(aConst,shape1,shape2,ageom3);
488 else GetTwoShapes(aConst,shape1,shape2);
489 if (shape1.IsNull() || shape2.IsNull()) {
491 cout << "TPrsStd_ConstraintTools::ComputePerpendicular : null shape" << endl;
496 GetGoodShape(shape1);
497 GetGoodShape(shape2);
499 Handle(AIS_PerpendicularRelation) ais;
500 if (anAIS.IsNull()) ais = new AIS_PerpendicularRelation(shape1,shape2);
502 ais = Handle(AIS_PerpendicularRelation)::DownCast(anAIS);
504 ais = new AIS_PerpendicularRelation(shape1,shape2);
507 ais->SetFirstShape(shape1);
508 ais->SetSecondShape(shape2);
513 Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom3);
514 if (aplane.IsNull()) {
516 cout << "TPrsStd_ConstraintTools::ComputePerpendicular: nul plane" << endl;
521 ais->SetPlane(aplane);
526 //=======================================================================
527 //function : ComputeParallel
529 //=======================================================================
530 void TPrsStd_ConstraintTools::ComputeParallel(const Handle(TDataXtd_Constraint)& aConst,
531 Handle(AIS_InteractiveObject)& anAIS)
533 Standard_Integer nbgeom = aConst->NbGeometries();
536 cout << "TPrsStd_ConstraintTools::ComputeParallel: at least 2 constraintes are needed" << endl;
542 if (!aConst->IsPlanar()) {
544 cout << "TPrsStd_ConstraintTools::ComputeParallel: must be a planar constraint" << endl;
550 TopoDS_Shape shape1,shape2 ;
551 Handle(Geom_Geometry) ageom3;
553 GetShapesAndGeom(aConst,shape1,shape2,ageom3);
554 if (shape1.IsNull() || shape2.IsNull()) {
556 cout << "TPrsStd_ConstraintTools::ComputeParallel : null shape" << endl;
561 Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom3);
562 if (aplane.IsNull()) {
564 cout << "TPrsStd_ConstraintTools::ComputeParallel: nul plane" << endl;
570 GetGoodShape(shape1);
571 GetGoodShape(shape2);
572 Handle(AIS_ParallelRelation) ais;
573 if (anAIS.IsNull()) ais = new AIS_ParallelRelation(shape1,shape2,aplane);
575 ais = Handle(AIS_ParallelRelation)::DownCast(anAIS);
577 ais = new AIS_ParallelRelation(shape1,shape2,aplane);
580 ais->SetFirstShape(shape1);
581 ais->SetSecondShape(shape2);
582 ais->SetPlane(aplane);
587 //=======================================================================
588 //function : ComputeSymmetry
590 //=======================================================================
591 void TPrsStd_ConstraintTools::ComputeSymmetry(const Handle(TDataXtd_Constraint)& aConst,
592 Handle(AIS_InteractiveObject)& anAIS)
594 Standard_Integer nbgeom = aConst->NbGeometries();
597 cout << "TPrsStd_ConstraintTools::ComputeSymmetry: at least 3 constraintes are needed" << endl;
603 Standard_Boolean is_planar(aConst->IsPlanar());
606 cout << "TPrsStd_ConstraintTools::ComputeSymmetry: must be a planar constraint" << endl;
612 TopoDS_Shape shape1,shape2,shape3 ;
613 Handle(Geom_Geometry) ageom3;
614 GetShapesAndGeom(aConst,shape1,shape2,shape3,ageom3);
616 if (shape1.IsNull() || shape2.IsNull() || shape3.IsNull()) {
618 cout << "TPrsStd_ConstraintTools::ComputeSymmetry : null shape" << endl;
623 GetGoodShape(shape1);
624 GetGoodShape(shape2);
625 GetGoodShape(shape3);
626 Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom3);
627 if (aplane.IsNull()) {
629 cout << "TPrsStd_ConstraintTools::ComputeSymmetry: null plane" << endl;
635 Handle(AIS_SymmetricRelation) ais;
636 if (anAIS.IsNull()) ais = new AIS_SymmetricRelation(shape3,shape1,shape2,aplane);
638 ais = Handle(AIS_SymmetricRelation)::DownCast(anAIS);
640 ais = new AIS_SymmetricRelation(shape3,shape1,shape2,aplane);
643 ais->SetFirstShape(shape1);
644 ais->SetSecondShape(shape2);
645 ais->SetPlane(aplane);
646 ais->SetTool(shape3);
652 //=======================================================================
653 //function : ComputeMidPoint
655 //=======================================================================
656 void TPrsStd_ConstraintTools::ComputeMidPoint(const Handle(TDataXtd_Constraint)& aConst,
657 Handle(AIS_InteractiveObject)& anAIS)
659 Standard_Integer nbgeom = aConst->NbGeometries();
663 cout << "TPrsStd_ConstraintTools::ComputeSymmetry: at least 3 constraints are needed" << endl;
669 Standard_Boolean is_planar(aConst->IsPlanar());
673 cout << "TPrsStd_ConstraintTools::ComputeSymmetry: must be a planar constraint" << endl;
679 TopoDS_Shape shape1,shape2,shape3;
680 Handle(Geom_Geometry) ageom3;
681 GetShapesAndGeom(aConst,shape1,shape2,shape3,ageom3);
683 if (shape1.IsNull() || shape2.IsNull() || shape3.IsNull())
686 cout << "TPrsStd_ConstraintTools::ComputeSymmetry : null shape" << endl;
691 GetGoodShape(shape1);
692 GetGoodShape(shape2);
693 GetGoodShape(shape3);
695 Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom3);
699 cout << "TPrsStd_ConstraintTools::ComputeSymmetry: null plane" << endl;
706 Handle(AIS_MidPointRelation) ais;
707 if ( anAIS.IsNull() ) ais = new AIS_MidPointRelation(shape3,shape1,shape2,aplane);
710 ais = Handle(AIS_MidPointRelation)::DownCast(anAIS);
713 ais = new AIS_MidPointRelation(shape3,shape1,shape2,aplane);
717 ais->SetFirstShape(shape1);
718 ais->SetSecondShape(shape2);
719 ais->SetPlane(aplane);
720 ais->SetTool(shape3);
726 //=======================================================================
727 //function : ComputeTangent
729 //=======================================================================
730 void TPrsStd_ConstraintTools::ComputeTangent (const Handle(TDataXtd_Constraint)& aConst,
731 Handle(AIS_InteractiveObject)& anAIS)
733 Standard_Integer nbgeom = aConst->NbGeometries();
736 cout << "TPrsStd_ConstraintTools::ComputeTangent: at leat two constraintes are needed" << endl;
741 if (!aConst->IsPlanar()) {
743 cout << "TPrsStd_ConstraintTools::ComputeTangent: must be a planar constraint" << endl;
748 TopoDS_Shape shape1,shape2 ;
749 Handle(Geom_Geometry) ageom3;
751 GetShapesAndGeom(aConst,shape1,shape2,ageom3);
752 if (shape1.IsNull() || shape2.IsNull()) {
754 cout << "TPrsStd_ConstraintTools::ComputeTangent : null shape" << endl;
759 GetGoodShape(shape1);
760 GetGoodShape(shape2);
761 Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom3);
762 if (aplane.IsNull()) {
764 cout << "TPrsStd_ConstraintTools::ComputeTangent: nul plane" << endl;
770 Handle(AIS_TangentRelation) ais;
773 ais = new AIS_TangentRelation(shape1,shape2,aplane);
774 ais->SetArrowSize(10000000); // jfa 9/10/2000
778 ais = Handle(AIS_TangentRelation)::DownCast(anAIS);
781 ais = new AIS_TangentRelation(shape1,shape2,aplane);
782 ais->SetArrowSize(10000000); // jfa 9/10/2000
786 ais->SetFirstShape(shape1);
787 ais->SetSecondShape(shape2);
788 ais->SetPlane(aplane);
789 ais->SetArrowSize(10000000); // jfa 9/10/2000
795 //=======================================================================
796 //function : ComputeAngleForOneFace
797 //purpose : computes AngleDimension for one-conical-face case
798 //=======================================================================
799 void TPrsStd_ConstraintTools::ComputeAngleForOneFace (const Handle(TDataXtd_Constraint)& aConst,
800 Handle(AIS_InteractiveObject)& anAIS)
804 Handle(Geom_Geometry) ageom3;
806 GetOneShape( aConst, shape );
807 if (shape.IsNull() ) {
809 cout << "TPrsStd_ConstraintTools::ComputeAngleForOneFace : null shape" << endl;
816 TCollection_ExtendedString txt;
817 TPrsStd_ConstraintTools::ComputeTextAndValue (aConst,val1,txt,Standard_True);
819 Handle(AIS_AngleDimension) ais;
821 if (!anAIS.IsNull()) {
822 ais = Handle(AIS_AngleDimension)::DownCast(anAIS);
824 face = TopoDS::Face( shape );
825 ais = new AIS_AngleDimension (face);
828 ais->SetMeasuredGeometry(TopoDS::Face( shape ));
832 face = TopoDS::Face (shape);
833 ais = new AIS_AngleDimension (face);
839 //=======================================================================
840 //function : CheckIsShapeCompound
842 //=======================================================================
844 static Standard_Boolean CheckIsShapeCompound(TopoDS_Shape& shape, TopoDS_Face& aFace)
846 if (shape.ShapeType() == TopAbs_COMPOUND) {
847 TopTools_IndexedMapOfShape aFaceMap;
848 TopExp::MapShapes(shape, TopAbs_FACE, aFaceMap);
849 for(Standard_Integer i = 1;i <= aFaceMap.Extent();i++)
851 aFace = TopoDS::Face(aFaceMap.FindKey(i));
852 if(!aFace.IsNull()) {
854 return (Standard_True);
859 cout << "TPrsStd::Compute angle : Shape is not Compound or is Null" <<endl;
861 return (Standard_False);
864 //=======================================================================
865 //function : ComputeAngle
867 //=======================================================================
869 void TPrsStd_ConstraintTools::ComputeAngle (const Handle(TDataXtd_Constraint)& aConst,
870 Handle(AIS_InteractiveObject)& anAIS)
872 Standard_Integer nbgeom = aConst->NbGeometries();
874 if( nbgeom == 1 ) { ComputeAngleForOneFace( aConst, anAIS ); return; }
876 cout << "TPrsStd_ConstraintTools::ComputeAngle: at least 2 constraints are needed" << endl;
882 TopoDS_Shape shape1,shape2 ;
883 Handle(Geom_Geometry) ageom3;
885 GetShapesAndGeom (aConst,shape1,shape2,ageom3);
886 if (shape1.IsNull() || shape2.IsNull()) {
888 cout << "TPrsStd_ConstraintTools::ComputeAngle : null shape" << endl;
894 Standard_Boolean isCurvilinear = Standard_False;
895 if (ageom3.IsNull()) {
896 // on essaie de le calculer
899 if (shape1.ShapeType() == TopAbs_WIRE) {
900 BRepBuilderAPI_MakeFace MkF (TopoDS::Wire(shape1),Standard_True);
907 if (shape1.ShapeType() == TopAbs_FACE)
908 aFace = TopoDS::Face(shape1);
910 if(!CheckIsShapeCompound(shape1, aFace)) {
912 cout << "Compute angle : Geom type = " << shape1.ShapeType()
913 << " non traite"<<endl;
922 BRepAdaptor_Surface aSurfaFace (aFace);
923 GeomAbs_SurfaceType aTypeaFace = aSurfaFace.GetType();
924 if (aTypeaFace == GeomAbs_Plane) {
925 aPlnaFace1 = aSurfaFace.Plane();
926 anax1aFace1 = aPlnaFace1.Axis(); // Normale au plan
927 } else if (aTypeaFace == GeomAbs_Cylinder) {
928 gp_Cylinder aCylaFace = aSurfaFace.Cylinder();
929 anax1aFace1 = aCylaFace.Axis();
930 } else if (aTypeaFace == GeomAbs_Cone) {
931 gp_Cone aCone = aSurfaFace.Cone();
932 anax1aFace1 = aCone.Axis();
933 } else if (aTypeaFace == GeomAbs_Torus) {
934 gp_Torus aTore = aSurfaFace.Torus();
935 anax1aFace1 = aTore.Axis();
938 cout<<"Compute angle"<<aTypeaFace<<" non traite"<<endl;
946 if (shape2.ShapeType() == TopAbs_WIRE) {
947 BRepBuilderAPI_MakeFace MkF (TopoDS::Wire(shape2),Standard_True);
954 if (shape2.ShapeType() == TopAbs_FACE)
955 aFace = TopoDS::Face(shape2);
957 if(!CheckIsShapeCompound(shape2, aFace)) {
959 cout << "Compute angle : Geom type = " << shape2.ShapeType()
960 << " non traite"<<endl;
966 aSurfaFace.Initialize(aFace);
967 aTypeaFace = aSurfaFace.GetType();
968 if (aTypeaFace == GeomAbs_Plane) {
969 aPlnaFace2 = aSurfaFace.Plane();
970 anax1aFace2 = aPlnaFace2.Axis(); // Normale au plan
971 } else if (aTypeaFace == GeomAbs_Cylinder) {
972 gp_Cylinder aCylaFace = aSurfaFace.Cylinder();
973 anax1aFace2 = aCylaFace.Axis();
974 } else if (aTypeaFace == GeomAbs_Cone) {
975 gp_Cone aCone = aSurfaFace.Cone();
976 anax1aFace2 = aCone.Axis();
977 } else if (aTypeaFace == GeomAbs_Torus) {
978 gp_Torus aTore = aSurfaFace.Torus();
979 anax1aFace2 = aTore.Axis();
982 cout << "Compute angle " << aTypeaFace << " non traite"<<endl;
988 if (aTypeaFace==GeomAbs_Plane) {
989 if (!anax1aFace1.IsParallel(anax1aFace2, Precision::Angular())) {
991 IntAna_QuadQuadGeo IntersectPlane (aPlnaFace1, aPlnaFace2, Precision::Angular(), Precision::Angular());
992 if (IntersectPlane.IsDone() &&
993 (IntersectPlane.TypeInter() != IntAna_Empty)) {
994 gp_Lin aLine = IntersectPlane.Line(1);
995 Handle(Geom_Line) computedgeom3 = new Geom_Line (aLine);
996 ageom3 = computedgeom3;
999 cout<<"Compute angle insertection of planes failed"<<endl;
1007 cout<<"Compute angle faces are //"<<endl;
1013 // Curvilinear faces...
1014 isCurvilinear = Standard_True;
1016 } // endif (ageom3.IsNull())
1019 Standard_Boolean isplan(Standard_False);
1021 if (!isCurvilinear) {
1022 if (ageom3->IsKind(STANDARD_TYPE(Geom_Plane))) isplan = Standard_True;
1023 else if (ageom3->IsKind(STANDARD_TYPE(Geom_Line))) isplan = Standard_False;
1026 cout << "TPrsStd_ConstraintTools::ComputeAngle: unknown 3rd arg " << endl;
1033 TCollection_ExtendedString txt;
1034 ComputeTextAndValue (aConst,val1,txt,Standard_True);
1036 Standard_Boolean toCreate (Standard_True);
1037 Standard_Boolean isface(shape1.ShapeType()==TopAbs_FACE);
1039 Handle(AIS_AngleDimension) ais;
1040 if (!anAIS.IsNull()) {
1041 ais = Handle(AIS_AngleDimension)::DownCast(anAIS);
1042 if( ais.IsNull() ) {
1043 toCreate = Standard_True;
1045 else toCreate = Standard_False;
1048 Standard_Integer ExtShape(0);
1050 // Creation de l'AIS
1053 FindExternalShape(aConst,ExtShape);
1054 GetGoodShape(shape1);
1055 GetGoodShape(shape2);
1056 ais = new AIS_AngleDimension (TopoDS::Edge(shape1),
1057 TopoDS::Edge(shape2));
1061 if (isCurvilinear) {
1062 ais = new AIS_AngleDimension (TopoDS::Face(shape1),
1063 TopoDS::Face(shape2));
1066 ais = new AIS_AngleDimension (TopoDS::Face(shape1),
1067 TopoDS::Face(shape2));
1074 GetGoodShape(shape1);
1075 GetGoodShape(shape2);
1077 ais->SetMeasuredGeometry (TopoDS::Face (shape1), TopoDS::Face (shape2));
1079 ais->SetCustomPlane (((Handle(Geom_Plane)&) ageom3)->Pln());
1080 else if (!isCurvilinear)
1083 aPlane.SetAxis (((Handle(Geom_Line)&) ageom3)->Position());
1084 ais->SetCustomPlane (aPlane);
1091 //=======================================================================
1092 //function : ComputeConcentric
1094 //=======================================================================
1095 void TPrsStd_ConstraintTools::ComputeConcentric(const Handle(TDataXtd_Constraint)& aConst,
1096 Handle(AIS_InteractiveObject)& anAIS)
1098 Standard_Integer nbgeom = aConst->NbGeometries();
1100 Standard_ProgramError::Raise ("TPrsStd_ConstraintTools::ComputeConcentric: at least 2 constraintes are needed");
1102 if (!aConst->IsPlanar()) {
1104 cout << "TPrsStd_ConstraintTools::ComputeConcentric: must be a planar constraint" << endl;
1109 TopoDS_Shape shape1,shape2 ;
1110 Handle(Geom_Geometry) ageom3;
1112 GetShapesAndGeom(aConst,shape1,shape2,ageom3);
1113 if (shape1.IsNull() || shape2.IsNull()) {
1115 cout << "TPrsStd_ConstraintTools::ComputeConcentric : null shape" << endl;
1121 GetGoodShape(shape1);
1122 GetGoodShape(shape2);
1124 //ota : to allow concentric constraint display between vertex and edge
1125 if (shape1.ShapeType() != TopAbs_EDGE && shape2.ShapeType() != TopAbs_EDGE) {
1127 cout << "TPrsStd_ConstraintTools::ComputeConcentric: concentric between two vertexes : NOT DISPLAYED" << endl;;
1133 Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom3);
1134 if (aplane.IsNull()) {
1136 cout << "TPrsStd_ConstraintTools::ComputeConcentric: nul plane" << endl;;
1142 Handle(AIS_ConcentricRelation) ais;
1143 if (!anAIS.IsNull()) {
1144 ais = Handle(AIS_ConcentricRelation)::DownCast(anAIS);
1146 ais = new AIS_ConcentricRelation (shape1,shape2,aplane);
1149 ais->SetFirstShape(shape1);
1150 ais->SetSecondShape(shape2);
1151 ais->SetPlane(aplane);
1155 ais = new AIS_ConcentricRelation (shape1,shape2,aplane);
1161 //=======================================================================
1162 //function : ComputeRadius
1164 //=======================================================================
1165 void TPrsStd_ConstraintTools::ComputeRadius (const Handle(TDataXtd_Constraint)& aConst,
1166 Handle(AIS_InteractiveObject)& anAIS)
1168 Standard_Integer nbgeom = aConst->NbGeometries();
1171 cout << "TPrsStd_ConstraintTools::ComputeRadius: at least one constrainte is needed" << endl;
1177 TopoDS_Shape shape1 ;
1178 GetOneShape (aConst,shape1);
1179 if (shape1.IsNull()) {
1181 cout << "TPrsStd_ConstraintTools::ComputeRadius: null shape" << endl;
1187 // POP on teste si ce n'est pas un compound
1188 if (shape1.ShapeType()==TopAbs_COMPOUND ||
1189 shape1.ShapeType()==TopAbs_COMPSOLID ||
1190 shape1.ShapeType()==TopAbs_SOLID ||
1191 shape1.ShapeType()==TopAbs_SHELL ) {
1193 cout << "TPrsStd_ConstraintTools::ComputeRadius: not good shape" << endl;
1200 shape1 = GetFace(shape1);
1203 TCollection_ExtendedString txt;
1204 ComputeTextAndValue(aConst,val1,txt,Standard_False);
1207 Standard_Boolean isplanar(aConst->IsPlanar());
1208 if (isplanar) GetGoodShape(shape1);
1210 Handle(AIS_RadiusDimension) ais;
1211 if (!anAIS.IsNull()) {
1212 ais = Handle(AIS_RadiusDimension)::DownCast(anAIS);
1214 ais = new AIS_RadiusDimension (shape1);
1217 ais->SetMeasuredGeometry(shape1);
1220 else ais = new AIS_RadiusDimension (shape1);
1223 Handle(Geom_Geometry) ageom2;
1224 GetGeom(aConst,ageom2);
1225 Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom2);
1226 if (aplane.IsNull()) {
1228 cout << "TPrsStd_ConstraintTools::ComputeRadius: nul plane" << endl;
1233 ais->SetCustomPlane(aplane->Pln());
1238 //=======================================================================
1239 //function : ComputeMinRadius
1241 //=======================================================================
1242 void TPrsStd_ConstraintTools::ComputeMinRadius (const Handle(TDataXtd_Constraint)& aConst,
1243 Handle(AIS_InteractiveObject)& anAIS)
1245 Standard_Integer nbgeom = aConst->NbGeometries();
1248 cout << "TPrsStd_ConstraintTools::ComputeMinRadius: at least one constrainte is needed" << endl;
1254 TopoDS_Shape shape1 ;
1255 GetOneShape (aConst,shape1);
1256 if (shape1.IsNull()) {
1258 cout << "TPrsStd_ConstraintTools::ComputeMinradius: null shape" << endl;
1264 // POP on teste si ce n'est pas un compound
1265 if (shape1.ShapeType()==TopAbs_COMPOUND ||
1266 shape1.ShapeType()==TopAbs_COMPSOLID ||
1267 shape1.ShapeType()==TopAbs_SOLID ||
1268 shape1.ShapeType()==TopAbs_SHELL ) {
1270 cout << "TPrsStd_ConstraintTools::ComputeMinRadius: not good shape" << endl;
1277 shape1 = GetFace(shape1);
1280 TCollection_ExtendedString txt;
1281 ComputeTextAndValue(aConst,val1,txt,Standard_False);
1284 Standard_Boolean isplanar(aConst->IsPlanar());
1285 if (isplanar) GetGoodShape(shape1);
1287 Handle(AIS_MinRadiusDimension) ais;
1288 if (!anAIS.IsNull()) {
1289 ais = Handle(AIS_MinRadiusDimension)::DownCast(anAIS);
1291 ais = new AIS_MinRadiusDimension (shape1,val1,txt);
1294 ais->SetValue(val1);
1295 ais->SetFirstShape(shape1);
1299 else ais = new AIS_MinRadiusDimension (shape1,val1,txt);
1302 Handle(Geom_Geometry) ageom2;
1303 GetGeom(aConst,ageom2);
1304 Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom2);
1305 if (aplane.IsNull()) {
1307 cout << "TPrsStd_ConstraintTools::ComputeMinRadius: nul plane" << endl;
1312 ais->SetPlane(aplane);
1317 //=======================================================================
1318 //function : ComputeMaxRadius
1320 //=======================================================================
1321 void TPrsStd_ConstraintTools::ComputeMaxRadius (const Handle(TDataXtd_Constraint)& aConst,
1322 Handle(AIS_InteractiveObject)& anAIS)
1324 Standard_Integer nbgeom = aConst->NbGeometries();
1327 cout << "TPrsStd_ConstraintTools::ComputeMaxRadius: at least one constrainte is needed" << endl;
1333 TopoDS_Shape shape1 ;
1334 GetOneShape (aConst,shape1);
1335 if (shape1.IsNull()) {
1337 cout << "TPrsStd_ConstraintTools::ComputeMaxradius: null shape" << endl;
1343 // POP on teste si ce n'est pas un compound
1344 if (shape1.ShapeType()==TopAbs_COMPOUND ||
1345 shape1.ShapeType()==TopAbs_COMPSOLID ||
1346 shape1.ShapeType()==TopAbs_SOLID ||
1347 shape1.ShapeType()==TopAbs_SHELL ) {
1349 cout << "TPrsStd_ConstraintTools::ComputeMaxRadius: not good shape" << endl;
1356 shape1 = GetFace(shape1);
1359 TCollection_ExtendedString txt;
1360 ComputeTextAndValue(aConst,val1,txt,Standard_False);
1363 Standard_Boolean isplanar(aConst->IsPlanar());
1364 if (isplanar) GetGoodShape(shape1);
1366 Handle(AIS_MaxRadiusDimension) ais;
1367 if (!anAIS.IsNull()) {
1368 ais = Handle(AIS_MaxRadiusDimension)::DownCast(anAIS);
1370 ais = new AIS_MaxRadiusDimension (shape1,val1,txt);
1373 ais->SetValue(val1);
1374 ais->SetFirstShape(shape1);
1378 else ais = new AIS_MaxRadiusDimension (shape1,val1,txt);
1381 Handle(Geom_Geometry) ageom2;
1382 GetGeom(aConst,ageom2);
1383 Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom2);
1384 if (aplane.IsNull()) {
1386 cout << "TPrsStd_ConstraintTools::ComputeMaxRadius: nul plane" << endl;
1391 ais->SetPlane(aplane);
1396 //=======================================================================
1397 //function : ComputeEqualDistance
1399 //=======================================================================
1400 void TPrsStd_ConstraintTools::ComputeEqualDistance(const Handle(TDataXtd_Constraint)& aConst,
1401 Handle(AIS_InteractiveObject)& anAIS)
1403 Standard_Integer nbgeom = aConst->NbGeometries();
1406 cout << "TPrsStd_ConstraintTools::ComputeEqual: at least four geometries are needed" << endl;;
1411 TopoDS_Shape aShape1, aShape2, aShape3, aShape4;
1412 Handle(Geom_Geometry) aGeom;
1413 GetShapesAndGeom(aConst, aShape1, aShape2, aShape3, aShape4, aGeom);
1414 if (aShape1.IsNull()||aShape2.IsNull()||
1415 aShape3.IsNull()||aShape4.IsNull()) {
1417 cout << "TPrsStd_ConstraintTools::ComputeEqualDistance : null shape" << endl;
1423 GetGoodShape(aShape1);
1424 GetGoodShape(aShape2);
1425 GetGoodShape(aShape3);
1426 GetGoodShape(aShape4);
1428 if (!CheckShapesPair(aShape1, aShape2) ||
1429 !CheckShapesPair(aShape3, aShape4)){
1431 cout << "TPrsStd_ConstraintTools::ComputeEqualDistance : at least one pair of shapes is incorrect"<<endl;
1438 Standard_Boolean IsPlanar(aConst->IsPlanar());
1439 Handle(Geom_Plane) aPlane ;
1440 if(IsPlanar) aPlane = Handle(Geom_Plane)::DownCast(aGeom) ;
1442 if (!IsPlanar || aPlane.IsNull()) {
1445 cout<< "The constraint plane is not assigned "<< endl;
1452 Handle(AIS_EqualDistanceRelation) ais;
1453 if (!anAIS.IsNull()) {
1455 ais = Handle(AIS_EqualDistanceRelation)::DownCast(anAIS);
1458 ais = new AIS_EqualDistanceRelation(aShape1, aShape2, aShape3, aShape4, aPlane);
1461 ais->SetFirstShape(aShape1);
1462 ais->SetSecondShape(aShape2);
1463 ais->SetShape3(aShape3);
1464 ais->SetShape4(aShape4);
1465 ais->SetPlane(aPlane);
1469 else ais = new AIS_EqualDistanceRelation(aShape1, aShape2, aShape3, aShape4, aPlane);
1476 //======================================================================
1477 // function : CheckShapesPair
1478 // purpose : checks the types of two shapes.
1479 // If the types aShape1 and aShape2 are EDGE - EDGE,
1480 // or EDGE - VERTEX,
1481 // or VERTEX - VERTEX,
1482 // or CIRCLE - CIRCLE,
1483 // or CIRCLE - VERTEX,
1484 // then function returns TRUE, otherwise FALSE.
1485 //======================================================================
1486 static Standard_Boolean CheckShapesPair(const TopoDS_Shape& aShape1,
1487 const TopoDS_Shape& aShape2)
1489 //Check whether the shapes form a correct pair.
1490 if (aShape1.ShapeType() == TopAbs_EDGE && aShape2.ShapeType() == TopAbs_EDGE)
1492 BRepAdaptor_Curve aCurve1(TopoDS::Edge(aShape1));
1493 BRepAdaptor_Curve aCurve2(TopoDS::Edge(aShape2));
1494 if (aCurve1.GetType() == GeomAbs_Line && aCurve2.GetType() == GeomAbs_Line)
1495 { //Are lines parallel ?
1496 gp_Dir aDir1 = aCurve1.Line().Direction();
1497 gp_Dir aDir2 = aCurve2.Line().Direction();
1498 if (!(aDir1.IsParallel(aDir2, Precision::Confusion()))) {
1500 cout << " Lines are not parallel"<<endl;
1502 return Standard_False;
1505 else if (aCurve1.GetType() == GeomAbs_Circle && aCurve2.GetType() == GeomAbs_Circle)
1507 gp_Pnt aCntr1 = aCurve1.Circle().Location(); //get the circle center
1508 gp_Pnt aCntr2 = aCurve2.Circle().Location(); //get the circle center
1509 if (!aCntr1.IsEqual(aCntr2,Precision::Confusion())){
1511 cout << " Circles are not concentric"<<endl;
1513 return Standard_False;
1518 cout << "Incorrect pair of curves "<<endl;
1520 return Standard_False;
1523 else if ( aShape1.ShapeType() != TopAbs_VERTEX || aShape2.ShapeType() != TopAbs_VERTEX)
1526 BRepAdaptor_Curve aCurve;
1527 if ( aShape1.ShapeType() == TopAbs_VERTEX) {
1528 aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape1));
1529 aCurve.Initialize(TopoDS::Edge(aShape2));
1532 aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape2));
1533 aCurve.Initialize(TopoDS::Edge(aShape1));
1535 if ( aCurve.GetType() == GeomAbs_Circle)
1537 gp_Pnt aCntr = aCurve.Circle().Location();
1538 if (!aCntr.IsEqual(aPnt, Precision::Confusion())){
1540 cout << " The point doesn't coincide with the circle center"<<endl;
1542 return Standard_False;
1546 return Standard_True;
1549 //=======================================================================
1550 //function : ComputeEqualRadius
1552 //=======================================================================
1553 void TPrsStd_ConstraintTools::ComputeEqualRadius(const Handle(TDataXtd_Constraint)& aConst,
1554 Handle(AIS_InteractiveObject)& anAIS)
1556 Standard_Integer nbgeom = aConst->NbGeometries();
1559 cout << "TPrsStd_ConstraintTools::ComputeEqualRadius: at least two geometries are needed" << endl;;
1564 TopoDS_Shape shape1, shape2;
1565 Handle(Geom_Geometry) ageom3;
1567 GetShapesAndGeom(aConst, shape1, shape2, ageom3);
1568 if (shape1.IsNull()||shape2.IsNull()) {
1570 cout << "TPrsStd_ConstraintTools::ComputeEqualRadius : null shape" << endl;
1577 Standard_Boolean IsPlanar(aConst->IsPlanar());
1579 GetGoodShape(shape1);
1580 GetGoodShape(shape2);
1581 const TopoDS_Edge edge1 = TopoDS::Edge(shape1);
1582 const TopoDS_Edge edge2 = TopoDS::Edge(shape2);
1583 Handle(Geom_Plane) aplane ;
1585 if (IsPlanar) aplane = Handle(Geom_Plane)::DownCast(ageom3) ;
1587 if (!IsPlanar || aplane.IsNull()) {
1588 // check are the planes of edge1 and edge2 coincident
1589 BRepAdaptor_Curve aCurve( edge1 );
1590 Handle( Geom_Curve ) aProjCurve = aCurve.Curve().Curve();
1591 gp_Circ aCircle = (Handle( Geom_Circle )::DownCast( aProjCurve ))->Circ();
1592 gp_Ax3 anAx31(aCircle.Position()); //get the circle axis
1593 // get the circle plane
1594 Handle(Geom_Plane) aPlane1 = new Geom_Plane (anAx31);
1596 aCurve.Initialize(edge2);
1597 aProjCurve = aCurve.Curve().Curve();
1598 aCircle = (Handle( Geom_Circle )::DownCast( aProjCurve ))->Circ();
1599 gp_Ax3 anAx32(aCircle.Position()); //get the circle axis
1600 // get the circle plane
1601 Handle(Geom_Plane) aPlane2 = new Geom_Plane (anAx32);
1603 Standard_Real A, B, C ,D1, D2;
1604 aPlane1->Coefficients(A, B, C, D1);//Get normalized coefficients
1605 aPlane2->Coefficients(A, B, C, D2);//Get normalized coefficients
1606 const gp_Dir& aDir1 = anAx31.Direction();
1607 const gp_Dir& aDir2 = anAx32.Direction();
1609 if(Abs(D1 - D2) < Precision::Confusion() &&
1610 aDir1.IsParallel(aDir2, Precision::Confusion()))
1614 cout << "TPrsStd_ConstraintTools::ComputeRadiusRelation: nul plane" << endl;
1620 Handle(AIS_EqualRadiusRelation) ais;
1621 if (!anAIS.IsNull()) {
1622 ais = Handle(AIS_EqualRadiusRelation)::DownCast(anAIS);
1625 ais = new AIS_EqualRadiusRelation(edge1, edge2, aplane);
1628 ais->SetFirstShape(shape1);
1629 ais->SetSecondShape(shape2);
1630 ais->SetPlane(aplane);
1634 ais = new AIS_EqualRadiusRelation(edge1, edge2, aplane);
1641 //=======================================================================
1642 //function : ComputeDiameter
1644 //=======================================================================
1645 void TPrsStd_ConstraintTools::ComputeDiameter(const Handle(TDataXtd_Constraint)& aConst,
1646 Handle(AIS_InteractiveObject)& anAIS)
1648 Standard_Integer nbgeom = aConst->NbGeometries();
1651 cout << "TPrsStd_ConstraintTools::ComputeDiameter: at least one constrainte is needed" << endl;;
1656 TopoDS_Shape shape1 ;
1658 GetOneShape(aConst,shape1);
1659 if (shape1.IsNull()) {
1661 cout << "TPrsStd_ConstraintTools::ComputeDiameter : null shape" << endl;
1667 TCollection_ExtendedString txt;
1668 ComputeTextAndValue(aConst,val1,txt,Standard_False);
1671 Standard_Boolean IsPlanar(aConst->IsPlanar());
1672 if (IsPlanar) GetGoodShape(shape1);
1673 Handle(AIS_DiameterDimension) ais;
1674 if (!anAIS.IsNull()) {
1675 ais = Handle(AIS_DiameterDimension)::DownCast(anAIS);
1677 ais = new AIS_DiameterDimension (shape1);
1680 ais->SetMeasuredGeometry(shape1);
1683 else ais = new AIS_DiameterDimension (shape1);
1686 Handle(Geom_Geometry) ageom2;
1687 GetGeom(aConst,ageom2);
1688 Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom2);
1689 if (aplane.IsNull()) {
1691 cout << "TPrsStd_ConstraintTools::ComputeDiameter: nul plane" << endl;
1696 //ais->SetCustomPlane(aplane);
1702 //=======================================================================
1703 //function : ComputeFix
1705 //=======================================================================
1706 void TPrsStd_ConstraintTools::ComputeFix(const Handle(TDataXtd_Constraint)& aConst,
1707 Handle(AIS_InteractiveObject)& anAIS)
1709 Standard_Integer nbgeom = aConst->NbGeometries();
1712 cout << "TPrsStd_ConstraintTools::ComputeFix: at least one constrainte is needed" << endl;;
1717 if (!aConst->IsPlanar()) {
1719 cout << "TPrsStd_ConstraintTools::ComputeFix: must be a planar constraint" << endl;;
1725 TopoDS_Shape shape1 ;
1726 Handle(Geom_Geometry) ageom2;
1728 GetOneShape(aConst,shape1);
1729 if (shape1.IsNull()) {
1731 cout << "TPrsStd_ConstraintTools::ComputeFix : null shape" << endl;
1736 GetGoodShape(shape1);
1737 GetGeom(aConst,ageom2);
1738 Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom2);
1739 if (aplane.IsNull()) {
1741 cout << "TPrsStd_ConstraintTools::ComputeFix: nul plane" << endl;
1747 Handle(AIS_FixRelation) ais;
1748 if (!anAIS.IsNull()) {
1749 ais = Handle(AIS_FixRelation)::DownCast(anAIS);
1751 ais = new AIS_FixRelation (shape1,aplane);
1754 ais->SetFirstShape(shape1);
1755 ais->SetPlane(aplane);
1758 else ais = new AIS_FixRelation (shape1,aplane);
1763 //=======================================================================
1764 //function : ComputeOffset
1766 //=======================================================================
1767 void TPrsStd_ConstraintTools::ComputeOffset (const Handle(TDataXtd_Constraint)& aConst,
1768 Handle(AIS_InteractiveObject)& anAIS)
1770 // Get plane for planar constraint
1771 Standard_Boolean is_planar (aConst->IsPlanar());
1772 Handle(Geom_Plane) aplane;
1774 GetGeom (aConst,aplane);
1775 if (aplane.IsNull()) {
1777 cout << "TPrsStd_ConstraintTools::ComputeOffset: null plane" << endl;
1785 TopoDS_Shape S1, S2;
1786 Standard_Integer nbgeom = aConst->NbGeometries();
1788 Handle(TNaming_NamedShape) ageom1 = aConst->GetGeometry(1);
1789 // c'est une shape qui contient les faces generees par les faces d'origines
1790 TNaming_Iterator It (ageom1);
1798 // Get geometry of the constraint
1799 GetTwoShapes (aConst,S1,S2);
1802 if (S1.IsNull() || S2.IsNull()) {
1804 cout << "TPrsStd_ConstraintTools::ComputeOffset: null shape" << endl;
1812 TCollection_ExtendedString txt;
1813 Handle(AIS_LengthDimension) ais;
1814 //Handle(Prs3d_Drawer) aDrawer;
1818 ComputeTextAndValue (aConst,val1,txt,Standard_False);
1819 if (!anAIS.IsNull())
1821 ais = Handle(AIS_LengthDimension)::DownCast(anAIS);
1824 if (S1.ShapeType() == TopAbs_FACE && S2.ShapeType() == TopAbs_FACE)
1828 ais = new AIS_LengthDimension (TopoDS::Face(S1),TopoDS::Face(S2));
1832 ais->SetMeasuredShapes (S1, S2);
1833 ais->SetCustomValue(val1);
1837 ais->SetCustomPlane (aplane->Pln());
1842 if (S1.ShapeType() == TopAbs_EDGE && S2.ShapeType() == TopAbs_EDGE) {
1843 // Find a plane for the dimension
1844 TopoDS_Edge OE = TopoDS::Edge(S1);
1845 BRepAdaptor_Curve CURVE(OE);
1846 if (CURVE.GetType() == GeomAbs_Line) {
1847 // Works only with line !!
1848 //#ifndef OCCT_DEBUG
1849 Handle(Geom_Geometry) aGeomGeometry = CURVE.Curve().Curve()->Transformed(CURVE.Trsf()) ;
1850 gp_Lin OLin = ((Handle(Geom_Line)&) aGeomGeometry)->Lin();
1852 // gp_Lin OLin = ((Handle(Geom_Line)&) CURVE.Curve().Curve()->Transformed(CURVE.Trsf()))->Lin();
1854 TopoDS_Edge NE = TopoDS::Edge(S2);
1855 CURVE.Initialize (NE);
1856 //#ifndef OCCT_DEBUG
1857 aGeomGeometry = CURVE.Curve().Curve()->Transformed(CURVE.Trsf()) ;
1858 gp_Lin NLin = ((Handle(Geom_Line)&)aGeomGeometry)->Lin();
1860 // gp_Lin NLin = ((Handle(Geom_Line)&) CURVE.Curve().Curve()->Transformed(CURVE.Trsf()))->Lin();
1862 gp_Dir TDir (NLin.Location().XYZ() - OLin.Location().XYZ());
1863 aplane = new Geom_Plane (NLin.Location(),NLin.Direction()^TDir);
1866 ais = new AIS_LengthDimension (S1,S2,aplane->Pln());
1869 ais->SetMeasuredShapes (S1, S2);
1870 ais->SetCustomValue(val1);
1872 ais->SetCustomPlane (aplane->Pln());
1878 if (CURVE.GetType() == GeomAbs_Circle) {
1879 //#ifndef OCCT_DEBUG
1880 Handle(Geom_Geometry) aGeomGeometry = CURVE.Curve().Curve()->Transformed(CURVE.Trsf()) ;
1881 gp_Ax1 ax = ((Handle(Geom_Circle)&) aGeomGeometry)->Circ().Axis();
1883 // gp_Ax1 ax = ((Handle(Geom_Circle)&) CURVE.Curve().Curve()->Transformed(CURVE.Trsf()))->Circ().Axis();
1885 aplane = new Geom_Plane (ax.Location(),ax.Direction());
1886 is_planar = Standard_True;
1893 if (S1.ShapeType() == TopAbs_COMPOUND &&
1894 S2.ShapeType() == TopAbs_COMPOUND) {
1895 // Resultat d'un offset - on reconstruit un wire pour determiner un plan
1899 TopExp_Explorer exp (S1,TopAbs_EDGE);
1900 for (;exp.More();exp.Next())
1901 B.Add (w1,exp.Current());
1903 BRepBuilderAPI_MakeFace MkF (w1,Standard_True);
1905 //#ifndef OCCT_DEBUG
1906 Handle(Geom_Surface) aGeomSurface = BRep_Tool::Surface(MkF.Face());
1907 aplane = (Handle(Geom_Plane)&) aGeomSurface ;
1909 // aplane = ((Handle(Geom_Plane)&) BRep_Tool::Surface(MkF.Face()));
1911 is_planar = Standard_True;
1917 ComputeTextAndValue (aConst,val1,txt,Standard_False);
1918 TopExp_Explorer EXP1 (S1,TopAbs_VERTEX);
1919 S1 = EXP1.Current();
1920 gp_Pnt P = BRep_Tool::Pnt(TopoDS::Vertex(S1));
1922 TopoDS_Vertex nearest;
1923 Standard_Real dist(RealLast());
1925 for (TopExp_Explorer EXP2(S2,TopAbs_VERTEX); EXP2.More(); EXP2.Next()) {
1926 const TopoDS_Vertex& current = TopoDS::Vertex(EXP2.Current());
1927 gp_Pnt curpnt = BRep_Tool::Pnt(current);
1928 Standard_Real curdist = P.SquareDistance(curpnt);
1929 if (curdist < dist) {
1935 ais = Handle(AIS_LengthDimension)::DownCast(anAIS);
1937 ais = new AIS_LengthDimension (S1,S2,aplane->Pln());
1940 ais->SetMeasuredShapes (S1, S2);
1941 ais->SetCustomValue (val1);
1942 ais->SetCustomPlane (aplane->Pln ());
1949 cout << "TPrsStd_ConstraintTools::ComputeOffset: Case not implemented" << endl;
1955 //=======================================================================
1956 //function : ComputePlacement
1958 //=======================================================================
1959 void TPrsStd_ConstraintTools::ComputePlacement
1960 (const Handle(TDataXtd_Constraint)& aConst,
1961 Handle(AIS_InteractiveObject)& anAIS)
1963 Standard_Integer nbgeom = aConst->NbGeometries();
1965 Standard_ProgramError::Raise
1966 ("TPrsStd_ConstraintTools::ComputePlacement: at leat two constraints are needed");
1968 TopoDS_Shape shape1,shape2 ;
1969 GetTwoShapes(aConst,shape1,shape2);
1970 if (shape1.IsNull() || shape2.IsNull()) {
1972 cout << "TPrsStd_ConstraintTools::ComputePlacement: nul shape" << endl;
1978 Standard_Real val1=0.0;
1979 TCollection_ExtendedString txt= " ";
1980 if (aConst->IsDimension()) {
1981 ComputeTextAndValue(aConst,val1,txt,Standard_False);
1984 Handle(AIS_OffsetDimension) ais;
1985 if (anAIS.IsNull()) {
1986 ais = new AIS_OffsetDimension(GetFace(shape1),GetFace(shape2),val1,txt);
1987 ais->SetArrowSize(val1/20.);
1989 ais = Handle(AIS_OffsetDimension)::DownCast(anAIS);
1991 ais = new AIS_OffsetDimension(GetFace(shape1),GetFace(shape2),val1,txt);
1992 ais->SetArrowSize(val1/20.);
1994 ais->SetFirstShape(GetFace(shape1));
1995 ais->SetSecondShape(GetFace(shape2));
1996 ais->SetValue(val1);
1998 ais->SetArrowSize(val1/20.);
2001 if (GetFace(shape1).IsNull() || GetFace(shape2).IsNull()) ais.Nullify();
2005 //=======================================================================
2006 //function : ComputeOthers
2008 //=======================================================================
2009 void TPrsStd_ConstraintTools::ComputeOthers
2010 (const Handle(TDataXtd_Constraint)& /*aConst*/,
2011 Handle(AIS_InteractiveObject)& /*anAIS*/)
2015 //=======================================================================
2016 //function : GetOneShape
2018 //=======================================================================
2019 void TPrsStd_ConstraintTools::GetOneShape
2020 (const Handle(TDataXtd_Constraint)& aConst,
2021 TopoDS_Shape& aShape)
2023 const Handle(TNaming_NamedShape)& ageom1 = aConst->GetGeometry(1);
2024 if (!ageom1.IsNull()) aShape = TNaming_Tool::CurrentShape(ageom1);
2027 //=======================================================================
2028 //function : GetTwoShapes
2030 //=======================================================================
2031 void TPrsStd_ConstraintTools::GetTwoShapes
2032 (const Handle(TDataXtd_Constraint)& aConst,
2033 TopoDS_Shape& aShape1,
2034 TopoDS_Shape& aShape2)
2036 const Handle(TNaming_NamedShape)& ageom1 = aConst->GetGeometry(1);
2037 if (!ageom1.IsNull()) aShape1 = TNaming_Tool::CurrentShape(aConst->GetGeometry(1));
2038 const Handle(TNaming_NamedShape)& ageom2 = aConst->GetGeometry(2);
2039 if (!ageom2.IsNull()) aShape2 = TNaming_Tool::CurrentShape(aConst->GetGeometry(2));
2042 //=======================================================================
2043 //function : GetShapesAndGeom
2045 //=======================================================================
2046 void TPrsStd_ConstraintTools::GetShapesAndGeom
2047 (const Handle(TDataXtd_Constraint)& aConst,
2048 TopoDS_Shape& aShape1,
2049 TopoDS_Shape& aShape2,
2050 Handle(Geom_Geometry)& aGeom)
2052 GetTwoShapes(aConst,aShape1,aShape2);
2053 GetGeom(aConst,aGeom);
2056 //=======================================================================
2057 //function : GetShapesAndGeom
2059 //=======================================================================
2060 void TPrsStd_ConstraintTools::GetShapesAndGeom
2061 (const Handle(TDataXtd_Constraint)& aConst,
2062 TopoDS_Shape& aShape1,
2063 TopoDS_Shape& aShape2,
2064 TopoDS_Shape& aShape3,
2065 Handle(Geom_Geometry)& aGeom)
2067 GetTwoShapes(aConst,aShape1,aShape2);
2068 const Handle(TNaming_NamedShape)& ageom3 = aConst->GetGeometry(3);//ota: GetGeometry(2) was
2069 if (!ageom3.IsNull()) aShape3 = TNaming_Tool::CurrentShape(aConst->GetGeometry(3));
2070 GetGeom(aConst,aGeom);
2073 //=======================================================================
2074 //function : GetShapesAndGeom
2076 //=======================================================================
2077 void TPrsStd_ConstraintTools::GetShapesAndGeom
2078 (const Handle(TDataXtd_Constraint)& aConst,
2079 TopoDS_Shape& aShape1,
2080 TopoDS_Shape& aShape2,
2081 TopoDS_Shape& aShape3,
2082 TopoDS_Shape& aShape4,
2083 Handle(Geom_Geometry)& aGeom)
2085 GetTwoShapes(aConst,aShape1, aShape2 );
2086 const Handle(TNaming_NamedShape)& ageom3 = aConst->GetGeometry(3);
2087 if (!ageom3.IsNull()) aShape3 = TNaming_Tool::CurrentShape(aConst->GetGeometry(3));
2088 const Handle(TNaming_NamedShape)& ageom4 = aConst->GetGeometry(4);
2089 if (!ageom4.IsNull()) aShape4 = TNaming_Tool::CurrentShape(aConst->GetGeometry(4));
2090 GetGeom(aConst,aGeom);
2093 //=======================================================================
2094 //function : ComputeCoincident
2096 //=======================================================================
2097 void TPrsStd_ConstraintTools::ComputeCoincident(const Handle(TDataXtd_Constraint)& aConst,
2098 Handle(AIS_InteractiveObject)& anAIS)
2100 Standard_Integer nbgeom = aConst->NbGeometries();
2103 cout << "TPrsStd_ConstraintTools::ComputeCoincident: at leat two constraintes are needed" << endl;
2109 if (!aConst->IsPlanar()) {
2111 cout << "TPrsStd_ConstraintTools::ComputeCoincident: must be a planar constraint" << endl;
2117 TopoDS_Shape shape1,shape2 ;
2118 Handle(Geom_Plane) aplane;
2119 GetShapesAndGeom(aConst,shape1,shape2,aplane);
2120 if (shape1.IsNull() || shape2.IsNull()) {
2122 cout << "TPrsStd_ConstraintTools::ComputeCoincident: nul shape" << endl;
2128 GetGoodShape(shape1);
2129 GetGoodShape(shape2);
2130 if (aplane.IsNull()) {
2132 cout << "TPrsStd_ConstraintTools::ComputeCoincident: nul plane" << endl;
2139 Handle(AIS_IdenticRelation) ais;
2140 if (anAIS.IsNull()) ais = new AIS_IdenticRelation(shape1,shape2,aplane);
2142 ais = Handle(AIS_IdenticRelation)::DownCast(anAIS);
2144 ais = new AIS_IdenticRelation(shape1,shape2,aplane);
2147 ais->SetFirstShape(shape1);
2148 ais->SetSecondShape(shape2);
2149 ais->SetPlane(aplane);
2155 //=======================================================================
2156 //function : ComputeRound
2158 //=======================================================================
2159 void TPrsStd_ConstraintTools::ComputeRound(const Handle(TDataXtd_Constraint)& aConst,
2160 Handle(AIS_InteractiveObject)& anAIS)
2162 Standard_Integer nbgeom = aConst->NbGeometries();
2165 cout << "TPrsStd_ConstraintTools::ComputeRound: at leat one geometry is needed" << endl;
2170 TopoDS_Shape shape1;
2171 GetOneShape (aConst,shape1);
2172 if (shape1.IsNull()) {
2174 cout << "TPrsStd_ConstraintTools::ComputePlacement: nul shape" << endl;
2181 TCollection_ExtendedString txt;
2182 ComputeTextAndValue(aConst,val1,txt,Standard_False);
2185 Handle(AIS_RadiusDimension) ais;
2190 if (anAIS.IsNull()) ais =
2191 new AIS_RadiusDimension(shape1);
2193 ais = Handle(AIS_RadiusDimension)::DownCast(anAIS);
2195 ais = new AIS_RadiusDimension(shape1);
2198 ais->SetMeasuredGeometry(shape1);
2202 catch(Standard_Failure) {
2209 //=======================================================================
2210 //function : GetGeom
2212 //=======================================================================
2213 void TPrsStd_ConstraintTools::GetGeom(const Handle(TDataXtd_Constraint)& aConst,
2214 Handle(Geom_Geometry)& aGeom)
2216 Handle(TNaming_NamedShape) atgeom = aConst->GetPlane();
2217 if (atgeom.IsNull()) {
2219 cout<<"TPrsStd_ConstraintTools::GetGeom : aConst->GetPlane().IsNull()"<<endl;
2227 TDF_Label label = atgeom->Label();
2229 Handle(TNaming_NamedShape) NS;
2230 if(label.FindAttribute(TNaming_NamedShape::GetID(),NS)){
2231 TopoDS_Shape s = TNaming_Tool::GetShape(NS);
2232 if(s.IsNull()) return;
2235 if (TDataXtd_Geometry::Plane(label,aplane)) aGeom = new Geom_Plane(aplane);
2236 else if (TDataXtd_Geometry::Line(label,anaxis)) aGeom = new Geom_Line(anaxis);
2237 else if (TDataXtd_Geometry::Point(label,apoint)) aGeom = new Geom_CartesianPoint(apoint);
2240 cout << "TPrsStd_ConstraintTools::GetGeom no geom on label " << endl;