X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSKETCHER%2FSketcher_Profile.cxx;h=d7c46982fd93aa55f92f38f5fd89df4b5ed0a8a0;hb=8f2d0b5697219b8b53289bd9c25a60ddc354ab53;hp=5e04c891e2ce15c5fbaa4389f9ff39a1bfb6df6c;hpb=85fb1ecd0d53dbed2fd325d6e12e855271639f1c;p=modules%2Fgeom.git diff --git a/src/SKETCHER/Sketcher_Profile.cxx b/src/SKETCHER/Sketcher_Profile.cxx index 5e04c891e..d7c46982f 100644 --- a/src/SKETCHER/Sketcher_Profile.cxx +++ b/src/SKETCHER/Sketcher_Profile.cxx @@ -67,6 +67,7 @@ Sketcher_Profile::Sketcher_Profile() //======================================================================= Sketcher_Profile::Sketcher_Profile(const char* aCmd) { + myErrMsg = ""; enum {line, circle, point, none} move; Standard_Integer i = 1; @@ -78,6 +79,9 @@ Sketcher_Profile::Sketcher_Profile(const char* aCmd) first = Standard_True; stayfirst = face = close = Standard_False; + Standard_Integer reversed = 0; + Standard_Integer control_Tolerance = 0; + TopoDS_Shape S; TopoDS_Vertex MP; BRepBuilderAPI_MakeWire MW; @@ -185,7 +189,7 @@ Sketcher_Profile::Sketcher_Profile(const char* aCmd) } case 'T': { - if (n1 != 3) goto badargs; + if (n1 != 3) goto badargs; Standard_Real vx = a(1).RealValue(); Standard_Real vy = a(2).RealValue(); if (a(0) == "TT") { @@ -245,7 +249,7 @@ Sketcher_Profile::Sketcher_Profile(const char* aCmd) move = none; break; } - case 'A': + case 'A': // TAngential arc by end point { if (n1 != 3) goto badargs; Standard_Real vx = a(1).RealValue(); @@ -254,16 +258,14 @@ Sketcher_Profile::Sketcher_Profile(const char* aCmd) vx -= x; vy -= y; } - Standard_Real det = (dx * vy - dy * vx); + Standard_Real det = dx * vy - dy * vx; if ( Abs(det) > Precision::Confusion()) { - Standard_Real c = (dx * vx + dy * vy) // Cosine of alpha = arc angle / 2 - / Sqrt((dx * dx + dy * dy) - * (vx * vx + vy * vy)); - radius = (vx * vx + vy * vy) // radius = distance between start - * Sqrt(dx * dx + dy * dy) // and end point / 2 * sin(alpha) - / (2.0 * det); // radius is > 0 or < 0 + Standard_Real c = (dx * vx + dy * vy) + / Sqrt((dx * dx + dy * dy) * (vx * vx + vy * vy)); // Cosine of alpha = arc of angle / 2 , alpha in [0,Pi] + radius = (vx * vx + vy * vy)* Sqrt(dx * dx + dy * dy) // radius = distance between start and end point / 2 * sin(alpha) + / (2.0 * det); // radius is > 0 or < 0 if (Abs(radius) > Precision::Confusion()) { - angle = 2.0 * acos(c); // angle in [0,Pi] + angle = 2.0 * acos(c); // angle in [0,2Pi] move = circle; } else @@ -274,6 +276,83 @@ Sketcher_Profile::Sketcher_Profile(const char* aCmd) move = none; break; } + case 'U': // Arc by end point and radiUs + { + if (n1 != 5) goto badargs; + Standard_Real vx = a(1).RealValue(); + Standard_Real vy = a(2).RealValue(); + radius = a(3).RealValue(); + reversed = a(4).IntegerValue(); + if (a(0) == "UU") { // Absolute + vx -= x; + vy -= y; + } + Standard_Real length = Sqrt(vx * vx + vy * vy); + if ( (4.0 - (vx * vx + vy * vy) / (radius * radius) >= 0.0 ) && (length > Precision::Confusion()) ) { + Standard_Real c = 0.5 * Sqrt(4.0 - (vx * vx + vy * vy) / (radius * radius)); // Cosine of alpha = arc angle / 2 , alpha in [0,Pi/2] + angle = 2.0 * acos(c); // angle in [0,Pi] + if ( reversed == 2 ) + angle = angle - 2 * PI; + dx = 0.5 * ( vy * 1.0/radius + + vx * Sqrt(4.0 / (vx * vx + vy * vy) - 1.0 / (radius * radius))); + dy = - 0.5 * ( vx * 1.0/radius + - vy * Sqrt(4.0 / (vx * vx + vy * vy) - 1.0 / (radius * radius))); + move = circle; + } + else{ + move = none; + } + break; + } + case 'E': // Arc by end point and cEnter + { + myErrMsg = ""; + if (n1 != 7) goto badargs; + Standard_Real vx = a(1).RealValue(); + Standard_Real vy = a(2).RealValue(); + Standard_Real vxc = a(3).RealValue(); + Standard_Real vyc = a(4).RealValue(); + reversed = a(5).IntegerValue(); + control_Tolerance = a(6).IntegerValue(); + + if (a(0) == "EE") { // Absolute + vx -= x; + vy -= y; + vxc -= x; + vyc -= y; + } + radius = Sqrt( vxc * vxc + vyc * vyc ); + Standard_Real det = vx * vyc - vy * vxc; + Standard_Real length = Sqrt(vx * vx + vy * vy); + Standard_Real length2 = Sqrt((vx-vxc) * (vx-vxc) + (vy-vyc) * (vy-vyc)); + Standard_Real length3 = Sqrt(vxc * vxc + vyc * vyc); + Standard_Real error = Abs(length2 - radius); + if ( error > Precision::Confusion() ){ + MESSAGE("Warning : The specified end point is not on the Arc, distance = "< Precision::Confusion() && // Don't create the arc if the end point + control_Tolerance == 1) // is too far from it + move = none; + else if ( (length > Precision::Confusion()) && + (length2 > Precision::Confusion()) && + (length3 > Precision::Confusion()) ) { + Standard_Real c = ( radius * radius - (vx * vxc + vy * vyc) ) + / ( radius * Sqrt((vx-vxc) * (vx-vxc) + (vy-vyc) * (vy-vyc)) ) ; // Cosine of arc angle + angle = acos(c); // angle in [0,Pi] + if ( reversed == 2 ) + angle = angle - 2 * PI; + if (det < 0) + angle = -angle; + dx = vyc / radius; + dy = -vxc / radius; + move = circle; + } + else { + move = none; + } + break; + } case 'I': { if (n1 != 2) goto badargs;