- }
- BRepAdaptor_Curve AdapCurve = BRepAdaptor_Curve(TopoDS::Edge(aRefShape));
- Standard_Real theCurveLength = GCPnts_AbscissaPoint::Length(AdapCurve);
- //std::cout<<"theCurveLength = "<<theCurveLength<<std::endl;
- if (theLength > theCurveLength) {
- Standard_ConstructionError::Raise
- ("Point On Curve creation aborted : given length is greater than edges length");
+ }
+ TopoDS_Edge aRefEdge = TopoDS::Edge(aRefShape1);
+ TopoDS_Vertex V1, V2;
+ TopExp::Vertices(aRefEdge, V1, V2, Standard_True);
+
+ // 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);