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 std::cout << "TPrsStd_ConstraintTools::ComputeDistance: 1 or 2 geometries are needed" << std::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 std::cout << "TPrsStd_ConstraintTools::ComputeDistance : null shape" << std::endl;
267 GetTwoShapes (theConst, aShape1, aShape2);
269 if (aShape1.IsNull() || aShape2.IsNull())
272 std::cout << "TPrsStd_ConstraintTools::ComputeDistance : null shape" << std::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 std::cout << "TPrsStd_ConstraintTools::ComputeDistance : shape should be edge" << std::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 std::cout << "TPrsStd_ConstraintTools::ComputeDistance : null plane" << std::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 std::cout << "TPrsStd_ConstraintTools::ComputePerpendicular: at leat two constraintes are needed" << std::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 std::cout << "TPrsStd_ConstraintTools::ComputePerpendicular : null shape" << std::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 std::cout << "TPrsStd_ConstraintTools::ComputePerpendicular: nul plane" << std::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 std::cout << "TPrsStd_ConstraintTools::ComputeParallel: at least 2 constraintes are needed" << std::endl;
533 if (!aConst->IsPlanar()) {
535 std::cout << "TPrsStd_ConstraintTools::ComputeParallel: must be a planar constraint" << std::endl;
541 TopoDS_Shape shape1,shape2 ;
542 Handle(Geom_Geometry) ageom3;
544 GetShapesAndGeom(aConst,shape1,shape2,ageom3);
545 if (shape1.IsNull() || shape2.IsNull()) {
547 std::cout << "TPrsStd_ConstraintTools::ComputeParallel : null shape" << std::endl;
552 Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom3);
553 if (aplane.IsNull()) {
555 std::cout << "TPrsStd_ConstraintTools::ComputeParallel: nul plane" << std::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 std::cout << "TPrsStd_ConstraintTools::ComputeSymmetry: at least 3 constraintes are needed" << std::endl;
594 Standard_Boolean is_planar(aConst->IsPlanar());
597 std::cout << "TPrsStd_ConstraintTools::ComputeSymmetry: must be a planar constraint" << std::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 std::cout << "TPrsStd_ConstraintTools::ComputeSymmetry : null shape" << std::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 std::cout << "TPrsStd_ConstraintTools::ComputeSymmetry: null plane" << std::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 std::cout << "TPrsStd_ConstraintTools::ComputeSymmetry: at least 3 constraints are needed" << std::endl;
660 Standard_Boolean is_planar(aConst->IsPlanar());
664 std::cout << "TPrsStd_ConstraintTools::ComputeSymmetry: must be a planar constraint" << std::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 std::cout << "TPrsStd_ConstraintTools::ComputeSymmetry : null shape" << std::endl;
682 GetGoodShape(shape1);
683 GetGoodShape(shape2);
684 GetGoodShape(shape3);
686 Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom3);
690 std::cout << "TPrsStd_ConstraintTools::ComputeSymmetry: null plane" << std::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 std::cout << "TPrsStd_ConstraintTools::ComputeTangent: at leat two constraintes are needed" << std::endl;
732 if (!aConst->IsPlanar()) {
734 std::cout << "TPrsStd_ConstraintTools::ComputeTangent: must be a planar constraint" << std::endl;
739 TopoDS_Shape shape1,shape2 ;
740 Handle(Geom_Geometry) ageom3;
742 GetShapesAndGeom(aConst,shape1,shape2,ageom3);
743 if (shape1.IsNull() || shape2.IsNull()) {
745 std::cout << "TPrsStd_ConstraintTools::ComputeTangent : null shape" << std::endl;
750 GetGoodShape(shape1);
751 GetGoodShape(shape2);
752 Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom3);
753 if (aplane.IsNull()) {
755 std::cout << "TPrsStd_ConstraintTools::ComputeTangent: nul plane" << std::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 std::cout << "TPrsStd_ConstraintTools::ComputeAngleForOneFace : null shape" << std::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 std::cout << "TPrsStd::Compute angle : Shape is not Compound or is Null" <<std::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 std::cout << "TPrsStd_ConstraintTools::ComputeAngle: at least 2 constraints are needed" << std::endl;
873 TopoDS_Shape shape1,shape2 ;
874 Handle(Geom_Geometry) ageom3;
876 GetShapesAndGeom (aConst,shape1,shape2,ageom3);
877 if (shape1.IsNull() || shape2.IsNull()) {
879 std::cout << "TPrsStd_ConstraintTools::ComputeAngle : null shape" << std::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 std::cout << "Compute angle : Geom type = " << shape1.ShapeType()
904 << " non traite"<<std::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 std::cout<<"Compute angle"<<aTypeaFace<<" non traite"<<std::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 std::cout << "Compute angle : Geom type = " << shape2.ShapeType()
951 << " non traite"<<std::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 std::cout << "Compute angle " << aTypeaFace << " non traite"<<std::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 std::cout<<"Compute angle insertection of planes failed"<<std::endl;
998 std::cout<<"Compute angle faces are //"<<std::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 std::cout << "TPrsStd_ConstraintTools::ComputeAngle: unknown 3rd arg " << std::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 throw Standard_ProgramError("TPrsStd_ConstraintTools::ComputeConcentric: at least 2 constraintes are needed");
1093 if (!aConst->IsPlanar()) {
1095 std::cout << "TPrsStd_ConstraintTools::ComputeConcentric: must be a planar constraint" << std::endl;
1100 TopoDS_Shape shape1,shape2 ;
1101 Handle(Geom_Geometry) ageom3;
1103 GetShapesAndGeom(aConst,shape1,shape2,ageom3);
1104 if (shape1.IsNull() || shape2.IsNull()) {
1106 std::cout << "TPrsStd_ConstraintTools::ComputeConcentric : null shape" << std::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 std::cout << "TPrsStd_ConstraintTools::ComputeConcentric: concentric between two vertexes : NOT DISPLAYED" << std::endl;;
1124 Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom3);
1125 if (aplane.IsNull()) {
1127 std::cout << "TPrsStd_ConstraintTools::ComputeConcentric: nul plane" << std::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 std::cout << "TPrsStd_ConstraintTools::ComputeRadius: at least one constrainte is needed" << std::endl;
1168 TopoDS_Shape shape1 ;
1169 GetOneShape (aConst,shape1);
1170 if (shape1.IsNull()) {
1172 std::cout << "TPrsStd_ConstraintTools::ComputeRadius: null shape" << std::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 std::cout << "TPrsStd_ConstraintTools::ComputeRadius: not good shape" << std::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 std::cout << "TPrsStd_ConstraintTools::ComputeRadius: nul plane" << std::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 std::cout << "TPrsStd_ConstraintTools::ComputeMinRadius: at least one constrainte is needed" << std::endl;
1245 TopoDS_Shape shape1 ;
1246 GetOneShape (aConst,shape1);
1247 if (shape1.IsNull()) {
1249 std::cout << "TPrsStd_ConstraintTools::ComputeMinradius: null shape" << std::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 std::cout << "TPrsStd_ConstraintTools::ComputeMinRadius: not good shape" << std::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 std::cout << "TPrsStd_ConstraintTools::ComputeMinRadius: nul plane" << std::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 std::cout << "TPrsStd_ConstraintTools::ComputeMaxRadius: at least one constrainte is needed" << std::endl;
1324 TopoDS_Shape shape1 ;
1325 GetOneShape (aConst,shape1);
1326 if (shape1.IsNull()) {
1328 std::cout << "TPrsStd_ConstraintTools::ComputeMaxradius: null shape" << std::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 std::cout << "TPrsStd_ConstraintTools::ComputeMaxRadius: not good shape" << std::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 std::cout << "TPrsStd_ConstraintTools::ComputeMaxRadius: nul plane" << std::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 std::cout << "TPrsStd_ConstraintTools::ComputeEqual: at least four geometries are needed" << std::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 std::cout << "TPrsStd_ConstraintTools::ComputeEqualDistance : null shape" << std::endl;
1414 GetGoodShape(aShape1);
1415 GetGoodShape(aShape2);
1416 GetGoodShape(aShape3);
1417 GetGoodShape(aShape4);
1419 if (!CheckShapesPair(aShape1, aShape2) ||
1420 !CheckShapesPair(aShape3, aShape4)){
1422 std::cout << "TPrsStd_ConstraintTools::ComputeEqualDistance : at least one pair of shapes is incorrect"<<std::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 std::cout<< "The constraint plane is not assigned "<< std::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 std::cout << " Lines are not parallel"<<std::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 std::cout << " Circles are not concentric"<<std::endl;
1504 return Standard_False;
1509 std::cout << "Incorrect pair of curves "<<std::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 std::cout << " The point doesn't coincide with the circle center"<<std::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 std::cout << "TPrsStd_ConstraintTools::ComputeEqualRadius: at least two geometries are needed" << std::endl;;
1555 TopoDS_Shape shape1, shape2;
1556 Handle(Geom_Geometry) ageom3;
1558 GetShapesAndGeom(aConst, shape1, shape2, ageom3);
1559 if (shape1.IsNull()||shape2.IsNull()) {
1561 std::cout << "TPrsStd_ConstraintTools::ComputeEqualRadius : null shape" << std::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 std::cout << "TPrsStd_ConstraintTools::ComputeRadiusRelation: nul plane" << std::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 std::cout << "TPrsStd_ConstraintTools::ComputeDiameter: at least one constrainte is needed" << std::endl;;
1647 TopoDS_Shape shape1 ;
1649 GetOneShape(aConst,shape1);
1650 if (shape1.IsNull()) {
1652 std::cout << "TPrsStd_ConstraintTools::ComputeDiameter : null shape" << std::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 std::cout << "TPrsStd_ConstraintTools::ComputeDiameter: nul plane" << std::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 std::cout << "TPrsStd_ConstraintTools::ComputeFix: at least one constrainte is needed" << std::endl;;
1708 if (!aConst->IsPlanar()) {
1710 std::cout << "TPrsStd_ConstraintTools::ComputeFix: must be a planar constraint" << std::endl;;
1716 TopoDS_Shape shape1 ;
1717 Handle(Geom_Geometry) ageom2;
1719 GetOneShape(aConst,shape1);
1720 if (shape1.IsNull()) {
1722 std::cout << "TPrsStd_ConstraintTools::ComputeFix : null shape" << std::endl;
1727 GetGoodShape(shape1);
1728 GetGeom(aConst,ageom2);
1729 Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast(ageom2);
1730 if (aplane.IsNull()) {
1732 std::cout << "TPrsStd_ConstraintTools::ComputeFix: nul plane" << std::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 Handle(Geom_Geometry) ageom;
1766 GetGeom (aConst,ageom);
1767 aplane = Handle(Geom_Plane)::DownCast (ageom);
1768 if (aplane.IsNull()) {
1770 std::cout << "TPrsStd_ConstraintTools::ComputeOffset: null plane" << std::endl;
1778 TopoDS_Shape S1, S2;
1779 Standard_Integer nbgeom = aConst->NbGeometries();
1781 Handle(TNaming_NamedShape) ageom1 = aConst->GetGeometry(1);
1782 // c'est une shape qui contient les faces generees par les faces d'origines
1783 TNaming_Iterator It (ageom1);
1791 // Get geometry of the constraint
1792 GetTwoShapes (aConst,S1,S2);
1795 if (S1.IsNull() || S2.IsNull()) {
1797 std::cout << "TPrsStd_ConstraintTools::ComputeOffset: null shape" << std::endl;
1805 TCollection_ExtendedString txt;
1806 Handle(AIS_LengthDimension) ais;
1807 //Handle(Prs3d_Drawer) aDrawer;
1811 ComputeTextAndValue (aConst,val1,txt,Standard_False);
1812 if (!anAIS.IsNull())
1814 ais = Handle(AIS_LengthDimension)::DownCast(anAIS);
1817 if (S1.ShapeType() == TopAbs_FACE && S2.ShapeType() == TopAbs_FACE)
1821 ais = new AIS_LengthDimension (TopoDS::Face(S1),TopoDS::Face(S2));
1825 ais->SetMeasuredShapes (S1, S2);
1826 ais->SetCustomValue(val1);
1831 ais->SetCustomPlane (aplane->Pln());
1838 if (S1.ShapeType() == TopAbs_EDGE && S2.ShapeType() == TopAbs_EDGE) {
1839 // Find a plane for the dimension
1840 TopoDS_Edge OE = TopoDS::Edge(S1);
1841 BRepAdaptor_Curve CURVE(OE);
1842 if (CURVE.GetType() == GeomAbs_Line) {
1843 // Works only with line !!
1844 Handle(Geom_Geometry) aGeomGeometry = CURVE.Curve().Curve()->Transformed(CURVE.Trsf()) ;
1845 gp_Lin OLin = Handle(Geom_Line)::DownCast (aGeomGeometry)->Lin();
1846 TopoDS_Edge NE = TopoDS::Edge(S2);
1847 CURVE.Initialize (NE);
1848 aGeomGeometry = CURVE.Curve().Curve()->Transformed(CURVE.Trsf()) ;
1849 gp_Lin NLin = Handle(Geom_Line)::DownCast (aGeomGeometry)->Lin();
1850 gp_Dir TDir (NLin.Location().XYZ() - OLin.Location().XYZ());
1851 aplane = new Geom_Plane (NLin.Location(),NLin.Direction()^TDir);
1854 ais = new AIS_LengthDimension (S1,S2,aplane->Pln());
1857 ais->SetMeasuredShapes (S1, S2);
1858 ais->SetCustomValue(val1);
1860 ais->SetCustomPlane (aplane->Pln());
1866 if (CURVE.GetType() == GeomAbs_Circle) {
1867 Handle(Geom_Geometry) aGeomGeometry = CURVE.Curve().Curve()->Transformed(CURVE.Trsf()) ;
1868 gp_Ax1 ax = Handle(Geom_Circle)::DownCast (aGeomGeometry)->Circ().Axis();
1869 aplane = new Geom_Plane (ax.Location(),ax.Direction());
1870 is_planar = Standard_True;
1877 if (S1.ShapeType() == TopAbs_COMPOUND &&
1878 S2.ShapeType() == TopAbs_COMPOUND) {
1879 // Resultat d'un offset - on reconstruit un wire pour determiner un plan
1883 TopExp_Explorer exp (S1,TopAbs_EDGE);
1884 for (;exp.More();exp.Next())
1885 B.Add (w1,exp.Current());
1887 BRepBuilderAPI_MakeFace MkF (w1,Standard_True);
1889 Handle(Geom_Surface) aGeomSurface = BRep_Tool::Surface(MkF.Face());
1890 aplane = Handle(Geom_Plane)::DownCast (aGeomSurface);
1891 is_planar = Standard_True;
1897 ComputeTextAndValue (aConst,val1,txt,Standard_False);
1898 TopExp_Explorer EXP1 (S1,TopAbs_VERTEX);
1899 S1 = EXP1.Current();
1900 gp_Pnt P = BRep_Tool::Pnt(TopoDS::Vertex(S1));
1902 TopoDS_Vertex nearest;
1903 Standard_Real dist(RealLast());
1905 for (TopExp_Explorer EXP2(S2,TopAbs_VERTEX); EXP2.More(); EXP2.Next()) {
1906 const TopoDS_Vertex& current = TopoDS::Vertex(EXP2.Current());
1907 gp_Pnt curpnt = BRep_Tool::Pnt(current);
1908 Standard_Real curdist = P.SquareDistance(curpnt);
1909 if (curdist < dist) {
1915 ais = Handle(AIS_LengthDimension)::DownCast(anAIS);
1917 ais = new AIS_LengthDimension (S1,S2,aplane->Pln());
1920 ais->SetMeasuredShapes (S1, S2);
1921 ais->SetCustomValue (val1);
1922 ais->SetCustomPlane (aplane->Pln ());
1929 std::cout << "TPrsStd_ConstraintTools::ComputeOffset: Case not implemented" << std::endl;
1935 //=======================================================================
1936 //function : ComputePlacement
1938 //=======================================================================
1939 void TPrsStd_ConstraintTools::ComputePlacement
1940 (const Handle(TDataXtd_Constraint)& aConst,
1941 Handle(AIS_InteractiveObject)& anAIS)
1943 Standard_Integer nbgeom = aConst->NbGeometries();
1945 throw Standard_ProgramError("TPrsStd_ConstraintTools::ComputePlacement: at leat two constraints are needed");
1947 TopoDS_Shape shape1,shape2 ;
1948 GetTwoShapes(aConst,shape1,shape2);
1949 if (shape1.IsNull() || shape2.IsNull()) {
1951 std::cout << "TPrsStd_ConstraintTools::ComputePlacement: nul shape" << std::endl;
1957 Standard_Real val1=0.0;
1958 TCollection_ExtendedString txt= " ";
1959 if (aConst->IsDimension()) {
1960 ComputeTextAndValue(aConst,val1,txt,Standard_False);
1963 Handle(AIS_OffsetDimension) ais;
1964 if (anAIS.IsNull()) {
1965 ais = new AIS_OffsetDimension(GetFace(shape1),GetFace(shape2),val1,txt);
1966 ais->SetArrowSize(val1/20.);
1968 ais = Handle(AIS_OffsetDimension)::DownCast(anAIS);
1970 ais = new AIS_OffsetDimension(GetFace(shape1),GetFace(shape2),val1,txt);
1971 ais->SetArrowSize(val1/20.);
1973 ais->SetFirstShape(GetFace(shape1));
1974 ais->SetSecondShape(GetFace(shape2));
1975 ais->SetValue(val1);
1977 ais->SetArrowSize(val1/20.);
1980 if (GetFace(shape1).IsNull() || GetFace(shape2).IsNull()) ais.Nullify();
1984 //=======================================================================
1985 //function : ComputeOthers
1987 //=======================================================================
1988 void TPrsStd_ConstraintTools::ComputeOthers
1989 (const Handle(TDataXtd_Constraint)& /*aConst*/,
1990 Handle(AIS_InteractiveObject)& /*anAIS*/)
1994 //=======================================================================
1995 //function : GetOneShape
1997 //=======================================================================
1998 void TPrsStd_ConstraintTools::GetOneShape
1999 (const Handle(TDataXtd_Constraint)& aConst,
2000 TopoDS_Shape& aShape)
2002 const Handle(TNaming_NamedShape)& ageom1 = aConst->GetGeometry(1);
2003 if (!ageom1.IsNull()) aShape = TNaming_Tool::CurrentShape(ageom1);
2006 //=======================================================================
2007 //function : GetTwoShapes
2009 //=======================================================================
2010 void TPrsStd_ConstraintTools::GetTwoShapes
2011 (const Handle(TDataXtd_Constraint)& aConst,
2012 TopoDS_Shape& aShape1,
2013 TopoDS_Shape& aShape2)
2015 const Handle(TNaming_NamedShape)& ageom1 = aConst->GetGeometry(1);
2016 if (!ageom1.IsNull()) aShape1 = TNaming_Tool::CurrentShape(aConst->GetGeometry(1));
2017 const Handle(TNaming_NamedShape)& ageom2 = aConst->GetGeometry(2);
2018 if (!ageom2.IsNull()) aShape2 = TNaming_Tool::CurrentShape(aConst->GetGeometry(2));
2021 //=======================================================================
2022 //function : GetShapesAndGeom
2024 //=======================================================================
2025 void TPrsStd_ConstraintTools::GetShapesAndGeom
2026 (const Handle(TDataXtd_Constraint)& aConst,
2027 TopoDS_Shape& aShape1,
2028 TopoDS_Shape& aShape2,
2029 Handle(Geom_Geometry)& aGeom)
2031 GetTwoShapes(aConst,aShape1,aShape2);
2032 GetGeom(aConst,aGeom);
2035 //=======================================================================
2036 //function : GetShapesAndGeom
2038 //=======================================================================
2039 void TPrsStd_ConstraintTools::GetShapesAndGeom
2040 (const Handle(TDataXtd_Constraint)& aConst,
2041 TopoDS_Shape& aShape1,
2042 TopoDS_Shape& aShape2,
2043 TopoDS_Shape& aShape3,
2044 Handle(Geom_Geometry)& aGeom)
2046 GetTwoShapes(aConst,aShape1,aShape2);
2047 const Handle(TNaming_NamedShape)& ageom3 = aConst->GetGeometry(3);//ota: GetGeometry(2) was
2048 if (!ageom3.IsNull()) aShape3 = TNaming_Tool::CurrentShape(aConst->GetGeometry(3));
2049 GetGeom(aConst,aGeom);
2052 //=======================================================================
2053 //function : GetShapesAndGeom
2055 //=======================================================================
2056 void TPrsStd_ConstraintTools::GetShapesAndGeom
2057 (const Handle(TDataXtd_Constraint)& aConst,
2058 TopoDS_Shape& aShape1,
2059 TopoDS_Shape& aShape2,
2060 TopoDS_Shape& aShape3,
2061 TopoDS_Shape& aShape4,
2062 Handle(Geom_Geometry)& aGeom)
2064 GetTwoShapes(aConst,aShape1, aShape2 );
2065 const Handle(TNaming_NamedShape)& ageom3 = aConst->GetGeometry(3);
2066 if (!ageom3.IsNull()) aShape3 = TNaming_Tool::CurrentShape(aConst->GetGeometry(3));
2067 const Handle(TNaming_NamedShape)& ageom4 = aConst->GetGeometry(4);
2068 if (!ageom4.IsNull()) aShape4 = TNaming_Tool::CurrentShape(aConst->GetGeometry(4));
2069 GetGeom(aConst,aGeom);
2072 //=======================================================================
2073 //function : ComputeCoincident
2075 //=======================================================================
2076 void TPrsStd_ConstraintTools::ComputeCoincident(const Handle(TDataXtd_Constraint)& aConst,
2077 Handle(AIS_InteractiveObject)& anAIS)
2079 Standard_Integer nbgeom = aConst->NbGeometries();
2082 std::cout << "TPrsStd_ConstraintTools::ComputeCoincident: at leat two constraintes are needed" << std::endl;
2088 if (!aConst->IsPlanar()) {
2090 std::cout << "TPrsStd_ConstraintTools::ComputeCoincident: must be a planar constraint" << std::endl;
2096 TopoDS_Shape shape1,shape2 ;
2097 Handle(Geom_Geometry) ageom;
2098 GetShapesAndGeom(aConst,shape1,shape2,ageom);
2099 Handle(Geom_Plane) aplane = Handle(Geom_Plane)::DownCast (ageom);
2100 if (shape1.IsNull() || shape2.IsNull()) {
2102 std::cout << "TPrsStd_ConstraintTools::ComputeCoincident: nul shape" << std::endl;
2108 GetGoodShape(shape1);
2109 GetGoodShape(shape2);
2110 if (aplane.IsNull()) {
2112 std::cout << "TPrsStd_ConstraintTools::ComputeCoincident: nul plane" << std::endl;
2119 Handle(AIS_IdenticRelation) ais;
2120 if (anAIS.IsNull()) ais = new AIS_IdenticRelation(shape1,shape2,aplane);
2122 ais = Handle(AIS_IdenticRelation)::DownCast(anAIS);
2124 ais = new AIS_IdenticRelation(shape1,shape2,aplane);
2127 ais->SetFirstShape(shape1);
2128 ais->SetSecondShape(shape2);
2129 ais->SetPlane(aplane);
2135 //=======================================================================
2136 //function : ComputeRound
2138 //=======================================================================
2139 void TPrsStd_ConstraintTools::ComputeRound(const Handle(TDataXtd_Constraint)& aConst,
2140 Handle(AIS_InteractiveObject)& anAIS)
2142 Standard_Integer nbgeom = aConst->NbGeometries();
2145 std::cout << "TPrsStd_ConstraintTools::ComputeRound: at leat one geometry is needed" << std::endl;
2150 TopoDS_Shape shape1;
2151 GetOneShape (aConst,shape1);
2152 if (shape1.IsNull()) {
2154 std::cout << "TPrsStd_ConstraintTools::ComputePlacement: nul shape" << std::endl;
2161 TCollection_ExtendedString txt;
2162 ComputeTextAndValue(aConst,val1,txt,Standard_False);
2165 Handle(AIS_RadiusDimension) ais;
2170 if (anAIS.IsNull()) ais =
2171 new AIS_RadiusDimension(shape1);
2173 ais = Handle(AIS_RadiusDimension)::DownCast(anAIS);
2175 ais = new AIS_RadiusDimension(shape1);
2178 ais->SetMeasuredGeometry(shape1);
2182 catch(Standard_Failure const&) {
2189 //=======================================================================
2190 //function : GetGeom
2192 //=======================================================================
2193 void TPrsStd_ConstraintTools::GetGeom(const Handle(TDataXtd_Constraint)& aConst,
2194 Handle(Geom_Geometry)& aGeom)
2196 Handle(TNaming_NamedShape) atgeom = aConst->GetPlane();
2197 if (atgeom.IsNull()) {
2199 std::cout<<"TPrsStd_ConstraintTools::GetGeom : aConst->GetPlane().IsNull()"<<std::endl;
2207 TDF_Label label = atgeom->Label();
2209 Handle(TNaming_NamedShape) NS;
2210 if(label.FindAttribute(TNaming_NamedShape::GetID(),NS)){
2211 TopoDS_Shape s = TNaming_Tool::GetShape(NS);
2212 if(s.IsNull()) return;
2215 if (TDataXtd_Geometry::Plane(label,aplane)) aGeom = new Geom_Plane(aplane);
2216 else if (TDataXtd_Geometry::Line(label,anaxis)) aGeom = new Geom_Line(anaxis);
2217 else if (TDataXtd_Geometry::Point(label,apoint)) aGeom = new Geom_CartesianPoint(apoint);
2220 std::cout << "TPrsStd_ConstraintTools::GetGeom no geom on label " << std::endl;