-// GEOM SKETCHER : basic sketcher
+// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
-// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+// GEOM SKETCHER : basic sketcher
// File : Sketcher_Profile.cxx
// Author : Damien COQUERET
// Module : GEOM
-// $Header:
#include <Standard_Stream.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopoDS_Face.hxx>
-#include <gp_Pln.hxx>
-#include <gp_Ax2.hxx>
#include <BRepLib.hxx>
#include <BRepBuilderAPI_MakeVertex.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
+
+#include <GeomAPI.hxx>
#include <Geom2d_Line.hxx>
#include <Geom2d_Circle.hxx>
#include <Geom_Surface.hxx>
+
#include <Precision.hxx>
-#include <GeomAPI.hxx>
+#include <gp_Pln.hxx>
+#include <gp_Ax2.hxx>
#include <TCollection_AsciiString.hxx>
-
-#include <SALOMEconfig.h>
-#include CORBA_SERVER_HEADER(SALOMEDS)
+#include <TColStd_Array1OfAsciiString.hxx>
#include "utilities.h"
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;
Handle(Geom_Surface) Surface;
myOK = Standard_False;
+ myError = 0;
- TCollection_AsciiString aCommand(CORBA::string_dup(aCmd));
+ //TCollection_AsciiString aCommand(CORBA::string_dup(aCmd));
+ TCollection_AsciiString aCommand ((char*)aCmd);
TCollection_AsciiString aToken = aCommand.Token(":", 1);
int n = 0;
// porting to WNT
- TCollection_AsciiString* aTab = 0;
+ TColStd_Array1OfAsciiString aTab (0, aCommand.Length() - 1);
if ( aCommand.Length() )
{
- aTab = new TCollection_AsciiString[ aCommand.Length() ];
while(aToken.Length() != 0) {
if(aCommand.Token(":", n + 1).Length() > 0)
- aTab[n] = aCommand.Token(":", n + 1);
+ aTab(n) = aCommand.Token(":", n + 1);
aToken = aCommand.Token(":", ++n);
}
n = n - 1;
}
- if ( aTab && aTab[0].Length() )
+ if ( aTab.Length() && aTab(0).Length() )
while(i < n) {
Standard_Real length = 0, radius = 0, angle = 0;
move = point;
-
+
int n1 = 0;
- TCollection_AsciiString* a = new TCollection_AsciiString[ aTab[0].Length() ];
- aToken = aTab[i].Token(" ", 1);
- while(aToken.Length() != 0) {
- if(aTab[i].Token(" ", n1 + 1).Length() > 0)
- a[n1] = aTab[i].Token(" ", n1 + 1);
- aToken = aTab[i].Token(" ", ++n1);
+ TColStd_Array1OfAsciiString a (0, aTab(0).Length());
+ aToken = aTab(i).Token(" ", 1);
+ while (aToken.Length() != 0) {
+ if (aTab(i).Token(" ", n1 + 1).Length() > 0)
+ a(n1) = aTab(i).Token(" ", n1 + 1);
+ aToken = aTab(i).Token(" ", ++n1);
}
n1 = n1 - 1;
-
- switch(a[0].Value(1))
+
+ switch(a(0).Value(1))
{
case 'F':
{
MESSAGE("profile : The F instruction must precede all moves");
return;
}
- x0 = x = a[1].RealValue();
- y0 = y = a[2].RealValue();
+ x0 = x = a(1).RealValue();
+ y0 = y = a(2).RealValue();
stayfirst = Standard_True;
break;
}
case 'O':
{
if (n1 != 4) goto badargs;
- P.SetLocation(gp_Pnt(a[1].RealValue(), a[2].RealValue(), a[3].RealValue()));
+ P.SetLocation(gp_Pnt(a(1).RealValue(), a(2).RealValue(), a(3).RealValue()));
stayfirst = Standard_True;
break;
}
case 'P':
{
if (n1 != 7) goto badargs;
- gp_Vec vn(a[1].RealValue(), a[2].RealValue(), a[3].RealValue());
- gp_Vec vx(a[4].RealValue(), a[5].RealValue(), a[6].RealValue());
+ gp_Vec vn(a(1).RealValue(), a(2).RealValue(), a(3).RealValue());
+ gp_Vec vx(a(4).RealValue(), a(5).RealValue(), a(6).RealValue());
if (vn.Magnitude() <= Precision::Confusion() || vx.Magnitude() <= Precision::Confusion()) {
MESSAGE("profile : null direction");
return;
case 'X':
{
if (n1 != 2) goto badargs;
- length = a[1].RealValue();
- if (a[0] == "XX")
+ length = a(1).RealValue();
+ if (a(0) == "XX")
length -= x;
dx = 1; dy = 0;
move = line;
case 'Y':
{
if (n1 != 2) goto badargs;
- length = a[1].RealValue();
- if (a[0] == "YY")
+ length = a(1).RealValue();
+ if (a(0) == "YY")
length -= y;
dx = 0; dy = 1;
move = line;
case 'L':
{
if (n1 != 2) goto badargs;
- length = a[1].RealValue();
+ length = a(1).RealValue();
if (Abs(length) > Precision::Confusion())
move = line;
else
case 'T':
{
if (n1 != 3) goto badargs;
- Standard_Real vx = a[1].RealValue();
- Standard_Real vy = a[2].RealValue();
- if (a[0] == "TT") {
+ Standard_Real vx = a(1).RealValue();
+ Standard_Real vy = a(2).RealValue();
+ if (a(0) == "TT") {
vx -= x;
vy -= y;
}
case 'R':
{
if (n1 != 2) goto badargs;
- angle = a[1].RealValue() * PI180;
- if (a[0] == "RR") {
+ angle = a(1).RealValue() * M_PI / 180.;
+ if (a(0) == "RR") {
dx = Cos(angle);
dy = Sin(angle);
}
case 'D':
{
if (n1 != 3) goto badargs;
- Standard_Real vx = a[1].RealValue();
- Standard_Real vy = a[2].RealValue();
+ Standard_Real vx = a(1).RealValue();
+ Standard_Real vy = a(2).RealValue();
length = Sqrt(vx * vx + vy * vy);
if (length > Precision::Confusion()) {
dx = vx / length;
case 'C':
{
if (n1 != 3) goto badargs;
- radius = a[1].RealValue();
+ radius = a(1).RealValue();
if (Abs(radius) > Precision::Confusion()) {
- angle = a[2].RealValue() * PI180;
+ angle = a(2).RealValue() * M_PI / 180.;
move = circle;
}
else
move = none;
break;
}
+ case 'A': // TAngential arc by end point
+ {
+ if (n1 != 3) goto badargs;
+ Standard_Real vx = a(1).RealValue();
+ Standard_Real vy = a(2).RealValue();
+ if (a(0) == "AA") {
+ vx -= x;
+ vy -= y;
+ }
+ Standard_Real det = dx * vy - dy * vx;
+ if ( Abs(det) > Precision::Confusion()) {
+ // Cosine of alpha = arc of angle / 2 , alpha in [0,Pi]
+ Standard_Real c = (dx * vx + dy * vy) / Sqrt((dx * dx + dy * dy) * (vx * vx + vy * vy));
+ // radius = distance between start and end point / 2 * sin(alpha)
+ // radius is > 0 or < 0
+ radius = (vx * vx + vy * vy)* Sqrt(dx * dx + dy * dy) / (2.0 * det);
+ if (Abs(radius) > Precision::Confusion()) {
+ angle = 2.0 * acos(c); // angle in [0,2Pi]
+ move = circle;
+ }
+ else
+ move = none;
+ break;
+ }
+ else
+ 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()) ) {
+ // Cosine of alpha = arc angle / 2 , alpha in [0,Pi/2]
+ Standard_Real c = 0.5 * Sqrt(4.0 - (vx * vx + vy * vy) / (radius * radius));
+ angle = 2.0 * acos(c); // angle in [0,Pi]
+ if ( reversed == 2 )
+ angle = angle - 2 * M_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
+ {
+ 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);
+ myError = error;
+ if ( error > Precision::Confusion() ){
+ MESSAGE("Warning : The specified end point is not on the Arc, distance = "<<error);
+ }
+ if ( error > Precision::Confusion() && control_Tolerance == 1) // Don't create the arc if the end point
+ move = none; // is too far from it
+ 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 * M_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;
- length = a[1].RealValue();
- if (a[0] == "IX") {
+ length = a(1).RealValue();
+ if (a(0) == "IX") {
if (Abs(dx) < Precision::Confusion()) {
MESSAGE("profile : cannot intersect, arg "<<i-1);
return;
}
length = (length - x) / dx;
}
- else if (a[0] == "IY") {
+ else if (a(0) == "IY") {
if (Abs(dy) < Precision::Confusion()) {
MESSAGE("profile : cannot intersect, arg "<<i-1);
return;
}
case 'W':
{
- if (a[0] == "WW")
+ if (a(0) == "WW")
close = Standard_True;
- else if(a[0] == "WF") {
+ else if(a(0) == "WF") {
close = Standard_True;
face = Standard_True;
}
}
default:
{
- MESSAGE("profile : unknown code "<<a[i]);
+ MESSAGE("profile : unknown code " << a(i));
return;
}
}
again :
- switch (move)
+ switch (move)
{
case line :
{
break;
}
}
-
+
// update first
first = stayfirst;
stayfirst = Standard_False;
-
+
if(!(dx == 0 && dy == 0))
myLastDir.SetCoord(dx, dy, 0.0);
else
return;
myLastPoint.SetX(x);
myLastPoint.SetY(y);
-
+
// next segment....
i++;
if ((i == n) && close) {
goto again;
}
}
- delete a;
}
- delete aTab;
- aTab = 0;
-
+
// get the result, face or wire
if (move == none) {
return;
}
S = MW;
}
-
+
if(!TheLocation.IsIdentity())
S.Move(TheLocation);