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
19 #include <AIS_AngleDimension.hxx>
20 #include <AIS_ConcentricRelation.hxx>
21 #include <AIS_DiameterDimension.hxx>
22 #include <AIS_EqualDistanceRelation.hxx>
23 #include <AIS_EqualRadiusRelation.hxx>
24 #include <AIS_FixRelation.hxx>
25 #include <AIS_IdenticRelation.hxx>
26 #include <AIS_InteractiveContext.hxx>
27 #include <AIS_InteractiveObject.hxx>
28 #include <AIS_LengthDimension.hxx>
29 #include <AIS_MaxRadiusDimension.hxx>
30 #include <AIS_MidPointRelation.hxx>
31 #include <AIS_MinRadiusDimension.hxx>
32 #include <AIS_OffsetDimension.hxx>
33 #include <AIS_ParallelRelation.hxx>
34 #include <AIS_PerpendicularRelation.hxx>
35 #include <AIS_RadiusDimension.hxx>
36 #include <AIS_Relation.hxx>
37 #include <AIS_SymmetricRelation.hxx>
38 #include <AIS_TangentRelation.hxx>
39 #include <BRep_Builder.hxx>
40 #include <BRep_Tool.hxx>
41 #include <BRepAdaptor_Curve.hxx>
42 #include <BRepAdaptor_Surface.hxx>
43 #include <BRepBuilderAPI_MakeFace.hxx>
44 #include <GC_MakePlane.hxx>
45 #include <Geom_CartesianPoint.hxx>
46 #include <Geom_Circle.hxx>
47 #include <Geom_Geometry.hxx>
48 #include <Geom_Line.hxx>
49 #include <Geom_Plane.hxx>
50 #include <GeomAbs_SurfaceType.hxx>
52 #include <gp_Cone.hxx>
53 #include <gp_Cylinder.hxx>
58 #include <gp_Torus.hxx>
59 #include <IntAna_QuadQuadGeo.hxx>
60 #include <Precision.hxx>
61 #include <Prs3d_Drawer.hxx>
62 #include <Standard_ErrorHandler.hxx>
63 #include <Standard_ProgramError.hxx>
64 #include <TCollection_ExtendedString.hxx>
65 #include <TDataStd_Name.hxx>
66 #include <TDataStd_Real.hxx>
67 #include <TDataXtd_Constraint.hxx>
68 #include <TDataXtd_Geometry.hxx>
69 #include <TDF_Label.hxx>
70 #include <TDF_Reference.hxx>
71 #include <TNaming_Iterator.hxx>
72 #include <TNaming_NamedShape.hxx>
73 #include <TNaming_Tool.hxx>
75 #include <TopExp_Explorer.hxx>
77 #include <TopoDS_Edge.hxx>
78 #include <TopoDS_Face.hxx>
79 #include <TopoDS_Shape.hxx>
80 #include <TopoDS_Vertex.hxx>
81 #include <TopTools_IndexedMapOfShape.hxx>
82 #include <TPrsStd_ConstraintTools.hxx>
83 #include <UnitsAPI.hxx>
86 static Standard_Boolean CheckShapesPair(const TopoDS_Shape& , const TopoDS_Shape& ); //ota
88 //=======================================================================
89 //function : static NullifyAIS
91 //=======================================================================
92 static void NullifyAIS ( Handle(AIS_InteractiveObject)& anais)
94 if (anais.IsNull()) return;
100 //=======================================================================
101 //function : static FindExternalShape
103 //=======================================================================
104 static void FindExternalShape(const Handle(TDataXtd_Constraint)& aConst,
105 Standard_Integer& extShape)
108 const TDF_Label& L = aConst->Label();
109 if (!aConst->GetGeometry(1)->Label().IsDescendant(L)) extShape = 1;
110 else if (!aConst->GetGeometry(2)->Label().IsDescendant(L)) extShape = 2;
113 //=======================================================================
114 //function : static GetGoodShape for planar constraint
116 //=======================================================================
117 static void GetGoodShape(TopoDS_Shape& theShape)
119 switch (theShape.ShapeType())
122 case TopAbs_VERTEX: { return; }
125 TopExp_Explorer anExp (theShape,TopAbs_EDGE);
128 theShape = anExp.Current();
133 anExp.Init (theShape, TopAbs_VERTEX);
136 theShape = anExp.Current();
143 // Pour le cas ou S est un compound
144 static Standard_Boolean IsFace (const TopoDS_Shape& S)
146 Standard_Boolean findface = Standard_False;
147 TopExp_Explorer EXP (S,TopAbs_FACE);
148 if (EXP.More()) findface = Standard_True;
152 static TopoDS_Face GetFace (const TopoDS_Shape& S)
155 TopExp_Explorer EXP (S,TopAbs_FACE);
156 if (EXP.More()) F = TopoDS::Face (EXP.Current());
160 static TopoDS_Edge GetEdge (const TopoDS_Shape& S)
163 TopExp_Explorer EXP (S, TopAbs_EDGE);
164 if (EXP.More()) E = TopoDS::Edge (EXP.Current());
170 //=======================================================================
171 //Function : ComputeAndTextValue
173 //=======================================================================
174 void TPrsStd_ConstraintTools::ComputeTextAndValue(const Handle(TDataXtd_Constraint)& aConst,
176 TCollection_ExtendedString& txt,
177 const Standard_Boolean anIsAngle )
179 Standard_Real outvalue;
180 const Handle(TDataStd_Real)& VAL = aConst->GetValue();
183 outvalue = UnitsAPI::CurrentFromLS(Abs(val),"PLANE ANGLE");
186 outvalue = UnitsAPI::CurrentFromLS(val,"LENGTH");
189 sprintf(res,"%g",outvalue);
190 txt = TCollection_ExtendedString(res);
192 if (VAL->IsCaptured()) {
193 Handle(TDF_Reference) ref;
194 VAL->Label().FindAttribute(TDF_Reference::GetID(),ref);
195 Handle(TDataStd_Name) name;
196 const TDF_Label& L = ref->Get();
197 if (ref->Get().FindAttribute(TDataStd_Name::GetID(),name)) {
198 TCollection_ExtendedString fullname;
199 Handle(TDataStd_Name) Fathername;
200 if (L.Father().FindAttribute(TDataStd_Name::GetID(),Fathername)) {
201 fullname = Fathername->Get() + TCollection_ExtendedString(".") + name->Get();
203 else fullname = name->Get();
204 txt = fullname + TCollection_ExtendedString("=") + txt;
210 //=======================================================================
211 //function : UpdateOnlyValue
213 //=======================================================================
215 void TPrsStd_ConstraintTools::UpdateOnlyValue(const Handle(TDataXtd_Constraint)& aConst,
216 const Handle(AIS_InteractiveObject)& anAIS)
218 if (anAIS.IsNull()) return;
219 if (!aConst->IsDimension()) return;
221 TCollection_ExtendedString txt;
222 TPrsStd_ConstraintTools:: ComputeTextAndValue(aConst,val,txt,aConst->GetType() == TDataXtd_ANGLE);
223 Handle(AIS_Relation) rel = Handle(AIS_Relation)::DownCast(anAIS);
224 if (!rel.IsNull()) rel->SetText(txt);
228 //=======================================================================
229 //function : ComputeDistance
230 //purpose : Build an AIS_LengthDimension.
231 //=======================================================================
232 void TPrsStd_ConstraintTools::ComputeDistance (const Handle(TDataXtd_Constraint)& theConst,
233 Handle(AIS_InteractiveObject)& theAIS)
235 Standard_Integer aGeomNum = theConst->NbGeometries();
237 // Dimension is build on one or two shapes.
238 if (aGeomNum < 1 || aGeomNum > 2)
241 cout << "TPrsStd_ConstraintTools::ComputeDistance: 1 or 2 geometries are needed" << endl;
247 TopoDS_Shape aShape1, aShape2;
248 Handle(Geom_Geometry) aGeom3;
249 Standard_Boolean isPlanar (theConst->IsPlanar());
251 // Get shapes and geometry
254 GetOneShape (theConst, aShape1);
256 if (aShape1.IsNull())
259 cout << "TPrsStd_ConstraintTools::ComputeDistance : null shape" << endl;
267 GetTwoShapes (theConst, aShape1, aShape2);
269 if (aShape1.IsNull() || aShape2.IsNull())
272 cout << "TPrsStd_ConstraintTools::ComputeDistance : null shape" << endl;
279 // Get plane from constraint
280 Handle(Geom_Plane) aPlane;
283 GetGeom (theConst, aGeom3);
285 GetGoodShape (aShape1);
289 GetGoodShape (aShape2);
292 aPlane = Handle(Geom_Plane)::DownCast (aGeom3);
296 Standard_Real aValue;
297 TCollection_ExtendedString aText;
298 ComputeTextAndValue (theConst, aValue, aText,Standard_False);
300 Standard_Boolean isFaces = Standard_False;
301 Standard_Boolean isEdges = Standard_False;
302 Standard_Boolean isEdgeFace = Standard_False;
303 Standard_Boolean isVertices = Standard_False;
304 Standard_Boolean isEdge = Standard_False;
306 Standard_Boolean SaveDrw = Standard_False;
307 Handle(Prs3d_Drawer) aDrawer;
308 Handle(AIS_LengthDimension) aDim;
310 if (!theAIS.IsNull())
312 aDim = Handle(AIS_LengthDimension)::DownCast (theAIS);
315 // Check shapes for AIS dimension
318 if (aShape1.ShapeType () != TopAbs_EDGE)
321 cout << "TPrsStd_ConstraintTools::ComputeDistance : shape should be edge" << endl;
327 isEdge = Standard_True;
331 isFaces = IsFace (aShape1) && IsFace (aShape2);
333 isEdges = (aShape1.ShapeType() == TopAbs_EDGE) && (aShape2.ShapeType() == TopAbs_EDGE);
335 isEdgeFace = ((aShape1.ShapeType() == TopAbs_FACE) && (aShape2.ShapeType() == TopAbs_EDGE))
336 || ((aShape1.ShapeType() == TopAbs_EDGE) && (aShape2.ShapeType() == TopAbs_FACE));
338 isVertices = (aShape1.ShapeType() == TopAbs_VERTEX) && (aShape2.ShapeType() == TopAbs_VERTEX);
340 if (!isPlanar && !isFaces && !isEdges && !isVertices)
342 // Search suitable geometry for dimension
343 if (aShape1.ShapeType() == aShape2.ShapeType())
345 TopoDS_Vertex aV1, aV2, aV3, aV4;
346 if (aShape1.ShapeType() == TopAbs_WIRE)
348 TopExp::Vertices (TopoDS::Wire(aShape1), aV1, aV2);
349 TopExp::Vertices (TopoDS::Wire(aShape2), aV3, aV4);
352 gp_Pnt aP1 = BRep_Tool::Pnt(aV1);
353 gp_Pnt aP2 = BRep_Tool::Pnt(aV3);
354 gp_Pnt aP3 = BRep_Tool::Pnt (aV4);
355 if (aP1.Distance (aP2) < aP1.Distance (aP3))
358 gp_Ax2 ax2 (aP1, gp_Dir (aP2.XYZ() - aP1.XYZ()));
359 aPlane = new Geom_Plane (aP1, ax2.XDirection());
364 gp_Ax2 anAx2 (aP1, gp_Dir (aP3.XYZ() - aP1.XYZ()));
365 aPlane = new Geom_Plane (aP1, anAx2.XDirection());
368 else if (!isEdgeFace)
377 Standard_Boolean isCheckPlane = (aDim.IsNull() && !isFaces) || isPlanar;
378 if ((isVertices || isEdges) && !isPlanar)
380 gp_Pnt aP1, aP2, aP3;
384 aP1 = BRep_Tool::Pnt (TopoDS::Vertex (aShape1));
385 aP2 = BRep_Tool::Pnt (TopoDS::Vertex (aShape2));
386 aP3 = gp_Pnt (aP1.Y() - 1.0, aP2.X() + 1.0, 0.0);
391 TopoDS_Vertex aV1, aV2, aV3, aV4;
392 TopExp::Vertices (TopoDS::Edge(aShape1), aV1, aV2);
393 TopExp::Vertices (TopoDS::Edge(aShape2), aV3, aV4);
394 aP1 = BRep_Tool::Pnt (aV1);
395 aP2 = BRep_Tool::Pnt (aV2);
396 aP3 = BRep_Tool::Pnt (aV3);
399 GC_MakePlane aPlaneMaker (aP1, aP2, aP3);
400 if (aPlaneMaker.IsDone() && !isPlanar)
402 aPlane = aPlaneMaker.Value();
406 if (isCheckPlane && aPlane.IsNull())
409 cout << "TPrsStd_ConstraintTools::ComputeDistance : null plane" << endl;
420 aDim = new AIS_LengthDimension (GetEdge (aShape1), aPlane->Pln());
424 aDim = new AIS_LengthDimension (GetFace (aShape1), GetFace (aShape2));
428 aDim = new AIS_LengthDimension (aShape1, aShape2, aPlane->Pln());
433 aDim->SetAttributes (aDrawer);
440 aDim->SetMeasuredGeometry (GetEdge(aShape1), aPlane->Pln());
444 aDim->SetMeasuredShapes (aShape1, aShape2);
447 aDim->SetCustomValue (aValue);
450 if (!aPlane.IsNull())
452 aDim->SetCustomPlane (aPlane->Pln());
458 //=======================================================================
459 //function : ComputePerpendicular
461 //=======================================================================
462 void TPrsStd_ConstraintTools::ComputePerpendicular(const Handle(TDataXtd_Constraint)& aConst,
463 Handle(AIS_InteractiveObject)& anAIS)
465 Standard_Integer nbgeom = aConst->NbGeometries();
468 cout << "TPrsStd_ConstraintTools::ComputePerpendicular: at leat two constraintes are needed" << endl;
474 TopoDS_Shape shape1,shape2 ;
475 Handle(Geom_Geometry) ageom3;
476 Standard_Boolean is_planar(aConst->IsPlanar());
478 if (is_planar) GetShapesAndGeom(aConst,shape1,shape2,ageom3);
479 else GetTwoShapes(aConst,shape1,shape2);
480 if (shape1.IsNull() || shape2.IsNull()) {
482 cout << "TPrsStd_ConstraintTools::ComputePerpendicular : null shape" << endl;
487 GetGoodShape(shape1);
488 GetGoodShape(shape2);
490 Handle(AIS_PerpendicularRelation) ais;
491 if (anAIS.IsNull()) ais = new AIS_PerpendicularRelation(shape1,shape2);
493 ais = Handle(AIS_PerpendicularRelation)::DownCast(anAIS);
495 ais = new AIS_PerpendicularRelation(shape1,shape2);
498 ais->SetFirstShape(shape1);
499 ais->SetSecondShape(shape2);
504 Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom3);
505 if (aplane.IsNull()) {
507 cout << "TPrsStd_ConstraintTools::ComputePerpendicular: nul plane" << endl;
512 ais->SetPlane(aplane);
517 //=======================================================================
518 //function : ComputeParallel
520 //=======================================================================
521 void TPrsStd_ConstraintTools::ComputeParallel(const Handle(TDataXtd_Constraint)& aConst,
522 Handle(AIS_InteractiveObject)& anAIS)
524 Standard_Integer nbgeom = aConst->NbGeometries();
527 cout << "TPrsStd_ConstraintTools::ComputeParallel: at least 2 constraintes are needed" << endl;
533 if (!aConst->IsPlanar()) {
535 cout << "TPrsStd_ConstraintTools::ComputeParallel: must be a planar constraint" << endl;
541 TopoDS_Shape shape1,shape2 ;
542 Handle(Geom_Geometry) ageom3;
544 GetShapesAndGeom(aConst,shape1,shape2,ageom3);
545 if (shape1.IsNull() || shape2.IsNull()) {
547 cout << "TPrsStd_ConstraintTools::ComputeParallel : null shape" << endl;
552 Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom3);
553 if (aplane.IsNull()) {
555 cout << "TPrsStd_ConstraintTools::ComputeParallel: nul plane" << endl;
561 GetGoodShape(shape1);
562 GetGoodShape(shape2);
563 Handle(AIS_ParallelRelation) ais;
564 if (anAIS.IsNull()) ais = new AIS_ParallelRelation(shape1,shape2,aplane);
566 ais = Handle(AIS_ParallelRelation)::DownCast(anAIS);
568 ais = new AIS_ParallelRelation(shape1,shape2,aplane);
571 ais->SetFirstShape(shape1);
572 ais->SetSecondShape(shape2);
573 ais->SetPlane(aplane);
578 //=======================================================================
579 //function : ComputeSymmetry
581 //=======================================================================
582 void TPrsStd_ConstraintTools::ComputeSymmetry(const Handle(TDataXtd_Constraint)& aConst,
583 Handle(AIS_InteractiveObject)& anAIS)
585 Standard_Integer nbgeom = aConst->NbGeometries();
588 cout << "TPrsStd_ConstraintTools::ComputeSymmetry: at least 3 constraintes are needed" << endl;
594 Standard_Boolean is_planar(aConst->IsPlanar());
597 cout << "TPrsStd_ConstraintTools::ComputeSymmetry: must be a planar constraint" << endl;
603 TopoDS_Shape shape1,shape2,shape3 ;
604 Handle(Geom_Geometry) ageom3;
605 GetShapesAndGeom(aConst,shape1,shape2,shape3,ageom3);
607 if (shape1.IsNull() || shape2.IsNull() || shape3.IsNull()) {
609 cout << "TPrsStd_ConstraintTools::ComputeSymmetry : null shape" << endl;
614 GetGoodShape(shape1);
615 GetGoodShape(shape2);
616 GetGoodShape(shape3);
617 Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom3);
618 if (aplane.IsNull()) {
620 cout << "TPrsStd_ConstraintTools::ComputeSymmetry: null plane" << endl;
626 Handle(AIS_SymmetricRelation) ais;
627 if (anAIS.IsNull()) ais = new AIS_SymmetricRelation(shape3,shape1,shape2,aplane);
629 ais = Handle(AIS_SymmetricRelation)::DownCast(anAIS);
631 ais = new AIS_SymmetricRelation(shape3,shape1,shape2,aplane);
634 ais->SetFirstShape(shape1);
635 ais->SetSecondShape(shape2);
636 ais->SetPlane(aplane);
637 ais->SetTool(shape3);
643 //=======================================================================
644 //function : ComputeMidPoint
646 //=======================================================================
647 void TPrsStd_ConstraintTools::ComputeMidPoint(const Handle(TDataXtd_Constraint)& aConst,
648 Handle(AIS_InteractiveObject)& anAIS)
650 Standard_Integer nbgeom = aConst->NbGeometries();
654 cout << "TPrsStd_ConstraintTools::ComputeSymmetry: at least 3 constraints are needed" << endl;
660 Standard_Boolean is_planar(aConst->IsPlanar());
664 cout << "TPrsStd_ConstraintTools::ComputeSymmetry: must be a planar constraint" << endl;
670 TopoDS_Shape shape1,shape2,shape3;
671 Handle(Geom_Geometry) ageom3;
672 GetShapesAndGeom(aConst,shape1,shape2,shape3,ageom3);
674 if (shape1.IsNull() || shape2.IsNull() || shape3.IsNull())
677 cout << "TPrsStd_ConstraintTools::ComputeSymmetry : null shape" << endl;
682 GetGoodShape(shape1);
683 GetGoodShape(shape2);
684 GetGoodShape(shape3);
686 Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom3);
690 cout << "TPrsStd_ConstraintTools::ComputeSymmetry: null plane" << endl;
697 Handle(AIS_MidPointRelation) ais;
698 if ( anAIS.IsNull() ) ais = new AIS_MidPointRelation(shape3,shape1,shape2,aplane);
701 ais = Handle(AIS_MidPointRelation)::DownCast(anAIS);
704 ais = new AIS_MidPointRelation(shape3,shape1,shape2,aplane);
708 ais->SetFirstShape(shape1);
709 ais->SetSecondShape(shape2);
710 ais->SetPlane(aplane);
711 ais->SetTool(shape3);
717 //=======================================================================
718 //function : ComputeTangent
720 //=======================================================================
721 void TPrsStd_ConstraintTools::ComputeTangent (const Handle(TDataXtd_Constraint)& aConst,
722 Handle(AIS_InteractiveObject)& anAIS)
724 Standard_Integer nbgeom = aConst->NbGeometries();
727 cout << "TPrsStd_ConstraintTools::ComputeTangent: at leat two constraintes are needed" << endl;
732 if (!aConst->IsPlanar()) {
734 cout << "TPrsStd_ConstraintTools::ComputeTangent: must be a planar constraint" << endl;
739 TopoDS_Shape shape1,shape2 ;
740 Handle(Geom_Geometry) ageom3;
742 GetShapesAndGeom(aConst,shape1,shape2,ageom3);
743 if (shape1.IsNull() || shape2.IsNull()) {
745 cout << "TPrsStd_ConstraintTools::ComputeTangent : null shape" << endl;
750 GetGoodShape(shape1);
751 GetGoodShape(shape2);
752 Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom3);
753 if (aplane.IsNull()) {
755 cout << "TPrsStd_ConstraintTools::ComputeTangent: nul plane" << endl;
761 Handle(AIS_TangentRelation) ais;
764 ais = new AIS_TangentRelation(shape1,shape2,aplane);
765 ais->SetArrowSize(10000000); // jfa 9/10/2000
769 ais = Handle(AIS_TangentRelation)::DownCast(anAIS);
772 ais = new AIS_TangentRelation(shape1,shape2,aplane);
773 ais->SetArrowSize(10000000); // jfa 9/10/2000
777 ais->SetFirstShape(shape1);
778 ais->SetSecondShape(shape2);
779 ais->SetPlane(aplane);
780 ais->SetArrowSize(10000000); // jfa 9/10/2000
786 //=======================================================================
787 //function : ComputeAngleForOneFace
788 //purpose : computes AngleDimension for one-conical-face case
789 //=======================================================================
790 void TPrsStd_ConstraintTools::ComputeAngleForOneFace (const Handle(TDataXtd_Constraint)& aConst,
791 Handle(AIS_InteractiveObject)& anAIS)
795 Handle(Geom_Geometry) ageom3;
797 GetOneShape( aConst, shape );
798 if (shape.IsNull() ) {
800 cout << "TPrsStd_ConstraintTools::ComputeAngleForOneFace : null shape" << endl;
807 TCollection_ExtendedString txt;
808 TPrsStd_ConstraintTools::ComputeTextAndValue (aConst,val1,txt,Standard_True);
810 Handle(AIS_AngleDimension) ais;
812 if (!anAIS.IsNull()) {
813 ais = Handle(AIS_AngleDimension)::DownCast(anAIS);
815 face = TopoDS::Face( shape );
816 ais = new AIS_AngleDimension (face);
819 ais->SetMeasuredGeometry(TopoDS::Face( shape ));
823 face = TopoDS::Face (shape);
824 ais = new AIS_AngleDimension (face);
830 //=======================================================================
831 //function : CheckIsShapeCompound
833 //=======================================================================
835 static Standard_Boolean CheckIsShapeCompound(TopoDS_Shape& shape, TopoDS_Face& aFace)
837 if (shape.ShapeType() == TopAbs_COMPOUND) {
838 TopTools_IndexedMapOfShape aFaceMap;
839 TopExp::MapShapes(shape, TopAbs_FACE, aFaceMap);
840 for(Standard_Integer i = 1;i <= aFaceMap.Extent();i++)
842 aFace = TopoDS::Face(aFaceMap.FindKey(i));
843 if(!aFace.IsNull()) {
845 return (Standard_True);
850 cout << "TPrsStd::Compute angle : Shape is not Compound or is Null" <<endl;
852 return (Standard_False);
855 //=======================================================================
856 //function : ComputeAngle
858 //=======================================================================
860 void TPrsStd_ConstraintTools::ComputeAngle (const Handle(TDataXtd_Constraint)& aConst,
861 Handle(AIS_InteractiveObject)& anAIS)
863 Standard_Integer nbgeom = aConst->NbGeometries();
865 if( nbgeom == 1 ) { ComputeAngleForOneFace( aConst, anAIS ); return; }
867 cout << "TPrsStd_ConstraintTools::ComputeAngle: at least 2 constraints are needed" << endl;
873 TopoDS_Shape shape1,shape2 ;
874 Handle(Geom_Geometry) ageom3;
876 GetShapesAndGeom (aConst,shape1,shape2,ageom3);
877 if (shape1.IsNull() || shape2.IsNull()) {
879 cout << "TPrsStd_ConstraintTools::ComputeAngle : null shape" << endl;
885 Standard_Boolean isCurvilinear = Standard_False;
886 if (ageom3.IsNull()) {
887 // on essaie de le calculer
890 if (shape1.ShapeType() == TopAbs_WIRE) {
891 BRepBuilderAPI_MakeFace MkF (TopoDS::Wire(shape1),Standard_True);
898 if (shape1.ShapeType() == TopAbs_FACE)
899 aFace = TopoDS::Face(shape1);
901 if(!CheckIsShapeCompound(shape1, aFace)) {
903 cout << "Compute angle : Geom type = " << shape1.ShapeType()
904 << " non traite"<<endl;
913 BRepAdaptor_Surface aSurfaFace (aFace);
914 GeomAbs_SurfaceType aTypeaFace = aSurfaFace.GetType();
915 if (aTypeaFace == GeomAbs_Plane) {
916 aPlnaFace1 = aSurfaFace.Plane();
917 anax1aFace1 = aPlnaFace1.Axis(); // Normale au plan
918 } else if (aTypeaFace == GeomAbs_Cylinder) {
919 gp_Cylinder aCylaFace = aSurfaFace.Cylinder();
920 anax1aFace1 = aCylaFace.Axis();
921 } else if (aTypeaFace == GeomAbs_Cone) {
922 gp_Cone aCone = aSurfaFace.Cone();
923 anax1aFace1 = aCone.Axis();
924 } else if (aTypeaFace == GeomAbs_Torus) {
925 gp_Torus aTore = aSurfaFace.Torus();
926 anax1aFace1 = aTore.Axis();
929 cout<<"Compute angle"<<aTypeaFace<<" non traite"<<endl;
937 if (shape2.ShapeType() == TopAbs_WIRE) {
938 BRepBuilderAPI_MakeFace MkF (TopoDS::Wire(shape2),Standard_True);
945 if (shape2.ShapeType() == TopAbs_FACE)
946 aFace = TopoDS::Face(shape2);
948 if(!CheckIsShapeCompound(shape2, aFace)) {
950 cout << "Compute angle : Geom type = " << shape2.ShapeType()
951 << " non traite"<<endl;
957 aSurfaFace.Initialize(aFace);
958 aTypeaFace = aSurfaFace.GetType();
959 if (aTypeaFace == GeomAbs_Plane) {
960 aPlnaFace2 = aSurfaFace.Plane();
961 anax1aFace2 = aPlnaFace2.Axis(); // Normale au plan
962 } else if (aTypeaFace == GeomAbs_Cylinder) {
963 gp_Cylinder aCylaFace = aSurfaFace.Cylinder();
964 anax1aFace2 = aCylaFace.Axis();
965 } else if (aTypeaFace == GeomAbs_Cone) {
966 gp_Cone aCone = aSurfaFace.Cone();
967 anax1aFace2 = aCone.Axis();
968 } else if (aTypeaFace == GeomAbs_Torus) {
969 gp_Torus aTore = aSurfaFace.Torus();
970 anax1aFace2 = aTore.Axis();
973 cout << "Compute angle " << aTypeaFace << " non traite"<<endl;
979 if (aTypeaFace==GeomAbs_Plane) {
980 if (!anax1aFace1.IsParallel(anax1aFace2, Precision::Angular())) {
982 IntAna_QuadQuadGeo IntersectPlane (aPlnaFace1, aPlnaFace2, Precision::Angular(), Precision::Angular());
983 if (IntersectPlane.IsDone() &&
984 (IntersectPlane.TypeInter() != IntAna_Empty)) {
985 gp_Lin aLine = IntersectPlane.Line(1);
986 Handle(Geom_Line) computedgeom3 = new Geom_Line (aLine);
987 ageom3 = computedgeom3;
990 cout<<"Compute angle insertection of planes failed"<<endl;
998 cout<<"Compute angle faces are //"<<endl;
1004 // Curvilinear faces...
1005 isCurvilinear = Standard_True;
1007 } // endif (ageom3.IsNull())
1010 Standard_Boolean isplan(Standard_False);
1012 if (!isCurvilinear) {
1013 if (ageom3->IsKind(STANDARD_TYPE(Geom_Plane))) isplan = Standard_True;
1014 else if (ageom3->IsKind(STANDARD_TYPE(Geom_Line))) isplan = Standard_False;
1017 cout << "TPrsStd_ConstraintTools::ComputeAngle: unknown 3rd arg " << endl;
1024 TCollection_ExtendedString txt;
1025 ComputeTextAndValue (aConst,val1,txt,Standard_True);
1027 Standard_Boolean toCreate (Standard_True);
1028 Standard_Boolean isface(shape1.ShapeType()==TopAbs_FACE);
1030 Handle(AIS_AngleDimension) ais;
1031 if (!anAIS.IsNull()) {
1032 ais = Handle(AIS_AngleDimension)::DownCast(anAIS);
1033 if( ais.IsNull() ) {
1034 toCreate = Standard_True;
1036 else toCreate = Standard_False;
1039 Standard_Integer ExtShape(0);
1041 // Creation de l'AIS
1044 FindExternalShape(aConst,ExtShape);
1045 GetGoodShape(shape1);
1046 GetGoodShape(shape2);
1047 ais = new AIS_AngleDimension (TopoDS::Edge(shape1),
1048 TopoDS::Edge(shape2));
1052 if (isCurvilinear) {
1053 ais = new AIS_AngleDimension (TopoDS::Face(shape1),
1054 TopoDS::Face(shape2));
1057 ais = new AIS_AngleDimension (TopoDS::Face(shape1),
1058 TopoDS::Face(shape2));
1065 GetGoodShape(shape1);
1066 GetGoodShape(shape2);
1068 ais->SetMeasuredGeometry (TopoDS::Face (shape1), TopoDS::Face (shape2));
1070 ais->SetCustomPlane (Handle(Geom_Plane)::DownCast (ageom3)->Pln());
1071 else if (!isCurvilinear)
1074 aPlane.SetAxis (Handle(Geom_Line)::DownCast (ageom3)->Position());
1075 ais->SetCustomPlane (aPlane);
1082 //=======================================================================
1083 //function : ComputeConcentric
1085 //=======================================================================
1086 void TPrsStd_ConstraintTools::ComputeConcentric(const Handle(TDataXtd_Constraint)& aConst,
1087 Handle(AIS_InteractiveObject)& anAIS)
1089 Standard_Integer nbgeom = aConst->NbGeometries();
1091 Standard_ProgramError::Raise ("TPrsStd_ConstraintTools::ComputeConcentric: at least 2 constraintes are needed");
1093 if (!aConst->IsPlanar()) {
1095 cout << "TPrsStd_ConstraintTools::ComputeConcentric: must be a planar constraint" << endl;
1100 TopoDS_Shape shape1,shape2 ;
1101 Handle(Geom_Geometry) ageom3;
1103 GetShapesAndGeom(aConst,shape1,shape2,ageom3);
1104 if (shape1.IsNull() || shape2.IsNull()) {
1106 cout << "TPrsStd_ConstraintTools::ComputeConcentric : null shape" << endl;
1112 GetGoodShape(shape1);
1113 GetGoodShape(shape2);
1115 //ota : to allow concentric constraint display between vertex and edge
1116 if (shape1.ShapeType() != TopAbs_EDGE && shape2.ShapeType() != TopAbs_EDGE) {
1118 cout << "TPrsStd_ConstraintTools::ComputeConcentric: concentric between two vertexes : NOT DISPLAYED" << endl;;
1124 Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom3);
1125 if (aplane.IsNull()) {
1127 cout << "TPrsStd_ConstraintTools::ComputeConcentric: nul plane" << endl;;
1133 Handle(AIS_ConcentricRelation) ais;
1134 if (!anAIS.IsNull()) {
1135 ais = Handle(AIS_ConcentricRelation)::DownCast(anAIS);
1137 ais = new AIS_ConcentricRelation (shape1,shape2,aplane);
1140 ais->SetFirstShape(shape1);
1141 ais->SetSecondShape(shape2);
1142 ais->SetPlane(aplane);
1146 ais = new AIS_ConcentricRelation (shape1,shape2,aplane);
1152 //=======================================================================
1153 //function : ComputeRadius
1155 //=======================================================================
1156 void TPrsStd_ConstraintTools::ComputeRadius (const Handle(TDataXtd_Constraint)& aConst,
1157 Handle(AIS_InteractiveObject)& anAIS)
1159 Standard_Integer nbgeom = aConst->NbGeometries();
1162 cout << "TPrsStd_ConstraintTools::ComputeRadius: at least one constrainte is needed" << endl;
1168 TopoDS_Shape shape1 ;
1169 GetOneShape (aConst,shape1);
1170 if (shape1.IsNull()) {
1172 cout << "TPrsStd_ConstraintTools::ComputeRadius: null shape" << endl;
1178 // POP on teste si ce n'est pas un compound
1179 if (shape1.ShapeType()==TopAbs_COMPOUND ||
1180 shape1.ShapeType()==TopAbs_COMPSOLID ||
1181 shape1.ShapeType()==TopAbs_SOLID ||
1182 shape1.ShapeType()==TopAbs_SHELL ) {
1184 cout << "TPrsStd_ConstraintTools::ComputeRadius: not good shape" << endl;
1191 shape1 = GetFace(shape1);
1194 TCollection_ExtendedString txt;
1195 ComputeTextAndValue(aConst,val1,txt,Standard_False);
1198 Standard_Boolean isplanar(aConst->IsPlanar());
1199 if (isplanar) GetGoodShape(shape1);
1201 Handle(AIS_RadiusDimension) ais;
1202 if (!anAIS.IsNull()) {
1203 ais = Handle(AIS_RadiusDimension)::DownCast(anAIS);
1205 ais = new AIS_RadiusDimension (shape1);
1208 ais->SetMeasuredGeometry(shape1);
1211 else ais = new AIS_RadiusDimension (shape1);
1214 Handle(Geom_Geometry) ageom2;
1215 GetGeom(aConst,ageom2);
1216 Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom2);
1217 if (aplane.IsNull()) {
1219 cout << "TPrsStd_ConstraintTools::ComputeRadius: nul plane" << endl;
1224 ais->SetCustomPlane(aplane->Pln());
1229 //=======================================================================
1230 //function : ComputeMinRadius
1232 //=======================================================================
1233 void TPrsStd_ConstraintTools::ComputeMinRadius (const Handle(TDataXtd_Constraint)& aConst,
1234 Handle(AIS_InteractiveObject)& anAIS)
1236 Standard_Integer nbgeom = aConst->NbGeometries();
1239 cout << "TPrsStd_ConstraintTools::ComputeMinRadius: at least one constrainte is needed" << endl;
1245 TopoDS_Shape shape1 ;
1246 GetOneShape (aConst,shape1);
1247 if (shape1.IsNull()) {
1249 cout << "TPrsStd_ConstraintTools::ComputeMinradius: null shape" << endl;
1255 // POP on teste si ce n'est pas un compound
1256 if (shape1.ShapeType()==TopAbs_COMPOUND ||
1257 shape1.ShapeType()==TopAbs_COMPSOLID ||
1258 shape1.ShapeType()==TopAbs_SOLID ||
1259 shape1.ShapeType()==TopAbs_SHELL ) {
1261 cout << "TPrsStd_ConstraintTools::ComputeMinRadius: not good shape" << endl;
1268 shape1 = GetFace(shape1);
1271 TCollection_ExtendedString txt;
1272 ComputeTextAndValue(aConst,val1,txt,Standard_False);
1275 Standard_Boolean isplanar(aConst->IsPlanar());
1276 if (isplanar) GetGoodShape(shape1);
1278 Handle(AIS_MinRadiusDimension) ais;
1279 if (!anAIS.IsNull()) {
1280 ais = Handle(AIS_MinRadiusDimension)::DownCast(anAIS);
1282 ais = new AIS_MinRadiusDimension (shape1,val1,txt);
1285 ais->SetValue(val1);
1286 ais->SetFirstShape(shape1);
1290 else ais = new AIS_MinRadiusDimension (shape1,val1,txt);
1293 Handle(Geom_Geometry) ageom2;
1294 GetGeom(aConst,ageom2);
1295 Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom2);
1296 if (aplane.IsNull()) {
1298 cout << "TPrsStd_ConstraintTools::ComputeMinRadius: nul plane" << endl;
1303 ais->SetPlane(aplane);
1308 //=======================================================================
1309 //function : ComputeMaxRadius
1311 //=======================================================================
1312 void TPrsStd_ConstraintTools::ComputeMaxRadius (const Handle(TDataXtd_Constraint)& aConst,
1313 Handle(AIS_InteractiveObject)& anAIS)
1315 Standard_Integer nbgeom = aConst->NbGeometries();
1318 cout << "TPrsStd_ConstraintTools::ComputeMaxRadius: at least one constrainte is needed" << endl;
1324 TopoDS_Shape shape1 ;
1325 GetOneShape (aConst,shape1);
1326 if (shape1.IsNull()) {
1328 cout << "TPrsStd_ConstraintTools::ComputeMaxradius: null shape" << endl;
1334 // POP on teste si ce n'est pas un compound
1335 if (shape1.ShapeType()==TopAbs_COMPOUND ||
1336 shape1.ShapeType()==TopAbs_COMPSOLID ||
1337 shape1.ShapeType()==TopAbs_SOLID ||
1338 shape1.ShapeType()==TopAbs_SHELL ) {
1340 cout << "TPrsStd_ConstraintTools::ComputeMaxRadius: not good shape" << endl;
1347 shape1 = GetFace(shape1);
1350 TCollection_ExtendedString txt;
1351 ComputeTextAndValue(aConst,val1,txt,Standard_False);
1354 Standard_Boolean isplanar(aConst->IsPlanar());
1355 if (isplanar) GetGoodShape(shape1);
1357 Handle(AIS_MaxRadiusDimension) ais;
1358 if (!anAIS.IsNull()) {
1359 ais = Handle(AIS_MaxRadiusDimension)::DownCast(anAIS);
1361 ais = new AIS_MaxRadiusDimension (shape1,val1,txt);
1364 ais->SetValue(val1);
1365 ais->SetFirstShape(shape1);
1369 else ais = new AIS_MaxRadiusDimension (shape1,val1,txt);
1372 Handle(Geom_Geometry) ageom2;
1373 GetGeom(aConst,ageom2);
1374 Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom2);
1375 if (aplane.IsNull()) {
1377 cout << "TPrsStd_ConstraintTools::ComputeMaxRadius: nul plane" << endl;
1382 ais->SetPlane(aplane);
1387 //=======================================================================
1388 //function : ComputeEqualDistance
1390 //=======================================================================
1391 void TPrsStd_ConstraintTools::ComputeEqualDistance(const Handle(TDataXtd_Constraint)& aConst,
1392 Handle(AIS_InteractiveObject)& anAIS)
1394 Standard_Integer nbgeom = aConst->NbGeometries();
1397 cout << "TPrsStd_ConstraintTools::ComputeEqual: at least four geometries are needed" << endl;;
1402 TopoDS_Shape aShape1, aShape2, aShape3, aShape4;
1403 Handle(Geom_Geometry) aGeom;
1404 GetShapesAndGeom(aConst, aShape1, aShape2, aShape3, aShape4, aGeom);
1405 if (aShape1.IsNull()||aShape2.IsNull()||
1406 aShape3.IsNull()||aShape4.IsNull()) {
1408 cout << "TPrsStd_ConstraintTools::ComputeEqualDistance : null shape" << endl;
1414 GetGoodShape(aShape1);
1415 GetGoodShape(aShape2);
1416 GetGoodShape(aShape3);
1417 GetGoodShape(aShape4);
1419 if (!CheckShapesPair(aShape1, aShape2) ||
1420 !CheckShapesPair(aShape3, aShape4)){
1422 cout << "TPrsStd_ConstraintTools::ComputeEqualDistance : at least one pair of shapes is incorrect"<<endl;
1429 Standard_Boolean IsPlanar(aConst->IsPlanar());
1430 Handle(Geom_Plane) aPlane ;
1431 if(IsPlanar) aPlane = Handle(Geom_Plane)::DownCast(aGeom) ;
1433 if (!IsPlanar || aPlane.IsNull()) {
1436 cout<< "The constraint plane is not assigned "<< endl;
1443 Handle(AIS_EqualDistanceRelation) ais;
1444 if (!anAIS.IsNull()) {
1446 ais = Handle(AIS_EqualDistanceRelation)::DownCast(anAIS);
1449 ais = new AIS_EqualDistanceRelation(aShape1, aShape2, aShape3, aShape4, aPlane);
1452 ais->SetFirstShape(aShape1);
1453 ais->SetSecondShape(aShape2);
1454 ais->SetShape3(aShape3);
1455 ais->SetShape4(aShape4);
1456 ais->SetPlane(aPlane);
1460 else ais = new AIS_EqualDistanceRelation(aShape1, aShape2, aShape3, aShape4, aPlane);
1467 //======================================================================
1468 // function : CheckShapesPair
1469 // purpose : checks the types of two shapes.
1470 // If the types aShape1 and aShape2 are EDGE - EDGE,
1471 // or EDGE - VERTEX,
1472 // or VERTEX - VERTEX,
1473 // or CIRCLE - CIRCLE,
1474 // or CIRCLE - VERTEX,
1475 // then function returns TRUE, otherwise FALSE.
1476 //======================================================================
1477 static Standard_Boolean CheckShapesPair(const TopoDS_Shape& aShape1,
1478 const TopoDS_Shape& aShape2)
1480 //Check whether the shapes form a correct pair.
1481 if (aShape1.ShapeType() == TopAbs_EDGE && aShape2.ShapeType() == TopAbs_EDGE)
1483 BRepAdaptor_Curve aCurve1(TopoDS::Edge(aShape1));
1484 BRepAdaptor_Curve aCurve2(TopoDS::Edge(aShape2));
1485 if (aCurve1.GetType() == GeomAbs_Line && aCurve2.GetType() == GeomAbs_Line)
1486 { //Are lines parallel ?
1487 gp_Dir aDir1 = aCurve1.Line().Direction();
1488 gp_Dir aDir2 = aCurve2.Line().Direction();
1489 if (!(aDir1.IsParallel(aDir2, Precision::Confusion()))) {
1491 cout << " Lines are not parallel"<<endl;
1493 return Standard_False;
1496 else if (aCurve1.GetType() == GeomAbs_Circle && aCurve2.GetType() == GeomAbs_Circle)
1498 gp_Pnt aCntr1 = aCurve1.Circle().Location(); //get the circle center
1499 gp_Pnt aCntr2 = aCurve2.Circle().Location(); //get the circle center
1500 if (!aCntr1.IsEqual(aCntr2,Precision::Confusion())){
1502 cout << " Circles are not concentric"<<endl;
1504 return Standard_False;
1509 cout << "Incorrect pair of curves "<<endl;
1511 return Standard_False;
1514 else if ( aShape1.ShapeType() != TopAbs_VERTEX || aShape2.ShapeType() != TopAbs_VERTEX)
1517 BRepAdaptor_Curve aCurve;
1518 if ( aShape1.ShapeType() == TopAbs_VERTEX) {
1519 aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape1));
1520 aCurve.Initialize(TopoDS::Edge(aShape2));
1523 aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape2));
1524 aCurve.Initialize(TopoDS::Edge(aShape1));
1526 if ( aCurve.GetType() == GeomAbs_Circle)
1528 gp_Pnt aCntr = aCurve.Circle().Location();
1529 if (!aCntr.IsEqual(aPnt, Precision::Confusion())){
1531 cout << " The point doesn't coincide with the circle center"<<endl;
1533 return Standard_False;
1537 return Standard_True;
1540 //=======================================================================
1541 //function : ComputeEqualRadius
1543 //=======================================================================
1544 void TPrsStd_ConstraintTools::ComputeEqualRadius(const Handle(TDataXtd_Constraint)& aConst,
1545 Handle(AIS_InteractiveObject)& anAIS)
1547 Standard_Integer nbgeom = aConst->NbGeometries();
1550 cout << "TPrsStd_ConstraintTools::ComputeEqualRadius: at least two geometries are needed" << endl;;
1555 TopoDS_Shape shape1, shape2;
1556 Handle(Geom_Geometry) ageom3;
1558 GetShapesAndGeom(aConst, shape1, shape2, ageom3);
1559 if (shape1.IsNull()||shape2.IsNull()) {
1561 cout << "TPrsStd_ConstraintTools::ComputeEqualRadius : null shape" << endl;
1568 Standard_Boolean IsPlanar(aConst->IsPlanar());
1570 GetGoodShape(shape1);
1571 GetGoodShape(shape2);
1572 const TopoDS_Edge edge1 = TopoDS::Edge(shape1);
1573 const TopoDS_Edge edge2 = TopoDS::Edge(shape2);
1574 Handle(Geom_Plane) aplane ;
1576 if (IsPlanar) aplane = Handle(Geom_Plane)::DownCast(ageom3) ;
1578 if (!IsPlanar || aplane.IsNull()) {
1579 // check are the planes of edge1 and edge2 coincident
1580 BRepAdaptor_Curve aCurve( edge1 );
1581 Handle( Geom_Curve ) aProjCurve = aCurve.Curve().Curve();
1582 gp_Circ aCircle = (Handle( Geom_Circle )::DownCast( aProjCurve ))->Circ();
1583 gp_Ax3 anAx31(aCircle.Position()); //get the circle axis
1584 // get the circle plane
1585 Handle(Geom_Plane) aPlane1 = new Geom_Plane (anAx31);
1587 aCurve.Initialize(edge2);
1588 aProjCurve = aCurve.Curve().Curve();
1589 aCircle = (Handle( Geom_Circle )::DownCast( aProjCurve ))->Circ();
1590 gp_Ax3 anAx32(aCircle.Position()); //get the circle axis
1591 // get the circle plane
1592 Handle(Geom_Plane) aPlane2 = new Geom_Plane (anAx32);
1594 Standard_Real A, B, C ,D1, D2;
1595 aPlane1->Coefficients(A, B, C, D1);//Get normalized coefficients
1596 aPlane2->Coefficients(A, B, C, D2);//Get normalized coefficients
1597 const gp_Dir& aDir1 = anAx31.Direction();
1598 const gp_Dir& aDir2 = anAx32.Direction();
1600 if(Abs(D1 - D2) < Precision::Confusion() &&
1601 aDir1.IsParallel(aDir2, Precision::Confusion()))
1605 cout << "TPrsStd_ConstraintTools::ComputeRadiusRelation: nul plane" << endl;
1611 Handle(AIS_EqualRadiusRelation) ais;
1612 if (!anAIS.IsNull()) {
1613 ais = Handle(AIS_EqualRadiusRelation)::DownCast(anAIS);
1616 ais = new AIS_EqualRadiusRelation(edge1, edge2, aplane);
1619 ais->SetFirstShape(shape1);
1620 ais->SetSecondShape(shape2);
1621 ais->SetPlane(aplane);
1625 ais = new AIS_EqualRadiusRelation(edge1, edge2, aplane);
1632 //=======================================================================
1633 //function : ComputeDiameter
1635 //=======================================================================
1636 void TPrsStd_ConstraintTools::ComputeDiameter(const Handle(TDataXtd_Constraint)& aConst,
1637 Handle(AIS_InteractiveObject)& anAIS)
1639 Standard_Integer nbgeom = aConst->NbGeometries();
1642 cout << "TPrsStd_ConstraintTools::ComputeDiameter: at least one constrainte is needed" << endl;;
1647 TopoDS_Shape shape1 ;
1649 GetOneShape(aConst,shape1);
1650 if (shape1.IsNull()) {
1652 cout << "TPrsStd_ConstraintTools::ComputeDiameter : null shape" << endl;
1658 TCollection_ExtendedString txt;
1659 ComputeTextAndValue(aConst,val1,txt,Standard_False);
1662 Standard_Boolean IsPlanar(aConst->IsPlanar());
1663 if (IsPlanar) GetGoodShape(shape1);
1664 Handle(AIS_DiameterDimension) ais;
1665 if (!anAIS.IsNull()) {
1666 ais = Handle(AIS_DiameterDimension)::DownCast(anAIS);
1668 ais = new AIS_DiameterDimension (shape1);
1671 ais->SetMeasuredGeometry(shape1);
1674 else ais = new AIS_DiameterDimension (shape1);
1677 Handle(Geom_Geometry) ageom2;
1678 GetGeom(aConst,ageom2);
1679 Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom2);
1680 if (aplane.IsNull()) {
1682 cout << "TPrsStd_ConstraintTools::ComputeDiameter: nul plane" << endl;
1687 //ais->SetCustomPlane(aplane);
1693 //=======================================================================
1694 //function : ComputeFix
1696 //=======================================================================
1697 void TPrsStd_ConstraintTools::ComputeFix(const Handle(TDataXtd_Constraint)& aConst,
1698 Handle(AIS_InteractiveObject)& anAIS)
1700 Standard_Integer nbgeom = aConst->NbGeometries();
1703 cout << "TPrsStd_ConstraintTools::ComputeFix: at least one constrainte is needed" << endl;;
1708 if (!aConst->IsPlanar()) {
1710 cout << "TPrsStd_ConstraintTools::ComputeFix: must be a planar constraint" << endl;;
1716 TopoDS_Shape shape1 ;
1717 Handle(Geom_Geometry) ageom2;
1719 GetOneShape(aConst,shape1);
1720 if (shape1.IsNull()) {
1722 cout << "TPrsStd_ConstraintTools::ComputeFix : null shape" << endl;
1727 GetGoodShape(shape1);
1728 GetGeom(aConst,ageom2);
1729 Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom2);
1730 if (aplane.IsNull()) {
1732 cout << "TPrsStd_ConstraintTools::ComputeFix: nul plane" << endl;
1738 Handle(AIS_FixRelation) ais;
1739 if (!anAIS.IsNull()) {
1740 ais = Handle(AIS_FixRelation)::DownCast(anAIS);
1742 ais = new AIS_FixRelation (shape1,aplane);
1745 ais->SetFirstShape(shape1);
1746 ais->SetPlane(aplane);
1749 else ais = new AIS_FixRelation (shape1,aplane);
1754 //=======================================================================
1755 //function : ComputeOffset
1757 //=======================================================================
1758 void TPrsStd_ConstraintTools::ComputeOffset (const Handle(TDataXtd_Constraint)& aConst,
1759 Handle(AIS_InteractiveObject)& anAIS)
1761 // Get plane for planar constraint
1762 Standard_Boolean is_planar (aConst->IsPlanar());
1763 Handle(Geom_Plane) aplane;
1765 GetGeom (aConst,aplane);
1766 if (aplane.IsNull()) {
1768 cout << "TPrsStd_ConstraintTools::ComputeOffset: null plane" << endl;
1776 TopoDS_Shape S1, S2;
1777 Standard_Integer nbgeom = aConst->NbGeometries();
1779 Handle(TNaming_NamedShape) ageom1 = aConst->GetGeometry(1);
1780 // c'est une shape qui contient les faces generees par les faces d'origines
1781 TNaming_Iterator It (ageom1);
1789 // Get geometry of the constraint
1790 GetTwoShapes (aConst,S1,S2);
1793 if (S1.IsNull() || S2.IsNull()) {
1795 cout << "TPrsStd_ConstraintTools::ComputeOffset: null shape" << endl;
1803 TCollection_ExtendedString txt;
1804 Handle(AIS_LengthDimension) ais;
1805 //Handle(Prs3d_Drawer) aDrawer;
1809 ComputeTextAndValue (aConst,val1,txt,Standard_False);
1810 if (!anAIS.IsNull())
1812 ais = Handle(AIS_LengthDimension)::DownCast(anAIS);
1815 if (S1.ShapeType() == TopAbs_FACE && S2.ShapeType() == TopAbs_FACE)
1819 ais = new AIS_LengthDimension (TopoDS::Face(S1),TopoDS::Face(S2));
1823 ais->SetMeasuredShapes (S1, S2);
1824 ais->SetCustomValue(val1);
1828 ais->SetCustomPlane (aplane->Pln());
1833 if (S1.ShapeType() == TopAbs_EDGE && S2.ShapeType() == TopAbs_EDGE) {
1834 // Find a plane for the dimension
1835 TopoDS_Edge OE = TopoDS::Edge(S1);
1836 BRepAdaptor_Curve CURVE(OE);
1837 if (CURVE.GetType() == GeomAbs_Line) {
1838 // Works only with line !!
1839 Handle(Geom_Geometry) aGeomGeometry = CURVE.Curve().Curve()->Transformed(CURVE.Trsf()) ;
1840 gp_Lin OLin = Handle(Geom_Line)::DownCast (aGeomGeometry)->Lin();
1841 TopoDS_Edge NE = TopoDS::Edge(S2);
1842 CURVE.Initialize (NE);
1843 aGeomGeometry = CURVE.Curve().Curve()->Transformed(CURVE.Trsf()) ;
1844 gp_Lin NLin = Handle(Geom_Line)::DownCast (aGeomGeometry)->Lin();
1845 gp_Dir TDir (NLin.Location().XYZ() - OLin.Location().XYZ());
1846 aplane = new Geom_Plane (NLin.Location(),NLin.Direction()^TDir);
1849 ais = new AIS_LengthDimension (S1,S2,aplane->Pln());
1852 ais->SetMeasuredShapes (S1, S2);
1853 ais->SetCustomValue(val1);
1855 ais->SetCustomPlane (aplane->Pln());
1861 if (CURVE.GetType() == GeomAbs_Circle) {
1862 Handle(Geom_Geometry) aGeomGeometry = CURVE.Curve().Curve()->Transformed(CURVE.Trsf()) ;
1863 gp_Ax1 ax = Handle(Geom_Circle)::DownCast (aGeomGeometry)->Circ().Axis();
1864 aplane = new Geom_Plane (ax.Location(),ax.Direction());
1865 is_planar = Standard_True;
1872 if (S1.ShapeType() == TopAbs_COMPOUND &&
1873 S2.ShapeType() == TopAbs_COMPOUND) {
1874 // Resultat d'un offset - on reconstruit un wire pour determiner un plan
1878 TopExp_Explorer exp (S1,TopAbs_EDGE);
1879 for (;exp.More();exp.Next())
1880 B.Add (w1,exp.Current());
1882 BRepBuilderAPI_MakeFace MkF (w1,Standard_True);
1884 Handle(Geom_Surface) aGeomSurface = BRep_Tool::Surface(MkF.Face());
1885 aplane = Handle(Geom_Plane)::DownCast (aGeomSurface);
1886 is_planar = Standard_True;
1892 ComputeTextAndValue (aConst,val1,txt,Standard_False);
1893 TopExp_Explorer EXP1 (S1,TopAbs_VERTEX);
1894 S1 = EXP1.Current();
1895 gp_Pnt P = BRep_Tool::Pnt(TopoDS::Vertex(S1));
1897 TopoDS_Vertex nearest;
1898 Standard_Real dist(RealLast());
1900 for (TopExp_Explorer EXP2(S2,TopAbs_VERTEX); EXP2.More(); EXP2.Next()) {
1901 const TopoDS_Vertex& current = TopoDS::Vertex(EXP2.Current());
1902 gp_Pnt curpnt = BRep_Tool::Pnt(current);
1903 Standard_Real curdist = P.SquareDistance(curpnt);
1904 if (curdist < dist) {
1910 ais = Handle(AIS_LengthDimension)::DownCast(anAIS);
1912 ais = new AIS_LengthDimension (S1,S2,aplane->Pln());
1915 ais->SetMeasuredShapes (S1, S2);
1916 ais->SetCustomValue (val1);
1917 ais->SetCustomPlane (aplane->Pln ());
1924 cout << "TPrsStd_ConstraintTools::ComputeOffset: Case not implemented" << endl;
1930 //=======================================================================
1931 //function : ComputePlacement
1933 //=======================================================================
1934 void TPrsStd_ConstraintTools::ComputePlacement
1935 (const Handle(TDataXtd_Constraint)& aConst,
1936 Handle(AIS_InteractiveObject)& anAIS)
1938 Standard_Integer nbgeom = aConst->NbGeometries();
1940 Standard_ProgramError::Raise
1941 ("TPrsStd_ConstraintTools::ComputePlacement: at leat two constraints are needed");
1943 TopoDS_Shape shape1,shape2 ;
1944 GetTwoShapes(aConst,shape1,shape2);
1945 if (shape1.IsNull() || shape2.IsNull()) {
1947 cout << "TPrsStd_ConstraintTools::ComputePlacement: nul shape" << endl;
1953 Standard_Real val1=0.0;
1954 TCollection_ExtendedString txt= " ";
1955 if (aConst->IsDimension()) {
1956 ComputeTextAndValue(aConst,val1,txt,Standard_False);
1959 Handle(AIS_OffsetDimension) ais;
1960 if (anAIS.IsNull()) {
1961 ais = new AIS_OffsetDimension(GetFace(shape1),GetFace(shape2),val1,txt);
1962 ais->SetArrowSize(val1/20.);
1964 ais = Handle(AIS_OffsetDimension)::DownCast(anAIS);
1966 ais = new AIS_OffsetDimension(GetFace(shape1),GetFace(shape2),val1,txt);
1967 ais->SetArrowSize(val1/20.);
1969 ais->SetFirstShape(GetFace(shape1));
1970 ais->SetSecondShape(GetFace(shape2));
1971 ais->SetValue(val1);
1973 ais->SetArrowSize(val1/20.);
1976 if (GetFace(shape1).IsNull() || GetFace(shape2).IsNull()) ais.Nullify();
1980 //=======================================================================
1981 //function : ComputeOthers
1983 //=======================================================================
1984 void TPrsStd_ConstraintTools::ComputeOthers
1985 (const Handle(TDataXtd_Constraint)& /*aConst*/,
1986 Handle(AIS_InteractiveObject)& /*anAIS*/)
1990 //=======================================================================
1991 //function : GetOneShape
1993 //=======================================================================
1994 void TPrsStd_ConstraintTools::GetOneShape
1995 (const Handle(TDataXtd_Constraint)& aConst,
1996 TopoDS_Shape& aShape)
1998 const Handle(TNaming_NamedShape)& ageom1 = aConst->GetGeometry(1);
1999 if (!ageom1.IsNull()) aShape = TNaming_Tool::CurrentShape(ageom1);
2002 //=======================================================================
2003 //function : GetTwoShapes
2005 //=======================================================================
2006 void TPrsStd_ConstraintTools::GetTwoShapes
2007 (const Handle(TDataXtd_Constraint)& aConst,
2008 TopoDS_Shape& aShape1,
2009 TopoDS_Shape& aShape2)
2011 const Handle(TNaming_NamedShape)& ageom1 = aConst->GetGeometry(1);
2012 if (!ageom1.IsNull()) aShape1 = TNaming_Tool::CurrentShape(aConst->GetGeometry(1));
2013 const Handle(TNaming_NamedShape)& ageom2 = aConst->GetGeometry(2);
2014 if (!ageom2.IsNull()) aShape2 = TNaming_Tool::CurrentShape(aConst->GetGeometry(2));
2017 //=======================================================================
2018 //function : GetShapesAndGeom
2020 //=======================================================================
2021 void TPrsStd_ConstraintTools::GetShapesAndGeom
2022 (const Handle(TDataXtd_Constraint)& aConst,
2023 TopoDS_Shape& aShape1,
2024 TopoDS_Shape& aShape2,
2025 Handle(Geom_Geometry)& aGeom)
2027 GetTwoShapes(aConst,aShape1,aShape2);
2028 GetGeom(aConst,aGeom);
2031 //=======================================================================
2032 //function : GetShapesAndGeom
2034 //=======================================================================
2035 void TPrsStd_ConstraintTools::GetShapesAndGeom
2036 (const Handle(TDataXtd_Constraint)& aConst,
2037 TopoDS_Shape& aShape1,
2038 TopoDS_Shape& aShape2,
2039 TopoDS_Shape& aShape3,
2040 Handle(Geom_Geometry)& aGeom)
2042 GetTwoShapes(aConst,aShape1,aShape2);
2043 const Handle(TNaming_NamedShape)& ageom3 = aConst->GetGeometry(3);//ota: GetGeometry(2) was
2044 if (!ageom3.IsNull()) aShape3 = TNaming_Tool::CurrentShape(aConst->GetGeometry(3));
2045 GetGeom(aConst,aGeom);
2048 //=======================================================================
2049 //function : GetShapesAndGeom
2051 //=======================================================================
2052 void TPrsStd_ConstraintTools::GetShapesAndGeom
2053 (const Handle(TDataXtd_Constraint)& aConst,
2054 TopoDS_Shape& aShape1,
2055 TopoDS_Shape& aShape2,
2056 TopoDS_Shape& aShape3,
2057 TopoDS_Shape& aShape4,
2058 Handle(Geom_Geometry)& aGeom)
2060 GetTwoShapes(aConst,aShape1, aShape2 );
2061 const Handle(TNaming_NamedShape)& ageom3 = aConst->GetGeometry(3);
2062 if (!ageom3.IsNull()) aShape3 = TNaming_Tool::CurrentShape(aConst->GetGeometry(3));
2063 const Handle(TNaming_NamedShape)& ageom4 = aConst->GetGeometry(4);
2064 if (!ageom4.IsNull()) aShape4 = TNaming_Tool::CurrentShape(aConst->GetGeometry(4));
2065 GetGeom(aConst,aGeom);
2068 //=======================================================================
2069 //function : ComputeCoincident
2071 //=======================================================================
2072 void TPrsStd_ConstraintTools::ComputeCoincident(const Handle(TDataXtd_Constraint)& aConst,
2073 Handle(AIS_InteractiveObject)& anAIS)
2075 Standard_Integer nbgeom = aConst->NbGeometries();
2078 cout << "TPrsStd_ConstraintTools::ComputeCoincident: at leat two constraintes are needed" << endl;
2084 if (!aConst->IsPlanar()) {
2086 cout << "TPrsStd_ConstraintTools::ComputeCoincident: must be a planar constraint" << endl;
2092 TopoDS_Shape shape1,shape2 ;
2093 Handle(Geom_Plane) aplane;
2094 GetShapesAndGeom(aConst,shape1,shape2,aplane);
2095 if (shape1.IsNull() || shape2.IsNull()) {
2097 cout << "TPrsStd_ConstraintTools::ComputeCoincident: nul shape" << endl;
2103 GetGoodShape(shape1);
2104 GetGoodShape(shape2);
2105 if (aplane.IsNull()) {
2107 cout << "TPrsStd_ConstraintTools::ComputeCoincident: nul plane" << endl;
2114 Handle(AIS_IdenticRelation) ais;
2115 if (anAIS.IsNull()) ais = new AIS_IdenticRelation(shape1,shape2,aplane);
2117 ais = Handle(AIS_IdenticRelation)::DownCast(anAIS);
2119 ais = new AIS_IdenticRelation(shape1,shape2,aplane);
2122 ais->SetFirstShape(shape1);
2123 ais->SetSecondShape(shape2);
2124 ais->SetPlane(aplane);
2130 //=======================================================================
2131 //function : ComputeRound
2133 //=======================================================================
2134 void TPrsStd_ConstraintTools::ComputeRound(const Handle(TDataXtd_Constraint)& aConst,
2135 Handle(AIS_InteractiveObject)& anAIS)
2137 Standard_Integer nbgeom = aConst->NbGeometries();
2140 cout << "TPrsStd_ConstraintTools::ComputeRound: at leat one geometry is needed" << endl;
2145 TopoDS_Shape shape1;
2146 GetOneShape (aConst,shape1);
2147 if (shape1.IsNull()) {
2149 cout << "TPrsStd_ConstraintTools::ComputePlacement: nul shape" << endl;
2156 TCollection_ExtendedString txt;
2157 ComputeTextAndValue(aConst,val1,txt,Standard_False);
2160 Handle(AIS_RadiusDimension) ais;
2165 if (anAIS.IsNull()) ais =
2166 new AIS_RadiusDimension(shape1);
2168 ais = Handle(AIS_RadiusDimension)::DownCast(anAIS);
2170 ais = new AIS_RadiusDimension(shape1);
2173 ais->SetMeasuredGeometry(shape1);
2177 catch(Standard_Failure) {
2184 //=======================================================================
2185 //function : GetGeom
2187 //=======================================================================
2188 void TPrsStd_ConstraintTools::GetGeom(const Handle(TDataXtd_Constraint)& aConst,
2189 Handle(Geom_Geometry)& aGeom)
2191 Handle(TNaming_NamedShape) atgeom = aConst->GetPlane();
2192 if (atgeom.IsNull()) {
2194 cout<<"TPrsStd_ConstraintTools::GetGeom : aConst->GetPlane().IsNull()"<<endl;
2202 TDF_Label label = atgeom->Label();
2204 Handle(TNaming_NamedShape) NS;
2205 if(label.FindAttribute(TNaming_NamedShape::GetID(),NS)){
2206 TopoDS_Shape s = TNaming_Tool::GetShape(NS);
2207 if(s.IsNull()) return;
2210 if (TDataXtd_Geometry::Plane(label,aplane)) aGeom = new Geom_Plane(aplane);
2211 else if (TDataXtd_Geometry::Line(label,anaxis)) aGeom = new Geom_Line(anaxis);
2212 else if (TDataXtd_Geometry::Point(label,apoint)) aGeom = new Geom_CartesianPoint(apoint);
2215 cout << "TPrsStd_ConstraintTools::GetGeom no geom on label " << endl;