+ // RefPoint
+ TopoDS_Vertex aRefVertex;
+ Handle(GEOM_Function) aRefPoint = aPI.GetRef();
+ if (aRefPoint.IsNull()) {
+ aRefVertex = V1;
+ }
+ else {
+ TopoDS_Shape aRefShape2 = aRefPoint->GetValue();
+ if (aRefShape2.ShapeType() != TopAbs_VERTEX) {
+ Standard_TypeMismatch::Raise
+ ("Point On Curve creation aborted : start point shape is not a vertex");
+ }
+ aRefVertex = TopoDS::Vertex(aRefShape2);
+ }
+ gp_Pnt aRefPnt = BRep_Tool::Pnt(aRefVertex);
+
+ // Length
+ Standard_Real aLength = aPI.GetLength();
+ //Standard_Real theCurveLength = IntTools::Length(aRefEdge);
+ //if (aLength > theCurveLength) {
+ // Standard_ConstructionError::Raise
+ // ("Point On Curve creation aborted : given length is greater than edges length");
+ //}
+
+ // Check orientation
+ Standard_Real UFirst, ULast;
+ Handle(Geom_Curve) EdgeCurve = BRep_Tool::Curve(aRefEdge, UFirst, ULast);
+ Handle(Geom_Curve) ReOrientedCurve = EdgeCurve;
+
+ Standard_Real dU = ULast - UFirst;
+ Standard_Real par1 = UFirst + 0.1 * dU;
+ Standard_Real par2 = ULast - 0.1 * dU;
+
+ gp_Pnt P1 = EdgeCurve->Value(par1);
+ gp_Pnt P2 = EdgeCurve->Value(par2);
+
+ if (aRefPnt.SquareDistance(P2) < aRefPnt.SquareDistance(P1)) {
+ ReOrientedCurve = EdgeCurve->Reversed();
+ UFirst = EdgeCurve->ReversedParameter(ULast);
+ }
+
+ // Get the point by length
+ GeomAdaptor_Curve AdapCurve = GeomAdaptor_Curve(ReOrientedCurve);
+ GCPnts_AbscissaPoint anAbsPnt (AdapCurve, aLength, UFirst);
+ Standard_Real aParam = anAbsPnt.Parameter();
+ aPnt = AdapCurve.Value(aParam);
+ }
+ else if (aType == POINT_SURFACE_PAR) {
+ Handle(GEOM_Function) aRefCurve = aPI.GetSurface();
+ TopoDS_Shape aRefShape = aRefCurve->GetValue();
+ if (aRefShape.ShapeType() != TopAbs_FACE) {
+ Standard_TypeMismatch::Raise
+ ("Point On Surface creation aborted : surface shape is not a face");
+ }
+ TopoDS_Face F = TopoDS::Face(aRefShape);
+ Handle(Geom_Surface) aSurf = BRep_Tool::Surface(F);
+ Standard_Real U1,U2,V1,V2;
+ //aSurf->Bounds(U1,U2,V1,V2);
+ ShapeAnalysis::GetFaceUVBounds(F,U1,U2,V1,V2);
+ Standard_Real U = U1 + (U2-U1) * aPI.GetParameter();
+ Standard_Real V = V1 + (V2-V1) * aPI.GetParameter2();
+ aPnt = aSurf->Value(U,V);
+ }
+ else if (aType == POINT_SURFACE_COORD) {
+ Handle(GEOM_Function) aRefCurve = aPI.GetSurface();
+ TopoDS_Shape aRefShape = aRefCurve->GetValue();
+ if (aRefShape.ShapeType() != TopAbs_FACE) {
+ Standard_TypeMismatch::Raise
+ ("Point On Surface creation aborted : surface shape is not a face");
+ }
+ gp_Pnt anInitPnt (aPI.GetX(), aPI.GetY(), aPI.GetZ());
+ if (!getExtremaSolution(anInitPnt, aRefShape, aPnt)) {
+ Standard_ConstructionError::Raise
+ ("Point On Surface creation aborted : cannot project point");
+ }
+ }
+ else if (aType == POINT_LINES_INTERSECTION) {
+ Handle(GEOM_Function) aRef1 = aPI.GetLine1();
+ Handle(GEOM_Function) aRef2 = aPI.GetLine2();
+
+ TopoDS_Shape aRefShape1 = aRef1->GetValue();
+ TopoDS_Shape aRefShape2 = aRef2->GetValue();
+
+ if ( (aRefShape1.ShapeType() != TopAbs_EDGE && aRefShape1.ShapeType() != TopAbs_WIRE)
+ || (aRefShape2.ShapeType() != TopAbs_EDGE && aRefShape2.ShapeType() != TopAbs_WIRE) ) {
+ Standard_TypeMismatch::Raise
+ ("Creation Point On Lines Intersection Aborted : Line shape is not an edge or wire");
+ }
+
+ if (aRefShape1.IsSame(aRefShape2))
+ Standard_ConstructionError::Raise("The lines to make intersection must be different");
+
+ //Calculate Lines Intersection Point
+ BRepExtrema_DistShapeShape dst (aRefShape1, aRefShape2);
+ if (dst.IsDone()) {
+ gp_Pnt P1, P2;
+ BRep_Builder B;
+ B.MakeCompound( aCompound );
+ for (int i = 1; i <= dst.NbSolution(); i++) {
+ P1 = dst.PointOnShape1(i);
+ P2 = dst.PointOnShape2(i);
+ Standard_Real Dist = P1.Distance(P2);
+ if ( Dist <= Precision::Confusion() && dst.NbSolution() > 1) {
+ BRepBuilderAPI_MakeVertex mkVertex (P1);
+ B.Add(aCompound, mkVertex.Shape());
+ retCompound = true;
+ } else if ( Dist <= Precision::Confusion() ) {
+ aPnt = P1;
+ } else {
+ Standard_TypeMismatch::Raise ("Shapes have not an Intersection Point");
+ }
+ }
+ }
+ }
+ else {